Use a common error handler in hostapd_notif_assoc()

This commit is contained in:
Jouni Malinen 2011-10-16 17:57:27 +03:00
parent 2bb20281cb
commit 08a74e6a61

View file

@ -45,6 +45,7 @@ int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
struct ieee802_11_elems elems; struct ieee802_11_elems elems;
const u8 *ie; const u8 *ie;
size_t ielen; size_t ielen;
u16 reason = WLAN_REASON_UNSPECIFIED;
if (addr == NULL) { if (addr == NULL) {
/* /*
@ -146,27 +147,24 @@ int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
ie, ielen, NULL, 0); ie, ielen, NULL, 0);
if (res != WPA_IE_OK) { if (res != WPA_IE_OK) {
int resp;
wpa_printf(MSG_DEBUG, "WPA/RSN information element " wpa_printf(MSG_DEBUG, "WPA/RSN information element "
"rejected? (res %u)", res); "rejected? (res %u)", res);
wpa_hexdump(MSG_DEBUG, "IE", ie, ielen); wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
if (res == WPA_INVALID_GROUP) if (res == WPA_INVALID_GROUP)
resp = WLAN_REASON_GROUP_CIPHER_NOT_VALID; reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
else if (res == WPA_INVALID_PAIRWISE) else if (res == WPA_INVALID_PAIRWISE)
resp = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID; reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
else if (res == WPA_INVALID_AKMP) else if (res == WPA_INVALID_AKMP)
resp = WLAN_REASON_AKMP_NOT_VALID; reason = WLAN_REASON_AKMP_NOT_VALID;
#ifdef CONFIG_IEEE80211W #ifdef CONFIG_IEEE80211W
else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
resp = WLAN_REASON_INVALID_IE; reason = WLAN_REASON_INVALID_IE;
else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
resp = WLAN_REASON_GROUP_CIPHER_NOT_VALID; reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
#endif /* CONFIG_IEEE80211W */ #endif /* CONFIG_IEEE80211W */
else else
resp = WLAN_REASON_INVALID_IE; reason = WLAN_REASON_INVALID_IE;
hostapd_drv_sta_disassoc(hapd, sta->addr, resp); goto fail;
ap_free_sta(hapd, sta);
return -1;
} }
} else if (hapd->conf->wps_state) { } else if (hapd->conf->wps_state) {
#ifdef CONFIG_WPS #ifdef CONFIG_WPS
@ -178,11 +176,9 @@ int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
wps = NULL; wps = NULL;
#ifdef CONFIG_WPS_STRICT #ifdef CONFIG_WPS_STRICT
if (wps && wps_validate_assoc_req(wps) < 0) { if (wps && wps_validate_assoc_req(wps) < 0) {
hostapd_drv_sta_disassoc(hapd, sta->addr, reason = WLAN_REASON_INVALID_IE;
WLAN_REASON_INVALID_IE);
ap_free_sta(hapd, sta);
wpabuf_free(wps); wpabuf_free(wps);
return -1; goto fail;
} }
#endif /* CONFIG_WPS_STRICT */ #endif /* CONFIG_WPS_STRICT */
if (wps) { if (wps) {
@ -215,6 +211,11 @@ skip_wpa_check:
#endif /* CONFIG_P2P */ #endif /* CONFIG_P2P */
return 0; return 0;
fail:
hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
ap_free_sta(hapd, sta);
return -1;
} }