Well, that was hard.
After studying the solis.c from NUT github, I have identified 2 changes in the source code that could make my NoBreak visible and funcional for the FreeNAS.
Changes in solis.c (
https://github.com/networkupstools/nut/blob/master/drivers/solis.c)
CommReceive(const char *bufptr, int size)
{
...
...
...
if( ( (RecPack[0] & 0xF0) == 0xA0 ) /* change 0xA0 to 0xB0 to support Back-UPS 1200 from Microsol */
&& ( RecPack[ 24 ] == 254 )
&& ( RecPack[ 23 ] == CheckSum ) ) {
....
....
....
if(!(detected)) {
SolisModel = (int) (RecPack[0] & 0x0F);
if( SolisModel < 13 )
imodel = SolisModel - 10; /* 10 = 0, 11 = 1 */
else
imodel = SolisModel - 11; /* 13 = 2, 14 = 3, 15 = 4 */
detected = true;
}
switch( SolisModel )
{
case 10:
/* ADD TO CASE 10, THE FOLLOWING CODE TO SUPPORT BACK-UPS 1200 FROM MICROSOL
{ ScanReceivePack();
break;
} */
{
ScanReceivePack();
break;
}
case 11:
case 12:
case 13:
case 14:
case 15:
{
ScanReceivePack();
break;
}
...
This modification on solis.c won't bring all the features correct, because I need to update the conversion formulas as well (current, frequency,etc), but the most important for FreeNAS is to know if the UPS is on battery mode or line mode. As this information was already correct, I didn't had to change it, so those 2 modifications on the code was enough to make FreeNAS talk to the UPS.
but here is my journey...
I have installed the NUT source in a jail to poke around with it.
But the hard thing was to discover the configuration parameters, as FreeNAS place the executables, conf files, libraries in a diferent directory from the default.
The closest that I have reached was this:
root@nut:/usr/local/nutado/nut-2.7.2 # ./configure --with-user=root --with-group=nut --exec_prefix=/usr/local prefix=/usr/local --sysconfdir=/etc/local/nut --sbindir=/usr/local/sbin --bindir=/usr/local/bin --with-drvpath=/usr/local/libexec/nut --with-statepath=/var/run --with-pidpath=/var/db/nut
I could talk very easily after this configuration plus the modified solis.c code.
After mount the FreeNAS partition I could talk to the NoBreak via command line.
After that I have mounted the filesystem of FreeNAS in write mode, and replace the solis executable form jail to FreeNAS USB.
It was possible to talk to the UPS via command line, but the UPS service button in the FreeNAS gui was not working, problably due to some differences in the configuration command above.
So, this solution was not Good....
and I was tired to mess with NUT source and compilation settings (I do not know much linux...).
So I downloaded the last FreeNAS iso, mounted in a USB drive and got the original "solis" executable.
The idea was to crack the executable directly to add the patches that I have done in the source of solis.c (hardcore way).
Open up in IDA and voila, the solis Assembly code was way optimizated, very difficult to read, despite the compiled solis from the jail was full with debug info, function names, etc.
After poking a little bit I have patched, 2 bytes was enough to fool the UPS service.
First change (0xA0 to 0xB0)
Original: 3D A0 00 00 00 75 8D 80 3D 77 11 21 00 FE 75 84
Patched: 3D B0 00 00 00 75 8D 80 3D 77 11 21 00 FE 75 84
This patch will force ScanReceivePack() function to be executed always:
Original: 76 29 BF A6 9C 40 00 E8 C7 F9 FF FF E9 15 FF FF
Patched: EB 29 BF A6 9C 40 00 E8 C7 F9 FF FF E9 15 FF FF
This will work for FreeNAS last version 9.2.1.5.
Instructions:
1) Open the "/usr/local/libexec/nut/solis" executable in any hex editor
2) Search for the bytes 3D A0 00 00 00 75 8D 80 3D 77 11 21 00 FE 75 84
3) Change the "A0" to "B0"
4) Search for the bytes: 76 29 BF A6 9C 40 00 E8 C7 F9 FF FF E9 15 FF FF
5) Change the "76" for "EB"
6) Save the file
7) Mount as write the Freenas filesystem using mount -uw /
8) Copy the cracked solis to /usr/local/libexec/nut
9) Mount the filesystem as readonly mount -ur /
10) Reboot.
This problem afects only Brazil Customers from Microsol UPS.
Microsol was bought by APC (Scheneider Electric) and changed the name from Microsol to APC Back-UPS 1200.
I was fooled as I thought this Microsol Model was the same as APC.
Now, this system is working like a charm.
OBSERVATION
If anybody know what are the correct settings to compile NUT for FreeNAS, please let me know.