xref: /freebsd/contrib/wpa/wpa_supplicant/examples/wpas-dbus-new-wps.py (revision d3d381b2b194b4d24853e92eecef55f262688d1a)
1#!/usr/bin/python
2
3import dbus
4import sys, os
5import time
6import gobject
7from dbus.mainloop.glib import DBusGMainLoop
8
9WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
10WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
11WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
12
13WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
14WPAS_DBUS_WPS_INTERFACE = "fi.w1.wpa_supplicant1.Interface.WPS"
15
16def propertiesChanged(properties):
17	if properties.has_key("State"):
18		print "PropertiesChanged: State: %s" % (properties["State"])
19
20def scanDone(success):
21	print "Scan done: success=%s" % success
22
23def bssAdded(bss, properties):
24	print "BSS added: %s" % (bss)
25
26def bssRemoved(bss):
27	print "BSS removed: %s" % (bss)
28
29def wpsEvent(name, args):
30	print "WPS event: %s" % (name)
31	print args
32
33def credentials(cred):
34	print "WPS credentials: %s" % (cred)
35
36def main():
37	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
38	global bus
39	bus = dbus.SystemBus()
40	wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
41
42	if len(sys.argv) != 2:
43		print "Missing ifname argument"
44		os._exit(1)
45
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,
61				signal_name="Event")
62	bus.add_signal_receiver(credentials,
63				dbus_interface=WPAS_DBUS_WPS_INTERFACE,
64				signal_name="Credentials")
65
66	ifname = sys.argv[1]
67
68	path = wpas.GetInterface(ifname)
69	if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
70	if_obj.Set(WPAS_DBUS_WPS_INTERFACE, 'ProcessCredentials',
71		   dbus.Boolean(1),
72		   dbus_interface=dbus.PROPERTIES_IFACE)
73	wps = dbus.Interface(if_obj, WPAS_DBUS_WPS_INTERFACE)
74	wps.Start({'Role': 'enrollee', 'Type': 'pbc'})
75
76	gobject.MainLoop().run()
77
78if __name__ == "__main__":
79	main()
80
81