wpasupplicant.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. #!/usr/bin/python
  2. #
  3. # Python class for controlling wpa_supplicant
  4. # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import os
  9. import time
  10. import logging
  11. import re
  12. import subprocess
  13. import wpaspy
  14. logger = logging.getLogger()
  15. wpas_ctrl = '/var/run/wpa_supplicant'
  16. class WpaSupplicant:
  17. def __init__(self, ifname, global_iface=None):
  18. self.ifname = ifname
  19. self.group_ifname = None
  20. self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
  21. self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
  22. self.mon.attach()
  23. self.global_iface = global_iface
  24. if global_iface:
  25. self.global_ctrl = wpaspy.Ctrl(global_iface)
  26. self.global_mon = wpaspy.Ctrl(global_iface)
  27. self.global_mon.attach()
  28. def request(self, cmd):
  29. logger.debug(self.ifname + ": CTRL: " + cmd)
  30. return self.ctrl.request(cmd)
  31. def global_request(self, cmd):
  32. if self.global_iface is None:
  33. self.request(cmd)
  34. else:
  35. logger.debug(self.ifname + ": CTRL: " + cmd)
  36. return self.global_ctrl.request(cmd)
  37. def group_request(self, cmd):
  38. if self.group_ifname and self.group_ifname != self.ifname:
  39. logger.debug(self.group_ifname + ": CTRL: " + cmd)
  40. gctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, self.group_ifname))
  41. return gctrl.request(cmd)
  42. return self.request(cmd)
  43. def ping(self):
  44. return "PONG" in self.request("PING")
  45. def reset(self):
  46. res = self.request("FLUSH")
  47. if not "OK" in res:
  48. logger.info("FLUSH to " + self.ifname + " failed: " + res)
  49. self.request("SET ignore_old_scan_res 0")
  50. self.request("SET external_sim 0")
  51. self.request("SET hessid 00:00:00:00:00:00")
  52. self.request("SET access_network_type 15")
  53. self.request("SET p2p_add_cli_chan 0")
  54. self.request("SET p2p_no_go_freq ")
  55. self.request("SET p2p_pref_chan ")
  56. self.request("SET disallow_aps ")
  57. self.request("SET p2p_no_group_iface 1")
  58. self.request("P2P_SET per_sta_psk 0")
  59. self.request("P2P_SET disabled 0")
  60. self.request("P2P_SERVICE_FLUSH")
  61. self.group_ifname = None
  62. self.dump_monitor()
  63. iter = 0
  64. while iter < 60:
  65. state = self.get_driver_status_field("scan_state")
  66. if "SCAN_STARTED" in state or "SCAN_REQUESTED" in state:
  67. logger.info(self.ifname + ": Waiting for scan operation to complete before continuing")
  68. time.sleep(1)
  69. else:
  70. break
  71. iter = iter + 1
  72. if iter == 60:
  73. logger.error(self.ifname + ": Driver scan state did not clear")
  74. print "Trying to clear cfg80211/mac80211 scan state"
  75. try:
  76. cmd = ["sudo", "ifconfig", self.ifname, "down"]
  77. subprocess.call(cmd)
  78. except subprocess.CalledProcessError, e:
  79. logger.info("ifconfig failed: " + str(e.returncode))
  80. logger.info(e.output)
  81. try:
  82. cmd = ["sudo", "ifconfig", self.ifname, "up"]
  83. subprocess.call(cmd)
  84. except subprocess.CalledProcessError, e:
  85. logger.info("ifconfig failed: " + str(e.returncode))
  86. logger.info(e.output)
  87. if not self.ping():
  88. logger.info("No PING response from " + self.ifname + " after reset")
  89. def add_network(self):
  90. id = self.request("ADD_NETWORK")
  91. if "FAIL" in id:
  92. raise Exception("ADD_NETWORK failed")
  93. return int(id)
  94. def remove_network(self, id):
  95. id = self.request("REMOVE_NETWORK " + str(id))
  96. if "FAIL" in id:
  97. raise Exception("REMOVE_NETWORK failed")
  98. return None
  99. def set_network(self, id, field, value):
  100. res = self.request("SET_NETWORK " + str(id) + " " + field + " " + value)
  101. if "FAIL" in res:
  102. raise Exception("SET_NETWORK failed")
  103. return None
  104. def set_network_quoted(self, id, field, value):
  105. res = self.request("SET_NETWORK " + str(id) + " " + field + ' "' + value + '"')
  106. if "FAIL" in res:
  107. raise Exception("SET_NETWORK failed")
  108. return None
  109. def list_networks(self):
  110. res = self.request("LIST_NETWORKS")
  111. lines = res.splitlines()
  112. networks = []
  113. for l in lines:
  114. if "network id" in l:
  115. continue
  116. [id,ssid,bssid,flags] = l.split('\t')
  117. network = {}
  118. network['id'] = id
  119. network['ssid'] = ssid
  120. network['bssid'] = bssid
  121. network['flags'] = flags
  122. networks.append(network)
  123. return networks
  124. def hs20_enable(self):
  125. self.request("SET interworking 1")
  126. self.request("SET hs20 1")
  127. def add_cred(self):
  128. id = self.request("ADD_CRED")
  129. if "FAIL" in id:
  130. raise Exception("ADD_CRED failed")
  131. return int(id)
  132. def remove_cred(self, id):
  133. id = self.request("REMOVE_CRED " + str(id))
  134. if "FAIL" in id:
  135. raise Exception("REMOVE_CRED failed")
  136. return None
  137. def set_cred(self, id, field, value):
  138. res = self.request("SET_CRED " + str(id) + " " + field + " " + value)
  139. if "FAIL" in res:
  140. raise Exception("SET_CRED failed")
  141. return None
  142. def set_cred_quoted(self, id, field, value):
  143. res = self.request("SET_CRED " + str(id) + " " + field + ' "' + value + '"')
  144. if "FAIL" in res:
  145. raise Exception("SET_CRED failed")
  146. return None
  147. def add_cred_values(self, params):
  148. id = self.add_cred()
  149. quoted = [ "realm", "username", "password", "domain", "imsi",
  150. "excluded_ssid" ]
  151. for field in quoted:
  152. if field in params:
  153. self.set_cred_quoted(id, field, params[field])
  154. not_quoted = [ "eap", "required_roaming_consortium" ]
  155. for field in not_quoted:
  156. if field in params:
  157. self.set_cred(id, field, params[field])
  158. return id;
  159. def select_network(self, id):
  160. id = self.request("SELECT_NETWORK " + str(id))
  161. if "FAIL" in id:
  162. raise Exception("SELECT_NETWORK failed")
  163. return None
  164. def connect_network(self, id):
  165. self.dump_monitor()
  166. self.select_network(id)
  167. ev = self.wait_event(["CTRL-EVENT-CONNECTED"], timeout=10)
  168. if ev is None:
  169. raise Exception("Association with the AP timed out")
  170. self.dump_monitor()
  171. def get_status(self):
  172. res = self.request("STATUS")
  173. lines = res.splitlines()
  174. vals = dict()
  175. for l in lines:
  176. [name,value] = l.split('=', 1)
  177. vals[name] = value
  178. return vals
  179. def get_status_field(self, field):
  180. vals = self.get_status()
  181. if field in vals:
  182. return vals[field]
  183. return None
  184. def get_group_status(self):
  185. res = self.group_request("STATUS")
  186. lines = res.splitlines()
  187. vals = dict()
  188. for l in lines:
  189. [name,value] = l.split('=', 1)
  190. vals[name] = value
  191. return vals
  192. def get_group_status_field(self, field):
  193. vals = self.get_group_status()
  194. if field in vals:
  195. return vals[field]
  196. return None
  197. def get_driver_status(self):
  198. res = self.request("STATUS-DRIVER")
  199. lines = res.splitlines()
  200. vals = dict()
  201. for l in lines:
  202. [name,value] = l.split('=', 1)
  203. vals[name] = value
  204. return vals
  205. def get_driver_status_field(self, field):
  206. vals = self.get_driver_status()
  207. if field in vals:
  208. return vals[field]
  209. return None
  210. def p2p_dev_addr(self):
  211. return self.get_status_field("p2p_device_address")
  212. def p2p_interface_addr(self):
  213. return self.get_group_status_field("address")
  214. def p2p_listen(self):
  215. return self.global_request("P2P_LISTEN")
  216. def p2p_find(self, social=False):
  217. if social:
  218. return self.global_request("P2P_FIND type=social")
  219. return self.global_request("P2P_FIND")
  220. def p2p_stop_find(self):
  221. return self.global_request("P2P_STOP_FIND")
  222. def wps_read_pin(self):
  223. #TODO: make this random
  224. self.pin = "12345670"
  225. return self.pin
  226. def peer_known(self, peer, full=True):
  227. res = self.global_request("P2P_PEER " + peer)
  228. if peer.lower() not in res.lower():
  229. return False
  230. if not full:
  231. return True
  232. return "[PROBE_REQ_ONLY]" not in res
  233. def discover_peer(self, peer, full=True, timeout=15, social=True):
  234. logger.info(self.ifname + ": Trying to discover peer " + peer)
  235. if self.peer_known(peer, full):
  236. return True
  237. self.p2p_find(social)
  238. count = 0
  239. while count < timeout:
  240. time.sleep(1)
  241. count = count + 1
  242. if self.peer_known(peer, full):
  243. return True
  244. return False
  245. def get_peer(self, peer):
  246. res = self.global_request("P2P_PEER " + peer)
  247. if peer.lower() not in res.lower():
  248. raise Exception("Peer information not available")
  249. lines = res.splitlines()
  250. vals = dict()
  251. for l in lines:
  252. if '=' in l:
  253. [name,value] = l.split('=', 1)
  254. vals[name] = value
  255. return vals
  256. def group_form_result(self, ev, expect_failure=False, go_neg_res=None):
  257. if expect_failure:
  258. if "P2P-GROUP-STARTED" in ev:
  259. raise Exception("Group formation succeeded when expecting failure")
  260. exp = r'<.>(P2P-GO-NEG-FAILURE) status=([0-9]*)'
  261. s = re.split(exp, ev)
  262. if len(s) < 3:
  263. return None
  264. res = {}
  265. res['result'] = 'go-neg-failed'
  266. res['status'] = int(s[2])
  267. return res
  268. if "P2P-GROUP-STARTED" not in ev:
  269. raise Exception("No P2P-GROUP-STARTED event seen")
  270. exp = r'<.>(P2P-GROUP-STARTED) ([^ ]*) ([^ ]*) ssid="(.*)" freq=([0-9]*) ((?:psk=.*)|(?:passphrase=".*")) go_dev_addr=([0-9a-f:]*)'
  271. s = re.split(exp, ev)
  272. if len(s) < 8:
  273. raise Exception("Could not parse P2P-GROUP-STARTED")
  274. res = {}
  275. res['result'] = 'success'
  276. res['ifname'] = s[2]
  277. self.group_ifname = s[2]
  278. res['role'] = s[3]
  279. res['ssid'] = s[4]
  280. res['freq'] = s[5]
  281. if "[PERSISTENT]" in ev:
  282. res['persistent'] = True
  283. else:
  284. res['persistent'] = False
  285. p = re.match(r'psk=([0-9a-f]*)', s[6])
  286. if p:
  287. res['psk'] = p.group(1)
  288. p = re.match(r'passphrase="(.*)"', s[6])
  289. if p:
  290. res['passphrase'] = p.group(1)
  291. res['go_dev_addr'] = s[7]
  292. if go_neg_res:
  293. exp = r'<.>(P2P-GO-NEG-SUCCESS) role=(GO|client) freq=([0-9]*)'
  294. s = re.split(exp, go_neg_res)
  295. if len(s) < 4:
  296. raise Exception("Could not parse P2P-GO-NEG-SUCCESS")
  297. res['go_neg_role'] = s[2]
  298. res['go_neg_freq'] = s[3]
  299. return res
  300. def p2p_go_neg_auth(self, peer, pin, method, go_intent=None, persistent=False, freq=None):
  301. if not self.discover_peer(peer):
  302. raise Exception("Peer " + peer + " not found")
  303. self.dump_monitor()
  304. cmd = "P2P_CONNECT " + peer + " " + pin + " " + method + " auth"
  305. if go_intent:
  306. cmd = cmd + ' go_intent=' + str(go_intent)
  307. if freq:
  308. cmd = cmd + ' freq=' + str(freq)
  309. if persistent:
  310. cmd = cmd + " persistent"
  311. if "OK" in self.global_request(cmd):
  312. return None
  313. raise Exception("P2P_CONNECT (auth) failed")
  314. def p2p_go_neg_auth_result(self, timeout=1, expect_failure=False):
  315. go_neg_res = None
  316. ev = self.wait_global_event(["P2P-GO-NEG-SUCCESS",
  317. "P2P-GO-NEG-FAILURE"], timeout);
  318. if ev is None:
  319. if expect_failure:
  320. return None
  321. raise Exception("Group formation timed out")
  322. if "P2P-GO-NEG-SUCCESS" in ev:
  323. go_neg_res = ev
  324. ev = self.wait_global_event(["P2P-GROUP-STARTED"], timeout);
  325. if ev is None:
  326. if expect_failure:
  327. return None
  328. raise Exception("Group formation timed out")
  329. self.dump_monitor()
  330. return self.group_form_result(ev, expect_failure, go_neg_res)
  331. def p2p_go_neg_init(self, peer, pin, method, timeout=0, go_intent=None, expect_failure=False, persistent=False, freq=None):
  332. if not self.discover_peer(peer):
  333. raise Exception("Peer " + peer + " not found")
  334. self.dump_monitor()
  335. if pin:
  336. cmd = "P2P_CONNECT " + peer + " " + pin + " " + method
  337. else:
  338. cmd = "P2P_CONNECT " + peer + " " + method
  339. if go_intent:
  340. cmd = cmd + ' go_intent=' + str(go_intent)
  341. if freq:
  342. cmd = cmd + ' freq=' + str(freq)
  343. if persistent:
  344. cmd = cmd + " persistent"
  345. if "OK" in self.global_request(cmd):
  346. if timeout == 0:
  347. self.dump_monitor()
  348. return None
  349. go_neg_res = None
  350. ev = self.wait_global_event(["P2P-GO-NEG-SUCCESS",
  351. "P2P-GO-NEG-FAILURE"], timeout)
  352. if ev is None:
  353. if expect_failure:
  354. return None
  355. raise Exception("Group formation timed out")
  356. if "P2P-GO-NEG-SUCCESS" in ev:
  357. go_neg_res = ev
  358. ev = self.wait_global_event(["P2P-GROUP-STARTED"], timeout)
  359. if ev is None:
  360. if expect_failure:
  361. return None
  362. raise Exception("Group formation timed out")
  363. self.dump_monitor()
  364. return self.group_form_result(ev, expect_failure, go_neg_res)
  365. raise Exception("P2P_CONNECT failed")
  366. def wait_event(self, events, timeout):
  367. count = 0
  368. while count < timeout * 10:
  369. count = count + 1
  370. time.sleep(0.1)
  371. while self.mon.pending():
  372. ev = self.mon.recv()
  373. logger.debug(self.ifname + ": " + ev)
  374. for event in events:
  375. if event in ev:
  376. return ev
  377. return None
  378. def wait_global_event(self, events, timeout):
  379. if self.global_iface is None:
  380. self.wait_event(events, timeout)
  381. else:
  382. count = 0
  383. while count < timeout * 10:
  384. count = count + 1
  385. time.sleep(0.1)
  386. while self.global_mon.pending():
  387. ev = self.global_mon.recv()
  388. logger.debug(self.ifname + "(global): " + ev)
  389. for event in events:
  390. if event in ev:
  391. return ev
  392. return None
  393. def wait_go_ending_session(self):
  394. ev = self.wait_event(["P2P-GROUP-REMOVED"], timeout=3)
  395. if ev is None:
  396. raise Exception("Group removal event timed out")
  397. if "reason=GO_ENDING_SESSION" not in ev:
  398. raise Exception("Unexpected group removal reason")
  399. def dump_monitor(self):
  400. while self.mon.pending():
  401. ev = self.mon.recv()
  402. logger.debug(self.ifname + ": " + ev)
  403. while self.global_mon.pending():
  404. ev = self.global_mon.recv()
  405. logger.debug(self.ifname + "(global): " + ev)
  406. def remove_group(self, ifname=None):
  407. if ifname is None:
  408. ifname = self.group_ifname if self.group_ifname else self.ifname
  409. if "OK" not in self.global_request("P2P_GROUP_REMOVE " + ifname):
  410. raise Exception("Group could not be removed")
  411. self.group_ifname = None
  412. def p2p_start_go(self, persistent=None, freq=None):
  413. self.dump_monitor()
  414. cmd = "P2P_GROUP_ADD"
  415. if persistent is None:
  416. pass
  417. elif persistent is True:
  418. cmd = cmd + " persistent"
  419. else:
  420. cmd = cmd + " persistent=" + str(persistent)
  421. if freq:
  422. cmd = cmd + " freq=" + str(freq)
  423. if "OK" in self.global_request(cmd):
  424. ev = self.wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
  425. if ev is None:
  426. raise Exception("GO start up timed out")
  427. self.dump_monitor()
  428. return self.group_form_result(ev)
  429. raise Exception("P2P_GROUP_ADD failed")
  430. def p2p_go_authorize_client(self, pin):
  431. cmd = "WPS_PIN any " + pin
  432. if "FAIL" in self.group_request(cmd):
  433. raise Exception("Failed to authorize client connection on GO")
  434. return None
  435. def p2p_go_authorize_client_pbc(self):
  436. cmd = "WPS_PBC"
  437. if "FAIL" in self.group_request(cmd):
  438. raise Exception("Failed to authorize client connection on GO")
  439. return None
  440. def p2p_connect_group(self, go_addr, pin, timeout=0, social=False):
  441. self.dump_monitor()
  442. if not self.discover_peer(go_addr, social=social):
  443. raise Exception("GO " + go_addr + " not found")
  444. self.dump_monitor()
  445. cmd = "P2P_CONNECT " + go_addr + " " + pin + " join"
  446. if "OK" in self.global_request(cmd):
  447. if timeout == 0:
  448. self.dump_monitor()
  449. return None
  450. ev = self.wait_global_event(["P2P-GROUP-STARTED"], timeout)
  451. if ev is None:
  452. raise Exception("Joining the group timed out")
  453. self.dump_monitor()
  454. return self.group_form_result(ev)
  455. raise Exception("P2P_CONNECT(join) failed")
  456. def tdls_setup(self, peer):
  457. cmd = "TDLS_SETUP " + peer
  458. if "FAIL" in self.group_request(cmd):
  459. raise Exception("Failed to request TDLS setup")
  460. return None
  461. def tdls_teardown(self, peer):
  462. cmd = "TDLS_TEARDOWN " + peer
  463. if "FAIL" in self.group_request(cmd):
  464. raise Exception("Failed to request TDLS teardown")
  465. return None
  466. def connect(self, ssid, psk=None, proto=None, key_mgmt=None, wep_key0=None,
  467. ieee80211w=None, pairwise=None, group=None, scan_freq=None,
  468. eap=None, identity=None, anonymous_identity=None,
  469. password=None, phase1=None, phase2=None, ca_cert=None,
  470. domain_suffix_match=None, password_hex=None,
  471. client_cert=None, private_key=None,
  472. wait_connect=True):
  473. logger.info("Connect STA " + self.ifname + " to AP")
  474. id = self.add_network()
  475. self.set_network_quoted(id, "ssid", ssid)
  476. if psk:
  477. self.set_network_quoted(id, "psk", psk)
  478. if proto:
  479. self.set_network(id, "proto", proto)
  480. if key_mgmt:
  481. self.set_network(id, "key_mgmt", key_mgmt)
  482. if ieee80211w:
  483. self.set_network(id, "ieee80211w", ieee80211w)
  484. if pairwise:
  485. self.set_network(id, "pairwise", pairwise)
  486. if group:
  487. self.set_network(id, "group", group)
  488. if wep_key0:
  489. self.set_network(id, "wep_key0", wep_key0)
  490. if scan_freq:
  491. self.set_network(id, "scan_freq", scan_freq)
  492. if eap:
  493. self.set_network(id, "eap", eap)
  494. if identity:
  495. self.set_network_quoted(id, "identity", identity)
  496. if anonymous_identity:
  497. self.set_network_quoted(id, "anonymous_identity",
  498. anonymous_identity)
  499. if password:
  500. self.set_network_quoted(id, "password", password)
  501. if password_hex:
  502. self.set_network(id, "password", password_hex)
  503. if ca_cert:
  504. self.set_network_quoted(id, "ca_cert", ca_cert)
  505. if client_cert:
  506. self.set_network_quoted(id, "client_cert", client_cert)
  507. if private_key:
  508. self.set_network_quoted(id, "private_key", private_key)
  509. if phase1:
  510. self.set_network_quoted(id, "phase1", phase1)
  511. if phase2:
  512. self.set_network_quoted(id, "phase2", phase2)
  513. if domain_suffix_match:
  514. self.set_network_quoted(id, "domain_suffix_match",
  515. domain_suffix_match)
  516. if wait_connect:
  517. self.connect_network(id)
  518. else:
  519. self.dump_monitor()
  520. self.select_network(id)
  521. return id
  522. def scan(self, type=None):
  523. if type:
  524. cmd = "SCAN TYPE=" + type
  525. else:
  526. cmd = "SCAN"
  527. self.dump_monitor()
  528. if not "OK" in self.request(cmd):
  529. raise Exception("Failed to trigger scan")
  530. ev = self.wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
  531. if ev is None:
  532. raise Exception("Scan timed out")
  533. def roam(self, bssid):
  534. self.dump_monitor()
  535. self.request("ROAM " + bssid)
  536. ev = self.wait_event(["CTRL-EVENT-CONNECTED"], timeout=10)
  537. if ev is None:
  538. raise Exception("Roaming with the AP timed out")
  539. self.dump_monitor()
  540. def wps_reg(self, bssid, pin, new_ssid=None, key_mgmt=None, cipher=None,
  541. new_passphrase=None):
  542. self.dump_monitor()
  543. if new_ssid:
  544. self.request("WPS_REG " + bssid + " " + pin + " " +
  545. new_ssid.encode("hex") + " " + key_mgmt + " " +
  546. cipher + " " + new_passphrase.encode("hex"))
  547. ev = self.wait_event(["WPS-SUCCESS"], timeout=15)
  548. else:
  549. self.request("WPS_REG " + bssid + " " + pin)
  550. ev = self.wait_event(["WPS-CRED-RECEIVED"], timeout=15)
  551. if ev is None:
  552. raise Exception("WPS cred timed out")
  553. ev = self.wait_event(["WPS-FAIL"], timeout=15)
  554. if ev is None:
  555. raise Exception("WPS timed out")
  556. ev = self.wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  557. if ev is None:
  558. raise Exception("Association with the AP timed out")
  559. def relog(self):
  560. self.request("RELOG")
  561. def wait_completed(self, timeout=10):
  562. for i in range(0, timeout * 2):
  563. if self.get_status_field("wpa_state") == "COMPLETED":
  564. return
  565. time.sleep(0.5)
  566. raise Exception("Timeout while waiting for COMPLETED state")
  567. def get_capability(self, field):
  568. res = self.request("GET_CAPABILITY " + field)
  569. if "FAIL" in res:
  570. return None
  571. return res.split(' ')