Beispiel #1
0
    def _parse_address(self, data, mode):
        if mode == MacHeader.AddressMode.SHORT:
            return MacAddress(data.read(2), MacAddress.SHORT, big_endian=False)

        if mode == MacHeader.AddressMode.EXTENDED:
            return MacAddress(data.read(8), MacAddress.LONG, big_endian=False)

        else:
            return None
Beispiel #2
0
    def test_should_decrypt_data_frame(self):

        mac802154.DeviceDescriptors.add(0x2001, MacAddress(bytearray(
            [0x16, 0x6e, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x07]), MacAddressType.LONG))

        frame = mac802154.MacFrame()
        frame.parse(io.BytesIO(bytearray([0x69, 0x98, 0x68,  # FC, seq
                                          0xce, 0xfa,       # Pan Id
                                          0x00, 0x20,       # Dst addr
                                          0x01, 0x20,       # Src addr
                                          0x0d, 0x00, 0x00, 0x00, 0x00, 0x01,             # Aux Security Header
                                          0xb5, 0x5a, 0x0d, 0x8e, 0x18, 0x5c, 0xb1, 0x06,  # Payload
                                          0xc4, 0x6f, 0x7d, 0x6b, 0xb5, 0x4a, 0x87, 0x14,
                                          0xae, 0xdd, 0x8e, 0xb7, 0x37, 0x62, 0x27, 0x48,
                                          0xc9, 0x53, 0x0c, 0x44, 0x31, 0x59, 0x8b, 0xa2,
                                          0x83, 0x59, 0xa1, 0x43,  # MIC (valid)
                                          0x74, 0xe0, 0x2a, 0xf6,
                                          0x99, 0xfc])))           # FCS (valid)

        self.assertEqual(
            mac802154.MacHeader.FrameType.DATA,
            frame.header.frame_type)
        self.assertEqual(False, frame.header.frame_pending)
        self.assertEqual(True, frame.header.ack_request)
        self.assertEqual(1, frame.header.frame_version)
        self.assertEqual(0x68, frame.header.seq)
        self.assertEqual(bytearray([0x99, 0xfc]), frame.header.fcs)
        self.assertEqual(0xface, frame.header.dest_pan_id)
        self.assertEqual(0x2000, frame.header.dest_address.rloc)
        self.assertEqual(0xface, frame.header.src_pan_id)
        self.assertEqual(0x2001, frame.header.src_address.rloc)

        self.assertEqual(0, frame.header.aux_sec_header.frame_counter)
        self.assertEqual(5, frame.header.aux_sec_header.security_level)

        self.assertEqual(bytes(bytearray([0x7c, 0x77, 0x80, 0xf0,
                                          0x4d, 0x4d, 0x4d, 0x4d,
                                          0xe0, 0x04, 0x44, 0x02,
                                          0x44, 0x66, 0x13, 0x5f,
                                          0x22, 0x80, 0xb1, 0x61,
                                          0x02, 0x61, 0x73, 0x11,
                                          0x2a, 0xff, 0x01, 0x08,
                                          0x16, 0x6e, 0x0a, 0x00,
                                          0x00, 0x00, 0x00, 0x07])),
                         frame.payload.data)