aboutsummaryrefslogtreecommitdiffstats
path: root/wpa_supplicant/examples/dbus-listen-preq.py
blob: 337519f4e927133d40a1040ed06a12ae94960081 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python

from __future__ import print_function
import dbus
import sys
import time
import gobject
from dbus.mainloop.glib import DBusGMainLoop

WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"

def usage():
	print("Usage: %s <ifname>" % sys.argv[0])
	print("Press Ctrl-C to stop")

def ProbeRequest(args):
	if 'addr' in args:
		print('%.2x:%.2x:%.2x:%.2x:%.2x:%.2x' % tuple(args['addr']),
                      end=' ')
	if 'dst' in args:
		print('-> %.2x:%.2x:%.2x:%.2x:%.2x:%.2x' % tuple(args['dst']),
                      end=' ')
	if 'bssid' in args:
		print('(bssid %.2x:%.2x:%.2x:%.2x:%.2x:%.2x)' % tuple(args['dst']),
                      end=' ')
	if 'signal' in args:
		print('signal:%d' % args['signal'], end=' ')
	if 'ies' in args:
		print('have IEs (%d bytes)' % len(args['ies']), end=' ')
        print('')

if __name__ == "__main__":
	global bus
	global wpas_obj
	global if_obj
	global p2p_iface

	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

	bus = dbus.SystemBus()
	wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)

	# Print list of i/f if no one is specified
	if (len(sys.argv) < 2)  :
		usage()
		sys.exit(0)

	wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)

	ifname = sys.argv[1]

	path = wpas.GetInterface(ifname)

	if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
	iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE)

	bus.add_signal_receiver(ProbeRequest,
				dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
				signal_name="ProbeRequest")

	iface.SubscribeProbeReq()

	gobject.MainLoop().run()