test_p2p_channel.py 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  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 utils import HwsimSkip
  14. from tshark import run_tshark
  15. from wpasupplicant import WpaSupplicant
  16. from hwsim import HWSimRadio
  17. from p2p_utils import *
  18. def set_country(country, dev=None):
  19. subprocess.call(['iw', 'reg', 'set', country])
  20. time.sleep(0.1)
  21. if dev:
  22. for i in range(10):
  23. ev = dev.wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=15)
  24. if ev is None:
  25. raise Exception("No regdom change event seen")
  26. if "type=COUNTRY alpha2=" + country in ev:
  27. return
  28. raise Exception("No matching regdom event seen for set_country(%s)" % country)
  29. def test_p2p_channel_5ghz(dev):
  30. """P2P group formation with 5 GHz preference"""
  31. try:
  32. set_country("US", dev[0])
  33. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  34. r_dev=dev[1], r_intent=0,
  35. test_data=False)
  36. check_grpform_results(i_res, r_res)
  37. freq = int(i_res['freq'])
  38. if freq < 5000:
  39. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  40. remove_group(dev[0], dev[1])
  41. finally:
  42. set_country("00")
  43. dev[1].flush_scan_cache()
  44. def test_p2p_channel_5ghz_no_vht(dev):
  45. """P2P group formation with 5 GHz preference when VHT channels are disallowed"""
  46. try:
  47. set_country("US", dev[0])
  48. dev[0].request("P2P_SET disallow_freq 5180-5240")
  49. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  50. r_dev=dev[1], r_intent=0,
  51. test_data=False)
  52. check_grpform_results(i_res, r_res)
  53. freq = int(i_res['freq'])
  54. if freq < 5000:
  55. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  56. remove_group(dev[0], dev[1])
  57. finally:
  58. set_country("00")
  59. dev[0].request("P2P_SET disallow_freq ")
  60. dev[1].flush_scan_cache()
  61. def test_p2p_channel_random_social(dev):
  62. """P2P group formation with 5 GHz preference but all 5 GHz channels disabled"""
  63. try:
  64. set_country("US", dev[0])
  65. dev[0].request("SET p2p_oper_channel 11")
  66. dev[0].request("P2P_SET disallow_freq 5000-6000,2462")
  67. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  68. r_dev=dev[1], r_intent=0,
  69. test_data=False)
  70. check_grpform_results(i_res, r_res)
  71. freq = int(i_res['freq'])
  72. if freq not in [ 2412, 2437, 2462 ]:
  73. raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
  74. remove_group(dev[0], dev[1])
  75. finally:
  76. set_country("00")
  77. dev[0].request("P2P_SET disallow_freq ")
  78. dev[1].flush_scan_cache()
  79. def test_p2p_channel_random(dev):
  80. """P2P group formation with 5 GHz preference but all 5 GHz channels and all social channels disabled"""
  81. try:
  82. set_country("US", dev[0])
  83. dev[0].request("SET p2p_oper_channel 11")
  84. dev[0].request("P2P_SET disallow_freq 5000-6000,2412,2437,2462")
  85. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  86. r_dev=dev[1], r_intent=0,
  87. test_data=False)
  88. check_grpform_results(i_res, r_res)
  89. freq = int(i_res['freq'])
  90. if freq > 2500 or freq in [ 2412, 2437, 2462 ]:
  91. raise Exception("Unexpected channel %d MHz" % freq)
  92. remove_group(dev[0], dev[1])
  93. finally:
  94. set_country("00")
  95. dev[0].request("P2P_SET disallow_freq ")
  96. dev[1].flush_scan_cache()
  97. def test_p2p_channel_random_social_with_op_class_change(dev, apdev, params):
  98. """P2P group formation using random social channel with oper class change needed"""
  99. try:
  100. set_country("US", dev[0])
  101. logger.info("Start group on 5 GHz")
  102. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  103. r_dev=dev[1], r_intent=0,
  104. test_data=False)
  105. check_grpform_results(i_res, r_res)
  106. freq = int(i_res['freq'])
  107. if freq < 5000:
  108. raise Exception("Unexpected channel %d MHz - did not pick 5 GHz preference" % freq)
  109. remove_group(dev[0], dev[1])
  110. logger.info("Disable 5 GHz and try to re-start group based on 5 GHz preference")
  111. dev[0].request("SET p2p_oper_reg_class 115")
  112. dev[0].request("SET p2p_oper_channel 36")
  113. dev[0].request("P2P_SET disallow_freq 5000-6000")
  114. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  115. r_dev=dev[1], r_intent=0,
  116. test_data=False)
  117. check_grpform_results(i_res, r_res)
  118. freq = int(i_res['freq'])
  119. if freq not in [ 2412, 2437, 2462 ]:
  120. raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
  121. remove_group(dev[0], dev[1])
  122. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  123. "wifi_p2p.public_action.subtype == 0")
  124. if out is not None:
  125. last = None
  126. for l in out.splitlines():
  127. if "Operating Channel:" not in l:
  128. continue
  129. last = l
  130. if last is None:
  131. raise Exception("Could not find GO Negotiation Request")
  132. if "Operating Class 81" not in last:
  133. raise Exception("Unexpected operating class: " + last.strip())
  134. finally:
  135. set_country("00")
  136. dev[0].request("P2P_SET disallow_freq ")
  137. dev[0].request("SET p2p_oper_reg_class 0")
  138. dev[0].request("SET p2p_oper_channel 0")
  139. dev[1].flush_scan_cache()
  140. def test_p2p_channel_avoid(dev):
  141. """P2P and avoid frequencies driver event"""
  142. try:
  143. set_country("US", dev[0])
  144. if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES 5000-6000,2412,2437,2462"):
  145. raise Exception("Could not simulate driver event")
  146. ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
  147. if ev is None:
  148. raise Exception("No CTRL-EVENT-AVOID-FREQ event")
  149. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  150. r_dev=dev[1], r_intent=0,
  151. test_data=False)
  152. check_grpform_results(i_res, r_res)
  153. freq = int(i_res['freq'])
  154. if freq > 2500 or freq in [ 2412, 2437, 2462 ]:
  155. raise Exception("Unexpected channel %d MHz" % freq)
  156. if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES"):
  157. raise Exception("Could not simulate driver event(2)")
  158. ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
  159. if ev is None:
  160. raise Exception("No CTRL-EVENT-AVOID-FREQ event")
  161. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  162. "AP-CSA-FINISHED"], timeout=1)
  163. if ev is not None:
  164. raise Exception("Unexpected + " + ev + " event")
  165. if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES " + str(freq)):
  166. raise Exception("Could not simulate driver event(3)")
  167. ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
  168. if ev is None:
  169. raise Exception("No CTRL-EVENT-AVOID-FREQ event")
  170. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  171. "AP-CSA-FINISHED"],
  172. timeout=10)
  173. if ev is None:
  174. raise Exception("No P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED 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. dev[1].wait_go_ending_session()
  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_res2['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. wpas.dump_monitor()
  310. channels = { 2 : 2417, 5 : 2432, 9 : 2452 }
  311. for key in channels:
  312. res_go = autogo(wpas, channels[key])
  313. wpas.dump_monitor()
  314. hwsim_utils.test_connectivity(wpas, hapd)
  315. if int(res_go['freq']) == 2412:
  316. raise Exception("Group operation channel is: 2412 excepted: " + res_go['freq'])
  317. wpas.remove_group(res_go['ifname'])
  318. wpas.dump_monitor()
  319. def test_go_neg_forced_freq_diff_than_bss_freq(dev, apdev):
  320. """P2P channel selection: GO negotiation with forced freq different than station interface"""
  321. with HWSimRadio(n_channels=2) as (radio, iface):
  322. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  323. wpas.interface_add(iface)
  324. if wpas.get_mcc() < 2:
  325. raise Exception("New radio does not support MCC")
  326. # Clear possible PBC session overlap from previous test case
  327. dev[1].flush_scan_cache()
  328. wpas.request("SET p2p_no_group_iface 0")
  329. hapd = hostapd.add_ap(apdev[0]['ifname'],
  330. { "country_code": 'US',
  331. "ssid": 'bss-5ghz', "hw_mode": 'a',
  332. "channel": '40' })
  333. wpas.connect("bss-5ghz", key_mgmt="NONE", scan_freq="5200")
  334. # GO and peer force the same freq, different than BSS freq,
  335. # wpas to become GO
  336. [i_res, r_res] = go_neg_pbc(i_dev=dev[1], i_intent=1, i_freq=5180,
  337. r_dev=wpas, r_intent=14, r_freq=5180)
  338. check_grpform_results(i_res, r_res)
  339. if i_res['freq'] != "5180":
  340. raise Exception("P2P group formed on unexpected frequency: " + i_res['freq'])
  341. if r_res['role'] != "GO":
  342. raise Exception("GO not selected according to go_intent")
  343. hwsim_utils.test_connectivity(wpas, hapd)
  344. wpas.remove_group(r_res['ifname'])
  345. dev[1].wait_go_ending_session()
  346. dev[1].flush_scan_cache()
  347. # GO and peer force the same freq, different than BSS freq, wpas to
  348. # become client
  349. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[1], i_intent=14, i_freq=2422,
  350. r_dev=wpas, r_intent=1, r_freq=2422)
  351. check_grpform_results(i_res2, r_res2)
  352. if i_res2['freq'] != "2422":
  353. raise Exception("P2P group formed on unexpected frequency: " + i_res2['freq'])
  354. if r_res2['role'] != "client":
  355. raise Exception("GO not selected according to go_intent")
  356. hwsim_utils.test_connectivity(wpas, hapd)
  357. wpas.request("DISCONNECT")
  358. hapd.request("DISABLE")
  359. subprocess.call(['iw', 'reg', 'set', '00'])
  360. wpas.flush_scan_cache()
  361. def test_go_pref_chan_bss_on_diff_chan(dev, apdev):
  362. """P2P channel selection: Station on different channel than GO configured pref channel"""
  363. dev[0].request("SET p2p_no_group_iface 0")
  364. try:
  365. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  366. "channel": '1' })
  367. dev[0].request("SET p2p_pref_chan 81:2")
  368. dev[0].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  369. res = autogo(dev[0])
  370. if res['freq'] != "2412":
  371. raise Exception("GO channel did not follow BSS")
  372. hwsim_utils.test_connectivity(dev[0], hapd)
  373. finally:
  374. dev[0].request("SET p2p_pref_chan ")
  375. def test_go_pref_chan_bss_on_disallowed_chan(dev, apdev):
  376. """P2P channel selection: Station interface on different channel than GO configured pref channel, and station channel is disallowed"""
  377. with HWSimRadio(n_channels=2) as (radio, iface):
  378. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  379. wpas.interface_add(iface)
  380. if wpas.get_mcc() < 2:
  381. raise Exception("New radio does not support MCC")
  382. wpas.request("SET p2p_no_group_iface 0")
  383. try:
  384. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  385. "channel": '1' })
  386. wpas.request("P2P_SET disallow_freq 2412")
  387. wpas.request("SET p2p_pref_chan 81:2")
  388. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  389. res2 = autogo(wpas)
  390. if res2['freq'] != "2417":
  391. raise Exception("GO channel did not follow pref_chan configuration")
  392. hwsim_utils.test_connectivity(wpas, hapd)
  393. finally:
  394. wpas.request("P2P_SET disallow_freq ")
  395. wpas.request("SET p2p_pref_chan ")
  396. def test_no_go_freq(dev, apdev):
  397. """P2P channel selection: no GO freq"""
  398. try:
  399. dev[0].request("SET p2p_no_go_freq 2412")
  400. # dev[0] as client, channel 1 is ok
  401. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=1,
  402. r_dev=dev[1], r_intent=14, r_freq=2412)
  403. check_grpform_results(i_res, r_res)
  404. if i_res['freq'] != "2412":
  405. raise Exception("P2P group not formed on forced freq")
  406. dev[1].remove_group(r_res['ifname'])
  407. dev[0].wait_go_ending_session()
  408. dev[0].flush_scan_cache()
  409. fail = False
  410. # dev[0] as GO, channel 1 is not allowed
  411. try:
  412. dev[0].request("SET p2p_no_go_freq 2412")
  413. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=14,
  414. r_dev=dev[1], r_intent=1, r_freq=2412)
  415. check_grpform_results(i_res2, r_res2)
  416. fail = True
  417. except:
  418. pass
  419. if fail:
  420. raise Exception("GO set on a disallowed freq")
  421. finally:
  422. dev[0].request("SET p2p_no_go_freq ")
  423. def test_go_neg_peers_force_diff_freq(dev, apdev):
  424. """P2P channel selection when peers for different frequency"""
  425. try:
  426. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=14, i_freq=5180,
  427. r_dev=dev[1], r_intent=0, r_freq=5200)
  428. except Exception, e:
  429. return
  430. raise Exception("Unexpected group formation success")
  431. def test_autogo_random_channel(dev, apdev):
  432. """P2P channel selection: GO instantiated on random channel 1, 6, 11"""
  433. freqs = []
  434. go_freqs = ["2412", "2437", "2462"]
  435. for i in range(0, 20):
  436. result = autogo(dev[0])
  437. if result['freq'] not in go_freqs:
  438. raise Exception("Unexpected frequency selected: " + result['freq'])
  439. if result['freq'] not in freqs:
  440. freqs.append(result['freq'])
  441. if len(freqs) == 3:
  442. break
  443. dev[0].remove_group(result['ifname'])
  444. if i == 20:
  445. raise Exception("GO created 20 times and not all social channels were selected. freqs not selected: " + str(list(set(go_freqs) - set(freqs))))
  446. def test_p2p_autogo_pref_chan_disallowed(dev, apdev):
  447. """P2P channel selection: GO preferred channels are disallowed"""
  448. try:
  449. dev[0].request("SET p2p_pref_chan 81:1,81:3,81:6,81:9,81:11")
  450. dev[0].request("P2P_SET disallow_freq 2412,2422,2437,2452,2462")
  451. for i in range(0, 5):
  452. res = autogo(dev[0])
  453. if res['freq'] in [ "2412", "2422", "2437", "2452", "2462" ]:
  454. raise Exception("GO channel is disallowed")
  455. dev[0].remove_group(res['ifname'])
  456. finally:
  457. dev[0].request("P2P_SET disallow_freq ")
  458. dev[0].request("SET p2p_pref_chan ")
  459. def test_p2p_autogo_pref_chan_not_in_regulatory(dev, apdev):
  460. """P2P channel selection: GO preferred channel not allowed in the regulatory rules"""
  461. try:
  462. set_country("US", dev[0])
  463. dev[0].request("SET p2p_pref_chan 124:149")
  464. res = autogo(dev[0], persistent=True)
  465. if res['freq'] != "5745":
  466. raise Exception("Unexpected channel selected: " + res['freq'])
  467. dev[0].remove_group(res['ifname'])
  468. netw = dev[0].list_networks(p2p=True)
  469. if len(netw) != 1:
  470. raise Exception("Unexpected number of network blocks: " + str(netw))
  471. id = netw[0]['id']
  472. set_country("DE", dev[0])
  473. res = autogo(dev[0], persistent=id)
  474. if res['freq'] == "5745":
  475. raise Exception("Unexpected channel selected(2): " + res['freq'])
  476. dev[0].remove_group(res['ifname'])
  477. finally:
  478. dev[0].request("SET p2p_pref_chan ")
  479. set_country("00")
  480. def run_autogo(dev, param):
  481. if "OK" not in dev.global_request("P2P_GROUP_ADD " + param):
  482. raise Exception("P2P_GROUP_ADD failed: " + param)
  483. ev = dev.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  484. if ev is None:
  485. raise Exception("GO start up timed out")
  486. res = dev.group_form_result(ev)
  487. dev.remove_group()
  488. return res
  489. def _test_autogo_ht_vht(dev):
  490. res = run_autogo(dev[0], "ht40")
  491. res = run_autogo(dev[0], "vht")
  492. res = run_autogo(dev[0], "freq=2")
  493. freq = int(res['freq'])
  494. if freq < 2412 or freq > 2462:
  495. raise Exception("Unexpected freq=2 channel: " + str(freq))
  496. res = run_autogo(dev[0], "freq=5")
  497. freq = int(res['freq'])
  498. if freq < 5000 or freq >= 6000:
  499. raise Exception("Unexpected freq=5 channel: " + str(freq))
  500. res = run_autogo(dev[0], "freq=5 ht40 vht")
  501. logger.info(str(res))
  502. freq = int(res['freq'])
  503. if freq < 5000 or freq >= 6000:
  504. raise Exception("Unexpected freq=5 ht40 vht channel: " + str(freq))
  505. def test_autogo_ht_vht(dev):
  506. """P2P autonomous GO with HT/VHT parameters"""
  507. try:
  508. set_country("US", dev[0])
  509. _test_autogo_ht_vht(dev)
  510. finally:
  511. set_country("00")
  512. def test_p2p_listen_chan_optimize(dev, apdev):
  513. """P2P listen channel optimization"""
  514. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  515. wpas.interface_add("wlan5")
  516. addr5 = wpas.p2p_dev_addr()
  517. try:
  518. if "OK" not in wpas.request("SET p2p_optimize_listen_chan 1"):
  519. raise Exception("Failed to set p2p_optimize_listen_chan")
  520. wpas.p2p_listen()
  521. if not dev[0].discover_peer(addr5):
  522. raise Exception("Could not discover peer")
  523. peer = dev[0].get_peer(addr5)
  524. lfreq = peer['listen_freq']
  525. wpas.p2p_stop_find()
  526. dev[0].p2p_stop_find()
  527. channel = "1" if lfreq != '2412' else "6"
  528. freq = "2412" if lfreq != '2412' else "2437"
  529. params = { "ssid": "test-open", "channel": channel }
  530. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  531. id = wpas.connect("test-open", key_mgmt="NONE", scan_freq=freq)
  532. wpas.p2p_listen()
  533. if "OK" not in dev[0].request("P2P_FLUSH"):
  534. raise Exception("P2P_FLUSH failed")
  535. if not dev[0].discover_peer(addr5):
  536. raise Exception("Could not discover peer")
  537. peer = dev[0].get_peer(addr5)
  538. lfreq2 = peer['listen_freq']
  539. if lfreq == lfreq2:
  540. raise Exception("Listen channel did not change")
  541. if lfreq2 != freq:
  542. raise Exception("Listen channel not on AP's operating channel")
  543. wpas.p2p_stop_find()
  544. dev[0].p2p_stop_find()
  545. wpas.request("DISCONNECT")
  546. wpas.wait_disconnected()
  547. # for larger coverage, cover case of current channel matching
  548. wpas.select_network(id)
  549. wpas.wait_connected()
  550. wpas.request("DISCONNECT")
  551. wpas.wait_disconnected()
  552. lchannel = "1" if channel != "1" else "6"
  553. lfreq3 = "2412" if channel != "1" else "2437"
  554. if "OK" not in wpas.request("P2P_SET listen_channel " + lchannel):
  555. raise Exception("Failed to set listen channel")
  556. wpas.select_network(id)
  557. wpas.wait_connected()
  558. wpas.p2p_listen()
  559. if "OK" not in dev[0].request("P2P_FLUSH"):
  560. raise Exception("P2P_FLUSH failed")
  561. if not dev[0].discover_peer(addr5):
  562. raise Exception("Could not discover peer")
  563. peer = dev[0].get_peer(addr5)
  564. lfreq4 = peer['listen_freq']
  565. if lfreq4 != lfreq3:
  566. raise Exception("Unexpected Listen channel after configuration")
  567. wpas.p2p_stop_find()
  568. dev[0].p2p_stop_find()
  569. finally:
  570. wpas.request("SET p2p_optimize_listen_chan 0")
  571. def test_p2p_channel_5ghz_only(dev):
  572. """P2P GO start with only 5 GHz band allowed"""
  573. try:
  574. set_country("US", dev[0])
  575. dev[0].request("P2P_SET disallow_freq 2400-2500")
  576. res = autogo(dev[0])
  577. freq = int(res['freq'])
  578. if freq < 5000:
  579. raise Exception("Unexpected channel %d MHz" % freq)
  580. dev[0].remove_group()
  581. finally:
  582. set_country("00")
  583. dev[0].request("P2P_SET disallow_freq ")
  584. def test_p2p_channel_5ghz_165_169_us(dev):
  585. """P2P GO and 5 GHz channels 165 (allowed) and 169 (disallowed) in US"""
  586. try:
  587. set_country("US", dev[0])
  588. res = dev[0].p2p_start_go(freq=5825)
  589. if res['freq'] != "5825":
  590. raise Exception("Unexpected frequency: " + res['freq'])
  591. dev[0].remove_group()
  592. res = dev[0].global_request("P2P_GROUP_ADD freq=5845")
  593. if "FAIL" not in res:
  594. raise Exception("GO on channel 169 allowed unexpectedly")
  595. finally:
  596. set_country("00")
  597. def test_p2p_go_move_reg_change(dev, apdev, params):
  598. """P2P GO move due to regulatory change [long]"""
  599. if not params['long']:
  600. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  601. try:
  602. set_country("US")
  603. dev[0].global_request("P2P_SET disallow_freq 2400-5000")
  604. res = autogo(dev[0])
  605. freq1 = int(res['freq'])
  606. if freq1 < 5000:
  607. raise Exception("Unexpected channel %d MHz" % freq1)
  608. dev[0].global_request("P2P_SET disallow_freq ")
  609. # GO move is not allowed while waiting for initial client connection
  610. time.sleep(20)
  611. set_country("00")
  612. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  613. "AP-CSA-FINISHED"],
  614. timeout=10)
  615. if ev is None:
  616. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  617. freq2 = dev[0].get_group_status_field('freq')
  618. if freq1 == freq2:
  619. raise Exception("Unexpected freq after group reform=" + freq2)
  620. dev[0].remove_group()
  621. finally:
  622. dev[0].global_request("P2P_SET disallow_freq ")
  623. set_country("00")
  624. def test_p2p_go_move_active(dev, apdev, params):
  625. """P2P GO stays in freq although SCM is possible [long]"""
  626. if not params['long']:
  627. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  628. with HWSimRadio(n_channels=2) as (radio, iface):
  629. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  630. wpas.interface_add(iface)
  631. if wpas.get_mcc() < 2:
  632. raise Exception("New radio does not support MCC")
  633. ndev = [ wpas, dev[1] ]
  634. _test_p2p_go_move_active(ndev, apdev)
  635. def _test_p2p_go_move_active(dev, apdev):
  636. dev[0].request("SET p2p_no_group_iface 0")
  637. try:
  638. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  639. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  640. "channel" : '11' })
  641. dev[0].connect("ap-test", key_mgmt="NONE",
  642. scan_freq="2462")
  643. res = autogo(dev[0])
  644. freq = int(res['freq'])
  645. if freq > 2430:
  646. raise Exception("Unexpected channel %d MHz" % freq)
  647. # GO move is not allowed while waiting for initial client connection
  648. time.sleep(20)
  649. dev[0].global_request("P2P_SET disallow_freq ")
  650. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  651. "AP-CSA-FINISHED"],
  652. timeout=10)
  653. if ev is not None:
  654. raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
  655. dev[0].remove_group()
  656. finally:
  657. dev[0].global_request("P2P_SET disallow_freq ")
  658. def test_p2p_go_move_scm(dev, apdev, params):
  659. """P2P GO move due to SCM operation preference [long]"""
  660. if not params['long']:
  661. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  662. with HWSimRadio(n_channels=2) as (radio, iface):
  663. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  664. wpas.interface_add(iface)
  665. if wpas.get_mcc() < 2:
  666. raise Exception("New radio does not support MCC")
  667. ndev = [ wpas, dev[1] ]
  668. _test_p2p_go_move_scm(ndev, apdev)
  669. def _test_p2p_go_move_scm(dev, apdev):
  670. dev[0].request("SET p2p_no_group_iface 0")
  671. try:
  672. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  673. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  674. "channel" : '11' })
  675. dev[0].connect("ap-test", key_mgmt="NONE",
  676. scan_freq="2462")
  677. dev[0].global_request("SET p2p_go_freq_change_policy 0")
  678. res = autogo(dev[0])
  679. freq = int(res['freq'])
  680. if freq > 2430:
  681. raise Exception("Unexpected channel %d MHz" % freq)
  682. # GO move is not allowed while waiting for initial client connection
  683. time.sleep(20)
  684. dev[0].global_request("P2P_SET disallow_freq ")
  685. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  686. "AP-CSA-FINISHED"], timeout=3)
  687. if ev is None:
  688. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  689. freq = dev[0].get_group_status_field('freq')
  690. if freq != '2462':
  691. raise Exception("Unexpected freq after group reform=" + freq)
  692. dev[0].remove_group()
  693. finally:
  694. dev[0].global_request("P2P_SET disallow_freq ")
  695. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  696. def test_p2p_go_move_scm_peer_supports(dev, apdev, params):
  697. """P2P GO move due to SCM operation preference (peer supports) [long]"""
  698. if dev[0].get_mcc() <= 1:
  699. raise HwsimSkip("Skip due to MCC not being enabled")
  700. if not params['long']:
  701. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  702. try:
  703. dev[0].global_request("SET p2p_go_freq_change_policy 1")
  704. set_country("US", dev[0])
  705. dev[0].request("SET p2p_no_group_iface 0")
  706. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  707. r_dev=dev[1], r_intent=0,
  708. test_data=False)
  709. check_grpform_results(i_res, r_res)
  710. freq = int(i_res['freq'])
  711. if freq < 5000:
  712. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  713. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  714. "channel" : '11' })
  715. logger.info('Connecting client to to an AP on channel 11');
  716. dev[0].connect("ap-test", key_mgmt="NONE",
  717. scan_freq="2462")
  718. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  719. "AP-CSA-FINISHED"], timeout=3)
  720. if ev is None:
  721. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  722. freq = dev[0].get_group_status_field('freq')
  723. if freq != '2462':
  724. raise Exception("Unexpected freq after group reform=" + freq)
  725. dev[0].remove_group()
  726. finally:
  727. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  728. set_country("00")
  729. def test_p2p_go_move_scm_peer_does_not_support(dev, apdev, params):
  730. """No P2P GO move due to SCM operation (peer does not supports) [long]"""
  731. if dev[0].get_mcc() <= 1:
  732. raise HwsimSkip("Skip due to MCC not being enabled")
  733. if not params['long']:
  734. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  735. try:
  736. dev[0].global_request("SET p2p_go_freq_change_policy 1")
  737. set_country("US", dev[0])
  738. dev[0].request("SET p2p_no_group_iface 0")
  739. if "OK" not in dev[1].request("DRIVER_EVENT AVOID_FREQUENCIES 2400-2500"):
  740. raise Exception("Could not simulate driver event")
  741. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  742. r_dev=dev[1], r_intent=0,
  743. test_data=False)
  744. check_grpform_results(i_res, r_res)
  745. freq = int(i_res['freq'])
  746. if freq < 5000:
  747. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  748. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  749. "channel" : '11' })
  750. logger.info('Connecting client to to an AP on channel 11');
  751. dev[0].connect("ap-test", key_mgmt="NONE",
  752. scan_freq="2462")
  753. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  754. "AP-CSA-FINISHED"],
  755. timeout=10)
  756. if ev is not None:
  757. raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
  758. dev[0].remove_group()
  759. finally:
  760. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  761. set_country("00")
  762. def test_p2p_go_move_scm_multi(dev, apdev, params):
  763. """P2P GO move due to SCM operation preference multiple times [long]"""
  764. if dev[0].get_mcc() <= 1:
  765. raise HwsimSkip("Skip due to MCC not being enabled")
  766. if not params['long']:
  767. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  768. dev[0].request("SET p2p_no_group_iface 0")
  769. try:
  770. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  771. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test-1',
  772. "channel" : '11' })
  773. dev[0].connect("ap-test-1", key_mgmt="NONE",
  774. scan_freq="2462")
  775. dev[0].global_request("SET p2p_go_freq_change_policy 0")
  776. res = autogo(dev[0])
  777. freq = int(res['freq'])
  778. if freq > 2430:
  779. raise Exception("Unexpected channel %d MHz" % freq)
  780. # GO move is not allowed while waiting for initial client connection
  781. time.sleep(20)
  782. dev[0].global_request("P2P_SET disallow_freq ")
  783. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  784. "AP-CSA-FINISHED"], timeout=3)
  785. if ev is None:
  786. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  787. freq = dev[0].get_group_status_field('freq')
  788. if freq != '2462':
  789. raise Exception("Unexpected freq after group reform=" + freq)
  790. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test-2',
  791. "channel" : '6' })
  792. dev[0].connect("ap-test-2", key_mgmt="NONE",
  793. scan_freq="2437")
  794. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  795. "AP-CSA-FINISHED"], timeout=5)
  796. if ev is None:
  797. raise Exception("(2) P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  798. freq = dev[0].get_group_status_field('freq')
  799. if freq != '2437':
  800. raise Exception("(2) Unexpected freq after group reform=" + freq)
  801. dev[0].remove_group()
  802. finally:
  803. dev[0].global_request("P2P_SET disallow_freq ")
  804. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  805. def test_p2p_delay_go_csa(dev, apdev, params):
  806. """P2P GO CSA delayed when inviting a P2P Device to an active P2P Group"""
  807. with HWSimRadio(n_channels=2) as (radio, iface):
  808. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  809. wpas.interface_add(iface)
  810. wpas.global_request("SET p2p_no_group_iface 0")
  811. if wpas.get_mcc() < 2:
  812. raise Exception("New radio does not support MCC")
  813. addr0 = wpas.p2p_dev_addr()
  814. addr1 = dev[1].p2p_dev_addr()
  815. try:
  816. dev[1].p2p_listen();
  817. if not wpas.discover_peer(addr1, social=True):
  818. raise Exception("Peer " + addr1 + " not found")
  819. wpas.p2p_stop_find()
  820. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  821. "channel": '1' })
  822. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  823. wpas.global_request("SET p2p_go_freq_change_policy 0")
  824. wpas.dump_monitor()
  825. logger.info("Start GO on channel 6")
  826. res = autogo(wpas, freq=2437)
  827. if res['freq'] != "2437":
  828. raise Exception("GO set on a freq=%s instead of 2437" % res['freq'])
  829. # Start find on dev[1] to run scans with dev[2] in parallel
  830. dev[1].p2p_find(social=True)
  831. # Use another client device to stop the initial client connection
  832. # timeout on the GO
  833. if not dev[2].discover_peer(addr0, social=True):
  834. raise Exception("Peer2 did not find the GO")
  835. dev[2].p2p_stop_find()
  836. pin = dev[2].wps_read_pin()
  837. wpas.p2p_go_authorize_client(pin)
  838. dev[2].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=2437")
  839. ev = dev[2].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  840. if ev is None:
  841. raise Exception("Peer2 did not get connected")
  842. if not dev[1].discover_peer(addr0, social=True):
  843. raise Exception("Peer did not find the GO")
  844. pin = dev[1].wps_read_pin()
  845. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth")
  846. dev[1].p2p_listen();
  847. # Force P2P GO channel switch on successful invitation signaling
  848. wpas.group_request("SET p2p_go_csa_on_inv 1")
  849. logger.info("Starting invitation")
  850. wpas.p2p_go_authorize_client(pin)
  851. wpas.global_request("P2P_INVITE group=" + wpas.group_ifname + " peer=" + addr1)
  852. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED",
  853. "P2P-GROUP-STARTED"], timeout=10)
  854. if ev is None:
  855. raise Exception("Timeout on invitation on peer")
  856. if "P2P-INVITATION-RECEIVED" in ev:
  857. raise Exception("Unexpected request to accept pre-authorized invitation")
  858. # A P2P GO move is not expected at this stage, as during the
  859. # invitation signaling, the P2P GO includes only its current
  860. # operating channel in the channel list, and as the invitation
  861. # response can only include channels that were also in the
  862. # invitation request channel list, the group common channels
  863. # includes only the current P2P GO operating channel.
  864. ev = wpas.wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  865. "AP-CSA-FINISHED"], timeout=1)
  866. if ev is not None:
  867. raise Exception("Unexpected + " + ev + " event")
  868. finally:
  869. wpas.global_request("SET p2p_go_freq_change_policy 2")
  870. def test_p2p_channel_vht80p80(dev):
  871. """P2P group formation and VHT 80+80 MHz channel"""
  872. try:
  873. set_country("US", dev[0])
  874. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  875. i_freq=5180,
  876. i_freq2=5775,
  877. i_max_oper_chwidth=160,
  878. i_ht40=True, i_vht=True,
  879. r_dev=dev[1], r_intent=0,
  880. test_data=False)
  881. check_grpform_results(i_res, r_res)
  882. freq = int(i_res['freq'])
  883. if freq < 5000:
  884. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  885. sig = dev[1].group_request("SIGNAL_POLL").splitlines()
  886. if "FREQUENCY=5180" not in sig:
  887. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  888. if "WIDTH=80+80 MHz" not in sig:
  889. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  890. if "CENTER_FRQ1=5210" not in sig:
  891. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  892. if "CENTER_FRQ2=5775" not in sig:
  893. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  894. remove_group(dev[0], dev[1])
  895. finally:
  896. set_country("00")
  897. dev[1].flush_scan_cache()
  898. def test_p2p_channel_vht80p80_autogo(dev):
  899. """P2P autonomous GO and VHT 80+80 MHz channel"""
  900. addr0 = dev[0].p2p_dev_addr()
  901. try:
  902. set_country("US", dev[0])
  903. if "OK" not in dev[0].global_request("P2P_GROUP_ADD vht freq=5180 freq2=5775"):
  904. raise Exception("Could not start GO")
  905. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
  906. if ev is None:
  907. raise Exception("GO start up timed out")
  908. dev[0].group_form_result(ev)
  909. pin = dev[1].wps_read_pin()
  910. dev[0].p2p_go_authorize_client(pin)
  911. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=5180")
  912. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  913. if ev is None:
  914. raise Exception("Peer did not get connected")
  915. sig = dev[1].group_request("SIGNAL_POLL").splitlines()
  916. if "FREQUENCY=5180" not in sig:
  917. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  918. if "WIDTH=80+80 MHz" not in sig:
  919. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  920. if "CENTER_FRQ1=5210" not in sig:
  921. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  922. if "CENTER_FRQ2=5775" not in sig:
  923. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  924. remove_group(dev[0], dev[1])
  925. finally:
  926. set_country("00")
  927. dev[1].flush_scan_cache()
  928. def test_p2p_channel_vht80_autogo(dev):
  929. """P2P autonomous GO and VHT 80 MHz channel"""
  930. addr0 = dev[0].p2p_dev_addr()
  931. try:
  932. set_country("US", dev[0])
  933. if "OK" not in dev[0].global_request("P2P_GROUP_ADD vht freq=5180 max_oper_chwidth=80"):
  934. raise Exception("Could not start GO")
  935. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
  936. if ev is None:
  937. raise Exception("GO start up timed out")
  938. dev[0].group_form_result(ev)
  939. pin = dev[1].wps_read_pin()
  940. dev[0].p2p_go_authorize_client(pin)
  941. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=5180")
  942. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  943. if ev is None:
  944. raise Exception("Peer did not get connected")
  945. sig = dev[1].group_request("SIGNAL_POLL").splitlines()
  946. if "FREQUENCY=5180" not in sig:
  947. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  948. if "WIDTH=80 MHz" not in sig:
  949. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  950. remove_group(dev[0], dev[1])
  951. finally:
  952. set_country("00")
  953. dev[1].flush_scan_cache()
  954. def test_p2p_channel_vht80p80_persistent(dev):
  955. """P2P persistent group re-invocation and VHT 80+80 MHz channel"""
  956. addr0 = dev[0].p2p_dev_addr()
  957. form(dev[0], dev[1])
  958. try:
  959. set_country("US", dev[0])
  960. invite(dev[0], dev[1], extra="vht freq=5745 freq2=5210")
  961. [go_res, cli_res] = check_result(dev[0], dev[1])
  962. sig = dev[1].group_request("SIGNAL_POLL").splitlines()
  963. if "FREQUENCY=5745" not in sig:
  964. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  965. if "WIDTH=80+80 MHz" not in sig:
  966. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  967. if "CENTER_FRQ1=5775" not in sig:
  968. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  969. if "CENTER_FRQ2=5210" not in sig:
  970. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  971. remove_group(dev[0], dev[1])
  972. finally:
  973. set_country("00")
  974. dev[1].flush_scan_cache()