]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/wpa/wpa_supplicant/examples/dbus-listen-preq.py
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / wpa / wpa_supplicant / examples / dbus-listen-preq.py
1 #!/usr/bin/python
2
3 import dbus
4 import sys
5 import time
6 import gobject
7 from dbus.mainloop.glib import DBusGMainLoop
8
9 WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
10 WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
11 WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
12 WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
13
14 def usage():
15         print "Usage: %s <ifname>" % sys.argv[0]
16         print "Press Ctrl-C to stop"
17
18 def ProbeRequest(args):
19         if 'addr' in args:
20                 print '%.2x:%.2x:%.2x:%.2x:%.2x:%.2x' % tuple(args['addr']),
21         if 'dst' in args:
22                 print '-> %.2x:%.2x:%.2x:%.2x:%.2x:%.2x' % tuple(args['dst']),
23         if 'bssid' in args:
24                 print '(bssid %.2x:%.2x:%.2x:%.2x:%.2x:%.2x)' % tuple(args['dst']),
25         if 'signal' in args:
26                 print 'signal:%d' % args['signal'],
27         if 'ies' in args:
28                 print 'have IEs (%d bytes)' % len(args['ies']),
29         print ''
30
31 if __name__ == "__main__":
32         global bus
33         global wpas_obj
34         global if_obj
35         global p2p_iface
36
37         dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
38
39         bus = dbus.SystemBus()
40         wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
41
42         # Print list of i/f if no one is specified
43         if (len(sys.argv) < 2)  :
44                 usage()
45                 sys.exit(0)
46
47         wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
48
49         ifname = sys.argv[1]
50
51         path = wpas.GetInterface(ifname)
52
53         if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
54         iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE)
55
56         bus.add_signal_receiver(ProbeRequest,
57                                 dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
58                                 signal_name="ProbeRequest")
59
60         iface.SubscribeProbeReq()
61
62         gobject.MainLoop().run()