test_p2p_channel.py 47 KB

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