p2p_hostapd.c 2.8 KB

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