test_wpas_mesh.py 44 KB

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