test_wpas_mesh.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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, chwidth=0):
  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 chwidth > 0:
  92. dev.set_network(id, "max_oper_chwidth", str(chwidth))
  93. if beacon_int:
  94. dev.set_network(id, "beacon_int", str(beacon_int))
  95. if basic_rates:
  96. dev.set_network(id, "mesh_basic_rates", basic_rates)
  97. if start:
  98. dev.mesh_group_add(id)
  99. return id
  100. def test_wpas_mesh_group_added(dev):
  101. """wpa_supplicant MESH group add"""
  102. check_mesh_support(dev[0])
  103. add_open_mesh_network(dev[0])
  104. # Check for MESH-GROUP-STARTED event
  105. check_mesh_group_added(dev[0])
  106. def test_wpas_mesh_group_remove(dev):
  107. """wpa_supplicant MESH group remove"""
  108. check_mesh_support(dev[0])
  109. add_open_mesh_network(dev[0])
  110. # Check for MESH-GROUP-STARTED event
  111. check_mesh_group_added(dev[0])
  112. dev[0].mesh_group_remove()
  113. # Check for MESH-GROUP-REMOVED event
  114. check_mesh_group_removed(dev[0])
  115. dev[0].mesh_group_remove()
  116. def test_wpas_mesh_peer_connected(dev):
  117. """wpa_supplicant MESH peer connected"""
  118. check_mesh_support(dev[0])
  119. add_open_mesh_network(dev[0], beacon_int=160)
  120. add_open_mesh_network(dev[1], beacon_int=160)
  121. # Check for mesh joined
  122. check_mesh_group_added(dev[0])
  123. check_mesh_group_added(dev[1])
  124. # Check for peer connected
  125. check_mesh_peer_connected(dev[0])
  126. check_mesh_peer_connected(dev[1])
  127. def test_wpas_mesh_peer_disconnected(dev):
  128. """wpa_supplicant MESH peer disconnected"""
  129. check_mesh_support(dev[0])
  130. add_open_mesh_network(dev[0])
  131. add_open_mesh_network(dev[1])
  132. # Check for mesh joined
  133. check_mesh_group_added(dev[0])
  134. check_mesh_group_added(dev[1])
  135. # Check for peer connected
  136. check_mesh_peer_connected(dev[0])
  137. check_mesh_peer_connected(dev[1])
  138. # Remove group on dev 1
  139. dev[1].mesh_group_remove()
  140. # Device 0 should get a disconnection event
  141. check_mesh_peer_disconnected(dev[0])
  142. def test_wpas_mesh_mode_scan(dev):
  143. """wpa_supplicant MESH scan support"""
  144. check_mesh_support(dev[0])
  145. add_open_mesh_network(dev[0])
  146. add_open_mesh_network(dev[1], beacon_int=175)
  147. # Check for mesh joined
  148. check_mesh_group_added(dev[0])
  149. check_mesh_group_added(dev[1])
  150. # Check for Mesh scan
  151. check_mesh_scan(dev[0], "use_id=1", beacon_int=175)
  152. def test_wpas_mesh_open(dev, apdev):
  153. """wpa_supplicant open MESH network connectivity"""
  154. check_mesh_support(dev[0])
  155. add_open_mesh_network(dev[0], freq="2462", basic_rates="60 120 240")
  156. add_open_mesh_network(dev[1], freq="2462", basic_rates="60 120 240")
  157. # Check for mesh joined
  158. check_mesh_group_added(dev[0])
  159. check_mesh_group_added(dev[1])
  160. # Check for peer connected
  161. check_mesh_peer_connected(dev[0])
  162. check_mesh_peer_connected(dev[1])
  163. # Test connectivity 0->1 and 1->0
  164. hwsim_utils.test_connectivity(dev[0], dev[1])
  165. def test_wpas_mesh_open_no_auto(dev, apdev):
  166. """wpa_supplicant open MESH network connectivity"""
  167. check_mesh_support(dev[0])
  168. id = add_open_mesh_network(dev[0], start=False)
  169. dev[0].set_network(id, "dot11MeshMaxRetries", "16")
  170. dev[0].set_network(id, "dot11MeshRetryTimeout", "255")
  171. dev[0].mesh_group_add(id)
  172. id = add_open_mesh_network(dev[1], start=False)
  173. dev[1].set_network(id, "no_auto_peer", "1")
  174. dev[1].mesh_group_add(id)
  175. # Check for mesh joined
  176. check_mesh_group_added(dev[0])
  177. check_mesh_group_added(dev[1])
  178. # Check for peer connected
  179. check_mesh_peer_connected(dev[0], timeout=30)
  180. check_mesh_peer_connected(dev[1])
  181. # Test connectivity 0->1 and 1->0
  182. hwsim_utils.test_connectivity(dev[0], dev[1])
  183. def add_mesh_secure_net(dev, psk=True):
  184. id = dev.add_network()
  185. dev.set_network(id, "mode", "5")
  186. dev.set_network_quoted(id, "ssid", "wpas-mesh-sec")
  187. dev.set_network(id, "key_mgmt", "SAE")
  188. dev.set_network(id, "frequency", "2412")
  189. if psk:
  190. dev.set_network_quoted(id, "psk", "thisismypassphrase!")
  191. return id
  192. def test_wpas_mesh_secure(dev, apdev):
  193. """wpa_supplicant secure MESH network connectivity"""
  194. check_mesh_support(dev[0], secure=True)
  195. dev[0].request("SET sae_groups ")
  196. id = add_mesh_secure_net(dev[0])
  197. dev[0].mesh_group_add(id)
  198. dev[1].request("SET sae_groups ")
  199. id = add_mesh_secure_net(dev[1])
  200. dev[1].mesh_group_add(id)
  201. # Check for mesh joined
  202. check_mesh_group_added(dev[0])
  203. check_mesh_group_added(dev[1])
  204. # Check for peer connected
  205. check_mesh_peer_connected(dev[0])
  206. check_mesh_peer_connected(dev[1])
  207. # Test connectivity 0->1 and 1->0
  208. hwsim_utils.test_connectivity(dev[0], dev[1])
  209. def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev):
  210. """wpa_supplicant secure MESH and SAE group mismatch"""
  211. check_mesh_support(dev[0], secure=True)
  212. addr0 = dev[0].p2p_interface_addr()
  213. addr1 = dev[1].p2p_interface_addr()
  214. addr2 = dev[2].p2p_interface_addr()
  215. dev[0].request("SET sae_groups 19 25")
  216. id = add_mesh_secure_net(dev[0])
  217. dev[0].mesh_group_add(id)
  218. dev[1].request("SET sae_groups 19")
  219. id = add_mesh_secure_net(dev[1])
  220. dev[1].mesh_group_add(id)
  221. dev[2].request("SET sae_groups 26")
  222. id = add_mesh_secure_net(dev[2])
  223. dev[2].mesh_group_add(id)
  224. check_mesh_group_added(dev[0])
  225. check_mesh_group_added(dev[1])
  226. check_mesh_group_added(dev[2])
  227. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
  228. if ev is None:
  229. raise Exception("Remote peer did not connect")
  230. if addr1 not in ev:
  231. raise Exception("Unexpected peer connected: " + ev)
  232. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
  233. if ev is None:
  234. raise Exception("Remote peer did not connect")
  235. if addr0 not in ev:
  236. raise Exception("Unexpected peer connected: " + ev)
  237. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  238. if ev is not None:
  239. raise Exception("Unexpected peer connection at dev[2]: " + ev)
  240. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  241. if ev is not None:
  242. raise Exception("Unexpected peer connection: " + ev)
  243. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  244. if ev is not None:
  245. raise Exception("Unexpected peer connection: " + ev)
  246. dev[0].request("SET sae_groups ")
  247. dev[1].request("SET sae_groups ")
  248. dev[2].request("SET sae_groups ")
  249. def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
  250. """wpa_supplicant secure MESH and missing SAE password"""
  251. check_mesh_support(dev[0], secure=True)
  252. id = add_mesh_secure_net(dev[0], psk=False)
  253. dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
  254. dev[0].mesh_group_add(id)
  255. ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
  256. timeout=5)
  257. if ev is None:
  258. raise Exception("Timeout on mesh start event")
  259. if "MESH-GROUP-STARTED" in ev:
  260. raise Exception("Unexpected mesh group start")
  261. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
  262. if ev is not None:
  263. raise Exception("Unexpected mesh group start")
  264. def test_wpas_mesh_secure_no_auto(dev, apdev):
  265. """wpa_supplicant secure MESH network connectivity"""
  266. check_mesh_support(dev[0], secure=True)
  267. dev[0].request("SET sae_groups 19")
  268. id = add_mesh_secure_net(dev[0])
  269. dev[0].mesh_group_add(id)
  270. dev[1].request("SET sae_groups 19")
  271. id = add_mesh_secure_net(dev[1])
  272. dev[1].set_network(id, "no_auto_peer", "1")
  273. dev[1].mesh_group_add(id)
  274. # Check for mesh joined
  275. check_mesh_group_added(dev[0])
  276. check_mesh_group_added(dev[1])
  277. # Check for peer connected
  278. check_mesh_peer_connected(dev[0], timeout=30)
  279. check_mesh_peer_connected(dev[1])
  280. # Test connectivity 0->1 and 1->0
  281. hwsim_utils.test_connectivity(dev[0], dev[1])
  282. dev[0].request("SET sae_groups ")
  283. dev[1].request("SET sae_groups ")
  284. def test_wpas_mesh_ctrl(dev):
  285. """wpa_supplicant ctrl_iface mesh command error cases"""
  286. check_mesh_support(dev[0])
  287. if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
  288. raise Exception("Unexpected MESH_GROUP_ADD success")
  289. id = dev[0].add_network()
  290. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  291. raise Exception("Unexpected MESH_GROUP_ADD success")
  292. dev[0].set_network(id, "mode", "5")
  293. dev[0].set_network(id, "key_mgmt", "WPA-PSK")
  294. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  295. raise Exception("Unexpected MESH_GROUP_ADD success")
  296. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
  297. raise Exception("Unexpected MESH_GROUP_REMOVE success")
  298. def test_wpas_mesh_dynamic_interface(dev):
  299. """wpa_supplicant mesh with dynamic interface"""
  300. check_mesh_support(dev[0])
  301. mesh0 = None
  302. mesh1 = None
  303. try:
  304. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  305. if "FAIL" in mesh0:
  306. raise Exception("MESH_INTERFACE_ADD failed")
  307. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  308. if "FAIL" in mesh1:
  309. raise Exception("MESH_INTERFACE_ADD failed")
  310. wpas0 = WpaSupplicant(ifname=mesh0)
  311. wpas1 = WpaSupplicant(ifname=mesh1)
  312. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  313. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  314. add_open_mesh_network(wpas0)
  315. add_open_mesh_network(wpas1)
  316. check_mesh_group_added(wpas0)
  317. check_mesh_group_added(wpas1)
  318. check_mesh_peer_connected(wpas0)
  319. check_mesh_peer_connected(wpas1)
  320. hwsim_utils.test_connectivity(wpas0, wpas1)
  321. # Must not allow MESH_GROUP_REMOVE on dynamic interface
  322. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
  323. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  324. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
  325. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  326. # Must not allow MESH_GROUP_REMOVE on another radio interface
  327. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
  328. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  329. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
  330. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  331. wpas0.remove_ifname()
  332. wpas1.remove_ifname()
  333. if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  334. raise Exception("MESH_GROUP_REMOVE failed")
  335. if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  336. raise Exception("MESH_GROUP_REMOVE failed")
  337. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  338. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  339. if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  340. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  341. logger.info("Make sure another dynamic group can be added")
  342. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  343. if "FAIL" in mesh0:
  344. raise Exception("MESH_INTERFACE_ADD failed")
  345. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  346. if "FAIL" in mesh1:
  347. raise Exception("MESH_INTERFACE_ADD failed")
  348. wpas0 = WpaSupplicant(ifname=mesh0)
  349. wpas1 = WpaSupplicant(ifname=mesh1)
  350. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  351. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  352. add_open_mesh_network(wpas0)
  353. add_open_mesh_network(wpas1)
  354. check_mesh_group_added(wpas0)
  355. check_mesh_group_added(wpas1)
  356. check_mesh_peer_connected(wpas0)
  357. check_mesh_peer_connected(wpas1)
  358. hwsim_utils.test_connectivity(wpas0, wpas1)
  359. finally:
  360. if mesh0:
  361. dev[0].request("MESH_GROUP_REMOVE " + mesh0)
  362. if mesh1:
  363. dev[1].request("MESH_GROUP_REMOVE " + mesh1)
  364. def test_wpas_mesh_max_peering(dev, apdev):
  365. """Mesh max peering limit"""
  366. check_mesh_support(dev[0])
  367. try:
  368. dev[0].request("SET max_peer_links 1")
  369. # first, connect dev[0] and dev[1]
  370. add_open_mesh_network(dev[0])
  371. add_open_mesh_network(dev[1])
  372. for i in range(2):
  373. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  374. if ev is None:
  375. raise Exception("dev%d did not connect with any peer" % i)
  376. # add dev[2] which will try to connect with both dev[0] and dev[1],
  377. # but can complete connection only with dev[1]
  378. add_open_mesh_network(dev[2])
  379. for i in range(1, 3):
  380. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  381. if ev is None:
  382. raise Exception("dev%d did not connect the second peer" % i)
  383. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  384. if ev is not None:
  385. raise Exception("dev0 connection beyond max peering limit")
  386. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  387. if ev is not None:
  388. raise Exception("dev2 reported unexpected peering: " + ev)
  389. for i in range(3):
  390. dev[i].mesh_group_remove()
  391. check_mesh_group_removed(dev[i])
  392. finally:
  393. dev[0].request("SET max_peer_links 99")
  394. def test_wpas_mesh_open_5ghz(dev, apdev):
  395. """wpa_supplicant open MESH network on 5 GHz band"""
  396. try:
  397. _test_wpas_mesh_open_5ghz(dev, apdev)
  398. finally:
  399. subprocess.call(['iw', 'reg', 'set', '00'])
  400. dev[0].flush_scan_cache()
  401. dev[1].flush_scan_cache()
  402. def _test_wpas_mesh_open_5ghz(dev, apdev):
  403. check_mesh_support(dev[0])
  404. subprocess.call(['iw', 'reg', 'set', 'US'])
  405. for i in range(2):
  406. for j in range(5):
  407. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  408. if ev is None:
  409. raise Exception("No regdom change event")
  410. if "alpha2=US" in ev:
  411. break
  412. add_open_mesh_network(dev[i], freq="5180")
  413. # Check for mesh joined
  414. check_mesh_group_added(dev[0])
  415. check_mesh_group_added(dev[1])
  416. # Check for peer connected
  417. check_mesh_peer_connected(dev[0])
  418. check_mesh_peer_connected(dev[1])
  419. # Test connectivity 0->1 and 1->0
  420. hwsim_utils.test_connectivity(dev[0], dev[1])
  421. def test_wpas_mesh_open_vht_80p80(dev, apdev):
  422. """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
  423. try:
  424. _test_wpas_mesh_open_vht_80p80(dev, apdev)
  425. finally:
  426. subprocess.call(['iw', 'reg', 'set', '00'])
  427. dev[0].flush_scan_cache()
  428. dev[1].flush_scan_cache()
  429. def _test_wpas_mesh_open_vht_80p80(dev, apdev):
  430. check_mesh_support(dev[0])
  431. subprocess.call(['iw', 'reg', 'set', 'US'])
  432. for i in range(2):
  433. for j in range(5):
  434. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  435. if ev is None:
  436. raise Exception("No regdom change event")
  437. if "alpha2=US" in ev:
  438. break
  439. add_open_mesh_network(dev[i], freq="5180", chwidth=3)
  440. # Check for mesh joined
  441. check_mesh_group_added(dev[0])
  442. check_mesh_group_added(dev[1])
  443. # Check for peer connected
  444. check_mesh_peer_connected(dev[0])
  445. check_mesh_peer_connected(dev[1])
  446. # Test connectivity 0->1 and 1->0
  447. hwsim_utils.test_connectivity(dev[0], dev[1])
  448. sig = dev[0].request("SIGNAL_POLL").splitlines()
  449. if "WIDTH=80+80 MHz" not in sig:
  450. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  451. if "CENTER_FRQ1=5210" not in sig:
  452. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  453. if "CENTER_FRQ2=5775" not in sig:
  454. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  455. sig = dev[1].request("SIGNAL_POLL").splitlines()
  456. if "WIDTH=80+80 MHz" not in sig:
  457. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  458. if "CENTER_FRQ1=5210" not in sig:
  459. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  460. if "CENTER_FRQ2=5775" not in sig:
  461. raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
  462. def test_wpas_mesh_password_mismatch(dev, apdev):
  463. """Mesh network and one device with mismatching password"""
  464. check_mesh_support(dev[0], secure=True)
  465. dev[0].request("SET sae_groups ")
  466. id = add_mesh_secure_net(dev[0])
  467. dev[0].mesh_group_add(id)
  468. dev[1].request("SET sae_groups ")
  469. id = add_mesh_secure_net(dev[1])
  470. dev[1].mesh_group_add(id)
  471. dev[2].request("SET sae_groups ")
  472. id = add_mesh_secure_net(dev[2])
  473. dev[2].set_network_quoted(id, "psk", "wrong password")
  474. dev[2].mesh_group_add(id)
  475. # The two peers with matching password need to be able to connect
  476. check_mesh_group_added(dev[0])
  477. check_mesh_group_added(dev[1])
  478. check_mesh_peer_connected(dev[0])
  479. check_mesh_peer_connected(dev[1])
  480. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  481. if ev is None:
  482. raise Exception("dev2 did not report auth failure (1)")
  483. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  484. if ev is None:
  485. raise Exception("dev2 did not report auth failure (2)")
  486. count = 0
  487. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  488. if ev is None:
  489. logger.info("dev0 did not report auth failure")
  490. else:
  491. if "addr=" + dev[2].own_addr() not in ev:
  492. raise Exception("Unexpected peer address in dev0 event: " + ev)
  493. count += 1
  494. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  495. if ev is None:
  496. logger.info("dev1 did not report auth failure")
  497. else:
  498. if "addr=" + dev[2].own_addr() not in ev:
  499. raise Exception("Unexpected peer address in dev1 event: " + ev)
  500. count += 1
  501. hwsim_utils.test_connectivity(dev[0], dev[1])
  502. for i in range(2):
  503. try:
  504. hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
  505. raise Exception("Data connectivity test passed unexpectedly")
  506. except Exception, e:
  507. if "data delivery failed" not in str(e):
  508. raise
  509. if count == 0:
  510. raise Exception("Neither dev0 nor dev1 reported auth failure")
  511. def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
  512. """Mesh password mismatch and retry [long]"""
  513. if not params['long']:
  514. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  515. check_mesh_support(dev[0], secure=True)
  516. dev[0].request("SET sae_groups ")
  517. id = add_mesh_secure_net(dev[0])
  518. dev[0].mesh_group_add(id)
  519. dev[1].request("SET sae_groups ")
  520. id = add_mesh_secure_net(dev[1])
  521. dev[1].set_network_quoted(id, "psk", "wrong password")
  522. dev[1].mesh_group_add(id)
  523. # Check for mesh joined
  524. check_mesh_group_added(dev[0])
  525. check_mesh_group_added(dev[1])
  526. for i in range(4):
  527. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  528. if ev is None:
  529. raise Exception("dev0 did not report auth failure (%d)" % i)
  530. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  531. if ev is None:
  532. raise Exception("dev1 did not report auth failure (%d)" % i)
  533. ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  534. if ev is None:
  535. raise Exception("dev0 did not report auth blocked")
  536. ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  537. if ev is None:
  538. raise Exception("dev1 did not report auth blocked")
  539. def test_mesh_wpa_auth_init_oom(dev, apdev):
  540. """Secure mesh network setup failing due to wpa_init() OOM"""
  541. check_mesh_support(dev[0], secure=True)
  542. dev[0].request("SET sae_groups ")
  543. with alloc_fail(dev[0], 1, "wpa_init"):
  544. id = add_mesh_secure_net(dev[0])
  545. dev[0].mesh_group_add(id)
  546. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
  547. if ev is not None:
  548. raise Exception("Unexpected mesh group start during OOM")
  549. def test_wpas_mesh_reconnect(dev, apdev):
  550. """Secure mesh network plink counting during reconnection"""
  551. check_mesh_support(dev[0])
  552. try:
  553. _test_wpas_mesh_reconnect(dev)
  554. finally:
  555. dev[0].request("SET max_peer_links 99")
  556. def _test_wpas_mesh_reconnect(dev):
  557. dev[0].request("SET max_peer_links 2")
  558. dev[0].request("SET sae_groups ")
  559. id = add_mesh_secure_net(dev[0])
  560. dev[0].set_network(id, "beacon_int", "100")
  561. dev[0].mesh_group_add(id)
  562. dev[1].request("SET sae_groups ")
  563. id = add_mesh_secure_net(dev[1])
  564. dev[1].mesh_group_add(id)
  565. check_mesh_group_added(dev[0])
  566. check_mesh_group_added(dev[1])
  567. check_mesh_peer_connected(dev[0])
  568. check_mesh_peer_connected(dev[1])
  569. for i in range(3):
  570. # Drop incoming management frames to avoid handling link close
  571. dev[0].request("SET ext_mgmt_frame_handling 1")
  572. dev[1].mesh_group_remove()
  573. check_mesh_group_removed(dev[1])
  574. dev[1].request("FLUSH")
  575. dev[0].request("SET ext_mgmt_frame_handling 0")
  576. id = add_mesh_secure_net(dev[1])
  577. dev[1].mesh_group_add(id)
  578. check_mesh_group_added(dev[1])
  579. check_mesh_peer_connected(dev[1])
  580. dev[0].dump_monitor()
  581. dev[1].dump_monitor()