-extern int wpa_debug_show_keys;
-extern int wpa_debug_timestamp;
-
-
-static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
- int level, const char *txt, size_t len)
-{
- struct hostapd_data *hapd = ctx;
- char *format, *module_str;
- int maxlen;
- int conf_syslog_level, conf_stdout_level;
- unsigned int conf_syslog, conf_stdout;
-
- maxlen = len + 100;
- format = os_malloc(maxlen);
- if (!format)
- return;
-
- if (hapd && hapd->conf) {
- conf_syslog_level = hapd->conf->logger_syslog_level;
- conf_stdout_level = hapd->conf->logger_stdout_level;
- conf_syslog = hapd->conf->logger_syslog;
- conf_stdout = hapd->conf->logger_stdout;
- } else {
- conf_syslog_level = conf_stdout_level = 0;
- conf_syslog = conf_stdout = (unsigned int) -1;
- }
-
- switch (module) {
- case HOSTAPD_MODULE_IEEE80211:
- module_str = "IEEE 802.11";
- break;
- case HOSTAPD_MODULE_IEEE8021X:
- module_str = "IEEE 802.1X";
- break;
- case HOSTAPD_MODULE_RADIUS:
- module_str = "RADIUS";
- break;
- case HOSTAPD_MODULE_WPA:
- module_str = "WPA";
- break;
- case HOSTAPD_MODULE_DRIVER:
- module_str = "DRIVER";
- break;
- case HOSTAPD_MODULE_IAPP:
- module_str = "IAPP";
- break;
- case HOSTAPD_MODULE_MLME:
- module_str = "MLME";
- break;
- default:
- module_str = NULL;
- break;
- }
-
- if (hapd && hapd->conf && addr)
- os_snprintf(format, maxlen, "%s: STA " MACSTR "%s%s: %s",
- hapd->conf->iface, MAC2STR(addr),
- module_str ? " " : "", module_str, txt);
- else if (hapd && hapd->conf)
- os_snprintf(format, maxlen, "%s:%s%s %s",
- hapd->conf->iface, module_str ? " " : "",
- module_str, txt);
- else if (addr)
- os_snprintf(format, maxlen, "STA " MACSTR "%s%s: %s",
- MAC2STR(addr), module_str ? " " : "",
- module_str, txt);
- else
- os_snprintf(format, maxlen, "%s%s%s",
- module_str, module_str ? ": " : "", txt);
-
- if ((conf_stdout & module) && level >= conf_stdout_level) {
- wpa_debug_print_timestamp();
- printf("%s\n", format);
- }
-
-#ifndef CONFIG_NATIVE_WINDOWS
- if ((conf_syslog & module) && level >= conf_syslog_level) {
- int priority;
- switch (level) {
- case HOSTAPD_LEVEL_DEBUG_VERBOSE:
- case HOSTAPD_LEVEL_DEBUG:
- priority = LOG_DEBUG;
- break;
- case HOSTAPD_LEVEL_INFO:
- priority = LOG_INFO;
- break;
- case HOSTAPD_LEVEL_NOTICE:
- priority = LOG_NOTICE;
- break;
- case HOSTAPD_LEVEL_WARNING:
- priority = LOG_WARNING;
- break;
- default:
- priority = LOG_INFO;
- break;
- }
- syslog(priority, "%s", format);
- }
-#endif /* CONFIG_NATIVE_WINDOWS */
-
- os_free(format);
-}
-
-
-static void hostapd_deauth_all_stas(struct hostapd_data *hapd)
-{
- u8 addr[ETH_ALEN];
-
- /* New Prism2.5/3 STA firmware versions seem to have issues with this
- * broadcast deauth frame. This gets the firmware in odd state where
- * nothing works correctly, so let's skip sending this for the hostap
- * driver. */
-
- if (hapd->driver && os_strcmp(hapd->driver->name, "hostap") != 0) {
- os_memset(addr, 0xff, ETH_ALEN);
- hostapd_sta_deauth(hapd, addr,
- WLAN_REASON_PREV_AUTH_NOT_VALID);
- }
-}
-
-
-/**
- * hostapd_prune_associations - Remove extraneous associations
- * @hapd: Pointer to BSS data for the most recent association
- * @sta: Pointer to the associated STA data
- *
- * This function looks through all radios and BSS's for previous
- * (stale) associations of STA. If any are found they are removed.
- */
-static void hostapd_prune_associations(struct hostapd_data *hapd,
- struct sta_info *sta)
-{
- struct sta_info *osta;
- 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 (ohapd == hapd)
- continue;
- osta = ap_get_sta(ohapd, sta->addr);
- if (!osta)
- continue;
-
- ap_sta_disassociate(ohapd, osta,
- WLAN_REASON_UNSPECIFIED);
- }
- }
-}
-
-
-/**
- * hostapd_new_assoc_sta - Notify that a new station associated with the AP
- * @hapd: Pointer to BSS data
- * @sta: Pointer to the associated STA data
- * @reassoc: 1 to indicate this was a re-association; 0 = first association
- *
- * This function will be called whenever a station associates with the AP. It
- * can be called for ieee802_11.c for drivers that export MLME to hostapd and
- * from driver_*.c for drivers that take care of management frames (IEEE 802.11
- * authentication and association) internally.
- */
-void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
- int reassoc)
-{
- if (hapd->tkip_countermeasures) {
- hostapd_sta_deauth(hapd, sta->addr,
- WLAN_REASON_MICHAEL_MIC_FAILURE);
- return;
- }
-
- hostapd_prune_associations(hapd, sta);
-
- /* IEEE 802.11F (IAPP) */
- if (hapd->conf->ieee802_11f)
- iapp_new_station(hapd->iapp, sta);
-
- /* Start accounting here, if IEEE 802.1X and WPA are not used.
- * IEEE 802.1X/WPA code will start accounting after the station has
- * been authorized. */
- if (!hapd->conf->ieee802_1x && !hapd->conf->wpa)
- accounting_sta_start(hapd, sta);
-
- hostapd_wme_sta_config(hapd, sta);
-
- /* Start IEEE 802.1X authentication process for new stations */
- ieee802_1x_new_station(hapd, sta);
- if (reassoc) {
- if (sta->auth_alg != WLAN_AUTH_FT &&
- !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
- wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
- } else
- wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);
-}