test_p2p_ext.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. # P2P vendor specific extension tests
  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 os
  10. from tshark import run_tshark
  11. from p2p_utils import *
  12. @remote_compatible
  13. def test_p2p_ext_discovery(dev):
  14. """P2P device discovery with vendor specific extensions"""
  15. addr0 = dev[0].p2p_dev_addr()
  16. addr1 = dev[1].p2p_dev_addr()
  17. try:
  18. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 1 dd050011223344"):
  19. raise Exception("VENDOR_ELEM_ADD failed")
  20. res = dev[0].request("VENDOR_ELEM_GET 1")
  21. if res != "dd050011223344":
  22. raise Exception("Unexpected VENDOR_ELEM_GET result: " + res)
  23. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 1 dd06001122335566"):
  24. raise Exception("VENDOR_ELEM_ADD failed")
  25. res = dev[0].request("VENDOR_ELEM_GET 1")
  26. if res != "dd050011223344dd06001122335566":
  27. raise Exception("Unexpected VENDOR_ELEM_GET result(2): " + res)
  28. res = dev[0].request("VENDOR_ELEM_GET 2")
  29. if res != "":
  30. raise Exception("Unexpected VENDOR_ELEM_GET result(3): " + res)
  31. if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd050011223344"):
  32. raise Exception("VENDOR_ELEM_REMOVE failed")
  33. res = dev[0].request("VENDOR_ELEM_GET 1")
  34. if res != "dd06001122335566":
  35. raise Exception("Unexpected VENDOR_ELEM_GET result(4): " + res)
  36. if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd06001122335566"):
  37. raise Exception("VENDOR_ELEM_REMOVE failed")
  38. res = dev[0].request("VENDOR_ELEM_GET 1")
  39. if res != "":
  40. raise Exception("Unexpected VENDOR_ELEM_GET result(5): " + res)
  41. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 1 dd050011223344dd06001122335566"):
  42. raise Exception("VENDOR_ELEM_ADD failed(2)")
  43. if "FAIL" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd051122334455"):
  44. raise Exception("Unexpected VENDOR_ELEM_REMOVE success")
  45. if "FAIL" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd"):
  46. raise Exception("Unexpected VENDOR_ELEM_REMOVE success(2)")
  47. if "FAIL" not in dev[0].request("VENDOR_ELEM_ADD 1 ddff"):
  48. raise Exception("Unexpected VENDOR_ELEM_ADD success(3)")
  49. dev[0].p2p_listen()
  50. if not dev[1].discover_peer(addr0):
  51. raise Exception("Device discovery timed out")
  52. if not dev[0].discover_peer(addr1):
  53. raise Exception("Device discovery timed out")
  54. peer = dev[1].get_peer(addr0)
  55. if peer['vendor_elems'] != "dd050011223344dd06001122335566":
  56. raise Exception("Vendor elements not reported correctly")
  57. res = dev[0].request("VENDOR_ELEM_GET 1")
  58. if res != "dd050011223344dd06001122335566":
  59. raise Exception("Unexpected VENDOR_ELEM_GET result(6): " + res)
  60. if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 dd06001122335566"):
  61. raise Exception("VENDOR_ELEM_REMOVE failed")
  62. res = dev[0].request("VENDOR_ELEM_GET 1")
  63. if res != "dd050011223344":
  64. raise Exception("Unexpected VENDOR_ELEM_GET result(7): " + res)
  65. finally:
  66. dev[0].request("VENDOR_ELEM_REMOVE 1 *")
  67. @remote_compatible
  68. def test_p2p_ext_discovery_go(dev):
  69. """P2P device discovery with vendor specific extensions for GO"""
  70. addr0 = dev[0].p2p_dev_addr()
  71. addr1 = dev[1].p2p_dev_addr()
  72. try:
  73. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 2 dd050011223344dd06001122335566"):
  74. raise Exception("VENDOR_ELEM_ADD failed")
  75. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 3 dd050011223344dd06001122335566"):
  76. raise Exception("VENDOR_ELEM_ADD failed")
  77. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 12 dd050011223344dd06001122335566"):
  78. raise Exception("VENDOR_ELEM_ADD failed")
  79. dev[0].p2p_start_go(freq="2412")
  80. if not dev[1].discover_peer(addr0):
  81. raise Exception("Device discovery timed out")
  82. peer = dev[1].get_peer(addr0)
  83. if peer['vendor_elems'] != "dd050011223344dd06001122335566":
  84. print peer['vendor_elems']
  85. raise Exception("Vendor elements not reported correctly")
  86. finally:
  87. dev[0].request("VENDOR_ELEM_REMOVE 2 *")
  88. dev[0].request("VENDOR_ELEM_REMOVE 3 *")
  89. dev[0].request("VENDOR_ELEM_REMOVE 12 *")
  90. def test_p2p_ext_vendor_elem_probe_req(dev):
  91. """VENDOR_ELEM in P2P Probe Request frames"""
  92. try:
  93. _test_p2p_ext_vendor_elem_probe_req(dev)
  94. finally:
  95. dev[0].request("VENDOR_ELEM_REMOVE 0 *")
  96. def _test_p2p_ext_vendor_elem_probe_req(dev):
  97. addr1 = dev[1].p2p_dev_addr()
  98. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 0 dd050011223300"):
  99. raise Exception("VENDOR_ELEM_ADD failed")
  100. dev[1].p2p_listen()
  101. if not dev[0].discover_peer(addr1):
  102. raise Exception("Device discovery timed out")
  103. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
  104. raise Exception("Failed to enable external management frame handling")
  105. ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
  106. if ev is None:
  107. raise Exception("MGMT-RX timeout")
  108. if " 40" not in ev:
  109. raise Exception("Not a Probe Request frame")
  110. if "dd050011223300" not in ev:
  111. raise Exception("Vendor element not found from Probe Request frame")
  112. dev[0].p2p_stop_find()
  113. dev[1].p2p_stop_find()
  114. def test_p2p_ext_vendor_elem_pd_req(dev):
  115. """VENDOR_ELEM in PD Request frames"""
  116. try:
  117. _test_p2p_ext_vendor_elem_pd_req(dev)
  118. finally:
  119. dev[0].request("VENDOR_ELEM_REMOVE 4 *")
  120. def _test_p2p_ext_vendor_elem_pd_req(dev):
  121. addr0 = dev[0].p2p_dev_addr()
  122. addr1 = dev[1].p2p_dev_addr()
  123. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 4 dd050011223301"):
  124. raise Exception("VENDOR_ELEM_ADD failed")
  125. dev[1].p2p_listen()
  126. if not dev[0].discover_peer(addr1):
  127. raise Exception("Device discovery timed out")
  128. dev[0].p2p_stop_find()
  129. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
  130. raise Exception("Failed to enable external management frame handling")
  131. dev[0].global_request("P2P_PROV_DISC " + addr1 + " display")
  132. for i in range(5):
  133. ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
  134. if ev is None:
  135. raise Exception("MGMT-RX timeout")
  136. if " d0" in ev:
  137. break
  138. if "dd050011223301" not in ev:
  139. raise Exception("Vendor element not found from PD Request frame")
  140. dev[1].p2p_stop_find()
  141. dev[0].p2p_stop_find()
  142. def test_p2p_ext_vendor_elem_pd_resp(dev):
  143. """VENDOR_ELEM in PD Response frames"""
  144. try:
  145. _test_p2p_ext_vendor_elem_pd_resp(dev)
  146. finally:
  147. dev[0].request("VENDOR_ELEM_REMOVE 5 *")
  148. def _test_p2p_ext_vendor_elem_pd_resp(dev):
  149. addr0 = dev[0].p2p_dev_addr()
  150. addr1 = dev[1].p2p_dev_addr()
  151. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 5 dd050011223302"):
  152. raise Exception("VENDOR_ELEM_ADD failed")
  153. dev[0].p2p_listen()
  154. if not dev[1].discover_peer(addr0):
  155. raise Exception("Device discovery timed out")
  156. dev[1].p2p_stop_find()
  157. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
  158. raise Exception("Failed to enable external management frame handling")
  159. dev[1].global_request("P2P_PROV_DISC " + addr0 + " display")
  160. for i in range(5):
  161. ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
  162. if ev is None:
  163. raise Exception("MGMT-RX timeout")
  164. if " d0" in ev:
  165. break
  166. if "dd050011223302" not in ev:
  167. raise Exception("Vendor element not found from PD Response frame")
  168. dev[0].p2p_stop_find()
  169. dev[1].p2p_stop_find()
  170. def test_p2p_ext_vendor_elem_go_neg_req(dev):
  171. """VENDOR_ELEM in GO Negotiation Request frames"""
  172. try:
  173. _test_p2p_ext_vendor_elem_go_neg_req(dev)
  174. finally:
  175. dev[0].request("VENDOR_ELEM_REMOVE 6 *")
  176. def _test_p2p_ext_vendor_elem_go_neg_req(dev):
  177. addr0 = dev[0].p2p_dev_addr()
  178. addr1 = dev[1].p2p_dev_addr()
  179. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 6 dd050011223303"):
  180. raise Exception("VENDOR_ELEM_ADD failed")
  181. dev[1].p2p_listen()
  182. if not dev[0].discover_peer(addr1):
  183. raise Exception("Device discovery timed out")
  184. dev[0].p2p_stop_find()
  185. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
  186. raise Exception("Failed to enable external management frame handling")
  187. dev[0].global_request("P2P_CONNECT " + addr1 + " 12345670 display")
  188. for i in range(5):
  189. ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
  190. if ev is None:
  191. raise Exception("MGMT-RX timeout")
  192. if " d0" in ev:
  193. break
  194. if "dd050011223303" not in ev:
  195. raise Exception("Vendor element not found from GO Negotiation Request frame")
  196. dev[1].p2p_stop_find()
  197. dev[0].p2p_stop_find()
  198. def test_p2p_ext_vendor_elem_go_neg_resp(dev):
  199. """VENDOR_ELEM in GO Negotiation Response frames"""
  200. try:
  201. _test_p2p_ext_vendor_elem_go_neg_resp(dev)
  202. finally:
  203. dev[0].request("VENDOR_ELEM_REMOVE 7 *")
  204. def _test_p2p_ext_vendor_elem_go_neg_resp(dev):
  205. addr0 = dev[0].p2p_dev_addr()
  206. addr1 = dev[1].p2p_dev_addr()
  207. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 7 dd050011223304"):
  208. raise Exception("VENDOR_ELEM_ADD failed")
  209. dev[0].p2p_listen()
  210. if not dev[1].discover_peer(addr0):
  211. raise Exception("Device discovery timed out")
  212. dev[1].p2p_stop_find()
  213. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
  214. raise Exception("Failed to enable external management frame handling")
  215. dev[1].global_request("P2P_CONNECT " + addr0 + " 12345670 display")
  216. for i in range(5):
  217. ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
  218. if ev is None:
  219. raise Exception("MGMT-RX timeout")
  220. if " d0" in ev:
  221. break
  222. if "dd050011223304" not in ev:
  223. raise Exception("Vendor element not found from GO Negotiation Response frame")
  224. dev[0].p2p_stop_find()
  225. dev[1].p2p_stop_find()
  226. def test_p2p_ext_vendor_elem_go_neg_conf(dev, apdev, params):
  227. """VENDOR_ELEM in GO Negotiation Confirm frames"""
  228. try:
  229. _test_p2p_ext_vendor_elem_go_neg_conf(dev, apdev, params)
  230. finally:
  231. dev[0].request("VENDOR_ELEM_REMOVE 8 *")
  232. def _test_p2p_ext_vendor_elem_go_neg_conf(dev, apdev, params):
  233. addr0 = dev[0].p2p_dev_addr()
  234. addr1 = dev[1].p2p_dev_addr()
  235. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 8 dd050011223305"):
  236. raise Exception("VENDOR_ELEM_ADD failed")
  237. dev[0].p2p_listen()
  238. dev[1].p2p_go_neg_auth(addr0, "12345670", "enter")
  239. dev[1].p2p_listen()
  240. dev[0].p2p_go_neg_init(addr1, "12345678", "display")
  241. ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
  242. if ev is None:
  243. raise Exception("GO negotiation timed out")
  244. ev = dev[0].wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=15)
  245. if ev is None:
  246. raise Exception("Group formation failure not indicated")
  247. dev[0].dump_monitor()
  248. dev[1].p2p_go_neg_auth_result(expect_failure=True)
  249. dev[1].dump_monitor()
  250. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  251. "wifi_p2p.public_action.subtype == 2")
  252. if "Vendor Specific Data: 3305" not in out:
  253. raise Exception("Vendor element not found from GO Negotiation Confirm frame")
  254. def test_p2p_ext_vendor_elem_invitation(dev):
  255. """VENDOR_ELEM in Invitation frames"""
  256. try:
  257. _test_p2p_ext_vendor_elem_invitation(dev)
  258. finally:
  259. dev[0].request("VENDOR_ELEM_REMOVE 9 *")
  260. dev[0].request("VENDOR_ELEM_REMOVE 10 *")
  261. def _test_p2p_ext_vendor_elem_invitation(dev):
  262. addr0 = dev[0].p2p_dev_addr()
  263. addr1 = dev[1].p2p_dev_addr()
  264. form(dev[0], dev[1])
  265. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 9 dd050011223306"):
  266. raise Exception("VENDOR_ELEM_ADD failed")
  267. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 10 dd050011223307"):
  268. raise Exception("VENDOR_ELEM_ADD failed")
  269. dev[1].p2p_listen()
  270. if not dev[0].discover_peer(addr1):
  271. raise Exception("Device discovery timed out")
  272. peer = dev[0].get_peer(addr1)
  273. dev[0].p2p_stop_find()
  274. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
  275. raise Exception("Failed to enable external management frame handling")
  276. dev[0].global_request("P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr1)
  277. for i in range(5):
  278. ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
  279. if ev is None:
  280. raise Exception("MGMT-RX timeout")
  281. if " d0" in ev:
  282. break
  283. if "dd050011223306" not in ev:
  284. raise Exception("Vendor element not found from Invitation Request frame")
  285. dev[0].p2p_stop_find()
  286. dev[1].p2p_stop_find()
  287. dev[0].p2p_listen()
  288. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 0"):
  289. raise Exception("Failed to disable external management frame handling")
  290. if not dev[1].discover_peer(addr0):
  291. raise Exception("Device discovery timed out")
  292. peer = dev[1].get_peer(addr0)
  293. dev[1].p2p_stop_find()
  294. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
  295. raise Exception("Failed to enable external management frame handling")
  296. dev[1].global_request("P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr0)
  297. for i in range(5):
  298. ev = dev[1].wait_event(["MGMT-RX"], timeout=5)
  299. if ev is None:
  300. raise Exception("MGMT-RX timeout")
  301. if " d0" in ev:
  302. break
  303. if "dd050011223307" not in ev:
  304. raise Exception("Vendor element not found from Invitation Response frame")
  305. dev[0].p2p_stop_find()
  306. dev[1].p2p_stop_find()
  307. def test_p2p_ext_vendor_elem_assoc(dev, apdev, params):
  308. """VENDOR_ELEM in Association frames"""
  309. try:
  310. _test_p2p_ext_vendor_elem_assoc(dev, apdev, params)
  311. finally:
  312. dev[0].request("VENDOR_ELEM_REMOVE 11 *")
  313. dev[1].request("VENDOR_ELEM_REMOVE 12 *")
  314. dev[0].request("VENDOR_ELEM_REMOVE 13 *")
  315. def _test_p2p_ext_vendor_elem_assoc(dev, apdev, params):
  316. addr0 = dev[0].p2p_dev_addr()
  317. addr1 = dev[1].p2p_dev_addr()
  318. res = dev[0].get_driver_status()
  319. p2p_device = True if (int(res['capa.flags'], 0) & 0x20000000) else False
  320. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 11 dd050011223308"):
  321. raise Exception("VENDOR_ELEM_ADD failed")
  322. if "OK" not in dev[1].request("VENDOR_ELEM_ADD 12 dd050011223309"):
  323. raise Exception("VENDOR_ELEM_ADD failed")
  324. if not p2p_device and "OK" not in dev[0].request("VENDOR_ELEM_ADD 13 dd05001122330a"):
  325. raise Exception("VENDOR_ELEM_ADD failed")
  326. dev[0].p2p_listen()
  327. dev[1].p2p_listen()
  328. dev[1].p2p_go_neg_auth(addr0, "12345670", "enter", go_intent=15)
  329. dev[0].p2p_go_neg_init(addr1, "12345670", "display", go_intent=0,
  330. timeout=15)
  331. dev[1].p2p_go_neg_auth_result()
  332. dev[1].remove_group()
  333. dev[0].wait_go_ending_session()
  334. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  335. "wlan.fc.type_subtype == 0x00", wait=False)
  336. if "Vendor Specific Data: 3308" not in out:
  337. raise Exception("Vendor element (P2P) not found from Association Request frame")
  338. if not p2p_device and "Vendor Specific Data: 330a" not in out:
  339. raise Exception("Vendor element (non-P2P) not found from Association Request frame")
  340. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  341. "wlan.fc.type_subtype == 0x01", wait=False)
  342. if "Vendor Specific Data: 3309" not in out:
  343. raise Exception("Vendor element not found from Association Response frame")