class TestDot11ManagementReassociationResponseFrames(unittest.TestCase):

    def setUp(self):
        # 802.11 Management Frame 
        #
        self.rawframe="\x00\x00\x1c\x00\xef\x18\x00\x00\xc0\xbb\xbc\xae;\x00\x00\x00\x10\x02\x85\t\xa0\x00\xba\x9ca\x00\x00\x1e0\x08:\x01p\x1a\x04T\xe3\x86\x00\x18\xf8lvB\x00\x18\xf8lvB\xe0g\x11\x04\x00\x00\x04\xc0\x01\x08\x82\x84\x8b\x96$0Hl2\x04\x0c\x12\x18`\xdd\t\x00\x10\x18\x02\x02\xf0\x00\x00\x00\xb3\xff\n\\"
        self.radiotap_decoder = RadioTapDecoder()
        radiotap=self.radiotap_decoder.decode(self.rawframe)

        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")

        self.dot11=radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")

        type = self.dot11.get_type()
        self.assertEqual(type,Dot11Types.DOT11_TYPE_MANAGEMENT)
        
        subtype = self.dot11.get_subtype()
        self.assertEqual(subtype,Dot11Types.DOT11_SUBTYPE_MANAGEMENT_REASSOCIATION_RESPONSE)
        
        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(typesubtype, Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_REASSOCIATION_RESPONSE)
        
        self.management_base=self.dot11.child()
        self.assertEqual(str(self.management_base.__class__), "dot11.Dot11ManagementFrame")
        
        self.management_reassociation_response=self.management_base.child()
        self.assertEqual(str(self.management_reassociation_response.__class__), "dot11.Dot11ManagementReassociationResponse")
            
        
    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(self.management_reassociation_response.get_header_size(), 33)
        self.assertEqual(self.management_reassociation_response.get_tail_size(), 0)
        
    def test_02(self):
        'Test Duration field'
        
        self.assertEqual(self.management_base.get_duration(), 0x013a)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)
    
    def test_03(self):
        'Test Destination Address field'
        
        addr=self.management_base.get_destination_address()
        
        self.assertEqual(addr.tolist(), [0x70,0x1a,0x04,0x54,0xe3,0x86])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(self.management_base.get_destination_address().tolist(), [0x12,0x1a,0x04,0x54,0xe3,0x34])

    def test_04(self):
        'Test Source Address field'
        
        addr=self.management_base.get_source_address()
        
        self.assertEqual(addr.tolist(), [0x00,0x18,0xF8,0x6C,0x76,0x42])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(), [0x12,0x18,0xF8,0x6C,0x76,0x34])

    def test_05(self):
        'Test BSSID Address field'
        
        addr=self.management_base.get_bssid()
        
        self.assertEqual(addr.tolist(), [0x00,0x18,0xF8,0x6C,0x76,0x42])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(), [0x12,0x18,0xF8,0x6C,0x76,0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0x67e0)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1) # Es de 4 bit
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 1662)
        self.management_base.set_sequence_number(0xF234) # Es de 12 bit
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)
        
    def test_09(self):
        'Test Management Frame Data field'
        frame_body="\x11\x04\x00\x00\x04\xc0\x01\x08\x82\x84\x8b\x96$0Hl2\x04\x0c\x12\x18`\xdd\t\x00\x10\x18\x02\x02\xf0\x00\x00\x00"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management Reassociation Response Capabilities field'
        self.assertEqual(self.management_reassociation_response.get_capabilities(), 0x0411)
        self.management_reassociation_response.set_capabilities(0x4321) 
        self.assertEqual(self.management_reassociation_response.get_capabilities(), 0x4321)

    def test_11(self):
        'Test Management Reassociation Response Status Code field' 
        self.assertEqual(self.management_reassociation_response.get_status_code(), 0x0000)
        self.management_reassociation_response.set_status_code(0x4321)
        self.assertEqual(self.management_reassociation_response.get_status_code(), 0x4321)

    def test_12(self):
        'Test Management Reassociation Response Association ID field'
        self.assertEqual(self.management_reassociation_response.get_association_id(), 0xc004)
        self.management_reassociation_response.set_association_id(0x4321)
        self.assertEqual(self.management_reassociation_response.get_association_id(), 0x4321)

    def test_13(self):
        'Test Management Reassociation Response Supported_rates getter/setter methods'
        self.assertEqual(self.management_reassociation_response.get_supported_rates(), (0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c))
        self.assertEqual(self.management_reassociation_response.get_supported_rates(human_readable=True), (1.0, 2.0, 5.5, 11.0, 18.0, 24.0, 36.0, 54.0))
        
        self.management_reassociation_response.set_supported_rates((0x12, 0x98, 0x24, 0xb0, 0x48, 0x60))

        self.assertEqual(self.management_reassociation_response.get_supported_rates(), (0x12, 0x98, 0x24, 0xb0, 0x48, 0x60))
        self.assertEqual(self.management_reassociation_response.get_supported_rates(human_readable=True), (9.0, 12.0, 18.0, 24.0, 36.0, 48.0))
        self.assertEqual(self.management_reassociation_response.get_header_size(), 33-2)

    def test_14(self):
        'Test Management Vendor Specific getter/setter methods'
        self.assertEqual(self.management_reassociation_response.get_vendor_specific(), [("\x00\x10\x18","\x02\x02\xf0\x00\x00\x00")])

        self.management_reassociation_response.add_vendor_specific("\x00\x00\x40", "\x04\x04\x04\x04\x04\x04")

        self.assertEqual(self.management_reassociation_response.get_vendor_specific(), 
            [("\x00\x10\x18", "\x02\x02\xf0\x00\x00\x00"),
             ("\x00\x00\x40", "\x04\x04\x04\x04\x04\x04"),
            ])
        self.assertEqual(self.management_reassociation_response.get_header_size(), 33+11)
class TestDot11ManagementAuthenticationFrames(unittest.TestCase):
    def setUp(self):
        # 802.11 Management Frame
        #
        self.rawframe = "\x00\x00\x1c\x00\xef\x18\x00\x00\x39\x55\x6f\x05\x3c\x00\x00\x00\x10\x02\x85\x09\xa0\x00\xb8\x9d\x60\x00\x00\x1b\xb0\x00\x3a\x01\x00\x18\xf8\x6c\x76\x42\x70\x1a\x04\x54\xe3\x86\x00\x18\xf8\x6c\x76\x42\x30\xc8\x00\x00\x01\x00\x00\x00\xdd\x09\x00\x10\x18\x02\x00\x10\x00\x00\x00\x8a\x64\xe9\x3b"
        self.radiotap_decoder = RadioTapDecoder()
        radiotap = self.radiotap_decoder.decode(self.rawframe)

        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")

        self.dot11 = radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")

        type = self.dot11.get_type()
        self.assertEqual(type, Dot11Types.DOT11_TYPE_MANAGEMENT)

        subtype = self.dot11.get_subtype()
        self.assertEqual(subtype,
                         Dot11Types.DOT11_SUBTYPE_MANAGEMENT_AUTHENTICATION)

        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(
            typesubtype,
            Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_AUTHENTICATION)

        self.management_base = self.dot11.child()
        self.assertEqual(str(self.management_base.__class__),
                         "dot11.Dot11ManagementFrame")

        self.management_authentication = self.management_base.child()
        self.assertEqual(str(self.management_authentication.__class__),
                         "dot11.Dot11ManagementAuthentication")

    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(self.management_authentication.get_header_size(), 17)
        self.assertEqual(self.management_authentication.get_tail_size(), 0)

    def test_02(self):
        'Test Duration field'

        self.assertEqual(self.management_base.get_duration(), 0x013a)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)

    def test_03(self):
        'Test Destination Address field'

        addr = self.management_base.get_destination_address()

        self.assertEqual(addr.tolist(), [0x00, 0x18, 0xF8, 0x6C, 0x76, 0x42])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(
            self.management_base.get_destination_address().tolist(),
            [0x12, 0x18, 0xF8, 0x6C, 0x76, 0x34])

    def test_04(self):
        'Test Source Address field'

        addr = self.management_base.get_source_address()

        self.assertEqual(addr.tolist(), [0x70, 0x1A, 0x04, 0x54, 0xE3, 0x86])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(),
                         [0x12, 0x1A, 0x04, 0x54, 0xE3, 0x34])

    def test_05(self):
        'Test BSSID Address field'

        addr = self.management_base.get_bssid()

        self.assertEqual(addr.tolist(), [0x00, 0x18, 0xF8, 0x6C, 0x76, 0x42])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(),
                         [0x12, 0x18, 0xF8, 0x6C, 0x76, 0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0xc830)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1)  # Es de 4 bit
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 3203)
        self.management_base.set_sequence_number(0xF234)  # Es de 12 bit
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)

    def test_09(self):
        'Test Management Frame Data field'
        frame_body = "\x00\x00\x01\x00\x00\x00\xdd\x09\x00\x10\x18\x02\x00\x10\x00\x00\x00"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management Frame Authentication Algorithm field'
        self.assertEqual(
            self.management_authentication.get_authentication_algorithm(),
            0x0000)
        self.management_authentication.set_authentication_algorithm(0x8765)
        self.assertEqual(
            self.management_authentication.get_authentication_algorithm(),
            0x8765)

    def test_11(self):
        'Test Management Frame Authentication Sequence field'
        self.assertEqual(
            self.management_authentication.get_authentication_sequence(),
            0x0001)
        self.management_authentication.set_authentication_sequence(0x8765)
        self.assertEqual(
            self.management_authentication.get_authentication_sequence(),
            0x8765)

    def test_12(self):
        'Test Management Frame Authentication Status field'
        self.assertEqual(
            self.management_authentication.get_authentication_status(), 0x0000)
        self.management_authentication.set_authentication_status(0x8765)
        self.assertEqual(
            self.management_authentication.get_authentication_status(), 0x8765)

    def test_13(self):
        'Test Management Vendor Specific getter/setter methods'
        self.assertEqual(self.management_authentication.get_vendor_specific(),
                         [("\x00\x10\x18", "\x02\x00\x10\x00\x00\x00")])
        self.management_authentication.add_vendor_specific(
            "\x00\x00\x40", "\x04\x04\x04\x04\x04\x04")

        self.assertEqual(self.management_authentication.get_vendor_specific(),
                         [
                             ("\x00\x10\x18", "\x02\x00\x10\x00\x00\x00"),
                             ("\x00\x00\x40", "\x04\x04\x04\x04\x04\x04"),
                         ])
        self.assertEqual(self.management_authentication.get_header_size(), 28)
