test_wpas_mesh.py 72 KB

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