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 struct mesh_peer_mgmt_ie {
30 static void plink_timer(void *eloop_ctx, void *user_data);
45 static const char * const mplstate[] = {
46 [PLINK_LISTEN] = "LISTEN",
47 [PLINK_OPEN_SENT] = "OPEN_SENT",
48 [PLINK_OPEN_RCVD] = "OPEN_RCVD",
49 [PLINK_CNF_RCVD] = "CNF_RCVD",
50 [PLINK_ESTAB] = "ESTAB",
51 [PLINK_HOLDING] = "HOLDING",
52 [PLINK_BLOCKED] = "BLOCKED"
55 static const char * const mplevent[] = {
56 [PLINK_UNDEFINED] = "UNDEFINED",
57 [OPN_ACPT] = "OPN_ACPT",
58 [OPN_RJCT] = "OPN_RJCT",
59 [OPN_IGNR] = "OPN_IGNR",
60 [CNF_ACPT] = "CNF_ACPT",
61 [CNF_RJCT] = "CNF_RJCT",
62 [CNF_IGNR] = "CNF_IGNR",
63 [CLS_ACPT] = "CLS_ACPT",
64 [CLS_IGNR] = "CLS_IGNR"
68 static int mesh_mpm_parse_peer_mgmt(struct wpa_supplicant *wpa_s,
70 const u8 *ie, size_t len,
71 struct mesh_peer_mgmt_ie *mpm_ie)
73 os_memset(mpm_ie, 0, sizeof(*mpm_ie));
75 /* remove optional PMK at end */
78 mpm_ie->pmk = ie + len - 16;
81 if ((action_field == PLINK_OPEN && len != 4) ||
82 (action_field == PLINK_CONFIRM && len != 6) ||
83 (action_field == PLINK_CLOSE && len != 6 && len != 8)) {
84 wpa_msg(wpa_s, MSG_DEBUG, "MPM: Invalid peer mgmt ie");
91 mpm_ie->proto_id = ie;
92 mpm_ie->llid = ie + 2;
96 /* close reason is always present at end for close */
97 if (action_field == PLINK_CLOSE) {
100 mpm_ie->reason = ie + len - 2;
104 /* plid, present for confirm, and possibly close */
112 static int plink_free_count(struct hostapd_data *hapd)
114 if (hapd->max_plinks > hapd->num_plinks)
115 return hapd->max_plinks - hapd->num_plinks;
120 static u16 copy_supp_rates(struct wpa_supplicant *wpa_s,
121 struct sta_info *sta,
122 struct ieee802_11_elems *elems)
124 if (!elems->supp_rates) {
125 wpa_msg(wpa_s, MSG_ERROR, "no supported rates from " MACSTR,
127 return WLAN_STATUS_UNSPECIFIED_FAILURE;
130 if (elems->supp_rates_len + elems->ext_supp_rates_len >
131 sizeof(sta->supported_rates)) {
132 wpa_msg(wpa_s, MSG_ERROR,
133 "Invalid supported rates element length " MACSTR
134 " %d+%d", MAC2STR(sta->addr), elems->supp_rates_len,
135 elems->ext_supp_rates_len);
136 return WLAN_STATUS_UNSPECIFIED_FAILURE;
139 sta->supported_rates_len = merge_byte_arrays(
140 sta->supported_rates, sizeof(sta->supported_rates),
141 elems->supp_rates, elems->supp_rates_len,
142 elems->ext_supp_rates, elems->ext_supp_rates_len);
144 return WLAN_STATUS_SUCCESS;
148 /* return true if elems from a neighbor match this MBSS */
149 static Boolean matches_local(struct wpa_supplicant *wpa_s,
150 struct ieee802_11_elems *elems)
152 struct mesh_conf *mconf = wpa_s->ifmsh->mconf;
154 if (elems->mesh_config_len < 5)
157 return (mconf->meshid_len == elems->mesh_id_len &&
158 os_memcmp(mconf->meshid, elems->mesh_id,
159 elems->mesh_id_len) == 0 &&
160 mconf->mesh_pp_id == elems->mesh_config[0] &&
161 mconf->mesh_pm_id == elems->mesh_config[1] &&
162 mconf->mesh_cc_id == elems->mesh_config[2] &&
163 mconf->mesh_sp_id == elems->mesh_config[3] &&
164 mconf->mesh_auth_id == elems->mesh_config[4]);
168 /* check if local link id is already used with another peer */
169 static Boolean llid_in_use(struct wpa_supplicant *wpa_s, u16 llid)
171 struct sta_info *sta;
172 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
174 for (sta = hapd->sta_list; sta; sta = sta->next) {
175 if (sta->my_lid == llid)
183 /* generate an llid for a link and set to initial state */
184 static void mesh_mpm_init_link(struct wpa_supplicant *wpa_s,
185 struct sta_info *sta)
190 if (os_get_random((u8 *) &llid, sizeof(llid)) < 0)
192 } while (!llid || llid_in_use(wpa_s, llid));
196 sta->plink_state = PLINK_LISTEN;
200 static void mesh_mpm_send_plink_action(struct wpa_supplicant *wpa_s,
201 struct sta_info *sta,
202 enum plink_action_field type,
206 struct hostapd_iface *ifmsh = wpa_s->ifmsh;
207 struct hostapd_data *bss = ifmsh->bss[0];
208 struct mesh_conf *conf = ifmsh->mconf;
209 u8 supp_rates[2 + 2 + 32];
210 #ifdef CONFIG_IEEE80211N
211 u8 ht_capa_oper[2 + 26 + 2 + 22];
212 #endif /* CONFIG_IEEE80211N */
214 u8 ie_len, add_plid = 0;
216 int ampe = conf->security & MESH_CONF_SEC_AMPE;
222 buf_len = 2 + /* capability info */
224 2 + 8 + /* supported rates */
226 2 + 32 + /* mesh ID */
227 2 + 7 + /* mesh config */
228 2 + 23 + /* peering management */
231 #ifdef CONFIG_IEEE80211N
232 if (type != PLINK_CLOSE &&
233 wpa_s->current_ssid->mesh_ht_mode > CHAN_NO_HT) {
234 buf_len += 2 + 26 + /* HT capabilities */
235 2 + 22; /* HT operation */
237 #endif /* CONFIG_IEEE80211N */
238 buf = wpabuf_alloc(buf_len);
242 cat = wpabuf_mhead_u8(buf);
243 wpabuf_put_u8(buf, WLAN_ACTION_SELF_PROTECTED);
244 wpabuf_put_u8(buf, type);
246 if (type != PLINK_CLOSE) {
249 /* capability info */
250 wpabuf_put_le16(buf, ampe ? IEEE80211_CAP_PRIVACY : 0);
253 if (type == PLINK_CONFIRM)
254 wpabuf_put_le16(buf, sta->peer_lid);
256 /* IE: supp + ext. supp rates */
257 pos = hostapd_eid_supp_rates(bss, supp_rates);
258 pos = hostapd_eid_ext_supp_rates(bss, pos);
259 wpabuf_put_data(buf, supp_rates, pos - supp_rates);
262 wpabuf_put_u8(buf, WLAN_EID_MESH_ID);
263 wpabuf_put_u8(buf, conf->meshid_len);
264 wpabuf_put_data(buf, conf->meshid, conf->meshid_len);
267 wpabuf_put_u8(buf, WLAN_EID_MESH_CONFIG);
268 wpabuf_put_u8(buf, 7);
269 wpabuf_put_u8(buf, conf->mesh_pp_id);
270 wpabuf_put_u8(buf, conf->mesh_pm_id);
271 wpabuf_put_u8(buf, conf->mesh_cc_id);
272 wpabuf_put_u8(buf, conf->mesh_sp_id);
273 wpabuf_put_u8(buf, conf->mesh_auth_id);
274 info = (bss->num_plinks > 63 ? 63 : bss->num_plinks) << 1;
275 /* TODO: Add Connected to Mesh Gate/AS subfields */
276 wpabuf_put_u8(buf, info);
277 /* always forwarding & accepting plinks for now */
278 wpabuf_put_u8(buf, 0x1 | 0x8);
279 } else { /* Peer closing frame */
281 wpabuf_put_u8(buf, WLAN_EID_MESH_ID);
282 wpabuf_put_u8(buf, conf->meshid_len);
283 wpabuf_put_data(buf, conf->meshid, conf->meshid_len);
286 /* IE: Mesh Peering Management element */
300 ie_len += 2; /* reason code */
304 wpabuf_put_u8(buf, WLAN_EID_PEER_MGMT);
305 wpabuf_put_u8(buf, ie_len);
306 /* peering protocol */
308 wpabuf_put_le16(buf, 1);
310 wpabuf_put_le16(buf, 0);
311 wpabuf_put_le16(buf, sta->my_lid);
313 wpabuf_put_le16(buf, sta->peer_lid);
314 if (type == PLINK_CLOSE)
315 wpabuf_put_le16(buf, close_reason);
317 if (sta->sae == NULL) {
318 wpa_msg(wpa_s, MSG_INFO, "Mesh MPM: no SAE session");
321 mesh_rsn_get_pmkid(wpa_s->mesh_rsn, sta,
322 wpabuf_put(buf, PMKID_LEN));
325 #ifdef CONFIG_IEEE80211N
326 if (type != PLINK_CLOSE &&
327 wpa_s->current_ssid->mesh_ht_mode > CHAN_NO_HT) {
328 pos = hostapd_eid_ht_capabilities(bss, ht_capa_oper);
329 pos = hostapd_eid_ht_operation(bss, pos);
330 wpabuf_put_data(buf, ht_capa_oper, pos - ht_capa_oper);
332 #endif /* CONFIG_IEEE80211N */
334 if (ampe && mesh_rsn_protect_frame(wpa_s->mesh_rsn, sta, cat, buf)) {
335 wpa_msg(wpa_s, MSG_INFO,
336 "Mesh MPM: failed to add AMPE and MIC IE");
340 ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
341 sta->addr, wpa_s->own_addr, wpa_s->own_addr,
342 wpabuf_head(buf), wpabuf_len(buf), 0);
344 wpa_msg(wpa_s, MSG_INFO,
345 "Mesh MPM: failed to send peering frame");
352 /* configure peering state in ours and driver's station entry */
354 wpa_mesh_set_plink_state(struct wpa_supplicant *wpa_s, struct sta_info *sta,
355 enum mesh_plink_state state)
357 struct hostapd_sta_add_params params;
360 sta->plink_state = state;
362 os_memset(¶ms, 0, sizeof(params));
363 params.addr = sta->addr;
364 params.plink_state = state;
367 wpa_msg(wpa_s, MSG_DEBUG, "MPM set " MACSTR " into %s",
368 MAC2STR(sta->addr), mplstate[state]);
369 ret = wpa_drv_sta_add(wpa_s, ¶ms);
371 wpa_msg(wpa_s, MSG_ERROR, "Driver failed to set " MACSTR
372 ": %d", MAC2STR(sta->addr), ret);
377 static void mesh_mpm_fsm_restart(struct wpa_supplicant *wpa_s,
378 struct sta_info *sta)
380 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
382 eloop_cancel_timeout(plink_timer, wpa_s, sta);
384 if (sta->mpm_close_reason == WLAN_REASON_MESH_CLOSE_RCVD) {
385 ap_free_sta(hapd, sta);
389 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_LISTEN);
390 sta->my_lid = sta->peer_lid = sta->mpm_close_reason = 0;
391 sta->mpm_retries = 0;
395 static void plink_timer(void *eloop_ctx, void *user_data)
397 struct wpa_supplicant *wpa_s = eloop_ctx;
398 struct sta_info *sta = user_data;
400 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
402 switch (sta->plink_state) {
403 case PLINK_OPEN_RCVD:
404 case PLINK_OPEN_SENT:
406 if (sta->mpm_retries < conf->dot11MeshMaxRetries) {
407 eloop_register_timeout(
408 conf->dot11MeshRetryTimeout / 1000,
409 (conf->dot11MeshRetryTimeout % 1000) * 1000,
410 plink_timer, wpa_s, sta);
411 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_OPEN, 0);
415 reason = WLAN_REASON_MESH_MAX_RETRIES;
416 /* fall through on else */
421 reason = WLAN_REASON_MESH_CONFIRM_TIMEOUT;
422 sta->plink_state = PLINK_HOLDING;
423 eloop_register_timeout(conf->dot11MeshHoldingTimeout / 1000,
424 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
425 plink_timer, wpa_s, sta);
426 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CLOSE, reason);
430 mesh_mpm_fsm_restart(wpa_s, sta);
438 /* initiate peering with station */
440 mesh_mpm_plink_open(struct wpa_supplicant *wpa_s, struct sta_info *sta,
441 enum mesh_plink_state next_state)
443 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
445 eloop_cancel_timeout(plink_timer, wpa_s, sta);
446 eloop_register_timeout(conf->dot11MeshRetryTimeout / 1000,
447 (conf->dot11MeshRetryTimeout % 1000) * 1000,
448 plink_timer, wpa_s, sta);
449 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_OPEN, 0);
450 wpa_mesh_set_plink_state(wpa_s, sta, next_state);
454 int mesh_mpm_plink_close(struct hostapd_data *hapd,
455 struct sta_info *sta, void *ctx)
457 struct wpa_supplicant *wpa_s = ctx;
458 int reason = WLAN_REASON_MESH_PEERING_CANCELLED;
461 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
462 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CLOSE, reason);
463 wpa_printf(MSG_DEBUG, "MPM closing plink sta=" MACSTR,
465 eloop_cancel_timeout(plink_timer, wpa_s, sta);
473 void mesh_mpm_deinit(struct wpa_supplicant *wpa_s, struct hostapd_iface *ifmsh)
475 struct hostapd_data *hapd = ifmsh->bss[0];
477 /* notify peers we're leaving */
478 ap_for_each_sta(hapd, mesh_mpm_plink_close, wpa_s);
480 hapd->num_plinks = 0;
481 hostapd_free_stas(hapd);
485 /* for mesh_rsn to indicate this peer has completed authentication, and we're
486 * ready to start AMPE */
487 void mesh_mpm_auth_peer(struct wpa_supplicant *wpa_s, const u8 *addr)
489 struct hostapd_data *data = wpa_s->ifmsh->bss[0];
490 struct hostapd_sta_add_params params;
491 struct sta_info *sta;
494 sta = ap_get_sta(data, addr);
496 wpa_msg(wpa_s, MSG_DEBUG, "no such mesh peer");
500 /* TODO: Should do nothing if this STA is already authenticated, but
501 * the AP code already sets this flag. */
502 sta->flags |= WLAN_STA_AUTH;
504 mesh_rsn_init_ampe_sta(wpa_s, sta);
506 os_memset(¶ms, 0, sizeof(params));
507 params.addr = sta->addr;
508 params.flags = WPA_STA_AUTHENTICATED | WPA_STA_AUTHORIZED;
511 wpa_msg(wpa_s, MSG_DEBUG, "MPM authenticating " MACSTR,
513 ret = wpa_drv_sta_add(wpa_s, ¶ms);
515 wpa_msg(wpa_s, MSG_ERROR,
516 "Driver failed to set " MACSTR ": %d",
517 MAC2STR(sta->addr), ret);
521 mesh_mpm_init_link(wpa_s, sta);
523 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPEN_SENT);
527 void wpa_mesh_new_mesh_peer(struct wpa_supplicant *wpa_s, const u8 *addr,
528 struct ieee802_11_elems *elems)
530 struct hostapd_sta_add_params params;
531 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
532 struct hostapd_data *data = wpa_s->ifmsh->bss[0];
533 struct sta_info *sta;
534 struct wpa_ssid *ssid = wpa_s->current_ssid;
537 sta = ap_get_sta(data, addr);
539 sta = ap_sta_add(data, addr);
545 if (copy_supp_rates(wpa_s, sta, elems))
548 mesh_mpm_init_link(wpa_s, sta);
550 #ifdef CONFIG_IEEE80211N
551 copy_sta_ht_capab(data, sta, elems->ht_capabilities,
552 elems->ht_capabilities_len);
553 update_ht_state(data, sta);
554 #endif /* CONFIG_IEEE80211N */
556 /* insert into driver */
557 os_memset(¶ms, 0, sizeof(params));
558 params.supp_rates = sta->supported_rates;
559 params.supp_rates_len = sta->supported_rates_len;
561 params.plink_state = sta->plink_state;
562 params.aid = sta->peer_lid;
563 params.listen_interval = 100;
564 params.ht_capabilities = sta->ht_capabilities;
565 params.flags |= WPA_STA_WMM;
566 params.flags_mask |= WPA_STA_AUTHENTICATED;
567 if (conf->security == MESH_CONF_SEC_NONE) {
568 params.flags |= WPA_STA_AUTHORIZED;
569 params.flags |= WPA_STA_AUTHENTICATED;
571 sta->flags |= WLAN_STA_MFP;
572 params.flags |= WPA_STA_MFP;
575 ret = wpa_drv_sta_add(wpa_s, ¶ms);
577 wpa_msg(wpa_s, MSG_ERROR,
578 "Driver failed to insert " MACSTR ": %d",
583 if (ssid && ssid->no_auto_peer) {
584 wpa_msg(wpa_s, MSG_INFO, "will not initiate new peer link with "
585 MACSTR " because of no_auto_peer", MAC2STR(addr));
589 if (conf->security == MESH_CONF_SEC_NONE)
590 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPEN_SENT);
592 mesh_rsn_auth_sae_sta(wpa_s, sta);
596 void mesh_mpm_mgmt_rx(struct wpa_supplicant *wpa_s, struct rx_mgmt *rx_mgmt)
598 struct hostapd_frame_info fi;
600 os_memset(&fi, 0, sizeof(fi));
601 fi.datarate = rx_mgmt->datarate;
602 fi.ssi_signal = rx_mgmt->ssi_signal;
603 ieee802_11_mgmt(wpa_s->ifmsh->bss[0], rx_mgmt->frame,
604 rx_mgmt->frame_len, &fi);
608 static void mesh_mpm_plink_estab(struct wpa_supplicant *wpa_s,
609 struct sta_info *sta)
611 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
612 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
615 wpa_msg(wpa_s, MSG_INFO, "mesh plink with " MACSTR " established",
618 if (conf->security & MESH_CONF_SEC_AMPE) {
619 wpa_drv_set_key(wpa_s, WPA_ALG_CCMP, sta->addr, 0, 0,
620 seq, sizeof(seq), sta->mtk, sizeof(sta->mtk));
621 wpa_drv_set_key(wpa_s, WPA_ALG_CCMP, sta->addr, 1, 0,
623 sta->mgtk, sizeof(sta->mgtk));
624 wpa_drv_set_key(wpa_s, WPA_ALG_IGTK, sta->addr, 4, 0,
626 sta->mgtk, sizeof(sta->mgtk));
628 wpa_hexdump_key(MSG_DEBUG, "mtk:", sta->mtk, sizeof(sta->mtk));
629 wpa_hexdump_key(MSG_DEBUG, "mgtk:",
630 sta->mgtk, sizeof(sta->mgtk));
633 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_ESTAB);
636 sta->flags |= WLAN_STA_ASSOC;
638 eloop_cancel_timeout(plink_timer, wpa_s, sta);
640 /* Send ctrl event */
641 wpa_msg_ctrl(wpa_s, MSG_INFO, MESH_PEER_CONNECTED MACSTR,
646 static void mesh_mpm_fsm(struct wpa_supplicant *wpa_s, struct sta_info *sta,
647 enum plink_event event)
649 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
650 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
653 wpa_msg(wpa_s, MSG_DEBUG, "MPM " MACSTR " state %s event %s",
654 MAC2STR(sta->addr), mplstate[sta->plink_state],
657 switch (sta->plink_state) {
661 mesh_mpm_fsm_restart(wpa_s, sta);
664 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPEN_RCVD);
665 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CONFIRM,
672 case PLINK_OPEN_SENT:
676 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
679 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
681 reason = WLAN_REASON_MESH_CLOSE_RCVD;
682 eloop_register_timeout(
683 conf->dot11MeshHoldingTimeout / 1000,
684 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
685 plink_timer, wpa_s, sta);
686 mesh_mpm_send_plink_action(wpa_s, sta,
687 PLINK_CLOSE, reason);
690 /* retry timer is left untouched */
691 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_OPEN_RCVD);
692 mesh_mpm_send_plink_action(wpa_s, sta,
696 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_CNF_RCVD);
697 eloop_register_timeout(
698 conf->dot11MeshConfirmTimeout / 1000,
699 (conf->dot11MeshConfirmTimeout % 1000) * 1000,
700 plink_timer, wpa_s, sta);
706 case PLINK_OPEN_RCVD:
710 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
713 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
715 reason = WLAN_REASON_MESH_CLOSE_RCVD;
716 eloop_register_timeout(
717 conf->dot11MeshHoldingTimeout / 1000,
718 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
719 plink_timer, wpa_s, sta);
720 sta->mpm_close_reason = reason;
721 mesh_mpm_send_plink_action(wpa_s, sta,
722 PLINK_CLOSE, reason);
725 mesh_mpm_send_plink_action(wpa_s, sta,
729 if (conf->security & MESH_CONF_SEC_AMPE)
730 mesh_rsn_derive_mtk(wpa_s, sta);
731 mesh_mpm_plink_estab(wpa_s, sta);
741 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
744 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
746 reason = WLAN_REASON_MESH_CLOSE_RCVD;
747 eloop_register_timeout(
748 conf->dot11MeshHoldingTimeout / 1000,
749 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
750 plink_timer, wpa_s, sta);
751 sta->mpm_close_reason = reason;
752 mesh_mpm_send_plink_action(wpa_s, sta,
753 PLINK_CLOSE, reason);
756 mesh_mpm_plink_estab(wpa_s, sta);
757 mesh_mpm_send_plink_action(wpa_s, sta,
767 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
768 reason = WLAN_REASON_MESH_CLOSE_RCVD;
770 eloop_register_timeout(
771 conf->dot11MeshHoldingTimeout / 1000,
772 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
773 plink_timer, wpa_s, sta);
774 sta->mpm_close_reason = reason;
776 wpa_msg(wpa_s, MSG_INFO, "mesh plink with " MACSTR
777 " closed with reason %d",
778 MAC2STR(sta->addr), reason);
780 wpa_msg_ctrl(wpa_s, MSG_INFO,
781 MESH_PEER_DISCONNECTED MACSTR,
786 mesh_mpm_send_plink_action(wpa_s, sta,
787 PLINK_CLOSE, reason);
790 mesh_mpm_send_plink_action(wpa_s, sta,
800 mesh_mpm_fsm_restart(wpa_s, sta);
806 reason = sta->mpm_close_reason;
807 mesh_mpm_send_plink_action(wpa_s, sta,
808 PLINK_CLOSE, reason);
815 wpa_msg(wpa_s, MSG_DEBUG,
816 "Unsupported MPM event %s for state %s",
817 mplevent[event], mplstate[sta->plink_state]);
823 void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
824 const struct ieee80211_mgmt *mgmt, size_t len)
827 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
828 struct mesh_conf *mconf = wpa_s->ifmsh->mconf;
829 struct sta_info *sta;
830 u16 plid = 0, llid = 0;
831 enum plink_event event;
832 struct ieee802_11_elems elems;
833 struct mesh_peer_mgmt_ie peer_mgmt_ie;
838 if (mgmt->u.action.category != WLAN_ACTION_SELF_PROTECTED)
841 action_field = mgmt->u.action.u.slf_prot_action.action;
842 if (action_field != PLINK_OPEN &&
843 action_field != PLINK_CONFIRM &&
844 action_field != PLINK_CLOSE)
847 ies = mgmt->u.action.u.slf_prot_action.variable;
848 ie_len = (const u8 *) mgmt + len -
849 mgmt->u.action.u.slf_prot_action.variable;
851 /* at least expect mesh id and peering mgmt */
852 if (ie_len < 2 + 2) {
853 wpa_printf(MSG_DEBUG,
854 "MPM: Ignore too short action frame %u ie_len %u",
855 action_field, (unsigned int) ie_len);
858 wpa_printf(MSG_DEBUG, "MPM: Received PLINK action %u", action_field);
860 if (action_field == PLINK_OPEN || action_field == PLINK_CONFIRM) {
861 wpa_printf(MSG_DEBUG, "MPM: Capability 0x%x",
863 ies += 2; /* capability */
866 if (action_field == PLINK_CONFIRM) {
867 wpa_printf(MSG_DEBUG, "MPM: AID 0x%x", WPA_GET_LE16(ies));
872 /* check for mesh peering, mesh id and mesh config IEs */
873 if (ieee802_11_parse_elems(ies, ie_len, &elems, 0) == ParseFailed) {
874 wpa_printf(MSG_DEBUG, "MPM: Failed to parse PLINK IEs");
877 if (!elems.peer_mgmt) {
878 wpa_printf(MSG_DEBUG,
879 "MPM: No Mesh Peering Management element");
882 if (action_field != PLINK_CLOSE) {
883 if (!elems.mesh_id || !elems.mesh_config) {
884 wpa_printf(MSG_DEBUG,
885 "MPM: No Mesh ID or Mesh Configuration element");
889 if (!matches_local(wpa_s, &elems)) {
890 wpa_printf(MSG_DEBUG,
891 "MPM: Mesh ID or Mesh Configuration element do not match local MBSS");
896 ret = mesh_mpm_parse_peer_mgmt(wpa_s, action_field,
901 wpa_printf(MSG_DEBUG, "MPM: Mesh parsing rejected frame");
905 /* the sender's llid is our plid and vice-versa */
906 plid = WPA_GET_LE16(peer_mgmt_ie.llid);
907 if (peer_mgmt_ie.plid)
908 llid = WPA_GET_LE16(peer_mgmt_ie.plid);
909 wpa_printf(MSG_DEBUG, "MPM: plid=0x%x llid=0x%x", plid, llid);
911 sta = ap_get_sta(hapd, mgmt->sa);
913 wpa_printf(MSG_DEBUG, "MPM: No STA entry for peer");
918 /* peer is in sae_accepted? */
919 if (sta->sae && sta->sae->state != SAE_ACCEPTED) {
920 wpa_printf(MSG_DEBUG, "MPM: SAE not yet accepted for peer");
923 #endif /* CONFIG_SAE */
926 mesh_mpm_init_link(wpa_s, sta);
928 if ((mconf->security & MESH_CONF_SEC_AMPE) &&
929 mesh_rsn_process_ampe(wpa_s, sta, &elems,
930 &mgmt->u.action.category,
932 wpa_printf(MSG_DEBUG, "MPM: RSN process rejected frame");
936 if (sta->plink_state == PLINK_BLOCKED) {
937 wpa_printf(MSG_DEBUG, "MPM: PLINK_BLOCKED");
941 /* Now we will figure out the appropriate event... */
942 switch (action_field) {
944 if (plink_free_count(hapd) == 0) {
947 "MPM: Peer link num over quota(%d)",
949 } else if (sta->peer_lid && sta->peer_lid != plid) {
952 sta->peer_lid = plid;
957 if (plink_free_count(hapd) == 0) {
960 "MPM: Peer link num over quota(%d)",
962 } else if (sta->my_lid != llid ||
963 (sta->peer_lid && sta->peer_lid != plid)) {
967 sta->peer_lid = plid;
972 if (sta->plink_state == PLINK_ESTAB)
973 /* Do not check for llid or plid. This does not
974 * follow the standard but since multiple plinks
975 * per cand are not supported, it is necessary in
976 * order to avoid a livelock when MP A sees an
977 * establish peer link to MP B but MP B does not
978 * see it. This can be caused by a timeout in
979 * B's peer link establishment or B being
983 else if (sta->peer_lid != plid)
985 else if (peer_mgmt_ie.plid && sta->my_lid != llid)
992 * This cannot be hit due to the action_field check above, but
993 * compilers may not be able to figure that out and can warn
994 * about uninitialized event below.
998 mesh_mpm_fsm(wpa_s, sta, event);
1002 /* called by ap_free_sta */
1003 void mesh_mpm_free_sta(struct sta_info *sta)
1005 eloop_cancel_timeout(plink_timer, ELOOP_ALL_CTX, sta);
1006 eloop_cancel_timeout(mesh_auth_timer, ELOOP_ALL_CTX, sta);