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

@@ -1858,20 +1858,20 @@ ZWave_plusInfoParse($$$$$)
}
my %zwave_sensorBinaryTypeV2 = (
"00"=>"unknown",
"01"=>"generalPurpose",
"02"=>"smoke",
"03"=>"CO",
"04"=>"CO2",
"05"=>"heat",
"06"=>"water",
"07"=>"freeze",
"08"=>"tamper",
"09"=>"aux",
"0a"=>"doorWindow",
"0b"=>"tilt",
"0c"=>"motion",
"0d"=>"glassBreak"
"00"=>"unknown",
"01"=>"generalPurpose",
"02"=>"smoke",
"03"=>"CO",
"04"=>"CO2",
"05"=>"heat",
"06"=>"water",
"07"=>"freeze",
"08"=>"tamper",
"09"=>"aux",
"0a"=>"doorWindow",
"0b"=>"tilt",
"0c"=>"motion",
"0d"=>"glassBreak"
);
sub
@@ -1896,6 +1896,34 @@ ZWave_assocGroup($$$$)
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)
##############################################
@@ -2875,9 +2903,16 @@ ZWave_Parse($$@)
$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
$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,"");
@@ -3279,19 +3314,19 @@ s2Hex($)
<br><br><b>Class SCENE_ACTIVATION</b>
<li>sceneConfig<br>
activate settings for a specific scene.
Parameters are: sceneId, dimmingDuration (00..ff)
Parameters are: sceneId, dimmingDuration (00..ff)
</li>
<br><br><b>Class SCENE_ACTUATOR_CONF</b>
<li>sceneConfig<br>
set configuration for a specific scene.
Parameters are: sceneId, dimmingDuration, finalValue (00..ff)
Parameters are: sceneId, dimmingDuration, finalValue (00..ff)
</li>
<br><br><b>Class SCENE_CONTROLLER_CONF</b>
<li>groupConfig<br>
set configuration for a specific scene.
Parameters are: groupId, sceneId, dimmingDuration.
Parameters are: groupId, sceneId, dimmingDuration.
</li>
<br><br><b>Class SECURITY</b>