test_p2p_channel.py 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  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], { "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],
  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], { "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],
  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],
  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],
  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], { "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], { "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], 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 wait_go_down_up(dev):
  597. ev = dev.wait_group_event(["AP-DISABLED"], timeout=5)
  598. if ev is None:
  599. raise Exception("AP-DISABLED not seen after P2P-REMOVE-AND-REFORM-GROUP")
  600. ev = dev.wait_group_event(["AP-ENABLED"], timeout=5)
  601. if ev is None:
  602. raise Exception("AP-ENABLED not seen after P2P-REMOVE-AND-REFORM-GROUP")
  603. def test_p2p_go_move_reg_change(dev, apdev):
  604. """P2P GO move due to regulatory change"""
  605. try:
  606. set_country("US")
  607. dev[0].global_request("P2P_SET disallow_freq 2400-5000")
  608. res = autogo(dev[0])
  609. freq1 = int(res['freq'])
  610. if freq1 < 5000:
  611. raise Exception("Unexpected channel %d MHz" % freq1)
  612. dev[0].global_request("P2P_SET disallow_freq ")
  613. # GO move is not allowed while waiting for initial client connection
  614. connect_cli(dev[0], dev[1], freq=freq1)
  615. dev[1].remove_group()
  616. freq = dev[0].get_group_status_field('freq')
  617. if int(freq) < 5000:
  618. raise Exception("Unexpected freq after initial client: " + freq)
  619. dev[0].dump_monitor()
  620. set_country("00")
  621. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  622. "AP-CSA-FINISHED"],
  623. timeout=10)
  624. if ev is None:
  625. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  626. if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
  627. wait_go_down_up(dev[0])
  628. freq2 = dev[0].get_group_status_field('freq')
  629. if freq1 == freq2:
  630. raise Exception("Unexpected freq after group reform=" + freq2)
  631. dev[0].remove_group()
  632. finally:
  633. dev[0].global_request("P2P_SET disallow_freq ")
  634. set_country("00")
  635. def test_p2p_go_move_active(dev, apdev):
  636. """P2P GO stays in freq although SCM is possible"""
  637. with HWSimRadio(n_channels=2) as (radio, iface):
  638. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  639. wpas.interface_add(iface)
  640. if wpas.get_mcc() < 2:
  641. raise Exception("New radio does not support MCC")
  642. ndev = [ wpas, dev[1] ]
  643. _test_p2p_go_move_active(ndev, apdev)
  644. def _test_p2p_go_move_active(dev, apdev):
  645. dev[0].request("SET p2p_no_group_iface 0")
  646. try:
  647. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  648. hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test',
  649. "channel" : '11' })
  650. dev[0].connect("ap-test", key_mgmt="NONE",
  651. scan_freq="2462")
  652. res = autogo(dev[0])
  653. freq = int(res['freq'])
  654. if freq > 2430:
  655. raise Exception("Unexpected channel %d MHz" % freq)
  656. # GO move is not allowed while waiting for initial client connection
  657. connect_cli(dev[0], dev[1], freq=freq)
  658. dev[1].remove_group()
  659. freq = dev[0].get_group_status_field('freq')
  660. if int(freq) > 2430:
  661. raise Exception("Unexpected freq after initial client: " + freq)
  662. dev[0].dump_monitor()
  663. dev[0].global_request("P2P_SET disallow_freq ")
  664. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  665. "AP-CSA-FINISHED"],
  666. timeout=10)
  667. if ev is not None:
  668. raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
  669. dev[0].remove_group()
  670. finally:
  671. dev[0].global_request("P2P_SET disallow_freq ")
  672. def test_p2p_go_move_scm(dev, apdev):
  673. """P2P GO move due to SCM operation preference"""
  674. with HWSimRadio(n_channels=2) as (radio, iface):
  675. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  676. wpas.interface_add(iface)
  677. if wpas.get_mcc() < 2:
  678. raise Exception("New radio does not support MCC")
  679. ndev = [ wpas, dev[1] ]
  680. _test_p2p_go_move_scm(ndev, apdev)
  681. def _test_p2p_go_move_scm(dev, apdev):
  682. dev[0].request("SET p2p_no_group_iface 0")
  683. try:
  684. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  685. hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test',
  686. "channel" : '11' })
  687. dev[0].connect("ap-test", key_mgmt="NONE",
  688. scan_freq="2462")
  689. dev[0].global_request("SET p2p_go_freq_change_policy 0")
  690. res = autogo(dev[0])
  691. freq = int(res['freq'])
  692. if freq > 2430:
  693. raise Exception("Unexpected channel %d MHz" % freq)
  694. # GO move is not allowed while waiting for initial client connection
  695. connect_cli(dev[0], dev[1], freq=freq)
  696. dev[1].remove_group()
  697. freq = dev[0].get_group_status_field('freq')
  698. if int(freq) > 2430:
  699. raise Exception("Unexpected freq after initial client: " + freq)
  700. dev[0].dump_monitor()
  701. dev[0].global_request("P2P_SET disallow_freq ")
  702. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  703. "AP-CSA-FINISHED"], timeout=3)
  704. if ev is None:
  705. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  706. if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
  707. wait_go_down_up(dev[0])
  708. freq = dev[0].get_group_status_field('freq')
  709. if freq != '2462':
  710. raise Exception("Unexpected freq after group reform=" + freq)
  711. dev[0].remove_group()
  712. finally:
  713. dev[0].global_request("P2P_SET disallow_freq ")
  714. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  715. def test_p2p_go_move_scm_peer_supports(dev, apdev):
  716. """P2P GO move due to SCM operation preference (peer supports)"""
  717. with HWSimRadio(n_channels=2) as (radio, iface):
  718. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  719. wpas.interface_add(iface)
  720. if wpas.get_mcc() < 2:
  721. raise Exception("New radio does not support MCC")
  722. ndev = [ wpas, dev[1] ]
  723. _test_p2p_go_move_scm_peer_supports(ndev, apdev)
  724. def _test_p2p_go_move_scm_peer_supports(dev, apdev):
  725. try:
  726. dev[0].global_request("SET p2p_go_freq_change_policy 1")
  727. set_country("US", dev[0])
  728. dev[0].request("SET p2p_no_group_iface 0")
  729. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  730. r_dev=dev[1], r_intent=0,
  731. test_data=False)
  732. check_grpform_results(i_res, r_res)
  733. freq = int(i_res['freq'])
  734. if freq < 5000:
  735. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  736. hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test',
  737. "channel" : '11' })
  738. logger.info('Connecting client to to an AP on channel 11');
  739. dev[0].connect("ap-test", key_mgmt="NONE",
  740. scan_freq="2462")
  741. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  742. "AP-CSA-FINISHED"], timeout=3)
  743. if ev is None:
  744. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  745. if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
  746. wait_go_down_up(dev[0])
  747. freq = dev[0].get_group_status_field('freq')
  748. if freq != '2462':
  749. raise Exception("Unexpected freq after group reform=" + freq)
  750. dev[0].remove_group()
  751. finally:
  752. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  753. set_country("00")
  754. def test_p2p_go_move_scm_peer_does_not_support(dev, apdev):
  755. """No P2P GO move due to SCM operation (peer does not supports)"""
  756. with HWSimRadio(n_channels=2) as (radio, iface):
  757. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  758. wpas.interface_add(iface)
  759. if wpas.get_mcc() < 2:
  760. raise Exception("New radio does not support MCC")
  761. ndev = [ wpas, dev[1] ]
  762. _test_p2p_go_move_scm_peer_does_not_support(ndev, apdev)
  763. def _test_p2p_go_move_scm_peer_does_not_support(dev, apdev):
  764. try:
  765. dev[0].global_request("SET p2p_go_freq_change_policy 1")
  766. set_country("US", dev[0])
  767. dev[0].request("SET p2p_no_group_iface 0")
  768. if "OK" not in dev[1].request("DRIVER_EVENT AVOID_FREQUENCIES 2400-2500"):
  769. raise Exception("Could not simulate driver event")
  770. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  771. r_dev=dev[1], r_intent=0,
  772. test_data=False)
  773. check_grpform_results(i_res, r_res)
  774. freq = int(i_res['freq'])
  775. if freq < 5000:
  776. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  777. hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test',
  778. "channel" : '11' })
  779. logger.info('Connecting client to to an AP on channel 11');
  780. dev[0].connect("ap-test", key_mgmt="NONE",
  781. scan_freq="2462")
  782. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  783. "AP-CSA-FINISHED"],
  784. timeout=10)
  785. if ev is not None:
  786. raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
  787. dev[0].remove_group()
  788. finally:
  789. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  790. dev[1].request("DRIVER_EVENT AVOID_FREQUENCIES")
  791. set_country("00")
  792. def test_p2p_go_move_scm_multi(dev, apdev):
  793. """P2P GO move due to SCM operation preference multiple times"""
  794. with HWSimRadio(n_channels=2) as (radio, iface):
  795. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  796. wpas.interface_add(iface)
  797. if wpas.get_mcc() < 2:
  798. raise Exception("New radio does not support MCC")
  799. ndev = [ wpas, dev[1] ]
  800. _test_p2p_go_move_scm_multi(ndev, apdev)
  801. def _test_p2p_go_move_scm_multi(dev, apdev):
  802. dev[0].request("SET p2p_no_group_iface 0")
  803. try:
  804. dev[0].global_request("P2P_SET disallow_freq 2430-6000")
  805. hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test-1',
  806. "channel" : '11' })
  807. dev[0].connect("ap-test-1", key_mgmt="NONE",
  808. scan_freq="2462")
  809. dev[0].global_request("SET p2p_go_freq_change_policy 0")
  810. res = autogo(dev[0])
  811. freq = int(res['freq'])
  812. if freq > 2430:
  813. raise Exception("Unexpected channel %d MHz" % freq)
  814. # GO move is not allowed while waiting for initial client connection
  815. connect_cli(dev[0], dev[1], freq=freq)
  816. dev[1].remove_group()
  817. freq = dev[0].get_group_status_field('freq')
  818. if int(freq) > 2430:
  819. raise Exception("Unexpected freq after initial client: " + freq)
  820. dev[0].dump_monitor()
  821. dev[0].global_request("P2P_SET disallow_freq ")
  822. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  823. "AP-CSA-FINISHED"], timeout=3)
  824. if ev is None:
  825. raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  826. if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
  827. wait_go_down_up(dev[0])
  828. freq = dev[0].get_group_status_field('freq')
  829. if freq != '2462':
  830. raise Exception("Unexpected freq after group reform=" + freq)
  831. hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test-2',
  832. "channel" : '6' })
  833. dev[0].connect("ap-test-2", key_mgmt="NONE",
  834. scan_freq="2437")
  835. ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  836. "AP-CSA-FINISHED"], timeout=5)
  837. if ev is None:
  838. raise Exception("(2) P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
  839. if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
  840. wait_go_down_up(dev[0])
  841. freq = dev[0].get_group_status_field('freq')
  842. if freq != '2437':
  843. raise Exception("(2) Unexpected freq after group reform=" + freq)
  844. dev[0].remove_group()
  845. finally:
  846. dev[0].global_request("P2P_SET disallow_freq ")
  847. dev[0].global_request("SET p2p_go_freq_change_policy 2")
  848. def test_p2p_delay_go_csa(dev, apdev, params):
  849. """P2P GO CSA delayed when inviting a P2P Device to an active P2P Group"""
  850. with HWSimRadio(n_channels=2) as (radio, iface):
  851. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  852. wpas.interface_add(iface)
  853. wpas.global_request("SET p2p_no_group_iface 0")
  854. if wpas.get_mcc() < 2:
  855. raise Exception("New radio does not support MCC")
  856. addr0 = wpas.p2p_dev_addr()
  857. addr1 = dev[1].p2p_dev_addr()
  858. try:
  859. dev[1].p2p_listen();
  860. if not wpas.discover_peer(addr1, social=True):
  861. raise Exception("Peer " + addr1 + " not found")
  862. wpas.p2p_stop_find()
  863. hapd = hostapd.add_ap(apdev[0], { "ssid": 'bss-2.4ghz',
  864. "channel": '1' })
  865. wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
  866. wpas.global_request("SET p2p_go_freq_change_policy 0")
  867. wpas.dump_monitor()
  868. logger.info("Start GO on channel 6")
  869. res = autogo(wpas, freq=2437)
  870. if res['freq'] != "2437":
  871. raise Exception("GO set on a freq=%s instead of 2437" % res['freq'])
  872. # Start find on dev[1] to run scans with dev[2] in parallel
  873. dev[1].p2p_find(social=True)
  874. # Use another client device to stop the initial client connection
  875. # timeout on the GO
  876. if not dev[2].discover_peer(addr0, social=True):
  877. raise Exception("Peer2 did not find the GO")
  878. dev[2].p2p_stop_find()
  879. pin = dev[2].wps_read_pin()
  880. wpas.p2p_go_authorize_client(pin)
  881. dev[2].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=2437")
  882. ev = dev[2].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  883. if ev is None:
  884. raise Exception("Peer2 did not get connected")
  885. if not dev[1].discover_peer(addr0, social=True):
  886. raise Exception("Peer did not find the GO")
  887. pin = dev[1].wps_read_pin()
  888. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth")
  889. dev[1].p2p_listen();
  890. # Force P2P GO channel switch on successful invitation signaling
  891. wpas.group_request("SET p2p_go_csa_on_inv 1")
  892. logger.info("Starting invitation")
  893. wpas.p2p_go_authorize_client(pin)
  894. wpas.global_request("P2P_INVITE group=" + wpas.group_ifname + " peer=" + addr1)
  895. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED",
  896. "P2P-GROUP-STARTED"], timeout=10)
  897. if ev is None:
  898. raise Exception("Timeout on invitation on peer")
  899. if "P2P-INVITATION-RECEIVED" in ev:
  900. raise Exception("Unexpected request to accept pre-authorized invitation")
  901. # A P2P GO move is not expected at this stage, as during the
  902. # invitation signaling, the P2P GO includes only its current
  903. # operating channel in the channel list, and as the invitation
  904. # response can only include channels that were also in the
  905. # invitation request channel list, the group common channels
  906. # includes only the current P2P GO operating channel.
  907. ev = wpas.wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
  908. "AP-CSA-FINISHED"], timeout=1)
  909. if ev is not None:
  910. raise Exception("Unexpected + " + ev + " event")
  911. finally:
  912. wpas.global_request("SET p2p_go_freq_change_policy 2")
  913. def test_p2p_channel_vht80p80(dev):
  914. """P2P group formation and VHT 80+80 MHz channel"""
  915. try:
  916. set_country("US", dev[0])
  917. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  918. i_freq=5180,
  919. i_freq2=5775,
  920. i_max_oper_chwidth=160,
  921. i_ht40=True, i_vht=True,
  922. r_dev=dev[1], r_intent=0,
  923. test_data=False)
  924. check_grpform_results(i_res, r_res)
  925. freq = int(i_res['freq'])
  926. if freq < 5000:
  927. raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
  928. sig = dev[1].group_request("SIGNAL_POLL").splitlines()
  929. if "FREQUENCY=5180" not in sig:
  930. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  931. if "WIDTH=80+80 MHz" not in sig:
  932. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  933. if "CENTER_FRQ1=5210" not in sig:
  934. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  935. if "CENTER_FRQ2=5775" not in sig:
  936. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  937. remove_group(dev[0], dev[1])
  938. finally:
  939. set_country("00")
  940. dev[1].flush_scan_cache()
  941. def test_p2p_channel_vht80p80_autogo(dev):
  942. """P2P autonomous GO and VHT 80+80 MHz channel"""
  943. addr0 = dev[0].p2p_dev_addr()
  944. try:
  945. set_country("US", dev[0])
  946. if "OK" not in dev[0].global_request("P2P_GROUP_ADD vht freq=5180 freq2=5775"):
  947. raise Exception("Could not start GO")
  948. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
  949. if ev is None:
  950. raise Exception("GO start up timed out")
  951. dev[0].group_form_result(ev)
  952. pin = dev[1].wps_read_pin()
  953. dev[0].p2p_go_authorize_client(pin)
  954. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=5180")
  955. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  956. if ev is None:
  957. raise Exception("Peer did not get connected")
  958. sig = dev[1].group_request("SIGNAL_POLL").splitlines()
  959. if "FREQUENCY=5180" not in sig:
  960. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  961. if "WIDTH=80+80 MHz" not in sig:
  962. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  963. if "CENTER_FRQ1=5210" not in sig:
  964. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  965. if "CENTER_FRQ2=5775" not in sig:
  966. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  967. remove_group(dev[0], dev[1])
  968. finally:
  969. set_country("00")
  970. dev[1].flush_scan_cache()
  971. def test_p2p_channel_vht80_autogo(dev):
  972. """P2P autonomous GO and VHT 80 MHz channel"""
  973. addr0 = dev[0].p2p_dev_addr()
  974. try:
  975. set_country("US", dev[0])
  976. if "OK" not in dev[0].global_request("P2P_GROUP_ADD vht freq=5180 max_oper_chwidth=80"):
  977. raise Exception("Could not start GO")
  978. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
  979. if ev is None:
  980. raise Exception("GO start up timed out")
  981. dev[0].group_form_result(ev)
  982. pin = dev[1].wps_read_pin()
  983. dev[0].p2p_go_authorize_client(pin)
  984. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=5180")
  985. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  986. if ev is None:
  987. raise Exception("Peer did not get connected")
  988. sig = dev[1].group_request("SIGNAL_POLL").splitlines()
  989. if "FREQUENCY=5180" not in sig:
  990. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  991. if "WIDTH=80 MHz" not in sig:
  992. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  993. remove_group(dev[0], dev[1])
  994. finally:
  995. set_country("00")
  996. dev[1].flush_scan_cache()
  997. def test_p2p_channel_vht80p80_persistent(dev):
  998. """P2P persistent group re-invocation and VHT 80+80 MHz channel"""
  999. addr0 = dev[0].p2p_dev_addr()
  1000. form(dev[0], dev[1])
  1001. try:
  1002. set_country("US", dev[0])
  1003. invite(dev[0], dev[1], extra="vht freq=5745 freq2=5210")
  1004. [go_res, cli_res] = check_result(dev[0], dev[1])
  1005. sig = dev[1].group_request("SIGNAL_POLL").splitlines()
  1006. if "FREQUENCY=5745" not in sig:
  1007. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  1008. if "WIDTH=80+80 MHz" not in sig:
  1009. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  1010. if "CENTER_FRQ1=5775" not in sig:
  1011. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  1012. if "CENTER_FRQ2=5210" not in sig:
  1013. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  1014. remove_group(dev[0], dev[1])
  1015. finally:
  1016. set_country("00")
  1017. dev[1].flush_scan_cache()