test_wpas_mesh.py 52 KB

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