test_wpas_mesh.py 47 KB

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