def test_wiwo_info_response_frame_fail(self): """ Getting the iface info of the Wiwo Info Response frame shouldn't return the same info that was defined on the info dictionary. """ info = {"iface": "wlan0", "protocol": "IEEE 802.11g", "channels": "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e", "channel": "\x01"} frame_buffer = "\x00\x11\x22\x33\x44\x55" \ "\x00\xde\xad\xbe\xef\x00" \ "\xfa\xfa" \ + chr(WiwoInfoResponseFrame.frametype) \ + "%s%s" % (struct.pack("B", len(info["iface"])), info["iface"]) \ + "%s%s" % (struct.pack("B", len(info["protocol"])), info["protocol"]) \ + "%s%s" % (struct.pack("B", len(info["channels"])), info["channels"]) \ + "%s" % info["channel"] eth = Ethernet(frame_buffer) data = frame_buffer[eth.get_header_size():] wf = WiwoFrame(data) if wf.get_type() == WiwoInfoResponseFrame.frametype: wirf = WiwoInfoResponseFrame(wf.get_body_as_string()) ifaces = wirf.get_interfaces() for iface in ifaces: self.assertNotEqual(0, iface.get_iface_len()) self.assertNotEqual("wlan1", iface.get_iface_as_string()) self.assertNotEqual(0, iface.get_protocol_len()) self.assertNotEqual("IEEE 802.3", iface.get_protocol_as_string()) self.assertNotEqual(0, iface.get_channels_count()) self.assertNotEqual(array.array("b", "\x00\x01"), iface.get_channels()) self.assertNotEqual(14, iface.get_channel())
def test_wiwo_info_response_multiple_interfaces_frame_success(self): """ Getting the iface info of the Wiwo Info Response frame should return the same info that was defined on the info dictionary. """ info_1 = { "iface": "wlan1", "protocol": "IEEE 802.11an", "channels": "\x24\x28\x2c\x30\x34\x38\x3c\x40\x95\x99\x9d\xa1\xa5", "channel": "\x24" } info_2 = { "iface": "wlan0", "protocol": "IEEE 802.11g", "channels": "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e", "channel": "\x01" } frame_buffer = "\x00\x11\x22\x33\x44\x55" \ "\x00\xde\xad\xbe\xef\x00" \ "\xfa\xfa" \ + chr(WiwoInfoResponseFrame.frametype) \ + "%s%s" % (struct.pack("B", len(info_1["iface"])), info_1["iface"]) \ + "%s%s" % (struct.pack("B", len(info_1["protocol"])), info_1["protocol"]) \ + "%s%s" % (struct.pack("B", len(info_1["channels"])), info_1["channels"]) \ + "%s" % info_1["channel"] \ + "%s%s" % (struct.pack("B", len(info_2["iface"])), info_2["iface"]) \ + "%s%s" % (struct.pack("B", len(info_2["protocol"])), info_2["protocol"]) \ + "%s%s" % (struct.pack("B", len(info_2["channels"])), info_2["channels"]) \ + "%s" % info_2["channel"] eth = Ethernet(frame_buffer) data = frame_buffer[eth.get_header_size():] wf = WiwoFrame(data) if wf.get_type() == WiwoInfoResponseFrame.frametype: wirf = WiwoInfoResponseFrame(wf.get_body_as_string()) ifaces = wirf.get_interfaces() self.assertEqual(len(info_1["iface"]), ifaces[0].get_iface_len()) self.assertEqual(info_1["iface"], ifaces[0].get_iface_as_string()) self.assertEqual(len(info_1["protocol"]), ifaces[0].get_protocol_len()) self.assertEqual(info_1["protocol"], ifaces[0].get_protocol_as_string()) self.assertEqual(len(info_1["channels"]), ifaces[0].get_channels_count()) self.assertEqual(array.array("B", info_1["channels"]), ifaces[0].get_channels()) self.assertEqual(len(info_2["iface"]), ifaces[1].get_iface_len()) self.assertEqual(info_2["iface"], ifaces[1].get_iface_as_string()) self.assertEqual(len(info_2["protocol"]), ifaces[1].get_protocol_len()) self.assertEqual(info_2["protocol"], ifaces[1].get_protocol_as_string()) self.assertEqual(len(info_2["channels"]), ifaces[1].get_channels_count()) self.assertEqual(array.array("B", info_2["channels"]), ifaces[1].get_channels())
def test_wiwo_info_response_multiple_interfaces_frame_success(self): """ Getting the iface info of the Wiwo Info Response frame should return the same info that was defined on the info dictionary. """ info_1 = {"iface": "wlan1", "protocol": "IEEE 802.11an", "channels": "\x24\x28\x2c\x30\x34\x38\x3c\x40\x95\x99\x9d\xa1\xa5", "channel": "\x24"} info_2 = {"iface": "wlan0", "protocol": "IEEE 802.11g", "channels": "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e", "channel": "\x01"} frame_buffer = "\x00\x11\x22\x33\x44\x55" \ "\x00\xde\xad\xbe\xef\x00" \ "\xfa\xfa" \ + chr(WiwoInfoResponseFrame.frametype) \ + "%s%s" % (struct.pack("B", len(info_1["iface"])), info_1["iface"]) \ + "%s%s" % (struct.pack("B", len(info_1["protocol"])), info_1["protocol"]) \ + "%s%s" % (struct.pack("B", len(info_1["channels"])), info_1["channels"]) \ + "%s" % info_1["channel"] \ + "%s%s" % (struct.pack("B", len(info_2["iface"])), info_2["iface"]) \ + "%s%s" % (struct.pack("B", len(info_2["protocol"])), info_2["protocol"]) \ + "%s%s" % (struct.pack("B", len(info_2["channels"])), info_2["channels"]) \ + "%s" % info_2["channel"] eth = Ethernet(frame_buffer) data = frame_buffer[eth.get_header_size():] wf = WiwoFrame(data) if wf.get_type() == WiwoInfoResponseFrame.frametype: wirf = WiwoInfoResponseFrame(wf.get_body_as_string()) ifaces = wirf.get_interfaces() self.assertEqual(len(info_1["iface"]), ifaces[0].get_iface_len()) self.assertEqual(info_1["iface"], ifaces[0].get_iface_as_string()) self.assertEqual(len(info_1["protocol"]), ifaces[0].get_protocol_len()) self.assertEqual(info_1["protocol"], ifaces[0].get_protocol_as_string()) self.assertEqual(len(info_1["channels"]), ifaces[0].get_channels_count()) self.assertEqual(array.array("B", info_1["channels"]), ifaces[0].get_channels()) self.assertEqual(len(info_2["iface"]), ifaces[1].get_iface_len()) self.assertEqual(info_2["iface"], ifaces[1].get_iface_as_string()) self.assertEqual(len(info_2["protocol"]), ifaces[1].get_protocol_len()) self.assertEqual(info_2["protocol"], ifaces[1].get_protocol_as_string()) self.assertEqual(len(info_2["channels"]), ifaces[1].get_channels_count()) self.assertEqual(array.array("B", info_2["channels"]), ifaces[1].get_channels())
def test_wiwo_info_response_frame_fail(self): """ Getting the iface info of the Wiwo Info Response frame shouldn't return the same info that was defined on the info dictionary. """ info = { "iface": "wlan0", "protocol": "IEEE 802.11g", "channels": "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e", "channel": "\x01" } frame_buffer = "\x00\x11\x22\x33\x44\x55" \ "\x00\xde\xad\xbe\xef\x00" \ "\xfa\xfa" \ + chr(WiwoInfoResponseFrame.frametype) \ + "%s%s" % (struct.pack("B", len(info["iface"])), info["iface"]) \ + "%s%s" % (struct.pack("B", len(info["protocol"])), info["protocol"]) \ + "%s%s" % (struct.pack("B", len(info["channels"])), info["channels"]) \ + "%s" % info["channel"] eth = Ethernet(frame_buffer) data = frame_buffer[eth.get_header_size():] wf = WiwoFrame(data) if wf.get_type() == WiwoInfoResponseFrame.frametype: wirf = WiwoInfoResponseFrame(wf.get_body_as_string()) ifaces = wirf.get_interfaces() for iface in ifaces: self.assertNotEqual(0, iface.get_iface_len()) self.assertNotEqual("wlan1", iface.get_iface_as_string()) self.assertNotEqual(0, iface.get_protocol_len()) self.assertNotEqual("IEEE 802.3", iface.get_protocol_as_string()) self.assertNotEqual(0, iface.get_channels_count()) self.assertNotEqual(array.array("b", "\x00\x01"), iface.get_channels()) self.assertNotEqual(14, iface.get_channel())