ap_drv_ops.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * hostapd - Driver operations
  3. * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
  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 "includes.h"
  15. #include "common.h"
  16. #include "hostapd.h"
  17. #include "sta_info.h"
  18. #include "driver_i.h"
  19. static int hostapd_sta_flags_to_drv(int flags)
  20. {
  21. int res = 0;
  22. if (flags & WLAN_STA_AUTHORIZED)
  23. res |= WPA_STA_AUTHORIZED;
  24. if (flags & WLAN_STA_WMM)
  25. res |= WPA_STA_WMM;
  26. if (flags & WLAN_STA_SHORT_PREAMBLE)
  27. res |= WPA_STA_SHORT_PREAMBLE;
  28. if (flags & WLAN_STA_MFP)
  29. res |= WPA_STA_MFP;
  30. return res;
  31. }
  32. static int hostapd_set_ap_wps_ie(struct hostapd_data *hapd,
  33. const struct wpabuf *beacon,
  34. const struct wpabuf *proberesp)
  35. {
  36. if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
  37. return 0;
  38. return hapd->driver->set_ap_wps_ie(hapd->conf->iface, hapd->drv_priv,
  39. beacon, proberesp);
  40. }
  41. static int hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg,
  42. size_t len)
  43. {
  44. if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
  45. return 0;
  46. return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
  47. }
  48. static int hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr,
  49. const u8 *data, size_t data_len, int encrypt)
  50. {
  51. if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
  52. return 0;
  53. return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
  54. data_len, encrypt,
  55. hapd->own_addr);
  56. }
  57. static int hostapd_set_authorized(struct hostapd_data *hapd,
  58. struct sta_info *sta, int authorized)
  59. {
  60. if (authorized) {
  61. return hostapd_sta_set_flags(hapd, sta->addr,
  62. hostapd_sta_flags_to_drv(
  63. sta->flags),
  64. WPA_STA_AUTHORIZED, ~0);
  65. }
  66. return hostapd_sta_set_flags(hapd, sta->addr,
  67. hostapd_sta_flags_to_drv(sta->flags),
  68. 0, ~WPA_STA_AUTHORIZED);
  69. }
  70. static int hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
  71. wpa_alg alg, const u8 *addr, int key_idx,
  72. int set_tx, const u8 *seq, size_t seq_len,
  73. const u8 *key, size_t key_len)
  74. {
  75. if (hapd->driver == NULL || hapd->driver->set_key == NULL)
  76. return 0;
  77. return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
  78. key_idx, set_tx, seq, seq_len, key,
  79. key_len);
  80. }
  81. static int hostapd_read_sta_data(struct hostapd_data *hapd,
  82. struct hostap_sta_driver_data *data,
  83. const u8 *addr)
  84. {
  85. if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
  86. return -1;
  87. return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
  88. }
  89. static int hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
  90. {
  91. if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
  92. return 0;
  93. return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
  94. }
  95. static int hostapd_set_sta_flags(struct hostapd_data *hapd,
  96. struct sta_info *sta)
  97. {
  98. int set_flags, total_flags, flags_and, flags_or;
  99. total_flags = hostapd_sta_flags_to_drv(sta->flags);
  100. set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
  101. if (!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
  102. sta->flags & WLAN_STA_AUTHORIZED)
  103. set_flags |= WPA_STA_AUTHORIZED;
  104. flags_or = total_flags & set_flags;
  105. flags_and = total_flags | ~set_flags;
  106. return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
  107. flags_or, flags_and);
  108. }
  109. static int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd,
  110. const char *ifname, int enabled)
  111. {
  112. struct wpa_bss_params params;
  113. os_memset(&params, 0, sizeof(params));
  114. params.ifname = ifname;
  115. params.enabled = enabled;
  116. if (enabled) {
  117. params.wpa = hapd->conf->wpa;
  118. params.ieee802_1x = hapd->conf->ieee802_1x;
  119. params.wpa_group = hapd->conf->wpa_group;
  120. params.wpa_pairwise = hapd->conf->wpa_pairwise;
  121. params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
  122. params.rsn_preauth = hapd->conf->rsn_preauth;
  123. }
  124. return hostapd_set_ieee8021x(hapd, &params);
  125. }
  126. void hostapd_set_driver_ops(struct hostapd_driver_ops *ops)
  127. {
  128. ops->set_ap_wps_ie = hostapd_set_ap_wps_ie;
  129. ops->send_mgmt_frame = hostapd_send_mgmt_frame;
  130. ops->send_eapol = hostapd_send_eapol;
  131. ops->set_authorized = hostapd_set_authorized;
  132. ops->set_key = hostapd_set_key;
  133. ops->read_sta_data = hostapd_read_sta_data;
  134. ops->sta_clear_stats = hostapd_sta_clear_stats;
  135. ops->set_sta_flags = hostapd_set_sta_flags;
  136. ops->set_drv_ieee8021x = hostapd_set_drv_ieee8021x;
  137. }