def print_handover_select(message): print "Connection Handover Select Message" number_suffix = ('st', 'nd', 'rd', 'th') message = HandoverSelectMessage(message) for i, carrier in enumerate(message.carriers): carrier_type = carrier['carrier-type'] if carrier_type == "application/vnd.wfa.wsc": carrier_name = "Wi-Fi (Simple Config)" elif carrier_type == "application/vnd.bluetooth.ep.oob": carrier_name = "Bluetooth (Easy Pairing)" else: carrier_name = carrier_type print " %d%s carrier" % (i + 1, number_suffix[min(i, 3)]), print "is %s" % carrier_name print " power = %s" % carrier['power-state'] config_data = carrier['config-data'] if carrier_type == "application/vnd.wfa.wsc": cfg = WiFiConfigData.fromstring(config_data) print " version = %d.%d" % cfg.version print " network = %s" % cfg.ssid print " password = %s" % cfg.network_key print " macaddr = %s" % cfg.mac_address print " security = %s / %s" % \ (cfg.authentication, cfg.encryption) elif carrier_type == "application/vnd.bluetooth.ep.oob": cfg = BluetoothConfigData.fromstring(config_data) print " bdaddr = %s" % cfg.device_address print " class = %s" % cfg.class_of_device.encode("hex") print " sp hash = %s" % cfg.simple_pairing_hash print " sp rand = %s" % cfg.simple_pairing_randomizer print " longname = %s" % cfg.long_name print " partname = %s" % cfg.short_name else: print carrier
def print_wifi_token(message): try: data = WiFiPasswordData.fromstring(message[0].data) print " Wi-Fi Password Token" print " version = %d.%d" % data.version print " PK Hash = %s" % data.public_key_hash.encode("hex") print " DevPwdID = %s" % data.device_password_id print " Password = %s" % data.device_password.encode("hex") for key, val in data.other_attributes: print " 0x%04x = %s" % (key, val.encode("hex")) return except ValueError: pass try: data = WiFiConfigData.fromstring(message[0].data) print " Wi-Fi Configuration Token" print " version = %d.%d" % data.version print " network = %s" % data.ssid print " password = %s" % data.network_key print " macaddr = %s" % data.mac_address print " security = %s / %s" % \ (data.authentication, data.encryption) return except ValueError: pass
def print_handover_select(message): print "Connection Handover Select Message" number_suffix = ('st', 'nd', 'rd', 'th') message = HandoverSelectMessage(message) for i, carrier in enumerate(message.carriers): carrier_type = carrier['carrier-type'] if carrier_type == "application/vnd.wfa.wsc": carrier_name = "Wi-Fi (Simple Config)" elif carrier_type == "application/vnd.bluetooth.ep.oob": carrier_name = "Bluetooth (Easy Pairing)" else: carrier_name = carrier_type print " %d%s carrier" % (i+1, number_suffix[min(i,3)]), print "is %s" % carrier_name print " power = %s" % carrier['power-state'] config_data = carrier['config-data'] if carrier_type == "application/vnd.wfa.wsc": cfg = WiFiConfigData.fromstring(config_data) print " version = %d.%d" % cfg.version print " network = %s" % cfg.ssid print " password = %s" % cfg.network_key print " macaddr = %s" % cfg.mac_address print " security = %s / %s" % \ (cfg.authentication, cfg.encryption) elif carrier_type == "application/vnd.bluetooth.ep.oob": cfg = BluetoothConfigData.fromstring(config_data) print " bdaddr = %s" % cfg.device_address print " class = %s" % cfg.class_of_device.encode("hex") print " sp hash = %s" % cfg.simple_pairing_hash print " sp rand = %s" % cfg.simple_pairing_randomizer print " longname = %s" % cfg.long_name print " partname = %s" % cfg.short_name else: print carrier
def write_configuration(tag): print print "Writing Wi-Fi Configuration" wifi_cfg = WiFiConfigData() wifi_cfg.ssid = "HomeNetwork" wifi_cfg.network_key = "secret" wifi_cfg.mac_address = "00:07:E9:4C:A8:1C" wifi_cfg.authentication = "WPA-Personal" wifi_cfg.encryption = "AES" bt21_cfg = BluetoothConfigData() bt21_cfg.device_address = "01:02:03:04:05:06" bt21_cfg.class_of_device = "\x00\x00\x00" bt21_cfg.simple_pairing_hash = range(16) bt21_cfg.simple_pairing_randomizer = [ord(x) for x in os.urandom(16)] bt21_cfg.short_name = "My Device" bt21_cfg.long_name = "My Most Expensive Device" message = HandoverSelectMessage() wifi_carrier = dict() wifi_carrier['carrier-type'] = 'application/vnd.wfa.wsc' wifi_carrier['config-data'] = wifi_cfg.tostring() wifi_carrier['power-state'] = "active" message.carriers.append(wifi_carrier) bt21_carrier = dict() bt21_carrier['carrier-type'] = 'application/vnd.bluetooth.ep.oob' bt21_carrier['config-data'] = bt21_cfg.tostring() bt21_carrier['power-state'] = "active" message.carriers.append(bt21_carrier) print format_data(message.tostring()) if tag: tag.ndef.message = message.tostring() return