test_p2p_channel.py 47 KB

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