]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
OCV: Use more granular error codes for OCI validation failures
authorVeerendranath Jakkam <vjakkam@codeaurora.org>
Wed, 2 Sep 2020 18:55:28 +0000 (00:25 +0530)
committerJouni Malinen <j@w1.fi>
Fri, 11 Sep 2020 12:23:28 +0000 (15:23 +0300)
Enhance the return values of ocv_verify_tx_params with enum to indicate
different OCI verification failures to caller.

Signed-off-by: Veerendranath Jakkam <vjakkam@codeaurora.org>
12 files changed:
src/ap/ieee802_11.c
src/ap/ieee802_11_shared.c
src/ap/wnm_ap.c
src/ap/wpa_auth.c
src/ap/wpa_auth_ft.c
src/common/ocv.c
src/common/ocv.h
src/rsn_supp/wpa.c
src/rsn_supp/wpa_ft.c
wpa_supplicant/mesh_mpm.c
wpa_supplicant/sme.c
wpa_supplicant/wnm_sta.c

index c98e77103106f8d43f050680a971b7ef3ddcf412..13431d5672d6a4bf27fa14812ad7cac5aba9ce80 100644 (file)
@@ -3563,7 +3563,8 @@ static int check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
                        return WLAN_STATUS_UNSPECIFIED_FAILURE;
 
                if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci,