Esempio n. 3
0
class TestDot11ManagementBeaconFrames(unittest.TestCase):

    def setUp(self):
        # 802.11 Management Frame 
        #
        self.rawframe='\x00\x00\x20\x00\x67\x08\x04\x00\x54\xc6\xb8\x24\x00\x00\x00\x00\x22\x0c\xda\xa0\x02\x00\x00\x00\x40\x01\x00\x00\x3c\x14\x24\x11\x80\x00\x00\x00\xff\xff\xff\xff\xff\xff\x06\x03\x7f\x07\xa0\x16\x06\x03\x7f\x07\xa0\x16\xb0\x77\x3a\x40\xcb\x26\x00\x00\x00\x00\x64\x00\x01\x05\x00\x0a\x66\x72\x65\x65\x62\x73\x64\x2d\x61\x70\x01\x08\x8c\x12\x98\x24\xb0\x48\x60\x6c\x03\x01\x24\x05\x04\x00\x01\x00\x00\x07\x2a\x55\x53\x20\x24\x01\x11\x28\x01\x11\x2c\x01\x11\x30\x01\x11\x34\x01\x17\x38\x01\x17\x3c\x01\x17\x40\x01\x17\x95\x01\x1e\x99\x01\x1e\x9d\x01\x1e\xa1\x01\x1e\xa5\x01\x1e\x20\x01\x00\xdd\x18\x00\x50\xf2\x02\x01\x01\x00\x00\x03\xa4\x00\x00\x27\xa4\x00\x00\x42\x43\x5e\x00\x62\x32\x2f\x00'
        self.radiotap_decoder = RadioTapDecoder()
        radiotap=self.radiotap_decoder.decode(self.rawframe)

        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")

        self.dot11=radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")   

        type = self.dot11.get_type()
        self.assertEqual(type,Dot11Types.DOT11_TYPE_MANAGEMENT)
        
        subtype = self.dot11.get_subtype()
        self.assertEqual(subtype,Dot11Types.DOT11_SUBTYPE_MANAGEMENT_BEACON)
        
        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(typesubtype,Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_BEACON)
        
        self.management_base=self.dot11.child()
        self.assertEqual(str(self.management_base.__class__), "dot11.Dot11ManagementFrame")   
        
        self.management_beacon=self.management_base.child()
        self.assertEqual(str(self.management_beacon.__class__), "dot11.Dot11ManagementBeacon")   
            
        
    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(self.management_beacon.get_header_size(), 116)
        self.assertEqual(self.management_beacon.get_tail_size(), 0)
        
    def test_02(self):
        'Test Duration field'
        
        self.assertEqual(self.management_base.get_duration(), 0x0000)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)
    
    def test_03(self):
        'Test Destination Address field'
        
        addr=self.management_base.get_destination_address()
        
        self.assertEqual(addr.tolist(), [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(self.management_base.get_destination_address().tolist(), [0x12,0xFF,0xFF,0xFF,0xFF,0x34])

    def test_04(self):
        'Test Source Address field'
        
        addr=self.management_base.get_source_address()
        
        self.assertEqual(addr.tolist(), [0x06,0x03,0x7f,0x07,0xa0,0x16])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(), [0x12,0x03,0x7f,0x07,0xa0,0x34])

    def test_05(self):
        'Test BSSID Address field'
        
        addr=self.management_base.get_bssid()
        
        self.assertEqual(addr.tolist(), [0x06,0x03,0x7f,0x07,0xa0,0x16])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(), [0x12,0x03,0x7f,0x07,0xa0,0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0x77b0)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1) # Es de 4 bit
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 1915)
        self.management_base.set_sequence_number(0xF234) # Es de 12 bit
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)
        
    def test_09(self):
        'Test Management Frame Data field'
        frame_body="\x3a\x40\xcb\x26\x00\x00\x00\x00\x64\x00\x01\x05\x00\x0a\x66\x72\x65\x65\x62\x73\x64\x2d\x61\x70\x01\x08\x8c\x12\x98\x24\xb0\x48\x60\x6c\x03\x01\x24\x05\x04\x00\x01\x00\x00\x07\x2a\x55\x53\x20\x24\x01\x11\x28\x01\x11\x2c\x01\x11\x30\x01\x11\x34\x01\x17\x38\x01\x17\x3c\x01\x17\x40\x01\x17\x95\x01\x1e\x99\x01\x1e\x9d\x01\x1e\xa1\x01\x1e\xa5\x01\x1e\x20\x01\x00\xdd\x18\x00\x50\xf2\x02\x01\x01\x00\x00\x03\xa4\x00\x00\x27\xa4\x00\x00\x42\x43\x5e\x00\x62\x32\x2f\x00"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management Beacon Timestamp field' 
        self.assertEqual(self.management_beacon.get_timestamp(), 0x0000000026CB403A)
        self.management_beacon.set_timestamp(0x8765432101234567) 
        self.assertEqual(self.management_beacon.get_timestamp(), 0x8765432101234567)

    def test_11(self):
        'Test Management Beacon Inteval field' 
        self.assertEqual(self.management_beacon.get_beacon_interval(), 0x0064)
        self.management_beacon.set_beacon_interval(0x4321) 
        self.assertEqual(self.management_beacon.get_beacon_interval(), 0x4321)

    def test_12(self):
        'Test Management Beacon Capabilities field' 
        self.assertEqual(self.management_beacon.get_capabilities(), 0x0501)
        self.management_beacon.set_capabilities(0x4321) 
        self.assertEqual(self.management_beacon.get_capabilities(), 0x4321)

    def test_13(self):
        'Test Management ssid getter/setter methods'
        act_ssid="freebsd-ap"
        new_ssid="holala"
        self.assertEqual(self.management_beacon.get_ssid(), act_ssid)
        self.management_beacon.set_ssid(new_ssid)
        self.assertEqual(self.management_beacon.get_ssid(), new_ssid)
        self.assertEqual(self.management_beacon.get_header_size(), 116-4)

    def test_14(self):
        'Test Management supported_rates getter/setter methods'
        self.assertEqual(self.management_beacon.get_supported_rates(), (0x8c,0x12,0x98,0x24,0xb0,0x48,0x60,0x6c) )
        self.assertEqual(self.management_beacon.get_supported_rates(human_readable=True), (6.0, 9.0, 12.0, 18.0, 24.0, 36.0, 48.0, 54.0) )
        
        self.management_beacon.set_supported_rates((0x12,0x98,0x24,0xb0,0x48,0x60))

        self.assertEqual(self.management_beacon.get_supported_rates(), (0x12,0x98,0x24,0xb0,0x48,0x60) )
        self.assertEqual(self.management_beacon.get_supported_rates(human_readable=True), ( 9.0, 12.0, 18.0, 24.0, 36.0, 48.0) )
        self.assertEqual(self.management_beacon.get_header_size(), 116-2)

    def test_15(self):
        'Test Management DS Parameter Set getter/setter methods'
        self.assertEqual(self.management_beacon.get_ds_parameter_set(), 36 )
        
        self.management_beacon.set_ds_parameter_set(40)

        self.assertEqual(self.management_beacon.get_ds_parameter_set(), 40 )
        self.assertEqual(self.management_beacon.get_header_size(), 116)

    def test_16(self):
        'Test Management Vendor Specific getter/setter methods'
        self.assertEqual(self.management_beacon.get_vendor_specific(), [("\x00\x50\xf2","\x02\x01\x01\x00\x00\x03\xa4\x00\x00\x27\xa4\x00\x00\x42\x43\x5e\x00\x62\x32\x2f\x00")])

        self.management_beacon.add_vendor_specific("\x00\x00\x40","\x04\x04\x04\x04\x04\x04")

        self.assertEqual(self.management_beacon.get_vendor_specific(), 
            [("\x00\x50\xf2","\x02\x01\x01\x00\x00\x03\xa4\x00\x00\x27\xa4\x00\x00\x42\x43\x5e\x00\x62\x32\x2f\x00"),
             ("\x00\x00\x40","\x04\x04\x04\x04\x04\x04"),
            ])
        self.assertEqual(self.management_beacon.get_header_size(), 127)
