test_p2p_wifi_display.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. # Wi-Fi Display test cases
  2. # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
  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 threading
  10. import Queue
  11. import hwsim_utils
  12. import utils
  13. from p2p_utils import *
  14. def test_wifi_display(dev):
  15. """Wi-Fi Display extensions to P2P"""
  16. wfd_devinfo = "00411c440028"
  17. dev[0].request("SET wifi_display 1")
  18. dev[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo)
  19. if wfd_devinfo not in dev[0].request("WFD_SUBELEM_GET 0"):
  20. raise Exception("Could not fetch back configured subelement")
  21. # Associated BSSID
  22. dev[0].request("WFD_SUBELEM_SET 1 0006020304050607")
  23. # Coupled Sink
  24. dev[0].request("WFD_SUBELEM_SET 6 000700000000000000")
  25. # Session Info
  26. dev[0].request("WFD_SUBELEM_SET 9 0000")
  27. # WFD Extended Capability
  28. dev[0].request("WFD_SUBELEM_SET 7 00020000")
  29. # WFD Content Protection
  30. prot = "0001" + "00"
  31. dev[0].request("WFD_SUBELEM_SET 5 " + prot)
  32. # WFD Video Formats
  33. video = "0015" + "010203040506070809101112131415161718192021"
  34. dev[0].request("WFD_SUBELEM_SET 3 " + video)
  35. # WFD 3D Video Formats
  36. video_3d = "0011" + "0102030405060708091011121314151617"
  37. dev[0].request("WFD_SUBELEM_SET 4 " + video_3d)
  38. # WFD Audio Formats
  39. audio = "000f" + "010203040506070809101112131415"
  40. dev[0].request("WFD_SUBELEM_SET 2 " + audio)
  41. elems = dev[0].request("WFD_SUBELEM_GET all")
  42. if wfd_devinfo not in elems:
  43. raise Exception("Could not fetch back configured subelements")
  44. wfd_devinfo2 = "00001c440028"
  45. dev[1].request("SET wifi_display 1")
  46. dev[1].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo2)
  47. if wfd_devinfo2 not in dev[1].request("WFD_SUBELEM_GET 0"):
  48. raise Exception("Could not fetch back configured subelement")
  49. dev[0].p2p_listen()
  50. if "FAIL" in dev[1].global_request("P2P_SERV_DISC_REQ " + dev[0].p2p_dev_addr() + " wifi-display [source][pri-sink] 2,3,4,5"):
  51. raise Exception("Setting SD request failed")
  52. dev[1].p2p_find(social=True)
  53. ev = dev[0].wait_global_event(["P2P-SERV-DISC-REQ"], timeout=10)
  54. if ev is None:
  55. raise Exception("Device discovery request not reported")
  56. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  57. if ev is None:
  58. raise Exception("Device discovery timed out")
  59. if "wfd_dev_info=0x" + wfd_devinfo not in ev:
  60. raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
  61. if "new=1" not in ev:
  62. raise Exception("new=1 flag missing from P2P-DEVICE-FOUND event")
  63. ev = dev[1].wait_global_event(["P2P-SERV-DISC-RESP"], timeout=5)
  64. if ev is None:
  65. raise Exception("Service discovery timed out")
  66. if prot not in ev:
  67. raise Exception("WFD Content Protection missing from WSD response")
  68. if video not in ev:
  69. raise Exception("WFD Video Formats missing from WSD response")
  70. if video_3d not in ev:
  71. raise Exception("WFD 3D Video Formats missing from WSD response")
  72. if audio not in ev:
  73. raise Exception("WFD Audio Formats missing from WSD response")
  74. dev[1].dump_monitor()
  75. dev[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo2)
  76. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=15)
  77. if ev is None:
  78. raise Exception("Peer info update timed out")
  79. if "new=0" not in ev:
  80. raise Exception("new=0 flag missing from P2P-DEVICE-FOUND event")
  81. if "wfd_dev_info=0x" + wfd_devinfo2 not in ev:
  82. raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
  83. dev[1].dump_monitor()
  84. dev[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo)
  85. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=15)
  86. if ev is None:
  87. raise Exception("Peer info update timed out")
  88. if "new=0" not in ev:
  89. raise Exception("new=0 flag missing from P2P-DEVICE-FOUND event")
  90. if "wfd_dev_info=0x" + wfd_devinfo not in ev:
  91. raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
  92. pin = dev[0].wps_read_pin()
  93. dev[0].p2p_go_neg_auth(dev[1].p2p_dev_addr(), pin, 'display')
  94. res1 = dev[1].p2p_go_neg_init(dev[0].p2p_dev_addr(), pin, 'enter',
  95. timeout=20, go_intent=15, freq=2437)
  96. res2 = dev[0].p2p_go_neg_auth_result()
  97. bss = dev[0].get_bss("p2p_dev_addr=" + dev[1].p2p_dev_addr())
  98. if bss['bssid'] != dev[1].p2p_interface_addr():
  99. raise Exception("Unexpected BSSID in the BSS entry for the GO")
  100. if wfd_devinfo2 not in bss['wfd_subelems']:
  101. raise Exception("Could not see wfd_subelems in GO's BSS entry")
  102. peer = dev[0].get_peer(dev[1].p2p_dev_addr())
  103. if wfd_devinfo2 not in peer['wfd_subelems']:
  104. raise Exception("Could not see wfd_subelems in GO's peer entry")
  105. peer = dev[1].get_peer(dev[0].p2p_dev_addr())
  106. if wfd_devinfo not in peer['wfd_subelems']:
  107. raise Exception("Could not see wfd_subelems in client's peer entry")
  108. wfd_devinfo3 = "00001c440028"
  109. dev[2].request("SET wifi_display 1")
  110. dev[2].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo3)
  111. dev[2].p2p_find(social=True)
  112. ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  113. if ev is None:
  114. raise Exception("Device discovery timed out")
  115. if dev[1].p2p_dev_addr() not in ev:
  116. ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  117. if ev is None:
  118. raise Exception("Device discovery timed out")
  119. if dev[1].p2p_dev_addr() not in ev:
  120. raise Exception("Could not discover GO")
  121. if "wfd_dev_info=0x" + wfd_devinfo2 not in ev:
  122. raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
  123. bss = dev[2].get_bss("p2p_dev_addr=" + dev[1].p2p_dev_addr())
  124. if bss['bssid'] != dev[1].p2p_interface_addr():
  125. raise Exception("Unexpected BSSID in the BSS entry for the GO")
  126. if wfd_devinfo2 not in bss['wfd_subelems']:
  127. raise Exception("Could not see wfd_subelems in GO's BSS entry")
  128. peer = dev[2].get_peer(dev[1].p2p_dev_addr())
  129. if wfd_devinfo2 not in peer['wfd_subelems']:
  130. raise Exception("Could not see wfd_subelems in GO's peer entry")
  131. dev[2].p2p_stop_find()
  132. if dev[0].request("WFD_SUBELEM_GET 2") != audio:
  133. raise Exception("Unexpected WFD_SUBELEM_GET 2 value")
  134. if dev[0].request("WFD_SUBELEM_GET 3") != video:
  135. raise Exception("Unexpected WFD_SUBELEM_GET 3 value")
  136. if dev[0].request("WFD_SUBELEM_GET 4") != video_3d:
  137. raise Exception("Unexpected WFD_SUBELEM_GET 42 value")
  138. if dev[0].request("WFD_SUBELEM_GET 5") != prot:
  139. raise Exception("Unexpected WFD_SUBELEM_GET 5 value")
  140. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET "):
  141. raise Exception("Unexpected WFD_SUBELEM_SET success")
  142. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET 6"):
  143. raise Exception("Unexpected WFD_SUBELEM_SET success")
  144. if "OK" not in dev[0].request("WFD_SUBELEM_SET 6 "):
  145. raise Exception("Unexpected WFD_SUBELEM_SET failure")
  146. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET 6 0"):
  147. raise Exception("Unexpected WFD_SUBELEM_SET success")
  148. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET 6 0q"):
  149. raise Exception("Unexpected WFD_SUBELEM_SET success")
  150. if dev[0].request("WFD_SUBELEM_GET 6") != "":
  151. raise Exception("Unexpected WFD_SUBELEM_GET 6 response")
  152. if dev[0].request("WFD_SUBELEM_GET 8") != "":
  153. raise Exception("Unexpected WFD_SUBELEM_GET 8 response")
  154. if dev[0].global_request("WFD_SUBELEM_GET 2") != audio:
  155. raise Exception("Unexpected WFD_SUBELEM_GET 2 value from global interface")
  156. if "OK" not in dev[0].global_request("WFD_SUBELEM_SET 1 0006020304050608"):
  157. raise Exception("WFD_SUBELEM_SET failed on global interface")
  158. if dev[0].request("WFD_SUBELEM_GET 1") != "0006020304050608":
  159. raise Exception("Unexpected WFD_SUBELEM_GET 1 value (per-interface)")
  160. elems = dev[0].request("WFD_SUBELEM_GET all")
  161. if "OK" not in dev[0].request("WFD_SUBELEM_SET all " + elems):
  162. raise Exception("WFD_SUBELEM_SET all failed")
  163. if dev[0].request("WFD_SUBELEM_GET all") != elems:
  164. raise Exception("Mismatch in WFS_SUBELEM_SET/GET all")
  165. test = "00000600411c440028"
  166. if "OK" not in dev[0].request("WFD_SUBELEM_SET all " + test):
  167. raise Exception("WFD_SUBELEM_SET all failed")
  168. if dev[0].request("WFD_SUBELEM_GET all") != test:
  169. raise Exception("Mismatch in WFS_SUBELEM_SET/GET all")
  170. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET all qwerty"):
  171. raise Exception("Invalid WFD_SUBELEM_SET all succeeded")
  172. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET all 11"):
  173. raise Exception("Invalid WFD_SUBELEM_SET all succeeded")
  174. dev[0].request("WFD_SUBELEM_SET all 112233445566")
  175. dev[0].request("WFD_SUBELEM_SET all ff0000fe0000fd00")
  176. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET 300 112233"):
  177. raise Exception("Invalid WFD_SUBELEM_SET 300 succeeded")
  178. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET -1 112233"):
  179. raise Exception("Invalid WFD_SUBELEM_SET -1 succeeded")
  180. if "FAIL" not in dev[0].request("WFD_SUBELEM_GET 300"):
  181. raise Exception("Invalid WFD_SUBELEM_GET 300 succeeded")
  182. if "FAIL" not in dev[0].request("WFD_SUBELEM_GET -1"):
  183. raise Exception("Invalid WFD_SUBELEM_GET -1 succeeded")
  184. dev[0].request("SET wifi_display 0")
  185. dev[1].request("SET wifi_display 0")
  186. dev[2].request("SET wifi_display 0")
  187. def enable_wifi_display(dev):
  188. dev.request("SET wifi_display 1")
  189. dev.request("WFD_SUBELEM_SET 0 000600411c440028")
  190. def test_wifi_display_go_invite(dev):
  191. """P2P GO with Wi-Fi Display inviting a client to join"""
  192. addr0 = dev[0].p2p_dev_addr()
  193. addr1 = dev[1].p2p_dev_addr()
  194. try:
  195. enable_wifi_display(dev[0])
  196. enable_wifi_display(dev[1])
  197. enable_wifi_display(dev[2])
  198. dev[1].p2p_listen()
  199. if not dev[0].discover_peer(addr1, social=True):
  200. raise Exception("Peer " + addr1 + " not found")
  201. dev[0].p2p_listen()
  202. if not dev[1].discover_peer(addr0, social=True):
  203. raise Exception("Peer " + addr0 + " not found")
  204. dev[1].p2p_listen()
  205. logger.info("Authorize invitation")
  206. pin = dev[1].wps_read_pin()
  207. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth")
  208. dev[0].p2p_start_go(freq=2412)
  209. # Add test client to the group
  210. connect_cli(dev[0], dev[2], social=True, freq=2412)
  211. logger.info("Invite peer to join the group")
  212. dev[0].p2p_go_authorize_client(pin)
  213. dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
  214. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED",
  215. "P2P-GROUP-STARTED"], timeout=20)
  216. if ev is None:
  217. raise Exception("Timeout on invitation on peer")
  218. if "P2P-INVITATION-RECEIVED" in ev:
  219. raise Exception("Unexpected request to accept pre-authorized invitation")
  220. dev[0].remove_group()
  221. dev[1].wait_go_ending_session()
  222. dev[2].wait_go_ending_session()
  223. finally:
  224. dev[0].request("SET wifi_display 0")
  225. dev[1].request("SET wifi_display 0")
  226. dev[2].request("SET wifi_display 0")
  227. def test_wifi_display_persistent_group(dev):
  228. """P2P persistent group formation and re-invocation with Wi-Fi Display enabled"""
  229. try:
  230. enable_wifi_display(dev[0])
  231. enable_wifi_display(dev[1])
  232. enable_wifi_display(dev[2])
  233. form(dev[0], dev[1])
  234. peer = dev[1].get_peer(dev[0].p2p_dev_addr())
  235. listen_freq = peer['listen_freq']
  236. invite_from_cli(dev[0], dev[1])
  237. invite_from_go(dev[0], dev[1])
  238. dev[0].dump_monitor()
  239. dev[1].dump_monitor()
  240. networks = dev[0].list_networks(p2p=True)
  241. if len(networks) != 1:
  242. raise Exception("Unexpected number of networks")
  243. if "[P2P-PERSISTENT]" not in networks[0]['flags']:
  244. raise Exception("Not the persistent group data")
  245. if "OK" not in dev[0].global_request("P2P_GROUP_ADD persistent=" + networks[0]['id'] + " freq=" + listen_freq):
  246. raise Exception("Could not start GO")
  247. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=2)
  248. if ev is None:
  249. raise Exception("GO start up timed out")
  250. dev[0].group_form_result(ev)
  251. connect_cli(dev[0], dev[2], social=True, freq=listen_freq)
  252. dev[0].dump_monitor()
  253. dev[1].dump_monitor()
  254. invite(dev[1], dev[0])
  255. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
  256. if ev is None:
  257. raise Exception("Timeout on group re-invocation (on client)")
  258. dev[1].group_form_result(ev)
  259. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=0.1)
  260. if ev is not None:
  261. raise Exception("Unexpected P2P-GROUP-START on GO")
  262. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  263. finally:
  264. dev[0].request("SET wifi_display 0")
  265. dev[1].request("SET wifi_display 0")
  266. dev[2].request("SET wifi_display 0")
  267. def test_wifi_display_invalid_subelem(dev):
  268. """Wi-Fi Display and invalid subelement parsing"""
  269. addr1 = dev[1].p2p_dev_addr()
  270. try:
  271. enable_wifi_display(dev[0])
  272. enable_wifi_display(dev[1])
  273. dev[1].request("WFD_SUBELEM_SET 0 ffff00411c440028")
  274. dev[1].p2p_listen()
  275. dev[0].p2p_find(social=True)
  276. ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  277. if ev is None:
  278. raise Exception("Device discovery timed out")
  279. if "wfd_dev_info=" in ev:
  280. raise Exception("Invalid WFD subelement was shown")
  281. finally:
  282. dev[0].request("SET wifi_display 0")
  283. dev[1].request("SET wifi_display 0")
  284. def test_wifi_display_parsing(dev):
  285. """Wi-Fi Display extensions to P2P and special parsing cases"""
  286. try:
  287. _test_wifi_display_parsing(dev)
  288. finally:
  289. dev[1].request("VENDOR_ELEM_REMOVE 11 *")
  290. dev[0].request("SET wifi_display 0")
  291. def _test_wifi_display_parsing(dev):
  292. wfd_devinfo = "00411c440028"
  293. dev[0].request("SET wifi_display 1")
  294. dev[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo)
  295. dev[0].p2p_start_go(freq=2412)
  296. # P2P Client with invalid WFD IE
  297. if "OK" not in dev[1].request("VENDOR_ELEM_ADD 11 dd10506f9a0a000000010000060000ffffff"):
  298. raise Exception("VENDOR_ELEM_ADD failed")
  299. pin = dev[1].wps_read_pin()
  300. dev[0].p2p_go_authorize_client(pin)
  301. dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60,
  302. social=True, freq=2412)
  303. bssid = dev[0].get_group_status_field('bssid')
  304. dev[2].scan_for_bss(bssid, freq=2412, force_scan=True)
  305. bss = dev[2].get_bss(bssid)
  306. if bss['wfd_subelems'] != "000006" + wfd_devinfo:
  307. raise Exception("Unexpected WFD elements in scan results: " + bss['wfd_subelems'])
  308. # P2P Client without WFD IE
  309. pin = dev[2].wps_read_pin()
  310. dev[0].p2p_go_authorize_client(pin)
  311. dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60,
  312. social=True, freq=2412)
  313. dev[2].remove_group()
  314. dev[0].remove_group()
  315. dev[1].wait_go_ending_session()