3 # wpa_supplicant/hostapd control interface using Python
4 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
16 def __init__(self, path):
20 self.s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
22 self.local = "/tmp/wpa_ctrl_" + str(os.getpid()) + '-' + str(counter)
24 self.s.bind(self.local)
26 self.s.connect(self.dest)
41 # Need to ignore this allow the socket to be closed
48 def request(self, cmd):
50 [r, w, e] = select.select([self.s], [], [], 10)
52 return self.s.recv(4096)
53 raise Exception("Timeout on waiting response")
58 res = self.request("ATTACH")
62 raise Exception("ATTACH failed")
67 res = self.request("DETACH")
71 raise Exception("DETACH failed")
73 def pending(self, timeout=0):
74 [r, w, e] = select.select([self.s], [], [], timeout)
80 res = self.s.recv(4096)