wpaspy: Handle DETACH response more robustly

There could be pending unsolicited event messages on the monitor socket
when the DETACH command is issued. As such, the response may be
something else then OK even if the actual detach operation succeeded.
Try to avoid this be dropping pending messages before issuing the detach
command. As an additional workaround, check the response against FAIL
instead of requiring OK so that the self.attached does not get left to
True incorrectly even if an additional event message were to be
received.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
Jouni Malinen 2014-04-28 15:31:25 +03:00 committed by Jouni Malinen
parent b7a6702fd4
commit 19318861a5

View file

@ -39,6 +39,7 @@ class Ctrl:
self.detach() self.detach()
except Exception, e: except Exception, e:
# Need to ignore this allow the socket to be closed # Need to ignore this allow the socket to be closed
self.attached = False
pass pass
if self.started: if self.started:
self.s.close() self.s.close()
@ -64,8 +65,10 @@ class Ctrl:
def detach(self): def detach(self):
if not self.attached: if not self.attached:
return None return None
while self.pending():
ev = self.recv()
res = self.request("DETACH") res = self.request("DETACH")
if "OK" in res: if "FAIL" not in res:
self.attached = False self.attached = False
return None return None
raise Exception("DETACH failed") raise Exception("DETACH failed")