[tests] fix key_id_mode handling and add exception handle (#4927)

This commit fixes key_id_mode handling and added exception handling
when key_id_mode is 0.

According to IEEE Std 802.15.4-2015, when Key Id Mode is 0x00:

    Key is determined implicitly from the originator and recipient(s)
    of the frame, as indicated in the frame header.

Our test scripts cannot handle such packets. If we leave key_id_mode =
0 case unhandled, we would get some exceptions that may cause
developers to think that something is wrong. However dropping packets
in this case is a normal behavior.
This commit is contained in:
Li Cao
2020-05-07 21:33:30 -07:00
committed by GitHub
parent 60aa241594
commit 417093e247
3 changed files with 49 additions and 22 deletions
+12 -1
View File
@@ -42,6 +42,15 @@ from net_crypto import (
)
class KeyIdMode0Exception(Exception):
"""
Raised when key id mode of packet is 0.
Such packet wouldn't be handled in test scripts,
but it's not abnormal behavior.
"""
pass
class DeviceDescriptors:
"""Class representing 802.15.4 Device Descriptors."""
@@ -377,11 +386,13 @@ class MacFrame:
key_id_mode = (security_control & 0x18) >> 3
if key_id_mode == 0:
key_id = data.read(9)
raise KeyIdMode0Exception
elif key_id_mode == 1:
key_id = data.read(1)
elif key_id_mode == 2:
key_id = data.read(5)
elif key_id_mode == 3:
key_id = data.read(9)
else:
pass