7 from dbus
.mainloop
.glib
import DBusGMainLoop
9 WPAS_DBUS_SERVICE
= "fi.w1.wpa_supplicant1"
10 WPAS_DBUS_INTERFACE
= "fi.w1.wpa_supplicant1"
11 WPAS_DBUS_OPATH
= "/fi/w1/wpa_supplicant1"
13 WPAS_DBUS_INTERFACES_INTERFACE
= "fi.w1.wpa_supplicant1.Interface"
14 WPAS_DBUS_WPS_INTERFACE
= "fi.w1.wpa_supplicant1.Interface.WPS"
16 def propertiesChanged(properties
):
17 if properties
.has_key("State"):
18 print "PropertiesChanged: State: %s" % (properties
["State"])
20 def scanDone(success
):
21 print "Scan done: success=%s" % success
23 def bssAdded(bss
, properties
):
24 print "BSS added: %s" % (bss
)
27 print "BSS removed: %s" % (bss
)
29 def wpsEvent(name
, args
):
30 print "WPS event: %s" % (name
)
33 def credentials(cred
):
34 print "WPS credentials: %s" % (cred
)
37 dbus
.mainloop
.glib
.DBusGMainLoop(set_as_default
=True)
39 bus
= dbus
.SystemBus()
40 wpas_obj
= bus
.get_object(WPAS_DBUS_SERVICE
, WPAS_DBUS_OPATH
)
42 if len(sys
.argv
) != 2:
43 print "Missing ifname argument"
46 wpas
= dbus
.Interface(wpas_obj
, WPAS_DBUS_INTERFACE
)
47 bus
.add_signal_receiver(scanDone
,
48 dbus_interface
=WPAS_DBUS_INTERFACES_INTERFACE
,
49 signal_name
="ScanDone")
50 bus
.add_signal_receiver(bssAdded
,
51 dbus_interface
=WPAS_DBUS_INTERFACES_INTERFACE
,
52 signal_name
="BSSAdded")
53 bus
.add_signal_receiver(bssRemoved
,
54 dbus_interface
=WPAS_DBUS_INTERFACES_INTERFACE
,
55 signal_name
="BSSRemoved")
56 bus
.add_signal_receiver(propertiesChanged
,
57 dbus_interface
=WPAS_DBUS_INTERFACES_INTERFACE
,
58 signal_name
="PropertiesChanged")
59 bus
.add_signal_receiver(wpsEvent
,
60 dbus_interface
=WPAS_DBUS_WPS_INTERFACE
,
62 bus
.add_signal_receiver(credentials
,
63 dbus_interface
=WPAS_DBUS_WPS_INTERFACE
,
64 signal_name
="Credentials")
68 path
= wpas
.GetInterface(ifname
)
69 if_obj
= bus
.get_object(WPAS_DBUS_SERVICE
, path
)
70 if_obj
.Set(WPAS_DBUS_WPS_INTERFACE
, 'ProcessCredentials',
72 dbus_interface
=dbus
.PROPERTIES_IFACE
)
73 wps
= dbus
.Interface(if_obj
, WPAS_DBUS_WPS_INTERFACE
)
74 wps
.Start({'Role': 'enrollee', 'Type': 'pbc'})
76 gobject
.MainLoop().run()
78 if __name__
== "__main__":