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(const char *ifname, struct hostapd_data *hapd,
69 if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
71 return hapd->driver->set_ieee8021x(ifname, hapd->drv_priv, enabled);
75 hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
77 if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
79 return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
84 hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
85 wpa_alg alg, const u8 *addr, int key_idx,
86 int set_tx, const u8 *seq, size_t seq_len,
87 const u8 *key, size_t key_len)
89 if (hapd->driver == NULL || hapd->driver->set_key == NULL)
91 return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
92 key_idx, set_tx, seq, seq_len, key,
97 hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
98 const u8 *addr, int idx, u8 *seq)
100 if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
102 return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
107 hostapd_get_seqnum_igtk(const char *ifname, struct hostapd_data *hapd,
108 const u8 *addr, int idx, u8 *seq)
110 if (hapd->driver == NULL || hapd->driver->get_seqnum_igtk == NULL)
112 return hapd->driver->get_seqnum_igtk(ifname, hapd->drv_priv, addr, idx,
117 hostapd_flush(struct hostapd_data *hapd)
119 if (hapd->driver == NULL || hapd->driver->flush == NULL)
121 return hapd->driver->flush(hapd->drv_priv);
125 hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
128 if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
130 return hapd->driver->set_generic_elem(hapd->conf->iface,
131 hapd->drv_priv, elem, elem_len);
135 hostapd_read_sta_data(struct hostapd_data *hapd,
136 struct hostap_sta_driver_data *data, const u8 *addr)
138 if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
140 return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
144 hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
145 size_t data_len, int encrypt)
147 if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
149 return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
155 hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
157 if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
159 return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
164 hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
166 if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
168 return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
173 hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
175 if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
177 return hapd->driver->sta_remove(hapd->drv_priv, addr);
181 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
183 if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
185 return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
190 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
192 if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
194 return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
199 hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len)
201 if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
203 return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
207 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
209 if (hapd->driver == NULL ||
210 hapd->driver->hapd_set_countermeasures == NULL)
212 return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
216 hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
217 u16 aid, u16 capability, const u8 *supp_rates,
218 size_t supp_rates_len, int flags, u16 listen_interval,
219 const struct ieee80211_ht_capabilities *ht_capabilities)
221 struct hostapd_sta_add_params params;
223 if (hapd->driver == NULL)
225 if (hapd->driver->sta_add == NULL)
228 os_memset(¶ms, 0, sizeof(params));
231 params.capability = capability;
232 params.supp_rates = supp_rates;
233 params.supp_rates_len = supp_rates_len;
234 params.flags = flags;
235 params.listen_interval = listen_interval;
236 params.ht_capabilities = ht_capabilities;
237 return hapd->driver->sta_add(ifname, hapd->drv_priv, ¶ms);
241 hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
243 if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
245 return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
249 hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
250 int ht_enabled, int sec_channel_offset)
252 struct hostapd_freq_params data;
253 if (hapd->driver == NULL)
255 if (hapd->driver->set_freq == NULL)
257 os_memset(&data, 0, sizeof(data));
260 data.channel = channel;
261 data.ht_enabled = ht_enabled;
262 data.sec_channel_offset = sec_channel_offset;
263 return hapd->driver->set_freq(hapd->drv_priv, &data);
267 hostapd_set_rts(struct hostapd_data *hapd, int rts)
269 if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
271 return hapd->driver->set_rts(hapd->drv_priv, rts);
275 hostapd_set_frag(struct hostapd_data *hapd, int frag)
277 if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
279 return hapd->driver->set_frag(hapd->drv_priv, frag);
283 hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
284 int total_flags, int flags_or, int flags_and)
286 if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
288 return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
289 flags_or, flags_and);
293 hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
294 int *basic_rates, int mode)
296 if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
298 return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
303 hostapd_set_country(struct hostapd_data *hapd, const char *country)
305 if (hapd->driver == NULL ||
306 hapd->driver->set_country == NULL)
308 return hapd->driver->set_country(hapd->drv_priv, country);
312 hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
314 if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
316 return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
320 hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
321 const u8 *head, size_t head_len,
322 const u8 *tail, size_t tail_len, int dtim_period,
325 if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
327 return hapd->driver->set_beacon(ifname, hapd->drv_priv,
328 head, head_len, tail, tail_len,
329 dtim_period, beacon_int);
333 hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
335 if (hapd->driver == NULL || hapd->driver->set_internal_bridge == NULL)
337 return hapd->driver->set_internal_bridge(hapd->drv_priv, value);
341 hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
343 if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
345 return hapd->driver->set_cts_protect(hapd->drv_priv, value);
349 hostapd_set_preamble(struct hostapd_data *hapd, int value)
351 if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
353 return hapd->driver->set_preamble(hapd->drv_priv, value);
357 hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
359 if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
361 return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
365 hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
366 int cw_min, int cw_max, int burst_time)
368 if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
370 return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
371 cw_min, cw_max, burst_time);
375 hostapd_bss_add(struct hostapd_data *hapd, const char *ifname, const u8 *bssid)
377 if (hapd->driver == NULL || hapd->driver->bss_add == NULL)
379 return hapd->driver->bss_add(hapd->drv_priv, ifname, bssid);
383 hostapd_bss_remove(struct hostapd_data *hapd, const char *ifname)
385 if (hapd->driver == NULL || hapd->driver->bss_remove == NULL)
387 return hapd->driver->bss_remove(hapd->drv_priv, ifname);
391 hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
394 if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
396 return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
400 hostapd_if_add(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
401 char *ifname, const u8 *addr)
403 if (hapd->driver == NULL || hapd->driver->if_add == NULL)
405 return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
410 hostapd_if_remove(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
411 char *ifname, const u8 *addr)
413 if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
415 return hapd->driver->if_remove(hapd->drv_priv, type, ifname, addr);
418 static inline struct hostapd_hw_modes *
419 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
422 if (hapd->driver == NULL ||
423 hapd->driver->get_hw_feature_data == NULL)
425 return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
430 hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
431 const u8 *addr, int vlan_id)
433 if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
435 return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
439 hostapd_driver_commit(struct hostapd_data *hapd)
441 if (hapd->driver == NULL || hapd->driver->commit == NULL)
443 return hapd->driver->commit(hapd->drv_priv);
447 hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
448 int accepted, u32 session_timeout)
450 if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
452 return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
457 hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
459 if (hapd->driver == NULL ||
460 hapd->driver->set_radius_acl_expire == NULL)
462 return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
466 hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
467 const u8 *ht_capab, size_t ht_capab_len,
468 const u8 *ht_oper, size_t ht_oper_len)
470 if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
471 ht_capab == NULL || ht_oper == NULL)
473 return hapd->driver->set_ht_params(
474 ifname, hapd->drv_priv, ht_capab, ht_capab_len,
475 ht_oper, ht_oper_len);
479 hostapd_drv_none(struct hostapd_data *hapd)
481 return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
485 hostapd_set_wps_beacon_ie(struct hostapd_data *hapd, const u8 *ie, size_t len)
487 if (hapd->driver == NULL || hapd->driver->set_wps_beacon_ie == NULL)
489 return hapd->driver->set_wps_beacon_ie(hapd->conf->iface,
490 hapd->drv_priv, ie, len);
494 hostapd_set_wps_probe_resp_ie(struct hostapd_data *hapd, const u8 *ie,
497 if (hapd->driver == NULL ||
498 hapd->driver->set_wps_probe_resp_ie == NULL)
500 return hapd->driver->set_wps_probe_resp_ie(hapd->conf->iface,
501 hapd->drv_priv, ie, len);
504 static inline int hostapd_driver_scan(struct hostapd_data *hapd,
505 struct wpa_driver_scan_params *params)
507 if (hapd->driver && hapd->driver->scan2)
508 return hapd->driver->scan2(hapd->drv_priv, params);
512 static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
513 struct hostapd_data *hapd)
515 if (hapd->driver && hapd->driver->get_scan_results2)
516 return hapd->driver->get_scan_results2(hapd->drv_priv);
520 #endif /* DRIVER_I_H */