class TestDot11ManagementProbeResponseFrames(unittest.TestCase):
    def setUp(self):
        # 802.11 Management Frame
        #
        self.rawProbeResponseframe = '\x00\x00\x18\x00\x2e\x48\x00\x00\x00\x02\x85\x09\xa0\x00\xb0\x01\x00\x00\x00\x00\x00\x00\x00\x00\x50\x00\x3a\x01\x00\x21\xfe\x39\x3f\x77\x00\x1b\x11\x32\x66\x23\x00\x1b\x11\x32\x66\x23\x20\x73\x7f\xa0\x22\xf8\x3f\x01\x00\x00\x64\x00\x11\x04\x00\x07\x66\x72\x65\x65\x62\x73\x64\x01\x08\x82\x84\x8b\x96\x24\x30\x48\x6c\x03\x01\x06\x2a\x01\x04\x2f\x01\x04\x32\x04\x0c\x12\x18\x60\xdd\x75\x00\x50\xf2\x04\x10\x4a\x00\x01\x10\x10\x44\x00\x01\x02\x10\x41\x00\x01\x00\x10\x3b\x00\x01\x03\x10\x47\x00\x10\x11\x4e\xf7\x46\xa9\xc6\xfb\x1d\x70\x1b\x00\x1b\x11\x32\x66\x23\x10\x21\x00\x06\x44\x2d\x4c\x69\x6e\x6b\x10\x23\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x24\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x42\x00\x08\x30\x30\x30\x30\x30\x30\x30\x30\x10\x54\x00\x08\x00\x06\x00\x50\xf2\x04\x00\x01\x10\x11\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x08\x00\x02\x00\x8e\xdd\x05\x00\x50\xf2\x05\x00\xdd\x09\x00\x10\x18\x02\x01\xf0\x00\x00\x00\xdd\x18\x00\x50\xf2\x01\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x00\x00'
        self.radiotap_decoder = RadioTapDecoder()
        radiotap = self.radiotap_decoder.decode(self.rawProbeResponseframe)

        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")

        self.dot11 = radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")

        type = self.dot11.get_type()
        self.assertEqual(type, Dot11Types.DOT11_TYPE_MANAGEMENT)

        subtype = self.dot11.get_subtype()
        self.assertEqual(subtype,
                         Dot11Types.DOT11_SUBTYPE_MANAGEMENT_PROBE_RESPONSE)

        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(
            typesubtype,
            Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_PROBE_RESPONSE)

        self.management_base = self.dot11.child()
        self.assertEqual(str(self.management_base.__class__),
                         "dot11.Dot11ManagementFrame")

        self.management_probe_response = self.management_base.child()
        self.assertEqual(str(self.management_probe_response.__class__),
                         "dot11.Dot11ManagementProbeResponse")

    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(self.management_probe_response.get_header_size(), 209)
        self.assertEqual(self.management_probe_response.get_tail_size(), 0)

    def test_02(self):
        'Test Duration field'

        self.assertEqual(self.management_base.get_duration(), 0x013a)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)

    def test_03(self):
        'Test Destination Address field'

        addr = self.management_base.get_destination_address()

        self.assertEqual(addr.tolist(), [0x00, 0x21, 0xFE, 0x39, 0x3F, 0x77])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(
            self.management_base.get_destination_address().tolist(),
            [0x12, 0x21, 0xFE, 0x39, 0x3F, 0x34])

    def test_04(self):
        'Test Source Address field'

        addr = self.management_base.get_source_address()

        self.assertEqual(addr.tolist(), [0x00, 0x1B, 0x11, 0x32, 0x66, 0x23])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(),
                         [0x12, 0x1B, 0x11, 0x32, 0x66, 0x34])

    def test_05(self):
        'Test BSSID Address field'

        addr = self.management_base.get_bssid()

        self.assertEqual(addr.tolist(), [0x00, 0x1B, 0x11, 0x32, 0x66, 0x23])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(),
                         [0x12, 0x1B, 0x11, 0x32, 0x66, 0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0x7320)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1)  # It's 4 bits long
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 1842)
        self.management_base.set_sequence_number(0xF234)  # It's 12 bits long
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)

    def test_09(self):
        'Test Management Frame Data field'
        frame_body = "\x7f\xa0\x22\xf8\x3f\x01\x00\x00\x64\x00\x11\x04\x00\x07\x66\x72\x65\x65\x62\x73\x64\x01\x08\x82\x84\x8b\x96\x24\x30\x48\x6c\x03\x01\x06\x2a\x01\x04\x2f\x01\x04\x32\x04\x0c\x12\x18\x60\xdd\x75\x00\x50\xf2\x04\x10\x4a\x00\x01\x10\x10\x44\x00\x01\x02\x10\x41\x00\x01\x00\x10\x3b\x00\x01\x03\x10\x47\x00\x10\x11\x4e\xf7\x46\xa9\xc6\xfb\x1d\x70\x1b\x00\x1b\x11\x32\x66\x23\x10\x21\x00\x06\x44\x2d\x4c\x69\x6e\x6b\x10\x23\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x24\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x42\x00\x08\x30\x30\x30\x30\x30\x30\x30\x30\x10\x54\x00\x08\x00\x06\x00\x50\xf2\x04\x00\x01\x10\x11\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x08\x00\x02\x00\x8e\xdd\x05\x00\x50\xf2\x05\x00\xdd\x09\x00\x10\x18\x02\x01\xf0\x00\x00\x00\xdd\x18\x00\x50\xf2\x01\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x00\x00"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management Beacon Timestamp field'
        self.assertEqual(self.management_probe_response.get_timestamp(),
                         0x0000013FF822A07F)
        self.management_probe_response.set_timestamp(0x8765432101234567)
        self.assertEqual(self.management_probe_response.get_timestamp(),
                         0x8765432101234567)

    def test_11(self):
        'Test Management Beacon Inteval field'
        self.assertEqual(self.management_probe_response.get_beacon_interval(),
                         0x0064)
        self.management_probe_response.set_beacon_interval(0x4321)
        self.assertEqual(self.management_probe_response.get_beacon_interval(),
                         0x4321)

    def test_12(self):
        'Test Management Beacon Capabilities field'
        self.assertEqual(self.management_probe_response.get_capabilities(),
                         0x0411)
        self.management_probe_response.set_capabilities(0x4321)
        self.assertEqual(self.management_probe_response.get_capabilities(),
                         0x4321)

    def test_13(self):
        'Test Management ssid getter/setter methods'
        act_ssid = "freebsd"
        new_ssid = "holala"
        self.assertEqual(self.management_probe_response.get_ssid(), act_ssid)
        self.management_probe_response.set_ssid(new_ssid)
        self.assertEqual(self.management_probe_response.get_ssid(), new_ssid)
        self.assertEqual(self.management_probe_response.get_header_size(),
                         209 - 1)

    def test_14(self):
        'Test Management supported_rates getter/setter methods'
        self.assertEqual(self.management_probe_response.get_supported_rates(),
                         (0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c))
        self.assertEqual(
            self.management_probe_response.get_supported_rates(
                human_readable=True),
            (1.0, 2.0, 5.5, 11.0, 18.0, 24.0, 36.0, 54.0))

        self.management_probe_response.set_supported_rates(
            (0x84, 0x8b, 0x96, 0x24, 0x30, 0x48))

        self.assertEqual(self.management_probe_response.get_supported_rates(),
                         (0x84, 0x8b, 0x96, 0x24, 0x30, 0x48))
        self.assertEqual(
            self.management_probe_response.get_supported_rates(
                human_readable=True), (2.0, 5.5, 11.0, 18.0, 24.0, 36.0))
        self.assertEqual(self.management_probe_response.get_header_size(),
                         209 - 2)

    def test_15(self):
        'Test Management DS Parameter Set getter/setter methods'
        self.assertEqual(self.management_probe_response.get_ds_parameter_set(),
                         6)

        self.management_probe_response.set_ds_parameter_set(40)

        self.assertEqual(self.management_probe_response.get_ds_parameter_set(),
                         40)
        self.assertEqual(self.management_probe_response.get_header_size(), 209)

    def test_16(self):
        'Test Management Vendor Specific getter/setter methods'
        self.assertEqual(self.management_probe_response.get_vendor_specific(
        ), [
            ("\x00\x50\xf2",
             "\x04\x10\x4a\x00\x01\x10\x10\x44\x00\x01\x02\x10\x41\x00\x01\x00\x10\x3b\x00\x01\x03\x10\x47\x00\x10\x11\x4e\xf7\x46\xa9\xc6\xfb\x1d\x70\x1b\x00\x1b\x11\x32\x66\x23\x10\x21\x00\x06\x44\x2d\x4c\x69\x6e\x6b\x10\x23\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x24\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x42\x00\x08\x30\x30\x30\x30\x30\x30\x30\x30\x10\x54\x00\x08\x00\x06\x00\x50\xf2\x04\x00\x01\x10\x11\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x08\x00\x02\x00\x8e"
             ),
            ("\x00\x50\xf2", "\x05\x00"),
            ("\x00\x10\x18", "\x02\x01\xf0\x00\x00\x00"),
            ("\x00\x50\xf2",
             "\x01\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x00\x00"
             ),
        ])

        self.management_probe_response.add_vendor_specific(
            "\x00\x00\x40", "\x04\x04\x04\x04\x04\x04")

        self.assertEqual(self.management_probe_response.get_vendor_specific(
        ), [
            ("\x00\x50\xf2",
             "\x04\x10\x4a\x00\x01\x10\x10\x44\x00\x01\x02\x10\x41\x00\x01\x00\x10\x3b\x00\x01\x03\x10\x47\x00\x10\x11\x4e\xf7\x46\xa9\xc6\xfb\x1d\x70\x1b\x00\x1b\x11\x32\x66\x23\x10\x21\x00\x06\x44\x2d\x4c\x69\x6e\x6b\x10\x23\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x24\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x42\x00\x08\x30\x30\x30\x30\x30\x30\x30\x30\x10\x54\x00\x08\x00\x06\x00\x50\xf2\x04\x00\x01\x10\x11\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x08\x00\x02\x00\x8e"
             ),
            ("\x00\x50\xf2", "\x05\x00"),
            ("\x00\x10\x18", "\x02\x01\xf0\x00\x00\x00"),
            ("\x00\x50\xf2",
             "\x01\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x00\x00"
             ),
            ("\x00\x00\x40", "\x04\x04\x04\x04\x04\x04"),
        ])
        self.assertEqual(self.management_probe_response.get_header_size(),
                         209 + 6 + 3 + 2)
class TestDot11ManagementProbeResponseFrames(unittest.TestCase):

    def setUp(self):
        # 802.11 Management Frame 
        #
        self.rawProbeResponseframe='\x00\x00\x18\x00\x2e\x48\x00\x00\x00\x02\x85\x09\xa0\x00\xb0\x01\x00\x00\x00\x00\x00\x00\x00\x00\x50\x00\x3a\x01\x00\x21\xfe\x39\x3f\x77\x00\x1b\x11\x32\x66\x23\x00\x1b\x11\x32\x66\x23\x20\x73\x7f\xa0\x22\xf8\x3f\x01\x00\x00\x64\x00\x11\x04\x00\x07\x66\x72\x65\x65\x62\x73\x64\x01\x08\x82\x84\x8b\x96\x24\x30\x48\x6c\x03\x01\x06\x2a\x01\x04\x2f\x01\x04\x32\x04\x0c\x12\x18\x60\xdd\x75\x00\x50\xf2\x04\x10\x4a\x00\x01\x10\x10\x44\x00\x01\x02\x10\x41\x00\x01\x00\x10\x3b\x00\x01\x03\x10\x47\x00\x10\x11\x4e\xf7\x46\xa9\xc6\xfb\x1d\x70\x1b\x00\x1b\x11\x32\x66\x23\x10\x21\x00\x06\x44\x2d\x4c\x69\x6e\x6b\x10\x23\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x24\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x42\x00\x08\x30\x30\x30\x30\x30\x30\x30\x30\x10\x54\x00\x08\x00\x06\x00\x50\xf2\x04\x00\x01\x10\x11\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x08\x00\x02\x00\x8e\xdd\x05\x00\x50\xf2\x05\x00\xdd\x09\x00\x10\x18\x02\x01\xf0\x00\x00\x00\xdd\x18\x00\x50\xf2\x01\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x00\x00'
        self.radiotap_decoder = RadioTapDecoder()
        radiotap=self.radiotap_decoder.decode(self.rawProbeResponseframe)

        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")

        self.dot11=radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")   

        type = self.dot11.get_type()
        self.assertEqual(type,Dot11Types.DOT11_TYPE_MANAGEMENT)
        
        subtype = self.dot11.get_subtype()
        self.assertEqual(subtype,Dot11Types.DOT11_SUBTYPE_MANAGEMENT_PROBE_RESPONSE)
        
        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(typesubtype,Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_PROBE_RESPONSE)
        
        self.management_base=self.dot11.child()
        self.assertEqual(str(self.management_base.__class__), "dot11.Dot11ManagementFrame")   
        
        self.management_probe_response=self.management_base.child()
        self.assertEqual(str(self.management_probe_response.__class__), "dot11.Dot11ManagementProbeResponse")   
            
        
    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(self.management_probe_response.get_header_size(), 209)
        self.assertEqual(self.management_probe_response.get_tail_size(), 0)
        
    def test_02(self):
        'Test Duration field'
        
        self.assertEqual(self.management_base.get_duration(), 0x013a)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)
    
    def test_03(self):
        'Test Destination Address field'
        
        addr=self.management_base.get_destination_address()
        
        self.assertEqual(addr.tolist(), [0x00,0x21,0xFE,0x39,0x3F,0x77])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(self.management_base.get_destination_address().tolist(), [0x12,0x21,0xFE,0x39,0x3F,0x34])

    def test_04(self):
        'Test Source Address field'
        
        addr=self.management_base.get_source_address()
        
        self.assertEqual(addr.tolist(), [0x00,0x1B,0x11,0x32,0x66,0x23])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(), [0x12,0x1B,0x11,0x32,0x66,0x34])

    def test_05(self):
        'Test BSSID Address field'
        
        addr=self.management_base.get_bssid()
        
        self.assertEqual(addr.tolist(), [0x00,0x1B,0x11,0x32,0x66,0x23])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(), [0x12,0x1B,0x11,0x32,0x66,0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0x7320)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1) # It's 4 bits long
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 1842)
        self.management_base.set_sequence_number(0xF234) # It's 12 bits long
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)
        
    def test_09(self):
        'Test Management Frame Data field'
        frame_body="\x7f\xa0\x22\xf8\x3f\x01\x00\x00\x64\x00\x11\x04\x00\x07\x66\x72\x65\x65\x62\x73\x64\x01\x08\x82\x84\x8b\x96\x24\x30\x48\x6c\x03\x01\x06\x2a\x01\x04\x2f\x01\x04\x32\x04\x0c\x12\x18\x60\xdd\x75\x00\x50\xf2\x04\x10\x4a\x00\x01\x10\x10\x44\x00\x01\x02\x10\x41\x00\x01\x00\x10\x3b\x00\x01\x03\x10\x47\x00\x10\x11\x4e\xf7\x46\xa9\xc6\xfb\x1d\x70\x1b\x00\x1b\x11\x32\x66\x23\x10\x21\x00\x06\x44\x2d\x4c\x69\x6e\x6b\x10\x23\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x24\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x42\x00\x08\x30\x30\x30\x30\x30\x30\x30\x30\x10\x54\x00\x08\x00\x06\x00\x50\xf2\x04\x00\x01\x10\x11\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x08\x00\x02\x00\x8e\xdd\x05\x00\x50\xf2\x05\x00\xdd\x09\x00\x10\x18\x02\x01\xf0\x00\x00\x00\xdd\x18\x00\x50\xf2\x01\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x00\x00"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management Beacon Timestamp field' 
        self.assertEqual(self.management_probe_response.get_timestamp(), 0x0000013FF822A07F)
        self.management_probe_response.set_timestamp(0x8765432101234567) 
        self.assertEqual(self.management_probe_response.get_timestamp(), 0x8765432101234567)

    def test_11(self):
        'Test Management Beacon Inteval field' 
        self.assertEqual(self.management_probe_response.get_beacon_interval(), 0x0064)
        self.management_probe_response.set_beacon_interval(0x4321) 
        self.assertEqual(self.management_probe_response.get_beacon_interval(), 0x4321)

    def test_12(self):
        'Test Management Beacon Capabilities field' 
        self.assertEqual(self.management_probe_response.get_capabilities(), 0x0411)
        self.management_probe_response.set_capabilities(0x4321) 
        self.assertEqual(self.management_probe_response.get_capabilities(), 0x4321)

    def test_13(self):
        'Test Management ssid getter/setter methods'
        act_ssid="freebsd"
        new_ssid="holala"
        self.assertEqual(self.management_probe_response.get_ssid(), act_ssid)
        self.management_probe_response.set_ssid(new_ssid)
        self.assertEqual(self.management_probe_response.get_ssid(), new_ssid)
        self.assertEqual(self.management_probe_response.get_header_size(), 209-1)

    def test_14(self):
        'Test Management supported_rates getter/setter methods'
        self.assertEqual(self.management_probe_response.get_supported_rates(), (0x82,0x84,0x8b,0x96,0x24,0x30,0x48,0x6c) )
        self.assertEqual(self.management_probe_response.get_supported_rates(human_readable=True), (1.0, 2.0, 5.5, 11.0, 18.0, 24.0, 36.0, 54.0 ) )
        
        self.management_probe_response.set_supported_rates((0x84,0x8b,0x96,0x24,0x30,0x48))

        self.assertEqual(self.management_probe_response.get_supported_rates(), (0x84,0x8b,0x96,0x24,0x30,0x48) )
        self.assertEqual(self.management_probe_response.get_supported_rates(human_readable=True), ( 2.0, 5.5, 11.0, 18.0, 24.0, 36.0 ) )
        self.assertEqual(self.management_probe_response.get_header_size(), 209-2)

    def test_15(self):
        'Test Management DS Parameter Set getter/setter methods'
        self.assertEqual(self.management_probe_response.get_ds_parameter_set(), 6 )
        
        self.management_probe_response.set_ds_parameter_set(40)

        self.assertEqual(self.management_probe_response.get_ds_parameter_set(), 40 )
        self.assertEqual(self.management_probe_response.get_header_size(), 209)

    def test_16(self):
        'Test Management Vendor Specific getter/setter methods'
        self.assertEqual(self.management_probe_response.get_vendor_specific(), 
            [("\x00\x50\xf2", "\x04\x10\x4a\x00\x01\x10\x10\x44\x00\x01\x02\x10\x41\x00\x01\x00\x10\x3b\x00\x01\x03\x10\x47\x00\x10\x11\x4e\xf7\x46\xa9\xc6\xfb\x1d\x70\x1b\x00\x1b\x11\x32\x66\x23\x10\x21\x00\x06\x44\x2d\x4c\x69\x6e\x6b\x10\x23\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x24\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x42\x00\x08\x30\x30\x30\x30\x30\x30\x30\x30\x10\x54\x00\x08\x00\x06\x00\x50\xf2\x04\x00\x01\x10\x11\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x08\x00\x02\x00\x8e"),
             ("\x00\x50\xf2", "\x05\x00"),
             ("\x00\x10\x18","\x02\x01\xf0\x00\x00\x00"),
             ("\x00\x50\xf2","\x01\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x00\x00"),
            ])
        
        self.management_probe_response.add_vendor_specific("\x00\x00\x40","\x04\x04\x04\x04\x04\x04")

        self.assertEqual(self.management_probe_response.get_vendor_specific(), 
            [("\x00\x50\xf2","\x04\x10\x4a\x00\x01\x10\x10\x44\x00\x01\x02\x10\x41\x00\x01\x00\x10\x3b\x00\x01\x03\x10\x47\x00\x10\x11\x4e\xf7\x46\xa9\xc6\xfb\x1d\x70\x1b\x00\x1b\x11\x32\x66\x23\x10\x21\x00\x06\x44\x2d\x4c\x69\x6e\x6b\x10\x23\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x24\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x42\x00\x08\x30\x30\x30\x30\x30\x30\x30\x30\x10\x54\x00\x08\x00\x06\x00\x50\xf2\x04\x00\x01\x10\x11\x00\x07\x44\x49\x52\x2d\x33\x32\x30\x10\x08\x00\x02\x00\x8e"),
             ("\x00\x50\xf2","\x05\x00"),
             ("\x00\x10\x18","\x02\x01\xf0\x00\x00\x00"),
             ("\x00\x50\xf2","\x01\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x01\x00\x00\x50\xf2\x02\x00\x00"),
             ("\x00\x00\x40","\x04\x04\x04\x04\x04\x04"),
            ])
        self.assertEqual(self.management_probe_response.get_header_size(), 209+6+3+2)
