test_p2p_channel.py 50 KB

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