test_p2p_device.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # cfg80211 P2P Device
  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. from wpasupplicant import WpaSupplicant
  10. from test_p2p_grpform import go_neg_pin_authorized
  11. from test_p2p_grpform import check_grpform_results
  12. from test_p2p_grpform import remove_group
  13. from hwsim import HWSimRadio
  14. def test_p2p_device_grpform(dev, apdev):
  15. """P2P group formation with driver using cfg80211 P2P Device"""
  16. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  17. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  18. wpas.interface_add(iface)
  19. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  20. r_dev=wpas, r_intent=0)
  21. check_grpform_results(i_res, r_res)
  22. remove_group(dev[0], wpas)
  23. res = wpas.global_request("IFNAME=p2p-dev-" + iface + " STATUS-DRIVER")
  24. lines = res.splitlines()
  25. found = False
  26. for l in lines:
  27. try:
  28. [name,value] = l.split('=', 1)
  29. if name == "wdev_id":
  30. found = True
  31. break
  32. except ValueError:
  33. pass
  34. if not found:
  35. raise Exception("wdev_id not found")
  36. def test_p2p_device_grpform2(dev, apdev):
  37. """P2P group formation with driver using cfg80211 P2P Device (reverse)"""
  38. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  39. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  40. wpas.interface_add(iface)
  41. [i_res, r_res] = go_neg_pin_authorized(i_dev=wpas, i_intent=15,
  42. r_dev=dev[0], r_intent=0)
  43. check_grpform_results(i_res, r_res)
  44. remove_group(wpas, dev[0])
  45. def test_p2p_device_group_remove(dev, apdev):
  46. """P2P group removal via the P2P ctrl interface with driver using cfg80211 P2P Device"""
  47. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  48. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  49. wpas.interface_add(iface)
  50. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  51. r_dev=wpas, r_intent=0)
  52. check_grpform_results(i_res, r_res)
  53. # Issue the remove request on the interface which will be removed
  54. p2p_iface_wpas = WpaSupplicant(ifname=r_res['ifname'])
  55. res = p2p_iface_wpas.request("P2P_GROUP_REMOVE *")
  56. if "OK" not in res:
  57. raise Exception("Failed to remove P2P group")
  58. ev = wpas.wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
  59. if ev is None:
  60. raise Exception("Group removal event not received")
  61. if not wpas.global_ping():
  62. raise Exception("Could not ping global ctrl_iface after group removal")
  63. def test_p2p_device_concurrent_scan(dev, apdev):
  64. """Concurrent P2P and station mode scans with driver using cfg80211 P2P Device"""
  65. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  66. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  67. wpas.interface_add(iface)
  68. wpas.p2p_find()
  69. time.sleep(0.1)
  70. wpas.request("SCAN")
  71. ev = wpas.wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=15)
  72. if ev is None:
  73. raise Exception("Station mode scan did not start")