test_wpas_mesh.py 75 KB

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