-                                        tx_chanwidth, tx_seg1_idx) != 0) {
+                                        tx_chanwidth, tx_seg1_idx) !=
+                   OCI_SUCCESS) {
                        wpa_printf(MSG_WARNING, "FILS: OCV failed: %s",
                                   ocv_errorstr);
                        wpa_msg(hapd->msg_ctx, MSG_INFO, OCV_FAILURE "addr="
index 79ed450e27a84f19d292488749762ecee7aa5523..17003d50673e22801c680b0e5b96ff6d8fa3e5d9 100644 (file)
@@ -275,7 +275,8 @@ void ieee802_11_sa_query_action(struct hostapd_data *hapd,
                        return;
 
                if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci,
-                                        tx_chanwidth, tx_seg1_idx) != 0) {
+                                        tx_chanwidth, tx_seg1_idx) !=
+                   OCI_SUCCESS) {
                        wpa_msg(hapd->msg_ctx, MSG_INFO, OCV_FAILURE "addr="
                                MACSTR " frame=saquery%s error=%s",
                                MAC2STR(sa),
index 248f5a1cff68ef194aa238f136d83fbe94270e6e..be817978e88a02d13bd45c9003459d4efaf9f972 100644 (file)
@@ -326,7 +326,7 @@ static void ieee802_11_rx_wnmsleep_req(struct hostapd_data *hapd,
 
                if (ocv_verify_tx_params(oci_ie, oci_ie_len, &ci,
                                         channel_width_to_int(ci.chanwidth),
-                                        ci.seg1_idx) != 0) {
+                                        ci.seg1_idx) != OCI_SUCCESS) {
                        wpa_msg(hapd, MSG_WARNING, "WNM: OCV failed: %s",
                                ocv_errorstr);
                        return;
index 9e6c0cad3c2925e7707c42c3f418f78b431b351a..a5b1953f659ea9a4fc3a6e613868a3b97f81d6b5 100644 (file)
@@ -3051,7 +3051,8 @@ SM_STATE(WPA_PTK, PTKCALCNEGOTIATING)
                        return;
 
                if (ocv_verify_tx_params(kde.oci, kde.oci_len, &ci,
-                                        tx_chanwidth, tx_seg1_idx) != 0) {
+                                        tx_chanwidth, tx_seg1_idx) !=
+                   OCI_SUCCESS) {
                        wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
                                         "OCV failed: %s", ocv_errorstr);
                        if (wpa_auth->conf.msg_ctx)
@@ -3913,7 +3914,8 @@ SM_STATE(WPA_PTK_GROUP, REKEYESTABLISHED)
                        return;
 
                if (ocv_verify_tx_params(kde.oci, kde.oci_len, &ci,
-                                        tx_chanwidth, tx_seg1_idx) != 0) {
+                                        tx_chanwidth, tx_seg1_idx) !=
+                   OCI_SUCCESS) {
                        wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
                                         "OCV failed: %s", ocv_errorstr);
                        if (wpa_auth->conf.msg_ctx)
index 9caac194e4cf18ee17d2face0dba6d8881a1e931..5cd7037e9b65397e52190ef0e17a50415a422a52 100644 (file)
@@ -3519,7 +3519,8 @@ int wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
                        return WLAN_STATUS_UNSPECIFIED_FAILURE;
 
                if (ocv_verify_tx_params(parse.oci, parse.oci_len, &ci,
-                                        tx_chanwidth, tx_seg1_idx) != 0) {
+                                        tx_chanwidth, tx_seg1_idx) !=
+                   OCI_SUCCESS) {
                        wpa_printf(MSG_WARNING, "OCV failed: %s", ocv_errorstr);
                        if (sm->wpa_auth->conf.msg_ctx)
                                wpa_msg(sm->wpa_auth->conf.msg_ctx, MSG_INFO,
index 6c35117a725b9aa73f4e12ebbdf3bb79f3859d46..4bc2749a7cc36d64605620a78a184f74506edfb0 100644 (file)
@@ -95,23 +95,24 @@ int ocv_insert_extended_oci(struct wpa_channel_info *ci, u8 *pos)
 }
 
 
-int ocv_verify_tx_params(const u8 *oci_ie, size_t oci_ie_len,
-                        struct wpa_channel_info *ci, int tx_chanwidth,
-                        int tx_seg1_idx)
+enum oci_verify_result
+ocv_verify_tx_params(const u8 *oci_ie, size_t oci_ie_len,
+                    struct wpa_channel_info *ci, int tx_chanwidth,
+                    int tx_seg1_idx)
 {
        struct oci_info oci;
 
        if (!oci_ie) {
                os_snprintf(ocv_errorstr, sizeof(ocv_errorstr),
                            "did not receive mandatory OCI");
-               return -1;
+               return OCI_NOT_FOUND;
        }
 
        if (oci_ie_len != 3) {
                os_snprintf(ocv_errorstr, sizeof(ocv_errorstr),
                            "received OCI of unexpected length (%d)",
                            (int) oci_ie_len);
-               return -1;
+               return OCI_INVALID_LENGTH;
        }
 
        os_memset(&oci, 0, sizeof(oci));
@@ -121,7 +122,7 @@ int ocv_verify_tx_params(const u8 *oci_ie, size_t oci_ie_len,
        if (ocv_derive_all_parameters(&oci) != 0) {
                os_snprintf(ocv_errorstr, sizeof(ocv_errorstr),
                            "unable to interpret received OCI");
-               return -1;
+               return OCI_PARSE_ERROR;
        }
 
        /* Primary frequency used to send frames to STA must match the STA's */
@@ -129,7 +130,7 @@ int ocv_verify_tx_params(const u8 *oci_ie, size_t oci_ie_len,
                os_snprintf(ocv_errorstr, sizeof(ocv_errorstr),
                            "primary channel mismatch in received OCI (we use %d but receiver is using %d)",
                            ci->frequency, oci.freq);
-               return -1;
+               return OCI_PRIMARY_FREQ_MISMATCH;
        }
 
        /* We shouldn't transmit with a higher bandwidth than the STA supports
@@ -138,7 +139,7 @@ int ocv_verify_tx_params(const u8 *oci_ie, size_t oci_ie_len,
                os_snprintf(ocv_errorstr, sizeof(ocv_errorstr),
                            "channel bandwidth mismatch in received OCI (we use %d but receiver only supports %d)",
                            tx_chanwidth, oci.chanwidth);
-               return -1;
+               return OCI_CHANNEL_WIDTH_MISMATCH;
        }
 
        /*
@@ -152,7 +153,7 @@ int ocv_verify_tx_params(const u8 *oci_ie, size_t oci_ie_len,
                os_snprintf(ocv_errorstr, sizeof(ocv_errorstr),
                            "secondary channel mismatch in received OCI (we use %d but receiver is using %d)",
                            ci->sec_channel, oci.sec_channel);
-               return -1;
+               return OCI_SECONDARY_FREQ_MISMATCH;
        }
 
        /*
@@ -165,8 +166,8 @@ int ocv_verify_tx_params(const u8 *oci_ie, size_t oci_ie_len,
                os_snprintf(ocv_errorstr, sizeof(ocv_errorstr),
                            "frequency segment 1 mismatch in received OCI (we use %d but receiver is using %d)",
                            tx_seg1_idx, oci.seg1_idx);
-               return -1;
+               return OCI_SEG_1_INDEX_MISMATCH;
        }
 
-       return 0;
+       return OCI_SUCCESS;
 }
index 6379d9d06c9ac4c5e85a75f37a02d6ea524a8fd1..7fa4522c12c2f247248b0e00e3d090e0c6214170 100644 (file)
@@ -27,14 +27,21 @@ struct oci_info {
 #define OCV_OCI_EXTENDED_LEN   (3 + OCV_OCI_LEN)
 #define OCV_OCI_KDE_LEN                (2 + RSN_SELECTOR_LEN + OCV_OCI_LEN)
 
+enum oci_verify_result {
+       OCI_SUCCESS, OCI_NOT_FOUND, OCI_INVALID_LENGTH, OCI_PARSE_ERROR,
+       OCI_PRIMARY_FREQ_MISMATCH, OCI_CHANNEL_WIDTH_MISMATCH,
+       OCI_SECONDARY_FREQ_MISMATCH, OCI_SEG_1_INDEX_MISMATCH
+};
+
 extern char ocv_errorstr[256];
 
 int ocv_derive_all_parameters(struct oci_info *oci);
 int ocv_insert_oci(struct wpa_channel_info *ci, u8 **argpos);
 int ocv_insert_oci_kde(struct wpa_channel_info *ci, u8 **argpos);
 int ocv_insert_extended_oci(struct wpa_channel_info *ci, u8 *pos);
-int ocv_verify_tx_params(const u8 *oci_ie, size_t oci_ie_len,
-                        struct wpa_channel_info *ci, int tx_chanwidth,
-                        int tx_seg1_idx);
+enum oci_verify_result
+ocv_verify_tx_params(const u8 *oci_ie, size_t oci_ie_len,
+                    struct wpa_channel_info *ci, int tx_chanwidth,
+                    int tx_seg1_idx);
 
 #endif /* OCV_H */
index b41e6e4270b33f1d54d970eeb49e568ba5d8b956..f3d324a67d36b3842d12ce96450657559f24fab6 100644 (file)
@@ -1717,7 +1717,7 @@ static void wpa_supplicant_process_3_of_4(struct wpa_sm *sm,
 
                if (ocv_verify_tx_params(ie.oci, ie.oci_len, &ci,
                                         channel_width_to_int(ci.chanwidth),
-                                        ci.seg1_idx) != 0) {
+                                        ci.seg1_idx) != OCI_SUCCESS) {
                        wpa_msg(sm->ctx->msg_ctx, MSG_INFO, OCV_FAILURE
                                "addr=" MACSTR " frame=eapol-key-m3 error=%s",
                                MAC2STR(sm->bssid), ocv_errorstr);
@@ -1865,7 +1865,7 @@ static int wpa_supplicant_process_1_of_2_rsn(struct wpa_sm *sm,
 
                if (ocv_verify_tx_params(ie.oci, ie.oci_len, &ci,
                                         channel_width_to_int(ci.chanwidth),
-                                        ci.seg1_idx) != 0) {
+                                        ci.seg1_idx) != OCI_SUCCESS) {
                        wpa_msg(sm->ctx->msg_ctx, MSG_INFO, OCV_FAILURE
                                "addr=" MACSTR " frame=eapol-key-g1 error=%s",
                                MAC2STR(sm->bssid), ocv_errorstr);
@@ -4799,7 +4799,7 @@ int fils_process_assoc_resp(struct wpa_sm *sm, const u8 *resp, size_t len)
 
                if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci,
                                         channel_width_to_int(ci.chanwidth),
-                                        ci.seg1_idx) != 0) {
+                                        ci.seg1_idx) != OCI_SUCCESS) {
                        wpa_msg(sm->ctx->msg_ctx, MSG_INFO, OCV_FAILURE
                                "addr=" MACSTR " frame=fils-assoc error=%s",
                                MAC2STR(sm->bssid), ocv_errorstr);
index bcaf42fe6d64f1c19a7289abf04be650556b0655..bf73376b68d9e90d3ac133e8134359085d5203f7 100644 (file)
@@ -1167,7 +1167,7 @@ int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
 
                if (ocv_verify_tx_params(parse.oci, parse.oci_len, &ci,
                                         channel_width_to_int(ci.chanwidth),
-                                        ci.seg1_idx) != 0) {
+                                        ci.seg1_idx) != OCI_SUCCESS) {
                        wpa_msg(sm->ctx->msg_ctx, MSG_INFO, OCV_FAILURE
                                "addr=" MACSTR " frame=ft-assoc error=%s",
                                MAC2STR(sm->bssid), ocv_errorstr);
index 3abbe09d0f048113204378607aa1a54941c1f978..4547eea884cd8c09f9695bf4837e412fca46ecbb 100644 (file)
@@ -1292,7 +1292,7 @@ void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
 
                        if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci,
                                                 tx_chanwidth, tx_seg1_idx) !=
-                           0) {
+                           OCI_SUCCESS) {
                                wpa_printf(MSG_WARNING, "MPM: OCV failed: %s",
                                           ocv_errorstr);
                                return;
index 2faaff930847de7acd819217b9e0fa23c7b3e110..7fec1cd8d666a22b79cb17adc8df94bbd263dfba 100644 (file)
@@ -2915,7 +2915,7 @@ void sme_sa_query_rx(struct wpa_supplicant *wpa_s, const u8 *sa,
 
                if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci,
                                         channel_width_to_int(ci.chanwidth),
-                                        ci.seg1_idx) != 0) {
+                                        ci.seg1_idx) != OCI_SUCCESS) {
                        wpa_msg(wpa_s, MSG_INFO, OCV_FAILURE "addr=" MACSTR
                                " frame=saquery%s error=%s",
                                MAC2STR(sa), data[0] == WLAN_SA_QUERY_REQUEST ?
index d0c9f0f4580ece9d4aad0177e9edbcfe3de5f8d3..19f1eca8a6764daed6c24a14552ce8aa7c90484b 100644 (file)
@@ -383,7 +383,7 @@ static void ieee802_11_rx_wnmsleep_resp(struct wpa_supplicant *wpa_s,
 
                if (ocv_verify_tx_params(oci_ie, oci_ie_len, &ci,
                                         channel_width_to_int(ci.chanwidth),
-                                        ci.seg1_idx) != 0) {
+                                        ci.seg1_idx) != OCI_SUCCESS) {
                        wpa_msg(wpa_s, MSG_WARNING, "WNM: OCV failed: %s",
                                ocv_errorstr);
                        return;