Esempio n. 6
0
class TestDot11ManagementBeaconFrames(unittest.TestCase):
    def setUp(self):
        # 802.11 Management Frame
        #
        self.rawframe = '\x00\x00\x20\x00\x67\x08\x04\x00\x54\xc6\xb8\x24\x00\x00\x00\x00\x22\x0c\xda\xa0\x02\x00\x00\x00\x40\x01\x00\x00\x3c\x14\x24\x11\x80\x00\x00\x00\xff\xff\xff\xff\xff\xff\x06\x03\x7f\x07\xa0\x16\x06\x03\x7f\x07\xa0\x16\xb0\x77\x3a\x40\xcb\x26\x00\x00\x00\x00\x64\x00\x01\x05\x00\x0a\x66\x72\x65\x65\x62\x73\x64\x2d\x61\x70\x01\x08\x8c\x12\x98\x24\xb0\x48\x60\x6c\x03\x01\x24\x05\x04\x00\x01\x00\x00\x07\x2a\x55\x53\x20\x24\x01\x11\x28\x01\x11\x2c\x01\x11\x30\x01\x11\x34\x01\x17\x38\x01\x17\x3c\x01\x17\x40\x01\x17\x95\x01\x1e\x99\x01\x1e\x9d\x01\x1e\xa1\x01\x1e\xa5\x01\x1e\x20\x01\x00\xdd\x18\x00\x50\xf2\x02\x01\x01\x00\x00\x03\xa4\x00\x00\x27\xa4\x00\x00\x42\x43\x5e\x00\x62\x32\x2f\x00'
        self.radiotap_decoder = RadioTapDecoder()
        radiotap = self.radiotap_decoder.decode(self.rawframe)

        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")

        self.dot11 = radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")

        type = self.dot11.get_type()
        self.assertEqual(type, Dot11Types.DOT11_TYPE_MANAGEMENT)

        subtype = self.dot11.get_subtype()
        self.assertEqual(subtype, Dot11Types.DOT11_SUBTYPE_MANAGEMENT_BEACON)

        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(typesubtype,
                         Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_BEACON)

        self.management_base = self.dot11.child()
        self.assertEqual(str(self.management_base.__class__),
                         "dot11.Dot11ManagementFrame")

        self.management_beacon = self.management_base.child()
        self.assertEqual(str(self.management_beacon.__class__),
                         "dot11.Dot11ManagementBeacon")

    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(self.management_beacon.get_header_size(), 116)
        self.assertEqual(self.management_beacon.get_tail_size(), 0)

    def test_02(self):
        'Test Duration field'

        self.assertEqual(self.management_base.get_duration(), 0x0000)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)

    def test_03(self):
        'Test Destination Address field'

        addr = self.management_base.get_destination_address()

        self.assertEqual(addr.tolist(), [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(
            self.management_base.get_destination_address().tolist(),
            [0x12, 0xFF, 0xFF, 0xFF, 0xFF, 0x34])

    def test_04(self):
        'Test Source Address field'

        addr = self.management_base.get_source_address()

        self.assertEqual(addr.tolist(), [0x06, 0x03, 0x7f, 0x07, 0xa0, 0x16])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(),
                         [0x12, 0x03, 0x7f, 0x07, 0xa0, 0x34])

    def test_05(self):
        'Test BSSID Address field'

        addr = self.management_base.get_bssid()

        self.assertEqual(addr.tolist(), [0x06, 0x03, 0x7f, 0x07, 0xa0, 0x16])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(),
                         [0x12, 0x03, 0x7f, 0x07, 0xa0, 0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0x77b0)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1)  # Es de 4 bit
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 1915)
        self.management_base.set_sequence_number(0xF234)  # Es de 12 bit
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)

    def test_09(self):
        'Test Management Frame Data field'
        frame_body = "\x3a\x40\xcb\x26\x00\x00\x00\x00\x64\x00\x01\x05\x00\x0a\x66\x72\x65\x65\x62\x73\x64\x2d\x61\x70\x01\x08\x8c\x12\x98\x24\xb0\x48\x60\x6c\x03\x01\x24\x05\x04\x00\x01\x00\x00\x07\x2a\x55\x53\x20\x24\x01\x11\x28\x01\x11\x2c\x01\x11\x30\x01\x11\x34\x01\x17\x38\x01\x17\x3c\x01\x17\x40\x01\x17\x95\x01\x1e\x99\x01\x1e\x9d\x01\x1e\xa1\x01\x1e\xa5\x01\x1e\x20\x01\x00\xdd\x18\x00\x50\xf2\x02\x01\x01\x00\x00\x03\xa4\x00\x00\x27\xa4\x00\x00\x42\x43\x5e\x00\x62\x32\x2f\x00"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management Beacon Timestamp field'
        self.assertEqual(self.management_beacon.get_timestamp(),
                         0x0000000026CB403A)
        self.management_beacon.set_timestamp(0x8765432101234567)
        self.assertEqual(self.management_beacon.get_timestamp(),
                         0x8765432101234567)

    def test_11(self):
        'Test Management Beacon Inteval field'
        self.assertEqual(self.management_beacon.get_beacon_interval(), 0x0064)
        self.management_beacon.set_beacon_interval(0x4321)
        self.assertEqual(self.management_beacon.get_beacon_interval(), 0x4321)

    def test_12(self):
        'Test Management Beacon Capabilities field'
        self.assertEqual(self.management_beacon.get_capabilities(), 0x0501)
        self.management_beacon.set_capabilities(0x4321)
        self.assertEqual(self.management_beacon.get_capabilities(), 0x4321)

    def test_13(self):
        'Test Management ssid getter/setter methods'
        act_ssid = "freebsd-ap"
        new_ssid = "holala"
        self.assertEqual(self.management_beacon.get_ssid(), act_ssid)
        self.management_beacon.set_ssid(new_ssid)
        self.assertEqual(self.management_beacon.get_ssid(), new_ssid)
        self.assertEqual(self.management_beacon.get_header_size(), 116 - 4)

    def test_14(self):
        'Test Management supported_rates getter/setter methods'
        self.assertEqual(self.management_beacon.get_supported_rates(),
                         (0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c))
        self.assertEqual(
            self.management_beacon.get_supported_rates(human_readable=True),
            (6.0, 9.0, 12.0, 18.0, 24.0, 36.0, 48.0, 54.0))

        self.management_beacon.set_supported_rates(
            (0x12, 0x98, 0x24, 0xb0, 0x48, 0x60))

        self.assertEqual(self.management_beacon.get_supported_rates(),
                         (0x12, 0x98, 0x24, 0xb0, 0x48, 0x60))
        self.assertEqual(
            self.management_beacon.get_supported_rates(human_readable=True),
            (9.0, 12.0, 18.0, 24.0, 36.0, 48.0))
        self.assertEqual(self.management_beacon.get_header_size(), 116 - 2)

    def test_15(self):
        'Test Management DS Parameter Set getter/setter methods'
        self.assertEqual(self.management_beacon.get_ds_parameter_set(), 36)

        self.management_beacon.set_ds_parameter_set(40)

        self.assertEqual(self.management_beacon.get_ds_parameter_set(), 40)
        self.assertEqual(self.management_beacon.get_header_size(), 116)

    def test_16(self):
        'Test Management Vendor Specific getter/setter methods'
        self.assertEqual(self.management_beacon.get_vendor_specific(), [(
            "\x00\x50\xf2",
            "\x02\x01\x01\x00\x00\x03\xa4\x00\x00\x27\xa4\x00\x00\x42\x43\x5e\x00\x62\x32\x2f\x00"
        )])

        self.management_beacon.add_vendor_specific("\x00\x00\x40",
                                                   "\x04\x04\x04\x04\x04\x04")

        self.assertEqual(self.management_beacon.get_vendor_specific(), [
            ("\x00\x50\xf2",
             "\x02\x01\x01\x00\x00\x03\xa4\x00\x00\x27\xa4\x00\x00\x42\x43\x5e\x00\x62\x32\x2f\x00"
             ),
            ("\x00\x00\x40", "\x04\x04\x04\x04\x04\x04"),
        ])
        self.assertEqual(self.management_beacon.get_header_size(), 127)
