test_wpas_mesh.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. #!/usr/bin/python
  2. #
  3. # wpa_supplicant mesh mode tests
  4. # Copyright (c) 2014, cozybit Inc.
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import logging
  9. logger = logging.getLogger()
  10. import subprocess
  11. import hwsim_utils
  12. from wpasupplicant import WpaSupplicant
  13. from utils import HwsimSkip, alloc_fail
  14. def check_mesh_support(dev, secure=False):
  15. if "MESH" not in dev.get_capability("modes"):
  16. raise HwsimSkip("Driver does not support mesh")
  17. if secure and "SAE" not in dev.get_capability("auth_alg"):
  18. raise HwsimSkip("SAE not supported")
  19. def check_mesh_scan(dev, params, other_started=False, beacon_int=0):
  20. if not other_started:
  21. dev.dump_monitor()
  22. id = dev.request("SCAN " + params)
  23. if "FAIL" in id:
  24. raise Exception("Failed to start scan")
  25. id = int(id)
  26. if other_started:
  27. ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
  28. if ev is None:
  29. raise Exception("Other scan did not start")
  30. if "id=" + str(id) in ev:
  31. raise Exception("Own scan id unexpectedly included in start event")
  32. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  33. if ev is None:
  34. raise Exception("Other scan did not complete")
  35. if "id=" + str(id) in ev:
  36. raise Exception(
  37. "Own scan id unexpectedly included in completed event")
  38. ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
  39. if ev is None:
  40. raise Exception("Scan did not start")
  41. if "id=" + str(id) not in ev:
  42. raise Exception("Scan id not included in start event")
  43. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  44. if ev is None:
  45. raise Exception("Scan did not complete")
  46. if "id=" + str(id) not in ev:
  47. raise Exception("Scan id not included in completed event")
  48. res = dev.request("SCAN_RESULTS")
  49. if res.find("[MESH]") < 0:
  50. raise Exception("Scan did not contain a MESH network")
  51. bssid = res.splitlines()[1].split(' ')[0]
  52. bss = dev.get_bss(bssid)
  53. if bss is None:
  54. raise Exception("Could not get BSS entry for mesh")
  55. if 'mesh_capability' not in bss:
  56. raise Exception("mesh_capability missing from BSS entry")
  57. if beacon_int:
  58. if 'beacon_int' not in bss:
  59. raise Exception("beacon_int missing from BSS entry")
  60. if str(beacon_int) != bss['beacon_int']:
  61. raise Exception("Unexpected beacon_int in BSS entry: " + bss['beacon_int'])
  62. def check_mesh_group_added(dev):
  63. ev = dev.wait_event(["MESH-GROUP-STARTED"])
  64. if ev is None:
  65. raise Exception("Test exception: Couldn't join mesh")
  66. def check_mesh_group_removed(dev):
  67. ev = dev.wait_event(["MESH-GROUP-REMOVED"])
  68. if ev is None:
  69. raise Exception("Test exception: Couldn't leave mesh")
  70. def check_mesh_peer_connected(dev, timeout=10):
  71. ev = dev.wait_event(["MESH-PEER-CONNECTED"], timeout=timeout)
  72. if ev is None:
  73. raise Exception("Test exception: Remote peer did not connect.")
  74. def check_mesh_peer_disconnected(dev):
  75. ev = dev.wait_event(["MESH-PEER-DISCONNECTED"])
  76. if ev is None:
  77. raise Exception("Test exception: Peer disconnect event not detected.")
  78. def test_wpas_add_set_remove_support(dev):
  79. """wpa_supplicant MESH add/set/remove network support"""
  80. check_mesh_support(dev[0])
  81. id = dev[0].add_network()
  82. dev[0].set_network(id, "mode", "5")
  83. dev[0].remove_network(id)
  84. def add_open_mesh_network(dev, freq="2412", start=True, beacon_int=0,
  85. basic_rates=None):
  86. id = dev.add_network()
  87. dev.set_network(id, "mode", "5")
  88. dev.set_network_quoted(id, "ssid", "wpas-mesh-open")
  89. dev.set_network(id, "key_mgmt", "NONE")
  90. dev.set_network(id, "frequency", freq)
  91. if beacon_int:
  92. dev.set_network(id, "beacon_int", str(beacon_int))
  93. if basic_rates:
  94. dev.set_network(id, "mesh_basic_rates", basic_rates)
  95. if start:
  96. dev.mesh_group_add(id)
  97. return id
  98. def test_wpas_mesh_group_added(dev):
  99. """wpa_supplicant MESH group add"""
  100. check_mesh_support(dev[0])
  101. add_open_mesh_network(dev[0])
  102. # Check for MESH-GROUP-STARTED event
  103. check_mesh_group_added(dev[0])
  104. def test_wpas_mesh_group_remove(dev):
  105. """wpa_supplicant MESH group remove"""
  106. check_mesh_support(dev[0])
  107. add_open_mesh_network(dev[0])
  108. # Check for MESH-GROUP-STARTED event
  109. check_mesh_group_added(dev[0])
  110. dev[0].mesh_group_remove()
  111. # Check for MESH-GROUP-REMOVED event
  112. check_mesh_group_removed(dev[0])
  113. dev[0].mesh_group_remove()
  114. def test_wpas_mesh_peer_connected(dev):
  115. """wpa_supplicant MESH peer connected"""
  116. check_mesh_support(dev[0])
  117. add_open_mesh_network(dev[0], beacon_int=160)
  118. add_open_mesh_network(dev[1], beacon_int=160)
  119. # Check for mesh joined
  120. check_mesh_group_added(dev[0])
  121. check_mesh_group_added(dev[1])
  122. # Check for peer connected
  123. check_mesh_peer_connected(dev[0])
  124. check_mesh_peer_connected(dev[1])
  125. def test_wpas_mesh_peer_disconnected(dev):
  126. """wpa_supplicant MESH peer disconnected"""
  127. check_mesh_support(dev[0])
  128. add_open_mesh_network(dev[0])
  129. add_open_mesh_network(dev[1])
  130. # Check for mesh joined
  131. check_mesh_group_added(dev[0])
  132. check_mesh_group_added(dev[1])
  133. # Check for peer connected
  134. check_mesh_peer_connected(dev[0])
  135. check_mesh_peer_connected(dev[1])
  136. # Remove group on dev 1
  137. dev[1].mesh_group_remove()
  138. # Device 0 should get a disconnection event
  139. check_mesh_peer_disconnected(dev[0])
  140. def test_wpas_mesh_mode_scan(dev):
  141. """wpa_supplicant MESH scan support"""
  142. check_mesh_support(dev[0])
  143. add_open_mesh_network(dev[0])
  144. add_open_mesh_network(dev[1], beacon_int=175)
  145. # Check for mesh joined
  146. check_mesh_group_added(dev[0])
  147. check_mesh_group_added(dev[1])
  148. # Check for Mesh scan
  149. check_mesh_scan(dev[0], "use_id=1", beacon_int=175)
  150. def test_wpas_mesh_open(dev, apdev):
  151. """wpa_supplicant open MESH network connectivity"""
  152. check_mesh_support(dev[0])
  153. add_open_mesh_network(dev[0], freq="2462", basic_rates="60 120 240")
  154. add_open_mesh_network(dev[1], freq="2462", basic_rates="60 120 240")
  155. # Check for mesh joined
  156. check_mesh_group_added(dev[0])
  157. check_mesh_group_added(dev[1])
  158. # Check for peer connected
  159. check_mesh_peer_connected(dev[0])
  160. check_mesh_peer_connected(dev[1])
  161. # Test connectivity 0->1 and 1->0
  162. hwsim_utils.test_connectivity(dev[0], dev[1])
  163. def test_wpas_mesh_open_no_auto(dev, apdev):
  164. """wpa_supplicant open MESH network connectivity"""
  165. check_mesh_support(dev[0])
  166. id = add_open_mesh_network(dev[0], start=False)
  167. dev[0].set_network(id, "dot11MeshMaxRetries", "16")
  168. dev[0].set_network(id, "dot11MeshRetryTimeout", "255")
  169. dev[0].mesh_group_add(id)
  170. id = add_open_mesh_network(dev[1], start=False)
  171. dev[1].set_network(id, "no_auto_peer", "1")
  172. dev[1].mesh_group_add(id)
  173. # Check for mesh joined
  174. check_mesh_group_added(dev[0])
  175. check_mesh_group_added(dev[1])
  176. # Check for peer connected
  177. check_mesh_peer_connected(dev[0], timeout=30)
  178. check_mesh_peer_connected(dev[1])
  179. # Test connectivity 0->1 and 1->0
  180. hwsim_utils.test_connectivity(dev[0], dev[1])
  181. def add_mesh_secure_net(dev, psk=True):
  182. id = dev.add_network()
  183. dev.set_network(id, "mode", "5")
  184. dev.set_network_quoted(id, "ssid", "wpas-mesh-sec")
  185. dev.set_network(id, "key_mgmt", "SAE")
  186. dev.set_network(id, "frequency", "2412")
  187. if psk:
  188. dev.set_network_quoted(id, "psk", "thisismypassphrase!")
  189. return id
  190. def test_wpas_mesh_secure(dev, apdev):
  191. """wpa_supplicant secure MESH network connectivity"""
  192. check_mesh_support(dev[0], secure=True)
  193. dev[0].request("SET sae_groups ")
  194. id = add_mesh_secure_net(dev[0])
  195. dev[0].mesh_group_add(id)
  196. dev[1].request("SET sae_groups ")
  197. id = add_mesh_secure_net(dev[1])
  198. dev[1].mesh_group_add(id)
  199. # Check for mesh joined
  200. check_mesh_group_added(dev[0])
  201. check_mesh_group_added(dev[1])
  202. # Check for peer connected
  203. check_mesh_peer_connected(dev[0])
  204. check_mesh_peer_connected(dev[1])
  205. # Test connectivity 0->1 and 1->0
  206. hwsim_utils.test_connectivity(dev[0], dev[1])
  207. def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev):
  208. """wpa_supplicant secure MESH and SAE group mismatch"""
  209. check_mesh_support(dev[0], secure=True)
  210. addr0 = dev[0].p2p_interface_addr()
  211. addr1 = dev[1].p2p_interface_addr()
  212. addr2 = dev[2].p2p_interface_addr()
  213. dev[0].request("SET sae_groups 19 25")
  214. id = add_mesh_secure_net(dev[0])
  215. dev[0].mesh_group_add(id)
  216. dev[1].request("SET sae_groups 19")
  217. id = add_mesh_secure_net(dev[1])
  218. dev[1].mesh_group_add(id)
  219. dev[2].request("SET sae_groups 26")
  220. id = add_mesh_secure_net(dev[2])
  221. dev[2].mesh_group_add(id)
  222. check_mesh_group_added(dev[0])
  223. check_mesh_group_added(dev[1])
  224. check_mesh_group_added(dev[2])
  225. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
  226. if ev is None:
  227. raise Exception("Remote peer did not connect")
  228. if addr1 not in ev:
  229. raise Exception("Unexpected peer connected: " + ev)
  230. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
  231. if ev is None:
  232. raise Exception("Remote peer did not connect")
  233. if addr0 not in ev:
  234. raise Exception("Unexpected peer connected: " + ev)
  235. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  236. if ev is not None:
  237. raise Exception("Unexpected peer connection at dev[2]: " + ev)
  238. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  239. if ev is not None:
  240. raise Exception("Unexpected peer connection: " + ev)
  241. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  242. if ev is not None:
  243. raise Exception("Unexpected peer connection: " + ev)
  244. dev[0].request("SET sae_groups ")
  245. dev[1].request("SET sae_groups ")
  246. dev[2].request("SET sae_groups ")
  247. def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
  248. """wpa_supplicant secure MESH and missing SAE password"""
  249. check_mesh_support(dev[0], secure=True)
  250. id = add_mesh_secure_net(dev[0], psk=False)
  251. dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
  252. dev[0].mesh_group_add(id)
  253. ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
  254. timeout=5)
  255. if ev is None:
  256. raise Exception("Timeout on mesh start event")
  257. if "MESH-GROUP-STARTED" in ev:
  258. raise Exception("Unexpected mesh group start")
  259. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
  260. if ev is not None:
  261. raise Exception("Unexpected mesh group start")
  262. def test_wpas_mesh_secure_no_auto(dev, apdev):
  263. """wpa_supplicant secure MESH network connectivity"""
  264. check_mesh_support(dev[0], secure=True)
  265. dev[0].request("SET sae_groups 19")
  266. id = add_mesh_secure_net(dev[0])
  267. dev[0].mesh_group_add(id)
  268. dev[1].request("SET sae_groups 19")
  269. id = add_mesh_secure_net(dev[1])
  270. dev[1].set_network(id, "no_auto_peer", "1")
  271. dev[1].mesh_group_add(id)
  272. # Check for mesh joined
  273. check_mesh_group_added(dev[0])
  274. check_mesh_group_added(dev[1])
  275. # Check for peer connected
  276. check_mesh_peer_connected(dev[0], timeout=30)
  277. check_mesh_peer_connected(dev[1])
  278. # Test connectivity 0->1 and 1->0
  279. hwsim_utils.test_connectivity(dev[0], dev[1])
  280. dev[0].request("SET sae_groups ")
  281. dev[1].request("SET sae_groups ")
  282. def test_wpas_mesh_ctrl(dev):
  283. """wpa_supplicant ctrl_iface mesh command error cases"""
  284. check_mesh_support(dev[0])
  285. if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
  286. raise Exception("Unexpected MESH_GROUP_ADD success")
  287. id = dev[0].add_network()
  288. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  289. raise Exception("Unexpected MESH_GROUP_ADD success")
  290. dev[0].set_network(id, "mode", "5")
  291. dev[0].set_network(id, "key_mgmt", "WPA-PSK")
  292. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  293. raise Exception("Unexpected MESH_GROUP_ADD success")
  294. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
  295. raise Exception("Unexpected MESH_GROUP_REMOVE success")
  296. def test_wpas_mesh_dynamic_interface(dev):
  297. """wpa_supplicant mesh with dynamic interface"""
  298. check_mesh_support(dev[0])
  299. mesh0 = None
  300. mesh1 = None
  301. try:
  302. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  303. if "FAIL" in mesh0:
  304. raise Exception("MESH_INTERFACE_ADD failed")
  305. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  306. if "FAIL" in mesh1:
  307. raise Exception("MESH_INTERFACE_ADD failed")
  308. wpas0 = WpaSupplicant(ifname=mesh0)
  309. wpas1 = WpaSupplicant(ifname=mesh1)
  310. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  311. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  312. add_open_mesh_network(wpas0)
  313. add_open_mesh_network(wpas1)
  314. check_mesh_group_added(wpas0)
  315. check_mesh_group_added(wpas1)
  316. check_mesh_peer_connected(wpas0)
  317. check_mesh_peer_connected(wpas1)
  318. hwsim_utils.test_connectivity(wpas0, wpas1)
  319. # Must not allow MESH_GROUP_REMOVE on dynamic interface
  320. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
  321. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  322. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
  323. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  324. # Must not allow MESH_GROUP_REMOVE on another radio interface
  325. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
  326. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  327. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
  328. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  329. wpas0.remove_ifname()
  330. wpas1.remove_ifname()
  331. if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  332. raise Exception("MESH_GROUP_REMOVE failed")
  333. if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  334. raise Exception("MESH_GROUP_REMOVE failed")
  335. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  336. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  337. if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  338. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  339. logger.info("Make sure another dynamic group can be added")
  340. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  341. if "FAIL" in mesh0:
  342. raise Exception("MESH_INTERFACE_ADD failed")
  343. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  344. if "FAIL" in mesh1:
  345. raise Exception("MESH_INTERFACE_ADD failed")
  346. wpas0 = WpaSupplicant(ifname=mesh0)
  347. wpas1 = WpaSupplicant(ifname=mesh1)
  348. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  349. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  350. add_open_mesh_network(wpas0)
  351. add_open_mesh_network(wpas1)
  352. check_mesh_group_added(wpas0)
  353. check_mesh_group_added(wpas1)
  354. check_mesh_peer_connected(wpas0)
  355. check_mesh_peer_connected(wpas1)
  356. hwsim_utils.test_connectivity(wpas0, wpas1)
  357. finally:
  358. if mesh0:
  359. dev[0].request("MESH_GROUP_REMOVE " + mesh0)
  360. if mesh1:
  361. dev[1].request("MESH_GROUP_REMOVE " + mesh1)
  362. def test_wpas_mesh_max_peering(dev, apdev):
  363. """Mesh max peering limit"""
  364. check_mesh_support(dev[0])
  365. try:
  366. dev[0].request("SET max_peer_links 1")
  367. # first, connect dev[0] and dev[1]
  368. add_open_mesh_network(dev[0])
  369. add_open_mesh_network(dev[1])
  370. for i in range(2):
  371. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  372. if ev is None:
  373. raise Exception("dev%d did not connect with any peer" % i)
  374. # add dev[2] which will try to connect with both dev[0] and dev[1],
  375. # but can complete connection only with dev[1]
  376. add_open_mesh_network(dev[2])
  377. for i in range(1, 3):
  378. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  379. if ev is None:
  380. raise Exception("dev%d did not connect the second peer" % i)
  381. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  382. if ev is not None:
  383. raise Exception("dev0 connection beyond max peering limit")
  384. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  385. if ev is not None:
  386. raise Exception("dev2 reported unexpected peering: " + ev)
  387. for i in range(3):
  388. dev[i].mesh_group_remove()
  389. check_mesh_group_removed(dev[i])
  390. finally:
  391. dev[0].request("SET max_peer_links 99")
  392. def test_wpas_mesh_open_5ghz(dev, apdev):
  393. """wpa_supplicant open MESH network on 5 GHz band"""
  394. try:
  395. _test_wpas_mesh_open_5ghz(dev, apdev)
  396. finally:
  397. subprocess.call(['iw', 'reg', 'set', '00'])
  398. dev[0].flush_scan_cache()
  399. dev[1].flush_scan_cache()
  400. def _test_wpas_mesh_open_5ghz(dev, apdev):
  401. check_mesh_support(dev[0])
  402. subprocess.call(['iw', 'reg', 'set', 'US'])
  403. for i in range(2):
  404. for j in range(5):
  405. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  406. if ev is None:
  407. raise Exception("No regdom change event")
  408. if "alpha2=US" in ev:
  409. break
  410. add_open_mesh_network(dev[i], freq="5180")
  411. # Check for mesh joined
  412. check_mesh_group_added(dev[0])
  413. check_mesh_group_added(dev[1])
  414. # Check for peer connected
  415. check_mesh_peer_connected(dev[0])
  416. check_mesh_peer_connected(dev[1])
  417. # Test connectivity 0->1 and 1->0
  418. hwsim_utils.test_connectivity(dev[0], dev[1])
  419. def test_wpas_mesh_password_mismatch(dev, apdev):
  420. """Mesh network and one device with mismatching password"""
  421. check_mesh_support(dev[0], secure=True)
  422. dev[0].request("SET sae_groups ")
  423. id = add_mesh_secure_net(dev[0])
  424. dev[0].mesh_group_add(id)
  425. dev[1].request("SET sae_groups ")
  426. id = add_mesh_secure_net(dev[1])
  427. dev[1].mesh_group_add(id)
  428. dev[2].request("SET sae_groups ")
  429. id = add_mesh_secure_net(dev[2])
  430. dev[2].set_network_quoted(id, "psk", "wrong password")
  431. dev[2].mesh_group_add(id)
  432. # The two peers with matching password need to be able to connect
  433. check_mesh_group_added(dev[0])
  434. check_mesh_group_added(dev[1])
  435. check_mesh_peer_connected(dev[0])
  436. check_mesh_peer_connected(dev[1])
  437. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  438. if ev is None:
  439. raise Exception("dev2 did not report auth failure (1)")
  440. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  441. if ev is None:
  442. raise Exception("dev2 did not report auth failure (2)")
  443. count = 0
  444. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  445. if ev is None:
  446. logger.info("dev0 did not report auth failure")
  447. else:
  448. if "addr=" + dev[2].own_addr() not in ev:
  449. raise Exception("Unexpected peer address in dev0 event: " + ev)
  450. count += 1
  451. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  452. if ev is None:
  453. logger.info("dev1 did not report auth failure")
  454. else:
  455. if "addr=" + dev[2].own_addr() not in ev:
  456. raise Exception("Unexpected peer address in dev1 event: " + ev)
  457. count += 1
  458. hwsim_utils.test_connectivity(dev[0], dev[1])
  459. for i in range(2):
  460. try:
  461. hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
  462. raise Exception("Data connectivity test passed unexpectedly")
  463. except Exception, e:
  464. if "data delivery failed" not in str(e):
  465. raise
  466. if count == 0:
  467. raise Exception("Neither dev0 nor dev1 reported auth failure")
  468. def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
  469. """Mesh password mismatch and retry [long]"""
  470. if not params['long']:
  471. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  472. check_mesh_support(dev[0], secure=True)
  473. dev[0].request("SET sae_groups ")
  474. id = add_mesh_secure_net(dev[0])
  475. dev[0].mesh_group_add(id)
  476. dev[1].request("SET sae_groups ")
  477. id = add_mesh_secure_net(dev[1])
  478. dev[1].set_network_quoted(id, "psk", "wrong password")
  479. dev[1].mesh_group_add(id)
  480. # Check for mesh joined
  481. check_mesh_group_added(dev[0])
  482. check_mesh_group_added(dev[1])
  483. for i in range(4):
  484. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  485. if ev is None:
  486. raise Exception("dev0 did not report auth failure (%d)" % i)
  487. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  488. if ev is None:
  489. raise Exception("dev1 did not report auth failure (%d)" % i)
  490. ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  491. if ev is None:
  492. raise Exception("dev0 did not report auth blocked")
  493. ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  494. if ev is None:
  495. raise Exception("dev1 did not report auth blocked")
  496. def test_mesh_wpa_auth_init_oom(dev, apdev):
  497. """Secure mesh network setup failing due to wpa_init() OOM"""
  498. check_mesh_support(dev[0], secure=True)
  499. dev[0].request("SET sae_groups ")
  500. with alloc_fail(dev[0], 1, "wpa_init"):
  501. id = add_mesh_secure_net(dev[0])
  502. dev[0].mesh_group_add(id)
  503. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
  504. if ev is not None:
  505. raise Exception("Unexpected mesh group start during OOM")