test_wpas_mesh.py 47 KB

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