mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-20 13:26:02 +00:00
Hacker Attack indication, bug fixing with action detector
git-svn-id: https://svn.fhem.de/fhem/trunk@4520 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
ba67d0fa0a
commit
96a6bcc1d5
@ -32,7 +32,7 @@ my $culHmChanSets =\%HMConfig::culHmChanSets;
|
|||||||
my $culHmFunctSets =\%HMConfig::culHmFunctSets;
|
my $culHmFunctSets =\%HMConfig::culHmFunctSets;
|
||||||
my $culHmBits =\%HMConfig::culHmBits;
|
my $culHmBits =\%HMConfig::culHmBits;
|
||||||
my $culHmCmdFlags =\@HMConfig::culHmCmdFlags;
|
my $culHmCmdFlags =\@HMConfig::culHmCmdFlags;
|
||||||
my $K_actDetID =\$HMConfig::K_actDetID;
|
my $K_actDetID ="000000";
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
@ -550,22 +550,20 @@ sub CUL_HM_Parse($$) {##############################
|
|||||||
my $ioName = $iohash->{NAME};
|
my $ioName = $iohash->{NAME};
|
||||||
my ($msg,$msgStat,$myRSSI,$msgIO) = split(":",$msgIn,4);
|
my ($msg,$msgStat,$myRSSI,$msgIO) = split(":",$msgIn,4);
|
||||||
# Msg format: Allnnffttssssssddddddpp...
|
# Msg format: Allnnffttssssssddddddpp...
|
||||||
$msg =~ m/A(..)(..)(..)(..)(......)(......)(.*)/;
|
my (undef,$len,$mNo,$mFlg,$mTp,$src,$dst,$p) = unpack 'A1A2A2A2A2A6A6A*',$msg;
|
||||||
my ($len,$mNo,$mFlg,$mTp,$src,$dst,$p) = ($1,$2,$3,$4,$5,$6,$7);
|
|
||||||
$p = "" if(!defined($p));
|
$p = "" if(!defined($p));
|
||||||
my @mI = unpack '(A2)*',$p; # split message info to bytes
|
my @mI = unpack '(A2)*',$p; # split message info to bytes
|
||||||
|
return "" if($msgStat && $msgStat eq 'NACK');# lowlevel error
|
||||||
return "" if( ($msgStat && $msgStat eq 'NACK')# lowlevel error
|
|
||||||
||($src eq $id)); # mirrored messages
|
|
||||||
# $shash will be replaced for multichannel commands
|
# $shash will be replaced for multichannel commands
|
||||||
my $shash = $modules{CUL_HM}{defptr}{$src};
|
my $shash = CUL_HM_id2Hash($src);
|
||||||
my $dhash = $modules{CUL_HM}{defptr}{$dst};
|
my $dhash = CUL_HM_id2Hash($dst);
|
||||||
CUL_HM_statCnt($ioName,"r");
|
CUL_HM_statCnt($ioName,"r");
|
||||||
|
my $dname = ($dst eq "000000") ? "broadcast" :
|
||||||
|
($dhash ? $dhash->{NAME} :
|
||||||
|
($dst eq $id ? $ioName :
|
||||||
|
$dst));
|
||||||
|
|
||||||
$respRemoved = 0; #set to 'no response in this message' at start
|
if(!$shash && $mTp eq "00") { # generate device
|
||||||
if(!$shash) { # Unknown source
|
|
||||||
# Generate an UNKNOWN event for pairing requests, ignore everything else
|
|
||||||
if($mTp eq "00") {
|
|
||||||
my $md = substr($p, 2, 4);
|
my $md = substr($p, 2, 4);
|
||||||
$md = $culHmModel->{$md}{name} ?
|
$md = $culHmModel->{$md}{name} ?
|
||||||
$culHmModel->{$md}{name} :
|
$culHmModel->{$md}{name} :
|
||||||
@ -575,8 +573,24 @@ sub CUL_HM_Parse($$) {##############################
|
|||||||
Log3 undef, 3, "CUL_HM Unknown device $sname, please define it";
|
Log3 undef, 3, "CUL_HM Unknown device $sname, please define it";
|
||||||
return "UNDEFINED $sname CUL_HM $src $msg";
|
return "UNDEFINED $sname CUL_HM $src $msg";
|
||||||
}
|
}
|
||||||
return "";
|
#################### attack alarm detection#####################
|
||||||
|
if ( $dhash
|
||||||
|
&& !CUL_HM_getAttrInt($dname,"ignore")
|
||||||
|
&& ($mTp eq '01' || $mTp eq '11')){
|
||||||
|
my $ioId = AttrVal($dhash->{IODev}{NAME},"hmId","-");
|
||||||
|
CUL_HM_eventP($dhash,"ErrIoId_$src")if($ioId ne $src);
|
||||||
|
Log 1,"General ErrIoAttack ".$dhash->{NAME}.":$msg"
|
||||||
|
."\n ".$dhash->{helper}{cSnd}
|
||||||
|
if(defined $dhash->{helper}{cSnd} && $dhash->{helper}{cSnd} ne substr($msg,7));
|
||||||
|
CUL_HM_eventP($dhash,"ErrIoAttack")
|
||||||
|
if(defined $dhash->{helper}{cSnd} && $dhash->{helper}{cSnd} ne substr($msg,7));
|
||||||
}
|
}
|
||||||
|
###########
|
||||||
|
|
||||||
|
# return "" if($src eq $id);# mirrored messages - covered by !$shash
|
||||||
|
return "" if(!$shash); # Unknown source
|
||||||
|
|
||||||
|
$respRemoved = 0; #set to 'no response in this message' at start
|
||||||
my @event; #events to be posted for main entity
|
my @event; #events to be posted for main entity
|
||||||
my @entities; #additional entities with events to be notifies
|
my @entities; #additional entities with events to be notifies
|
||||||
|
|
||||||
@ -592,10 +606,6 @@ sub CUL_HM_Parse($$) {##############################
|
|||||||
}
|
}
|
||||||
CUL_HM_eventP($shash,"Evt_$msgStat")if ($msgStat);#log io-events
|
CUL_HM_eventP($shash,"Evt_$msgStat")if ($msgStat);#log io-events
|
||||||
CUL_HM_eventP($shash,"Rcv");
|
CUL_HM_eventP($shash,"Rcv");
|
||||||
my $dname = ($dst eq "000000") ? "broadcast" :
|
|
||||||
($dhash ? $dhash->{NAME} :
|
|
||||||
($dst eq $id ? $ioName :
|
|
||||||
$dst));
|
|
||||||
my $target = " (to $dname)";
|
my $target = " (to $dname)";
|
||||||
my $st = AttrVal($name, "subType", "");
|
my $st = AttrVal($name, "subType", "");
|
||||||
my $md = AttrVal($name, "model" , "");
|
my $md = AttrVal($name, "model" , "");
|
||||||
@ -3718,6 +3728,7 @@ sub CUL_HM_responseSetup($$) {#store all we need to handle the response
|
|||||||
else{
|
else{
|
||||||
CUL_HM_respWaitSu ($hash,"cmd:=$cmd","mNo:=$mNo","reSent:=$rss");
|
CUL_HM_respWaitSu ($hash,"cmd:=$cmd","mNo:=$mNo","reSent:=$rss");
|
||||||
}
|
}
|
||||||
|
$hash->{helper}{cSnd} = substr($cmd,8);
|
||||||
}
|
}
|
||||||
elsif($mTp eq '11' && $chn =~ m/^(02|81)$/){#!!! chn is subtype!!!
|
elsif($mTp eq '11' && $chn =~ m/^(02|81)$/){#!!! chn is subtype!!!
|
||||||
# CUL_HM_qStateUpdatIfEnab($dst.$subType);# subtype actually is channel
|
# CUL_HM_qStateUpdatIfEnab($dst.$subType);# subtype actually is channel
|
||||||
@ -3727,6 +3738,7 @@ sub CUL_HM_responseSetup($$) {#store all we need to handle the response
|
|||||||
$to = "timedOn:=1";
|
$to = "timedOn:=1";
|
||||||
}
|
}
|
||||||
CUL_HM_respWaitSu ($hash,"cmd:=$cmd","mNo:=$mNo","reSent:=$rss",$to);
|
CUL_HM_respWaitSu ($hash,"cmd:=$cmd","mNo:=$mNo","reSent:=$rss",$to);
|
||||||
|
$hash->{helper}{cSnd} = substr($cmd,8);
|
||||||
}
|
}
|
||||||
elsif($mTp eq '12' && $mFlg & 0x10){#wakeup with burst
|
elsif($mTp eq '12' && $mFlg & 0x10){#wakeup with burst
|
||||||
# response setup - do not repeat, set counter to 250
|
# response setup - do not repeat, set counter to 250
|
||||||
@ -4305,7 +4317,8 @@ sub CUL_HM_id2Name($) { #in: name or HMid out: name
|
|||||||
sub CUL_HM_id2Hash($) {#in: id, out:hash
|
sub CUL_HM_id2Hash($) {#in: id, out:hash
|
||||||
my ($id) = @_;
|
my ($id) = @_;
|
||||||
return $modules{CUL_HM}{defptr}{$id} if ($modules{CUL_HM}{defptr}{$id});
|
return $modules{CUL_HM}{defptr}{$id} if ($modules{CUL_HM}{defptr}{$id});
|
||||||
return $modules{CUL_HM}{defptr}{substr($id,0,6)}; # could be chn 01 of dev
|
$id = substr($id,0,6);
|
||||||
|
return $modules{CUL_HM}{defptr}{$id}?($modules{CUL_HM}{defptr}{$id}):undef;
|
||||||
}
|
}
|
||||||
sub CUL_HM_getDeviceHash($) {#in: hash out: devicehash
|
sub CUL_HM_getDeviceHash($) {#in: hash out: devicehash
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
@ -205,7 +205,8 @@ sub HMinfo_peerCheck(@) { #####################################################
|
|||||||
}
|
}
|
||||||
sub HMinfo_burstCheck(@) { ####################################################
|
sub HMinfo_burstCheck(@) { ####################################################
|
||||||
my @entities = @_;
|
my @entities = @_;
|
||||||
my @peerIDsNeed;
|
my @needBurstMiss;
|
||||||
|
my @needBurstFail;
|
||||||
my @peerIDsCond;
|
my @peerIDsCond;
|
||||||
foreach my $eName (@entities){
|
foreach my $eName (@entities){
|
||||||
next if (!$defs{$eName}{helper}{role}{chn});#device has no channels
|
next if (!$defs{$eName}{helper}{role}{chn});#device has no channels
|
||||||
@ -223,7 +224,10 @@ sub HMinfo_burstCheck(@) { ####################################################
|
|||||||
my $prxt = CUL_HM_getRxType($defs{$pn});
|
my $prxt = CUL_HM_getRxType($defs{$pn});
|
||||||
|
|
||||||
next if (!($prxt & 0x82)); # not a burst peer
|
next if (!($prxt & 0x82)); # not a burst peer
|
||||||
push @peerIDsNeed," $eName for peer $pn" if (ReadingsVal($eName,"R-$pn-peerNeedsBurst","") !~ m /on/);
|
my $pnb = ReadingsVal($eName,"R-$pn-peerNeedsBurst",undef);
|
||||||
|
if (!$pnb) {push @needBurstMiss, $eName;}
|
||||||
|
elsif($pnb !~ m /on/){push @needBurstFail, $eName;}
|
||||||
|
|
||||||
if ($prxt & 0x80){# conditional burst - is it on?
|
if ($prxt & 0x80){# conditional burst - is it on?
|
||||||
my $pDevN = CUL_HM_getDeviceName($pn);
|
my $pDevN = CUL_HM_getDeviceName($pn);
|
||||||
push @peerIDsCond," $pDevN for remote $eName" if (ReadingsVal($pDevN,"R-burstRx","") !~ m /on/);
|
push @peerIDsCond," $pDevN for remote $eName" if (ReadingsVal($pDevN,"R-burstRx","") !~ m /on/);
|
||||||
@ -231,7 +235,8 @@ sub HMinfo_burstCheck(@) { ####################################################
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
my $ret = "";
|
my $ret = "";
|
||||||
$ret .="\n\n peerNeedsBurst not set" ."\n ".(join "\n ",sort @peerIDsNeed) if(@peerIDsNeed);
|
$ret .="\n\n peerNeedsBurst cannot be determined" ."\n ".(join "\n ",sort @needBurstMiss) if(@needBurstMiss);
|
||||||
|
$ret .="\n\n peerNeedsBurst not set" ."\n ".(join "\n ",sort @needBurstFail) if(@needBurstFail);
|
||||||
$ret .="\n\n conditionalBurst not set" ."\n ".(join "\n ",sort @peerIDsCond) if(@peerIDsCond);
|
$ret .="\n\n conditionalBurst not set" ."\n ".(join "\n ",sort @peerIDsCond) if(@peerIDsCond);
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
@ -778,10 +783,13 @@ sub HMinfo_status($){##########################################################
|
|||||||
}
|
}
|
||||||
#--- used for IO, protocol and communication (e.g. rssi)
|
#--- used for IO, protocol and communication (e.g. rssi)
|
||||||
my @IOdev;
|
my @IOdev;
|
||||||
|
|
||||||
|
my %protC = (ErrIoId_ =>0,ErrIoAttack =>0);
|
||||||
my %protE = (NACK =>0,IOerr =>0,ResndFail =>0,CmdDel =>0);
|
my %protE = (NACK =>0,IOerr =>0,ResndFail =>0,CmdDel =>0);
|
||||||
my %protW = (Resnd =>0,CmdPend =>0);
|
my %protW = (Resnd =>0,CmdPend =>0);
|
||||||
my @protNamesE; # devices with current protocol events
|
my @protNamesC; # devices with current protocol Critical
|
||||||
my @protNamesW; # devices with current protocol events
|
my @protNamesE; # devices with current protocol Errors
|
||||||
|
my @protNamesW; # devices with current protocol Warnings
|
||||||
my @Anames; # devices with ActionDetector events
|
my @Anames; # devices with ActionDetector events
|
||||||
my %rssiMin;
|
my %rssiMin;
|
||||||
my %rssiMinCnt = ("99>"=>0,"80>"=>0,"60>"=>0,"59<"=>0);
|
my %rssiMinCnt = ("99>"=>0,"80>"=>0,"60>"=>0,"59<"=>0);
|
||||||
@ -811,7 +819,17 @@ sub HMinfo_status($){##########################################################
|
|||||||
$nbrD++;
|
$nbrD++;
|
||||||
push @IOdev,$ehash->{IODev}{NAME} if($ehash->{IODev} && $ehash->{IODev}{NAME});
|
push @IOdev,$ehash->{IODev}{NAME} if($ehash->{IODev} && $ehash->{IODev}{NAME});
|
||||||
push @Anames,$eName if ($attr{$eName}{actStatus} && $attr{$eName}{actStatus} ne "alive");
|
push @Anames,$eName if ($attr{$eName}{actStatus} && $attr{$eName}{actStatus} ne "alive");
|
||||||
foreach (grep {$ehash->{"prot".$_}} keys %protE){#protocol events reported
|
|
||||||
|
foreach (grep /ErrIoId_/, keys %{$ehash}){# detect addtional critical entries
|
||||||
|
my $k = $_;
|
||||||
|
$k =~ s/^prot//;
|
||||||
|
$protC{$k} = 0 if(!defined $protC{$_});
|
||||||
|
}
|
||||||
|
foreach (grep {$ehash->{"prot".$_}} keys %protC){#protocol critical alarms
|
||||||
|
$protC{$_}++;
|
||||||
|
push @protNamesC,$eName;
|
||||||
|
}
|
||||||
|
foreach (grep {$ehash->{"prot".$_}} keys %protE){#protocol errors
|
||||||
$protE{$_}++;
|
$protE{$_}++;
|
||||||
push @protNamesE,$eName;
|
push @protNamesE,$eName;
|
||||||
}
|
}
|
||||||
@ -861,16 +879,20 @@ sub HMinfo_status($){##########################################################
|
|||||||
# ------- what about protocol events ------
|
# ------- what about protocol events ------
|
||||||
# Current Events are Rcv,NACK,IOerr,Resend,ResendFail,Snd
|
# Current Events are Rcv,NACK,IOerr,Resend,ResendFail,Snd
|
||||||
# additional variables are protCmdDel,protCmdPend,protState,protLastRcv
|
# additional variables are protCmdDel,protCmdPend,protState,protLastRcv
|
||||||
my @tp;
|
my @tpc;
|
||||||
push @tp,"$_:$protE{$_}" foreach (grep {$protE{$_}} keys(%protE));
|
push @tpc,"$_:$protC{$_}" foreach (grep {$protC{$_}} keys(%protC));
|
||||||
push @updates,"ERR__protocol:".join",",@tp if(@tp);
|
if(@tpc){push @updates,"CRIT__protocol:".join",",@tpc;} else{delete $hash->{READINGS}{CRIT__protocol} };
|
||||||
|
my @tpe;
|
||||||
|
push @tpe,"$_:$protE{$_}" foreach (grep {$protE{$_}} keys(%protE));
|
||||||
|
if(@tpe){push @updates,"ERR__protocol:".join",",@tpe;} else{ delete $hash->{READINGS}{ERR__protocol} };
|
||||||
my @tpw;
|
my @tpw;
|
||||||
push @tpw,"$_:$protW{$_}" foreach (grep {$protW{$_}} keys(%protW));
|
push @tpw,"$_:$protW{$_}" foreach (grep {$protW{$_}} keys(%protW));
|
||||||
push @updates,"W__protocol:".join",",@tpw if(@tpw);
|
if(@tpw){push @updates,"W__protocol:".join",",@tpw ;} else{ delete $hash->{READINGS}{W__protocol} };
|
||||||
|
|
||||||
@protNamesE = grep !/^$/,HMinfo_noDup(@protNamesE);;
|
@protNamesC = grep !/^$/,HMinfo_noDup(@protNamesC);
|
||||||
|
$hash->{CRI__protoNames} = join",",@protNamesC if(@protNamesC);
|
||||||
|
@protNamesE = grep !/^$/,HMinfo_noDup(@protNamesE);
|
||||||
$hash->{ERR__protoNames} = join",",@protNamesE if(@protNamesE);
|
$hash->{ERR__protoNames} = join",",@protNamesE if(@protNamesE);
|
||||||
|
|
||||||
@protNamesW = grep !/^$/,HMinfo_noDup(@protNamesW);
|
@protNamesW = grep !/^$/,HMinfo_noDup(@protNamesW);
|
||||||
$hash->{W__protoNames} = join",",@protNamesW if(@protNamesW);
|
$hash->{W__protoNames} = join",",@protNamesW if(@protNamesW);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user