test_p2p_channel.py 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  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("SE", 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()
  1051. def test_p2p_channel_drv_pref_go_neg(dev):
  1052. """P2P GO Negotiation with GO device channel preference"""
  1053. dev[0].global_request("SET get_pref_freq_list_override 3:2417 4:2422")
  1054. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  1055. r_dev=dev[1], r_intent=0,
  1056. test_data=False)
  1057. check_grpform_results(i_res, r_res)
  1058. freq = int(i_res['freq'])
  1059. if freq != 2417:
  1060. raise Exception("Unexpected channel selected: %d" % freq)
  1061. remove_group(dev[0], dev[1])
  1062. def test_p2p_channel_drv_pref_go_neg2(dev):
  1063. """P2P GO Negotiation with P2P client device channel preference"""
  1064. dev[0].global_request("SET get_pref_freq_list_override 3:2417,2422")
  1065. dev[1].global_request("SET get_pref_freq_list_override 4:2422")
  1066. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  1067. r_dev=dev[1], r_intent=0,
  1068. test_data=False)
  1069. check_grpform_results(i_res, r_res)
  1070. freq = int(i_res['freq'])
  1071. if freq != 2422:
  1072. raise Exception("Unexpected channel selected: %d" % freq)
  1073. remove_group(dev[0], dev[1])
  1074. def test_p2p_channel_drv_pref_go_neg3(dev):
  1075. """P2P GO Negotiation with GO device channel preference"""
  1076. dev[1].global_request("SET get_pref_freq_list_override 3:2417,2427 4:2422")
  1077. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  1078. r_dev=dev[1], r_intent=15,
  1079. test_data=False)
  1080. check_grpform_results(i_res, r_res)
  1081. freq = int(i_res['freq'])
  1082. if freq != 2417:
  1083. raise Exception("Unexpected channel selected: %d" % freq)
  1084. remove_group(dev[0], dev[1])
  1085. def test_p2p_channel_drv_pref_go_neg4(dev):
  1086. """P2P GO Negotiation with P2P client device channel preference"""
  1087. dev[0].global_request("SET get_pref_freq_list_override 3:2417,2422,5180")
  1088. dev[1].global_request("P2P_SET override_pref_op_chan 115:36")
  1089. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  1090. r_dev=dev[1], r_intent=0,
  1091. test_data=False)
  1092. check_grpform_results(i_res, r_res)
  1093. freq = int(i_res['freq'])
  1094. if freq != 2417:
  1095. raise Exception("Unexpected channel selected: %d" % freq)
  1096. remove_group(dev[0], dev[1])
  1097. def test_p2p_channel_drv_pref_go_neg5(dev):
  1098. """P2P GO Negotiation with P2P client device channel preference"""
  1099. dev[0].global_request("SET get_pref_freq_list_override 3:2417")
  1100. dev[1].global_request("SET get_pref_freq_list_override 4:2422")
  1101. dev[1].global_request("P2P_SET override_pref_op_chan 115:36")
  1102. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  1103. r_dev=dev[1], r_intent=0,
  1104. test_data=False)
  1105. check_grpform_results(i_res, r_res)
  1106. freq = int(i_res['freq'])
  1107. if freq != 2417:
  1108. raise Exception("Unexpected channel selected: %d" % freq)
  1109. remove_group(dev[0], dev[1])
  1110. def test_p2p_channel_drv_pref_autogo(dev):
  1111. """P2P autonomous GO with driver channel preference"""
  1112. dev[0].global_request("SET get_pref_freq_list_override 3:2417,2422,5180")
  1113. res_go = autogo(dev[0])
  1114. if res_go['freq'] != "2417":
  1115. raise Exception("Unexpected operating frequency: " + res_go['freq'])