test_p2ps.py 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475
  1. # P2P services
  2. # Copyright (c) 2014-2015, Qualcomm Atheros, Inc.
  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 time
  9. import random
  10. import re
  11. import hwsim_utils
  12. from wpasupplicant import WpaSupplicant
  13. import hostapd
  14. from p2p_utils import *
  15. from utils import HwsimSkip
  16. from hwsim import HWSimRadio
  17. # Dev[0] -> Advertiser
  18. # Dev[1] -> Seeker
  19. # ev0 -> Event generated at advertiser side
  20. # ev1 -> Event generated at Seeker side
  21. def p2ps_advertise(r_dev, r_role, svc_name, srv_info, rsp_info=None, cpt=None):
  22. """P2PS Advertise function"""
  23. adv_id = random.randrange(1, 0xFFFFFFFF)
  24. advid = hex(adv_id)[2:]
  25. cpt_param = (" cpt=" + cpt) if cpt is not None else ""
  26. if rsp_info is not None and srv_info is not None:
  27. if "OK" not in r_dev.global_request("P2P_SERVICE_ADD asp " + str(r_role) + " " + str(advid) + " 1 1108 " + svc_name + cpt_param + " svc_info='" + srv_info + "'" + " rsp_info=" + rsp_info + "'"):
  28. raise Exception("P2P_SERVICE_ADD with response info and service info failed")
  29. if rsp_info is None and srv_info is not None:
  30. if "OK" not in r_dev.global_request("P2P_SERVICE_ADD asp " + str(r_role) + " " + str(advid) + " 1 1108 " + svc_name + cpt_param + " svc_info='" + srv_info + "'"):
  31. raise Exception("P2P_SERVICE_ADD with service info failed")
  32. if rsp_info is None and srv_info is None:
  33. if "OK" not in r_dev.global_request("P2P_SERVICE_ADD asp " + str(r_role) + " " + str(advid) + " 1 1108 " + svc_name + cpt_param):
  34. raise Exception("P2P_SERVICE_ADD without service info and without response info failed")
  35. if rsp_info is not None and srv_info is None:
  36. if "OK" not in r_dev.global_request("P2P_SERVICE_ADD asp " + str(r_role) + " " + str(adv_id) + " 1 1108 " + svc_name + cpt_param + " svc_info='" + " rsp_info=" + rsp_info + "'"):
  37. raise Exception("P2P_SERVICE_ADD with response info failed")
  38. r_dev.p2p_listen()
  39. return advid
  40. def p2ps_exact_seek(i_dev, r_dev, svc_name, srv_info=None,
  41. single_peer_expected=True):
  42. """P2PS exact service seek request"""
  43. if srv_info is not None:
  44. ev1 = i_dev.global_request("P2P_SERV_DISC_REQ 00:00:00:00:00:00 asp 1 " + svc_name + " '" + srv_info + "'")
  45. if ev1 is None:
  46. raise Exception("Failed to add Service Discovery request for exact seek request")
  47. if "OK" not in i_dev.global_request("P2P_FIND 10 type=social seek=" + svc_name):
  48. raise Exception("Failed to initiate seek operation")
  49. timeout = time.time() + 10
  50. ev1 = i_dev.wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  51. while ev1 is not None and not single_peer_expected:
  52. if r_dev.p2p_dev_addr() in ev1 and "adv_id=" in ev1:
  53. break
  54. ev1 = i_dev.wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  55. if timeout < time.time():
  56. raise Exception("Device not found")
  57. if ev1 is None:
  58. raise Exception("P2P-DEVICE-FOUND timeout on seeker side")
  59. if r_dev.p2p_dev_addr() not in ev1:
  60. raise Exception("Unexpected peer")
  61. if srv_info is None:
  62. adv_id = ev1.split("adv_id=")[1].split(" ")[0]
  63. rcvd_svc_name = ev1.split("asp_svc=")[1].split(" ")[0]
  64. if rcvd_svc_name != svc_name:
  65. raise Exception("service name not matching")
  66. else:
  67. ev1 = i_dev.wait_global_event(["P2P-SERV-ASP-RESP"], timeout=10)
  68. if ev1 is None:
  69. raise Exception("Failed to receive Service Discovery Response")
  70. if r_dev.p2p_dev_addr() not in ev1:
  71. raise Exception("Service Discovery response from Unknown Peer")
  72. if srv_info is not None and srv_info not in ev1:
  73. raise Exception("service info not available in Service Discovery response")
  74. adv_id = ev1.split(" ")[3]
  75. rcvd_svc_name = ev1.split(" ")[6]
  76. if rcvd_svc_name != svc_name:
  77. raise Exception("service name not matching")
  78. i_dev.p2p_stop_find()
  79. return [adv_id, rcvd_svc_name]
  80. def p2ps_nonexact_seek(i_dev, r_dev, svc_name, srv_info=None, adv_num=None):
  81. """P2PS nonexact service seek request"""
  82. if adv_num is None:
  83. adv_num = 1
  84. if srv_info is not None:
  85. ev1 = i_dev.global_request("P2P_SERV_DISC_REQ 00:00:00:00:00:00 asp 1 " + svc_name + " '" + srv_info + "'")
  86. else:
  87. ev1 = i_dev.global_request("P2P_SERV_DISC_REQ 00:00:00:00:00:00 asp 1 " + svc_name + " '")
  88. if ev1 is None:
  89. raise Exception("Failed to add Service Discovery request for nonexact seek request")
  90. if "OK" not in i_dev.global_request("P2P_FIND 10 type=social seek="):
  91. raise Exception("Failed to initiate seek")
  92. ev1 = i_dev.wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  93. if ev1 is None:
  94. raise Exception("P2P-DEVICE-FOUND timeout on seeker side")
  95. if r_dev.p2p_dev_addr() not in ev1:
  96. raise Exception("Unexpected peer")
  97. ev_list = []
  98. for i in range (0, adv_num):
  99. ev1 = i_dev.wait_global_event(["P2P-SERV-ASP-RESP"], timeout=10)
  100. if ev1 is None:
  101. raise Exception("Failed to receive Service Discovery Response")
  102. if r_dev.p2p_dev_addr() not in ev1:
  103. raise Exception("Service Discovery response from Unknown Peer")
  104. if srv_info is not None and srv_info not in ev1:
  105. raise Exception("service info not available in Service Discovery response")
  106. adv_id = ev1.split(" ")[3]
  107. rcvd_svc_name = ev1.split(" ")[6]
  108. ev_list.append(''.join([adv_id, ' ', rcvd_svc_name]))
  109. i_dev.p2p_stop_find()
  110. return ev_list
  111. def p2ps_parse_event(ev, *args):
  112. ret = ()
  113. for arg in args:
  114. m = re.search("\s+" + arg + r"=(\S+)", ev)
  115. ret += (m.group(1) if m is not None else None,)
  116. return ret
  117. def p2ps_provision(seeker, advertiser, adv_id, auto_accept=True, method="1000",
  118. adv_cpt=None, seeker_cpt=None, handler=None, adv_role=None,
  119. seeker_role=None):
  120. addr0 = seeker.p2p_dev_addr()
  121. addr1 = advertiser.p2p_dev_addr()
  122. seeker.asp_provision(addr1, adv_id=str(adv_id), adv_mac=addr1, session_id=1,
  123. session_mac=addr0, method=method, cpt=seeker_cpt,
  124. role=seeker_role)
  125. if not auto_accept or method == "100":
  126. pin = None
  127. ev_pd_start = advertiser.wait_global_event(["P2PS-PROV-START"],
  128. timeout=10)
  129. if ev_pd_start is None:
  130. raise Exception("P2PS-PROV-START timeout on Advertiser side")
  131. peer = ev_pd_start.split()[1]
  132. advert_id, advert_mac, session, session_mac =\
  133. p2ps_parse_event(ev_pd_start, "adv_id", "adv_mac", "session", "mac")
  134. ev = seeker.wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout=10)
  135. if ev is None:
  136. raise Exception("P2P-PROV-DISC-FAILURE timeout on seeker side")
  137. if handler:
  138. handler(seeker, advertiser)
  139. # Put seeker into a listen state, since we expect the deferred flow to
  140. # continue.
  141. seeker.p2p_ext_listen(500, 500)
  142. if method == "100":
  143. ev = advertiser.wait_global_event(["P2P-PROV-DISC-ENTER-PIN"],
  144. timeout=10)
  145. if ev is None:
  146. raise Exception("P2P-PROV-DISC-ENTER-PIN timeout on advertiser side")
  147. if addr0 not in ev:
  148. raise Exception("Unknown peer " + addr0)
  149. ev = seeker.wait_global_event(["P2P-PROV-DISC-SHOW-PIN"],
  150. timeout=10)
  151. if ev is None:
  152. raise Exception("P2P-PROV-DISC-SHOW-PIN timeout on seeker side")
  153. if addr1 not in ev:
  154. raise Exception("Unknown peer " + addr1)
  155. pin = ev.split()[2]
  156. elif method == "8":
  157. ev = advertiser.wait_global_event(["P2P-PROV-DISC-SHOW-PIN"],
  158. timeout=10)
  159. if ev is None:
  160. raise Exception("P2P-PROV-DISC-SHOW-PIN timeout on advertiser side")
  161. if addr0 not in ev:
  162. raise Exception("Unknown peer " + addr0)
  163. pin = ev.split()[2]
  164. # Stop P2P_LISTEN before issuing P2P_ASP_PROVISION_RESP to avoid
  165. # excessive delay and test case timeouts if it takes large number of
  166. # retries to find the peer awake on its Listen channel.
  167. advertiser.p2p_stop_find()
  168. advertiser.asp_provision(peer, adv_id=advert_id, adv_mac=advert_mac,
  169. session_id=int(session, 0),
  170. session_mac=session_mac, status=12,
  171. cpt=adv_cpt, role=adv_role)
  172. ev1 = seeker.wait_global_event(["P2PS-PROV-DONE"], timeout=10)
  173. if ev1 is None:
  174. raise Exception("P2PS-PROV-DONE timeout on seeker side")
  175. ev2 = advertiser.wait_global_event(["P2PS-PROV-DONE"], timeout=10)
  176. if ev2 is None:
  177. raise Exception("P2PS-PROV-DONE timeout on advertiser side")
  178. if method == "8":
  179. ev = seeker.wait_global_event(["P2P-PROV-DISC-ENTER-PIN"],
  180. timeout=10)
  181. if ev is None:
  182. raise Exception("P2P-PROV-DISC-ENTER-PIN failed on seeker side")
  183. if addr1 not in ev:
  184. raise Exception("Unknown peer " + addr1)
  185. seeker.p2p_cancel_ext_listen()
  186. if pin is not None:
  187. return ev1, ev2, pin
  188. return ev1, ev2
  189. # Auto-accept is true and the method is either P2PS or advertiser is DISPLAY
  190. ev1 = seeker.wait_global_event(["P2PS-PROV-DONE"], timeout=10)
  191. if ev1 is None:
  192. raise Exception("P2PS-PROV-DONE timeout on seeker side")
  193. ev2 = advertiser.wait_global_event(["P2PS-PROV-DONE"], timeout=10)
  194. if ev2 is None:
  195. raise Exception("P2PS-PROV-DONE timeout on advertiser side")
  196. if method == "8":
  197. ev = seeker.wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=10)
  198. if ev is None:
  199. raise Exception("P2P-PROV-DISC-ENTER-PIN timeout on seeker side")
  200. if addr1 not in ev:
  201. raise Exception("Unknown peer " + addr1)
  202. ev = advertiser.wait_global_event(["P2P-PROV-DISC-SHOW-PIN"],
  203. timeout=10)
  204. if ev is None:
  205. raise Exception("P2P-PROV-DISC-SHOW-PIN timeout on advertiser side")
  206. if addr0 not in ev:
  207. raise Exception("Unknown peer " + addr0)
  208. pin = ev.split()[2]
  209. return ev1, ev2, pin
  210. return ev1, ev2
  211. def p2ps_connect_pd(dev0, dev1, ev0, ev1, pin=None, join_extra="", go_ev=None):
  212. conf_methods_map = {"8": "p2ps", "1": "display", "5": "keypad"}
  213. peer0 = ev0.split()[1]
  214. peer1 = ev1.split()[1]
  215. status0, conncap0, adv_id0, adv_mac0, mac0, session0, dev_passwd_id0, go0, join0, feature_cap0, persist0, group_ssid0 =\
  216. p2ps_parse_event(ev0, "status", "conncap", "adv_id", "adv_mac", "mac", "session", "dev_passwd_id", "go", "join", "feature_cap", "persist", "group_ssid")
  217. status1, conncap1, adv_id1, adv_mac1, mac1, session1, dev_passwd_id1, go1, join1, feature_cap1, persist1, group_ssid1 =\
  218. p2ps_parse_event(ev1, "status", "conncap", "adv_id", "adv_mac", "mac", "session", "dev_passwd_id", "go", "join", "feature_cap", "persist", "group_ssid")
  219. if status0 != "0" and status0 != "12":
  220. raise Exception("PD failed on " + dev0.p2p_dev_addr())
  221. if status1 != "0" and status1 != "12":
  222. raise Exception("PD failed on " + dev1.p2p_dev_addr())
  223. if status0 == "12" and status1 == "12":
  224. raise Exception("Both sides have status 12 which doesn't make sense")
  225. if adv_id0 != adv_id1 or adv_id0 is None:
  226. raise Exception("Adv. IDs don't match")
  227. if adv_mac0 != adv_mac1 or adv_mac0 is None:
  228. raise Exception("Adv. MACs don't match")
  229. if session0 != session1 or session0 is None:
  230. raise Exception("Session IDs don't match")
  231. if mac0 != mac1 or mac0 is None:
  232. raise Exception("Session MACs don't match")
  233. #TODO: Validate feature capability
  234. if bool(persist0) != bool(persist1):
  235. raise Exception("Only one peer has persistent group")
  236. if persist0 is None and not all([conncap0, conncap1, dev_passwd_id0,
  237. dev_passwd_id1]):
  238. raise Exception("Persistent group not used but conncap/dev_passwd_id are missing")
  239. if persist0 is not None and any([conncap0, conncap1, dev_passwd_id0,
  240. dev_passwd_id1]):
  241. raise Exception("Persistent group is used but conncap/dev_passwd_id are present")
  242. # Persistent Connection (todo: handle frequency)
  243. if persist0 is not None:
  244. dev0.p2p_stop_find()
  245. if "OK" not in dev0.global_request("P2P_GROUP_ADD persistent=" + persist0 + " freq=2412"):
  246. raise Exception("Could not re-start persistent group")
  247. ev0 = dev0.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  248. if ev0 is None:
  249. raise Exception("P2P-GROUP-STARTED timeout on " + dev0.p2p_dev_addr())
  250. dev0.group_form_result(ev0)
  251. if "OK" not in dev1.global_request("P2P_GROUP_ADD persistent=" + persist1 + " freq=2412"):
  252. raise Exception("Could not re-start persistent group")
  253. ev1 = dev1.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  254. if ev1 is None:
  255. raise Exception("P2P-GROUP-STARTED timeout on " + dev1.p2p_dev_addr())
  256. dev1.group_form_result(ev1)
  257. if "GO" in ev0:
  258. ev = dev0.wait_global_event(["AP-STA-CONNECTED"], timeout=10)
  259. if ev is None:
  260. raise Exception("AP-STA-CONNECTED timeout on " + dev0.p2p_dev_addr())
  261. else:
  262. ev = dev1.wait_global_event(["AP-STA-CONNECTED"], timeout=10)
  263. if ev is None:
  264. raise Exception("AP-STA-CONNECTED timeout on " + dev1.p2p_dev_addr())
  265. else:
  266. try:
  267. method0 = conf_methods_map[dev_passwd_id0]
  268. method1 = conf_methods_map[dev_passwd_id1]
  269. except KeyError:
  270. raise Exception("Unsupported method")
  271. if method0 == "p2ps":
  272. pin = "12345670"
  273. if pin is None:
  274. raise Exception("Pin is not provided")
  275. if conncap0 == "1" and conncap1 == "1": # NEW/NEW - GON
  276. if any([join0, join1, go0, go1]):
  277. raise Exception("Unexpected join/go PD attributes")
  278. dev0.p2p_listen()
  279. if "OK" not in dev0.global_request("P2P_CONNECT " + peer0 + " " + pin + " " + method0 + " persistent auth"):
  280. raise Exception("P2P_CONNECT fails on " + dev0.p2p_dev_addr())
  281. if "OK" not in dev1.global_request("P2P_CONNECT " + peer1 + " " + pin + " " + method1 + " persistent"):
  282. raise Exception("P2P_CONNECT fails on " + dev1.p2p_dev_addr())
  283. ev = dev0.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
  284. if ev is None:
  285. raise Exception("GO Neg did not succeed on " + dev0.p2p_dev_addr())
  286. ev = dev1.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
  287. if ev is None:
  288. raise Exception("GO Neg did not succeed on " + dev1.p2p_dev_addr())
  289. ev = dev0.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  290. if ev is None:
  291. raise Exception("P2P-GROUP-STARTED timeout on " + dev0.p2p_dev_addr())
  292. dev0.group_form_result(ev)
  293. ev = dev1.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  294. if ev is None:
  295. raise Exception("P2P-GROUP-STARTED timeout on " + dev1.p2p_dev_addr())
  296. dev1.group_form_result(ev)
  297. else:
  298. if conncap0 == "2" and conncap1 == "4": # dev0 CLI, dev1 GO
  299. dev_cli, dev_go, go_if, join_address, go_method, cli_method, join_ssid = dev0, dev1, go1, join0, method1, method0, group_ssid0
  300. elif conncap0 == "4" and conncap1 == "2": # dev0 GO, dev1 CLI
  301. dev_cli, dev_go, go_if, join_address, go_method, cli_method, join_ssid = dev1, dev0, go0, join1, method0, method1, group_ssid1
  302. else:
  303. raise Exception("Bad connection capabilities")
  304. if go_if is None:
  305. raise Exception("Device " + dev_go.p2p_dev_addr() + " failed to become GO")
  306. if join_address is None:
  307. raise Exception("Device " + dev_cli.p2p_dev_addr() + " failed to become CLI")
  308. if not dev_go.get_group_ifname().startswith('p2p-'):
  309. if go_ev:
  310. ev = go_ev
  311. else:
  312. ev = dev_go.wait_global_event(["P2P-GROUP-STARTED"],
  313. timeout=10)
  314. if ev is None:
  315. raise Exception("P2P-GROUP-STARTED timeout on " + dev_go.p2p_dev_addr())
  316. dev_go.group_form_result(ev)
  317. if go_method != "p2ps":
  318. ev = dev_go.group_request("WPS_PIN any " + pin)
  319. if ev is None:
  320. raise Exception("Failed to initiate pin authorization on registrar side")
  321. if join_ssid:
  322. group_ssid_txt = " ssid=" + join_ssid
  323. else:
  324. group_ssid_txt = ""
  325. if "OK" not in dev_cli.global_request("P2P_CONNECT " + join_address + " " + pin + " " + cli_method + join_extra + " persistent join" + group_ssid_txt):
  326. raise Exception("P2P_CONNECT failed on " + dev_cli.p2p_dev_addr())
  327. ev = dev_cli.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  328. if ev is None:
  329. raise Exception("P2P-GROUP-STARTED timeout on " + dev_cli.p2p_dev_addr())
  330. dev_cli.group_form_result(ev)
  331. ev = dev_go.wait_global_event(["AP-STA-CONNECTED"], timeout=10)
  332. if ev is None:
  333. raise Exception("AP-STA-CONNECTED timeout on " + dev_go.p2p_dev_addr())
  334. hwsim_utils.test_connectivity_p2p(dev0, dev1)
  335. def set_no_group_iface(dev, enable):
  336. if enable:
  337. res = dev.get_driver_status()
  338. if (int(res['capa.flags'], 0) & 0x20000000):
  339. raise HwsimSkip("P2P Device used. Cannot set enable no_group_iface")
  340. dev.global_request("SET p2p_no_group_iface 1")
  341. else:
  342. dev.global_request("SET p2p_no_group_iface 0")
  343. def test_p2ps_exact_search(dev):
  344. """P2PS exact service request"""
  345. p2ps_advertise(r_dev=dev[0], r_role='1', svc_name='org.wi-fi.wfds.send.rx',
  346. srv_info='I can receive files upto size 2 GB')
  347. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  348. svc_name='org.wi-fi.wfds.send.rx')
  349. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  350. if ev0 is None:
  351. raise Exception("Unable to remove the advertisement instance")
  352. def test_p2ps_exact_search_srvinfo(dev):
  353. """P2PS exact service request with service info"""
  354. p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
  355. srv_info='I can receive files upto size 2 GB')
  356. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  357. svc_name='org.wi-fi.wfds.send.rx',
  358. srv_info='2 GB')
  359. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  360. if ev0 is None:
  361. raise Exception("Unable to remove the advertisement instance")
  362. def test_p2ps_nonexact_search(dev):
  363. """P2PS nonexact seek request"""
  364. p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.play.rx',
  365. srv_info='I support Miracast Mode ')
  366. ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
  367. svc_name='org.wi-fi.wfds.play*')
  368. adv_id = ev_list[0].split()[0]
  369. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  370. if ev0 is None:
  371. raise Exception("Unable to remove the advertisement instance")
  372. def test_p2ps_nonexact_search_srvinfo(dev):
  373. """P2PS nonexact seek request with service info"""
  374. p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
  375. srv_info='I can receive files upto size 2 GB')
  376. ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
  377. svc_name='org.wi-fi.wfds.send*',
  378. srv_info='2 GB')
  379. adv_id = ev_list[0].split()[0]
  380. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  381. if ev0 is None:
  382. raise Exception("Unable to remove the advertisement instance")
  383. def test_p2ps_connect_p2ps_method_nonautoaccept(dev):
  384. """P2PS connect for non-auto-accept and P2PS config method"""
  385. p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
  386. srv_info='I can receive files upto size 2 GB')
  387. ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
  388. svc_name='org.wi-fi.wfds.send*',
  389. srv_info='2 GB')
  390. adv_id = ev_list[0].split()[0]
  391. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False)
  392. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  393. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  394. if ev0 is None:
  395. raise Exception("Unable to remove the advertisement instance")
  396. remove_group(dev[0], dev[1])
  397. def test_p2ps_connect_p2ps_method_autoaccept(dev):
  398. """P2PS connection with P2PS default config method and auto-accept"""
  399. p2ps_advertise(r_dev=dev[0], r_role='1', svc_name='org.wi-fi.wfds.send.rx',
  400. srv_info='I can receive files upto size 2 GB')
  401. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  402. svc_name='org.wi-fi.wfds.send.rx',
  403. srv_info='2 GB')
  404. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  405. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  406. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  407. if ev0 is None:
  408. raise Exception("Unable to remove the advertisement instance")
  409. remove_group(dev[0], dev[1])
  410. def test_p2ps_connect_keypad_method_nonautoaccept(dev):
  411. """P2PS Connection with non-auto-accept and seeker having keypad method"""
  412. p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
  413. srv_info='I can receive files upto size 2 GB')
  414. ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
  415. svc_name='org.wi-fi.wfds.send*',
  416. srv_info='2 GB')
  417. adv_id = ev_list[0].split()[0]
  418. ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False, method="8")
  419. p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
  420. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  421. if ev0 is None:
  422. raise Exception("Unable to remove the advertisement instance")
  423. remove_group(dev[0], dev[1])
  424. def test_p2ps_connect_display_method_nonautoaccept(dev):
  425. """P2PS connection with non-auto-accept and seeker having display method"""
  426. p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
  427. srv_info='I can receive files upto size 2 GB')
  428. ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
  429. svc_name='org.wi-fi.wfds*', srv_info='2 GB')
  430. adv_id = ev_list[0].split()[0]
  431. ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False, method="100")
  432. p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
  433. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  434. if ev0 is None:
  435. raise Exception("Unable to remove the advertisement instance")
  436. remove_group(dev[0], dev[1])
  437. def test_p2ps_connect_keypad_method_autoaccept(dev):
  438. """P2PS connection with auto-accept and keypad method on seeker side"""
  439. p2ps_advertise(r_dev=dev[0], r_role='1', svc_name='org.wi-fi.wfds.send.rx',
  440. srv_info='I can receive files upto size 2 GB')
  441. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  442. svc_name='org.wi-fi.wfds.send.rx',
  443. srv_info='2 GB')
  444. ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, method="8")
  445. p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
  446. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  447. if ev0 is None:
  448. raise Exception("Unable to remove the advertisement instance")
  449. remove_group(dev[0], dev[1])
  450. def test_p2ps_connect_display_method_autoaccept(dev):
  451. """P2PS connection with auto-accept and display method on seeker side"""
  452. p2ps_advertise(r_dev=dev[0], r_role='1', svc_name='org.wi-fi.wfds.send.rx',
  453. srv_info='I can receive files upto size 2 GB')
  454. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  455. svc_name='org.wi-fi.wfds.send.rx',
  456. srv_info='2 GB')
  457. ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, method="100")
  458. p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
  459. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  460. if ev0 is None:
  461. raise Exception("Unable to remove the advertisement instance")
  462. remove_group(dev[0], dev[1])
  463. def test_p2ps_connect_adv_go_p2ps_method(dev):
  464. """P2PS auto-accept connection with advertisement as GO and P2PS method"""
  465. p2ps_advertise(r_dev=dev[0], r_role='4', svc_name='org.wi-fi.wfds.send.rx',
  466. srv_info='I can receive files upto size 2 GB')
  467. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  468. svc_name='org.wi-fi.wfds.send.rx',
  469. srv_info='2 GB')
  470. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  471. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  472. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  473. if ev0 is None:
  474. raise Exception("Unable to remove the advertisement instance")
  475. remove_group(dev[0], dev[1])
  476. def test_p2ps_connect_adv_go_p2ps_method_group_iface(dev):
  477. """P2PS auto-accept connection with advertisement as GO and P2PS method using separate group interface"""
  478. set_no_group_iface(dev[0], 0)
  479. set_no_group_iface(dev[1], 0)
  480. p2ps_advertise(r_dev=dev[0], r_role='4', svc_name='org.wi-fi.wfds.send.rx',
  481. srv_info='I can receive files upto size 2 GB')
  482. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  483. svc_name='org.wi-fi.wfds.send.rx',
  484. srv_info='2 GB')
  485. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  486. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  487. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  488. if ev0 is None:
  489. raise Exception("Unable to remove the advertisement instance")
  490. remove_group(dev[0], dev[1])
  491. def test_p2ps_connect_adv_client_p2ps_method(dev):
  492. """P2PS auto-accept connection with advertisement as Client and P2PS method"""
  493. p2ps_advertise(r_dev=dev[0], r_role='2', svc_name='org.wi-fi.wfds.send.rx',
  494. srv_info='I can receive files upto size 2 GB')
  495. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  496. svc_name='org.wi-fi.wfds.send.rx',
  497. srv_info='2 GB')
  498. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  499. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  500. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  501. if ev0 is None:
  502. raise Exception("Unable to remove the advertisement instance")
  503. remove_group(dev[0], dev[1])
  504. def p2ps_connect_adv_go_pin_method(dev, keep_group=False):
  505. p2ps_advertise(r_dev=dev[0], r_role='4', svc_name='org.wi-fi.wfds.send.rx',
  506. srv_info='I can receive files upto size 2 GB')
  507. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  508. svc_name='org.wi-fi.wfds.send.rx',
  509. srv_info='2 GB')
  510. ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, method="8")
  511. p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
  512. if not keep_group:
  513. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  514. if ev0 is None:
  515. raise Exception("Unable to remove the advertisement instance")
  516. remove_group(dev[0], dev[1])
  517. def test_p2ps_connect_adv_go_pin_method(dev):
  518. """P2PS advertiser as GO with keypad config method on seeker side and auto-accept"""
  519. p2ps_connect_adv_go_pin_method(dev)
  520. def test_p2ps_connect_adv_client_pin_method(dev):
  521. """P2PS advertiser as client with keypad config method on seeker side and auto-accept"""
  522. dev[0].flush_scan_cache()
  523. p2ps_advertise(r_dev=dev[0], r_role='2', svc_name='org.wi-fi.wfds.send.rx',
  524. srv_info='I can receive files upto size 2 GB')
  525. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  526. svc_name='org.wi-fi.wfds.send.rx',
  527. srv_info='2 GB')
  528. ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, method="8")
  529. p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
  530. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  531. if ev0 is None:
  532. raise Exception("Unable to remove the advertisement instance")
  533. remove_group(dev[0], dev[1])
  534. def test_p2ps_service_discovery_multiple_queries(dev):
  535. """P2P service discovery with multiple queries"""
  536. addr0 = dev[0].p2p_dev_addr()
  537. addr1 = dev[1].p2p_dev_addr()
  538. adv_id1 = p2ps_advertise(r_dev=dev[0], r_role='0',
  539. svc_name='org.wi-fi.wfds.send.tx',
  540. srv_info='I can transfer files upto size of 2 GB')
  541. adv_id2 = p2ps_advertise(r_dev=dev[0], r_role='0',
  542. svc_name='org.wi-fi.wfds.send.rx',
  543. srv_info='I can receive files upto size of 2 GB')
  544. adv_id3 = p2ps_advertise(r_dev=dev[0], r_role='1',
  545. svc_name='org.wi-fi.wfds.display.tx',
  546. srv_info='Miracast Mode')
  547. adv_id4 = p2ps_advertise(r_dev=dev[0], r_role='1',
  548. svc_name='org.wi-fi.wfds.display.rx',
  549. srv_info='Miracast Mode')
  550. dev[1].global_request("P2P_SERV_DISC_REQ " + addr0 + " asp 1 org.wi-fi.wfds.display.tx 'Miracast Mode'")
  551. dev[1].global_request("P2P_FIND 10 type=social seek=org.wi-fi.wfds.display.tx")
  552. dev[1].global_request("P2P_SERV_DISC_REQ " + addr0 + " asp 2 org.wi-fi.wfds.send* 'size of 2 GB'")
  553. dev[1].p2p_stop_find()
  554. dev[1].global_request("P2P_FIND 10 type=social seek=")
  555. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  556. if ev is None:
  557. raise Exception("P2P Device Found timed out")
  558. if addr0 not in ev:
  559. raise Exception("Unexpected service discovery request source")
  560. ev_list = []
  561. for i in range(0, 3):
  562. ev = dev[1].wait_global_event(["P2P-SERV-ASP-RESP"], timeout=10)
  563. if ev is None:
  564. raise Exception("P2P Service discovery timed out")
  565. if addr0 in ev:
  566. ev_list.append(ev)
  567. if len(ev_list) == 3:
  568. break
  569. dev[1].p2p_stop_find()
  570. for test in [ ("seek=org.wi-fi.wfds.display.TX",
  571. "asp_svc=org.wi-fi.wfds.display.tx"),
  572. ("seek=foo seek=org.wi-fi.wfds.display.tx seek=bar",
  573. "asp_svc=org.wi-fi.wfds.display.tx"),
  574. ("seek=1 seek=2 seek=3 seek=org.wi-fi.wfds.display.tx seek=4 seek=5 seek=6",
  575. "asp_svc=org.wi-fi.wfds.display.tx"),
  576. ("seek=not-found", None),
  577. ("seek=org.wi-fi.wfds", "asp_svc=org.wi-fi.wfds")]:
  578. dev[2].global_request("P2P_FIND 10 type=social " + test[0])
  579. if test[1] is None:
  580. ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=1)
  581. if ev is not None:
  582. raise Exception("Unexpected device found: " + ev)
  583. continue
  584. ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  585. if ev is None:
  586. raise Exception("P2P device discovery timed out (dev2)")
  587. if test[1] not in ev:
  588. raise Exception("Expected asp_svc not reported: " + ev)
  589. dev[2].p2p_stop_find()
  590. dev[2].request("P2P_FLUSH")
  591. dev[0].p2p_stop_find()
  592. ev1 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id1))
  593. if ev1 is None:
  594. raise Exception("Unable to remove the advertisement instance")
  595. ev2 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id2))
  596. if ev2 is None:
  597. raise Exception("Unable to remove the advertisement instance")
  598. ev3 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id3))
  599. if ev3 is None:
  600. raise Exception("Unable to remove the advertisement instance")
  601. ev4 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id4))
  602. if ev4 is None:
  603. raise Exception("Unable to remove the advertisement instance")
  604. if "OK" not in dev[0].global_request("P2P_SERVICE_ADD asp 1 12345678 1 1108 org.wi-fi.wfds.foobar svc_info='Test'"):
  605. raise Exception("P2P_SERVICE_ADD failed")
  606. if "OK" not in dev[0].global_request("P2P_SERVICE_DEL asp all"):
  607. raise Exception("P2P_SERVICE_DEL asp all failed")
  608. if "OK" not in dev[0].global_request("P2P_SERVICE_ADD asp 1 12345678 1 1108 org.wi-fi.wfds.foobar svc_info='Test'"):
  609. raise Exception("P2P_SERVICE_ADD failed")
  610. if "OK" not in dev[0].global_request("P2P_SERVICE_REP asp 1 12345678 1 1108 org.wi-fi.wfds.foobar svc_info='Test'"):
  611. raise Exception("P2P_SERVICE_REP failed")
  612. if "FAIL" not in dev[0].global_request("P2P_SERVICE_REP asp 1 12345678 1 1108 org.wi-fi.wfds.Foo svc_info='Test'"):
  613. raise Exception("Invalid P2P_SERVICE_REP accepted")
  614. if "OK" not in dev[0].global_request("P2P_SERVICE_ADD asp 1 a2345678 1 1108 org.wi-fi.wfds.something svc_info='Test'"):
  615. raise Exception("P2P_SERVICE_ADD failed")
  616. if "OK" not in dev[0].global_request("P2P_SERVICE_ADD asp 1 a2345679 1 1108 org.wi-fi.wfds.Foo svc_info='Test'"):
  617. raise Exception("P2P_SERVICE_ADD failed")
  618. def get_ifnames():
  619. with open('/proc/net/dev', 'r') as f:
  620. data = f.read()
  621. ifnames = []
  622. for line in data.splitlines():
  623. ifname = line.strip().split(' ')[0]
  624. if ':' not in ifname:
  625. continue
  626. ifname = ifname.split(':')[0]
  627. ifnames.append(ifname)
  628. return ifnames
  629. def p2ps_connect_p2ps_method(dev, keep_group=False, join_extra="", flush=True):
  630. if flush:
  631. dev[0].flush_scan_cache()
  632. dev[1].flush_scan_cache()
  633. p2ps_advertise(r_dev=dev[0], r_role='2', svc_name='org.wi-fi.wfds.send.rx',
  634. srv_info='I can receive files upto size 2 GB')
  635. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  636. svc_name='org.wi-fi.wfds.send.rx',
  637. srv_info='2 GB')
  638. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  639. go_ev = None
  640. if "join=" in ev0 and "go=" in ev1:
  641. # dev[1] started GO and dev[0] is about to join it.
  642. # Parse P2P-GROUP-STARTED from the GO to learn the operating frequency.
  643. go_ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  644. if go_ev is None:
  645. raise Exception("P2P-GROUP-STARTED timeout on dev1")
  646. res = dev[1].group_form_result(go_ev)
  647. if join_extra == "":
  648. join_extra = " freq=" + res['freq']
  649. ifnames = get_ifnames()
  650. p2ps_connect_pd(dev[0], dev[1], ev0, ev1, join_extra=join_extra,
  651. go_ev=go_ev)
  652. grp_ifname0 = dev[0].get_group_ifname()
  653. grp_ifname1 = dev[1].get_group_ifname()
  654. if not keep_group:
  655. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  656. if ev0 is None:
  657. raise Exception("Unable to remove the advertisement instance")
  658. ifnames = ifnames + get_ifnames()
  659. remove_group(dev[0], dev[1])
  660. ifnames = ifnames + get_ifnames()
  661. return grp_ifname0, grp_ifname1, ifnames
  662. def has_string_prefix(vals, prefix):
  663. for val in vals:
  664. if val.startswith(prefix):
  665. return True
  666. return False
  667. def test_p2ps_connect_p2ps_method_1(dev):
  668. """P2PS connection with P2PS method - no group interface"""
  669. set_no_group_iface(dev[0], 1)
  670. set_no_group_iface(dev[1], 1)
  671. (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev)
  672. if grp_ifname0 != dev[0].ifname:
  673. raise Exception("unexpected dev0 group ifname: " + grp_ifname0)
  674. if grp_ifname1 != dev[1].ifname:
  675. raise Exception("unexpected dev1 group ifname: " + grp_ifname1)
  676. if has_string_prefix(ifnames, 'p2p-' + grp_ifname0):
  677. raise Exception("dev0 group interface unexpectedly present")
  678. if has_string_prefix(ifnames, 'p2p-' + grp_ifname1):
  679. raise Exception("dev1 group interface unexpectedly present")
  680. def test_p2ps_connect_p2ps_method_2(dev):
  681. """P2PS connection with P2PS method - group interface on dev0"""
  682. set_no_group_iface(dev[0], 0)
  683. set_no_group_iface(dev[1], 1)
  684. (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev)
  685. if not grp_ifname0.startswith('p2p-' + dev[0].ifname + '-'):
  686. raise Exception("unexpected dev0 group ifname: " + grp_ifname0)
  687. if grp_ifname1 != dev[1].ifname:
  688. raise Exception("unexpected dev1 group ifname: " + grp_ifname1)
  689. if has_string_prefix(ifnames, 'p2p-' + grp_ifname0):
  690. raise Exception("dev0 group interface unexpectedly present")
  691. def test_p2ps_connect_p2ps_method_3(dev):
  692. """P2PS connection with P2PS method - group interface on dev1"""
  693. set_no_group_iface(dev[0], 1)
  694. set_no_group_iface(dev[1], 0)
  695. (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev)
  696. if grp_ifname0 != dev[0].ifname:
  697. raise Exception("unexpected dev0 group ifname: " + grp_ifname0)
  698. if not grp_ifname1.startswith('p2p-' + dev[1].ifname + '-'):
  699. raise Exception("unexpected dev1 group ifname: " + grp_ifname1)
  700. if has_string_prefix(ifnames, 'p2p-' + grp_ifname0):
  701. raise Exception("dev0 group interface unexpectedly present")
  702. def test_p2ps_connect_p2ps_method_4(dev):
  703. """P2PS connection with P2PS method - group interface on both"""
  704. set_no_group_iface(dev[0], 0)
  705. set_no_group_iface(dev[1], 0)
  706. (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev)
  707. if not grp_ifname0.startswith('p2p-' + dev[0].ifname + '-'):
  708. raise Exception("unexpected dev0 group ifname: " + res0['ifname'])
  709. if not grp_ifname1.startswith('p2p-' + dev[1].ifname + '-'):
  710. raise Exception("unexpected dev1 group ifname: " + res1['ifname'])
  711. def test_p2ps_connect_adv_go_persistent(dev):
  712. """P2PS auto-accept connection with advertisement as GO and having persistent group"""
  713. go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15,
  714. r_dev=dev[1], r_intent=0)
  715. dev[0].remove_group()
  716. dev[1].wait_go_ending_session()
  717. p2ps_advertise(r_dev=dev[0], r_role='4', svc_name='org.wi-fi.wfds.send.rx',
  718. srv_info='I can receive files upto size 2 GB')
  719. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  720. svc_name='org.wi-fi.wfds.send.rx',
  721. srv_info='2 GB')
  722. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  723. if "persist=" not in ev0 or "persist=" not in ev1:
  724. raise Exception("Persistent group isn't used by peers")
  725. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  726. remove_group(dev[0], dev[1])
  727. def test_p2ps_adv_go_persistent_no_peer_entry(dev):
  728. """P2PS advertisement as GO having persistent group (no peer entry)"""
  729. go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15,
  730. r_dev=dev[1], r_intent=0)
  731. dev[0].remove_group()
  732. dev[1].wait_go_ending_session()
  733. p2ps_advertise(r_dev=dev[0], r_role='4', svc_name='org.wi-fi.wfds.send.rx',
  734. srv_info='I can receive files upto size 2 GB')
  735. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  736. svc_name='org.wi-fi.wfds.send.rx',
  737. srv_info='2 GB')
  738. dev[0].global_request("P2P_FLUSH")
  739. dev[0].p2p_listen()
  740. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  741. if "persist=" not in ev0 or "persist=" not in ev1:
  742. raise Exception("Persistent group isn't used by peers")
  743. def test_p2ps_pd_follow_on_status_failure(dev):
  744. """P2PS PD follow on request with status 11"""
  745. addr0 = dev[0].p2p_dev_addr()
  746. addr1 = dev[1].p2p_dev_addr()
  747. p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
  748. srv_info='I can receive files upto size 2 GB')
  749. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  750. svc_name='org.wi-fi.wfds.send.rx',
  751. srv_info='2 GB')
  752. dev[1].asp_provision(addr0, adv_id=str(adv_id), adv_mac=addr0,
  753. session_id=1, session_mac=addr1)
  754. ev_pd_start = dev[0].wait_global_event(["P2PS-PROV-START"], timeout=10)
  755. if ev_pd_start is None:
  756. raise Exception("P2PS-PROV-START timeout on Advertiser side")
  757. ev = dev[1].wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout=10)
  758. if ev is None:
  759. raise Exception("P2P-PROV-DISC-FAILURE timeout on seeker side")
  760. dev[1].p2p_ext_listen(500, 500)
  761. dev[0].p2p_stop_find()
  762. dev[0].asp_provision(addr1, adv_id=str(adv_id), adv_mac=addr0, session_id=1,
  763. session_mac=addr1, status=11, method=0)
  764. ev = dev[1].wait_global_event(["P2PS-PROV-DONE"], timeout=10)
  765. if ev is None:
  766. raise Exception("P2P-PROV-DONE timeout on seeker side")
  767. if adv_id not in ev:
  768. raise Exception("P2P-PROV-DONE without adv_id on seeker side")
  769. if "status=11" not in ev:
  770. raise Exception("P2P-PROV-DONE without status on seeker side")
  771. ev = dev[0].wait_global_event(["P2PS-PROV-DONE"], timeout=10)
  772. if ev is None:
  773. raise Exception("P2P-PROV-DONE timeout on advertiser side")
  774. if adv_id not in ev:
  775. raise Exception("P2P-PROV-DONE without adv_id on advertiser side")
  776. if "status=11" not in ev:
  777. raise Exception("P2P-PROV-DONE without status on advertiser side")
  778. def test_p2ps_client_probe(dev):
  779. """P2PS CLI discoverability on operating channel"""
  780. cli_probe = dev[0].global_request("SET p2p_cli_probe 1")
  781. p2ps_connect_p2ps_method(dev, keep_group=True)
  782. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[2], r_dev=dev[0],
  783. svc_name='org.wi-fi.wfds.send.rx',
  784. single_peer_expected=False)
  785. dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  786. remove_group(dev[0], dev[1])
  787. def test_p2ps_go_probe(dev):
  788. """P2PS GO discoverability on operating channel"""
  789. p2ps_connect_adv_go_pin_method(dev, keep_group=True)
  790. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[2], r_dev=dev[0],
  791. svc_name='org.wi-fi.wfds.send.rx',
  792. single_peer_expected=False)
  793. dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  794. remove_group(dev[0], dev[1])
  795. def test_p2ps_wildcard_p2ps(dev):
  796. """P2PS wildcard SD Probe Request/Response"""
  797. p2ps_wildcard = "org.wi-fi.wfds"
  798. adv_id = p2ps_advertise(r_dev=dev[0], r_role='1',
  799. svc_name='org.foo.service',
  800. srv_info='I can do stuff')
  801. adv_id2 = p2ps_advertise(r_dev=dev[0], r_role='1',
  802. svc_name='org.wi-fi.wfds.send.rx',
  803. srv_info='I can receive files upto size 2 GB')
  804. if "OK" not in dev[1].global_request("P2P_FIND 10 type=social seek=org.foo.service seek=" + p2ps_wildcard):
  805. raise Exception("Failed on P2P_FIND command")
  806. ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  807. if ev1 is None:
  808. raise Exception("P2P-DEVICE-FOUND timeout on seeker side")
  809. if dev[0].p2p_dev_addr() not in ev1:
  810. raise Exception("Unexpected peer")
  811. ev2 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  812. if ev2 is None:
  813. raise Exception("P2P-DEVICE-FOUND timeout on seeker side (2)")
  814. if dev[0].p2p_dev_addr() not in ev2:
  815. raise Exception("Unexpected peer (2)")
  816. if p2ps_wildcard not in ev1 + ev2:
  817. raise Exception("P2PS Wildcard name not found in P2P-DEVICE-FOUND event")
  818. if "org.foo.service" not in ev1 + ev2:
  819. raise Exception("Vendor specific service name not found in P2P-DEVICE-FOUND event")
  820. if "OK" not in dev[1].global_request("P2P_STOP_FIND"):
  821. raise Exception("P2P_STOP_FIND failed")
  822. dev[1].dump_monitor()
  823. res = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  824. if res is None:
  825. raise Exception("Unable to remove the advertisement instance")
  826. if "OK" not in dev[1].global_request("P2P_FIND 10 type=social seek=" + p2ps_wildcard):
  827. raise Exception("Failed on P2P_FIND command")
  828. ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  829. if ev1 is None:
  830. raise Exception("P2P-DEVICE-FOUND timeout on seeker side")
  831. if dev[0].p2p_dev_addr() not in ev1:
  832. raise Exception("Unexpected peer")
  833. if p2ps_wildcard not in ev1:
  834. raise Exception("P2PS Wildcard name not found in P2P-DEVICE-FOUND event (2)")
  835. dev[1].dump_monitor()
  836. res = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id2))
  837. if res is None:
  838. raise Exception("Unable to remove the advertisement instance 2")
  839. if "OK" not in dev[1].global_request("P2P_FIND 10 type=social seek=" + p2ps_wildcard):
  840. raise Exception("Failed on P2P_FIND command")
  841. ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=2)
  842. if ev1 is not None:
  843. raise Exception("Unexpected P2P-DEVICE-FOUND event on seeker side")
  844. dev[1].p2p_stop_find()
  845. dev[1].dump_monitor()
  846. def test_p2ps_many_services_in_probe(dev):
  847. """P2PS with large number of services in Probe Request/Response"""
  848. long1 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.a'
  849. long2 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.b'
  850. long3 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.c'
  851. long4 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.d'
  852. long5 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.e'
  853. for name in [ long1, long2, long3, long4, long5 ]:
  854. p2ps_advertise(r_dev=dev[0], r_role='1',
  855. svc_name=name,
  856. srv_info='I can do stuff')
  857. if "OK" not in dev[1].global_request("P2P_FIND 10 type=social seek=%s seek=%s seek=%s seek=%s seek=%s" % (long1, long2, long3, long4, long5)):
  858. raise Exception("Failed on P2P_FIND command")
  859. events = ""
  860. # Note: Require only four events since all the services do not fit within
  861. # the length limit.
  862. for i in range(4):
  863. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  864. if ev is None:
  865. raise Exception("Missing P2P-DEVICE-FOUND")
  866. events = events + ev
  867. dev[1].p2p_stop_find()
  868. dev[1].dump_monitor()
  869. for name in [ long2, long3, long4, long5 ]:
  870. if name not in events:
  871. raise Exception("Service missing from peer events")
  872. def p2ps_test_feature_capability_cpt(dev, adv_cpt, seeker_cpt, adv_role,
  873. result):
  874. p2ps_advertise(r_dev=dev[0], r_role=adv_role,
  875. svc_name='org.wi-fi.wfds.send.rx',
  876. srv_info='I can receive files upto size 2 GB', cpt=adv_cpt)
  877. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  878. svc_name='org.wi-fi.wfds.send.rx',
  879. srv_info='2 GB')
  880. auto_accept = adv_role != "0"
  881. ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id,
  882. auto_accept=auto_accept, adv_cpt=adv_cpt,
  883. seeker_cpt=seeker_cpt, method="8")
  884. status0, fcap0 = p2ps_parse_event(ev0, "status", "feature_cap")
  885. status1, fcap1 = p2ps_parse_event(ev0, "status", "feature_cap")
  886. if fcap0 is None:
  887. raise Exception("Bad feature capability on Seeker side")
  888. if fcap1 is None:
  889. raise Exception("Bad feature capability on Advertiser side")
  890. if fcap0 != fcap1:
  891. raise Exception("Incompatible feature capability values")
  892. if status0 not in ("0", "12") or status1 not in ("0", "12"):
  893. raise Exception("Unexpected PD result status")
  894. if result == "UDP" and fcap0[1] != "1":
  895. raise Exception("Unexpected CPT feature capability value (expected: UDP)")
  896. elif result == "MAC" and fcap0[1] != "2":
  897. raise Exception("Unexpected CPT feature capability value (expected: MAC)")
  898. ev = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  899. if ev is None:
  900. raise Exception("Unable to remove the advertisement instance")
  901. def test_p2ps_feature_capability_mac_autoaccept(dev):
  902. """P2PS PD Feature Capability CPT: advertiser MAC, seeker UDP:MAC, autoaccept"""
  903. p2ps_test_feature_capability_cpt(dev, adv_cpt="MAC", seeker_cpt="UDP:MAC",
  904. adv_role="4", result="MAC")
  905. def test_p2ps_feature_capability_mac_nonautoaccept(dev):
  906. """P2PS PD Feature Capability CPT: advertiser:MAC, seeker UDP:MAC, nonautoaccept"""
  907. p2ps_test_feature_capability_cpt(dev, adv_cpt="MAC", seeker_cpt="UDP:MAC",
  908. adv_role="0", result="MAC")
  909. def test_p2ps_feature_capability_mac_udp_autoaccept(dev):
  910. """P2PS PD Feature Capability CPT: advertiser MAC:UDP, seeker UDP:MAC, autoaccept"""
  911. p2ps_test_feature_capability_cpt(dev, adv_cpt="MAC:UDP",
  912. seeker_cpt="UDP:MAC", adv_role="2",
  913. result="MAC")
  914. def test_p2ps_feature_capability_mac_udp_nonautoaccept(dev):
  915. """P2PS PD Feature Capability CPT: advertiser MAC:UDP, seeker UDP:MAC, nonautoaccept"""
  916. p2ps_test_feature_capability_cpt(dev, adv_cpt="MAC:UDP",
  917. seeker_cpt="UDP:MAC", adv_role="0",
  918. result="UDP")
  919. def test_p2ps_feature_capability_udp_mac_autoaccept(dev):
  920. """P2PS PD Feature Capability CPT: advertiser UDP:MAC, seeker MAC:UDP, autoaccept"""
  921. p2ps_test_feature_capability_cpt(dev, adv_cpt="UDP:MAC",
  922. seeker_cpt="MAC:UDP", adv_role="2",
  923. result="UDP")
  924. def test_p2ps_feature_capability_udp_mac_nonautoaccept(dev):
  925. """P2PS PD Feature Capability CPT: advertiser UDP:MAC, seeker MAC:UDP, nonautoaccept"""
  926. p2ps_test_feature_capability_cpt(dev, adv_cpt="UDP:MAC",
  927. seeker_cpt="MAC:UDP", adv_role="0",
  928. result="MAC")
  929. def test_p2ps_channel_one_connected(dev, apdev):
  930. """P2PS connection with P2PS method - one of the stations connected"""
  931. set_no_group_iface(dev[0], 0)
  932. set_no_group_iface(dev[1], 0)
  933. try:
  934. hapd = hostapd.add_ap(apdev[0]['ifname'],
  935. { "ssid": 'bss-2.4ghz', "channel": '7' })
  936. dev[1].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2442")
  937. (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev, keep_group=True, join_extra=" freq=2442")
  938. freq = dev[0].get_group_status_field('freq');
  939. if freq != '2442':
  940. raise Exception('Unexpected frequency for group 2442 != ' + freq)
  941. finally:
  942. remove_group(dev[0], dev[1])
  943. dev[0].global_request("P2P_SERVICE_DEL asp all")
  944. def set_random_listen_chan(dev):
  945. chan = random.randrange(0, 3) * 5 + 1
  946. dev.global_request("P2P_SET listen_channel %d" % chan)
  947. def test_p2ps_channel_both_connected_same(dev, apdev):
  948. """P2PS connection with P2PS method - stations connected on same channel"""
  949. set_no_group_iface(dev[2], 0)
  950. set_no_group_iface(dev[1], 0)
  951. dev[2].global_request("P2P_SET listen_channel 6")
  952. dev[1].global_request("P2P_SET listen_channel 6")
  953. dev[1].flush_scan_cache()
  954. dev[2].flush_scan_cache()
  955. try:
  956. hapd = hostapd.add_ap(apdev[0]['ifname'],
  957. { "ssid": 'bss-2.4ghz', "channel": '6' })
  958. dev[2].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2437")
  959. dev[1].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2437")
  960. tmpdev = [ dev[2], dev[1] ]
  961. (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(tmpdev, keep_group=True, join_extra=" freq=2437", flush=False)
  962. freq = dev[2].get_group_status_field('freq');
  963. if freq != '2437':
  964. raise Exception('Unexpected frequency for group 2437 != ' + freq)
  965. finally:
  966. remove_group(dev[2], dev[1])
  967. dev[2].global_request("P2P_SERVICE_DEL asp all")
  968. for i in range(1, 3):
  969. set_random_listen_chan(dev[i])
  970. def disconnect_handler(seeker, advertiser):
  971. advertiser.request("DISCONNECT")
  972. advertiser.wait_disconnected(timeout=1)
  973. def test_p2ps_channel_both_connected_different(dev, apdev):
  974. """P2PS connection with P2PS method - stations connected on different channel"""
  975. if dev[0].get_mcc() > 1:
  976. raise HwsimSkip('Skip due to MCC being enabled')
  977. set_no_group_iface(dev[0], 0)
  978. set_no_group_iface(dev[1], 0)
  979. try:
  980. hapd1 = hostapd.add_ap(apdev[0]['ifname'],
  981. { "ssid": 'bss-channel-3', "channel": '3' })
  982. hapd2 = hostapd.add_ap(apdev[1]['ifname'],
  983. { "ssid": 'bss-channel-10', "channel": '10' })
  984. dev[0].connect("bss-channel-3", key_mgmt="NONE", scan_freq="2422")
  985. dev[1].connect("bss-channel-10", key_mgmt="NONE", scan_freq="2457")
  986. p2ps_advertise(r_dev=dev[0], r_role='2',
  987. svc_name='org.wi-fi.wfds.send.rx',
  988. srv_info='I can receive files upto size 2 GB')
  989. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  990. svc_name='org.wi-fi.wfds.send.rx',
  991. srv_info='2 GB')
  992. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False,
  993. handler=disconnect_handler)
  994. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  995. freq = dev[0].get_group_status_field('freq');
  996. if freq != '2457':
  997. raise Exception('Unexpected frequency for group 2457 != ' + freq)
  998. finally:
  999. remove_group(dev[0], dev[1])
  1000. dev[0].global_request("P2P_SERVICE_DEL asp all")
  1001. def test_p2ps_channel_both_connected_different_mcc(dev, apdev):
  1002. """P2PS connection with P2PS method - stations connected on different channels with mcc"""
  1003. if dev[0].get_mcc() == 1:
  1004. raise HwsimSkip('Skip case due to MCC not enabled')
  1005. set_no_group_iface(dev[0], 0)
  1006. set_no_group_iface(dev[1], 0)
  1007. try:
  1008. hapd1 = hostapd.add_ap(apdev[0]['ifname'],
  1009. { "ssid": 'bss-channel-3', "channel": '3' })
  1010. hapd2 = hostapd.add_ap(apdev[1]['ifname'],
  1011. { "ssid": 'bss-channel-10', "channel": '10' })
  1012. dev[0].connect("bss-channel-3", key_mgmt="NONE", scan_freq="2422")
  1013. dev[1].connect("bss-channel-10", key_mgmt="NONE", scan_freq="2457")
  1014. (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev, keep_group=True)
  1015. freq = dev[0].get_group_status_field('freq');
  1016. if freq != '2422' and freq != '2457':
  1017. raise Exception('Unexpected frequency for group =' + freq)
  1018. finally:
  1019. remove_group(dev[0], dev[1])
  1020. dev[0].global_request("P2P_SERVICE_DEL asp all")
  1021. def clear_disallow_handler(seeker, advertiser):
  1022. advertiser.global_request("P2P_SET disallow_freq ")
  1023. def test_p2ps_channel_disallow_freq(dev, apdev):
  1024. """P2PS connection with P2PS method - disallow freqs"""
  1025. set_no_group_iface(dev[0], 0)
  1026. set_no_group_iface(dev[1], 0)
  1027. try:
  1028. dev[0].global_request("P2P_SET disallow_freq 2412-2457")
  1029. dev[1].global_request("P2P_SET disallow_freq 2417-2462")
  1030. p2ps_advertise(r_dev=dev[0], r_role='2',
  1031. svc_name='org.wi-fi.wfds.send.rx',
  1032. srv_info='I can receive files upto size 2 GB')
  1033. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  1034. svc_name='org.wi-fi.wfds.send.rx',
  1035. srv_info='2 GB')
  1036. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False,
  1037. handler=clear_disallow_handler)
  1038. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  1039. freq = dev[0].get_group_status_field('freq');
  1040. if freq != '2412':
  1041. raise Exception('Unexpected frequency for group 2412 != ' + freq)
  1042. finally:
  1043. remove_group(dev[0], dev[1])
  1044. dev[0].global_request("P2P_SERVICE_DEL asp all")
  1045. dev[0].global_request("P2P_SET disallow_freq ")
  1046. dev[1].global_request("P2P_SET disallow_freq ")
  1047. def test_p2ps_channel_sta_connected_disallow_freq(dev, apdev):
  1048. """P2PS connection with P2PS method - one station and disallow freqs"""
  1049. if dev[0].get_mcc() > 1:
  1050. raise HwsimSkip('Skip due to MCC being enabled')
  1051. set_no_group_iface(dev[0], 0)
  1052. set_no_group_iface(dev[1], 0)
  1053. try:
  1054. dev[0].global_request("P2P_SET disallow_freq 2437")
  1055. hapd = hostapd.add_ap(apdev[0]['ifname'],
  1056. { "ssid": 'bss-channel-6', "channel": '6' })
  1057. dev[1].connect("bss-channel-6", key_mgmt="NONE", scan_freq="2437")
  1058. p2ps_advertise(r_dev=dev[0], r_role='2',
  1059. svc_name='org.wi-fi.wfds.send.rx',
  1060. srv_info='I can receive files upto size 2 GB')
  1061. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  1062. svc_name='org.wi-fi.wfds.send.rx',
  1063. srv_info='2 GB')
  1064. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False,
  1065. handler=clear_disallow_handler)
  1066. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  1067. freq = dev[0].get_group_status_field('freq');
  1068. if freq != '2437':
  1069. raise Exception('Unexpected frequency for group 2437 != ' + freq)
  1070. finally:
  1071. remove_group(dev[0], dev[1])
  1072. dev[0].global_request("P2P_SET disallow_freq ")
  1073. dev[0].global_request("P2P_SERVICE_DEL asp all")
  1074. def test_p2ps_channel_sta_connected_disallow_freq_mcc(dev, apdev):
  1075. """P2PS connection with P2PS method - one station and disallow freqs with mcc"""
  1076. with HWSimRadio(n_channels=2) as (radio, iface):
  1077. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1078. wpas.interface_add(iface)
  1079. if wpas.get_mcc() < 2:
  1080. raise Exception("New radio does not support MCC")
  1081. set_no_group_iface(dev[0], 0)
  1082. set_no_group_iface(wpas, 0)
  1083. try:
  1084. dev[0].global_request("P2P_SET disallow_freq 2437")
  1085. hapd1 = hostapd.add_ap(apdev[0]['ifname'],
  1086. { "ssid": 'bss-channel-6', "channel": '6' })
  1087. wpas.connect("bss-channel-6", key_mgmt="NONE", scan_freq="2437")
  1088. tmpdev = [ dev[0], wpas ]
  1089. (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(tmpdev, keep_group=True)
  1090. freq = dev[0].get_group_status_field('freq');
  1091. if freq == '2437':
  1092. raise Exception('Unexpected frequency=2437')
  1093. finally:
  1094. remove_group(dev[0], wpas)
  1095. dev[0].global_request("P2P_SET disallow_freq ")
  1096. dev[0].global_request("P2P_SERVICE_DEL asp all")
  1097. def test_p2ps_active_go_adv(dev, apdev):
  1098. """P2PS connection with P2PS method - active GO on advertiser"""
  1099. set_no_group_iface(dev[0], 0)
  1100. set_no_group_iface(dev[1], 0)
  1101. try:
  1102. # Add a P2P GO
  1103. dev[0].global_request("P2P_GROUP_ADD persistent")
  1104. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  1105. if ev is None:
  1106. raise Exception("P2P-GROUP-STARTED timeout on " + dev[0].p2p_dev_addr())
  1107. dev[0].group_form_result(ev)
  1108. p2ps_advertise(r_dev=dev[0], r_role='4',
  1109. svc_name='org.wi-fi.wfds.send.rx',
  1110. srv_info='I can receive files upto size 2 GB')
  1111. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  1112. svc_name='org.wi-fi.wfds.send.rx',
  1113. single_peer_expected=False)
  1114. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  1115. # explicitly stop find/listen as otherwise the long listen started by
  1116. # the advertiser would prevent the seeker to connect with the P2P GO
  1117. dev[0].p2p_stop_find()
  1118. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  1119. finally:
  1120. remove_group(dev[0], dev[1])
  1121. dev[0].global_request("P2P_SERVICE_DEL asp all")
  1122. def test_p2ps_active_go_seeker(dev, apdev):
  1123. """P2PS connection with P2PS method - active GO on seeker"""
  1124. set_no_group_iface(dev[0], 0)
  1125. set_no_group_iface(dev[1], 0)
  1126. try:
  1127. # Add a P2P GO on the seeker
  1128. dev[1].global_request("P2P_GROUP_ADD persistent")
  1129. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  1130. if ev is None:
  1131. raise Exception("P2P-GROUP-STARTED timeout on " + dev[1].p2p_dev_addr())
  1132. res = dev[1].group_form_result(ev)
  1133. p2ps_advertise(r_dev=dev[0], r_role='2',
  1134. svc_name='org.wi-fi.wfds.send.rx',
  1135. srv_info='I can receive files upto size 2 GB')
  1136. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  1137. svc_name='org.wi-fi.wfds.send.rx',
  1138. srv_info='2 GB')
  1139. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  1140. p2ps_connect_pd(dev[0], dev[1], ev0, ev1,
  1141. join_extra=" freq=" + res['freq'])
  1142. finally:
  1143. remove_group(dev[0], dev[1])
  1144. dev[0].global_request("P2P_SERVICE_DEL asp all")
  1145. def test_p2ps_channel_active_go_and_station_same(dev, apdev):
  1146. """P2PS connection, active P2P GO and station on channel"""
  1147. set_no_group_iface(dev[2], 0)
  1148. set_no_group_iface(dev[1], 0)
  1149. dev[2].global_request("P2P_SET listen_channel 11")
  1150. dev[1].global_request("P2P_SET listen_channel 11")
  1151. try:
  1152. hapd = hostapd.add_ap(apdev[0]['ifname'],
  1153. { "ssid": 'bss-channel-11', "channel": '11' })
  1154. dev[2].connect("bss-channel-11", key_mgmt="NONE", scan_freq="2462")
  1155. # Add a P2P GO on the seeker
  1156. dev[1].global_request("P2P_GROUP_ADD freq=2462 persistent")
  1157. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  1158. if ev is None:
  1159. raise Exception("P2P-GROUP-STARTED timeout on " + dev[1].p2p_dev_addr())
  1160. dev[1].group_form_result(ev)
  1161. p2ps_advertise(r_dev=dev[2], r_role='2',
  1162. svc_name='org.wi-fi.wfds.send.rx',
  1163. srv_info='I can receive files upto size 2 GB')
  1164. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[2],
  1165. svc_name='org.wi-fi.wfds.send.rx',
  1166. srv_info='2 GB')
  1167. ev1, ev0 = p2ps_provision(dev[1], dev[2], adv_id)
  1168. p2ps_connect_pd(dev[2], dev[1], ev0, ev1, join_extra=" freq=2462")
  1169. finally:
  1170. remove_group(dev[2], dev[1])
  1171. dev[2].global_request("P2P_SERVICE_DEL asp all")
  1172. for i in range(1, 3):
  1173. set_random_listen_chan(dev[i])
  1174. def test_p2ps_channel_active_go_and_station_different(dev, apdev):
  1175. """P2PS connection, active P2P GO and station on channel"""
  1176. if dev[0].get_mcc() > 1:
  1177. raise HwsimSkip('Skip due to MCC being enabled')
  1178. set_no_group_iface(dev[0], 0)
  1179. set_no_group_iface(dev[1], 0)
  1180. try:
  1181. hapd = hostapd.add_ap(apdev[0]['ifname'],
  1182. { "ssid": 'bss-channel-2', "channel": '2' })
  1183. dev[0].connect("bss-channel-2", key_mgmt="NONE", scan_freq="2417")
  1184. # Add a P2P GO on the seeker. Force the listen channel to be the same,
  1185. # as extended listen will not kick as long as P2P GO is waiting for
  1186. # initial connection.
  1187. dev[1].global_request("P2P_SET listen_channel 11")
  1188. dev[1].global_request("P2P_GROUP_ADD freq=2462 persistent")
  1189. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  1190. if ev is None:
  1191. raise Exception("P2P-GROUP-STARTED timeout on " + dev[1].p2p_dev_addr())
  1192. dev[1].group_form_result(ev)
  1193. p2ps_advertise(r_dev=dev[0], r_role='2',
  1194. svc_name='org.wi-fi.wfds.send.rx',
  1195. srv_info='I can receive files upto size 2 GB')
  1196. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  1197. svc_name='org.wi-fi.wfds.send.rx',
  1198. srv_info='2 GB')
  1199. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False,
  1200. handler=disconnect_handler, adv_role='2',
  1201. seeker_role='4')
  1202. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  1203. freq = dev[0].get_group_status_field('freq');
  1204. if freq != '2462':
  1205. raise Exception('Unexpected frequency for group 2462!=' + freq)
  1206. finally:
  1207. dev[0].global_request("P2P_SERVICE_DEL asp all")
  1208. set_random_listen_chan(dev[1])
  1209. def test_p2ps_channel_active_go_and_station_different_mcc(dev, apdev):
  1210. """P2PS connection, active P2P GO and station on channel"""
  1211. if dev[0].get_mcc() == 1:
  1212. raise HwsimSkip('Skip due to MCC not being enabled')
  1213. set_no_group_iface(dev[0], 0)
  1214. set_no_group_iface(dev[1], 0)
  1215. try:
  1216. hapd = hostapd.add_ap(apdev[0]['ifname'],
  1217. { "ssid": 'bss-channel-6', "channel": '6' })
  1218. dev[0].connect("bss-channel-6", key_mgmt="NONE", scan_freq="2437")
  1219. # Add a P2P GO on the seeker
  1220. dev[1].global_request("P2P_GROUP_ADD freq=2462 persistent")
  1221. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  1222. if ev is None:
  1223. raise Exception("P2P-GROUP-STARTED timeout on " + dev[1].p2p_dev_addr())
  1224. dev[1].group_form_result(ev)
  1225. p2ps_advertise(r_dev=dev[0], r_role='2',
  1226. svc_name='org.wi-fi.wfds.send.rx',
  1227. srv_info='I can receive files upto size 2 GB')
  1228. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  1229. svc_name='org.wi-fi.wfds.send.rx',
  1230. srv_info='2 GB')
  1231. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  1232. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  1233. finally:
  1234. remove_group(dev[0], dev[1])
  1235. dev[0].request("DISCONNECT")
  1236. hapd.disable()
  1237. dev[0].global_request("P2P_SERVICE_DEL asp all")