test_ap_dynamic.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. # Test cases for dynamic BSS changes with hostapd
  2. # Copyright (c) 2013, Qualcomm Atheros, Inc.
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. from remotehost import remote_compatible
  7. import time
  8. import subprocess
  9. import logging
  10. logger = logging.getLogger()
  11. import os
  12. import hwsim_utils
  13. import hostapd
  14. from utils import alloc_fail, require_under_vm, get_phy
  15. from test_ap_acs import force_prev_ap_on_24g
  16. @remote_compatible
  17. def test_ap_change_ssid(dev, apdev):
  18. """Dynamic SSID change with hostapd and WPA2-PSK"""
  19. params = hostapd.wpa2_params(ssid="test-wpa2-psk-start",
  20. passphrase="12345678")
  21. hapd = hostapd.add_ap(apdev[0], params)
  22. id = dev[0].connect("test-wpa2-psk-start", psk="12345678",
  23. scan_freq="2412")
  24. dev[0].request("DISCONNECT")
  25. logger.info("Change SSID dynamically")
  26. res = hapd.request("SET ssid test-wpa2-psk-new")
  27. if "OK" not in res:
  28. raise Exception("SET command failed")
  29. res = hapd.request("RELOAD")
  30. if "OK" not in res:
  31. raise Exception("RELOAD command failed")
  32. dev[0].set_network_quoted(id, "ssid", "test-wpa2-psk-new")
  33. dev[0].connect_network(id)
  34. def multi_check(dev, check, scan_opt=True):
  35. id = []
  36. num_bss = len(check)
  37. for i in range(0, num_bss):
  38. dev[i].request("BSS_FLUSH 0")
  39. dev[i].dump_monitor()
  40. for i in range(0, num_bss):
  41. if check[i]:
  42. continue
  43. id.append(dev[i].connect("bss-" + str(i + 1), key_mgmt="NONE",
  44. scan_freq="2412", wait_connect=False))
  45. for i in range(num_bss):
  46. if not check[i]:
  47. continue
  48. bssid = '02:00:00:00:03:0' + str(i)
  49. if scan_opt:
  50. dev[i].scan_for_bss(bssid, freq=2412)
  51. id.append(dev[i].connect("bss-" + str(i + 1), key_mgmt="NONE",
  52. scan_freq="2412", wait_connect=True))
  53. first = True
  54. for i in range(num_bss):
  55. if not check[i]:
  56. timeout=0.2 if first else 0.01
  57. first = False
  58. ev = dev[i].wait_event(["CTRL-EVENT-CONNECTED"], timeout=timeout)
  59. if ev:
  60. raise Exception("Unexpected connection")
  61. for i in range(0, num_bss):
  62. dev[i].remove_network(id[i])
  63. for i in range(num_bss):
  64. if check[i]:
  65. dev[i].wait_disconnected(timeout=5)
  66. res = ''
  67. for i in range(0, num_bss):
  68. res = res + dev[i].request("BSS RANGE=ALL MASK=0x2")
  69. for i in range(0, num_bss):
  70. if not check[i]:
  71. bssid = '02:00:00:00:03:0' + str(i)
  72. if bssid in res:
  73. raise Exception("Unexpected BSS" + str(i) + " in scan results")
  74. def test_ap_bss_add_remove(dev, apdev):
  75. """Dynamic BSS add/remove operations with hostapd"""
  76. try:
  77. _test_ap_bss_add_remove(dev, apdev)
  78. finally:
  79. for i in range(3):
  80. dev[i].request("SCAN_INTERVAL 5")
  81. def _test_ap_bss_add_remove(dev, apdev):
  82. for i in range(3):
  83. dev[i].flush_scan_cache()
  84. dev[i].request("SCAN_INTERVAL 1")
  85. ifname1 = apdev[0]['ifname']
  86. ifname2 = apdev[0]['ifname'] + '-2'
  87. ifname3 = apdev[0]['ifname'] + '-3'
  88. logger.info("Set up three BSSes one by one")
  89. hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
  90. multi_check(dev, [ True, False, False ])
  91. hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
  92. multi_check(dev, [ True, True, False ])
  93. hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
  94. multi_check(dev, [ True, True, True ])
  95. logger.info("Remove the last BSS and re-add it")
  96. hostapd.remove_bss(apdev[0], ifname3)
  97. multi_check(dev, [ True, True, False ])
  98. hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
  99. multi_check(dev, [ True, True, True ])
  100. logger.info("Remove the middle BSS and re-add it")
  101. hostapd.remove_bss(apdev[0], ifname2)
  102. multi_check(dev, [ True, False, True ])
  103. hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
  104. multi_check(dev, [ True, True, True ])
  105. logger.info("Remove the first BSS and re-add it and other BSSs")
  106. hostapd.remove_bss(apdev[0], ifname1)
  107. multi_check(dev, [ False, False, False ])
  108. hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
  109. hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
  110. hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
  111. multi_check(dev, [ True, True, True ])
  112. logger.info("Remove two BSSes and re-add them")
  113. hostapd.remove_bss(apdev[0], ifname2)
  114. multi_check(dev, [ True, False, True ])
  115. hostapd.remove_bss(apdev[0], ifname3)
  116. multi_check(dev, [ True, False, False ])
  117. hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
  118. multi_check(dev, [ True, True, False ])
  119. hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
  120. multi_check(dev, [ True, True, True ])
  121. logger.info("Remove three BSSes in and re-add them")
  122. hostapd.remove_bss(apdev[0], ifname3)
  123. multi_check(dev, [ True, True, False ])
  124. hostapd.remove_bss(apdev[0], ifname2)
  125. multi_check(dev, [ True, False, False ])
  126. hostapd.remove_bss(apdev[0], ifname1)
  127. multi_check(dev, [ False, False, False ])
  128. hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
  129. multi_check(dev, [ True, False, False ])
  130. hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
  131. multi_check(dev, [ True, True, False ])
  132. hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
  133. multi_check(dev, [ True, True, True ])
  134. logger.info("Test error handling if a duplicate ifname is tried")
  135. hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf', ignore_error=True)
  136. multi_check(dev, [ True, True, True ])
  137. def test_ap_bss_add_remove_during_ht_scan(dev, apdev):
  138. """Dynamic BSS add during HT40 co-ex scan"""
  139. for i in range(3):
  140. dev[i].flush_scan_cache()
  141. ifname1 = apdev[0]['ifname']
  142. ifname2 = apdev[0]['ifname'] + '-2'
  143. hostapd.add_bss(apdev[0], ifname1, 'bss-ht40-1.conf')
  144. hostapd.add_bss(apdev[0], ifname2, 'bss-ht40-2.conf')
  145. multi_check(dev, [ True, True ], scan_opt=False)
  146. hostapd.remove_bss(apdev[0], ifname2)
  147. hostapd.remove_bss(apdev[0], ifname1)
  148. hostapd.add_bss(apdev[0], ifname1, 'bss-ht40-1.conf')
  149. hostapd.add_bss(apdev[0], ifname2, 'bss-ht40-2.conf')
  150. hostapd.remove_bss(apdev[0], ifname2)
  151. multi_check(dev, [ True, False ], scan_opt=False)
  152. hostapd.remove_bss(apdev[0], ifname1)
  153. hostapd.add_bss(apdev[0], ifname1, 'bss-ht40-1.conf')
  154. hostapd.add_bss(apdev[0], ifname2, 'bss-ht40-2.conf')
  155. hostapd.remove_bss(apdev[0], ifname1)
  156. multi_check(dev, [ False, False ])
  157. def test_ap_multi_bss_config(dev, apdev):
  158. """hostapd start with a multi-BSS configuration file"""
  159. for i in range(3):
  160. dev[i].flush_scan_cache()
  161. ifname1 = apdev[0]['ifname']
  162. ifname2 = apdev[0]['ifname'] + '-2'
  163. ifname3 = apdev[0]['ifname'] + '-3'
  164. logger.info("Set up three BSSes with one configuration file")
  165. hapd = hostapd.add_iface(apdev[0], 'multi-bss.conf')
  166. hapd.enable()
  167. multi_check(dev, [ True, True, True ])
  168. hostapd.remove_bss(apdev[0], ifname2)
  169. multi_check(dev, [ True, False, True ])
  170. hostapd.remove_bss(apdev[0], ifname3)
  171. multi_check(dev, [ True, False, False ])
  172. hostapd.remove_bss(apdev[0], ifname1)
  173. multi_check(dev, [ False, False, False ])
  174. hapd = hostapd.add_iface(apdev[0], 'multi-bss.conf')
  175. hapd.enable()
  176. hostapd.remove_bss(apdev[0], ifname1)
  177. multi_check(dev, [ False, False, False ])
  178. def invalid_ap(ap):
  179. logger.info("Trying to start AP " + ap['ifname'] + " with invalid configuration")
  180. hapd = hostapd.add_ap(ap, {}, no_enable=True)
  181. hapd.set("ssid", "invalid-config")
  182. hapd.set("channel", "12345")
  183. try:
  184. hapd.enable()
  185. started = True
  186. except Exception, e:
  187. started = False
  188. if started:
  189. raise Exception("ENABLE command succeeded unexpectedly")
  190. return hapd
  191. @remote_compatible
  192. def test_ap_invalid_config(dev, apdev):
  193. """Try to start AP with invalid configuration and fix configuration"""
  194. hapd = invalid_ap(apdev[0])
  195. logger.info("Fix configuration and start AP again")
  196. hapd.set("channel", "1")
  197. hapd.enable()
  198. dev[0].connect("invalid-config", key_mgmt="NONE", scan_freq="2412")
  199. @remote_compatible
  200. def test_ap_invalid_config2(dev, apdev):
  201. """Try to start AP with invalid configuration and remove interface"""
  202. hapd = invalid_ap(apdev[0])
  203. logger.info("Remove interface with failed configuration")
  204. hostapd.remove_bss(apdev[0])
  205. def test_ap_remove_during_acs(dev, apdev):
  206. """Remove interface during ACS"""
  207. force_prev_ap_on_24g(apdev[0])
  208. params = hostapd.wpa2_params(ssid="test-acs-remove", passphrase="12345678")
  209. params['channel'] = '0'
  210. hostapd.add_ap(apdev[0], params)
  211. hostapd.remove_bss(apdev[0])
  212. def test_ap_remove_during_acs2(dev, apdev):
  213. """Remove BSS during ACS in multi-BSS configuration"""
  214. force_prev_ap_on_24g(apdev[0])
  215. ifname = apdev[0]['ifname']
  216. ifname2 = ifname + "-2"
  217. hapd = hostapd.add_ap(apdev[0], {}, no_enable=True)
  218. hapd.set("ssid", "test-acs-remove")
  219. hapd.set("channel", "0")
  220. hapd.set("bss", ifname2)
  221. hapd.set("ssid", "test-acs-remove2")
  222. hapd.enable()
  223. hostapd.remove_bss(apdev[0])
  224. def test_ap_remove_during_acs3(dev, apdev):
  225. """Remove second BSS during ACS in multi-BSS configuration"""
  226. force_prev_ap_on_24g(apdev[0])
  227. ifname = apdev[0]['ifname']
  228. ifname2 = ifname + "-2"
  229. hapd = hostapd.add_ap(apdev[0], {}, no_enable=True)
  230. hapd.set("ssid", "test-acs-remove")
  231. hapd.set("channel", "0")
  232. hapd.set("bss", ifname2)
  233. hapd.set("ssid", "test-acs-remove2")
  234. hapd.enable()
  235. hostapd.remove_bss(apdev[0], ifname2)
  236. @remote_compatible
  237. def test_ap_remove_during_ht_coex_scan(dev, apdev):
  238. """Remove interface during HT co-ex scan"""
  239. params = hostapd.wpa2_params(ssid="test-ht-remove", passphrase="12345678")
  240. params['channel'] = '1'
  241. params['ht_capab'] = "[HT40+]"
  242. ifname = apdev[0]['ifname']
  243. hostapd.add_ap(apdev[0], params)
  244. hostapd.remove_bss(apdev[0])
  245. def test_ap_remove_during_ht_coex_scan2(dev, apdev):
  246. """Remove BSS during HT co-ex scan in multi-BSS configuration"""
  247. ifname = apdev[0]['ifname']
  248. ifname2 = ifname + "-2"
  249. hapd = hostapd.add_ap(apdev[0], {}, no_enable=True)
  250. hapd.set("ssid", "test-ht-remove")
  251. hapd.set("channel", "1")
  252. hapd.set("ht_capab", "[HT40+]")
  253. hapd.set("bss", ifname2)
  254. hapd.set("ssid", "test-ht-remove2")
  255. hapd.enable()
  256. hostapd.remove_bss(apdev[0])
  257. def test_ap_remove_during_ht_coex_scan3(dev, apdev):
  258. """Remove second BSS during HT co-ex scan in multi-BSS configuration"""
  259. ifname = apdev[0]['ifname']
  260. ifname2 = ifname + "-2"
  261. hapd = hostapd.add_ap(apdev[0], {}, no_enable=True)
  262. hapd.set("ssid", "test-ht-remove")
  263. hapd.set("channel", "1")
  264. hapd.set("ht_capab", "[HT40+]")
  265. hapd.set("bss", ifname2)
  266. hapd.set("ssid", "test-ht-remove2")
  267. hapd.enable()
  268. hostapd.remove_bss(apdev[0], ifname2)
  269. @remote_compatible
  270. def test_ap_enable_disable_reenable(dev, apdev):
  271. """Enable, disable, re-enable AP"""
  272. hapd = hostapd.add_ap(apdev[0], {}, no_enable=True)
  273. hapd.set("ssid", "dynamic")
  274. hapd.enable()
  275. ev = hapd.wait_event(["AP-ENABLED"], timeout=30)
  276. if ev is None:
  277. raise Exception("AP startup timed out")
  278. dev[0].connect("dynamic", key_mgmt="NONE", scan_freq="2412")
  279. hapd.disable()
  280. ev = hapd.wait_event(["AP-DISABLED"], timeout=30)
  281. if ev is None:
  282. raise Exception("AP disabling timed out")
  283. dev[0].wait_disconnected(timeout=10)
  284. hapd.enable()
  285. ev = hapd.wait_event(["AP-ENABLED"], timeout=30)
  286. if ev is None:
  287. raise Exception("AP startup timed out")
  288. dev[1].connect("dynamic", key_mgmt="NONE", scan_freq="2412")
  289. dev[0].wait_connected(timeout=10)
  290. def test_ap_double_disable(dev, apdev):
  291. """Double DISABLE regression test"""
  292. hapd = hostapd.add_bss(apdev[0], apdev[0]['ifname'], 'bss-1.conf')
  293. hostapd.add_bss(apdev[0], apdev[0]['ifname'] + '-2', 'bss-2.conf')
  294. hapd.disable()
  295. if "FAIL" not in hapd.request("DISABLE"):
  296. raise Exception("Second DISABLE accepted unexpectedly")
  297. hapd.enable()
  298. hapd.disable()
  299. if "FAIL" not in hapd.request("DISABLE"):
  300. raise Exception("Second DISABLE accepted unexpectedly")
  301. def test_ap_bss_add_many(dev, apdev):
  302. """Large number of BSS add operations with hostapd"""
  303. try:
  304. _test_ap_bss_add_many(dev, apdev)
  305. finally:
  306. dev[0].request("SCAN_INTERVAL 5")
  307. ifname = apdev[0]['ifname']
  308. hapd = hostapd.HostapdGlobal(apdev[0])
  309. hapd.flush()
  310. for i in range(16):
  311. ifname2 = ifname + '-' + str(i)
  312. hapd.remove(ifname2)
  313. try:
  314. os.remove('/tmp/hwsim-bss.conf')
  315. except:
  316. pass
  317. def _test_ap_bss_add_many(dev, apdev):
  318. ifname = apdev[0]['ifname']
  319. hostapd.add_bss(apdev[0], ifname, 'bss-1.conf')
  320. fname = '/tmp/hwsim-bss.conf'
  321. for i in range(16):
  322. ifname2 = ifname + '-' + str(i)
  323. with open(fname, 'w') as f:
  324. f.write("driver=nl80211\n")
  325. f.write("hw_mode=g\n")
  326. f.write("channel=1\n")
  327. f.write("ieee80211n=1\n")
  328. f.write("interface=%s\n" % ifname2)
  329. f.write("bssid=02:00:00:00:03:%02x\n" % (i + 1))
  330. f.write("ctrl_interface=/var/run/hostapd\n")
  331. f.write("ssid=test-%d\n" % i)
  332. hostapd.add_bss(apdev[0], ifname2, fname)
  333. os.remove(fname)
  334. dev[0].request("SCAN_INTERVAL 1")
  335. dev[0].connect("bss-1", key_mgmt="NONE", scan_freq="2412")
  336. dev[0].request("DISCONNECT")
  337. dev[0].wait_disconnected(timeout=5)
  338. for i in range(16):
  339. dev[0].connect("test-%d" % i, key_mgmt="NONE", scan_freq="2412")
  340. dev[0].request("DISCONNECT")
  341. dev[0].wait_disconnected(timeout=5)
  342. ifname2 = ifname + '-' + str(i)
  343. hostapd.remove_bss(apdev[0], ifname2)
  344. def test_ap_bss_add_reuse_existing(dev, apdev):
  345. """Dynamic BSS add operation reusing existing interface"""
  346. ifname1 = apdev[0]['ifname']
  347. ifname2 = apdev[0]['ifname'] + '-2'
  348. hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
  349. subprocess.check_call(["iw", "dev", ifname1, "interface", "add", ifname2,
  350. "type", "__ap"])
  351. hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
  352. hostapd.remove_bss(apdev[0], ifname2)
  353. subprocess.check_call(["iw", "dev", ifname2, "del"])
  354. def hapd_bss_out_of_mem(hapd, phy, confname, count, func):
  355. with alloc_fail(hapd, count, func):
  356. hapd_global = hostapd.HostapdGlobal()
  357. res = hapd_global.ctrl.request("ADD bss_config=" + phy + ":" + confname)
  358. if "OK" in res:
  359. raise Exception("add_bss succeeded")
  360. def test_ap_bss_add_out_of_memory(dev, apdev):
  361. """Running out of memory while adding a BSS"""
  362. hapd2 = hostapd.add_ap(apdev[1], { "ssid": "open" })
  363. ifname1 = apdev[0]['ifname']
  364. ifname2 = apdev[0]['ifname'] + '-2'
  365. hapd_bss_out_of_mem(hapd2, 'phy3', 'bss-1.conf', 1, 'hostapd_add_iface')
  366. for i in range(1, 3):
  367. hapd_bss_out_of_mem(hapd2, 'phy3', 'bss-1.conf',
  368. i, 'hostapd_interface_init_bss')
  369. hapd_bss_out_of_mem(hapd2, 'phy3', 'bss-1.conf',
  370. 1, 'ieee802_11_build_ap_params')
  371. hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
  372. hapd_bss_out_of_mem(hapd2, 'phy3', 'bss-2.conf',
  373. 1, 'hostapd_interface_init_bss')
  374. hapd_bss_out_of_mem(hapd2, 'phy3', 'bss-2.conf',
  375. 1, 'ieee802_11_build_ap_params')
  376. hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
  377. hostapd.remove_bss(apdev[0], ifname2)
  378. hostapd.remove_bss(apdev[0], ifname1)
  379. def test_ap_multi_bss(dev, apdev):
  380. """Multiple BSSes with hostapd"""
  381. ifname1 = apdev[0]['ifname']
  382. ifname2 = apdev[0]['ifname'] + '-2'
  383. hapd1 = hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
  384. hapd2 = hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
  385. dev[0].connect("bss-1", key_mgmt="NONE", scan_freq="2412")
  386. dev[1].connect("bss-2", key_mgmt="NONE", scan_freq="2412")
  387. hwsim_utils.test_connectivity(dev[0], hapd1)
  388. hwsim_utils.test_connectivity(dev[1], hapd2)
  389. sta0 = hapd1.get_sta(dev[0].own_addr())
  390. sta1 = hapd2.get_sta(dev[1].own_addr())
  391. if 'rx_packets' not in sta0 or int(sta0['rx_packets']) < 1:
  392. raise Exception("sta0 did not report receiving packets")
  393. if 'rx_packets' not in sta1 or int(sta1['rx_packets']) < 1:
  394. raise Exception("sta1 did not report receiving packets")
  395. @remote_compatible
  396. def test_ap_add_with_driver(dev, apdev):
  397. """Add hostapd interface with driver specified"""
  398. ifname = apdev[0]['ifname']
  399. try:
  400. hostname = apdev[0]['hostname']
  401. except:
  402. hostname = None
  403. hapd_global = hostapd.HostapdGlobal(apdev[0])
  404. hapd_global.add(ifname, driver="nl80211")
  405. port = hapd_global.get_ctrl_iface_port(ifname)
  406. hapd = hostapd.Hostapd(ifname, hostname, port)
  407. hapd.set_defaults()
  408. hapd.set("ssid", "dynamic")
  409. hapd.enable()
  410. ev = hapd.wait_event(["AP-ENABLED"], timeout=30)
  411. if ev is None:
  412. raise Exception("AP startup timed out")
  413. dev[0].connect("dynamic", key_mgmt="NONE", scan_freq="2412")
  414. dev[0].request("DISCONNECT")
  415. dev[0].wait_disconnected()
  416. hapd.disable()
  417. def test_ap_iapp(dev, apdev):
  418. """IAPP and multiple BSSes"""
  419. require_under_vm()
  420. try:
  421. _test_ap_iapp(dev, apdev)
  422. finally:
  423. subprocess.call(['ifconfig', 'br-multicast', 'down'],
  424. stderr=open('/dev/null', 'w'))
  425. subprocess.call(['brctl', 'delbr', 'br-multicast'],
  426. stderr=open('/dev/null', 'w'))
  427. def _test_ap_iapp(dev, apdev):
  428. br_ifname = 'br-multicast'
  429. subprocess.call(['brctl', 'addbr', br_ifname])
  430. subprocess.call(['brctl', 'setfd', br_ifname, '0'])
  431. subprocess.call(['ip', 'addr', 'add', '10.174.65.206/31', 'dev', br_ifname])
  432. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up'])
  433. subprocess.call(['ip', 'route', 'add', '224.0.0.0/4', 'dev', br_ifname])
  434. params = { "ssid": "test-1",
  435. "bridge": br_ifname,
  436. "iapp_interface": br_ifname }
  437. hapd = hostapd.add_ap(apdev[0], params)
  438. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412)
  439. dev[0].connect("test-1", key_mgmt="NONE", scan_freq="2412")
  440. dev[1].connect("test-1", key_mgmt="NONE", scan_freq="2412")
  441. hapd2 = hostapd.add_ap(apdev[1], params)
  442. dev[0].scan_for_bss(apdev[1]['bssid'], freq=2412)
  443. dev[0].roam(apdev[1]['bssid'])
  444. dev[0].roam(apdev[0]['bssid'])
  445. dev[0].request("DISCONNECT")
  446. dev[1].request("DISCONNECT")
  447. dev[0].wait_disconnected()
  448. dev[1].wait_disconnected()
  449. hapd.disable()
  450. hapd2.disable()
  451. def test_ap_duplicate_bssid(dev, apdev):
  452. """Duplicate BSSID"""
  453. params = { "ssid": "test" }
  454. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  455. hapd.enable()
  456. ifname2 = apdev[0]['ifname'] + '-2'
  457. ifname3 = apdev[0]['ifname'] + '-3'
  458. # "BSS 'wlan3-2' may not have BSSID set to the MAC address of the radio"
  459. try:
  460. hostapd.add_bss(apdev[0], ifname2, 'bss-2-dup.conf')
  461. raise Exception("BSS add succeeded unexpectedly")
  462. except Exception, e:
  463. if "Could not add hostapd BSS" in str(e):
  464. pass
  465. else:
  466. raise
  467. hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
  468. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  469. dev[0].request("DISCONNECT")
  470. dev[0].wait_disconnected()
  471. hapd.set("bssid", "02:00:00:00:03:02")
  472. hapd.disable()
  473. # "Duplicate BSSID 02:00:00:00:03:02 on interface 'wlan3-3' and 'wlan3'."
  474. if "FAIL" not in hapd.request("ENABLE"):
  475. raise Exception("ENABLE with duplicate BSSID succeeded unexpectedly")
  476. def test_ap_bss_config_file(dev, apdev, params):
  477. """hostapd BSS config file"""
  478. pidfile = os.path.join(params['logdir'], "ap_bss_config_file-hostapd.pid")
  479. logfile = os.path.join(params['logdir'], "ap_bss_config_file-hostapd-log")
  480. prg = os.path.join(params['logdir'], 'alt-hostapd/hostapd/hostapd')
  481. if not os.path.exists(prg):
  482. prg = '../../hostapd/hostapd'
  483. phy = get_phy(apdev[0])
  484. cmd = [ prg, '-B', '-dddt', '-P', pidfile, '-f', logfile, '-S', '-T',
  485. '-b', phy + ':bss-1.conf', '-b', phy + ':bss-2.conf',
  486. '-b', phy + ':bss-3.conf' ]
  487. res = subprocess.check_call(cmd)
  488. if res != 0:
  489. raise Exception("Could not start hostapd: %s" % str(res))
  490. multi_check(dev, [ True, True, True ])
  491. for i in range(0, 3):
  492. dev[i].request("DISCONNECT")
  493. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  494. hapd.ping()
  495. if "OK" not in hapd.request("TERMINATE"):
  496. raise Exception("Failed to terminate hostapd process")
  497. ev = hapd.wait_event(["CTRL-EVENT-TERMINATING"], timeout=15)
  498. if ev is None:
  499. raise Exception("CTRL-EVENT-TERMINATING not seen")
  500. for i in range(30):
  501. time.sleep(0.1)
  502. if not os.path.exists(pidfile):
  503. break
  504. if os.path.exists(pidfile):
  505. raise Exception("PID file exits after process termination")