7 WPAS_DBUS_SERVICE
= "fi.epitest.hostap.WPASupplicant"
8 WPAS_DBUS_INTERFACE
= "fi.epitest.hostap.WPASupplicant"
9 WPAS_DBUS_OPATH
= "/fi/epitest/hostap/WPASupplicant"
11 WPAS_DBUS_INTERFACES_INTERFACE
= "fi.epitest.hostap.WPASupplicant.Interface"
12 WPAS_DBUS_INTERFACES_OPATH
= "/fi/epitest/hostap/WPASupplicant/Interfaces"
13 WPAS_DBUS_BSSID_INTERFACE
= "fi.epitest.hostap.WPASupplicant.BSSID"
15 def byte_array_to_string(s
):
19 if c
>= 32 and c
< 127:
22 r
+= urllib
.quote(chr(c
))
26 if len(sys
.argv
) != 2:
27 print "Usage: wpas-test.py <interface>"
32 bus
= dbus
.SystemBus()
33 wpas_obj
= bus
.get_object(WPAS_DBUS_SERVICE
, WPAS_DBUS_OPATH
)
34 wpas
= dbus
.Interface(wpas_obj
, WPAS_DBUS_INTERFACE
)
36 # See if wpa_supplicant already knows about this interface
39 path
= wpas
.getInterface(ifname
)
40 except dbus
.dbus_bindings
.DBusException
, exc
:
41 if str(exc
) != "wpa_supplicant knows nothing about this interface.":
44 path
= wpas
.addInterface(ifname
, {'driver': dbus
.Variant('wext')})
45 except dbus
.dbus_bindings
.DBusException
, exc
:
46 if str(exc
) != "wpa_supplicant already controls this interface.":
49 if_obj
= bus
.get_object(WPAS_DBUS_SERVICE
, path
)
50 iface
= dbus
.Interface(if_obj
, WPAS_DBUS_INTERFACES_INTERFACE
)
52 # Should really wait for the "scanResults" signal instead of sleeping
54 res
= iface
.scanResults()
56 print "Scanned wireless networks:"
58 net_obj
= bus
.get_object(WPAS_DBUS_SERVICE
, opath
)
59 net
= dbus
.Interface(net_obj
, WPAS_DBUS_BSSID_INTERFACE
)
60 props
= net
.properties()
62 # Convert the byte-array for SSID and BSSID to printable strings
64 for item
in props
["bssid"]:
65 bssid
= bssid
+ ":%02x" % item
67 ssid
= byte_array_to_string(props
["ssid"])
69 if props
.has_key("wpaie"):
72 if props
.has_key("rsnie"):
75 if props
.has_key("frequency"):
76 freq
= props
["frequency"]
77 caps
= props
["capabilities"]
78 qual
= props
["quality"]
79 level
= props
["level"]
80 noise
= props
["noise"]
81 maxrate
= props
["maxrate"] / 1000000
83 print " %s :: ssid='%s' wpa=%s wpa2=%s quality=%d%% rate=%d freq=%d" % (bssid
, ssid
, wpa
, wpa2
, qual
, maxrate
, freq
)
85 wpas
.removeInterface(dbus
.ObjectPath(path
))
86 # Should fail here with unknown interface error
89 if __name__
== "__main__":