test_p2p_channel.py 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  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):
  659. """P2P GO move due to SCM operation preference"""
  660. with HWSimRadio(n_channels=2) as (radio, iface):
  661. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  662. wpas.interface_add(iface)
  663. if wpas.get_mcc() < 2:
  664. raise Exception("New radio does not support MCC")
  665. ndev = [ wpas, dev[1] ]
  666. _test_p2p_go_move_scm(ndev, apdev)
  667. def _test_p2p_go_move_scm(dev, apdev):
  668. dev[0].request("SET p2p_no_group_iface 0")
  669. try:
  670. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  671. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  672. "channel" : '11' })
  673. dev[0].connect("ap-test", key_mgmt="NONE",
  674. scan_freq="2462")
  675. dev[0].global_request("SET p2p_go_freq_change_policy 0")
  676. res = autogo(dev[0])
  677. freq = int(res['freq'])
  678. if freq > 2430:
  679. raise Exception("Unexpected channel %d MHz" % freq)
  680. # GO move is not allowed while waiting for initial client connection
  681. connect_cli(dev[0], dev[1], freq=freq)
  682. dev[1].remove_group()
  683. freq = dev[0].get_group_status_field('freq')
  684. if int(freq) > 2430:
  685. raise Exception("Unexpected freq after initial client: " + freq)
  686. dev[0].dump_monitor()
  687. dev[0].global_request("P2P_SET disallow_freq ")
  688. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  689. "AP-CSA-FINISHED"], timeout=3)
  690. if ev is None:
  691. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  692. freq = dev[0].get_group_status_field('freq')
  693. if freq != '2462':
  694. raise Exception("Unexpected freq after group reform=" + freq)
  695. dev[0].remove_group()
  696. finally:
  697. dev[0].global_request("P2P_SET disallow_freq ")
  698. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  699. def test_p2p_go_move_scm_peer_supports(dev, apdev):
  700. """P2P GO move due to SCM operation preference (peer supports)"""
  701. with HWSimRadio(n_channels=2) as (radio, iface):
  702. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  703. wpas.interface_add(iface)
  704. if wpas.get_mcc() < 2:
  705. raise Exception("New radio does not support MCC")
  706. ndev = [ wpas, dev[1] ]
  707. _test_p2p_go_move_scm_peer_supports(ndev, apdev)
  708. def _test_p2p_go_move_scm_peer_supports(dev, apdev):
  709. try:
  710. dev[0].global_request("SET p2p_go_freq_change_policy 1")
  711. set_country("US", dev[0])
  712. dev[0].request("SET p2p_no_group_iface 0")
  713. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  714. r_dev=dev[1], r_intent=0,
  715. test_data=False)
  716. check_grpform_results(i_res, r_res)
  717. freq = int(i_res['freq'])
  718. if freq < 5000:
  719. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  720. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  721. "channel" : '11' })
  722. logger.info('Connecting client to to an AP on channel 11');
  723. dev[0].connect("ap-test", key_mgmt="NONE",
  724. scan_freq="2462")
  725. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  726. "AP-CSA-FINISHED"], timeout=3)
  727. if ev is None:
  728. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  729. freq = dev[0].get_group_status_field('freq')
  730. if freq != '2462':
  731. raise Exception("Unexpected freq after group reform=" + freq)
  732. dev[0].remove_group()
  733. finally:
  734. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  735. set_country("00")
  736. def test_p2p_go_move_scm_peer_does_not_support(dev, apdev):
  737. """No P2P GO move due to SCM operation (peer does not supports)"""
  738. with HWSimRadio(n_channels=2) as (radio, iface):
  739. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  740. wpas.interface_add(iface)
  741. if wpas.get_mcc() < 2:
  742. raise Exception("New radio does not support MCC")
  743. ndev = [ wpas, dev[1] ]
  744. _test_p2p_go_move_scm_peer_does_not_support(ndev, apdev)
  745. def _test_p2p_go_move_scm_peer_does_not_support(dev, apdev):
  746. try:
  747. dev[0].global_request("SET p2p_go_freq_change_policy 1")
  748. set_country("US", dev[0])
  749. dev[0].request("SET p2p_no_group_iface 0")
  750. if "OK" not in dev[1].request("DRIVER_EVENT AVOID_FREQUENCIES 2400-2500"):
  751. raise Exception("Could not simulate driver event")
  752. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  753. r_dev=dev[1], r_intent=0,
  754. test_data=False)
  755. check_grpform_results(i_res, r_res)
  756. freq = int(i_res['freq'])
  757. if freq < 5000:
  758. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  759. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  760. "channel" : '11' })
  761. logger.info('Connecting client to to an AP on channel 11');
  762. dev[0].connect("ap-test", key_mgmt="NONE",
  763. scan_freq="2462")
  764. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  765. "AP-CSA-FINISHED"],
  766. timeout=10)
  767. if ev is not None:
  768. raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
  769. dev[0].remove_group()
  770. finally:
  771. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  772. set_country("00")
  773. def test_p2p_go_move_scm_multi(dev, apdev, params):
  774. """P2P GO move due to SCM operation preference multiple times [long]"""
  775. if dev[0].get_mcc() <= 1:
  776. raise HwsimSkip("Skip due to MCC not being enabled")
  777. if not params['long']:
  778. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  779. dev[0].request("SET p2p_no_group_iface 0")
  780. try:
  781. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  782. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test-1',
  783. "channel" : '11' })
  784. dev[0].connect("ap-test-1", key_mgmt="NONE",
  785. scan_freq="2462")
  786. dev[0].global_request("SET p2p_go_freq_change_policy 0")
  787. res = autogo(dev[0])
  788. freq = int(res['freq'])
  789. if freq > 2430:
  790. raise Exception("Unexpected channel %d MHz" % freq)
  791. # GO move is not allowed while waiting for initial client connection
  792. time.sleep(20)
  793. dev[0].global_request("P2P_SET disallow_freq ")
  794. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  795. "AP-CSA-FINISHED"], timeout=3)
  796. if ev is None:
  797. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  798. freq = dev[0].get_group_status_field('freq')
  799. if freq != '2462':
  800. raise Exception("Unexpected freq after group reform=" + freq)
  801. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test-2',
  802. "channel" : '6' })
  803. dev[0].connect("ap-test-2", key_mgmt="NONE",
  804. scan_freq="2437")
  805. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  806. "AP-CSA-FINISHED"], timeout=5)
  807. if ev is None:
  808. raise Exception("(2) P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  809. freq = dev[0].get_group_status_field('freq')
  810. if freq != '2437':
  811. raise Exception("(2) Unexpected freq after group reform=" + freq)
  812. dev[0].remove_group()
  813. finally:
  814. dev[0].global_request("P2P_SET disallow_freq ")
  815. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  816. def test_p2p_delay_go_csa(dev, apdev, params):
  817. """P2P GO CSA delayed when inviting a P2P Device to an active P2P Group"""
  818. with HWSimRadio(n_channels=2) as (radio, iface):
  819. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  820. wpas.interface_add(iface)
  821. wpas.global_request("SET p2p_no_group_iface 0")
  822. if wpas.get_mcc() < 2:
  823. raise Exception("New radio does not support MCC")
  824. addr0 = wpas.p2p_dev_addr()
  825. addr1 = dev[1].p2p_dev_addr()
  826. try:
  827. dev[1].p2p_listen();
  828. if not wpas.discover_peer(addr1, social=True):
  829. raise Exception("Peer " + addr1 + " not found")
  830. wpas.p2p_stop_find()
  831. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  832. "channel": '1' })
  833. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  834. wpas.global_request("SET p2p_go_freq_change_policy 0")
  835. wpas.dump_monitor()
  836. logger.info("Start GO on channel 6")
  837. res = autogo(wpas, freq=2437)
  838. if res['freq'] != "2437":
  839. raise Exception("GO set on a freq=%s instead of 2437" % res['freq'])
  840. # Start find on dev[1] to run scans with dev[2] in parallel
  841. dev[1].p2p_find(social=True)
  842. # Use another client device to stop the initial client connection
  843. # timeout on the GO
  844. if not dev[2].discover_peer(addr0, social=True):
  845. raise Exception("Peer2 did not find the GO")
  846. dev[2].p2p_stop_find()
  847. pin = dev[2].wps_read_pin()
  848. wpas.p2p_go_authorize_client(pin)
  849. dev[2].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=2437")
  850. ev = dev[2].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  851. if ev is None:
  852. raise Exception("Peer2 did not get connected")
  853. if not dev[1].discover_peer(addr0, social=True):
  854. raise Exception("Peer did not find the GO")
  855. pin = dev[1].wps_read_pin()
  856. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth")
  857. dev[1].p2p_listen();
  858. # Force P2P GO channel switch on successful invitation signaling
  859. wpas.group_request("SET p2p_go_csa_on_inv 1")
  860. logger.info("Starting invitation")
  861. wpas.p2p_go_authorize_client(pin)
  862. wpas.global_request("P2P_INVITE group=" + wpas.group_ifname + " peer=" + addr1)
  863. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED",
  864. "P2P-GROUP-STARTED"], timeout=10)
  865. if ev is None:
  866. raise Exception("Timeout on invitation on peer")
  867. if "P2P-INVITATION-RECEIVED" in ev:
  868. raise Exception("Unexpected request to accept pre-authorized invitation")
  869. # A P2P GO move is not expected at this stage, as during the
  870. # invitation signaling, the P2P GO includes only its current
  871. # operating channel in the channel list, and as the invitation
  872. # response can only include channels that were also in the
  873. # invitation request channel list, the group common channels
  874. # includes only the current P2P GO operating channel.
  875. ev = wpas.wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  876. "AP-CSA-FINISHED"], timeout=1)
  877. if ev is not None:
  878. raise Exception("Unexpected + " + ev + " event")
  879. finally:
  880. wpas.global_request("SET p2p_go_freq_change_policy 2")
  881. def test_p2p_channel_vht80p80(dev):
  882. """P2P group formation and VHT 80+80 MHz channel"""
  883. try:
  884. set_country("US", dev[0])
  885. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  886. i_freq=5180,
  887. i_freq2=5775,
  888. i_max_oper_chwidth=160,
  889. i_ht40=True, i_vht=True,
  890. r_dev=dev[1], r_intent=0,
  891. test_data=False)
  892. check_grpform_results(i_res, r_res)
  893. freq = int(i_res['freq'])
  894. if freq < 5000:
  895. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  896. sig = dev[1].group_request("SIGNAL_POLL").splitlines()
  897. if "FREQUENCY=5180" not in sig:
  898. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  899. if "WIDTH=80+80 MHz" not in sig:
  900. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  901. if "CENTER_FRQ1=5210" not in sig:
  902. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  903. if "CENTER_FRQ2=5775" not in sig:
  904. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  905. remove_group(dev[0], dev[1])
  906. finally:
  907. set_country("00")
  908. dev[1].flush_scan_cache()
  909. def test_p2p_channel_vht80p80_autogo(dev):
  910. """P2P autonomous GO and VHT 80+80 MHz channel"""
  911. addr0 = dev[0].p2p_dev_addr()
  912. try:
  913. set_country("US", dev[0])
  914. if "OK" not in dev[0].global_request("P2P_GROUP_ADD vht freq=5180 freq2=5775"):
  915. raise Exception("Could not start GO")
  916. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
  917. if ev is None:
  918. raise Exception("GO start up timed out")
  919. dev[0].group_form_result(ev)
  920. pin = dev[1].wps_read_pin()
  921. dev[0].p2p_go_authorize_client(pin)
  922. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=5180")
  923. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  924. if ev is None:
  925. raise Exception("Peer did not get connected")
  926. sig = dev[1].group_request("SIGNAL_POLL").splitlines()
  927. if "FREQUENCY=5180" not in sig:
  928. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  929. if "WIDTH=80+80 MHz" not in sig:
  930. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  931. if "CENTER_FRQ1=5210" not in sig:
  932. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  933. if "CENTER_FRQ2=5775" not in sig:
  934. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  935. remove_group(dev[0], dev[1])
  936. finally:
  937. set_country("00")
  938. dev[1].flush_scan_cache()
  939. def test_p2p_channel_vht80_autogo(dev):
  940. """P2P autonomous GO and VHT 80 MHz channel"""
  941. addr0 = dev[0].p2p_dev_addr()
  942. try:
  943. set_country("US", dev[0])
  944. if "OK" not in dev[0].global_request("P2P_GROUP_ADD vht freq=5180 max_oper_chwidth=80"):
  945. raise Exception("Could not start GO")
  946. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
  947. if ev is None:
  948. raise Exception("GO start up timed out")
  949. dev[0].group_form_result(ev)
  950. pin = dev[1].wps_read_pin()
  951. dev[0].p2p_go_authorize_client(pin)
  952. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=5180")
  953. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  954. if ev is None:
  955. raise Exception("Peer did not get connected")
  956. sig = dev[1].group_request("SIGNAL_POLL").splitlines()
  957. if "FREQUENCY=5180" not in sig:
  958. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  959. if "WIDTH=80 MHz" not in sig:
  960. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  961. remove_group(dev[0], dev[1])
  962. finally:
  963. set_country("00")
  964. dev[1].flush_scan_cache()
  965. def test_p2p_channel_vht80p80_persistent(dev):
  966. """P2P persistent group re-invocation and VHT 80+80 MHz channel"""
  967. addr0 = dev[0].p2p_dev_addr()
  968. form(dev[0], dev[1])
  969. try:
  970. set_country("US", dev[0])
  971. invite(dev[0], dev[1], extra="vht freq=5745 freq2=5210")
  972. [go_res, cli_res] = check_result(dev[0], dev[1])
  973. sig = dev[1].group_request("SIGNAL_POLL").splitlines()
  974. if "FREQUENCY=5745" not in sig:
  975. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  976. if "WIDTH=80+80 MHz" not in sig:
  977. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  978. if "CENTER_FRQ1=5775" not in sig:
  979. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  980. if "CENTER_FRQ2=5210" not in sig:
  981. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  982. remove_group(dev[0], dev[1])
  983. finally:
  984. set_country("00")
  985. dev[1].flush_scan_cache()