test_wpas_mesh.py 72 KB

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