test_wpas_mesh.py 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031
  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. if "@ 160)" not in reg:
  739. raise HwsimSkip("160 MHz channel not supported in regulatory information")
  740. add_open_mesh_network(dev[i], freq="5520", chwidth=2)
  741. # Check for mesh joined
  742. check_mesh_group_added(dev[0])
  743. check_mesh_group_added(dev[1])
  744. # Check for peer connected
  745. check_mesh_peer_connected(dev[0])
  746. check_mesh_peer_connected(dev[1])
  747. # Test connectivity 0->1 and 1->0
  748. hwsim_utils.test_connectivity(dev[0], dev[1])
  749. sig = dev[0].request("SIGNAL_POLL").splitlines()
  750. if "WIDTH=160 MHz" not in sig:
  751. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  752. if "FREQUENCY=5520" not in sig:
  753. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  754. sig = dev[1].request("SIGNAL_POLL").splitlines()
  755. if "WIDTH=160 MHz" not in sig:
  756. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  757. if "FREQUENCY=5520" not in sig:
  758. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  759. def test_wpas_mesh_password_mismatch(dev, apdev):
  760. """Mesh network and one device with mismatching password"""
  761. check_mesh_support(dev[0], secure=True)
  762. dev[0].request("SET sae_groups ")
  763. id = add_mesh_secure_net(dev[0])
  764. dev[0].mesh_group_add(id)
  765. dev[1].request("SET sae_groups ")
  766. id = add_mesh_secure_net(dev[1])
  767. dev[1].mesh_group_add(id)
  768. dev[2].request("SET sae_groups ")
  769. id = add_mesh_secure_net(dev[2])
  770. dev[2].set_network_quoted(id, "psk", "wrong password")
  771. dev[2].mesh_group_add(id)
  772. # The two peers with matching password need to be able to connect
  773. check_mesh_group_added(dev[0])
  774. check_mesh_group_added(dev[1])
  775. check_mesh_peer_connected(dev[0])
  776. check_mesh_peer_connected(dev[1])
  777. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  778. if ev is None:
  779. raise Exception("dev2 did not report auth failure (1)")
  780. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  781. if ev is None:
  782. raise Exception("dev2 did not report auth failure (2)")
  783. dev[2].dump_monitor()
  784. count = 0
  785. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=5)
  786. if ev is None:
  787. logger.info("dev0 did not report auth failure")
  788. else:
  789. if "addr=" + dev[2].own_addr() not in ev:
  790. raise Exception("Unexpected peer address in dev0 event: " + ev)
  791. count += 1
  792. dev[0].dump_monitor()
  793. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=5)
  794. if ev is None:
  795. logger.info("dev1 did not report auth failure")
  796. else:
  797. if "addr=" + dev[2].own_addr() not in ev:
  798. raise Exception("Unexpected peer address in dev1 event: " + ev)
  799. count += 1
  800. dev[1].dump_monitor()
  801. hwsim_utils.test_connectivity(dev[0], dev[1])
  802. for i in range(2):
  803. try:
  804. hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
  805. raise Exception("Data connectivity test passed unexpectedly")
  806. except Exception, e:
  807. if "data delivery failed" not in str(e):
  808. raise
  809. if count == 0:
  810. raise Exception("Neither dev0 nor dev1 reported auth failure")
  811. def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
  812. """Mesh password mismatch and retry [long]"""
  813. if not params['long']:
  814. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  815. check_mesh_support(dev[0], secure=True)
  816. dev[0].request("SET sae_groups ")
  817. id = add_mesh_secure_net(dev[0])
  818. dev[0].mesh_group_add(id)
  819. dev[1].request("SET sae_groups ")
  820. id = add_mesh_secure_net(dev[1])
  821. dev[1].set_network_quoted(id, "psk", "wrong password")
  822. dev[1].mesh_group_add(id)
  823. # Check for mesh joined
  824. check_mesh_group_added(dev[0])
  825. check_mesh_group_added(dev[1])
  826. for i in range(4):
  827. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  828. if ev is None:
  829. raise Exception("dev0 did not report auth failure (%d)" % i)
  830. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  831. if ev is None:
  832. raise Exception("dev1 did not report auth failure (%d)" % i)
  833. ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  834. if ev is None:
  835. raise Exception("dev0 did not report auth blocked")
  836. ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  837. if ev is None:
  838. raise Exception("dev1 did not report auth blocked")
  839. def test_mesh_wpa_auth_init_oom(dev, apdev):
  840. """Secure mesh network setup failing due to wpa_init() OOM"""
  841. check_mesh_support(dev[0], secure=True)
  842. dev[0].request("SET sae_groups ")
  843. with alloc_fail(dev[0], 1, "wpa_init"):
  844. id = add_mesh_secure_net(dev[0])
  845. dev[0].mesh_group_add(id)
  846. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
  847. if ev is not None:
  848. raise Exception("Unexpected mesh group start during OOM")
  849. def test_mesh_wpa_init_fail(dev, apdev):
  850. """Secure mesh network setup local failure"""
  851. check_mesh_support(dev[0], secure=True)
  852. dev[0].request("SET sae_groups ")
  853. with fail_test(dev[0], 1, "os_get_random;=__mesh_rsn_auth_init"):
  854. id = add_mesh_secure_net(dev[0])
  855. dev[0].mesh_group_add(id)
  856. wait_fail_trigger(dev[0], "GET_FAIL")
  857. dev[0].dump_monitor()
  858. with alloc_fail(dev[0], 1, "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_ALLOC_FAIL")
  862. dev[0].dump_monitor()
  863. with fail_test(dev[0], 1, "os_get_random;mesh_rsn_init_ampe_sta"):
  864. id = add_mesh_secure_net(dev[0])
  865. dev[0].mesh_group_add(id)
  866. dev[1].request("SET sae_groups ")
  867. id = add_mesh_secure_net(dev[1])
  868. dev[1].mesh_group_add(id)
  869. wait_fail_trigger(dev[0], "GET_FAIL")
  870. def test_wpas_mesh_reconnect(dev, apdev):
  871. """Secure mesh network plink counting during reconnection"""
  872. check_mesh_support(dev[0])
  873. try:
  874. _test_wpas_mesh_reconnect(dev)
  875. finally:
  876. dev[0].request("SET max_peer_links 99")
  877. def _test_wpas_mesh_reconnect(dev):
  878. dev[0].request("SET max_peer_links 2")
  879. dev[0].request("SET sae_groups ")
  880. id = add_mesh_secure_net(dev[0])
  881. dev[0].set_network(id, "beacon_int", "100")
  882. dev[0].mesh_group_add(id)
  883. dev[1].request("SET sae_groups ")
  884. id = add_mesh_secure_net(dev[1])
  885. dev[1].mesh_group_add(id)
  886. check_mesh_group_added(dev[0])
  887. check_mesh_group_added(dev[1])
  888. check_mesh_peer_connected(dev[0])
  889. check_mesh_peer_connected(dev[1])
  890. for i in range(3):
  891. # Drop incoming management frames to avoid handling link close
  892. dev[0].request("SET ext_mgmt_frame_handling 1")
  893. dev[1].mesh_group_remove()
  894. check_mesh_group_removed(dev[1])
  895. dev[1].request("FLUSH")
  896. dev[0].request("SET ext_mgmt_frame_handling 0")
  897. id = add_mesh_secure_net(dev[1])
  898. dev[1].mesh_group_add(id)
  899. check_mesh_group_added(dev[1])
  900. check_mesh_peer_connected(dev[1])
  901. dev[0].dump_monitor()
  902. dev[1].dump_monitor()
  903. def test_wpas_mesh_gate_forwarding(dev, apdev, p):
  904. """Mesh forwards traffic to unknown sta to mesh gates"""
  905. addr0 = dev[0].own_addr()
  906. addr1 = dev[1].own_addr()
  907. addr2 = dev[2].own_addr()
  908. external_sta = '02:11:22:33:44:55'
  909. # start 3 node connected mesh
  910. check_mesh_support(dev[0])
  911. for i in range(3):
  912. add_open_mesh_network(dev[i])
  913. check_mesh_group_added(dev[i])
  914. for i in range(3):
  915. check_mesh_peer_connected(dev[i])
  916. hwsim_utils.test_connectivity(dev[0], dev[1])
  917. hwsim_utils.test_connectivity(dev[1], dev[2])
  918. hwsim_utils.test_connectivity(dev[0], dev[2])
  919. # dev0 and dev1 are mesh gates
  920. subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
  921. 'mesh_gate_announcements=1'])
  922. subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
  923. 'mesh_gate_announcements=1'])
  924. # wait for gate announcement frames
  925. time.sleep(1)
  926. # data frame from dev2 -> external sta should be sent to both gates
  927. dev[2].request("DATA_TEST_CONFIG 1")
  928. dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
  929. dev[2].request("DATA_TEST_CONFIG 0")
  930. capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
  931. filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
  932. external_sta)
  933. for i in range(15):
  934. da = run_tshark(capfile, filt, [ "wlan.da" ])
  935. if addr0 in da and addr1 in da:
  936. logger.debug("Frames seen in tshark iteration %d" % i)
  937. break
  938. time.sleep(0.3)
  939. if addr0 not in da:
  940. raise Exception("Frame to gate %s not observed" % addr0)
  941. if addr1 not in da:
  942. raise Exception("Frame to gate %s not observed" % addr1)
  943. def test_wpas_mesh_pmksa_caching(dev, apdev):
  944. """Secure mesh network and PMKSA caching"""
  945. check_mesh_support(dev[0], secure=True)
  946. dev[0].request("SET sae_groups ")
  947. id = add_mesh_secure_net(dev[0])
  948. dev[0].mesh_group_add(id)
  949. dev[1].request("SET sae_groups ")
  950. id = add_mesh_secure_net(dev[1])
  951. dev[1].mesh_group_add(id)
  952. # Check for mesh joined
  953. check_mesh_group_added(dev[0])
  954. check_mesh_group_added(dev[1])
  955. # Check for peer connected
  956. check_mesh_peer_connected(dev[0])
  957. check_mesh_peer_connected(dev[1])
  958. addr0 = dev[0].own_addr()
  959. addr1 = dev[1].own_addr()
  960. pmksa0 = dev[0].get_pmksa(addr1)
  961. pmksa1 = dev[1].get_pmksa(addr0)
  962. if pmksa0 is None or pmksa1 is None:
  963. raise Exception("No PMKSA cache entry created")
  964. if pmksa0['pmkid'] != pmksa1['pmkid']:
  965. raise Exception("PMKID mismatch in PMKSA cache entries")
  966. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  967. raise Exception("Failed to remove peer")
  968. pmksa0b = dev[0].get_pmksa(addr1)
  969. if pmksa0b is None:
  970. raise Exception("PMKSA cache entry not maintained")
  971. time.sleep(0.1)
  972. if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
  973. raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
  974. def test_wpas_mesh_pmksa_caching2(dev, apdev):
  975. """Secure mesh network and PMKSA caching with no_auto_peer=1"""
  976. check_mesh_support(dev[0], secure=True)
  977. addr0 = dev[0].own_addr()
  978. addr1 = dev[1].own_addr()
  979. dev[0].request("SET sae_groups ")
  980. id = add_mesh_secure_net(dev[0])
  981. dev[0].set_network(id, "no_auto_peer", "1")
  982. dev[0].mesh_group_add(id)
  983. dev[1].request("SET sae_groups ")
  984. id = add_mesh_secure_net(dev[1])
  985. dev[1].set_network(id, "no_auto_peer", "1")
  986. dev[1].mesh_group_add(id)
  987. # Check for mesh joined
  988. check_mesh_group_added(dev[0])
  989. check_mesh_group_added(dev[1])
  990. # Check for peer connected
  991. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  992. if ev is None:
  993. raise Exception("Missing no-initiate message")
  994. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  995. raise Exception("MESH_PEER_ADD failed")
  996. check_mesh_peer_connected(dev[0])
  997. check_mesh_peer_connected(dev[1])
  998. pmksa0 = dev[0].get_pmksa(addr1)
  999. pmksa1 = dev[1].get_pmksa(addr0)
  1000. if pmksa0 is None or pmksa1 is None:
  1001. raise Exception("No PMKSA cache entry created")
  1002. if pmksa0['pmkid'] != pmksa1['pmkid']:
  1003. raise Exception("PMKID mismatch in PMKSA cache entries")
  1004. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1005. raise Exception("Failed to remove peer")
  1006. pmksa0b = dev[0].get_pmksa(addr1)
  1007. if pmksa0b is None:
  1008. raise Exception("PMKSA cache entry not maintained")
  1009. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1010. if ev is None:
  1011. raise Exception("Missing no-initiate message (2)")
  1012. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1013. raise Exception("MESH_PEER_ADD failed (2)")
  1014. check_mesh_peer_connected(dev[0])
  1015. check_mesh_peer_connected(dev[1])
  1016. pmksa0c = dev[0].get_pmksa(addr1)
  1017. pmksa1c = dev[1].get_pmksa(addr0)
  1018. if pmksa0c is None or pmksa1c is None:
  1019. raise Exception("No PMKSA cache entry created (2)")
  1020. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  1021. raise Exception("PMKID mismatch in PMKSA cache entries")
  1022. if pmksa0['pmkid'] != pmksa0c['pmkid']:
  1023. raise Exception("PMKID changed")
  1024. hwsim_utils.test_connectivity(dev[0], dev[1])
  1025. def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
  1026. """Secure mesh network and PMKSA caching with no PMKID match"""
  1027. check_mesh_support(dev[0], secure=True)
  1028. addr0 = dev[0].own_addr()
  1029. addr1 = dev[1].own_addr()
  1030. dev[0].request("SET sae_groups ")
  1031. id = add_mesh_secure_net(dev[0])
  1032. dev[0].set_network(id, "no_auto_peer", "1")
  1033. dev[0].mesh_group_add(id)
  1034. dev[1].request("SET sae_groups ")
  1035. id = add_mesh_secure_net(dev[1])
  1036. dev[1].set_network(id, "no_auto_peer", "1")
  1037. dev[1].mesh_group_add(id)
  1038. # Check for mesh joined
  1039. check_mesh_group_added(dev[0])
  1040. check_mesh_group_added(dev[1])
  1041. # Check for peer connected
  1042. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1043. if ev is None:
  1044. raise Exception("Missing no-initiate message")
  1045. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1046. raise Exception("MESH_PEER_ADD failed")
  1047. check_mesh_peer_connected(dev[0])
  1048. check_mesh_peer_connected(dev[1])
  1049. pmksa0 = dev[0].get_pmksa(addr1)
  1050. pmksa1 = dev[1].get_pmksa(addr0)
  1051. if pmksa0 is None or pmksa1 is None:
  1052. raise Exception("No PMKSA cache entry created")
  1053. if pmksa0['pmkid'] != pmksa1['pmkid']:
  1054. raise Exception("PMKID mismatch in PMKSA cache entries")
  1055. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1056. raise Exception("Failed to remove peer")
  1057. if "OK" not in dev[1].request("PMKSA_FLUSH"):
  1058. raise Exception("Failed to flush PMKSA cache")
  1059. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1060. if ev is None:
  1061. raise Exception("Missing no-initiate message (2)")
  1062. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1063. raise Exception("MESH_PEER_ADD failed (2)")
  1064. check_mesh_peer_connected(dev[0])
  1065. check_mesh_peer_connected(dev[1])
  1066. pmksa0c = dev[0].get_pmksa(addr1)
  1067. pmksa1c = dev[1].get_pmksa(addr0)
  1068. if pmksa0c is None or pmksa1c is None:
  1069. raise Exception("No PMKSA cache entry created (2)")
  1070. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  1071. raise Exception("PMKID mismatch in PMKSA cache entries")
  1072. if pmksa0['pmkid'] == pmksa0c['pmkid']:
  1073. raise Exception("PMKID did not change")
  1074. hwsim_utils.test_connectivity(dev[0], dev[1])
  1075. def test_mesh_pmksa_caching_oom(dev, apdev):
  1076. """Secure mesh network and PMKSA caching failing due to OOM"""
  1077. check_mesh_support(dev[0], secure=True)
  1078. addr0 = dev[0].own_addr()
  1079. addr1 = dev[1].own_addr()
  1080. dev[0].request("SET sae_groups ")
  1081. id = add_mesh_secure_net(dev[0])
  1082. dev[0].set_network(id, "no_auto_peer", "1")
  1083. dev[0].mesh_group_add(id)
  1084. dev[1].request("SET sae_groups ")
  1085. id = add_mesh_secure_net(dev[1])
  1086. dev[1].set_network(id, "no_auto_peer", "1")
  1087. dev[1].mesh_group_add(id)
  1088. # Check for mesh joined
  1089. check_mesh_group_added(dev[0])
  1090. check_mesh_group_added(dev[1])
  1091. # Check for peer connected
  1092. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1093. if ev is None:
  1094. raise Exception("Missing no-initiate message")
  1095. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1096. raise Exception("MESH_PEER_ADD failed")
  1097. check_mesh_peer_connected(dev[0])
  1098. check_mesh_peer_connected(dev[1])
  1099. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1100. raise Exception("Failed to remove peer")
  1101. pmksa0b = dev[0].get_pmksa(addr1)
  1102. if pmksa0b is None:
  1103. raise Exception("PMKSA cache entry not maintained")
  1104. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1105. if ev is None:
  1106. raise Exception("Missing no-initiate message (2)")
  1107. with alloc_fail(dev[0], 1, "wpa_auth_sta_init;mesh_rsn_auth_sae_sta"):
  1108. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1109. raise Exception("MESH_PEER_ADD failed (2)")
  1110. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1111. def test_mesh_oom(dev, apdev):
  1112. """Mesh network setup failing due to OOM"""
  1113. check_mesh_support(dev[0], secure=True)
  1114. dev[0].request("SET sae_groups ")
  1115. with alloc_fail(dev[0], 1, "mesh_config_create"):
  1116. add_open_mesh_network(dev[0])
  1117. ev = dev[0].wait_event(["Failed to init mesh"])
  1118. if ev is None:
  1119. raise Exception("Init failure not reported")
  1120. with alloc_fail(dev[0], 4, "=wpa_supplicant_mesh_init"):
  1121. add_open_mesh_network(dev[0], basic_rates="60 120 240")
  1122. ev = dev[0].wait_event(["Failed to init mesh"])
  1123. if ev is None:
  1124. raise Exception("Init failure not reported")
  1125. for i in range(1, 66):
  1126. dev[0].dump_monitor()
  1127. logger.info("Test instance %d" % i)
  1128. try:
  1129. with alloc_fail(dev[0], i, "wpa_supplicant_mesh_init"):
  1130. add_open_mesh_network(dev[0])
  1131. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1132. ev = dev[0].wait_event(["Failed to init mesh",
  1133. "MESH-GROUP-STARTED"])
  1134. if ev is None:
  1135. raise Exception("Init failure not reported")
  1136. except Exception, e:
  1137. if i < 15:
  1138. raise
  1139. logger.info("Ignore no-oom for i=%d" % i)
  1140. with alloc_fail(dev[0], 5, "=wpa_supplicant_mesh_init"):
  1141. id = add_mesh_secure_net(dev[0])
  1142. dev[0].mesh_group_add(id)
  1143. ev = dev[0].wait_event(["Failed to init mesh"])
  1144. if ev is None:
  1145. raise Exception("Init failure not reported")
  1146. def test_mesh_add_interface_oom(dev):
  1147. """wpa_supplicant mesh with dynamic interface addition failing"""
  1148. check_mesh_support(dev[0])
  1149. for i in range(1, 3):
  1150. mesh = None
  1151. try:
  1152. with alloc_fail(dev[0], i, "wpas_mesh_add_interface"):
  1153. mesh = dev[0].request("MESH_INTERFACE_ADD").strip()
  1154. finally:
  1155. if mesh and mesh != "FAIL":
  1156. dev[0].request("MESH_GROUP_REMOVE " + mesh)
  1157. def test_mesh_scan_oom(dev):
  1158. """wpa_supplicant mesh scan results and OOM"""
  1159. check_mesh_support(dev[0])
  1160. add_open_mesh_network(dev[0])
  1161. check_mesh_group_added(dev[0])
  1162. for i in range(5):
  1163. dev[1].scan(freq="2412")
  1164. res = dev[1].request("SCAN_RESULTS")
  1165. if "[MESH]" in res:
  1166. break
  1167. for r in res.splitlines():
  1168. if "[MESH]" in r:
  1169. break
  1170. bssid = r.split('\t')[0]
  1171. bss = dev[1].get_bss(bssid)
  1172. if bss is None:
  1173. raise Exception("Could not get BSS entry for mesh")
  1174. for i in range(1, 3):
  1175. with alloc_fail(dev[1], i, "mesh_attr_text"):
  1176. bss = dev[1].get_bss(bssid)
  1177. if bss and "mesh_id" in bss:
  1178. raise Exception("Unexpected BSS result during OOM")
  1179. def test_mesh_drv_fail(dev, apdev):
  1180. """Mesh network setup failing due to driver command failure"""
  1181. check_mesh_support(dev[0], secure=True)
  1182. dev[0].request("SET sae_groups ")
  1183. with fail_test(dev[0], 1, "nl80211_join_mesh"):
  1184. add_open_mesh_network(dev[0])
  1185. ev = dev[0].wait_event(["mesh join error"])
  1186. if ev is None:
  1187. raise Exception("Join failure not reported")
  1188. dev[0].dump_monitor()
  1189. with fail_test(dev[0], 1, "wpa_driver_nl80211_if_add"):
  1190. if "FAIL" not in dev[0].request("MESH_INTERFACE_ADD").strip():
  1191. raise Exception("Interface added unexpectedly")
  1192. dev[0].dump_monitor()
  1193. with fail_test(dev[0], 1, "wpa_driver_nl80211_init_mesh"):
  1194. add_open_mesh_network(dev[0])
  1195. ev = dev[0].wait_event(["Could not join mesh"])
  1196. if ev is None:
  1197. raise Exception("Join failure not reported")
  1198. def test_mesh_sae_groups_invalid(dev, apdev):
  1199. """Mesh with invalid SAE group configuration"""
  1200. check_mesh_support(dev[0], secure=True)
  1201. dev[0].request("SET sae_groups 25")
  1202. id = add_mesh_secure_net(dev[0])
  1203. dev[0].mesh_group_add(id)
  1204. dev[1].request("SET sae_groups 123 122 121")
  1205. id = add_mesh_secure_net(dev[1])
  1206. dev[1].mesh_group_add(id)
  1207. check_mesh_group_added(dev[0])
  1208. check_mesh_group_added(dev[1])
  1209. ev = dev[0].wait_event(["new peer notification"], timeout=10)
  1210. if ev is None:
  1211. raise Exception("dev[0] did not see peer")
  1212. ev = dev[1].wait_event(["new peer notification"], timeout=10)
  1213. if ev is None:
  1214. raise Exception("dev[1] did not see peer")
  1215. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  1216. if ev is not None:
  1217. raise Exception("Unexpected connection(0)")
  1218. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1219. if ev is not None:
  1220. raise Exception("Unexpected connection(1)")
  1221. # Additional coverage in mesh_rsn_sae_group() with non-zero
  1222. # wpa_s->mesh_rsn->sae_group_index.
  1223. dev[0].dump_monitor()
  1224. dev[1].dump_monitor()
  1225. id = add_mesh_secure_net(dev[2])
  1226. dev[2].mesh_group_add(id)
  1227. check_mesh_group_added(dev[2])
  1228. check_mesh_peer_connected(dev[0])
  1229. check_mesh_peer_connected(dev[2])
  1230. ev = dev[1].wait_event(["new peer notification"], timeout=10)
  1231. if ev is None:
  1232. raise Exception("dev[1] did not see peer(2)")
  1233. dev[0].dump_monitor()
  1234. dev[1].dump_monitor()
  1235. dev[2].dump_monitor()
  1236. dev[0].request("SET sae_groups ")
  1237. dev[1].request("SET sae_groups ")
  1238. def test_mesh_sae_failure(dev, apdev):
  1239. """Mesh and local SAE failures"""
  1240. check_mesh_support(dev[0], secure=True)
  1241. dev[0].request("SET sae_groups ")
  1242. dev[1].request("SET sae_groups ")
  1243. funcs = [ (1, "=mesh_rsn_auth_sae_sta", True),
  1244. (1, "mesh_rsn_build_sae_commit;mesh_rsn_auth_sae_sta", False),
  1245. (1, "auth_sae_init_committed;mesh_rsn_auth_sae_sta", True),
  1246. (1, "=mesh_rsn_protect_frame", True),
  1247. (2, "=mesh_rsn_protect_frame", True),
  1248. (1, "aes_siv_encrypt;mesh_rsn_protect_frame", True),
  1249. (1, "=mesh_rsn_process_ampe", True),
  1250. (1, "aes_siv_decrypt;mesh_rsn_process_ampe", True) ]
  1251. for count, func, success in funcs:
  1252. id = add_mesh_secure_net(dev[0])
  1253. dev[0].mesh_group_add(id)
  1254. with alloc_fail(dev[1], count, func):
  1255. id = add_mesh_secure_net(dev[1])
  1256. dev[1].mesh_group_add(id)
  1257. check_mesh_group_added(dev[0])
  1258. check_mesh_group_added(dev[1])
  1259. if success:
  1260. # retry is expected to work
  1261. check_mesh_peer_connected(dev[0])
  1262. check_mesh_peer_connected(dev[1])
  1263. else:
  1264. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  1265. dev[0].mesh_group_remove()
  1266. dev[1].mesh_group_remove()
  1267. check_mesh_group_removed(dev[0])
  1268. check_mesh_group_removed(dev[1])
  1269. def test_mesh_failure(dev, apdev):
  1270. """Mesh and local failures"""
  1271. check_mesh_support(dev[0])
  1272. funcs = [ (1, "ap_sta_add;mesh_mpm_add_peer", True),
  1273. (1, "wpabuf_alloc;mesh_mpm_send_plink_action", True) ]
  1274. for count, func, success in funcs:
  1275. add_open_mesh_network(dev[0])
  1276. with alloc_fail(dev[1], count, func):
  1277. add_open_mesh_network(dev[1])
  1278. check_mesh_group_added(dev[0])
  1279. check_mesh_group_added(dev[1])
  1280. if success:
  1281. # retry is expected to work
  1282. check_mesh_peer_connected(dev[0])
  1283. check_mesh_peer_connected(dev[1])
  1284. else:
  1285. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  1286. dev[0].mesh_group_remove()
  1287. dev[1].mesh_group_remove()
  1288. check_mesh_group_removed(dev[0])
  1289. check_mesh_group_removed(dev[1])
  1290. funcs = [ (1, "mesh_mpm_init_link", True) ]
  1291. for count, func, success in funcs:
  1292. add_open_mesh_network(dev[0])
  1293. with fail_test(dev[1], count, func):
  1294. add_open_mesh_network(dev[1])
  1295. check_mesh_group_added(dev[0])
  1296. check_mesh_group_added(dev[1])
  1297. if success:
  1298. # retry is expected to work
  1299. check_mesh_peer_connected(dev[0])
  1300. check_mesh_peer_connected(dev[1])
  1301. else:
  1302. wait_fail_trigger(dev[1], "GET_FAIL")
  1303. dev[0].mesh_group_remove()
  1304. dev[1].mesh_group_remove()
  1305. check_mesh_group_removed(dev[0])
  1306. check_mesh_group_removed(dev[1])
  1307. def test_mesh_invalid_frequency(dev, apdev):
  1308. """Mesh and invalid frequency configuration"""
  1309. check_mesh_support(dev[0])
  1310. add_open_mesh_network(dev[0], freq=None)
  1311. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  1312. "Could not join mesh"])
  1313. if ev is None or "Could not join mesh" not in ev:
  1314. raise Exception("Mesh join failure not reported")
  1315. dev[0].request("REMOVE_NETWORK all")
  1316. add_open_mesh_network(dev[0], freq="2413")
  1317. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  1318. "Could not join mesh"])
  1319. if ev is None or "Could not join mesh" not in ev:
  1320. raise Exception("Mesh join failure not reported")
  1321. def test_mesh_default_beacon_int(dev, apdev):
  1322. """Mesh and default beacon interval"""
  1323. check_mesh_support(dev[0])
  1324. try:
  1325. dev[0].request("SET beacon_int 200")
  1326. add_open_mesh_network(dev[0])
  1327. check_mesh_group_added(dev[0])
  1328. finally:
  1329. dev[0].request("SET beacon_int 0")
  1330. def test_mesh_scan_parse_error(dev, apdev):
  1331. """Mesh scan element parse error"""
  1332. check_mesh_support(dev[0])
  1333. params = { "ssid": "open",
  1334. "beacon_int": "2000" }
  1335. hapd = hostapd.add_ap(apdev[0], params)
  1336. bssid = apdev[0]['bssid']
  1337. hapd.set('vendor_elements', 'dd0201')
  1338. for i in range(10):
  1339. dev[0].scan(freq=2412)
  1340. if bssid in dev[0].request("SCAN_RESULTS"):
  1341. break
  1342. # This will fail in IE parsing due to the truncated IE in the Probe
  1343. # Response frame.
  1344. bss = dev[0].request("BSS " + bssid)
  1345. def test_mesh_missing_mic(dev, apdev):
  1346. """Secure mesh network and missing MIC"""
  1347. check_mesh_support(dev[0], secure=True)
  1348. dev[0].request("SET ext_mgmt_frame_handling 1")
  1349. dev[0].request("SET sae_groups ")
  1350. id = add_mesh_secure_net(dev[0])
  1351. dev[0].mesh_group_add(id)
  1352. dev[1].request("SET sae_groups ")
  1353. id = add_mesh_secure_net(dev[1])
  1354. dev[1].mesh_group_add(id)
  1355. # Check for mesh joined
  1356. check_mesh_group_added(dev[0])
  1357. check_mesh_group_added(dev[1])
  1358. count = 0
  1359. remove_mic = True
  1360. while True:
  1361. count += 1
  1362. if count > 15:
  1363. raise Exception("Did not see Action frames")
  1364. rx_msg = dev[0].mgmt_rx()
  1365. if rx_msg is None:
  1366. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1367. if ev:
  1368. break
  1369. raise Exception("MGMT-RX timeout")
  1370. if rx_msg['subtype'] == 13:
  1371. payload = rx_msg['payload']
  1372. frame = rx_msg['frame']
  1373. (categ, action) = struct.unpack('BB', payload[0:2])
  1374. if categ == 15 and action == 1 and remove_mic:
  1375. # Mesh Peering Open
  1376. pos = frame.find('\x8c\x10')
  1377. if not pos:
  1378. raise Exception("Could not find MIC element")
  1379. logger.info("Found MIC at %d" % pos)
  1380. # Remove MIC
  1381. rx_msg['frame'] = frame[0:pos]
  1382. remove_mic = False
  1383. 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'))):
  1384. raise Exception("MGMT_RX_PROCESS failed")
  1385. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1386. if ev:
  1387. break
  1388. def test_mesh_pmkid_mismatch(dev, apdev):
  1389. """Secure mesh network and PMKID mismatch"""
  1390. check_mesh_support(dev[0], secure=True)
  1391. addr0 = dev[0].own_addr()
  1392. addr1 = dev[1].own_addr()
  1393. dev[0].request("SET sae_groups ")
  1394. id = add_mesh_secure_net(dev[0])
  1395. dev[0].set_network(id, "no_auto_peer", "1")
  1396. dev[0].mesh_group_add(id)
  1397. dev[1].request("SET sae_groups ")
  1398. id = add_mesh_secure_net(dev[1])
  1399. dev[1].set_network(id, "no_auto_peer", "1")
  1400. dev[1].mesh_group_add(id)
  1401. # Check for mesh joined
  1402. check_mesh_group_added(dev[0])
  1403. check_mesh_group_added(dev[1])
  1404. # Check for peer connected
  1405. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1406. if ev is None:
  1407. raise Exception("Missing no-initiate message")
  1408. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1409. raise Exception("MESH_PEER_ADD failed")
  1410. check_mesh_peer_connected(dev[0])
  1411. check_mesh_peer_connected(dev[1])
  1412. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1413. raise Exception("Failed to remove peer")
  1414. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1415. if ev is None:
  1416. raise Exception("Missing no-initiate message (2)")
  1417. dev[0].dump_monitor()
  1418. dev[1].dump_monitor()
  1419. dev[0].request("SET ext_mgmt_frame_handling 1")
  1420. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1421. raise Exception("MESH_PEER_ADD failed (2)")
  1422. count = 0
  1423. break_pmkid = True
  1424. while True:
  1425. count += 1
  1426. if count > 50:
  1427. raise Exception("Did not see Action frames")
  1428. rx_msg = dev[0].mgmt_rx()
  1429. if rx_msg is None:
  1430. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  1431. if ev:
  1432. break
  1433. raise Exception("MGMT-RX timeout")
  1434. if rx_msg['subtype'] == 13:
  1435. payload = rx_msg['payload']
  1436. frame = rx_msg['frame']
  1437. (categ, action) = struct.unpack('BB', payload[0:2])
  1438. if categ == 15 and action == 1 and break_pmkid:
  1439. # Mesh Peering Open
  1440. pos = frame.find('\x75\x14')
  1441. if not pos:
  1442. raise Exception("Could not find Mesh Peering Management element")
  1443. logger.info("Found Mesh Peering Management element at %d" % pos)
  1444. # Break PMKID to hit "Mesh RSN: Invalid PMKID (Chosen PMK did
  1445. # not match calculated PMKID)"
  1446. rx_msg['frame'] = frame[0:pos + 6] + '\x00\x00\x00\x00' + frame[pos + 10:]
  1447. break_pmkid = False
  1448. 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'))):
  1449. raise Exception("MGMT_RX_PROCESS failed")
  1450. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1451. if ev:
  1452. break
  1453. def test_mesh_peering_proto(dev, apdev):
  1454. """Mesh peering management protocol testing"""
  1455. check_mesh_support(dev[0])
  1456. dev[0].request("SET ext_mgmt_frame_handling 1")
  1457. add_open_mesh_network(dev[0], beacon_int=160)
  1458. add_open_mesh_network(dev[1], beacon_int=160)
  1459. count = 0
  1460. test = 1
  1461. while True:
  1462. count += 1
  1463. if count > 50:
  1464. raise Exception("Did not see Action frames")
  1465. rx_msg = dev[0].mgmt_rx()
  1466. if rx_msg is None:
  1467. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1468. if ev:
  1469. break
  1470. raise Exception("MGMT-RX timeout")
  1471. if rx_msg['subtype'] == 13:
  1472. payload = rx_msg['payload']
  1473. frame = rx_msg['frame']
  1474. (categ, action) = struct.unpack('BB', payload[0:2])
  1475. if categ == 15 and action == 1 and test == 1:
  1476. # Mesh Peering Open
  1477. pos = frame.find('\x75\x04')
  1478. if not pos:
  1479. raise Exception("Could not find Mesh Peering Management element")
  1480. logger.info("Found Mesh Peering Management element at %d" % pos)
  1481. # Remove the element to hit
  1482. # "MPM: No Mesh Peering Management element"
  1483. rx_msg['frame'] = frame[0:pos]
  1484. test += 1
  1485. elif categ == 15 and action == 1 and test == 2:
  1486. # Mesh Peering Open
  1487. pos = frame.find('\x72\x0e')
  1488. if not pos:
  1489. raise Exception("Could not find Mesh ID element")
  1490. logger.info("Found Mesh ID element at %d" % pos)
  1491. # Remove the element to hit
  1492. # "MPM: No Mesh ID or Mesh Configuration element"
  1493. rx_msg['frame'] = frame[0:pos] + frame[pos + 16:]
  1494. test += 1
  1495. elif categ == 15 and action == 1 and test == 3:
  1496. # Mesh Peering Open
  1497. pos = frame.find('\x72\x0e')
  1498. if not pos:
  1499. raise Exception("Could not find Mesh ID element")
  1500. logger.info("Found Mesh ID element at %d" % pos)
  1501. # Replace Mesh ID to hit "MPM: Mesh ID or Mesh Configuration
  1502. # element do not match local MBSS"
  1503. rx_msg['frame'] = frame[0:pos] + '\x72\x0etest-test-test' + frame[pos + 16:]
  1504. test += 1
  1505. elif categ == 15 and action == 1 and test == 4:
  1506. # Mesh Peering Open
  1507. # Remove IEs to hit
  1508. # "MPM: Ignore too short action frame 1 ie_len 0"
  1509. rx_msg['frame'] = frame[0:26]
  1510. test += 1
  1511. elif categ == 15 and action == 1 and test == 5:
  1512. # Mesh Peering Open
  1513. # Truncate IEs to hit
  1514. # "MPM: Failed to parse PLINK IEs"
  1515. rx_msg['frame'] = frame[0:30]
  1516. test += 1
  1517. elif categ == 15 and action == 1 and test == 6:
  1518. # Mesh Peering Open
  1519. pos = frame.find('\x75\x04')
  1520. if not pos:
  1521. raise Exception("Could not find Mesh Peering Management element")
  1522. logger.info("Found Mesh Peering Management element at %d" % pos)
  1523. # Truncate the element to hit
  1524. # "MPM: Invalid peer mgmt ie" and
  1525. # "MPM: Mesh parsing rejected frame"
  1526. rx_msg['frame'] = frame[0:pos] + '\x75\x00\x00\x00' + frame[pos + 6:]
  1527. test += 1
  1528. 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'))):
  1529. raise Exception("MGMT_RX_PROCESS failed")
  1530. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1531. if ev:
  1532. break
  1533. if test != 7:
  1534. raise Exception("Not all test frames completed")
  1535. def test_mesh_mpm_init_proto(dev, apdev):
  1536. """Mesh peering management protocol testing for peer addition"""
  1537. check_mesh_support(dev[0])
  1538. add_open_mesh_network(dev[0])
  1539. check_mesh_group_added(dev[0])
  1540. dev[0].dump_monitor()
  1541. dev[0].request("SET ext_mgmt_frame_handling 1")
  1542. addr = "020000000100"
  1543. hdr = "d000ac00020000000000" + addr + addr + "1000"
  1544. fixed = "0f010000"
  1545. supp_rates = "010802040b168c129824"
  1546. ext_supp_rates = "3204b048606c"
  1547. mesh_id = "720e777061732d6d6573682d6f70656e"
  1548. mesh_conf = "710701010001000009"
  1549. mpm = "75040000079d"
  1550. ht_capab = "2d1a7c001bffff000000000000000000000100000000000000000000"
  1551. ht_oper = "3d160b000000000000000000000000000000000000000000"
  1552. dev[0].request("NOTE no supported rates")
  1553. frame = hdr + fixed + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1554. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1555. raise Exception("MGMT_RX_PROCESS failed")
  1556. dev[0].request("NOTE Invalid supported rates element length 33+0")
  1557. long_supp_rates = "012100112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"
  1558. frame = hdr + fixed + long_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 Too short mesh config")
  1562. short_mesh_conf = "710401010001"
  1563. frame = hdr + fixed + supp_rates + mesh_id + short_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 Add STA failure")
  1567. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1568. with fail_test(dev[0], 1, "wpa_driver_nl80211_sta_add"):
  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 Send Action failure")
  1572. with fail_test(dev[0], 1, "driver_nl80211_send_action"):
  1573. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1574. raise Exception("MGMT_RX_PROCESS failed")
  1575. dev[0].request("NOTE Set STA failure")
  1576. addr = "020000000101"
  1577. hdr = "d000ac00020000000000" + addr + addr + "1000"
  1578. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1579. with fail_test(dev[0], 2, "wpa_driver_nl80211_sta_add"):
  1580. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1581. raise Exception("MGMT_RX_PROCESS failed")
  1582. dev[0].request("NOTE ap_sta_add OOM")
  1583. addr = "020000000102"
  1584. hdr = "d000ac00020000000000" + addr + addr + "1000"
  1585. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1586. with alloc_fail(dev[0], 1, "ap_sta_add"):
  1587. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1588. raise Exception("MGMT_RX_PROCESS failed")
  1589. dev[0].request("NOTE hostapd_get_aid() failure")
  1590. addr = "020000000103"
  1591. hdr = "d000ac00020000000000" + addr + addr + "1000"
  1592. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1593. with fail_test(dev[0], 1, "hostapd_get_aid"):
  1594. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1595. raise Exception("MGMT_RX_PROCESS failed")
  1596. if "OK" not in dev[0].request("MESH_PEER_REMOVE 02:00:00:00:01:00"):
  1597. raise Exception("Failed to remove peer")
  1598. if "FAIL" not in dev[0].request("MESH_PEER_REMOVE 02:00:00:00:01:02"):
  1599. raise Exception("Unexpected MESH_PEER_REMOVE success")
  1600. if "FAIL" not in dev[1].request("MESH_PEER_REMOVE 02:00:00:00:01:02"):
  1601. raise Exception("Unexpected MESH_PEER_REMOVE success(2)")
  1602. if "FAIL" not in dev[1].request("MESH_PEER_ADD 02:00:00:00:01:02"):
  1603. raise Exception("Unexpected MESH_PEER_ADD success")
  1604. def test_mesh_holding(dev, apdev):
  1605. """Mesh MPM FSM and HOLDING state event OPN_ACPT"""
  1606. check_mesh_support(dev[0])
  1607. add_open_mesh_network(dev[0])
  1608. add_open_mesh_network(dev[1])
  1609. check_mesh_group_added(dev[0])
  1610. check_mesh_group_added(dev[1])
  1611. check_mesh_peer_connected(dev[0])
  1612. check_mesh_peer_connected(dev[1])
  1613. addr0 = dev[0].own_addr()
  1614. addr1 = dev[1].own_addr()
  1615. dev[0].request("SET ext_mgmt_frame_handling 1")
  1616. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1617. raise Exception("Failed to remove peer")
  1618. rx_msg = dev[0].mgmt_rx()
  1619. if rx_msg is None:
  1620. raise Exception("MGMT-RX timeout")
  1621. if rx_msg['subtype'] != 13:
  1622. raise Exception("Unexpected management frame")
  1623. payload = rx_msg['payload']
  1624. (categ, action) = struct.unpack('BB', payload[0:2])
  1625. if categ != 0x0f or action != 0x03:
  1626. raise Exception("Did not see Mesh Peering Close")
  1627. peer_lid = payload[-6:-4].encode("hex")
  1628. my_lid = payload[-4:-2].encode("hex")
  1629. # Drop Mesh Peering Close and instead, process an unexpected Mesh Peering
  1630. # Open to trigger transmission of another Mesh Peering Close in the HOLDING
  1631. # state based on an OPN_ACPT event.
  1632. dst = addr0.replace(':', '')
  1633. src = addr1.replace(':', '')
  1634. hdr = "d000ac00" + dst + src + src + "1000"
  1635. fixed = "0f010000"
  1636. supp_rates = "010802040b168c129824"
  1637. ext_supp_rates = "3204b048606c"
  1638. mesh_id = "720e777061732d6d6573682d6f70656e"
  1639. mesh_conf = "710701010001000009"
  1640. mpm = "7504" + my_lid + peer_lid
  1641. ht_capab = "2d1a7c001bffff000000000000000000000100000000000000000000"
  1642. ht_oper = "3d160b000000000000000000000000000000000000000000"
  1643. frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
  1644. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
  1645. raise Exception("MGMT_RX_PROCESS failed")
  1646. time.sleep(0.1)
  1647. def test_mesh_cnf_rcvd_event_cls_acpt(dev, apdev):
  1648. """Mesh peering management protocol testing - CLS_ACPT event in CNF_RCVD"""
  1649. check_mesh_support(dev[0])
  1650. add_open_mesh_network(dev[0])
  1651. check_mesh_group_added(dev[0])
  1652. dev[0].dump_monitor()
  1653. dev[0].request("SET ext_mgmt_frame_handling 1")
  1654. add_open_mesh_network(dev[1])
  1655. check_mesh_group_added(dev[1])
  1656. addr0 = dev[0].own_addr()
  1657. addr1 = dev[1].own_addr()
  1658. rx_msg = dev[0].mgmt_rx()
  1659. # Drop Mesh Peering Open
  1660. rx_msg = dev[0].mgmt_rx()
  1661. # Allow Mesh Peering Confirm to go through
  1662. 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'))):
  1663. raise Exception("MGMT_RX_PROCESS failed")
  1664. payload = rx_msg['payload']
  1665. peer_lid = payload[51:53].encode("hex")
  1666. my_lid = payload[53:55].encode("hex")
  1667. dst = addr0.replace(':', '')
  1668. src = addr1.replace(':', '')
  1669. hdr = "d000ac00" + dst + src + src + "1000"
  1670. fixed = "0f03"
  1671. mesh_id = "720e777061732d6d6573682d6f70656e"
  1672. mpm = "75080000" + peer_lid + my_lid + "3700"
  1673. frame = hdr + fixed + mesh_id + mpm
  1674. # Inject Mesh Peering Close to hit "state CNF_RCVD event CLS_ACPT" to
  1675. # HOLDING transition.
  1676. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame):
  1677. raise Exception("MGMT_RX_PROCESS failed")
  1678. def test_mesh_opn_snt_event_cls_acpt(dev, apdev):
  1679. """Mesh peering management protocol testing - CLS_ACPT event in OPN_SNT"""
  1680. check_mesh_support(dev[0])
  1681. add_open_mesh_network(dev[0])
  1682. check_mesh_group_added(dev[0])
  1683. dev[0].dump_monitor()
  1684. dev[0].request("SET ext_mgmt_frame_handling 1")
  1685. add_open_mesh_network(dev[1])
  1686. check_mesh_group_added(dev[1])
  1687. addr0 = dev[0].own_addr()
  1688. addr1 = dev[1].own_addr()
  1689. rx_msg = dev[0].mgmt_rx()
  1690. # Drop Mesh Peering Open
  1691. rx_msg = dev[0].mgmt_rx()
  1692. # Drop Mesh Peering Confirm
  1693. payload = rx_msg['payload']
  1694. peer_lid = "0000"
  1695. my_lid = payload[53:55].encode("hex")
  1696. dst = addr0.replace(':', '')
  1697. src = addr1.replace(':', '')
  1698. hdr = "d000ac00" + dst + src + src + "1000"
  1699. fixed = "0f03"
  1700. mesh_id = "720e777061732d6d6573682d6f70656e"
  1701. mpm = "75080000" + peer_lid + my_lid + "3700"
  1702. frame = hdr + fixed + mesh_id + mpm
  1703. # Inject Mesh Peering Close to hit "state OPN_SNTevent CLS_ACPT" to
  1704. # HOLDING transition.
  1705. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame):
  1706. raise Exception("MGMT_RX_PROCESS failed")
  1707. def test_mesh_select_network(dev):
  1708. """Mesh network and SELECT_NETWORK"""
  1709. check_mesh_support(dev[0])
  1710. id0 = add_open_mesh_network(dev[0], start=False)
  1711. id1 = add_open_mesh_network(dev[1], start=False)
  1712. dev[0].select_network(id0)
  1713. dev[1].select_network(id1)
  1714. check_mesh_group_added(dev[0])
  1715. check_mesh_group_added(dev[1])
  1716. check_mesh_peer_connected(dev[0])
  1717. check_mesh_peer_connected(dev[1])
  1718. hwsim_utils.test_connectivity(dev[0], dev[1])