1e28a4053SRui Paulo#!/usr/bin/python 2e28a4053SRui Paulo 3e28a4053SRui Pauloimport dbus 4e28a4053SRui Pauloimport sys, os 5e28a4053SRui Pauloimport time 6e28a4053SRui Pauloimport gobject 7e28a4053SRui Paulofrom dbus.mainloop.glib import DBusGMainLoop 8e28a4053SRui Paulo 9e28a4053SRui PauloWPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1" 10e28a4053SRui PauloWPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1" 11e28a4053SRui PauloWPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1" 12e28a4053SRui Paulo 13e28a4053SRui PauloWPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface" 14e28a4053SRui PauloWPAS_DBUS_WPS_INTERFACE = "fi.w1.wpa_supplicant1.Interface.WPS" 15e28a4053SRui Paulo 16e28a4053SRui Paulodef propertiesChanged(properties): 17e28a4053SRui Paulo if properties.has_key("State"): 18*4bc52338SCy Schubert print("PropertiesChanged: State: %s" % (properties["State"])) 19e28a4053SRui Paulo 20e28a4053SRui Paulodef scanDone(success): 21*4bc52338SCy Schubert print("Scan done: success=%s" % success) 22e28a4053SRui Paulo 23e28a4053SRui Paulodef bssAdded(bss, properties): 24*4bc52338SCy Schubert print("BSS added: %s" % (bss)) 25e28a4053SRui Paulo 26e28a4053SRui Paulodef bssRemoved(bss): 27*4bc52338SCy Schubert print("BSS removed: %s" % (bss)) 28e28a4053SRui Paulo 29e28a4053SRui Paulodef wpsEvent(name, args): 30*4bc52338SCy Schubert print("WPS event: %s" % (name)) 31*4bc52338SCy Schubert print(args) 32e28a4053SRui Paulo 33e28a4053SRui Paulodef credentials(cred): 34*4bc52338SCy Schubert print("WPS credentials: %s" % (cred)) 35e28a4053SRui Paulo 36e28a4053SRui Paulodef main(): 37e28a4053SRui Paulo dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) 38e28a4053SRui Paulo global bus 39e28a4053SRui Paulo bus = dbus.SystemBus() 40e28a4053SRui Paulo wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH) 41e28a4053SRui Paulo 42e28a4053SRui Paulo if len(sys.argv) != 2: 43*4bc52338SCy Schubert print("Missing ifname argument") 44e28a4053SRui Paulo os._exit(1) 45e28a4053SRui Paulo 46e28a4053SRui Paulo wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE) 47e28a4053SRui Paulo bus.add_signal_receiver(scanDone, 48e28a4053SRui Paulo dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE, 49e28a4053SRui Paulo signal_name="ScanDone") 50e28a4053SRui Paulo bus.add_signal_receiver(bssAdded, 51e28a4053SRui Paulo dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE, 52e28a4053SRui Paulo signal_name="BSSAdded") 53e28a4053SRui Paulo bus.add_signal_receiver(bssRemoved, 54e28a4053SRui Paulo dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE, 55e28a4053SRui Paulo signal_name="BSSRemoved") 56e28a4053SRui Paulo bus.add_signal_receiver(propertiesChanged, 57e28a4053SRui Paulo dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE, 58e28a4053SRui Paulo signal_name="PropertiesChanged") 59e28a4053SRui Paulo bus.add_signal_receiver(wpsEvent, 60e28a4053SRui Paulo dbus_interface=WPAS_DBUS_WPS_INTERFACE, 61e28a4053SRui Paulo signal_name="Event") 62e28a4053SRui Paulo bus.add_signal_receiver(credentials, 63e28a4053SRui Paulo dbus_interface=WPAS_DBUS_WPS_INTERFACE, 64e28a4053SRui Paulo signal_name="Credentials") 65e28a4053SRui Paulo 66e28a4053SRui Paulo ifname = sys.argv[1] 67e28a4053SRui Paulo 68e28a4053SRui Paulo path = wpas.GetInterface(ifname) 69e28a4053SRui Paulo if_obj = bus.get_object(WPAS_DBUS_SERVICE, path) 70e28a4053SRui Paulo if_obj.Set(WPAS_DBUS_WPS_INTERFACE, 'ProcessCredentials', 71e28a4053SRui Paulo dbus.Boolean(1), 72e28a4053SRui Paulo dbus_interface=dbus.PROPERTIES_IFACE) 73e28a4053SRui Paulo wps = dbus.Interface(if_obj, WPAS_DBUS_WPS_INTERFACE) 74e28a4053SRui Paulo wps.Start({'Role': 'enrollee', 'Type': 'pbc'}) 75e28a4053SRui Paulo 76e28a4053SRui Paulo gobject.MainLoop().run() 77e28a4053SRui Paulo 78e28a4053SRui Pauloif __name__ == "__main__": 79e28a4053SRui Paulo main() 80e28a4053SRui Paulo 81