test_wpas_mesh.py 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  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 subprocess
  10. import time
  11. import hwsim_utils
  12. from wpasupplicant import WpaSupplicant
  13. from utils import HwsimSkip, alloc_fail, fail_test, wait_fail_trigger
  14. from tshark import run_tshark
  15. def check_mesh_support(dev, secure=False):
  16. if "MESH" not in dev.get_capability("modes"):
  17. raise HwsimSkip("Driver does not support mesh")
  18. if secure and "SAE" not in dev.get_capability("auth_alg"):
  19. raise HwsimSkip("SAE not supported")
  20. def check_mesh_scan(dev, params, other_started=False, beacon_int=0):
  21. if not other_started:
  22. dev.dump_monitor()
  23. id = dev.request("SCAN " + params)
  24. if "FAIL" in id:
  25. raise Exception("Failed to start scan")
  26. id = int(id)
  27. if other_started:
  28. ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
  29. if ev is None:
  30. raise Exception("Other scan did not start")
  31. if "id=" + str(id) in ev:
  32. raise Exception("Own scan id unexpectedly included in start event")
  33. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  34. if ev is None:
  35. raise Exception("Other scan did not complete")
  36. if "id=" + str(id) in ev:
  37. raise Exception(
  38. "Own scan id unexpectedly included in completed event")
  39. ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
  40. if ev is None:
  41. raise Exception("Scan did not start")
  42. if "id=" + str(id) not in ev:
  43. raise Exception("Scan id not included in start event")
  44. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  45. if ev is None:
  46. raise Exception("Scan did not complete")
  47. if "id=" + str(id) not in ev:
  48. raise Exception("Scan id not included in completed event")
  49. res = dev.request("SCAN_RESULTS")
  50. if res.find("[MESH]") < 0:
  51. raise Exception("Scan did not contain a MESH network")
  52. bssid = res.splitlines()[1].split(' ')[0]
  53. bss = dev.get_bss(bssid)
  54. if bss is None:
  55. raise Exception("Could not get BSS entry for mesh")
  56. if 'mesh_capability' not in bss:
  57. raise Exception("mesh_capability missing from BSS entry")
  58. if beacon_int:
  59. if 'beacon_int' not in bss:
  60. raise Exception("beacon_int missing from BSS entry")
  61. if str(beacon_int) != bss['beacon_int']:
  62. raise Exception("Unexpected beacon_int in BSS entry: " + bss['beacon_int'])
  63. def check_mesh_group_added(dev):
  64. ev = dev.wait_event(["MESH-GROUP-STARTED"])
  65. if ev is None:
  66. raise Exception("Test exception: Couldn't join mesh")
  67. def check_mesh_group_removed(dev):
  68. ev = dev.wait_event(["MESH-GROUP-REMOVED"])
  69. if ev is None:
  70. raise Exception("Test exception: Couldn't leave mesh")
  71. def check_mesh_peer_connected(dev, timeout=10):
  72. ev = dev.wait_event(["MESH-PEER-CONNECTED"], timeout=timeout)
  73. if ev is None:
  74. raise Exception("Test exception: Remote peer did not connect.")
  75. def check_mesh_peer_disconnected(dev):
  76. ev = dev.wait_event(["MESH-PEER-DISCONNECTED"])
  77. if ev is None:
  78. raise Exception("Test exception: Peer disconnect event not detected.")
  79. def test_wpas_add_set_remove_support(dev):
  80. """wpa_supplicant MESH add/set/remove network support"""
  81. check_mesh_support(dev[0])
  82. id = dev[0].add_network()
  83. dev[0].set_network(id, "mode", "5")
  84. dev[0].remove_network(id)
  85. def add_open_mesh_network(dev, freq="2412", start=True, beacon_int=0,
  86. basic_rates=None, chwidth=0):
  87. id = dev.add_network()
  88. dev.set_network(id, "mode", "5")
  89. dev.set_network_quoted(id, "ssid", "wpas-mesh-open")
  90. dev.set_network(id, "key_mgmt", "NONE")
  91. if freq:
  92. dev.set_network(id, "frequency", freq)
  93. if chwidth > 0:
  94. dev.set_network(id, "max_oper_chwidth", str(chwidth))
  95. if beacon_int:
  96. dev.set_network(id, "beacon_int", str(beacon_int))
  97. if basic_rates:
  98. dev.set_network(id, "mesh_basic_rates", basic_rates)
  99. if start:
  100. dev.mesh_group_add(id)
  101. return id
  102. def test_wpas_mesh_group_added(dev):
  103. """wpa_supplicant MESH group add"""
  104. check_mesh_support(dev[0])
  105. add_open_mesh_network(dev[0])
  106. # Check for MESH-GROUP-STARTED event
  107. check_mesh_group_added(dev[0])
  108. def test_wpas_mesh_group_remove(dev):
  109. """wpa_supplicant MESH group remove"""
  110. check_mesh_support(dev[0])
  111. add_open_mesh_network(dev[0])
  112. # Check for MESH-GROUP-STARTED event
  113. check_mesh_group_added(dev[0])
  114. dev[0].mesh_group_remove()
  115. # Check for MESH-GROUP-REMOVED event
  116. check_mesh_group_removed(dev[0])
  117. dev[0].mesh_group_remove()
  118. def test_wpas_mesh_peer_connected(dev):
  119. """wpa_supplicant MESH peer connected"""
  120. check_mesh_support(dev[0])
  121. add_open_mesh_network(dev[0], beacon_int=160)
  122. add_open_mesh_network(dev[1], beacon_int=160)
  123. # Check for mesh joined
  124. check_mesh_group_added(dev[0])
  125. check_mesh_group_added(dev[1])
  126. # Check for peer connected
  127. check_mesh_peer_connected(dev[0])
  128. check_mesh_peer_connected(dev[1])
  129. def test_wpas_mesh_peer_disconnected(dev):
  130. """wpa_supplicant MESH peer disconnected"""
  131. check_mesh_support(dev[0])
  132. add_open_mesh_network(dev[0])
  133. add_open_mesh_network(dev[1])
  134. # Check for mesh joined
  135. check_mesh_group_added(dev[0])
  136. check_mesh_group_added(dev[1])
  137. # Check for peer connected
  138. check_mesh_peer_connected(dev[0])
  139. check_mesh_peer_connected(dev[1])
  140. # Remove group on dev 1
  141. dev[1].mesh_group_remove()
  142. # Device 0 should get a disconnection event
  143. check_mesh_peer_disconnected(dev[0])
  144. def test_wpas_mesh_mode_scan(dev):
  145. """wpa_supplicant MESH scan support"""
  146. check_mesh_support(dev[0])
  147. add_open_mesh_network(dev[0])
  148. add_open_mesh_network(dev[1], beacon_int=175)
  149. # Check for mesh joined
  150. check_mesh_group_added(dev[0])
  151. check_mesh_group_added(dev[1])
  152. # Check for Mesh scan
  153. check_mesh_scan(dev[0], "use_id=1", beacon_int=175)
  154. def test_wpas_mesh_open(dev, apdev):
  155. """wpa_supplicant open MESH network connectivity"""
  156. check_mesh_support(dev[0])
  157. add_open_mesh_network(dev[0], freq="2462", basic_rates="60 120 240")
  158. add_open_mesh_network(dev[1], freq="2462", basic_rates="60 120 240")
  159. # Check for mesh joined
  160. check_mesh_group_added(dev[0])
  161. check_mesh_group_added(dev[1])
  162. # Check for peer connected
  163. check_mesh_peer_connected(dev[0])
  164. check_mesh_peer_connected(dev[1])
  165. # Test connectivity 0->1 and 1->0
  166. hwsim_utils.test_connectivity(dev[0], dev[1])
  167. def test_wpas_mesh_open_no_auto(dev, apdev):
  168. """wpa_supplicant open MESH network connectivity"""
  169. check_mesh_support(dev[0])
  170. id = add_open_mesh_network(dev[0], start=False)
  171. dev[0].set_network(id, "dot11MeshMaxRetries", "16")
  172. dev[0].set_network(id, "dot11MeshRetryTimeout", "255")
  173. dev[0].mesh_group_add(id)
  174. id = add_open_mesh_network(dev[1], start=False)
  175. dev[1].set_network(id, "no_auto_peer", "1")
  176. dev[1].mesh_group_add(id)
  177. # Check for mesh joined
  178. check_mesh_group_added(dev[0])
  179. check_mesh_group_added(dev[1])
  180. # Check for peer connected
  181. check_mesh_peer_connected(dev[0], timeout=30)
  182. check_mesh_peer_connected(dev[1])
  183. # Test connectivity 0->1 and 1->0
  184. hwsim_utils.test_connectivity(dev[0], dev[1])
  185. def add_mesh_secure_net(dev, psk=True):
  186. id = dev.add_network()
  187. dev.set_network(id, "mode", "5")
  188. dev.set_network_quoted(id, "ssid", "wpas-mesh-sec")
  189. dev.set_network(id, "key_mgmt", "SAE")
  190. dev.set_network(id, "frequency", "2412")
  191. if psk:
  192. dev.set_network_quoted(id, "psk", "thisismypassphrase!")
  193. return id
  194. def test_wpas_mesh_secure(dev, apdev):
  195. """wpa_supplicant secure MESH network connectivity"""
  196. check_mesh_support(dev[0], secure=True)
  197. dev[0].request("SET sae_groups ")
  198. id = add_mesh_secure_net(dev[0])
  199. dev[0].mesh_group_add(id)
  200. dev[1].request("SET sae_groups ")
  201. id = add_mesh_secure_net(dev[1])
  202. dev[1].mesh_group_add(id)
  203. # Check for mesh joined
  204. check_mesh_group_added(dev[0])
  205. check_mesh_group_added(dev[1])
  206. # Check for peer connected
  207. check_mesh_peer_connected(dev[0])
  208. check_mesh_peer_connected(dev[1])
  209. # Test connectivity 0->1 and 1->0
  210. hwsim_utils.test_connectivity(dev[0], dev[1])
  211. def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev):
  212. """wpa_supplicant secure MESH and SAE group mismatch"""
  213. check_mesh_support(dev[0], secure=True)
  214. addr0 = dev[0].p2p_interface_addr()
  215. addr1 = dev[1].p2p_interface_addr()
  216. addr2 = dev[2].p2p_interface_addr()
  217. dev[0].request("SET sae_groups 19 25")
  218. id = add_mesh_secure_net(dev[0])
  219. dev[0].mesh_group_add(id)
  220. dev[1].request("SET sae_groups 19")
  221. id = add_mesh_secure_net(dev[1])
  222. dev[1].mesh_group_add(id)
  223. dev[2].request("SET sae_groups 26")
  224. id = add_mesh_secure_net(dev[2])
  225. dev[2].mesh_group_add(id)
  226. check_mesh_group_added(dev[0])
  227. check_mesh_group_added(dev[1])
  228. check_mesh_group_added(dev[2])
  229. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
  230. if ev is None:
  231. raise Exception("Remote peer did not connect")
  232. if addr1 not in ev:
  233. raise Exception("Unexpected peer connected: " + ev)
  234. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
  235. if ev is None:
  236. raise Exception("Remote peer did not connect")
  237. if addr0 not in ev:
  238. raise Exception("Unexpected peer connected: " + ev)
  239. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  240. if ev is not None:
  241. raise Exception("Unexpected peer connection at dev[2]: " + ev)
  242. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  243. if ev is not None:
  244. raise Exception("Unexpected peer connection: " + ev)
  245. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  246. if ev is not None:
  247. raise Exception("Unexpected peer connection: " + ev)
  248. dev[0].request("SET sae_groups ")
  249. dev[1].request("SET sae_groups ")
  250. dev[2].request("SET sae_groups ")
  251. def test_wpas_mesh_secure_sae_group_negotiation(dev, apdev):
  252. """wpa_supplicant secure MESH and SAE group negotiation"""
  253. check_mesh_support(dev[0], secure=True)
  254. addr0 = dev[0].own_addr()
  255. addr1 = dev[1].own_addr()
  256. #dev[0].request("SET sae_groups 21 20 25 26")
  257. dev[0].request("SET sae_groups 25")
  258. id = add_mesh_secure_net(dev[0])
  259. dev[0].mesh_group_add(id)
  260. dev[1].request("SET sae_groups 19 25")
  261. id = add_mesh_secure_net(dev[1])
  262. dev[1].mesh_group_add(id)
  263. check_mesh_group_added(dev[0])
  264. check_mesh_group_added(dev[1])
  265. check_mesh_peer_connected(dev[0])
  266. check_mesh_peer_connected(dev[1])
  267. dev[0].request("SET sae_groups ")
  268. dev[1].request("SET sae_groups ")
  269. def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
  270. """wpa_supplicant secure MESH and missing SAE password"""
  271. check_mesh_support(dev[0], secure=True)
  272. id = add_mesh_secure_net(dev[0], psk=False)
  273. dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
  274. dev[0].mesh_group_add(id)
  275. ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
  276. timeout=5)
  277. if ev is None:
  278. raise Exception("Timeout on mesh start event")
  279. if "MESH-GROUP-STARTED" in ev:
  280. raise Exception("Unexpected mesh group start")
  281. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
  282. if ev is not None:
  283. raise Exception("Unexpected mesh group start")
  284. def test_wpas_mesh_secure_no_auto(dev, apdev):
  285. """wpa_supplicant secure MESH network connectivity"""
  286. check_mesh_support(dev[0], secure=True)
  287. dev[0].request("SET sae_groups 19")
  288. id = add_mesh_secure_net(dev[0])
  289. dev[0].mesh_group_add(id)
  290. dev[1].request("SET sae_groups 19")
  291. id = add_mesh_secure_net(dev[1])
  292. dev[1].set_network(id, "no_auto_peer", "1")
  293. dev[1].mesh_group_add(id)
  294. # Check for mesh joined
  295. check_mesh_group_added(dev[0])
  296. check_mesh_group_added(dev[1])
  297. # Check for peer connected
  298. check_mesh_peer_connected(dev[0], timeout=30)
  299. check_mesh_peer_connected(dev[1])
  300. # Test connectivity 0->1 and 1->0
  301. hwsim_utils.test_connectivity(dev[0], dev[1])
  302. dev[0].request("SET sae_groups ")
  303. dev[1].request("SET sae_groups ")
  304. def test_wpas_mesh_secure_dropped_frame(dev, apdev):
  305. """Secure mesh network connectivity when the first plink Open is dropped"""
  306. check_mesh_support(dev[0], secure=True)
  307. dev[0].request("SET ext_mgmt_frame_handling 1")
  308. dev[0].request("SET sae_groups ")
  309. id = add_mesh_secure_net(dev[0])
  310. dev[0].mesh_group_add(id)
  311. dev[1].request("SET sae_groups ")
  312. id = add_mesh_secure_net(dev[1])
  313. dev[1].mesh_group_add(id)
  314. # Check for mesh joined
  315. check_mesh_group_added(dev[0])
  316. check_mesh_group_added(dev[1])
  317. # Drop the first Action frame (plink Open) to test unexpected order of
  318. # Confirm/Open messages.
  319. count = 0
  320. while True:
  321. count += 1
  322. if count > 10:
  323. raise Exception("Did not see Action frames")
  324. rx_msg = dev[0].mgmt_rx()
  325. if rx_msg is None:
  326. raise Exception("MGMT-RX timeout")
  327. if rx_msg['subtype'] == 13:
  328. logger.info("Drop the first Action frame")
  329. break
  330. 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'))):
  331. raise Exception("MGMT_RX_PROCESS failed")
  332. dev[0].request("SET ext_mgmt_frame_handling 0")
  333. # Check for peer connected
  334. check_mesh_peer_connected(dev[0])
  335. check_mesh_peer_connected(dev[1])
  336. # Test connectivity 0->1 and 1->0
  337. hwsim_utils.test_connectivity(dev[0], dev[1])
  338. def test_wpas_mesh_ctrl(dev):
  339. """wpa_supplicant ctrl_iface mesh command error cases"""
  340. check_mesh_support(dev[0])
  341. if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
  342. raise Exception("Unexpected MESH_GROUP_ADD success")
  343. id = dev[0].add_network()
  344. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  345. raise Exception("Unexpected MESH_GROUP_ADD success")
  346. dev[0].set_network(id, "mode", "5")
  347. dev[0].set_network(id, "key_mgmt", "WPA-PSK")
  348. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  349. raise Exception("Unexpected MESH_GROUP_ADD success")
  350. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
  351. raise Exception("Unexpected MESH_GROUP_REMOVE success")
  352. def test_wpas_mesh_dynamic_interface(dev):
  353. """wpa_supplicant mesh with dynamic interface"""
  354. check_mesh_support(dev[0])
  355. mesh0 = None
  356. mesh1 = None
  357. try:
  358. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  359. if "FAIL" in mesh0:
  360. raise Exception("MESH_INTERFACE_ADD failed")
  361. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  362. if "FAIL" in mesh1:
  363. raise Exception("MESH_INTERFACE_ADD failed")
  364. wpas0 = WpaSupplicant(ifname=mesh0)
  365. wpas1 = WpaSupplicant(ifname=mesh1)
  366. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  367. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  368. add_open_mesh_network(wpas0)
  369. add_open_mesh_network(wpas1)
  370. check_mesh_group_added(wpas0)
  371. check_mesh_group_added(wpas1)
  372. check_mesh_peer_connected(wpas0)
  373. check_mesh_peer_connected(wpas1)
  374. hwsim_utils.test_connectivity(wpas0, wpas1)
  375. # Must not allow MESH_GROUP_REMOVE on dynamic interface
  376. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
  377. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  378. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
  379. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  380. # Must not allow MESH_GROUP_REMOVE on another radio interface
  381. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
  382. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  383. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
  384. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  385. wpas0.remove_ifname()
  386. wpas1.remove_ifname()
  387. if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  388. raise Exception("MESH_GROUP_REMOVE failed")
  389. if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  390. raise Exception("MESH_GROUP_REMOVE failed")
  391. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  392. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  393. if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  394. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  395. logger.info("Make sure another dynamic group can be added")
  396. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  397. if "FAIL" in mesh0:
  398. raise Exception("MESH_INTERFACE_ADD failed")
  399. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  400. if "FAIL" in mesh1:
  401. raise Exception("MESH_INTERFACE_ADD failed")
  402. wpas0 = WpaSupplicant(ifname=mesh0)
  403. wpas1 = WpaSupplicant(ifname=mesh1)
  404. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  405. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  406. add_open_mesh_network(wpas0)
  407. add_open_mesh_network(wpas1)
  408. check_mesh_group_added(wpas0)
  409. check_mesh_group_added(wpas1)
  410. check_mesh_peer_connected(wpas0)
  411. check_mesh_peer_connected(wpas1)
  412. hwsim_utils.test_connectivity(wpas0, wpas1)
  413. finally:
  414. if mesh0:
  415. dev[0].request("MESH_GROUP_REMOVE " + mesh0)
  416. if mesh1:
  417. dev[1].request("MESH_GROUP_REMOVE " + mesh1)
  418. def test_wpas_mesh_max_peering(dev, apdev):
  419. """Mesh max peering limit"""
  420. check_mesh_support(dev[0])
  421. try:
  422. dev[0].request("SET max_peer_links 1")
  423. # first, connect dev[0] and dev[1]
  424. add_open_mesh_network(dev[0])
  425. add_open_mesh_network(dev[1])
  426. for i in range(2):
  427. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  428. if ev is None:
  429. raise Exception("dev%d did not connect with any peer" % i)
  430. # add dev[2] which will try to connect with both dev[0] and dev[1],
  431. # but can complete connection only with dev[1]
  432. add_open_mesh_network(dev[2])
  433. for i in range(1, 3):
  434. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  435. if ev is None:
  436. raise Exception("dev%d did not connect the second peer" % i)
  437. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  438. if ev is not None:
  439. raise Exception("dev0 connection beyond max peering limit")
  440. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  441. if ev is not None:
  442. raise Exception("dev2 reported unexpected peering: " + ev)
  443. for i in range(3):
  444. dev[i].mesh_group_remove()
  445. check_mesh_group_removed(dev[i])
  446. finally:
  447. dev[0].request("SET max_peer_links 99")
  448. def test_wpas_mesh_open_5ghz(dev, apdev):
  449. """wpa_supplicant open MESH network on 5 GHz band"""
  450. try:
  451. _test_wpas_mesh_open_5ghz(dev, apdev)
  452. finally:
  453. subprocess.call(['iw', 'reg', 'set', '00'])
  454. dev[0].flush_scan_cache()
  455. dev[1].flush_scan_cache()
  456. def _test_wpas_mesh_open_5ghz(dev, apdev):
  457. check_mesh_support(dev[0])
  458. subprocess.call(['iw', 'reg', 'set', 'US'])
  459. for i in range(2):
  460. for j in range(5):
  461. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  462. if ev is None:
  463. raise Exception("No regdom change event")
  464. if "alpha2=US" in ev:
  465. break
  466. add_open_mesh_network(dev[i], freq="5180")
  467. # Check for mesh joined
  468. check_mesh_group_added(dev[0])
  469. check_mesh_group_added(dev[1])
  470. # Check for peer connected
  471. check_mesh_peer_connected(dev[0])
  472. check_mesh_peer_connected(dev[1])
  473. # Test connectivity 0->1 and 1->0
  474. hwsim_utils.test_connectivity(dev[0], dev[1])
  475. def test_wpas_mesh_open_vht_80p80(dev, apdev):
  476. """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
  477. try:
  478. _test_wpas_mesh_open_vht_80p80(dev, apdev)
  479. finally:
  480. subprocess.call(['iw', 'reg', 'set', '00'])
  481. dev[0].flush_scan_cache()
  482. dev[1].flush_scan_cache()
  483. def _test_wpas_mesh_open_vht_80p80(dev, apdev):
  484. check_mesh_support(dev[0])
  485. subprocess.call(['iw', 'reg', 'set', 'US'])
  486. for i in range(2):
  487. for j in range(5):
  488. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  489. if ev is None:
  490. raise Exception("No regdom change event")
  491. if "alpha2=US" in ev:
  492. break
  493. add_open_mesh_network(dev[i], freq="5180", chwidth=3)
  494. # Check for mesh joined
  495. check_mesh_group_added(dev[0])
  496. check_mesh_group_added(dev[1])
  497. # Check for peer connected
  498. check_mesh_peer_connected(dev[0])
  499. check_mesh_peer_connected(dev[1])
  500. # Test connectivity 0->1 and 1->0
  501. hwsim_utils.test_connectivity(dev[0], dev[1])
  502. sig = dev[0].request("SIGNAL_POLL").splitlines()
  503. if "WIDTH=80+80 MHz" not in sig:
  504. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  505. if "CENTER_FRQ1=5210" not in sig:
  506. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  507. if "CENTER_FRQ2=5775" not in sig:
  508. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  509. sig = dev[1].request("SIGNAL_POLL").splitlines()
  510. if "WIDTH=80+80 MHz" not in sig:
  511. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  512. if "CENTER_FRQ1=5210" not in sig:
  513. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  514. if "CENTER_FRQ2=5775" not in sig:
  515. raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
  516. def test_mesh_open_vht_160(dev, apdev):
  517. """Open mesh network on VHT 160 MHz channel"""
  518. try:
  519. _test_mesh_open_vht_160(dev, apdev)
  520. finally:
  521. subprocess.call(['iw', 'reg', 'set', '00'])
  522. dev[0].flush_scan_cache()
  523. dev[1].flush_scan_cache()
  524. def _test_mesh_open_vht_160(dev, apdev):
  525. check_mesh_support(dev[0])
  526. subprocess.call(['iw', 'reg', 'set', 'ZA'])
  527. for i in range(2):
  528. for j in range(5):
  529. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  530. if ev is None:
  531. raise Exception("No regdom change event")
  532. if "alpha2=ZA" in ev:
  533. break
  534. cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
  535. reg = cmd.stdout.read()
  536. if "@ 160)" not in reg:
  537. raise HwsimSkip("160 MHz channel not supported in regulatory information")
  538. add_open_mesh_network(dev[i], freq="5520", chwidth=2)
  539. # Check for mesh joined
  540. check_mesh_group_added(dev[0])
  541. check_mesh_group_added(dev[1])
  542. # Check for peer connected
  543. check_mesh_peer_connected(dev[0])
  544. check_mesh_peer_connected(dev[1])
  545. # Test connectivity 0->1 and 1->0
  546. hwsim_utils.test_connectivity(dev[0], dev[1])
  547. sig = dev[0].request("SIGNAL_POLL").splitlines()
  548. if "WIDTH=160 MHz" not in sig:
  549. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  550. if "FREQUENCY=5520" not in sig:
  551. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  552. sig = dev[1].request("SIGNAL_POLL").splitlines()
  553. if "WIDTH=160 MHz" not in sig:
  554. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  555. if "FREQUENCY=5520" not in sig:
  556. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  557. def test_wpas_mesh_password_mismatch(dev, apdev):
  558. """Mesh network and one device with mismatching password"""
  559. check_mesh_support(dev[0], secure=True)
  560. dev[0].request("SET sae_groups ")
  561. id = add_mesh_secure_net(dev[0])
  562. dev[0].mesh_group_add(id)
  563. dev[1].request("SET sae_groups ")
  564. id = add_mesh_secure_net(dev[1])
  565. dev[1].mesh_group_add(id)
  566. dev[2].request("SET sae_groups ")
  567. id = add_mesh_secure_net(dev[2])
  568. dev[2].set_network_quoted(id, "psk", "wrong password")
  569. dev[2].mesh_group_add(id)
  570. # The two peers with matching password need to be able to connect
  571. check_mesh_group_added(dev[0])
  572. check_mesh_group_added(dev[1])
  573. check_mesh_peer_connected(dev[0])
  574. check_mesh_peer_connected(dev[1])
  575. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  576. if ev is None:
  577. raise Exception("dev2 did not report auth failure (1)")
  578. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  579. if ev is None:
  580. raise Exception("dev2 did not report auth failure (2)")
  581. count = 0
  582. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  583. if ev is None:
  584. logger.info("dev0 did not report auth failure")
  585. else:
  586. if "addr=" + dev[2].own_addr() not in ev:
  587. raise Exception("Unexpected peer address in dev0 event: " + ev)
  588. count += 1
  589. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  590. if ev is None:
  591. logger.info("dev1 did not report auth failure")
  592. else:
  593. if "addr=" + dev[2].own_addr() not in ev:
  594. raise Exception("Unexpected peer address in dev1 event: " + ev)
  595. count += 1
  596. hwsim_utils.test_connectivity(dev[0], dev[1])
  597. for i in range(2):
  598. try:
  599. hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
  600. raise Exception("Data connectivity test passed unexpectedly")
  601. except Exception, e:
  602. if "data delivery failed" not in str(e):
  603. raise
  604. if count == 0:
  605. raise Exception("Neither dev0 nor dev1 reported auth failure")
  606. def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
  607. """Mesh password mismatch and retry [long]"""
  608. if not params['long']:
  609. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  610. check_mesh_support(dev[0], secure=True)
  611. dev[0].request("SET sae_groups ")
  612. id = add_mesh_secure_net(dev[0])
  613. dev[0].mesh_group_add(id)
  614. dev[1].request("SET sae_groups ")
  615. id = add_mesh_secure_net(dev[1])
  616. dev[1].set_network_quoted(id, "psk", "wrong password")
  617. dev[1].mesh_group_add(id)
  618. # Check for mesh joined
  619. check_mesh_group_added(dev[0])
  620. check_mesh_group_added(dev[1])
  621. for i in range(4):
  622. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  623. if ev is None:
  624. raise Exception("dev0 did not report auth failure (%d)" % i)
  625. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  626. if ev is None:
  627. raise Exception("dev1 did not report auth failure (%d)" % i)
  628. ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  629. if ev is None:
  630. raise Exception("dev0 did not report auth blocked")
  631. ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  632. if ev is None:
  633. raise Exception("dev1 did not report auth blocked")
  634. def test_mesh_wpa_auth_init_oom(dev, apdev):
  635. """Secure mesh network setup failing due to wpa_init() OOM"""
  636. check_mesh_support(dev[0], secure=True)
  637. dev[0].request("SET sae_groups ")
  638. with alloc_fail(dev[0], 1, "wpa_init"):
  639. id = add_mesh_secure_net(dev[0])
  640. dev[0].mesh_group_add(id)
  641. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
  642. if ev is not None:
  643. raise Exception("Unexpected mesh group start during OOM")
  644. def test_mesh_wpa_init_fail(dev, apdev):
  645. """Secure mesh network setup local failure"""
  646. check_mesh_support(dev[0], secure=True)
  647. dev[0].request("SET sae_groups ")
  648. with fail_test(dev[0], 1, "os_get_random;=__mesh_rsn_auth_init"):
  649. id = add_mesh_secure_net(dev[0])
  650. dev[0].mesh_group_add(id)
  651. wait_fail_trigger(dev[0], "GET_FAIL")
  652. with alloc_fail(dev[0], 1, "mesh_rsn_auth_init"):
  653. id = add_mesh_secure_net(dev[0])
  654. dev[0].mesh_group_add(id)
  655. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  656. def test_wpas_mesh_reconnect(dev, apdev):
  657. """Secure mesh network plink counting during reconnection"""
  658. check_mesh_support(dev[0])
  659. try:
  660. _test_wpas_mesh_reconnect(dev)
  661. finally:
  662. dev[0].request("SET max_peer_links 99")
  663. def _test_wpas_mesh_reconnect(dev):
  664. dev[0].request("SET max_peer_links 2")
  665. dev[0].request("SET sae_groups ")
  666. id = add_mesh_secure_net(dev[0])
  667. dev[0].set_network(id, "beacon_int", "100")
  668. dev[0].mesh_group_add(id)
  669. dev[1].request("SET sae_groups ")
  670. id = add_mesh_secure_net(dev[1])
  671. dev[1].mesh_group_add(id)
  672. check_mesh_group_added(dev[0])
  673. check_mesh_group_added(dev[1])
  674. check_mesh_peer_connected(dev[0])
  675. check_mesh_peer_connected(dev[1])
  676. for i in range(3):
  677. # Drop incoming management frames to avoid handling link close
  678. dev[0].request("SET ext_mgmt_frame_handling 1")
  679. dev[1].mesh_group_remove()
  680. check_mesh_group_removed(dev[1])
  681. dev[1].request("FLUSH")
  682. dev[0].request("SET ext_mgmt_frame_handling 0")
  683. id = add_mesh_secure_net(dev[1])
  684. dev[1].mesh_group_add(id)
  685. check_mesh_group_added(dev[1])
  686. check_mesh_peer_connected(dev[1])
  687. dev[0].dump_monitor()
  688. dev[1].dump_monitor()
  689. def test_wpas_mesh_gate_forwarding(dev, apdev, p):
  690. """Mesh forwards traffic to unknown sta to mesh gates"""
  691. addr0 = dev[0].own_addr()
  692. addr1 = dev[1].own_addr()
  693. addr2 = dev[2].own_addr()
  694. external_sta = '02:11:22:33:44:55'
  695. # start 3 node connected mesh
  696. check_mesh_support(dev[0])
  697. for i in range(3):
  698. add_open_mesh_network(dev[i])
  699. check_mesh_group_added(dev[i])
  700. for i in range(3):
  701. check_mesh_peer_connected(dev[i])
  702. hwsim_utils.test_connectivity(dev[0], dev[1])
  703. hwsim_utils.test_connectivity(dev[1], dev[2])
  704. hwsim_utils.test_connectivity(dev[0], dev[2])
  705. # dev0 and dev1 are mesh gates
  706. subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
  707. 'mesh_gate_announcements=1'])
  708. subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
  709. 'mesh_gate_announcements=1'])
  710. # wait for gate announcement frames
  711. time.sleep(1)
  712. # data frame from dev2 -> external sta should be sent to both gates
  713. dev[2].request("DATA_TEST_CONFIG 1")
  714. dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
  715. dev[2].request("DATA_TEST_CONFIG 0")
  716. capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
  717. filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
  718. external_sta)
  719. for i in range(15):
  720. da = run_tshark(capfile, filt, [ "wlan.da" ])
  721. if addr0 in da and addr1 in da:
  722. logger.debug("Frames seen in tshark iteration %d" % i)
  723. break
  724. time.sleep(0.3)
  725. if addr0 not in da:
  726. raise Exception("Frame to gate %s not observed" % addr0)
  727. if addr1 not in da:
  728. raise Exception("Frame to gate %s not observed" % addr1)
  729. def test_wpas_mesh_pmksa_caching(dev, apdev):
  730. """Secure mesh network and PMKSA caching"""
  731. check_mesh_support(dev[0], secure=True)
  732. dev[0].request("SET sae_groups ")
  733. id = add_mesh_secure_net(dev[0])
  734. dev[0].mesh_group_add(id)
  735. dev[1].request("SET sae_groups ")
  736. id = add_mesh_secure_net(dev[1])
  737. dev[1].mesh_group_add(id)
  738. # Check for mesh joined
  739. check_mesh_group_added(dev[0])
  740. check_mesh_group_added(dev[1])
  741. # Check for peer connected
  742. check_mesh_peer_connected(dev[0])
  743. check_mesh_peer_connected(dev[1])
  744. addr0 = dev[0].own_addr()
  745. addr1 = dev[1].own_addr()
  746. pmksa0 = dev[0].get_pmksa(addr1)
  747. pmksa1 = dev[1].get_pmksa(addr0)
  748. if pmksa0 is None or pmksa1 is None:
  749. raise Exception("No PMKSA cache entry created")
  750. if pmksa0['pmkid'] != pmksa1['pmkid']:
  751. raise Exception("PMKID mismatch in PMKSA cache entries")
  752. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  753. raise Exception("Failed to remove peer")
  754. pmksa0b = dev[0].get_pmksa(addr1)
  755. if pmksa0b is None:
  756. raise Exception("PMKSA cache entry not maintained")
  757. time.sleep(0.1)
  758. if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
  759. raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
  760. def test_wpas_mesh_pmksa_caching2(dev, apdev):
  761. """Secure mesh network and PMKSA caching with no_auto_peer=1"""
  762. check_mesh_support(dev[0], secure=True)
  763. addr0 = dev[0].own_addr()
  764. addr1 = dev[1].own_addr()
  765. dev[0].request("SET sae_groups ")
  766. id = add_mesh_secure_net(dev[0])
  767. dev[0].set_network(id, "no_auto_peer", "1")
  768. dev[0].mesh_group_add(id)
  769. dev[1].request("SET sae_groups ")
  770. id = add_mesh_secure_net(dev[1])
  771. dev[1].set_network(id, "no_auto_peer", "1")
  772. dev[1].mesh_group_add(id)
  773. # Check for mesh joined
  774. check_mesh_group_added(dev[0])
  775. check_mesh_group_added(dev[1])
  776. # Check for peer connected
  777. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  778. if ev is None:
  779. raise Exception("Missing no-initiate message")
  780. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  781. raise Exception("MESH_PEER_ADD failed")
  782. check_mesh_peer_connected(dev[0])
  783. check_mesh_peer_connected(dev[1])
  784. pmksa0 = dev[0].get_pmksa(addr1)
  785. pmksa1 = dev[1].get_pmksa(addr0)
  786. if pmksa0 is None or pmksa1 is None:
  787. raise Exception("No PMKSA cache entry created")
  788. if pmksa0['pmkid'] != pmksa1['pmkid']:
  789. raise Exception("PMKID mismatch in PMKSA cache entries")
  790. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  791. raise Exception("Failed to remove peer")
  792. pmksa0b = dev[0].get_pmksa(addr1)
  793. if pmksa0b is None:
  794. raise Exception("PMKSA cache entry not maintained")
  795. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  796. if ev is None:
  797. raise Exception("Missing no-initiate message (2)")
  798. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  799. raise Exception("MESH_PEER_ADD failed (2)")
  800. check_mesh_peer_connected(dev[0])
  801. check_mesh_peer_connected(dev[1])
  802. pmksa0c = dev[0].get_pmksa(addr1)
  803. pmksa1c = dev[1].get_pmksa(addr0)
  804. if pmksa0c is None or pmksa1c is None:
  805. raise Exception("No PMKSA cache entry created (2)")
  806. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  807. raise Exception("PMKID mismatch in PMKSA cache entries")
  808. if pmksa0['pmkid'] != pmksa0c['pmkid']:
  809. raise Exception("PMKID changed")
  810. hwsim_utils.test_connectivity(dev[0], dev[1])
  811. def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
  812. """Secure mesh network and PMKSA caching with no PMKID match"""
  813. check_mesh_support(dev[0], secure=True)
  814. addr0 = dev[0].own_addr()
  815. addr1 = dev[1].own_addr()
  816. dev[0].request("SET sae_groups ")
  817. id = add_mesh_secure_net(dev[0])
  818. dev[0].set_network(id, "no_auto_peer", "1")
  819. dev[0].mesh_group_add(id)
  820. dev[1].request("SET sae_groups ")
  821. id = add_mesh_secure_net(dev[1])
  822. dev[1].set_network(id, "no_auto_peer", "1")
  823. dev[1].mesh_group_add(id)
  824. # Check for mesh joined
  825. check_mesh_group_added(dev[0])
  826. check_mesh_group_added(dev[1])
  827. # Check for peer connected
  828. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  829. if ev is None:
  830. raise Exception("Missing no-initiate message")
  831. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  832. raise Exception("MESH_PEER_ADD failed")
  833. check_mesh_peer_connected(dev[0])
  834. check_mesh_peer_connected(dev[1])
  835. pmksa0 = dev[0].get_pmksa(addr1)
  836. pmksa1 = dev[1].get_pmksa(addr0)
  837. if pmksa0 is None or pmksa1 is None:
  838. raise Exception("No PMKSA cache entry created")
  839. if pmksa0['pmkid'] != pmksa1['pmkid']:
  840. raise Exception("PMKID mismatch in PMKSA cache entries")
  841. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  842. raise Exception("Failed to remove peer")
  843. if "OK" not in dev[1].request("PMKSA_FLUSH"):
  844. raise Exception("Failed to flush PMKSA cache")
  845. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  846. if ev is None:
  847. raise Exception("Missing no-initiate message (2)")
  848. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  849. raise Exception("MESH_PEER_ADD failed (2)")
  850. check_mesh_peer_connected(dev[0])
  851. check_mesh_peer_connected(dev[1])
  852. pmksa0c = dev[0].get_pmksa(addr1)
  853. pmksa1c = dev[1].get_pmksa(addr0)
  854. if pmksa0c is None or pmksa1c is None:
  855. raise Exception("No PMKSA cache entry created (2)")
  856. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  857. raise Exception("PMKID mismatch in PMKSA cache entries")
  858. if pmksa0['pmkid'] == pmksa0c['pmkid']:
  859. raise Exception("PMKID did not change")
  860. hwsim_utils.test_connectivity(dev[0], dev[1])
  861. def test_mesh_oom(dev, apdev):
  862. """Mesh network setup failing due to OOM"""
  863. check_mesh_support(dev[0], secure=True)
  864. dev[0].request("SET sae_groups ")
  865. with alloc_fail(dev[0], 1, "mesh_config_create"):
  866. add_open_mesh_network(dev[0])
  867. ev = dev[0].wait_event(["Failed to init mesh"])
  868. if ev is None:
  869. raise Exception("Init failure not reported")
  870. with alloc_fail(dev[0], 4, "=wpa_supplicant_mesh_init"):
  871. add_open_mesh_network(dev[0], basic_rates="60 120 240")
  872. ev = dev[0].wait_event(["Failed to init mesh"])
  873. if ev is None:
  874. raise Exception("Init failure not reported")
  875. for i in range(1, 66):
  876. dev[0].dump_monitor()
  877. logger.info("Test instance %d" % i)
  878. try:
  879. with alloc_fail(dev[0], i, "wpa_supplicant_mesh_init"):
  880. add_open_mesh_network(dev[0])
  881. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  882. ev = dev[0].wait_event(["Failed to init mesh",
  883. "MESH-GROUP-STARTED"])
  884. if ev is None:
  885. raise Exception("Init failure not reported")
  886. except Exception, e:
  887. if i < 15:
  888. raise
  889. logger.info("Ignore no-oom for i=%d" % i)
  890. with alloc_fail(dev[0], 5, "=wpa_supplicant_mesh_init"):
  891. id = add_mesh_secure_net(dev[0])
  892. dev[0].mesh_group_add(id)
  893. ev = dev[0].wait_event(["Failed to init mesh"])
  894. if ev is None:
  895. raise Exception("Init failure not reported")
  896. def test_mesh_add_interface_oom(dev):
  897. """wpa_supplicant mesh with dynamic interface addition failing"""
  898. check_mesh_support(dev[0])
  899. for i in range(1, 3):
  900. mesh = None
  901. try:
  902. with alloc_fail(dev[0], i, "wpas_mesh_add_interface"):
  903. mesh = dev[0].request("MESH_INTERFACE_ADD").strip()
  904. finally:
  905. if mesh and mesh != "FAIL":
  906. dev[0].request("MESH_GROUP_REMOVE " + mesh)
  907. def test_mesh_scan_oom(dev):
  908. """wpa_supplicant mesh scan results and OOM"""
  909. check_mesh_support(dev[0])
  910. add_open_mesh_network(dev[0])
  911. check_mesh_group_added(dev[0])
  912. for i in range(5):
  913. dev[1].scan(freq="2412")
  914. res = dev[1].request("SCAN_RESULTS")
  915. if "[MESH]" in res:
  916. break
  917. for r in res.splitlines():
  918. if "[MESH]" in r:
  919. break
  920. bssid = r.split('\t')[0]
  921. bss = dev[1].get_bss(bssid)
  922. if bss is None:
  923. raise Exception("Could not get BSS entry for mesh")
  924. for i in range(1, 3):
  925. with alloc_fail(dev[1], i, "mesh_attr_text"):
  926. bss = dev[1].get_bss(bssid)
  927. if bss is not None:
  928. raise Exception("Unexpected BSS result during OOM")
  929. def test_mesh_drv_fail(dev, apdev):
  930. """Mesh network setup failing due to driver command failure"""
  931. check_mesh_support(dev[0], secure=True)
  932. dev[0].request("SET sae_groups ")
  933. with fail_test(dev[0], 1, "nl80211_join_mesh"):
  934. add_open_mesh_network(dev[0])
  935. ev = dev[0].wait_event(["mesh join error"])
  936. if ev is None:
  937. raise Exception("Join failure not reported")
  938. dev[0].dump_monitor()
  939. with fail_test(dev[0], 1, "wpa_driver_nl80211_if_add"):
  940. if "FAIL" not in dev[0].request("MESH_INTERFACE_ADD").strip():
  941. raise Exception("Interface added unexpectedly")
  942. dev[0].dump_monitor()
  943. with fail_test(dev[0], 1, "wpa_driver_nl80211_init_mesh"):
  944. add_open_mesh_network(dev[0])
  945. ev = dev[0].wait_event(["Could not join mesh"])
  946. if ev is None:
  947. raise Exception("Join failure not reported")
  948. def test_mesh_sae_groups_invalid(dev, apdev):
  949. """Mesh with invalid SAE group configuration"""
  950. check_mesh_support(dev[0], secure=True)
  951. dev[0].request("SET sae_groups 25")
  952. id = add_mesh_secure_net(dev[0])
  953. dev[0].mesh_group_add(id)
  954. dev[1].request("SET sae_groups 123 122 121")
  955. id = add_mesh_secure_net(dev[1])
  956. dev[1].mesh_group_add(id)
  957. check_mesh_group_added(dev[0])
  958. check_mesh_group_added(dev[1])
  959. ev = dev[0].wait_event(["new peer notification"], timeout=10)
  960. if ev is None:
  961. raise Exception("dev[0] did not see peer")
  962. ev = dev[1].wait_event(["new peer notification"], timeout=10)
  963. if ev is None:
  964. raise Exception("dev[1] did not see peer")
  965. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  966. if ev is not None:
  967. raise Exception("Unexpected connection(0)")
  968. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
  969. if ev is not None:
  970. raise Exception("Unexpected connection(1)")
  971. dev[0].request("SET sae_groups ")
  972. dev[1].request("SET sae_groups ")
  973. def test_mesh_sae_failure(dev, apdev):
  974. """Mesh and local SAE failures"""
  975. check_mesh_support(dev[0], secure=True)
  976. dev[0].request("SET sae_groups ")
  977. dev[1].request("SET sae_groups ")
  978. funcs = [ (1, "=mesh_rsn_auth_sae_sta", True),
  979. (1, "mesh_rsn_build_sae_commit;mesh_rsn_auth_sae_sta", False),
  980. (1, "auth_sae_init_committed;mesh_rsn_auth_sae_sta", True),
  981. (1, "=mesh_rsn_protect_frame", True),
  982. (2, "=mesh_rsn_protect_frame", True),
  983. (1, "aes_siv_encrypt;mesh_rsn_protect_frame", True),
  984. (1, "=mesh_rsn_process_ampe", True),
  985. (1, "aes_siv_decrypt;mesh_rsn_process_ampe", True) ]
  986. for count, func, success in funcs:
  987. id = add_mesh_secure_net(dev[0])
  988. dev[0].mesh_group_add(id)
  989. with alloc_fail(dev[1], count, func):
  990. id = add_mesh_secure_net(dev[1])
  991. dev[1].mesh_group_add(id)
  992. check_mesh_group_added(dev[0])
  993. check_mesh_group_added(dev[1])
  994. if success:
  995. # retry is expected to work
  996. check_mesh_peer_connected(dev[0])
  997. check_mesh_peer_connected(dev[1])
  998. else:
  999. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  1000. dev[0].mesh_group_remove()
  1001. dev[1].mesh_group_remove()
  1002. check_mesh_group_removed(dev[0])
  1003. check_mesh_group_removed(dev[1])
  1004. def test_mesh_failure(dev, apdev):
  1005. """Mesh and local failures"""
  1006. check_mesh_support(dev[0])
  1007. funcs = [ (1, "ap_sta_add;mesh_mpm_add_peer", True),
  1008. (1, "wpabuf_alloc;mesh_mpm_send_plink_action", True) ]
  1009. for count, func, success in funcs:
  1010. add_open_mesh_network(dev[0])
  1011. with alloc_fail(dev[1], count, func):
  1012. add_open_mesh_network(dev[1])
  1013. check_mesh_group_added(dev[0])
  1014. check_mesh_group_added(dev[1])
  1015. if success:
  1016. # retry is expected to work
  1017. check_mesh_peer_connected(dev[0])
  1018. check_mesh_peer_connected(dev[1])
  1019. else:
  1020. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
  1021. dev[0].mesh_group_remove()
  1022. dev[1].mesh_group_remove()
  1023. check_mesh_group_removed(dev[0])
  1024. check_mesh_group_removed(dev[1])
  1025. funcs = [ (1, "mesh_mpm_init_link", True) ]
  1026. for count, func, success in funcs:
  1027. add_open_mesh_network(dev[0])
  1028. with fail_test(dev[1], count, func):
  1029. add_open_mesh_network(dev[1])
  1030. check_mesh_group_added(dev[0])
  1031. check_mesh_group_added(dev[1])
  1032. if success:
  1033. # retry is expected to work
  1034. check_mesh_peer_connected(dev[0])
  1035. check_mesh_peer_connected(dev[1])
  1036. else:
  1037. wait_fail_trigger(dev[1], "GET_FAIL")
  1038. dev[0].mesh_group_remove()
  1039. dev[1].mesh_group_remove()
  1040. check_mesh_group_removed(dev[0])
  1041. check_mesh_group_removed(dev[1])
  1042. def test_mesh_invalid_frequency(dev, apdev):
  1043. """Mesh and invalid frequency configuration"""
  1044. check_mesh_support(dev[0])
  1045. add_open_mesh_network(dev[0], freq=None)
  1046. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  1047. "Could not join mesh"])
  1048. if ev is None or "Could not join mesh" not in ev:
  1049. raise Exception("Mesh join failure not reported")
  1050. dev[0].request("REMOVE_NETWORK all")
  1051. add_open_mesh_network(dev[0], freq="2413")
  1052. ev = dev[0].wait_event(["MESH-GROUP-STARTED",
  1053. "Could not join mesh"])
  1054. if ev is None or "Could not join mesh" not in ev:
  1055. raise Exception("Mesh join failure not reported")
  1056. def test_mesh_default_beacon_int(dev, apdev):
  1057. """Mesh and default beacon interval"""
  1058. check_mesh_support(dev[0])
  1059. try:
  1060. dev[0].request("SET beacon_int 200")
  1061. add_open_mesh_network(dev[0])
  1062. check_mesh_group_added(dev[0])
  1063. finally:
  1064. dev[0].request("SET beacon_int 0")