test_wpas_mesh.py 80 KB

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