X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=hostapd%2Fhostapd.c;h=da873d0b947feb5788c260d8fe551b328784ea03;hb=03da66bd59567c90dc3b3b0892c3346472a0b413;hp=f2272424f5bb5fc20f238b1495492af7514c2466;hpb=9c6d8e1db5ea47b044074c1b818fae74aaea2185;p=libeap.git diff --git a/hostapd/hostapd.c b/hostapd/hostapd.c index f227242..da873d0 100644 --- a/hostapd/hostapd.c +++ b/hostapd/hostapd.c @@ -14,31 +14,32 @@ #include "includes.h" +#include "common.h" #include "eloop.h" +#include "crypto/tls.h" +#include "common/ieee802_11_defs.h" +#include "eapol_auth/eapol_auth_sm.h" +#include "radius/radius_client.h" +#include "radius/radius_server.h" +#include "eap_server/eap_sim_db.h" +#include "eap_server/eap.h" +#include "eap_server/tncs.h" +#include "l2_packet/l2_packet.h" #include "hostapd.h" #include "ieee802_1x.h" #include "beacon.h" #include "hw_features.h" #include "accounting.h" -#include "eapol_sm.h" #include "iapp.h" -#include "ieee802_11_defs.h" #include "ieee802_11_auth.h" +#include "sta_flags.h" #include "sta_info.h" #include "ap_list.h" #include "driver_i.h" -#include "radius/radius_client.h" -#include "radius/radius_server.h" #include "wpa.h" #include "preauth.h" #include "vlan_init.h" #include "ctrl_iface.h" -#include "tls.h" -#include "eap_server/eap_sim_db.h" -#include "eap_server/eap.h" -#include "eap_server/tncs.h" -#include "version.h" -#include "l2_packet/l2_packet.h" #include "wps_hostapd.h" #include "tkip_countermeasures.h" @@ -120,6 +121,7 @@ int hostapd_reload_config(struct hostapd_iface *iface) struct hostapd_data *hapd = iface->bss[0]; struct hostapd_config *newconf, *oldconf; struct wpa_auth_config wpa_auth_conf; + size_t j; newconf = hostapd_config_read(iface->config_fname); if (newconf == NULL) @@ -129,7 +131,8 @@ int hostapd_reload_config(struct hostapd_iface *iface) * Deauthenticate all stations since the new configuration may not * allow them to use the BSS anymore. */ - hostapd_flush_old_stations(hapd); + for (j = 0; j < iface->num_bss; j++) + hostapd_flush_old_stations(iface->bss[j]); /* TODO: update dynamic data based on changed configuration * items (e.g., open/close sockets, etc.) */ @@ -187,119 +190,6 @@ int handle_reload_iface(struct hostapd_iface *iface, void *ctx) } -#ifdef HOSTAPD_DUMP_STATE -/** - * hostapd_dump_state - SIGUSR1 handler to dump hostapd state to a text file - */ -static void hostapd_dump_state(struct hostapd_data *hapd) -{ - FILE *f; - time_t now; - struct sta_info *sta; - int i; - char *buf; - - if (!hapd->conf->dump_log_name) { - wpa_printf(MSG_DEBUG, "Dump file not defined - ignoring dump " - "request"); - return; - } - - wpa_printf(MSG_DEBUG, "Dumping hostapd state to '%s'", - hapd->conf->dump_log_name); - f = fopen(hapd->conf->dump_log_name, "w"); - if (f == NULL) { - wpa_printf(MSG_WARNING, "Could not open dump file '%s' for " - "writing.", hapd->conf->dump_log_name); - return; - } - - time(&now); - fprintf(f, "hostapd state dump - %s", ctime(&now)); - fprintf(f, "num_sta=%d num_sta_non_erp=%d " - "num_sta_no_short_slot_time=%d\n" - "num_sta_no_short_preamble=%d\n", - hapd->num_sta, hapd->iface->num_sta_non_erp, - hapd->iface->num_sta_no_short_slot_time, - hapd->iface->num_sta_no_short_preamble); - - for (sta = hapd->sta_list; sta != NULL; sta = sta->next) { - fprintf(f, "\nSTA=" MACSTR "\n", MAC2STR(sta->addr)); - - fprintf(f, - " AID=%d flags=0x%x %s%s%s%s%s%s%s%s%s%s%s%s%s%s\n" - " capability=0x%x listen_interval=%d\n", - sta->aid, - sta->flags, - (sta->flags & WLAN_STA_AUTH ? "[AUTH]" : ""), - (sta->flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""), - (sta->flags & WLAN_STA_PS ? "[PS]" : ""), - (sta->flags & WLAN_STA_TIM ? "[TIM]" : ""), - (sta->flags & WLAN_STA_PERM ? "[PERM]" : ""), - (sta->flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : - ""), - (sta->flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" : - ""), - (sta->flags & WLAN_STA_SHORT_PREAMBLE ? - "[SHORT_PREAMBLE]" : ""), - (sta->flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""), - (sta->flags & WLAN_STA_WMM ? "[WMM]" : ""), - (sta->flags & WLAN_STA_MFP ? "[MFP]" : ""), - (sta->flags & WLAN_STA_WPS ? "[WPS]" : ""), - (sta->flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""), - (sta->flags & WLAN_STA_NONERP ? "[NonERP]" : ""), - sta->capability, - sta->listen_interval); - - fprintf(f, " supported_rates="); - for (i = 0; i < sta->supported_rates_len; i++) - fprintf(f, "%02x ", sta->supported_rates[i]); - fprintf(f, "\n"); - - fprintf(f, - " timeout_next=%s\n", - (sta->timeout_next == STA_NULLFUNC ? "NULLFUNC POLL" : - (sta->timeout_next == STA_DISASSOC ? "DISASSOC" : - "DEAUTH"))); - - ieee802_1x_dump_state(f, " ", sta); - } - - buf = os_malloc(4096); - if (buf) { - int count = radius_client_get_mib(hapd->radius, buf, 4096); - if (count < 0) - count = 0; - else if (count > 4095) - count = 4095; - buf[count] = '\0'; - fprintf(f, "%s", buf); - - count = radius_server_get_mib(hapd->radius_srv, buf, 4096); - if (count < 0) - count = 0; - else if (count > 4095) - count = 4095; - buf[count] = '\0'; - fprintf(f, "%s", buf); - os_free(buf); - } - fclose(f); -} - - -int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx) -{ - size_t i; - - for (i = 0; i < iface->num_bss; i++) - hostapd_dump_state(iface->bss[i]); - - return 0; -} -#endif /* HOSTAPD_DUMP_STATE */ - - static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd, char *ifname) { @@ -390,8 +280,6 @@ 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); @@ -426,8 +314,6 @@ static void hostapd_cleanup(struct hostapd_data *hapd) hostapd_deinit_wps(hapd); - hostapd_wireless_event_deinit(hapd); - #ifdef EAP_TLS_FUNCS if (hapd->ssl_ctx) { tls_deinit(hapd->ssl_ctx); @@ -447,6 +333,9 @@ static void hostapd_cleanup(struct hostapd_data *hapd) wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s", hapd->conf->iface); } + + os_free(hapd->probereq_cb); + hapd->probereq_cb = NULL; } @@ -816,7 +705,7 @@ static int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst, os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN); os_memcpy(&m->u, data, data_len); - res = hostapd_send_mgmt_frame(hapd, (u8 *) m, mlen, 0); + res = hostapd_send_mgmt_frame(hapd, (u8 *) m, mlen); os_free(m); return res; } @@ -1113,6 +1002,13 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first) } } + hostapd_flush_old_stations(hapd); + hostapd_set_privacy(hapd, 0); + + hostapd_broadcast_wep_clear(hapd); + if (hostapd_setup_encryption(hapd->conf->iface, hapd)) + return -1; + /* * Fetch the SSID from the system and use it or, * if one was specified in the config file, verify they @@ -1154,14 +1050,6 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first) return -1; } - /* Set flag for whether SSID is broadcast in beacons */ - if (hostapd_set_broadcast_ssid(hapd, - !!hapd->conf->ignore_broadcast_ssid)) { - wpa_printf(MSG_ERROR, "Could not set broadcast SSID flag for " - "kernel driver"); - return -1; - } - /* Set SSID for the kernel driver (to be used in beacon and probe * response frames) */ if (set_ssid && hostapd_set_ssid(hapd, (u8 *) conf->ssid.ssid, @@ -1307,19 +1195,14 @@ static int setup_interface(struct hostapd_iface *iface) size_t i; char country[4]; u8 *b = conf->bssid; - int freq; - size_t j; - u8 *prev_addr; /* * Initialize the driver interface and make sure that all BSSes get * configured with a pointer to this driver interface. */ - if (b[0] | b[1] | b[2] | b[3] | b[4] | b[5]) { - hapd->drv_priv = hostapd_driver_init_bssid(hapd, b); - } else { - hapd->drv_priv = hostapd_driver_init(hapd); - } + if (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5])) + b = NULL; + hapd->drv_priv = hostapd_driver_init(hapd, b); if (hapd->drv_priv == NULL) { wpa_printf(MSG_ERROR, "%s driver initialization failed.", @@ -1335,12 +1218,6 @@ static int setup_interface(struct hostapd_iface *iface) if (hostapd_validate_bssid_configuration(iface)) return -1; -#ifdef CONFIG_IEEE80211N - SET_2BIT_LE16(&iface->ht_op_mode, - HT_INFO_OPERATION_MODE_OP_MODE_OFFSET, - OP_MODE_PURE); -#endif /* CONFIG_IEEE80211N */ - if (hapd->iconf->country[0] && hapd->iconf->country[1]) { os_memcpy(country, hapd->iconf->country, 3); country[3] = '\0'; @@ -1350,13 +1227,6 @@ static int setup_interface(struct hostapd_iface *iface) } } - if (hapd->iconf->ieee80211d && - hostapd_set_ieee80211d(hapd, 1) < 0) { - wpa_printf(MSG_ERROR, "Failed to set ieee80211d (%d)", - hapd->iconf->ieee80211d); - return -1; - } - if (hapd->iconf->bridge_packets != INTERNAL_BRIDGE_DO_NOT_CONTROL && hostapd_set_internal_bridge(hapd, hapd->iconf->bridge_packets)) { wpa_printf(MSG_ERROR, "Failed to set bridge_packets for " @@ -1364,10 +1234,6 @@ static int setup_interface(struct hostapd_iface *iface) return -1; } - /* TODO: merge with hostapd_driver_init() ? */ - if (hostapd_wireless_event_init(hapd) < 0) - return -1; - if (hostapd_get_hw_features(iface)) { /* Not all drivers support this yet, so continue without hw * feature data. */ @@ -1378,11 +1244,33 @@ static int setup_interface(struct hostapd_iface *iface) "channel. (%d)", ret); return -1; } + ret = hostapd_check_ht_capab(iface); + if (ret < 0) + return -1; + if (ret == 1) { + wpa_printf(MSG_DEBUG, "Interface initialization will " + "be completed in a callback"); + return 0; + } } + return hostapd_setup_interface_complete(iface, 0); +} - hostapd_flush_old_stations(hapd); - hostapd_set_privacy(hapd, 0); +int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err) +{ + struct hostapd_data *hapd = iface->bss[0]; + int freq; + size_t j; + u8 *prev_addr; + + if (err) { + wpa_printf(MSG_ERROR, "Interface initialization failed"); + eloop_terminate(); + return -1; + } + + wpa_printf(MSG_DEBUG, "Completing interface initialization"); if (hapd->iconf->channel) { freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel); wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d " @@ -1400,13 +1288,6 @@ static int setup_interface(struct hostapd_iface *iface) } } - hostapd_broadcast_wep_clear(hapd); - if (hostapd_setup_encryption(hapd->conf->iface, hapd)) - return -1; - - hostapd_set_beacon_int(hapd, hapd->iconf->beacon_int); - ieee802_11_set_beacon(hapd); - if (hapd->iconf->rts_threshold > -1 && hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) { wpa_printf(MSG_ERROR, "Could not set RTS threshold for " @@ -1443,6 +1324,9 @@ static int setup_interface(struct hostapd_iface *iface) return -1; } + wpa_printf(MSG_DEBUG, "%s: Setup of interface done.", + iface->bss[0]->conf->iface); + return 0; } @@ -1467,9 +1351,6 @@ int hostapd_setup_interface(struct hostapd_iface *iface) iface->bss[0]->conf->iface); eloop_terminate(); return -1; - } else if (!hostapd_drv_none(iface->bss[0])) { - wpa_printf(MSG_DEBUG, "%s: Setup of interface done.", - iface->bss[0]->conf->iface); } return 0; @@ -1502,11 +1383,6 @@ hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface, hapd->conf = bss; hapd->iface = hapd_iface; - if (hapd->conf->individual_wep_key_len > 0) { - /* use key0 in individual key and key1 in broadcast key */ - hapd->default_wep_key_idx = 1; - } - #ifdef EAP_TLS_FUNCS if (hapd->conf->eap_server && (hapd->conf->ca_cert || hapd->conf->server_cert || @@ -1585,3 +1461,26 @@ void hostapd_interface_deinit(struct hostapd_iface *iface) os_free(iface->bss[j]); hostapd_cleanup_iface(iface); } + + +int hostapd_register_probereq_cb(struct hostapd_data *hapd, + void (*cb)(void *ctx, const u8 *sa, + const u8 *ie, size_t ie_len), + void *ctx) +{ + struct hostapd_probereq_cb *n; + + n = os_realloc(hapd->probereq_cb, (hapd->num_probereq_cb + 1) * + sizeof(struct hostapd_probereq_cb)); + if (n == NULL) + return -1; + + hapd->probereq_cb = n; + n = &hapd->probereq_cb[hapd->num_probereq_cb]; + hapd->num_probereq_cb++; + + n->cb = cb; + n->ctx = ctx; + + return 0; +}