test_p2ps.py 71 KB

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