wpas-dbus-new-wps.py 2.2 KB

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