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;
50 params.own_addr = hapd->own_addr;
52 ret = hapd->driver->hapd_init(hapd, ¶ms);
53 os_free(params.bridge);
59 hostapd_driver_deinit(struct hostapd_data *hapd)
61 if (hapd->driver == NULL || hapd->driver->hapd_deinit == NULL)
63 hapd->driver->hapd_deinit(hapd->drv_priv);
67 hostapd_set_ieee8021x(const char *ifname, struct hostapd_data *hapd,
70 if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
72 return hapd->driver->set_ieee8021x(ifname, hapd->drv_priv, enabled);
76 hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
78 if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
80 return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
85 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 hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
99 const u8 *addr, int idx, u8 *seq)
101 if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
103 return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
108 hostapd_get_seqnum_igtk(const char *ifname, struct hostapd_data *hapd,
109 const u8 *addr, int idx, u8 *seq)
111 if (hapd->driver == NULL || hapd->driver->get_seqnum_igtk == NULL)
113 return hapd->driver->get_seqnum_igtk(ifname, hapd->drv_priv, addr, idx,
118 hostapd_flush(struct hostapd_data *hapd)
120 if (hapd->driver == NULL || hapd->driver->flush == NULL)
122 return hapd->driver->flush(hapd->drv_priv);
126 hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
129 if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
131 return hapd->driver->set_generic_elem(hapd->conf->iface,
132 hapd->drv_priv, elem, elem_len);
136 hostapd_read_sta_data(struct hostapd_data *hapd,
137 struct hostap_sta_driver_data *data, const u8 *addr)
139 if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
141 return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
145 hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
146 size_t data_len, int encrypt)
148 if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
150 return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
156 hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
158 if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
160 return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
165 hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
167 if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
169 return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
174 hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
176 if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
178 return hapd->driver->sta_remove(hapd->drv_priv, addr);
182 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
184 if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
186 return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
191 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
193 if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
195 return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
200 hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len)
202 if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
204 return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
208 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
210 if (hapd->driver == NULL ||
211 hapd->driver->hapd_set_countermeasures == NULL)
213 return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
217 hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
218 u16 aid, u16 capability, const u8 *supp_rates,
219 size_t supp_rates_len, int flags, u16 listen_interval,
220 const struct ht_cap_ie *ht_capabilities)
222 struct hostapd_sta_add_params params;
224 if (hapd->driver == NULL)
226 if (hapd->driver->sta_add == NULL)
229 os_memset(¶ms, 0, sizeof(params));
232 params.capability = capability;
233 params.supp_rates = supp_rates;
234 params.supp_rates_len = supp_rates_len;
235 params.flags = flags;
236 params.listen_interval = listen_interval;
237 params.ht_capabilities = ht_capabilities;
238 return hapd->driver->sta_add(ifname, hapd->drv_priv, ¶ms);
242 hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
244 if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
246 return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
250 hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
251 int ht_enabled, int sec_channel_offset)
253 struct hostapd_freq_params data;
254 if (hapd->driver == NULL)
256 if (hapd->driver->set_freq == NULL)
258 os_memset(&data, 0, sizeof(data));
261 data.channel = channel;
262 data.ht_enabled = ht_enabled;
263 data.sec_channel_offset = sec_channel_offset;
264 return hapd->driver->set_freq(hapd->drv_priv, &data);
268 hostapd_set_rts(struct hostapd_data *hapd, int rts)
270 if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
272 return hapd->driver->set_rts(hapd->drv_priv, rts);
276 hostapd_set_frag(struct hostapd_data *hapd, int frag)
278 if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
280 return hapd->driver->set_frag(hapd->drv_priv, frag);
284 hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
285 int total_flags, int flags_or, int flags_and)
287 if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
289 return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
290 flags_or, flags_and);
294 hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
295 int *basic_rates, int mode)
297 if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
299 return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
304 hostapd_set_country(struct hostapd_data *hapd, const char *country)
306 if (hapd->driver == NULL ||
307 hapd->driver->set_country == NULL)
309 return hapd->driver->set_country(hapd->drv_priv, country);
313 hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
315 if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
317 return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
321 hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
322 const u8 *head, size_t head_len,
323 const u8 *tail, size_t tail_len, int dtim_period,
326 if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
328 return hapd->driver->set_beacon(ifname, hapd->drv_priv,
329 head, head_len, tail, tail_len,
330 dtim_period, beacon_int);
334 hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
336 if (hapd->driver == NULL || hapd->driver->set_internal_bridge == NULL)
338 return hapd->driver->set_internal_bridge(hapd->drv_priv, value);
342 hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
344 if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
346 return hapd->driver->set_cts_protect(hapd->drv_priv, value);
350 hostapd_set_preamble(struct hostapd_data *hapd, int value)
352 if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
354 return hapd->driver->set_preamble(hapd->drv_priv, value);
358 hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
360 if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
362 return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
366 hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
367 int cw_min, int cw_max, int burst_time)
369 if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
371 return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
372 cw_min, cw_max, burst_time);
376 hostapd_bss_add(struct hostapd_data *hapd, const char *ifname, const u8 *bssid)
378 if (hapd->driver == NULL || hapd->driver->bss_add == NULL)
380 return hapd->driver->bss_add(hapd->drv_priv, ifname, bssid);
384 hostapd_bss_remove(struct hostapd_data *hapd, const char *ifname)
386 if (hapd->driver == NULL || hapd->driver->bss_remove == NULL)
388 return hapd->driver->bss_remove(hapd->drv_priv, ifname);
392 hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
395 if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
397 return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
401 hostapd_if_add(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
402 char *ifname, const u8 *addr)
404 if (hapd->driver == NULL || hapd->driver->if_add == NULL)
406 return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
411 hostapd_if_update(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
412 char *ifname, const u8 *addr)
414 if (hapd->driver == NULL || hapd->driver->if_update == NULL)
416 return hapd->driver->if_update(hapd->drv_priv, type, ifname, addr);
420 hostapd_if_remove(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
421 char *ifname, const u8 *addr)
423 if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
425 return hapd->driver->if_remove(hapd->drv_priv, type, ifname, addr);
428 static inline struct hostapd_hw_modes *
429 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
432 if (hapd->driver == NULL ||
433 hapd->driver->get_hw_feature_data == NULL)
435 return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
440 hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
441 const u8 *addr, int vlan_id)
443 if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
445 return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
449 hostapd_driver_commit(struct hostapd_data *hapd)
451 if (hapd->driver == NULL || hapd->driver->commit == NULL)
453 return hapd->driver->commit(hapd->drv_priv);
457 hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
458 int accepted, u32 session_timeout)
460 if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
462 return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
467 hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
469 if (hapd->driver == NULL ||
470 hapd->driver->set_radius_acl_expire == NULL)
472 return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
475 #ifdef CONFIG_IEEE80211N
477 hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
478 const u8 *ht_capab, size_t ht_capab_len,
479 const u8 *ht_oper, size_t ht_oper_len)
481 if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
482 ht_capab == NULL || ht_oper == NULL)
484 return hapd->driver->set_ht_params(
485 ifname, hapd->drv_priv, ht_capab, ht_capab_len,
486 ht_oper, ht_oper_len);
488 #endif /* CONFIG_IEEE80211N */
491 hostapd_drv_none(struct hostapd_data *hapd)
493 return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
497 hostapd_set_wps_beacon_ie(struct hostapd_data *hapd, const u8 *ie, size_t len)
499 if (hapd->driver == NULL || hapd->driver->set_wps_beacon_ie == NULL)
501 return hapd->driver->set_wps_beacon_ie(hapd->conf->iface,
502 hapd->drv_priv, ie, len);
506 hostapd_set_wps_probe_resp_ie(struct hostapd_data *hapd, const u8 *ie,
509 if (hapd->driver == NULL ||
510 hapd->driver->set_wps_probe_resp_ie == NULL)
512 return hapd->driver->set_wps_probe_resp_ie(hapd->conf->iface,
513 hapd->drv_priv, ie, len);
516 static inline int hostapd_driver_scan(struct hostapd_data *hapd,
517 struct wpa_driver_scan_params *params)
519 if (hapd->driver && hapd->driver->scan2)
520 return hapd->driver->scan2(hapd->drv_priv, params);
524 static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
525 struct hostapd_data *hapd)
527 if (hapd->driver && hapd->driver->get_scan_results2)
528 return hapd->driver->get_scan_results2(hapd->drv_priv);
532 #endif /* DRIVER_I_H */