test_wpas_mesh.py 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. # wpa_supplicant mesh mode tests
  2. # Copyright (c) 2014, cozybit Inc.
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import logging
  7. logger = logging.getLogger()
  8. import os
  9. import subprocess
  10. import time
  11. import hwsim_utils
  12. from wpasupplicant import WpaSupplicant
  13. from utils import HwsimSkip, alloc_fail, fail_test, wait_fail_trigger
  14. from tshark import run_tshark
  15. def check_mesh_support(dev, secure=False):
  16. if "MESH" not in dev.get_capability("modes"):
  17. raise HwsimSkip("Driver does not support mesh")
  18. if secure and "SAE" not in dev.get_capability("auth_alg"):
  19. raise HwsimSkip("SAE not supported")
  20. def check_mesh_scan(dev, params, other_started=False, beacon_int=0):
  21. if not other_started:
  22. dev.dump_monitor()
  23. id = dev.request("SCAN " + params)
  24. if "FAIL" in id:
  25. raise Exception("Failed to start scan")
  26. id = int(id)
  27. if other_started:
  28. ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
  29. if ev is None:
  30. raise Exception("Other scan did not start")
  31. if "id=" + str(id) in ev:
  32. raise Exception("Own scan id unexpectedly included in start event")
  33. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  34. if ev is None:
  35. raise Exception("Other scan did not complete")
  36. if "id=" + str(id) in ev:
  37. raise Exception(
  38. "Own scan id unexpectedly included in completed event")
  39. ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
  40. if ev is None:
  41. raise Exception("Scan did not start")
  42. if "id=" + str(id) not in ev:
  43. raise Exception("Scan id not included in start event")
  44. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  45. if ev is None:
  46. raise Exception("Scan did not complete")
  47. if "id=" + str(id) not in ev:
  48. raise Exception("Scan id not included in completed event")
  49. res = dev.request("SCAN_RESULTS")
  50. if res.find("[MESH]") < 0:
  51. raise Exception("Scan did not contain a MESH network")
  52. bssid = res.splitlines()[1].split(' ')[0]
  53. bss = dev.get_bss(bssid)
  54. if bss is None:
  55. raise Exception("Could not get BSS entry for mesh")
  56. if 'mesh_capability' not in bss:
  57. raise Exception("mesh_capability missing from BSS entry")
  58. if beacon_int:
  59. if 'beacon_int' not in bss:
  60. raise Exception("beacon_int missing from BSS entry")
  61. if str(beacon_int) != bss['beacon_int']:
  62. raise Exception("Unexpected beacon_int in BSS entry: " + bss['beacon_int'])
  63. def check_mesh_group_added(dev):
  64. ev = dev.wait_event(["MESH-GROUP-STARTED"])
  65. if ev is None:
  66. raise Exception("Test exception: Couldn't join mesh")
  67. def check_mesh_group_removed(dev):
  68. ev = dev.wait_event(["MESH-GROUP-REMOVED"])
  69. if ev is None:
  70. raise Exception("Test exception: Couldn't leave mesh")
  71. def check_mesh_peer_connected(dev, timeout=10):
  72. ev = dev.wait_event(["MESH-PEER-CONNECTED"], timeout=timeout)
  73. if ev is None:
  74. raise Exception("Test exception: Remote peer did not connect.")
  75. def check_mesh_peer_disconnected(dev):
  76. ev = dev.wait_event(["MESH-PEER-DISCONNECTED"])
  77. if ev is None:
  78. raise Exception("Test exception: Peer disconnect event not detected.")
  79. def test_wpas_add_set_remove_support(dev):
  80. """wpa_supplicant MESH add/set/remove network support"""
  81. check_mesh_support(dev[0])
  82. id = dev[0].add_network()
  83. dev[0].set_network(id, "mode", "5")
  84. dev[0].remove_network(id)
  85. def add_open_mesh_network(dev, freq="2412", start=True, beacon_int=0,
  86. basic_rates=None, chwidth=0):
  87. id = dev.add_network()
  88. dev.set_network(id, "mode", "5")
  89. dev.set_network_quoted(id, "ssid", "wpas-mesh-open")
  90. dev.set_network(id, "key_mgmt", "NONE")
  91. if freq:
  92. dev.set_network(id, "frequency", freq)
  93. if chwidth > 0:
  94. dev.set_network(id, "max_oper_chwidth", str(chwidth))
  95. if beacon_int:
  96. dev.set_network(id, "beacon_int", str(beacon_int))
  97. if basic_rates:
  98. dev.set_network(id, "mesh_basic_rates", basic_rates)
  99. if start:
  100. dev.mesh_group_add(id)
  101. return id
  102. def test_wpas_mesh_group_added(dev):
  103. """wpa_supplicant MESH group add"""
  104. check_mesh_support(dev[0])
  105. add_open_mesh_network(dev[0])
  106. # Check for MESH-GROUP-STARTED event
  107. check_mesh_group_added(dev[0])
  108. def test_wpas_mesh_group_remove(dev):
  109. """wpa_supplicant MESH group remove"""
  110. check_mesh_support(dev[0])
  111. add_open_mesh_network(dev[0])
  112. # Check for MESH-GROUP-STARTED event
  113. check_mesh_group_added(dev[0])
  114. dev[0].mesh_group_remove()
  115. # Check for MESH-GROUP-REMOVED event
  116. check_mesh_group_removed(dev[0])
  117. dev[0].mesh_group_remove()
  118. def test_wpas_mesh_peer_connected(dev):
  119. """wpa_supplicant MESH peer connected"""
  120. check_mesh_support(dev[0])
  121. add_open_mesh_network(dev[0], beacon_int=160)
  122. add_open_mesh_network(dev[1], beacon_int=160)
  123. # Check for mesh joined
  124. check_mesh_group_added(dev[0])
  125. check_mesh_group_added(dev[1])
  126. # Check for peer connected
  127. check_mesh_peer_connected(dev[0])
  128. check_mesh_peer_connected(dev[1])
  129. def test_wpas_mesh_peer_disconnected(dev):
  130. """wpa_supplicant MESH peer disconnected"""
  131. check_mesh_support(dev[0])
  132. add_open_mesh_network(dev[0])
  133. add_open_mesh_network(dev[1])
  134. # Check for mesh joined
  135. check_mesh_group_added(dev[0])
  136. check_mesh_group_added(dev[1])
  137. # Check for peer connected
  138. check_mesh_peer_connected(dev[0])
  139. check_mesh_peer_connected(dev[1])
  140. # Remove group on dev 1
  141. dev[1].mesh_group_remove()
  142. # Device 0 should get a disconnection event
  143. check_mesh_peer_disconnected(dev[0])
  144. def test_wpas_mesh_mode_scan(dev):
  145. """wpa_supplicant MESH scan support"""
  146. check_mesh_support(dev[0])
  147. add_open_mesh_network(dev[0])
  148. add_open_mesh_network(dev[1], beacon_int=175)
  149. # Check for mesh joined
  150. check_mesh_group_added(dev[0])
  151. check_mesh_group_added(dev[1])
  152. # Check for Mesh scan
  153. check_mesh_scan(dev[0], "use_id=1", beacon_int=175)
  154. def test_wpas_mesh_open(dev, apdev):
  155. """wpa_supplicant open MESH network connectivity"""
  156. check_mesh_support(dev[0])
  157. add_open_mesh_network(dev[0], freq="2462", basic_rates="60 120 240")
  158. add_open_mesh_network(dev[1], freq="2462", basic_rates="60 120 240")
  159. # Check for mesh joined
  160. check_mesh_group_added(dev[0])
  161. check_mesh_group_added(dev[1])
  162. # Check for peer connected
  163. check_mesh_peer_connected(dev[0])
  164. check_mesh_peer_connected(dev[1])
  165. # Test connectivity 0->1 and 1->0
  166. hwsim_utils.test_connectivity(dev[0], dev[1])
  167. def test_wpas_mesh_open_no_auto(dev, apdev):
  168. """wpa_supplicant open MESH network connectivity"""
  169. check_mesh_support(dev[0])
  170. id = add_open_mesh_network(dev[0], start=False)
  171. dev[0].set_network(id, "dot11MeshMaxRetries", "16")
  172. dev[0].set_network(id, "dot11MeshRetryTimeout", "255")
  173. dev[0].mesh_group_add(id)
  174. id = add_open_mesh_network(dev[1], start=False)
  175. dev[1].set_network(id, "no_auto_peer", "1")
  176. dev[1].mesh_group_add(id)
  177. # Check for mesh joined
  178. check_mesh_group_added(dev[0])
  179. check_mesh_group_added(dev[1])
  180. # Check for peer connected
  181. check_mesh_peer_connected(dev[0], timeout=30)
  182. check_mesh_peer_connected(dev[1])
  183. # Test connectivity 0->1 and 1->0
  184. hwsim_utils.test_connectivity(dev[0], dev[1])
  185. def add_mesh_secure_net(dev, psk=True):
  186. id = dev.add_network()
  187. dev.set_network(id, "mode", "5")
  188. dev.set_network_quoted(id, "ssid", "wpas-mesh-sec")
  189. dev.set_network(id, "key_mgmt", "SAE")
  190. dev.set_network(id, "frequency", "2412")
  191. if psk:
  192. dev.set_network_quoted(id, "psk", "thisismypassphrase!")
  193. return id
  194. def test_wpas_mesh_secure(dev, apdev):
  195. """wpa_supplicant secure MESH network connectivity"""
  196. check_mesh_support(dev[0], secure=True)
  197. dev[0].request("SET sae_groups ")
  198. id = add_mesh_secure_net(dev[0])
  199. dev[0].mesh_group_add(id)
  200. dev[1].request("SET sae_groups ")
  201. id = add_mesh_secure_net(dev[1])
  202. dev[1].mesh_group_add(id)
  203. # Check for mesh joined
  204. check_mesh_group_added(dev[0])
  205. check_mesh_group_added(dev[1])
  206. # Check for peer connected
  207. check_mesh_peer_connected(dev[0])
  208. check_mesh_peer_connected(dev[1])
  209. # Test connectivity 0->1 and 1->0
  210. hwsim_utils.test_connectivity(dev[0], dev[1])
  211. def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev):
  212. """wpa_supplicant secure MESH and SAE group mismatch"""
  213. check_mesh_support(dev[0], secure=True)
  214. addr0 = dev[0].p2p_interface_addr()
  215. addr1 = dev[1].p2p_interface_addr()
  216. addr2 = dev[2].p2p_interface_addr()
  217. dev[0].request("SET sae_groups 19 25")
  218. id = add_mesh_secure_net(dev[0])
  219. dev[0].mesh_group_add(id)
  220. dev[1].request("SET sae_groups 19")
  221. id = add_mesh_secure_net(dev[1])
  222. dev[1].mesh_group_add(id)
  223. dev[2].request("SET sae_groups 26")
  224. id = add_mesh_secure_net(dev[2])
  225. dev[2].mesh_group_add(id)
  226. check_mesh_group_added(dev[0])
  227. check_mesh_group_added(dev[1])
  228. check_mesh_group_added(dev[2])
  229. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
  230. if ev is None:
  231. raise Exception("Remote peer did not connect")
  232. if addr1 not in ev:
  233. raise Exception("Unexpected peer connected: " + ev)
  234. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
  235. if ev is None:
  236. raise Exception("Remote peer did not connect")
  237. if addr0 not in ev:
  238. raise Exception("Unexpected peer connected: " + ev)
  239. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  240. if ev is not None:
  241. raise Exception("Unexpected peer connection at dev[2]: " + ev)
  242. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  243. if ev is not None:
  244. raise Exception("Unexpected peer connection: " + ev)
  245. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  246. if ev is not None:
  247. raise Exception("Unexpected peer connection: " + ev)
  248. dev[0].request("SET sae_groups ")
  249. dev[1].request("SET sae_groups ")
  250. dev[2].request("SET sae_groups ")
  251. def test_wpas_mesh_secure_sae_group_negotiation(dev, apdev):
  252. """wpa_supplicant secure MESH and SAE group negotiation"""
  253. check_mesh_support(dev[0], secure=True)
  254. addr0 = dev[0].own_addr()
  255. addr1 = dev[1].own_addr()
  256. #dev[0].request("SET sae_groups 21 20 25 26")
  257. dev[0].request("SET sae_groups 25")
  258. id = add_mesh_secure_net(dev[0])
  259. dev[0].mesh_group_add(id)
  260. dev[1].request("SET sae_groups 19 25")
  261. id = add_mesh_secure_net(dev[1])
  262. dev[1].mesh_group_add(id)
  263. check_mesh_group_added(dev[0])
  264. check_mesh_group_added(dev[1])
  265. check_mesh_peer_connected(dev[0])
  266. check_mesh_peer_connected(dev[1])
  267. dev[0].request("SET sae_groups ")
  268. dev[1].request("SET sae_groups ")
  269. def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
  270. """wpa_supplicant secure MESH and missing SAE password"""
  271. check_mesh_support(dev[0], secure=True)
  272. id = add_mesh_secure_net(dev[0], psk=False)
  273. dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
  274. dev[0].mesh_group_add(id)
  275. ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
  276. timeout=5)
  277. if ev is None:
  278. raise Exception("Timeout on mesh start event")
  279. if "MESH-GROUP-STARTED" in ev:
  280. raise Exception("Unexpected mesh group start")
  281. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
  282. if ev is not None:
  283. raise Exception("Unexpected mesh group start")
  284. def test_wpas_mesh_secure_no_auto(dev, apdev):
  285. """wpa_supplicant secure MESH network connectivity"""
  286. check_mesh_support(dev[0], secure=True)
  287. dev[0].request("SET sae_groups 19")
  288. id = add_mesh_secure_net(dev[0])
  289. dev[0].mesh_group_add(id)
  290. dev[1].request("SET sae_groups 19")
  291. id = add_mesh_secure_net(dev[1])
  292. dev[1].set_network(id, "no_auto_peer", "1")
  293. dev[1].mesh_group_add(id)
  294. # Check for mesh joined
  295. check_mesh_group_added(dev[0])
  296. check_mesh_group_added(dev[1])
  297. # Check for peer connected
  298. check_mesh_peer_connected(dev[0], timeout=30)
  299. check_mesh_peer_connected(dev[1])
  300. # Test connectivity 0->1 and 1->0
  301. hwsim_utils.test_connectivity(dev[0], dev[1])
  302. dev[0].request("SET sae_groups ")
  303. dev[1].request("SET sae_groups ")
  304. def test_wpas_mesh_secure_dropped_frame(dev, apdev):
  305. """Secure mesh network connectivity when the first plink Open is dropped"""
  306. check_mesh_support(dev[0], secure=True)
  307. dev[0].request("SET ext_mgmt_frame_handling 1")
  308. dev[0].request("SET sae_groups ")
  309. id = add_mesh_secure_net(dev[0])
  310. dev[0].mesh_group_add(id)
  311. dev[1].request("SET sae_groups ")
  312. id = add_mesh_secure_net(dev[1])
  313. dev[1].mesh_group_add(id)
  314. # Check for mesh joined
  315. check_mesh_group_added(dev[0])
  316. check_mesh_group_added(dev[1])
  317. # Drop the first Action frame (plink Open) to test unexpected order of
  318. # Confirm/Open messages.
  319. count = 0
  320. while True:
  321. count += 1
  322. if count > 10:
  323. raise Exception("Did not see Action frames")
  324. rx_msg = dev[0].mgmt_rx()
  325. if rx_msg is None:
  326. raise Exception("MGMT-RX timeout")
  327. if rx_msg['subtype'] == 13:
  328. logger.info("Drop the first Action frame")
  329. break
  330. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(rx_msg['freq'], rx_msg['datarate'], rx_msg['ssi_signal'], rx_msg['frame'].encode('hex'))):
  331. raise Exception("MGMT_RX_PROCESS failed")
  332. dev[0].request("SET ext_mgmt_frame_handling 0")
  333. # Check for peer connected
  334. check_mesh_peer_connected(dev[0])
  335. check_mesh_peer_connected(dev[1])
  336. # Test connectivity 0->1 and 1->0
  337. hwsim_utils.test_connectivity(dev[0], dev[1])
  338. def test_wpas_mesh_ctrl(dev):
  339. """wpa_supplicant ctrl_iface mesh command error cases"""
  340. check_mesh_support(dev[0])
  341. if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
  342. raise Exception("Unexpected MESH_GROUP_ADD success")
  343. id = dev[0].add_network()
  344. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  345. raise Exception("Unexpected MESH_GROUP_ADD success")
  346. dev[0].set_network(id, "mode", "5")
  347. dev[0].set_network(id, "key_mgmt", "WPA-PSK")
  348. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  349. raise Exception("Unexpected MESH_GROUP_ADD success")
  350. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
  351. raise Exception("Unexpected MESH_GROUP_REMOVE success")
  352. def test_wpas_mesh_dynamic_interface(dev):
  353. """wpa_supplicant mesh with dynamic interface"""
  354. check_mesh_support(dev[0])
  355. mesh0 = None
  356. mesh1 = None
  357. try:
  358. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  359. if "FAIL" in mesh0:
  360. raise Exception("MESH_INTERFACE_ADD failed")
  361. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  362. if "FAIL" in mesh1:
  363. raise Exception("MESH_INTERFACE_ADD failed")
  364. wpas0 = WpaSupplicant(ifname=mesh0)
  365. wpas1 = WpaSupplicant(ifname=mesh1)
  366. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  367. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  368. add_open_mesh_network(wpas0)
  369. add_open_mesh_network(wpas1)
  370. check_mesh_group_added(wpas0)
  371. check_mesh_group_added(wpas1)
  372. check_mesh_peer_connected(wpas0)
  373. check_mesh_peer_connected(wpas1)
  374. hwsim_utils.test_connectivity(wpas0, wpas1)
  375. # Must not allow MESH_GROUP_REMOVE on dynamic interface
  376. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
  377. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  378. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
  379. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  380. # Must not allow MESH_GROUP_REMOVE on another radio interface
  381. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
  382. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  383. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
  384. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  385. wpas0.remove_ifname()
  386. wpas1.remove_ifname()
  387. if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  388. raise Exception("MESH_GROUP_REMOVE failed")
  389. if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  390. raise Exception("MESH_GROUP_REMOVE failed")
  391. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  392. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  393. if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  394. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  395. logger.info("Make sure another dynamic group can be added")
  396. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  397. if "FAIL" in mesh0:
  398. raise Exception("MESH_INTERFACE_ADD failed")
  399. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  400. if "FAIL" in mesh1:
  401. raise Exception("MESH_INTERFACE_ADD failed")
  402. wpas0 = WpaSupplicant(ifname=mesh0)
  403. wpas1 = WpaSupplicant(ifname=mesh1)
  404. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  405. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  406. add_open_mesh_network(wpas0)
  407. add_open_mesh_network(wpas1)
  408. check_mesh_group_added(wpas0)
  409. check_mesh_group_added(wpas1)
  410. check_mesh_peer_connected(wpas0)
  411. check_mesh_peer_connected(wpas1)
  412. hwsim_utils.test_connectivity(wpas0, wpas1)
  413. finally:
  414. if mesh0:
  415. dev[0].request("MESH_GROUP_REMOVE " + mesh0)
  416. if mesh1:
  417. dev[1].request("MESH_GROUP_REMOVE " + mesh1)
  418. def test_wpas_mesh_max_peering(dev, apdev):
  419. """Mesh max peering limit"""
  420. check_mesh_support(dev[0])
  421. try:
  422. dev[0].request("SET max_peer_links 1")
  423. # first, connect dev[0] and dev[1]
  424. add_open_mesh_network(dev[0])
  425. add_open_mesh_network(dev[1])
  426. for i in range(2):
  427. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  428. if ev is None:
  429. raise Exception("dev%d did not connect with any peer" % i)
  430. # add dev[2] which will try to connect with both dev[0] and dev[1],
  431. # but can complete connection only with dev[1]
  432. add_open_mesh_network(dev[2])
  433. for i in range(1, 3):
  434. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  435. if ev is None:
  436. raise Exception("dev%d did not connect the second peer" % i)
  437. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  438. if ev is not None:
  439. raise Exception("dev0 connection beyond max peering limit")
  440. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  441. if ev is not None:
  442. raise Exception("dev2 reported unexpected peering: " + ev)
  443. for i in range(3):
  444. dev[i].mesh_group_remove()
  445. check_mesh_group_removed(dev[i])
  446. finally:
  447. dev[0].request("SET max_peer_links 99")
  448. def test_wpas_mesh_open_5ghz(dev, apdev):
  449. """wpa_supplicant open MESH network on 5 GHz band"""
  450. try:
  451. _test_wpas_mesh_open_5ghz(dev, apdev)
  452. finally:
  453. subprocess.call(['iw', 'reg', 'set', '00'])
  454. dev[0].flush_scan_cache()
  455. dev[1].flush_scan_cache()
  456. def _test_wpas_mesh_open_5ghz(dev, apdev):
  457. check_mesh_support(dev[0])
  458. subprocess.call(['iw', 'reg', 'set', 'US'])
  459. for i in range(2):
  460. for j in range(5):
  461. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  462. if ev is None:
  463. raise Exception("No regdom change event")
  464. if "alpha2=US" in ev:
  465. break
  466. add_open_mesh_network(dev[i], freq="5180")
  467. # Check for mesh joined
  468. check_mesh_group_added(dev[0])
  469. check_mesh_group_added(dev[1])
  470. # Check for peer connected
  471. check_mesh_peer_connected(dev[0])
  472. check_mesh_peer_connected(dev[1])
  473. # Test connectivity 0->1 and 1->0
  474. hwsim_utils.test_connectivity(dev[0], dev[1])
  475. def test_wpas_mesh_open_vht_80p80(dev, apdev):
  476. """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
  477. try:
  478. _test_wpas_mesh_open_vht_80p80(dev, apdev)
  479. finally:
  480. subprocess.call(['iw', 'reg', 'set', '00'])
  481. dev[0].flush_scan_cache()
  482. dev[1].flush_scan_cache()
  483. def _test_wpas_mesh_open_vht_80p80(dev, apdev):
  484. check_mesh_support(dev[0])
  485. subprocess.call(['iw', 'reg', 'set', 'US'])
  486. for i in range(2):
  487. for j in range(5):
  488. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  489. if ev is None:
  490. raise Exception("No regdom change event")
  491. if "alpha2=US" in ev:
  492. break
  493. add_open_mesh_network(dev[i], freq="5180", chwidth=3)
  494. # Check for mesh joined
  495. check_mesh_group_added(dev[0])
  496. check_mesh_group_added(dev[1])
  497. # Check for peer connected
  498. check_mesh_peer_connected(dev[0])
  499. check_mesh_peer_connected(dev[1])
  500. # Test connectivity 0->1 and 1->0
  501. hwsim_utils.test_connectivity(dev[0], dev[1])
  502. sig = dev[0].request("SIGNAL_POLL").splitlines()
  503. if "WIDTH=80+80 MHz" not in sig:
  504. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  505. if "CENTER_FRQ1=5210" not in sig:
  506. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  507. if "CENTER_FRQ2=5775" not in sig:
  508. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  509. sig = dev[1].request("SIGNAL_POLL").splitlines()
  510. if "WIDTH=80+80 MHz" not in sig:
  511. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  512. if "CENTER_FRQ1=5210" not in sig:
  513. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  514. if "CENTER_FRQ2=5775" not in sig:
  515. raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
  516. def test_wpas_mesh_password_mismatch(dev, apdev):
  517. """Mesh network and one device with mismatching password"""
  518. check_mesh_support(dev[0], secure=True)
  519. dev[0].request("SET sae_groups ")
  520. id = add_mesh_secure_net(dev[0])
  521. dev[0].mesh_group_add(id)
  522. dev[1].request("SET sae_groups ")
  523. id = add_mesh_secure_net(dev[1])
  524. dev[1].mesh_group_add(id)
  525. dev[2].request("SET sae_groups ")
  526. id = add_mesh_secure_net(dev[2])
  527. dev[2].set_network_quoted(id, "psk", "wrong password")
  528. dev[2].mesh_group_add(id)
  529. # The two peers with matching password need to be able to connect
  530. check_mesh_group_added(dev[0])
  531. check_mesh_group_added(dev[1])
  532. check_mesh_peer_connected(dev[0])
  533. check_mesh_peer_connected(dev[1])
  534. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  535. if ev is None:
  536. raise Exception("dev2 did not report auth failure (1)")
  537. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  538. if ev is None:
  539. raise Exception("dev2 did not report auth failure (2)")
  540. count = 0
  541. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  542. if ev is None:
  543. logger.info("dev0 did not report auth failure")
  544. else:
  545. if "addr=" + dev[2].own_addr() not in ev:
  546. raise Exception("Unexpected peer address in dev0 event: " + ev)
  547. count += 1
  548. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  549. if ev is None:
  550. logger.info("dev1 did not report auth failure")
  551. else:
  552. if "addr=" + dev[2].own_addr() not in ev:
  553. raise Exception("Unexpected peer address in dev1 event: " + ev)
  554. count += 1
  555. hwsim_utils.test_connectivity(dev[0], dev[1])
  556. for i in range(2):
  557. try:
  558. hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
  559. raise Exception("Data connectivity test passed unexpectedly")
  560. except Exception, e:
  561. if "data delivery failed" not in str(e):
  562. raise
  563. if count == 0:
  564. raise Exception("Neither dev0 nor dev1 reported auth failure")
  565. def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
  566. """Mesh password mismatch and retry [long]"""
  567. if not params['long']:
  568. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  569. check_mesh_support(dev[0], secure=True)
  570. dev[0].request("SET sae_groups ")
  571. id = add_mesh_secure_net(dev[0])
  572. dev[0].mesh_group_add(id)
  573. dev[1].request("SET sae_groups ")
  574. id = add_mesh_secure_net(dev[1])
  575. dev[1].set_network_quoted(id, "psk", "wrong password")
  576. dev[1].mesh_group_add(id)
  577. # Check for mesh joined
  578. check_mesh_group_added(dev[0])
  579. check_mesh_group_added(dev[1])
  580. for i in range(4):
  581. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  582. if ev is None:
  583. raise Exception("dev0 did not report auth failure (%d)" % i)
  584. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  585. if ev is None:
  586. raise Exception("dev1 did not report auth failure (%d)" % i)
  587. ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  588. if ev is None:
  589. raise Exception("dev0 did not report auth blocked")
  590. ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  591. if ev is None:
  592. raise Exception("dev1 did not report auth blocked")
  593. def test_mesh_wpa_auth_init_oom(dev, apdev):
  594. """Secure mesh network setup failing due to wpa_init() OOM"""
  595. check_mesh_support(dev[0], secure=True)
  596. dev[0].request("SET sae_groups ")
  597. with alloc_fail(dev[0], 1, "wpa_init"):
  598. id = add_mesh_secure_net(dev[0])
  599. dev[0].mesh_group_add(id)
  600. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
  601. if ev is not None:
  602. raise Exception("Unexpected mesh group start during OOM")
  603. def test_mesh_wpa_init_fail(dev, apdev):
  604. """Secure mesh network setup local failure"""
  605. check_mesh_support(dev[0], secure=True)
  606. dev[0].request("SET sae_groups ")
  607. with fail_test(dev[0], 1, "os_get_random;=__mesh_rsn_auth_init"):
  608. id = add_mesh_secure_net(dev[0])
  609. dev[0].mesh_group_add(id)
  610. wait_fail_trigger(dev[0], "GET_FAIL")
  611. with alloc_fail(dev[0], 1, "mesh_rsn_auth_init"):
  612. id = add_mesh_secure_net(dev[0])
  613. dev[0].mesh_group_add(id)
  614. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  615. def test_wpas_mesh_reconnect(dev, apdev):
  616. """Secure mesh network plink counting during reconnection"""
  617. check_mesh_support(dev[0])
  618. try:
  619. _test_wpas_mesh_reconnect(dev)
  620. finally:
  621. dev[0].request("SET max_peer_links 99")
  622. def _test_wpas_mesh_reconnect(dev):
  623. dev[0].request("SET max_peer_links 2")
  624. dev[0].request("SET sae_groups ")
  625. id = add_mesh_secure_net(dev[0])
  626. dev[0].set_network(id, "beacon_int", "100")
  627. dev[0].mesh_group_add(id)
  628. dev[1].request("SET sae_groups ")
  629. id = add_mesh_secure_net(dev[1])
  630. dev[1].mesh_group_add(id)
  631. check_mesh_group_added(dev[0])
  632. check_mesh_group_added(dev[1])
  633. check_mesh_peer_connected(dev[0])
  634. check_mesh_peer_connected(dev[1])
  635. for i in range(3):
  636. # Drop incoming management frames to avoid handling link close
  637. dev[0].request("SET ext_mgmt_frame_handling 1")
  638. dev[1].mesh_group_remove()
  639. check_mesh_group_removed(dev[1])
  640. dev[1].request("FLUSH")
  641. dev[0].request("SET ext_mgmt_frame_handling 0")
  642. id = add_mesh_secure_net(dev[1])
  643. dev[1].mesh_group_add(id)
  644. check_mesh_group_added(dev[1])
  645. check_mesh_peer_connected(dev[1])
  646. dev[0].dump_monitor()
  647. dev[1].dump_monitor()
  648. def test_wpas_mesh_gate_forwarding(dev, apdev, p):
  649. """Mesh forwards traffic to unknown sta to mesh gates"""
  650. addr0 = dev[0].own_addr()
  651. addr1 = dev[1].own_addr()
  652. addr2 = dev[2].own_addr()
  653. external_sta = '02:11:22:33:44:55'
  654. # start 3 node connected mesh
  655. check_mesh_support(dev[0])
  656. for i in range(3):
  657. add_open_mesh_network(dev[i])
  658. check_mesh_group_added(dev[i])
  659. for i in range(3):
  660. check_mesh_peer_connected(dev[i])
  661. hwsim_utils.test_connectivity(dev[0], dev[1])
  662. hwsim_utils.test_connectivity(dev[1], dev[2])
  663. hwsim_utils.test_connectivity(dev[0], dev[2])
  664. # dev0 and dev1 are mesh gates
  665. subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
  666. 'mesh_gate_announcements=1'])
  667. subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
  668. 'mesh_gate_announcements=1'])
  669. # wait for gate announcement frames
  670. time.sleep(1)
  671. # data frame from dev2 -> external sta should be sent to both gates
  672. dev[2].request("DATA_TEST_CONFIG 1")
  673. dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
  674. dev[2].request("DATA_TEST_CONFIG 0")
  675. capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
  676. filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
  677. external_sta)
  678. for i in range(15):
  679. da = run_tshark(capfile, filt, [ "wlan.da" ])
  680. if addr0 in da and addr1 in da:
  681. logger.debug("Frames seen in tshark iteration %d" % i)
  682. break
  683. time.sleep(0.3)
  684. if addr0 not in da:
  685. raise Exception("Frame to gate %s not observed" % addr0)
  686. if addr1 not in da:
  687. raise Exception("Frame to gate %s not observed" % addr1)
  688. def test_wpas_mesh_pmksa_caching(dev, apdev):
  689. """Secure mesh network and PMKSA caching"""
  690. check_mesh_support(dev[0], secure=True)
  691. dev[0].request("SET sae_groups ")
  692. id = add_mesh_secure_net(dev[0])
  693. dev[0].mesh_group_add(id)
  694. dev[1].request("SET sae_groups ")
  695. id = add_mesh_secure_net(dev[1])
  696. dev[1].mesh_group_add(id)
  697. # Check for mesh joined
  698. check_mesh_group_added(dev[0])
  699. check_mesh_group_added(dev[1])
  700. # Check for peer connected
  701. check_mesh_peer_connected(dev[0])
  702. check_mesh_peer_connected(dev[1])
  703. addr0 = dev[0].own_addr()
  704. addr1 = dev[1].own_addr()
  705. pmksa0 = dev[0].get_pmksa(addr1)
  706. pmksa1 = dev[1].get_pmksa(addr0)
  707. if pmksa0 is None or pmksa1 is None:
  708. raise Exception("No PMKSA cache entry created")
  709. if pmksa0['pmkid'] != pmksa1['pmkid']:
  710. raise Exception("PMKID mismatch in PMKSA cache entries")
  711. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  712. raise Exception("Failed to remove peer")
  713. pmksa0b = dev[0].get_pmksa(addr1)
  714. if pmksa0b is None:
  715. raise Exception("PMKSA cache entry not maintained")
  716. time.sleep(0.1)
  717. if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
  718. raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
  719. def test_wpas_mesh_pmksa_caching2(dev, apdev):
  720. """Secure mesh network and PMKSA caching with no_auto_peer=1"""
  721. check_mesh_support(dev[0], secure=True)
  722. addr0 = dev[0].own_addr()
  723. addr1 = dev[1].own_addr()
  724. dev[0].request("SET sae_groups ")
  725. id = add_mesh_secure_net(dev[0])
  726. dev[0].set_network(id, "no_auto_peer", "1")
  727. dev[0].mesh_group_add(id)
  728. dev[1].request("SET sae_groups ")
  729. id = add_mesh_secure_net(dev[1])
  730. dev[1].set_network(id, "no_auto_peer", "1")
  731. dev[1].mesh_group_add(id)
  732. # Check for mesh joined
  733. check_mesh_group_added(dev[0])
  734. check_mesh_group_added(dev[1])
  735. # Check for peer connected
  736. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  737. if ev is None:
  738. raise Exception("Missing no-initiate message")
  739. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  740. raise Exception("MESH_PEER_ADD failed")
  741. check_mesh_peer_connected(dev[0])
  742. check_mesh_peer_connected(dev[1])
  743. pmksa0 = dev[0].get_pmksa(addr1)
  744. pmksa1 = dev[1].get_pmksa(addr0)
  745. if pmksa0 is None or pmksa1 is None:
  746. raise Exception("No PMKSA cache entry created")
  747. if pmksa0['pmkid'] != pmksa1['pmkid']:
  748. raise Exception("PMKID mismatch in PMKSA cache entries")
  749. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  750. raise Exception("Failed to remove peer")
  751. pmksa0b = dev[0].get_pmksa(addr1)
  752. if pmksa0b is None:
  753. raise Exception("PMKSA cache entry not maintained")
  754. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  755. if ev is None:
  756. raise Exception("Missing no-initiate message (2)")
  757. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  758. raise Exception("MESH_PEER_ADD failed (2)")
  759. check_mesh_peer_connected(dev[0])
  760. check_mesh_peer_connected(dev[1])
  761. pmksa0c = dev[0].get_pmksa(addr1)
  762. pmksa1c = dev[1].get_pmksa(addr0)
  763. if pmksa0c is None or pmksa1c is None:
  764. raise Exception("No PMKSA cache entry created (2)")
  765. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  766. raise Exception("PMKID mismatch in PMKSA cache entries")
  767. if pmksa0['pmkid'] != pmksa0c['pmkid']:
  768. raise Exception("PMKID changed")
  769. hwsim_utils.test_connectivity(dev[0], dev[1])
  770. def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
  771. """Secure mesh network and PMKSA caching with no PMKID match"""
  772. check_mesh_support(dev[0], secure=True)
  773. addr0 = dev[0].own_addr()
  774. addr1 = dev[1].own_addr()
  775. dev[0].request("SET sae_groups ")
  776. id = add_mesh_secure_net(dev[0])
  777. dev[0].set_network(id, "no_auto_peer", "1")
  778. dev[0].mesh_group_add(id)
  779. dev[1].request("SET sae_groups ")
  780. id = add_mesh_secure_net(dev[1])
  781. dev[1].set_network(id, "no_auto_peer", "1")
  782. dev[1].mesh_group_add(id)
  783. # Check for mesh joined
  784. check_mesh_group_added(dev[0])
  785. check_mesh_group_added(dev[1])
  786. # Check for peer connected
  787. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  788. if ev is None:
  789. raise Exception("Missing no-initiate message")
  790. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  791. raise Exception("MESH_PEER_ADD failed")
  792. check_mesh_peer_connected(dev[0])
  793. check_mesh_peer_connected(dev[1])
  794. pmksa0 = dev[0].get_pmksa(addr1)
  795. pmksa1 = dev[1].get_pmksa(addr0)
  796. if pmksa0 is None or pmksa1 is None:
  797. raise Exception("No PMKSA cache entry created")
  798. if pmksa0['pmkid'] != pmksa1['pmkid']:
  799. raise Exception("PMKID mismatch in PMKSA cache entries")
  800. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  801. raise Exception("Failed to remove peer")
  802. if "OK" not in dev[1].request("PMKSA_FLUSH"):
  803. raise Exception("Failed to flush PMKSA cache")
  804. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  805. if ev is None:
  806. raise Exception("Missing no-initiate message (2)")
  807. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  808. raise Exception("MESH_PEER_ADD failed (2)")
  809. check_mesh_peer_connected(dev[0])
  810. check_mesh_peer_connected(dev[1])
  811. pmksa0c = dev[0].get_pmksa(addr1)
  812. pmksa1c = dev[1].get_pmksa(addr0)
  813. if pmksa0c is None or pmksa1c is None:
  814. raise Exception("No PMKSA cache entry created (2)")
  815. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  816. raise Exception("PMKID mismatch in PMKSA cache entries")
  817. if pmksa0['pmkid'] == pmksa0c['pmkid']:
  818. raise Exception("PMKID did not change")
  819. hwsim_utils.test_connectivity(dev[0], dev[1])
  820. def test_mesh_oom(dev, apdev):
  821. """Mesh network setup failing due to OOM"""
  822. check_mesh_support(dev[0], secure=True)
  823. dev[0].request("SET sae_groups ")
  824. with alloc_fail(dev[0], 1, "mesh_config_create"):
  825. add_open_mesh_network(dev[0])
  826. ev = dev[0].wait_event(["Failed to init mesh"])
  827. if ev is None:
  828. raise Exception("Init failure not reported")
  829. for i in range(1, 65):
  830. with alloc_fail(dev[0], i, "wpa_supplicant_mesh_init"):
  831. add_open_mesh_network(dev[0])
  832. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  833. ev = dev[0].wait_event(["Failed to init mesh",
  834. "MESH-GROUP-STARTED"])
  835. if ev is None:
  836. raise Exception("Init failure not reported")
  837. def test_mesh_add_interface_oom(dev):
  838. """wpa_supplicant mesh with dynamic interface addition failing"""
  839. check_mesh_support(dev[0])
  840. for i in range(1, 3):
  841. mesh = None
  842. try:
  843. with alloc_fail(dev[0], i, "wpas_mesh_add_interface"):
  844. mesh = dev[0].request("MESH_INTERFACE_ADD").strip()
  845. finally:
  846. if mesh and mesh != "FAIL":
  847. dev[0].request("MESH_GROUP_REMOVE " + mesh)
  848. def test_mesh_scan_oom(dev):
  849. """wpa_supplicant mesh scan results and OOM"""
  850. check_mesh_support(dev[0])
  851. add_open_mesh_network(dev[0])
  852. check_mesh_group_added(dev[0])
  853. for i in range(5):
  854. dev[1].scan(freq="2412")
  855. res = dev[1].request("SCAN_RESULTS")
  856. if "[MESH]" in res:
  857. break
  858. for r in res.splitlines():
  859. if "[MESH]" in r:
  860. break
  861. bssid = r.split('\t')[0]
  862. bss = dev[1].get_bss(bssid)
  863. if bss is None:
  864. raise Exception("Could not get BSS entry for mesh")
  865. for i in range(1, 3):
  866. with alloc_fail(dev[1], i, "mesh_attr_text"):
  867. bss = dev[1].get_bss(bssid)
  868. if bss is not None:
  869. raise Exception("Unexpected BSS result during OOM")
  870. def test_mesh_sae_groups_invalid(dev, apdev):
  871. """Mesh with invalid SAE group configuration"""
  872. check_mesh_support(dev[0], secure=True)
  873. dev[0].request("SET sae_groups 25")
  874. id = add_mesh_secure_net(dev[0])
  875. dev[0].mesh_group_add(id)
  876. dev[1].request("SET sae_groups 123 122 121")
  877. id = add_mesh_secure_net(dev[1])
  878. dev[1].mesh_group_add(id)
  879. check_mesh_group_added(dev[0])
  880. check_mesh_group_added(dev[1])
  881. ev = dev[0].wait_event(["new peer notification"], timeout=10)
  882. if ev is None:
  883. raise Exception("dev[0] did not see peer")
  884. ev = dev[1].wait_event(["new peer notification"], timeout=10)
  885. if ev is None:
  886. raise Exception("dev[1] did not see peer")
  887. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  888. if ev is not None:
  889. raise Exception("Unexpected connection(0)")
  890. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  891. if ev is not None:
  892. raise Exception("Unexpected connection(1)")
  893. dev[0].request("SET sae_groups ")
  894. dev[1].request("SET sae_groups ")
  895. def test_mesh_sae_failure(dev, apdev):
  896. """Mesh and local SAE failures"""
  897. check_mesh_support(dev[0], secure=True)
  898. dev[0].request("SET sae_groups ")
  899. dev[1].request("SET sae_groups ")
  900. funcs = [ (1, "=mesh_rsn_auth_sae_sta", True),
  901. (1, "mesh_rsn_build_sae_commit;mesh_rsn_auth_sae_sta", False),
  902. (1, "auth_sae_init_committed;mesh_rsn_auth_sae_sta", True),
  903. (1, "=mesh_rsn_protect_frame", True),
  904. (2, "=mesh_rsn_protect_frame", True),
  905. (1, "aes_siv_encrypt;mesh_rsn_protect_frame", True),
  906. (1, "=mesh_rsn_process_ampe", True),
  907. (1, "aes_siv_decrypt;mesh_rsn_process_ampe", True) ]
  908. for count, func, success in funcs:
  909. id = add_mesh_secure_net(dev[0])
  910. dev[0].mesh_group_add(id)
  911. with alloc_fail(dev[1], count, func):
  912. id = add_mesh_secure_net(dev[1])
  913. dev[1].mesh_group_add(id)
  914. check_mesh_group_added(dev[0])
  915. check_mesh_group_added(dev[1])
  916. if success:
  917. # retry is expected to work
  918. check_mesh_peer_connected(dev[0])
  919. check_mesh_peer_connected(dev[1])
  920. else:
  921. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  922. dev[0].mesh_group_remove()
  923. dev[1].mesh_group_remove()
  924. check_mesh_group_removed(dev[0])
  925. check_mesh_group_removed(dev[1])
  926. def test_mesh_failure(dev, apdev):
  927. """Mesh and local failures"""
  928. check_mesh_support(dev[0])
  929. funcs = [ (1, "ap_sta_add;mesh_mpm_add_peer", True),
  930. (1, "wpabuf_alloc;mesh_mpm_send_plink_action", True) ]
  931. for count, func, success in funcs:
  932. add_open_mesh_network(dev[0])
  933. with alloc_fail(dev[1], count, func):
  934. add_open_mesh_network(dev[1])
  935. check_mesh_group_added(dev[0])
  936. check_mesh_group_added(dev[1])
  937. if success:
  938. # retry is expected to work
  939. check_mesh_peer_connected(dev[0])
  940. check_mesh_peer_connected(dev[1])
  941. else:
  942. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  943. dev[0].mesh_group_remove()
  944. dev[1].mesh_group_remove()
  945. check_mesh_group_removed(dev[0])
  946. check_mesh_group_removed(dev[1])
  947. funcs = [ (1, "mesh_mpm_init_link", True) ]
  948. for count, func, success in funcs:
  949. add_open_mesh_network(dev[0])
  950. with fail_test(dev[1], count, func):
  951. add_open_mesh_network(dev[1])
  952. check_mesh_group_added(dev[0])
  953. check_mesh_group_added(dev[1])
  954. if success:
  955. # retry is expected to work
  956. check_mesh_peer_connected(dev[0])
  957. check_mesh_peer_connected(dev[1])
  958. else:
  959. wait_fail_trigger(dev[1], "GET_FAIL")
  960. dev[0].mesh_group_remove()
  961. dev[1].mesh_group_remove()
  962. check_mesh_group_removed(dev[0])
  963. check_mesh_group_removed(dev[1])
  964. def test_mesh_invalid_frequency(dev, apdev):
  965. """Mesh and invalid frequency configuration"""
  966. check_mesh_support(dev[0])
  967. add_open_mesh_network(dev[0], freq=None)
  968. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  969. "Could not join mesh"])
  970. if ev is None or "Could not join mesh" not in ev:
  971. raise Exception("Mesh join failure not reported")
  972. dev[0].request("REMOVE_NETWORK all")
  973. add_open_mesh_network(dev[0], freq="2413")
  974. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  975. "Could not join mesh"])
  976. if ev is None or "Could not join mesh" not in ev:
  977. raise Exception("Mesh join failure not reported")