hostapd.c
来自「最新的Host AP 新添加了许多pcmcia 的驱动」· C语言 代码 · 共 2,028 行 · 第 1/4 页
C
2,028 行
} fclose(f);}#endif /* HOSTAPD_DUMP_STATE */static void handle_dump_state(int sig, void *eloop_ctx, void *signal_ctx){#ifdef HOSTAPD_DUMP_STATE struct hapd_interfaces *hapds = (struct hapd_interfaces *) eloop_ctx; size_t i, j; for (i = 0; i < hapds->count; i++) { struct hostapd_iface *hapd_iface = hapds->iface[i]; for (j = 0; j < hapd_iface->num_bss; j++) hostapd_dump_state(hapd_iface->bss[j]); }#endif /* HOSTAPD_DUMP_STATE */}#endif /* CONFIG_NATIVE_WINDOWS */static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd, char *ifname){ int i; for (i = 0; i < NUM_WEP_KEYS; i++) { if (hostapd_set_encryption(ifname, hapd, "none", NULL, i, NULL, 0, i == 0 ? 1 : 0)) { wpa_printf(MSG_DEBUG, "Failed to clear default " "encryption keys (ifname=%s keyidx=%d)", ifname, i); } }#ifdef CONFIG_IEEE80211W if (hapd->conf->ieee80211w) { for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) { if (hostapd_set_encryption(ifname, hapd, "none", NULL, i, NULL, 0, i == 0 ? 1 : 0)) { wpa_printf(MSG_DEBUG, "Failed to clear " "default mgmt encryption keys " "(ifname=%s keyidx=%d)", ifname, i); } } }#endif /* CONFIG_IEEE80211W */}static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd){ hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface); return 0;}static int hostapd_broadcast_wep_set(struct hostapd_data *hapd){ int errors = 0, idx; struct hostapd_ssid *ssid = &hapd->conf->ssid; idx = ssid->wep.idx; if (ssid->wep.default_len && hostapd_set_encryption(hapd->conf->iface, hapd, "WEP", NULL, idx, ssid->wep.key[idx], ssid->wep.len[idx], idx == ssid->wep.idx)) { wpa_printf(MSG_WARNING, "Could not set WEP encryption."); errors++; } if (ssid->dyn_vlan_keys) { size_t i; for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) { const char *ifname; struct hostapd_wep_keys *key = ssid->dyn_vlan_keys[i]; if (key == NULL) continue; ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, i); if (ifname == NULL) continue; idx = key->idx; if (hostapd_set_encryption(ifname, hapd, "WEP", NULL, idx, key->key[idx], key->len[idx], idx == key->idx)) { wpa_printf(MSG_WARNING, "Could not set " "dynamic VLAN WEP encryption."); errors++; } } } return errors;}/** * hostapd_cleanup - Per-BSS cleanup (deinitialization) * @hapd: Pointer to BSS data * * This function is used to free all per-BSS data structures and resources. * This gets called in a loop for each BSS between calls to * hostapd_cleanup_iface_pre() and hostapd_cleanup_iface() when an interface * is deinitialized. Most of the modules that are initialized in * hostapd_setup_bss() are deinitialized here. */static void hostapd_cleanup(struct hostapd_data *hapd){ hostapd_ctrl_iface_deinit(hapd); os_free(hapd->default_wep_key); hapd->default_wep_key = NULL; iapp_deinit(hapd->iapp); hapd->iapp = NULL; accounting_deinit(hapd); rsn_preauth_iface_deinit(hapd); if (hapd->wpa_auth) { wpa_deinit(hapd->wpa_auth); hapd->wpa_auth = NULL; if (hostapd_set_privacy(hapd, 0)) { wpa_printf(MSG_DEBUG, "Could not disable " "PrivacyInvoked for interface %s", hapd->conf->iface); } if (hostapd_set_generic_elem(hapd, (u8 *) "", 0)) { wpa_printf(MSG_DEBUG, "Could not remove generic " "information element from interface %s", hapd->conf->iface); } } ieee802_1x_deinit(hapd); vlan_deinit(hapd); hostapd_acl_deinit(hapd); radius_client_deinit(hapd->radius); hapd->radius = NULL; radius_server_deinit(hapd->radius_srv); hapd->radius_srv = NULL;#ifdef CONFIG_IEEE80211R l2_packet_deinit(hapd->l2);#endif /* CONFIG_IEEE80211R */ hostapd_deinit_wps(hapd); hostapd_wireless_event_deinit(hapd);#ifdef EAP_TLS_FUNCS if (hapd->ssl_ctx) { tls_deinit(hapd->ssl_ctx); hapd->ssl_ctx = NULL; }#endif /* EAP_TLS_FUNCS */#ifdef EAP_SERVER if (hapd->eap_sim_db_priv) { eap_sim_db_deinit(hapd->eap_sim_db_priv); hapd->eap_sim_db_priv = NULL; }#endif /* EAP_SERVER */ if (hapd->interface_added && hostapd_bss_remove(hapd, hapd->conf->iface)) { wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s", hapd->conf->iface); }}/** * hostapd_cleanup_iface_pre - Preliminary per-interface cleanup * @iface: Pointer to interface data * * This function is called before per-BSS data structures are deinitialized * with hostapd_cleanup(). */static void hostapd_cleanup_iface_pre(struct hostapd_iface *iface){}/** * hostapd_cleanup_iface - Complete per-interface cleanup * @iface: Pointer to interface data * * This function is called after per-BSS data structures are deinitialized * with hostapd_cleanup(). */static void hostapd_cleanup_iface(struct hostapd_iface *iface){ hostapd_free_hw_features(iface->hw_features, iface->num_hw_features); iface->hw_features = NULL; os_free(iface->current_rates); iface->current_rates = NULL; ap_list_deinit(iface); hostapd_config_free(iface->conf); iface->conf = NULL; os_free(iface->config_fname); os_free(iface->bss); os_free(iface);}static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd){ int i; hostapd_broadcast_wep_set(hapd); if (hapd->conf->ssid.wep.default_len) return 0; for (i = 0; i < 4; i++) { if (hapd->conf->ssid.wep.key[i] && hostapd_set_encryption(iface, hapd, "WEP", NULL, i, hapd->conf->ssid.wep.key[i], hapd->conf->ssid.wep.len[i], i == hapd->conf->ssid.wep.idx)) { wpa_printf(MSG_WARNING, "Could not set WEP " "encryption."); return -1; } if (hapd->conf->ssid.wep.key[i] && i == hapd->conf->ssid.wep.idx) hostapd_set_privacy(hapd, 1); } return 0;}static int hostapd_flush_old_stations(struct hostapd_data *hapd){ int ret = 0; if (hostapd_drv_none(hapd)) return 0; wpa_printf(MSG_DEBUG, "Flushing old station entries"); if (hostapd_flush(hapd)) { wpa_printf(MSG_WARNING, "Could not connect to kernel driver."); ret = -1; } wpa_printf(MSG_DEBUG, "Deauthenticate all stations"); hostapd_deauth_all_stas(hapd); return ret;}static void hostapd_wpa_auth_logger(void *ctx, const u8 *addr, logger_level level, const char *txt){ struct hostapd_data *hapd = ctx; int hlevel; switch (level) { case LOGGER_WARNING: hlevel = HOSTAPD_LEVEL_WARNING; break; case LOGGER_INFO: hlevel = HOSTAPD_LEVEL_INFO; break; case LOGGER_DEBUG: default: hlevel = HOSTAPD_LEVEL_DEBUG; break; } hostapd_logger(hapd, addr, HOSTAPD_MODULE_WPA, hlevel, "%s", txt);}static void hostapd_wpa_auth_disconnect(void *ctx, const u8 *addr, u16 reason){ struct hostapd_data *hapd = ctx; struct sta_info *sta; wpa_printf(MSG_DEBUG, "%s: WPA authenticator requests disconnect: " "STA " MACSTR " reason %d", __func__, MAC2STR(addr), reason); sta = ap_get_sta(hapd, addr); hostapd_sta_deauth(hapd, addr, reason); if (sta == NULL) return; sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_AUTHORIZED); eloop_cancel_timeout(ap_handle_timer, hapd, sta); eloop_register_timeout(0, 0, ap_handle_timer, hapd, sta); sta->timeout_next = STA_REMOVE;}static void hostapd_wpa_auth_mic_failure_report(void *ctx, const u8 *addr){ struct hostapd_data *hapd = ctx; ieee80211_michael_mic_failure(hapd, addr, 0);}static void hostapd_wpa_auth_set_eapol(void *ctx, const u8 *addr, wpa_eapol_variable var, int value){ struct hostapd_data *hapd = ctx; struct sta_info *sta = ap_get_sta(hapd, addr); if (sta == NULL) return; switch (var) { case WPA_EAPOL_portEnabled: ieee802_1x_notify_port_enabled(sta->eapol_sm, value); break; case WPA_EAPOL_portValid: ieee802_1x_notify_port_valid(sta->eapol_sm, value); break; case WPA_EAPOL_authorized: ieee802_1x_set_sta_authorized(hapd, sta, value); break; case WPA_EAPOL_portControl_Auto: if (sta->eapol_sm) sta->eapol_sm->portControl = Auto; break; case WPA_EAPOL_keyRun: if (sta->eapol_sm) sta->eapol_sm->keyRun = value ? TRUE : FALSE; break; case WPA_EAPOL_keyAvailable: if (sta->eapol_sm) sta->eapol_sm->eap_if->eapKeyAvailable = value ? TRUE : FALSE; break; case WPA_EAPOL_keyDone: if (sta->eapol_sm) sta->eapol_sm->keyDone = value ? TRUE : FALSE; break; case WPA_EAPOL_inc_EapolFramesTx: if (sta->eapol_sm) sta->eapol_sm->dot1xAuthEapolFramesTx++; break; }}static int hostapd_wpa_auth_get_eapol(void *ctx, const u8 *addr, wpa_eapol_variable var){ struct hostapd_data *hapd = ctx; struct sta_info *sta = ap_get_sta(hapd, addr); if (sta == NULL || sta->eapol_sm == NULL) return -1; switch (var) { case WPA_EAPOL_keyRun: return sta->eapol_sm->keyRun; case WPA_EAPOL_keyAvailable: return sta->eapol_sm->eap_if->eapKeyAvailable; default: return -1; }}static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr, const u8 *prev_psk){ struct hostapd_data *hapd = ctx; return hostapd_get_psk(hapd->conf, addr, prev_psk);}static int hostapd_wpa_auth_get_msk(void *ctx, const u8 *addr, u8 *msk, size_t *len){ struct hostapd_data *hapd = ctx; const u8 *key; size_t keylen; struct sta_info *sta; sta = ap_get_sta(hapd, addr); if (sta == NULL) return -1; key = ieee802_1x_get_key(sta->eapol_sm, &keylen); if (key == NULL) return -1; if (keylen > *len) keylen = *len; os_memcpy(msk, key, keylen); *len = keylen; return 0;}static int hostapd_wpa_auth_set_key(void *ctx, int vlan_id, const char *alg, const u8 *addr, int idx, u8 *key, size_t key_len){ struct hostapd_data *hapd = ctx; const char *ifname = hapd->conf->iface; if (vlan_id > 0) { ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id); if (ifname == NULL) return -1; } return hostapd_set_encryption(ifname, hapd, alg, addr, idx, key, key_len, 1);}static int hostapd_wpa_auth_get_seqnum(void *ctx, const u8 *addr, int idx, u8 *seq){ struct hostapd_data *hapd = ctx; return hostapd_get_seqnum(hapd->conf->iface, hapd, addr, idx, seq);}static int hostapd_wpa_auth_get_seqnum_igtk(void *ctx, const u8 *addr, int idx, u8 *seq){ struct hostapd_data *hapd = ctx; return hostapd_get_seqnum_igtk(hapd->conf->iface, hapd, addr, idx, seq);}static int hostapd_wpa_auth_send_eapol(void *ctx, const u8 *addr, const u8 *data, size_t data_len, int encrypt){ struct hostapd_data *hapd = ctx; return hostapd_send_eapol(hapd, addr, data, data_len, encrypt);}static int hostapd_wpa_auth_for_each_sta( void *ctx, int (*cb)(struct wpa_state_machine *sm, void *ctx), void *cb_ctx){ struct hostapd_data *hapd = ctx; struct sta_info *sta; for (sta = hapd->sta_list; sta; sta = sta->next) { if (sta->wpa_sm && cb(sta->wpa_sm, cb_ctx)) return 1; } return 0;}static int hostapd_wpa_auth_for_each_auth( void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx), void *cb_ctx){ struct hostapd_data *ohapd; size_t i, j; struct hapd_interfaces *interfaces = eloop_get_user_data(); for (i = 0; i < interfaces->count; i++) { for (j = 0; j < interfaces->iface[i]->num_bss; j++) { ohapd = interfaces->iface[i]->bss[j]; if (cb(ohapd->wpa_auth, cb_ctx)) return 1; } } return 0;}static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto, const u8 *data, size_t data_len){ struct hostapd_data *hapd = ctx; if (hapd->driver && hapd->driver->send_ether) return hapd->driver->send_ether(hapd->drv_priv, dst, hapd->own_addr, proto, data, data_len); if (hapd->l2 == NULL) return -1; return l2_packet_send(hapd->l2, dst, proto, data, data_len);}#ifdef CONFIG_IEEE80211Rstatic int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst, const u8 *data, size_t data_len){ struct hostapd_data *hapd = ctx; int res; struct ieee80211_mgmt *m; size_t mlen; struct sta_info *sta; sta = ap_get_sta(hapd, dst); if (sta == NULL || sta->wpa_sm == NULL)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?