10_ZWave.pm: check CRC16 (Forum #43765)

git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@9892 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig
2015-11-14 19:06:16 +00:00
parent 45abfae646
commit ab64dba511

View File

@@ -405,7 +405,7 @@ my %zwave_quietCmds = (
sendNonce=>1, sendNonce=>1,
secEncap=>1, secEncap=>1,
secNonce=>1 secNonce=>1
); );
my %zwave_cmdArgs = ( my %zwave_cmdArgs = (
@@ -529,7 +529,7 @@ ZWave_Define($$)
$proposed = $p if($defs{$p}{homeId} && $defs{$p}{homeId} eq $homeId); $proposed = $p if($defs{$p}{homeId} && $defs{$p}{homeId} eq $homeId);
} }
} }
AssignIoPort($hash, $proposed); AssignIoPort($hash, $proposed);
if(@a) { # Autocreate: set the classes, execute the init calls if(@a) { # Autocreate: set the classes, execute the init calls
ZWave_SetClasses($homeId, $id, undef, $a[0]); ZWave_SetClasses($homeId, $id, undef, $a[0]);
@@ -736,7 +736,7 @@ ZWave_Cmd($$@)
my $data; my $data;
if($cmd eq "neighborUpdate" || if($cmd eq "neighborUpdate" ||
$cmd eq "neighborList") { $cmd eq "neighborList") {
$data = $cmdFmt; $data = $cmdFmt;
@@ -1858,20 +1858,20 @@ ZWave_plusInfoParse($$$$$)
} }
my %zwave_sensorBinaryTypeV2 = ( my %zwave_sensorBinaryTypeV2 = (
"00"=>"unknown", "00"=>"unknown",
"01"=>"generalPurpose", "01"=>"generalPurpose",
"02"=>"smoke", "02"=>"smoke",
"03"=>"CO", "03"=>"CO",
"04"=>"CO2", "04"=>"CO2",
"05"=>"heat", "05"=>"heat",
"06"=>"water", "06"=>"water",
"07"=>"freeze", "07"=>"freeze",
"08"=>"tamper", "08"=>"tamper",
"09"=>"aux", "09"=>"aux",
"0a"=>"doorWindow", "0a"=>"doorWindow",
"0b"=>"tilt", "0b"=>"tilt",
"0c"=>"motion", "0c"=>"motion",
"0d"=>"glassBreak" "0d"=>"glassBreak"
); );
sub sub
@@ -1896,6 +1896,34 @@ ZWave_assocGroup($$$$)
return sprintf("assocGroup_%d:Max %d Nodes %s", hex($gId),hex($max), $nodes); return sprintf("assocGroup_%d:Max %d Nodes %s", hex($gId),hex($max), $nodes);
} }
sub
ZWave_CRC16($)
{
my ($msg) = @_;
my $buf = pack 'H*', $msg;
my $len = length($buf);
my $poly = 0x1021; #CRC-CCITT (CRC-16) x16 + x12 + x5 + 1
my $crc16 = 0x1D0F; #Startvalue
for(my $i=0; $i<$len; $i++) {
my $byte = ord(substr($buf, $i, 1));
$byte = $byte * 0x100; # expand to 16 Bit
for(0..7) {
if(($byte & 0x8000) ^ ($crc16 & 0x8000)) { # if Hi-bits are different
$crc16 <<= 1;
$crc16 ^= $poly;
} else {
$crc16 <<= 1;
}
$crc16 &= 0xFFFF;
$byte <<= 1;
$byte &= 0xFFFF;
}
}
return sprintf "%x", $crc16;
}
############################################## ##############################################
# SECURITY (start) # SECURITY (start)
############################################## ##############################################
@@ -2619,7 +2647,7 @@ ZWave_addToSendStack($$)
if(ZWave_isWakeUp($hash)) { if(ZWave_isWakeUp($hash)) {
# SECURITY XXX and neighborList # SECURITY XXX and neighborList
if ($cmd =~ m/^......988[01].*/ || $cmd =~ m/^80..0101$/) { if ($cmd =~ m/^......988[01].*/ || $cmd =~ m/^80..0101$/) {
Log3 $hash->{NAME}, 5, "$hash->{NAME}: Sendstack bypassed for $cmd"; Log3 $hash->{NAME}, 5, "$hash->{NAME}: Sendstack bypassed for $cmd";
} else { } else {
return "Scheduled for sending after WAKEUP" if(!$hash->{wakeupAlive}); return "Scheduled for sending after WAKEUP" if(!$hash->{wakeupAlive});
@@ -2875,9 +2903,16 @@ ZWave_Parse($$@)
$arg = sprintf("%s%02x%s", $1, hex($2) & 0x7f, $3); $arg = sprintf("%s%02x%s", $1, hex($2) & 0x7f, $3);
} }
if($arg =~ /^..5601(.*)..../) { # CRC_16_ENCAP: Unwrap encapsulated command if($arg =~ /^..5601(.*)(....)/) { # CRC_16_ENCAP: Unwrap encapsulated command
#Log3 $ioName, 4, "CRC FIX, MSG: ($1)"; # see Forum #23494 #Log3 $ioName, 4, "CRC FIX, MSG: ($1)"; # see Forum #23494
$arg = sprintf("%02x$1", length($1)/2); my $crc16 = ZWave_CRC16("5601".$1);
if ($2 eq $crc16) {
$arg = sprintf("%02x$1", length($1)/2);
} else {
Log3 $ioName, 4, "$ioName CRC_16 checksum mismatch, received $2," .
" calculated $crc16";
return "";
}
} }
my ($baseHash, $baseId, $ep) = ("",$id,""); my ($baseHash, $baseId, $ep) = ("",$id,"");
@@ -3159,11 +3194,11 @@ s2Hex($)
<br><br><b>Class BASIC_WINDOW_COVERING</b> <br><br><b>Class BASIC_WINDOW_COVERING</b>
<li>coveringClose<br> <li>coveringClose<br>
Starts closing the window cover. Moving stops if blinds are fully closed or Starts closing the window cover. Moving stops if blinds are fully closed or
a coveringStop command was issued. a coveringStop command was issued.
</li> </li>
<li>coveringOpen<br> <li>coveringOpen<br>
Starts opening the window cover. Moving stops if blinds are fully open or Starts opening the window cover. Moving stops if blinds are fully open or
a coveringStop command was issued. a coveringStop command was issued.
</li> </li>
<li>coveringStop<br> <li>coveringStop<br>
Stop moving the window cover. Blinds are partially open (closed). Stop moving the window cover. Blinds are partially open (closed).
@@ -3194,7 +3229,7 @@ s2Hex($)
set &lt;name&gt; wcrgb 0 255 0 0 0 (setting full cold white)<br> set &lt;name&gt; wcrgb 0 255 0 0 0 (setting full cold white)<br>
</ul> </ul>
</li> </li>
<br><br><b>Class CONFIGURATION</b> <br><br><b>Class CONFIGURATION</b>
<li>configByte cfgAddress 8bitValue<br> <li>configByte cfgAddress 8bitValue<br>
configWord cfgAddress 16bitValue<br> configWord cfgAddress 16bitValue<br>
@@ -3233,7 +3268,7 @@ s2Hex($)
value is supported by the device.<br> value is supported by the device.<br>
The command will reset ALL accumulated values, it is not possible to The command will reset ALL accumulated values, it is not possible to
choose a single value.</li> choose a single value.</li>
<br><br><b>Class MULTI_CHANNEL_ASSOCIATION</b> <br><br><b>Class MULTI_CHANNEL_ASSOCIATION</b>
<li>mcaAdd groupId node1 node2 ... 0 node1 endPoint1 node2 endPoint2 ...<br> <li>mcaAdd groupId node1 node2 ... 0 node1 endPoint1 node2 endPoint2 ...<br>
Add a list of node or node:endpoint associations. The latter can be used to Add a list of node or node:endpoint associations. The latter can be used to
@@ -3265,7 +3300,7 @@ s2Hex($)
level 0=normal, level 1=-1dBm, .., level 9=-9dBm.</li> level 0=normal, level 1=-1dBm, .., level 9=-9dBm.</li>
<li>powerlevelTest nodeId level frames <br> <li>powerlevelTest nodeId level frames <br>
send number of frames [1-65535] to nodeId with level [0-9].</li> send number of frames [1-65535] to nodeId with level [0-9].</li>
<br><br><b>Class PROTECTION</b> <br><br><b>Class PROTECTION</b>
<li>protectionOff<br> <li>protectionOff<br>
device is unprotected</li> device is unprotected</li>
@@ -3279,19 +3314,19 @@ s2Hex($)
<br><br><b>Class SCENE_ACTIVATION</b> <br><br><b>Class SCENE_ACTIVATION</b>
<li>sceneConfig<br> <li>sceneConfig<br>
activate settings for a specific scene. activate settings for a specific scene.
Parameters are: sceneId, dimmingDuration (00..ff) Parameters are: sceneId, dimmingDuration (00..ff)
</li> </li>
<br><br><b>Class SCENE_ACTUATOR_CONF</b> <br><br><b>Class SCENE_ACTUATOR_CONF</b>
<li>sceneConfig<br> <li>sceneConfig<br>
set configuration for a specific scene. set configuration for a specific scene.
Parameters are: sceneId, dimmingDuration, finalValue (00..ff) Parameters are: sceneId, dimmingDuration, finalValue (00..ff)
</li> </li>
<br><br><b>Class SCENE_CONTROLLER_CONF</b> <br><br><b>Class SCENE_CONTROLLER_CONF</b>
<li>groupConfig<br> <li>groupConfig<br>
set configuration for a specific scene. set configuration for a specific scene.
Parameters are: groupId, sceneId, dimmingDuration. Parameters are: groupId, sceneId, dimmingDuration.
</li> </li>
<br><br><b>Class SECURITY</b> <br><br><b>Class SECURITY</b>
@@ -3475,7 +3510,7 @@ s2Hex($)
return the indicator status of the node, as indState:on, indState:off or return the indicator status of the node, as indState:on, indState:off or
indState:dim value. indState:dim value.
</li> </li>
<br><br><b>Class MANUFACTURER_PROPRIETARY</b> <br><br><b>Class MANUFACTURER_PROPRIETARY</b>
<li>position<br> <li>position<br>
Fibaro FGRM-222 only: return the blinds position and slat angle. Fibaro FGRM-222 only: return the blinds position and slat angle.
@@ -3536,7 +3571,7 @@ s2Hex($)
Get the name from the EEPROM. Note: only ASCII is supported.</li> Get the name from the EEPROM. Note: only ASCII is supported.</li>
<li>location<br> <li>location<br>
Get the location from the EEPROM. Note: only ASCII is supported.</li> Get the location from the EEPROM. Note: only ASCII is supported.</li>
<br><br><b>Class POWERLEVEL</b> <br><br><b>Class POWERLEVEL</b>
<li>powerlevel<br> <li>powerlevel<br>
Get the current powerlevel and remaining time in this level.</li> Get the current powerlevel and remaining time in this level.</li>
@@ -3581,7 +3616,7 @@ s2Hex($)
<li>alarm alarmType<br> <li>alarm alarmType<br>
return the nodes alarm status of the requested alarmType. 00 = GENERIC, return the nodes alarm status of the requested alarmType. 00 = GENERIC,
01 = SMOKE, 02 = CO, 03 = CO2, 04 = HEAT, 05 = WATER, ff = returns the 01 = SMOKE, 02 = CO, 03 = CO2, 04 = HEAT, 05 = WATER, ff = returns the
nodes first supported alarm type. nodes first supported alarm type.
</li> </li>
<br><br><b>Class SENSOR_BINARY</b> <br><br><b>Class SENSOR_BINARY</b>
@@ -3608,7 +3643,7 @@ s2Hex($)
<li>swmStatus<br> <li>swmStatus<br>
return the status of the node, as state:on, state:off or state:dim value. return the status of the node, as state:on, state:off or state:dim value.
</li> </li>
<br><br><b>Class THERMOSTAT_MODE</b> <br><br><b>Class THERMOSTAT_MODE</b>
<li>thermostatMode<br> <li>thermostatMode<br>
request the mode request the mode
@@ -3648,7 +3683,7 @@ s2Hex($)
<li>zwavePlusInfo<br> <li>zwavePlusInfo<br>
request the zwavePlusInfo request the zwavePlusInfo
</li> </li>
</ul> </ul>
<br> <br>
@@ -3740,7 +3775,7 @@ s2Hex($)
<li>config_X:Y<br> <li>config_X:Y<br>
Note: if the model is set (see MANUFACTURER_SPECIFIC get), then more Note: if the model is set (see MANUFACTURER_SPECIFIC get), then more
specific config messages are available.</li> specific config messages are available.</li>
<br><br><b>Class DEVICE_RESET_LOCALLY</b> <br><br><b>Class DEVICE_RESET_LOCALLY</b>
<li>deviceResetLocally:yes<br></li> <li>deviceResetLocally:yes<br></li>
@@ -3766,7 +3801,7 @@ s2Hex($)
(VenetianBlindMode)</li> (VenetianBlindMode)</li>
<li>position:[%]<br> <li>position:[%]<br>
(RollerBlindMode)</li> (RollerBlindMode)</li>
<br><br><b>Class MANUFACTURER_SPECIFIC</b> <br><br><b>Class MANUFACTURER_SPECIFIC</b>
<li>modelId:hexValue hexValue hexValue</li> <li>modelId:hexValue hexValue hexValue</li>
<li>model:manufacturerName productName</li> <li>model:manufacturerName productName</li>
@@ -3795,16 +3830,16 @@ s2Hex($)
NOTE: "current 0 remain 0" means normal mode without timeout</li> NOTE: "current 0 remain 0" means normal mode without timeout</li>
<li>powerlvlTest:node x status y frameAck z<br> <li>powerlvlTest:node x status y frameAck z<br>
NOTE: status 0=failed, 1=success (at least one ACK), 2=in progress</li> NOTE: status 0=failed, 1=success (at least one ACK), 2=in progress</li>
<br><br><b>Class PROTECTION</b> <br><br><b>Class PROTECTION</b>
<li>protection:[on|off|seq]</li> <li>protection:[on|off|seq]</li>
<br><br><b>Class SCENE_ACTIVATION</b> <br><br><b>Class SCENE_ACTIVATION</b>
<li>scene_Id:level finalValue</li> <li>scene_Id:level finalValue</li>
<br><br><b>Class SCENE_ACTUATOR_CONF</b> <br><br><b>Class SCENE_ACTUATOR_CONF</b>
<li>scene_Id:level dimmingDuration finalValue</li> <li>scene_Id:level dimmingDuration finalValue</li>
<br><br><b>Class SCENE_CONTROLLER_CONF</b> <br><br><b>Class SCENE_CONTROLLER_CONF</b>
<li>group_Id:scene dimmingDuration</li> <li>group_Id:scene dimmingDuration</li>
@@ -3814,7 +3849,7 @@ s2Hex($)
intended to generate event</li> intended to generate event</li>
<br><br><b>Class SENSOR_ALARM</b> <br><br><b>Class SENSOR_ALARM</b>
<li>alarm_type_X:level Y node $nodeID seconds $seconds</li> <li>alarm_type_X:level Y node $nodeID seconds $seconds</li>
<br><br><b>Class SENSOR_BINARY</b> <br><br><b>Class SENSOR_BINARY</b>
<li>SENSORY_BINARY V1:</li> <li>SENSORY_BINARY V1:</li>
@@ -3906,7 +3941,7 @@ s2Hex($)
<li>state:swmBeginUp</li> <li>state:swmBeginUp</li>
<li>state:swmBeginDown</li> <li>state:swmBeginDown</li>
<li>state:swmEnd</li> <li>state:swmEnd</li>
<br><br><b>Class THERMOSTAT_MODE</b> <br><br><b>Class THERMOSTAT_MODE</b>
<li>off</li> <li>off</li>
<li>cooling</li> <li>cooling</li>
@@ -3935,7 +3970,7 @@ s2Hex($)
<li>wakeup:notification</li> <li>wakeup:notification</li>
<li>wakeupReport:interval:X target:Y</li> <li>wakeupReport:interval:X target:Y</li>
<li>wakeupIntervalCapabilitiesReport:min W max X default Y step Z</li> <li>wakeupIntervalCapabilitiesReport:min W max X default Y step Z</li>
<br><br><b>Class ZWAVEPLUS_INFO</b> <br><br><b>Class ZWAVEPLUS_INFO</b>
<li>zwavePlusInfo:version: V role: W node: X installerIcon: Y userIcon: Z</li> <li>zwavePlusInfo:version: V role: W node: X installerIcon: Y userIcon: Z</li>