test_wpas_mesh.py 33 KB

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