2 * hostapd - Driver operations
3 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
23 static int hostapd_sta_flags_to_drv(int flags)
26 if (flags & WLAN_STA_AUTHORIZED)
27 res |= WPA_STA_AUTHORIZED;
28 if (flags & WLAN_STA_WMM)
30 if (flags & WLAN_STA_SHORT_PREAMBLE)
31 res |= WPA_STA_SHORT_PREAMBLE;
32 if (flags & WLAN_STA_MFP)
38 static int hostapd_set_ap_wps_ie(struct hostapd_data *hapd,
39 const struct wpabuf *beacon,
40 const struct wpabuf *proberesp)
42 if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
44 return hapd->driver->set_ap_wps_ie(hapd->conf->iface, hapd->drv_priv,
49 static int hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg,
52 if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
54 return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
58 static int hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr,
59 const u8 *data, size_t data_len, int encrypt)
61 if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
63 return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
69 static int hostapd_set_authorized(struct hostapd_data *hapd,
70 struct sta_info *sta, int authorized)
73 return hostapd_sta_set_flags(hapd, sta->addr,
74 hostapd_sta_flags_to_drv(
76 WPA_STA_AUTHORIZED, ~0);
79 return hostapd_sta_set_flags(hapd, sta->addr,
80 hostapd_sta_flags_to_drv(sta->flags),
81 0, ~WPA_STA_AUTHORIZED);
85 static int hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
86 wpa_alg alg, const u8 *addr, int key_idx,
87 int set_tx, const u8 *seq, size_t seq_len,
88 const u8 *key, size_t key_len)
90 if (hapd->driver == NULL || hapd->driver->set_key == NULL)
92 return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
93 key_idx, set_tx, seq, seq_len, key,
98 static int hostapd_read_sta_data(struct hostapd_data *hapd,
99 struct hostap_sta_driver_data *data,
102 if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
104 return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
108 static int hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
110 if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
112 return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
116 static int hostapd_set_sta_flags(struct hostapd_data *hapd,
117 struct sta_info *sta)
119 int set_flags, total_flags, flags_and, flags_or;
120 total_flags = hostapd_sta_flags_to_drv(sta->flags);
121 set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
122 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
123 sta->flags & WLAN_STA_AUTHORIZED)
124 set_flags |= WPA_STA_AUTHORIZED;
125 flags_or = total_flags & set_flags;
126 flags_and = total_flags | ~set_flags;
127 return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
128 flags_or, flags_and);
132 void hostapd_set_driver_ops(struct hostapd_driver_ops *ops)
134 ops->set_ap_wps_ie = hostapd_set_ap_wps_ie;
135 ops->send_mgmt_frame = hostapd_send_mgmt_frame;
136 ops->send_eapol = hostapd_send_eapol;
137 ops->set_authorized = hostapd_set_authorized;
138 ops->set_key = hostapd_set_key;
139 ops->read_sta_data = hostapd_read_sta_data;
140 ops->sta_clear_stats = hostapd_sta_clear_stats;
141 ops->set_sta_flags = hostapd_set_sta_flags;