test_wpas_mesh.py 45 KB

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