test_wpas_mesh.py 72 KB

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