Esempio n. 7
0
class TestDot11ManagementDisassociationFrames(unittest.TestCase):
    def setUp(self):
        # 802.11 Management Frame
        #
        self.rawframe = "\x00\x00\x1c\x00\xef\x18\x00\x00\xe7\x8a\xec\xb8\x3b\x00\x00\x00\x10\x02\x85\x09\xa0\x00\xb5\x9d\x60\x00\x00\x18\xa0\x00\x3a\x01\x00\x18\xf8\x6c\x76\x42\x70\x1a\x04\x54\xe3\x86\x00\x18\xf8\x6c\x76\x42\x70\x92\x08\x00\xbf\x1b\xa3\xa8"
        self.radiotap_decoder = RadioTapDecoder()
        radiotap = self.radiotap_decoder.decode(self.rawframe)

        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")

        self.dot11 = radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")

        type = self.dot11.get_type()
        self.assertEqual(type, Dot11Types.DOT11_TYPE_MANAGEMENT)

        subtype = self.dot11.get_subtype()
        self.assertEqual(subtype,
                         Dot11Types.DOT11_SUBTYPE_MANAGEMENT_DISASSOCIATION)

        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(
            typesubtype,
            Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_DISASSOCIATION)

        self.management_base = self.dot11.child()
        self.assertEqual(str(self.management_base.__class__),
                         "dot11.Dot11ManagementFrame")

        self.management_disassociation = self.management_base.child()
        self.assertEqual(str(self.management_disassociation.__class__),
                         "dot11.Dot11ManagementDisassociation")

    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(self.management_disassociation.get_header_size(), 2)
        self.assertEqual(self.management_disassociation.get_tail_size(), 0)

    def test_02(self):
        'Test Duration field'

        self.assertEqual(self.management_base.get_duration(), 0x013a)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)

    def test_03(self):
        'Test Destination Address field'

        addr = self.management_base.get_destination_address()

        self.assertEqual(addr.tolist(), [0x00, 0x18, 0xF8, 0x6C, 0x76, 0x42])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(
            self.management_base.get_destination_address().tolist(),
            [0x12, 0x18, 0xF8, 0x6C, 0x76, 0x34])

    def test_04(self):
        'Test Source Address field'

        addr = self.management_base.get_source_address()

        self.assertEqual(addr.tolist(), [0x70, 0x1A, 0x04, 0x54, 0xE3, 0x86])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(),
                         [0x12, 0x1A, 0x04, 0x54, 0xE3, 0x34])

    def test_05(self):
        'Test BSSID Address field'

        addr = self.management_base.get_bssid()

        self.assertEqual(addr.tolist(), [0x00, 0x18, 0xF8, 0x6C, 0x76, 0x42])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(),
                         [0x12, 0x18, 0xF8, 0x6C, 0x76, 0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0x9270)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1)  # Es de 4 bit
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 2343)
        self.management_base.set_sequence_number(0xF234)  # Es de 12 bit
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)

    def test_09(self):
        'Test Management Frame Data field'
        frame_body = "\x08\x00"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management Reason Code field'
        self.assertEqual(self.management_disassociation.get_reason_code(),
                         0x0008)
        self.management_disassociation.set_reason_code(0x8765)
        self.assertEqual(self.management_disassociation.get_reason_code(),
                         0x8765)
Esempio n. 8
0
class TestDot11ManagementAssociationResponseFrames(unittest.TestCase):
    def setUp(self):
        # 802.11 Management Frame
        #
        self.rawframe = "\x00\x00\x1c\x00\xef\x18\x00\x00\xc2L\xfa\x00<\x00\x00\x00\x10\x02\x85\t\xa0\x00\xb4\x9e_\x00\x00\x16\x10\x00:\x01p\x1a\x04T\xe3\x86\x00\x18\xf8lvB\x00\x18\xf8lvB\xf0\x02\x11\x04\x00\x00\x04\xc0\x01\x08\x82\x84\x8b\x96$0Hl2\x04\x0c\x12\x18`\xdd\t\x00\x10\x18\x02\x02\xf0\x00\x00\x00f%\xdf7"
        self.radiotap_decoder = RadioTapDecoder()
        radiotap = self.radiotap_decoder.decode(self.rawframe)

        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")

        self.dot11 = radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")

        type = self.dot11.get_type()
        self.assertEqual(type, Dot11Types.DOT11_TYPE_MANAGEMENT)

        subtype = self.dot11.get_subtype()
        self.assertEqual(
            subtype, Dot11Types.DOT11_SUBTYPE_MANAGEMENT_ASSOCIATION_RESPONSE)

        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(
            typesubtype,
            Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_ASSOCIATION_RESPONSE)

        self.management_base = self.dot11.child()
        self.assertEqual(str(self.management_base.__class__),
                         "dot11.Dot11ManagementFrame")

        self.management_association_response = self.management_base.child()
        self.assertEqual(str(self.management_association_response.__class__),
                         "dot11.Dot11ManagementAssociationResponse")

    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(
            self.management_association_response.get_header_size(), 33)
        self.assertEqual(self.management_association_response.get_tail_size(),
                         0)

    def test_02(self):
        'Test Duration field'

        self.assertEqual(self.management_base.get_duration(), 0x013a)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)

    def test_03(self):
        'Test Destination Address field'

        addr = self.management_base.get_destination_address()

        self.assertEqual(addr.tolist(), [0x70, 0x1a, 0x04, 0x54, 0xe3, 0x86])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(
            self.management_base.get_destination_address().tolist(),
            [0x12, 0x1a, 0x04, 0x54, 0xe3, 0x34])

    def test_04(self):
        'Test Source Address field'

        addr = self.management_base.get_source_address()

        self.assertEqual(addr.tolist(), [0x00, 0x18, 0xF8, 0x6C, 0x76, 0x42])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(),
                         [0x12, 0x18, 0xF8, 0x6C, 0x76, 0x34])

    def test_05(self):
        'Test BSSID Address field'

        addr = self.management_base.get_bssid()

        self.assertEqual(addr.tolist(), [0x00, 0x18, 0xF8, 0x6C, 0x76, 0x42])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(),
                         [0x12, 0x18, 0xF8, 0x6C, 0x76, 0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0x02f0)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1)  # Es de 4 bit
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 47)
        self.management_base.set_sequence_number(0xF234)  # Es de 12 bit
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)

    def test_09(self):
        'Test Management Frame Data field'
        frame_body = "\x11\x04\x00\x00\x04\xc0\x01\x08\x82\x84\x8b\x96$0Hl2\x04\x0c\x12\x18`\xdd\t\x00\x10\x18\x02\x02\xf0\x00\x00\x00"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management Association Response Capabilities field'
        self.assertEqual(
            self.management_association_response.get_capabilities(), 0x0411)
        self.management_association_response.set_capabilities(0x4321)
        self.assertEqual(
            self.management_association_response.get_capabilities(), 0x4321)

    def test_11(self):
        'Test Management Association Response Status Code field'
        self.assertEqual(
            self.management_association_response.get_status_code(), 0x0000)
        self.management_association_response.set_status_code(0x4321)
        self.assertEqual(
            self.management_association_response.get_status_code(), 0x4321)

    def test_12(self):
        'Test Management Association Response Association ID field'
        self.assertEqual(
            self.management_association_response.get_association_id(), 0xc004)
        self.management_association_response.set_association_id(0x4321)
        self.assertEqual(
            self.management_association_response.get_association_id(), 0x4321)

    def test_13(self):
        'Test Management Association Response Supported_rates getter/setter methods'
        self.assertEqual(
            self.management_association_response.get_supported_rates(),
            (0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c))
        self.assertEqual(
            self.management_association_response.get_supported_rates(
                human_readable=True),
            (1.0, 2.0, 5.5, 11.0, 18.0, 24.0, 36.0, 54.0))

        self.management_association_response.set_supported_rates(
            (0x12, 0x98, 0x24, 0xb0, 0x48, 0x60))

        self.assertEqual(
            self.management_association_response.get_supported_rates(),
            (0x12, 0x98, 0x24, 0xb0, 0x48, 0x60))
        self.assertEqual(
            self.management_association_response.get_supported_rates(
                human_readable=True), (9.0, 12.0, 18.0, 24.0, 36.0, 48.0))
        self.assertEqual(
            self.management_association_response.get_header_size(), 33 - 2)

    def test_14(self):
        'Test Management Vendor Specific getter/setter methods'
        self.assertEqual(
            self.management_association_response.get_vendor_specific(),
            [("\x00\x10\x18", "\x02\x02\xf0\x00\x00\x00")])

        self.management_association_response.add_vendor_specific(
            "\x00\x00\x40", "\x04\x04\x04\x04\x04\x04")

        self.assertEqual(
            self.management_association_response.get_vendor_specific(), [
                ("\x00\x10\x18", "\x02\x02\xf0\x00\x00\x00"),
                ("\x00\x00\x40", "\x04\x04\x04\x04\x04\x04"),
            ])
        self.assertEqual(
            self.management_association_response.get_header_size(), 33 + 11)
Esempio n. 9
0
class TestRadioTapDecoder(unittest.TestCase):
    def setUp(self):
        self.RadioTapData = '\x00\x00\x20\x00\x67\x08\x04\x00\x30\x03\x1a\x25\x00\x00\x00\x00\x22\x0c\xd9\xa0\x02\x00\x00\x00\x40\x01\x00\x00\x3c\x14\x24\x11\x08\x02\x00\x00\xff\xff\xff\xff\xff\xff\x06\x03\x7f\x07\xa0\x16\x00\x19\xe3\xd3\x53\x52\x90\x7f\xaa\xaa\x03\x00\x00\x00\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x19\xe3\xd3\x53\x52\xa9\xfe\xf7\x00\x00\x00\x00\x00\x00\x00\x43\x08\x0e\x36'
        self.radiotap_decoder = RadioTapDecoder()
        self.in0 = self.radiotap_decoder.decode(self.RadioTapData)
        self.in1 = self.in0.child()
        self.in2 = self.in1.child()
        self.in3 = self.in2.child()
        self.in4 = self.in3.child()
        self.in5 = self.in4.child()
        self.in6 = self.in5.child()

    def test_00(self):
        'Test RadioTap decoder'
        self.assertEqual(str(self.in0.__class__), "dot11.RadioTap")

    def test_01(self):
        'Test Dot11 decoder'
        self.assertEqual(str(self.in1.__class__), "dot11.Dot11")

    def test_02(self):
        'Test Dot11DataFrame decoder'
        self.assertEqual(str(self.in2.__class__), "dot11.Dot11DataFrame")

    def test_03(self):
        'Test LLC decoder'
        self.assertEqual(str(self.in3.__class__), "dot11.LLC")

    def test_04(self):
        'Test SNAP decoder'
        self.assertEqual(str(self.in4.__class__), "dot11.SNAP")


