Return an enum from wpa_validate_wpa_ie()
This is more specific then returning a generic int and also allows the compiler to do more checks. Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
This commit is contained in:
parent
2b4f9ce287
commit
ca57d5f553
4 changed files with 101 additions and 59 deletions
|
@ -109,7 +109,8 @@ int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
|
|||
const u8 *req_ies, size_t req_ies_len, int reassoc)
|
||||
{
|
||||
struct sta_info *sta;
|
||||
int new_assoc, res;
|
||||
int new_assoc;
|
||||
enum wpa_validate_result res;
|
||||
struct ieee802_11_elems elems;
|
||||
const u8 *ie;
|
||||
size_t ielen;
|
||||
|
@ -323,33 +324,63 @@ int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
|
|||
elems.rsnxe ? elems.rsnxe_len + 2 : 0,
|
||||
elems.mdie, elems.mdie_len,
|
||||
elems.owe_dh, elems.owe_dh_len);
|
||||
if (res != WPA_IE_OK) {
|
||||
reason = WLAN_REASON_INVALID_IE;
|
||||
status = WLAN_STATUS_INVALID_IE;
|
||||
switch (res) {
|
||||
case WPA_IE_OK:
|
||||
reason = WLAN_REASON_UNSPECIFIED;
|
||||
status = WLAN_STATUS_SUCCESS;
|
||||
break;
|
||||
case WPA_INVALID_IE:
|
||||
reason = WLAN_REASON_INVALID_IE;
|
||||
status = WLAN_STATUS_INVALID_IE;
|
||||
break;
|
||||
case WPA_INVALID_GROUP:
|
||||
reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
|
||||
status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
|
||||
break;
|
||||
case WPA_INVALID_PAIRWISE:
|
||||
reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
|
||||
status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
|
||||
break;
|
||||
case WPA_INVALID_AKMP:
|
||||
reason = WLAN_REASON_AKMP_NOT_VALID;
|
||||
status = WLAN_STATUS_AKMP_NOT_VALID;
|
||||
break;
|
||||
case WPA_NOT_ENABLED:
|
||||
reason = WLAN_REASON_INVALID_IE;
|
||||
status = WLAN_STATUS_INVALID_IE;
|
||||
break;
|
||||
case WPA_ALLOC_FAIL:
|
||||
reason = WLAN_REASON_UNSPECIFIED;
|
||||
status = WLAN_STATUS_UNSPECIFIED_FAILURE;
|
||||
break;
|
||||
case WPA_MGMT_FRAME_PROTECTION_VIOLATION:
|
||||
reason = WLAN_REASON_INVALID_IE;
|
||||
status = WLAN_STATUS_INVALID_IE;
|
||||
break;
|
||||
case WPA_INVALID_MGMT_GROUP_CIPHER:
|
||||
reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
|
||||
status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
|
||||
break;
|
||||
case WPA_INVALID_MDIE:
|
||||
reason = WLAN_REASON_INVALID_MDE;
|
||||
status = WLAN_STATUS_INVALID_MDIE;
|
||||
break;
|
||||
case WPA_INVALID_PROTO:
|
||||
reason = WLAN_REASON_INVALID_IE;
|
||||
status = WLAN_STATUS_INVALID_IE;
|
||||
break;
|
||||
case WPA_INVALID_PMKID:
|
||||
reason = WLAN_REASON_INVALID_PMKID;
|
||||
status = WLAN_STATUS_INVALID_PMKID;
|
||||
break;
|
||||
}
|
||||
if (status != WLAN_STATUS_SUCCESS) {
|
||||
wpa_printf(MSG_DEBUG,
|
||||
"WPA/RSN information element rejected? (res %u)",
|
||||
res);
|
||||
wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
|
||||
if (res == WPA_INVALID_GROUP) {
|
||||
reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
|
||||
status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
|
||||
} else if (res == WPA_INVALID_PAIRWISE) {
|
||||
reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
|
||||
status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
|
||||
} else if (res == WPA_INVALID_AKMP) {
|
||||
reason = WLAN_REASON_AKMP_NOT_VALID;
|
||||
status = WLAN_STATUS_AKMP_NOT_VALID;
|
||||
} else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) {
|
||||
reason = WLAN_REASON_INVALID_IE;
|
||||
status = WLAN_STATUS_INVALID_IE;
|
||||
} else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) {
|
||||
reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
|
||||
status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
|
||||
} else if (res == WPA_INVALID_PMKID) {
|
||||
reason = WLAN_REASON_INVALID_PMKID;
|
||||
status = WLAN_STATUS_INVALID_PMKID;
|
||||
} else {
|
||||
reason = WLAN_REASON_INVALID_IE;
|
||||
status = WLAN_STATUS_INVALID_IE;
|
||||
}
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
|
|
@ -1611,27 +1611,35 @@ static int auth_sae_queued_addr(struct hostapd_data *hapd, const u8 *addr)
|
|||
#endif /* CONFIG_SAE */
|
||||
|
||||
|
||||
static u16 wpa_res_to_status_code(int res)
|
||||
static u16 wpa_res_to_status_code(enum wpa_validate_result res)
|
||||
{
|
||||
if (res == WPA_INVALID_GROUP)
|
||||
return WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
|
||||
if (res == WPA_INVALID_PAIRWISE)
|
||||
return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
|
||||
if (res == WPA_INVALID_AKMP)
|
||||
return WLAN_STATUS_AKMP_NOT_VALID;
|
||||
if (res == WPA_ALLOC_FAIL)
|
||||
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
||||
if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
|
||||
return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
|
||||
if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
|
||||
return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
|
||||
if (res == WPA_INVALID_MDIE)
|
||||
return WLAN_STATUS_INVALID_MDIE;
|
||||
if (res == WPA_INVALID_PMKID)
|
||||
return WLAN_STATUS_INVALID_PMKID;
|
||||
if (res != WPA_IE_OK)
|
||||
switch (res) {
|
||||
case WPA_IE_OK:
|
||||
return WLAN_STATUS_SUCCESS;
|
||||
case WPA_INVALID_IE:
|
||||
return WLAN_STATUS_INVALID_IE;
|
||||
return WLAN_STATUS_SUCCESS;
|
||||
case WPA_INVALID_GROUP:
|
||||
return WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
|
||||
case WPA_INVALID_PAIRWISE:
|
||||
return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
|
||||
case WPA_INVALID_AKMP:
|
||||
return WLAN_STATUS_AKMP_NOT_VALID;
|
||||
case WPA_NOT_ENABLED:
|
||||
return WLAN_STATUS_INVALID_IE;
|
||||
case WPA_ALLOC_FAIL:
|
||||
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
||||
case WPA_MGMT_FRAME_PROTECTION_VIOLATION:
|
||||
return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
|
||||
case WPA_INVALID_MGMT_GROUP_CIPHER:
|
||||
return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
|
||||
case WPA_INVALID_MDIE:
|
||||
return WLAN_STATUS_INVALID_MDIE;
|
||||
case WPA_INVALID_PROTO:
|
||||
return WLAN_STATUS_INVALID_IE;
|
||||
case WPA_INVALID_PMKID:
|
||||
return WLAN_STATUS_INVALID_PMKID;
|
||||
}
|
||||
return WLAN_STATUS_INVALID_IE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1651,7 +1659,7 @@ void handle_auth_fils(struct hostapd_data *hapd, struct sta_info *sta,
|
|||
u16 resp = WLAN_STATUS_SUCCESS;
|
||||
const u8 *end;
|
||||
struct ieee802_11_elems elems;
|
||||
int res;
|
||||
enum wpa_validate_result res;
|
||||
struct wpa_ie_data rsn;
|
||||
struct rsn_pmksa_cache_entry *pmksa = NULL;
|
||||
|
||||
|
@ -3044,7 +3052,7 @@ u16 owe_process_rsn_ie(struct hostapd_data *hapd,
|
|||
u16 status;
|
||||
u8 *owe_buf, ie[256 * 2];
|
||||
size_t ie_len = 0;
|
||||
int res;
|
||||
enum wpa_validate_result res;
|
||||
|
||||
if (!rsn_ie || rsn_ie_len < 2) {
|
||||
wpa_printf(MSG_DEBUG, "OWE: No RSNE in (Re)AssocReq");
|
||||
|
@ -3255,7 +3263,8 @@ static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
|
|||
}
|
||||
|
||||
if (hapd->conf->wpa && wpa_ie) {
|
||||
int res;
|
||||
enum wpa_validate_result res;
|
||||
|
||||
wpa_ie -= 2;
|
||||
wpa_ie_len += 2;
|
||||
if (sta->wpa_sm == NULL)
|
||||
|
|
|
@ -331,19 +331,20 @@ void wpa_deinit(struct wpa_authenticator *wpa_auth);
|
|||
int wpa_reconfig(struct wpa_authenticator *wpa_auth,
|
||||
struct wpa_auth_config *conf);
|
||||
|
||||
enum {
|
||||
enum wpa_validate_result {
|
||||
WPA_IE_OK, WPA_INVALID_IE, WPA_INVALID_GROUP, WPA_INVALID_PAIRWISE,
|
||||
WPA_INVALID_AKMP, WPA_NOT_ENABLED, WPA_ALLOC_FAIL,
|
||||
WPA_MGMT_FRAME_PROTECTION_VIOLATION, WPA_INVALID_MGMT_GROUP_CIPHER,
|
||||
WPA_INVALID_MDIE, WPA_INVALID_PROTO, WPA_INVALID_PMKID
|
||||
};
|
||||
|
||||
int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
|
||||
struct wpa_state_machine *sm, int freq,
|
||||
const u8 *wpa_ie, size_t wpa_ie_len,
|
||||
const u8 *rsnxe, size_t rsnxe_len,
|
||||
const u8 *mdie, size_t mdie_len,
|
||||
const u8 *owe_dh, size_t owe_dh_len);
|
||||
enum wpa_validate_result
|
||||
wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
|
||||
struct wpa_state_machine *sm, int freq,
|
||||
const u8 *wpa_ie, size_t wpa_ie_len,
|
||||
const u8 *rsnxe, size_t rsnxe_len,
|
||||
const u8 *mdie, size_t mdie_len,
|
||||
const u8 *owe_dh, size_t owe_dh_len);
|
||||
int wpa_validate_osen(struct wpa_authenticator *wpa_auth,
|
||||
struct wpa_state_machine *sm,
|
||||
const u8 *osen_ie, size_t osen_ie_len);
|
||||
|
|
|
@ -548,12 +548,13 @@ static int wpa_auth_okc_iter(struct wpa_authenticator *a, void *ctx)
|
|||
}
|
||||
|
||||
|
||||
int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
|
||||
struct wpa_state_machine *sm, int freq,
|
||||
const u8 *wpa_ie, size_t wpa_ie_len,
|
||||
const u8 *rsnxe, size_t rsnxe_len,
|
||||
const u8 *mdie, size_t mdie_len,
|
||||
const u8 *owe_dh, size_t owe_dh_len)
|
||||
enum wpa_validate_result
|
||||
wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
|
||||
struct wpa_state_machine *sm, int freq,
|
||||
const u8 *wpa_ie, size_t wpa_ie_len,
|
||||
const u8 *rsnxe, size_t rsnxe_len,
|
||||
const u8 *mdie, size_t mdie_len,
|
||||
const u8 *owe_dh, size_t owe_dh_len)
|
||||
{
|
||||
struct wpa_auth_config *conf = &wpa_auth->conf;
|
||||
struct wpa_ie_data data;
|
||||
|
|
Loading…
Reference in a new issue