2 * WPA Supplicant - Basic mesh peer management
3 * Copyright (c) 2013-2014, cozybit, Inc. All rights reserved.
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
14 #include "ap/hostapd.h"
15 #include "ap/sta_info.h"
16 #include "ap/ieee802_11.h"
17 #include "wpa_supplicant_i.h"
22 /* TODO make configurable */
23 #define dot11MeshMaxRetries 10
24 #define dot11MeshRetryTimeout 1
25 #define dot11MeshConfirmTimeout 1
26 #define dot11MeshHoldingTimeout 1
28 struct mesh_peer_mgmt_ie {
36 static void plink_timer(void *eloop_ctx, void *user_data);
51 static const char * const mplstate[] = {
52 [PLINK_LISTEN] = "LISTEN",
53 [PLINK_OPEN_SENT] = "OPEN_SENT",
54 [PLINK_OPEN_RCVD] = "OPEN_RCVD",
55 [PLINK_CNF_RCVD] = "CNF_RCVD",
56 [PLINK_ESTAB] = "ESTAB",
57 [PLINK_HOLDING] = "HOLDING",
58 [PLINK_BLOCKED] = "BLOCKED"
61 static const char * const mplevent[] = {
62 [PLINK_UNDEFINED] = "UNDEFINED",
63 [OPN_ACPT] = "OPN_ACPT",
64 [OPN_RJCT] = "OPN_RJCT",
65 [OPN_IGNR] = "OPN_IGNR",
66 [CNF_ACPT] = "CNF_ACPT",
67 [CNF_RJCT] = "CNF_RJCT",
68 [CNF_IGNR] = "CNF_IGNR",
69 [CLS_ACPT] = "CLS_ACPT",
70 [CLS_IGNR] = "CLS_IGNR"
74 static int mesh_mpm_parse_peer_mgmt(struct wpa_supplicant *wpa_s,
76 const u8 *ie, size_t len,
77 struct mesh_peer_mgmt_ie *mpm_ie)
79 os_memset(mpm_ie, 0, sizeof(*mpm_ie));
81 /* remove optional PMK at end */
84 mpm_ie->pmk = ie + len - 16;
87 if ((action_field == PLINK_OPEN && len != 4) ||
88 (action_field == PLINK_CONFIRM && len != 6) ||
89 (action_field == PLINK_CLOSE && len != 6 && len != 8)) {
90 wpa_msg(wpa_s, MSG_DEBUG, "MPM: Invalid peer mgmt ie");
97 mpm_ie->proto_id = ie;
98 mpm_ie->llid = ie + 2;
102 /* close reason is always present at end for close */
103 if (action_field == PLINK_CLOSE) {
106 mpm_ie->reason = ie + len - 2;
110 /* plid, present for confirm, and possibly close */
118 static int plink_free_count(struct hostapd_data *hapd)
120 if (hapd->max_plinks > hapd->num_plinks)
121 return hapd->max_plinks - hapd->num_plinks;
126 static u16 copy_supp_rates(struct wpa_supplicant *wpa_s,
127 struct sta_info *sta,
128 struct ieee802_11_elems *elems)
130 if (!elems->supp_rates) {
131 wpa_msg(wpa_s, MSG_ERROR, "no supported rates from " MACSTR,
133 return WLAN_STATUS_UNSPECIFIED_FAILURE;
136 if (elems->supp_rates_len + elems->ext_supp_rates_len >
137 sizeof(sta->supported_rates)) {
138 wpa_msg(wpa_s, MSG_ERROR,
139 "Invalid supported rates element length " MACSTR
140 " %d+%d", MAC2STR(sta->addr), elems->supp_rates_len,
141 elems->ext_supp_rates_len);
142 return WLAN_STATUS_UNSPECIFIED_FAILURE;
145 sta->supported_rates_len = merge_byte_arrays(
146 sta->supported_rates, sizeof(sta->supported_rates),
147 elems->supp_rates, elems->supp_rates_len,
148 elems->ext_supp_rates, elems->ext_supp_rates_len);
150 return WLAN_STATUS_SUCCESS;
154 /* return true if elems from a neighbor match this MBSS */
155 static Boolean matches_local(struct wpa_supplicant *wpa_s,
156 struct ieee802_11_elems *elems)
158 struct mesh_conf *mconf = wpa_s->ifmsh->mconf;
160 if (elems->mesh_config_len < 5)
163 return (mconf->meshid_len == elems->mesh_id_len &&
164 os_memcmp(mconf->meshid, elems->mesh_id,
165 elems->mesh_id_len) == 0 &&
166 mconf->mesh_pp_id == elems->mesh_config[0] &&
167 mconf->mesh_pm_id == elems->mesh_config[1] &&
168 mconf->mesh_cc_id == elems->mesh_config[2] &&
169 mconf->mesh_sp_id == elems->mesh_config[3] &&
170 mconf->mesh_auth_id == elems->mesh_config[4]);
174 /* check if local link id is already used with another peer */
175 static Boolean llid_in_use(struct wpa_supplicant *wpa_s, u16 llid)
177 struct sta_info *sta;
178 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
180 for (sta = hapd->sta_list; sta; sta = sta->next) {
181 if (sta->my_lid == llid)
189 /* generate an llid for a link and set to initial state */
190 static void mesh_mpm_init_link(struct wpa_supplicant *wpa_s,
191 struct sta_info *sta)
196 if (os_get_random((u8 *) &llid, sizeof(llid)) < 0)
198 } while (!llid || llid_in_use(wpa_s, llid));
202 sta->plink_state = PLINK_LISTEN;
206 static void mesh_mpm_send_plink_action(struct wpa_supplicant *wpa_s,
207 struct sta_info *sta,
208 enum plink_action_field type,
212 struct hostapd_iface *ifmsh = wpa_s->ifmsh;
213 struct hostapd_data *bss = ifmsh->bss[0];
214 struct mesh_conf *conf = ifmsh->mconf;
215 u8 supp_rates[2 + 2 + 32];
216 #ifdef CONFIG_IEEE80211N
217 u8 ht_capa_oper[2 + 26 + 2 + 22];
218 #endif /* CONFIG_IEEE80211N */
220 u8 ie_len, add_plid = 0;
222 int ampe = conf->security & MESH_CONF_SEC_AMPE;
227 buf = wpabuf_alloc(2 + /* capability info */
229 2 + 8 + /* supported rates */
231 2 + 32 + /* mesh ID */
232 2 + 7 + /* mesh config */
233 2 + 26 + /* HT capabilities */
234 2 + 22 + /* HT operation */
235 2 + 23 + /* peering management */
241 cat = wpabuf_mhead_u8(buf);
242 wpabuf_put_u8(buf, WLAN_ACTION_SELF_PROTECTED);
243 wpabuf_put_u8(buf, type);
245 if (type != PLINK_CLOSE) {
246 /* capability info */
247 wpabuf_put_le16(buf, ampe ? IEEE80211_CAP_PRIVACY : 0);
250 if (type == PLINK_CONFIRM)
251 wpabuf_put_le16(buf, sta->peer_lid);
253 /* IE: supp + ext. supp rates */
254 pos = hostapd_eid_supp_rates(bss, supp_rates);
255 pos = hostapd_eid_ext_supp_rates(bss, pos);
256 wpabuf_put_data(buf, supp_rates, pos - supp_rates);
259 wpabuf_put_u8(buf, WLAN_EID_MESH_ID);
260 wpabuf_put_u8(buf, conf->meshid_len);
261 wpabuf_put_data(buf, conf->meshid, conf->meshid_len);
264 wpabuf_put_u8(buf, WLAN_EID_MESH_CONFIG);
265 wpabuf_put_u8(buf, 7);
266 wpabuf_put_u8(buf, conf->mesh_pp_id);
267 wpabuf_put_u8(buf, conf->mesh_pm_id);
268 wpabuf_put_u8(buf, conf->mesh_cc_id);
269 wpabuf_put_u8(buf, conf->mesh_sp_id);
270 wpabuf_put_u8(buf, conf->mesh_auth_id);
271 /* TODO: formation info */
272 wpabuf_put_u8(buf, 0);
273 /* always forwarding & accepting plinks for now */
274 wpabuf_put_u8(buf, 0x1 | 0x8);
275 } else { /* Peer closing frame */
277 wpabuf_put_u8(buf, WLAN_EID_MESH_ID);
278 wpabuf_put_u8(buf, conf->meshid_len);
279 wpabuf_put_data(buf, conf->meshid, conf->meshid_len);
282 /* IE: Mesh Peering Management element */
296 ie_len += 2; /* reason code */
300 wpabuf_put_u8(buf, WLAN_EID_PEER_MGMT);
301 wpabuf_put_u8(buf, ie_len);
302 /* peering protocol */
304 wpabuf_put_le16(buf, 1);
306 wpabuf_put_le16(buf, 0);
307 wpabuf_put_le16(buf, sta->my_lid);
309 wpabuf_put_le16(buf, sta->peer_lid);
310 if (type == PLINK_CLOSE)
311 wpabuf_put_le16(buf, close_reason);
313 mesh_rsn_get_pmkid(wpa_s->mesh_rsn, sta,
314 wpabuf_put(buf, PMKID_LEN));
316 #ifdef CONFIG_IEEE80211N
317 if (type != PLINK_CLOSE &&
318 wpa_s->current_ssid->mesh_ht_mode != CHAN_NO_HT) {
319 pos = hostapd_eid_ht_capabilities(bss, ht_capa_oper);
320 pos = hostapd_eid_ht_operation(bss, pos);
321 wpabuf_put_data(buf, ht_capa_oper, pos - ht_capa_oper);
323 #endif /* CONFIG_IEEE80211N */
325 if (ampe && mesh_rsn_protect_frame(wpa_s->mesh_rsn, sta, cat, buf)) {
326 wpa_msg(wpa_s, MSG_INFO,
327 "Mesh MPM: failed to add AMPE and MIC IE");
331 ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
332 sta->addr, wpa_s->own_addr, wpa_s->own_addr,
333 wpabuf_head(buf), wpabuf_len(buf), 0);
335 wpa_msg(wpa_s, MSG_INFO,
336 "Mesh MPM: failed to send peering frame");
343 /* configure peering state in ours and driver's station entry */
345 wpa_mesh_set_plink_state(struct wpa_supplicant *wpa_s, struct sta_info *sta,
346 enum mesh_plink_state state)
348 struct hostapd_sta_add_params params;
351 sta->plink_state = state;
353 os_memset(¶ms, 0, sizeof(params));
354 params.addr = sta->addr;
355 params.plink_state = state;
358 wpa_msg(wpa_s, MSG_DEBUG, "MPM set " MACSTR " into %s",
359 MAC2STR(sta->addr), mplstate[state]);
360 ret = wpa_drv_sta_add(wpa_s, ¶ms);
362 wpa_msg(wpa_s, MSG_ERROR, "Driver failed to set " MACSTR
363 ": %d", MAC2STR(sta->addr), ret);
368 static void mesh_mpm_fsm_restart(struct wpa_supplicant *wpa_s,
369 struct sta_info *sta)
371 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
373 eloop_cancel_timeout(plink_timer, wpa_s, sta);
375 if (sta->mpm_close_reason == WLAN_REASON_MESH_CLOSE_RCVD) {
376 ap_free_sta(hapd, sta);
380 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_LISTEN);
381 sta->my_lid = sta->peer_lid = sta->mpm_close_reason = 0;
382 sta->mpm_retries = 0;
386 static void plink_timer(void *eloop_ctx, void *user_data)
388 struct wpa_supplicant *wpa_s = eloop_ctx;
389 struct sta_info *sta = user_data;
392 switch (sta->plink_state) {
393 case PLINK_OPEN_RCVD:
394 case PLINK_OPEN_SENT:
396 if (sta->mpm_retries < dot11MeshMaxRetries) {
397 eloop_register_timeout(dot11MeshRetryTimeout, 0,
398 plink_timer, wpa_s, sta);
399 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_OPEN, 0);
403 reason = WLAN_REASON_MESH_MAX_RETRIES;
404 /* fall through on else */
409 reason = WLAN_REASON_MESH_CONFIRM_TIMEOUT;
410 sta->plink_state = PLINK_HOLDING;
411 eloop_register_timeout(dot11MeshHoldingTimeout, 0,
412 plink_timer, wpa_s, sta);
413 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CLOSE, reason);
417 mesh_mpm_fsm_restart(wpa_s, sta);
425 /* initiate peering with station */
427 mesh_mpm_plink_open(struct wpa_supplicant *wpa_s, struct sta_info *sta,
428 enum mesh_plink_state next_state)
430 eloop_cancel_timeout(plink_timer, wpa_s, sta);
431 eloop_register_timeout(dot11MeshRetryTimeout, 0, plink_timer,
433 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_OPEN, 0);
434 wpa_mesh_set_plink_state(wpa_s, sta, next_state);
438 int mesh_mpm_plink_close(struct hostapd_data *hapd,
439 struct sta_info *sta, void *ctx)
441 struct wpa_supplicant *wpa_s = ctx;
442 int reason = WLAN_REASON_MESH_PEERING_CANCELLED;
445 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
446 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CLOSE, reason);
447 wpa_printf(MSG_DEBUG, "MPM closing plink sta=" MACSTR,
449 eloop_cancel_timeout(plink_timer, wpa_s, sta);
457 void mesh_mpm_deinit(struct wpa_supplicant *wpa_s, struct hostapd_iface *ifmsh)
459 struct hostapd_data *hapd = ifmsh->bss[0];
461 /* notify peers we're leaving */
462 ap_for_each_sta(hapd, mesh_mpm_plink_close, wpa_s);
464 hapd->num_plinks = 0;
465 hostapd_free_stas(hapd);
469 /* for mesh_rsn to indicate this peer has completed authentication, and we're
470 * ready to start AMPE */
471 void mesh_mpm_auth_peer(struct wpa_supplicant *wpa_s, const u8 *addr)
473 struct hostapd_data *data = wpa_s->ifmsh->bss[0];
474 struct hostapd_sta_add_params params;
475 struct sta_info *sta;
478 sta = ap_get_sta(data, addr);
480 wpa_msg(wpa_s, MSG_DEBUG, "no such mesh peer");
484 /* TODO: Should do nothing if this STA is already authenticated, but
485 * the AP code already sets this flag. */
486 sta->flags |= WLAN_STA_AUTH;
488 mesh_rsn_init_ampe_sta(wpa_s, sta);
490 os_memset(¶ms, 0, sizeof(params));
491 params.addr = sta->addr;
492 params.flags = WPA_STA_AUTHENTICATED | WPA_STA_AUTHORIZED;
495 wpa_msg(wpa_s, MSG_DEBUG, "MPM authenticating " MACSTR,
497 ret = wpa_drv_sta_add(wpa_s, ¶ms);
499 wpa_msg(wpa_s, MSG_ERROR,
500 "Driver failed to set " MACSTR ": %d",
501 MAC2STR(sta->addr), ret);
505 mesh_mpm_init_link(wpa_s, sta);
507 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPEN_SENT);
511 void wpa_mesh_new_mesh_peer(struct wpa_supplicant *wpa_s, const u8 *addr,
512 struct ieee802_11_elems *elems)
514 struct hostapd_sta_add_params params;
515 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
516 struct hostapd_data *data = wpa_s->ifmsh->bss[0];
517 struct sta_info *sta;
518 struct wpa_ssid *ssid = wpa_s->current_ssid;
521 sta = ap_get_sta(data, addr);
523 sta = ap_sta_add(data, addr);
529 if (copy_supp_rates(wpa_s, sta, elems))
532 mesh_mpm_init_link(wpa_s, sta);
534 #ifdef CONFIG_IEEE80211N
535 copy_sta_ht_capab(data, sta, elems->ht_capabilities,
536 elems->ht_capabilities_len);
537 update_ht_state(data, sta);
538 #endif /* CONFIG_IEEE80211N */
540 /* insert into driver */
541 os_memset(¶ms, 0, sizeof(params));
542 params.supp_rates = sta->supported_rates;
543 params.supp_rates_len = sta->supported_rates_len;
545 params.plink_state = sta->plink_state;
546 params.aid = sta->peer_lid;
547 params.listen_interval = 100;
548 params.ht_capabilities = sta->ht_capabilities;
549 params.flags |= WPA_STA_WMM;
550 params.flags_mask |= WPA_STA_AUTHENTICATED;
551 if (conf->security == MESH_CONF_SEC_NONE) {
552 params.flags |= WPA_STA_AUTHORIZED;
553 params.flags |= WPA_STA_AUTHENTICATED;
555 sta->flags |= WLAN_STA_MFP;
556 params.flags |= WPA_STA_MFP;
559 ret = wpa_drv_sta_add(wpa_s, ¶ms);
561 wpa_msg(wpa_s, MSG_ERROR,
562 "Driver failed to insert " MACSTR ": %d",
567 if (ssid && ssid->no_auto_peer) {
568 wpa_msg(wpa_s, MSG_INFO, "will not initiate new peer link with "
569 MACSTR " because of no_auto_peer", MAC2STR(addr));
573 if (conf->security == MESH_CONF_SEC_NONE)
574 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPEN_SENT);
576 mesh_rsn_auth_sae_sta(wpa_s, sta);
580 void mesh_mpm_mgmt_rx(struct wpa_supplicant *wpa_s, struct rx_mgmt *rx_mgmt)
582 struct hostapd_frame_info fi;
584 os_memset(&fi, 0, sizeof(fi));
585 fi.datarate = rx_mgmt->datarate;
586 fi.ssi_signal = rx_mgmt->ssi_signal;
587 ieee802_11_mgmt(wpa_s->ifmsh->bss[0], rx_mgmt->frame,
588 rx_mgmt->frame_len, &fi);
592 static void mesh_mpm_plink_estab(struct wpa_supplicant *wpa_s,
593 struct sta_info *sta)
595 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
596 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
599 wpa_msg(wpa_s, MSG_INFO, "mesh plink with " MACSTR " established",
602 if (conf->security & MESH_CONF_SEC_AMPE) {
603 wpa_drv_set_key(wpa_s, WPA_ALG_CCMP, sta->addr, 0, 0,
604 seq, sizeof(seq), sta->mtk, sizeof(sta->mtk));
605 wpa_drv_set_key(wpa_s, WPA_ALG_CCMP, sta->addr, 1, 0,
607 sta->mgtk, sizeof(sta->mgtk));
608 wpa_drv_set_key(wpa_s, WPA_ALG_IGTK, sta->addr, 4, 0,
610 sta->mgtk, sizeof(sta->mgtk));
612 wpa_hexdump_key(MSG_DEBUG, "mtk:", sta->mtk, sizeof(sta->mtk));
613 wpa_hexdump_key(MSG_DEBUG, "mgtk:",
614 sta->mgtk, sizeof(sta->mgtk));
617 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_ESTAB);
620 sta->flags |= WLAN_STA_ASSOC;
622 eloop_cancel_timeout(plink_timer, wpa_s, sta);
624 /* Send ctrl event */
625 wpa_msg_ctrl(wpa_s, MSG_INFO, MESH_PEER_CONNECTED MACSTR,
630 static void mesh_mpm_fsm(struct wpa_supplicant *wpa_s, struct sta_info *sta,
631 enum plink_event event)
633 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
634 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
637 wpa_msg(wpa_s, MSG_DEBUG, "MPM " MACSTR " state %s event %s",
638 MAC2STR(sta->addr), mplstate[sta->plink_state],
641 switch (sta->plink_state) {
645 mesh_mpm_fsm_restart(wpa_s, sta);
648 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPEN_RCVD);
649 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CONFIRM,
656 case PLINK_OPEN_SENT:
660 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
663 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
665 reason = WLAN_REASON_MESH_CLOSE_RCVD;
666 eloop_register_timeout(dot11MeshHoldingTimeout, 0,
667 plink_timer, wpa_s, sta);
668 mesh_mpm_send_plink_action(wpa_s, sta,
669 PLINK_CLOSE, reason);
672 /* retry timer is left untouched */
673 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_OPEN_RCVD);
674 mesh_mpm_send_plink_action(wpa_s, sta,
678 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_CNF_RCVD);
679 eloop_register_timeout(dot11MeshConfirmTimeout, 0,
680 plink_timer, wpa_s, sta);
686 case PLINK_OPEN_RCVD:
690 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
693 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
695 reason = WLAN_REASON_MESH_CLOSE_RCVD;
696 eloop_register_timeout(dot11MeshHoldingTimeout, 0,
697 plink_timer, wpa_s, sta);
698 sta->mpm_close_reason = reason;
699 mesh_mpm_send_plink_action(wpa_s, sta,
700 PLINK_CLOSE, reason);
703 mesh_mpm_send_plink_action(wpa_s, sta,
707 if (conf->security & MESH_CONF_SEC_AMPE)
708 mesh_rsn_derive_mtk(wpa_s, sta);
709 mesh_mpm_plink_estab(wpa_s, sta);
719 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
722 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
724 reason = WLAN_REASON_MESH_CLOSE_RCVD;
725 eloop_register_timeout(dot11MeshHoldingTimeout, 0,
726 plink_timer, wpa_s, sta);
727 sta->mpm_close_reason = reason;
728 mesh_mpm_send_plink_action(wpa_s, sta,
729 PLINK_CLOSE, reason);
732 mesh_mpm_plink_estab(wpa_s, sta);
733 mesh_mpm_send_plink_action(wpa_s, sta,
743 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
744 reason = WLAN_REASON_MESH_CLOSE_RCVD;
746 eloop_register_timeout(dot11MeshHoldingTimeout, 0,
747 plink_timer, wpa_s, sta);
748 sta->mpm_close_reason = reason;
750 wpa_msg(wpa_s, MSG_INFO, "mesh plink with " MACSTR
751 " closed with reason %d",
752 MAC2STR(sta->addr), reason);
754 wpa_msg_ctrl(wpa_s, MSG_INFO,
755 MESH_PEER_DISCONNECTED MACSTR,
760 mesh_mpm_send_plink_action(wpa_s, sta,
761 PLINK_CLOSE, reason);
764 mesh_mpm_send_plink_action(wpa_s, sta,
774 mesh_mpm_fsm_restart(wpa_s, sta);
780 reason = sta->mpm_close_reason;
781 mesh_mpm_send_plink_action(wpa_s, sta,
782 PLINK_CLOSE, reason);
789 wpa_msg(wpa_s, MSG_DEBUG,
790 "Unsupported MPM event %s for state %s",
791 mplevent[event], mplstate[sta->plink_state]);
797 void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
798 const struct ieee80211_mgmt *mgmt, size_t len)
801 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
802 struct mesh_conf *mconf = wpa_s->ifmsh->mconf;
803 struct sta_info *sta;
804 u16 plid = 0, llid = 0;
805 enum plink_event event;
806 struct ieee802_11_elems elems;
807 struct mesh_peer_mgmt_ie peer_mgmt_ie;
812 if (mgmt->u.action.category != WLAN_ACTION_SELF_PROTECTED)
815 action_field = mgmt->u.action.u.slf_prot_action.action;
817 ies = mgmt->u.action.u.slf_prot_action.variable;
818 ie_len = (const u8 *) mgmt + len -
819 mgmt->u.action.u.slf_prot_action.variable;
821 /* at least expect mesh id and peering mgmt */
825 if (action_field == PLINK_OPEN || action_field == PLINK_CONFIRM) {
826 ies += 2; /* capability */
829 if (action_field == PLINK_CONFIRM) {
834 /* check for mesh peering, mesh id and mesh config IEs */
835 if (ieee802_11_parse_elems(ies, ie_len, &elems, 0) == ParseFailed)
837 if (!elems.peer_mgmt)
839 if ((action_field != PLINK_CLOSE) &&
840 (!elems.mesh_id || !elems.mesh_config))
843 if (action_field != PLINK_CLOSE && !matches_local(wpa_s, &elems))
846 ret = mesh_mpm_parse_peer_mgmt(wpa_s, action_field,
853 /* the sender's llid is our plid and vice-versa */
854 plid = WPA_GET_LE16(peer_mgmt_ie.llid);
855 if (peer_mgmt_ie.plid)
856 llid = WPA_GET_LE16(peer_mgmt_ie.plid);
858 sta = ap_get_sta(hapd, mgmt->sa);
863 /* peer is in sae_accepted? */
864 if (sta->sae && sta->sae->state != SAE_ACCEPTED)
866 #endif /* CONFIG_SAE */
869 mesh_mpm_init_link(wpa_s, sta);
871 if (mconf->security & MESH_CONF_SEC_AMPE)
872 if (mesh_rsn_process_ampe(wpa_s, sta, &elems,
873 &mgmt->u.action.category,
877 if (sta->plink_state == PLINK_BLOCKED)
880 /* Now we will figure out the appropriate event... */
881 switch (action_field) {
883 if (!plink_free_count(hapd) ||
884 (sta->peer_lid && sta->peer_lid != plid)) {
887 sta->peer_lid = plid;
892 if (!plink_free_count(hapd) ||
893 sta->my_lid != llid ||
894 (sta->peer_lid && sta->peer_lid != plid)) {
898 sta->peer_lid = plid;
903 if (sta->plink_state == PLINK_ESTAB)
904 /* Do not check for llid or plid. This does not
905 * follow the standard but since multiple plinks
906 * per cand are not supported, it is necessary in
907 * order to avoid a livelock when MP A sees an
908 * establish peer link to MP B but MP B does not
909 * see it. This can be caused by a timeout in
910 * B's peer link establishment or B being
914 else if (sta->peer_lid != plid)
916 else if (peer_mgmt_ie.plid && sta->my_lid != llid)
922 wpa_msg(wpa_s, MSG_ERROR,
923 "Mesh plink: unknown frame subtype");
926 mesh_mpm_fsm(wpa_s, sta, event);
930 /* called by ap_free_sta */
931 void mesh_mpm_free_sta(struct sta_info *sta)
933 eloop_cancel_timeout(plink_timer, ELOOP_ALL_CTX, sta);
934 eloop_cancel_timeout(mesh_auth_timer, ELOOP_ALL_CTX, sta);