00001
00017 #ifndef DRIVER_I_H
00018 #define DRIVER_I_H
00019
00020 #include "drivers/driver.h"
00021 #include "config.h"
00022
00023 static inline void *
00024 hostapd_driver_init(struct hostapd_data *hapd, const u8 *bssid)
00025 {
00026 struct wpa_init_params params;
00027 void *ret;
00028 size_t i;
00029
00030 if (hapd->driver == NULL || hapd->driver->hapd_init == NULL)
00031 return NULL;
00032
00033 os_memset(¶ms, 0, sizeof(params));
00034 params.bssid = bssid;
00035 params.ifname = hapd->conf->iface;
00036 params.ssid = (const u8 *) hapd->conf->ssid.ssid;
00037 params.ssid_len = hapd->conf->ssid.ssid_len;
00038 params.test_socket = hapd->conf->test_socket;
00039 params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
00040
00041 params.num_bridge = hapd->iface->num_bss;
00042 params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
00043 if (params.bridge == NULL)
00044 return NULL;
00045 for (i = 0; i < hapd->iface->num_bss; i++) {
00046 struct hostapd_data *bss = hapd->iface->bss[i];
00047 if (bss->conf->bridge[0])
00048 params.bridge[i] = bss->conf->bridge;
00049 }
00050
00051 params.own_addr = hapd->own_addr;
00052
00053 ret = hapd->driver->hapd_init(hapd, ¶ms);
00054 os_free(params.bridge);
00055
00056 return ret;
00057 }
00058
00059 static inline void
00060 hostapd_driver_deinit(struct hostapd_data *hapd)
00061 {
00062 if (hapd->driver == NULL || hapd->driver->hapd_deinit == NULL)
00063 return;
00064 hapd->driver->hapd_deinit(hapd->drv_priv);
00065 }
00066
00067 static inline int
00068 hostapd_set_ieee8021x(const char *ifname, struct hostapd_data *hapd,
00069 int enabled)
00070 {
00071 if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
00072 return 0;
00073 return hapd->driver->set_ieee8021x(ifname, hapd->drv_priv, enabled);
00074 }
00075
00076 static inline int
00077 hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
00078 {
00079 if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
00080 return 0;
00081 return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
00082 enabled);
00083 }
00084
00085 static inline int
00086 hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
00087 wpa_alg alg, const u8 *addr, int key_idx,
00088 int set_tx, const u8 *seq, size_t seq_len,
00089 const u8 *key, size_t key_len)
00090 {
00091 if (hapd->driver == NULL || hapd->driver->set_key == NULL)
00092 return 0;
00093 return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
00094 key_idx, set_tx, seq, seq_len, key,
00095 key_len);
00096 }
00097
00098 static inline int
00099 hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
00100 const u8 *addr, int idx, u8 *seq)
00101 {
00102 if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
00103 return 0;
00104 return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
00105 seq);
00106 }
00107
00108 static inline int
00109 hostapd_get_seqnum_igtk(const char *ifname, struct hostapd_data *hapd,
00110 const u8 *addr, int idx, u8 *seq)
00111 {
00112 if (hapd->driver == NULL || hapd->driver->get_seqnum_igtk == NULL)
00113 return -1;
00114 return hapd->driver->get_seqnum_igtk(ifname, hapd->drv_priv, addr, idx,
00115 seq);
00116 }
00117
00118 static inline int
00119 hostapd_flush(struct hostapd_data *hapd)
00120 {
00121 if (hapd->driver == NULL || hapd->driver->flush == NULL)
00122 return 0;
00123 return hapd->driver->flush(hapd->drv_priv);
00124 }
00125
00126 static inline int
00127 hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
00128 size_t elem_len)
00129 {
00130 if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
00131 return 0;
00132 return hapd->driver->set_generic_elem(hapd->conf->iface,
00133 hapd->drv_priv, elem, elem_len);
00134 }
00135
00136 static inline int
00137 hostapd_read_sta_data(struct hostapd_data *hapd,
00138 struct hostap_sta_driver_data *data, const u8 *addr)
00139 {
00140 if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
00141 return -1;
00142 return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
00143 }
00144
00145 static inline int
00146 hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
00147 size_t data_len, int encrypt)
00148 {
00149 if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
00150 return 0;
00151 return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
00152 data_len, encrypt,
00153 hapd->own_addr);
00154 }
00155
00156 static inline int
00157 hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
00158 {
00159 if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
00160 return 0;
00161 return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
00162 reason);
00163 }
00164
00165 static inline int
00166 hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
00167 {
00168 if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
00169 return 0;
00170 return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
00171 reason);
00172 }
00173
00174 static inline int
00175 hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
00176 {
00177 if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
00178 return 0;
00179 return hapd->driver->sta_remove(hapd->drv_priv, addr);
00180 }
00181
00182 static inline int
00183 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
00184 {
00185 if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
00186 return 0;
00187 return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
00188 buf, len);
00189 }
00190
00191 static inline int
00192 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
00193 {
00194 if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
00195 return 0;
00196 return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
00197 buf, len);
00198 }
00199
00200 static inline int
00201 hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len)
00202 {
00203 if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
00204 return 0;
00205 return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
00206 }
00207
00208 static inline int
00209 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
00210 {
00211 if (hapd->driver == NULL ||
00212 hapd->driver->hapd_set_countermeasures == NULL)
00213 return 0;
00214 return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
00215 }
00216
00217 static inline int
00218 hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
00219 u16 aid, u16 capability, const u8 *supp_rates,
00220 size_t supp_rates_len, int flags, u16 listen_interval,
00221 const struct ht_cap_ie *ht_capabilities)
00222 {
00223 struct hostapd_sta_add_params params;
00224
00225 if (hapd->driver == NULL)
00226 return 0;
00227 if (hapd->driver->sta_add == NULL)
00228 return 0;
00229
00230 os_memset(¶ms, 0, sizeof(params));
00231 params.addr = addr;
00232 params.aid = aid;
00233 params.capability = capability;
00234 params.supp_rates = supp_rates;
00235 params.supp_rates_len = supp_rates_len;
00236 params.flags = flags;
00237 params.listen_interval = listen_interval;
00238 params.ht_capabilities = ht_capabilities;
00239 return hapd->driver->sta_add(ifname, hapd->drv_priv, ¶ms);
00240 }
00241
00242 static inline int
00243 hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
00244 {
00245 if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
00246 return 0;
00247 return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
00248 }
00249
00250 static inline int
00251 hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
00252 int ht_enabled, int sec_channel_offset)
00253 {
00254 struct hostapd_freq_params data;
00255 if (hapd->driver == NULL)
00256 return 0;
00257 if (hapd->driver->set_freq == NULL)
00258 return 0;
00259 os_memset(&data, 0, sizeof(data));
00260 data.mode = mode;
00261 data.freq = freq;
00262 data.channel = channel;
00263 data.ht_enabled = ht_enabled;
00264 data.sec_channel_offset = sec_channel_offset;
00265 return hapd->driver->set_freq(hapd->drv_priv, &data);
00266 }
00267
00268 static inline int
00269 hostapd_set_rts(struct hostapd_data *hapd, int rts)
00270 {
00271 if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
00272 return 0;
00273 return hapd->driver->set_rts(hapd->drv_priv, rts);
00274 }
00275
00276 static inline int
00277 hostapd_set_frag(struct hostapd_data *hapd, int frag)
00278 {
00279 if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
00280 return 0;
00281 return hapd->driver->set_frag(hapd->drv_priv, frag);
00282 }
00283
00284 static inline int
00285 hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
00286 int total_flags, int flags_or, int flags_and)
00287 {
00288 if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
00289 return 0;
00290 return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
00291 flags_or, flags_and);
00292 }
00293
00294 static inline int
00295 hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
00296 int *basic_rates, int mode)
00297 {
00298 if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
00299 return 0;
00300 return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
00301 basic_rates, mode);
00302 }
00303
00304 static inline int
00305 hostapd_set_country(struct hostapd_data *hapd, const char *country)
00306 {
00307 if (hapd->driver == NULL ||
00308 hapd->driver->set_country == NULL)
00309 return 0;
00310 return hapd->driver->set_country(hapd->drv_priv, country);
00311 }
00312
00313 static inline int
00314 hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
00315 {
00316 if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
00317 return 0;
00318 return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
00319 }
00320
00321 static inline int
00322 hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
00323 const u8 *head, size_t head_len,
00324 const u8 *tail, size_t tail_len, int dtim_period,
00325 int beacon_int)
00326 {
00327 if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
00328 return 0;
00329 return hapd->driver->set_beacon(ifname, hapd->drv_priv,
00330 head, head_len, tail, tail_len,
00331 dtim_period, beacon_int);
00332 }
00333
00334 static inline int
00335 hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
00336 {
00337 if (hapd->driver == NULL || hapd->driver->set_internal_bridge == NULL)
00338 return 0;
00339 return hapd->driver->set_internal_bridge(hapd->drv_priv, value);
00340 }
00341
00342 static inline int
00343 hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
00344 {
00345 if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
00346 return 0;
00347 return hapd->driver->set_cts_protect(hapd->drv_priv, value);
00348 }
00349
00350 static inline int
00351 hostapd_set_preamble(struct hostapd_data *hapd, int value)
00352 {
00353 if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
00354 return 0;
00355 return hapd->driver->set_preamble(hapd->drv_priv, value);
00356 }
00357
00358 static inline int
00359 hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
00360 {
00361 if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
00362 return 0;
00363 return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
00364 }
00365
00366 static inline int
00367 hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
00368 int cw_min, int cw_max, int burst_time)
00369 {
00370 if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
00371 return 0;
00372 return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
00373 cw_min, cw_max, burst_time);
00374 }
00375
00376 static inline int
00377 hostapd_bss_add(struct hostapd_data *hapd, const char *ifname, const u8 *bssid)
00378 {
00379 if (hapd->driver == NULL || hapd->driver->bss_add == NULL)
00380 return 0;
00381 return hapd->driver->bss_add(hapd->drv_priv, ifname, bssid);
00382 }
00383
00384 static inline int
00385 hostapd_bss_remove(struct hostapd_data *hapd, const char *ifname)
00386 {
00387 if (hapd->driver == NULL || hapd->driver->bss_remove == NULL)
00388 return 0;
00389 return hapd->driver->bss_remove(hapd->drv_priv, ifname);
00390 }
00391
00392 static inline int
00393 hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
00394 const u8 *mask)
00395 {
00396 if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
00397 return 1;
00398 return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
00399 }
00400
00401 static inline int
00402 hostapd_if_add(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
00403 char *ifname, const u8 *addr)
00404 {
00405 if (hapd->driver == NULL || hapd->driver->if_add == NULL)
00406 return -1;
00407 return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
00408 ifname, addr);
00409 }
00410
00411 static inline int
00412 hostapd_if_update(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
00413 char *ifname, const u8 *addr)
00414 {
00415 if (hapd->driver == NULL || hapd->driver->if_update == NULL)
00416 return -1;
00417 return hapd->driver->if_update(hapd->drv_priv, type, ifname, addr);
00418 }
00419
00420 static inline int
00421 hostapd_if_remove(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
00422 char *ifname, const u8 *addr)
00423 {
00424 if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
00425 return -1;
00426 return hapd->driver->if_remove(hapd->drv_priv, type, ifname, addr);
00427 }
00428
00429 static inline struct hostapd_hw_modes *
00430 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
00431 u16 *flags)
00432 {
00433 if (hapd->driver == NULL ||
00434 hapd->driver->get_hw_feature_data == NULL)
00435 return NULL;
00436 return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
00437 flags);
00438 }
00439
00440 static inline int
00441 hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
00442 const u8 *addr, int vlan_id)
00443 {
00444 if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
00445 return 0;
00446 return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
00447 }
00448
00449 static inline int
00450 hostapd_driver_commit(struct hostapd_data *hapd)
00451 {
00452 if (hapd->driver == NULL || hapd->driver->commit == NULL)
00453 return 0;
00454 return hapd->driver->commit(hapd->drv_priv);
00455 }
00456
00457 static inline int
00458 hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
00459 int accepted, u32 session_timeout)
00460 {
00461 if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
00462 return 0;
00463 return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
00464 session_timeout);
00465 }
00466
00467 static inline int
00468 hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
00469 {
00470 if (hapd->driver == NULL ||
00471 hapd->driver->set_radius_acl_expire == NULL)
00472 return 0;
00473 return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
00474 }
00475
00476 #ifdef CONFIG_IEEE80211N
00477 static inline int
00478 hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
00479 const u8 *ht_capab, size_t ht_capab_len,
00480 const u8 *ht_oper, size_t ht_oper_len)
00481 {
00482 if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
00483 ht_capab == NULL || ht_oper == NULL)
00484 return 0;
00485 return hapd->driver->set_ht_params(
00486 ifname, hapd->drv_priv, ht_capab, ht_capab_len,
00487 ht_oper, ht_oper_len);
00488 }
00489 #endif
00490
00491 static inline int
00492 hostapd_drv_none(struct hostapd_data *hapd)
00493 {
00494 return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
00495 }
00496
00497 static inline int
00498 hostapd_set_wps_beacon_ie(struct hostapd_data *hapd, const u8 *ie, size_t len)
00499 {
00500 if (hapd->driver == NULL || hapd->driver->set_wps_beacon_ie == NULL)
00501 return 0;
00502 return hapd->driver->set_wps_beacon_ie(hapd->conf->iface,
00503 hapd->drv_priv, ie, len);
00504 }
00505
00506 static inline int
00507 hostapd_set_wps_probe_resp_ie(struct hostapd_data *hapd, const u8 *ie,
00508 size_t len)
00509 {
00510 if (hapd->driver == NULL ||
00511 hapd->driver->set_wps_probe_resp_ie == NULL)
00512 return 0;
00513 return hapd->driver->set_wps_probe_resp_ie(hapd->conf->iface,
00514 hapd->drv_priv, ie, len);
00515 }
00516
00517 static inline int hostapd_driver_scan(struct hostapd_data *hapd,
00518 struct wpa_driver_scan_params *params)
00519 {
00520 if (hapd->driver && hapd->driver->scan2)
00521 return hapd->driver->scan2(hapd->drv_priv, params);
00522 return -1;
00523 }
00524
00525 static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
00526 struct hostapd_data *hapd)
00527 {
00528 if (hapd->driver && hapd->driver->get_scan_results2)
00529 return hapd->driver->get_scan_results2(hapd->drv_priv);
00530 return NULL;
00531 }
00532
00533 #endif
00534