wpas-dbus-new-wps.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 stateChanged(newState, oldState):
  13. print "StateChanged(%s -> %s)" % (oldState, newState)
  14. def scanDone(success):
  15. print "Scan done: success=%s" % success
  16. def bssAdded(bss, properties):
  17. print "BSS added: %s" % (bss)
  18. def bssRemoved(bss):
  19. print "BSS removed: %s" % (bss)
  20. def wpsEvent(name, args):
  21. print "WPS event: %s" % (name)
  22. print args
  23. def credentials(cred):
  24. print "WPS credentials: %s" % (cred)
  25. def main():
  26. dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
  27. global bus
  28. bus = dbus.SystemBus()
  29. wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
  30. if len(sys.argv) != 2:
  31. print "Missing ifname argument"
  32. os._exit(1)
  33. wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
  34. bus.add_signal_receiver(scanDone,
  35. dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
  36. signal_name="ScanDone")
  37. bus.add_signal_receiver(bssAdded,
  38. dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
  39. signal_name="BSSAdded")
  40. bus.add_signal_receiver(bssRemoved,
  41. dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
  42. signal_name="BSSRemoved")
  43. bus.add_signal_receiver(stateChanged,
  44. dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
  45. signal_name="StateChanged")
  46. bus.add_signal_receiver(wpsEvent,
  47. dbus_interface=WPAS_DBUS_WPS_INTERFACE,
  48. signal_name="Event")
  49. bus.add_signal_receiver(credentials,
  50. dbus_interface=WPAS_DBUS_WPS_INTERFACE,
  51. signal_name="Credentials")
  52. ifname = sys.argv[1]
  53. path = wpas.GetInterface(ifname)
  54. global if_obj
  55. if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
  56. global iface
  57. wps = dbus.Interface(if_obj, WPAS_DBUS_WPS_INTERFACE)
  58. wps.Start({'Role': 'enrollee', 'Type': 'pbc'})
  59. gobject.MainLoop().run()
  60. if __name__ == "__main__":
  61. main()