test_p2p_device.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. def test_p2p_device_grpform2(dev, apdev):
  24. """P2P group formation with driver using cfg80211 P2P Device (reverse)"""
  25. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  26. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  27. wpas.interface_add(iface)
  28. [i_res, r_res] = go_neg_pin_authorized(i_dev=wpas, i_intent=15,
  29. r_dev=dev[0], r_intent=0)
  30. check_grpform_results(i_res, r_res)
  31. remove_group(wpas, dev[0])
  32. def test_p2p_device_group_remove(dev, apdev):
  33. """P2P group removal via the P2P ctrl interface with driver using cfg80211 P2P Device"""
  34. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  35. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  36. wpas.interface_add(iface)
  37. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  38. r_dev=wpas, r_intent=0)
  39. check_grpform_results(i_res, r_res)
  40. # Issue the remove request on the interface which will be removed
  41. p2p_iface_wpas = WpaSupplicant(ifname=r_res['ifname'])
  42. res = p2p_iface_wpas.request("P2P_GROUP_REMOVE *")
  43. if "OK" not in res:
  44. raise Exception("Failed to remove P2P group")
  45. ev = wpas.wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
  46. if ev is None:
  47. raise Exception("Group removal event not received")
  48. if not wpas.global_ping():
  49. raise Exception("Could not ping global ctrl_iface after group removal")
  50. def test_p2p_device_concurrent_scan(dev, apdev):
  51. """Concurrent P2P and station mode scans with driver using cfg80211 P2P Device"""
  52. with HWSimRadio(use_p2p_device=True) as (radio, iface):
  53. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  54. wpas.interface_add(iface)
  55. wpas.p2p_find()
  56. time.sleep(0.1)
  57. wpas.request("SCAN")
  58. ev = wpas.wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=15)
  59. if ev is None:
  60. raise Exception("Station mode scan did not start")