test_wpas_mesh.py 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601
  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. def test_wpas_mesh_open_no_auto(dev, apdev):
  170. """wpa_supplicant open MESH network connectivity"""
  171. check_mesh_support(dev[0])
  172. id = add_open_mesh_network(dev[0], start=False)
  173. dev[0].set_network(id, "dot11MeshMaxRetries", "16")
  174. dev[0].set_network(id, "dot11MeshRetryTimeout", "255")
  175. dev[0].mesh_group_add(id)
  176. id = add_open_mesh_network(dev[1], start=False)
  177. dev[1].set_network(id, "no_auto_peer", "1")
  178. dev[1].mesh_group_add(id)
  179. # Check for mesh joined
  180. check_mesh_group_added(dev[0])
  181. check_mesh_group_added(dev[1])
  182. # Check for peer connected
  183. check_mesh_peer_connected(dev[0], timeout=30)
  184. check_mesh_peer_connected(dev[1])
  185. # Test connectivity 0->1 and 1->0
  186. hwsim_utils.test_connectivity(dev[0], dev[1])
  187. def add_mesh_secure_net(dev, psk=True):
  188. id = dev.add_network()
  189. dev.set_network(id, "mode", "5")
  190. dev.set_network_quoted(id, "ssid", "wpas-mesh-sec")
  191. dev.set_network(id, "key_mgmt", "SAE")
  192. dev.set_network(id, "frequency", "2412")
  193. if psk:
  194. dev.set_network_quoted(id, "psk", "thisismypassphrase!")
  195. return id
  196. def test_wpas_mesh_secure(dev, apdev):
  197. """wpa_supplicant secure MESH network connectivity"""
  198. check_mesh_support(dev[0], secure=True)
  199. dev[0].request("SET sae_groups ")
  200. id = add_mesh_secure_net(dev[0])
  201. dev[0].mesh_group_add(id)
  202. dev[1].request("SET sae_groups ")
  203. id = add_mesh_secure_net(dev[1])
  204. dev[1].mesh_group_add(id)
  205. # Check for mesh joined
  206. check_mesh_group_added(dev[0])
  207. check_mesh_group_added(dev[1])
  208. # Check for peer connected
  209. check_mesh_peer_connected(dev[0])
  210. check_mesh_peer_connected(dev[1])
  211. # Test connectivity 0->1 and 1->0
  212. hwsim_utils.test_connectivity(dev[0], dev[1])
  213. def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev):
  214. """wpa_supplicant secure MESH and SAE group mismatch"""
  215. check_mesh_support(dev[0], secure=True)
  216. addr0 = dev[0].p2p_interface_addr()
  217. addr1 = dev[1].p2p_interface_addr()
  218. addr2 = dev[2].p2p_interface_addr()
  219. dev[0].request("SET sae_groups 19 25")
  220. id = add_mesh_secure_net(dev[0])
  221. dev[0].mesh_group_add(id)
  222. dev[1].request("SET sae_groups 19")
  223. id = add_mesh_secure_net(dev[1])
  224. dev[1].mesh_group_add(id)
  225. dev[2].request("SET sae_groups 26")
  226. id = add_mesh_secure_net(dev[2])
  227. dev[2].mesh_group_add(id)
  228. check_mesh_group_added(dev[0])
  229. check_mesh_group_added(dev[1])
  230. check_mesh_group_added(dev[2])
  231. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
  232. if ev is None:
  233. raise Exception("Remote peer did not connect")
  234. if addr1 not in ev:
  235. raise Exception("Unexpected peer connected: " + ev)
  236. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
  237. if ev is None:
  238. raise Exception("Remote peer did not connect")
  239. if addr0 not in ev:
  240. raise Exception("Unexpected peer connected: " + ev)
  241. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  242. if ev is not None:
  243. raise Exception("Unexpected peer connection at dev[2]: " + ev)
  244. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  245. if ev is not None:
  246. raise Exception("Unexpected peer connection: " + ev)
  247. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  248. if ev is not None:
  249. raise Exception("Unexpected peer connection: " + ev)
  250. dev[0].request("SET sae_groups ")
  251. dev[1].request("SET sae_groups ")
  252. dev[2].request("SET sae_groups ")
  253. def test_wpas_mesh_secure_sae_group_negotiation(dev, apdev):
  254. """wpa_supplicant secure MESH and SAE group negotiation"""
  255. check_mesh_support(dev[0], secure=True)
  256. addr0 = dev[0].own_addr()
  257. addr1 = dev[1].own_addr()
  258. #dev[0].request("SET sae_groups 21 20 25 26")
  259. dev[0].request("SET sae_groups 25")
  260. id = add_mesh_secure_net(dev[0])
  261. dev[0].mesh_group_add(id)
  262. dev[1].request("SET sae_groups 19 25")
  263. id = add_mesh_secure_net(dev[1])
  264. dev[1].mesh_group_add(id)
  265. check_mesh_group_added(dev[0])
  266. check_mesh_group_added(dev[1])
  267. check_mesh_peer_connected(dev[0])
  268. check_mesh_peer_connected(dev[1])
  269. dev[0].request("SET sae_groups ")
  270. dev[1].request("SET sae_groups ")
  271. def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
  272. """wpa_supplicant secure MESH and missing SAE password"""
  273. check_mesh_support(dev[0], secure=True)
  274. id = add_mesh_secure_net(dev[0], psk=False)
  275. dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
  276. dev[0].mesh_group_add(id)
  277. ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
  278. timeout=5)
  279. if ev is None:
  280. raise Exception("Timeout on mesh start event")
  281. if "MESH-GROUP-STARTED" in ev:
  282. raise Exception("Unexpected mesh group start")
  283. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
  284. if ev is not None:
  285. raise Exception("Unexpected mesh group start")
  286. def test_wpas_mesh_secure_no_auto(dev, apdev):
  287. """wpa_supplicant secure MESH network connectivity"""
  288. check_mesh_support(dev[0], secure=True)
  289. dev[0].request("SET sae_groups 19")
  290. id = add_mesh_secure_net(dev[0])
  291. dev[0].mesh_group_add(id)
  292. dev[1].request("SET sae_groups 19")
  293. id = add_mesh_secure_net(dev[1])
  294. dev[1].set_network(id, "no_auto_peer", "1")
  295. dev[1].mesh_group_add(id)
  296. # Check for mesh joined
  297. check_mesh_group_added(dev[0])
  298. check_mesh_group_added(dev[1])
  299. # Check for peer connected
  300. check_mesh_peer_connected(dev[0], timeout=30)
  301. check_mesh_peer_connected(dev[1])
  302. # Test connectivity 0->1 and 1->0
  303. hwsim_utils.test_connectivity(dev[0], dev[1])
  304. dev[0].request("SET sae_groups ")
  305. dev[1].request("SET sae_groups ")
  306. def test_wpas_mesh_secure_dropped_frame(dev, apdev):
  307. """Secure mesh network connectivity when the first plink Open is dropped"""
  308. check_mesh_support(dev[0], secure=True)
  309. dev[0].request("SET ext_mgmt_frame_handling 1")
  310. dev[0].request("SET sae_groups ")
  311. id = add_mesh_secure_net(dev[0])
  312. dev[0].mesh_group_add(id)
  313. dev[1].request("SET sae_groups ")
  314. id = add_mesh_secure_net(dev[1])
  315. dev[1].mesh_group_add(id)
  316. # Check for mesh joined
  317. check_mesh_group_added(dev[0])
  318. check_mesh_group_added(dev[1])
  319. # Drop the first Action frame (plink Open) to test unexpected order of
  320. # Confirm/Open messages.
  321. count = 0
  322. while True:
  323. count += 1
  324. if count > 10:
  325. raise Exception("Did not see Action frames")
  326. rx_msg = dev[0].mgmt_rx()
  327. if rx_msg is None:
  328. raise Exception("MGMT-RX timeout")
  329. if rx_msg['subtype'] == 13:
  330. logger.info("Drop the first Action frame")
  331. break
  332. 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'))):
  333. raise Exception("MGMT_RX_PROCESS failed")
  334. dev[0].request("SET ext_mgmt_frame_handling 0")
  335. # Check for peer connected
  336. check_mesh_peer_connected(dev[0])
  337. check_mesh_peer_connected(dev[1])
  338. # Test connectivity 0->1 and 1->0
  339. hwsim_utils.test_connectivity(dev[0], dev[1])
  340. def test_wpas_mesh_ctrl(dev):
  341. """wpa_supplicant ctrl_iface mesh command error cases"""
  342. check_mesh_support(dev[0])
  343. if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
  344. raise Exception("Unexpected MESH_GROUP_ADD success")
  345. id = dev[0].add_network()
  346. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  347. raise Exception("Unexpected MESH_GROUP_ADD success")
  348. dev[0].set_network(id, "mode", "5")
  349. dev[0].set_network(id, "key_mgmt", "WPA-PSK")
  350. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  351. raise Exception("Unexpected MESH_GROUP_ADD success")
  352. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
  353. raise Exception("Unexpected MESH_GROUP_REMOVE success")
  354. def test_wpas_mesh_dynamic_interface(dev):
  355. """wpa_supplicant mesh with dynamic interface"""
  356. check_mesh_support(dev[0])
  357. mesh0 = None
  358. mesh1 = None
  359. try:
  360. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  361. if "FAIL" in mesh0:
  362. raise Exception("MESH_INTERFACE_ADD failed")
  363. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  364. if "FAIL" in mesh1:
  365. raise Exception("MESH_INTERFACE_ADD failed")
  366. wpas0 = WpaSupplicant(ifname=mesh0)
  367. wpas1 = WpaSupplicant(ifname=mesh1)
  368. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  369. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  370. add_open_mesh_network(wpas0)
  371. add_open_mesh_network(wpas1)
  372. check_mesh_group_added(wpas0)
  373. check_mesh_group_added(wpas1)
  374. check_mesh_peer_connected(wpas0)
  375. check_mesh_peer_connected(wpas1)
  376. hwsim_utils.test_connectivity(wpas0, wpas1)
  377. # Must not allow MESH_GROUP_REMOVE on dynamic interface
  378. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
  379. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  380. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
  381. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  382. # Must not allow MESH_GROUP_REMOVE on another radio interface
  383. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
  384. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  385. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
  386. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  387. wpas0.remove_ifname()
  388. wpas1.remove_ifname()
  389. if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  390. raise Exception("MESH_GROUP_REMOVE failed")
  391. if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  392. raise Exception("MESH_GROUP_REMOVE failed")
  393. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  394. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  395. if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  396. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  397. logger.info("Make sure another dynamic group can be added")
  398. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  399. if "FAIL" in mesh0:
  400. raise Exception("MESH_INTERFACE_ADD failed")
  401. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  402. if "FAIL" in mesh1:
  403. raise Exception("MESH_INTERFACE_ADD failed")
  404. wpas0 = WpaSupplicant(ifname=mesh0)
  405. wpas1 = WpaSupplicant(ifname=mesh1)
  406. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  407. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  408. add_open_mesh_network(wpas0)
  409. add_open_mesh_network(wpas1)
  410. check_mesh_group_added(wpas0)
  411. check_mesh_group_added(wpas1)
  412. check_mesh_peer_connected(wpas0)
  413. check_mesh_peer_connected(wpas1)
  414. hwsim_utils.test_connectivity(wpas0, wpas1)
  415. finally:
  416. if mesh0:
  417. dev[0].request("MESH_GROUP_REMOVE " + mesh0)
  418. if mesh1:
  419. dev[1].request("MESH_GROUP_REMOVE " + mesh1)
  420. def test_wpas_mesh_max_peering(dev, apdev, params):
  421. """Mesh max peering limit"""
  422. check_mesh_support(dev[0])
  423. try:
  424. dev[0].request("SET max_peer_links 1")
  425. # first, connect dev[0] and dev[1]
  426. add_open_mesh_network(dev[0])
  427. add_open_mesh_network(dev[1])
  428. for i in range(2):
  429. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  430. if ev is None:
  431. raise Exception("dev%d did not connect with any peer" % i)
  432. # add dev[2] which will try to connect with both dev[0] and dev[1],
  433. # but can complete connection only with dev[1]
  434. add_open_mesh_network(dev[2])
  435. for i in range(1, 3):
  436. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  437. if ev is None:
  438. raise Exception("dev%d did not connect the second peer" % i)
  439. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  440. if ev is not None:
  441. raise Exception("dev0 connection beyond max peering limit")
  442. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  443. if ev is not None:
  444. raise Exception("dev2 reported unexpected peering: " + ev)
  445. for i in range(3):
  446. dev[i].mesh_group_remove()
  447. check_mesh_group_removed(dev[i])
  448. finally:
  449. dev[0].request("SET max_peer_links 99")
  450. addr0 = dev[0].own_addr()
  451. addr1 = dev[1].own_addr()
  452. addr2 = dev[2].own_addr()
  453. capfile = os.path.join(params['logdir'], "hwsim0.pcapng")
  454. filt = "wlan.fc.type_subtype == 8"
  455. out = run_tshark(capfile, filt, [ "wlan.sa", "wlan.mesh.config.cap" ])
  456. pkts = out.splitlines()
  457. one = [ 0, 0, 0 ]
  458. zero = [ 0, 0, 0 ]
  459. for pkt in pkts:
  460. addr, cap = pkt.split('\t')
  461. cap = int(cap, 16)
  462. if addr == addr0:
  463. idx = 0
  464. elif addr == addr1:
  465. idx = 1
  466. elif addr == addr2:
  467. idx = 2
  468. else:
  469. continue
  470. if cap & 0x01:
  471. one[idx] += 1
  472. else:
  473. zero[idx] += 1
  474. logger.info("one: " + str(one))
  475. logger.info("zero: " + str(zero))
  476. if zero[0] == 0:
  477. raise Exception("Accepting Additional Mesh Peerings not cleared")
  478. if one[0] == 0:
  479. raise Exception("Accepting Additional Mesh Peerings was not set in the first Beacon frame")
  480. if zero[1] > 0 or zero[2] > 0 or one[1] == 0 or one[2] == 0:
  481. raise Exception("Unexpected value in Accepting Additional Mesh Peerings from other STAs")
  482. def test_wpas_mesh_open_5ghz(dev, apdev):
  483. """wpa_supplicant open MESH network on 5 GHz band"""
  484. try:
  485. _test_wpas_mesh_open_5ghz(dev, apdev)
  486. finally:
  487. subprocess.call(['iw', 'reg', 'set', '00'])
  488. dev[0].flush_scan_cache()
  489. dev[1].flush_scan_cache()
  490. def _test_wpas_mesh_open_5ghz(dev, apdev):
  491. check_mesh_support(dev[0])
  492. subprocess.call(['iw', 'reg', 'set', 'US'])
  493. for i in range(2):
  494. for j in range(5):
  495. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  496. if ev is None:
  497. raise Exception("No regdom change event")
  498. if "alpha2=US" in ev:
  499. break
  500. add_open_mesh_network(dev[i], freq="5180")
  501. # Check for mesh joined
  502. check_mesh_group_added(dev[0])
  503. check_mesh_group_added(dev[1])
  504. # Check for peer connected
  505. check_mesh_peer_connected(dev[0])
  506. check_mesh_peer_connected(dev[1])
  507. # Test connectivity 0->1 and 1->0
  508. hwsim_utils.test_connectivity(dev[0], dev[1])
  509. def test_wpas_mesh_open_vht_80p80(dev, apdev):
  510. """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
  511. try:
  512. _test_wpas_mesh_open_vht_80p80(dev, apdev)
  513. finally:
  514. subprocess.call(['iw', 'reg', 'set', '00'])
  515. dev[0].flush_scan_cache()
  516. dev[1].flush_scan_cache()
  517. def _test_wpas_mesh_open_vht_80p80(dev, apdev):
  518. check_mesh_support(dev[0])
  519. subprocess.call(['iw', 'reg', 'set', 'US'])
  520. for i in range(2):
  521. for j in range(5):
  522. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  523. if ev is None:
  524. raise Exception("No regdom change event")
  525. if "alpha2=US" in ev:
  526. break
  527. add_open_mesh_network(dev[i], freq="5180", chwidth=3)
  528. # Check for mesh joined
  529. check_mesh_group_added(dev[0])
  530. check_mesh_group_added(dev[1])
  531. # Check for peer connected
  532. check_mesh_peer_connected(dev[0])
  533. check_mesh_peer_connected(dev[1])
  534. # Test connectivity 0->1 and 1->0
  535. hwsim_utils.test_connectivity(dev[0], dev[1])
  536. sig = dev[0].request("SIGNAL_POLL").splitlines()
  537. if "WIDTH=80+80 MHz" not in sig:
  538. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  539. if "CENTER_FRQ1=5210" not in sig:
  540. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  541. if "CENTER_FRQ2=5775" not in sig:
  542. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  543. sig = dev[1].request("SIGNAL_POLL").splitlines()
  544. if "WIDTH=80+80 MHz" not in sig:
  545. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  546. if "CENTER_FRQ1=5210" not in sig:
  547. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  548. if "CENTER_FRQ2=5775" not in sig:
  549. raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
  550. def test_mesh_open_vht_160(dev, apdev):
  551. """Open mesh network on VHT 160 MHz channel"""
  552. try:
  553. _test_mesh_open_vht_160(dev, apdev)
  554. finally:
  555. subprocess.call(['iw', 'reg', 'set', '00'])
  556. dev[0].flush_scan_cache()
  557. dev[1].flush_scan_cache()
  558. def _test_mesh_open_vht_160(dev, apdev):
  559. check_mesh_support(dev[0])
  560. subprocess.call(['iw', 'reg', 'set', 'ZA'])
  561. for i in range(2):
  562. for j in range(5):
  563. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  564. if ev is None:
  565. raise Exception("No regdom change event")
  566. if "alpha2=ZA" in ev:
  567. break
  568. cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
  569. reg = cmd.stdout.read()
  570. if "@ 160)" not in reg:
  571. raise HwsimSkip("160 MHz channel not supported in regulatory information")
  572. add_open_mesh_network(dev[i], freq="5520", chwidth=2)
  573. # Check for mesh joined
  574. check_mesh_group_added(dev[0])
  575. check_mesh_group_added(dev[1])
  576. # Check for peer connected
  577. check_mesh_peer_connected(dev[0])
  578. check_mesh_peer_connected(dev[1])
  579. # Test connectivity 0->1 and 1->0
  580. hwsim_utils.test_connectivity(dev[0], dev[1])
  581. sig = dev[0].request("SIGNAL_POLL").splitlines()
  582. if "WIDTH=160 MHz" not in sig:
  583. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  584. if "FREQUENCY=5520" not in sig:
  585. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  586. sig = dev[1].request("SIGNAL_POLL").splitlines()
  587. if "WIDTH=160 MHz" not in sig:
  588. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  589. if "FREQUENCY=5520" not in sig:
  590. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  591. def test_wpas_mesh_password_mismatch(dev, apdev):
  592. """Mesh network and one device with mismatching password"""
  593. check_mesh_support(dev[0], secure=True)
  594. dev[0].request("SET sae_groups ")
  595. id = add_mesh_secure_net(dev[0])
  596. dev[0].mesh_group_add(id)
  597. dev[1].request("SET sae_groups ")
  598. id = add_mesh_secure_net(dev[1])
  599. dev[1].mesh_group_add(id)
  600. dev[2].request("SET sae_groups ")
  601. id = add_mesh_secure_net(dev[2])
  602. dev[2].set_network_quoted(id, "psk", "wrong password")
  603. dev[2].mesh_group_add(id)
  604. # The two peers with matching password need to be able to connect
  605. check_mesh_group_added(dev[0])
  606. check_mesh_group_added(dev[1])
  607. check_mesh_peer_connected(dev[0])
  608. check_mesh_peer_connected(dev[1])
  609. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  610. if ev is None:
  611. raise Exception("dev2 did not report auth failure (1)")
  612. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  613. if ev is None:
  614. raise Exception("dev2 did not report auth failure (2)")
  615. count = 0
  616. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  617. if ev is None:
  618. logger.info("dev0 did not report auth failure")
  619. else:
  620. if "addr=" + dev[2].own_addr() not in ev:
  621. raise Exception("Unexpected peer address in dev0 event: " + ev)
  622. count += 1
  623. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  624. if ev is None:
  625. logger.info("dev1 did not report auth failure")
  626. else:
  627. if "addr=" + dev[2].own_addr() not in ev:
  628. raise Exception("Unexpected peer address in dev1 event: " + ev)
  629. count += 1
  630. hwsim_utils.test_connectivity(dev[0], dev[1])
  631. for i in range(2):
  632. try:
  633. hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
  634. raise Exception("Data connectivity test passed unexpectedly")
  635. except Exception, e:
  636. if "data delivery failed" not in str(e):
  637. raise
  638. if count == 0:
  639. raise Exception("Neither dev0 nor dev1 reported auth failure")
  640. def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
  641. """Mesh password mismatch and retry [long]"""
  642. if not params['long']:
  643. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  644. check_mesh_support(dev[0], secure=True)
  645. dev[0].request("SET sae_groups ")
  646. id = add_mesh_secure_net(dev[0])
  647. dev[0].mesh_group_add(id)
  648. dev[1].request("SET sae_groups ")
  649. id = add_mesh_secure_net(dev[1])
  650. dev[1].set_network_quoted(id, "psk", "wrong password")
  651. dev[1].mesh_group_add(id)
  652. # Check for mesh joined
  653. check_mesh_group_added(dev[0])
  654. check_mesh_group_added(dev[1])
  655. for i in range(4):
  656. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  657. if ev is None:
  658. raise Exception("dev0 did not report auth failure (%d)" % i)
  659. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  660. if ev is None:
  661. raise Exception("dev1 did not report auth failure (%d)" % i)
  662. ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  663. if ev is None:
  664. raise Exception("dev0 did not report auth blocked")
  665. ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  666. if ev is None:
  667. raise Exception("dev1 did not report auth blocked")
  668. def test_mesh_wpa_auth_init_oom(dev, apdev):
  669. """Secure mesh network setup failing due to wpa_init() OOM"""
  670. check_mesh_support(dev[0], secure=True)
  671. dev[0].request("SET sae_groups ")
  672. with alloc_fail(dev[0], 1, "wpa_init"):
  673. id = add_mesh_secure_net(dev[0])
  674. dev[0].mesh_group_add(id)
  675. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
  676. if ev is not None:
  677. raise Exception("Unexpected mesh group start during OOM")
  678. def test_mesh_wpa_init_fail(dev, apdev):
  679. """Secure mesh network setup local failure"""
  680. check_mesh_support(dev[0], secure=True)
  681. dev[0].request("SET sae_groups ")
  682. with fail_test(dev[0], 1, "os_get_random;=__mesh_rsn_auth_init"):
  683. id = add_mesh_secure_net(dev[0])
  684. dev[0].mesh_group_add(id)
  685. wait_fail_trigger(dev[0], "GET_FAIL")
  686. dev[0].dump_monitor()
  687. with alloc_fail(dev[0], 1, "mesh_rsn_auth_init"):
  688. id = add_mesh_secure_net(dev[0])
  689. dev[0].mesh_group_add(id)
  690. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  691. dev[0].dump_monitor()
  692. with fail_test(dev[0], 1, "os_get_random;mesh_rsn_init_ampe_sta"):
  693. id = add_mesh_secure_net(dev[0])
  694. dev[0].mesh_group_add(id)
  695. dev[1].request("SET sae_groups ")
  696. id = add_mesh_secure_net(dev[1])
  697. dev[1].mesh_group_add(id)
  698. wait_fail_trigger(dev[0], "GET_FAIL")
  699. def test_wpas_mesh_reconnect(dev, apdev):
  700. """Secure mesh network plink counting during reconnection"""
  701. check_mesh_support(dev[0])
  702. try:
  703. _test_wpas_mesh_reconnect(dev)
  704. finally:
  705. dev[0].request("SET max_peer_links 99")
  706. def _test_wpas_mesh_reconnect(dev):
  707. dev[0].request("SET max_peer_links 2")
  708. dev[0].request("SET sae_groups ")
  709. id = add_mesh_secure_net(dev[0])
  710. dev[0].set_network(id, "beacon_int", "100")
  711. dev[0].mesh_group_add(id)
  712. dev[1].request("SET sae_groups ")
  713. id = add_mesh_secure_net(dev[1])
  714. dev[1].mesh_group_add(id)
  715. check_mesh_group_added(dev[0])
  716. check_mesh_group_added(dev[1])
  717. check_mesh_peer_connected(dev[0])
  718. check_mesh_peer_connected(dev[1])
  719. for i in range(3):
  720. # Drop incoming management frames to avoid handling link close
  721. dev[0].request("SET ext_mgmt_frame_handling 1")
  722. dev[1].mesh_group_remove()
  723. check_mesh_group_removed(dev[1])
  724. dev[1].request("FLUSH")
  725. dev[0].request("SET ext_mgmt_frame_handling 0")
  726. id = add_mesh_secure_net(dev[1])
  727. dev[1].mesh_group_add(id)
  728. check_mesh_group_added(dev[1])
  729. check_mesh_peer_connected(dev[1])
  730. dev[0].dump_monitor()
  731. dev[1].dump_monitor()
  732. def test_wpas_mesh_gate_forwarding(dev, apdev, p):
  733. """Mesh forwards traffic to unknown sta to mesh gates"""
  734. addr0 = dev[0].own_addr()
  735. addr1 = dev[1].own_addr()
  736. addr2 = dev[2].own_addr()
  737. external_sta = '02:11:22:33:44:55'
  738. # start 3 node connected mesh
  739. check_mesh_support(dev[0])
  740. for i in range(3):
  741. add_open_mesh_network(dev[i])
  742. check_mesh_group_added(dev[i])
  743. for i in range(3):
  744. check_mesh_peer_connected(dev[i])
  745. hwsim_utils.test_connectivity(dev[0], dev[1])
  746. hwsim_utils.test_connectivity(dev[1], dev[2])
  747. hwsim_utils.test_connectivity(dev[0], dev[2])
  748. # dev0 and dev1 are mesh gates
  749. subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
  750. 'mesh_gate_announcements=1'])
  751. subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
  752. 'mesh_gate_announcements=1'])
  753. # wait for gate announcement frames
  754. time.sleep(1)
  755. # data frame from dev2 -> external sta should be sent to both gates
  756. dev[2].request("DATA_TEST_CONFIG 1")
  757. dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
  758. dev[2].request("DATA_TEST_CONFIG 0")
  759. capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
  760. filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
  761. external_sta)
  762. for i in range(15):
  763. da = run_tshark(capfile, filt, [ "wlan.da" ])
  764. if addr0 in da and addr1 in da:
  765. logger.debug("Frames seen in tshark iteration %d" % i)
  766. break
  767. time.sleep(0.3)
  768. if addr0 not in da:
  769. raise Exception("Frame to gate %s not observed" % addr0)
  770. if addr1 not in da:
  771. raise Exception("Frame to gate %s not observed" % addr1)
  772. def test_wpas_mesh_pmksa_caching(dev, apdev):
  773. """Secure mesh network and PMKSA caching"""
  774. check_mesh_support(dev[0], secure=True)
  775. dev[0].request("SET sae_groups ")
  776. id = add_mesh_secure_net(dev[0])
  777. dev[0].mesh_group_add(id)
  778. dev[1].request("SET sae_groups ")
  779. id = add_mesh_secure_net(dev[1])
  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. # Check for peer connected
  785. check_mesh_peer_connected(dev[0])
  786. check_mesh_peer_connected(dev[1])
  787. addr0 = dev[0].own_addr()
  788. addr1 = dev[1].own_addr()
  789. pmksa0 = dev[0].get_pmksa(addr1)
  790. pmksa1 = dev[1].get_pmksa(addr0)
  791. if pmksa0 is None or pmksa1 is None:
  792. raise Exception("No PMKSA cache entry created")
  793. if pmksa0['pmkid'] != pmksa1['pmkid']:
  794. raise Exception("PMKID mismatch in PMKSA cache entries")
  795. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  796. raise Exception("Failed to remove peer")
  797. pmksa0b = dev[0].get_pmksa(addr1)
  798. if pmksa0b is None:
  799. raise Exception("PMKSA cache entry not maintained")
  800. time.sleep(0.1)
  801. if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
  802. raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
  803. def test_wpas_mesh_pmksa_caching2(dev, apdev):
  804. """Secure mesh network and PMKSA caching with no_auto_peer=1"""
  805. check_mesh_support(dev[0], secure=True)
  806. addr0 = dev[0].own_addr()
  807. addr1 = dev[1].own_addr()
  808. dev[0].request("SET sae_groups ")
  809. id = add_mesh_secure_net(dev[0])
  810. dev[0].set_network(id, "no_auto_peer", "1")
  811. dev[0].mesh_group_add(id)
  812. dev[1].request("SET sae_groups ")
  813. id = add_mesh_secure_net(dev[1])
  814. dev[1].set_network(id, "no_auto_peer", "1")
  815. dev[1].mesh_group_add(id)
  816. # Check for mesh joined
  817. check_mesh_group_added(dev[0])
  818. check_mesh_group_added(dev[1])
  819. # Check for peer connected
  820. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  821. if ev is None:
  822. raise Exception("Missing no-initiate message")
  823. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  824. raise Exception("MESH_PEER_ADD failed")
  825. check_mesh_peer_connected(dev[0])
  826. check_mesh_peer_connected(dev[1])
  827. pmksa0 = dev[0].get_pmksa(addr1)
  828. pmksa1 = dev[1].get_pmksa(addr0)
  829. if pmksa0 is None or pmksa1 is None:
  830. raise Exception("No PMKSA cache entry created")
  831. if pmksa0['pmkid'] != pmksa1['pmkid']:
  832. raise Exception("PMKID mismatch in PMKSA cache entries")
  833. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  834. raise Exception("Failed to remove peer")
  835. pmksa0b = dev[0].get_pmksa(addr1)
  836. if pmksa0b is None:
  837. raise Exception("PMKSA cache entry not maintained")
  838. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  839. if ev is None:
  840. raise Exception("Missing no-initiate message (2)")
  841. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  842. raise Exception("MESH_PEER_ADD failed (2)")
  843. check_mesh_peer_connected(dev[0])
  844. check_mesh_peer_connected(dev[1])
  845. pmksa0c = dev[0].get_pmksa(addr1)
  846. pmksa1c = dev[1].get_pmksa(addr0)
  847. if pmksa0c is None or pmksa1c is None:
  848. raise Exception("No PMKSA cache entry created (2)")
  849. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  850. raise Exception("PMKID mismatch in PMKSA cache entries")
  851. if pmksa0['pmkid'] != pmksa0c['pmkid']:
  852. raise Exception("PMKID changed")
  853. hwsim_utils.test_connectivity(dev[0], dev[1])
  854. def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
  855. """Secure mesh network and PMKSA caching with no PMKID match"""
  856. check_mesh_support(dev[0], secure=True)
  857. addr0 = dev[0].own_addr()
  858. addr1 = dev[1].own_addr()
  859. dev[0].request("SET sae_groups ")
  860. id = add_mesh_secure_net(dev[0])
  861. dev[0].set_network(id, "no_auto_peer", "1")
  862. dev[0].mesh_group_add(id)
  863. dev[1].request("SET sae_groups ")
  864. id = add_mesh_secure_net(dev[1])
  865. dev[1].set_network(id, "no_auto_peer", "1")
  866. dev[1].mesh_group_add(id)
  867. # Check for mesh joined
  868. check_mesh_group_added(dev[0])
  869. check_mesh_group_added(dev[1])
  870. # Check for peer connected
  871. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  872. if ev is None:
  873. raise Exception("Missing no-initiate message")
  874. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  875. raise Exception("MESH_PEER_ADD failed")
  876. check_mesh_peer_connected(dev[0])
  877. check_mesh_peer_connected(dev[1])
  878. pmksa0 = dev[0].get_pmksa(addr1)
  879. pmksa1 = dev[1].get_pmksa(addr0)
  880. if pmksa0 is None or pmksa1 is None:
  881. raise Exception("No PMKSA cache entry created")
  882. if pmksa0['pmkid'] != pmksa1['pmkid']:
  883. raise Exception("PMKID mismatch in PMKSA cache entries")
  884. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  885. raise Exception("Failed to remove peer")
  886. if "OK" not in dev[1].request("PMKSA_FLUSH"):
  887. raise Exception("Failed to flush PMKSA cache")
  888. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  889. if ev is None:
  890. raise Exception("Missing no-initiate message (2)")
  891. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  892. raise Exception("MESH_PEER_ADD failed (2)")
  893. check_mesh_peer_connected(dev[0])
  894. check_mesh_peer_connected(dev[1])
  895. pmksa0c = dev[0].get_pmksa(addr1)
  896. pmksa1c = dev[1].get_pmksa(addr0)
  897. if pmksa0c is None or pmksa1c is None:
  898. raise Exception("No PMKSA cache entry created (2)")
  899. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  900. raise Exception("PMKID mismatch in PMKSA cache entries")
  901. if pmksa0['pmkid'] == pmksa0c['pmkid']:
  902. raise Exception("PMKID did not change")
  903. hwsim_utils.test_connectivity(dev[0], dev[1])
  904. def test_mesh_pmksa_caching_oom(dev, apdev):
  905. """Secure mesh network and PMKSA caching failing due to OOM"""
  906. check_mesh_support(dev[0], secure=True)
  907. addr0 = dev[0].own_addr()
  908. addr1 = dev[1].own_addr()
  909. dev[0].request("SET sae_groups ")
  910. id = add_mesh_secure_net(dev[0])
  911. dev[0].set_network(id, "no_auto_peer", "1")
  912. dev[0].mesh_group_add(id)
  913. dev[1].request("SET sae_groups ")
  914. id = add_mesh_secure_net(dev[1])
  915. dev[1].set_network(id, "no_auto_peer", "1")
  916. dev[1].mesh_group_add(id)
  917. # Check for mesh joined
  918. check_mesh_group_added(dev[0])
  919. check_mesh_group_added(dev[1])
  920. # Check for peer connected
  921. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  922. if ev is None:
  923. raise Exception("Missing no-initiate message")
  924. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  925. raise Exception("MESH_PEER_ADD failed")
  926. check_mesh_peer_connected(dev[0])
  927. check_mesh_peer_connected(dev[1])
  928. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  929. raise Exception("Failed to remove peer")
  930. pmksa0b = dev[0].get_pmksa(addr1)
  931. if pmksa0b is None:
  932. raise Exception("PMKSA cache entry not maintained")
  933. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  934. if ev is None:
  935. raise Exception("Missing no-initiate message (2)")
  936. with alloc_fail(dev[0], 1, "wpa_auth_sta_init;mesh_rsn_auth_sae_sta"):
  937. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  938. raise Exception("MESH_PEER_ADD failed (2)")
  939. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  940. def test_mesh_oom(dev, apdev):
  941. """Mesh network setup failing due to OOM"""
  942. check_mesh_support(dev[0], secure=True)
  943. dev[0].request("SET sae_groups ")
  944. with alloc_fail(dev[0], 1, "mesh_config_create"):
  945. add_open_mesh_network(dev[0])
  946. ev = dev[0].wait_event(["Failed to init mesh"])
  947. if ev is None:
  948. raise Exception("Init failure not reported")
  949. with alloc_fail(dev[0], 4, "=wpa_supplicant_mesh_init"):
  950. add_open_mesh_network(dev[0], basic_rates="60 120 240")
  951. ev = dev[0].wait_event(["Failed to init mesh"])
  952. if ev is None:
  953. raise Exception("Init failure not reported")
  954. for i in range(1, 66):
  955. dev[0].dump_monitor()
  956. logger.info("Test instance %d" % i)
  957. try:
  958. with alloc_fail(dev[0], i, "wpa_supplicant_mesh_init"):
  959. add_open_mesh_network(dev[0])
  960. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  961. ev = dev[0].wait_event(["Failed to init mesh",
  962. "MESH-GROUP-STARTED"])
  963. if ev is None:
  964. raise Exception("Init failure not reported")
  965. except Exception, e:
  966. if i < 15:
  967. raise
  968. logger.info("Ignore no-oom for i=%d" % i)
  969. with alloc_fail(dev[0], 5, "=wpa_supplicant_mesh_init"):
  970. id = add_mesh_secure_net(dev[0])
  971. dev[0].mesh_group_add(id)
  972. ev = dev[0].wait_event(["Failed to init mesh"])
  973. if ev is None:
  974. raise Exception("Init failure not reported")
  975. def test_mesh_add_interface_oom(dev):
  976. """wpa_supplicant mesh with dynamic interface addition failing"""
  977. check_mesh_support(dev[0])
  978. for i in range(1, 3):
  979. mesh = None
  980. try:
  981. with alloc_fail(dev[0], i, "wpas_mesh_add_interface"):
  982. mesh = dev[0].request("MESH_INTERFACE_ADD").strip()
  983. finally:
  984. if mesh and mesh != "FAIL":
  985. dev[0].request("MESH_GROUP_REMOVE " + mesh)
  986. def test_mesh_scan_oom(dev):
  987. """wpa_supplicant mesh scan results and OOM"""
  988. check_mesh_support(dev[0])
  989. add_open_mesh_network(dev[0])
  990. check_mesh_group_added(dev[0])
  991. for i in range(5):
  992. dev[1].scan(freq="2412")
  993. res = dev[1].request("SCAN_RESULTS")
  994. if "[MESH]" in res:
  995. break
  996. for r in res.splitlines():
  997. if "[MESH]" in r:
  998. break
  999. bssid = r.split('\t')[0]
  1000. bss = dev[1].get_bss(bssid)
  1001. if bss is None:
  1002. raise Exception("Could not get BSS entry for mesh")
  1003. for i in range(1, 3):
  1004. with alloc_fail(dev[1], i, "mesh_attr_text"):
  1005. bss = dev[1].get_bss(bssid)
  1006. if bss is not None:
  1007. raise Exception("Unexpected BSS result during OOM")
  1008. def test_mesh_drv_fail(dev, apdev):
  1009. """Mesh network setup failing due to driver command failure"""
  1010. check_mesh_support(dev[0], secure=True)
  1011. dev[0].request("SET sae_groups ")
  1012. with fail_test(dev[0], 1, "nl80211_join_mesh"):
  1013. add_open_mesh_network(dev[0])
  1014. ev = dev[0].wait_event(["mesh join error"])
  1015. if ev is None:
  1016. raise Exception("Join failure not reported")
  1017. dev[0].dump_monitor()
  1018. with fail_test(dev[0], 1, "wpa_driver_nl80211_if_add"):
  1019. if "FAIL" not in dev[0].request("MESH_INTERFACE_ADD").strip():
  1020. raise Exception("Interface added unexpectedly")
  1021. dev[0].dump_monitor()
  1022. with fail_test(dev[0], 1, "wpa_driver_nl80211_init_mesh"):
  1023. add_open_mesh_network(dev[0])
  1024. ev = dev[0].wait_event(["Could not join mesh"])
  1025. if ev is None:
  1026. raise Exception("Join failure not reported")
  1027. def test_mesh_sae_groups_invalid(dev, apdev):
  1028. """Mesh with invalid SAE group configuration"""
  1029. check_mesh_support(dev[0], secure=True)
  1030. dev[0].request("SET sae_groups 25")
  1031. id = add_mesh_secure_net(dev[0])
  1032. dev[0].mesh_group_add(id)
  1033. dev[1].request("SET sae_groups 123 122 121")
  1034. id = add_mesh_secure_net(dev[1])
  1035. dev[1].mesh_group_add(id)
  1036. check_mesh_group_added(dev[0])
  1037. check_mesh_group_added(dev[1])
  1038. ev = dev[0].wait_event(["new peer notification"], timeout=10)
  1039. if ev is None:
  1040. raise Exception("dev[0] did not see peer")
  1041. ev = dev[1].wait_event(["new peer notification"], timeout=10)
  1042. if ev is None:
  1043. raise Exception("dev[1] did not see peer")
  1044. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  1045. if ev is not None:
  1046. raise Exception("Unexpected connection(0)")
  1047. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1048. if ev is not None:
  1049. raise Exception("Unexpected connection(1)")
  1050. # Additional coverage in mesh_rsn_sae_group() with non-zero
  1051. # wpa_s->mesh_rsn->sae_group_index.
  1052. dev[0].dump_monitor()
  1053. dev[1].dump_monitor()
  1054. id = add_mesh_secure_net(dev[2])
  1055. dev[2].mesh_group_add(id)
  1056. check_mesh_group_added(dev[2])
  1057. check_mesh_peer_connected(dev[0])
  1058. check_mesh_peer_connected(dev[2])
  1059. ev = dev[1].wait_event(["new peer notification"], timeout=10)
  1060. if ev is None:
  1061. raise Exception("dev[1] did not see peer(2)")
  1062. dev[0].dump_monitor()
  1063. dev[1].dump_monitor()
  1064. dev[2].dump_monitor()
  1065. dev[0].request("SET sae_groups ")
  1066. dev[1].request("SET sae_groups ")
  1067. def test_mesh_sae_failure(dev, apdev):
  1068. """Mesh and local SAE failures"""
  1069. check_mesh_support(dev[0], secure=True)
  1070. dev[0].request("SET sae_groups ")
  1071. dev[1].request("SET sae_groups ")
  1072. funcs = [ (1, "=mesh_rsn_auth_sae_sta", True),
  1073. (1, "mesh_rsn_build_sae_commit;mesh_rsn_auth_sae_sta", False),
  1074. (1, "auth_sae_init_committed;mesh_rsn_auth_sae_sta", True),
  1075. (1, "=mesh_rsn_protect_frame", True),
  1076. (2, "=mesh_rsn_protect_frame", True),
  1077. (1, "aes_siv_encrypt;mesh_rsn_protect_frame", True),
  1078. (1, "=mesh_rsn_process_ampe", True),
  1079. (1, "aes_siv_decrypt;mesh_rsn_process_ampe", True) ]
  1080. for count, func, success in funcs:
  1081. id = add_mesh_secure_net(dev[0])
  1082. dev[0].mesh_group_add(id)
  1083. with alloc_fail(dev[1], count, func):
  1084. id = add_mesh_secure_net(dev[1])
  1085. dev[1].mesh_group_add(id)
  1086. check_mesh_group_added(dev[0])
  1087. check_mesh_group_added(dev[1])
  1088. if success:
  1089. # retry is expected to work
  1090. check_mesh_peer_connected(dev[0])
  1091. check_mesh_peer_connected(dev[1])
  1092. else:
  1093. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  1094. dev[0].mesh_group_remove()
  1095. dev[1].mesh_group_remove()
  1096. check_mesh_group_removed(dev[0])
  1097. check_mesh_group_removed(dev[1])
  1098. def test_mesh_failure(dev, apdev):
  1099. """Mesh and local failures"""
  1100. check_mesh_support(dev[0])
  1101. funcs = [ (1, "ap_sta_add;mesh_mpm_add_peer", True),
  1102. (1, "wpabuf_alloc;mesh_mpm_send_plink_action", True) ]
  1103. for count, func, success in funcs:
  1104. add_open_mesh_network(dev[0])
  1105. with alloc_fail(dev[1], count, func):
  1106. add_open_mesh_network(dev[1])
  1107. check_mesh_group_added(dev[0])
  1108. check_mesh_group_added(dev[1])
  1109. if success:
  1110. # retry is expected to work
  1111. check_mesh_peer_connected(dev[0])
  1112. check_mesh_peer_connected(dev[1])
  1113. else:
  1114. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  1115. dev[0].mesh_group_remove()
  1116. dev[1].mesh_group_remove()
  1117. check_mesh_group_removed(dev[0])
  1118. check_mesh_group_removed(dev[1])
  1119. funcs = [ (1, "mesh_mpm_init_link", True) ]
  1120. for count, func, success in funcs:
  1121. add_open_mesh_network(dev[0])
  1122. with fail_test(dev[1], count, func):
  1123. add_open_mesh_network(dev[1])
  1124. check_mesh_group_added(dev[0])
  1125. check_mesh_group_added(dev[1])
  1126. if success:
  1127. # retry is expected to work
  1128. check_mesh_peer_connected(dev[0])
  1129. check_mesh_peer_connected(dev[1])
  1130. else:
  1131. wait_fail_trigger(dev[1], "GET_FAIL")
  1132. dev[0].mesh_group_remove()
  1133. dev[1].mesh_group_remove()
  1134. check_mesh_group_removed(dev[0])
  1135. check_mesh_group_removed(dev[1])
  1136. def test_mesh_invalid_frequency(dev, apdev):
  1137. """Mesh and invalid frequency configuration"""
  1138. check_mesh_support(dev[0])
  1139. add_open_mesh_network(dev[0], freq=None)
  1140. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  1141. "Could not join mesh"])
  1142. if ev is None or "Could not join mesh" not in ev:
  1143. raise Exception("Mesh join failure not reported")
  1144. dev[0].request("REMOVE_NETWORK all")
  1145. add_open_mesh_network(dev[0], freq="2413")
  1146. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  1147. "Could not join mesh"])
  1148. if ev is None or "Could not join mesh" not in ev:
  1149. raise Exception("Mesh join failure not reported")
  1150. def test_mesh_default_beacon_int(dev, apdev):
  1151. """Mesh and default beacon interval"""
  1152. check_mesh_support(dev[0])
  1153. try:
  1154. dev[0].request("SET beacon_int 200")
  1155. add_open_mesh_network(dev[0])
  1156. check_mesh_group_added(dev[0])
  1157. finally:
  1158. dev[0].request("SET beacon_int 0")
  1159. def test_mesh_scan_parse_error(dev, apdev):
  1160. """Mesh scan element parse error"""
  1161. check_mesh_support(dev[0])
  1162. params = { "ssid": "open",
  1163. "beacon_int": "2000" }
  1164. hapd = hostapd.add_ap(apdev[0], params)
  1165. bssid = apdev[0]['bssid']
  1166. hapd.set('vendor_elements', 'dd0201')
  1167. for i in range(10):
  1168. dev[0].scan(freq=2412)
  1169. if bssid in dev[0].request("SCAN_RESULTS"):
  1170. break
  1171. # This will fail in IE parsing due to the truncated IE in the Probe
  1172. # Response frame.
  1173. bss = dev[0].request("BSS " + bssid)
  1174. def test_mesh_missing_mic(dev, apdev):
  1175. """Secure mesh network and missing MIC"""
  1176. check_mesh_support(dev[0], secure=True)
  1177. dev[0].request("SET ext_mgmt_frame_handling 1")
  1178. dev[0].request("SET sae_groups ")
  1179. id = add_mesh_secure_net(dev[0])
  1180. dev[0].mesh_group_add(id)
  1181. dev[1].request("SET sae_groups ")
  1182. id = add_mesh_secure_net(dev[1])
  1183. dev[1].mesh_group_add(id)
  1184. # Check for mesh joined
  1185. check_mesh_group_added(dev[0])
  1186. check_mesh_group_added(dev[1])
  1187. count = 0
  1188. remove_mic = True
  1189. while True:
  1190. count += 1
  1191. if count > 15:
  1192. raise Exception("Did not see Action frames")
  1193. rx_msg = dev[0].mgmt_rx()
  1194. if rx_msg is None:
  1195. raise Exception("MGMT-RX timeout")
  1196. if rx_msg['subtype'] == 13:
  1197. payload = rx_msg['payload']
  1198. frame = rx_msg['frame']
  1199. (categ, action) = struct.unpack('BB', payload[0:2])
  1200. if categ == 15 and action == 1 and remove_mic:
  1201. # Mesh Peering Open
  1202. pos = frame.find('\x8c\x10')
  1203. if not pos:
  1204. raise Exception("Could not find MIC element")
  1205. logger.info("Found MIC at %d" % pos)
  1206. # Remove MIC
  1207. rx_msg['frame'] = frame[0:pos]
  1208. remove_mic = False
  1209. 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'))):
  1210. raise Exception("MGMT_RX_PROCESS failed")
  1211. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1212. if ev:
  1213. break
  1214. def test_mesh_pmkid_mismatch(dev, apdev):
  1215. """Secure mesh network and PMKID mismatch"""
  1216. check_mesh_support(dev[0], secure=True)
  1217. addr0 = dev[0].own_addr()
  1218. addr1 = dev[1].own_addr()
  1219. dev[0].request("SET sae_groups ")
  1220. id = add_mesh_secure_net(dev[0])
  1221. dev[0].set_network(id, "no_auto_peer", "1")
  1222. dev[0].mesh_group_add(id)
  1223. dev[1].request("SET sae_groups ")
  1224. id = add_mesh_secure_net(dev[1])
  1225. dev[1].set_network(id, "no_auto_peer", "1")
  1226. dev[1].mesh_group_add(id)
  1227. # Check for mesh joined
  1228. check_mesh_group_added(dev[0])
  1229. check_mesh_group_added(dev[1])
  1230. # Check for peer connected
  1231. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1232. if ev is None:
  1233. raise Exception("Missing no-initiate message")
  1234. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1235. raise Exception("MESH_PEER_ADD failed")
  1236. check_mesh_peer_connected(dev[0])
  1237. check_mesh_peer_connected(dev[1])
  1238. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  1239. raise Exception("Failed to remove peer")
  1240. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  1241. if ev is None:
  1242. raise Exception("Missing no-initiate message (2)")
  1243. dev[0].dump_monitor()
  1244. dev[1].dump_monitor()
  1245. dev[0].request("SET ext_mgmt_frame_handling 1")
  1246. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  1247. raise Exception("MESH_PEER_ADD failed (2)")
  1248. count = 0
  1249. break_pmkid = True
  1250. while True:
  1251. count += 1
  1252. if count > 50:
  1253. raise Exception("Did not see Action frames")
  1254. rx_msg = dev[0].mgmt_rx()
  1255. if rx_msg is None:
  1256. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  1257. if ev:
  1258. break
  1259. raise Exception("MGMT-RX timeout")
  1260. if rx_msg['subtype'] == 13:
  1261. payload = rx_msg['payload']
  1262. frame = rx_msg['frame']
  1263. (categ, action) = struct.unpack('BB', payload[0:2])
  1264. if categ == 15 and action == 1 and break_pmkid:
  1265. # Mesh Peering Open
  1266. pos = frame.find('\x75\x14')
  1267. if not pos:
  1268. raise Exception("Could not find Mesh Peering Management element")
  1269. logger.info("Found Mesh Peering Management element at %d" % pos)
  1270. # Break PMKID to hit "Mesh RSN: Invalid PMKID (Chosen PMK did
  1271. # not match calculated PMKID)"
  1272. rx_msg['frame'] = frame[0:pos + 6] + '\x00\x00\x00\x00' + frame[pos + 10:]
  1273. break_pmkid = False
  1274. 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'))):
  1275. raise Exception("MGMT_RX_PROCESS failed")
  1276. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1277. if ev:
  1278. break
  1279. def test_mesh_peering_proto(dev, apdev):
  1280. """Mesh peering management protocol testing"""
  1281. check_mesh_support(dev[0])
  1282. dev[0].request("SET ext_mgmt_frame_handling 1")
  1283. add_open_mesh_network(dev[0], beacon_int=160)
  1284. add_open_mesh_network(dev[1], beacon_int=160)
  1285. count = 0
  1286. test = 1
  1287. while True:
  1288. count += 1
  1289. if count > 50:
  1290. raise Exception("Did not see Action frames")
  1291. rx_msg = dev[0].mgmt_rx()
  1292. if rx_msg is None:
  1293. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1294. if ev:
  1295. break
  1296. raise Exception("MGMT-RX timeout")
  1297. if rx_msg['subtype'] == 13:
  1298. payload = rx_msg['payload']
  1299. frame = rx_msg['frame']
  1300. (categ, action) = struct.unpack('BB', payload[0:2])
  1301. if categ == 15 and action == 1 and test == 1:
  1302. # Mesh Peering Open
  1303. pos = frame.find('\x75\x04')
  1304. if not pos:
  1305. raise Exception("Could not find Mesh Peering Management element")
  1306. logger.info("Found Mesh Peering Management element at %d" % pos)
  1307. # Remove the element to hit
  1308. # "MPM: No Mesh Peering Management element"
  1309. rx_msg['frame'] = frame[0:pos]
  1310. test += 1
  1311. elif categ == 15 and action == 1 and test == 2:
  1312. # Mesh Peering Open
  1313. pos = frame.find('\x72\x0e')
  1314. if not pos:
  1315. raise Exception("Could not find Mesh ID element")
  1316. logger.info("Found Mesh ID element at %d" % pos)
  1317. # Remove the element to hit
  1318. # "MPM: No Mesh ID or Mesh Configuration element"
  1319. rx_msg['frame'] = frame[0:pos] + frame[pos + 16:]
  1320. test += 1
  1321. elif categ == 15 and action == 1 and test == 3:
  1322. # Mesh Peering Open
  1323. pos = frame.find('\x72\x0e')
  1324. if not pos:
  1325. raise Exception("Could not find Mesh ID element")
  1326. logger.info("Found Mesh ID element at %d" % pos)
  1327. # Replace Mesh ID to hit "MPM: Mesh ID or Mesh Configuration
  1328. # element do not match local MBSS"
  1329. rx_msg['frame'] = frame[0:pos] + '\x72\x0etest-test-test' + frame[pos + 16:]
  1330. test += 1
  1331. elif categ == 15 and action == 1 and test == 4:
  1332. # Mesh Peering Open
  1333. # Remove IEs to hit
  1334. # "MPM: Ignore too short action frame 1 ie_len 0"
  1335. rx_msg['frame'] = frame[0:26]
  1336. test += 1
  1337. elif categ == 15 and action == 1 and test == 5:
  1338. # Mesh Peering Open
  1339. # Truncate IEs to hit
  1340. # "MPM: Failed to parse PLINK IEs"
  1341. rx_msg['frame'] = frame[0:30]
  1342. test += 1
  1343. elif categ == 15 and action == 1 and test == 6:
  1344. # Mesh Peering Open
  1345. pos = frame.find('\x75\x04')
  1346. if not pos:
  1347. raise Exception("Could not find Mesh Peering Management element")
  1348. logger.info("Found Mesh Peering Management element at %d" % pos)
  1349. # Truncate the element to hit
  1350. # "MPM: Invalid peer mgmt ie" and
  1351. # "MPM: Mesh parsing rejected frame"
  1352. rx_msg['frame'] = frame[0:pos] + '\x75\x00\x00\x00' + frame[pos + 6:]
  1353. test += 1
  1354. 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'))):
  1355. raise Exception("MGMT_RX_PROCESS failed")
  1356. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  1357. if ev:
  1358. break
  1359. if test != 7:
  1360. raise Exception("Not all test frames completed")