test_wpas_mesh.py 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  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_ctrl(dev):
  288. """wpa_supplicant ctrl_iface mesh command error cases"""
  289. check_mesh_support(dev[0])
  290. if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
  291. raise Exception("Unexpected MESH_GROUP_ADD success")
  292. id = dev[0].add_network()
  293. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  294. raise Exception("Unexpected MESH_GROUP_ADD success")
  295. dev[0].set_network(id, "mode", "5")
  296. dev[0].set_network(id, "key_mgmt", "WPA-PSK")
  297. if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
  298. raise Exception("Unexpected MESH_GROUP_ADD success")
  299. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
  300. raise Exception("Unexpected MESH_GROUP_REMOVE success")
  301. def test_wpas_mesh_dynamic_interface(dev):
  302. """wpa_supplicant mesh with dynamic interface"""
  303. check_mesh_support(dev[0])
  304. mesh0 = None
  305. mesh1 = None
  306. try:
  307. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  308. if "FAIL" in mesh0:
  309. raise Exception("MESH_INTERFACE_ADD failed")
  310. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  311. if "FAIL" in mesh1:
  312. raise Exception("MESH_INTERFACE_ADD failed")
  313. wpas0 = WpaSupplicant(ifname=mesh0)
  314. wpas1 = WpaSupplicant(ifname=mesh1)
  315. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  316. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  317. add_open_mesh_network(wpas0)
  318. add_open_mesh_network(wpas1)
  319. check_mesh_group_added(wpas0)
  320. check_mesh_group_added(wpas1)
  321. check_mesh_peer_connected(wpas0)
  322. check_mesh_peer_connected(wpas1)
  323. hwsim_utils.test_connectivity(wpas0, wpas1)
  324. # Must not allow MESH_GROUP_REMOVE on dynamic interface
  325. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
  326. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  327. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
  328. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  329. # Must not allow MESH_GROUP_REMOVE on another radio interface
  330. if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
  331. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  332. if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
  333. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  334. wpas0.remove_ifname()
  335. wpas1.remove_ifname()
  336. if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  337. raise Exception("MESH_GROUP_REMOVE failed")
  338. if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  339. raise Exception("MESH_GROUP_REMOVE failed")
  340. if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
  341. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  342. if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
  343. raise Exception("Invalid MESH_GROUP_REMOVE accepted")
  344. logger.info("Make sure another dynamic group can be added")
  345. mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
  346. if "FAIL" in mesh0:
  347. raise Exception("MESH_INTERFACE_ADD failed")
  348. mesh1 = dev[1].request("MESH_INTERFACE_ADD")
  349. if "FAIL" in mesh1:
  350. raise Exception("MESH_INTERFACE_ADD failed")
  351. wpas0 = WpaSupplicant(ifname=mesh0)
  352. wpas1 = WpaSupplicant(ifname=mesh1)
  353. logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
  354. logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
  355. add_open_mesh_network(wpas0)
  356. add_open_mesh_network(wpas1)
  357. check_mesh_group_added(wpas0)
  358. check_mesh_group_added(wpas1)
  359. check_mesh_peer_connected(wpas0)
  360. check_mesh_peer_connected(wpas1)
  361. hwsim_utils.test_connectivity(wpas0, wpas1)
  362. finally:
  363. if mesh0:
  364. dev[0].request("MESH_GROUP_REMOVE " + mesh0)
  365. if mesh1:
  366. dev[1].request("MESH_GROUP_REMOVE " + mesh1)
  367. def test_wpas_mesh_max_peering(dev, apdev):
  368. """Mesh max peering limit"""
  369. check_mesh_support(dev[0])
  370. try:
  371. dev[0].request("SET max_peer_links 1")
  372. # first, connect dev[0] and dev[1]
  373. add_open_mesh_network(dev[0])
  374. add_open_mesh_network(dev[1])
  375. for i in range(2):
  376. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  377. if ev is None:
  378. raise Exception("dev%d did not connect with any peer" % i)
  379. # add dev[2] which will try to connect with both dev[0] and dev[1],
  380. # but can complete connection only with dev[1]
  381. add_open_mesh_network(dev[2])
  382. for i in range(1, 3):
  383. ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
  384. if ev is None:
  385. raise Exception("dev%d did not connect the second peer" % i)
  386. ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
  387. if ev is not None:
  388. raise Exception("dev0 connection beyond max peering limit")
  389. ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
  390. if ev is not None:
  391. raise Exception("dev2 reported unexpected peering: " + ev)
  392. for i in range(3):
  393. dev[i].mesh_group_remove()
  394. check_mesh_group_removed(dev[i])
  395. finally:
  396. dev[0].request("SET max_peer_links 99")
  397. def test_wpas_mesh_open_5ghz(dev, apdev):
  398. """wpa_supplicant open MESH network on 5 GHz band"""
  399. try:
  400. _test_wpas_mesh_open_5ghz(dev, apdev)
  401. finally:
  402. subprocess.call(['iw', 'reg', 'set', '00'])
  403. dev[0].flush_scan_cache()
  404. dev[1].flush_scan_cache()
  405. def _test_wpas_mesh_open_5ghz(dev, apdev):
  406. check_mesh_support(dev[0])
  407. subprocess.call(['iw', 'reg', 'set', 'US'])
  408. for i in range(2):
  409. for j in range(5):
  410. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  411. if ev is None:
  412. raise Exception("No regdom change event")
  413. if "alpha2=US" in ev:
  414. break
  415. add_open_mesh_network(dev[i], freq="5180")
  416. # Check for mesh joined
  417. check_mesh_group_added(dev[0])
  418. check_mesh_group_added(dev[1])
  419. # Check for peer connected
  420. check_mesh_peer_connected(dev[0])
  421. check_mesh_peer_connected(dev[1])
  422. # Test connectivity 0->1 and 1->0
  423. hwsim_utils.test_connectivity(dev[0], dev[1])
  424. def test_wpas_mesh_open_vht_80p80(dev, apdev):
  425. """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
  426. try:
  427. _test_wpas_mesh_open_vht_80p80(dev, apdev)
  428. finally:
  429. subprocess.call(['iw', 'reg', 'set', '00'])
  430. dev[0].flush_scan_cache()
  431. dev[1].flush_scan_cache()
  432. def _test_wpas_mesh_open_vht_80p80(dev, apdev):
  433. check_mesh_support(dev[0])
  434. subprocess.call(['iw', 'reg', 'set', 'US'])
  435. for i in range(2):
  436. for j in range(5):
  437. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  438. if ev is None:
  439. raise Exception("No regdom change event")
  440. if "alpha2=US" in ev:
  441. break
  442. add_open_mesh_network(dev[i], freq="5180", chwidth=3)
  443. # Check for mesh joined
  444. check_mesh_group_added(dev[0])
  445. check_mesh_group_added(dev[1])
  446. # Check for peer connected
  447. check_mesh_peer_connected(dev[0])
  448. check_mesh_peer_connected(dev[1])
  449. # Test connectivity 0->1 and 1->0
  450. hwsim_utils.test_connectivity(dev[0], dev[1])
  451. sig = dev[0].request("SIGNAL_POLL").splitlines()
  452. if "WIDTH=80+80 MHz" not in sig:
  453. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  454. if "CENTER_FRQ1=5210" not in sig:
  455. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  456. if "CENTER_FRQ2=5775" not in sig:
  457. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  458. sig = dev[1].request("SIGNAL_POLL").splitlines()
  459. if "WIDTH=80+80 MHz" not in sig:
  460. raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
  461. if "CENTER_FRQ1=5210" not in sig:
  462. raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
  463. if "CENTER_FRQ2=5775" not in sig:
  464. raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
  465. def test_wpas_mesh_password_mismatch(dev, apdev):
  466. """Mesh network and one device with mismatching password"""
  467. check_mesh_support(dev[0], secure=True)
  468. dev[0].request("SET sae_groups ")
  469. id = add_mesh_secure_net(dev[0])
  470. dev[0].mesh_group_add(id)
  471. dev[1].request("SET sae_groups ")
  472. id = add_mesh_secure_net(dev[1])
  473. dev[1].mesh_group_add(id)
  474. dev[2].request("SET sae_groups ")
  475. id = add_mesh_secure_net(dev[2])
  476. dev[2].set_network_quoted(id, "psk", "wrong password")
  477. dev[2].mesh_group_add(id)
  478. # The two peers with matching password need to be able to connect
  479. check_mesh_group_added(dev[0])
  480. check_mesh_group_added(dev[1])
  481. check_mesh_peer_connected(dev[0])
  482. check_mesh_peer_connected(dev[1])
  483. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  484. if ev is None:
  485. raise Exception("dev2 did not report auth failure (1)")
  486. ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  487. if ev is None:
  488. raise Exception("dev2 did not report auth failure (2)")
  489. count = 0
  490. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  491. if ev is None:
  492. logger.info("dev0 did not report auth failure")
  493. else:
  494. if "addr=" + dev[2].own_addr() not in ev:
  495. raise Exception("Unexpected peer address in dev0 event: " + ev)
  496. count += 1
  497. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
  498. if ev is None:
  499. logger.info("dev1 did not report auth failure")
  500. else:
  501. if "addr=" + dev[2].own_addr() not in ev:
  502. raise Exception("Unexpected peer address in dev1 event: " + ev)
  503. count += 1
  504. hwsim_utils.test_connectivity(dev[0], dev[1])
  505. for i in range(2):
  506. try:
  507. hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
  508. raise Exception("Data connectivity test passed unexpectedly")
  509. except Exception, e:
  510. if "data delivery failed" not in str(e):
  511. raise
  512. if count == 0:
  513. raise Exception("Neither dev0 nor dev1 reported auth failure")
  514. def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
  515. """Mesh password mismatch and retry [long]"""
  516. if not params['long']:
  517. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  518. check_mesh_support(dev[0], secure=True)
  519. dev[0].request("SET sae_groups ")
  520. id = add_mesh_secure_net(dev[0])
  521. dev[0].mesh_group_add(id)
  522. dev[1].request("SET sae_groups ")
  523. id = add_mesh_secure_net(dev[1])
  524. dev[1].set_network_quoted(id, "psk", "wrong password")
  525. dev[1].mesh_group_add(id)
  526. # Check for mesh joined
  527. check_mesh_group_added(dev[0])
  528. check_mesh_group_added(dev[1])
  529. for i in range(4):
  530. ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  531. if ev is None:
  532. raise Exception("dev0 did not report auth failure (%d)" % i)
  533. ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
  534. if ev is None:
  535. raise Exception("dev1 did not report auth failure (%d)" % i)
  536. ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  537. if ev is None:
  538. raise Exception("dev0 did not report auth blocked")
  539. ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
  540. if ev is None:
  541. raise Exception("dev1 did not report auth blocked")
  542. def test_mesh_wpa_auth_init_oom(dev, apdev):
  543. """Secure mesh network setup failing due to wpa_init() OOM"""
  544. check_mesh_support(dev[0], secure=True)
  545. dev[0].request("SET sae_groups ")
  546. with alloc_fail(dev[0], 1, "wpa_init"):
  547. id = add_mesh_secure_net(dev[0])
  548. dev[0].mesh_group_add(id)
  549. ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
  550. if ev is not None:
  551. raise Exception("Unexpected mesh group start during OOM")
  552. def test_wpas_mesh_reconnect(dev, apdev):
  553. """Secure mesh network plink counting during reconnection"""
  554. check_mesh_support(dev[0])
  555. try:
  556. _test_wpas_mesh_reconnect(dev)
  557. finally:
  558. dev[0].request("SET max_peer_links 99")
  559. def _test_wpas_mesh_reconnect(dev):
  560. dev[0].request("SET max_peer_links 2")
  561. dev[0].request("SET sae_groups ")
  562. id = add_mesh_secure_net(dev[0])
  563. dev[0].set_network(id, "beacon_int", "100")
  564. dev[0].mesh_group_add(id)
  565. dev[1].request("SET sae_groups ")
  566. id = add_mesh_secure_net(dev[1])
  567. dev[1].mesh_group_add(id)
  568. check_mesh_group_added(dev[0])
  569. check_mesh_group_added(dev[1])
  570. check_mesh_peer_connected(dev[0])
  571. check_mesh_peer_connected(dev[1])
  572. for i in range(3):
  573. # Drop incoming management frames to avoid handling link close
  574. dev[0].request("SET ext_mgmt_frame_handling 1")
  575. dev[1].mesh_group_remove()
  576. check_mesh_group_removed(dev[1])
  577. dev[1].request("FLUSH")
  578. dev[0].request("SET ext_mgmt_frame_handling 0")
  579. id = add_mesh_secure_net(dev[1])
  580. dev[1].mesh_group_add(id)
  581. check_mesh_group_added(dev[1])
  582. check_mesh_peer_connected(dev[1])
  583. dev[0].dump_monitor()
  584. dev[1].dump_monitor()
  585. def test_wpas_mesh_gate_forwarding(dev, apdev, p):
  586. """Mesh forwards traffic to unknown sta to mesh gates"""
  587. addr0 = dev[0].own_addr()
  588. addr1 = dev[1].own_addr()
  589. addr2 = dev[2].own_addr()
  590. external_sta = '02:11:22:33:44:55'
  591. # start 3 node connected mesh
  592. check_mesh_support(dev[0])
  593. for i in range(3):
  594. add_open_mesh_network(dev[i])
  595. check_mesh_group_added(dev[i])
  596. for i in range(3):
  597. check_mesh_peer_connected(dev[i])
  598. hwsim_utils.test_connectivity(dev[0], dev[1])
  599. hwsim_utils.test_connectivity(dev[1], dev[2])
  600. hwsim_utils.test_connectivity(dev[0], dev[2])
  601. # dev0 and dev1 are mesh gates
  602. subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
  603. 'mesh_gate_announcements=1'])
  604. subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
  605. 'mesh_gate_announcements=1'])
  606. # wait for gate announcement frames
  607. time.sleep(1)
  608. # data frame from dev2 -> external sta should be sent to both gates
  609. dev[2].request("DATA_TEST_CONFIG 1")
  610. dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
  611. dev[2].request("DATA_TEST_CONFIG 0")
  612. capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
  613. filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
  614. external_sta)
  615. for i in range(15):
  616. da = run_tshark(capfile, filt, [ "wlan.da" ])
  617. if addr0 in da and addr1 in da:
  618. logger.debug("Frames seen in tshark iteration %d" % i)
  619. break
  620. time.sleep(0.3)
  621. if addr0 not in da:
  622. raise Exception("Frame to gate %s not observed" % addr0)
  623. if addr1 not in da:
  624. raise Exception("Frame to gate %s not observed" % addr1)
  625. def test_wpas_mesh_pmksa_caching(dev, apdev):
  626. """Secure mesh network and PMKSA caching"""
  627. check_mesh_support(dev[0], secure=True)
  628. dev[0].request("SET sae_groups ")
  629. id = add_mesh_secure_net(dev[0])
  630. dev[0].mesh_group_add(id)
  631. dev[1].request("SET sae_groups ")
  632. id = add_mesh_secure_net(dev[1])
  633. dev[1].mesh_group_add(id)
  634. # Check for mesh joined
  635. check_mesh_group_added(dev[0])
  636. check_mesh_group_added(dev[1])
  637. # Check for peer connected
  638. check_mesh_peer_connected(dev[0])
  639. check_mesh_peer_connected(dev[1])
  640. addr0 = dev[0].own_addr()
  641. addr1 = dev[1].own_addr()
  642. pmksa0 = dev[0].get_pmksa(addr1)
  643. pmksa1 = dev[1].get_pmksa(addr0)
  644. if pmksa0 is None or pmksa1 is None:
  645. raise Exception("No PMKSA cache entry created")
  646. if pmksa0['pmkid'] != pmksa1['pmkid']:
  647. raise Exception("PMKID mismatch in PMKSA cache entries")
  648. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  649. raise Exception("Failed to remove peer")
  650. pmksa0b = dev[0].get_pmksa(addr1)
  651. if pmksa0b is None:
  652. raise Exception("PMKSA cache entry not maintained")
  653. time.sleep(0.1)
  654. if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
  655. raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
  656. def test_wpas_mesh_pmksa_caching2(dev, apdev):
  657. """Secure mesh network and PMKSA caching with no_auto_peer=1"""
  658. check_mesh_support(dev[0], secure=True)
  659. addr0 = dev[0].own_addr()
  660. addr1 = dev[1].own_addr()
  661. dev[0].request("SET sae_groups ")
  662. id = add_mesh_secure_net(dev[0])
  663. dev[0].set_network(id, "no_auto_peer", "1")
  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].set_network(id, "no_auto_peer", "1")
  668. dev[1].mesh_group_add(id)
  669. # Check for mesh joined
  670. check_mesh_group_added(dev[0])
  671. check_mesh_group_added(dev[1])
  672. # Check for peer connected
  673. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  674. if ev is None:
  675. raise Exception("Missing no-initiate message")
  676. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  677. raise Exception("MESH_PEER_ADD failed")
  678. check_mesh_peer_connected(dev[0])
  679. check_mesh_peer_connected(dev[1])
  680. pmksa0 = dev[0].get_pmksa(addr1)
  681. pmksa1 = dev[1].get_pmksa(addr0)
  682. if pmksa0 is None or pmksa1 is None:
  683. raise Exception("No PMKSA cache entry created")
  684. if pmksa0['pmkid'] != pmksa1['pmkid']:
  685. raise Exception("PMKID mismatch in PMKSA cache entries")
  686. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  687. raise Exception("Failed to remove peer")
  688. pmksa0b = dev[0].get_pmksa(addr1)
  689. if pmksa0b is None:
  690. raise Exception("PMKSA cache entry not maintained")
  691. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  692. if ev is None:
  693. raise Exception("Missing no-initiate message (2)")
  694. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  695. raise Exception("MESH_PEER_ADD failed (2)")
  696. check_mesh_peer_connected(dev[0])
  697. check_mesh_peer_connected(dev[1])
  698. pmksa0c = dev[0].get_pmksa(addr1)
  699. pmksa1c = dev[1].get_pmksa(addr0)
  700. if pmksa0c is None or pmksa1c is None:
  701. raise Exception("No PMKSA cache entry created (2)")
  702. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  703. raise Exception("PMKID mismatch in PMKSA cache entries")
  704. if pmksa0['pmkid'] != pmksa0c['pmkid']:
  705. raise Exception("PMKID changed")
  706. hwsim_utils.test_connectivity(dev[0], dev[1])
  707. def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
  708. """Secure mesh network and PMKSA caching with no PMKID match"""
  709. check_mesh_support(dev[0], secure=True)
  710. addr0 = dev[0].own_addr()
  711. addr1 = dev[1].own_addr()
  712. dev[0].request("SET sae_groups ")
  713. id = add_mesh_secure_net(dev[0])
  714. dev[0].set_network(id, "no_auto_peer", "1")
  715. dev[0].mesh_group_add(id)
  716. dev[1].request("SET sae_groups ")
  717. id = add_mesh_secure_net(dev[1])
  718. dev[1].set_network(id, "no_auto_peer", "1")
  719. dev[1].mesh_group_add(id)
  720. # Check for mesh joined
  721. check_mesh_group_added(dev[0])
  722. check_mesh_group_added(dev[1])
  723. # Check for peer connected
  724. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  725. if ev is None:
  726. raise Exception("Missing no-initiate message")
  727. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  728. raise Exception("MESH_PEER_ADD failed")
  729. check_mesh_peer_connected(dev[0])
  730. check_mesh_peer_connected(dev[1])
  731. pmksa0 = dev[0].get_pmksa(addr1)
  732. pmksa1 = dev[1].get_pmksa(addr0)
  733. if pmksa0 is None or pmksa1 is None:
  734. raise Exception("No PMKSA cache entry created")
  735. if pmksa0['pmkid'] != pmksa1['pmkid']:
  736. raise Exception("PMKID mismatch in PMKSA cache entries")
  737. if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
  738. raise Exception("Failed to remove peer")
  739. if "OK" not in dev[1].request("PMKSA_FLUSH"):
  740. raise Exception("Failed to flush PMKSA cache")
  741. ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
  742. if ev is None:
  743. raise Exception("Missing no-initiate message (2)")
  744. if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
  745. raise Exception("MESH_PEER_ADD failed (2)")
  746. check_mesh_peer_connected(dev[0])
  747. check_mesh_peer_connected(dev[1])
  748. pmksa0c = dev[0].get_pmksa(addr1)
  749. pmksa1c = dev[1].get_pmksa(addr0)
  750. if pmksa0c is None or pmksa1c is None:
  751. raise Exception("No PMKSA cache entry created (2)")
  752. if pmksa0c['pmkid'] != pmksa1c['pmkid']:
  753. raise Exception("PMKID mismatch in PMKSA cache entries")
  754. if pmksa0['pmkid'] == pmksa0c['pmkid']:
  755. raise Exception("PMKID did not change")
  756. hwsim_utils.test_connectivity(dev[0], dev[1])