#    def test_05(self):
#        'Test ARP decoder'
#        self.assertEqual(str(self.in5.__class__), "ImpactPacket.ARP")

#    def test_05(self):
#        'Test Data decoder'
#        self.assertEqual(str(self.in6.__class__), "ImpactPacket.Data")

    def test_06(self):
        'Test Protocol Finder'
        p = self.radiotap_decoder.get_protocol(dot11.RadioTap)
        self.assertEqual(str(p.__class__), "dot11.RadioTap")

        p = self.radiotap_decoder.get_protocol(dot11.Dot11)
        self.assertEqual(str(p.__class__), "dot11.Dot11")

        p = self.radiotap_decoder.get_protocol(dot11.Dot11DataFrame)
        self.assertEqual(str(p.__class__), "dot11.Dot11DataFrame")

        p = self.radiotap_decoder.get_protocol(dot11.LLC)
        self.assertEqual(str(p.__class__), "dot11.LLC")

        p = self.radiotap_decoder.get_protocol(dot11.SNAP)
        self.assertEqual(str(p.__class__), "dot11.SNAP")

        #p=self.radiotap_decoder.get_protocol(ImpactPacket.ARP)
        #self.assertEqual(str(p.__class__), "ImpactPacket.ARP")

        #p=self.radiotap_decoder.get_protocol(ImpactPacket.Data)
        #self.assertEqual(str(p.__class__), "ImpactPacket.Data")

        # When not found, None is returned
        p = self.radiotap_decoder.get_protocol(dot11.Dot11WPA)
        self.assertEqual(p, None)
class TestDot11ManagementBeaconFrames(unittest.TestCase):
    def setUp(self):
        # 802.11 Management Frame
        #
        self.rawframe = '\x00\x00\x10\x00\x6e\x00\x00\x00\x00\x02\x94\x09\xa0\x00\x3a\x00\xc0\x00\x3a\x01\x00\x15\xaf\x64\xac\xbd\x00\x18\x39\xc1\xfc\xe2\x00\x18\x39\xc1\xfc\xe2\x20\x3b\x0f\x00'
        self.radiotap_decoder = RadioTapDecoder()
        radiotap = self.radiotap_decoder.decode(self.rawframe)

        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")

        self.dot11 = radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")

        type = self.dot11.get_type()
        self.assertEqual(type, Dot11Types.DOT11_TYPE_MANAGEMENT)

        subtype = self.dot11.get_subtype()
        self.assertEqual(subtype,
                         Dot11Types.DOT11_SUBTYPE_MANAGEMENT_DEAUTHENTICATION)

        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(
            typesubtype,
            Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_DEAUTHENTICATION)

        self.management_base = self.dot11.child()
        self.assertEqual(str(self.management_base.__class__),
                         "dot11.Dot11ManagementFrame")

        self.management_deauthentication = self.management_base.child()
        self.assertEqual(str(self.management_deauthentication.__class__),
                         "dot11.Dot11ManagementDeauthentication")

    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(self.management_deauthentication.get_header_size(), 2)
        self.assertEqual(self.management_deauthentication.get_tail_size(), 0)

    def test_02(self):
        'Test Duration field'

        self.assertEqual(self.management_base.get_duration(), 0x013a)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)

    def test_03(self):
        'Test Destination Address field'

        addr = self.management_base.get_destination_address()

        self.assertEqual(addr.tolist(), [0x00, 0x15, 0xAF, 0x64, 0xAC, 0xBD])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(
            self.management_base.get_destination_address().tolist(),
            [0x12, 0x15, 0xAF, 0x64, 0xAC, 0x34])

    def test_04(self):
        'Test Source Address field'

        addr = self.management_base.get_source_address()

        self.assertEqual(addr.tolist(), [0x00, 0x18, 0x39, 0xC1, 0xFC, 0xE2])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(),
                         [0x12, 0x18, 0x39, 0xC1, 0xFC, 0x34])

    def test_05(self):
        'Test BSSID Address field'

        addr = self.management_base.get_bssid()

        self.assertEqual(addr.tolist(), [0x00, 0x18, 0x39, 0xC1, 0xFC, 0xE2])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(),
                         [0x12, 0x18, 0x39, 0xC1, 0xFC, 0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0x3b20)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1)  # Es de 4 bit
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 946)
        self.management_base.set_sequence_number(0xF234)  # Es de 12 bit
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)

    def test_09(self):
        'Test Management Frame Data field'
        frame_body = "\x0f\x00"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management Reason Code field'
        self.assertEqual(self.management_deauthentication.get_reason_code(),
                         0x000f)
        self.management_deauthentication.set_reason_code(0x8765)
        self.assertEqual(self.management_deauthentication.get_reason_code(),
                         0x8765)
class TestDot11ManagementAuthenticationFrames(unittest.TestCase):

    def setUp(self):
        # 802.11 Management Frame 
        #
	self.rawframe="\x00\x00\x1c\x00\xef\x18\x00\x00\x39\x55\x6f\x05\x3c\x00\x00\x00\x10\x02\x85\x09\xa0\x00\xb8\x9d\x60\x00\x00\x1b\xb0\x00\x3a\x01\x00\x18\xf8\x6c\x76\x42\x70\x1a\x04\x54\xe3\x86\x00\x18\xf8\x6c\x76\x42\x30\xc8\x00\x00\x01\x00\x00\x00\xdd\x09\x00\x10\x18\x02\x00\x10\x00\x00\x00\x8a\x64\xe9\x3b"
        self.radiotap_decoder = RadioTapDecoder()
        radiotap=self.radiotap_decoder.decode(self.rawframe)

        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")

        self.dot11=radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")

        type = self.dot11.get_type()
        self.assertEqual(type,Dot11Types.DOT11_TYPE_MANAGEMENT)
        
        subtype = self.dot11.get_subtype()
        self.assertEqual(subtype,Dot11Types.DOT11_SUBTYPE_MANAGEMENT_AUTHENTICATION)
        
        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(typesubtype,Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_AUTHENTICATION)
        
        self.management_base=self.dot11.child()
        self.assertEqual(str(self.management_base.__class__), "dot11.Dot11ManagementFrame")
        
        self.management_authentication=self.management_base.child()
        self.assertEqual(str(self.management_authentication.__class__), "dot11.Dot11ManagementAuthentication")
            
        
    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(self.management_authentication.get_header_size(), 17)
        self.assertEqual(self.management_authentication.get_tail_size(), 0)
        
    def test_02(self):
        'Test Duration field'
        
        self.assertEqual(self.management_base.get_duration(), 0x013a)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)
    
    def test_03(self):
        'Test Destination Address field'
        
        addr=self.management_base.get_destination_address()
        
        self.assertEqual(addr.tolist(), [0x00,0x18,0xF8,0x6C,0x76,0x42])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(self.management_base.get_destination_address().tolist(), [0x12,0x18,0xF8,0x6C,0x76,0x34])

    def test_04(self):
        'Test Source Address field'
        
        addr=self.management_base.get_source_address()
        
        self.assertEqual(addr.tolist(), [0x70,0x1A,0x04,0x54,0xE3,0x86])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(), [0x12,0x1A,0x04,0x54,0xE3,0x34])

    def test_05(self):
        'Test BSSID Address field'
        
        addr=self.management_base.get_bssid()
        
        self.assertEqual(addr.tolist(), [0x00,0x18,0xF8,0x6C,0x76,0x42])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(), [0x12,0x18,0xF8,0x6C,0x76,0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0xc830)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1) # Es de 4 bit
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 3203)
        self.management_base.set_sequence_number(0xF234) # Es de 12 bit
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)
        
    def test_09(self):
        'Test Management Frame Data field'
        frame_body="\x00\x00\x01\x00\x00\x00\xdd\x09\x00\x10\x18\x02\x00\x10\x00\x00\x00"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management Frame Authentication Algorithm field' 
        self.assertEqual(self.management_authentication.get_authentication_algorithm(), 0x0000)
        self.management_authentication.set_authentication_algorithm(0x8765)
        self.assertEqual(self.management_authentication.get_authentication_algorithm(), 0x8765)

    def test_11(self):
        'Test Management Frame Authentication Sequence field' 
        self.assertEqual(self.management_authentication.get_authentication_sequence(), 0x0001)
        self.management_authentication.set_authentication_sequence(0x8765)
        self.assertEqual(self.management_authentication.get_authentication_sequence(), 0x8765)

    def test_12(self):
        'Test Management Frame Authentication Status field' 
        self.assertEqual(self.management_authentication.get_authentication_status(), 0x0000)
        self.management_authentication.set_authentication_status(0x8765)
        self.assertEqual(self.management_authentication.get_authentication_status(), 0x8765)

    def test_13(self):
        'Test Management Vendor Specific getter/setter methods'
        self.assertEqual(self.management_authentication.get_vendor_specific(), [("\x00\x10\x18","\x02\x00\x10\x00\x00\x00")])
        self.management_authentication.add_vendor_specific("\x00\x00\x40","\x04\x04\x04\x04\x04\x04")

        self.assertEqual(self.management_authentication.get_vendor_specific(), 
            [("\x00\x10\x18","\x02\x00\x10\x00\x00\x00"),
             ("\x00\x00\x40","\x04\x04\x04\x04\x04\x04"),
            ])
        self.assertEqual(self.management_authentication.get_header_size(), 28)
