test_wpas_mesh.py 84 KB

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