test_p2ps.py 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  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. from test_p2p_grpform import check_grpform_results
  14. from test_p2p_grpform import remove_group
  15. from test_p2p_persistent import go_neg_pin_authorized_persistent
  16. from utils import HwsimSkip
  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. return [adv_id, rcvd_svc_name]
  79. def p2ps_nonexact_seek(i_dev, r_dev, svc_name, srv_info=None, adv_num=None):
  80. """P2PS nonexact service seek request"""
  81. if adv_num is None:
  82. adv_num = 1
  83. if srv_info is not None:
  84. ev1 = i_dev.global_request("P2P_SERV_DISC_REQ 00:00:00:00:00:00 asp 1 " + svc_name + " '" + srv_info + "'")
  85. else:
  86. ev1 = i_dev.global_request("P2P_SERV_DISC_REQ 00:00:00:00:00:00 asp 1 " + svc_name + " '")
  87. if ev1 is None:
  88. raise Exception("Failed to add Service Discovery request for nonexact seek request")
  89. if "OK" not in i_dev.global_request("P2P_FIND 10 type=social seek="):
  90. raise Exception("Failed to initiate seek")
  91. ev1 = i_dev.wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  92. if ev1 is None:
  93. raise Exception("P2P-DEVICE-FOUND timeout on seeker side")
  94. if r_dev.p2p_dev_addr() not in ev1:
  95. raise Exception("Unexpected peer")
  96. ev_list = []
  97. for i in range (0, adv_num):
  98. ev1 = i_dev.wait_global_event(["P2P-SERV-ASP-RESP"], timeout=10)
  99. if ev1 is None:
  100. raise Exception("Failed to receive Service Discovery Response")
  101. if r_dev.p2p_dev_addr() not in ev1:
  102. raise Exception("Service Discovery response from Unknown Peer")
  103. if srv_info is not None and srv_info not in ev1:
  104. raise Exception("service info not available in Service Discovery response")
  105. adv_id = ev1.split(" ")[3]
  106. rcvd_svc_name = ev1.split(" ")[6]
  107. ev_list.append(''.join([adv_id, ' ', rcvd_svc_name]))
  108. return ev_list
  109. def p2ps_parse_event(ev, *args):
  110. ret = ()
  111. for arg in args:
  112. m = re.search("\s+" + arg + r"=(\S+)", ev)
  113. ret += (m.group(1) if m is not None else None,)
  114. return ret
  115. def p2ps_provision(seeker, advertiser, adv_id, auto_accept=True, method="1000", adv_cpt=None, seeker_cpt=None):
  116. addr0 = seeker.p2p_dev_addr()
  117. addr1 = advertiser.p2p_dev_addr()
  118. seeker.asp_provision(addr1, adv_id=str(adv_id), adv_mac=addr1, session_id=1,
  119. session_mac=addr0, method=method, cpt=seeker_cpt)
  120. if not auto_accept or method == "100":
  121. pin = None
  122. ev_pd_start = advertiser.wait_global_event(["P2PS-PROV-START"],
  123. timeout=10)
  124. if ev_pd_start is None:
  125. raise Exception("P2PS-PROV-START timeout on Advertiser side")
  126. peer = ev_pd_start.split()[1]
  127. advert_id, advert_mac, session, session_mac =\
  128. p2ps_parse_event(ev_pd_start, "adv_id", "adv_mac", "session", "mac")
  129. ev = seeker.wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout=10)
  130. if ev is None:
  131. raise Exception("P2P-PROV-DISC-FAILURE timeout on seeker side")
  132. if method == "100":
  133. ev = advertiser.wait_global_event(["P2P-PROV-DISC-ENTER-PIN"],
  134. timeout=10)
  135. if ev is None:
  136. raise Exception("P2P-PROV-DISC-ENTER-PIN timeout on advertiser side")
  137. if addr0 not in ev:
  138. raise Exception("Unknown peer " + addr0)
  139. ev = seeker.wait_global_event(["P2P-PROV-DISC-SHOW-PIN"],
  140. timeout=10)
  141. if ev is None:
  142. raise Exception("P2P-PROV-DISC-SHOW-PIN timeout on seeker side")
  143. if addr1 not in ev:
  144. raise Exception("Unknown peer " + addr1)
  145. pin = ev.split()[2]
  146. elif method == "8":
  147. ev = advertiser.wait_global_event(["P2P-PROV-DISC-SHOW-PIN"],
  148. timeout=10)
  149. if ev is None:
  150. raise Exception("P2P-PROV-DISC-SHOW-PIN timeout on advertiser side")
  151. if addr0 not in ev:
  152. raise Exception("Unknown peer " + addr0)
  153. pin = ev.split()[2]
  154. advertiser.asp_provision(peer, adv_id=advert_id, adv_mac=advert_mac,
  155. session_id=int(session, 0),
  156. session_mac=session_mac, status=12,
  157. cpt=adv_cpt)
  158. ev1 = seeker.wait_global_event(["P2PS-PROV-DONE"], timeout=10)
  159. if ev1 is None:
  160. raise Exception("P2PS-PROV-DONE timeout on seeker side")
  161. ev2 = advertiser.wait_global_event(["P2PS-PROV-DONE"], timeout=10)
  162. if ev2 is None:
  163. raise Exception("P2PS-PROV-DONE timeout on advertiser side")
  164. if method == "8":
  165. ev = seeker.wait_global_event(["P2P-PROV-DISC-ENTER-PIN"],
  166. timeout=10)
  167. if ev is None:
  168. raise Exception("P2P-PROV-DISC-ENTER-PIN failed on seeker side")
  169. if addr1 not in ev:
  170. raise Exception("Unknown peer " + addr1)
  171. if pin is not None:
  172. return ev1, ev2, pin
  173. return ev1, ev2
  174. # Auto-accept is true and the method is either P2PS or advertiser is DISPLAY
  175. ev1 = seeker.wait_global_event(["P2PS-PROV-DONE"], timeout=10)
  176. if ev1 is None:
  177. raise Exception("P2PS-PROV-DONE timeout on seeker side")
  178. ev2 = advertiser.wait_global_event(["P2PS-PROV-DONE"], timeout=10)
  179. if ev2 is None:
  180. raise Exception("P2PS-PROV-DONE timeout on advertiser side")
  181. if method == "8":
  182. ev = seeker.wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=10)
  183. if ev is None:
  184. raise Exception("P2P-PROV-DISC-ENTER-PIN timeout on seeker side")
  185. if addr1 not in ev:
  186. raise Exception("Unknown peer " + addr1)
  187. ev = advertiser.wait_global_event(["P2P-PROV-DISC-SHOW-PIN"],
  188. timeout=10)
  189. if ev is None:
  190. raise Exception("P2P-PROV-DISC-SHOW-PIN timeout on advertiser side")
  191. if addr0 not in ev:
  192. raise Exception("Unknown peer " + addr0)
  193. pin = ev.split()[2]
  194. return ev1, ev2, pin
  195. return ev1, ev2
  196. def p2ps_connect_pd(dev0, dev1, ev0, ev1, pin=None):
  197. conf_methods_map = {"8": "p2ps", "1": "display", "5": "keypad"}
  198. peer0 = ev0.split()[1]
  199. peer1 = ev1.split()[1]
  200. status0, conncap0, adv_id0, adv_mac0, mac0, session0, dev_passwd_id0, go0, join0, feature_cap0, persist0 =\
  201. p2ps_parse_event(ev0, "status", "conncap", "adv_id", "adv_mac", "mac", "session", "dev_passwd_id", "go", "join", "feature_cap", "persist")
  202. status1, conncap1, adv_id1, adv_mac1, mac1, session1, dev_passwd_id1, go1, join1, feature_cap1, persist1 =\
  203. p2ps_parse_event(ev1, "status", "conncap", "adv_id", "adv_mac", "mac", "session", "dev_passwd_id", "go", "join", "feature_cap", "persist")
  204. if status0 != "0" and status0 != "12":
  205. raise Exception("PD failed on " + dev0.p2p_dev_addr())
  206. if status1 != "0" and status1 != "12":
  207. raise Exception("PD failed on " + dev1.p2p_dev_addr())
  208. if status0 == "12" and status1 == "12":
  209. raise Exception("Both sides have status 12 which doesn't make sense")
  210. if adv_id0 != adv_id1 or adv_id0 is None:
  211. raise Exception("Adv. IDs don't match")
  212. if adv_mac0 != adv_mac1 or adv_mac0 is None:
  213. raise Exception("Adv. MACs don't match")
  214. if session0 != session1 or session0 is None:
  215. raise Exception("Session IDs don't match")
  216. if mac0 != mac1 or mac0 is None:
  217. raise Exception("Session MACs don't match")
  218. #TODO: Validate feature capability
  219. if bool(persist0) != bool(persist1):
  220. raise Exception("Only one peer has persistent group")
  221. if persist0 is None and not all([conncap0, conncap1, dev_passwd_id0,
  222. dev_passwd_id1]):
  223. raise Exception("Persistent group not used but conncap/dev_passwd_id are missing")
  224. if persist0 is not None and any([conncap0, conncap1, dev_passwd_id0,
  225. dev_passwd_id1]):
  226. raise Exception("Persistent group is used but conncap/dev_passwd_id are present")
  227. # Persistent Connection (todo: handle frequency)
  228. if persist0 is not None:
  229. if "OK" not in dev0.global_request("P2P_GROUP_ADD persistent=" + persist0 + " freq=2412"):
  230. raise Exception("Could not re-start persistent group")
  231. ev0 = dev0.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  232. if ev0 is None:
  233. raise Exception("P2P-GROUP-STARTED timeout on " + dev0.p2p_dev_addr())
  234. dev0.group_form_result(ev0)
  235. if "OK" not in dev1.global_request("P2P_GROUP_ADD persistent=" + persist1 + " freq=2412"):
  236. raise Exception("Could not re-start persistent group")
  237. ev1 = dev1.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  238. if ev1 is None:
  239. raise Exception("P2P-GROUP-STARTED timeout on " + dev1.p2p_dev_addr())
  240. dev1.group_form_result(ev1)
  241. if "GO" in ev0:
  242. ev = dev0.wait_global_event(["AP-STA-CONNECTED"], timeout=10)
  243. if ev is None:
  244. raise Exception("AP-STA-CONNECTED timeout on " + dev0.p2p_dev_addr())
  245. else:
  246. ev = dev1.wait_global_event(["AP-STA-CONNECTED"], timeout=10)
  247. if ev is None:
  248. raise Exception("AP-STA-CONNECTED timeout on " + dev1.p2p_dev_addr())
  249. else:
  250. try:
  251. method0 = conf_methods_map[dev_passwd_id0]
  252. method1 = conf_methods_map[dev_passwd_id1]
  253. except KeyError:
  254. raise Exception("Unsupported method")
  255. if method0 == "p2ps":
  256. pin = "12345670"
  257. if pin is None:
  258. raise Exception("Pin is not provided")
  259. if conncap0 == "1" and conncap1 == "1": # NEW/NEW - GON
  260. if any([join0, join1, go0, go1]):
  261. raise Exception("Unexpected join/go PD attributes")
  262. dev0.p2p_listen()
  263. if "OK" not in dev0.global_request("P2P_CONNECT " + peer0 + " " + pin + " " + method0 + " persistent auth"):
  264. raise Exception("P2P_CONNECT fails on " + dev0.p2p_dev_addr())
  265. if "OK" not in dev1.global_request("P2P_CONNECT " + peer1 + " " + pin + " " + method1 + " persistent"):
  266. raise Exception("P2P_CONNECT fails on " + dev1.p2p_dev_addr())
  267. ev = dev0.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
  268. if ev is None:
  269. raise Exception("GO Neg did not succeed on " + dev0.p2p_dev_addr())
  270. ev = dev1.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
  271. if ev is None:
  272. raise Exception("GO Neg did not succeed on " + dev1.p2p_dev_addr())
  273. ev = dev0.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  274. if ev is None:
  275. raise Exception("P2P-GROUP-STARTED timeout on " + dev0.p2p_dev_addr())
  276. dev0.group_form_result(ev)
  277. ev = dev1.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  278. if ev is None:
  279. raise Exception("P2P-GROUP-STARTED timeout on " + dev1.p2p_dev_addr())
  280. dev1.group_form_result(ev)
  281. else:
  282. if conncap0 == "2" and conncap1 == "4": # dev0 CLI, dev1 GO
  283. dev_cli, dev_go, go_if, join_address, go_method, cli_method = dev0, dev1, go1, join0, method1, method0
  284. elif conncap0 == "4" and conncap1 == "2": # dev0 GO, dev1 CLI
  285. dev_cli, dev_go, go_if, join_address, go_method, cli_method = dev1, dev0, go0, join1, method0, method1
  286. else:
  287. raise Exception("Bad connection capabilities")
  288. if go_if is None:
  289. raise Exception("Device " + dev_go.p2p_dev_addr() + " failed to become GO")
  290. if join_address is None:
  291. raise Exception("Device " + dev_cli.p2p_dev_addr() + " failed to become CLI")
  292. ev = dev_go.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  293. if ev is None:
  294. raise Exception("P2P-GROUP-STARTED timeout on " + dev_go.p2p_dev_addr())
  295. dev_go.group_form_result(ev)
  296. if go_method != "p2ps":
  297. ev = dev_go.group_request("WPS_PIN any " + pin)
  298. if ev is None:
  299. raise Exception("Failed to initiate pin authorization on registrar side")
  300. if "OK" not in dev_cli.global_request("P2P_CONNECT " + join_address + " " + pin + " " + cli_method + " persistent join"):
  301. raise Exception("P2P_CONNECT failed on " + dev_cli.p2p_dev_addr())
  302. ev = dev_cli.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  303. if ev is None:
  304. raise Exception("P2P-GROUP-STARTED timeout on " + dev_cli.p2p_dev_addr())
  305. dev_cli.group_form_result(ev)
  306. ev = dev_go.wait_global_event(["AP-STA-CONNECTED"], timeout=10)
  307. if ev is None:
  308. raise Exception("AP-STA-CONNECTED timeout on " + dev_go.p2p_dev_addr())
  309. hwsim_utils.test_connectivity_p2p(dev0, dev1)
  310. def set_no_group_iface(dev, enable):
  311. if enable:
  312. res = dev.get_driver_status()
  313. if (int(res['capa.flags'], 0) & 0x20000000):
  314. raise HwsimSkip("P2P Device used. Cannot set enable no_group_iface")
  315. dev.global_request("SET p2p_no_group_iface 1")
  316. else:
  317. dev.global_request("SET p2p_no_group_iface 0")
  318. def test_p2ps_exact_search(dev):
  319. """P2PS exact service request"""
  320. p2ps_advertise(r_dev=dev[0], r_role='1', svc_name='org.wi-fi.wfds.send.rx',
  321. srv_info='I can receive files upto size 2 GB')
  322. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  323. svc_name='org.wi-fi.wfds.send.rx')
  324. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  325. if ev0 is None:
  326. raise Exception("Unable to remove the advertisement instance")
  327. def test_p2ps_exact_search_srvinfo(dev):
  328. """P2PS exact service request with service info"""
  329. p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
  330. srv_info='I can receive files upto size 2 GB')
  331. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  332. svc_name='org.wi-fi.wfds.send.rx',
  333. srv_info='2 GB')
  334. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  335. if ev0 is None:
  336. raise Exception("Unable to remove the advertisement instance")
  337. def test_p2ps_nonexact_search(dev):
  338. """P2PS nonexact seek request"""
  339. p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.play.rx',
  340. srv_info='I support Miracast Mode ')
  341. ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
  342. svc_name='org.wi-fi.wfds.play*')
  343. adv_id = ev_list[0].split()[0]
  344. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  345. if ev0 is None:
  346. raise Exception("Unable to remove the advertisement instance")
  347. def test_p2ps_nonexact_search_srvinfo(dev):
  348. """P2PS nonexact seek request with service info"""
  349. p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
  350. srv_info='I can receive files upto size 2 GB')
  351. ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
  352. svc_name='org.wi-fi.wfds.send*',
  353. srv_info='2 GB')
  354. adv_id = ev_list[0].split()[0]
  355. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  356. if ev0 is None:
  357. raise Exception("Unable to remove the advertisement instance")
  358. def test_p2ps_connect_p2ps_method_nonautoaccept(dev):
  359. """P2PS connect for non-auto-accept and P2PS config method"""
  360. p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
  361. srv_info='I can receive files upto size 2 GB')
  362. ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
  363. svc_name='org.wi-fi.wfds.send*',
  364. srv_info='2 GB')
  365. adv_id = ev_list[0].split()[0]
  366. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False)
  367. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  368. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  369. if ev0 is None:
  370. raise Exception("Unable to remove the advertisement instance")
  371. remove_group(dev[0], dev[1])
  372. def test_p2ps_connect_p2ps_method_autoaccept(dev):
  373. """P2PS connection with P2PS default config method and auto-accept"""
  374. p2ps_advertise(r_dev=dev[0], r_role='1', svc_name='org.wi-fi.wfds.send.rx',
  375. srv_info='I can receive files upto size 2 GB')
  376. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  377. svc_name='org.wi-fi.wfds.send.rx',
  378. srv_info='2 GB')
  379. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  380. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  381. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  382. if ev0 is None:
  383. raise Exception("Unable to remove the advertisement instance")
  384. remove_group(dev[0], dev[1])
  385. def test_p2ps_connect_keypad_method_nonautoaccept(dev):
  386. """P2PS Connection with non-auto-accept and seeker having keypad method"""
  387. p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
  388. srv_info='I can receive files upto size 2 GB')
  389. ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
  390. svc_name='org.wi-fi.wfds.send*',
  391. srv_info='2 GB')
  392. adv_id = ev_list[0].split()[0]
  393. ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False, method="8")
  394. p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
  395. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  396. if ev0 is None:
  397. raise Exception("Unable to remove the advertisement instance")
  398. remove_group(dev[0], dev[1])
  399. def test_p2ps_connect_display_method_nonautoaccept(dev):
  400. """P2PS connection with non-auto-accept and seeker having display method"""
  401. p2ps_advertise(r_dev=dev[0], r_role='0', svc_name='org.wi-fi.wfds.send.rx',
  402. srv_info='I can receive files upto size 2 GB')
  403. ev_list = p2ps_nonexact_seek(i_dev=dev[1], r_dev=dev[0],
  404. svc_name='org.wi-fi.wfds*', srv_info='2 GB')
  405. adv_id = ev_list[0].split()[0]
  406. ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, auto_accept=False, method="100")
  407. p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
  408. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  409. if ev0 is None:
  410. raise Exception("Unable to remove the advertisement instance")
  411. remove_group(dev[0], dev[1])
  412. def test_p2ps_connect_keypad_method_autoaccept(dev):
  413. """P2PS connection with auto-accept and keypad method on seeker side"""
  414. p2ps_advertise(r_dev=dev[0], r_role='1', svc_name='org.wi-fi.wfds.send.rx',
  415. srv_info='I can receive files upto size 2 GB')
  416. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  417. svc_name='org.wi-fi.wfds.send.rx',
  418. srv_info='2 GB')
  419. ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, method="8")
  420. p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
  421. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  422. if ev0 is None:
  423. raise Exception("Unable to remove the advertisement instance")
  424. remove_group(dev[0], dev[1])
  425. def test_p2ps_connect_display_method_autoaccept(dev):
  426. """P2PS connection with auto-accept and display method on seeker side"""
  427. p2ps_advertise(r_dev=dev[0], r_role='1', svc_name='org.wi-fi.wfds.send.rx',
  428. srv_info='I can receive files upto size 2 GB')
  429. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  430. svc_name='org.wi-fi.wfds.send.rx',
  431. srv_info='2 GB')
  432. ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, method="100")
  433. p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
  434. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  435. if ev0 is None:
  436. raise Exception("Unable to remove the advertisement instance")
  437. remove_group(dev[0], dev[1])
  438. def test_p2ps_connect_adv_go_p2ps_method(dev):
  439. """P2PS auto-accept connection with advertisement as GO and P2PS method"""
  440. p2ps_advertise(r_dev=dev[0], r_role='4', svc_name='org.wi-fi.wfds.send.rx',
  441. srv_info='I can receive files upto size 2 GB')
  442. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  443. svc_name='org.wi-fi.wfds.send.rx',
  444. srv_info='2 GB')
  445. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  446. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  447. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  448. if ev0 is None:
  449. raise Exception("Unable to remove the advertisement instance")
  450. remove_group(dev[0], dev[1])
  451. def test_p2ps_connect_adv_go_p2ps_method_group_iface(dev):
  452. """P2PS auto-accept connection with advertisement as GO and P2PS method using separate group interface"""
  453. set_no_group_iface(dev[0], 0)
  454. set_no_group_iface(dev[1], 0)
  455. p2ps_advertise(r_dev=dev[0], r_role='4', svc_name='org.wi-fi.wfds.send.rx',
  456. srv_info='I can receive files upto size 2 GB')
  457. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  458. svc_name='org.wi-fi.wfds.send.rx',
  459. srv_info='2 GB')
  460. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  461. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  462. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  463. if ev0 is None:
  464. raise Exception("Unable to remove the advertisement instance")
  465. remove_group(dev[0], dev[1])
  466. def test_p2ps_connect_adv_client_p2ps_method(dev):
  467. """P2PS auto-accept connection with advertisement as Client and P2PS method"""
  468. p2ps_advertise(r_dev=dev[0], r_role='2', svc_name='org.wi-fi.wfds.send.rx',
  469. srv_info='I can receive files upto size 2 GB')
  470. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  471. svc_name='org.wi-fi.wfds.send.rx',
  472. srv_info='2 GB')
  473. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  474. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  475. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  476. if ev0 is None:
  477. raise Exception("Unable to remove the advertisement instance")
  478. remove_group(dev[0], dev[1])
  479. def p2ps_connect_adv_go_pin_method(dev, keep_group=False):
  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, pin = p2ps_provision(dev[1], dev[0], adv_id, method="8")
  486. p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
  487. if not keep_group:
  488. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  489. if ev0 is None:
  490. raise Exception("Unable to remove the advertisement instance")
  491. remove_group(dev[0], dev[1])
  492. def test_p2ps_connect_adv_go_pin_method(dev):
  493. """P2PS advertiser as GO with keypad config method on seeker side and auto-accept"""
  494. p2ps_connect_adv_go_pin_method(dev)
  495. def test_p2ps_connect_adv_client_pin_method(dev):
  496. """P2PS advertiser as client with keypad config method on seeker side and auto-accept"""
  497. dev[0].flush_scan_cache()
  498. p2ps_advertise(r_dev=dev[0], r_role='2', svc_name='org.wi-fi.wfds.send.rx',
  499. srv_info='I can receive files upto size 2 GB')
  500. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  501. svc_name='org.wi-fi.wfds.send.rx',
  502. srv_info='2 GB')
  503. ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id, method="8")
  504. p2ps_connect_pd(dev[0], dev[1], ev0, ev1, pin)
  505. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  506. if ev0 is None:
  507. raise Exception("Unable to remove the advertisement instance")
  508. remove_group(dev[0], dev[1])
  509. def test_p2ps_service_discovery_multiple_queries(dev):
  510. """P2P service discovery with multiple queries"""
  511. addr0 = dev[0].p2p_dev_addr()
  512. addr1 = dev[1].p2p_dev_addr()
  513. adv_id1 = p2ps_advertise(r_dev=dev[0], r_role='0',
  514. svc_name='org.wi-fi.wfds.send.tx',
  515. srv_info='I can transfer files upto size of 2 GB')
  516. adv_id2 = p2ps_advertise(r_dev=dev[0], r_role='0',
  517. svc_name='org.wi-fi.wfds.send.rx',
  518. srv_info='I can receive files upto size of 2 GB')
  519. adv_id3 = p2ps_advertise(r_dev=dev[0], r_role='1',
  520. svc_name='org.wi-fi.wfds.display.tx',
  521. srv_info='Miracast Mode')
  522. adv_id4 = p2ps_advertise(r_dev=dev[0], r_role='1',
  523. svc_name='org.wi-fi.wfds.display.rx',
  524. srv_info='Miracast Mode')
  525. dev[1].global_request("P2P_SERV_DISC_REQ " + addr0 + " asp 1 org.wi-fi.wfds.display.tx 'Miracast Mode'")
  526. dev[1].global_request("P2P_FIND 10 type=social seek=org.wi-fi.wfds.display.tx")
  527. dev[1].global_request("P2P_SERV_DISC_REQ " + addr0 + " asp 2 org.wi-fi.wfds.send* 'size of 2 GB'")
  528. dev[1].p2p_stop_find()
  529. dev[1].global_request("P2P_FIND 10 type=social seek=")
  530. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  531. if ev is None:
  532. raise Exception("P2P Device Found timed out")
  533. if addr0 not in ev:
  534. raise Exception("Unexpected service discovery request source")
  535. ev_list = []
  536. for i in range(0, 3):
  537. ev = dev[1].wait_global_event(["P2P-SERV-ASP-RESP"], timeout=10)
  538. if ev is None:
  539. raise Exception("P2P Service discovery timed out")
  540. if addr0 in ev:
  541. ev_list.append(ev)
  542. if len(ev_list) == 3:
  543. break
  544. dev[1].p2p_stop_find()
  545. for test in [ ("seek=org.wi-fi.wfds.display.TX",
  546. "asp_svc=org.wi-fi.wfds.display.tx"),
  547. ("seek=foo seek=org.wi-fi.wfds.display.tx seek=bar",
  548. "asp_svc=org.wi-fi.wfds.display.tx"),
  549. ("seek=1 seek=2 seek=3 seek=org.wi-fi.wfds.display.tx seek=4 seek=5 seek=6",
  550. "asp_svc=org.wi-fi.wfds.display.tx"),
  551. ("seek=not-found", None),
  552. ("seek=org.wi-fi.wfds", "asp_svc=org.wi-fi.wfds")]:
  553. dev[2].global_request("P2P_FIND 10 type=social " + test[0])
  554. if test[1] is None:
  555. ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=1)
  556. if ev is not None:
  557. raise Exception("Unexpected device found: " + ev)
  558. continue
  559. ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  560. if ev is None:
  561. raise Exception("P2P device discovery timed out (dev2)")
  562. if test[1] not in ev:
  563. raise Exception("Expected asp_svc not reported: " + ev)
  564. dev[2].p2p_stop_find()
  565. dev[2].request("P2P_FLUSH")
  566. dev[0].p2p_stop_find()
  567. ev1 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id1))
  568. if ev1 is None:
  569. raise Exception("Unable to remove the advertisement instance")
  570. ev2 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id2))
  571. if ev2 is None:
  572. raise Exception("Unable to remove the advertisement instance")
  573. ev3 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id3))
  574. if ev3 is None:
  575. raise Exception("Unable to remove the advertisement instance")
  576. ev4 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id4))
  577. if ev4 is None:
  578. raise Exception("Unable to remove the advertisement instance")
  579. if "OK" not in dev[0].global_request("P2P_SERVICE_ADD asp 1 12345678 1 1108 org.wi-fi.wfds.foobar svc_info='Test'"):
  580. raise Exception("P2P_SERVICE_ADD failed")
  581. if "OK" not in dev[0].global_request("P2P_SERVICE_DEL asp all"):
  582. raise Exception("P2P_SERVICE_DEL asp all failed")
  583. if "OK" not in dev[0].global_request("P2P_SERVICE_ADD asp 1 12345678 1 1108 org.wi-fi.wfds.foobar svc_info='Test'"):
  584. raise Exception("P2P_SERVICE_ADD failed")
  585. if "OK" not in dev[0].global_request("P2P_SERVICE_REP asp 1 12345678 1 1108 org.wi-fi.wfds.foobar svc_info='Test'"):
  586. raise Exception("P2P_SERVICE_REP failed")
  587. if "FAIL" not in dev[0].global_request("P2P_SERVICE_REP asp 1 12345678 1 1108 org.wi-fi.wfds.Foo svc_info='Test'"):
  588. raise Exception("Invalid P2P_SERVICE_REP accepted")
  589. if "OK" not in dev[0].global_request("P2P_SERVICE_ADD asp 1 a2345678 1 1108 org.wi-fi.wfds.something svc_info='Test'"):
  590. raise Exception("P2P_SERVICE_ADD failed")
  591. if "OK" not in dev[0].global_request("P2P_SERVICE_ADD asp 1 a2345679 1 1108 org.wi-fi.wfds.Foo svc_info='Test'"):
  592. raise Exception("P2P_SERVICE_ADD failed")
  593. def get_ifnames():
  594. with open('/proc/net/dev', 'r') as f:
  595. data = f.read()
  596. ifnames = []
  597. for line in data.splitlines():
  598. ifname = line.strip().split(' ')[0]
  599. if ':' not in ifname:
  600. continue
  601. ifname = ifname.split(':')[0]
  602. ifnames.append(ifname)
  603. return ifnames
  604. def p2ps_connect_p2ps_method(dev, keep_group=False):
  605. dev[0].flush_scan_cache()
  606. dev[1].flush_scan_cache()
  607. p2ps_advertise(r_dev=dev[0], r_role='2', svc_name='org.wi-fi.wfds.send.rx',
  608. srv_info='I can receive files upto size 2 GB')
  609. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  610. svc_name='org.wi-fi.wfds.send.rx',
  611. srv_info='2 GB')
  612. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  613. ifnames = get_ifnames()
  614. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  615. grp_ifname0 = dev[0].get_group_ifname()
  616. grp_ifname1 = dev[1].get_group_ifname()
  617. if not keep_group:
  618. ev0 = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  619. if ev0 is None:
  620. raise Exception("Unable to remove the advertisement instance")
  621. ifnames = ifnames + get_ifnames()
  622. remove_group(dev[0], dev[1])
  623. ifnames = ifnames + get_ifnames()
  624. return grp_ifname0, grp_ifname1, ifnames
  625. def has_string_prefix(vals, prefix):
  626. for val in vals:
  627. if val.startswith(prefix):
  628. return True
  629. return False
  630. def test_p2ps_connect_p2ps_method_1(dev):
  631. """P2PS connection with P2PS method - no group interface"""
  632. set_no_group_iface(dev[0], 1)
  633. set_no_group_iface(dev[1], 1)
  634. (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev)
  635. if grp_ifname0 != dev[0].ifname:
  636. raise Exception("unexpected dev0 group ifname: " + grp_ifname0)
  637. if grp_ifname1 != dev[1].ifname:
  638. raise Exception("unexpected dev1 group ifname: " + grp_ifname1)
  639. if has_string_prefix(ifnames, 'p2p-' + grp_ifname0):
  640. raise Exception("dev0 group interface unexpectedly present")
  641. if has_string_prefix(ifnames, 'p2p-' + grp_ifname1):
  642. raise Exception("dev1 group interface unexpectedly present")
  643. def test_p2ps_connect_p2ps_method_2(dev):
  644. """P2PS connection with P2PS method - group interface on dev0"""
  645. set_no_group_iface(dev[0], 0)
  646. set_no_group_iface(dev[1], 1)
  647. (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev)
  648. if not grp_ifname0.startswith('p2p-' + dev[0].ifname + '-'):
  649. raise Exception("unexpected dev0 group ifname: " + grp_ifname0)
  650. if grp_ifname1 != dev[1].ifname:
  651. raise Exception("unexpected dev1 group ifname: " + grp_ifname1)
  652. if has_string_prefix(ifnames, 'p2p-' + grp_ifname0):
  653. raise Exception("dev0 group interface unexpectedly present")
  654. def test_p2ps_connect_p2ps_method_3(dev):
  655. """P2PS connection with P2PS method - group interface on dev1"""
  656. set_no_group_iface(dev[0], 1)
  657. set_no_group_iface(dev[1], 0)
  658. (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev)
  659. if grp_ifname0 != dev[0].ifname:
  660. raise Exception("unexpected dev0 group ifname: " + grp_ifname0)
  661. if not grp_ifname1.startswith('p2p-' + dev[1].ifname + '-'):
  662. raise Exception("unexpected dev1 group ifname: " + grp_ifname1)
  663. if has_string_prefix(ifnames, 'p2p-' + grp_ifname0):
  664. raise Exception("dev0 group interface unexpectedly present")
  665. def test_p2ps_connect_p2ps_method_4(dev):
  666. """P2PS connection with P2PS method - group interface on both"""
  667. set_no_group_iface(dev[0], 0)
  668. set_no_group_iface(dev[1], 0)
  669. (grp_ifname0, grp_ifname1, ifnames) = p2ps_connect_p2ps_method(dev)
  670. if not grp_ifname0.startswith('p2p-' + dev[0].ifname + '-'):
  671. raise Exception("unexpected dev0 group ifname: " + res0['ifname'])
  672. if not grp_ifname1.startswith('p2p-' + dev[1].ifname + '-'):
  673. raise Exception("unexpected dev1 group ifname: " + res1['ifname'])
  674. def test_p2ps_connect_adv_go_persistent(dev):
  675. """P2PS auto-accept connection with advertisement as GO and having persistent group"""
  676. go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15,
  677. r_dev=dev[1], r_intent=0)
  678. dev[0].remove_group()
  679. dev[1].wait_go_ending_session()
  680. p2ps_advertise(r_dev=dev[0], r_role='4', svc_name='org.wi-fi.wfds.send.rx',
  681. srv_info='I can receive files upto size 2 GB')
  682. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  683. svc_name='org.wi-fi.wfds.send.rx',
  684. srv_info='2 GB')
  685. ev1, ev0 = p2ps_provision(dev[1], dev[0], adv_id)
  686. if "persist=" not in ev0 or "persist=" not in ev1:
  687. raise Exception("Persistent group isn't used by peers")
  688. p2ps_connect_pd(dev[0], dev[1], ev0, ev1)
  689. remove_group(dev[0], dev[1])
  690. def test_p2ps_client_probe(dev):
  691. """P2PS CLI discoverability on operating channel"""
  692. cli_probe = dev[0].global_request("SET p2p_cli_probe 1")
  693. p2ps_connect_p2ps_method(dev, keep_group=True)
  694. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[2], r_dev=dev[0],
  695. svc_name='org.wi-fi.wfds.send.rx',
  696. single_peer_expected=False)
  697. dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  698. remove_group(dev[0], dev[1])
  699. def test_p2ps_go_probe(dev):
  700. """P2PS GO discoverability on operating channel"""
  701. p2ps_connect_adv_go_pin_method(dev, keep_group=True)
  702. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[2], r_dev=dev[0],
  703. svc_name='org.wi-fi.wfds.send.rx',
  704. single_peer_expected=False)
  705. dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  706. remove_group(dev[0], dev[1])
  707. def test_p2ps_wildcard_p2ps(dev):
  708. """P2PS wildcard SD Probe Request/Response"""
  709. p2ps_wildcard = "org.wi-fi.wfds"
  710. adv_id = p2ps_advertise(r_dev=dev[0], r_role='1',
  711. svc_name='org.foo.service',
  712. srv_info='I can do stuff')
  713. adv_id2 = p2ps_advertise(r_dev=dev[0], r_role='1',
  714. svc_name='org.wi-fi.wfds.send.rx',
  715. srv_info='I can receive files upto size 2 GB')
  716. if "OK" not in dev[1].global_request("P2P_FIND 10 type=social seek=org.foo.service seek=" + p2ps_wildcard):
  717. raise Exception("Failed on P2P_FIND command")
  718. ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  719. if ev1 is None:
  720. raise Exception("P2P-DEVICE-FOUND timeout on seeker side")
  721. if dev[0].p2p_dev_addr() not in ev1:
  722. raise Exception("Unexpected peer")
  723. ev2 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  724. if ev2 is None:
  725. raise Exception("P2P-DEVICE-FOUND timeout on seeker side (2)")
  726. if dev[0].p2p_dev_addr() not in ev2:
  727. raise Exception("Unexpected peer (2)")
  728. if p2ps_wildcard not in ev1 + ev2:
  729. raise Exception("P2PS Wildcard name not found in P2P-DEVICE-FOUND event")
  730. if "org.foo.service" not in ev1 + ev2:
  731. raise Exception("Vendor specific service name not found in P2P-DEVICE-FOUND event")
  732. if "OK" not in dev[1].global_request("P2P_STOP_FIND"):
  733. raise Exception("P2P_STOP_FIND failed")
  734. dev[1].dump_monitor()
  735. res = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  736. if res is None:
  737. raise Exception("Unable to remove the advertisement instance")
  738. if "OK" not in dev[1].global_request("P2P_FIND 10 type=social seek=" + p2ps_wildcard):
  739. raise Exception("Failed on P2P_FIND command")
  740. ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  741. if ev1 is None:
  742. raise Exception("P2P-DEVICE-FOUND timeout on seeker side")
  743. if dev[0].p2p_dev_addr() not in ev1:
  744. raise Exception("Unexpected peer")
  745. if p2ps_wildcard not in ev1:
  746. raise Exception("P2PS Wildcard name not found in P2P-DEVICE-FOUND event (2)")
  747. dev[1].dump_monitor()
  748. res = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id2))
  749. if res is None:
  750. raise Exception("Unable to remove the advertisement instance 2")
  751. if "OK" not in dev[1].global_request("P2P_FIND 10 type=social seek=" + p2ps_wildcard):
  752. raise Exception("Failed on P2P_FIND command")
  753. ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=2)
  754. if ev1 is not None:
  755. raise Exception("Unexpected P2P-DEVICE-FOUND event on seeker side")
  756. dev[1].p2p_stop_find()
  757. dev[1].dump_monitor()
  758. def test_p2ps_many_services_in_probe(dev):
  759. """P2PS with large number of services in Probe Request/Response"""
  760. long1 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.a'
  761. long2 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.b'
  762. long3 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.c'
  763. long4 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.d'
  764. long5 = 'org.example.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.e'
  765. for name in [ long1, long2, long3, long4, long5 ]:
  766. p2ps_advertise(r_dev=dev[0], r_role='1',
  767. svc_name=name,
  768. srv_info='I can do stuff')
  769. 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)):
  770. raise Exception("Failed on P2P_FIND command")
  771. events = ""
  772. # Note: Require only four events since all the services do not fit within
  773. # the length limit.
  774. for i in range(4):
  775. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  776. if ev is None:
  777. raise Exception("Missing P2P-DEVICE-FOUND")
  778. events = events + ev
  779. dev[1].p2p_stop_find()
  780. dev[1].dump_monitor()
  781. for name in [ long2, long3, long4, long5 ]:
  782. if name not in events:
  783. raise Exception("Service missing from peer events")
  784. def p2ps_test_feature_capability_cpt(dev, adv_cpt, seeker_cpt, adv_role,
  785. result):
  786. p2ps_advertise(r_dev=dev[0], r_role=adv_role,
  787. svc_name='org.wi-fi.wfds.send.rx',
  788. srv_info='I can receive files upto size 2 GB', cpt=adv_cpt)
  789. [adv_id, rcvd_svc_name] = p2ps_exact_seek(i_dev=dev[1], r_dev=dev[0],
  790. svc_name='org.wi-fi.wfds.send.rx',
  791. srv_info='2 GB')
  792. auto_accept = adv_role != "0"
  793. ev1, ev0, pin = p2ps_provision(dev[1], dev[0], adv_id,
  794. auto_accept=auto_accept, adv_cpt=adv_cpt,
  795. seeker_cpt=seeker_cpt, method="8")
  796. status0, fcap0 = p2ps_parse_event(ev0, "status", "feature_cap")
  797. status1, fcap1 = p2ps_parse_event(ev0, "status", "feature_cap")
  798. if fcap0 is None:
  799. raise Exception("Bad feature capability on Seeker side")
  800. if fcap1 is None:
  801. raise Exception("Bad feature capability on Advertiser side")
  802. if fcap0 != fcap1:
  803. raise Exception("Incompatible feature capability values")
  804. if status0 not in ("0", "12") or status1 not in ("0", "12"):
  805. raise Exception("Unexpected PD result status")
  806. if result == "UDP" and fcap0[1] != "1":
  807. raise Exception("Unexpected CPT feature capability value (expected: UDP)")
  808. elif result == "MAC" and fcap0[1] != "2":
  809. raise Exception("Unexpected CPT feature capability value (expected: MAC)")
  810. ev = dev[0].global_request("P2P_SERVICE_DEL asp " + str(adv_id))
  811. if ev is None:
  812. raise Exception("Unable to remove the advertisement instance")
  813. def test_p2ps_feature_capability_mac_autoaccept(dev):
  814. """P2PS PD Feature Capability CPT: advertiser MAC, seeker UDP:MAC, autoaccept"""
  815. p2ps_test_feature_capability_cpt(dev, adv_cpt="MAC", seeker_cpt="UDP:MAC",
  816. adv_role="4", result="MAC")
  817. def test_p2ps_feature_capability_mac_nonautoaccept(dev):
  818. """P2PS PD Feature Capability CPT: advertiser:MAC, seeker UDP:MAC, nonautoaccept"""
  819. p2ps_test_feature_capability_cpt(dev, adv_cpt="MAC", seeker_cpt="UDP:MAC",
  820. adv_role="0", result="MAC")
  821. def test_p2ps_feature_capability_mac_udp_autoaccept(dev):
  822. """P2PS PD Feature Capability CPT: advertiser MAC:UDP, seeker UDP:MAC, autoaccept"""
  823. p2ps_test_feature_capability_cpt(dev, adv_cpt="MAC:UDP",
  824. seeker_cpt="UDP:MAC", adv_role="2",
  825. result="MAC")
  826. def test_p2ps_feature_capability_mac_udp_nonautoaccept(dev):
  827. """P2PS PD Feature Capability CPT: advertiser MAC:UDP, seeker UDP:MAC, nonautoaccept"""
  828. p2ps_test_feature_capability_cpt(dev, adv_cpt="MAC:UDP",
  829. seeker_cpt="UDP:MAC", adv_role="0",
  830. result="UDP")
  831. def test_p2ps_feature_capability_udp_mac_autoaccept(dev):
  832. """P2PS PD Feature Capability CPT: advertiser UDP:MAC, seeker MAC:UDP, autoaccept"""
  833. p2ps_test_feature_capability_cpt(dev, adv_cpt="UDP:MAC",
  834. seeker_cpt="MAC:UDP", adv_role="2",
  835. result="UDP")
  836. def test_p2ps_feature_capability_udp_mac_nonautoaccept(dev):
  837. """P2PS PD Feature Capability CPT: advertiser UDP:MAC, seeker MAC:UDP, nonautoaccept"""
  838. p2ps_test_feature_capability_cpt(dev, adv_cpt="UDP:MAC",
  839. seeker_cpt="MAC:UDP", adv_role="0",
  840. result="MAC")