test_p2p_wifi_display.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. def test_wifi_display(dev):
  14. """Wi-Fi Display extensions to P2P"""
  15. wfd_devinfo = "00411c440028"
  16. dev[0].request("SET wifi_display 1")
  17. dev[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo)
  18. if wfd_devinfo not in dev[0].request("WFD_SUBELEM_GET 0"):
  19. raise Exception("Could not fetch back configured subelement")
  20. # Associated BSSID
  21. dev[0].request("WFD_SUBELEM_SET 1 0006020304050607")
  22. # Coupled Sink
  23. dev[0].request("WFD_SUBELEM_SET 6 000700000000000000")
  24. # Session Info
  25. dev[0].request("WFD_SUBELEM_SET 9 0000")
  26. # WFD Extended Capability
  27. dev[0].request("WFD_SUBELEM_SET 7 00020000")
  28. # WFD Content Protection
  29. prot = "0001" + "00"
  30. dev[0].request("WFD_SUBELEM_SET 5 " + prot)
  31. # WFD Video Formats
  32. video = "0015" + "010203040506070809101112131415161718192021"
  33. dev[0].request("WFD_SUBELEM_SET 3 " + video)
  34. # WFD 3D Video Formats
  35. video_3d = "0011" + "0102030405060708091011121314151617"
  36. dev[0].request("WFD_SUBELEM_SET 4 " + video_3d)
  37. # WFD Audio Formats
  38. audio = "000f" + "010203040506070809101112131415"
  39. dev[0].request("WFD_SUBELEM_SET 2 " + audio)
  40. wfd_devinfo2 = "00001c440028"
  41. dev[1].request("SET wifi_display 1")
  42. dev[1].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo2)
  43. if wfd_devinfo2 not in dev[1].request("WFD_SUBELEM_GET 0"):
  44. raise Exception("Could not fetch back configured subelement")
  45. dev[0].p2p_listen()
  46. if "FAIL" in dev[1].request("P2P_SERV_DISC_REQ " + dev[0].p2p_dev_addr() + " wifi-display [source][pri-sink] 2,3,4,5"):
  47. raise Exception("Setting SD request failed")
  48. dev[1].p2p_find(social=True)
  49. ev = dev[0].wait_global_event(["P2P-SERV-DISC-REQ"], timeout=10)
  50. if ev is None:
  51. raise Exception("Device discovery request not reported")
  52. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  53. if ev is None:
  54. raise Exception("Device discovery timed out")
  55. if "wfd_dev_info=0x" + wfd_devinfo not in ev:
  56. raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
  57. ev = dev[1].wait_global_event(["P2P-SERV-DISC-RESP"], timeout=5)
  58. if ev is None:
  59. raise Exception("Service discovery timed out")
  60. if prot not in ev:
  61. raise Exception("WFD Content Protection missing from WSD response")
  62. if video not in ev:
  63. raise Exception("WFD Video Formats missing from WSD response")
  64. if video_3d not in ev:
  65. raise Exception("WFD 3D Video Formats missing from WSD response")
  66. if audio not in ev:
  67. raise Exception("WFD Audio Formats missing from WSD response")
  68. pin = dev[0].wps_read_pin()
  69. dev[0].p2p_go_neg_auth(dev[1].p2p_dev_addr(), pin, 'display')
  70. res1 = dev[1].p2p_go_neg_init(dev[0].p2p_dev_addr(), pin, 'enter', timeout=20, go_intent=15)
  71. res2 = dev[0].p2p_go_neg_auth_result()
  72. bss = dev[0].get_bss("p2p_dev_addr=" + dev[1].p2p_dev_addr())
  73. if bss['bssid'] != dev[1].p2p_interface_addr():
  74. raise Exception("Unexpected BSSID in the BSS entry for the GO")
  75. if wfd_devinfo2 not in bss['wfd_subelems']:
  76. raise Exception("Could not see wfd_subelems in GO's BSS entry")
  77. peer = dev[0].get_peer(dev[1].p2p_dev_addr())
  78. if wfd_devinfo2 not in peer['wfd_subelems']:
  79. raise Exception("Could not see wfd_subelems in GO's peer entry")
  80. peer = dev[1].get_peer(dev[0].p2p_dev_addr())
  81. if wfd_devinfo not in peer['wfd_subelems']:
  82. raise Exception("Could not see wfd_subelems in client's peer entry")
  83. wfd_devinfo3 = "00001c440028"
  84. dev[2].request("SET wifi_display 1")
  85. dev[2].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo3)
  86. dev[2].p2p_find(social=True)
  87. ev = dev[2].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
  88. if ev is None:
  89. raise Exception("Device discovery timed out")
  90. if dev[1].p2p_dev_addr() not in ev:
  91. ev = dev[2].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
  92. if ev is None:
  93. raise Exception("Device discovery timed out")
  94. if dev[1].p2p_dev_addr() not in ev:
  95. raise Exception("Could not discover GO")
  96. if "wfd_dev_info=0x" + wfd_devinfo2 not in ev:
  97. raise Exception("Wi-Fi Display Info not in P2P-DEVICE-FOUND event")
  98. bss = dev[2].get_bss("p2p_dev_addr=" + dev[1].p2p_dev_addr())
  99. if bss['bssid'] != dev[1].p2p_interface_addr():
  100. raise Exception("Unexpected BSSID in the BSS entry for the GO")
  101. if wfd_devinfo2 not in bss['wfd_subelems']:
  102. raise Exception("Could not see wfd_subelems in GO's BSS entry")
  103. peer = dev[2].get_peer(dev[1].p2p_dev_addr())
  104. if wfd_devinfo2 not in peer['wfd_subelems']:
  105. raise Exception("Could not see wfd_subelems in GO's peer entry")
  106. dev[2].p2p_stop_find()
  107. if dev[0].request("WFD_SUBELEM_GET 2") != audio:
  108. raise Exception("Unexpected WFD_SUBELEM_GET 2 value")
  109. if dev[0].request("WFD_SUBELEM_GET 3") != video:
  110. raise Exception("Unexpected WFD_SUBELEM_GET 3 value")
  111. if dev[0].request("WFD_SUBELEM_GET 4") != video_3d:
  112. raise Exception("Unexpected WFD_SUBELEM_GET 42 value")
  113. if dev[0].request("WFD_SUBELEM_GET 5") != prot:
  114. raise Exception("Unexpected WFD_SUBELEM_GET 5 value")
  115. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET "):
  116. raise Exception("Unexpected WFD_SUBELEM_SET success")
  117. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET 6"):
  118. raise Exception("Unexpected WFD_SUBELEM_SET success")
  119. if "OK" not in dev[0].request("WFD_SUBELEM_SET 6 "):
  120. raise Exception("Unexpected WFD_SUBELEM_SET failure")
  121. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET 6 0"):
  122. raise Exception("Unexpected WFD_SUBELEM_SET success")
  123. if "FAIL" not in dev[0].request("WFD_SUBELEM_SET 6 0q"):
  124. raise Exception("Unexpected WFD_SUBELEM_SET success")
  125. if dev[0].request("WFD_SUBELEM_GET 6") != "":
  126. raise Exception("Unexpected WFD_SUBELEM_GET 6 response")
  127. if dev[0].request("WFD_SUBELEM_GET 8") != "":
  128. raise Exception("Unexpected WFD_SUBELEM_GET 8 response")
  129. if dev[0].global_request("WFD_SUBELEM_GET 2") != audio:
  130. raise Exception("Unexpected WFD_SUBELEM_GET 2 value from global interface")
  131. if "OK" not in dev[0].global_request("WFD_SUBELEM_SET 1 0006020304050608"):
  132. raise Exception("WFD_SUBELEM_SET failed on global interface")
  133. if dev[0].request("WFD_SUBELEM_GET 1") != "0006020304050608":
  134. raise Exception("Unexpected WFD_SUBELEM_GET 1 value (per-interface)")
  135. dev[0].request("SET wifi_display 0")
  136. dev[1].request("SET wifi_display 0")
  137. dev[2].request("SET wifi_display 0")