2 * hostapd - internal driver interface wrappers
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2007-2008, Intel Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
19 #include "drivers/driver.h"
23 hostapd_driver_init(struct hostapd_data *hapd, const u8 *bssid)
25 struct wpa_init_params params;
29 if (hapd->driver == NULL || hapd->driver->hapd_init == NULL)
32 os_memset(¶ms, 0, sizeof(params));
34 params.ifname = hapd->conf->iface;
35 params.ssid = (const u8 *) hapd->conf->ssid.ssid;
36 params.ssid_len = hapd->conf->ssid.ssid_len;
37 params.test_socket = hapd->conf->test_socket;
38 params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
40 params.num_bridge = hapd->iface->num_bss;
41 params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
42 if (params.bridge == NULL)
44 for (i = 0; i < hapd->iface->num_bss; i++) {
45 struct hostapd_data *bss = hapd->iface->bss[i];
46 if (bss->conf->bridge[0])
47 params.bridge[i] = bss->conf->bridge;
49 ret = hapd->driver->hapd_init(hapd, ¶ms);
50 os_free(params.bridge);
56 hostapd_driver_deinit(struct hostapd_data *hapd)
58 if (hapd->driver == NULL || hapd->driver->hapd_deinit == NULL)
60 hapd->driver->hapd_deinit(hapd->drv_priv);
64 hostapd_set_ieee8021x(const char *ifname, struct hostapd_data *hapd,
67 if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
69 return hapd->driver->set_ieee8021x(ifname, hapd->drv_priv, enabled);
73 hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
75 if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
77 return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
82 hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
83 wpa_alg alg, const u8 *addr, int key_idx,
84 int set_tx, const u8 *seq, size_t seq_len,
85 const u8 *key, size_t key_len)
87 if (hapd->driver == NULL || hapd->driver->hapd_set_key == NULL)
89 return hapd->driver->hapd_set_key(ifname, hapd->drv_priv, alg, addr,
90 key_idx, set_tx, seq, seq_len, key,
95 hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
96 const u8 *addr, int idx, u8 *seq)
98 if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
100 return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
105 hostapd_get_seqnum_igtk(const char *ifname, struct hostapd_data *hapd,
106 const u8 *addr, int idx, u8 *seq)
108 if (hapd->driver == NULL || hapd->driver->get_seqnum_igtk == NULL)
110 return hapd->driver->get_seqnum_igtk(ifname, hapd->drv_priv, addr, idx,
115 hostapd_flush(struct hostapd_data *hapd)
117 if (hapd->driver == NULL || hapd->driver->flush == NULL)
119 return hapd->driver->flush(hapd->drv_priv);
123 hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
126 if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
128 return hapd->driver->set_generic_elem(hapd->conf->iface,
129 hapd->drv_priv, elem, elem_len);
133 hostapd_read_sta_data(struct hostapd_data *hapd,
134 struct hostap_sta_driver_data *data, const u8 *addr)
136 if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
138 return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
142 hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
143 size_t data_len, int encrypt)
145 if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
147 return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
153 hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
155 if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
157 return hapd->driver->sta_deauth(hapd->drv_priv, addr, reason);
161 hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
163 if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
165 return hapd->driver->sta_disassoc(hapd->drv_priv, addr, reason);
169 hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
171 if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
173 return hapd->driver->sta_remove(hapd->drv_priv, addr);
177 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
179 if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
181 return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
186 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
188 if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
190 return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
195 hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len)
197 if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
199 return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
203 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
205 if (hapd->driver == NULL ||
206 hapd->driver->hapd_set_countermeasures == NULL)
208 return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
212 hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
213 u16 aid, u16 capability, const u8 *supp_rates,
214 size_t supp_rates_len, int flags, u16 listen_interval,
215 const struct ht_cap_ie *ht_capabilities)
217 struct hostapd_sta_add_params params;
219 if (hapd->driver == NULL)
221 if (hapd->driver->sta_add == NULL)
224 os_memset(¶ms, 0, sizeof(params));
227 params.capability = capability;
228 params.supp_rates = supp_rates;
229 params.supp_rates_len = supp_rates_len;
230 params.flags = flags;
231 params.listen_interval = listen_interval;
232 params.ht_capabilities = ht_capabilities;
233 return hapd->driver->sta_add(ifname, hapd->drv_priv, ¶ms);
237 hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
239 if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
241 return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
245 hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
246 int ht_enabled, int sec_channel_offset)
248 struct hostapd_freq_params data;
249 if (hapd->driver == NULL)
251 if (hapd->driver->set_freq == NULL)
253 os_memset(&data, 0, sizeof(data));
256 data.channel = channel;
257 data.ht_enabled = ht_enabled;
258 data.sec_channel_offset = sec_channel_offset;
259 return hapd->driver->set_freq(hapd->drv_priv, &data);
263 hostapd_set_rts(struct hostapd_data *hapd, int rts)
265 if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
267 return hapd->driver->set_rts(hapd->drv_priv, rts);
271 hostapd_set_frag(struct hostapd_data *hapd, int frag)
273 if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
275 return hapd->driver->set_frag(hapd->drv_priv, frag);
279 hostapd_set_retry(struct hostapd_data *hapd, int short_retry, int long_retry)
281 if (hapd->driver == NULL || hapd->driver->set_retry == NULL)
283 return hapd->driver->set_retry(hapd->drv_priv, short_retry,
288 hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
289 int total_flags, int flags_or, int flags_and)
291 if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
293 return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
294 flags_or, flags_and);
298 hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
299 int *basic_rates, int mode)
301 if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
303 return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
308 hostapd_set_country(struct hostapd_data *hapd, const char *country)
310 if (hapd->driver == NULL ||
311 hapd->driver->set_country == NULL)
313 return hapd->driver->set_country(hapd->drv_priv, country);
317 hostapd_set_ieee80211d(struct hostapd_data *hapd, int enabled)
319 if (hapd->driver == NULL ||
320 hapd->driver->set_ieee80211d == NULL)
322 return hapd->driver->set_ieee80211d(hapd->drv_priv, enabled);
326 hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
328 if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
330 return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
334 hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
335 const u8 *head, size_t head_len,
336 const u8 *tail, size_t tail_len, int dtim_period)
338 if (hapd->driver == NULL || hapd->driver->hapd_set_beacon == NULL)
340 return hapd->driver->hapd_set_beacon(ifname, hapd->drv_priv,
342 tail, tail_len, dtim_period);
346 hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
348 if (hapd->driver == NULL || hapd->driver->set_internal_bridge == NULL)
350 return hapd->driver->set_internal_bridge(hapd->drv_priv, value);
354 hostapd_set_beacon_int(struct hostapd_data *hapd, int value)
356 if (hapd->driver == NULL || hapd->driver->set_beacon_int == NULL)
358 return hapd->driver->set_beacon_int(hapd->drv_priv, value);
362 hostapd_set_broadcast_ssid(struct hostapd_data *hapd, int value)
364 if (hapd->driver == NULL || hapd->driver->set_broadcast_ssid == NULL)
366 return hapd->driver->set_broadcast_ssid(hapd->drv_priv, value);
370 hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
372 if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
374 return hapd->driver->set_cts_protect(hapd->drv_priv, value);
378 hostapd_set_preamble(struct hostapd_data *hapd, int value)
380 if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
382 return hapd->driver->set_preamble(hapd->drv_priv, value);
386 hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
388 if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
390 return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
394 hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
395 int cw_min, int cw_max, int burst_time)
397 if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
399 return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
400 cw_min, cw_max, burst_time);
404 hostapd_bss_add(struct hostapd_data *hapd, const char *ifname, const u8 *bssid)
406 if (hapd->driver == NULL || hapd->driver->bss_add == NULL)
408 return hapd->driver->bss_add(hapd->drv_priv, ifname, bssid);
412 hostapd_bss_remove(struct hostapd_data *hapd, const char *ifname)
414 if (hapd->driver == NULL || hapd->driver->bss_remove == NULL)
416 return hapd->driver->bss_remove(hapd->drv_priv, ifname);
420 hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
423 if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
425 return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
429 hostapd_if_add(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
430 char *ifname, const u8 *addr)
432 if (hapd->driver == NULL || hapd->driver->if_add == NULL)
434 return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
439 hostapd_if_update(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
440 char *ifname, const u8 *addr)
442 if (hapd->driver == NULL || hapd->driver->if_update == NULL)
444 return hapd->driver->if_update(hapd->drv_priv, type, ifname, addr);
448 hostapd_if_remove(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
449 char *ifname, const u8 *addr)
451 if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
453 return hapd->driver->if_remove(hapd->drv_priv, type, ifname, addr);
457 hostapd_passive_scan(struct hostapd_data *hapd, int now, int our_mode_only,
458 int interval, int _listen, int *channel,
461 if (hapd->driver == NULL || hapd->driver->passive_scan == NULL)
463 return hapd->driver->passive_scan(hapd->drv_priv, now, our_mode_only,
464 interval, _listen, channel, last_rx);
467 static inline struct hostapd_hw_modes *
468 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
471 if (hapd->driver == NULL ||
472 hapd->driver->get_hw_feature_data == NULL)
474 return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
479 hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
480 const u8 *addr, int vlan_id)
482 if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
484 return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
488 hostapd_driver_commit(struct hostapd_data *hapd)
490 if (hapd->driver == NULL || hapd->driver->commit == NULL)
492 return hapd->driver->commit(hapd->drv_priv);
496 hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
497 int accepted, u32 session_timeout)
499 if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
501 return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
506 hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
508 if (hapd->driver == NULL ||
509 hapd->driver->set_radius_acl_expire == NULL)
511 return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
514 #ifdef CONFIG_IEEE80211N
516 hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
517 const u8 *ht_capab, size_t ht_capab_len,
518 const u8 *ht_oper, size_t ht_oper_len)
520 if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
521 ht_capab == NULL || ht_oper == NULL)
523 return hapd->driver->set_ht_params(
524 ifname, hapd->drv_priv, ht_capab, ht_capab_len,
525 ht_oper, ht_oper_len);
527 #endif /* CONFIG_IEEE80211N */
530 hostapd_drv_none(struct hostapd_data *hapd)
532 return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
536 hostapd_set_wps_beacon_ie(struct hostapd_data *hapd, const u8 *ie, size_t len)
538 if (hapd->driver == NULL || hapd->driver->set_wps_beacon_ie == NULL)
540 return hapd->driver->set_wps_beacon_ie(hapd->conf->iface,
541 hapd->drv_priv, ie, len);
545 hostapd_set_wps_probe_resp_ie(struct hostapd_data *hapd, const u8 *ie,
548 if (hapd->driver == NULL ||
549 hapd->driver->set_wps_probe_resp_ie == NULL)
551 return hapd->driver->set_wps_probe_resp_ie(hapd->conf->iface,
552 hapd->drv_priv, ie, len);
555 static inline int hostapd_driver_set_mode(struct hostapd_data *hapd, int mode)
557 if (hapd->driver == NULL || hapd->driver->set_mode == NULL)
559 return hapd->driver->set_mode(hapd->drv_priv, mode);
562 static inline int hostapd_driver_scan(struct hostapd_data *hapd,
563 struct wpa_driver_scan_params *params)
565 if (hapd->driver && hapd->driver->scan2)
566 return hapd->driver->scan2(hapd->drv_priv, params);
570 static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
571 struct hostapd_data *hapd)
573 if (hapd->driver && hapd->driver->get_scan_results2)
574 return hapd->driver->get_scan_results2(hapd->drv_priv);
578 #endif /* DRIVER_I_H */