class TestDot11ManagementAssociationRequestFrames(unittest.TestCase):

    def setUp(self):
        # 802.11 Management Frame 
        #
	self.rawframe="\x00\x00\x1c\x00\xef\x18\x00\x00jH\xfa\x00<\x00\x00\x00\x10\x02\x85\t\xa0\x00\xb9\x9e_\x00\x00\x1b\x00\x00:\x01\x00\x18\xf8lvBp\x1a\x04T\xe3\x86\x00\x18\xf8lvBP\x8e1\x04\n\x00\x00\x05ddwrt\x01\x08\x82\x84\x8b\x96$0Hl!\x02\n\x11$\x02\x01\x0e0\x14\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\x08\x002\x04\x0c\x12\x18`\xdd\t\x00\x10\x18\x02\x00\x10\x00\x00\x00\xbf]o\xce"
        self.radiotap_decoder = RadioTapDecoder()
        radiotap=self.radiotap_decoder.decode(self.rawframe)

        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")

        self.dot11=radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")

        type = self.dot11.get_type()
        self.assertEqual(type,Dot11Types.DOT11_TYPE_MANAGEMENT)
        
        subtype = self.dot11.get_subtype()
        self.assertEqual(subtype,Dot11Types.DOT11_SUBTYPE_MANAGEMENT_ASSOCIATION_REQUEST)
        
        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(typesubtype,Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_ASSOCIATION_REQUEST)
        
        self.management_base=self.dot11.child()
        self.assertEqual(str(self.management_base.__class__), "dot11.Dot11ManagementFrame")
        
        self.management_association_request=self.management_base.child()
        self.assertEqual(str(self.management_association_request.__class__), "dot11.Dot11ManagementAssociationRequest")
            
        
    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(self.management_association_request.get_header_size(), 68)
	self.assertEqual(self.management_association_request.get_tail_size(), 0)
        
    def test_02(self):
        'Test Duration field'
        
        self.assertEqual(self.management_base.get_duration(), 0x013a)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)
    
    def test_03(self):
        'Test Destination Address field'
        
        addr=self.management_base.get_destination_address()
        
        self.assertEqual(addr.tolist(), [0x00,0x18,0xF8,0x6C,0x76,0x42])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(self.management_base.get_destination_address().tolist(), [0x12,0x18,0xF8,0x6C,0x76,0x34])

    def test_04(self):
        'Test Source Address field'
        
        addr=self.management_base.get_source_address()
        
        self.assertEqual(addr.tolist(), [0x70,0x1A,0x04,0x54,0xE3,0x86])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(), [0x12,0x1A,0x04,0x54,0xE3,0x34])

    def test_05(self):
        'Test BSSID Address field'
        
        addr=self.management_base.get_bssid()
        
        self.assertEqual(addr.tolist(), [0x00,0x18,0xF8,0x6C,0x76,0x42])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(), [0x12,0x18,0xF8,0x6C,0x76,0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0x8e50)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1) # Es de 4 bit
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 2277)
        self.management_base.set_sequence_number(0xF234) # Es de 12 bit
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)
        
    def test_09(self):
        'Test Management Frame Data field'
        frame_body="1\x04\n\x00\x00\x05ddwrt\x01\x08\x82\x84\x8b\x96$0Hl!\x02\n\x11$\x02\x01\x0e0\x14\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\x08\x002\x04\x0c\x12\x18`\xdd\t\x00\x10\x18\x02\x00\x10\x00\x00\x00"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management Association Request Capabilities field' 
        self.assertEqual(self.management_association_request.get_capabilities(), 0x0431)
        self.management_association_request.set_capabilities(0x4321) 
        self.assertEqual(self.management_association_request.get_capabilities(), 0x4321)

    def test_11(self):
        'Test Management Association Request Listen Interval field' 
        self.assertEqual(self.management_association_request.get_listen_interval(), 0x000a)
        self.management_association_request.set_listen_interval(0x4321) 
        self.assertEqual(self.management_association_request.get_listen_interval(), 0x4321)

    def test_12(self):
        'Test Management Association Request Ssid getter/setter methods'
        act_ssid="ddwrt"
        new_ssid="holala"
        self.assertEqual(self.management_association_request.get_ssid(), act_ssid)
        self.management_association_request.set_ssid(new_ssid)
        self.assertEqual(self.management_association_request.get_ssid(), new_ssid)
        self.assertEqual(self.management_association_request.get_header_size(), 68+1)

    def test_13(self):
        'Test Management Association Request Supported_rates getter/setter methods'
	self.assertEqual(self.management_association_request.get_supported_rates(), (0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c))
        self.assertEqual(self.management_association_request.get_supported_rates(human_readable=True), (1.0, 2.0, 5.5, 11.0, 18.0, 24.0, 36.0, 54.0))
        
        self.management_association_request.set_supported_rates((0x12, 0x98, 0x24, 0xb0, 0x48, 0x60))

        self.assertEqual(self.management_association_request.get_supported_rates(), (0x12, 0x98, 0x24, 0xb0, 0x48, 0x60))
        self.assertEqual(self.management_association_request.get_supported_rates(human_readable=True), (9.0, 12.0, 18.0, 24.0, 36.0, 48.0))
        self.assertEqual(self.management_association_request.get_header_size(), 68-2)

    def test_14(self):
        'Test Management Association Request RSN getter/setter methods'
	self.assertEqual(self.management_association_request.get_rsn(), "\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\x08\x00")
        
        self.management_association_request.set_rsn("\xff\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\x08\xff")

        self.assertEqual(self.management_association_request.get_rsn(), "\xff\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\x08\xff")
        self.assertEqual(self.management_association_request.get_header_size(), 68)

    def test_15(self):
        'Test Management Vendor Specific getter/setter methods'
        self.assertEqual(self.management_association_request.get_vendor_specific(), [("\x00\x10\x18","\x02\x00\x10\x00\x00\x00")])

        self.management_association_request.add_vendor_specific("\x00\x00\x40", "\x04\x04\x04\x04\x04\x04")

        self.assertEqual(self.management_association_request.get_vendor_specific(), 
            [("\x00\x10\x18", "\x02\x00\x10\x00\x00\x00"),
             ("\x00\x00\x40", "\x04\x04\x04\x04\x04\x04"),
            ])
        self.assertEqual(self.management_association_request.get_header_size(), 68+11)
class TestDot11ManagementProbeRequestFrames(unittest.TestCase):

    def setUp(self):
        # 802.11 Management Frame 
        #
        self.rawProbeRequestframe='\x00\x00\x18\x00\x2e\x48\x00\x00\x00\x02\x85\x09\xa0\x00\xda\x01\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\xff\xff\xff\xff\xff\xff\x00\x23\x4d\x13\xf9\x1b\xff\xff\xff\xff\xff\xff\x90\x45\x00\x05\x64\x6c\x69\x6e\x6b\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24\x32\x04\x30\x48\x60\x6c'
        self.radiotap_decoder = RadioTapDecoder()
        radiotap=self.radiotap_decoder.decode(self.rawProbeRequestframe)
        
        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")      
                
        self.dot11=radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")   

        type = self.dot11.get_type()
        self.assertEqual(type,Dot11Types.DOT11_TYPE_MANAGEMENT)
        
        subtype = self.dot11.get_subtype()
        self.assertEqual(subtype,Dot11Types.DOT11_SUBTYPE_MANAGEMENT_PROBE_REQUEST)
        
        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(typesubtype,Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_PROBE_REQUEST)
        
        self.management_base=self.dot11.child()
        self.assertEqual(str(self.management_base.__class__), "dot11.Dot11ManagementFrame")   
        
        self.management_probe_request=self.management_base.child()
        self.assertEqual(str(self.management_probe_request.__class__), "dot11.Dot11ManagementProbeRequest")   
            
        
    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(self.management_probe_request.get_header_size(), 23)
        self.assertEqual(self.management_probe_request.get_tail_size(), 0)
        
    def test_02(self):
        'Test Duration field'
        
        self.assertEqual(self.management_base.get_duration(), 0x0000)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)
    
    def test_03(self):
        'Test Destination Address field'
        
        addr=self.management_base.get_destination_address()
        
        self.assertEqual(addr.tolist(), [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(self.management_base.get_destination_address().tolist(), [0x12,0xFF,0xFF,0xFF,0xFF,0x34])

    def test_04(self):
        'Test Source Address field'
        
        addr=self.management_base.get_source_address()
        
        self.assertEqual(addr.tolist(), [0x00,0x23,0x4d,0x13,0xf9,0x1b])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(), [0x12,0x23,0x4d,0x13,0xf9,0x34])

    def test_05(self):
        'Test BSSID Address field'
        
        addr=self.management_base.get_bssid()
        
        self.assertEqual(addr.tolist(), [0xff,0xff,0xff,0xff,0xff,0xff])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(), [0x12,0xff,0xff,0xff,0xff,0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0x4590)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1) # Es de 4 bit
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 1113)
        self.management_base.set_sequence_number(0xF234) # Es de 12 bit
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)
        
    def test_09(self):
        'Test Management Frame Data field'
        frame_body="\x00\x05\x64\x6c\x69\x6e\x6b\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24\x32\x04\x30\x48\x60\x6c"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management ssid getter/setter methods'
        act_ssid="dlink"
        new_ssid="holala"
        self.assertEqual(self.management_probe_request.get_ssid(), act_ssid)
        self.management_probe_request.set_ssid(new_ssid)
        self.assertEqual(self.management_probe_request.get_ssid(), new_ssid)
        self.assertEqual(self.management_probe_request.get_header_size(), 23+len(new_ssid)-len(act_ssid))

    def test_11(self):
        'Test Management supported_rates getter/setter methods'
        self.assertEqual(self.management_probe_request.get_supported_rates(), (0x02,0x04,0x0b,0x16,0x0c,0x12,0x18,0x24) )
        self.assertEqual(self.management_probe_request.get_supported_rates(human_readable=True), (1.0, 2.0, 5.5, 11.0, 6.0, 9.0, 12.0, 18.0) )
        self.management_probe_request.set_supported_rates((0x04,0x0b,0x16,0x0c,0x12,0x18))
        self.assertEqual(self.management_probe_request.get_supported_rates(), (0x04,0x0b,0x16,0x0c,0x12,0x18))
        self.assertEqual(self.management_probe_request.get_supported_rates(human_readable=True), (2.0, 5.5, 11.0, 6.0, 9.0, 12.0) )
        self.assertEqual(self.management_probe_request.get_header_size(), 23-2)
Esempio n. 14
0
class TestRadioTapDecoder(unittest.TestCase):

    def setUp(self):
        self.RadioTapData='\x00\x00\x20\x00\x67\x08\x04\x00\x30\x03\x1a\x25\x00\x00\x00\x00\x22\x0c\xd9\xa0\x02\x00\x00\x00\x40\x01\x00\x00\x3c\x14\x24\x11\x08\x02\x00\x00\xff\xff\xff\xff\xff\xff\x06\x03\x7f\x07\xa0\x16\x00\x19\xe3\xd3\x53\x52\x90\x7f\xaa\xaa\x03\x00\x00\x00\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x19\xe3\xd3\x53\x52\xa9\xfe\xf7\x00\x00\x00\x00\x00\x00\x00\x43\x08\x0e\x36'
        self.radiotap_decoder = RadioTapDecoder()
        self.in0=self.radiotap_decoder.decode(self.RadioTapData)
        self.in1=self.in0.child()
        self.in2=self.in1.child()
        self.in3=self.in2.child()
        self.in4=self.in3.child()
        self.in5=self.in4.child()
        self.in6=self.in5.child()
        
    def test_00(self):
        'Test RadioTap decoder'
        self.assertEqual(str(self.in0.__class__), "dot11.RadioTap")
        
    def test_01(self):
        'Test Dot11 decoder'
        self.assertEqual(str(self.in1.__class__), "dot11.Dot11")
        
    def test_02(self):
        'Test Dot11DataFrame decoder'
        self.assertEqual(str(self.in2.__class__), "dot11.Dot11DataFrame")
    
    def test_03(self):
        'Test LLC decoder'
        self.assertEqual(str(self.in3.__class__), "dot11.LLC")

    def test_04(self):
        'Test SNAP decoder'
        self.assertEqual(str(self.in4.__class__), "dot11.SNAP")

#    def test_05(self):
#        'Test ARP decoder'
#        self.assertEqual(str(self.in5.__class__), "ImpactPacket.ARP")

#    def test_05(self):
#        'Test Data decoder'
#        self.assertEqual(str(self.in6.__class__), "ImpactPacket.Data")
        
    def test_06(self):
        'Test Protocol Finder'
        p=self.radiotap_decoder.get_protocol(dot11.RadioTap)
        self.assertEqual(str(p.__class__), "dot11.RadioTap")
                
        p=self.radiotap_decoder.get_protocol(dot11.Dot11)
        self.assertEqual(str(p.__class__), "dot11.Dot11")
        
        p=self.radiotap_decoder.get_protocol(dot11.Dot11DataFrame)
        self.assertEqual(str(p.__class__), "dot11.Dot11DataFrame")
        
        p=self.radiotap_decoder.get_protocol(dot11.LLC)
        self.assertEqual(str(p.__class__), "dot11.LLC")
        
        p=self.radiotap_decoder.get_protocol(dot11.SNAP)
        self.assertEqual(str(p.__class__), "dot11.SNAP")
        
        #p=self.radiotap_decoder.get_protocol(ImpactPacket.ARP)
        #self.assertEqual(str(p.__class__), "ImpactPacket.ARP")
        
        #p=self.radiotap_decoder.get_protocol(ImpactPacket.Data)
        #self.assertEqual(str(p.__class__), "ImpactPacket.Data")
        
        # When not found, None is returned
        p=self.radiotap_decoder.get_protocol(dot11.Dot11WPA)
        self.assertEqual(p, None)
