test_p2p_channel.py 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  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. channels = { 2 : 2417, 5 : 2432, 9 : 2452 }
  314. for key in channels:
  315. res_go = autogo(wpas, channels[key])
  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. def test_go_neg_forced_freq_diff_than_bss_freq(dev, apdev):
  321. """P2P channel selection: GO negotiation with forced freq different than station interface"""
  322. with HWSimRadio(n_channels=2) as (radio, iface):
  323. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  324. wpas.interface_add(iface)
  325. if wpas.get_mcc() < 2:
  326. raise Exception("New radio does not support MCC")
  327. # Clear possible PBC session overlap from previous test case
  328. dev[1].flush_scan_cache()
  329. wpas.request("SET p2p_no_group_iface 0")
  330. hapd = hostapd.add_ap(apdev[0]['ifname'],
  331. { "country_code": 'US',
  332. "ssid": 'bss-5ghz', "hw_mode": 'a',
  333. "channel": '40' })
  334. wpas.connect("bss-5ghz", key_mgmt="NONE", scan_freq="5200")
  335. # GO and peer force the same freq, different than BSS freq,
  336. # wpas to become GO
  337. [i_res, r_res] = go_neg_pbc(i_dev=dev[1], i_intent=1, i_freq=5180,
  338. r_dev=wpas, r_intent=14, r_freq=5180)
  339. check_grpform_results(i_res, r_res)
  340. if i_res['freq'] != "5180":
  341. raise Exception("P2P group formed on unexpected frequency: " + i_res['freq'])
  342. if r_res['role'] != "GO":
  343. raise Exception("GO not selected according to go_intent")
  344. hwsim_utils.test_connectivity(wpas, hapd)
  345. wpas.remove_group(r_res['ifname'])
  346. dev[1].wait_go_ending_session()
  347. dev[1].flush_scan_cache()
  348. # GO and peer force the same freq, different than BSS freq, wpas to
  349. # become client
  350. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[1], i_intent=14, i_freq=2422,
  351. r_dev=wpas, r_intent=1, r_freq=2422)
  352. check_grpform_results(i_res2, r_res2)
  353. if i_res2['freq'] != "2422":
  354. raise Exception("P2P group formed on unexpected frequency: " + i_res2['freq'])
  355. if r_res2['role'] != "client":
  356. raise Exception("GO not selected according to go_intent")
  357. hwsim_utils.test_connectivity(wpas, hapd)
  358. wpas.request("DISCONNECT")
  359. hapd.request("DISABLE")
  360. subprocess.call(['iw', 'reg', 'set', '00'])
  361. wpas.flush_scan_cache()
  362. def test_go_pref_chan_bss_on_diff_chan(dev, apdev):
  363. """P2P channel selection: Station on different channel than GO configured pref channel"""
  364. dev[0].request("SET p2p_no_group_iface 0")
  365. try:
  366. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  367. "channel": '1' })
  368. dev[0].request("SET p2p_pref_chan 81:2")
  369. dev[0].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  370. res = autogo(dev[0])
  371. if res['freq'] != "2412":
  372. raise Exception("GO channel did not follow BSS")
  373. hwsim_utils.test_connectivity(dev[0], hapd)
  374. finally:
  375. dev[0].request("SET p2p_pref_chan ")
  376. def test_go_pref_chan_bss_on_disallowed_chan(dev, apdev):
  377. """P2P channel selection: Station interface on different channel than GO configured pref channel, and station channel is disallowed"""
  378. with HWSimRadio(n_channels=2) as (radio, iface):
  379. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  380. wpas.interface_add(iface)
  381. if wpas.get_mcc() < 2:
  382. raise Exception("New radio does not support MCC")
  383. wpas.request("SET p2p_no_group_iface 0")
  384. try:
  385. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz',
  386. "channel": '1' })
  387. wpas.request("P2P_SET disallow_freq 2412")
  388. wpas.request("SET p2p_pref_chan 81:2")
  389. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  390. res2 = autogo(wpas)
  391. if res2['freq'] != "2417":
  392. raise Exception("GO channel did not follow pref_chan configuration")
  393. hwsim_utils.test_connectivity(wpas, hapd)
  394. finally:
  395. wpas.request("P2P_SET disallow_freq ")
  396. wpas.request("SET p2p_pref_chan ")
  397. def test_no_go_freq(dev, apdev):
  398. """P2P channel selection: no GO freq"""
  399. try:
  400. dev[0].request("SET p2p_no_go_freq 2412")
  401. # dev[0] as client, channel 1 is ok
  402. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=1,
  403. r_dev=dev[1], r_intent=14, r_freq=2412)
  404. check_grpform_results(i_res, r_res)
  405. if i_res['freq'] != "2412":
  406. raise Exception("P2P group not formed on forced freq")
  407. dev[1].remove_group(r_res['ifname'])
  408. dev[0].wait_go_ending_session()
  409. dev[0].flush_scan_cache()
  410. fail = False
  411. # dev[0] as GO, channel 1 is not allowed
  412. try:
  413. dev[0].request("SET p2p_no_go_freq 2412")
  414. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=14,
  415. r_dev=dev[1], r_intent=1, r_freq=2412)
  416. check_grpform_results(i_res2, r_res2)
  417. fail = True
  418. except:
  419. pass
  420. if fail:
  421. raise Exception("GO set on a disallowed freq")
  422. finally:
  423. dev[0].request("SET p2p_no_go_freq ")
  424. def test_go_neg_peers_force_diff_freq(dev, apdev):
  425. """P2P channel selection when peers for different frequency"""
  426. try:
  427. [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=14, i_freq=5180,
  428. r_dev=dev[1], r_intent=0, r_freq=5200)
  429. except Exception, e:
  430. return
  431. raise Exception("Unexpected group formation success")
  432. def test_autogo_random_channel(dev, apdev):
  433. """P2P channel selection: GO instantiated on random channel 1, 6, 11"""
  434. freqs = []
  435. go_freqs = ["2412", "2437", "2462"]
  436. for i in range(0, 20):
  437. result = autogo(dev[0])
  438. if result['freq'] not in go_freqs:
  439. raise Exception("Unexpected frequency selected: " + result['freq'])
  440. if result['freq'] not in freqs:
  441. freqs.append(result['freq'])
  442. if len(freqs) == 3:
  443. break
  444. dev[0].remove_group(result['ifname'])
  445. if i == 20:
  446. raise Exception("GO created 20 times and not all social channels were selected. freqs not selected: " + str(list(set(go_freqs) - set(freqs))))
  447. def test_p2p_autogo_pref_chan_disallowed(dev, apdev):
  448. """P2P channel selection: GO preferred channels are disallowed"""
  449. try:
  450. dev[0].request("SET p2p_pref_chan 81:1,81:3,81:6,81:9,81:11")
  451. dev[0].request("P2P_SET disallow_freq 2412,2422,2437,2452,2462")
  452. for i in range(0, 5):
  453. res = autogo(dev[0])
  454. if res['freq'] in [ "2412", "2422", "2437", "2452", "2462" ]:
  455. raise Exception("GO channel is disallowed")
  456. dev[0].remove_group(res['ifname'])
  457. finally:
  458. dev[0].request("P2P_SET disallow_freq ")
  459. dev[0].request("SET p2p_pref_chan ")
  460. def test_p2p_autogo_pref_chan_not_in_regulatory(dev, apdev):
  461. """P2P channel selection: GO preferred channel not allowed in the regulatory rules"""
  462. try:
  463. set_country("US", dev[0])
  464. dev[0].request("SET p2p_pref_chan 124:149")
  465. res = autogo(dev[0], persistent=True)
  466. if res['freq'] != "5745":
  467. raise Exception("Unexpected channel selected: " + res['freq'])
  468. dev[0].remove_group(res['ifname'])
  469. netw = dev[0].list_networks(p2p=True)
  470. if len(netw) != 1:
  471. raise Exception("Unexpected number of network blocks: " + str(netw))
  472. id = netw[0]['id']
  473. set_country("DE", dev[0])
  474. res = autogo(dev[0], persistent=id)
  475. if res['freq'] == "5745":
  476. raise Exception("Unexpected channel selected(2): " + res['freq'])
  477. dev[0].remove_group(res['ifname'])
  478. finally:
  479. dev[0].request("SET p2p_pref_chan ")
  480. set_country("00")
  481. def run_autogo(dev, param):
  482. if "OK" not in dev.global_request("P2P_GROUP_ADD " + param):
  483. raise Exception("P2P_GROUP_ADD failed: " + param)
  484. ev = dev.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  485. if ev is None:
  486. raise Exception("GO start up timed out")
  487. res = dev.group_form_result(ev)
  488. dev.remove_group()
  489. return res
  490. def _test_autogo_ht_vht(dev):
  491. res = run_autogo(dev[0], "ht40")
  492. res = run_autogo(dev[0], "vht")
  493. res = run_autogo(dev[0], "freq=2")
  494. freq = int(res['freq'])
  495. if freq < 2412 or freq > 2462:
  496. raise Exception("Unexpected freq=2 channel: " + str(freq))
  497. res = run_autogo(dev[0], "freq=5")
  498. freq = int(res['freq'])
  499. if freq < 5000 or freq >= 6000:
  500. raise Exception("Unexpected freq=5 channel: " + str(freq))
  501. res = run_autogo(dev[0], "freq=5 ht40 vht")
  502. logger.info(str(res))
  503. freq = int(res['freq'])
  504. if freq < 5000 or freq >= 6000:
  505. raise Exception("Unexpected freq=5 ht40 vht channel: " + str(freq))
  506. def test_autogo_ht_vht(dev):
  507. """P2P autonomous GO with HT/VHT parameters"""
  508. try:
  509. set_country("US", dev[0])
  510. _test_autogo_ht_vht(dev)
  511. finally:
  512. set_country("00")
  513. def test_p2p_listen_chan_optimize(dev, apdev):
  514. """P2P listen channel optimization"""
  515. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  516. wpas.interface_add("wlan5")
  517. addr5 = wpas.p2p_dev_addr()
  518. try:
  519. if "OK" not in wpas.request("SET p2p_optimize_listen_chan 1"):
  520. raise Exception("Failed to set p2p_optimize_listen_chan")
  521. wpas.p2p_listen()
  522. if not dev[0].discover_peer(addr5):
  523. raise Exception("Could not discover peer")
  524. peer = dev[0].get_peer(addr5)
  525. lfreq = peer['listen_freq']
  526. wpas.p2p_stop_find()
  527. dev[0].p2p_stop_find()
  528. channel = "1" if lfreq != '2412' else "6"
  529. freq = "2412" if lfreq != '2412' else "2437"
  530. params = { "ssid": "test-open", "channel": channel }
  531. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  532. id = wpas.connect("test-open", key_mgmt="NONE", scan_freq=freq)
  533. wpas.p2p_listen()
  534. if "OK" not in dev[0].request("P2P_FLUSH"):
  535. raise Exception("P2P_FLUSH failed")
  536. if not dev[0].discover_peer(addr5):
  537. raise Exception("Could not discover peer")
  538. peer = dev[0].get_peer(addr5)
  539. lfreq2 = peer['listen_freq']
  540. if lfreq == lfreq2:
  541. raise Exception("Listen channel did not change")
  542. if lfreq2 != freq:
  543. raise Exception("Listen channel not on AP's operating channel")
  544. wpas.p2p_stop_find()
  545. dev[0].p2p_stop_find()
  546. wpas.request("DISCONNECT")
  547. wpas.wait_disconnected()
  548. # for larger coverage, cover case of current channel matching
  549. wpas.select_network(id)
  550. wpas.wait_connected()
  551. wpas.request("DISCONNECT")
  552. wpas.wait_disconnected()
  553. lchannel = "1" if channel != "1" else "6"
  554. lfreq3 = "2412" if channel != "1" else "2437"
  555. if "OK" not in wpas.request("P2P_SET listen_channel " + lchannel):
  556. raise Exception("Failed to set listen channel")
  557. wpas.select_network(id)
  558. wpas.wait_connected()
  559. wpas.p2p_listen()
  560. if "OK" not in dev[0].request("P2P_FLUSH"):
  561. raise Exception("P2P_FLUSH failed")
  562. if not dev[0].discover_peer(addr5):
  563. raise Exception("Could not discover peer")
  564. peer = dev[0].get_peer(addr5)
  565. lfreq4 = peer['listen_freq']
  566. if lfreq4 != lfreq3:
  567. raise Exception("Unexpected Listen channel after configuration")
  568. wpas.p2p_stop_find()
  569. dev[0].p2p_stop_find()
  570. finally:
  571. wpas.request("SET p2p_optimize_listen_chan 0")
  572. def test_p2p_channel_5ghz_only(dev):
  573. """P2P GO start with only 5 GHz band allowed"""
  574. try:
  575. set_country("US", dev[0])
  576. dev[0].request("P2P_SET disallow_freq 2400-2500")
  577. res = autogo(dev[0])
  578. freq = int(res['freq'])
  579. if freq < 5000:
  580. raise Exception("Unexpected channel %d MHz" % freq)
  581. dev[0].remove_group()
  582. finally:
  583. set_country("00")
  584. dev[0].request("P2P_SET disallow_freq ")
  585. def test_p2p_channel_5ghz_165_169_us(dev):
  586. """P2P GO and 5 GHz channels 165 (allowed) and 169 (disallowed) in US"""
  587. try:
  588. set_country("US", dev[0])
  589. res = dev[0].p2p_start_go(freq=5825)
  590. if res['freq'] != "5825":
  591. raise Exception("Unexpected frequency: " + res['freq'])
  592. dev[0].remove_group()
  593. res = dev[0].global_request("P2P_GROUP_ADD freq=5845")
  594. if "FAIL" not in res:
  595. raise Exception("GO on channel 169 allowed unexpectedly")
  596. finally:
  597. set_country("00")
  598. def test_p2p_go_move_reg_change(dev, apdev, params):
  599. """P2P GO move due to regulatory change [long]"""
  600. if not params['long']:
  601. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  602. try:
  603. set_country("US")
  604. dev[0].global_request("P2P_SET disallow_freq 2400-5000")
  605. res = autogo(dev[0])
  606. freq1 = int(res['freq'])
  607. if freq1 < 5000:
  608. raise Exception("Unexpected channel %d MHz" % freq1)
  609. dev[0].global_request("P2P_SET disallow_freq ")
  610. # GO move is not allowed while waiting for initial client connection
  611. time.sleep(20)
  612. set_country("00")
  613. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  614. "AP-CSA-FINISHED"],
  615. timeout=10)
  616. if ev is None:
  617. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  618. freq2 = dev[0].get_group_status_field('freq')
  619. if freq1 == freq2:
  620. raise Exception("Unexpected freq after group reform=" + freq2)
  621. dev[0].remove_group()
  622. finally:
  623. dev[0].global_request("P2P_SET disallow_freq ")
  624. set_country("00")
  625. def test_p2p_go_move_active(dev, apdev, params):
  626. """P2P GO stays in freq although SCM is possible [long]"""
  627. if dev[0].get_mcc() <= 1:
  628. raise HwsimSkip("Skip due to MCC not being enabled")
  629. if not params['long']:
  630. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  631. dev[0].request("SET p2p_no_group_iface 0")
  632. try:
  633. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  634. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  635. "channel" : '11' })
  636. dev[0].connect("ap-test", key_mgmt="NONE",
  637. scan_freq="2462")
  638. res = autogo(dev[0])
  639. freq = int(res['freq'])
  640. if freq > 2430:
  641. raise Exception("Unexpected channel %d MHz" % freq)
  642. # GO move is not allowed while waiting for initial client connection
  643. time.sleep(20)
  644. dev[0].global_request("P2P_SET disallow_freq ")
  645. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  646. "AP-CSA-FINISHED"],
  647. timeout=10)
  648. if ev is not None:
  649. raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
  650. dev[0].remove_group()
  651. finally:
  652. dev[0].global_request("P2P_SET disallow_freq ")
  653. def test_p2p_go_move_scm(dev, apdev, params):
  654. """P2P GO move due to SCM operation preference [long]"""
  655. if dev[0].get_mcc() <= 1:
  656. raise HwsimSkip("Skip due to MCC not being enabled")
  657. if not params['long']:
  658. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  659. dev[0].request("SET p2p_no_group_iface 0")
  660. try:
  661. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  662. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  663. "channel" : '11' })
  664. dev[0].connect("ap-test", key_mgmt="NONE",
  665. scan_freq="2462")
  666. dev[0].global_request("SET p2p_go_freq_change_policy 0")
  667. res = autogo(dev[0])
  668. freq = int(res['freq'])
  669. if freq > 2430:
  670. raise Exception("Unexpected channel %d MHz" % freq)
  671. # GO move is not allowed while waiting for initial client connection
  672. time.sleep(20)
  673. dev[0].global_request("P2P_SET disallow_freq ")
  674. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  675. "AP-CSA-FINISHED"], timeout=3)
  676. if ev is None:
  677. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  678. freq = dev[0].get_group_status_field('freq')
  679. if freq != '2462':
  680. raise Exception("Unexpected freq after group reform=" + freq)
  681. dev[0].remove_group()
  682. finally:
  683. dev[0].global_request("P2P_SET disallow_freq ")
  684. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  685. def test_p2p_go_move_scm_peer_supports(dev, apdev, params):
  686. """P2P GO move due to SCM operation preference (peer supports) [long]"""
  687. if dev[0].get_mcc() <= 1:
  688. raise HwsimSkip("Skip due to MCC not being enabled")
  689. if not params['long']:
  690. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  691. try:
  692. dev[0].global_request("SET p2p_go_freq_change_policy 1")
  693. set_country("US", dev[0])
  694. dev[0].request("SET p2p_no_group_iface 0")
  695. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  696. r_dev=dev[1], r_intent=0,
  697. test_data=False)
  698. check_grpform_results(i_res, r_res)
  699. freq = int(i_res['freq'])
  700. if freq < 5000:
  701. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  702. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  703. "channel" : '11' })
  704. logger.info('Connecting client to to an AP on channel 11');
  705. dev[0].connect("ap-test", key_mgmt="NONE",
  706. scan_freq="2462")
  707. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  708. "AP-CSA-FINISHED"], timeout=3)
  709. if ev is None:
  710. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  711. freq = dev[0].get_group_status_field('freq')
  712. if freq != '2462':
  713. raise Exception("Unexpected freq after group reform=" + freq)
  714. dev[0].remove_group()
  715. finally:
  716. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  717. set_country("00")
  718. def test_p2p_go_move_scm_peer_does_not_support(dev, apdev, params):
  719. """No P2P GO move due to SCM operation (peer does not supports) [long]"""
  720. if dev[0].get_mcc() <= 1:
  721. raise HwsimSkip("Skip due to MCC not being enabled")
  722. if not params['long']:
  723. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  724. try:
  725. dev[0].global_request("SET p2p_go_freq_change_policy 1")
  726. set_country("US", dev[0])
  727. dev[0].request("SET p2p_no_group_iface 0")
  728. if "OK" not in dev[1].request("DRIVER_EVENT AVOID_FREQUENCIES 2400-2500"):
  729. raise Exception("Could not simulate driver event")
  730. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  731. r_dev=dev[1], r_intent=0,
  732. test_data=False)
  733. check_grpform_results(i_res, r_res)
  734. freq = int(i_res['freq'])
  735. if freq < 5000:
  736. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  737. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test',
  738. "channel" : '11' })
  739. logger.info('Connecting client to to an AP on channel 11');
  740. dev[0].connect("ap-test", key_mgmt="NONE",
  741. scan_freq="2462")
  742. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  743. "AP-CSA-FINISHED"],
  744. timeout=10)
  745. if ev is not None:
  746. raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
  747. dev[0].remove_group()
  748. finally:
  749. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  750. set_country("00")
  751. def test_p2p_go_move_scm_multi(dev, apdev, params):
  752. """P2P GO move due to SCM operation preference multiple times [long]"""
  753. if dev[0].get_mcc() <= 1:
  754. raise HwsimSkip("Skip due to MCC not being enabled")
  755. if not params['long']:
  756. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  757. dev[0].request("SET p2p_no_group_iface 0")
  758. try:
  759. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  760. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test-1',
  761. "channel" : '11' })
  762. dev[0].connect("ap-test-1", key_mgmt="NONE",
  763. scan_freq="2462")
  764. dev[0].global_request("SET p2p_go_freq_change_policy 0")
  765. res = autogo(dev[0])
  766. freq = int(res['freq'])
  767. if freq > 2430:
  768. raise Exception("Unexpected channel %d MHz" % freq)
  769. # GO move is not allowed while waiting for initial client connection
  770. time.sleep(20)
  771. dev[0].global_request("P2P_SET disallow_freq ")
  772. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  773. "AP-CSA-FINISHED"], timeout=3)
  774. if ev is None:
  775. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  776. freq = dev[0].get_group_status_field('freq')
  777. if freq != '2462':
  778. raise Exception("Unexpected freq after group reform=" + freq)
  779. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid" : 'ap-test-2',
  780. "channel" : '6' })
  781. dev[0].connect("ap-test-2", key_mgmt="NONE",
  782. scan_freq="2437")
  783. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  784. "AP-CSA-FINISHED"], timeout=5)
  785. if ev is None:
  786. raise Exception("(2) P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  787. freq = dev[0].get_group_status_field('freq')
  788. if freq != '2437':
  789. raise Exception("(2) Unexpected freq after group reform=" + freq)
  790. dev[0].remove_group()
  791. finally:
  792. dev[0].global_request("P2P_SET disallow_freq ")
  793. dev[0].global_request("SET p2p_go_freq_change_policy 2")