test_wpas_mesh.py 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029
  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 struct
  10. import subprocess
  11. import time
  12. import hwsim_utils
  13. import hostapd
  14. from wpasupplicant import WpaSupplicant
  15. from utils import HwsimSkip, alloc_fail, fail_test, wait_fail_trigger
  16. from tshark import run_tshark
  17. from test_ap_ht import set_world_reg
  18. def check_mesh_support(dev, secure=False):
  19. if "MESH" not in dev.get_capability("modes"):
  20. raise HwsimSkip("Driver does not support mesh")
  21. if secure and "SAE" not in dev.get_capability("auth_alg"):
  22. raise HwsimSkip("SAE not supported")
  23. def check_mesh_scan(dev, params, other_started=False, beacon_int=0):
  24. if not other_started:
  25. dev.dump_monitor()
  26. id = dev.request("SCAN " + params)
  27. if "FAIL" in id:
  28. raise Exception("Failed to start scan")
  29. id = int(id)
  30. if other_started:
  31. ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
  32. if ev is None:
  33. raise Exception("Other scan did not start")
  34. if "id=" + str(id) in ev:
  35. raise Exception("Own scan id unexpectedly included in start event")
  36. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  37. if ev is None:
  38. raise Exception("Other scan did not complete")
  39. if "id=" + str(id) in ev:
  40. raise Exception(
  41. "Own scan id unexpectedly included in completed event")
  42. ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
  43. if ev is None:
  44. raise Exception("Scan did not start")
  45. if "id=" + str(id) not in ev:
  46. raise Exception("Scan id not included in start event")
  47. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  48. if ev is None:
  49. raise Exception("Scan did not complete")
  50. if "id=" + str(id) not in ev:
  51. raise Exception("Scan id not included in completed event")
  52. res = dev.request("SCAN_RESULTS")
  53. if res.find("[MESH]") < 0:
  54. raise Exception("Scan did not contain a MESH network")
  55. bssid = res.splitlines()[1].split(' ')[0]
  56. bss = dev.get_bss(bssid)
  57. if bss is None:
  58. raise Exception("Could not get BSS entry for mesh")
  59. if 'mesh_capability' not in bss:
  60. raise Exception("mesh_capability missing from BSS entry")
  61. if beacon_int:
  62. if 'beacon_int' not in bss:
  63. raise Exception("beacon_int missing from BSS entry")
  64. if str(beacon_int) != bss['beacon_int']:
  65. raise Exception("Unexpected beacon_int in BSS entry: " + bss['beacon_int'])
  66. def check_mesh_group_added(dev):
  67. ev = dev.wait_event(["MESH-GROUP-STARTED"])
  68. if ev is None:
  69. raise Exception("Test exception: Couldn't join mesh")
  70. def check_mesh_group_removed(dev):
  71. ev = dev.wait_event(["MESH-GROUP-REMOVED"])
  72. if ev is None:
  73. raise Exception("Test exception: Couldn't leave mesh")
  74. def check_mesh_peer_connected(dev, timeout=10):
  75. ev = dev.wait_event(["MESH-PEER-CONNECTED"], timeout=timeout)
  76. if ev is None:
  77. raise Exception("Test exception: Remote peer did not connect.")
  78. def check_mesh_peer_disconnected(dev):
  79. ev = dev.wait_event(["MESH-PEER-DISCONNECTED"])
  80. if ev is None:
  81. raise Exception("Test exception: Peer disconnect event not detected.")
  82. def test_wpas_add_set_remove_support(dev):
  83. """wpa_supplicant MESH add/set/remove network support"""
  84. check_mesh_support(dev[0])
  85. id = dev[0].add_network()
  86. dev[0].set_network(id, "mode", "5")
  87. dev[0].remove_network(id)
  88. def add_open_mesh_network(dev, freq="2412", start=True, beacon_int=0,
  89. basic_rates=None, chwidth=0):
  90. id = dev.add_network()
  91. dev.set_network(id, "mode", "5")
  92. dev.set_network_quoted(id, "ssid", "wpas-mesh-open")
  93. dev.set_network(id, "key_mgmt", "NONE")
  94. if freq:
  95. dev.set_network(id, "frequency", freq)
  96. if chwidth > 0:
  97. dev.set_network(id, "max_oper_chwidth", str(chwidth))
  98. if beacon_int:
  99. dev.set_network(id, "beacon_int", str(beacon_int))
  100. if basic_rates:
  101. dev.set_network(id, "mesh_basic_rates", basic_rates)
  102. if start:
  103. dev.mesh_group_add(id)
  104. return id
  105. def test_wpas_mesh_group_added(dev):
  106. """wpa_supplicant MESH group add"""
  107. check_mesh_support(dev[0])
  108. add_open_mesh_network(dev[0])
  109. # Check for MESH-GROUP-STARTED event
  110. check_mesh_group_added(dev[0])
  111. def test_wpas_mesh_group_remove(dev):
  112. """wpa_supplicant MESH group remove"""
  113. check_mesh_support(dev[0])
  114. add_open_mesh_network(dev[0])
  115. # Check for MESH-GROUP-STARTED event
  116. check_mesh_group_added(dev[0])
  117. dev[0].mesh_group_remove()
  118. # Check for MESH-GROUP-REMOVED event
  119. check_mesh_group_removed(dev[0])
  120. dev[0].mesh_group_remove()
  121. def test_wpas_mesh_peer_connected(dev):
  122. """wpa_supplicant MESH peer connected"""
  123. check_mesh_support(dev[0])
  124. add_open_mesh_network(dev[0], beacon_int=160)
  125. add_open_mesh_network(dev[1], beacon_int=160)
  126. # Check for mesh joined
  127. check_mesh_group_added(dev[0])
  128. check_mesh_group_added(dev[1])
  129. # Check for peer connected
  130. check_mesh_peer_connected(dev[0])
  131. check_mesh_peer_connected(dev[1])
  132. def test_wpas_mesh_peer_disconnected(dev):
  133. """wpa_supplicant MESH peer disconnected"""
  134. check_mesh_support(dev[0])
  135. add_open_mesh_network(dev[0])
  136. add_open_mesh_network(dev[1])
  137. # Check for mesh joined
  138. check_mesh_group_added(dev[0])
  139. check_mesh_group_added(dev[1])
  140. # Check for peer connected
  141. check_mesh_peer_connected(dev[0])
  142. check_mesh_peer_connected(dev[1])
  143. # Remove group on dev 1
  144. dev[1].mesh_group_remove()
  145. # Device 0 should get a disconnection event
  146. check_mesh_peer_disconnected(dev[0])
  147. def test_wpas_mesh_mode_scan(dev):
  148. """wpa_supplicant MESH scan support"""
  149. check_mesh_support(dev[0])
  150. add_open_mesh_network(dev[0])
  151. add_open_mesh_network(dev[1], beacon_int=175)
  152. # Check for mesh joined
  153. check_mesh_group_added(dev[0])
  154. check_mesh_group_added(dev[1])
  155. # Check for Mesh scan
  156. check_mesh_scan(dev[0], "use_id=1", beacon_int=175)
  157. def test_wpas_mesh_open(dev, apdev):
  158. """wpa_supplicant open MESH network connectivity"""
  159. check_mesh_support(dev[0])
  160. add_open_mesh_network(dev[0], freq="2462", basic_rates="60 120 240")
  161. add_open_mesh_network(dev[1], freq="2462", basic_rates="60 120 240")
  162. # Check for mesh joined
  163. check_mesh_group_added(dev[0])
  164. check_mesh_group_added(dev[1])
  165. # Check for peer connected
  166. check_mesh_peer_connected(dev[0])
  167. check_mesh_peer_connected(dev[1])
  168. # Test connectivity 0->1 and 1->0
  169. hwsim_utils.test_connectivity(dev[0], dev[1])
  170. state = dev[0].get_status_field("wpa_state")
  171. if state != "COMPLETED":
  172. raise Exception("Unexpected wpa_state on dev0: " + state)
  173. state = dev[1].get_status_field("wpa_state")
  174. if state != "COMPLETED":
  175. raise Exception("Unexpected wpa_state on dev1: " + state)
  176. mode = dev[0].get_status_field("mode")
  177. if mode != "mesh":
  178. raise Exception("Unexpected mode: " + mode)
  179. def test_wpas_mesh_open_no_auto(dev, apdev):
  180. """wpa_supplicant open MESH network connectivity"""
  181. check_mesh_support(dev[0])
  182. id = add_open_mesh_network(dev[0], start=False)
  183. dev[0].set_network(id, "dot11MeshMaxRetries", "16")
  184. dev[0].set_network(id, "dot11MeshRetryTimeout", "255")
  185. dev[0].mesh_group_add(id)
  186. id = add_open_mesh_network(dev[1], start=False)
  187. dev[1].set_network(id, "no_auto_peer", "1")
  188. dev[1].mesh_group_add(id)
  189. # Check for mesh joined
  190. check_mesh_group_added(dev[0])
  191. check_mesh_group_added(dev[1])
  192. # Check for peer connected
  193. check_mesh_peer_connected(dev[0], timeout=30)
  194. check_mesh_peer_connected(dev[1])
  195. # Test connectivity 0->1 and 1->0
  196. hwsim_utils.test_connectivity(dev[0], dev[1])
  197. def test_mesh_open_no_auto2(dev, apdev):
  198. """Open mesh network connectivity, no_auto on both peers"""
  199. check_mesh_support(dev[0])
  200. id = add_open_mesh_network(dev[0], start=False)
  201. dev[0].set_network(id, "no_auto_peer", "1")
  202. dev[0].mesh_group_add(id)
  203. id = add_open_mesh_network(dev[1], start=False)
  204. dev[1].set_network(id, "no_auto_peer", "1")
  205. dev[1].mesh_group_add(id)
  206. check_mesh_group_added(dev[0])
  207. check_mesh_group_added(dev[1])
  208. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  209. if ev is None:
  210. raise Exception("Missing no-initiate message")
  211. addr1 = dev[1].own_addr()
  212. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  213. raise Exception("MESH_PEER_ADD failed")
  214. if "FAIL" not in dev[0].request("MESH_PEER_ADD ff:ff:ff:ff:ff:ff"):
  215. raise Exception("MESH_PEER_ADD with unknown STA succeeded")
  216. check_mesh_peer_connected(dev[0], timeout=30)
  217. check_mesh_peer_connected(dev[1])
  218. if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
  219. raise Exception("MESH_PEER_ADD succeeded for connected STA")
  220. hwsim_utils.test_connectivity(dev[0], dev[1])
  221. def add_mesh_secure_net(dev, psk=True, pmf=False, pairwise=None, group=None):
  222. id = dev.add_network()
  223. dev.set_network(id, "mode", "5")
  224. dev.set_network_quoted(id, "ssid", "wpas-mesh-sec")
  225. dev.set_network(id, "key_mgmt", "SAE")
  226. dev.set_network(id, "frequency", "2412")
  227. if psk:
  228. dev.set_network_quoted(id, "psk", "thisismypassphrase!")
  229. if pmf:
  230. dev.set_network(id, "ieee80211w", "2")
  231. if pairwise:
  232. dev.set_network(id, "pairwise", pairwise)
  233. if group:
  234. dev.set_network(id, "group", group)
  235. return id
  236. def test_wpas_mesh_secure(dev, apdev):
  237. """wpa_supplicant secure MESH network connectivity"""
  238. check_mesh_support(dev[0], secure=True)
  239. dev[0].request("SET sae_groups ")
  240. id = add_mesh_secure_net(dev[0])
  241. dev[0].mesh_group_add(id)
  242. dev[1].request("SET sae_groups ")
  243. id = add_mesh_secure_net(dev[1])
  244. dev[1].mesh_group_add(id)
  245. # Check for mesh joined
  246. check_mesh_group_added(dev[0])
  247. check_mesh_group_added(dev[1])
  248. # Check for peer connected
  249. check_mesh_peer_connected(dev[0])
  250. check_mesh_peer_connected(dev[1])
  251. # Test connectivity 0->1 and 1->0
  252. hwsim_utils.test_connectivity(dev[0], dev[1])
  253. state = dev[0].get_status_field("wpa_state")
  254. if state != "COMPLETED":
  255. raise Exception("Unexpected wpa_state on dev0: " + state)
  256. state = dev[1].get_status_field("wpa_state")
  257. if state != "COMPLETED":
  258. raise Exception("Unexpected wpa_state on dev1: " + state)
  259. def test_mesh_secure_pmf(dev, apdev):
  260. """Secure mesh network connectivity with PMF enabled"""
  261. check_mesh_support(dev[0], secure=True)
  262. dev[0].request("SET sae_groups ")
  263. id = add_mesh_secure_net(dev[0], pmf=True)
  264. dev[0].mesh_group_add(id)
  265. dev[1].request("SET sae_groups ")
  266. id = add_mesh_secure_net(dev[1], pmf=True)
  267. dev[1].mesh_group_add(id)
  268. # Check for mesh joined
  269. check_mesh_group_added(dev[0])
  270. check_mesh_group_added(dev[1])
  271. # Check for peer connected
  272. check_mesh_peer_connected(dev[0])
  273. check_mesh_peer_connected(dev[1])
  274. # Test connectivity 0->1 and 1->0
  275. hwsim_utils.test_connectivity(dev[0], dev[1])
  276. def run_mesh_secure(dev, cipher):
  277. if cipher not in dev[0].get_capability("pairwise"):
  278. raise HwsimSkip("Cipher %s not supported" % cipher)
  279. check_mesh_support(dev[0], secure=True)
  280. dev[0].request("SET sae_groups ")
  281. id = add_mesh_secure_net(dev[0], pairwise=cipher, group=cipher)
  282. dev[0].mesh_group_add(id)
  283. dev[1].request("SET sae_groups ")
  284. id = add_mesh_secure_net(dev[1], pairwise=cipher, group=cipher)
  285. dev[1].mesh_group_add(id)
  286. # Check for mesh joined
  287. check_mesh_group_added(dev[0])
  288. check_mesh_group_added(dev[1])
  289. # Check for peer connected
  290. check_mesh_peer_connected(dev[0])
  291. check_mesh_peer_connected(dev[1])
  292. # Test connectivity 0->1 and 1->0
  293. hwsim_utils.test_connectivity(dev[0], dev[1])
  294. def test_mesh_secure_ccmp(dev, apdev):
  295. """Secure mesh with CCMP"""
  296. run_mesh_secure(dev, "CCMP")
  297. def test_mesh_secure_gcmp(dev, apdev):
  298. """Secure mesh with GCMP"""
  299. run_mesh_secure(dev, "GCMP")
  300. def test_mesh_secure_gcmp_256(dev, apdev):
  301. """Secure mesh with GCMP-256"""
  302. run_mesh_secure(dev, "GCMP-256")
  303. def test_mesh_secure_ccmp_256(dev, apdev):
  304. """Secure mesh with CCMP-256"""
  305. run_mesh_secure(dev, "CCMP-256")
  306. def test_mesh_secure_invalid_pairwise_cipher(dev, apdev):
  307. """Secure mesh and invalid group cipher"""
  308. check_mesh_support(dev[0], secure=True)
  309. dev[0].request("SET sae_groups ")
  310. id = add_mesh_secure_net(dev[0], pairwise="TKIP", group="CCMP")
  311. if dev[0].mesh_group_add(id) != None:
  312. raise Exception("Unexpected group add success")
  313. ev = dev[0].wait_event(["mesh: Invalid pairwise cipher"], timeout=1)
  314. if ev is None:
  315. raise Exception("Invalid pairwise cipher not reported")
  316. def test_mesh_secure_invalid_group_cipher(dev, apdev):
  317. """Secure mesh and invalid group cipher"""
  318. check_mesh_support(dev[0], secure=True)
  319. dev[0].request("SET sae_groups ")
  320. id = add_mesh_secure_net(dev[0], pairwise="CCMP", group="TKIP")
  321. if dev[0].mesh_group_add(id) != None:
  322. raise Exception("Unexpected group add success")
  323. ev = dev[0].wait_event(["mesh: Invalid group cipher"], timeout=1)
  324. if ev is None:
  325. raise Exception("Invalid group cipher not reported")
  326. def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev):
  327. """wpa_supplicant secure MESH and SAE group mismatch"""
  328. check_mesh_support(dev[0], secure=True)
  329. addr0 = dev[0].p2p_interface_addr()
  330. addr1 = dev[1].p2p_interface_addr()
  331. addr2 = dev[2].p2p_interface_addr()
  332. dev[0].request("SET sae_groups 19 25")
  333. id = add_mesh_secure_net(dev[0])
  334. dev[0].mesh_group_add(id)
  335. dev[1].request("SET sae_groups 19")
  336. id = add_mesh_secure_net(dev[1])
  337. dev[1].mesh_group_add(id)
  338. dev[2].request("SET sae_groups 26")
  339. id = add_mesh_secure_net(dev[2])
  340. dev[2].mesh_group_add(id)
  341. check_mesh_group_added(dev[0])
  342. check_mesh_group_added(dev[1])
  343. check_mesh_group_added(dev[2])
  344. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
  345. if ev is None:
  346. raise Exception("Remote peer did not connect")
  347. if addr1 not in ev:
  348. raise Exception("Unexpected peer connected: " + ev)
  349. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
  350. if ev is None:
  351. raise Exception("Remote peer did not connect")
  352. if addr0 not in ev:
  353. raise Exception("Unexpected peer connected: " + ev)
  354. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  355. if ev is not None:
  356. raise Exception("Unexpected peer connection at dev[2]: " + ev)
  357. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  358. if ev is not None:
  359. raise Exception("Unexpected peer connection: " + ev)
  360. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  361. if ev is not None:
  362. raise Exception("Unexpected peer connection: " + ev)
  363. dev[0].request("SET sae_groups ")
  364. dev[1].request("SET sae_groups ")
  365. dev[2].request("SET sae_groups ")
  366. def test_wpas_mesh_secure_sae_group_negotiation(dev, apdev):
  367. """wpa_supplicant secure MESH and SAE group negotiation"""
  368. check_mesh_support(dev[0], secure=True)
  369. addr0 = dev[0].own_addr()
  370. addr1 = dev[1].own_addr()
  371. #dev[0].request("SET sae_groups 21 20 25 26")
  372. dev[0].request("SET sae_groups 25")
  373. id = add_mesh_secure_net(dev[0])
  374. dev[0].mesh_group_add(id)
  375. dev[1].request("SET sae_groups 19 25")
  376. id = add_mesh_secure_net(dev[1])
  377. dev[1].mesh_group_add(id)
  378. check_mesh_group_added(dev[0])
  379. check_mesh_group_added(dev[1])
  380. check_mesh_peer_connected(dev[0])
  381. check_mesh_peer_connected(dev[1])
  382. dev[0].request("SET sae_groups ")
  383. dev[1].request("SET sae_groups ")
  384. def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
  385. """wpa_supplicant secure MESH and missing SAE password"""
  386. check_mesh_support(dev[0], secure=True)
  387. id = add_mesh_secure_net(dev[0], psk=False)
  388. dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
  389. dev[0].mesh_group_add(id)
  390. ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
  391. timeout=5)
  392. if ev is None:
  393. raise Exception("Timeout on mesh start event")
  394. if "MESH-GROUP-STARTED" in ev:
  395. raise Exception("Unexpected mesh group start")
  396. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
  397. if ev is not None:
  398. raise Exception("Unexpected mesh group start")
  399. def test_wpas_mesh_secure_no_auto(dev, apdev):
  400. """wpa_supplicant secure MESH network connectivity"""
  401. check_mesh_support(dev[0], secure=True)
  402. dev[0].request("SET sae_groups 19")
  403. id = add_mesh_secure_net(dev[0])
  404. dev[0].mesh_group_add(id)
  405. dev[1].request("SET sae_groups 19")
  406. id = add_mesh_secure_net(dev[1])
  407. dev[1].set_network(id, "no_auto_peer", "1")
  408. dev[1].mesh_group_add(id)
  409. # Check for mesh joined
  410. check_mesh_group_added(dev[0])
  411. check_mesh_group_added(dev[1])
  412. # Check for peer connected
  413. check_mesh_peer_connected(dev[0], timeout=30)
  414. check_mesh_peer_connected(dev[1])
  415. # Test connectivity 0->1 and 1->0
  416. hwsim_utils.test_connectivity(dev[0], dev[1])
  417. dev[0].request("SET sae_groups ")
  418. dev[1].request("SET sae_groups ")
  419. def test_wpas_mesh_secure_dropped_frame(dev, apdev):
  420. """Secure mesh network connectivity when the first plink Open is dropped"""
  421. check_mesh_support(dev[0], secure=True)
  422. dev[0].request("SET ext_mgmt_frame_handling 1")
  423. dev[0].request("SET sae_groups ")
  424. id = add_mesh_secure_net(dev[0])
  425. dev[0].mesh_group_add(id)
  426. dev[1].request("SET sae_groups ")
  427. id = add_mesh_secure_net(dev[1])
  428. dev[1].mesh_group_add(id)
  429. # Check for mesh joined
  430. check_mesh_group_added(dev[0])
  431. check_mesh_group_added(dev[1])
  432. # Drop the first Action frame (plink Open) to test unexpected order of
  433. # Confirm/Open messages.
  434. count = 0
  435. while True:
  436. count += 1
  437. if count > 10:
  438. raise Exception("Did not see Action frames")
  439. rx_msg = dev[0].mgmt_rx()
  440. if rx_msg is None:
  441. raise Exception("MGMT-RX timeout")
  442. if rx_msg['subtype'] == 13:
  443. logger.info("Drop the first Action frame")
  444. break
  445. 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'))):
  446. raise Exception("MGMT_RX_PROCESS failed")
  447. dev[0].request("SET ext_mgmt_frame_handling 0")
  448. # Check for peer connected
  449. check_mesh_peer_connected(dev[0])
  450. check_mesh_peer_connected(dev[1])
  451. # Test connectivity 0->1 and 1->0
  452. hwsim_utils.test_connectivity(dev[0], dev[1])
  453. def test_mesh_secure_fail(dev, apdev):
  454. """Secure mesh network connectivity failure"""
  455. check_mesh_support(dev[0], secure=True)
  456. dev[0].request("SET sae_groups ")
  457. id = add_mesh_secure_net(dev[0], pmf=True)
  458. dev[0].mesh_group_add(id)
  459. dev[1].request("SET sae_groups ")
  460. id = add_mesh_secure_net(dev[1], pmf=True)
  461. with fail_test(dev[0], 1, "wpa_driver_nl80211_sta_add;mesh_mpm_auth_peer"):
  462. dev[1].mesh_group_add(id)
  463. check_mesh_group_added(dev[0])
  464. check_mesh_group_added(dev[1])
  465. check_mesh_peer_connected(dev[0])
  466. check_mesh_peer_connected(dev[1])
  467. def test_wpas_mesh_ctrl(dev):
  468. """wpa_supplicant ctrl_iface mesh command error cases"""
  469. check_mesh_support(dev[0])
  470. if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
  471. raise Exception("Unexpected MESH_GROUP_ADD success")
  472. id = dev[0].add_network()
  473. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  474. raise Exception("Unexpected MESH_GROUP_ADD success")
  475. dev[0].set_network(id, "mode", "5")
  476. dev[0].set_network(id, "key_mgmt", "WPA-PSK")
  477. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  478. raise Exception("Unexpected MESH_GROUP_ADD success")
  479. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
  480. raise Exception("Unexpected MESH_GROUP_REMOVE success")
  481. def test_wpas_mesh_dynamic_interface(dev):
  482. """wpa_supplicant mesh with dynamic interface"""
  483. check_mesh_support(dev[0])
  484. mesh0 = None
  485. mesh1 = None
  486. try:
  487. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  488. if "FAIL" in mesh0:
  489. raise Exception("MESH_INTERFACE_ADD failed")
  490. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  491. if "FAIL" in mesh1:
  492. raise Exception("MESH_INTERFACE_ADD failed")
  493. wpas0 = WpaSupplicant(ifname=mesh0)
  494. wpas1 = WpaSupplicant(ifname=mesh1)
  495. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  496. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  497. add_open_mesh_network(wpas0)
  498. add_open_mesh_network(wpas1)
  499. check_mesh_group_added(wpas0)
  500. check_mesh_group_added(wpas1)
  501. check_mesh_peer_connected(wpas0)
  502. check_mesh_peer_connected(wpas1)
  503. hwsim_utils.test_connectivity(wpas0, wpas1)
  504. # Must not allow MESH_GROUP_REMOVE on dynamic interface
  505. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
  506. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  507. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
  508. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  509. # Must not allow MESH_GROUP_REMOVE on another radio interface
  510. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
  511. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  512. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
  513. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  514. wpas0.remove_ifname()
  515. wpas1.remove_ifname()
  516. if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  517. raise Exception("MESH_GROUP_REMOVE failed")
  518. if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  519. raise Exception("MESH_GROUP_REMOVE failed")
  520. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  521. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  522. if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  523. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  524. logger.info("Make sure another dynamic group can be added")
  525. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  526. if "FAIL" in mesh0:
  527. raise Exception("MESH_INTERFACE_ADD failed")
  528. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  529. if "FAIL" in mesh1:
  530. raise Exception("MESH_INTERFACE_ADD failed")
  531. wpas0 = WpaSupplicant(ifname=mesh0)
  532. wpas1 = WpaSupplicant(ifname=mesh1)
  533. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  534. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  535. add_open_mesh_network(wpas0)
  536. add_open_mesh_network(wpas1)
  537. check_mesh_group_added(wpas0)
  538. check_mesh_group_added(wpas1)
  539. check_mesh_peer_connected(wpas0)
  540. check_mesh_peer_connected(wpas1)
  541. hwsim_utils.test_connectivity(wpas0, wpas1)
  542. finally:
  543. if mesh0:
  544. dev[0].request("MESH_GROUP_REMOVE " + mesh0)
  545. if mesh1:
  546. dev[1].request("MESH_GROUP_REMOVE " + mesh1)
  547. def test_wpas_mesh_max_peering(dev, apdev, params):
  548. """Mesh max peering limit"""
  549. check_mesh_support(dev[0])
  550. try:
  551. dev[0].request("SET max_peer_links 1")
  552. # first, connect dev[0] and dev[1]
  553. add_open_mesh_network(dev[0])
  554. add_open_mesh_network(dev[1])
  555. for i in range(2):
  556. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  557. if ev is None:
  558. raise Exception("dev%d did not connect with any peer" % i)
  559. # add dev[2] which will try to connect with both dev[0] and dev[1],
  560. # but can complete connection only with dev[1]
  561. add_open_mesh_network(dev[2])
  562. for i in range(1, 3):
  563. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  564. if ev is None:
  565. raise Exception("dev%d did not connect the second peer" % i)
  566. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  567. if ev is not None:
  568. raise Exception("dev0 connection beyond max peering limit")
  569. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  570. if ev is not None:
  571. raise Exception("dev2 reported unexpected peering: " + ev)
  572. for i in range(3):
  573. dev[i].mesh_group_remove()
  574. check_mesh_group_removed(dev[i])
  575. finally:
  576. dev[0].request("SET max_peer_links 99")
  577. addr0 = dev[0].own_addr()
  578. addr1 = dev[1].own_addr()
  579. addr2 = dev[2].own_addr()
  580. capfile = os.path.join(params['logdir'], "hwsim0.pcapng")
  581. filt = "wlan.fc.type_subtype == 8"
  582. out = run_tshark(capfile, filt, [ "wlan.sa", "wlan.mesh.config.cap" ])
  583. pkts = out.splitlines()
  584. one = [ 0, 0, 0 ]
  585. zero = [ 0, 0, 0 ]
  586. for pkt in pkts:
  587. addr, cap = pkt.split('\t')
  588. cap = int(cap, 16)
  589. if addr == addr0:
  590. idx = 0
  591. elif addr == addr1:
  592. idx = 1
  593. elif addr == addr2:
  594. idx = 2
  595. else:
  596. continue
  597. if cap & 0x01:
  598. one[idx] += 1
  599. else:
  600. zero[idx] += 1
  601. logger.info("one: " + str(one))
  602. logger.info("zero: " + str(zero))
  603. if zero[0] == 0:
  604. raise Exception("Accepting Additional Mesh Peerings not cleared")
  605. if one[0] == 0:
  606. raise Exception("Accepting Additional Mesh Peerings was not set in the first Beacon frame")
  607. if zero[1] > 0 or zero[2] > 0 or one[1] == 0 or one[2] == 0:
  608. raise Exception("Unexpected value in Accepting Additional Mesh Peerings from other STAs")
  609. def test_wpas_mesh_open_5ghz(dev, apdev):
  610. """wpa_supplicant open MESH network on 5 GHz band"""
  611. try:
  612. _test_wpas_mesh_open_5ghz(dev, apdev)
  613. finally:
  614. subprocess.call(['iw', 'reg', 'set', '00'])
  615. dev[0].flush_scan_cache()
  616. dev[1].flush_scan_cache()
  617. def _test_wpas_mesh_open_5ghz(dev, apdev):
  618. check_mesh_support(dev[0])
  619. subprocess.call(['iw', 'reg', 'set', 'US'])
  620. for i in range(2):
  621. for j in range(5):
  622. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  623. if ev is None:
  624. raise Exception("No regdom change event")
  625. if "alpha2=US" in ev:
  626. break
  627. add_open_mesh_network(dev[i], freq="5180")
  628. # Check for mesh joined
  629. check_mesh_group_added(dev[0])
  630. check_mesh_group_added(dev[1])
  631. # Check for peer connected
  632. check_mesh_peer_connected(dev[0])
  633. check_mesh_peer_connected(dev[1])
  634. # Test connectivity 0->1 and 1->0
  635. hwsim_utils.test_connectivity(dev[0], dev[1])
  636. def test_wpas_mesh_open_5ghz_coex(dev, apdev):
  637. """Mesh network on 5 GHz band and 20/40 coex change"""
  638. try:
  639. _test_wpas_mesh_open_5ghz_coex(dev, apdev)
  640. finally:
  641. set_world_reg(apdev0=apdev[0], dev0=dev[0])
  642. dev[0].flush_scan_cache()
  643. dev[1].flush_scan_cache()
  644. def _test_wpas_mesh_open_5ghz_coex(dev, apdev):
  645. check_mesh_support(dev[0])
  646. subprocess.call(['iw', 'reg', 'set', 'US'])
  647. # Start a 20 MHz BSS on channel 40 that would be the secondary channel of
  648. # HT40+ mesh on channel 36.
  649. params = { "ssid": "test-ht40",
  650. "hw_mode": "a",
  651. "channel": "40",
  652. "country_code": "US" }
  653. hapd = hostapd.add_ap(apdev[0], params)
  654. bssid = hapd.own_addr()
  655. for i in range(2):
  656. for j in range(5):
  657. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  658. if ev is None:
  659. raise Exception("No regdom change event")
  660. if "alpha2=US" in ev:
  661. break
  662. dev[i].scan_for_bss(bssid, freq=5200)
  663. add_open_mesh_network(dev[i], freq="5180")
  664. check_mesh_group_added(dev[0])
  665. check_mesh_group_added(dev[1])
  666. check_mesh_peer_connected(dev[0])
  667. check_mesh_peer_connected(dev[1])
  668. freq = dev[0].get_status_field("freq")
  669. if freq != "5200":
  670. raise Exception("Unexpected STATUS freq=" + freq)
  671. sig = dev[0].request("SIGNAL_POLL").splitlines()
  672. if "FREQUENCY=5200" not in sig:
  673. raise Exception("Unexpected SIGNAL_POLL output: " + str(sig))
  674. hapd.disable()
  675. def test_wpas_mesh_open_vht_80p80(dev, apdev):
  676. """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
  677. try:
  678. _test_wpas_mesh_open_vht_80p80(dev, apdev)
  679. finally:
  680. subprocess.call(['iw', 'reg', 'set', '00'])
  681. dev[0].flush_scan_cache()
  682. dev[1].flush_scan_cache()
  683. def _test_wpas_mesh_open_vht_80p80(dev, apdev):
  684. check_mesh_support(dev[0])
  685. subprocess.call(['iw', 'reg', 'set', 'US'])
  686. for i in range(2):
  687. for j in range(5):
  688. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  689. if ev is None:
  690. raise Exception("No regdom change event")
  691. if "alpha2=US" in ev:
  692. break
  693. add_open_mesh_network(dev[i], freq="5180", chwidth=3)
  694. # Check for mesh joined
  695. check_mesh_group_added(dev[0])
  696. check_mesh_group_added(dev[1])
  697. # Check for peer connected
  698. check_mesh_peer_connected(dev[0])
  699. check_mesh_peer_connected(dev[1])
  700. # Test connectivity 0->1 and 1->0
  701. hwsim_utils.test_connectivity(dev[0], dev[1])
  702. sig = dev[0].request("SIGNAL_POLL").splitlines()
  703. if "WIDTH=80+80 MHz" not in sig:
  704. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  705. if "CENTER_FRQ1=5210" not in sig:
  706. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  707. if "CENTER_FRQ2=5775" not in sig:
  708. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  709. sig = dev[1].request("SIGNAL_POLL").splitlines()
  710. if "WIDTH=80+80 MHz" not in sig:
  711. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  712. if "CENTER_FRQ1=5210" not in sig:
  713. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  714. if "CENTER_FRQ2=5775" not in sig:
  715. raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
  716. def test_mesh_open_vht_160(dev, apdev):
  717. """Open mesh network on VHT 160 MHz channel"""
  718. try:
  719. _test_mesh_open_vht_160(dev, apdev)
  720. finally:
  721. subprocess.call(['iw', 'reg', 'set', '00'])
  722. dev[0].flush_scan_cache()
  723. dev[1].flush_scan_cache()
  724. def _test_mesh_open_vht_160(dev, apdev):
  725. check_mesh_support(dev[0])
  726. subprocess.call(['iw', 'reg', 'set', 'ZA'])
  727. for i in range(2):
  728. for j in range(5):
  729. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  730. if ev is None:
  731. raise Exception("No regdom change event")
  732. if "alpha2=ZA" in ev:
  733. break
  734. cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
  735. reg = cmd.stdout.read()
  736. if "@ 160)" not in reg:
  737. raise HwsimSkip("160 MHz channel not supported in regulatory information")
  738. add_open_mesh_network(dev[i], freq="5520", chwidth=2)
  739. # Check for mesh joined
  740. check_mesh_group_added(dev[0])
  741. check_mesh_group_added(dev[1])
  742. # Check for peer connected
  743. check_mesh_peer_connected(dev[0])
  744. check_mesh_peer_connected(dev[1])
  745. # Test connectivity 0->1 and 1->0
  746. hwsim_utils.test_connectivity(dev[0], dev[1])
  747. sig = dev[0].request("SIGNAL_POLL").splitlines()
  748. if "WIDTH=160 MHz" not in sig:
  749. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  750. if "FREQUENCY=5520" not in sig:
  751. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  752. sig = dev[1].request("SIGNAL_POLL").splitlines()
  753. if "WIDTH=160 MHz" not in sig:
  754. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  755. if "FREQUENCY=5520" not in sig:
  756. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  757. def test_wpas_mesh_password_mismatch(dev, apdev):
  758. """Mesh network and one device with mismatching password"""
  759. check_mesh_support(dev[0], secure=True)
  760. dev[0].request("SET sae_groups ")
  761. id = add_mesh_secure_net(dev[0])
  762. dev[0].mesh_group_add(id)
  763. dev[1].request("SET sae_groups ")
  764. id = add_mesh_secure_net(dev[1])
  765. dev[1].mesh_group_add(id)
  766. dev[2].request("SET sae_groups ")
  767. id = add_mesh_secure_net(dev[2])
  768. dev[2].set_network_quoted(id, "psk", "wrong password")
  769. dev[2].mesh_group_add(id)
  770. # The two peers with matching password need to be able to connect
  771. check_mesh_group_added(dev[0])
  772. check_mesh_group_added(dev[1])
  773. check_mesh_peer_connected(dev[0])
  774. check_mesh_peer_connected(dev[1])
  775. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  776. if ev is None:
  777. raise Exception("dev2 did not report auth failure (1)")
  778. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  779. if ev is None:
  780. raise Exception("dev2 did not report auth failure (2)")
  781. dev[2].dump_monitor()
  782. count = 0
  783. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=5)
  784. if ev is None:
  785. logger.info("dev0 did not report auth failure")
  786. else:
  787. if "addr=" + dev[2].own_addr() not in ev:
  788. raise Exception("Unexpected peer address in dev0 event: " + ev)
  789. count += 1
  790. dev[0].dump_monitor()
  791. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=5)
  792. if ev is None:
  793. logger.info("dev1 did not report auth failure")
  794. else:
  795. if "addr=" + dev[2].own_addr() not in ev:
  796. raise Exception("Unexpected peer address in dev1 event: " + ev)
  797. count += 1
  798. dev[1].dump_monitor()
  799. hwsim_utils.test_connectivity(dev[0], dev[1])
  800. for i in range(2):
  801. try:
  802. hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
  803. raise Exception("Data connectivity test passed unexpectedly")
  804. except Exception, e:
  805. if "data delivery failed" not in str(e):
  806. raise
  807. if count == 0:
  808. raise Exception("Neither dev0 nor dev1 reported auth failure")
  809. def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
  810. """Mesh password mismatch and retry [long]"""
  811. if not params['long']:
  812. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  813. check_mesh_support(dev[0], secure=True)
  814. dev[0].request("SET sae_groups ")
  815. id = add_mesh_secure_net(dev[0])
  816. dev[0].mesh_group_add(id)
  817. dev[1].request("SET sae_groups ")
  818. id = add_mesh_secure_net(dev[1])
  819. dev[1].set_network_quoted(id, "psk", "wrong password")
  820. dev[1].mesh_group_add(id)
  821. # Check for mesh joined
  822. check_mesh_group_added(dev[0])
  823. check_mesh_group_added(dev[1])
  824. for i in range(4):
  825. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  826. if ev is None:
  827. raise Exception("dev0 did not report auth failure (%d)" % i)
  828. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  829. if ev is None:
  830. raise Exception("dev1 did not report auth failure (%d)" % i)
  831. ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  832. if ev is None:
  833. raise Exception("dev0 did not report auth blocked")
  834. ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  835. if ev is None:
  836. raise Exception("dev1 did not report auth blocked")
  837. def test_mesh_wpa_auth_init_oom(dev, apdev):
  838. """Secure mesh network setup failing due to wpa_init() OOM"""
  839. check_mesh_support(dev[0], secure=True)
  840. dev[0].request("SET sae_groups ")
  841. with alloc_fail(dev[0], 1, "wpa_init"):
  842. id = add_mesh_secure_net(dev[0])
  843. dev[0].mesh_group_add(id)
  844. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
  845. if ev is not None:
  846. raise Exception("Unexpected mesh group start during OOM")
  847. def test_mesh_wpa_init_fail(dev, apdev):
  848. """Secure mesh network setup local failure"""
  849. check_mesh_support(dev[0], secure=True)
  850. dev[0].request("SET sae_groups ")
  851. with fail_test(dev[0], 1, "os_get_random;=__mesh_rsn_auth_init"):
  852. id = add_mesh_secure_net(dev[0])
  853. dev[0].mesh_group_add(id)
  854. wait_fail_trigger(dev[0], "GET_FAIL")
  855. dev[0].dump_monitor()
  856. with alloc_fail(dev[0], 1, "mesh_rsn_auth_init"):
  857. id = add_mesh_secure_net(dev[0])
  858. dev[0].mesh_group_add(id)
  859. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  860. dev[0].dump_monitor()
  861. with fail_test(dev[0], 1, "os_get_random;mesh_rsn_init_ampe_sta"):
  862. id = add_mesh_secure_net(dev[0])
  863. dev[0].mesh_group_add(id)
  864. dev[1].request("SET sae_groups ")
  865. id = add_mesh_secure_net(dev[1])
  866. dev[1].mesh_group_add(id)
  867. wait_fail_trigger(dev[0], "GET_FAIL")
  868. def test_wpas_mesh_reconnect(dev, apdev):
  869. """Secure mesh network plink counting during reconnection"""
  870. check_mesh_support(dev[0])
  871. try:
  872. _test_wpas_mesh_reconnect(dev)
  873. finally:
  874. dev[0].request("SET max_peer_links 99")
  875. def _test_wpas_mesh_reconnect(dev):
  876. dev[0].request("SET max_peer_links 2")
  877. dev[0].request("SET sae_groups ")
  878. id = add_mesh_secure_net(dev[0])
  879. dev[0].set_network(id, "beacon_int", "100")
  880. dev[0].mesh_group_add(id)
  881. dev[1].request("SET sae_groups ")
  882. id = add_mesh_secure_net(dev[1])
  883. dev[1].mesh_group_add(id)
  884. check_mesh_group_added(dev[0])
  885. check_mesh_group_added(dev[1])
  886. check_mesh_peer_connected(dev[0])
  887. check_mesh_peer_connected(dev[1])
  888. for i in range(3):
  889. # Drop incoming management frames to avoid handling link close
  890. dev[0].request("SET ext_mgmt_frame_handling 1")
  891. dev[1].mesh_group_remove()
  892. check_mesh_group_removed(dev[1])
  893. dev[1].request("FLUSH")
  894. dev[0].request("SET ext_mgmt_frame_handling 0")
  895. id = add_mesh_secure_net(dev[1])
  896. dev[1].mesh_group_add(id)
  897. check_mesh_group_added(dev[1])
  898. check_mesh_peer_connected(dev[1])
  899. dev[0].dump_monitor()
  900. dev[1].dump_monitor()
  901. def test_wpas_mesh_gate_forwarding(dev, apdev, p):
  902. """Mesh forwards traffic to unknown sta to mesh gates"""
  903. addr0 = dev[0].own_addr()
  904. addr1 = dev[1].own_addr()
  905. addr2 = dev[2].own_addr()
  906. external_sta = '02:11:22:33:44:55'
  907. # start 3 node connected mesh
  908. check_mesh_support(dev[0])
  909. for i in range(3):
  910. add_open_mesh_network(dev[i])
  911. check_mesh_group_added(dev[i])
  912. for i in range(3):
  913. check_mesh_peer_connected(dev[i])
  914. hwsim_utils.test_connectivity(dev[0], dev[1])
  915. hwsim_utils.test_connectivity(dev[1], dev[2])
  916. hwsim_utils.test_connectivity(dev[0], dev[2])
  917. # dev0 and dev1 are mesh gates
  918. subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
  919. 'mesh_gate_announcements=1'])
  920. subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
  921. 'mesh_gate_announcements=1'])
  922. # wait for gate announcement frames
  923. time.sleep(1)
  924. # data frame from dev2 -> external sta should be sent to both gates
  925. dev[2].request("DATA_TEST_CONFIG 1")
  926. dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
  927. dev[2].request("DATA_TEST_CONFIG 0")
  928. capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
  929. filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
  930. external_sta)
  931. for i in range(15):
  932. da = run_tshark(capfile, filt, [ "wlan.da" ])
  933. if addr0 in da and addr1 in da:
  934. logger.debug("Frames seen in tshark iteration %d" % i)
  935. break
  936. time.sleep(0.3)
  937. if addr0 not in da:
  938. raise Exception("Frame to gate %s not observed" % addr0)
  939. if addr1 not in da:
  940. raise Exception("Frame to gate %s not observed" % addr1)
  941. def test_wpas_mesh_pmksa_caching(dev, apdev):
  942. """Secure mesh network and PMKSA caching"""
  943. check_mesh_support(dev[0], secure=True)
  944. dev[0].request("SET sae_groups ")
  945. id = add_mesh_secure_net(dev[0])
  946. dev[0].mesh_group_add(id)
  947. dev[1].request("SET sae_groups ")
  948. id = add_mesh_secure_net(dev[1])
  949. dev[1].mesh_group_add(id)
  950. # Check for mesh joined
  951. check_mesh_group_added(dev[0])
  952. check_mesh_group_added(dev[1])
  953. # Check for peer connected
  954. check_mesh_peer_connected(dev[0])
  955. check_mesh_peer_connected(dev[1])
  956. addr0 = dev[0].own_addr()
  957. addr1 = dev[1].own_addr()
  958. pmksa0 = dev[0].get_pmksa(addr1)
  959. pmksa1 = dev[1].get_pmksa(addr0)
  960. if pmksa0 is None or pmksa1 is None:
  961. raise Exception("No PMKSA cache entry created")
  962. if pmksa0['pmkid'] != pmksa1['pmkid']:
  963. raise Exception("PMKID mismatch in PMKSA cache entries")
  964. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  965. raise Exception("Failed to remove peer")
  966. pmksa0b = dev[0].get_pmksa(addr1)
  967. if pmksa0b is None:
  968. raise Exception("PMKSA cache entry not maintained")
  969. time.sleep(0.1)
  970. if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
  971. raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
  972. def test_wpas_mesh_pmksa_caching2(dev, apdev):
  973. """Secure mesh network and PMKSA caching with no_auto_peer=1"""
  974. check_mesh_support(dev[0], secure=True)
  975. addr0 = dev[0].own_addr()
  976. addr1 = dev[1].own_addr()
  977. dev[0].request("SET sae_groups ")
  978. id = add_mesh_secure_net(dev[0])
  979. dev[0].set_network(id, "no_auto_peer", "1")
  980. dev[0].mesh_group_add(id)
  981. dev[1].request("SET sae_groups ")
  982. id = add_mesh_secure_net(dev[1])
  983. dev[1].set_network(id, "no_auto_peer", "1")
  984. dev[1].mesh_group_add(id)
  985. # Check for mesh joined
  986. check_mesh_group_added(dev[0])
  987. check_mesh_group_added(dev[1])
  988. # Check for peer connected
  989. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  990. if ev is None:
  991. raise Exception("Missing no-initiate message")
  992. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  993. raise Exception("MESH_PEER_ADD failed")
  994. check_mesh_peer_connected(dev[0])
  995. check_mesh_peer_connected(dev[1])
  996. pmksa0 = dev[0].get_pmksa(addr1)
  997. pmksa1 = dev[1].get_pmksa(addr0)
  998. if pmksa0 is None or pmksa1 is None:
  999. raise Exception("No PMKSA cache entry created")
  1000. if pmksa0['pmkid'] != pmksa1['pmkid']:
  1001. raise Exception("PMKID mismatch in PMKSA cache entries")
  1002. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1003. raise Exception("Failed to remove peer")
  1004. pmksa0b = dev[0].get_pmksa(addr1)
  1005. if pmksa0b is None:
  1006. raise Exception("PMKSA cache entry not maintained")
  1007. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1008. if ev is None:
  1009. raise Exception("Missing no-initiate message (2)")
  1010. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1011. raise Exception("MESH_PEER_ADD failed (2)")
  1012. check_mesh_peer_connected(dev[0])
  1013. check_mesh_peer_connected(dev[1])
  1014. pmksa0c = dev[0].get_pmksa(addr1)
  1015. pmksa1c = dev[1].get_pmksa(addr0)
  1016. if pmksa0c is None or pmksa1c is None:
  1017. raise Exception("No PMKSA cache entry created (2)")
  1018. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  1019. raise Exception("PMKID mismatch in PMKSA cache entries")
  1020. if pmksa0['pmkid'] != pmksa0c['pmkid']:
  1021. raise Exception("PMKID changed")
  1022. hwsim_utils.test_connectivity(dev[0], dev[1])
  1023. def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
  1024. """Secure mesh network and PMKSA caching with no PMKID match"""
  1025. check_mesh_support(dev[0], secure=True)
  1026. addr0 = dev[0].own_addr()
  1027. addr1 = dev[1].own_addr()
  1028. dev[0].request("SET sae_groups ")
  1029. id = add_mesh_secure_net(dev[0])
  1030. dev[0].set_network(id, "no_auto_peer", "1")
  1031. dev[0].mesh_group_add(id)
  1032. dev[1].request("SET sae_groups ")
  1033. id = add_mesh_secure_net(dev[1])
  1034. dev[1].set_network(id, "no_auto_peer", "1")
  1035. dev[1].mesh_group_add(id)
  1036. # Check for mesh joined
  1037. check_mesh_group_added(dev[0])
  1038. check_mesh_group_added(dev[1])
  1039. # Check for peer connected
  1040. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1041. if ev is None:
  1042. raise Exception("Missing no-initiate message")
  1043. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1044. raise Exception("MESH_PEER_ADD failed")
  1045. check_mesh_peer_connected(dev[0])
  1046. check_mesh_peer_connected(dev[1])
  1047. pmksa0 = dev[0].get_pmksa(addr1)
  1048. pmksa1 = dev[1].get_pmksa(addr0)
  1049. if pmksa0 is None or pmksa1 is None:
  1050. raise Exception("No PMKSA cache entry created")
  1051. if pmksa0['pmkid'] != pmksa1['pmkid']:
  1052. raise Exception("PMKID mismatch in PMKSA cache entries")
  1053. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1054. raise Exception("Failed to remove peer")
  1055. if "OK" not in dev[1].request("PMKSA_FLUSH"):
  1056. raise Exception("Failed to flush PMKSA cache")
  1057. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1058. if ev is None:
  1059. raise Exception("Missing no-initiate message (2)")
  1060. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1061. raise Exception("MESH_PEER_ADD failed (2)")
  1062. check_mesh_peer_connected(dev[0])
  1063. check_mesh_peer_connected(dev[1])
  1064. pmksa0c = dev[0].get_pmksa(addr1)
  1065. pmksa1c = dev[1].get_pmksa(addr0)
  1066. if pmksa0c is None or pmksa1c is None:
  1067. raise Exception("No PMKSA cache entry created (2)")
  1068. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  1069. raise Exception("PMKID mismatch in PMKSA cache entries")
  1070. if pmksa0['pmkid'] == pmksa0c['pmkid']:
  1071. raise Exception("PMKID did not change")
  1072. hwsim_utils.test_connectivity(dev[0], dev[1])
  1073. def test_mesh_pmksa_caching_oom(dev, apdev):
  1074. """Secure mesh network and PMKSA caching failing due to OOM"""
  1075. check_mesh_support(dev[0], secure=True)
  1076. addr0 = dev[0].own_addr()
  1077. addr1 = dev[1].own_addr()
  1078. dev[0].request("SET sae_groups ")
  1079. id = add_mesh_secure_net(dev[0])
  1080. dev[0].set_network(id, "no_auto_peer", "1")
  1081. dev[0].mesh_group_add(id)
  1082. dev[1].request("SET sae_groups ")
  1083. id = add_mesh_secure_net(dev[1])
  1084. dev[1].set_network(id, "no_auto_peer", "1")
  1085. dev[1].mesh_group_add(id)
  1086. # Check for mesh joined
  1087. check_mesh_group_added(dev[0])
  1088. check_mesh_group_added(dev[1])
  1089. # Check for peer connected
  1090. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1091. if ev is None:
  1092. raise Exception("Missing no-initiate message")
  1093. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1094. raise Exception("MESH_PEER_ADD failed")
  1095. check_mesh_peer_connected(dev[0])
  1096. check_mesh_peer_connected(dev[1])
  1097. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1098. raise Exception("Failed to remove peer")
  1099. pmksa0b = dev[0].get_pmksa(addr1)
  1100. if pmksa0b is None:
  1101. raise Exception("PMKSA cache entry not maintained")
  1102. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1103. if ev is None:
  1104. raise Exception("Missing no-initiate message (2)")
  1105. with alloc_fail(dev[0], 1, "wpa_auth_sta_init;mesh_rsn_auth_sae_sta"):
  1106. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1107. raise Exception("MESH_PEER_ADD failed (2)")
  1108. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1109. def test_mesh_oom(dev, apdev):
  1110. """Mesh network setup failing due to OOM"""
  1111. check_mesh_support(dev[0], secure=True)
  1112. dev[0].request("SET sae_groups ")
  1113. with alloc_fail(dev[0], 1, "mesh_config_create"):
  1114. add_open_mesh_network(dev[0])
  1115. ev = dev[0].wait_event(["Failed to init mesh"])
  1116. if ev is None:
  1117. raise Exception("Init failure not reported")
  1118. with alloc_fail(dev[0], 4, "=wpa_supplicant_mesh_init"):
  1119. add_open_mesh_network(dev[0], basic_rates="60 120 240")
  1120. ev = dev[0].wait_event(["Failed to init mesh"])
  1121. if ev is None:
  1122. raise Exception("Init failure not reported")
  1123. for i in range(1, 66):
  1124. dev[0].dump_monitor()
  1125. logger.info("Test instance %d" % i)
  1126. try:
  1127. with alloc_fail(dev[0], i, "wpa_supplicant_mesh_init"):
  1128. add_open_mesh_network(dev[0])
  1129. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1130. ev = dev[0].wait_event(["Failed to init mesh",
  1131. "MESH-GROUP-STARTED"])
  1132. if ev is None:
  1133. raise Exception("Init failure not reported")
  1134. except Exception, e:
  1135. if i < 15:
  1136. raise
  1137. logger.info("Ignore no-oom for i=%d" % i)
  1138. with alloc_fail(dev[0], 5, "=wpa_supplicant_mesh_init"):
  1139. id = add_mesh_secure_net(dev[0])
  1140. dev[0].mesh_group_add(id)
  1141. ev = dev[0].wait_event(["Failed to init mesh"])
  1142. if ev is None:
  1143. raise Exception("Init failure not reported")
  1144. def test_mesh_add_interface_oom(dev):
  1145. """wpa_supplicant mesh with dynamic interface addition failing"""
  1146. check_mesh_support(dev[0])
  1147. for i in range(1, 3):
  1148. mesh = None
  1149. try:
  1150. with alloc_fail(dev[0], i, "wpas_mesh_add_interface"):
  1151. mesh = dev[0].request("MESH_INTERFACE_ADD").strip()
  1152. finally:
  1153. if mesh and mesh != "FAIL":
  1154. dev[0].request("MESH_GROUP_REMOVE " + mesh)
  1155. def test_mesh_scan_oom(dev):
  1156. """wpa_supplicant mesh scan results and OOM"""
  1157. check_mesh_support(dev[0])
  1158. add_open_mesh_network(dev[0])
  1159. check_mesh_group_added(dev[0])
  1160. for i in range(5):
  1161. dev[1].scan(freq="2412")
  1162. res = dev[1].request("SCAN_RESULTS")
  1163. if "[MESH]" in res:
  1164. break
  1165. for r in res.splitlines():
  1166. if "[MESH]" in r:
  1167. break
  1168. bssid = r.split('\t')[0]
  1169. bss = dev[1].get_bss(bssid)
  1170. if bss is None:
  1171. raise Exception("Could not get BSS entry for mesh")
  1172. for i in range(1, 3):
  1173. with alloc_fail(dev[1], i, "mesh_attr_text"):
  1174. bss = dev[1].get_bss(bssid)
  1175. if bss and "mesh_id" in bss:
  1176. raise Exception("Unexpected BSS result during OOM")
  1177. def test_mesh_drv_fail(dev, apdev):
  1178. """Mesh network setup failing due to driver command failure"""
  1179. check_mesh_support(dev[0], secure=True)
  1180. dev[0].request("SET sae_groups ")
  1181. with fail_test(dev[0], 1, "nl80211_join_mesh"):
  1182. add_open_mesh_network(dev[0])
  1183. ev = dev[0].wait_event(["mesh join error"])
  1184. if ev is None:
  1185. raise Exception("Join failure not reported")
  1186. dev[0].dump_monitor()
  1187. with fail_test(dev[0], 1, "wpa_driver_nl80211_if_add"):
  1188. if "FAIL" not in dev[0].request("MESH_INTERFACE_ADD").strip():
  1189. raise Exception("Interface added unexpectedly")
  1190. dev[0].dump_monitor()
  1191. with fail_test(dev[0], 1, "wpa_driver_nl80211_init_mesh"):
  1192. add_open_mesh_network(dev[0])
  1193. ev = dev[0].wait_event(["Could not join mesh"])
  1194. if ev is None:
  1195. raise Exception("Join failure not reported")
  1196. def test_mesh_sae_groups_invalid(dev, apdev):
  1197. """Mesh with invalid SAE group configuration"""
  1198. check_mesh_support(dev[0], secure=True)
  1199. dev[0].request("SET sae_groups 25")
  1200. id = add_mesh_secure_net(dev[0])
  1201. dev[0].mesh_group_add(id)
  1202. dev[1].request("SET sae_groups 123 122 121")
  1203. id = add_mesh_secure_net(dev[1])
  1204. dev[1].mesh_group_add(id)
  1205. check_mesh_group_added(dev[0])
  1206. check_mesh_group_added(dev[1])
  1207. ev = dev[0].wait_event(["new peer notification"], timeout=10)
  1208. if ev is None:
  1209. raise Exception("dev[0] did not see peer")
  1210. ev = dev[1].wait_event(["new peer notification"], timeout=10)
  1211. if ev is None:
  1212. raise Exception("dev[1] did not see peer")
  1213. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  1214. if ev is not None:
  1215. raise Exception("Unexpected connection(0)")
  1216. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1217. if ev is not None:
  1218. raise Exception("Unexpected connection(1)")
  1219. # Additional coverage in mesh_rsn_sae_group() with non-zero
  1220. # wpa_s->mesh_rsn->sae_group_index.
  1221. dev[0].dump_monitor()
  1222. dev[1].dump_monitor()
  1223. id = add_mesh_secure_net(dev[2])
  1224. dev[2].mesh_group_add(id)
  1225. check_mesh_group_added(dev[2])
  1226. check_mesh_peer_connected(dev[0])
  1227. check_mesh_peer_connected(dev[2])
  1228. ev = dev[1].wait_event(["new peer notification"], timeout=10)
  1229. if ev is None:
  1230. raise Exception("dev[1] did not see peer(2)")
  1231. dev[0].dump_monitor()
  1232. dev[1].dump_monitor()
  1233. dev[2].dump_monitor()
  1234. dev[0].request("SET sae_groups ")
  1235. dev[1].request("SET sae_groups ")
  1236. def test_mesh_sae_failure(dev, apdev):
  1237. """Mesh and local SAE failures"""
  1238. check_mesh_support(dev[0], secure=True)
  1239. dev[0].request("SET sae_groups ")
  1240. dev[1].request("SET sae_groups ")
  1241. funcs = [ (1, "=mesh_rsn_auth_sae_sta", True),
  1242. (1, "mesh_rsn_build_sae_commit;mesh_rsn_auth_sae_sta", False),
  1243. (1, "auth_sae_init_committed;mesh_rsn_auth_sae_sta", True),
  1244. (1, "=mesh_rsn_protect_frame", True),
  1245. (2, "=mesh_rsn_protect_frame", True),
  1246. (1, "aes_siv_encrypt;mesh_rsn_protect_frame", True),
  1247. (1, "=mesh_rsn_process_ampe", True),
  1248. (1, "aes_siv_decrypt;mesh_rsn_process_ampe", True) ]
  1249. for count, func, success in funcs:
  1250. id = add_mesh_secure_net(dev[0])
  1251. dev[0].mesh_group_add(id)
  1252. with alloc_fail(dev[1], count, func):
  1253. id = add_mesh_secure_net(dev[1])
  1254. dev[1].mesh_group_add(id)
  1255. check_mesh_group_added(dev[0])
  1256. check_mesh_group_added(dev[1])
  1257. if success:
  1258. # retry is expected to work
  1259. check_mesh_peer_connected(dev[0])
  1260. check_mesh_peer_connected(dev[1])
  1261. else:
  1262. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  1263. dev[0].mesh_group_remove()
  1264. dev[1].mesh_group_remove()
  1265. check_mesh_group_removed(dev[0])
  1266. check_mesh_group_removed(dev[1])
  1267. def test_mesh_failure(dev, apdev):
  1268. """Mesh and local failures"""
  1269. check_mesh_support(dev[0])
  1270. funcs = [ (1, "ap_sta_add;mesh_mpm_add_peer", True),
  1271. (1, "wpabuf_alloc;mesh_mpm_send_plink_action", True) ]
  1272. for count, func, success in funcs:
  1273. add_open_mesh_network(dev[0])
  1274. with alloc_fail(dev[1], count, func):
  1275. add_open_mesh_network(dev[1])
  1276. check_mesh_group_added(dev[0])
  1277. check_mesh_group_added(dev[1])
  1278. if success:
  1279. # retry is expected to work
  1280. check_mesh_peer_connected(dev[0])
  1281. check_mesh_peer_connected(dev[1])
  1282. else:
  1283. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  1284. dev[0].mesh_group_remove()
  1285. dev[1].mesh_group_remove()
  1286. check_mesh_group_removed(dev[0])
  1287. check_mesh_group_removed(dev[1])
  1288. funcs = [ (1, "mesh_mpm_init_link", True) ]
  1289. for count, func, success in funcs:
  1290. add_open_mesh_network(dev[0])
  1291. with fail_test(dev[1], count, func):
  1292. add_open_mesh_network(dev[1])
  1293. check_mesh_group_added(dev[0])
  1294. check_mesh_group_added(dev[1])
  1295. if success:
  1296. # retry is expected to work
  1297. check_mesh_peer_connected(dev[0])
  1298. check_mesh_peer_connected(dev[1])
  1299. else:
  1300. wait_fail_trigger(dev[1], "GET_FAIL")
  1301. dev[0].mesh_group_remove()
  1302. dev[1].mesh_group_remove()
  1303. check_mesh_group_removed(dev[0])
  1304. check_mesh_group_removed(dev[1])
  1305. def test_mesh_invalid_frequency(dev, apdev):
  1306. """Mesh and invalid frequency configuration"""
  1307. check_mesh_support(dev[0])
  1308. add_open_mesh_network(dev[0], freq=None)
  1309. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  1310. "Could not join mesh"])
  1311. if ev is None or "Could not join mesh" not in ev:
  1312. raise Exception("Mesh join failure not reported")
  1313. dev[0].request("REMOVE_NETWORK all")
  1314. add_open_mesh_network(dev[0], freq="2413")
  1315. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  1316. "Could not join mesh"])
  1317. if ev is None or "Could not join mesh" not in ev:
  1318. raise Exception("Mesh join failure not reported")
  1319. def test_mesh_default_beacon_int(dev, apdev):
  1320. """Mesh and default beacon interval"""
  1321. check_mesh_support(dev[0])
  1322. try:
  1323. dev[0].request("SET beacon_int 200")
  1324. add_open_mesh_network(dev[0])
  1325. check_mesh_group_added(dev[0])
  1326. finally:
  1327. dev[0].request("SET beacon_int 0")
  1328. def test_mesh_scan_parse_error(dev, apdev):
  1329. """Mesh scan element parse error"""
  1330. check_mesh_support(dev[0])
  1331. params = { "ssid": "open",
  1332. "beacon_int": "2000" }
  1333. hapd = hostapd.add_ap(apdev[0], params)
  1334. bssid = apdev[0]['bssid']
  1335. hapd.set('vendor_elements', 'dd0201')
  1336. for i in range(10):
  1337. dev[0].scan(freq=2412)
  1338. if bssid in dev[0].request("SCAN_RESULTS"):
  1339. break
  1340. # This will fail in IE parsing due to the truncated IE in the Probe
  1341. # Response frame.
  1342. bss = dev[0].request("BSS " + bssid)
  1343. def test_mesh_missing_mic(dev, apdev):
  1344. """Secure mesh network and missing MIC"""
  1345. check_mesh_support(dev[0], secure=True)
  1346. dev[0].request("SET ext_mgmt_frame_handling 1")
  1347. dev[0].request("SET sae_groups ")
  1348. id = add_mesh_secure_net(dev[0])
  1349. dev[0].mesh_group_add(id)
  1350. dev[1].request("SET sae_groups ")
  1351. id = add_mesh_secure_net(dev[1])
  1352. dev[1].mesh_group_add(id)
  1353. # Check for mesh joined
  1354. check_mesh_group_added(dev[0])
  1355. check_mesh_group_added(dev[1])
  1356. count = 0
  1357. remove_mic = True
  1358. while True:
  1359. count += 1
  1360. if count > 15:
  1361. raise Exception("Did not see Action frames")
  1362. rx_msg = dev[0].mgmt_rx()
  1363. if rx_msg is None:
  1364. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1365. if ev:
  1366. break
  1367. raise Exception("MGMT-RX timeout")
  1368. if rx_msg['subtype'] == 13:
  1369. payload = rx_msg['payload']
  1370. frame = rx_msg['frame']
  1371. (categ, action) = struct.unpack('BB', payload[0:2])
  1372. if categ == 15 and action == 1 and remove_mic:
  1373. # Mesh Peering Open
  1374. pos = frame.find('\x8c\x10')
  1375. if not pos:
  1376. raise Exception("Could not find MIC element")
  1377. logger.info("Found MIC at %d" % pos)
  1378. # Remove MIC
  1379. rx_msg['frame'] = frame[0:pos]
  1380. remove_mic = False
  1381. 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'))):
  1382. raise Exception("MGMT_RX_PROCESS failed")
  1383. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1384. if ev:
  1385. break
  1386. def test_mesh_pmkid_mismatch(dev, apdev):
  1387. """Secure mesh network and PMKID mismatch"""
  1388. check_mesh_support(dev[0], secure=True)
  1389. addr0 = dev[0].own_addr()
  1390. addr1 = dev[1].own_addr()
  1391. dev[0].request("SET sae_groups ")
  1392. id = add_mesh_secure_net(dev[0])
  1393. dev[0].set_network(id, "no_auto_peer", "1")
  1394. dev[0].mesh_group_add(id)
  1395. dev[1].request("SET sae_groups ")
  1396. id = add_mesh_secure_net(dev[1])
  1397. dev[1].set_network(id, "no_auto_peer", "1")
  1398. dev[1].mesh_group_add(id)
  1399. # Check for mesh joined
  1400. check_mesh_group_added(dev[0])
  1401. check_mesh_group_added(dev[1])
  1402. # Check for peer connected
  1403. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1404. if ev is None:
  1405. raise Exception("Missing no-initiate message")
  1406. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1407. raise Exception("MESH_PEER_ADD failed")
  1408. check_mesh_peer_connected(dev[0])
  1409. check_mesh_peer_connected(dev[1])
  1410. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1411. raise Exception("Failed to remove peer")
  1412. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1413. if ev is None:
  1414. raise Exception("Missing no-initiate message (2)")
  1415. dev[0].dump_monitor()
  1416. dev[1].dump_monitor()
  1417. dev[0].request("SET ext_mgmt_frame_handling 1")
  1418. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1419. raise Exception("MESH_PEER_ADD failed (2)")
  1420. count = 0
  1421. break_pmkid = True
  1422. while True:
  1423. count += 1
  1424. if count > 50:
  1425. raise Exception("Did not see Action frames")
  1426. rx_msg = dev[0].mgmt_rx()
  1427. if rx_msg is None:
  1428. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  1429. if ev:
  1430. break
  1431. raise Exception("MGMT-RX timeout")
  1432. if rx_msg['subtype'] == 13:
  1433. payload = rx_msg['payload']
  1434. frame = rx_msg['frame']
  1435. (categ, action) = struct.unpack('BB', payload[0:2])
  1436. if categ == 15 and action == 1 and break_pmkid:
  1437. # Mesh Peering Open
  1438. pos = frame.find('\x75\x14')
  1439. if not pos:
  1440. raise Exception("Could not find Mesh Peering Management element")
  1441. logger.info("Found Mesh Peering Management element at %d" % pos)
  1442. # Break PMKID to hit "Mesh RSN: Invalid PMKID (Chosen PMK did
  1443. # not match calculated PMKID)"
  1444. rx_msg['frame'] = frame[0:pos + 6] + '\x00\x00\x00\x00' + frame[pos + 10:]
  1445. break_pmkid = False
  1446. 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'))):
  1447. raise Exception("MGMT_RX_PROCESS failed")
  1448. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1449. if ev:
  1450. break
  1451. def test_mesh_peering_proto(dev, apdev):
  1452. """Mesh peering management protocol testing"""
  1453. check_mesh_support(dev[0])
  1454. dev[0].request("SET ext_mgmt_frame_handling 1")
  1455. add_open_mesh_network(dev[0], beacon_int=160)
  1456. add_open_mesh_network(dev[1], beacon_int=160)
  1457. count = 0
  1458. test = 1
  1459. while True:
  1460. count += 1
  1461. if count > 50:
  1462. raise Exception("Did not see Action frames")
  1463. rx_msg = dev[0].mgmt_rx()
  1464. if rx_msg is None:
  1465. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1466. if ev:
  1467. break
  1468. raise Exception("MGMT-RX timeout")
  1469. if rx_msg['subtype'] == 13:
  1470. payload = rx_msg['payload']
  1471. frame = rx_msg['frame']
  1472. (categ, action) = struct.unpack('BB', payload[0:2])
  1473. if categ == 15 and action == 1 and test == 1:
  1474. # Mesh Peering Open
  1475. pos = frame.find('\x75\x04')
  1476. if not pos:
  1477. raise Exception("Could not find Mesh Peering Management element")
  1478. logger.info("Found Mesh Peering Management element at %d" % pos)
  1479. # Remove the element to hit
  1480. # "MPM: No Mesh Peering Management element"
  1481. rx_msg['frame'] = frame[0:pos]
  1482. test += 1
  1483. elif categ == 15 and action == 1 and test == 2:
  1484. # Mesh Peering Open
  1485. pos = frame.find('\x72\x0e')
  1486. if not pos:
  1487. raise Exception("Could not find Mesh ID element")
  1488. logger.info("Found Mesh ID element at %d" % pos)
  1489. # Remove the element to hit
  1490. # "MPM: No Mesh ID or Mesh Configuration element"
  1491. rx_msg['frame'] = frame[0:pos] + frame[pos + 16:]
  1492. test += 1
  1493. elif categ == 15 and action == 1 and test == 3:
  1494. # Mesh Peering Open
  1495. pos = frame.find('\x72\x0e')
  1496. if not pos:
  1497. raise Exception("Could not find Mesh ID element")
  1498. logger.info("Found Mesh ID element at %d" % pos)
  1499. # Replace Mesh ID to hit "MPM: Mesh ID or Mesh Configuration
  1500. # element do not match local MBSS"
  1501. rx_msg['frame'] = frame[0:pos] + '\x72\x0etest-test-test' + frame[pos + 16:]
  1502. test += 1
  1503. elif categ == 15 and action == 1 and test == 4:
  1504. # Mesh Peering Open
  1505. # Remove IEs to hit
  1506. # "MPM: Ignore too short action frame 1 ie_len 0"
  1507. rx_msg['frame'] = frame[0:26]
  1508. test += 1
  1509. elif categ == 15 and action == 1 and test == 5:
  1510. # Mesh Peering Open
  1511. # Truncate IEs to hit
  1512. # "MPM: Failed to parse PLINK IEs"
  1513. rx_msg['frame'] = frame[0:30]
  1514. test += 1
  1515. elif categ == 15 and action == 1 and test == 6:
  1516. # Mesh Peering Open
  1517. pos = frame.find('\x75\x04')
  1518. if not pos:
  1519. raise Exception("Could not find Mesh Peering Management element")
  1520. logger.info("Found Mesh Peering Management element at %d" % pos)
  1521. # Truncate the element to hit
  1522. # "MPM: Invalid peer mgmt ie" and
  1523. # "MPM: Mesh parsing rejected frame"
  1524. rx_msg['frame'] = frame[0:pos] + '\x75\x00\x00\x00' + frame[pos + 6:]
  1525. test += 1
  1526. 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'))):
  1527. raise Exception("MGMT_RX_PROCESS failed")
  1528. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1529. if ev:
  1530. break
  1531. if test != 7:
  1532. raise Exception("Not all test frames completed")
  1533. def test_mesh_mpm_init_proto(dev, apdev):
  1534. """Mesh peering management protocol testing for peer addition"""
  1535. check_mesh_support(dev[0])
  1536. add_open_mesh_network(dev[0])
  1537. check_mesh_group_added(dev[0])
  1538. dev[0].dump_monitor()
  1539. dev[0].request("SET ext_mgmt_frame_handling 1")
  1540. addr = "020000000100"
  1541. hdr = "d000ac00020000000000" + addr + addr + "1000"
  1542. fixed = "0f010000"
  1543. supp_rates = "010802040b168c129824"
  1544. ext_supp_rates = "3204b048606c"
  1545. mesh_id = "720e777061732d6d6573682d6f70656e"
  1546. mesh_conf = "710701010001000009"
  1547. mpm = "75040000079d"
  1548. ht_capab = "2d1a7c001bffff000000000000000000000100000000000000000000"
  1549. ht_oper = "3d160b000000000000000000000000000000000000000000"
  1550. dev[0].request("NOTE no supported rates")
  1551. frame = hdr + fixed + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1552. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1553. raise Exception("MGMT_RX_PROCESS failed")
  1554. dev[0].request("NOTE Invalid supported rates element length 33+0")
  1555. long_supp_rates = "012100112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"
  1556. frame = hdr + fixed + long_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1557. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1558. raise Exception("MGMT_RX_PROCESS failed")
  1559. dev[0].request("NOTE Too short mesh config")
  1560. short_mesh_conf = "710401010001"
  1561. frame = hdr + fixed + supp_rates + mesh_id + short_mesh_conf + mpm + ht_capab + ht_oper
  1562. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1563. raise Exception("MGMT_RX_PROCESS failed")
  1564. dev[0].request("NOTE Add STA failure")
  1565. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1566. with fail_test(dev[0], 1, "wpa_driver_nl80211_sta_add"):
  1567. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1568. raise Exception("MGMT_RX_PROCESS failed")
  1569. dev[0].request("NOTE Send Action failure")
  1570. with fail_test(dev[0], 1, "driver_nl80211_send_action"):
  1571. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1572. raise Exception("MGMT_RX_PROCESS failed")
  1573. dev[0].request("NOTE Set STA failure")
  1574. addr = "020000000101"
  1575. hdr = "d000ac00020000000000" + addr + addr + "1000"
  1576. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1577. with fail_test(dev[0], 2, "wpa_driver_nl80211_sta_add"):
  1578. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1579. raise Exception("MGMT_RX_PROCESS failed")
  1580. dev[0].request("NOTE ap_sta_add OOM")
  1581. addr = "020000000102"
  1582. hdr = "d000ac00020000000000" + addr + addr + "1000"
  1583. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1584. with alloc_fail(dev[0], 1, "ap_sta_add"):
  1585. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1586. raise Exception("MGMT_RX_PROCESS failed")
  1587. dev[0].request("NOTE hostapd_get_aid() failure")
  1588. addr = "020000000103"
  1589. hdr = "d000ac00020000000000" + addr + addr + "1000"
  1590. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1591. with fail_test(dev[0], 1, "hostapd_get_aid"):
  1592. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1593. raise Exception("MGMT_RX_PROCESS failed")
  1594. if "OK" not in dev[0].request("MESH_PEER_REMOVE 02:00:00:00:01:00"):
  1595. raise Exception("Failed to remove peer")
  1596. if "FAIL" not in dev[0].request("MESH_PEER_REMOVE 02:00:00:00:01:02"):
  1597. raise Exception("Unexpected MESH_PEER_REMOVE success")
  1598. if "FAIL" not in dev[1].request("MESH_PEER_REMOVE 02:00:00:00:01:02"):
  1599. raise Exception("Unexpected MESH_PEER_REMOVE success(2)")
  1600. if "FAIL" not in dev[1].request("MESH_PEER_ADD 02:00:00:00:01:02"):
  1601. raise Exception("Unexpected MESH_PEER_ADD success")
  1602. def test_mesh_holding(dev, apdev):
  1603. """Mesh MPM FSM and HOLDING state event OPN_ACPT"""
  1604. check_mesh_support(dev[0])
  1605. add_open_mesh_network(dev[0])
  1606. add_open_mesh_network(dev[1])
  1607. check_mesh_group_added(dev[0])
  1608. check_mesh_group_added(dev[1])
  1609. check_mesh_peer_connected(dev[0])
  1610. check_mesh_peer_connected(dev[1])
  1611. addr0 = dev[0].own_addr()
  1612. addr1 = dev[1].own_addr()
  1613. dev[0].request("SET ext_mgmt_frame_handling 1")
  1614. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1615. raise Exception("Failed to remove peer")
  1616. rx_msg = dev[0].mgmt_rx()
  1617. if rx_msg is None:
  1618. raise Exception("MGMT-RX timeout")
  1619. if rx_msg['subtype'] != 13:
  1620. raise Exception("Unexpected management frame")
  1621. payload = rx_msg['payload']
  1622. (categ, action) = struct.unpack('BB', payload[0:2])
  1623. if categ != 0x0f or action != 0x03:
  1624. raise Exception("Did not see Mesh Peering Close")
  1625. peer_lid = payload[-6:-4].encode("hex")
  1626. my_lid = payload[-4:-2].encode("hex")
  1627. # Drop Mesh Peering Close and instead, process an unexpected Mesh Peering
  1628. # Open to trigger transmission of another Mesh Peering Close in the HOLDING
  1629. # state based on an OPN_ACPT event.
  1630. dst = addr0.replace(':', '')
  1631. src = addr1.replace(':', '')
  1632. hdr = "d000ac00" + dst + src + src + "1000"
  1633. fixed = "0f010000"
  1634. supp_rates = "010802040b168c129824"
  1635. ext_supp_rates = "3204b048606c"
  1636. mesh_id = "720e777061732d6d6573682d6f70656e"
  1637. mesh_conf = "710701010001000009"
  1638. mpm = "7504" + my_lid + peer_lid
  1639. ht_capab = "2d1a7c001bffff000000000000000000000100000000000000000000"
  1640. ht_oper = "3d160b000000000000000000000000000000000000000000"
  1641. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1642. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1643. raise Exception("MGMT_RX_PROCESS failed")
  1644. time.sleep(0.1)
  1645. def test_mesh_cnf_rcvd_event_cls_acpt(dev, apdev):
  1646. """Mesh peering management protocol testing - CLS_ACPT event in CNF_RCVD"""
  1647. check_mesh_support(dev[0])
  1648. add_open_mesh_network(dev[0])
  1649. check_mesh_group_added(dev[0])
  1650. dev[0].dump_monitor()
  1651. dev[0].request("SET ext_mgmt_frame_handling 1")
  1652. add_open_mesh_network(dev[1])
  1653. check_mesh_group_added(dev[1])
  1654. addr0 = dev[0].own_addr()
  1655. addr1 = dev[1].own_addr()
  1656. rx_msg = dev[0].mgmt_rx()
  1657. # Drop Mesh Peering Open
  1658. rx_msg = dev[0].mgmt_rx()
  1659. # Allow Mesh Peering Confirm to go through
  1660. 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'))):
  1661. raise Exception("MGMT_RX_PROCESS failed")
  1662. payload = rx_msg['payload']
  1663. peer_lid = payload[51:53].encode("hex")
  1664. my_lid = payload[53:55].encode("hex")
  1665. dst = addr0.replace(':', '')
  1666. src = addr1.replace(':', '')
  1667. hdr = "d000ac00" + dst + src + src + "1000"
  1668. fixed = "0f03"
  1669. mesh_id = "720e777061732d6d6573682d6f70656e"
  1670. mpm = "75080000" + peer_lid + my_lid + "3700"
  1671. frame = hdr + fixed + mesh_id + mpm
  1672. # Inject Mesh Peering Close to hit "state CNF_RCVD event CLS_ACPT" to
  1673. # HOLDING transition.
  1674. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame):
  1675. raise Exception("MGMT_RX_PROCESS failed")
  1676. def test_mesh_opn_snt_event_cls_acpt(dev, apdev):
  1677. """Mesh peering management protocol testing - CLS_ACPT event in OPN_SNT"""
  1678. check_mesh_support(dev[0])
  1679. add_open_mesh_network(dev[0])
  1680. check_mesh_group_added(dev[0])
  1681. dev[0].dump_monitor()
  1682. dev[0].request("SET ext_mgmt_frame_handling 1")
  1683. add_open_mesh_network(dev[1])
  1684. check_mesh_group_added(dev[1])
  1685. addr0 = dev[0].own_addr()
  1686. addr1 = dev[1].own_addr()
  1687. rx_msg = dev[0].mgmt_rx()
  1688. # Drop Mesh Peering Open
  1689. rx_msg = dev[0].mgmt_rx()
  1690. # Drop Mesh Peering Confirm
  1691. payload = rx_msg['payload']
  1692. peer_lid = "0000"
  1693. my_lid = payload[53:55].encode("hex")
  1694. dst = addr0.replace(':', '')
  1695. src = addr1.replace(':', '')
  1696. hdr = "d000ac00" + dst + src + src + "1000"
  1697. fixed = "0f03"
  1698. mesh_id = "720e777061732d6d6573682d6f70656e"
  1699. mpm = "75080000" + peer_lid + my_lid + "3700"
  1700. frame = hdr + fixed + mesh_id + mpm
  1701. # Inject Mesh Peering Close to hit "state OPN_SNTevent CLS_ACPT" to
  1702. # HOLDING transition.
  1703. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame):
  1704. raise Exception("MGMT_RX_PROCESS failed")
  1705. def test_mesh_select_network(dev):
  1706. """Mesh network and SELECT_NETWORK"""
  1707. check_mesh_support(dev[0])
  1708. id0 = add_open_mesh_network(dev[0], start=False)
  1709. id1 = add_open_mesh_network(dev[1], start=False)
  1710. dev[0].select_network(id0)
  1711. dev[1].select_network(id1)
  1712. check_mesh_group_added(dev[0])
  1713. check_mesh_group_added(dev[1])
  1714. check_mesh_peer_connected(dev[0])
  1715. check_mesh_peer_connected(dev[1])
  1716. hwsim_utils.test_connectivity(dev[0], dev[1])