test_wpas_mesh.py 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230
  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_dynamic_interface_remove(dev):
  551. """wpa_supplicant mesh with dynamic interface and removal"""
  552. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  553. wpas.interface_add("wlan5")
  554. check_mesh_support(wpas)
  555. mesh5 = wpas.request("MESH_INTERFACE_ADD ifname=mesh5")
  556. if "FAIL" in mesh5:
  557. raise Exception("MESH_INTERFACE_ADD failed")
  558. wpas5 = WpaSupplicant(ifname=mesh5)
  559. logger.info(mesh5 + " address " + wpas5.get_status_field("address"))
  560. add_open_mesh_network(wpas5)
  561. add_open_mesh_network(dev[0])
  562. check_mesh_group_added(wpas5)
  563. check_mesh_group_added(dev[0])
  564. check_mesh_peer_connected(wpas5)
  565. check_mesh_peer_connected(dev[0])
  566. hwsim_utils.test_connectivity(wpas5, dev[0])
  567. # Remove the main interface while mesh interface is in use
  568. wpas.interface_remove("wlan5")
  569. def test_wpas_mesh_max_peering(dev, apdev, params):
  570. """Mesh max peering limit"""
  571. check_mesh_support(dev[0])
  572. try:
  573. dev[0].request("SET max_peer_links 1")
  574. # first, connect dev[0] and dev[1]
  575. add_open_mesh_network(dev[0])
  576. add_open_mesh_network(dev[1])
  577. for i in range(2):
  578. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  579. if ev is None:
  580. raise Exception("dev%d did not connect with any peer" % i)
  581. # add dev[2] which will try to connect with both dev[0] and dev[1],
  582. # but can complete connection only with dev[1]
  583. add_open_mesh_network(dev[2])
  584. for i in range(1, 3):
  585. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  586. if ev is None:
  587. raise Exception("dev%d did not connect the second peer" % i)
  588. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  589. if ev is not None:
  590. raise Exception("dev0 connection beyond max peering limit")
  591. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  592. if ev is not None:
  593. raise Exception("dev2 reported unexpected peering: " + ev)
  594. for i in range(3):
  595. dev[i].mesh_group_remove()
  596. check_mesh_group_removed(dev[i])
  597. finally:
  598. dev[0].request("SET max_peer_links 99")
  599. addr0 = dev[0].own_addr()
  600. addr1 = dev[1].own_addr()
  601. addr2 = dev[2].own_addr()
  602. capfile = os.path.join(params['logdir'], "hwsim0.pcapng")
  603. filt = "wlan.fc.type_subtype == 8"
  604. out = run_tshark(capfile, filt, [ "wlan.sa", "wlan.mesh.config.cap" ])
  605. pkts = out.splitlines()
  606. one = [ 0, 0, 0 ]
  607. zero = [ 0, 0, 0 ]
  608. for pkt in pkts:
  609. addr, cap = pkt.split('\t')
  610. cap = int(cap, 16)
  611. if addr == addr0:
  612. idx = 0
  613. elif addr == addr1:
  614. idx = 1
  615. elif addr == addr2:
  616. idx = 2
  617. else:
  618. continue
  619. if cap & 0x01:
  620. one[idx] += 1
  621. else:
  622. zero[idx] += 1
  623. logger.info("one: " + str(one))
  624. logger.info("zero: " + str(zero))
  625. if zero[0] == 0:
  626. raise Exception("Accepting Additional Mesh Peerings not cleared")
  627. if one[0] == 0:
  628. raise Exception("Accepting Additional Mesh Peerings was not set in the first Beacon frame")
  629. if zero[1] > 0 or zero[2] > 0 or one[1] == 0 or one[2] == 0:
  630. raise Exception("Unexpected value in Accepting Additional Mesh Peerings from other STAs")
  631. def test_wpas_mesh_open_5ghz(dev, apdev):
  632. """wpa_supplicant open MESH network on 5 GHz band"""
  633. try:
  634. _test_wpas_mesh_open_5ghz(dev, apdev)
  635. finally:
  636. dev[0].request("MESH_GROUP_REMOVE " + dev[0].ifname)
  637. dev[1].request("MESH_GROUP_REMOVE " + dev[1].ifname)
  638. subprocess.call(['iw', 'reg', 'set', '00'])
  639. dev[0].flush_scan_cache()
  640. dev[1].flush_scan_cache()
  641. def _test_wpas_mesh_open_5ghz(dev, apdev):
  642. check_mesh_support(dev[0])
  643. subprocess.call(['iw', 'reg', 'set', 'US'])
  644. for i in range(2):
  645. for j in range(5):
  646. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  647. if ev is None:
  648. raise Exception("No regdom change event")
  649. if "alpha2=US" in ev:
  650. break
  651. add_open_mesh_network(dev[i], freq="5180")
  652. # Check for mesh joined
  653. check_mesh_group_added(dev[0])
  654. check_mesh_group_added(dev[1])
  655. # Check for peer connected
  656. check_mesh_peer_connected(dev[0])
  657. check_mesh_peer_connected(dev[1])
  658. # Test connectivity 0->1 and 1->0
  659. hwsim_utils.test_connectivity(dev[0], dev[1])
  660. dev[0].mesh_group_remove()
  661. dev[1].mesh_group_remove()
  662. check_mesh_group_removed(dev[0])
  663. check_mesh_group_removed(dev[1])
  664. dev[0].dump_monitor()
  665. dev[1].dump_monitor()
  666. def test_wpas_mesh_open_5ghz_coex(dev, apdev):
  667. """Mesh network on 5 GHz band and 20/40 coex change"""
  668. try:
  669. _test_wpas_mesh_open_5ghz_coex(dev, apdev)
  670. finally:
  671. dev[0].request("MESH_GROUP_REMOVE " + dev[0].ifname)
  672. dev[1].request("MESH_GROUP_REMOVE " + dev[1].ifname)
  673. set_world_reg(apdev0=apdev[0], dev0=dev[0])
  674. dev[0].flush_scan_cache()
  675. dev[1].flush_scan_cache()
  676. def _test_wpas_mesh_open_5ghz_coex(dev, apdev):
  677. check_mesh_support(dev[0])
  678. subprocess.call(['iw', 'reg', 'set', 'US'])
  679. # Start a 20 MHz BSS on channel 40 that would be the secondary channel of
  680. # HT40+ mesh on channel 36.
  681. params = { "ssid": "test-ht40",
  682. "hw_mode": "a",
  683. "channel": "40",
  684. "country_code": "US" }
  685. hapd = hostapd.add_ap(apdev[0], params)
  686. bssid = hapd.own_addr()
  687. for i in range(2):
  688. for j in range(5):
  689. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  690. if ev is None:
  691. raise Exception("No regdom change event")
  692. if "alpha2=US" in ev:
  693. break
  694. dev[i].scan_for_bss(bssid, freq=5200)
  695. add_open_mesh_network(dev[i], freq="5180")
  696. check_mesh_group_added(dev[0])
  697. check_mesh_group_added(dev[1])
  698. check_mesh_peer_connected(dev[0])
  699. check_mesh_peer_connected(dev[1])
  700. freq = dev[0].get_status_field("freq")
  701. if freq != "5200":
  702. raise Exception("Unexpected STATUS freq=" + freq)
  703. sig = dev[0].request("SIGNAL_POLL").splitlines()
  704. if "FREQUENCY=5200" not in sig:
  705. raise Exception("Unexpected SIGNAL_POLL output: " + str(sig))
  706. hapd.disable()
  707. dev[0].mesh_group_remove()
  708. dev[1].mesh_group_remove()
  709. check_mesh_group_removed(dev[0])
  710. check_mesh_group_removed(dev[1])
  711. dev[0].dump_monitor()
  712. dev[1].dump_monitor()
  713. def test_wpas_mesh_open_vht_80p80(dev, apdev):
  714. """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
  715. try:
  716. _test_wpas_mesh_open_vht_80p80(dev, apdev)
  717. finally:
  718. dev[0].request("MESH_GROUP_REMOVE " + dev[0].ifname)
  719. dev[1].request("MESH_GROUP_REMOVE " + dev[1].ifname)
  720. subprocess.call(['iw', 'reg', 'set', '00'])
  721. dev[0].flush_scan_cache()
  722. dev[1].flush_scan_cache()
  723. def _test_wpas_mesh_open_vht_80p80(dev, apdev):
  724. check_mesh_support(dev[0])
  725. subprocess.call(['iw', 'reg', 'set', 'US'])
  726. for i in range(2):
  727. for j in range(5):
  728. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  729. if ev is None:
  730. raise Exception("No regdom change event")
  731. if "alpha2=US" in ev:
  732. break
  733. add_open_mesh_network(dev[i], freq="5180", chwidth=3)
  734. # Check for mesh joined
  735. check_mesh_group_added(dev[0])
  736. check_mesh_group_added(dev[1])
  737. # Check for peer connected
  738. check_mesh_peer_connected(dev[0])
  739. check_mesh_peer_connected(dev[1])
  740. # Test connectivity 0->1 and 1->0
  741. hwsim_utils.test_connectivity(dev[0], dev[1])
  742. sig = dev[0].request("SIGNAL_POLL").splitlines()
  743. if "WIDTH=80+80 MHz" not in sig:
  744. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  745. if "CENTER_FRQ1=5210" not in sig:
  746. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  747. if "CENTER_FRQ2=5775" not in sig:
  748. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  749. sig = dev[1].request("SIGNAL_POLL").splitlines()
  750. if "WIDTH=80+80 MHz" not in sig:
  751. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  752. if "CENTER_FRQ1=5210" not in sig:
  753. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  754. if "CENTER_FRQ2=5775" not in sig:
  755. raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
  756. dev[0].mesh_group_remove()
  757. dev[1].mesh_group_remove()
  758. check_mesh_group_removed(dev[0])
  759. check_mesh_group_removed(dev[1])
  760. dev[0].dump_monitor()
  761. dev[1].dump_monitor()
  762. def test_mesh_open_vht_160(dev, apdev):
  763. """Open mesh network on VHT 160 MHz channel"""
  764. try:
  765. _test_mesh_open_vht_160(dev, apdev)
  766. finally:
  767. dev[0].request("MESH_GROUP_REMOVE " + dev[0].ifname)
  768. dev[1].request("MESH_GROUP_REMOVE " + dev[1].ifname)
  769. subprocess.call(['iw', 'reg', 'set', '00'])
  770. dev[0].flush_scan_cache()
  771. dev[1].flush_scan_cache()
  772. def _test_mesh_open_vht_160(dev, apdev):
  773. check_mesh_support(dev[0])
  774. subprocess.call(['iw', 'reg', 'set', 'ZA'])
  775. for i in range(2):
  776. for j in range(5):
  777. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  778. if ev is None:
  779. raise Exception("No regdom change event")
  780. if "alpha2=ZA" in ev:
  781. break
  782. cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
  783. reg = cmd.stdout.read()
  784. found = False
  785. for entry in reg.splitlines():
  786. if "@ 160)" in entry and "DFS" not in entry:
  787. found = True
  788. break
  789. if not found:
  790. raise HwsimSkip("160 MHz channel without DFS not supported in regulatory information")
  791. add_open_mesh_network(dev[i], freq="5520", chwidth=2)
  792. # Check for mesh joined
  793. check_mesh_group_added(dev[0])
  794. check_mesh_group_added(dev[1])
  795. # Check for peer connected
  796. check_mesh_peer_connected(dev[0])
  797. check_mesh_peer_connected(dev[1])
  798. dev[0].dump_monitor()
  799. dev[1].dump_monitor()
  800. # Test connectivity 0->1 and 1->0
  801. hwsim_utils.test_connectivity(dev[0], dev[1])
  802. sig = dev[0].request("SIGNAL_POLL").splitlines()
  803. if "WIDTH=160 MHz" not in sig:
  804. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  805. if "FREQUENCY=5520" not in sig:
  806. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  807. sig = dev[1].request("SIGNAL_POLL").splitlines()
  808. if "WIDTH=160 MHz" not in sig:
  809. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  810. if "FREQUENCY=5520" not in sig:
  811. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  812. dev[0].mesh_group_remove()
  813. dev[1].mesh_group_remove()
  814. check_mesh_group_removed(dev[0])
  815. check_mesh_group_removed(dev[1])
  816. dev[0].dump_monitor()
  817. dev[1].dump_monitor()
  818. def test_wpas_mesh_password_mismatch(dev, apdev):
  819. """Mesh network and one device with mismatching password"""
  820. check_mesh_support(dev[0], secure=True)
  821. dev[0].request("SET sae_groups ")
  822. id = add_mesh_secure_net(dev[0])
  823. dev[0].mesh_group_add(id)
  824. dev[1].request("SET sae_groups ")
  825. id = add_mesh_secure_net(dev[1])
  826. dev[1].mesh_group_add(id)
  827. dev[2].request("SET sae_groups ")
  828. id = add_mesh_secure_net(dev[2])
  829. dev[2].set_network_quoted(id, "psk", "wrong password")
  830. dev[2].mesh_group_add(id)
  831. # The two peers with matching password need to be able to connect
  832. check_mesh_group_added(dev[0])
  833. check_mesh_group_added(dev[1])
  834. check_mesh_peer_connected(dev[0])
  835. check_mesh_peer_connected(dev[1])
  836. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  837. if ev is None:
  838. raise Exception("dev2 did not report auth failure (1)")
  839. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  840. if ev is None:
  841. raise Exception("dev2 did not report auth failure (2)")
  842. dev[2].dump_monitor()
  843. count = 0
  844. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=5)
  845. if ev is None:
  846. logger.info("dev0 did not report auth failure")
  847. else:
  848. if "addr=" + dev[2].own_addr() not in ev:
  849. raise Exception("Unexpected peer address in dev0 event: " + ev)
  850. count += 1
  851. dev[0].dump_monitor()
  852. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=5)
  853. if ev is None:
  854. logger.info("dev1 did not report auth failure")
  855. else:
  856. if "addr=" + dev[2].own_addr() not in ev:
  857. raise Exception("Unexpected peer address in dev1 event: " + ev)
  858. count += 1
  859. dev[1].dump_monitor()
  860. hwsim_utils.test_connectivity(dev[0], dev[1])
  861. for i in range(2):
  862. try:
  863. hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
  864. raise Exception("Data connectivity test passed unexpectedly")
  865. except Exception, e:
  866. if "data delivery failed" not in str(e):
  867. raise
  868. if count == 0:
  869. raise Exception("Neither dev0 nor dev1 reported auth failure")
  870. def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
  871. """Mesh password mismatch and retry [long]"""
  872. if not params['long']:
  873. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  874. check_mesh_support(dev[0], secure=True)
  875. dev[0].request("SET sae_groups ")
  876. id = add_mesh_secure_net(dev[0])
  877. dev[0].mesh_group_add(id)
  878. dev[1].request("SET sae_groups ")
  879. id = add_mesh_secure_net(dev[1])
  880. dev[1].set_network_quoted(id, "psk", "wrong password")
  881. dev[1].mesh_group_add(id)
  882. # Check for mesh joined
  883. check_mesh_group_added(dev[0])
  884. check_mesh_group_added(dev[1])
  885. for i in range(4):
  886. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  887. if ev is None:
  888. raise Exception("dev0 did not report auth failure (%d)" % i)
  889. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  890. if ev is None:
  891. raise Exception("dev1 did not report auth failure (%d)" % i)
  892. ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  893. if ev is None:
  894. raise Exception("dev0 did not report auth blocked")
  895. ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  896. if ev is None:
  897. raise Exception("dev1 did not report auth blocked")
  898. def test_mesh_wpa_auth_init_oom(dev, apdev):
  899. """Secure mesh network setup failing due to wpa_init() OOM"""
  900. check_mesh_support(dev[0], secure=True)
  901. dev[0].request("SET sae_groups ")
  902. with alloc_fail(dev[0], 1, "wpa_init"):
  903. id = add_mesh_secure_net(dev[0])
  904. dev[0].mesh_group_add(id)
  905. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
  906. if ev is not None:
  907. raise Exception("Unexpected mesh group start during OOM")
  908. def test_mesh_wpa_init_fail(dev, apdev):
  909. """Secure mesh network setup local failure"""
  910. check_mesh_support(dev[0], secure=True)
  911. dev[0].request("SET sae_groups ")
  912. with fail_test(dev[0], 1, "os_get_random;=__mesh_rsn_auth_init"):
  913. id = add_mesh_secure_net(dev[0])
  914. dev[0].mesh_group_add(id)
  915. wait_fail_trigger(dev[0], "GET_FAIL")
  916. dev[0].dump_monitor()
  917. with alloc_fail(dev[0], 1, "mesh_rsn_auth_init"):
  918. id = add_mesh_secure_net(dev[0])
  919. dev[0].mesh_group_add(id)
  920. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  921. dev[0].dump_monitor()
  922. with fail_test(dev[0], 1, "os_get_random;mesh_rsn_init_ampe_sta"):
  923. id = add_mesh_secure_net(dev[0])
  924. dev[0].mesh_group_add(id)
  925. dev[1].request("SET sae_groups ")
  926. id = add_mesh_secure_net(dev[1])
  927. dev[1].mesh_group_add(id)
  928. wait_fail_trigger(dev[0], "GET_FAIL")
  929. def test_wpas_mesh_reconnect(dev, apdev):
  930. """Secure mesh network plink counting during reconnection"""
  931. check_mesh_support(dev[0])
  932. try:
  933. _test_wpas_mesh_reconnect(dev)
  934. finally:
  935. dev[0].request("SET max_peer_links 99")
  936. def _test_wpas_mesh_reconnect(dev):
  937. dev[0].request("SET max_peer_links 2")
  938. dev[0].request("SET sae_groups ")
  939. id = add_mesh_secure_net(dev[0])
  940. dev[0].set_network(id, "beacon_int", "100")
  941. dev[0].mesh_group_add(id)
  942. dev[1].request("SET sae_groups ")
  943. id = add_mesh_secure_net(dev[1])
  944. dev[1].mesh_group_add(id)
  945. check_mesh_group_added(dev[0])
  946. check_mesh_group_added(dev[1])
  947. check_mesh_peer_connected(dev[0])
  948. check_mesh_peer_connected(dev[1])
  949. for i in range(3):
  950. # Drop incoming management frames to avoid handling link close
  951. dev[0].request("SET ext_mgmt_frame_handling 1")
  952. dev[1].mesh_group_remove()
  953. check_mesh_group_removed(dev[1])
  954. dev[1].request("FLUSH")
  955. dev[0].request("SET ext_mgmt_frame_handling 0")
  956. id = add_mesh_secure_net(dev[1])
  957. dev[1].mesh_group_add(id)
  958. check_mesh_group_added(dev[1])
  959. check_mesh_peer_connected(dev[1])
  960. dev[0].dump_monitor()
  961. dev[1].dump_monitor()
  962. def test_wpas_mesh_gate_forwarding(dev, apdev, p):
  963. """Mesh forwards traffic to unknown sta to mesh gates"""
  964. addr0 = dev[0].own_addr()
  965. addr1 = dev[1].own_addr()
  966. addr2 = dev[2].own_addr()
  967. external_sta = '02:11:22:33:44:55'
  968. # start 3 node connected mesh
  969. check_mesh_support(dev[0])
  970. for i in range(3):
  971. add_open_mesh_network(dev[i])
  972. check_mesh_group_added(dev[i])
  973. for i in range(3):
  974. check_mesh_peer_connected(dev[i])
  975. hwsim_utils.test_connectivity(dev[0], dev[1])
  976. hwsim_utils.test_connectivity(dev[1], dev[2])
  977. hwsim_utils.test_connectivity(dev[0], dev[2])
  978. # dev0 and dev1 are mesh gates
  979. subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
  980. 'mesh_gate_announcements=1'])
  981. subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
  982. 'mesh_gate_announcements=1'])
  983. # wait for gate announcement frames
  984. time.sleep(1)
  985. # data frame from dev2 -> external sta should be sent to both gates
  986. dev[2].request("DATA_TEST_CONFIG 1")
  987. dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
  988. dev[2].request("DATA_TEST_CONFIG 0")
  989. capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
  990. filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
  991. external_sta)
  992. for i in range(15):
  993. da = run_tshark(capfile, filt, [ "wlan.da" ])
  994. if addr0 in da and addr1 in da:
  995. logger.debug("Frames seen in tshark iteration %d" % i)
  996. break
  997. time.sleep(0.3)
  998. if addr0 not in da:
  999. raise Exception("Frame to gate %s not observed" % addr0)
  1000. if addr1 not in da:
  1001. raise Exception("Frame to gate %s not observed" % addr1)
  1002. def test_wpas_mesh_pmksa_caching(dev, apdev):
  1003. """Secure mesh network and PMKSA caching"""
  1004. check_mesh_support(dev[0], secure=True)
  1005. dev[0].request("SET sae_groups ")
  1006. id = add_mesh_secure_net(dev[0])
  1007. dev[0].mesh_group_add(id)
  1008. dev[1].request("SET sae_groups ")
  1009. id = add_mesh_secure_net(dev[1])
  1010. dev[1].mesh_group_add(id)
  1011. # Check for mesh joined
  1012. check_mesh_group_added(dev[0])
  1013. check_mesh_group_added(dev[1])
  1014. # Check for peer connected
  1015. check_mesh_peer_connected(dev[0])
  1016. check_mesh_peer_connected(dev[1])
  1017. addr0 = dev[0].own_addr()
  1018. addr1 = dev[1].own_addr()
  1019. pmksa0 = dev[0].get_pmksa(addr1)
  1020. pmksa1 = dev[1].get_pmksa(addr0)
  1021. if pmksa0 is None or pmksa1 is None:
  1022. raise Exception("No PMKSA cache entry created")
  1023. if pmksa0['pmkid'] != pmksa1['pmkid']:
  1024. raise Exception("PMKID mismatch in PMKSA cache entries")
  1025. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1026. raise Exception("Failed to remove peer")
  1027. pmksa0b = dev[0].get_pmksa(addr1)
  1028. if pmksa0b is None:
  1029. raise Exception("PMKSA cache entry not maintained")
  1030. time.sleep(0.1)
  1031. if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1032. raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
  1033. def test_wpas_mesh_pmksa_caching2(dev, apdev):
  1034. """Secure mesh network and PMKSA caching with no_auto_peer=1"""
  1035. check_mesh_support(dev[0], secure=True)
  1036. addr0 = dev[0].own_addr()
  1037. addr1 = dev[1].own_addr()
  1038. dev[0].request("SET sae_groups ")
  1039. id = add_mesh_secure_net(dev[0])
  1040. dev[0].set_network(id, "no_auto_peer", "1")
  1041. dev[0].mesh_group_add(id)
  1042. dev[1].request("SET sae_groups ")
  1043. id = add_mesh_secure_net(dev[1])
  1044. dev[1].set_network(id, "no_auto_peer", "1")
  1045. dev[1].mesh_group_add(id)
  1046. # Check for mesh joined
  1047. check_mesh_group_added(dev[0])
  1048. check_mesh_group_added(dev[1])
  1049. # Check for peer connected
  1050. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1051. if ev is None:
  1052. raise Exception("Missing no-initiate message")
  1053. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1054. raise Exception("MESH_PEER_ADD failed")
  1055. check_mesh_peer_connected(dev[0])
  1056. check_mesh_peer_connected(dev[1])
  1057. pmksa0 = dev[0].get_pmksa(addr1)
  1058. pmksa1 = dev[1].get_pmksa(addr0)
  1059. if pmksa0 is None or pmksa1 is None:
  1060. raise Exception("No PMKSA cache entry created")
  1061. if pmksa0['pmkid'] != pmksa1['pmkid']:
  1062. raise Exception("PMKID mismatch in PMKSA cache entries")
  1063. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1064. raise Exception("Failed to remove peer")
  1065. pmksa0b = dev[0].get_pmksa(addr1)
  1066. if pmksa0b is None:
  1067. raise Exception("PMKSA cache entry not maintained")
  1068. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1069. if ev is None:
  1070. raise Exception("Missing no-initiate message (2)")
  1071. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1072. raise Exception("MESH_PEER_ADD failed (2)")
  1073. check_mesh_peer_connected(dev[0])
  1074. check_mesh_peer_connected(dev[1])
  1075. pmksa0c = dev[0].get_pmksa(addr1)
  1076. pmksa1c = dev[1].get_pmksa(addr0)
  1077. if pmksa0c is None or pmksa1c is None:
  1078. raise Exception("No PMKSA cache entry created (2)")
  1079. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  1080. raise Exception("PMKID mismatch in PMKSA cache entries")
  1081. if pmksa0['pmkid'] != pmksa0c['pmkid']:
  1082. raise Exception("PMKID changed")
  1083. hwsim_utils.test_connectivity(dev[0], dev[1])
  1084. def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
  1085. """Secure mesh network and PMKSA caching with no PMKID match"""
  1086. check_mesh_support(dev[0], secure=True)
  1087. addr0 = dev[0].own_addr()
  1088. addr1 = dev[1].own_addr()
  1089. dev[0].request("SET sae_groups ")
  1090. id = add_mesh_secure_net(dev[0])
  1091. dev[0].set_network(id, "no_auto_peer", "1")
  1092. dev[0].mesh_group_add(id)
  1093. dev[1].request("SET sae_groups ")
  1094. id = add_mesh_secure_net(dev[1])
  1095. dev[1].set_network(id, "no_auto_peer", "1")
  1096. dev[1].mesh_group_add(id)
  1097. # Check for mesh joined
  1098. check_mesh_group_added(dev[0])
  1099. check_mesh_group_added(dev[1])
  1100. # Check for peer connected
  1101. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1102. if ev is None:
  1103. raise Exception("Missing no-initiate message")
  1104. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1105. raise Exception("MESH_PEER_ADD failed")
  1106. check_mesh_peer_connected(dev[0])
  1107. check_mesh_peer_connected(dev[1])
  1108. pmksa0 = dev[0].get_pmksa(addr1)
  1109. pmksa1 = dev[1].get_pmksa(addr0)
  1110. if pmksa0 is None or pmksa1 is None:
  1111. raise Exception("No PMKSA cache entry created")
  1112. if pmksa0['pmkid'] != pmksa1['pmkid']:
  1113. raise Exception("PMKID mismatch in PMKSA cache entries")
  1114. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1115. raise Exception("Failed to remove peer")
  1116. if "OK" not in dev[1].request("PMKSA_FLUSH"):
  1117. raise Exception("Failed to flush PMKSA cache")
  1118. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1119. if ev is None:
  1120. raise Exception("Missing no-initiate message (2)")
  1121. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1122. raise Exception("MESH_PEER_ADD failed (2)")
  1123. check_mesh_peer_connected(dev[0])
  1124. check_mesh_peer_connected(dev[1])
  1125. pmksa0c = dev[0].get_pmksa(addr1)
  1126. pmksa1c = dev[1].get_pmksa(addr0)
  1127. if pmksa0c is None or pmksa1c is None:
  1128. raise Exception("No PMKSA cache entry created (2)")
  1129. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  1130. raise Exception("PMKID mismatch in PMKSA cache entries")
  1131. if pmksa0['pmkid'] == pmksa0c['pmkid']:
  1132. raise Exception("PMKID did not change")
  1133. hwsim_utils.test_connectivity(dev[0], dev[1])
  1134. def test_mesh_pmksa_caching_oom(dev, apdev):
  1135. """Secure mesh network and PMKSA caching failing due to OOM"""
  1136. check_mesh_support(dev[0], secure=True)
  1137. addr0 = dev[0].own_addr()
  1138. addr1 = dev[1].own_addr()
  1139. dev[0].request("SET sae_groups ")
  1140. id = add_mesh_secure_net(dev[0])
  1141. dev[0].set_network(id, "no_auto_peer", "1")
  1142. dev[0].mesh_group_add(id)
  1143. dev[1].request("SET sae_groups ")
  1144. id = add_mesh_secure_net(dev[1])
  1145. dev[1].set_network(id, "no_auto_peer", "1")
  1146. dev[1].mesh_group_add(id)
  1147. # Check for mesh joined
  1148. check_mesh_group_added(dev[0])
  1149. check_mesh_group_added(dev[1])
  1150. # Check for peer connected
  1151. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1152. if ev is None:
  1153. raise Exception("Missing no-initiate message")
  1154. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1155. raise Exception("MESH_PEER_ADD failed")
  1156. check_mesh_peer_connected(dev[0])
  1157. check_mesh_peer_connected(dev[1])
  1158. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1159. raise Exception("Failed to remove peer")
  1160. pmksa0b = dev[0].get_pmksa(addr1)
  1161. if pmksa0b is None:
  1162. raise Exception("PMKSA cache entry not maintained")
  1163. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1164. if ev is None:
  1165. raise Exception("Missing no-initiate message (2)")
  1166. with alloc_fail(dev[0], 1, "wpa_auth_sta_init;mesh_rsn_auth_sae_sta"):
  1167. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1168. raise Exception("MESH_PEER_ADD failed (2)")
  1169. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1170. def test_wpas_mesh_pmksa_caching_ext(dev, apdev):
  1171. """Secure mesh network and PMKSA caching and external storage"""
  1172. check_mesh_support(dev[0], secure=True)
  1173. dev[0].request("SET sae_groups ")
  1174. id = add_mesh_secure_net(dev[0])
  1175. dev[0].mesh_group_add(id)
  1176. dev[1].request("SET sae_groups ")
  1177. id = add_mesh_secure_net(dev[1])
  1178. dev[1].mesh_group_add(id)
  1179. # Check for mesh joined
  1180. check_mesh_group_added(dev[0])
  1181. check_mesh_group_added(dev[1])
  1182. # Check for peer connected
  1183. check_mesh_peer_connected(dev[0])
  1184. check_mesh_peer_connected(dev[1])
  1185. dev[0].dump_monitor()
  1186. dev[1].dump_monitor()
  1187. addr0 = dev[0].own_addr()
  1188. addr1 = dev[1].own_addr()
  1189. pmksa0 = dev[0].get_pmksa(addr1)
  1190. pmksa1 = dev[1].get_pmksa(addr0)
  1191. if pmksa0 is None or pmksa1 is None:
  1192. raise Exception("No PMKSA cache entry created")
  1193. if pmksa0['pmkid'] != pmksa1['pmkid']:
  1194. raise Exception("PMKID mismatch in PMKSA cache entries")
  1195. res1 = dev[1].request("MESH_PMKSA_GET any")
  1196. res2 = dev[1].request("MESH_PMKSA_GET " + addr0)
  1197. logger.info("MESH_PMKSA_GET: " + res1)
  1198. if "UNKNOWN COMMAND" in res1:
  1199. raise HwsimSkip("MESH_PMKSA_GET not supported in the build")
  1200. logger.info("MESH_PMKSA_GET: " + res2)
  1201. if pmksa0['pmkid'] not in res1:
  1202. raise Exception("PMKID not included in PMKSA entry")
  1203. if res1 != res2:
  1204. raise Exception("Unexpected difference in MESH_PMKSA_GET output")
  1205. dev[1].mesh_group_remove()
  1206. check_mesh_group_removed(dev[1])
  1207. dev[0].dump_monitor()
  1208. dev[1].dump_monitor()
  1209. res = dev[1].get_pmksa(addr0)
  1210. if res is not None:
  1211. raise Exception("Unexpected PMKSA cache entry remaining")
  1212. if "OK" not in dev[1].request("MESH_PMKSA_ADD " + res2):
  1213. raise Exception("MESH_PMKSA_ADD failed")
  1214. dev[1].mesh_group_add(id)
  1215. check_mesh_group_added(dev[1])
  1216. check_mesh_peer_connected(dev[1])
  1217. dev[0].dump_monitor()
  1218. dev[1].dump_monitor()
  1219. pmksa1b = dev[1].get_pmksa(addr0)
  1220. if pmksa1b is None:
  1221. raise Exception("No PMKSA cache entry created after external storage restore")
  1222. if pmksa1['pmkid'] != pmksa1b['pmkid']:
  1223. raise Exception("PMKID mismatch in PMKSA cache entries after external storage restore")
  1224. hwsim_utils.test_connectivity(dev[0], dev[1])
  1225. res = dev[1].request("MESH_PMKSA_GET foo")
  1226. if "FAIL" not in res:
  1227. raise Exception("Invalid MESH_PMKSA_GET accepted")
  1228. dev[1].mesh_group_remove()
  1229. check_mesh_group_removed(dev[1])
  1230. dev[0].dump_monitor()
  1231. dev[1].dump_monitor()
  1232. dev[1].request("REMOVE_NETWORK all")
  1233. res = dev[1].request("MESH_PMKSA_GET any")
  1234. if "FAIL" not in res:
  1235. raise Exception("MESH_PMKSA_GET accepted when not in mesh")
  1236. tests = [ "foo",
  1237. "02:02:02:02:02:02",
  1238. "02:02:02:02:02:02 q",
  1239. "02:02:02:02:02:02 c3d51a7ccfca0c6d5287291a7169d79b",
  1240. "02:02:02:02:02:02 c3d51a7ccfca0c6d5287291a7169d79b q",
  1241. "02:02:02:02:02:02 c3d51a7ccfca0c6d5287291a7169d79b 1bed4fa22ece7997ca1bdc8b829019fe63acac91cba3405522c24c91f7cfb49f",
  1242. "02:02:02:02:02:02 c3d51a7ccfca0c6d5287291a7169d79b 1bed4fa22ece7997ca1bdc8b829019fe63acac91cba3405522c24c91f7cfb49f q" ]
  1243. for t in tests:
  1244. if "FAIL" not in dev[1].request("MESH_PMKSA_ADD " + t):
  1245. raise Exception("Invalid MESH_PMKSA_ADD accepted")
  1246. def test_mesh_oom(dev, apdev):
  1247. """Mesh network setup failing due to OOM"""
  1248. check_mesh_support(dev[0], secure=True)
  1249. dev[0].request("SET sae_groups ")
  1250. with alloc_fail(dev[0], 1, "mesh_config_create"):
  1251. add_open_mesh_network(dev[0])
  1252. ev = dev[0].wait_event(["Failed to init mesh"])
  1253. if ev is None:
  1254. raise Exception("Init failure not reported")
  1255. with alloc_fail(dev[0], 4, "=wpa_supplicant_mesh_init"):
  1256. add_open_mesh_network(dev[0], basic_rates="60 120 240")
  1257. ev = dev[0].wait_event(["Failed to init mesh"])
  1258. if ev is None:
  1259. raise Exception("Init failure not reported")
  1260. for i in range(1, 66):
  1261. dev[0].dump_monitor()
  1262. logger.info("Test instance %d" % i)
  1263. try:
  1264. with alloc_fail(dev[0], i, "wpa_supplicant_mesh_init"):
  1265. add_open_mesh_network(dev[0])
  1266. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1267. ev = dev[0].wait_event(["Failed to init mesh",
  1268. "MESH-GROUP-STARTED"])
  1269. if ev is None:
  1270. raise Exception("Init failure not reported")
  1271. except Exception, e:
  1272. if i < 15:
  1273. raise
  1274. logger.info("Ignore no-oom for i=%d" % i)
  1275. with alloc_fail(dev[0], 5, "=wpa_supplicant_mesh_init"):
  1276. id = add_mesh_secure_net(dev[0])
  1277. dev[0].mesh_group_add(id)
  1278. ev = dev[0].wait_event(["Failed to init mesh"])
  1279. if ev is None:
  1280. raise Exception("Init failure not reported")
  1281. def test_mesh_add_interface_oom(dev):
  1282. """wpa_supplicant mesh with dynamic interface addition failing"""
  1283. check_mesh_support(dev[0])
  1284. for i in range(1, 3):
  1285. mesh = None
  1286. try:
  1287. with alloc_fail(dev[0], i, "wpas_mesh_add_interface"):
  1288. mesh = dev[0].request("MESH_INTERFACE_ADD").strip()
  1289. finally:
  1290. if mesh and mesh != "FAIL":
  1291. dev[0].request("MESH_GROUP_REMOVE " + mesh)
  1292. def test_mesh_scan_oom(dev):
  1293. """wpa_supplicant mesh scan results and OOM"""
  1294. check_mesh_support(dev[0])
  1295. add_open_mesh_network(dev[0])
  1296. check_mesh_group_added(dev[0])
  1297. for i in range(5):
  1298. dev[1].scan(freq="2412")
  1299. res = dev[1].request("SCAN_RESULTS")
  1300. if "[MESH]" in res:
  1301. break
  1302. for r in res.splitlines():
  1303. if "[MESH]" in r:
  1304. break
  1305. bssid = r.split('\t')[0]
  1306. bss = dev[1].get_bss(bssid)
  1307. if bss is None:
  1308. raise Exception("Could not get BSS entry for mesh")
  1309. for i in range(1, 3):
  1310. with alloc_fail(dev[1], i, "mesh_attr_text"):
  1311. bss = dev[1].get_bss(bssid)
  1312. if bss and "mesh_id" in bss:
  1313. raise Exception("Unexpected BSS result during OOM")
  1314. def test_mesh_drv_fail(dev, apdev):
  1315. """Mesh network setup failing due to driver command failure"""
  1316. check_mesh_support(dev[0], secure=True)
  1317. dev[0].request("SET sae_groups ")
  1318. with fail_test(dev[0], 1, "nl80211_join_mesh"):
  1319. add_open_mesh_network(dev[0])
  1320. ev = dev[0].wait_event(["mesh join error"])
  1321. if ev is None:
  1322. raise Exception("Join failure not reported")
  1323. dev[0].dump_monitor()
  1324. with fail_test(dev[0], 1, "wpa_driver_nl80211_if_add"):
  1325. if "FAIL" not in dev[0].request("MESH_INTERFACE_ADD").strip():
  1326. raise Exception("Interface added unexpectedly")
  1327. dev[0].dump_monitor()
  1328. with fail_test(dev[0], 1, "wpa_driver_nl80211_init_mesh"):
  1329. add_open_mesh_network(dev[0])
  1330. ev = dev[0].wait_event(["Could not join mesh"])
  1331. if ev is None:
  1332. raise Exception("Join failure not reported")
  1333. def test_mesh_sae_groups_invalid(dev, apdev):
  1334. """Mesh with invalid SAE group configuration"""
  1335. check_mesh_support(dev[0], secure=True)
  1336. dev[0].request("SET sae_groups 25")
  1337. id = add_mesh_secure_net(dev[0])
  1338. dev[0].mesh_group_add(id)
  1339. dev[1].request("SET sae_groups 123 122 121")
  1340. id = add_mesh_secure_net(dev[1])
  1341. dev[1].mesh_group_add(id)
  1342. check_mesh_group_added(dev[0])
  1343. check_mesh_group_added(dev[1])
  1344. ev = dev[0].wait_event(["new peer notification"], timeout=10)
  1345. if ev is None:
  1346. raise Exception("dev[0] did not see peer")
  1347. ev = dev[1].wait_event(["new peer notification"], timeout=10)
  1348. if ev is None:
  1349. raise Exception("dev[1] did not see peer")
  1350. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  1351. if ev is not None:
  1352. raise Exception("Unexpected connection(0)")
  1353. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1354. if ev is not None:
  1355. raise Exception("Unexpected connection(1)")
  1356. # Additional coverage in mesh_rsn_sae_group() with non-zero
  1357. # wpa_s->mesh_rsn->sae_group_index.
  1358. dev[0].dump_monitor()
  1359. dev[1].dump_monitor()
  1360. id = add_mesh_secure_net(dev[2])
  1361. dev[2].mesh_group_add(id)
  1362. check_mesh_group_added(dev[2])
  1363. check_mesh_peer_connected(dev[0])
  1364. check_mesh_peer_connected(dev[2])
  1365. ev = dev[1].wait_event(["new peer notification"], timeout=10)
  1366. if ev is None:
  1367. raise Exception("dev[1] did not see peer(2)")
  1368. dev[0].dump_monitor()
  1369. dev[1].dump_monitor()
  1370. dev[2].dump_monitor()
  1371. dev[0].request("SET sae_groups ")
  1372. dev[1].request("SET sae_groups ")
  1373. def test_mesh_sae_failure(dev, apdev):
  1374. """Mesh and local SAE failures"""
  1375. check_mesh_support(dev[0], secure=True)
  1376. dev[0].request("SET sae_groups ")
  1377. dev[1].request("SET sae_groups ")
  1378. funcs = [ (1, "=mesh_rsn_auth_sae_sta", True),
  1379. (1, "mesh_rsn_build_sae_commit;mesh_rsn_auth_sae_sta", False),
  1380. (1, "auth_sae_init_committed;mesh_rsn_auth_sae_sta", True),
  1381. (1, "=mesh_rsn_protect_frame", True),
  1382. (2, "=mesh_rsn_protect_frame", True),
  1383. (1, "aes_siv_encrypt;mesh_rsn_protect_frame", True),
  1384. (1, "=mesh_rsn_process_ampe", True),
  1385. (1, "aes_siv_decrypt;mesh_rsn_process_ampe", True) ]
  1386. for count, func, success in funcs:
  1387. id = add_mesh_secure_net(dev[0])
  1388. dev[0].mesh_group_add(id)
  1389. with alloc_fail(dev[1], count, func):
  1390. id = add_mesh_secure_net(dev[1])
  1391. dev[1].mesh_group_add(id)
  1392. check_mesh_group_added(dev[0])
  1393. check_mesh_group_added(dev[1])
  1394. if success:
  1395. # retry is expected to work
  1396. check_mesh_peer_connected(dev[0])
  1397. check_mesh_peer_connected(dev[1])
  1398. else:
  1399. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  1400. dev[0].mesh_group_remove()
  1401. dev[1].mesh_group_remove()
  1402. check_mesh_group_removed(dev[0])
  1403. check_mesh_group_removed(dev[1])
  1404. def test_mesh_failure(dev, apdev):
  1405. """Mesh and local failures"""
  1406. check_mesh_support(dev[0])
  1407. funcs = [ (1, "ap_sta_add;mesh_mpm_add_peer", True),
  1408. (1, "wpabuf_alloc;mesh_mpm_send_plink_action", True) ]
  1409. for count, func, success in funcs:
  1410. add_open_mesh_network(dev[0])
  1411. with alloc_fail(dev[1], count, func):
  1412. add_open_mesh_network(dev[1])
  1413. check_mesh_group_added(dev[0])
  1414. check_mesh_group_added(dev[1])
  1415. if success:
  1416. # retry is expected to work
  1417. check_mesh_peer_connected(dev[0])
  1418. check_mesh_peer_connected(dev[1])
  1419. else:
  1420. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  1421. dev[0].mesh_group_remove()
  1422. dev[1].mesh_group_remove()
  1423. check_mesh_group_removed(dev[0])
  1424. check_mesh_group_removed(dev[1])
  1425. funcs = [ (1, "mesh_mpm_init_link", True) ]
  1426. for count, func, success in funcs:
  1427. add_open_mesh_network(dev[0])
  1428. with fail_test(dev[1], count, func):
  1429. add_open_mesh_network(dev[1])
  1430. check_mesh_group_added(dev[0])
  1431. check_mesh_group_added(dev[1])
  1432. if success:
  1433. # retry is expected to work
  1434. check_mesh_peer_connected(dev[0])
  1435. check_mesh_peer_connected(dev[1])
  1436. else:
  1437. wait_fail_trigger(dev[1], "GET_FAIL")
  1438. dev[0].mesh_group_remove()
  1439. dev[1].mesh_group_remove()
  1440. check_mesh_group_removed(dev[0])
  1441. check_mesh_group_removed(dev[1])
  1442. def test_mesh_invalid_frequency(dev, apdev):
  1443. """Mesh and invalid frequency configuration"""
  1444. check_mesh_support(dev[0])
  1445. add_open_mesh_network(dev[0], freq=None)
  1446. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  1447. "Could not join mesh"])
  1448. if ev is None or "Could not join mesh" not in ev:
  1449. raise Exception("Mesh join failure not reported")
  1450. dev[0].request("REMOVE_NETWORK all")
  1451. add_open_mesh_network(dev[0], freq="2413")
  1452. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  1453. "Could not join mesh"])
  1454. if ev is None or "Could not join mesh" not in ev:
  1455. raise Exception("Mesh join failure not reported")
  1456. def test_mesh_default_beacon_int(dev, apdev):
  1457. """Mesh and default beacon interval"""
  1458. check_mesh_support(dev[0])
  1459. try:
  1460. dev[0].request("SET beacon_int 200")
  1461. add_open_mesh_network(dev[0])
  1462. check_mesh_group_added(dev[0])
  1463. finally:
  1464. dev[0].request("SET beacon_int 0")
  1465. def test_mesh_scan_parse_error(dev, apdev):
  1466. """Mesh scan element parse error"""
  1467. check_mesh_support(dev[0])
  1468. params = { "ssid": "open",
  1469. "beacon_int": "2000" }
  1470. hapd = hostapd.add_ap(apdev[0], params)
  1471. bssid = apdev[0]['bssid']
  1472. hapd.set('vendor_elements', 'dd0201')
  1473. for i in range(10):
  1474. dev[0].scan(freq=2412)
  1475. if bssid in dev[0].request("SCAN_RESULTS"):
  1476. break
  1477. # This will fail in IE parsing due to the truncated IE in the Probe
  1478. # Response frame.
  1479. bss = dev[0].request("BSS " + bssid)
  1480. def test_mesh_missing_mic(dev, apdev):
  1481. """Secure mesh network and missing MIC"""
  1482. check_mesh_support(dev[0], secure=True)
  1483. dev[0].request("SET ext_mgmt_frame_handling 1")
  1484. dev[0].request("SET sae_groups ")
  1485. id = add_mesh_secure_net(dev[0])
  1486. dev[0].mesh_group_add(id)
  1487. dev[1].request("SET sae_groups ")
  1488. id = add_mesh_secure_net(dev[1])
  1489. dev[1].mesh_group_add(id)
  1490. # Check for mesh joined
  1491. check_mesh_group_added(dev[0])
  1492. check_mesh_group_added(dev[1])
  1493. count = 0
  1494. remove_mic = True
  1495. while True:
  1496. count += 1
  1497. if count > 15:
  1498. raise Exception("Did not see Action frames")
  1499. rx_msg = dev[0].mgmt_rx()
  1500. if rx_msg is None:
  1501. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1502. if ev:
  1503. break
  1504. raise Exception("MGMT-RX timeout")
  1505. if rx_msg['subtype'] == 13:
  1506. payload = rx_msg['payload']
  1507. frame = rx_msg['frame']
  1508. (categ, action) = struct.unpack('BB', payload[0:2])
  1509. if categ == 15 and action == 1 and remove_mic:
  1510. # Mesh Peering Open
  1511. pos = frame.find('\x8c\x10')
  1512. if not pos:
  1513. raise Exception("Could not find MIC element")
  1514. logger.info("Found MIC at %d" % pos)
  1515. # Remove MIC
  1516. rx_msg['frame'] = frame[0:pos]
  1517. remove_mic = False
  1518. 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'))):
  1519. raise Exception("MGMT_RX_PROCESS failed")
  1520. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1521. if ev:
  1522. break
  1523. def test_mesh_pmkid_mismatch(dev, apdev):
  1524. """Secure mesh network and PMKID mismatch"""
  1525. check_mesh_support(dev[0], secure=True)
  1526. addr0 = dev[0].own_addr()
  1527. addr1 = dev[1].own_addr()
  1528. dev[0].request("SET sae_groups ")
  1529. id = add_mesh_secure_net(dev[0])
  1530. dev[0].set_network(id, "no_auto_peer", "1")
  1531. dev[0].mesh_group_add(id)
  1532. dev[1].request("SET sae_groups ")
  1533. id = add_mesh_secure_net(dev[1])
  1534. dev[1].set_network(id, "no_auto_peer", "1")
  1535. dev[1].mesh_group_add(id)
  1536. # Check for mesh joined
  1537. check_mesh_group_added(dev[0])
  1538. check_mesh_group_added(dev[1])
  1539. # Check for peer connected
  1540. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1541. if ev is None:
  1542. raise Exception("Missing no-initiate message")
  1543. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1544. raise Exception("MESH_PEER_ADD failed")
  1545. check_mesh_peer_connected(dev[0])
  1546. check_mesh_peer_connected(dev[1])
  1547. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1548. raise Exception("Failed to remove peer")
  1549. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1550. if ev is None:
  1551. raise Exception("Missing no-initiate message (2)")
  1552. dev[0].dump_monitor()
  1553. dev[1].dump_monitor()
  1554. dev[0].request("SET ext_mgmt_frame_handling 1")
  1555. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1556. raise Exception("MESH_PEER_ADD failed (2)")
  1557. count = 0
  1558. break_pmkid = True
  1559. while True:
  1560. count += 1
  1561. if count > 50:
  1562. raise Exception("Did not see Action frames")
  1563. rx_msg = dev[0].mgmt_rx()
  1564. if rx_msg is None:
  1565. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  1566. if ev:
  1567. break
  1568. raise Exception("MGMT-RX timeout")
  1569. if rx_msg['subtype'] == 13:
  1570. payload = rx_msg['payload']
  1571. frame = rx_msg['frame']
  1572. (categ, action) = struct.unpack('BB', payload[0:2])
  1573. if categ == 15 and action == 1 and break_pmkid:
  1574. # Mesh Peering Open
  1575. pos = frame.find('\x75\x14')
  1576. if not pos:
  1577. raise Exception("Could not find Mesh Peering Management element")
  1578. logger.info("Found Mesh Peering Management element at %d" % pos)
  1579. # Break PMKID to hit "Mesh RSN: Invalid PMKID (Chosen PMK did
  1580. # not match calculated PMKID)"
  1581. rx_msg['frame'] = frame[0:pos + 6] + '\x00\x00\x00\x00' + frame[pos + 10:]
  1582. break_pmkid = False
  1583. 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'))):
  1584. raise Exception("MGMT_RX_PROCESS failed")
  1585. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1586. if ev:
  1587. break
  1588. def test_mesh_peering_proto(dev, apdev):
  1589. """Mesh peering management protocol testing"""
  1590. check_mesh_support(dev[0])
  1591. dev[0].request("SET ext_mgmt_frame_handling 1")
  1592. add_open_mesh_network(dev[0], beacon_int=160)
  1593. add_open_mesh_network(dev[1], beacon_int=160)
  1594. count = 0
  1595. test = 1
  1596. while True:
  1597. count += 1
  1598. if count > 50:
  1599. raise Exception("Did not see Action frames")
  1600. rx_msg = dev[0].mgmt_rx()
  1601. if rx_msg is None:
  1602. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1603. if ev:
  1604. break
  1605. raise Exception("MGMT-RX timeout")
  1606. if rx_msg['subtype'] == 13:
  1607. payload = rx_msg['payload']
  1608. frame = rx_msg['frame']
  1609. (categ, action) = struct.unpack('BB', payload[0:2])
  1610. if categ == 15 and action == 1 and test == 1:
  1611. # Mesh Peering Open
  1612. pos = frame.find('\x75\x04')
  1613. if not pos:
  1614. raise Exception("Could not find Mesh Peering Management element")
  1615. logger.info("Found Mesh Peering Management element at %d" % pos)
  1616. # Remove the element to hit
  1617. # "MPM: No Mesh Peering Management element"
  1618. rx_msg['frame'] = frame[0:pos]
  1619. test += 1
  1620. elif categ == 15 and action == 1 and test == 2:
  1621. # Mesh Peering Open
  1622. pos = frame.find('\x72\x0e')
  1623. if not pos:
  1624. raise Exception("Could not find Mesh ID element")
  1625. logger.info("Found Mesh ID element at %d" % pos)
  1626. # Remove the element to hit
  1627. # "MPM: No Mesh ID or Mesh Configuration element"
  1628. rx_msg['frame'] = frame[0:pos] + frame[pos + 16:]
  1629. test += 1
  1630. elif categ == 15 and action == 1 and test == 3:
  1631. # Mesh Peering Open
  1632. pos = frame.find('\x72\x0e')
  1633. if not pos:
  1634. raise Exception("Could not find Mesh ID element")
  1635. logger.info("Found Mesh ID element at %d" % pos)
  1636. # Replace Mesh ID to hit "MPM: Mesh ID or Mesh Configuration
  1637. # element do not match local MBSS"
  1638. rx_msg['frame'] = frame[0:pos] + '\x72\x0etest-test-test' + frame[pos + 16:]
  1639. test += 1
  1640. elif categ == 15 and action == 1 and test == 4:
  1641. # Mesh Peering Open
  1642. # Remove IEs to hit
  1643. # "MPM: Ignore too short action frame 1 ie_len 0"
  1644. rx_msg['frame'] = frame[0:26]
  1645. test += 1
  1646. elif categ == 15 and action == 1 and test == 5:
  1647. # Mesh Peering Open
  1648. # Truncate IEs to hit
  1649. # "MPM: Failed to parse PLINK IEs"
  1650. rx_msg['frame'] = frame[0:30]
  1651. test += 1
  1652. elif categ == 15 and action == 1 and test == 6:
  1653. # Mesh Peering Open
  1654. pos = frame.find('\x75\x04')
  1655. if not pos:
  1656. raise Exception("Could not find Mesh Peering Management element")
  1657. logger.info("Found Mesh Peering Management element at %d" % pos)
  1658. # Truncate the element to hit
  1659. # "MPM: Invalid peer mgmt ie" and
  1660. # "MPM: Mesh parsing rejected frame"
  1661. rx_msg['frame'] = frame[0:pos] + '\x75\x00\x00\x00' + frame[pos + 6:]
  1662. test += 1
  1663. 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'))):
  1664. raise Exception("MGMT_RX_PROCESS failed")
  1665. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1666. if ev:
  1667. break
  1668. if test != 7:
  1669. raise Exception("Not all test frames completed")
  1670. def test_mesh_mpm_init_proto(dev, apdev):
  1671. """Mesh peering management protocol testing for peer addition"""
  1672. check_mesh_support(dev[0])
  1673. add_open_mesh_network(dev[0])
  1674. check_mesh_group_added(dev[0])
  1675. dev[0].dump_monitor()
  1676. dev[0].request("SET ext_mgmt_frame_handling 1")
  1677. addr = "020000000100"
  1678. hdr = "d000ac00020000000000" + addr + addr + "1000"
  1679. fixed = "0f010000"
  1680. supp_rates = "010802040b168c129824"
  1681. ext_supp_rates = "3204b048606c"
  1682. mesh_id = "720e777061732d6d6573682d6f70656e"
  1683. mesh_conf = "710701010001000009"
  1684. mpm = "75040000079d"
  1685. ht_capab = "2d1a7c001bffff000000000000000000000100000000000000000000"
  1686. ht_oper = "3d160b000000000000000000000000000000000000000000"
  1687. dev[0].request("NOTE no supported rates")
  1688. frame = hdr + fixed + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1689. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1690. raise Exception("MGMT_RX_PROCESS failed")
  1691. dev[0].request("NOTE Invalid supported rates element length 33+0")
  1692. long_supp_rates = "012100112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"
  1693. frame = hdr + fixed + long_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1694. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1695. raise Exception("MGMT_RX_PROCESS failed")
  1696. dev[0].request("NOTE Too short mesh config")
  1697. short_mesh_conf = "710401010001"
  1698. frame = hdr + fixed + supp_rates + mesh_id + short_mesh_conf + mpm + ht_capab + ht_oper
  1699. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1700. raise Exception("MGMT_RX_PROCESS failed")
  1701. dev[0].request("NOTE Add STA failure")
  1702. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1703. with fail_test(dev[0], 1, "wpa_driver_nl80211_sta_add"):
  1704. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1705. raise Exception("MGMT_RX_PROCESS failed")
  1706. dev[0].request("NOTE Send Action failure")
  1707. with fail_test(dev[0], 1, "driver_nl80211_send_action"):
  1708. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1709. raise Exception("MGMT_RX_PROCESS failed")
  1710. dev[0].request("NOTE Set STA failure")
  1711. addr = "020000000101"
  1712. hdr = "d000ac00020000000000" + addr + addr + "1000"
  1713. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1714. with fail_test(dev[0], 2, "wpa_driver_nl80211_sta_add"):
  1715. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1716. raise Exception("MGMT_RX_PROCESS failed")
  1717. dev[0].request("NOTE ap_sta_add OOM")
  1718. addr = "020000000102"
  1719. hdr = "d000ac00020000000000" + addr + addr + "1000"
  1720. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1721. with alloc_fail(dev[0], 1, "ap_sta_add"):
  1722. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1723. raise Exception("MGMT_RX_PROCESS failed")
  1724. dev[0].request("NOTE hostapd_get_aid() failure")
  1725. addr = "020000000103"
  1726. hdr = "d000ac00020000000000" + addr + addr + "1000"
  1727. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1728. with fail_test(dev[0], 1, "hostapd_get_aid"):
  1729. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1730. raise Exception("MGMT_RX_PROCESS failed")
  1731. if "OK" not in dev[0].request("MESH_PEER_REMOVE 02:00:00:00:01:00"):
  1732. raise Exception("Failed to remove peer")
  1733. if "FAIL" not in dev[0].request("MESH_PEER_REMOVE 02:00:00:00:01:02"):
  1734. raise Exception("Unexpected MESH_PEER_REMOVE success")
  1735. if "FAIL" not in dev[1].request("MESH_PEER_REMOVE 02:00:00:00:01:02"):
  1736. raise Exception("Unexpected MESH_PEER_REMOVE success(2)")
  1737. if "FAIL" not in dev[1].request("MESH_PEER_ADD 02:00:00:00:01:02"):
  1738. raise Exception("Unexpected MESH_PEER_ADD success")
  1739. def test_mesh_holding(dev, apdev):
  1740. """Mesh MPM FSM and HOLDING state event OPN_ACPT"""
  1741. check_mesh_support(dev[0])
  1742. add_open_mesh_network(dev[0])
  1743. add_open_mesh_network(dev[1])
  1744. check_mesh_group_added(dev[0])
  1745. check_mesh_group_added(dev[1])
  1746. check_mesh_peer_connected(dev[0])
  1747. check_mesh_peer_connected(dev[1])
  1748. addr0 = dev[0].own_addr()
  1749. addr1 = dev[1].own_addr()
  1750. dev[0].request("SET ext_mgmt_frame_handling 1")
  1751. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1752. raise Exception("Failed to remove peer")
  1753. rx_msg = dev[0].mgmt_rx()
  1754. if rx_msg is None:
  1755. raise Exception("MGMT-RX timeout")
  1756. if rx_msg['subtype'] != 13:
  1757. raise Exception("Unexpected management frame")
  1758. payload = rx_msg['payload']
  1759. (categ, action) = struct.unpack('BB', payload[0:2])
  1760. if categ != 0x0f or action != 0x03:
  1761. raise Exception("Did not see Mesh Peering Close")
  1762. peer_lid = payload[-6:-4].encode("hex")
  1763. my_lid = payload[-4:-2].encode("hex")
  1764. # Drop Mesh Peering Close and instead, process an unexpected Mesh Peering
  1765. # Open to trigger transmission of another Mesh Peering Close in the HOLDING
  1766. # state based on an OPN_ACPT event.
  1767. dst = addr0.replace(':', '')
  1768. src = addr1.replace(':', '')
  1769. hdr = "d000ac00" + dst + src + src + "1000"
  1770. fixed = "0f010000"
  1771. supp_rates = "010802040b168c129824"
  1772. ext_supp_rates = "3204b048606c"
  1773. mesh_id = "720e777061732d6d6573682d6f70656e"
  1774. mesh_conf = "710701010001000009"
  1775. mpm = "7504" + my_lid + peer_lid
  1776. ht_capab = "2d1a7c001bffff000000000000000000000100000000000000000000"
  1777. ht_oper = "3d160b000000000000000000000000000000000000000000"
  1778. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1779. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1780. raise Exception("MGMT_RX_PROCESS failed")
  1781. time.sleep(0.1)
  1782. def test_mesh_cnf_rcvd_event_cls_acpt(dev, apdev):
  1783. """Mesh peering management protocol testing - CLS_ACPT event in CNF_RCVD"""
  1784. check_mesh_support(dev[0])
  1785. add_open_mesh_network(dev[0])
  1786. check_mesh_group_added(dev[0])
  1787. dev[0].dump_monitor()
  1788. dev[0].request("SET ext_mgmt_frame_handling 1")
  1789. add_open_mesh_network(dev[1])
  1790. check_mesh_group_added(dev[1])
  1791. addr0 = dev[0].own_addr()
  1792. addr1 = dev[1].own_addr()
  1793. rx_msg = dev[0].mgmt_rx()
  1794. # Drop Mesh Peering Open
  1795. rx_msg = dev[0].mgmt_rx()
  1796. # Allow Mesh Peering Confirm to go through
  1797. 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'))):
  1798. raise Exception("MGMT_RX_PROCESS failed")
  1799. payload = rx_msg['payload']
  1800. peer_lid = payload[51:53].encode("hex")
  1801. my_lid = payload[53:55].encode("hex")
  1802. dst = addr0.replace(':', '')
  1803. src = addr1.replace(':', '')
  1804. hdr = "d000ac00" + dst + src + src + "1000"
  1805. fixed = "0f03"
  1806. mesh_id = "720e777061732d6d6573682d6f70656e"
  1807. mpm = "75080000" + peer_lid + my_lid + "3700"
  1808. frame = hdr + fixed + mesh_id + mpm
  1809. # Inject Mesh Peering Close to hit "state CNF_RCVD event CLS_ACPT" to
  1810. # HOLDING transition.
  1811. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame):
  1812. raise Exception("MGMT_RX_PROCESS failed")
  1813. def test_mesh_opn_snt_event_cls_acpt(dev, apdev):
  1814. """Mesh peering management protocol testing - CLS_ACPT event in OPN_SNT"""
  1815. check_mesh_support(dev[0])
  1816. add_open_mesh_network(dev[0])
  1817. check_mesh_group_added(dev[0])
  1818. dev[0].dump_monitor()
  1819. dev[0].request("SET ext_mgmt_frame_handling 1")
  1820. add_open_mesh_network(dev[1])
  1821. check_mesh_group_added(dev[1])
  1822. addr0 = dev[0].own_addr()
  1823. addr1 = dev[1].own_addr()
  1824. rx_msg = dev[0].mgmt_rx()
  1825. # Drop Mesh Peering Open
  1826. rx_msg = dev[0].mgmt_rx()
  1827. # Drop Mesh Peering Confirm
  1828. payload = rx_msg['payload']
  1829. peer_lid = "0000"
  1830. my_lid = payload[53:55].encode("hex")
  1831. dst = addr0.replace(':', '')
  1832. src = addr1.replace(':', '')
  1833. hdr = "d000ac00" + dst + src + src + "1000"
  1834. fixed = "0f03"
  1835. mesh_id = "720e777061732d6d6573682d6f70656e"
  1836. mpm = "75080000" + peer_lid + my_lid + "3700"
  1837. frame = hdr + fixed + mesh_id + mpm
  1838. # Inject Mesh Peering Close to hit "state OPN_SNTevent CLS_ACPT" to
  1839. # HOLDING transition.
  1840. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame):
  1841. raise Exception("MGMT_RX_PROCESS failed")
  1842. def test_mesh_select_network(dev):
  1843. """Mesh network and SELECT_NETWORK"""
  1844. check_mesh_support(dev[0])
  1845. id0 = add_open_mesh_network(dev[0], start=False)
  1846. id1 = add_open_mesh_network(dev[1], start=False)
  1847. dev[0].select_network(id0)
  1848. dev[1].select_network(id1)
  1849. check_mesh_group_added(dev[0])
  1850. check_mesh_group_added(dev[1])
  1851. check_mesh_peer_connected(dev[0])
  1852. check_mesh_peer_connected(dev[1])
  1853. hwsim_utils.test_connectivity(dev[0], dev[1])
  1854. def test_mesh_forwarding(dev):
  1855. """Mesh with two stations that can't reach each other directly"""
  1856. try:
  1857. set_group_map(dev[0], 1)
  1858. set_group_map(dev[1], 3)
  1859. set_group_map(dev[2], 2)
  1860. check_mesh_support(dev[0])
  1861. for i in range(3):
  1862. add_open_mesh_network(dev[i])
  1863. check_mesh_group_added(dev[i])
  1864. for i in range(3):
  1865. check_mesh_peer_connected(dev[i])
  1866. hwsim_utils.test_connectivity(dev[0], dev[1])
  1867. hwsim_utils.test_connectivity(dev[1], dev[2])
  1868. hwsim_utils.test_connectivity(dev[0], dev[2])
  1869. finally:
  1870. # reset groups
  1871. set_group_map(dev[0], 1)
  1872. set_group_map(dev[1], 1)
  1873. set_group_map(dev[2], 1)
  1874. def test_mesh_forwarding_secure(dev):
  1875. """Mesh with two stations that can't reach each other directly (RSN)"""
  1876. check_mesh_support(dev[0], secure=True)
  1877. try:
  1878. set_group_map(dev[0], 1)
  1879. set_group_map(dev[1], 3)
  1880. set_group_map(dev[2], 2)
  1881. for i in range(3):
  1882. dev[i].request("SET sae_groups ")
  1883. id = add_mesh_secure_net(dev[i])
  1884. dev[i].mesh_group_add(id)
  1885. check_mesh_group_added(dev[i])
  1886. for i in range(3):
  1887. check_mesh_peer_connected(dev[i])
  1888. hwsim_utils.test_connectivity(dev[0], dev[1])
  1889. hwsim_utils.test_connectivity(dev[1], dev[2])
  1890. hwsim_utils.test_connectivity(dev[0], dev[2])
  1891. finally:
  1892. # reset groups
  1893. set_group_map(dev[0], 1)
  1894. set_group_map(dev[1], 1)
  1895. set_group_map(dev[2], 1)