test_p2p_channel.py 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  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 test_p2p_grpform import go_neg_pin_authorized
  18. from test_p2p_grpform import check_grpform_results
  19. from test_p2p_grpform import remove_group
  20. from test_p2p_grpform import go_neg_pbc
  21. from test_p2p_autogo import autogo
  22. def set_country(country, dev=None):
  23. subprocess.call(['iw', 'reg', 'set', country])
  24. time.sleep(0.1)
  25. if dev:
  26. for i in range(10):
  27. ev = dev.wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=15)
  28. if ev is None:
  29. raise Exception("No regdom change event seen")
  30. if "type=COUNTRY alpha2=" + country in ev:
  31. return
  32. raise Exception("No matching regdom event seen for set_country(%s)" % country)
  33. def test_p2p_channel_5ghz(dev):
  34. """P2P group formation with 5 GHz preference"""
  35. try:
  36. set_country("US", dev[0])
  37. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  38. r_dev=dev[1], r_intent=0,
  39. test_data=False)
  40. check_grpform_results(i_res, r_res)
  41. freq = int(i_res['freq'])
  42. if freq < 5000:
  43. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  44. remove_group(dev[0], dev[1])
  45. finally:
  46. set_country("00")
  47. dev[1].flush_scan_cache()
  48. def test_p2p_channel_5ghz_no_vht(dev):
  49. """P2P group formation with 5 GHz preference when VHT channels are disallowed"""
  50. try:
  51. set_country("US", dev[0])
  52. dev[0].request("P2P_SET disallow_freq 5180-5240")
  53. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  54. r_dev=dev[1], r_intent=0,
  55. test_data=False)
  56. check_grpform_results(i_res, r_res)
  57. freq = int(i_res['freq'])
  58. if freq < 5000:
  59. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  60. remove_group(dev[0], dev[1])
  61. finally:
  62. set_country("00")
  63. dev[0].request("P2P_SET disallow_freq ")
  64. dev[1].flush_scan_cache()
  65. def test_p2p_channel_random_social(dev):
  66. """P2P group formation with 5 GHz preference but all 5 GHz channels disabled"""
  67. try:
  68. set_country("US", dev[0])
  69. dev[0].request("SET p2p_oper_channel 11")
  70. dev[0].request("P2P_SET disallow_freq 5000-6000,2462")
  71. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  72. r_dev=dev[1], r_intent=0,
  73. test_data=False)
  74. check_grpform_results(i_res, r_res)
  75. freq = int(i_res['freq'])
  76. if freq not in [ 2412, 2437, 2462 ]:
  77. raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
  78. remove_group(dev[0], dev[1])
  79. finally:
  80. set_country("00")
  81. dev[0].request("P2P_SET disallow_freq ")
  82. dev[1].flush_scan_cache()
  83. def test_p2p_channel_random(dev):
  84. """P2P group formation with 5 GHz preference but all 5 GHz channels and all social channels disabled"""
  85. try:
  86. set_country("US", dev[0])
  87. dev[0].request("SET p2p_oper_channel 11")
  88. dev[0].request("P2P_SET disallow_freq 5000-6000,2412,2437,2462")
  89. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  90. r_dev=dev[1], r_intent=0,
  91. test_data=False)
  92. check_grpform_results(i_res, r_res)
  93. freq = int(i_res['freq'])
  94. if freq > 2500 or freq in [ 2412, 2437, 2462 ]:
  95. raise Exception("Unexpected channel %d MHz" % freq)
  96. remove_group(dev[0], dev[1])
  97. finally:
  98. set_country("00")
  99. dev[0].request("P2P_SET disallow_freq ")
  100. dev[1].flush_scan_cache()
  101. def test_p2p_channel_random_social_with_op_class_change(dev, apdev, params):
  102. """P2P group formation using random social channel with oper class change needed"""
  103. try:
  104. set_country("US", dev[0])
  105. logger.info("Start group on 5 GHz")
  106. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  107. r_dev=dev[1], r_intent=0,
  108. test_data=False)
  109. check_grpform_results(i_res, r_res)
  110. freq = int(i_res['freq'])
  111. if freq < 5000:
  112. raise Exception("Unexpected channel %d MHz - did not pick 5 GHz preference" % freq)
  113. remove_group(dev[0], dev[1])
  114. logger.info("Disable 5 GHz and try to re-start group based on 5 GHz preference")
  115. dev[0].request("SET p2p_oper_reg_class 115")
  116. dev[0].request("SET p2p_oper_channel 36")
  117. dev[0].request("P2P_SET disallow_freq 5000-6000")
  118. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  119. r_dev=dev[1], r_intent=0,
  120. test_data=False)
  121. check_grpform_results(i_res, r_res)
  122. freq = int(i_res['freq'])
  123. if freq not in [ 2412, 2437, 2462 ]:
  124. raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
  125. remove_group(dev[0], dev[1])
  126. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  127. "wifi_p2p.public_action.subtype == 0")
  128. if out is not None:
  129. last = None
  130. for l in out.splitlines():
  131. if "Operating Channel:" not in l:
  132. continue
  133. last = l
  134. if last is None:
  135. raise Exception("Could not find GO Negotiation Request")
  136. if "Operating Class 81" not in last:
  137. raise Exception("Unexpected operating class: " + last.strip())
  138. finally:
  139. set_country("00")
  140. dev[0].request("P2P_SET disallow_freq ")
  141. dev[0].request("SET p2p_oper_reg_class 0")
  142. dev[0].request("SET p2p_oper_channel 0")
  143. dev[1].flush_scan_cache()
  144. def test_p2p_channel_avoid(dev):
  145. """P2P and avoid frequencies driver event"""
  146. try:
  147. set_country("US", dev[0])
  148. if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES 5000-6000,2412,2437,2462"):
  149. raise Exception("Could not simulate driver event")
  150. ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
  151. if ev is None:
  152. raise Exception("No CTRL-EVENT-AVOID-FREQ event")
  153. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  154. r_dev=dev[1], r_intent=0,
  155. test_data=False)
  156. check_grpform_results(i_res, r_res)
  157. freq = int(i_res['freq'])
  158. if freq > 2500 or freq in [ 2412, 2437, 2462 ]:
  159. raise Exception("Unexpected channel %d MHz" % freq)
  160. if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES"):
  161. raise Exception("Could not simulate driver event(2)")
  162. ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
  163. if ev is None:
  164. raise Exception("No CTRL-EVENT-AVOID-FREQ event")
  165. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  166. "AP-CSA-FINISHED"], timeout=1)
  167. if ev is not None:
  168. raise Exception("Unexpected + " + ev + " event")
  169. if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES " + str(freq)):
  170. raise Exception("Could not simulate driver event(3)")
  171. ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
  172. if ev is None:
  173. raise Exception("No CTRL-EVENT-AVOID-FREQ event")
  174. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  175. "AP-CSA-FINISHED"],
  176. timeout=10)
  177. if ev is None:
  178. raise Exception("No P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED event")
  179. finally:
  180. set_country("00")
  181. dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES")
  182. dev[1].flush_scan_cache()
  183. def test_autogo_following_bss(dev, apdev):
  184. """P2P autonomous GO operate on the same channel as station interface"""
  185. if dev[0].get_mcc() > 1:
  186. logger.info("test mode: MCC")
  187. dev[0].request("SET p2p_no_group_iface 0")
  188. channels = { 3 : "2422", 5 : "2432", 9 : "2452" }
  189. for key in channels:
  190. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  191. "channel" : str(key) })
  192. dev[0].connect("ap-test", key_mgmt="NONE",
  193. scan_freq=str(channels[key]))
  194. res_go = autogo(dev[0])
  195. if res_go['freq'] != channels[key]:
  196. raise Exception("Group operation channel is not the same as on connected station interface")
  197. hwsim_utils.test_connectivity(dev[0], hapd)
  198. dev[0].remove_group(res_go['ifname'])
  199. def test_go_neg_with_bss_connected(dev, apdev):
  200. """P2P channel selection: GO negotiation when station interface is connected"""
  201. dev[0].flush_scan_cache()
  202. dev[1].flush_scan_cache()
  203. dev[0].request("SET p2p_no_group_iface 0")
  204. hapd = hostapd.add_ap(apdev[0]['ifname'],
  205. { "ssid": 'bss-2.4ghz', "channel": '5' })
  206. dev[0].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2432")
  207. #dev[0] as GO
  208. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=10, r_dev=dev[1],
  209. r_intent=1)
  210. check_grpform_results(i_res, r_res)
  211. if i_res['role'] != "GO":
  212. raise Exception("GO not selected according to go_intent")
  213. if i_res['freq'] != "2432":
  214. raise Exception("Group formed on a different frequency than BSS")
  215. hwsim_utils.test_connectivity(dev[0], hapd)
  216. dev[0].remove_group(i_res['ifname'])
  217. dev[1].wait_go_ending_session()
  218. if dev[0].get_mcc() > 1:
  219. logger.info("Skip as-client case due to MCC being enabled")
  220. return;
  221. #dev[0] as client
  222. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=1, r_dev=dev[1],
  223. r_intent=10)
  224. check_grpform_results(i_res2, r_res2)
  225. if i_res2['role'] != "client":
  226. raise Exception("GO not selected according to go_intent")
  227. if i_res2['freq'] != "2432":
  228. raise Exception("Group formed on a different frequency than BSS")
  229. hwsim_utils.test_connectivity(dev[0], hapd)
  230. dev[1].remove_group(r_res2['ifname'])
  231. dev[0].wait_go_ending_session()
  232. dev[0].request("DISCONNECT")
  233. hapd.disable()
  234. dev[0].flush_scan_cache()
  235. dev[1].flush_scan_cache()
  236. def test_autogo_with_bss_on_disallowed_chan(dev, apdev):
  237. """P2P channel selection: Autonomous GO with BSS on a disallowed channel"""
  238. with HWSimRadio(n_channels=2) as (radio, iface):
  239. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  240. wpas.interface_add(iface)
  241. wpas.request("SET p2p_no_group_iface 0")
  242. if wpas.get_mcc() < 2:
  243. raise Exception("New radio does not support MCC")
  244. try:
  245. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  246. "channel": '1' })
  247. wpas.request("P2P_SET disallow_freq 2412")
  248. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  249. res = autogo(wpas)
  250. if res['freq'] == "2412":
  251. raise Exception("GO set on a disallowed channel")
  252. hwsim_utils.test_connectivity(wpas, hapd)
  253. finally:
  254. wpas.request("P2P_SET disallow_freq ")
  255. def test_go_neg_with_bss_on_disallowed_chan(dev, apdev):
  256. """P2P channel selection: GO negotiation with station interface on a disallowed channel"""
  257. with HWSimRadio(n_channels=2) as (radio, iface):
  258. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  259. wpas.interface_add(iface)
  260. wpas.request("SET p2p_no_group_iface 0")
  261. if wpas.get_mcc() < 2:
  262. raise Exception("New radio does not support MCC")
  263. try:
  264. hapd = hostapd.add_ap(apdev[0]['ifname'],
  265. { "ssid": 'bss-2.4ghz', "channel": '1' })
  266. # make sure PBC overlap from old test cases is not maintained
  267. dev[1].flush_scan_cache()
  268. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  269. wpas.request("P2P_SET disallow_freq 2412")
  270. #wpas as GO
  271. [i_res, r_res] = go_neg_pbc(i_dev=wpas, i_intent=10, r_dev=dev[1],
  272. r_intent=1)
  273. check_grpform_results(i_res, r_res)
  274. if i_res['role'] != "GO":
  275. raise Exception("GO not selected according to go_intent")
  276. if i_res['freq'] == "2412":
  277. raise Exception("Group formed on a disallowed channel")
  278. hwsim_utils.test_connectivity(wpas, hapd)
  279. wpas.remove_group(i_res['ifname'])
  280. dev[1].wait_go_ending_session()
  281. dev[1].flush_scan_cache()
  282. wpas.dump_monitor()
  283. dev[1].dump_monitor()
  284. #wpas as client
  285. [i_res2, r_res2] = go_neg_pbc(i_dev=wpas, i_intent=1, r_dev=dev[1],
  286. r_intent=10)
  287. check_grpform_results(i_res2, r_res2)
  288. if i_res2['role'] != "client":
  289. raise Exception("GO not selected according to go_intent")
  290. if i_res2['freq'] == "2412":
  291. raise Exception("Group formed on a disallowed channel")
  292. hwsim_utils.test_connectivity(wpas, hapd)
  293. dev[1].remove_group(r_res2['ifname'])
  294. wpas.wait_go_ending_session()
  295. ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=5)
  296. if ev is None:
  297. raise Exception("Group removal not indicated")
  298. wpas.request("DISCONNECT")
  299. hapd.disable()
  300. finally:
  301. wpas.request("P2P_SET disallow_freq ")
  302. def test_autogo_force_diff_channel(dev, apdev):
  303. """P2P autonomous GO and station interface operate on different channels"""
  304. with HWSimRadio(n_channels=2) as (radio, iface):
  305. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  306. wpas.interface_add(iface)
  307. if wpas.get_mcc() < 2:
  308. raise Exception("New radio does not support MCC")
  309. wpas.request("SET p2p_no_group_iface 0")
  310. hapd = hostapd.add_ap(apdev[0]['ifname'],
  311. {"ssid" : 'ap-test', "channel" : '1'})
  312. wpas.connect("ap-test", key_mgmt = "NONE", scan_freq = "2412")
  313. wpas.dump_monitor()
  314. channels = { 2 : 2417, 5 : 2432, 9 : 2452 }
  315. for key in channels:
  316. res_go = autogo(wpas, channels[key])
  317. wpas.dump_monitor()
  318. hwsim_utils.test_connectivity(wpas, hapd)
  319. if int(res_go['freq']) == 2412:
  320. raise Exception("Group operation channel is: 2412 excepted: " + res_go['freq'])
  321. wpas.remove_group(res_go['ifname'])
  322. wpas.dump_monitor()
  323. def test_go_neg_forced_freq_diff_than_bss_freq(dev, apdev):
  324. """P2P channel selection: GO negotiation with forced freq different than station interface"""
  325. with HWSimRadio(n_channels=2) as (radio, iface):
  326. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  327. wpas.interface_add(iface)
  328. if wpas.get_mcc() < 2:
  329. raise Exception("New radio does not support MCC")
  330. # Clear possible PBC session overlap from previous test case
  331. dev[1].flush_scan_cache()
  332. wpas.request("SET p2p_no_group_iface 0")
  333. hapd = hostapd.add_ap(apdev[0]['ifname'],
  334. { "country_code": 'US',
  335. "ssid": 'bss-5ghz', "hw_mode": 'a',
  336. "channel": '40' })
  337. wpas.connect("bss-5ghz", key_mgmt="NONE", scan_freq="5200")
  338. # GO and peer force the same freq, different than BSS freq,
  339. # wpas to become GO
  340. [i_res, r_res] = go_neg_pbc(i_dev=dev[1], i_intent=1, i_freq=5180,
  341. r_dev=wpas, r_intent=14, r_freq=5180)
  342. check_grpform_results(i_res, r_res)
  343. if i_res['freq'] != "5180":
  344. raise Exception("P2P group formed on unexpected frequency: " + i_res['freq'])
  345. if r_res['role'] != "GO":
  346. raise Exception("GO not selected according to go_intent")
  347. hwsim_utils.test_connectivity(wpas, hapd)
  348. wpas.remove_group(r_res['ifname'])
  349. dev[1].wait_go_ending_session()
  350. dev[1].flush_scan_cache()
  351. # GO and peer force the same freq, different than BSS freq, wpas to
  352. # become client
  353. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[1], i_intent=14, i_freq=2422,
  354. r_dev=wpas, r_intent=1, r_freq=2422)
  355. check_grpform_results(i_res2, r_res2)
  356. if i_res2['freq'] != "2422":
  357. raise Exception("P2P group formed on unexpected frequency: " + i_res2['freq'])
  358. if r_res2['role'] != "client":
  359. raise Exception("GO not selected according to go_intent")
  360. hwsim_utils.test_connectivity(wpas, hapd)
  361. wpas.request("DISCONNECT")
  362. hapd.request("DISABLE")
  363. subprocess.call(['iw', 'reg', 'set', '00'])
  364. wpas.flush_scan_cache()
  365. def test_go_pref_chan_bss_on_diff_chan(dev, apdev):
  366. """P2P channel selection: Station on different channel than GO configured pref channel"""
  367. dev[0].request("SET p2p_no_group_iface 0")
  368. try:
  369. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  370. "channel": '1' })
  371. dev[0].request("SET p2p_pref_chan 81:2")
  372. dev[0].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  373. res = autogo(dev[0])
  374. if res['freq'] != "2412":
  375. raise Exception("GO channel did not follow BSS")
  376. hwsim_utils.test_connectivity(dev[0], hapd)
  377. finally:
  378. dev[0].request("SET p2p_pref_chan ")
  379. def test_go_pref_chan_bss_on_disallowed_chan(dev, apdev):
  380. """P2P channel selection: Station interface on different channel than GO configured pref channel, and station channel is disallowed"""
  381. with HWSimRadio(n_channels=2) as (radio, iface):
  382. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  383. wpas.interface_add(iface)
  384. if wpas.get_mcc() < 2:
  385. raise Exception("New radio does not support MCC")
  386. wpas.request("SET p2p_no_group_iface 0")
  387. try:
  388. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  389. "channel": '1' })
  390. wpas.request("P2P_SET disallow_freq 2412")
  391. wpas.request("SET p2p_pref_chan 81:2")
  392. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  393. res2 = autogo(wpas)
  394. if res2['freq'] != "2417":
  395. raise Exception("GO channel did not follow pref_chan configuration")
  396. hwsim_utils.test_connectivity(wpas, hapd)
  397. finally:
  398. wpas.request("P2P_SET disallow_freq ")
  399. wpas.request("SET p2p_pref_chan ")
  400. def test_no_go_freq(dev, apdev):
  401. """P2P channel selection: no GO freq"""
  402. try:
  403. dev[0].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].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].request("SET p2p_no_go_freq ")
  427. def test_go_neg_peers_force_diff_freq(dev, apdev):
  428. """P2P channel selection when peers for different frequency"""
  429. try:
  430. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=14, i_freq=5180,
  431. r_dev=dev[1], r_intent=0, r_freq=5200)
  432. except Exception, e:
  433. return
  434. raise Exception("Unexpected group formation success")
  435. def test_autogo_random_channel(dev, apdev):
  436. """P2P channel selection: GO instantiated on random channel 1, 6, 11"""
  437. freqs = []
  438. go_freqs = ["2412", "2437", "2462"]
  439. for i in range(0, 20):
  440. result = autogo(dev[0])
  441. if result['freq'] not in go_freqs:
  442. raise Exception("Unexpected frequency selected: " + result['freq'])
  443. if result['freq'] not in freqs:
  444. freqs.append(result['freq'])
  445. if len(freqs) == 3:
  446. break
  447. dev[0].remove_group(result['ifname'])
  448. if i == 20:
  449. raise Exception("GO created 20 times and not all social channels were selected. freqs not selected: " + str(list(set(go_freqs) - set(freqs))))
  450. def test_p2p_autogo_pref_chan_disallowed(dev, apdev):
  451. """P2P channel selection: GO preferred channels are disallowed"""
  452. try:
  453. dev[0].request("SET p2p_pref_chan 81:1,81:3,81:6,81:9,81:11")
  454. dev[0].request("P2P_SET disallow_freq 2412,2422,2437,2452,2462")
  455. for i in range(0, 5):
  456. res = autogo(dev[0])
  457. if res['freq'] in [ "2412", "2422", "2437", "2452", "2462" ]:
  458. raise Exception("GO channel is disallowed")
  459. dev[0].remove_group(res['ifname'])
  460. finally:
  461. dev[0].request("P2P_SET disallow_freq ")
  462. dev[0].request("SET p2p_pref_chan ")
  463. def test_p2p_autogo_pref_chan_not_in_regulatory(dev, apdev):
  464. """P2P channel selection: GO preferred channel not allowed in the regulatory rules"""
  465. try:
  466. set_country("US", dev[0])
  467. dev[0].request("SET p2p_pref_chan 124:149")
  468. res = autogo(dev[0], persistent=True)
  469. if res['freq'] != "5745":
  470. raise Exception("Unexpected channel selected: " + res['freq'])
  471. dev[0].remove_group(res['ifname'])
  472. netw = dev[0].list_networks(p2p=True)
  473. if len(netw) != 1:
  474. raise Exception("Unexpected number of network blocks: " + str(netw))
  475. id = netw[0]['id']
  476. set_country("DE", dev[0])
  477. res = autogo(dev[0], persistent=id)
  478. if res['freq'] == "5745":
  479. raise Exception("Unexpected channel selected(2): " + res['freq'])
  480. dev[0].remove_group(res['ifname'])
  481. finally:
  482. dev[0].request("SET p2p_pref_chan ")
  483. set_country("00")
  484. def run_autogo(dev, param):
  485. if "OK" not in dev.global_request("P2P_GROUP_ADD " + param):
  486. raise Exception("P2P_GROUP_ADD failed: " + param)
  487. ev = dev.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  488. if ev is None:
  489. raise Exception("GO start up timed out")
  490. res = dev.group_form_result(ev)
  491. dev.remove_group()
  492. return res
  493. def _test_autogo_ht_vht(dev):
  494. res = run_autogo(dev[0], "ht40")
  495. res = run_autogo(dev[0], "vht")
  496. res = run_autogo(dev[0], "freq=2")
  497. freq = int(res['freq'])
  498. if freq < 2412 or freq > 2462:
  499. raise Exception("Unexpected freq=2 channel: " + str(freq))
  500. res = run_autogo(dev[0], "freq=5")
  501. freq = int(res['freq'])
  502. if freq < 5000 or freq >= 6000:
  503. raise Exception("Unexpected freq=5 channel: " + str(freq))
  504. res = run_autogo(dev[0], "freq=5 ht40 vht")
  505. logger.info(str(res))
  506. freq = int(res['freq'])
  507. if freq < 5000 or freq >= 6000:
  508. raise Exception("Unexpected freq=5 ht40 vht channel: " + str(freq))
  509. def test_autogo_ht_vht(dev):
  510. """P2P autonomous GO with HT/VHT parameters"""
  511. try:
  512. set_country("US", dev[0])
  513. _test_autogo_ht_vht(dev)
  514. finally:
  515. set_country("00")
  516. def test_p2p_listen_chan_optimize(dev, apdev):
  517. """P2P listen channel optimization"""
  518. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  519. wpas.interface_add("wlan5")
  520. addr5 = wpas.p2p_dev_addr()
  521. try:
  522. if "OK" not in wpas.request("SET p2p_optimize_listen_chan 1"):
  523. raise Exception("Failed to set p2p_optimize_listen_chan")
  524. wpas.p2p_listen()
  525. if not dev[0].discover_peer(addr5):
  526. raise Exception("Could not discover peer")
  527. peer = dev[0].get_peer(addr5)
  528. lfreq = peer['listen_freq']
  529. wpas.p2p_stop_find()
  530. dev[0].p2p_stop_find()
  531. channel = "1" if lfreq != '2412' else "6"
  532. freq = "2412" if lfreq != '2412' else "2437"
  533. params = { "ssid": "test-open", "channel": channel }
  534. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  535. id = wpas.connect("test-open", key_mgmt="NONE", scan_freq=freq)
  536. wpas.p2p_listen()
  537. if "OK" not in dev[0].request("P2P_FLUSH"):
  538. raise Exception("P2P_FLUSH failed")
  539. if not dev[0].discover_peer(addr5):
  540. raise Exception("Could not discover peer")
  541. peer = dev[0].get_peer(addr5)
  542. lfreq2 = peer['listen_freq']
  543. if lfreq == lfreq2:
  544. raise Exception("Listen channel did not change")
  545. if lfreq2 != freq:
  546. raise Exception("Listen channel not on AP's operating channel")
  547. wpas.p2p_stop_find()
  548. dev[0].p2p_stop_find()
  549. wpas.request("DISCONNECT")
  550. wpas.wait_disconnected()
  551. # for larger coverage, cover case of current channel matching
  552. wpas.select_network(id)
  553. wpas.wait_connected()
  554. wpas.request("DISCONNECT")
  555. wpas.wait_disconnected()
  556. lchannel = "1" if channel != "1" else "6"
  557. lfreq3 = "2412" if channel != "1" else "2437"
  558. if "OK" not in wpas.request("P2P_SET listen_channel " + lchannel):
  559. raise Exception("Failed to set listen channel")
  560. wpas.select_network(id)
  561. wpas.wait_connected()
  562. wpas.p2p_listen()
  563. if "OK" not in dev[0].request("P2P_FLUSH"):
  564. raise Exception("P2P_FLUSH failed")
  565. if not dev[0].discover_peer(addr5):
  566. raise Exception("Could not discover peer")
  567. peer = dev[0].get_peer(addr5)
  568. lfreq4 = peer['listen_freq']
  569. if lfreq4 != lfreq3:
  570. raise Exception("Unexpected Listen channel after configuration")
  571. wpas.p2p_stop_find()
  572. dev[0].p2p_stop_find()
  573. finally:
  574. wpas.request("SET p2p_optimize_listen_chan 0")
  575. def test_p2p_channel_5ghz_only(dev):
  576. """P2P GO start with only 5 GHz band allowed"""
  577. try:
  578. set_country("US", dev[0])
  579. dev[0].request("P2P_SET disallow_freq 2400-2500")
  580. res = autogo(dev[0])
  581. freq = int(res['freq'])
  582. if freq < 5000:
  583. raise Exception("Unexpected channel %d MHz" % freq)
  584. dev[0].remove_group()
  585. finally:
  586. set_country("00")
  587. dev[0].request("P2P_SET disallow_freq ")
  588. def test_p2p_channel_5ghz_165_169_us(dev):
  589. """P2P GO and 5 GHz channels 165 (allowed) and 169 (disallowed) in US"""
  590. try:
  591. set_country("US", dev[0])
  592. res = dev[0].p2p_start_go(freq=5825)
  593. if res['freq'] != "5825":
  594. raise Exception("Unexpected frequency: " + res['freq'])
  595. dev[0].remove_group()
  596. res = dev[0].global_request("P2P_GROUP_ADD freq=5845")
  597. if "FAIL" not in res:
  598. raise Exception("GO on channel 169 allowed unexpectedly")
  599. finally:
  600. set_country("00")
  601. def test_p2p_go_move_reg_change(dev, apdev, params):
  602. """P2P GO move due to regulatory change [long]"""
  603. if not params['long']:
  604. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  605. try:
  606. set_country("US")
  607. dev[0].global_request("P2P_SET disallow_freq 2400-5000")
  608. res = autogo(dev[0])
  609. freq1 = int(res['freq'])
  610. if freq1 < 5000:
  611. raise Exception("Unexpected channel %d MHz" % freq1)
  612. dev[0].global_request("P2P_SET disallow_freq ")
  613. # GO move is not allowed while waiting for initial client connection
  614. time.sleep(20)
  615. set_country("00")
  616. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  617. "AP-CSA-FINISHED"],
  618. timeout=10)
  619. if ev is None:
  620. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  621. freq2 = dev[0].get_group_status_field('freq')
  622. if freq1 == freq2:
  623. raise Exception("Unexpected freq after group reform=" + freq2)
  624. dev[0].remove_group()
  625. finally:
  626. dev[0].global_request("P2P_SET disallow_freq ")
  627. set_country("00")
  628. def test_p2p_go_move_active(dev, apdev, params):
  629. """P2P GO stays in freq although SCM is possible [long]"""
  630. if dev[0].get_mcc() <= 1:
  631. raise HwsimSkip("Skip due to MCC not being enabled")
  632. if not params['long']:
  633. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  634. dev[0].request("SET p2p_no_group_iface 0")
  635. try:
  636. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  637. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  638. "channel" : '11' })
  639. dev[0].connect("ap-test", key_mgmt="NONE",
  640. scan_freq="2462")
  641. res = autogo(dev[0])
  642. freq = int(res['freq'])
  643. if freq > 2430:
  644. raise Exception("Unexpected channel %d MHz" % freq)
  645. # GO move is not allowed while waiting for initial client connection
  646. time.sleep(20)
  647. dev[0].global_request("P2P_SET disallow_freq ")
  648. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  649. "AP-CSA-FINISHED"],
  650. timeout=10)
  651. if ev is not None:
  652. raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
  653. dev[0].remove_group()
  654. finally:
  655. dev[0].global_request("P2P_SET disallow_freq ")
  656. def test_p2p_go_move_scm(dev, apdev, params):
  657. """P2P GO move due to SCM operation preference [long]"""
  658. if dev[0].get_mcc() <= 1:
  659. raise HwsimSkip("Skip due to MCC not being enabled")
  660. if not params['long']:
  661. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  662. dev[0].request("SET p2p_no_group_iface 0")
  663. try:
  664. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  665. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  666. "channel" : '11' })
  667. dev[0].connect("ap-test", key_mgmt="NONE",
  668. scan_freq="2462")
  669. dev[0].global_request("SET p2p_go_freq_change_policy 0")
  670. res = autogo(dev[0])
  671. freq = int(res['freq'])
  672. if freq > 2430:
  673. raise Exception("Unexpected channel %d MHz" % freq)
  674. # GO move is not allowed while waiting for initial client connection
  675. time.sleep(20)
  676. dev[0].global_request("P2P_SET disallow_freq ")
  677. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  678. "AP-CSA-FINISHED"], timeout=3)
  679. if ev is None:
  680. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  681. freq = dev[0].get_group_status_field('freq')
  682. if freq != '2462':
  683. raise Exception("Unexpected freq after group reform=" + freq)
  684. dev[0].remove_group()
  685. finally:
  686. dev[0].global_request("P2P_SET disallow_freq ")
  687. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  688. def test_p2p_go_move_scm_peer_supports(dev, apdev, params):
  689. """P2P GO move due to SCM operation preference (peer supports) [long]"""
  690. if dev[0].get_mcc() <= 1:
  691. raise HwsimSkip("Skip due to MCC not being enabled")
  692. if not params['long']:
  693. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  694. try:
  695. dev[0].global_request("SET p2p_go_freq_change_policy 1")
  696. set_country("US", dev[0])
  697. dev[0].request("SET p2p_no_group_iface 0")
  698. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  699. r_dev=dev[1], r_intent=0,
  700. test_data=False)
  701. check_grpform_results(i_res, r_res)
  702. freq = int(i_res['freq'])
  703. if freq < 5000:
  704. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  705. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  706. "channel" : '11' })
  707. logger.info('Connecting client to to an AP on channel 11');
  708. dev[0].connect("ap-test", key_mgmt="NONE",
  709. scan_freq="2462")
  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. freq = dev[0].get_group_status_field('freq')
  715. if freq != '2462':
  716. raise Exception("Unexpected freq after group reform=" + freq)
  717. dev[0].remove_group()
  718. finally:
  719. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  720. set_country("00")
  721. def test_p2p_go_move_scm_peer_does_not_support(dev, apdev, params):
  722. """No P2P GO move due to SCM operation (peer does not supports) [long]"""
  723. if dev[0].get_mcc() <= 1:
  724. raise HwsimSkip("Skip due to MCC not being enabled")
  725. if not params['long']:
  726. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  727. try:
  728. dev[0].global_request("SET p2p_go_freq_change_policy 1")
  729. set_country("US", dev[0])
  730. dev[0].request("SET p2p_no_group_iface 0")
  731. if "OK" not in dev[1].request("DRIVER_EVENT AVOID_FREQUENCIES 2400-2500"):
  732. raise Exception("Could not simulate driver event")
  733. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  734. r_dev=dev[1], r_intent=0,
  735. test_data=False)
  736. check_grpform_results(i_res, r_res)
  737. freq = int(i_res['freq'])
  738. if freq < 5000:
  739. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  740. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  741. "channel" : '11' })
  742. logger.info('Connecting client to to an AP on channel 11');
  743. dev[0].connect("ap-test", key_mgmt="NONE",
  744. scan_freq="2462")
  745. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  746. "AP-CSA-FINISHED"],
  747. timeout=10)
  748. if ev is not None:
  749. raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
  750. dev[0].remove_group()
  751. finally:
  752. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  753. set_country("00")
  754. def test_p2p_go_move_scm_multi(dev, apdev, params):
  755. """P2P GO move due to SCM operation preference multiple times [long]"""
  756. if dev[0].get_mcc() <= 1:
  757. raise HwsimSkip("Skip due to MCC not being enabled")
  758. if not params['long']:
  759. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  760. dev[0].request("SET p2p_no_group_iface 0")
  761. try:
  762. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  763. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test-1',
  764. "channel" : '11' })
  765. dev[0].connect("ap-test-1", key_mgmt="NONE",
  766. scan_freq="2462")
  767. dev[0].global_request("SET p2p_go_freq_change_policy 0")
  768. res = autogo(dev[0])
  769. freq = int(res['freq'])
  770. if freq > 2430:
  771. raise Exception("Unexpected channel %d MHz" % freq)
  772. # GO move is not allowed while waiting for initial client connection
  773. time.sleep(20)
  774. dev[0].global_request("P2P_SET disallow_freq ")
  775. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  776. "AP-CSA-FINISHED"], timeout=3)
  777. if ev is None:
  778. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  779. freq = dev[0].get_group_status_field('freq')
  780. if freq != '2462':
  781. raise Exception("Unexpected freq after group reform=" + freq)
  782. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test-2',
  783. "channel" : '6' })
  784. dev[0].connect("ap-test-2", key_mgmt="NONE",
  785. scan_freq="2437")
  786. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  787. "AP-CSA-FINISHED"], timeout=5)
  788. if ev is None:
  789. raise Exception("(2) P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  790. freq = dev[0].get_group_status_field('freq')
  791. if freq != '2437':
  792. raise Exception("(2) Unexpected freq after group reform=" + freq)
  793. dev[0].remove_group()
  794. finally:
  795. dev[0].global_request("P2P_SET disallow_freq ")
  796. dev[0].global_request("SET p2p_go_freq_change_policy 2")