test_wpas_mesh.py 67 KB

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