]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - src/ap/ieee802_11.c
Introduce and add key_flag
[thirdparty/hostap.git] / src / ap / ieee802_11.c
index ef1078ff0398f424ea7a9b9037a45751bf40cfa0..cd61077944a9624c5a59c82ca53dad5e3d5b6353 100644 (file)
@@ -316,7 +316,7 @@ static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
 #endif /* CONFIG_NO_RC4 */
 
 
-static int send_auth_reply(struct hostapd_data *hapd,
+static int send_auth_reply(struct hostapd_data *hapd, struct sta_info *sta,
                           const u8 *dst, const u8 *bssid,
                           u16 auth_alg, u16 auth_transaction, u16 resp,
                           const u8 *ies, size_t ies_len, const char *dbg)
@@ -349,7 +349,37 @@ static int send_auth_reply(struct hostapd_data *hapd,
                   " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu) (dbg=%s)",
                   MAC2STR(dst), auth_alg, auth_transaction,
                   resp, (unsigned long) ies_len, dbg);
-       if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
+#ifdef CONFIG_TESTING_OPTIONS
+#ifdef CONFIG_SAE
+       if (hapd->conf->sae_confirm_immediate == 2 &&
+           auth_alg == WLAN_AUTH_SAE) {
+               if (auth_transaction == 1 &&
+                   (resp == WLAN_STATUS_SUCCESS ||
+                    resp == WLAN_STATUS_SAE_HASH_TO_ELEMENT)) {
+                       wpa_printf(MSG_DEBUG,
+                                  "TESTING: Postpone SAE Commit transmission until Confirm is ready");
+                       os_free(sta->sae_postponed_commit);
+                       sta->sae_postponed_commit = buf;
+                       sta->sae_postponed_commit_len = rlen;
+                       return WLAN_STATUS_SUCCESS;
+               }
+
+               if (auth_transaction == 2 && sta && sta->sae_postponed_commit) {
+                       wpa_printf(MSG_DEBUG,
+                                  "TESTING: Send postponed SAE Commit first, immediately followed by SAE Confirm");
+                       if (hostapd_drv_send_mlme(hapd,
+                                                 sta->sae_postponed_commit,
+                                                 sta->sae_postponed_commit_len,
+                                                 0, NULL, 0, 0) < 0)
+                               wpa_printf(MSG_INFO, "send_auth_reply: send failed");
+                       os_free(sta->sae_postponed_commit);
+                       sta->sae_postponed_commit = NULL;
+                       sta->sae_postponed_commit_len = 0;
+               }
+       }
+#endif /* CONFIG_SAE */
+#endif /* CONFIG_TESTING_OPTIONS */
+       if (hostapd_drv_send_mlme(hapd, reply, rlen, 0, NULL, 0, 0) < 0)
                wpa_printf(MSG_INFO, "send_auth_reply: send failed");
        else
                reply_res = WLAN_STATUS_SUCCESS;
@@ -369,7 +399,7 @@ static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
        struct sta_info *sta;
        int reply_res;
 
-       reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT,
+       reply_res = send_auth_reply(hapd, NULL, dst, bssid, WLAN_AUTH_FT,
                                    auth_transaction, status, ies, ies_len,
                                    "auth-ft-finish");
 
@@ -514,7 +544,8 @@ static int auth_sae_send_commit(struct hostapd_data *hapd,
 
        status = (sta->sae->tmp && sta->sae->tmp->h2e) ?
                WLAN_STATUS_SAE_HASH_TO_ELEMENT : WLAN_STATUS_SUCCESS;
-       reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1,
+       reply_res = send_auth_reply(hapd, sta, sta->addr, bssid,
+                                   WLAN_AUTH_SAE, 1,
                                    status, wpabuf_head(data),
                                    wpabuf_len(data), "sae-send-commit");
 
@@ -535,7 +566,8 @@ static int auth_sae_send_confirm(struct hostapd_data *hapd,
        if (data == NULL)
                return WLAN_STATUS_UNSPECIFIED_FAILURE;
 
-       reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2,
+       reply_res = send_auth_reply(hapd, sta, sta->addr, bssid,
+                                   WLAN_AUTH_SAE, 2,
                                    WLAN_STATUS_SUCCESS, wpabuf_head(data),
                                    wpabuf_len(data), "sae-send-confirm");
 
@@ -1103,7 +1135,7 @@ static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
                wpa_printf(MSG_DEBUG, "SAE: TESTING - reflection attack");
                pos = mgmt->u.auth.variable;
                end = ((const u8 *) mgmt) + len;
-               send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
+               send_auth_reply(hapd, sta, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
                                auth_transaction, resp, pos, end - pos,
                                "auth-sae-reflection-attack");
                goto remove_sta;
@@ -1111,7 +1143,7 @@ static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
 
        if (hapd->conf->sae_commit_override && auth_transaction == 1) {
                wpa_printf(MSG_DEBUG, "SAE: TESTING - commit override");
-               send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
+               send_auth_reply(hapd, sta, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
                                auth_transaction, resp,
                                wpabuf_head(hapd->conf->sae_commit_override),
                                wpabuf_len(hapd->conf->sae_commit_override),
@@ -1365,7 +1397,7 @@ reply:
                        data = wpabuf_alloc_copy(pos, 2);
 
                sae_sme_send_external_auth_status(hapd, sta, resp);
-               send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
+               send_auth_reply(hapd, sta, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
                                auth_transaction, resp,
                                data ? wpabuf_head(data) : (u8 *) "",
                                data ? wpabuf_len(data) : 0, "auth-sae");
@@ -2006,7 +2038,7 @@ static void handle_auth_fils_finish(struct hostapd_data *hapd,
        auth_alg = (pub ||
                    resp == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) ?
                WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK;
-       send_auth_reply(hapd, sta->addr, hapd->own_addr, auth_alg, 2, resp,
+       send_auth_reply(hapd, sta, sta->addr, hapd->own_addr, auth_alg, 2, resp,
                        data ? wpabuf_head(data) : (u8 *) "",
                        data ? wpabuf_len(data) : 0, "auth-fils-finish");
        wpabuf_free(data);
@@ -2050,20 +2082,18 @@ void ieee802_11_finish_fils_auth(struct hostapd_data *hapd,
 #endif /* CONFIG_FILS */
 
 
-int ieee802_11_allowed_address(struct hostapd_data *hapd, const u8 *addr,
-                              const u8 *msg, size_t len,
-                              struct radius_sta *info, int is_probe_req)
+static int ieee802_11_allowed_address(struct hostapd_data *hapd, const u8 *addr,
+                                     const u8 *msg, size_t len,
+                                     struct radius_sta *info)
 {
        int res;
 
-       res = hostapd_allowed_address(hapd, addr, msg, len, info, is_probe_req);
+       res = hostapd_allowed_address(hapd, addr, msg, len, info, 0);
 
        if (res == HOSTAPD_ACL_REJECT) {
-               if (!is_probe_req)
-                       wpa_printf(MSG_DEBUG,
-                                  "Station " MACSTR
-                                  " not allowed to authenticate",
-                                  MAC2STR(addr));
+               wpa_printf(MSG_DEBUG, "Station " MACSTR
+                          " not allowed to authenticate",
+                          MAC2STR(addr));
                return HOSTAPD_ACL_REJECT;
        }
 
@@ -2305,8 +2335,8 @@ static void handle_auth(struct hostapd_data *hapd,
                }
        }
 
-       res = ieee802_11_allowed_address(
-               hapd, mgmt->sa, (const u8 *) mgmt, len, &rad_info, 0);
+       res = ieee802_11_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
+                                        &rad_info);
        if (res == HOSTAPD_ACL_REJECT) {
                wpa_msg(hapd->msg_ctx, MSG_DEBUG,
                        "Ignore Authentication frame from " MACSTR
@@ -2531,7 +2561,7 @@ static void handle_auth(struct hostapd_data *hapd,
        }
 
  fail:
-       reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
+       reply_res = send_auth_reply(hapd, sta, mgmt->sa, mgmt->bssid, auth_alg,
                                    auth_transaction + 1, resp, resp_ies,
                                    resp_ies_len, "handle-auth");
 
@@ -3464,7 +3494,7 @@ static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
        send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
        reply.u.deauth.reason_code = host_to_le16(reason_code);
 
-       if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
+       if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0, NULL, 0, 0) < 0)
                wpa_printf(MSG_INFO, "Failed to send deauth: %s",
                           strerror(errno));
 }
@@ -3850,7 +3880,7 @@ static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
        }
 #endif /* CONFIG_FILS */
 
-       if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
+       if (hostapd_drv_send_mlme(hapd, reply, send_len, 0, NULL, 0, 0) < 0) {
                wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
                           strerror(errno));
                res = WLAN_STATUS_UNSPECIFIED_FAILURE;
@@ -4065,7 +4095,7 @@ static void handle_assoc(struct hostapd_data *hapd,
 
                        acl_res = ieee802_11_allowed_address(hapd, mgmt->sa,
                                                             (const u8 *) mgmt,
-                                                            len, &info, 0);
+                                                            len, &info);
                        if (acl_res == HOSTAPD_ACL_REJECT) {
                                wpa_msg(hapd->msg_ctx, MSG_DEBUG,
                                        "Ignore Association Request frame from "
@@ -4680,7 +4710,7 @@ static int handle_action(struct hostapd_data *hapd,
                os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
                resp->u.action.category |= 0x80;
 
-               if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
+               if (hostapd_drv_send_mlme(hapd, resp, len, 0, NULL, 0, 0) < 0) {
                        wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
                                   "Action frame");
                }
@@ -4881,8 +4911,11 @@ static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
        for (i = 0; i < 4; i++) {
                if (ssid->wep.key[i] &&
                    hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
-                                       i == ssid->wep.idx, NULL, 0,
-                                       ssid->wep.key[i], ssid->wep.len[i])) {
+                                       0, i == ssid->wep.idx, NULL, 0,
+                                       ssid->wep.key[i], ssid->wep.len[i],
+                                       i == ssid->wep.idx ?
+                                       KEY_FLAG_GROUP_RX_TX_DEFAULT :
+                                       KEY_FLAG_GROUP_RX_TX)) {
                        wpa_printf(MSG_WARNING,
                                   "Could not set WEP keys for WDS interface; %s",
                                   ifname_wds);