ap_drv_ops.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_set_ap_wps_ie(struct hostapd_data *hapd,
  20. const struct wpabuf *beacon,
  21. const struct wpabuf *proberesp)
  22. {
  23. if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
  24. return 0;
  25. return hapd->driver->set_ap_wps_ie(hapd->conf->iface, hapd->drv_priv,
  26. beacon, proberesp);
  27. }
  28. static int hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg,
  29. size_t len)
  30. {
  31. if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
  32. return 0;
  33. return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
  34. }
  35. static int hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr,
  36. const u8 *data, size_t data_len, int encrypt)
  37. {
  38. if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
  39. return 0;
  40. return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
  41. data_len, encrypt,
  42. hapd->own_addr);
  43. }
  44. static int hostapd_set_authorized(struct hostapd_data *hapd,
  45. struct sta_info *sta, int authorized)
  46. {
  47. if (authorized) {
  48. return hostapd_sta_set_flags(hapd, sta->addr,
  49. hostapd_sta_flags_to_drv(
  50. sta->flags),
  51. WPA_STA_AUTHORIZED, ~0);
  52. }
  53. return hostapd_sta_set_flags(hapd, sta->addr,
  54. hostapd_sta_flags_to_drv(sta->flags),
  55. 0, ~WPA_STA_AUTHORIZED);
  56. }
  57. static int hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
  58. wpa_alg alg, const u8 *addr, int key_idx,
  59. int set_tx, const u8 *seq, size_t seq_len,
  60. const u8 *key, size_t key_len)
  61. {
  62. if (hapd->driver == NULL || hapd->driver->set_key == NULL)
  63. return 0;
  64. return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
  65. key_idx, set_tx, seq, seq_len, key,
  66. key_len);
  67. }
  68. static int hostapd_read_sta_data(struct hostapd_data *hapd,
  69. struct hostap_sta_driver_data *data,
  70. const u8 *addr)
  71. {
  72. if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
  73. return -1;
  74. return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
  75. }
  76. static int hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
  77. {
  78. if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
  79. return 0;
  80. return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
  81. }
  82. void hostapd_set_driver_ops(struct hostapd_driver_ops *ops)
  83. {
  84. ops->set_ap_wps_ie = hostapd_set_ap_wps_ie;
  85. ops->send_mgmt_frame = hostapd_send_mgmt_frame;
  86. ops->send_eapol = hostapd_send_eapol;
  87. ops->set_authorized = hostapd_set_authorized;
  88. ops->set_key = hostapd_set_key;
  89. ops->read_sta_data = hostapd_read_sta_data;
  90. ops->sta_clear_stats = hostapd_sta_clear_stats;
  91. }