test_p2p_ext.py 15 KB

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