2 * hostapd - internal driver interface wrappers
3 * Copyright (c) 2002-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.
18 #include "drivers/driver.h"
22 hostapd_driver_init(struct hostapd_data *hapd, const u8 *bssid)
24 struct wpa_init_params params;
28 if (hapd->driver == NULL || hapd->driver->hapd_init == NULL)
31 os_memset(¶ms, 0, sizeof(params));
33 params.ifname = hapd->conf->iface;
34 params.ssid = (const u8 *) hapd->conf->ssid.ssid;
35 params.ssid_len = hapd->conf->ssid.ssid_len;
36 params.test_socket = hapd->conf->test_socket;
37 params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
39 params.num_bridge = hapd->iface->num_bss;
40 params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
41 if (params.bridge == NULL)
43 for (i = 0; i < hapd->iface->num_bss; i++) {
44 struct hostapd_data *bss = hapd->iface->bss[i];
45 if (bss->conf->bridge[0])
46 params.bridge[i] = bss->conf->bridge;
49 params.own_addr = hapd->own_addr;
51 ret = hapd->driver->hapd_init(hapd, ¶ms);
52 os_free(params.bridge);
58 hostapd_driver_deinit(struct hostapd_data *hapd)
60 if (hapd->driver == NULL || hapd->driver->hapd_deinit == NULL)
62 hapd->driver->hapd_deinit(hapd->drv_priv);
66 hostapd_set_ieee8021x(struct hostapd_data *hapd, struct wpa_bss_params *params)
68 if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
70 return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
74 hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
76 if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
78 return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
83 hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
84 const u8 *addr, int idx, u8 *seq)
86 if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
88 return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
93 hostapd_flush(struct hostapd_data *hapd)
95 if (hapd->driver == NULL || hapd->driver->flush == NULL)
97 return hapd->driver->flush(hapd->drv_priv);
101 hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
104 if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
106 return hapd->driver->set_generic_elem(hapd->conf->iface,
107 hapd->drv_priv, elem, elem_len);
111 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
113 if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
115 return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
120 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
122 if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
124 return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
129 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
131 if (hapd->driver == NULL ||
132 hapd->driver->hapd_set_countermeasures == NULL)
134 return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
138 hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
139 u16 aid, u16 capability, const u8 *supp_rates,
140 size_t supp_rates_len, u16 listen_interval,
141 const struct ieee80211_ht_capabilities *ht_capabilities)
143 struct hostapd_sta_add_params params;
145 if (hapd->driver == NULL)
147 if (hapd->driver->sta_add == NULL)
150 os_memset(¶ms, 0, sizeof(params));
153 params.capability = capability;
154 params.supp_rates = supp_rates;
155 params.supp_rates_len = supp_rates_len;
156 params.listen_interval = listen_interval;
157 params.ht_capabilities = ht_capabilities;
158 return hapd->driver->sta_add(ifname, hapd->drv_priv, ¶ms);
162 hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
163 int ht_enabled, int sec_channel_offset)
165 struct hostapd_freq_params data;
166 if (hapd->driver == NULL)
168 if (hapd->driver->set_freq == NULL)
170 os_memset(&data, 0, sizeof(data));
173 data.channel = channel;
174 data.ht_enabled = ht_enabled;
175 data.sec_channel_offset = sec_channel_offset;
176 return hapd->driver->set_freq(hapd->drv_priv, &data);
180 hostapd_set_rts(struct hostapd_data *hapd, int rts)
182 if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
184 return hapd->driver->set_rts(hapd->drv_priv, rts);
188 hostapd_set_frag(struct hostapd_data *hapd, int frag)
190 if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
192 return hapd->driver->set_frag(hapd->drv_priv, frag);
196 hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
197 int total_flags, int flags_or, int flags_and)
199 if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
201 return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
202 flags_or, flags_and);
206 hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
207 int *basic_rates, int mode)
209 if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
211 return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
216 hostapd_set_country(struct hostapd_data *hapd, const char *country)
218 if (hapd->driver == NULL ||
219 hapd->driver->set_country == NULL)
221 return hapd->driver->set_country(hapd->drv_priv, country);
225 hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
227 if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
229 return hapd->driver->set_cts_protect(hapd->drv_priv, value);
233 hostapd_set_preamble(struct hostapd_data *hapd, int value)
235 if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
237 return hapd->driver->set_preamble(hapd->drv_priv, value);
241 hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
243 if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
245 return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
249 hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
250 int cw_min, int cw_max, int burst_time)
252 if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
254 return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
255 cw_min, cw_max, burst_time);
259 hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
262 if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
264 return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
268 hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
269 const char *ifname, const u8 *addr, void *bss_ctx)
271 if (hapd->driver == NULL || hapd->driver->if_add == NULL)
273 return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
274 ifname, addr, bss_ctx);
278 hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
281 if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
283 return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
286 static inline struct hostapd_hw_modes *
287 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
290 if (hapd->driver == NULL ||
291 hapd->driver->get_hw_feature_data == NULL)
293 return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
298 hostapd_driver_commit(struct hostapd_data *hapd)
300 if (hapd->driver == NULL || hapd->driver->commit == NULL)
302 return hapd->driver->commit(hapd->drv_priv);
306 hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
307 const u8 *ht_capab, size_t ht_capab_len,
308 const u8 *ht_oper, size_t ht_oper_len)
310 if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
311 ht_capab == NULL || ht_oper == NULL)
313 return hapd->driver->set_ht_params(
314 ifname, hapd->drv_priv, ht_capab, ht_capab_len,
315 ht_oper, ht_oper_len);
319 hostapd_drv_none(struct hostapd_data *hapd)
321 return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
324 static inline int hostapd_driver_scan(struct hostapd_data *hapd,
325 struct wpa_driver_scan_params *params)
327 if (hapd->driver && hapd->driver->scan2)
328 return hapd->driver->scan2(hapd->drv_priv, params);
332 static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
333 struct hostapd_data *hapd)
335 if (hapd->driver && hapd->driver->get_scan_results2)
336 return hapd->driver->get_scan_results2(hapd->drv_priv);
340 #endif /* DRIVER_I_H */