~ubuntu-branches/ubuntu/vivid/wpasupplicant/vivid

« back to all changes in this revision

Viewing changes to wpa_supplicant/examples/wpas-test.py

  • Committer: Bazaar Package Importer
  • Author(s): Kel Modderman
  • Date: 2008-03-12 20:03:04 UTC
  • mfrom: (1.1.10 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080312200304-4331y9wj46pdd34z
Tags: 0.6.3-1
* New upstream release.
* Drop patches applied upstream:
  - debian/patches/30_wpa_gui_qt4_eventhistoryui_rework.patch
  - debian/patches/31_wpa_gui_qt4_eventhistory_always_scrollbar.patch
  - debian/patches/32_wpa_gui_qt4_eventhistory_scroll_with_events.patch
  - debian/patches/40_dbus_ssid_data.patch
* Tidy up the clean target of debian/rules. Now that the madwifi headers are
  handled differently we no longer need to do any cleanup.
* Fix formatting error in debian/ifupdown/wpa_action.8 to make lintian
  quieter.
* Add patch to fix formatting errors in manpages build from sgml source. Use
  <emphasis> tags to hightlight keywords instead of surrounding them in
  strong quotes.
  - debian/patches/41_manpage_format_fixes.patch
* wpasupplicant binary package no longer suggests pcscd, guessnet, iproute
  or wireless-tools, nor does it recommend dhcp3-client. These are not
  needed.
* Add debian/patches/10_silence_siocsiwauth_icotl_failure.patch to disable
  ioctl failure messages that occur under normal conditions.
* Cherry pick two upstream git commits concerning the dbus interface:
  - debian/patches/11_avoid_dbus_version_namespace.patch
  - debian/patches/12_fix_potential_use_after_free.patch
* Add debian/patches/42_manpage_explain_available_drivers.patch to explain
  that not all of the driver backends are available in the provided
  wpa_supplicant binary, and that the canonical list of supported driver
  backends can be retrieved from the wpa_supplicant -h (help) output.
  (Closes: #466910)
* Add debian/patches/20_wpa_gui_qt4_disable_link_prl.patch to remove
  link_prl CONFIG compile flag added by qmake-qt4 >= 4.3.4-2 to avoid excess
  linking.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import dbus
 
4
import sys, os
 
5
import time
 
6
 
 
7
WPAS_DBUS_SERVICE = "fi.epitest.hostap.WPASupplicant"
 
8
WPAS_DBUS_INTERFACE = "fi.epitest.hostap.WPASupplicant"
 
9
WPAS_DBUS_OPATH = "/fi/epitest/hostap/WPASupplicant"
 
10
 
 
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"
 
14
 
 
15
def byte_array_to_string(s):
 
16
        import urllib
 
17
        r = ""    
 
18
        for c in s:
 
19
                if c >= 32 and c < 127:
 
20
                        r += "%c" % c
 
21
                else:
 
22
                        r += urllib.quote(chr(c))
 
23
        return r
 
24
 
 
25
def main():
 
26
        if len(sys.argv) != 2:
 
27
                print "Usage: wpas-test.py <interface>"
 
28
                os._exit(1)
 
29
 
 
30
        ifname = sys.argv[1]
 
31
 
 
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)
 
35
 
 
36
        # See if wpa_supplicant already knows about this interface
 
37
        path = None
 
38
        try:
 
39
                path = wpas.getInterface(ifname)
 
40
        except dbus.dbus_bindings.DBusException, exc:
 
41
                if str(exc) != "wpa_supplicant knows nothing about this interface.":
 
42
                        raise exc
 
43
                try:
 
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.":
 
47
                                raise exc
 
48
 
 
49
        if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
 
50
        iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE)
 
51
        iface.scan()
 
52
        # Should really wait for the "scanResults" signal instead of sleeping
 
53
        time.sleep(5)
 
54
        res = iface.scanResults()
 
55
 
 
56
        print "Scanned wireless networks:"
 
57
        for opath in res:
 
58
                net_obj = bus.get_object(WPAS_DBUS_SERVICE, opath)
 
59
                net = dbus.Interface(net_obj, WPAS_DBUS_BSSID_INTERFACE)
 
60
                props = net.properties()
 
61
 
 
62
                # Convert the byte-array for SSID and BSSID to printable strings
 
63
                bssid = ""
 
64
                for item in props["bssid"]:
 
65
                        bssid = bssid + ":%02x" % item
 
66
                bssid = bssid[1:]
 
67
                ssid = byte_array_to_string(props["ssid"])
 
68
                wpa = "no"
 
69
                if props.has_key("wpaie"):
 
70
                        wpa = "yes"
 
71
                wpa2 = "no"
 
72
                if props.has_key("rsnie"):
 
73
                        wpa2 = "yes"
 
74
                freq = 0
 
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
 
82
 
 
83
                print "  %s  ::  ssid='%s'  wpa=%s  wpa2=%s  quality=%d%%  rate=%d  freq=%d" % (bssid, ssid, wpa, wpa2, qual, maxrate, freq)
 
84
 
 
85
        wpas.removeInterface(dbus.ObjectPath(path))
 
86
        # Should fail here with unknown interface error
 
87
        iface.scan()
 
88
 
 
89
if __name__ == "__main__":
 
90
        main()
 
91