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
49 def request(self, cmd, timeout=10):
51 [r, w, e] = select.select([self.s], [], [], timeout)
53 return self.s.recv(4096)
54 raise Exception("Timeout on waiting response")
59 res = self.request("ATTACH")
63 raise Exception("ATTACH failed")
70 res = self.request("DETACH")
74 raise Exception("DETACH failed")
76 def pending(self, timeout=0):
77 [r, w, e] = select.select([self.s], [], [], timeout)
83 res = self.s.recv(4096)