jclehner / bcm2-utils

Utilities for Broadcom-based cable modems
GNU General Public License v3.0
142 stars 23 forks source link

bcm2cfg not working for EVW321B #21

Closed Jurrie closed 4 years ago

Jurrie commented 4 years ago

Hello,

I have a EVW321B (which I assume should work with the EVW32C profile?) and I'm trying bcm2cfg on it. I downloaded the GatewaySettings.bin file, and ran bcm2cfg info on it. It fails to parse group 'userif' and group 'firewall'.

Also, when I change a setting to the exact same value, the checksum becomes different, and the modem will not restore that GatewaySettings.bin:

$ ./bcm2cfg info ./GatewaySettings.bin
failed to parse group userif
failed to parse group firewall
./GatewaySettings.bin
type    : gwsettings
profile : evw32c
checksum: c1d66210260a6585c4e28c997dfd2d3f (ok)
size    : 15573 (ok)
key     : 6c3ea0477630ce21a2ce334aa746c2cdc782dc4c098c66cbd9cd27d825682c81

36535256  6SRV  0.1     grp_6srv       1294 b
52472e2e  RG..  0.32    rg             3386 b
4d4c6f67  MLog  0.5     userif          120 b
4344502e  CDP.  1.5     dhcp           1500 b
7a6f7267  zorg  0.7     grp_zorg        246 b
416d4468  AmDh  0.1     grp_amdh        118 b
46495245  FIRE  0.8     firewall        110 b
4353502e  CSP.  1.4     grp_csp          53 b
50524e54  PRNT  0.5     grp_prnt        123 b
56504e47  VPNG  1.0     grp_vpng         15 b
38303231  8021  0.42    bcmwifi         804 b
38303232  8022  0.42    bcmwifi2        804 b
57694775  WiGu  0.15    guestwifi      3434 b
57694776  WiGv  0.15    guestwifi2     3486 b
$ ./bcm2cfg get ./GatewaySettings.bin rg.syslog_email 
failed to parse group userif
failed to parse group firewall
rg.syslog_email = ""
$ ./bcm2cfg set ./GatewaySettings.bin rg.syslog_email ''
failed to parse group userif
failed to parse group firewall
rg.syslog_email = ""
$ ./bcm2cfg info ./GatewaySettings.bin
failed to parse group userif
failed to parse group firewall
./GatewaySettings.bin
type    : gwsettings
profile : evw32c
checksum: 3ea68fb27b16c00669effb5abc76a04f (ok)
size    : 15573 (ok)
key     : 6c3ea0477630ce21a2ce334aa746c2cdc782dc4c098c66cbd9cd27d825682c81

36535256  6SRV  0.1     grp_6srv       1294 b
52472e2e  RG..  0.32    rg             3386 b
4d4c6f67  MLog  0.5     userif          120 b
4344502e  CDP.  1.5     dhcp           1500 b
7a6f7267  zorg  0.7     grp_zorg        246 b
416d4468  AmDh  0.1     grp_amdh        118 b
46495245  FIRE  0.8     firewall        110 b
4353502e  CSP.  1.4     grp_csp          53 b
50524e54  PRNT  0.5     grp_prnt        123 b
56504e47  VPNG  1.0     grp_vpng         15 b
38303231  8021  0.42    bcmwifi         804 b
38303232  8022  0.42    bcmwifi2        804 b
57694775  WiGu  0.15    guestwifi      3434 b
57694776  WiGv  0.15    guestwifi2     3486 b

On a side note, when I change line nonvoldef.cc:192 from NV_VAR(nv_u32, "ssh_inactivity_timeout"), to NV_VAR(nv_data, "", 1), the group 'userif' is parsed and I can get and set settings contained in that group. The above behavior does not change however, and the modem will still not restore my GatewaySettings.bin.

Is it possible I have a newer, unsupported firmware? I'm on hardware version 3.12.1 and software version 9.12.8006. Or is the EVW321B not supported at all?

With kind regards,

Jurrie

jclehner commented 4 years ago

Hi,

Also, when I change a setting to the exact same value, the checksum becomes different

This is likely caused by fixed-length null-terminated strings. Suppose a settings group contains an 8-character string, which is currently set to "foobar". The null byte occipies the 7th byte, but the 8th byte could be anything. The strings "foobar\x00\xff", "foobar\x00\x5a" or "foobar\x00\x00" all have the same meaning. Currently, bcm2cfg doesn't keep the junk past the end of the null terminator, replacing it with \xff, so reading and writing the file without changing anything could alter the file contents (and thus the checksum).

Is it possible I have a newer, unsupported firmware? I'm on hardware version 3.12.1 and software version 9.12.8006. Or is the EVW321B not supported at all?

Your issue is likely caused by a bad settings group specification in nonvoldef.cc, which corrupts the file, causing it to be rejected by the device. Please send me your GatewaySettings.bin file, and I'll see what I can do!

jclehner commented 4 years ago

I've updated the code to keep the junk at the end of strings. Can you verify that the device now accepts a modified GatewaySettings.bin file?

Jurrie commented 4 years ago

Indeed the checksum now stays the same if I change a setting to the same value. Unfortunately, my modem will still not accept the changed GatewaySettings.bin.

When I diff the hexdumps of my original GatewaySettings.bin and the modified-to-same-value GatewaySettings.bin, I see that the files are completely different. Output of bcm2cfg info is the same. Is this to be expected?

jclehner commented 4 years ago

Ah, it sounded a lot like bad padding, and indeed the profile definition used ANSI X9.23 padding, whereas the file you sent me, and the sample that I have from an EVW32C both use PKCS #7. I've reverted the commit that keeps a string's junk for now. Please try if the device now accepts a file, where you set an option to its original value (like in the rg.syslog_email example).

Output of bcm2cfg info is the same. Is this to be expected?

bcm2cfg info doesn't tell you everything, since it doesn't print the data blobs whose meaning is unknown at this point (those having an empty name in nonvoldef.cc). Using bcm2cfg -v info will print these too.

Jurrie commented 4 years ago

The device now did accept a GatewaySettings.bin. Even better: it also accepts one with settings modified to different values. So I guess this is fixed now!

On a side note: previously I was warned that both userif and firewall groups were unparsable. But now, I only get that warning for firewall. The userif group seems to be parsed now; I can see and update the settings just fine.

jclehner commented 4 years ago

On a side note: previously I was warned that both userif and firewall groups were unparsable. But now, I only get that warning for firewall. The userif group seems to be parsed now; I can see and update the settings just fine.

I've modified the group definition in one of the latest commits!