]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - wpa_supplicant/mesh_mpm.c
FT: Remove and re-add STA entry after FT protocol success with PMF
[thirdparty/hostap.git] / wpa_supplicant / mesh_mpm.c
index 74ad762bb175dd5b3d8d00a0ce60d077619f0425..4925b5cdeca8e65e31cc3f6ce1eee71bcc7a4c22 100644 (file)
@@ -11,6 +11,8 @@
 #include "utils/common.h"
 #include "utils/eloop.h"
 #include "common/ieee802_11_defs.h"
+#include "common/hw_features_common.h"
+#include "common/ocv.h"
 #include "ap/hostapd.h"
 #include "ap/sta_info.h"
 #include "ap/ieee802_11.h"
@@ -19,6 +21,7 @@
 #include "driver_i.h"
 #include "mesh_mpm.h"
 #include "mesh_rsn.h"
+#include "notify.h"
 
 struct mesh_peer_mgmt_ie {
        const u8 *proto_id; /* Mesh Peering Protocol Identifier (2 octets) */
@@ -35,19 +38,17 @@ enum plink_event {
        PLINK_UNDEFINED,
        OPN_ACPT,
        OPN_RJCT,
-       OPN_IGNR,
        CNF_ACPT,
        CNF_RJCT,
-       CNF_IGNR,
        CLS_ACPT,
-       CLS_IGNR
+       REQ_RJCT
 };
 
 static const char * const mplstate[] = {
        [0] = "UNINITIALIZED",
-       [PLINK_LISTEN] = "LISTEN",
-       [PLINK_OPEN_SENT] = "OPEN_SENT",
-       [PLINK_OPEN_RCVD] = "OPEN_RCVD",
+       [PLINK_IDLE] = "IDLE",
+       [PLINK_OPN_SNT] = "OPN_SNT",
+       [PLINK_OPN_RCVD] = "OPN_RCVD",
        [PLINK_CNF_RCVD] = "CNF_RCVD",
        [PLINK_ESTAB] = "ESTAB",
        [PLINK_HOLDING] = "HOLDING",
@@ -58,12 +59,10 @@ static const char * const mplevent[] = {
        [PLINK_UNDEFINED] = "UNDEFINED",
        [OPN_ACPT] = "OPN_ACPT",
        [OPN_RJCT] = "OPN_RJCT",
-       [OPN_IGNR] = "OPN_IGNR",
        [CNF_ACPT] = "CNF_ACPT",
        [CNF_RJCT] = "CNF_RJCT",
-       [CNF_IGNR] = "CNF_IGNR",
        [CLS_ACPT] = "CLS_ACPT",
-       [CLS_IGNR] = "CLS_IGNR"
+       [REQ_RJCT] = "REQ_RJCT",
 };
 
 
@@ -190,17 +189,18 @@ static void mesh_mpm_init_link(struct wpa_supplicant *wpa_s,
 
        do {
                if (os_get_random((u8 *) &llid, sizeof(llid)) < 0)
-                       continue;
+                       llid = 0; /* continue */
        } while (!llid || llid_in_use(wpa_s, llid));
 
        sta->my_lid = llid;
        sta->peer_lid = 0;
+       sta->peer_aid = 0;
 
        /*
         * We do not use wpa_mesh_set_plink_state() here because there is no
         * entry in kernel yet.
         */
-       sta->plink_state = PLINK_LISTEN;
+       sta->plink_state = PLINK_IDLE;
 }
 
 
@@ -223,29 +223,43 @@ static void mesh_mpm_send_plink_action(struct wpa_supplicant *wpa_s,
        if (!sta)
                return;
 
-       buf_len = 2 +      /* capability info */
+       buf_len = 2 +      /* Category and Action */
+                 2 +      /* capability info */
                  2 +      /* AID */
                  2 + 8 +  /* supported rates */
                  2 + (32 - 8) +
                  2 + 32 + /* mesh ID */
                  2 + 7 +  /* mesh config */
-                 2 + 23 + /* peering management */
-                 2 + 96 + /* AMPE */
+                 2 + 24 + /* peering management */
+                 2 + 96 + 32 + 32 + /* AMPE (96 + max GTKlen + max IGTKlen) */
                  2 + 16;  /* MIC */
-#ifdef CONFIG_IEEE80211N
        if (type != PLINK_CLOSE && wpa_s->mesh_ht_enabled) {
                buf_len += 2 + 26 + /* HT capabilities */
                           2 + 22;  /* HT operation */
        }
-#endif /* CONFIG_IEEE80211N */
 #ifdef CONFIG_IEEE80211AC
        if (type != PLINK_CLOSE && wpa_s->mesh_vht_enabled) {
                buf_len += 2 + 12 + /* VHT Capabilities */
                           2 + 5;  /* VHT Operation */
        }
 #endif /* CONFIG_IEEE80211AC */
+#ifdef CONFIG_IEEE80211AX
+       if (type != PLINK_CLOSE && wpa_s->mesh_he_enabled) {
+               buf_len += 3 +
+                          HE_MAX_MAC_CAPAB_SIZE +
+                          HE_MAX_PHY_CAPAB_SIZE +
+                          HE_MAX_MCS_CAPAB_SIZE +
+                          HE_MAX_PPET_CAPAB_SIZE;
+               buf_len += 3 + sizeof(struct ieee80211_he_operation);
+       }
+#endif /* CONFIG_IEEE80211AX */
        if (type != PLINK_CLOSE)
                buf_len += conf->rsn_ie_len; /* RSN IE */
+#ifdef CONFIG_OCV
+       /* OCI is included even when the other STA doesn't support OCV */
+       if (type != PLINK_CLOSE && conf->ocv)
+               buf_len += OCV_OCI_EXTENDED_LEN;
+#endif /* CONFIG_OCV */
 
        buf = wpabuf_alloc(buf_len);
        if (!buf)
@@ -290,7 +304,8 @@ static void mesh_mpm_send_plink_action(struct wpa_supplicant *wpa_s,
                /* TODO: Add Connected to Mesh Gate/AS subfields */
                wpabuf_put_u8(buf, info);
                /* always forwarding & accepting plinks for now */
-               wpabuf_put_u8(buf, 0x1 | 0x8);
+               wpabuf_put_u8(buf, MESH_CAP_ACCEPT_ADDITIONAL_PEER |
+                             MESH_CAP_FORWARDING);
        } else {        /* Peer closing frame */
                /* IE: Mesh ID */
                wpabuf_put_u8(buf, WLAN_EID_MESH_ID);
@@ -337,7 +352,6 @@ static void mesh_mpm_send_plink_action(struct wpa_supplicant *wpa_s,
                                   wpabuf_put(buf, PMKID_LEN));
        }
 
-#ifdef CONFIG_IEEE80211N
        if (type != PLINK_CLOSE && wpa_s->mesh_ht_enabled) {
                u8 ht_capa_oper[2 + 26 + 2 + 22];
 
@@ -345,16 +359,46 @@ static void mesh_mpm_send_plink_action(struct wpa_supplicant *wpa_s,
                pos = hostapd_eid_ht_operation(bss, pos);
                wpabuf_put_data(buf, ht_capa_oper, pos - ht_capa_oper);
        }
-#endif /* CONFIG_IEEE80211N */
 #ifdef CONFIG_IEEE80211AC
        if (type != PLINK_CLOSE && wpa_s->mesh_vht_enabled) {
                u8 vht_capa_oper[2 + 12 + 2 + 5];
 
-               pos = hostapd_eid_vht_capabilities(bss, vht_capa_oper);
+               pos = hostapd_eid_vht_capabilities(bss, vht_capa_oper, 0);
                pos = hostapd_eid_vht_operation(bss, pos);
                wpabuf_put_data(buf, vht_capa_oper, pos - vht_capa_oper);
        }
 #endif /* CONFIG_IEEE80211AC */
+#ifdef CONFIG_IEEE80211AX
+       if (type != PLINK_CLOSE && wpa_s->mesh_he_enabled) {
+               u8 he_capa_oper[3 +
+                               HE_MAX_MAC_CAPAB_SIZE +
+                               HE_MAX_PHY_CAPAB_SIZE +
+                               HE_MAX_MCS_CAPAB_SIZE +
+                               HE_MAX_PPET_CAPAB_SIZE +
+                               3 + sizeof(struct ieee80211_he_operation)];
+
+               pos = hostapd_eid_he_capab(bss, he_capa_oper,
+                                          IEEE80211_MODE_MESH);
+               pos = hostapd_eid_he_operation(bss, pos);
+               wpabuf_put_data(buf, he_capa_oper, pos - he_capa_oper);
+       }
+#endif /* CONFIG_IEEE80211AX */
+
+#ifdef CONFIG_OCV
+       if (type != PLINK_CLOSE && conf->ocv) {
+               struct wpa_channel_info ci;
+
+               if (wpa_drv_channel_info(wpa_s, &ci) != 0) {
+                       wpa_printf(MSG_WARNING,
+                                  "Mesh MPM: Failed to get channel info for OCI element");
+                       goto fail;
+               }
+
+               pos = wpabuf_put(buf, OCV_OCI_EXTENDED_LEN);
+               if (ocv_insert_extended_oci(&ci, pos) < 0)
+                       goto fail;
+       }
+#endif /* CONFIG_OCV */
 
        if (ampe && mesh_rsn_protect_frame(wpa_s->mesh_rsn, sta, cat, buf)) {
                wpa_msg(wpa_s, MSG_INFO,
@@ -393,6 +437,7 @@ void wpa_mesh_set_plink_state(struct wpa_supplicant *wpa_s,
        os_memset(&params, 0, sizeof(params));
        params.addr = sta->addr;
        params.plink_state = state;
+       params.peer_aid = sta->peer_aid;
        params.set = 1;
 
        ret = wpa_drv_sta_add(wpa_s, &params);
@@ -423,8 +468,8 @@ static void plink_timer(void *eloop_ctx, void *user_data)
        struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
 
        switch (sta->plink_state) {
-       case PLINK_OPEN_RCVD:
-       case PLINK_OPEN_SENT:
+       case PLINK_OPN_RCVD:
+       case PLINK_OPN_SNT:
                /* retry timer */
                if (sta->mpm_retries < conf->dot11MeshMaxRetries) {
                        eloop_register_timeout(
@@ -436,7 +481,7 @@ static void plink_timer(void *eloop_ctx, void *user_data)
                        break;
                }
                reason = WLAN_REASON_MESH_MAX_RETRIES;
-               /* fall through on else */
+               /* fall through */
 
        case PLINK_CNF_RCVD:
                /* confirm timer */
@@ -558,7 +603,7 @@ int mesh_mpm_connect_peer(struct wpa_supplicant *wpa_s, const u8 *addr,
                return -1;
        }
 
-       if ((PLINK_OPEN_SENT <= sta->plink_state &&
+       if ((PLINK_OPN_SNT <= sta->plink_state &&
            sta->plink_state <= PLINK_ESTAB) ||
            (sta->sae && sta->sae->state > SAE_NOTHING)) {
                wpa_msg(wpa_s, MSG_INFO,
@@ -567,7 +612,7 @@ int mesh_mpm_connect_peer(struct wpa_supplicant *wpa_s, const u8 *addr,
        }
 
        if (conf->security == MESH_CONF_SEC_NONE) {
-               mesh_mpm_plink_open(wpa_s, sta, PLINK_OPEN_SENT);
+               mesh_mpm_plink_open(wpa_s, sta, PLINK_OPN_SNT);
        } else {
                mesh_rsn_auth_sae_sta(wpa_s, sta);
                os_memcpy(hapd->mesh_required_peer, addr, ETH_ALEN);
@@ -630,7 +675,7 @@ void mesh_mpm_auth_peer(struct wpa_supplicant *wpa_s, const u8 *addr)
        if (!sta->my_lid)
                mesh_mpm_init_link(wpa_s, sta);
 
-       mesh_mpm_plink_open(wpa_s, sta, PLINK_OPEN_SENT);
+       mesh_mpm_plink_open(wpa_s, sta, PLINK_OPN_SNT);
 }
 
 /*
@@ -647,15 +692,25 @@ static struct sta_info * mesh_mpm_add_peer(struct wpa_supplicant *wpa_s,
        struct mesh_conf *conf = wpa_s->ifmsh->mconf;
        struct hostapd_data *data = wpa_s->ifmsh->bss[0];
        struct sta_info *sta;
+       struct ieee80211_ht_operation *oper;
        int ret;
 
-       sta = ap_get_sta(data, addr);
-       if (!sta) {
-               sta = ap_sta_add(data, addr);
-               if (!sta)
-                       return NULL;
+       if (elems->mesh_config_len >= 7 &&
+           !(elems->mesh_config[6] & MESH_CAP_ACCEPT_ADDITIONAL_PEER)) {
+               wpa_msg(wpa_s, MSG_DEBUG,
+                       "mesh: Ignore a crowded peer " MACSTR,
+                       MAC2STR(addr));
+               return NULL;
        }
 
+       sta = ap_get_sta(data, addr);
+       if (sta)
+               return NULL;
+
+       sta = ap_sta_add(data, addr);
+       if (!sta)
+               return NULL;
+
        /* Set WMM by default since Mesh STAs are QoS STAs */
        sta->flags |= WLAN_STA_WMM;
 
@@ -668,16 +723,31 @@ static struct sta_info * mesh_mpm_add_peer(struct wpa_supplicant *wpa_s,
        if (!sta->my_lid)
                mesh_mpm_init_link(wpa_s, sta);
 
-#ifdef CONFIG_IEEE80211N
        copy_sta_ht_capab(data, sta, elems->ht_capabilities);
+
+       oper = (struct ieee80211_ht_operation *) elems->ht_operation;
+       if (oper &&
+           !(oper->ht_param & HT_INFO_HT_PARAM_STA_CHNL_WIDTH) &&
+           sta->ht_capabilities) {
+               wpa_msg(wpa_s, MSG_DEBUG, MACSTR
+                       " does not support 40 MHz bandwidth",
+                       MAC2STR(sta->addr));
+               set_disable_ht40(sta->ht_capabilities, 1);
+       }
+
        update_ht_state(data, sta);
-#endif /* CONFIG_IEEE80211N */
 
 #ifdef CONFIG_IEEE80211AC
        copy_sta_vht_capab(data, sta, elems->vht_capabilities);
+       copy_sta_vht_oper(data, sta, elems->vht_operation);
        set_sta_vht_opmode(data, sta, elems->vht_opmode_notif);
 #endif /* CONFIG_IEEE80211AC */
 
+#ifdef CONFIG_IEEE80211AX
+       copy_sta_he_capab(data, sta, IEEE80211_MODE_MESH,
+                         elems->he_capabilities, elems->he_capabilities_len);
+#endif /* CONFIG_IEEE80211AX */
+
        if (hostapd_get_aid(data, sta) < 0) {
                wpa_msg(wpa_s, MSG_ERROR, "No AIDs available");
                ap_free_sta(data, sta);
@@ -691,9 +761,12 @@ static struct sta_info * mesh_mpm_add_peer(struct wpa_supplicant *wpa_s,
        params.addr = addr;
        params.plink_state = sta->plink_state;
        params.aid = sta->aid;
+       params.peer_aid = sta->peer_aid;
        params.listen_interval = 100;
        params.ht_capabilities = sta->ht_capabilities;
        params.vht_capabilities = sta->vht_capabilities;
+       params.he_capab = sta->he_capab;
+       params.he_capab_len = sta->he_capab_len;
        params.flags |= WPA_STA_WMM;
        params.flags_mask |= WPA_STA_AUTHENTICATED;
        if (conf->security == MESH_CONF_SEC_NONE) {
@@ -761,9 +834,9 @@ void wpa_mesh_new_mesh_peer(struct wpa_supplicant *wpa_s, const u8 *addr,
        }
 
        if (conf->security == MESH_CONF_SEC_NONE) {
-               if (sta->plink_state < PLINK_OPEN_SENT ||
+               if (sta->plink_state < PLINK_OPN_SNT ||
                    sta->plink_state > PLINK_ESTAB)
-                       mesh_mpm_plink_open(wpa_s, sta, PLINK_OPEN_SENT);
+                       mesh_mpm_plink_open(wpa_s, sta, PLINK_OPN_SNT);
        } else {
                mesh_rsn_auth_sae_sta(wpa_s, sta);
        }
@@ -794,30 +867,33 @@ static void mesh_mpm_plink_estab(struct wpa_supplicant *wpa_s,
 
        if (conf->security & MESH_CONF_SEC_AMPE) {
                wpa_hexdump_key(MSG_DEBUG, "mesh: MTK", sta->mtk, sta->mtk_len);
-               /* TODO: support for other ciphers */
-               wpa_drv_set_key(wpa_s, WPA_ALG_CCMP, sta->addr, 0, 0,
-                               seq, sizeof(seq), sta->mtk, sta->mtk_len);
+               wpa_drv_set_key(wpa_s, wpa_cipher_to_alg(conf->pairwise_cipher),
+                               sta->addr, 0, 0, seq, sizeof(seq),
+                               sta->mtk, sta->mtk_len,
+                               KEY_FLAG_PAIRWISE_RX_TX);
 
                wpa_hexdump_key(MSG_DEBUG, "mesh: RX MGTK Key RSC",
                                sta->mgtk_rsc, sizeof(sta->mgtk_rsc));
                wpa_hexdump_key(MSG_DEBUG, "mesh: RX MGTK",
                                sta->mgtk, sta->mgtk_len);
-               /* TODO: support for other ciphers */
-               /* FIX: key index.. */
-               wpa_drv_set_key(wpa_s, WPA_ALG_CCMP, sta->addr, 1, 0,
+               wpa_drv_set_key(wpa_s, wpa_cipher_to_alg(conf->group_cipher),
+                               sta->addr, sta->mgtk_key_id, 0,
                                sta->mgtk_rsc, sizeof(sta->mgtk_rsc),
-                               sta->mgtk, sta->mgtk_len);
+                               sta->mgtk, sta->mgtk_len,
+                               KEY_FLAG_GROUP_RX);
 
                if (sta->igtk_len) {
                        wpa_hexdump_key(MSG_DEBUG, "mesh: RX IGTK Key RSC",
                                        sta->igtk_rsc, sizeof(sta->igtk_rsc));
-                       wpa_hexdump_key(MSG_DEBUG, "RX IGTK",
-                                       sta->igtk, sta->igtk_len);
-                       /* FIX: key index.. */
-                       wpa_drv_set_key(wpa_s, WPA_ALG_IGTK, sta->addr,
-                                       sta->igtk_key_id, 0,
-                                       sta->igtk_rsc, sizeof(sta->igtk_rsc),
+                       wpa_hexdump_key(MSG_DEBUG, "mesh: RX IGTK",
                                        sta->igtk, sta->igtk_len);
+                       wpa_drv_set_key(
+                               wpa_s,
+                               wpa_cipher_to_alg(conf->mgmt_group_cipher),
+                               sta->addr, sta->igtk_key_id, 0,
+                               sta->igtk_rsc, sizeof(sta->igtk_rsc),
+                               sta->igtk, sta->igtk_len,
+                               KEY_FLAG_GROUP_RX);
                }
        }
 
@@ -834,40 +910,47 @@ static void mesh_mpm_plink_estab(struct wpa_supplicant *wpa_s,
        /* Send ctrl event */
        wpa_msg(wpa_s, MSG_INFO, MESH_PEER_CONNECTED MACSTR,
                MAC2STR(sta->addr));
+
+       /* Send D-Bus event */
+       wpas_notify_mesh_peer_connected(wpa_s, sta->addr);
 }
 
 
 static void mesh_mpm_fsm(struct wpa_supplicant *wpa_s, struct sta_info *sta,
-                        enum plink_event event)
+                        enum plink_event event, u16 reason)
 {
        struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
        struct mesh_conf *conf = wpa_s->ifmsh->mconf;
-       u16 reason = 0;
 
        wpa_msg(wpa_s, MSG_DEBUG, "MPM " MACSTR " state %s event %s",
                MAC2STR(sta->addr), mplstate[sta->plink_state],
                mplevent[event]);
 
        switch (sta->plink_state) {
-       case PLINK_LISTEN:
+       case PLINK_IDLE:
                switch (event) {
                case CLS_ACPT:
                        mesh_mpm_fsm_restart(wpa_s, sta);
                        break;
                case OPN_ACPT:
-                       mesh_mpm_plink_open(wpa_s, sta, PLINK_OPEN_RCVD);
+                       mesh_mpm_plink_open(wpa_s, sta, PLINK_OPN_RCVD);
                        mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CONFIRM,
                                                   0);
                        break;
+               case REQ_RJCT:
+                       mesh_mpm_send_plink_action(wpa_s, sta,
+                                                  PLINK_CLOSE, reason);
+                       break;
                default:
                        break;
                }
                break;
-       case PLINK_OPEN_SENT:
+       case PLINK_OPN_SNT:
                switch (event) {
                case OPN_RJCT:
                case CNF_RJCT:
-                       reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
+                       if (!reason)
+                               reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
                        /* fall-through */
                case CLS_ACPT:
                        wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
@@ -882,7 +965,7 @@ static void mesh_mpm_fsm(struct wpa_supplicant *wpa_s, struct sta_info *sta,
                        break;
                case OPN_ACPT:
                        /* retry timer is left untouched */
-                       wpa_mesh_set_plink_state(wpa_s, sta, PLINK_OPEN_RCVD);
+                       wpa_mesh_set_plink_state(wpa_s, sta, PLINK_OPN_RCVD);
                        mesh_mpm_send_plink_action(wpa_s, sta,
                                                   PLINK_CONFIRM, 0);
                        break;
@@ -898,11 +981,12 @@ static void mesh_mpm_fsm(struct wpa_supplicant *wpa_s, struct sta_info *sta,
                        break;
                }
                break;
-       case PLINK_OPEN_RCVD:
+       case PLINK_OPN_RCVD:
                switch (event) {
                case OPN_RJCT:
                case CNF_RJCT:
-                       reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
+                       if (!reason)
+                               reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
                        /* fall-through */
                case CLS_ACPT:
                        wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
@@ -933,7 +1017,8 @@ static void mesh_mpm_fsm(struct wpa_supplicant *wpa_s, struct sta_info *sta,
                switch (event) {
                case OPN_RJCT:
                case CNF_RJCT:
-                       reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
+                       if (!reason)
+                               reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
                        /* fall-through */
                case CLS_ACPT:
                        wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
@@ -960,9 +1045,12 @@ static void mesh_mpm_fsm(struct wpa_supplicant *wpa_s, struct sta_info *sta,
                break;
        case PLINK_ESTAB:
                switch (event) {
+               case OPN_RJCT:
+               case CNF_RJCT:
                case CLS_ACPT:
                        wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
-                       reason = WLAN_REASON_MESH_CLOSE_RCVD;
+                       if (!reason)
+                               reason = WLAN_REASON_MESH_CLOSE_RCVD;
 
                        eloop_register_timeout(
                                conf->dot11MeshHoldingTimeout / 1000,
@@ -977,6 +1065,10 @@ static void mesh_mpm_fsm(struct wpa_supplicant *wpa_s, struct sta_info *sta,
                        wpa_msg(wpa_s, MSG_INFO, MESH_PEER_DISCONNECTED MACSTR,
                                MAC2STR(sta->addr));
 
+                       /* Send D-Bus event */
+                       wpas_notify_mesh_peer_disconnected(wpa_s, sta->addr,
+                                                          reason);
+
                        hapd->num_plinks--;
 
                        mesh_mpm_send_plink_action(wpa_s, sta,
@@ -1023,13 +1115,14 @@ void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
        struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
        struct mesh_conf *mconf = wpa_s->ifmsh->mconf;
        struct sta_info *sta;
-       u16 plid = 0, llid = 0;
+       u16 plid = 0, llid = 0, aid = 0;
        enum plink_event event;
        struct ieee802_11_elems elems;
        struct mesh_peer_mgmt_ie peer_mgmt_ie;
        const u8 *ies;
        size_t ie_len;
        int ret;
+       u16 reason = 0;
 
        if (mgmt->u.action.category != WLAN_ACTION_SELF_PROTECTED)
                return;
@@ -1060,7 +1153,8 @@ void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
                ie_len -= 2;
        }
        if (action_field == PLINK_CONFIRM) {
-               wpa_printf(MSG_DEBUG, "MPM: AID 0x%x", WPA_GET_LE16(ies));
+               aid = WPA_GET_LE16(ies);
+               wpa_printf(MSG_DEBUG, "MPM: AID 0x%x", aid);
                ies += 2;       /* aid */
                ie_len -= 2;
        }
@@ -1104,6 +1198,10 @@ void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
                llid = WPA_GET_LE16(peer_mgmt_ie.plid);
        wpa_printf(MSG_DEBUG, "MPM: plid=0x%x llid=0x%x", plid, llid);
 
+       if (action_field == PLINK_CLOSE)
+               wpa_printf(MSG_DEBUG, "MPM: close reason=%u",
+                          WPA_GET_LE16(peer_mgmt_ie.reason));
+
        sta = ap_get_sta(hapd, mgmt->sa);
 
        /*
@@ -1112,7 +1210,7 @@ void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
         */
        if (!sta && action_field == PLINK_OPEN &&
            (!(mconf->security & MESH_CONF_SEC_AMPE) ||
-            wpa_auth_pmksa_get(hapd->wpa_auth, mgmt->sa)))
+            wpa_auth_pmksa_get(hapd->wpa_auth, mgmt->sa, NULL)))
                sta = mesh_mpm_add_peer(wpa_s, mgmt->sa, &elems);
 
        if (!sta) {
@@ -1131,13 +1229,74 @@ void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
        if (!sta->my_lid)
                mesh_mpm_init_link(wpa_s, sta);
 
-       if ((mconf->security & MESH_CONF_SEC_AMPE) &&
-           mesh_rsn_process_ampe(wpa_s, sta, &elems,
-                                 &mgmt->u.action.category,
-                                 peer_mgmt_ie.chosen_pmk,
-                                 ies, ie_len)) {
-               wpa_printf(MSG_DEBUG, "MPM: RSN process rejected frame");
-               return;
+       if (mconf->security & MESH_CONF_SEC_AMPE) {
+               int res;
+
+               res = mesh_rsn_process_ampe(wpa_s, sta, &elems,
+                                           &mgmt->u.action.category,
+                                           peer_mgmt_ie.chosen_pmk,
+                                           ies, ie_len);
+               if (res) {
+                       wpa_printf(MSG_DEBUG,
+                                  "MPM: RSN process rejected frame (res=%d)",
+                                  res);
+                       if (action_field == PLINK_OPEN && res == -2) {
+                               /* AES-SIV decryption failed */
+                               mesh_mpm_fsm(wpa_s, sta, OPN_RJCT,
+                                            WLAN_REASON_MESH_INVALID_GTK);
+                       }
+                       return;
+               }
+
+#ifdef CONFIG_OCV
+               if (action_field == PLINK_OPEN && elems.rsn_ie) {
+                       struct wpa_state_machine *sm = sta->wpa_sm;
+                       struct wpa_ie_data data;
+
+                       res = wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2,
+                                                  elems.rsn_ie_len + 2,
+                                                  &data);
+                       if (res) {
+                               wpa_printf(MSG_DEBUG,
+                                          "Failed to parse RSN IE (res=%d)",
+                                          res);
+                               wpa_hexdump(MSG_DEBUG, "RSN IE", elems.rsn_ie,
+                                           elems.rsn_ie_len);
+                               return;
+                       }
+
+                       wpa_auth_set_ocv(sm, mconf->ocv &&
+                                        (data.capabilities &
+                                         WPA_CAPABILITY_OCVC));
+               }
+
+               if (action_field != PLINK_CLOSE &&
+                   wpa_auth_uses_ocv(sta->wpa_sm)) {
+                       struct wpa_channel_info ci;
+                       int tx_chanwidth;
+                       int tx_seg1_idx;
+
+                       if (wpa_drv_channel_info(wpa_s, &ci) != 0) {
+                               wpa_printf(MSG_WARNING,
+                                          "MPM: Failed to get channel info to validate received OCI in MPM Confirm");
+                               return;
+                       }
+
+                       if (get_tx_parameters(
+                                   sta, channel_width_to_int(ci.chanwidth),
+                                   ci.seg1_idx, &tx_chanwidth,
+                                   &tx_seg1_idx) < 0)
+                               return;
+
+                       if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci,
+                                                tx_chanwidth, tx_seg1_idx) !=
+                           0) {
+                               wpa_printf(MSG_WARNING, "MPM: %s",
+                                          ocv_errorstr);
+                               return;
+                       }
+               }
+#endif /* CONFIG_OCV */
        }
 
        if (sta->plink_state == PLINK_BLOCKED) {
@@ -1149,12 +1308,16 @@ void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
        switch (action_field) {
        case PLINK_OPEN:
                if (plink_free_count(hapd) == 0) {
-                       event = OPN_IGNR;
+                       event = REQ_RJCT;
+                       reason = WLAN_REASON_MESH_MAX_PEERS;
                        wpa_printf(MSG_INFO,
                                   "MPM: Peer link num over quota(%d)",
                                   hapd->max_plinks);
                } else if (sta->peer_lid && sta->peer_lid != plid) {
-                       event = OPN_IGNR;
+                       wpa_printf(MSG_DEBUG,
+                                  "MPM: peer_lid mismatch: 0x%x != 0x%x",
+                                  sta->peer_lid, plid);
+                       return; /* no FSM event */
                } else {
                        sta->peer_lid = plid;
                        event = OPN_ACPT;
@@ -1162,16 +1325,21 @@ void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
                break;
        case PLINK_CONFIRM:
                if (plink_free_count(hapd) == 0) {
-                       event = CNF_IGNR;
+                       event = REQ_RJCT;
+                       reason = WLAN_REASON_MESH_MAX_PEERS;
                        wpa_printf(MSG_INFO,
                                   "MPM: Peer link num over quota(%d)",
                                   hapd->max_plinks);
                } else if (sta->my_lid != llid ||
                           (sta->peer_lid && sta->peer_lid != plid)) {
-                       event = CNF_IGNR;
+                       wpa_printf(MSG_DEBUG,
+                                  "MPM: lid mismatch: my_lid: 0x%x != 0x%x or peer_lid: 0x%x != 0x%x",
+                                  sta->my_lid, llid, sta->peer_lid, plid);
+                       return; /* no FSM event */
                } else {
                        if (!sta->peer_lid)
                                sta->peer_lid = plid;
+                       sta->peer_aid = aid;
                        event = CNF_ACPT;
                }
                break;
@@ -1187,12 +1355,19 @@ void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
                         * restarted.
                         */
                        event = CLS_ACPT;
-               else if (sta->peer_lid != plid)
-                       event = CLS_IGNR;
-               else if (peer_mgmt_ie.plid && sta->my_lid != llid)
-                       event = CLS_IGNR;
-               else
+               else if (sta->peer_lid != plid) {
+                       wpa_printf(MSG_DEBUG,
+                                  "MPM: peer_lid mismatch: 0x%x != 0x%x",
+                                  sta->peer_lid, plid);
+                       return; /* no FSM event */
+               } else if (peer_mgmt_ie.plid && sta->my_lid != llid) {
+                       wpa_printf(MSG_DEBUG,
+                                  "MPM: my_lid mismatch: 0x%x != 0x%x",
+                                  sta->my_lid, llid);
+                       return; /* no FSM event */
+               } else {
                        event = CLS_ACPT;
+               }
                break;
        default:
                /*
@@ -1202,7 +1377,7 @@ void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
                 */
                return;
        }
-       mesh_mpm_fsm(wpa_s, sta, event);
+       mesh_mpm_fsm(wpa_s, sta, event, reason);
 }