test_wpas_mesh.py 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  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. dev.set_network(id, "frequency", freq)
  92. if chwidth > 0:
  93. dev.set_network(id, "max_oper_chwidth", str(chwidth))
  94. if beacon_int:
  95. dev.set_network(id, "beacon_int", str(beacon_int))
  96. if basic_rates:
  97. dev.set_network(id, "mesh_basic_rates", basic_rates)
  98. if start:
  99. dev.mesh_group_add(id)
  100. return id
  101. def test_wpas_mesh_group_added(dev):
  102. """wpa_supplicant MESH group add"""
  103. check_mesh_support(dev[0])
  104. add_open_mesh_network(dev[0])
  105. # Check for MESH-GROUP-STARTED event
  106. check_mesh_group_added(dev[0])
  107. def test_wpas_mesh_group_remove(dev):
  108. """wpa_supplicant MESH group remove"""
  109. check_mesh_support(dev[0])
  110. add_open_mesh_network(dev[0])
  111. # Check for MESH-GROUP-STARTED event
  112. check_mesh_group_added(dev[0])
  113. dev[0].mesh_group_remove()
  114. # Check for MESH-GROUP-REMOVED event
  115. check_mesh_group_removed(dev[0])
  116. dev[0].mesh_group_remove()
  117. def test_wpas_mesh_peer_connected(dev):
  118. """wpa_supplicant MESH peer connected"""
  119. check_mesh_support(dev[0])
  120. add_open_mesh_network(dev[0], beacon_int=160)
  121. add_open_mesh_network(dev[1], beacon_int=160)
  122. # Check for mesh joined
  123. check_mesh_group_added(dev[0])
  124. check_mesh_group_added(dev[1])
  125. # Check for peer connected
  126. check_mesh_peer_connected(dev[0])
  127. check_mesh_peer_connected(dev[1])
  128. def test_wpas_mesh_peer_disconnected(dev):
  129. """wpa_supplicant MESH peer disconnected"""
  130. check_mesh_support(dev[0])
  131. add_open_mesh_network(dev[0])
  132. add_open_mesh_network(dev[1])
  133. # Check for mesh joined
  134. check_mesh_group_added(dev[0])
  135. check_mesh_group_added(dev[1])
  136. # Check for peer connected
  137. check_mesh_peer_connected(dev[0])
  138. check_mesh_peer_connected(dev[1])
  139. # Remove group on dev 1
  140. dev[1].mesh_group_remove()
  141. # Device 0 should get a disconnection event
  142. check_mesh_peer_disconnected(dev[0])
  143. def test_wpas_mesh_mode_scan(dev):
  144. """wpa_supplicant MESH scan support"""
  145. check_mesh_support(dev[0])
  146. add_open_mesh_network(dev[0])
  147. add_open_mesh_network(dev[1], beacon_int=175)
  148. # Check for mesh joined
  149. check_mesh_group_added(dev[0])
  150. check_mesh_group_added(dev[1])
  151. # Check for Mesh scan
  152. check_mesh_scan(dev[0], "use_id=1", beacon_int=175)
  153. def test_wpas_mesh_open(dev, apdev):
  154. """wpa_supplicant open MESH network connectivity"""
  155. check_mesh_support(dev[0])
  156. add_open_mesh_network(dev[0], freq="2462", basic_rates="60 120 240")
  157. add_open_mesh_network(dev[1], freq="2462", basic_rates="60 120 240")
  158. # Check for mesh joined
  159. check_mesh_group_added(dev[0])
  160. check_mesh_group_added(dev[1])
  161. # Check for peer connected
  162. check_mesh_peer_connected(dev[0])
  163. check_mesh_peer_connected(dev[1])
  164. # Test connectivity 0->1 and 1->0
  165. hwsim_utils.test_connectivity(dev[0], dev[1])
  166. def test_wpas_mesh_open_no_auto(dev, apdev):
  167. """wpa_supplicant open MESH network connectivity"""
  168. check_mesh_support(dev[0])
  169. id = add_open_mesh_network(dev[0], start=False)
  170. dev[0].set_network(id, "dot11MeshMaxRetries", "16")
  171. dev[0].set_network(id, "dot11MeshRetryTimeout", "255")
  172. dev[0].mesh_group_add(id)
  173. id = add_open_mesh_network(dev[1], start=False)
  174. dev[1].set_network(id, "no_auto_peer", "1")
  175. dev[1].mesh_group_add(id)
  176. # Check for mesh joined
  177. check_mesh_group_added(dev[0])
  178. check_mesh_group_added(dev[1])
  179. # Check for peer connected
  180. check_mesh_peer_connected(dev[0], timeout=30)
  181. check_mesh_peer_connected(dev[1])
  182. # Test connectivity 0->1 and 1->0
  183. hwsim_utils.test_connectivity(dev[0], dev[1])
  184. def add_mesh_secure_net(dev, psk=True):
  185. id = dev.add_network()
  186. dev.set_network(id, "mode", "5")
  187. dev.set_network_quoted(id, "ssid", "wpas-mesh-sec")
  188. dev.set_network(id, "key_mgmt", "SAE")
  189. dev.set_network(id, "frequency", "2412")
  190. if psk:
  191. dev.set_network_quoted(id, "psk", "thisismypassphrase!")
  192. return id
  193. def test_wpas_mesh_secure(dev, apdev):
  194. """wpa_supplicant secure MESH network connectivity"""
  195. check_mesh_support(dev[0], secure=True)
  196. dev[0].request("SET sae_groups ")
  197. id = add_mesh_secure_net(dev[0])
  198. dev[0].mesh_group_add(id)
  199. dev[1].request("SET sae_groups ")
  200. id = add_mesh_secure_net(dev[1])
  201. dev[1].mesh_group_add(id)
  202. # Check for mesh joined
  203. check_mesh_group_added(dev[0])
  204. check_mesh_group_added(dev[1])
  205. # Check for peer connected
  206. check_mesh_peer_connected(dev[0])
  207. check_mesh_peer_connected(dev[1])
  208. # Test connectivity 0->1 and 1->0
  209. hwsim_utils.test_connectivity(dev[0], dev[1])
  210. def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev):
  211. """wpa_supplicant secure MESH and SAE group mismatch"""
  212. check_mesh_support(dev[0], secure=True)
  213. addr0 = dev[0].p2p_interface_addr()
  214. addr1 = dev[1].p2p_interface_addr()
  215. addr2 = dev[2].p2p_interface_addr()
  216. dev[0].request("SET sae_groups 19 25")
  217. id = add_mesh_secure_net(dev[0])
  218. dev[0].mesh_group_add(id)
  219. dev[1].request("SET sae_groups 19")
  220. id = add_mesh_secure_net(dev[1])
  221. dev[1].mesh_group_add(id)
  222. dev[2].request("SET sae_groups 26")
  223. id = add_mesh_secure_net(dev[2])
  224. dev[2].mesh_group_add(id)
  225. check_mesh_group_added(dev[0])
  226. check_mesh_group_added(dev[1])
  227. check_mesh_group_added(dev[2])
  228. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
  229. if ev is None:
  230. raise Exception("Remote peer did not connect")
  231. if addr1 not in ev:
  232. raise Exception("Unexpected peer connected: " + ev)
  233. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
  234. if ev is None:
  235. raise Exception("Remote peer did not connect")
  236. if addr0 not in ev:
  237. raise Exception("Unexpected peer connected: " + ev)
  238. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  239. if ev is not None:
  240. raise Exception("Unexpected peer connection at dev[2]: " + ev)
  241. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  242. if ev is not None:
  243. raise Exception("Unexpected peer connection: " + ev)
  244. ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  245. if ev is not None:
  246. raise Exception("Unexpected peer connection: " + ev)
  247. dev[0].request("SET sae_groups ")
  248. dev[1].request("SET sae_groups ")
  249. dev[2].request("SET sae_groups ")
  250. def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
  251. """wpa_supplicant secure MESH and missing SAE password"""
  252. check_mesh_support(dev[0], secure=True)
  253. id = add_mesh_secure_net(dev[0], psk=False)
  254. dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
  255. dev[0].mesh_group_add(id)
  256. ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
  257. timeout=5)
  258. if ev is None:
  259. raise Exception("Timeout on mesh start event")
  260. if "MESH-GROUP-STARTED" in ev:
  261. raise Exception("Unexpected mesh group start")
  262. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
  263. if ev is not None:
  264. raise Exception("Unexpected mesh group start")
  265. def test_wpas_mesh_secure_no_auto(dev, apdev):
  266. """wpa_supplicant secure MESH network connectivity"""
  267. check_mesh_support(dev[0], secure=True)
  268. dev[0].request("SET sae_groups 19")
  269. id = add_mesh_secure_net(dev[0])
  270. dev[0].mesh_group_add(id)
  271. dev[1].request("SET sae_groups 19")
  272. id = add_mesh_secure_net(dev[1])
  273. dev[1].set_network(id, "no_auto_peer", "1")
  274. dev[1].mesh_group_add(id)
  275. # Check for mesh joined
  276. check_mesh_group_added(dev[0])
  277. check_mesh_group_added(dev[1])
  278. # Check for peer connected
  279. check_mesh_peer_connected(dev[0], timeout=30)
  280. check_mesh_peer_connected(dev[1])
  281. # Test connectivity 0->1 and 1->0
  282. hwsim_utils.test_connectivity(dev[0], dev[1])
  283. dev[0].request("SET sae_groups ")
  284. dev[1].request("SET sae_groups ")
  285. def test_wpas_mesh_secure_dropped_frame(dev, apdev):
  286. """Secure mesh network connectivity when the first plink Open is dropped"""
  287. check_mesh_support(dev[0], secure=True)
  288. dev[0].request("SET ext_mgmt_frame_handling 1")
  289. dev[0].request("SET sae_groups ")
  290. id = add_mesh_secure_net(dev[0])
  291. dev[0].mesh_group_add(id)
  292. dev[1].request("SET sae_groups ")
  293. id = add_mesh_secure_net(dev[1])
  294. dev[1].mesh_group_add(id)
  295. # Check for mesh joined
  296. check_mesh_group_added(dev[0])
  297. check_mesh_group_added(dev[1])
  298. # Drop the first Action frame (plink Open) to test unexpected order of
  299. # Confirm/Open messages.
  300. count = 0
  301. while True:
  302. count += 1
  303. if count > 10:
  304. raise Exception("Did not see Action frames")
  305. rx_msg = dev[0].mgmt_rx()
  306. if rx_msg is None:
  307. raise Exception("MGMT-RX timeout")
  308. if rx_msg['subtype'] == 13:
  309. logger.info("Drop the first Action frame")
  310. break
  311. 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'))):
  312. raise Exception("MGMT_RX_PROCESS failed")
  313. dev[0].request("SET ext_mgmt_frame_handling 0")
  314. # Check for peer connected
  315. check_mesh_peer_connected(dev[0])
  316. check_mesh_peer_connected(dev[1])
  317. # Test connectivity 0->1 and 1->0
  318. hwsim_utils.test_connectivity(dev[0], dev[1])
  319. def test_wpas_mesh_ctrl(dev):
  320. """wpa_supplicant ctrl_iface mesh command error cases"""
  321. check_mesh_support(dev[0])
  322. if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
  323. raise Exception("Unexpected MESH_GROUP_ADD success")
  324. id = dev[0].add_network()
  325. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  326. raise Exception("Unexpected MESH_GROUP_ADD success")
  327. dev[0].set_network(id, "mode", "5")
  328. dev[0].set_network(id, "key_mgmt", "WPA-PSK")
  329. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  330. raise Exception("Unexpected MESH_GROUP_ADD success")
  331. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
  332. raise Exception("Unexpected MESH_GROUP_REMOVE success")
  333. def test_wpas_mesh_dynamic_interface(dev):
  334. """wpa_supplicant mesh with dynamic interface"""
  335. check_mesh_support(dev[0])
  336. mesh0 = None
  337. mesh1 = None
  338. try:
  339. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  340. if "FAIL" in mesh0:
  341. raise Exception("MESH_INTERFACE_ADD failed")
  342. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  343. if "FAIL" in mesh1:
  344. raise Exception("MESH_INTERFACE_ADD failed")
  345. wpas0 = WpaSupplicant(ifname=mesh0)
  346. wpas1 = WpaSupplicant(ifname=mesh1)
  347. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  348. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  349. add_open_mesh_network(wpas0)
  350. add_open_mesh_network(wpas1)
  351. check_mesh_group_added(wpas0)
  352. check_mesh_group_added(wpas1)
  353. check_mesh_peer_connected(wpas0)
  354. check_mesh_peer_connected(wpas1)
  355. hwsim_utils.test_connectivity(wpas0, wpas1)
  356. # Must not allow MESH_GROUP_REMOVE on dynamic interface
  357. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
  358. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  359. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
  360. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  361. # Must not allow MESH_GROUP_REMOVE on another radio interface
  362. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
  363. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  364. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
  365. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  366. wpas0.remove_ifname()
  367. wpas1.remove_ifname()
  368. if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  369. raise Exception("MESH_GROUP_REMOVE failed")
  370. if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  371. raise Exception("MESH_GROUP_REMOVE failed")
  372. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  373. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  374. if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  375. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  376. logger.info("Make sure another dynamic group can be added")
  377. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  378. if "FAIL" in mesh0:
  379. raise Exception("MESH_INTERFACE_ADD failed")
  380. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  381. if "FAIL" in mesh1:
  382. raise Exception("MESH_INTERFACE_ADD failed")
  383. wpas0 = WpaSupplicant(ifname=mesh0)
  384. wpas1 = WpaSupplicant(ifname=mesh1)
  385. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  386. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  387. add_open_mesh_network(wpas0)
  388. add_open_mesh_network(wpas1)
  389. check_mesh_group_added(wpas0)
  390. check_mesh_group_added(wpas1)
  391. check_mesh_peer_connected(wpas0)
  392. check_mesh_peer_connected(wpas1)
  393. hwsim_utils.test_connectivity(wpas0, wpas1)
  394. finally:
  395. if mesh0:
  396. dev[0].request("MESH_GROUP_REMOVE " + mesh0)
  397. if mesh1:
  398. dev[1].request("MESH_GROUP_REMOVE " + mesh1)
  399. def test_wpas_mesh_max_peering(dev, apdev):
  400. """Mesh max peering limit"""
  401. check_mesh_support(dev[0])
  402. try:
  403. dev[0].request("SET max_peer_links 1")
  404. # first, connect dev[0] and dev[1]
  405. add_open_mesh_network(dev[0])
  406. add_open_mesh_network(dev[1])
  407. for i in range(2):
  408. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  409. if ev is None:
  410. raise Exception("dev%d did not connect with any peer" % i)
  411. # add dev[2] which will try to connect with both dev[0] and dev[1],
  412. # but can complete connection only with dev[1]
  413. add_open_mesh_network(dev[2])
  414. for i in range(1, 3):
  415. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  416. if ev is None:
  417. raise Exception("dev%d did not connect the second peer" % i)
  418. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  419. if ev is not None:
  420. raise Exception("dev0 connection beyond max peering limit")
  421. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  422. if ev is not None:
  423. raise Exception("dev2 reported unexpected peering: " + ev)
  424. for i in range(3):
  425. dev[i].mesh_group_remove()
  426. check_mesh_group_removed(dev[i])
  427. finally:
  428. dev[0].request("SET max_peer_links 99")
  429. def test_wpas_mesh_open_5ghz(dev, apdev):
  430. """wpa_supplicant open MESH network on 5 GHz band"""
  431. try:
  432. _test_wpas_mesh_open_5ghz(dev, apdev)
  433. finally:
  434. subprocess.call(['iw', 'reg', 'set', '00'])
  435. dev[0].flush_scan_cache()
  436. dev[1].flush_scan_cache()
  437. def _test_wpas_mesh_open_5ghz(dev, apdev):
  438. check_mesh_support(dev[0])
  439. subprocess.call(['iw', 'reg', 'set', 'US'])
  440. for i in range(2):
  441. for j in range(5):
  442. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  443. if ev is None:
  444. raise Exception("No regdom change event")
  445. if "alpha2=US" in ev:
  446. break
  447. add_open_mesh_network(dev[i], freq="5180")
  448. # Check for mesh joined
  449. check_mesh_group_added(dev[0])
  450. check_mesh_group_added(dev[1])
  451. # Check for peer connected
  452. check_mesh_peer_connected(dev[0])
  453. check_mesh_peer_connected(dev[1])
  454. # Test connectivity 0->1 and 1->0
  455. hwsim_utils.test_connectivity(dev[0], dev[1])
  456. def test_wpas_mesh_open_vht_80p80(dev, apdev):
  457. """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
  458. try:
  459. _test_wpas_mesh_open_vht_80p80(dev, apdev)
  460. finally:
  461. subprocess.call(['iw', 'reg', 'set', '00'])
  462. dev[0].flush_scan_cache()
  463. dev[1].flush_scan_cache()
  464. def _test_wpas_mesh_open_vht_80p80(dev, apdev):
  465. check_mesh_support(dev[0])
  466. subprocess.call(['iw', 'reg', 'set', 'US'])
  467. for i in range(2):
  468. for j in range(5):
  469. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  470. if ev is None:
  471. raise Exception("No regdom change event")
  472. if "alpha2=US" in ev:
  473. break
  474. add_open_mesh_network(dev[i], freq="5180", chwidth=3)
  475. # Check for mesh joined
  476. check_mesh_group_added(dev[0])
  477. check_mesh_group_added(dev[1])
  478. # Check for peer connected
  479. check_mesh_peer_connected(dev[0])
  480. check_mesh_peer_connected(dev[1])
  481. # Test connectivity 0->1 and 1->0
  482. hwsim_utils.test_connectivity(dev[0], dev[1])
  483. sig = dev[0].request("SIGNAL_POLL").splitlines()
  484. if "WIDTH=80+80 MHz" not in sig:
  485. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  486. if "CENTER_FRQ1=5210" not in sig:
  487. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  488. if "CENTER_FRQ2=5775" not in sig:
  489. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  490. sig = dev[1].request("SIGNAL_POLL").splitlines()
  491. if "WIDTH=80+80 MHz" not in sig:
  492. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  493. if "CENTER_FRQ1=5210" not in sig:
  494. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  495. if "CENTER_FRQ2=5775" not in sig:
  496. raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
  497. def test_wpas_mesh_password_mismatch(dev, apdev):
  498. """Mesh network and one device with mismatching password"""
  499. check_mesh_support(dev[0], secure=True)
  500. dev[0].request("SET sae_groups ")
  501. id = add_mesh_secure_net(dev[0])
  502. dev[0].mesh_group_add(id)
  503. dev[1].request("SET sae_groups ")
  504. id = add_mesh_secure_net(dev[1])
  505. dev[1].mesh_group_add(id)
  506. dev[2].request("SET sae_groups ")
  507. id = add_mesh_secure_net(dev[2])
  508. dev[2].set_network_quoted(id, "psk", "wrong password")
  509. dev[2].mesh_group_add(id)
  510. # The two peers with matching password need to be able to connect
  511. check_mesh_group_added(dev[0])
  512. check_mesh_group_added(dev[1])
  513. check_mesh_peer_connected(dev[0])
  514. check_mesh_peer_connected(dev[1])
  515. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  516. if ev is None:
  517. raise Exception("dev2 did not report auth failure (1)")
  518. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  519. if ev is None:
  520. raise Exception("dev2 did not report auth failure (2)")
  521. count = 0
  522. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  523. if ev is None:
  524. logger.info("dev0 did not report auth failure")
  525. else:
  526. if "addr=" + dev[2].own_addr() not in ev:
  527. raise Exception("Unexpected peer address in dev0 event: " + ev)
  528. count += 1
  529. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  530. if ev is None:
  531. logger.info("dev1 did not report auth failure")
  532. else:
  533. if "addr=" + dev[2].own_addr() not in ev:
  534. raise Exception("Unexpected peer address in dev1 event: " + ev)
  535. count += 1
  536. hwsim_utils.test_connectivity(dev[0], dev[1])
  537. for i in range(2):
  538. try:
  539. hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
  540. raise Exception("Data connectivity test passed unexpectedly")
  541. except Exception, e:
  542. if "data delivery failed" not in str(e):
  543. raise
  544. if count == 0:
  545. raise Exception("Neither dev0 nor dev1 reported auth failure")
  546. def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
  547. """Mesh password mismatch and retry [long]"""
  548. if not params['long']:
  549. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  550. check_mesh_support(dev[0], secure=True)
  551. dev[0].request("SET sae_groups ")
  552. id = add_mesh_secure_net(dev[0])
  553. dev[0].mesh_group_add(id)
  554. dev[1].request("SET sae_groups ")
  555. id = add_mesh_secure_net(dev[1])
  556. dev[1].set_network_quoted(id, "psk", "wrong password")
  557. dev[1].mesh_group_add(id)
  558. # Check for mesh joined
  559. check_mesh_group_added(dev[0])
  560. check_mesh_group_added(dev[1])
  561. for i in range(4):
  562. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  563. if ev is None:
  564. raise Exception("dev0 did not report auth failure (%d)" % i)
  565. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  566. if ev is None:
  567. raise Exception("dev1 did not report auth failure (%d)" % i)
  568. ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  569. if ev is None:
  570. raise Exception("dev0 did not report auth blocked")
  571. ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  572. if ev is None:
  573. raise Exception("dev1 did not report auth blocked")
  574. def test_mesh_wpa_auth_init_oom(dev, apdev):
  575. """Secure mesh network setup failing due to wpa_init() OOM"""
  576. check_mesh_support(dev[0], secure=True)
  577. dev[0].request("SET sae_groups ")
  578. with alloc_fail(dev[0], 1, "wpa_init"):
  579. id = add_mesh_secure_net(dev[0])
  580. dev[0].mesh_group_add(id)
  581. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
  582. if ev is not None:
  583. raise Exception("Unexpected mesh group start during OOM")
  584. def test_mesh_wpa_init_fail(dev, apdev):
  585. """Secure mesh network setup local failure"""
  586. check_mesh_support(dev[0], secure=True)
  587. dev[0].request("SET sae_groups ")
  588. with fail_test(dev[0], 1, "os_get_random;=__mesh_rsn_auth_init"):
  589. id = add_mesh_secure_net(dev[0])
  590. dev[0].mesh_group_add(id)
  591. wait_fail_trigger(dev[0], "GET_FAIL")
  592. with alloc_fail(dev[0], 1, "mesh_rsn_auth_init"):
  593. id = add_mesh_secure_net(dev[0])
  594. dev[0].mesh_group_add(id)
  595. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  596. def test_wpas_mesh_reconnect(dev, apdev):
  597. """Secure mesh network plink counting during reconnection"""
  598. check_mesh_support(dev[0])
  599. try:
  600. _test_wpas_mesh_reconnect(dev)
  601. finally:
  602. dev[0].request("SET max_peer_links 99")
  603. def _test_wpas_mesh_reconnect(dev):
  604. dev[0].request("SET max_peer_links 2")
  605. dev[0].request("SET sae_groups ")
  606. id = add_mesh_secure_net(dev[0])
  607. dev[0].set_network(id, "beacon_int", "100")
  608. dev[0].mesh_group_add(id)
  609. dev[1].request("SET sae_groups ")
  610. id = add_mesh_secure_net(dev[1])
  611. dev[1].mesh_group_add(id)
  612. check_mesh_group_added(dev[0])
  613. check_mesh_group_added(dev[1])
  614. check_mesh_peer_connected(dev[0])
  615. check_mesh_peer_connected(dev[1])
  616. for i in range(3):
  617. # Drop incoming management frames to avoid handling link close
  618. dev[0].request("SET ext_mgmt_frame_handling 1")
  619. dev[1].mesh_group_remove()
  620. check_mesh_group_removed(dev[1])
  621. dev[1].request("FLUSH")
  622. dev[0].request("SET ext_mgmt_frame_handling 0")
  623. id = add_mesh_secure_net(dev[1])
  624. dev[1].mesh_group_add(id)
  625. check_mesh_group_added(dev[1])
  626. check_mesh_peer_connected(dev[1])
  627. dev[0].dump_monitor()
  628. dev[1].dump_monitor()
  629. def test_wpas_mesh_gate_forwarding(dev, apdev, p):
  630. """Mesh forwards traffic to unknown sta to mesh gates"""
  631. addr0 = dev[0].own_addr()
  632. addr1 = dev[1].own_addr()
  633. addr2 = dev[2].own_addr()
  634. external_sta = '02:11:22:33:44:55'
  635. # start 3 node connected mesh
  636. check_mesh_support(dev[0])
  637. for i in range(3):
  638. add_open_mesh_network(dev[i])
  639. check_mesh_group_added(dev[i])
  640. for i in range(3):
  641. check_mesh_peer_connected(dev[i])
  642. hwsim_utils.test_connectivity(dev[0], dev[1])
  643. hwsim_utils.test_connectivity(dev[1], dev[2])
  644. hwsim_utils.test_connectivity(dev[0], dev[2])
  645. # dev0 and dev1 are mesh gates
  646. subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
  647. 'mesh_gate_announcements=1'])
  648. subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
  649. 'mesh_gate_announcements=1'])
  650. # wait for gate announcement frames
  651. time.sleep(1)
  652. # data frame from dev2 -> external sta should be sent to both gates
  653. dev[2].request("DATA_TEST_CONFIG 1")
  654. dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
  655. dev[2].request("DATA_TEST_CONFIG 0")
  656. capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
  657. filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
  658. external_sta)
  659. for i in range(15):
  660. da = run_tshark(capfile, filt, [ "wlan.da" ])
  661. if addr0 in da and addr1 in da:
  662. logger.debug("Frames seen in tshark iteration %d" % i)
  663. break
  664. time.sleep(0.3)
  665. if addr0 not in da:
  666. raise Exception("Frame to gate %s not observed" % addr0)
  667. if addr1 not in da:
  668. raise Exception("Frame to gate %s not observed" % addr1)
  669. def test_wpas_mesh_pmksa_caching(dev, apdev):
  670. """Secure mesh network and PMKSA caching"""
  671. check_mesh_support(dev[0], secure=True)
  672. dev[0].request("SET sae_groups ")
  673. id = add_mesh_secure_net(dev[0])
  674. dev[0].mesh_group_add(id)
  675. dev[1].request("SET sae_groups ")
  676. id = add_mesh_secure_net(dev[1])
  677. dev[1].mesh_group_add(id)
  678. # Check for mesh joined
  679. check_mesh_group_added(dev[0])
  680. check_mesh_group_added(dev[1])
  681. # Check for peer connected
  682. check_mesh_peer_connected(dev[0])
  683. check_mesh_peer_connected(dev[1])
  684. addr0 = dev[0].own_addr()
  685. addr1 = dev[1].own_addr()
  686. pmksa0 = dev[0].get_pmksa(addr1)
  687. pmksa1 = dev[1].get_pmksa(addr0)
  688. if pmksa0 is None or pmksa1 is None:
  689. raise Exception("No PMKSA cache entry created")
  690. if pmksa0['pmkid'] != pmksa1['pmkid']:
  691. raise Exception("PMKID mismatch in PMKSA cache entries")
  692. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  693. raise Exception("Failed to remove peer")
  694. pmksa0b = dev[0].get_pmksa(addr1)
  695. if pmksa0b is None:
  696. raise Exception("PMKSA cache entry not maintained")
  697. time.sleep(0.1)
  698. if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
  699. raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
  700. def test_wpas_mesh_pmksa_caching2(dev, apdev):
  701. """Secure mesh network and PMKSA caching with no_auto_peer=1"""
  702. check_mesh_support(dev[0], secure=True)
  703. addr0 = dev[0].own_addr()
  704. addr1 = dev[1].own_addr()
  705. dev[0].request("SET sae_groups ")
  706. id = add_mesh_secure_net(dev[0])
  707. dev[0].set_network(id, "no_auto_peer", "1")
  708. dev[0].mesh_group_add(id)
  709. dev[1].request("SET sae_groups ")
  710. id = add_mesh_secure_net(dev[1])
  711. dev[1].set_network(id, "no_auto_peer", "1")
  712. dev[1].mesh_group_add(id)
  713. # Check for mesh joined
  714. check_mesh_group_added(dev[0])
  715. check_mesh_group_added(dev[1])
  716. # Check for peer connected
  717. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  718. if ev is None:
  719. raise Exception("Missing no-initiate message")
  720. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  721. raise Exception("MESH_PEER_ADD failed")
  722. check_mesh_peer_connected(dev[0])
  723. check_mesh_peer_connected(dev[1])
  724. pmksa0 = dev[0].get_pmksa(addr1)
  725. pmksa1 = dev[1].get_pmksa(addr0)
  726. if pmksa0 is None or pmksa1 is None:
  727. raise Exception("No PMKSA cache entry created")
  728. if pmksa0['pmkid'] != pmksa1['pmkid']:
  729. raise Exception("PMKID mismatch in PMKSA cache entries")
  730. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  731. raise Exception("Failed to remove peer")
  732. pmksa0b = dev[0].get_pmksa(addr1)
  733. if pmksa0b is None:
  734. raise Exception("PMKSA cache entry not maintained")
  735. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  736. if ev is None:
  737. raise Exception("Missing no-initiate message (2)")
  738. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  739. raise Exception("MESH_PEER_ADD failed (2)")
  740. check_mesh_peer_connected(dev[0])
  741. check_mesh_peer_connected(dev[1])
  742. pmksa0c = dev[0].get_pmksa(addr1)
  743. pmksa1c = dev[1].get_pmksa(addr0)
  744. if pmksa0c is None or pmksa1c is None:
  745. raise Exception("No PMKSA cache entry created (2)")
  746. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  747. raise Exception("PMKID mismatch in PMKSA cache entries")
  748. if pmksa0['pmkid'] != pmksa0c['pmkid']:
  749. raise Exception("PMKID changed")
  750. hwsim_utils.test_connectivity(dev[0], dev[1])
  751. def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
  752. """Secure mesh network and PMKSA caching with no PMKID match"""
  753. check_mesh_support(dev[0], secure=True)
  754. addr0 = dev[0].own_addr()
  755. addr1 = dev[1].own_addr()
  756. dev[0].request("SET sae_groups ")
  757. id = add_mesh_secure_net(dev[0])
  758. dev[0].set_network(id, "no_auto_peer", "1")
  759. dev[0].mesh_group_add(id)
  760. dev[1].request("SET sae_groups ")
  761. id = add_mesh_secure_net(dev[1])
  762. dev[1].set_network(id, "no_auto_peer", "1")
  763. dev[1].mesh_group_add(id)
  764. # Check for mesh joined
  765. check_mesh_group_added(dev[0])
  766. check_mesh_group_added(dev[1])
  767. # Check for peer connected
  768. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  769. if ev is None:
  770. raise Exception("Missing no-initiate message")
  771. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  772. raise Exception("MESH_PEER_ADD failed")
  773. check_mesh_peer_connected(dev[0])
  774. check_mesh_peer_connected(dev[1])
  775. pmksa0 = dev[0].get_pmksa(addr1)
  776. pmksa1 = dev[1].get_pmksa(addr0)
  777. if pmksa0 is None or pmksa1 is None:
  778. raise Exception("No PMKSA cache entry created")
  779. if pmksa0['pmkid'] != pmksa1['pmkid']:
  780. raise Exception("PMKID mismatch in PMKSA cache entries")
  781. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  782. raise Exception("Failed to remove peer")
  783. if "OK" not in dev[1].request("PMKSA_FLUSH"):
  784. raise Exception("Failed to flush PMKSA cache")
  785. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  786. if ev is None:
  787. raise Exception("Missing no-initiate message (2)")
  788. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  789. raise Exception("MESH_PEER_ADD failed (2)")
  790. check_mesh_peer_connected(dev[0])
  791. check_mesh_peer_connected(dev[1])
  792. pmksa0c = dev[0].get_pmksa(addr1)
  793. pmksa1c = dev[1].get_pmksa(addr0)
  794. if pmksa0c is None or pmksa1c is None:
  795. raise Exception("No PMKSA cache entry created (2)")
  796. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  797. raise Exception("PMKID mismatch in PMKSA cache entries")
  798. if pmksa0['pmkid'] == pmksa0c['pmkid']:
  799. raise Exception("PMKID did not change")
  800. hwsim_utils.test_connectivity(dev[0], dev[1])
  801. def test_mesh_oom(dev, apdev):
  802. """Mesh network setup failing due to OOM"""
  803. check_mesh_support(dev[0], secure=True)
  804. dev[0].request("SET sae_groups ")
  805. with alloc_fail(dev[0], 1, "mesh_config_create"):
  806. add_open_mesh_network(dev[0])
  807. ev = dev[0].wait_event(["Failed to init mesh"])
  808. if ev is None:
  809. raise Exception("Init failure not reported")
  810. for i in range(1, 65):
  811. with alloc_fail(dev[0], i, "wpa_supplicant_mesh_init"):
  812. add_open_mesh_network(dev[0])
  813. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  814. ev = dev[0].wait_event(["Failed to init mesh",
  815. "MESH-GROUP-STARTED"])
  816. if ev is None:
  817. raise Exception("Init failure not reported")
  818. def test_mesh_add_interface_oom(dev):
  819. """wpa_supplicant mesh with dynamic interface addition failing"""
  820. check_mesh_support(dev[0])
  821. for i in range(1, 3):
  822. mesh = None
  823. try:
  824. with alloc_fail(dev[0], i, "wpas_mesh_add_interface"):
  825. mesh = dev[0].request("MESH_INTERFACE_ADD").strip()
  826. finally:
  827. if mesh and mesh != "FAIL":
  828. dev[0].request("MESH_GROUP_REMOVE " + mesh)
  829. def test_mesh_scan_oom(dev):
  830. """wpa_supplicant mesh scan results and OOM"""
  831. check_mesh_support(dev[0])
  832. add_open_mesh_network(dev[0])
  833. check_mesh_group_added(dev[0])
  834. for i in range(5):
  835. dev[1].scan(freq="2412")
  836. res = dev[1].request("SCAN_RESULTS")
  837. if "[MESH]" in res:
  838. break
  839. for r in res.splitlines():
  840. if "[MESH]" in r:
  841. break
  842. bssid = r.split('\t')[0]
  843. bss = dev[1].get_bss(bssid)
  844. if bss is None:
  845. raise Exception("Could not get BSS entry for mesh")
  846. for i in range(1, 3):
  847. with alloc_fail(dev[1], i, "mesh_attr_text"):
  848. bss = dev[1].get_bss(bssid)
  849. if bss is not None:
  850. raise Exception("Unexpected BSS result during OOM")