test_p2p_channel.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. # P2P channel selection test cases
  2. # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
  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 hostapd
  12. import hwsim_utils
  13. from tshark import run_tshark
  14. from wpasupplicant import WpaSupplicant
  15. from hwsim import HWSimRadio
  16. from test_p2p_grpform import go_neg_pin_authorized
  17. from test_p2p_grpform import check_grpform_results
  18. from test_p2p_grpform import remove_group
  19. from test_p2p_grpform import go_neg_pbc
  20. from test_p2p_autogo import autogo
  21. def set_country(country, dev=None):
  22. subprocess.call(['iw', 'reg', 'set', country])
  23. time.sleep(0.1)
  24. if dev:
  25. for i in range(10):
  26. ev = dev.wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=15)
  27. if ev is None:
  28. raise Exception("No regdom change event seen")
  29. if "type=COUNTRY alpha2=" + country in ev:
  30. return
  31. raise Exception("No matching regdom event seen for set_country(%s)" % country)
  32. def test_p2p_channel_5ghz(dev):
  33. """P2P group formation with 5 GHz preference"""
  34. try:
  35. set_country("US", dev[0])
  36. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  37. r_dev=dev[1], r_intent=0,
  38. test_data=False)
  39. check_grpform_results(i_res, r_res)
  40. freq = int(i_res['freq'])
  41. if freq < 5000:
  42. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  43. remove_group(dev[0], dev[1])
  44. finally:
  45. set_country("00")
  46. dev[1].flush_scan_cache()
  47. def test_p2p_channel_5ghz_no_vht(dev):
  48. """P2P group formation with 5 GHz preference when VHT channels are disallowed"""
  49. try:
  50. set_country("US", dev[0])
  51. dev[0].request("P2P_SET disallow_freq 5180-5240")
  52. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  53. r_dev=dev[1], r_intent=0,
  54. test_data=False)
  55. check_grpform_results(i_res, r_res)
  56. freq = int(i_res['freq'])
  57. if freq < 5000:
  58. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  59. remove_group(dev[0], dev[1])
  60. finally:
  61. set_country("00")
  62. dev[0].request("P2P_SET disallow_freq ")
  63. dev[1].flush_scan_cache()
  64. def test_p2p_channel_random_social(dev):
  65. """P2P group formation with 5 GHz preference but all 5 GHz channels disabled"""
  66. try:
  67. set_country("US", dev[0])
  68. dev[0].request("SET p2p_oper_channel 11")
  69. dev[0].request("P2P_SET disallow_freq 5000-6000,2462")
  70. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  71. r_dev=dev[1], r_intent=0,
  72. test_data=False)
  73. check_grpform_results(i_res, r_res)
  74. freq = int(i_res['freq'])
  75. if freq not in [ 2412, 2437, 2462 ]:
  76. raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
  77. remove_group(dev[0], dev[1])
  78. finally:
  79. set_country("00")
  80. dev[0].request("P2P_SET disallow_freq ")
  81. dev[1].flush_scan_cache()
  82. def test_p2p_channel_random(dev):
  83. """P2P group formation with 5 GHz preference but all 5 GHz channels and all social channels disabled"""
  84. try:
  85. set_country("US", dev[0])
  86. dev[0].request("SET p2p_oper_channel 11")
  87. dev[0].request("P2P_SET disallow_freq 5000-6000,2412,2437,2462")
  88. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  89. r_dev=dev[1], r_intent=0,
  90. test_data=False)
  91. check_grpform_results(i_res, r_res)
  92. freq = int(i_res['freq'])
  93. if freq > 2500 or freq in [ 2412, 2437, 2462 ]:
  94. raise Exception("Unexpected channel %d MHz" % freq)
  95. remove_group(dev[0], dev[1])
  96. finally:
  97. set_country("00")
  98. dev[0].request("P2P_SET disallow_freq ")
  99. dev[1].flush_scan_cache()
  100. def test_p2p_channel_random_social_with_op_class_change(dev, apdev, params):
  101. """P2P group formation using random social channel with oper class change needed"""
  102. try:
  103. set_country("US", dev[0])
  104. logger.info("Start group on 5 GHz")
  105. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  106. r_dev=dev[1], r_intent=0,
  107. test_data=False)
  108. check_grpform_results(i_res, r_res)
  109. freq = int(i_res['freq'])
  110. if freq < 5000:
  111. raise Exception("Unexpected channel %d MHz - did not pick 5 GHz preference" % freq)
  112. remove_group(dev[0], dev[1])
  113. logger.info("Disable 5 GHz and try to re-start group based on 5 GHz preference")
  114. dev[0].request("SET p2p_oper_reg_class 115")
  115. dev[0].request("SET p2p_oper_channel 36")
  116. dev[0].request("P2P_SET disallow_freq 5000-6000")
  117. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  118. r_dev=dev[1], r_intent=0,
  119. test_data=False)
  120. check_grpform_results(i_res, r_res)
  121. freq = int(i_res['freq'])
  122. if freq not in [ 2412, 2437, 2462 ]:
  123. raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
  124. remove_group(dev[0], dev[1])
  125. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  126. "wifi_p2p.public_action.subtype == 0")
  127. if out is not None:
  128. last = None
  129. for l in out.splitlines():
  130. if "Operating Channel:" not in l:
  131. continue
  132. last = l
  133. if last is None:
  134. raise Exception("Could not find GO Negotiation Request")
  135. if "Operating Class 81" not in last:
  136. raise Exception("Unexpected operating class: " + last.strip())
  137. finally:
  138. set_country("00")
  139. dev[0].request("P2P_SET disallow_freq ")
  140. dev[0].request("SET p2p_oper_reg_class 0")
  141. dev[0].request("SET p2p_oper_channel 0")
  142. dev[1].flush_scan_cache()
  143. def test_p2p_channel_avoid(dev):
  144. """P2P and avoid frequencies driver event"""
  145. try:
  146. set_country("US", dev[0])
  147. if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES 5000-6000,2412,2437,2462"):
  148. raise Exception("Could not simulate driver event")
  149. ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
  150. if ev is None:
  151. raise Exception("No CTRL-EVENT-AVOID-FREQ event")
  152. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  153. r_dev=dev[1], r_intent=0,
  154. test_data=False)
  155. check_grpform_results(i_res, r_res)
  156. freq = int(i_res['freq'])
  157. if freq > 2500 or freq in [ 2412, 2437, 2462 ]:
  158. raise Exception("Unexpected channel %d MHz" % freq)
  159. if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES"):
  160. raise Exception("Could not simulate driver event(2)")
  161. ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
  162. if ev is None:
  163. raise Exception("No CTRL-EVENT-AVOID-FREQ event")
  164. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP"], timeout=1)
  165. if ev is not None:
  166. raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP event")
  167. if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES " + str(freq)):
  168. raise Exception("Could not simulate driver event(3)")
  169. ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
  170. if ev is None:
  171. raise Exception("No CTRL-EVENT-AVOID-FREQ event")
  172. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP"],
  173. timeout=10)
  174. if ev is None:
  175. raise Exception("No P2P-REMOVE-AND-REFORM-GROUP event")
  176. finally:
  177. set_country("00")
  178. dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES")
  179. dev[1].flush_scan_cache()
  180. def test_autogo_following_bss(dev, apdev):
  181. """P2P autonomous GO operate on the same channel as station interface"""
  182. if dev[0].get_mcc() > 1:
  183. logger.info("test mode: MCC")
  184. dev[0].request("SET p2p_no_group_iface 0")
  185. channels = { 3 : "2422", 5 : "2432", 9 : "2452" }
  186. for key in channels:
  187. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  188. "channel" : str(key) })
  189. dev[0].connect("ap-test", key_mgmt="NONE",
  190. scan_freq=str(channels[key]))
  191. res_go = autogo(dev[0])
  192. if res_go['freq'] != channels[key]:
  193. raise Exception("Group operation channel is not the same as on connected station interface")
  194. hwsim_utils.test_connectivity(dev[0], hapd)
  195. dev[0].remove_group(res_go['ifname'])
  196. def test_go_neg_with_bss_connected(dev, apdev):
  197. """P2P channel selection: GO negotiation when station interface is connected"""
  198. dev[0].flush_scan_cache()
  199. dev[1].flush_scan_cache()
  200. dev[0].request("SET p2p_no_group_iface 0")
  201. hapd = hostapd.add_ap(apdev[0]['ifname'],
  202. { "ssid": 'bss-2.4ghz', "channel": '5' })
  203. dev[0].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2432")
  204. #dev[0] as GO
  205. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=10, r_dev=dev[1],
  206. r_intent=1)
  207. check_grpform_results(i_res, r_res)
  208. if i_res['role'] != "GO":
  209. raise Exception("GO not selected according to go_intent")
  210. if i_res['freq'] != "2432":
  211. raise Exception("Group formed on a different frequency than BSS")
  212. hwsim_utils.test_connectivity(dev[0], hapd)
  213. dev[0].remove_group(i_res['ifname'])
  214. if dev[0].get_mcc() > 1:
  215. logger.info("Skip as-client case due to MCC being enabled")
  216. return;
  217. #dev[0] as client
  218. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=1, r_dev=dev[1],
  219. r_intent=10)
  220. check_grpform_results(i_res2, r_res2)
  221. if i_res2['role'] != "client":
  222. raise Exception("GO not selected according to go_intent")
  223. if i_res2['freq'] != "2432":
  224. raise Exception("Group formed on a different frequency than BSS")
  225. hwsim_utils.test_connectivity(dev[0], hapd)
  226. dev[1].remove_group(r_res['ifname'])
  227. dev[0].wait_go_ending_session()
  228. dev[0].request("DISCONNECT")
  229. hapd.disable()
  230. dev[0].flush_scan_cache()
  231. dev[1].flush_scan_cache()
  232. def test_autogo_with_bss_on_disallowed_chan(dev, apdev):
  233. """P2P channel selection: Autonomous GO with BSS on a disallowed channel"""
  234. with HWSimRadio(n_channels=2) as (radio, iface):
  235. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  236. wpas.interface_add(iface)
  237. wpas.request("SET p2p_no_group_iface 0")
  238. if wpas.get_mcc() < 2:
  239. raise Exception("New radio does not support MCC")
  240. try:
  241. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  242. "channel": '1' })
  243. wpas.request("P2P_SET disallow_freq 2412")
  244. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  245. res = autogo(wpas)
  246. if res['freq'] == "2412":
  247. raise Exception("GO set on a disallowed channel")
  248. hwsim_utils.test_connectivity(wpas, hapd)
  249. finally:
  250. wpas.request("P2P_SET disallow_freq ")
  251. def test_go_neg_with_bss_on_disallowed_chan(dev, apdev):
  252. """P2P channel selection: GO negotiation with station interface on a disallowed channel"""
  253. with HWSimRadio(n_channels=2) as (radio, iface):
  254. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  255. wpas.interface_add(iface)
  256. wpas.request("SET p2p_no_group_iface 0")
  257. if wpas.get_mcc() < 2:
  258. raise Exception("New radio does not support MCC")
  259. try:
  260. hapd = hostapd.add_ap(apdev[0]['ifname'],
  261. { "ssid": 'bss-2.4ghz', "channel": '1' })
  262. # make sure PBC overlap from old test cases is not maintained
  263. dev[1].flush_scan_cache()
  264. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  265. wpas.request("P2P_SET disallow_freq 2412")
  266. #wpas as GO
  267. [i_res, r_res] = go_neg_pbc(i_dev=wpas, i_intent=10, r_dev=dev[1],
  268. r_intent=1)
  269. check_grpform_results(i_res, r_res)
  270. if i_res['role'] != "GO":
  271. raise Exception("GO not selected according to go_intent")
  272. if i_res['freq'] == "2412":
  273. raise Exception("Group formed on a disallowed channel")
  274. hwsim_utils.test_connectivity(wpas, hapd)
  275. wpas.remove_group(i_res['ifname'])
  276. dev[1].wait_go_ending_session()
  277. dev[1].flush_scan_cache()
  278. wpas.dump_monitor()
  279. dev[1].dump_monitor()
  280. #wpas as client
  281. [i_res2, r_res2] = go_neg_pbc(i_dev=wpas, i_intent=1, r_dev=dev[1],
  282. r_intent=10)
  283. check_grpform_results(i_res2, r_res2)
  284. if i_res2['role'] != "client":
  285. raise Exception("GO not selected according to go_intent")
  286. if i_res2['freq'] == "2412":
  287. raise Exception("Group formed on a disallowed channel")
  288. hwsim_utils.test_connectivity(wpas, hapd)
  289. dev[1].remove_group(r_res2['ifname'])
  290. wpas.wait_go_ending_session()
  291. ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=5)
  292. if ev is None:
  293. raise Exception("Group removal not indicated")
  294. wpas.request("DISCONNECT")
  295. hapd.disable()
  296. finally:
  297. wpas.request("P2P_SET disallow_freq ")
  298. def test_autogo_force_diff_channel(dev, apdev):
  299. """P2P autonomous GO and station interface operate on different channels"""
  300. with HWSimRadio(n_channels=2) as (radio, iface):
  301. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  302. wpas.interface_add(iface)
  303. if wpas.get_mcc() < 2:
  304. raise Exception("New radio does not support MCC")
  305. wpas.request("SET p2p_no_group_iface 0")
  306. hapd = hostapd.add_ap(apdev[0]['ifname'],
  307. {"ssid" : 'ap-test', "channel" : '1'})
  308. wpas.connect("ap-test", key_mgmt = "NONE", scan_freq = "2412")
  309. channels = { 2 : 2417, 5 : 2432, 9 : 2452 }
  310. for key in channels:
  311. res_go = autogo(wpas, channels[key])
  312. hwsim_utils.test_connectivity(wpas, hapd)
  313. if int(res_go['freq']) == 2412:
  314. raise Exception("Group operation channel is: 2412 excepted: " + res_go['freq'])
  315. wpas.remove_group(res_go['ifname'])
  316. def test_go_neg_forced_freq_diff_than_bss_freq(dev, apdev):
  317. """P2P channel selection: GO negotiation with forced freq different than station interface"""
  318. with HWSimRadio(n_channels=2) as (radio, iface):
  319. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  320. wpas.interface_add(iface)
  321. if wpas.get_mcc() < 2:
  322. raise Exception("New radio does not support MCC")
  323. # Clear possible PBC session overlap from previous test case
  324. dev[1].flush_scan_cache()
  325. wpas.request("SET p2p_no_group_iface 0")
  326. hapd = hostapd.add_ap(apdev[0]['ifname'],
  327. { "country_code": 'US',
  328. "ssid": 'bss-5ghz', "hw_mode": 'a',
  329. "channel": '40' })
  330. wpas.connect("bss-5ghz", key_mgmt="NONE", scan_freq="5200")
  331. # GO and peer force the same freq, different than BSS freq,
  332. # wpas to become GO
  333. [i_res, r_res] = go_neg_pbc(i_dev=dev[1], i_intent=1, i_freq=5180,
  334. r_dev=wpas, r_intent=14, r_freq=5180)
  335. check_grpform_results(i_res, r_res)
  336. if i_res['freq'] != "5180":
  337. raise Exception("P2P group formed on unexpected frequency: " + i_res['freq'])
  338. if r_res['role'] != "GO":
  339. raise Exception("GO not selected according to go_intent")
  340. hwsim_utils.test_connectivity(wpas, hapd)
  341. wpas.remove_group(r_res['ifname'])
  342. dev[1].wait_go_ending_session()
  343. dev[1].flush_scan_cache()
  344. # GO and peer force the same freq, different than BSS freq, wpas to
  345. # become client
  346. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[1], i_intent=14, i_freq=2422,
  347. r_dev=wpas, r_intent=1, r_freq=2422)
  348. check_grpform_results(i_res2, r_res2)
  349. if i_res2['freq'] != "2422":
  350. raise Exception("P2P group formed on unexpected frequency: " + i_res2['freq'])
  351. if r_res2['role'] != "client":
  352. raise Exception("GO not selected according to go_intent")
  353. hwsim_utils.test_connectivity(wpas, hapd)
  354. wpas.request("DISCONNECT")
  355. hapd.request("DISABLE")
  356. subprocess.call(['iw', 'reg', 'set', '00'])
  357. wpas.flush_scan_cache()
  358. def test_go_pref_chan_bss_on_diff_chan(dev, apdev):
  359. """P2P channel selection: Station on different channel than GO configured pref channel"""
  360. dev[0].request("SET p2p_no_group_iface 0")
  361. try:
  362. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  363. "channel": '1' })
  364. dev[0].request("SET p2p_pref_chan 81:2")
  365. dev[0].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  366. res = autogo(dev[0])
  367. if res['freq'] != "2412":
  368. raise Exception("GO channel did not follow BSS")
  369. hwsim_utils.test_connectivity(dev[0], hapd)
  370. finally:
  371. dev[0].request("SET p2p_pref_chan ")
  372. def test_go_pref_chan_bss_on_disallowed_chan(dev, apdev):
  373. """P2P channel selection: Station interface on different channel than GO configured pref channel, and station channel is disallowed"""
  374. with HWSimRadio(n_channels=2) as (radio, iface):
  375. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  376. wpas.interface_add(iface)
  377. if wpas.get_mcc() < 2:
  378. raise Exception("New radio does not support MCC")
  379. wpas.request("SET p2p_no_group_iface 0")
  380. try:
  381. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  382. "channel": '1' })
  383. wpas.request("P2P_SET disallow_freq 2412")
  384. wpas.request("SET p2p_pref_chan 81:2")
  385. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  386. res2 = autogo(wpas)
  387. if res2['freq'] != "2417":
  388. raise Exception("GO channel did not follow pref_chan configuration")
  389. hwsim_utils.test_connectivity(wpas, hapd)
  390. finally:
  391. wpas.request("P2P_SET disallow_freq ")
  392. wpas.request("SET p2p_pref_chan ")
  393. def test_no_go_freq(dev, apdev):
  394. """P2P channel selection: no GO freq"""
  395. try:
  396. dev[0].request("SET p2p_no_go_freq 2412")
  397. # dev[0] as client, channel 1 is ok
  398. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=1,
  399. r_dev=dev[1], r_intent=14, r_freq=2412)
  400. check_grpform_results(i_res, r_res)
  401. if i_res['freq'] != "2412":
  402. raise Exception("P2P group not formed on forced freq")
  403. dev[1].remove_group(r_res['ifname'])
  404. dev[0].wait_go_ending_session()
  405. dev[0].flush_scan_cache()
  406. fail = False
  407. # dev[0] as GO, channel 1 is not allowed
  408. try:
  409. dev[0].request("SET p2p_no_go_freq 2412")
  410. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=14,
  411. r_dev=dev[1], r_intent=1, r_freq=2412)
  412. check_grpform_results(i_res2, r_res2)
  413. fail = True
  414. except:
  415. pass
  416. if fail:
  417. raise Exception("GO set on a disallowed freq")
  418. finally:
  419. dev[0].request("SET p2p_no_go_freq ")
  420. def test_go_neg_peers_force_diff_freq(dev, apdev):
  421. """P2P channel selection when peers for different frequency"""
  422. try:
  423. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=14, i_freq=5180,
  424. r_dev=dev[1], r_intent=0, r_freq=5200)
  425. except Exception, e:
  426. return
  427. raise Exception("Unexpected group formation success")
  428. def test_autogo_random_channel(dev, apdev):
  429. """P2P channel selection: GO instantiated on random channel 1, 6, 11"""
  430. freqs = []
  431. go_freqs = ["2412", "2437", "2462"]
  432. for i in range(0, 20):
  433. result = autogo(dev[0])
  434. if result['freq'] not in go_freqs:
  435. raise Exception("Unexpected frequency selected: " + result['freq'])
  436. if result['freq'] not in freqs:
  437. freqs.append(result['freq'])
  438. if len(freqs) == 3:
  439. break
  440. dev[0].remove_group(result['ifname'])
  441. if i == 20:
  442. raise Exception("GO created 20 times and not all social channels were selected. freqs not selected: " + str(list(set(go_freqs) - set(freqs))))
  443. def test_p2p_autogo_pref_chan_disallowed(dev, apdev):
  444. """P2P channel selection: GO preferred channels are disallowed"""
  445. try:
  446. dev[0].request("SET p2p_pref_chan 81:1,81:3,81:6,81:9,81:11")
  447. dev[0].request("P2P_SET disallow_freq 2412,2422,2437,2452,2462")
  448. for i in range(0, 5):
  449. res = autogo(dev[0])
  450. if res['freq'] in [ "2412", "2422", "2437", "2452", "2462" ]:
  451. raise Exception("GO channel is disallowed")
  452. dev[0].remove_group(res['ifname'])
  453. finally:
  454. dev[0].request("P2P_SET disallow_freq ")
  455. dev[0].request("SET p2p_pref_chan ")
  456. def test_p2p_autogo_pref_chan_not_in_regulatory(dev, apdev):
  457. """P2P channel selection: GO preferred channel not allowed in the regulatory rules"""
  458. try:
  459. set_country("US", dev[0])
  460. dev[0].request("SET p2p_pref_chan 124:149")
  461. res = autogo(dev[0], persistent=True)
  462. if res['freq'] != "5745":
  463. raise Exception("Unexpected channel selected: " + res['freq'])
  464. dev[0].remove_group(res['ifname'])
  465. netw = dev[0].list_networks(p2p=True)
  466. if len(netw) != 1:
  467. raise Exception("Unexpected number of network blocks: " + str(netw))
  468. id = netw[0]['id']
  469. set_country("DE", dev[0])
  470. res = autogo(dev[0], persistent=id)
  471. if res['freq'] == "5745":
  472. raise Exception("Unexpected channel selected(2): " + res['freq'])
  473. dev[0].remove_group(res['ifname'])
  474. finally:
  475. dev[0].request("SET p2p_pref_chan ")
  476. set_country("00")
  477. def run_autogo(dev, param):
  478. if "OK" not in dev.global_request("P2P_GROUP_ADD " + param):
  479. raise Exception("P2P_GROUP_ADD failed: " + param)
  480. ev = dev.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  481. if ev is None:
  482. raise Exception("GO start up timed out")
  483. res = dev.group_form_result(ev)
  484. dev.remove_group()
  485. return res
  486. def _test_autogo_ht_vht(dev):
  487. res = run_autogo(dev[0], "ht40")
  488. res = run_autogo(dev[0], "vht")
  489. res = run_autogo(dev[0], "freq=2")
  490. freq = int(res['freq'])
  491. if freq < 2412 or freq > 2462:
  492. raise Exception("Unexpected freq=2 channel: " + str(freq))
  493. res = run_autogo(dev[0], "freq=5")
  494. freq = int(res['freq'])
  495. if freq < 5000 or freq >= 6000:
  496. raise Exception("Unexpected freq=5 channel: " + str(freq))
  497. res = run_autogo(dev[0], "freq=5 ht40 vht")
  498. logger.info(str(res))
  499. freq = int(res['freq'])
  500. if freq < 5000 or freq >= 6000:
  501. raise Exception("Unexpected freq=5 ht40 vht channel: " + str(freq))
  502. def test_autogo_ht_vht(dev):
  503. """P2P autonomous GO with HT/VHT parameters"""
  504. try:
  505. set_country("US", dev[0])
  506. _test_autogo_ht_vht(dev)
  507. finally:
  508. set_country("00")
  509. def test_p2p_listen_chan_optimize(dev, apdev):
  510. """P2P listen channel optimization"""
  511. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  512. wpas.interface_add("wlan5")
  513. addr5 = wpas.p2p_dev_addr()
  514. try:
  515. if "OK" not in wpas.request("SET p2p_optimize_listen_chan 1"):
  516. raise Exception("Failed to set p2p_optimize_listen_chan")
  517. wpas.p2p_listen()
  518. if not dev[0].discover_peer(addr5):
  519. raise Exception("Could not discover peer")
  520. peer = dev[0].get_peer(addr5)
  521. lfreq = peer['listen_freq']
  522. wpas.p2p_stop_find()
  523. dev[0].p2p_stop_find()
  524. channel = "1" if lfreq != '2412' else "6"
  525. freq = "2412" if lfreq != '2412' else "2437"
  526. params = { "ssid": "test-open", "channel": channel }
  527. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  528. id = wpas.connect("test-open", key_mgmt="NONE", scan_freq=freq)
  529. wpas.p2p_listen()
  530. if "OK" not in dev[0].request("P2P_FLUSH"):
  531. raise Exception("P2P_FLUSH failed")
  532. if not dev[0].discover_peer(addr5):
  533. raise Exception("Could not discover peer")
  534. peer = dev[0].get_peer(addr5)
  535. lfreq2 = peer['listen_freq']
  536. if lfreq == lfreq2:
  537. raise Exception("Listen channel did not change")
  538. if lfreq2 != freq:
  539. raise Exception("Listen channel not on AP's operating channel")
  540. wpas.p2p_stop_find()
  541. dev[0].p2p_stop_find()
  542. wpas.request("DISCONNECT")
  543. wpas.wait_disconnected()
  544. # for larger coverage, cover case of current channel matching
  545. wpas.select_network(id)
  546. wpas.wait_connected()
  547. wpas.request("DISCONNECT")
  548. wpas.wait_disconnected()
  549. lchannel = "1" if channel != "1" else "6"
  550. lfreq3 = "2412" if channel != "1" else "2437"
  551. if "OK" not in wpas.request("P2P_SET listen_channel " + lchannel):
  552. raise Exception("Failed to set listen channel")
  553. wpas.select_network(id)
  554. wpas.wait_connected()
  555. wpas.p2p_listen()
  556. if "OK" not in dev[0].request("P2P_FLUSH"):
  557. raise Exception("P2P_FLUSH failed")
  558. if not dev[0].discover_peer(addr5):
  559. raise Exception("Could not discover peer")
  560. peer = dev[0].get_peer(addr5)
  561. lfreq4 = peer['listen_freq']
  562. if lfreq4 != lfreq3:
  563. raise Exception("Unexpected Listen channel after configuration")
  564. wpas.p2p_stop_find()
  565. dev[0].p2p_stop_find()
  566. finally:
  567. wpas.request("SET p2p_optimize_listen_chan 0")
  568. def test_p2p_channel_5ghz_only(dev):
  569. """P2P GO start with only 5 GHz band allowed"""
  570. try:
  571. set_country("US", dev[0])
  572. dev[0].request("P2P_SET disallow_freq 2400-2500")
  573. res = autogo(dev[0])
  574. freq = int(res['freq'])
  575. if freq < 5000:
  576. raise Exception("Unexpected channel %d MHz" % freq)
  577. dev[0].remove_group()
  578. finally:
  579. set_country("00")
  580. dev[0].request("P2P_SET disallow_freq ")