test_wpas_mesh.py 62 KB

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