class TestDot11ManagementDisassociationFrames(unittest.TestCase):

    def setUp(self):
        # 802.11 Management Frame 
        #
	self.rawframe="\x00\x00\x1c\x00\xef\x18\x00\x00\xe7\x8a\xec\xb8\x3b\x00\x00\x00\x10\x02\x85\x09\xa0\x00\xb5\x9d\x60\x00\x00\x18\xa0\x00\x3a\x01\x00\x18\xf8\x6c\x76\x42\x70\x1a\x04\x54\xe3\x86\x00\x18\xf8\x6c\x76\x42\x70\x92\x08\x00\xbf\x1b\xa3\xa8"
        self.radiotap_decoder = RadioTapDecoder()
        radiotap=self.radiotap_decoder.decode(self.rawframe)

        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")

        self.dot11=radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")

        type = self.dot11.get_type()
        self.assertEqual(type,Dot11Types.DOT11_TYPE_MANAGEMENT)
        
        subtype = self.dot11.get_subtype()
        self.assertEqual(subtype,Dot11Types.DOT11_SUBTYPE_MANAGEMENT_DISASSOCIATION)
        
        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(typesubtype,Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_DISASSOCIATION)
        
        self.management_base=self.dot11.child()
        self.assertEqual(str(self.management_base.__class__), "dot11.Dot11ManagementFrame")
        
        self.management_disassociation=self.management_base.child()
        self.assertEqual(str(self.management_disassociation.__class__), "dot11.Dot11ManagementDisassociation")
            
        
    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(self.management_disassociation.get_header_size(), 2)
        self.assertEqual(self.management_disassociation.get_tail_size(), 0)
        
    def test_02(self):
        'Test Duration field'
        
        self.assertEqual(self.management_base.get_duration(), 0x013a)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)
    
    def test_03(self):
        'Test Destination Address field'
        
        addr=self.management_base.get_destination_address()
        
        self.assertEqual(addr.tolist(), [0x00,0x18,0xF8,0x6C,0x76,0x42])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(self.management_base.get_destination_address().tolist(), [0x12,0x18,0xF8,0x6C,0x76,0x34])

    def test_04(self):
        'Test Source Address field'
        
        addr=self.management_base.get_source_address()
        
        self.assertEqual(addr.tolist(), [0x70,0x1A,0x04,0x54,0xE3,0x86])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(), [0x12,0x1A,0x04,0x54,0xE3,0x34])

    def test_05(self):
        'Test BSSID Address field'
        
        addr=self.management_base.get_bssid()
        
        self.assertEqual(addr.tolist(), [0x00,0x18,0xF8,0x6C,0x76,0x42])
        addr[0]=0x12
        addr[5]=0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(), [0x12,0x18,0xF8,0x6C,0x76,0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0x9270)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1) # Es de 4 bit
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 2343)
        self.management_base.set_sequence_number(0xF234) # Es de 12 bit
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)
        
    def test_09(self):
        'Test Management Frame Data field'
        frame_body="\x08\x00"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management Reason Code field' 
        self.assertEqual(self.management_disassociation.get_reason_code(), 0x0008)
        self.management_disassociation.set_reason_code(0x8765)
        self.assertEqual(self.management_disassociation.get_reason_code(), 0x8765)
Esempio n. 16
0
class TestDot11ManagementAssociationRequestFrames(unittest.TestCase):
    def setUp(self):
        # 802.11 Management Frame
        #
        self.rawframe = "\x00\x00\x1c\x00\xef\x18\x00\x00jH\xfa\x00<\x00\x00\x00\x10\x02\x85\t\xa0\x00\xb9\x9e_\x00\x00\x1b\x00\x00:\x01\x00\x18\xf8lvBp\x1a\x04T\xe3\x86\x00\x18\xf8lvBP\x8e1\x04\n\x00\x00\x05ddwrt\x01\x08\x82\x84\x8b\x96$0Hl!\x02\n\x11$\x02\x01\x0e0\x14\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\x08\x002\x04\x0c\x12\x18`\xdd\t\x00\x10\x18\x02\x00\x10\x00\x00\x00\xbf]o\xce"
        self.radiotap_decoder = RadioTapDecoder()
        radiotap = self.radiotap_decoder.decode(self.rawframe)

        self.assertEqual(str(radiotap.__class__), "dot11.RadioTap")

        self.dot11 = radiotap.child()
        self.assertEqual(str(self.dot11.__class__), "dot11.Dot11")

        type = self.dot11.get_type()
        self.assertEqual(type, Dot11Types.DOT11_TYPE_MANAGEMENT)

        subtype = self.dot11.get_subtype()
        self.assertEqual(
            subtype, Dot11Types.DOT11_SUBTYPE_MANAGEMENT_ASSOCIATION_REQUEST)

        typesubtype = self.dot11.get_type_n_subtype()
        self.assertEqual(
            typesubtype,
            Dot11Types.DOT11_TYPE_MANAGEMENT_SUBTYPE_ASSOCIATION_REQUEST)

        self.management_base = self.dot11.child()
        self.assertEqual(str(self.management_base.__class__),
                         "dot11.Dot11ManagementFrame")

        self.management_association_request = self.management_base.child()
        self.assertEqual(str(self.management_association_request.__class__),
                         "dot11.Dot11ManagementAssociationRequest")

    def test_01(self):
        'Test Header and Tail Size field'
        self.assertEqual(self.management_base.get_header_size(), 22)
        self.assertEqual(self.management_base.get_tail_size(), 0)
        self.assertEqual(self.management_association_request.get_header_size(),
                         68)
        self.assertEqual(self.management_association_request.get_tail_size(),
                         0)

    def test_02(self):
        'Test Duration field'

        self.assertEqual(self.management_base.get_duration(), 0x013a)
        self.management_base.set_duration(0x1234)
        self.assertEqual(self.management_base.get_duration(), 0x1234)

    def test_03(self):
        'Test Destination Address field'

        addr = self.management_base.get_destination_address()

        self.assertEqual(addr.tolist(), [0x00, 0x18, 0xF8, 0x6C, 0x76, 0x42])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_destination_address(addr)
        self.assertEqual(
            self.management_base.get_destination_address().tolist(),
            [0x12, 0x18, 0xF8, 0x6C, 0x76, 0x34])

    def test_04(self):
        'Test Source Address field'

        addr = self.management_base.get_source_address()

        self.assertEqual(addr.tolist(), [0x70, 0x1A, 0x04, 0x54, 0xE3, 0x86])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_source_address(addr)
        self.assertEqual(self.management_base.get_source_address().tolist(),
                         [0x12, 0x1A, 0x04, 0x54, 0xE3, 0x34])

    def test_05(self):
        'Test BSSID Address field'

        addr = self.management_base.get_bssid()

        self.assertEqual(addr.tolist(), [0x00, 0x18, 0xF8, 0x6C, 0x76, 0x42])
        addr[0] = 0x12
        addr[5] = 0x34
        self.management_base.set_bssid(addr)
        self.assertEqual(self.management_base.get_bssid().tolist(),
                         [0x12, 0x18, 0xF8, 0x6C, 0x76, 0x34])

    def test_06(self):
        'Test Sequence control field'
        self.assertEqual(self.management_base.get_sequence_control(), 0x8e50)
        self.management_base.set_sequence_control(0x1234)
        self.assertEqual(self.management_base.get_sequence_control(), 0x1234)

    def test_07(self):
        'Test Fragment number field'
        self.assertEqual(self.management_base.get_fragment_number(), 0x00)
        self.management_base.set_fragment_number(0xF1)  # Es de 4 bit
        self.assertEqual(self.management_base.get_fragment_number(), 0x01)

    def test_08(self):
        'Test Sequence number field'
        self.assertEqual(self.management_base.get_sequence_number(), 2277)
        self.management_base.set_sequence_number(0xF234)  # Es de 12 bit
        self.assertEqual(self.management_base.get_sequence_number(), 0x0234)

    def test_09(self):
        'Test Management Frame Data field'
        frame_body = "1\x04\n\x00\x00\x05ddwrt\x01\x08\x82\x84\x8b\x96$0Hl!\x02\n\x11$\x02\x01\x0e0\x14\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\x08\x002\x04\x0c\x12\x18`\xdd\t\x00\x10\x18\x02\x00\x10\x00\x00\x00"
        self.assertEqual(self.management_base.get_frame_body(), frame_body)

    def test_10(self):
        'Test Management Association Request Capabilities field'
        self.assertEqual(
            self.management_association_request.get_capabilities(), 0x0431)
        self.management_association_request.set_capabilities(0x4321)
        self.assertEqual(
            self.management_association_request.get_capabilities(), 0x4321)

    def test_11(self):
        'Test Management Association Request Listen Interval field'
        self.assertEqual(
            self.management_association_request.get_listen_interval(), 0x000a)
        self.management_association_request.set_listen_interval(0x4321)
        self.assertEqual(
            self.management_association_request.get_listen_interval(), 0x4321)

    def test_12(self):
        'Test Management Association Request Ssid getter/setter methods'
        act_ssid = "ddwrt"
        new_ssid = "holala"
        self.assertEqual(self.management_association_request.get_ssid(),
                         act_ssid)
        self.management_association_request.set_ssid(new_ssid)
        self.assertEqual(self.management_association_request.get_ssid(),
                         new_ssid)
        self.assertEqual(self.management_association_request.get_header_size(),
                         68 + 1)

    def test_13(self):
        'Test Management Association Request Supported_rates getter/setter methods'
        self.assertEqual(
            self.management_association_request.get_supported_rates(),
            (0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c))
        self.assertEqual(
            self.management_association_request.get_supported_rates(
                human_readable=True),
            (1.0, 2.0, 5.5, 11.0, 18.0, 24.0, 36.0, 54.0))

        self.management_association_request.set_supported_rates(
            (0x12, 0x98, 0x24, 0xb0, 0x48, 0x60))

        self.assertEqual(
            self.management_association_request.get_supported_rates(),
            (0x12, 0x98, 0x24, 0xb0, 0x48, 0x60))
        self.assertEqual(
            self.management_association_request.get_supported_rates(
                human_readable=True), (9.0, 12.0, 18.0, 24.0, 36.0, 48.0))
        self.assertEqual(self.management_association_request.get_header_size(),
                         68 - 2)

    def test_14(self):
        'Test Management Association Request RSN getter/setter methods'
        self.assertEqual(
            self.management_association_request.get_rsn(),
            "\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\x08\x00"
        )

        self.management_association_request.set_rsn(
            "\xff\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\x08\xff"
        )

        self.assertEqual(
            self.management_association_request.get_rsn(),
            "\xff\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\x08\xff"
        )
        self.assertEqual(self.management_association_request.get_header_size(),
                         68)

    def test_15(self):
        'Test Management Vendor Specific getter/setter methods'
        self.assertEqual(
            self.management_association_request.get_vendor_specific(),
            [("\x00\x10\x18", "\x02\x00\x10\x00\x00\x00")])

        self.management_association_request.add_vendor_specific(
            "\x00\x00\x40", "\x04\x04\x04\x04\x04\x04")

        self.assertEqual(
            self.management_association_request.get_vendor_specific(), [
                ("\x00\x10\x18", "\x02\x00\x10\x00\x00\x00"),
                ("\x00\x00\x40", "\x04\x04\x04\x04\x04\x04"),
            ])
        self.assertEqual(self.management_association_request.get_header_size(),
                         68 + 11)