test_p2p_wifi_display.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 test_p2p_autogo import connect_cli
  14. from test_p2p_persistent import form, invite, invite_from_cli, invite_from_go
  15. def test_wifi_display(dev):
  16. """Wi-Fi Display extensions to P2P"""
  17. wfd_devinfo = "00411c440028"
  18. dev[0].request("SET wifi_display 1")
  19. dev[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo)
  20. if wfd_devinfo not in dev[0].request("WFD_SUBELEM_GET 0"):
  21. raise Exception("Could not fetch back configured subelement")
  22. # Associated BSSID
  23. dev[0].request("WFD_SUBELEM_SET 1 0006020304050607")
  24. # Coupled Sink
  25. dev[0].request("WFD_SUBELEM_SET 6 000700000000000000")
  26. # Session Info
  27. dev[0].request("WFD_SUBELEM_SET 9 0000")
  28. # WFD Extended Capability
  29. dev[0].request("WFD_SUBELEM_SET 7 00020000")
  30. # WFD Content Protection
  31. prot = "0001" + "00"
  32. dev[0].request("WFD_SUBELEM_SET 5 " + prot)
  33. # WFD Video Formats
  34. video = "0015" + "010203040506070809101112131415161718192021"
  35. dev[0].request("WFD_SUBELEM_SET 3 " + video)
  36. # WFD 3D Video Formats
  37. video_3d = "0011" + "0102030405060708091011121314151617"
  38. dev[0].request("WFD_SUBELEM_SET 4 " + video_3d)
  39. # WFD Audio Formats
  40. audio = "000f" + "010203040506070809101112131415"
  41. dev[0].request("WFD_SUBELEM_SET 2 " + audio)
  42. elems = dev[0].request("WFD_SUBELEM_GET all")
  43. if wfd_devinfo not in elems:
  44. raise Exception("Could not fetch back configured subelements")
  45. wfd_devinfo2 = "00001c440028"
  46. dev[1].request("SET wifi_display 1")
  47. dev[1].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo2)
  48. if wfd_devinfo2 not in dev[1].request("WFD_SUBELEM_GET 0"):
  49. raise Exception("Could not fetch back configured subelement")
  50. dev[0].p2p_listen()
  51. if "FAIL" in dev[1].request("P2P_SERV_DISC_REQ " + dev[0].p2p_dev_addr() + " wifi-display [source][pri-sink] 2,3,4,5"):
  52. raise Exception("Setting SD request failed")
  53. dev[1].p2p_find(social=True)
  54. ev = dev[0].wait_global_event(["P2P-SERV-DISC-REQ"], timeout=10)
  55. if ev is None:
  56. raise Exception("Device discovery request not reported")
  57. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  58. if ev is None:
  59. raise Exception("Device discovery timed out")
  60. if "wfd_dev_info=0x" + wfd_devinfo not in ev:
  61. raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
  62. if "new=1" not in ev:
  63. raise Exception("new=1 flag missing from P2P-DEVICE-FOUND event")
  64. ev = dev[1].wait_global_event(["P2P-SERV-DISC-RESP"], timeout=5)
  65. if ev is None:
  66. raise Exception("Service discovery timed out")
  67. if prot not in ev:
  68. raise Exception("WFD Content Protection missing from WSD response")
  69. if video not in ev:
  70. raise Exception("WFD Video Formats missing from WSD response")
  71. if video_3d not in ev:
  72. raise Exception("WFD 3D Video Formats missing from WSD response")
  73. if audio not in ev:
  74. raise Exception("WFD Audio Formats missing from WSD response")
  75. dev[1].dump_monitor()
  76. dev[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo2)
  77. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=15)
  78. if ev is None:
  79. raise Exception("Peer info update timed out")
  80. if "new=0" not in ev:
  81. raise Exception("new=0 flag missing from P2P-DEVICE-FOUND event")
  82. if "wfd_dev_info=0x" + wfd_devinfo2 not in ev:
  83. raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
  84. dev[1].dump_monitor()
  85. dev[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo)
  86. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=15)
  87. if ev is None:
  88. raise Exception("Peer info update timed out")
  89. if "new=0" not in ev:
  90. raise Exception("new=0 flag missing from P2P-DEVICE-FOUND event")
  91. if "wfd_dev_info=0x" + wfd_devinfo not in ev:
  92. raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
  93. pin = dev[0].wps_read_pin()
  94. dev[0].p2p_go_neg_auth(dev[1].p2p_dev_addr(), pin, 'display')
  95. res1 = dev[1].p2p_go_neg_init(dev[0].p2p_dev_addr(), pin, 'enter', timeout=20, go_intent=15)
  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_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_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()
  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. connect_cli(dev[0], dev[2], social=True, freq=listen_freq)
  248. dev[0].dump_monitor()
  249. dev[1].dump_monitor()
  250. invite(dev[1], dev[0])
  251. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
  252. if ev is None:
  253. raise Exception("Timeout on group re-invocation (on client)")
  254. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=0.1)
  255. if ev is not None:
  256. raise Exception("Unexpected P2P-GROUP-START on GO")
  257. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  258. finally:
  259. dev[0].request("SET wifi_display 0")
  260. dev[1].request("SET wifi_display 0")
  261. dev[2].request("SET wifi_display 0")
  262. def test_wifi_display_invalid_subelem(dev):
  263. """Wi-Fi Display and invalid subelement parsing"""
  264. addr1 = dev[1].p2p_dev_addr()
  265. try:
  266. enable_wifi_display(dev[0])
  267. enable_wifi_display(dev[1])
  268. dev[1].request("WFD_SUBELEM_SET 0 ffff00411c440028")
  269. dev[1].p2p_listen()
  270. dev[0].p2p_find(social=True)
  271. ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  272. if ev is None:
  273. raise Exception("Device discovery timed out")
  274. if "wfd_dev_info=" in ev:
  275. raise Exception("Invalid WFD subelement was shown")
  276. finally:
  277. dev[0].request("SET wifi_display 0")
  278. dev[1].request("SET wifi_display 0")