test_wpas_mesh.py 74 KB

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