test_wpas_mesh.py 83 KB

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