2010-01-01 21:34:15 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import dbus
|
|
|
|
import sys, os
|
|
|
|
import time
|
|
|
|
import gobject
|
|
|
|
from dbus.mainloop.glib import DBusGMainLoop
|
|
|
|
|
|
|
|
WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
|
|
|
|
WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
|
|
|
|
WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
|
|
|
|
|
|
|
|
WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
|
|
|
|
WPAS_DBUS_WPS_INTERFACE = "fi.w1.wpa_supplicant1.Interface.WPS"
|
|
|
|
|
2010-01-04 15:34:06 +01:00
|
|
|
def propertiesChanged(properties):
|
|
|
|
if properties.has_key("State"):
|
2019-01-24 08:45:42 +01:00
|
|
|
print("PropertiesChanged: State: %s" % (properties["State"]))
|
2010-01-01 21:34:15 +01:00
|
|
|
|
|
|
|
def scanDone(success):
|
2019-01-24 08:45:42 +01:00
|
|
|
print("Scan done: success=%s" % success)
|
2010-01-01 21:34:15 +01:00
|
|
|
|
|
|
|
def bssAdded(bss, properties):
|
2019-01-24 08:45:42 +01:00
|
|
|
print("BSS added: %s" % (bss))
|
2010-01-01 21:34:15 +01:00
|
|
|
|
|
|
|
def bssRemoved(bss):
|
2019-01-24 08:45:42 +01:00
|
|
|
print("BSS removed: %s" % (bss))
|
2010-01-01 21:34:15 +01:00
|
|
|
|
|
|
|
def wpsEvent(name, args):
|
2019-01-24 08:45:42 +01:00
|
|
|
print("WPS event: %s" % (name))
|
|
|
|
print(args)
|
2010-01-01 21:34:15 +01:00
|
|
|
|
|
|
|
def credentials(cred):
|
2019-01-24 08:45:42 +01:00
|
|
|
print("WPS credentials: %s" % (cred))
|
2010-01-01 21:34:15 +01:00
|
|
|
|
|
|
|
def main():
|
|
|
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
|
|
|
global bus
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
|
|
|
|
|
|
|
|
if len(sys.argv) != 2:
|
2019-01-24 08:45:42 +01:00
|
|
|
print("Missing ifname argument")
|
2010-01-01 21:34:15 +01:00
|
|
|
os._exit(1)
|
|
|
|
|
|
|
|
wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
|
|
|
|
bus.add_signal_receiver(scanDone,
|
|
|
|
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
|
|
|
|
signal_name="ScanDone")
|
|
|
|
bus.add_signal_receiver(bssAdded,
|
|
|
|
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
|
|
|
|
signal_name="BSSAdded")
|
|
|
|
bus.add_signal_receiver(bssRemoved,
|
|
|
|
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
|
|
|
|
signal_name="BSSRemoved")
|
2010-01-04 15:34:06 +01:00
|
|
|
bus.add_signal_receiver(propertiesChanged,
|
2010-01-01 21:34:15 +01:00
|
|
|
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
|
2010-01-04 15:34:06 +01:00
|
|
|
signal_name="PropertiesChanged")
|
2010-01-01 21:34:15 +01:00
|
|
|
bus.add_signal_receiver(wpsEvent,
|
|
|
|
dbus_interface=WPAS_DBUS_WPS_INTERFACE,
|
|
|
|
signal_name="Event")
|
|
|
|
bus.add_signal_receiver(credentials,
|
|
|
|
dbus_interface=WPAS_DBUS_WPS_INTERFACE,
|
|
|
|
signal_name="Credentials")
|
|
|
|
|
|
|
|
ifname = sys.argv[1]
|
|
|
|
|
|
|
|
path = wpas.GetInterface(ifname)
|
|
|
|
if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
|
2010-01-01 22:04:27 +01:00
|
|
|
if_obj.Set(WPAS_DBUS_WPS_INTERFACE, 'ProcessCredentials',
|
|
|
|
dbus.Boolean(1),
|
|
|
|
dbus_interface=dbus.PROPERTIES_IFACE)
|
2010-01-01 21:34:15 +01:00
|
|
|
wps = dbus.Interface(if_obj, WPAS_DBUS_WPS_INTERFACE)
|
|
|
|
wps.Start({'Role': 'enrollee', 'Type': 'pbc'})
|
|
|
|
|
|
|
|
gobject.MainLoop().run()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
|
|
|
|