test_ibss.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. # IBSS test cases
  2. # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. from remotehost import remote_compatible
  7. import logging
  8. logger = logging.getLogger()
  9. import time
  10. import re
  11. import subprocess
  12. import hwsim_utils
  13. from utils import alloc_fail, wait_fail_trigger
  14. def connect_ibss_cmd(dev, id, freq=2412):
  15. dev.dump_monitor()
  16. dev.select_network(id, freq=str(freq))
  17. def wait_ibss_connection(dev):
  18. logger.info(dev.ifname + " waiting for IBSS start/join to complete")
  19. ev = dev.wait_connected(timeout=20,
  20. error="Connection to the IBSS timed out")
  21. exp = r'<.>(CTRL-EVENT-CONNECTED) - Connection to ([0-9a-f:]*) completed.*'
  22. s = re.split(exp, ev)
  23. if len(s) < 3:
  24. return None
  25. return s[2]
  26. def wait_4way_handshake(dev1, dev2):
  27. logger.info(dev1.ifname + " waiting for 4-way handshake completion with " + dev2.ifname + " " + dev2.p2p_interface_addr())
  28. ev = dev1.wait_event(["IBSS-RSN-COMPLETED " + dev2.p2p_interface_addr()],
  29. timeout=20)
  30. if ev is None:
  31. raise Exception("4-way handshake in IBSS timed out")
  32. def wait_4way_handshake2(dev1, dev2, dev3):
  33. logger.info(dev1.ifname + " waiting for 4-way handshake completion with " + dev2.ifname + " " + dev2.p2p_interface_addr() + " and " + dev3.p2p_interface_addr())
  34. ev = dev1.wait_event(["IBSS-RSN-COMPLETED " + dev2.p2p_interface_addr(),
  35. "IBSS-RSN-COMPLETED " + dev3.p2p_interface_addr()],
  36. timeout=20)
  37. if ev is None:
  38. raise Exception("4-way handshake in IBSS timed out")
  39. ev = dev1.wait_event(["IBSS-RSN-COMPLETED " + dev2.p2p_interface_addr(),
  40. "IBSS-RSN-COMPLETED " + dev3.p2p_interface_addr()],
  41. timeout=20)
  42. if ev is None:
  43. raise Exception("4-way handshake in IBSS timed out")
  44. def add_ibss(dev, ssid, psk=None, proto=None, key_mgmt=None, pairwise=None,
  45. group=None, beacon_int=None, bssid=None, scan_freq=None,
  46. wep_key0=None, freq=2412, chwidth=0, group_rekey=0):
  47. id = dev.add_network()
  48. dev.set_network(id, "mode", "1")
  49. dev.set_network(id, "frequency", str(freq))
  50. if chwidth > 0:
  51. dev.set_network(id, "max_oper_chwidth", str(chwidth))
  52. if scan_freq:
  53. dev.set_network(id, "scan_freq", str(scan_freq))
  54. dev.set_network_quoted(id, "ssid", ssid)
  55. if psk:
  56. dev.set_network_quoted(id, "psk", psk)
  57. if proto:
  58. dev.set_network(id, "proto", proto)
  59. if key_mgmt:
  60. dev.set_network(id, "key_mgmt", key_mgmt)
  61. if pairwise:
  62. dev.set_network(id, "pairwise", pairwise)
  63. if group:
  64. dev.set_network(id, "group", group)
  65. if beacon_int:
  66. dev.set_network(id, "beacon_int", beacon_int)
  67. if bssid:
  68. dev.set_network(id, "bssid", bssid)
  69. if wep_key0:
  70. dev.set_network(id, "wep_key0", wep_key0)
  71. if group_rekey:
  72. dev.set_network(id, "group_rekey", str(group_rekey))
  73. dev.request("ENABLE_NETWORK " + str(id) + " no-connect")
  74. return id
  75. def add_ibss_rsn(dev, ssid, group_rekey=0, scan_freq=None):
  76. return add_ibss(dev, ssid, "12345678", "RSN", "WPA-PSK", "CCMP", "CCMP",
  77. group_rekey=group_rekey, scan_freq=scan_freq)
  78. def add_ibss_rsn_tkip(dev, ssid):
  79. return add_ibss(dev, ssid, "12345678", "RSN", "WPA-PSK", "TKIP", "TKIP")
  80. def add_ibss_wpa_none(dev, ssid):
  81. return add_ibss(dev, ssid, "12345678", "WPA", "WPA-NONE", "TKIP", "TKIP")
  82. def add_ibss_wpa_none_ccmp(dev, ssid):
  83. return add_ibss(dev, ssid, "12345678", "WPA", "WPA-NONE", "CCMP", "CCMP")
  84. def test_ibss_rsn(dev):
  85. """IBSS RSN"""
  86. ssid="ibss-rsn"
  87. logger.info("Start IBSS on the first STA")
  88. id = add_ibss_rsn(dev[0], ssid)
  89. # FIX: For now, this disables HT to avoid a strange issue with mac80211
  90. # frame reordering during the final test_connectivity() call. Once that is
  91. # figured out, these disable_ht=1 calls should be removed from the test
  92. # case.
  93. dev[0].set_network(id, "disable_ht", "1")
  94. connect_ibss_cmd(dev[0], id)
  95. bssid0 = wait_ibss_connection(dev[0])
  96. logger.info("Join two STAs to the IBSS")
  97. id = add_ibss_rsn(dev[1], ssid)
  98. dev[1].set_network(id, "disable_ht", "1")
  99. connect_ibss_cmd(dev[1], id)
  100. bssid1 = wait_ibss_connection(dev[1])
  101. if bssid0 != bssid1:
  102. logger.info("STA0 BSSID " + bssid0 + " differs from STA1 BSSID " + bssid1)
  103. # try to merge with a scan
  104. dev[1].scan()
  105. wait_4way_handshake(dev[0], dev[1])
  106. wait_4way_handshake(dev[1], dev[0])
  107. id = add_ibss_rsn(dev[2], ssid)
  108. connect_ibss_cmd(dev[2], id)
  109. bssid2 = wait_ibss_connection(dev[2])
  110. if bssid0 != bssid2:
  111. logger.info("STA0 BSSID " + bssid0 + " differs from STA2 BSSID " + bssid2)
  112. # try to merge with a scan
  113. dev[2].scan()
  114. wait_4way_handshake(dev[0], dev[2])
  115. wait_4way_handshake2(dev[2], dev[0], dev[1])
  116. # Allow some time for all peers to complete key setup
  117. time.sleep(3)
  118. hwsim_utils.test_connectivity(dev[0], dev[1])
  119. hwsim_utils.test_connectivity(dev[0], dev[2])
  120. hwsim_utils.test_connectivity(dev[1], dev[2])
  121. dev[1].request("REMOVE_NETWORK all")
  122. time.sleep(1)
  123. id = add_ibss_rsn(dev[1], ssid)
  124. dev[1].set_network(id, "disable_ht", "1")
  125. connect_ibss_cmd(dev[1], id)
  126. bssid1 = wait_ibss_connection(dev[1])
  127. if bssid0 != bssid1:
  128. logger.info("STA0 BSSID " + bssid0 + " differs from STA1 BSSID " + bssid1)
  129. # try to merge with a scan
  130. dev[1].scan()
  131. wait_4way_handshake(dev[0], dev[1])
  132. wait_4way_handshake(dev[1], dev[0])
  133. time.sleep(3)
  134. hwsim_utils.test_connectivity(dev[0], dev[1])
  135. if "OK" not in dev[0].request("IBSS_RSN " + dev[1].p2p_interface_addr()):
  136. raise Exception("IBSS_RSN command failed")
  137. key_mgmt = dev[0].get_status_field("key_mgmt")
  138. if key_mgmt != "WPA2-PSK":
  139. raise Exception("Unexpected STATUS key_mgmt: " + key_mgmt)
  140. def test_ibss_rsn_group_rekey(dev):
  141. """IBSS RSN group rekeying"""
  142. ssid="ibss-rsn"
  143. logger.info("Start IBSS on the first STA")
  144. id = add_ibss_rsn(dev[0], ssid, group_rekey=4, scan_freq=2412)
  145. connect_ibss_cmd(dev[0], id)
  146. bssid0 = wait_ibss_connection(dev[0])
  147. dev[0].dump_monitor()
  148. logger.info("Join two STAs to the IBSS")
  149. dev[1].scan_for_bss(bssid0, freq=2412)
  150. id = add_ibss_rsn(dev[1], ssid, scan_freq=2412)
  151. connect_ibss_cmd(dev[1], id)
  152. bssid1 = wait_ibss_connection(dev[1])
  153. if bssid0 != bssid1:
  154. raise Exception("STA0 BSSID " + bssid0 + " differs from STA1 BSSID " + bssid1)
  155. wait_4way_handshake(dev[0], dev[1])
  156. wait_4way_handshake(dev[1], dev[0])
  157. dev[0].dump_monitor()
  158. dev[1].dump_monitor()
  159. hwsim_utils.test_connectivity(dev[0], dev[1])
  160. ev = dev[1].wait_event(["WPA: Group rekeying completed"], timeout=10)
  161. if ev is None:
  162. raise Exception("No group rekeying reported")
  163. hwsim_utils.test_connectivity(dev[0], dev[1])
  164. def test_ibss_wpa_none(dev):
  165. """IBSS WPA-None"""
  166. ssid="ibss-wpa-none"
  167. logger.info("Start IBSS on the first STA")
  168. id = add_ibss_wpa_none(dev[0], ssid)
  169. connect_ibss_cmd(dev[0], id)
  170. bssid0 = wait_ibss_connection(dev[0])
  171. # This is a bit ugly, but no one really cares about WPA-None, so there may
  172. # not be enough justification to clean this up.. For now, wpa_supplicant
  173. # will show two connection events with mac80211_hwsim where the first one
  174. # comes with all zeros address.
  175. if bssid0 == "00:00:00:00:00:00":
  176. logger.info("Waiting for real BSSID on the first STA")
  177. bssid0 = wait_ibss_connection(dev[0])
  178. logger.info("Join two STAs to the IBSS")
  179. id = add_ibss_wpa_none(dev[1], ssid)
  180. connect_ibss_cmd(dev[1], id)
  181. id = add_ibss_wpa_none(dev[2], ssid)
  182. connect_ibss_cmd(dev[2], id)
  183. bssid1 = wait_ibss_connection(dev[1])
  184. if bssid0 != bssid1:
  185. logger.info("STA0 BSSID " + bssid0 + " differs from STA1 BSSID " + bssid1)
  186. bssid1 = wait_ibss_connection(dev[1])
  187. bssid2 = wait_ibss_connection(dev[2])
  188. if bssid0 != bssid2:
  189. logger.info("STA0 BSSID " + bssid0 + " differs from STA2 BSSID " + bssid2)
  190. bssid2 = wait_ibss_connection(dev[2])
  191. logger.info("bssid0=%s bssid1=%s bssid2=%s" % (bssid0, bssid1, bssid2))
  192. bss = dev[0].get_bss(bssid0)
  193. if not bss:
  194. bss = dev[1].get_bss(bssid1)
  195. if not bss:
  196. raise Exception("Could not find BSS entry for IBSS")
  197. if 'flags' not in bss:
  198. raise Exception("Could not get BSS flags from BSS table")
  199. if "[WPA-None-TKIP]" not in bss['flags']:
  200. raise Exception("Unexpected BSS flags: " + bss['flags'])
  201. # Allow some time for all peers to complete key setup
  202. time.sleep(1)
  203. # This is supposed to work, but looks like WPA-None does not work with
  204. # mac80211 currently..
  205. try:
  206. hwsim_utils.test_connectivity(dev[0], dev[1])
  207. except Exception, e:
  208. logger.info("Ignoring known connectivity failure: " + str(e))
  209. try:
  210. hwsim_utils.test_connectivity(dev[0], dev[2])
  211. except Exception, e:
  212. logger.info("Ignoring known connectivity failure: " + str(e))
  213. try:
  214. hwsim_utils.test_connectivity(dev[1], dev[2])
  215. except Exception, e:
  216. logger.info("Ignoring known connectivity failure: " + str(e))
  217. key_mgmt = dev[0].get_status_field("key_mgmt")
  218. if key_mgmt != "WPA-NONE":
  219. raise Exception("Unexpected STATUS key_mgmt: " + key_mgmt)
  220. def test_ibss_wpa_none_ccmp(dev):
  221. """IBSS WPA-None/CCMP"""
  222. ssid="ibss-wpa-none"
  223. logger.info("Start IBSS on the first STA")
  224. id = add_ibss_wpa_none(dev[0], ssid)
  225. connect_ibss_cmd(dev[0], id)
  226. bssid0 = wait_ibss_connection(dev[0])
  227. # This is a bit ugly, but no one really cares about WPA-None, so there may
  228. # not be enough justification to clean this up.. For now, wpa_supplicant
  229. # will show two connection events with mac80211_hwsim where the first one
  230. # comes with all zeros address.
  231. if bssid0 == "00:00:00:00:00:00":
  232. logger.info("Waiting for real BSSID on the first STA")
  233. bssid0 = wait_ibss_connection(dev[0])
  234. logger.info("Join a STA to the IBSS")
  235. id = add_ibss_wpa_none(dev[1], ssid)
  236. connect_ibss_cmd(dev[1], id)
  237. bssid1 = wait_ibss_connection(dev[1])
  238. if bssid0 != bssid1:
  239. logger.info("STA0 BSSID " + bssid0 + " differs from STA1 BSSID " + bssid1)
  240. bssid1 = wait_ibss_connection(dev[1])
  241. logger.info("bssid0=%s bssid1=%s" % (bssid0, bssid1))
  242. # Allow some time for all peers to complete key setup
  243. time.sleep(1)
  244. # This is supposed to work, but looks like WPA-None does not work with
  245. # mac80211 currently..
  246. try:
  247. hwsim_utils.test_connectivity(dev[0], dev[1])
  248. except Exception, e:
  249. logger.info("Ignoring known connectivity failure: " + str(e))
  250. def test_ibss_open(dev):
  251. """IBSS open (no security)"""
  252. ssid="ibss"
  253. id = add_ibss(dev[0], ssid, key_mgmt="NONE", beacon_int="150")
  254. connect_ibss_cmd(dev[0], id)
  255. bssid0 = wait_ibss_connection(dev[0])
  256. id = add_ibss(dev[1], ssid, key_mgmt="NONE", beacon_int="200")
  257. connect_ibss_cmd(dev[1], id)
  258. bssid1 = wait_ibss_connection(dev[1])
  259. if bssid0 != bssid1:
  260. logger.info("STA0 BSSID " + bssid0 + " differs from STA1 BSSID " + bssid1)
  261. res = dev[0].request("SCAN_RESULTS")
  262. if "[IBSS]" not in res:
  263. res = dev[1].request("SCAN_RESULTS")
  264. if "[IBSS]" not in res:
  265. raise Exception("IBSS flag missing from scan results: " + res)
  266. bss = dev[0].get_bss(bssid0)
  267. if not bss:
  268. bss = dev[1].get_bss(bssid1)
  269. if not bss:
  270. raise Exception("Could not find BSS entry for IBSS")
  271. if 'flags' not in bss:
  272. raise Exception("Could not get BSS flags from BSS table")
  273. if "[IBSS]" not in bss['flags']:
  274. raise Exception("Unexpected BSS flags: " + bss['flags'])
  275. freq0 = dev[0].get_status_field("freq")
  276. freq1 = dev[1].get_status_field("freq")
  277. if freq0 != "2412" or freq1 != "2412":
  278. raise Exception("IBSS operating frequency not reported correctly (%s %s)" % (freq0, freq1))
  279. key_mgmt = dev[0].get_status_field("key_mgmt")
  280. if key_mgmt != "NONE":
  281. raise Exception("Unexpected STATUS key_mgmt: " + key_mgmt)
  282. def test_ibss_open_fixed_bssid(dev):
  283. """IBSS open (no security) and fixed BSSID"""
  284. ssid="ibss"
  285. bssid="02:11:22:33:44:55"
  286. try:
  287. dev[0].request("AP_SCAN 2")
  288. add_ibss(dev[0], ssid, key_mgmt="NONE", bssid=bssid, beacon_int="150")
  289. dev[0].request("REASSOCIATE")
  290. dev[1].request("AP_SCAN 2")
  291. add_ibss(dev[1], ssid, key_mgmt="NONE", bssid=bssid, beacon_int="200")
  292. dev[1].request("REASSOCIATE")
  293. bssid0 = wait_ibss_connection(dev[0])
  294. bssid1 = wait_ibss_connection(dev[1])
  295. if bssid0 != bssid:
  296. raise Exception("STA0 BSSID " + bssid0 + " differs from fixed BSSID " + bssid)
  297. if bssid1 != bssid:
  298. raise Exception("STA0 BSSID " + bssid0 + " differs from fixed BSSID " + bssid)
  299. finally:
  300. dev[0].request("AP_SCAN 1")
  301. dev[1].request("AP_SCAN 1")
  302. def test_ibss_open_retry(dev):
  303. """IBSS open (no security) with cfg80211 retry workaround"""
  304. subprocess.check_call(['iw', 'dev', dev[0].ifname, 'set', 'type', 'adhoc'])
  305. subprocess.check_call(['iw', 'dev', dev[0].ifname, 'ibss', 'join',
  306. 'ibss-test', '2412', 'HT20', 'fixed-freq',
  307. '02:22:33:44:55:66'])
  308. ssid="ibss"
  309. try:
  310. dev[0].request("AP_SCAN 2")
  311. id = add_ibss(dev[0], ssid, key_mgmt="NONE", beacon_int="150",
  312. bssid="02:33:44:55:66:77", scan_freq=2412)
  313. #connect_ibss_cmd(dev[0], id)
  314. dev[0].request("REASSOCIATE")
  315. bssid0 = wait_ibss_connection(dev[0])
  316. subprocess.check_call(['iw', 'dev', dev[0].ifname, 'ibss', 'leave'])
  317. time.sleep(1)
  318. dev[0].request("DISCONNECT")
  319. finally:
  320. dev[0].request("AP_SCAN 1")
  321. def test_ibss_rsn_tkip(dev):
  322. """IBSS RSN with TKIP as the cipher"""
  323. ssid="ibss-rsn-tkip"
  324. id = add_ibss_rsn_tkip(dev[0], ssid)
  325. connect_ibss_cmd(dev[0], id)
  326. bssid0 = wait_ibss_connection(dev[0])
  327. id = add_ibss_rsn_tkip(dev[1], ssid)
  328. connect_ibss_cmd(dev[1], id)
  329. bssid1 = wait_ibss_connection(dev[1])
  330. if bssid0 != bssid1:
  331. logger.info("STA0 BSSID " + bssid0 + " differs from STA1 BSSID " + bssid1)
  332. # try to merge with a scan
  333. dev[1].scan()
  334. wait_4way_handshake(dev[0], dev[1])
  335. wait_4way_handshake(dev[1], dev[0])
  336. def test_ibss_wep(dev):
  337. """IBSS with WEP"""
  338. ssid="ibss-wep"
  339. id = add_ibss(dev[0], ssid, key_mgmt="NONE", wep_key0='"hello"')
  340. connect_ibss_cmd(dev[0], id)
  341. bssid0 = wait_ibss_connection(dev[0])
  342. id = add_ibss(dev[1], ssid, key_mgmt="NONE", wep_key0='"hello"')
  343. connect_ibss_cmd(dev[1], id)
  344. bssid1 = wait_ibss_connection(dev[1])
  345. @remote_compatible
  346. def test_ibss_rsn_error_case(dev):
  347. """IBSS RSN regression test for IBSS_RSN prior IBSS setup"""
  348. if "FAIL" not in dev[0].request("IBSS_RSN 02:03:04:05:06:07"):
  349. raise Exception("Unexpected IBSS_RSN result")
  350. def test_ibss_5ghz(dev):
  351. """IBSS on 5 GHz band"""
  352. try:
  353. _test_ibss_5ghz(dev)
  354. finally:
  355. subprocess.call(['iw', 'reg', 'set', '00'])
  356. dev[0].flush_scan_cache()
  357. dev[1].flush_scan_cache()
  358. def _test_ibss_5ghz(dev):
  359. subprocess.call(['iw', 'reg', 'set', 'US'])
  360. for i in range(2):
  361. for j in range(5):
  362. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  363. if ev is None:
  364. raise Exception("No regdom change event")
  365. if "alpha2=US" in ev:
  366. break
  367. dev[i].dump_monitor()
  368. ssid="ibss"
  369. id = add_ibss(dev[0], ssid, key_mgmt="NONE", beacon_int="150", freq=5180)
  370. connect_ibss_cmd(dev[0], id, freq=5180)
  371. bssid0 = wait_ibss_connection(dev[0])
  372. dev[1].scan_for_bss(bssid0, freq=5180)
  373. id = add_ibss(dev[1], ssid, key_mgmt="NONE", beacon_int="200", freq=5180)
  374. connect_ibss_cmd(dev[1], id, freq=5180)
  375. bssid1 = wait_ibss_connection(dev[1])
  376. if bssid0 != bssid1:
  377. logger.info("STA0 BSSID " + bssid0 + " differs from STA1 BSSID " + bssid1)
  378. dev[0].request("DISCONNECT")
  379. dev[1].request("DISCONNECT")
  380. dev[0].dump_monitor()
  381. dev[1].dump_monitor()
  382. def test_ibss_vht_80p80(dev):
  383. """IBSS on VHT 80+80 MHz channel"""
  384. try:
  385. _test_ibss_vht_80p80(dev)
  386. finally:
  387. subprocess.call(['iw', 'reg', 'set', '00'])
  388. dev[0].flush_scan_cache()
  389. dev[1].flush_scan_cache()
  390. def _test_ibss_vht_80p80(dev):
  391. subprocess.call(['iw', 'reg', 'set', 'US'])
  392. for i in range(2):
  393. for j in range(5):
  394. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  395. if ev is None:
  396. raise Exception("No regdom change event")
  397. if "alpha2=US" in ev:
  398. break
  399. dev[i].dump_monitor()
  400. ssid="ibss"
  401. id = add_ibss(dev[0], ssid, key_mgmt="NONE", freq=5180, chwidth=3)
  402. connect_ibss_cmd(dev[0], id, freq=5180)
  403. bssid0 = wait_ibss_connection(dev[0])
  404. sig = dev[0].request("SIGNAL_POLL").splitlines()
  405. if "FREQUENCY=5180" not in sig:
  406. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  407. if "WIDTH=80+80 MHz" not in sig:
  408. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  409. if "CENTER_FRQ1=5210" not in sig:
  410. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  411. if "CENTER_FRQ2=5775" not in sig:
  412. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  413. dev[1].scan_for_bss(bssid0, freq=5180)
  414. id = add_ibss(dev[1], ssid, key_mgmt="NONE", freq=5180, chwidth=3)
  415. connect_ibss_cmd(dev[1], id, freq=5180)
  416. bssid1 = wait_ibss_connection(dev[1])
  417. if bssid0 != bssid1:
  418. logger.info("STA0 BSSID " + bssid0 + " differs from STA1 BSSID " + bssid1)
  419. sig = dev[1].request("SIGNAL_POLL").splitlines()
  420. if "FREQUENCY=5180" not in sig:
  421. raise Exception("Unexpected SIGNAL_POLL value(1b): " + str(sig))
  422. logger.info("STA1 SIGNAL_POLL: " + str(sig))
  423. # For now, don't report errors on joining STA failing to get 80+80 MHZ
  424. # since mac80211 missed functionality for that to work.
  425. dev[0].request("DISCONNECT")
  426. dev[1].request("DISCONNECT")
  427. dev[0].dump_monitor()
  428. dev[1].dump_monitor()
  429. def test_ibss_rsn_oom(dev):
  430. """IBSS RSN OOM during wpa_init"""
  431. with alloc_fail(dev[0], 1, "wpa_init"):
  432. ssid="ibss-rsn"
  433. id = add_ibss_rsn(dev[0], ssid, scan_freq=2412)
  434. connect_ibss_cmd(dev[0], id)
  435. bssid0 = wait_ibss_connection(dev[0])
  436. dev[0].request("REMOVE_NETWORK all")
  437. dev[0].dump_monitor()
  438. with alloc_fail(dev[0], 1, "=ibss_rsn_init"):
  439. ssid="ibss-rsn"
  440. id = add_ibss_rsn(dev[0], ssid, scan_freq=2412)
  441. connect_ibss_cmd(dev[0], id)
  442. bssid0 = wait_ibss_connection(dev[0])
  443. dev[0].request("REMOVE_NETWORK all")
  444. dev[0].dump_monitor()
  445. def send_eapol_rx(dev, dst):
  446. if "OK" not in dev.request("EAPOL_RX %s 0203005f02008a001000000000000000013a54fb19d8a785f5986bdc2ba800553550bc9513e6603eb50809154588c22b110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" % dst):
  447. raise Exception("EAPOL_RX for %s failed" % dst)
  448. def test_ibss_rsn_eapol_trigger(dev):
  449. """IBSS RSN and EAPOL trigger for a new peer"""
  450. ssid="ibss-rsn"
  451. id = add_ibss_rsn(dev[0], ssid, scan_freq=2412)
  452. connect_ibss_cmd(dev[0], id)
  453. bssid0 = wait_ibss_connection(dev[0])
  454. send_eapol_rx(dev[0], "02:ff:00:00:00:01")
  455. send_eapol_rx(dev[0], "02:ff:00:00:00:01")
  456. dst = "02:ff:00:00:00:01"
  457. logger.info("Too short EAPOL frame")
  458. if "OK" not in dev[0].request("EAPOL_RX %s 0203005e02008a001000000000000000013a54fb19d8a785f5986bdc2ba800553550bc9513e6603eb50809154588c22b1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" % dst):
  459. raise Exception("EAPOL_RX for %s failed" % dst)
  460. logger.info("RSN: EAPOL frame (type 255) discarded, not a Key frame")
  461. if "OK" not in dev[0].request("EAPOL_RX %s 02ff005f02008a001000000000000000013a54fb19d8a785f5986bdc2ba800553550bc9513e6603eb50809154588c22b110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" % dst):
  462. raise Exception("EAPOL_RX for %s failed" % dst)
  463. logger.info("RSN: EAPOL frame payload size 96 invalid (frame size 99)")
  464. if "OK" not in dev[0].request("EAPOL_RX %s 0203006002008a001000000000000000013a54fb19d8a785f5986bdc2ba800553550bc9513e6603eb50809154588c22b110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" % dst):
  465. raise Exception("EAPOL_RX for %s failed" % dst)
  466. logger.info("RSN: EAPOL-Key type (255) unknown, discarded")
  467. if "OK" not in dev[0].request("EAPOL_RX %s 0203005fff008a001000000000000000013a54fb19d8a785f5986bdc2ba800553550bc9513e6603eb50809154588c22b110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" % dst):
  468. raise Exception("EAPOL_RX for %s failed" % dst)
  469. with alloc_fail(dev[0], 1, "ibss_rsn_rx_eapol"):
  470. send_eapol_rx(dev[0], "02:ff:00:00:00:02")
  471. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  472. with alloc_fail(dev[0], 1, "wpa_auth_sta_init;ibss_rsn_auth_init"):
  473. send_eapol_rx(dev[0], "02:ff:00:00:00:03")
  474. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  475. with alloc_fail(dev[0], 1, "=ibss_rsn_peer_init"):
  476. send_eapol_rx(dev[0], "02:ff:00:00:00:04")
  477. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  478. with alloc_fail(dev[0], 1, "ibss_rsn_process_rx_eapol"):
  479. send_eapol_rx(dev[0], "02:ff:00:00:00:05")
  480. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  481. with alloc_fail(dev[0], 1,
  482. "wpa_sm_set_assoc_wpa_ie_default;ibss_rsn_supp_init"):
  483. send_eapol_rx(dev[0], "02:ff:00:00:00:06")
  484. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  485. with alloc_fail(dev[0], 1, "wpa_sm_init;ibss_rsn_supp_init"):
  486. send_eapol_rx(dev[0], "02:ff:00:00:00:07")
  487. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  488. with alloc_fail(dev[0], 1, "=ibss_rsn_supp_init"):
  489. send_eapol_rx(dev[0], "02:ff:00:00:00:08")
  490. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  491. with alloc_fail(dev[0], 1, "supp_alloc_eapol"):
  492. send_eapol_rx(dev[0], "02:ff:00:00:00:09")
  493. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  494. with alloc_fail(dev[0], 1, "wpa_validate_wpa_ie;ibss_rsn_auth_init"):
  495. send_eapol_rx(dev[0], "02:ff:00:00:00:0a")
  496. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  497. logger.info("RSN: Timeout on waiting Authentication frame response")
  498. if "OK" not in dev[0].request("IBSS_RSN 02:ff:00:00:00:0b"):
  499. raise Exception("Unexpected IBSS_RSN result")
  500. time.sleep(1.1)