test_p2p_wifi_display.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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_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. wfd_devinfo2 = "00001c440028"
  43. dev[1].request("SET wifi_display 1")
  44. dev[1].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo2)
  45. if wfd_devinfo2 not in dev[1].request("WFD_SUBELEM_GET 0"):
  46. raise Exception("Could not fetch back configured subelement")
  47. dev[0].p2p_listen()
  48. if "FAIL" in dev[1].request("P2P_SERV_DISC_REQ " + dev[0].p2p_dev_addr() + " wifi-display [source][pri-sink] 2,3,4,5"):
  49. raise Exception("Setting SD request failed")
  50. dev[1].p2p_find(social=True)
  51. ev = dev[0].wait_global_event(["P2P-SERV-DISC-REQ"], timeout=10)
  52. if ev is None:
  53. raise Exception("Device discovery request not reported")
  54. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  55. if ev is None:
  56. raise Exception("Device discovery timed out")
  57. if "wfd_dev_info=0x" + wfd_devinfo not in ev:
  58. raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
  59. if "new=1" not in ev:
  60. raise Exception("new=1 flag missing from P2P-DEVICE-FOUND event")
  61. ev = dev[1].wait_global_event(["P2P-SERV-DISC-RESP"], timeout=5)
  62. if ev is None:
  63. raise Exception("Service discovery timed out")
  64. if prot not in ev:
  65. raise Exception("WFD Content Protection missing from WSD response")
  66. if video not in ev:
  67. raise Exception("WFD Video Formats missing from WSD response")
  68. if video_3d not in ev:
  69. raise Exception("WFD 3D Video Formats missing from WSD response")
  70. if audio not in ev:
  71. raise Exception("WFD Audio Formats missing from WSD response")
  72. dev[1].dump_monitor()
  73. dev[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo2)
  74. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=15)
  75. if ev is None:
  76. raise Exception("Peer info update timed out")
  77. if "new=0" not in ev:
  78. raise Exception("new=0 flag missing from P2P-DEVICE-FOUND event")
  79. if "wfd_dev_info=0x" + wfd_devinfo2 not in ev:
  80. raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
  81. dev[1].dump_monitor()
  82. dev[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo)
  83. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=15)
  84. if ev is None:
  85. raise Exception("Peer info update timed out")
  86. if "new=0" not in ev:
  87. raise Exception("new=0 flag missing from P2P-DEVICE-FOUND event")
  88. if "wfd_dev_info=0x" + wfd_devinfo not in ev:
  89. raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
  90. pin = dev[0].wps_read_pin()
  91. dev[0].p2p_go_neg_auth(dev[1].p2p_dev_addr(), pin, 'display')
  92. res1 = dev[1].p2p_go_neg_init(dev[0].p2p_dev_addr(), pin, 'enter', timeout=20, go_intent=15)
  93. res2 = dev[0].p2p_go_neg_auth_result()
  94. bss = dev[0].get_bss("p2p_dev_addr=" + dev[1].p2p_dev_addr())
  95. if bss['bssid'] != dev[1].p2p_interface_addr():
  96. raise Exception("Unexpected BSSID in the BSS entry for the GO")
  97. if wfd_devinfo2 not in bss['wfd_subelems']:
  98. raise Exception("Could not see wfd_subelems in GO's BSS entry")
  99. peer = dev[0].get_peer(dev[1].p2p_dev_addr())
  100. if wfd_devinfo2 not in peer['wfd_subelems']:
  101. raise Exception("Could not see wfd_subelems in GO's peer entry")
  102. peer = dev[1].get_peer(dev[0].p2p_dev_addr())
  103. if wfd_devinfo not in peer['wfd_subelems']:
  104. raise Exception("Could not see wfd_subelems in client's peer entry")
  105. wfd_devinfo3 = "00001c440028"
  106. dev[2].request("SET wifi_display 1")
  107. dev[2].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo3)
  108. dev[2].p2p_find(social=True)
  109. ev = dev[2].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
  110. if ev is None:
  111. raise Exception("Device discovery timed out")
  112. if dev[1].p2p_dev_addr() not in ev:
  113. ev = dev[2].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
  114. if ev is None:
  115. raise Exception("Device discovery timed out")
  116. if dev[1].p2p_dev_addr() not in ev:
  117. raise Exception("Could not discover GO")
  118. if "wfd_dev_info=0x" + wfd_devinfo2 not in ev:
  119. raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
  120. bss = dev[2].get_bss("p2p_dev_addr=" + dev[1].p2p_dev_addr())
  121. if bss['bssid'] != dev[1].p2p_interface_addr():
  122. raise Exception("Unexpected BSSID in the BSS entry for the GO")
  123. if wfd_devinfo2 not in bss['wfd_subelems']:
  124. raise Exception("Could not see wfd_subelems in GO's BSS entry")
  125. peer = dev[2].get_peer(dev[1].p2p_dev_addr())
  126. if wfd_devinfo2 not in peer['wfd_subelems']:
  127. raise Exception("Could not see wfd_subelems in GO's peer entry")
  128. dev[2].p2p_stop_find()
  129. if dev[0].request("WFD_SUBELEM_GET 2") != audio:
  130. raise Exception("Unexpected WFD_SUBELEM_GET 2 value")
  131. if dev[0].request("WFD_SUBELEM_GET 3") != video:
  132. raise Exception("Unexpected WFD_SUBELEM_GET 3 value")
  133. if dev[0].request("WFD_SUBELEM_GET 4") != video_3d:
  134. raise Exception("Unexpected WFD_SUBELEM_GET 42 value")
  135. if dev[0].request("WFD_SUBELEM_GET 5") != prot:
  136. raise Exception("Unexpected WFD_SUBELEM_GET 5 value")
  137. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET "):
  138. raise Exception("Unexpected WFD_SUBELEM_SET success")
  139. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET 6"):
  140. raise Exception("Unexpected WFD_SUBELEM_SET success")
  141. if "OK" not in dev[0].request("WFD_SUBELEM_SET 6 "):
  142. raise Exception("Unexpected WFD_SUBELEM_SET failure")
  143. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET 6 0"):
  144. raise Exception("Unexpected WFD_SUBELEM_SET success")
  145. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET 6 0q"):
  146. raise Exception("Unexpected WFD_SUBELEM_SET success")
  147. if dev[0].request("WFD_SUBELEM_GET 6") != "":
  148. raise Exception("Unexpected WFD_SUBELEM_GET 6 response")
  149. if dev[0].request("WFD_SUBELEM_GET 8") != "":
  150. raise Exception("Unexpected WFD_SUBELEM_GET 8 response")
  151. if dev[0].global_request("WFD_SUBELEM_GET 2") != audio:
  152. raise Exception("Unexpected WFD_SUBELEM_GET 2 value from global interface")
  153. if "OK" not in dev[0].global_request("WFD_SUBELEM_SET 1 0006020304050608"):
  154. raise Exception("WFD_SUBELEM_SET failed on global interface")
  155. if dev[0].request("WFD_SUBELEM_GET 1") != "0006020304050608":
  156. raise Exception("Unexpected WFD_SUBELEM_GET 1 value (per-interface)")
  157. dev[0].request("SET wifi_display 0")
  158. dev[1].request("SET wifi_display 0")
  159. dev[2].request("SET wifi_display 0")
  160. def enable_wifi_display(dev):
  161. dev.request("SET wifi_display 1")
  162. dev.request("WFD_SUBELEM_SET 0 000600411c440028")
  163. def test_wifi_display_go_invite(dev):
  164. """P2P GO with Wi-Fi Display inviting a client to join"""
  165. addr0 = dev[0].p2p_dev_addr()
  166. addr1 = dev[1].p2p_dev_addr()
  167. try:
  168. enable_wifi_display(dev[0])
  169. enable_wifi_display(dev[1])
  170. enable_wifi_display(dev[2])
  171. dev[1].p2p_listen()
  172. if not dev[0].discover_peer(addr1, social=True):
  173. raise Exception("Peer " + addr1 + " not found")
  174. dev[0].p2p_listen()
  175. if not dev[1].discover_peer(addr0, social=True):
  176. raise Exception("Peer " + addr0 + " not found")
  177. dev[1].p2p_listen()
  178. logger.info("Authorize invitation")
  179. pin = dev[1].wps_read_pin()
  180. dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth")
  181. dev[0].p2p_start_go(freq=2412)
  182. # Add test client to the group
  183. connect_cli(dev[0], dev[2])
  184. logger.info("Invite peer to join the group")
  185. dev[0].p2p_go_authorize_client(pin)
  186. dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
  187. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED",
  188. "P2P-GROUP-STARTED"], timeout=20)
  189. if ev is None:
  190. raise Exception("Timeout on invitation on peer")
  191. if "P2P-INVITATION-RECEIVED" in ev:
  192. raise Exception("Unexpected request to accept pre-authorized invitation")
  193. dev[0].remove_group()
  194. dev[1].wait_go_ending_session()
  195. dev[2].wait_go_ending_session()
  196. finally:
  197. dev[0].request("SET wifi_display 0")
  198. dev[1].request("SET wifi_display 0")
  199. dev[2].request("SET wifi_display 0")
  200. def test_wifi_display_persistent_group(dev):
  201. """P2P persistent group formation and re-invocation with Wi-Fi Display enabled"""
  202. try:
  203. enable_wifi_display(dev[0])
  204. enable_wifi_display(dev[1])
  205. enable_wifi_display(dev[2])
  206. form(dev[0], dev[1])
  207. peer = dev[1].get_peer(dev[0].p2p_dev_addr())
  208. listen_freq = peer['listen_freq']
  209. invite_from_cli(dev[0], dev[1])
  210. invite_from_go(dev[0], dev[1])
  211. dev[0].dump_monitor()
  212. dev[1].dump_monitor()
  213. networks = dev[0].list_networks()
  214. if len(networks) != 1:
  215. raise Exception("Unexpected number of networks")
  216. if "[P2P-PERSISTENT]" not in networks[0]['flags']:
  217. raise Exception("Not the persistent group data")
  218. if "OK" not in dev[0].global_request("P2P_GROUP_ADD persistent=" + networks[0]['id'] + " freq=" + listen_freq):
  219. raise Exception("Could not state GO")
  220. connect_cli(dev[0], dev[2])
  221. invite_from_cli(dev[0], dev[1])
  222. finally:
  223. dev[0].request("SET wifi_display 0")
  224. dev[1].request("SET wifi_display 0")
  225. dev[2].request("SET wifi_display 0")
  226. def test_wifi_display_invalid_subelem(dev):
  227. """Wi-Fi Display and invalid subelement parsing"""
  228. addr1 = dev[1].p2p_dev_addr()
  229. try:
  230. enable_wifi_display(dev[0])
  231. enable_wifi_display(dev[1])
  232. dev[1].request("WFD_SUBELEM_SET 0 ffff00411c440028")
  233. dev[1].p2p_listen()
  234. dev[0].p2p_find(social=True)
  235. ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  236. if ev is None:
  237. raise Exception("Device discovery timed out")
  238. if "wfd_dev_info=" in ev:
  239. raise Exception("Invalid WFD subelement was shown")
  240. finally:
  241. dev[0].request("SET wifi_display 0")
  242. dev[1].request("SET wifi_display 0")