nl80211: Fix a typo
[hostap-gosc2009.git] / wpa_supplicant / examples / wpas-dbus-new-getall.py
blobea4a48af99616d4490922dfdc339670813b1eb81
1 #!/usr/bin/python
3 import dbus
4 import sys, os
5 import time
6 import gobject
8 WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
9 WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
10 WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
12 WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
13 WPAS_DBUS_INTERFACES_OPATH = "/fi/w1/wpa_supplicant1/Interfaces"
14 WPAS_DBUS_BSS_INTERFACE = "fi.w1.wpa_supplicant1.Interface.BSS"
16 def showBss(bss):
17 net_obj = bus.get_object(WPAS_DBUS_SERVICE, bss)
18 net = dbus.Interface(net_obj, WPAS_DBUS_BSS_INTERFACE)
19 props = net_obj.GetAll(WPAS_DBUS_BSS_INTERFACE,
20 dbus_interface=dbus.PROPERTIES_IFACE)
21 print props
22 props = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Properties',
23 dbus_interface=dbus.PROPERTIES_IFACE)
24 #print props
26 # Convert the byte-array for SSID and BSSID to printable strings
27 bssid = ""
28 for item in props['BSSID']:
29 bssid = bssid + ":%02x" % item
30 bssid = bssid[1:]
31 ssid = byte_array_to_string(props["SSID"])
33 wpa = "no"
34 if props.has_key("WPAIE"):
35 wpa = "yes"
36 wpa2 = "no"
37 if props.has_key("RSNIE"):
38 wpa2 = "yes"
39 freq = 0
40 if props.has_key("Frequency"):
41 freq = props["Frequency"]
42 caps = props["Capabilities"]
43 qual = props["Quality"]
44 level = props["Level"]
45 noise = props["Noise"]
46 maxrate = props["MaxRate"] / 1000000
48 print " %s :: ssid='%s' wpa=%s wpa2=%s quality=%d%% rate=%d freq=%d" % (bssid, ssid, wpa, wpa2, qual, maxrate, freq)
50 def scanDone(success):
51 gobject.MainLoop().quit()
52 print "Scan done: success=%s" % success
54 res = if_obj.Get(WPAS_DBUS_INTERFACES_INTERFACE, 'BSSs',
55 dbus_interface=dbus.PROPERTIES_IFACE)
56 props = if_obj.GetAll(WPAS_DBUS_INTERFACES_INTERFACE,
57 dbus_interface=dbus.PROPERTIES_IFACE)
58 print props
60 print "Scanned wireless networks:"
61 for opath in res:
62 print opath
63 showBss(opath)
65 def main():
66 bus = dbus.SystemBus()
67 wpas_obj = bus.get_object("fi.w1.wpa_supplicant1",
68 "/fi/w1/wpa_supplicant1")
69 props = wpas_obj.GetAll("fi.w1.wpa_supplicant1",
70 dbus_interface=dbus.PROPERTIES_IFACE)
71 print "GetAll(fi.w1.wpa_supplicant1, /fi/w1/wpa_supplicant1):"
72 print props
74 if len(sys.argv) != 2:
75 os._exit(1)
77 ifname = sys.argv[1]
79 wpas = dbus.Interface(wpas_obj, "fi.w1.wpa_supplicant1")
80 path = wpas.GetInterface(ifname)
81 if_obj = bus.get_object("fi.w1.wpa_supplicant1", path)
82 props = if_obj.GetAll("fi.w1.wpa_supplicant1.Interface",
83 dbus_interface=dbus.PROPERTIES_IFACE)
84 print
85 print "GetAll(fi.w1.wpa_supplicant1.Interface, %s):" % (path)
86 print props
88 props = if_obj.GetAll("fi.w1.wpa_supplicant1.Interface.WPS",
89 dbus_interface=dbus.PROPERTIES_IFACE)
90 print
91 print "GetAll(fi.w1.wpa_supplicant1.Interface.WPS, %s):" % (path)
92 print props
94 res = if_obj.Get("fi.w1.wpa_supplicant1.Interface", 'BSSs',
95 dbus_interface=dbus.PROPERTIES_IFACE)
96 if len(res) > 0:
97 bss_obj = bus.get_object("fi.w1.wpa_supplicant1", res[0])
98 props = bss_obj.GetAll("fi.w1.wpa_supplicant1.Interface.BSS",
99 dbus_interface=dbus.PROPERTIES_IFACE)
100 print
101 print "GetAll(fi.w1.wpa_supplicant1.Interface.BSS, %s):" % (res[0])
102 print props
104 res = if_obj.Get("fi.w1.wpa_supplicant1.Interface", 'Networks',
105 dbus_interface=dbus.PROPERTIES_IFACE)
106 if len(res) > 0:
107 net_obj = bus.get_object("fi.w1.wpa_supplicant1", res[0])
108 props = net_obj.GetAll("fi.w1.wpa_supplicant1.Interface.Network",
109 dbus_interface=dbus.PROPERTIES_IFACE)
110 print
111 print "GetAll(fi.w1.wpa_supplicant1.Interface.Network, %s):" % (res[0])
112 print props
114 if __name__ == "__main__":
115 main()