test_p2p_channel.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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 wpasupplicant import WpaSupplicant
  14. from hwsim import HWSimRadio
  15. from test_p2p_grpform import go_neg_pin_authorized
  16. from test_p2p_grpform import check_grpform_results
  17. from test_p2p_grpform import remove_group
  18. from test_p2p_grpform import go_neg_pbc
  19. from test_p2p_autogo import autogo
  20. def set_country(country):
  21. subprocess.call(['sudo', 'iw', 'reg', 'set', country])
  22. time.sleep(0.1)
  23. def test_p2p_channel_5ghz(dev):
  24. """P2P group formation with 5 GHz preference"""
  25. try:
  26. set_country("US")
  27. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  28. r_dev=dev[1], r_intent=0,
  29. test_data=False)
  30. check_grpform_results(i_res, r_res)
  31. freq = int(i_res['freq'])
  32. if freq < 5000:
  33. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  34. remove_group(dev[0], dev[1])
  35. finally:
  36. set_country("00")
  37. dev[1].flush_scan_cache()
  38. def test_p2p_channel_5ghz_no_vht(dev):
  39. """P2P group formation with 5 GHz preference when VHT channels are disallowed"""
  40. try:
  41. set_country("US")
  42. dev[0].request("P2P_SET disallow_freq 5180-5240")
  43. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  44. r_dev=dev[1], r_intent=0,
  45. test_data=False)
  46. check_grpform_results(i_res, r_res)
  47. freq = int(i_res['freq'])
  48. if freq < 5000:
  49. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  50. remove_group(dev[0], dev[1])
  51. finally:
  52. set_country("00")
  53. dev[0].request("P2P_SET disallow_freq ")
  54. dev[1].flush_scan_cache()
  55. def test_p2p_channel_random_social(dev):
  56. """P2P group formation with 5 GHz preference but all 5 GHz channels disabled"""
  57. try:
  58. set_country("US")
  59. dev[0].request("SET p2p_oper_channel 11")
  60. dev[0].request("P2P_SET disallow_freq 5000-6000,2462")
  61. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  62. r_dev=dev[1], r_intent=0,
  63. test_data=False)
  64. check_grpform_results(i_res, r_res)
  65. freq = int(i_res['freq'])
  66. if freq not in [ 2412, 2437, 2462 ]:
  67. raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
  68. remove_group(dev[0], dev[1])
  69. finally:
  70. set_country("00")
  71. dev[0].request("P2P_SET disallow_freq ")
  72. dev[1].flush_scan_cache()
  73. def test_p2p_channel_random(dev):
  74. """P2P group formation with 5 GHz preference but all 5 GHz channels and all social channels disabled"""
  75. try:
  76. set_country("US")
  77. dev[0].request("SET p2p_oper_channel 11")
  78. dev[0].request("P2P_SET disallow_freq 5000-6000,2412,2437,2462")
  79. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  80. r_dev=dev[1], r_intent=0,
  81. test_data=False)
  82. check_grpform_results(i_res, r_res)
  83. freq = int(i_res['freq'])
  84. if freq > 2500 or freq in [ 2412, 2437, 2462 ]:
  85. raise Exception("Unexpected channel %d MHz" % freq)
  86. remove_group(dev[0], dev[1])
  87. finally:
  88. set_country("00")
  89. dev[0].request("P2P_SET disallow_freq ")
  90. dev[1].flush_scan_cache()
  91. def test_p2p_channel_random_social_with_op_class_change(dev, apdev, params):
  92. """P2P group formation using random social channel with oper class change needed"""
  93. try:
  94. set_country("US")
  95. logger.info("Start group on 5 GHz")
  96. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  97. r_dev=dev[1], r_intent=0,
  98. test_data=False)
  99. check_grpform_results(i_res, r_res)
  100. freq = int(i_res['freq'])
  101. if freq < 5000:
  102. raise Exception("Unexpected channel %d MHz - did not pick 5 GHz preference" % freq)
  103. remove_group(dev[0], dev[1])
  104. logger.info("Disable 5 GHz and try to re-start group based on 5 GHz preference")
  105. dev[0].request("SET p2p_oper_reg_class 115")
  106. dev[0].request("SET p2p_oper_channel 36")
  107. dev[0].request("P2P_SET disallow_freq 5000-6000")
  108. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  109. r_dev=dev[1], r_intent=0,
  110. test_data=False)
  111. check_grpform_results(i_res, r_res)
  112. freq = int(i_res['freq'])
  113. if freq not in [ 2412, 2437, 2462 ]:
  114. raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
  115. remove_group(dev[0], dev[1])
  116. try:
  117. arg = [ "tshark",
  118. "-r", os.path.join(params['logdir'], "hwsim0.pcapng"),
  119. "-Y", "wifi_p2p.public_action.subtype == 0",
  120. "-V" ]
  121. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
  122. stderr=open('/dev/null', 'w'))
  123. except Exception, e:
  124. logger.info("Could run run tshark check: " + str(e))
  125. cmd = None
  126. pass
  127. if cmd:
  128. last = None
  129. for l in cmd.stdout.read().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")
  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_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_event(["P2P-REMOVE-AND-REFORM-GROUP"], timeout=10)
  173. if ev is None:
  174. raise Exception("No P2P-REMOVE-AND-REFORM-GROUP event")
  175. finally:
  176. set_country("00")
  177. dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES")
  178. dev[1].flush_scan_cache()
  179. def test_autogo_following_bss(dev, apdev):
  180. """P2P autonomous GO operate on the same channel as station interface"""
  181. if dev[0].get_mcc() > 1:
  182. logger.info("test mode: MCC")
  183. dev[0].request("SET p2p_no_group_iface 0")
  184. channels = { 3 : "2422", 5 : "2432", 9 : "2452" }
  185. for key in channels:
  186. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  187. "channel" : str(key) })
  188. dev[0].connect("ap-test", key_mgmt="NONE",
  189. scan_freq=str(channels[key]))
  190. res_go = autogo(dev[0])
  191. if res_go['freq'] != channels[key]:
  192. raise Exception("Group operation channel is not the same as on connected station interface")
  193. hwsim_utils.test_connectivity(dev[0], hapd)
  194. dev[0].remove_group(res_go['ifname'])
  195. def test_go_neg_with_bss_connected(dev, apdev):
  196. """P2P channel selection: GO negotiation when station interface is connected"""
  197. dev[0].flush_scan_cache()
  198. dev[1].flush_scan_cache()
  199. dev[0].request("SET p2p_no_group_iface 0")
  200. hapd = hostapd.add_ap(apdev[0]['ifname'],
  201. { "ssid": 'bss-2.4ghz', "channel": '5' })
  202. dev[0].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2432")
  203. #dev[0] as GO
  204. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=10, r_dev=dev[1],
  205. r_intent=1)
  206. check_grpform_results(i_res, r_res)
  207. if i_res['role'] != "GO":
  208. raise Exception("GO not selected according to go_intent")
  209. if i_res['freq'] != "2432":
  210. raise Exception("Group formed on a different frequency than BSS")
  211. hwsim_utils.test_connectivity(dev[0], hapd)
  212. dev[0].remove_group(i_res['ifname'])
  213. if dev[0].get_mcc() > 1:
  214. logger.info("Skip as-client case due to MCC being enabled")
  215. return;
  216. #dev[0] as client
  217. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=1, r_dev=dev[1],
  218. r_intent=10)
  219. check_grpform_results(i_res2, r_res2)
  220. if i_res2['role'] != "client":
  221. raise Exception("GO not selected according to go_intent")
  222. if i_res2['freq'] != "2432":
  223. raise Exception("Group formed on a different frequency than BSS")
  224. hwsim_utils.test_connectivity(dev[0], hapd)
  225. def test_autogo_with_bss_on_disallowed_chan(dev, apdev):
  226. """P2P channel selection: Autonomous GO with BSS on a disallowed channel"""
  227. with HWSimRadio(n_channels=2) as (radio, iface):
  228. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  229. wpas.interface_add(iface)
  230. wpas.request("SET p2p_no_group_iface 0")
  231. if wpas.get_mcc() < 2:
  232. raise Exception("New radio does not support MCC")
  233. try:
  234. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  235. "channel": '1' })
  236. wpas.request("P2P_SET disallow_freq 2412")
  237. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  238. res = autogo(wpas)
  239. if res['freq'] == "2412":
  240. raise Exception("GO set on a disallowed channel")
  241. hwsim_utils.test_connectivity(wpas, hapd)
  242. finally:
  243. wpas.request("P2P_SET disallow_freq ")
  244. def test_go_neg_with_bss_on_disallowed_chan(dev, apdev):
  245. """P2P channel selection: GO negotiation with station interface on a disallowed channel"""
  246. with HWSimRadio(n_channels=2) as (radio, iface):
  247. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  248. wpas.interface_add(iface)
  249. wpas.request("SET p2p_no_group_iface 0")
  250. if wpas.get_mcc() < 2:
  251. raise Exception("New radio does not support MCC")
  252. try:
  253. hapd = hostapd.add_ap(apdev[0]['ifname'],
  254. { "ssid": 'bss-2.4ghz', "channel": '1' })
  255. # make sure PBC overlap from old test cases is not maintained
  256. dev[0].flush_scan_cache()
  257. dev[1].flush_scan_cache()
  258. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  259. wpas.request("P2P_SET disallow_freq 2412")
  260. #wpas as GO
  261. [i_res, r_res] = go_neg_pbc(i_dev=wpas, i_intent=10, r_dev=dev[1],
  262. r_intent=1)
  263. check_grpform_results(i_res, r_res)
  264. if i_res['role'] != "GO":
  265. raise Exception("GO not selected according to go_intent")
  266. if i_res['freq'] == "2412":
  267. raise Exception("Group formed on a disallowed channel")
  268. hwsim_utils.test_connectivity(wpas, hapd)
  269. wpas.remove_group(i_res['ifname'])
  270. #wpas as client
  271. [i_res2, r_res2] = go_neg_pbc(i_dev=wpas, i_intent=1, r_dev=dev[1],
  272. r_intent=10)
  273. check_grpform_results(i_res2, r_res2)
  274. if i_res2['role'] != "client":
  275. raise Exception("GO not selected according to go_intent")
  276. if i_res2['freq'] == "2412":
  277. raise Exception("Group formed on a disallowed channel")
  278. hwsim_utils.test_connectivity(wpas, hapd)
  279. finally:
  280. wpas.request("P2P_SET disallow_freq ")
  281. def test_autogo_force_diff_channel(dev, apdev):
  282. """P2P autonomous GO and station interface operate on different channels"""
  283. with HWSimRadio(n_channels=2) as (radio, iface):
  284. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  285. wpas.interface_add(iface)
  286. if wpas.get_mcc() < 2:
  287. raise Exception("New radio does not support MCC")
  288. wpas.request("SET p2p_no_group_iface 0")
  289. hapd = hostapd.add_ap(apdev[0]['ifname'],
  290. {"ssid" : 'ap-test', "channel" : '1'})
  291. wpas.connect("ap-test", key_mgmt = "NONE", scan_freq = "2412")
  292. channels = { 2 : 2417, 5 : 2432, 9 : 2452 }
  293. for key in channels:
  294. res_go = autogo(wpas, channels[key])
  295. hwsim_utils.test_connectivity(wpas, hapd)
  296. if int(res_go['freq']) == 2412:
  297. raise Exception("Group operation channel is: 2412 excepted: " + res_go['freq'])
  298. wpas.remove_group(res_go['ifname'])
  299. def test_go_neg_forced_freq_diff_than_bss_freq(dev, apdev):
  300. """P2P channel selection: GO negotiation with forced freq different than station interface"""
  301. with HWSimRadio(n_channels=2) as (radio, iface):
  302. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  303. wpas.interface_add(iface)
  304. if wpas.get_mcc() < 2:
  305. raise Exception("New radio does not support MCC")
  306. # Clear possible PBC session overlap from previous test case
  307. dev[1].flush_scan_cache()
  308. wpas.request("SET p2p_no_group_iface 0")
  309. hapd = hostapd.add_ap(apdev[0]['ifname'],
  310. { "country_code": 'US',
  311. "ssid": 'bss-5ghz', "hw_mode": 'a',
  312. "channel": '40' })
  313. wpas.connect("bss-5ghz", key_mgmt="NONE", scan_freq="5200")
  314. # GO and peer force the same freq, different than BSS freq,
  315. # wpas to become GO
  316. [i_res, r_res] = go_neg_pbc(i_dev=dev[1], i_intent=1, i_freq=5180,
  317. r_dev=wpas, r_intent=14, r_freq=5180)
  318. check_grpform_results(i_res, r_res)
  319. if i_res['freq'] != "5180":
  320. raise Exception("P2P group formed on unexpected frequency: " + i_res['freq'])
  321. if r_res['role'] != "GO":
  322. raise Exception("GO not selected according to go_intent")
  323. hwsim_utils.test_connectivity(wpas, hapd)
  324. wpas.remove_group(r_res['ifname'])
  325. # GO and peer force the same freq, different than BSS freq, wpas to
  326. # become client
  327. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[1], i_intent=14, i_freq=2422,
  328. r_dev=wpas, r_intent=1, r_freq=2422)
  329. check_grpform_results(i_res2, r_res2)
  330. if i_res2['freq'] != "2422":
  331. raise Exception("P2P group formed on unexpected frequency: " + i_res2['freq'])
  332. if r_res2['role'] != "client":
  333. raise Exception("GO not selected according to go_intent")
  334. hwsim_utils.test_connectivity(wpas, hapd)
  335. wpas.request("DISCONNECT")
  336. hapd.request("DISABLE")
  337. subprocess.call(['iw', 'reg', 'set', '00'])
  338. wpas.flush_scan_cache()
  339. def test_go_pref_chan_bss_on_diff_chan(dev, apdev):
  340. """P2P channel selection: Station on different channel than GO configured pref channel"""
  341. dev[0].request("SET p2p_no_group_iface 0")
  342. try:
  343. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  344. "channel": '1' })
  345. dev[0].request("SET p2p_pref_chan 81:2")
  346. dev[0].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  347. res = autogo(dev[0])
  348. if res['freq'] != "2412":
  349. raise Exception("GO channel did not follow BSS")
  350. hwsim_utils.test_connectivity(dev[0], hapd)
  351. finally:
  352. dev[0].request("SET p2p_pref_chan ")
  353. def test_go_pref_chan_bss_on_disallowed_chan(dev, apdev):
  354. """P2P channel selection: Station interface on different channel than GO configured pref channel, and station channel is disallowed"""
  355. with HWSimRadio(n_channels=2) as (radio, iface):
  356. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  357. wpas.interface_add(iface)
  358. if wpas.get_mcc() < 2:
  359. raise Exception("New radio does not support MCC")
  360. wpas.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. wpas.request("P2P_SET disallow_freq 2412")
  365. wpas.request("SET p2p_pref_chan 81:2")
  366. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  367. res2 = autogo(wpas)
  368. if res2['freq'] != "2417":
  369. raise Exception("GO channel did not follow pref_chan configuration")
  370. hwsim_utils.test_connectivity(wpas, hapd)
  371. finally:
  372. wpas.request("P2P_SET disallow_freq ")
  373. wpas.request("SET p2p_pref_chan ")
  374. def test_no_go_freq(dev, apdev):
  375. """P2P channel selection: no GO freq"""
  376. try:
  377. dev[0].request("SET p2p_no_go_freq 2412")
  378. # dev[0] as client, channel 1 is ok
  379. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=1,
  380. r_dev=dev[1], r_intent=14, r_freq=2412)
  381. check_grpform_results(i_res, r_res)
  382. if i_res['freq'] != "2412":
  383. raise Exception("P2P group not formed on forced freq")
  384. dev[1].remove_group(r_res['ifname'])
  385. fail = False
  386. # dev[0] as GO, channel 1 is not allowed
  387. try:
  388. dev[0].request("SET p2p_no_go_freq 2412")
  389. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=14,
  390. r_dev=dev[1], r_intent=1, r_freq=2412)
  391. check_grpform_results(i_res2, r_res2)
  392. fail = True
  393. except:
  394. pass
  395. if fail:
  396. raise Exception("GO set on a disallowed freq")
  397. finally:
  398. dev[0].request("SET p2p_no_go_freq ")
  399. def test_go_neg_peers_force_diff_freq(dev, apdev):
  400. """P2P channel selection when peers for different frequency"""
  401. try:
  402. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=14, i_freq=5180,
  403. r_dev=dev[1], r_intent=0, r_freq=5200)
  404. except Exception, e:
  405. return
  406. raise Exception("Unexpected group formation success")
  407. def test_autogo_random_channel(dev, apdev):
  408. """P2P channel selection: GO instantiated on random channel 1, 6, 11"""
  409. freqs = []
  410. go_freqs = ["2412", "2437", "2462"]
  411. for i in range(0, 20):
  412. result = autogo(dev[0])
  413. if result['freq'] not in go_freqs:
  414. raise Exception("Unexpected frequency selected: " + result['freq'])
  415. if result['freq'] not in freqs:
  416. freqs.append(result['freq'])
  417. if len(freqs) == 3:
  418. break
  419. dev[0].remove_group(result['ifname'])
  420. if i == 20:
  421. raise Exception("GO created 20 times and not all social channels were selected. freqs not selected: " + str(list(set(go_freqs) - set(freqs))))
  422. def test_p2p_autogo_pref_chan_disallowed(dev, apdev):
  423. """P2P channel selection: GO preferred channels are disallowed"""
  424. try:
  425. dev[0].request("SET p2p_pref_chan 81:1,81:3,81:6,81:9,81:11")
  426. dev[0].request("P2P_SET disallow_freq 2412,2422,2437,2452,2462")
  427. for i in range(0, 5):
  428. res = autogo(dev[0])
  429. if res['freq'] in [ "2412", "2422", "2437", "2452", "2462" ]:
  430. raise Exception("GO channel is disallowed")
  431. dev[0].remove_group(res['ifname'])
  432. finally:
  433. dev[0].request("P2P_SET disallow_freq ")
  434. dev[0].request("SET p2p_pref_chan ")
  435. def test_p2p_autogo_pref_chan_not_in_regulatory(dev, apdev):
  436. """P2P channel selection: GO preferred channel not allowed in the regulatory rules"""
  437. try:
  438. set_country("US")
  439. dev[0].request("SET p2p_pref_chan 124:149")
  440. res = autogo(dev[0], persistent=True)
  441. if res['freq'] != "5745":
  442. raise Exception("Unexpected channel selected: " + res['freq'])
  443. dev[0].remove_group(res['ifname'])
  444. netw = dev[0].list_networks()
  445. if len(netw) != 1:
  446. raise Exception("Unexpected number of network blocks: " + str(netw))
  447. id = netw[0]['id']
  448. set_country("DE")
  449. res = autogo(dev[0], persistent=id)
  450. if res['freq'] == "5745":
  451. raise Exception("Unexpected channel selected(2): " + res['freq'])
  452. dev[0].remove_group(res['ifname'])
  453. finally:
  454. dev[0].request("SET p2p_pref_chan ")
  455. set_country("00")
  456. def run_autogo(dev, param):
  457. if "OK" not in dev.global_request("P2P_GROUP_ADD " + param):
  458. raise Exception("P2P_GROUP_ADD failed: " + param)
  459. ev = dev.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  460. if ev is None:
  461. raise Exception("GO start up timed out")
  462. res = dev.group_form_result(ev)
  463. dev.remove_group()
  464. return res
  465. def _test_autogo_ht_vht(dev):
  466. res = run_autogo(dev[0], "ht40")
  467. res = run_autogo(dev[0], "vht")
  468. res = run_autogo(dev[0], "freq=2")
  469. freq = int(res['freq'])
  470. if freq < 2412 or freq > 2462:
  471. raise Exception("Unexpected freq=2 channel: " + str(freq))
  472. res = run_autogo(dev[0], "freq=5")
  473. freq = int(res['freq'])
  474. if freq < 5000 or freq >= 6000:
  475. raise Exception("Unexpected freq=5 channel: " + str(freq))
  476. res = run_autogo(dev[0], "freq=5 ht40 vht")
  477. print res
  478. freq = int(res['freq'])
  479. if freq < 5000 or freq >= 6000:
  480. raise Exception("Unexpected freq=5 ht40 vht channel: " + str(freq))
  481. def test_autogo_ht_vht(dev):
  482. """P2P autonomous GO with HT/VHT parameters"""
  483. try:
  484. set_country("US")
  485. _test_autogo_ht_vht(dev)
  486. finally:
  487. set_country("00")