p2p_hostapd.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * hostapd / P2P integration
  3. * Copyright (c) 2009-2010, Atheros Communications
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "common/ieee802_11_defs.h"
  11. #include "p2p/p2p.h"
  12. #include "hostapd.h"
  13. #include "ap_config.h"
  14. #include "ap_drv_ops.h"
  15. #include "sta_info.h"
  16. #include "p2p_hostapd.h"
  17. #ifdef CONFIG_P2P
  18. int hostapd_p2p_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
  19. char *buf, size_t buflen)
  20. {
  21. if (sta->p2p_ie == NULL)
  22. return 0;
  23. return p2p_ie_text(sta->p2p_ie, buf, buf + buflen);
  24. }
  25. int hostapd_p2p_set_noa(struct hostapd_data *hapd, u8 count, int start,
  26. int duration)
  27. {
  28. wpa_printf(MSG_DEBUG, "P2P: Set NoA parameters: count=%u start=%d "
  29. "duration=%d", count, start, duration);
  30. if (count == 0) {
  31. hapd->noa_enabled = 0;
  32. hapd->noa_start = 0;
  33. hapd->noa_duration = 0;
  34. }
  35. if (count != 255) {
  36. wpa_printf(MSG_DEBUG, "P2P: Non-periodic NoA - set "
  37. "NoA parameters");
  38. return hostapd_driver_set_noa(hapd, count, start, duration);
  39. }
  40. hapd->noa_enabled = 1;
  41. hapd->noa_start = start;
  42. hapd->noa_duration = duration;
  43. if (hapd->num_sta_no_p2p == 0) {
  44. wpa_printf(MSG_DEBUG, "P2P: No legacy STAs connected - update "
  45. "periodic NoA parameters");
  46. return hostapd_driver_set_noa(hapd, count, start, duration);
  47. }
  48. wpa_printf(MSG_DEBUG, "P2P: Legacy STA(s) connected - do not enable "
  49. "periodic NoA");
  50. return 0;
  51. }
  52. void hostapd_p2p_non_p2p_sta_connected(struct hostapd_data *hapd)
  53. {
  54. wpa_printf(MSG_DEBUG, "P2P: First non-P2P device connected");
  55. if (hapd->noa_enabled) {
  56. wpa_printf(MSG_DEBUG, "P2P: Disable periodic NoA");
  57. hostapd_driver_set_noa(hapd, 0, 0, 0);
  58. }
  59. }
  60. void hostapd_p2p_non_p2p_sta_disconnected(struct hostapd_data *hapd)
  61. {
  62. wpa_printf(MSG_DEBUG, "P2P: Last non-P2P device disconnected");
  63. if (hapd->noa_enabled) {
  64. wpa_printf(MSG_DEBUG, "P2P: Enable periodic NoA");
  65. hostapd_driver_set_noa(hapd, 255, hapd->noa_start,
  66. hapd->noa_duration);
  67. }
  68. }
  69. #endif /* CONFIG_P2P */
  70. #ifdef CONFIG_P2P_MANAGER
  71. u8 * hostapd_eid_p2p_manage(struct hostapd_data *hapd, u8 *eid)
  72. {
  73. u8 bitmap;
  74. *eid++ = WLAN_EID_VENDOR_SPECIFIC;
  75. *eid++ = 4 + 3 + 1;
  76. WPA_PUT_BE32(eid, P2P_IE_VENDOR_TYPE);
  77. eid += 4;
  78. *eid++ = P2P_ATTR_MANAGEABILITY;
  79. WPA_PUT_LE16(eid, 1);
  80. eid += 2;
  81. bitmap = P2P_MAN_DEVICE_MANAGEMENT;
  82. if (hapd->conf->p2p & P2P_ALLOW_CROSS_CONNECTION)
  83. bitmap |= P2P_MAN_CROSS_CONNECTION_PERMITTED;
  84. bitmap |= P2P_MAN_COEXISTENCE_OPTIONAL;
  85. *eid++ = bitmap;
  86. return eid;
  87. }
  88. #endif /* CONFIG_P2P_MANAGER */