test_wpas_mesh.py 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707
  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 add_mesh_secure_net(dev, psk=True, pmf=False, pairwise=None, group=None):
  194. id = dev.add_network()
  195. dev.set_network(id, "mode", "5")
  196. dev.set_network_quoted(id, "ssid", "wpas-mesh-sec")
  197. dev.set_network(id, "key_mgmt", "SAE")
  198. dev.set_network(id, "frequency", "2412")
  199. if psk:
  200. dev.set_network_quoted(id, "psk", "thisismypassphrase!")
  201. if pmf:
  202. dev.set_network(id, "ieee80211w", "2")
  203. if pairwise:
  204. dev.set_network(id, "pairwise", pairwise)
  205. if group:
  206. dev.set_network(id, "group", group)
  207. return id
  208. def test_wpas_mesh_secure(dev, apdev):
  209. """wpa_supplicant secure MESH network connectivity"""
  210. check_mesh_support(dev[0], secure=True)
  211. dev[0].request("SET sae_groups ")
  212. id = add_mesh_secure_net(dev[0])
  213. dev[0].mesh_group_add(id)
  214. dev[1].request("SET sae_groups ")
  215. id = add_mesh_secure_net(dev[1])
  216. dev[1].mesh_group_add(id)
  217. # Check for mesh joined
  218. check_mesh_group_added(dev[0])
  219. check_mesh_group_added(dev[1])
  220. # Check for peer connected
  221. check_mesh_peer_connected(dev[0])
  222. check_mesh_peer_connected(dev[1])
  223. # Test connectivity 0->1 and 1->0
  224. hwsim_utils.test_connectivity(dev[0], dev[1])
  225. state = dev[0].get_status_field("wpa_state")
  226. if state != "COMPLETED":
  227. raise Exception("Unexpected wpa_state on dev0: " + state)
  228. state = dev[1].get_status_field("wpa_state")
  229. if state != "COMPLETED":
  230. raise Exception("Unexpected wpa_state on dev1: " + state)
  231. def test_mesh_secure_pmf(dev, apdev):
  232. """Secure mesh network connectivity with PMF enabled"""
  233. check_mesh_support(dev[0], secure=True)
  234. dev[0].request("SET sae_groups ")
  235. id = add_mesh_secure_net(dev[0], pmf=True)
  236. dev[0].mesh_group_add(id)
  237. dev[1].request("SET sae_groups ")
  238. id = add_mesh_secure_net(dev[1], pmf=True)
  239. dev[1].mesh_group_add(id)
  240. # Check for mesh joined
  241. check_mesh_group_added(dev[0])
  242. check_mesh_group_added(dev[1])
  243. # Check for peer connected
  244. check_mesh_peer_connected(dev[0])
  245. check_mesh_peer_connected(dev[1])
  246. # Test connectivity 0->1 and 1->0
  247. hwsim_utils.test_connectivity(dev[0], dev[1])
  248. def run_mesh_secure(dev, cipher):
  249. if cipher not in dev[0].get_capability("pairwise"):
  250. raise HwsimSkip("Cipher %s not supported" % cipher)
  251. check_mesh_support(dev[0], secure=True)
  252. dev[0].request("SET sae_groups ")
  253. id = add_mesh_secure_net(dev[0], pairwise=cipher, group=cipher)
  254. dev[0].mesh_group_add(id)
  255. dev[1].request("SET sae_groups ")
  256. id = add_mesh_secure_net(dev[1], pairwise=cipher, group=cipher)
  257. dev[1].mesh_group_add(id)
  258. # Check for mesh joined
  259. check_mesh_group_added(dev[0])
  260. check_mesh_group_added(dev[1])
  261. # Check for peer connected
  262. check_mesh_peer_connected(dev[0])
  263. check_mesh_peer_connected(dev[1])
  264. # Test connectivity 0->1 and 1->0
  265. hwsim_utils.test_connectivity(dev[0], dev[1])
  266. def test_mesh_secure_ccmp(dev, apdev):
  267. """Secure mesh with CCMP"""
  268. run_mesh_secure(dev, "CCMP")
  269. def test_mesh_secure_gcmp(dev, apdev):
  270. """Secure mesh with GCMP"""
  271. run_mesh_secure(dev, "GCMP")
  272. def test_mesh_secure_gcmp_256(dev, apdev):
  273. """Secure mesh with GCMP-256"""
  274. run_mesh_secure(dev, "GCMP-256")
  275. def test_mesh_secure_ccmp_256(dev, apdev):
  276. """Secure mesh with CCMP-256"""
  277. run_mesh_secure(dev, "CCMP-256")
  278. def test_mesh_secure_invalid_pairwise_cipher(dev, apdev):
  279. """Secure mesh and invalid group cipher"""
  280. check_mesh_support(dev[0], secure=True)
  281. dev[0].request("SET sae_groups ")
  282. id = add_mesh_secure_net(dev[0], pairwise="TKIP", group="CCMP")
  283. if dev[0].mesh_group_add(id) != None:
  284. raise Exception("Unexpected group add success")
  285. ev = dev[0].wait_event(["mesh: Invalid pairwise cipher"], timeout=1)
  286. if ev is None:
  287. raise Exception("Invalid pairwise cipher not reported")
  288. def test_mesh_secure_invalid_group_cipher(dev, apdev):
  289. """Secure mesh and invalid group cipher"""
  290. check_mesh_support(dev[0], secure=True)
  291. dev[0].request("SET sae_groups ")
  292. id = add_mesh_secure_net(dev[0], pairwise="CCMP", group="TKIP")
  293. if dev[0].mesh_group_add(id) != None:
  294. raise Exception("Unexpected group add success")
  295. ev = dev[0].wait_event(["mesh: Invalid group cipher"], timeout=1)
  296. if ev is None:
  297. raise Exception("Invalid group cipher not reported")
  298. def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev):
  299. """wpa_supplicant secure MESH and SAE group mismatch"""
  300. check_mesh_support(dev[0], secure=True)
  301. addr0 = dev[0].p2p_interface_addr()
  302. addr1 = dev[1].p2p_interface_addr()
  303. addr2 = dev[2].p2p_interface_addr()
  304. dev[0].request("SET sae_groups 19 25")
  305. id = add_mesh_secure_net(dev[0])
  306. dev[0].mesh_group_add(id)
  307. dev[1].request("SET sae_groups 19")
  308. id = add_mesh_secure_net(dev[1])
  309. dev[1].mesh_group_add(id)
  310. dev[2].request("SET sae_groups 26")
  311. id = add_mesh_secure_net(dev[2])
  312. dev[2].mesh_group_add(id)
  313. check_mesh_group_added(dev[0])
  314. check_mesh_group_added(dev[1])
  315. check_mesh_group_added(dev[2])
  316. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
  317. if ev is None:
  318. raise Exception("Remote peer did not connect")
  319. if addr1 not in ev:
  320. raise Exception("Unexpected peer connected: " + ev)
  321. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
  322. if ev is None:
  323. raise Exception("Remote peer did not connect")
  324. if addr0 not in ev:
  325. raise Exception("Unexpected peer connected: " + ev)
  326. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  327. if ev is not None:
  328. raise Exception("Unexpected peer connection at dev[2]: " + ev)
  329. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  330. if ev is not None:
  331. raise Exception("Unexpected peer connection: " + ev)
  332. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  333. if ev is not None:
  334. raise Exception("Unexpected peer connection: " + ev)
  335. dev[0].request("SET sae_groups ")
  336. dev[1].request("SET sae_groups ")
  337. dev[2].request("SET sae_groups ")
  338. def test_wpas_mesh_secure_sae_group_negotiation(dev, apdev):
  339. """wpa_supplicant secure MESH and SAE group negotiation"""
  340. check_mesh_support(dev[0], secure=True)
  341. addr0 = dev[0].own_addr()
  342. addr1 = dev[1].own_addr()
  343. #dev[0].request("SET sae_groups 21 20 25 26")
  344. dev[0].request("SET sae_groups 25")
  345. id = add_mesh_secure_net(dev[0])
  346. dev[0].mesh_group_add(id)
  347. dev[1].request("SET sae_groups 19 25")
  348. id = add_mesh_secure_net(dev[1])
  349. dev[1].mesh_group_add(id)
  350. check_mesh_group_added(dev[0])
  351. check_mesh_group_added(dev[1])
  352. check_mesh_peer_connected(dev[0])
  353. check_mesh_peer_connected(dev[1])
  354. dev[0].request("SET sae_groups ")
  355. dev[1].request("SET sae_groups ")
  356. def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
  357. """wpa_supplicant secure MESH and missing SAE password"""
  358. check_mesh_support(dev[0], secure=True)
  359. id = add_mesh_secure_net(dev[0], psk=False)
  360. dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
  361. dev[0].mesh_group_add(id)
  362. ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
  363. timeout=5)
  364. if ev is None:
  365. raise Exception("Timeout on mesh start event")
  366. if "MESH-GROUP-STARTED" in ev:
  367. raise Exception("Unexpected mesh group start")
  368. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
  369. if ev is not None:
  370. raise Exception("Unexpected mesh group start")
  371. def test_wpas_mesh_secure_no_auto(dev, apdev):
  372. """wpa_supplicant secure MESH network connectivity"""
  373. check_mesh_support(dev[0], secure=True)
  374. dev[0].request("SET sae_groups 19")
  375. id = add_mesh_secure_net(dev[0])
  376. dev[0].mesh_group_add(id)
  377. dev[1].request("SET sae_groups 19")
  378. id = add_mesh_secure_net(dev[1])
  379. dev[1].set_network(id, "no_auto_peer", "1")
  380. dev[1].mesh_group_add(id)
  381. # Check for mesh joined
  382. check_mesh_group_added(dev[0])
  383. check_mesh_group_added(dev[1])
  384. # Check for peer connected
  385. check_mesh_peer_connected(dev[0], timeout=30)
  386. check_mesh_peer_connected(dev[1])
  387. # Test connectivity 0->1 and 1->0
  388. hwsim_utils.test_connectivity(dev[0], dev[1])
  389. dev[0].request("SET sae_groups ")
  390. dev[1].request("SET sae_groups ")
  391. def test_wpas_mesh_secure_dropped_frame(dev, apdev):
  392. """Secure mesh network connectivity when the first plink Open is dropped"""
  393. check_mesh_support(dev[0], secure=True)
  394. dev[0].request("SET ext_mgmt_frame_handling 1")
  395. dev[0].request("SET sae_groups ")
  396. id = add_mesh_secure_net(dev[0])
  397. dev[0].mesh_group_add(id)
  398. dev[1].request("SET sae_groups ")
  399. id = add_mesh_secure_net(dev[1])
  400. dev[1].mesh_group_add(id)
  401. # Check for mesh joined
  402. check_mesh_group_added(dev[0])
  403. check_mesh_group_added(dev[1])
  404. # Drop the first Action frame (plink Open) to test unexpected order of
  405. # Confirm/Open messages.
  406. count = 0
  407. while True:
  408. count += 1
  409. if count > 10:
  410. raise Exception("Did not see Action frames")
  411. rx_msg = dev[0].mgmt_rx()
  412. if rx_msg is None:
  413. raise Exception("MGMT-RX timeout")
  414. if rx_msg['subtype'] == 13:
  415. logger.info("Drop the first Action frame")
  416. break
  417. 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'))):
  418. raise Exception("MGMT_RX_PROCESS failed")
  419. dev[0].request("SET ext_mgmt_frame_handling 0")
  420. # Check for peer connected
  421. check_mesh_peer_connected(dev[0])
  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. def test_wpas_mesh_ctrl(dev):
  426. """wpa_supplicant ctrl_iface mesh command error cases"""
  427. check_mesh_support(dev[0])
  428. if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
  429. raise Exception("Unexpected MESH_GROUP_ADD success")
  430. id = dev[0].add_network()
  431. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  432. raise Exception("Unexpected MESH_GROUP_ADD success")
  433. dev[0].set_network(id, "mode", "5")
  434. dev[0].set_network(id, "key_mgmt", "WPA-PSK")
  435. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  436. raise Exception("Unexpected MESH_GROUP_ADD success")
  437. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
  438. raise Exception("Unexpected MESH_GROUP_REMOVE success")
  439. def test_wpas_mesh_dynamic_interface(dev):
  440. """wpa_supplicant mesh with dynamic interface"""
  441. check_mesh_support(dev[0])
  442. mesh0 = None
  443. mesh1 = None
  444. try:
  445. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  446. if "FAIL" in mesh0:
  447. raise Exception("MESH_INTERFACE_ADD failed")
  448. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  449. if "FAIL" in mesh1:
  450. raise Exception("MESH_INTERFACE_ADD failed")
  451. wpas0 = WpaSupplicant(ifname=mesh0)
  452. wpas1 = WpaSupplicant(ifname=mesh1)
  453. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  454. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  455. add_open_mesh_network(wpas0)
  456. add_open_mesh_network(wpas1)
  457. check_mesh_group_added(wpas0)
  458. check_mesh_group_added(wpas1)
  459. check_mesh_peer_connected(wpas0)
  460. check_mesh_peer_connected(wpas1)
  461. hwsim_utils.test_connectivity(wpas0, wpas1)
  462. # Must not allow MESH_GROUP_REMOVE on dynamic interface
  463. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
  464. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  465. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
  466. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  467. # Must not allow MESH_GROUP_REMOVE on another radio interface
  468. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
  469. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  470. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
  471. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  472. wpas0.remove_ifname()
  473. wpas1.remove_ifname()
  474. if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  475. raise Exception("MESH_GROUP_REMOVE failed")
  476. if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  477. raise Exception("MESH_GROUP_REMOVE failed")
  478. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  479. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  480. if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  481. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  482. logger.info("Make sure another dynamic group can be added")
  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. finally:
  501. if mesh0:
  502. dev[0].request("MESH_GROUP_REMOVE " + mesh0)
  503. if mesh1:
  504. dev[1].request("MESH_GROUP_REMOVE " + mesh1)
  505. def test_wpas_mesh_max_peering(dev, apdev, params):
  506. """Mesh max peering limit"""
  507. check_mesh_support(dev[0])
  508. try:
  509. dev[0].request("SET max_peer_links 1")
  510. # first, connect dev[0] and dev[1]
  511. add_open_mesh_network(dev[0])
  512. add_open_mesh_network(dev[1])
  513. for i in range(2):
  514. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  515. if ev is None:
  516. raise Exception("dev%d did not connect with any peer" % i)
  517. # add dev[2] which will try to connect with both dev[0] and dev[1],
  518. # but can complete connection only with dev[1]
  519. add_open_mesh_network(dev[2])
  520. for i in range(1, 3):
  521. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  522. if ev is None:
  523. raise Exception("dev%d did not connect the second peer" % i)
  524. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  525. if ev is not None:
  526. raise Exception("dev0 connection beyond max peering limit")
  527. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  528. if ev is not None:
  529. raise Exception("dev2 reported unexpected peering: " + ev)
  530. for i in range(3):
  531. dev[i].mesh_group_remove()
  532. check_mesh_group_removed(dev[i])
  533. finally:
  534. dev[0].request("SET max_peer_links 99")
  535. addr0 = dev[0].own_addr()
  536. addr1 = dev[1].own_addr()
  537. addr2 = dev[2].own_addr()
  538. capfile = os.path.join(params['logdir'], "hwsim0.pcapng")
  539. filt = "wlan.fc.type_subtype == 8"
  540. out = run_tshark(capfile, filt, [ "wlan.sa", "wlan.mesh.config.cap" ])
  541. pkts = out.splitlines()
  542. one = [ 0, 0, 0 ]
  543. zero = [ 0, 0, 0 ]
  544. for pkt in pkts:
  545. addr, cap = pkt.split('\t')
  546. cap = int(cap, 16)
  547. if addr == addr0:
  548. idx = 0
  549. elif addr == addr1:
  550. idx = 1
  551. elif addr == addr2:
  552. idx = 2
  553. else:
  554. continue
  555. if cap & 0x01:
  556. one[idx] += 1
  557. else:
  558. zero[idx] += 1
  559. logger.info("one: " + str(one))
  560. logger.info("zero: " + str(zero))
  561. if zero[0] == 0:
  562. raise Exception("Accepting Additional Mesh Peerings not cleared")
  563. if one[0] == 0:
  564. raise Exception("Accepting Additional Mesh Peerings was not set in the first Beacon frame")
  565. if zero[1] > 0 or zero[2] > 0 or one[1] == 0 or one[2] == 0:
  566. raise Exception("Unexpected value in Accepting Additional Mesh Peerings from other STAs")
  567. def test_wpas_mesh_open_5ghz(dev, apdev):
  568. """wpa_supplicant open MESH network on 5 GHz band"""
  569. try:
  570. _test_wpas_mesh_open_5ghz(dev, apdev)
  571. finally:
  572. subprocess.call(['iw', 'reg', 'set', '00'])
  573. dev[0].flush_scan_cache()
  574. dev[1].flush_scan_cache()
  575. def _test_wpas_mesh_open_5ghz(dev, apdev):
  576. check_mesh_support(dev[0])
  577. subprocess.call(['iw', 'reg', 'set', 'US'])
  578. for i in range(2):
  579. for j in range(5):
  580. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  581. if ev is None:
  582. raise Exception("No regdom change event")
  583. if "alpha2=US" in ev:
  584. break
  585. add_open_mesh_network(dev[i], freq="5180")
  586. # Check for mesh joined
  587. check_mesh_group_added(dev[0])
  588. check_mesh_group_added(dev[1])
  589. # Check for peer connected
  590. check_mesh_peer_connected(dev[0])
  591. check_mesh_peer_connected(dev[1])
  592. # Test connectivity 0->1 and 1->0
  593. hwsim_utils.test_connectivity(dev[0], dev[1])
  594. def test_wpas_mesh_open_vht_80p80(dev, apdev):
  595. """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
  596. try:
  597. _test_wpas_mesh_open_vht_80p80(dev, apdev)
  598. finally:
  599. subprocess.call(['iw', 'reg', 'set', '00'])
  600. dev[0].flush_scan_cache()
  601. dev[1].flush_scan_cache()
  602. def _test_wpas_mesh_open_vht_80p80(dev, apdev):
  603. check_mesh_support(dev[0])
  604. subprocess.call(['iw', 'reg', 'set', 'US'])
  605. for i in range(2):
  606. for j in range(5):
  607. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  608. if ev is None:
  609. raise Exception("No regdom change event")
  610. if "alpha2=US" in ev:
  611. break
  612. add_open_mesh_network(dev[i], freq="5180", chwidth=3)
  613. # Check for mesh joined
  614. check_mesh_group_added(dev[0])
  615. check_mesh_group_added(dev[1])
  616. # Check for peer connected
  617. check_mesh_peer_connected(dev[0])
  618. check_mesh_peer_connected(dev[1])
  619. # Test connectivity 0->1 and 1->0
  620. hwsim_utils.test_connectivity(dev[0], dev[1])
  621. sig = dev[0].request("SIGNAL_POLL").splitlines()
  622. if "WIDTH=80+80 MHz" not in sig:
  623. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  624. if "CENTER_FRQ1=5210" not in sig:
  625. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  626. if "CENTER_FRQ2=5775" not in sig:
  627. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  628. sig = dev[1].request("SIGNAL_POLL").splitlines()
  629. if "WIDTH=80+80 MHz" not in sig:
  630. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  631. if "CENTER_FRQ1=5210" not in sig:
  632. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  633. if "CENTER_FRQ2=5775" not in sig:
  634. raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
  635. def test_mesh_open_vht_160(dev, apdev):
  636. """Open mesh network on VHT 160 MHz channel"""
  637. try:
  638. _test_mesh_open_vht_160(dev, apdev)
  639. finally:
  640. subprocess.call(['iw', 'reg', 'set', '00'])
  641. dev[0].flush_scan_cache()
  642. dev[1].flush_scan_cache()
  643. def _test_mesh_open_vht_160(dev, apdev):
  644. check_mesh_support(dev[0])
  645. subprocess.call(['iw', 'reg', 'set', 'ZA'])
  646. for i in range(2):
  647. for j in range(5):
  648. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  649. if ev is None:
  650. raise Exception("No regdom change event")
  651. if "alpha2=ZA" in ev:
  652. break
  653. cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
  654. reg = cmd.stdout.read()
  655. if "@ 160)" not in reg:
  656. raise HwsimSkip("160 MHz channel not supported in regulatory information")
  657. add_open_mesh_network(dev[i], freq="5520", chwidth=2)
  658. # Check for mesh joined
  659. check_mesh_group_added(dev[0])
  660. check_mesh_group_added(dev[1])
  661. # Check for peer connected
  662. check_mesh_peer_connected(dev[0])
  663. check_mesh_peer_connected(dev[1])
  664. # Test connectivity 0->1 and 1->0
  665. hwsim_utils.test_connectivity(dev[0], dev[1])
  666. sig = dev[0].request("SIGNAL_POLL").splitlines()
  667. if "WIDTH=160 MHz" not in sig:
  668. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  669. if "FREQUENCY=5520" not in sig:
  670. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  671. sig = dev[1].request("SIGNAL_POLL").splitlines()
  672. if "WIDTH=160 MHz" not in sig:
  673. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  674. if "FREQUENCY=5520" not in sig:
  675. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  676. def test_wpas_mesh_password_mismatch(dev, apdev):
  677. """Mesh network and one device with mismatching password"""
  678. check_mesh_support(dev[0], secure=True)
  679. dev[0].request("SET sae_groups ")
  680. id = add_mesh_secure_net(dev[0])
  681. dev[0].mesh_group_add(id)
  682. dev[1].request("SET sae_groups ")
  683. id = add_mesh_secure_net(dev[1])
  684. dev[1].mesh_group_add(id)
  685. dev[2].request("SET sae_groups ")
  686. id = add_mesh_secure_net(dev[2])
  687. dev[2].set_network_quoted(id, "psk", "wrong password")
  688. dev[2].mesh_group_add(id)
  689. # The two peers with matching password need to be able to connect
  690. check_mesh_group_added(dev[0])
  691. check_mesh_group_added(dev[1])
  692. check_mesh_peer_connected(dev[0])
  693. check_mesh_peer_connected(dev[1])
  694. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  695. if ev is None:
  696. raise Exception("dev2 did not report auth failure (1)")
  697. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  698. if ev is None:
  699. raise Exception("dev2 did not report auth failure (2)")
  700. count = 0
  701. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  702. if ev is None:
  703. logger.info("dev0 did not report auth failure")
  704. else:
  705. if "addr=" + dev[2].own_addr() not in ev:
  706. raise Exception("Unexpected peer address in dev0 event: " + ev)
  707. count += 1
  708. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  709. if ev is None:
  710. logger.info("dev1 did not report auth failure")
  711. else:
  712. if "addr=" + dev[2].own_addr() not in ev:
  713. raise Exception("Unexpected peer address in dev1 event: " + ev)
  714. count += 1
  715. hwsim_utils.test_connectivity(dev[0], dev[1])
  716. for i in range(2):
  717. try:
  718. hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
  719. raise Exception("Data connectivity test passed unexpectedly")
  720. except Exception, e:
  721. if "data delivery failed" not in str(e):
  722. raise
  723. if count == 0:
  724. raise Exception("Neither dev0 nor dev1 reported auth failure")
  725. def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
  726. """Mesh password mismatch and retry [long]"""
  727. if not params['long']:
  728. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  729. check_mesh_support(dev[0], secure=True)
  730. dev[0].request("SET sae_groups ")
  731. id = add_mesh_secure_net(dev[0])
  732. dev[0].mesh_group_add(id)
  733. dev[1].request("SET sae_groups ")
  734. id = add_mesh_secure_net(dev[1])
  735. dev[1].set_network_quoted(id, "psk", "wrong password")
  736. dev[1].mesh_group_add(id)
  737. # Check for mesh joined
  738. check_mesh_group_added(dev[0])
  739. check_mesh_group_added(dev[1])
  740. for i in range(4):
  741. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  742. if ev is None:
  743. raise Exception("dev0 did not report auth failure (%d)" % i)
  744. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  745. if ev is None:
  746. raise Exception("dev1 did not report auth failure (%d)" % i)
  747. ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  748. if ev is None:
  749. raise Exception("dev0 did not report auth blocked")
  750. ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  751. if ev is None:
  752. raise Exception("dev1 did not report auth blocked")
  753. def test_mesh_wpa_auth_init_oom(dev, apdev):
  754. """Secure mesh network setup failing due to wpa_init() OOM"""
  755. check_mesh_support(dev[0], secure=True)
  756. dev[0].request("SET sae_groups ")
  757. with alloc_fail(dev[0], 1, "wpa_init"):
  758. id = add_mesh_secure_net(dev[0])
  759. dev[0].mesh_group_add(id)
  760. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
  761. if ev is not None:
  762. raise Exception("Unexpected mesh group start during OOM")
  763. def test_mesh_wpa_init_fail(dev, apdev):
  764. """Secure mesh network setup local failure"""
  765. check_mesh_support(dev[0], secure=True)
  766. dev[0].request("SET sae_groups ")
  767. with fail_test(dev[0], 1, "os_get_random;=__mesh_rsn_auth_init"):
  768. id = add_mesh_secure_net(dev[0])
  769. dev[0].mesh_group_add(id)
  770. wait_fail_trigger(dev[0], "GET_FAIL")
  771. dev[0].dump_monitor()
  772. with alloc_fail(dev[0], 1, "mesh_rsn_auth_init"):
  773. id = add_mesh_secure_net(dev[0])
  774. dev[0].mesh_group_add(id)
  775. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  776. dev[0].dump_monitor()
  777. with fail_test(dev[0], 1, "os_get_random;mesh_rsn_init_ampe_sta"):
  778. id = add_mesh_secure_net(dev[0])
  779. dev[0].mesh_group_add(id)
  780. dev[1].request("SET sae_groups ")
  781. id = add_mesh_secure_net(dev[1])
  782. dev[1].mesh_group_add(id)
  783. wait_fail_trigger(dev[0], "GET_FAIL")
  784. def test_wpas_mesh_reconnect(dev, apdev):
  785. """Secure mesh network plink counting during reconnection"""
  786. check_mesh_support(dev[0])
  787. try:
  788. _test_wpas_mesh_reconnect(dev)
  789. finally:
  790. dev[0].request("SET max_peer_links 99")
  791. def _test_wpas_mesh_reconnect(dev):
  792. dev[0].request("SET max_peer_links 2")
  793. dev[0].request("SET sae_groups ")
  794. id = add_mesh_secure_net(dev[0])
  795. dev[0].set_network(id, "beacon_int", "100")
  796. dev[0].mesh_group_add(id)
  797. dev[1].request("SET sae_groups ")
  798. id = add_mesh_secure_net(dev[1])
  799. dev[1].mesh_group_add(id)
  800. check_mesh_group_added(dev[0])
  801. check_mesh_group_added(dev[1])
  802. check_mesh_peer_connected(dev[0])
  803. check_mesh_peer_connected(dev[1])
  804. for i in range(3):
  805. # Drop incoming management frames to avoid handling link close
  806. dev[0].request("SET ext_mgmt_frame_handling 1")
  807. dev[1].mesh_group_remove()
  808. check_mesh_group_removed(dev[1])
  809. dev[1].request("FLUSH")
  810. dev[0].request("SET ext_mgmt_frame_handling 0")
  811. id = add_mesh_secure_net(dev[1])
  812. dev[1].mesh_group_add(id)
  813. check_mesh_group_added(dev[1])
  814. check_mesh_peer_connected(dev[1])
  815. dev[0].dump_monitor()
  816. dev[1].dump_monitor()
  817. def test_wpas_mesh_gate_forwarding(dev, apdev, p):
  818. """Mesh forwards traffic to unknown sta to mesh gates"""
  819. addr0 = dev[0].own_addr()
  820. addr1 = dev[1].own_addr()
  821. addr2 = dev[2].own_addr()
  822. external_sta = '02:11:22:33:44:55'
  823. # start 3 node connected mesh
  824. check_mesh_support(dev[0])
  825. for i in range(3):
  826. add_open_mesh_network(dev[i])
  827. check_mesh_group_added(dev[i])
  828. for i in range(3):
  829. check_mesh_peer_connected(dev[i])
  830. hwsim_utils.test_connectivity(dev[0], dev[1])
  831. hwsim_utils.test_connectivity(dev[1], dev[2])
  832. hwsim_utils.test_connectivity(dev[0], dev[2])
  833. # dev0 and dev1 are mesh gates
  834. subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
  835. 'mesh_gate_announcements=1'])
  836. subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
  837. 'mesh_gate_announcements=1'])
  838. # wait for gate announcement frames
  839. time.sleep(1)
  840. # data frame from dev2 -> external sta should be sent to both gates
  841. dev[2].request("DATA_TEST_CONFIG 1")
  842. dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
  843. dev[2].request("DATA_TEST_CONFIG 0")
  844. capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
  845. filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
  846. external_sta)
  847. for i in range(15):
  848. da = run_tshark(capfile, filt, [ "wlan.da" ])
  849. if addr0 in da and addr1 in da:
  850. logger.debug("Frames seen in tshark iteration %d" % i)
  851. break
  852. time.sleep(0.3)
  853. if addr0 not in da:
  854. raise Exception("Frame to gate %s not observed" % addr0)
  855. if addr1 not in da:
  856. raise Exception("Frame to gate %s not observed" % addr1)
  857. def test_wpas_mesh_pmksa_caching(dev, apdev):
  858. """Secure mesh network and PMKSA caching"""
  859. check_mesh_support(dev[0], secure=True)
  860. dev[0].request("SET sae_groups ")
  861. id = add_mesh_secure_net(dev[0])
  862. dev[0].mesh_group_add(id)
  863. dev[1].request("SET sae_groups ")
  864. id = add_mesh_secure_net(dev[1])
  865. dev[1].mesh_group_add(id)
  866. # Check for mesh joined
  867. check_mesh_group_added(dev[0])
  868. check_mesh_group_added(dev[1])
  869. # Check for peer connected
  870. check_mesh_peer_connected(dev[0])
  871. check_mesh_peer_connected(dev[1])
  872. addr0 = dev[0].own_addr()
  873. addr1 = dev[1].own_addr()
  874. pmksa0 = dev[0].get_pmksa(addr1)
  875. pmksa1 = dev[1].get_pmksa(addr0)
  876. if pmksa0 is None or pmksa1 is None:
  877. raise Exception("No PMKSA cache entry created")
  878. if pmksa0['pmkid'] != pmksa1['pmkid']:
  879. raise Exception("PMKID mismatch in PMKSA cache entries")
  880. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  881. raise Exception("Failed to remove peer")
  882. pmksa0b = dev[0].get_pmksa(addr1)
  883. if pmksa0b is None:
  884. raise Exception("PMKSA cache entry not maintained")
  885. time.sleep(0.1)
  886. if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
  887. raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
  888. def test_wpas_mesh_pmksa_caching2(dev, apdev):
  889. """Secure mesh network and PMKSA caching with no_auto_peer=1"""
  890. check_mesh_support(dev[0], secure=True)
  891. addr0 = dev[0].own_addr()
  892. addr1 = dev[1].own_addr()
  893. dev[0].request("SET sae_groups ")
  894. id = add_mesh_secure_net(dev[0])
  895. dev[0].set_network(id, "no_auto_peer", "1")
  896. dev[0].mesh_group_add(id)
  897. dev[1].request("SET sae_groups ")
  898. id = add_mesh_secure_net(dev[1])
  899. dev[1].set_network(id, "no_auto_peer", "1")
  900. dev[1].mesh_group_add(id)
  901. # Check for mesh joined
  902. check_mesh_group_added(dev[0])
  903. check_mesh_group_added(dev[1])
  904. # Check for peer connected
  905. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  906. if ev is None:
  907. raise Exception("Missing no-initiate message")
  908. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  909. raise Exception("MESH_PEER_ADD failed")
  910. check_mesh_peer_connected(dev[0])
  911. check_mesh_peer_connected(dev[1])
  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. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  924. if ev is None:
  925. raise Exception("Missing no-initiate message (2)")
  926. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  927. raise Exception("MESH_PEER_ADD failed (2)")
  928. check_mesh_peer_connected(dev[0])
  929. check_mesh_peer_connected(dev[1])
  930. pmksa0c = dev[0].get_pmksa(addr1)
  931. pmksa1c = dev[1].get_pmksa(addr0)
  932. if pmksa0c is None or pmksa1c is None:
  933. raise Exception("No PMKSA cache entry created (2)")
  934. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  935. raise Exception("PMKID mismatch in PMKSA cache entries")
  936. if pmksa0['pmkid'] != pmksa0c['pmkid']:
  937. raise Exception("PMKID changed")
  938. hwsim_utils.test_connectivity(dev[0], dev[1])
  939. def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
  940. """Secure mesh network and PMKSA caching with no PMKID match"""
  941. check_mesh_support(dev[0], secure=True)
  942. addr0 = dev[0].own_addr()
  943. addr1 = dev[1].own_addr()
  944. dev[0].request("SET sae_groups ")
  945. id = add_mesh_secure_net(dev[0])
  946. dev[0].set_network(id, "no_auto_peer", "1")
  947. dev[0].mesh_group_add(id)
  948. dev[1].request("SET sae_groups ")
  949. id = add_mesh_secure_net(dev[1])
  950. dev[1].set_network(id, "no_auto_peer", "1")
  951. dev[1].mesh_group_add(id)
  952. # Check for mesh joined
  953. check_mesh_group_added(dev[0])
  954. check_mesh_group_added(dev[1])
  955. # Check for peer connected
  956. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  957. if ev is None:
  958. raise Exception("Missing no-initiate message")
  959. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  960. raise Exception("MESH_PEER_ADD failed")
  961. check_mesh_peer_connected(dev[0])
  962. check_mesh_peer_connected(dev[1])
  963. pmksa0 = dev[0].get_pmksa(addr1)
  964. pmksa1 = dev[1].get_pmksa(addr0)
  965. if pmksa0 is None or pmksa1 is None:
  966. raise Exception("No PMKSA cache entry created")
  967. if pmksa0['pmkid'] != pmksa1['pmkid']:
  968. raise Exception("PMKID mismatch in PMKSA cache entries")
  969. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  970. raise Exception("Failed to remove peer")
  971. if "OK" not in dev[1].request("PMKSA_FLUSH"):
  972. raise Exception("Failed to flush PMKSA cache")
  973. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  974. if ev is None:
  975. raise Exception("Missing no-initiate message (2)")
  976. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  977. raise Exception("MESH_PEER_ADD failed (2)")
  978. check_mesh_peer_connected(dev[0])
  979. check_mesh_peer_connected(dev[1])
  980. pmksa0c = dev[0].get_pmksa(addr1)
  981. pmksa1c = dev[1].get_pmksa(addr0)
  982. if pmksa0c is None or pmksa1c is None:
  983. raise Exception("No PMKSA cache entry created (2)")
  984. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  985. raise Exception("PMKID mismatch in PMKSA cache entries")
  986. if pmksa0['pmkid'] == pmksa0c['pmkid']:
  987. raise Exception("PMKID did not change")
  988. hwsim_utils.test_connectivity(dev[0], dev[1])
  989. def test_mesh_pmksa_caching_oom(dev, apdev):
  990. """Secure mesh network and PMKSA caching failing due to OOM"""
  991. check_mesh_support(dev[0], secure=True)
  992. addr0 = dev[0].own_addr()
  993. addr1 = dev[1].own_addr()
  994. dev[0].request("SET sae_groups ")
  995. id = add_mesh_secure_net(dev[0])
  996. dev[0].set_network(id, "no_auto_peer", "1")
  997. dev[0].mesh_group_add(id)
  998. dev[1].request("SET sae_groups ")
  999. id = add_mesh_secure_net(dev[1])
  1000. dev[1].set_network(id, "no_auto_peer", "1")
  1001. dev[1].mesh_group_add(id)
  1002. # Check for mesh joined
  1003. check_mesh_group_added(dev[0])
  1004. check_mesh_group_added(dev[1])
  1005. # Check for peer connected
  1006. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1007. if ev is None:
  1008. raise Exception("Missing no-initiate message")
  1009. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1010. raise Exception("MESH_PEER_ADD failed")
  1011. check_mesh_peer_connected(dev[0])
  1012. check_mesh_peer_connected(dev[1])
  1013. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1014. raise Exception("Failed to remove peer")
  1015. pmksa0b = dev[0].get_pmksa(addr1)
  1016. if pmksa0b is None:
  1017. raise Exception("PMKSA cache entry not maintained")
  1018. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1019. if ev is None:
  1020. raise Exception("Missing no-initiate message (2)")
  1021. with alloc_fail(dev[0], 1, "wpa_auth_sta_init;mesh_rsn_auth_sae_sta"):
  1022. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1023. raise Exception("MESH_PEER_ADD failed (2)")
  1024. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1025. def test_mesh_oom(dev, apdev):
  1026. """Mesh network setup failing due to OOM"""
  1027. check_mesh_support(dev[0], secure=True)
  1028. dev[0].request("SET sae_groups ")
  1029. with alloc_fail(dev[0], 1, "mesh_config_create"):
  1030. add_open_mesh_network(dev[0])
  1031. ev = dev[0].wait_event(["Failed to init mesh"])
  1032. if ev is None:
  1033. raise Exception("Init failure not reported")
  1034. with alloc_fail(dev[0], 4, "=wpa_supplicant_mesh_init"):
  1035. add_open_mesh_network(dev[0], basic_rates="60 120 240")
  1036. ev = dev[0].wait_event(["Failed to init mesh"])
  1037. if ev is None:
  1038. raise Exception("Init failure not reported")
  1039. for i in range(1, 66):
  1040. dev[0].dump_monitor()
  1041. logger.info("Test instance %d" % i)
  1042. try:
  1043. with alloc_fail(dev[0], i, "wpa_supplicant_mesh_init"):
  1044. add_open_mesh_network(dev[0])
  1045. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1046. ev = dev[0].wait_event(["Failed to init mesh",
  1047. "MESH-GROUP-STARTED"])
  1048. if ev is None:
  1049. raise Exception("Init failure not reported")
  1050. except Exception, e:
  1051. if i < 15:
  1052. raise
  1053. logger.info("Ignore no-oom for i=%d" % i)
  1054. with alloc_fail(dev[0], 5, "=wpa_supplicant_mesh_init"):
  1055. id = add_mesh_secure_net(dev[0])
  1056. dev[0].mesh_group_add(id)
  1057. ev = dev[0].wait_event(["Failed to init mesh"])
  1058. if ev is None:
  1059. raise Exception("Init failure not reported")
  1060. def test_mesh_add_interface_oom(dev):
  1061. """wpa_supplicant mesh with dynamic interface addition failing"""
  1062. check_mesh_support(dev[0])
  1063. for i in range(1, 3):
  1064. mesh = None
  1065. try:
  1066. with alloc_fail(dev[0], i, "wpas_mesh_add_interface"):
  1067. mesh = dev[0].request("MESH_INTERFACE_ADD").strip()
  1068. finally:
  1069. if mesh and mesh != "FAIL":
  1070. dev[0].request("MESH_GROUP_REMOVE " + mesh)
  1071. def test_mesh_scan_oom(dev):
  1072. """wpa_supplicant mesh scan results and OOM"""
  1073. check_mesh_support(dev[0])
  1074. add_open_mesh_network(dev[0])
  1075. check_mesh_group_added(dev[0])
  1076. for i in range(5):
  1077. dev[1].scan(freq="2412")
  1078. res = dev[1].request("SCAN_RESULTS")
  1079. if "[MESH]" in res:
  1080. break
  1081. for r in res.splitlines():
  1082. if "[MESH]" in r:
  1083. break
  1084. bssid = r.split('\t')[0]
  1085. bss = dev[1].get_bss(bssid)
  1086. if bss is None:
  1087. raise Exception("Could not get BSS entry for mesh")
  1088. for i in range(1, 3):
  1089. with alloc_fail(dev[1], i, "mesh_attr_text"):
  1090. bss = dev[1].get_bss(bssid)
  1091. if bss and "mesh_id" in bss:
  1092. raise Exception("Unexpected BSS result during OOM")
  1093. def test_mesh_drv_fail(dev, apdev):
  1094. """Mesh network setup failing due to driver command failure"""
  1095. check_mesh_support(dev[0], secure=True)
  1096. dev[0].request("SET sae_groups ")
  1097. with fail_test(dev[0], 1, "nl80211_join_mesh"):
  1098. add_open_mesh_network(dev[0])
  1099. ev = dev[0].wait_event(["mesh join error"])
  1100. if ev is None:
  1101. raise Exception("Join failure not reported")
  1102. dev[0].dump_monitor()
  1103. with fail_test(dev[0], 1, "wpa_driver_nl80211_if_add"):
  1104. if "FAIL" not in dev[0].request("MESH_INTERFACE_ADD").strip():
  1105. raise Exception("Interface added unexpectedly")
  1106. dev[0].dump_monitor()
  1107. with fail_test(dev[0], 1, "wpa_driver_nl80211_init_mesh"):
  1108. add_open_mesh_network(dev[0])
  1109. ev = dev[0].wait_event(["Could not join mesh"])
  1110. if ev is None:
  1111. raise Exception("Join failure not reported")
  1112. def test_mesh_sae_groups_invalid(dev, apdev):
  1113. """Mesh with invalid SAE group configuration"""
  1114. check_mesh_support(dev[0], secure=True)
  1115. dev[0].request("SET sae_groups 25")
  1116. id = add_mesh_secure_net(dev[0])
  1117. dev[0].mesh_group_add(id)
  1118. dev[1].request("SET sae_groups 123 122 121")
  1119. id = add_mesh_secure_net(dev[1])
  1120. dev[1].mesh_group_add(id)
  1121. check_mesh_group_added(dev[0])
  1122. check_mesh_group_added(dev[1])
  1123. ev = dev[0].wait_event(["new peer notification"], timeout=10)
  1124. if ev is None:
  1125. raise Exception("dev[0] did not see peer")
  1126. ev = dev[1].wait_event(["new peer notification"], timeout=10)
  1127. if ev is None:
  1128. raise Exception("dev[1] did not see peer")
  1129. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  1130. if ev is not None:
  1131. raise Exception("Unexpected connection(0)")
  1132. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1133. if ev is not None:
  1134. raise Exception("Unexpected connection(1)")
  1135. # Additional coverage in mesh_rsn_sae_group() with non-zero
  1136. # wpa_s->mesh_rsn->sae_group_index.
  1137. dev[0].dump_monitor()
  1138. dev[1].dump_monitor()
  1139. id = add_mesh_secure_net(dev[2])
  1140. dev[2].mesh_group_add(id)
  1141. check_mesh_group_added(dev[2])
  1142. check_mesh_peer_connected(dev[0])
  1143. check_mesh_peer_connected(dev[2])
  1144. ev = dev[1].wait_event(["new peer notification"], timeout=10)
  1145. if ev is None:
  1146. raise Exception("dev[1] did not see peer(2)")
  1147. dev[0].dump_monitor()
  1148. dev[1].dump_monitor()
  1149. dev[2].dump_monitor()
  1150. dev[0].request("SET sae_groups ")
  1151. dev[1].request("SET sae_groups ")
  1152. def test_mesh_sae_failure(dev, apdev):
  1153. """Mesh and local SAE failures"""
  1154. check_mesh_support(dev[0], secure=True)
  1155. dev[0].request("SET sae_groups ")
  1156. dev[1].request("SET sae_groups ")
  1157. funcs = [ (1, "=mesh_rsn_auth_sae_sta", True),
  1158. (1, "mesh_rsn_build_sae_commit;mesh_rsn_auth_sae_sta", False),
  1159. (1, "auth_sae_init_committed;mesh_rsn_auth_sae_sta", True),
  1160. (1, "=mesh_rsn_protect_frame", True),
  1161. (2, "=mesh_rsn_protect_frame", True),
  1162. (1, "aes_siv_encrypt;mesh_rsn_protect_frame", True),
  1163. (1, "=mesh_rsn_process_ampe", True),
  1164. (1, "aes_siv_decrypt;mesh_rsn_process_ampe", True) ]
  1165. for count, func, success in funcs:
  1166. id = add_mesh_secure_net(dev[0])
  1167. dev[0].mesh_group_add(id)
  1168. with alloc_fail(dev[1], count, func):
  1169. id = add_mesh_secure_net(dev[1])
  1170. dev[1].mesh_group_add(id)
  1171. check_mesh_group_added(dev[0])
  1172. check_mesh_group_added(dev[1])
  1173. if success:
  1174. # retry is expected to work
  1175. check_mesh_peer_connected(dev[0])
  1176. check_mesh_peer_connected(dev[1])
  1177. else:
  1178. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  1179. dev[0].mesh_group_remove()
  1180. dev[1].mesh_group_remove()
  1181. check_mesh_group_removed(dev[0])
  1182. check_mesh_group_removed(dev[1])
  1183. def test_mesh_failure(dev, apdev):
  1184. """Mesh and local failures"""
  1185. check_mesh_support(dev[0])
  1186. funcs = [ (1, "ap_sta_add;mesh_mpm_add_peer", True),
  1187. (1, "wpabuf_alloc;mesh_mpm_send_plink_action", True) ]
  1188. for count, func, success in funcs:
  1189. add_open_mesh_network(dev[0])
  1190. with alloc_fail(dev[1], count, func):
  1191. add_open_mesh_network(dev[1])
  1192. check_mesh_group_added(dev[0])
  1193. check_mesh_group_added(dev[1])
  1194. if success:
  1195. # retry is expected to work
  1196. check_mesh_peer_connected(dev[0])
  1197. check_mesh_peer_connected(dev[1])
  1198. else:
  1199. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  1200. dev[0].mesh_group_remove()
  1201. dev[1].mesh_group_remove()
  1202. check_mesh_group_removed(dev[0])
  1203. check_mesh_group_removed(dev[1])
  1204. funcs = [ (1, "mesh_mpm_init_link", True) ]
  1205. for count, func, success in funcs:
  1206. add_open_mesh_network(dev[0])
  1207. with fail_test(dev[1], count, func):
  1208. add_open_mesh_network(dev[1])
  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_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_invalid_frequency(dev, apdev):
  1222. """Mesh and invalid frequency configuration"""
  1223. check_mesh_support(dev[0])
  1224. add_open_mesh_network(dev[0], freq=None)
  1225. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  1226. "Could not join mesh"])
  1227. if ev is None or "Could not join mesh" not in ev:
  1228. raise Exception("Mesh join failure not reported")
  1229. dev[0].request("REMOVE_NETWORK all")
  1230. add_open_mesh_network(dev[0], freq="2413")
  1231. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  1232. "Could not join mesh"])
  1233. if ev is None or "Could not join mesh" not in ev:
  1234. raise Exception("Mesh join failure not reported")
  1235. def test_mesh_default_beacon_int(dev, apdev):
  1236. """Mesh and default beacon interval"""
  1237. check_mesh_support(dev[0])
  1238. try:
  1239. dev[0].request("SET beacon_int 200")
  1240. add_open_mesh_network(dev[0])
  1241. check_mesh_group_added(dev[0])
  1242. finally:
  1243. dev[0].request("SET beacon_int 0")
  1244. def test_mesh_scan_parse_error(dev, apdev):
  1245. """Mesh scan element parse error"""
  1246. check_mesh_support(dev[0])
  1247. params = { "ssid": "open",
  1248. "beacon_int": "2000" }
  1249. hapd = hostapd.add_ap(apdev[0], params)
  1250. bssid = apdev[0]['bssid']
  1251. hapd.set('vendor_elements', 'dd0201')
  1252. for i in range(10):
  1253. dev[0].scan(freq=2412)
  1254. if bssid in dev[0].request("SCAN_RESULTS"):
  1255. break
  1256. # This will fail in IE parsing due to the truncated IE in the Probe
  1257. # Response frame.
  1258. bss = dev[0].request("BSS " + bssid)
  1259. def test_mesh_missing_mic(dev, apdev):
  1260. """Secure mesh network and missing MIC"""
  1261. check_mesh_support(dev[0], secure=True)
  1262. dev[0].request("SET ext_mgmt_frame_handling 1")
  1263. dev[0].request("SET sae_groups ")
  1264. id = add_mesh_secure_net(dev[0])
  1265. dev[0].mesh_group_add(id)
  1266. dev[1].request("SET sae_groups ")
  1267. id = add_mesh_secure_net(dev[1])
  1268. dev[1].mesh_group_add(id)
  1269. # Check for mesh joined
  1270. check_mesh_group_added(dev[0])
  1271. check_mesh_group_added(dev[1])
  1272. count = 0
  1273. remove_mic = True
  1274. while True:
  1275. count += 1
  1276. if count > 15:
  1277. raise Exception("Did not see Action frames")
  1278. rx_msg = dev[0].mgmt_rx()
  1279. if rx_msg is None:
  1280. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1281. if ev:
  1282. break
  1283. raise Exception("MGMT-RX timeout")
  1284. if rx_msg['subtype'] == 13:
  1285. payload = rx_msg['payload']
  1286. frame = rx_msg['frame']
  1287. (categ, action) = struct.unpack('BB', payload[0:2])
  1288. if categ == 15 and action == 1 and remove_mic:
  1289. # Mesh Peering Open
  1290. pos = frame.find('\x8c\x10')
  1291. if not pos:
  1292. raise Exception("Could not find MIC element")
  1293. logger.info("Found MIC at %d" % pos)
  1294. # Remove MIC
  1295. rx_msg['frame'] = frame[0:pos]
  1296. remove_mic = False
  1297. 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'))):
  1298. raise Exception("MGMT_RX_PROCESS failed")
  1299. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1300. if ev:
  1301. break
  1302. def test_mesh_pmkid_mismatch(dev, apdev):
  1303. """Secure mesh network and PMKID mismatch"""
  1304. check_mesh_support(dev[0], secure=True)
  1305. addr0 = dev[0].own_addr()
  1306. addr1 = dev[1].own_addr()
  1307. dev[0].request("SET sae_groups ")
  1308. id = add_mesh_secure_net(dev[0])
  1309. dev[0].set_network(id, "no_auto_peer", "1")
  1310. dev[0].mesh_group_add(id)
  1311. dev[1].request("SET sae_groups ")
  1312. id = add_mesh_secure_net(dev[1])
  1313. dev[1].set_network(id, "no_auto_peer", "1")
  1314. dev[1].mesh_group_add(id)
  1315. # Check for mesh joined
  1316. check_mesh_group_added(dev[0])
  1317. check_mesh_group_added(dev[1])
  1318. # Check for peer connected
  1319. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1320. if ev is None:
  1321. raise Exception("Missing no-initiate message")
  1322. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1323. raise Exception("MESH_PEER_ADD failed")
  1324. check_mesh_peer_connected(dev[0])
  1325. check_mesh_peer_connected(dev[1])
  1326. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1327. raise Exception("Failed to remove peer")
  1328. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1329. if ev is None:
  1330. raise Exception("Missing no-initiate message (2)")
  1331. dev[0].dump_monitor()
  1332. dev[1].dump_monitor()
  1333. dev[0].request("SET ext_mgmt_frame_handling 1")
  1334. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1335. raise Exception("MESH_PEER_ADD failed (2)")
  1336. count = 0
  1337. break_pmkid = True
  1338. while True:
  1339. count += 1
  1340. if count > 50:
  1341. raise Exception("Did not see Action frames")
  1342. rx_msg = dev[0].mgmt_rx()
  1343. if rx_msg is None:
  1344. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  1345. if ev:
  1346. break
  1347. raise Exception("MGMT-RX timeout")
  1348. if rx_msg['subtype'] == 13:
  1349. payload = rx_msg['payload']
  1350. frame = rx_msg['frame']
  1351. (categ, action) = struct.unpack('BB', payload[0:2])
  1352. if categ == 15 and action == 1 and break_pmkid:
  1353. # Mesh Peering Open
  1354. pos = frame.find('\x75\x14')
  1355. if not pos:
  1356. raise Exception("Could not find Mesh Peering Management element")
  1357. logger.info("Found Mesh Peering Management element at %d" % pos)
  1358. # Break PMKID to hit "Mesh RSN: Invalid PMKID (Chosen PMK did
  1359. # not match calculated PMKID)"
  1360. rx_msg['frame'] = frame[0:pos + 6] + '\x00\x00\x00\x00' + frame[pos + 10:]
  1361. break_pmkid = False
  1362. 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'))):
  1363. raise Exception("MGMT_RX_PROCESS failed")
  1364. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1365. if ev:
  1366. break
  1367. def test_mesh_peering_proto(dev, apdev):
  1368. """Mesh peering management protocol testing"""
  1369. check_mesh_support(dev[0])
  1370. dev[0].request("SET ext_mgmt_frame_handling 1")
  1371. add_open_mesh_network(dev[0], beacon_int=160)
  1372. add_open_mesh_network(dev[1], beacon_int=160)
  1373. count = 0
  1374. test = 1
  1375. while True:
  1376. count += 1
  1377. if count > 50:
  1378. raise Exception("Did not see Action frames")
  1379. rx_msg = dev[0].mgmt_rx()
  1380. if rx_msg is None:
  1381. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1382. if ev:
  1383. break
  1384. raise Exception("MGMT-RX timeout")
  1385. if rx_msg['subtype'] == 13:
  1386. payload = rx_msg['payload']
  1387. frame = rx_msg['frame']
  1388. (categ, action) = struct.unpack('BB', payload[0:2])
  1389. if categ == 15 and action == 1 and test == 1:
  1390. # Mesh Peering Open
  1391. pos = frame.find('\x75\x04')
  1392. if not pos:
  1393. raise Exception("Could not find Mesh Peering Management element")
  1394. logger.info("Found Mesh Peering Management element at %d" % pos)
  1395. # Remove the element to hit
  1396. # "MPM: No Mesh Peering Management element"
  1397. rx_msg['frame'] = frame[0:pos]
  1398. test += 1
  1399. elif categ == 15 and action == 1 and test == 2:
  1400. # Mesh Peering Open
  1401. pos = frame.find('\x72\x0e')
  1402. if not pos:
  1403. raise Exception("Could not find Mesh ID element")
  1404. logger.info("Found Mesh ID element at %d" % pos)
  1405. # Remove the element to hit
  1406. # "MPM: No Mesh ID or Mesh Configuration element"
  1407. rx_msg['frame'] = frame[0:pos] + frame[pos + 16:]
  1408. test += 1
  1409. elif categ == 15 and action == 1 and test == 3:
  1410. # Mesh Peering Open
  1411. pos = frame.find('\x72\x0e')
  1412. if not pos:
  1413. raise Exception("Could not find Mesh ID element")
  1414. logger.info("Found Mesh ID element at %d" % pos)
  1415. # Replace Mesh ID to hit "MPM: Mesh ID or Mesh Configuration
  1416. # element do not match local MBSS"
  1417. rx_msg['frame'] = frame[0:pos] + '\x72\x0etest-test-test' + frame[pos + 16:]
  1418. test += 1
  1419. elif categ == 15 and action == 1 and test == 4:
  1420. # Mesh Peering Open
  1421. # Remove IEs to hit
  1422. # "MPM: Ignore too short action frame 1 ie_len 0"
  1423. rx_msg['frame'] = frame[0:26]
  1424. test += 1
  1425. elif categ == 15 and action == 1 and test == 5:
  1426. # Mesh Peering Open
  1427. # Truncate IEs to hit
  1428. # "MPM: Failed to parse PLINK IEs"
  1429. rx_msg['frame'] = frame[0:30]
  1430. test += 1
  1431. elif categ == 15 and action == 1 and test == 6:
  1432. # Mesh Peering Open
  1433. pos = frame.find('\x75\x04')
  1434. if not pos:
  1435. raise Exception("Could not find Mesh Peering Management element")
  1436. logger.info("Found Mesh Peering Management element at %d" % pos)
  1437. # Truncate the element to hit
  1438. # "MPM: Invalid peer mgmt ie" and
  1439. # "MPM: Mesh parsing rejected frame"
  1440. rx_msg['frame'] = frame[0:pos] + '\x75\x00\x00\x00' + frame[pos + 6:]
  1441. test += 1
  1442. 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'))):
  1443. raise Exception("MGMT_RX_PROCESS failed")
  1444. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1445. if ev:
  1446. break
  1447. if test != 7:
  1448. raise Exception("Not all test frames completed")