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));
198 * We do not use wpa_mesh_set_plink_state() here because there is no
199 * entry in kernel yet.
201 sta->plink_state = PLINK_LISTEN;
205 static void mesh_mpm_send_plink_action(struct wpa_supplicant *wpa_s,
206 struct sta_info *sta,
207 enum plink_action_field type,
211 struct hostapd_iface *ifmsh = wpa_s->ifmsh;
212 struct hostapd_data *bss = ifmsh->bss[0];
213 struct mesh_conf *conf = ifmsh->mconf;
214 u8 supp_rates[2 + 2 + 32];
215 #ifdef CONFIG_IEEE80211N
216 u8 ht_capa_oper[2 + 26 + 2 + 22];
217 #endif /* CONFIG_IEEE80211N */
219 u8 ie_len, add_plid = 0;
221 int ampe = conf->security & MESH_CONF_SEC_AMPE;
227 buf_len = 2 + /* capability info */
229 2 + 8 + /* supported rates */
231 2 + 32 + /* mesh ID */
232 2 + 7 + /* mesh config */
233 2 + 23 + /* peering management */
236 #ifdef CONFIG_IEEE80211N
237 if (type != PLINK_CLOSE && wpa_s->mesh_ht_enabled) {
238 buf_len += 2 + 26 + /* HT capabilities */
239 2 + 22; /* HT operation */
241 #endif /* CONFIG_IEEE80211N */
242 if (type != PLINK_CLOSE)
243 buf_len += conf->rsn_ie_len; /* RSN IE */
245 buf = wpabuf_alloc(buf_len);
249 cat = wpabuf_mhead_u8(buf);
250 wpabuf_put_u8(buf, WLAN_ACTION_SELF_PROTECTED);
251 wpabuf_put_u8(buf, type);
253 if (type != PLINK_CLOSE) {
256 /* capability info */
257 wpabuf_put_le16(buf, ampe ? IEEE80211_CAP_PRIVACY : 0);
260 if (type == PLINK_CONFIRM)
261 wpabuf_put_le16(buf, sta->aid);
263 /* IE: supp + ext. supp rates */
264 pos = hostapd_eid_supp_rates(bss, supp_rates);
265 pos = hostapd_eid_ext_supp_rates(bss, pos);
266 wpabuf_put_data(buf, supp_rates, pos - supp_rates);
269 wpabuf_put_data(buf, conf->rsn_ie, conf->rsn_ie_len);
272 wpabuf_put_u8(buf, WLAN_EID_MESH_ID);
273 wpabuf_put_u8(buf, conf->meshid_len);
274 wpabuf_put_data(buf, conf->meshid, conf->meshid_len);
277 wpabuf_put_u8(buf, WLAN_EID_MESH_CONFIG);
278 wpabuf_put_u8(buf, 7);
279 wpabuf_put_u8(buf, conf->mesh_pp_id);
280 wpabuf_put_u8(buf, conf->mesh_pm_id);
281 wpabuf_put_u8(buf, conf->mesh_cc_id);
282 wpabuf_put_u8(buf, conf->mesh_sp_id);
283 wpabuf_put_u8(buf, conf->mesh_auth_id);
284 info = (bss->num_plinks > 63 ? 63 : bss->num_plinks) << 1;
285 /* TODO: Add Connected to Mesh Gate/AS subfields */
286 wpabuf_put_u8(buf, info);
287 /* always forwarding & accepting plinks for now */
288 wpabuf_put_u8(buf, 0x1 | 0x8);
289 } else { /* Peer closing frame */
291 wpabuf_put_u8(buf, WLAN_EID_MESH_ID);
292 wpabuf_put_u8(buf, conf->meshid_len);
293 wpabuf_put_data(buf, conf->meshid, conf->meshid_len);
296 /* IE: Mesh Peering Management element */
310 ie_len += 2; /* reason code */
314 wpabuf_put_u8(buf, WLAN_EID_PEER_MGMT);
315 wpabuf_put_u8(buf, ie_len);
316 /* peering protocol */
318 wpabuf_put_le16(buf, 1);
320 wpabuf_put_le16(buf, 0);
321 wpabuf_put_le16(buf, sta->my_lid);
323 wpabuf_put_le16(buf, sta->peer_lid);
324 if (type == PLINK_CLOSE)
325 wpabuf_put_le16(buf, close_reason);
327 if (sta->sae == NULL) {
328 wpa_msg(wpa_s, MSG_INFO, "Mesh MPM: no SAE session");
331 mesh_rsn_get_pmkid(wpa_s->mesh_rsn, sta,
332 wpabuf_put(buf, PMKID_LEN));
335 #ifdef CONFIG_IEEE80211N
336 if (type != PLINK_CLOSE && wpa_s->mesh_ht_enabled) {
337 pos = hostapd_eid_ht_capabilities(bss, ht_capa_oper);
338 pos = hostapd_eid_ht_operation(bss, pos);
339 wpabuf_put_data(buf, ht_capa_oper, pos - ht_capa_oper);
341 #endif /* CONFIG_IEEE80211N */
343 if (ampe && mesh_rsn_protect_frame(wpa_s->mesh_rsn, sta, cat, buf)) {
344 wpa_msg(wpa_s, MSG_INFO,
345 "Mesh MPM: failed to add AMPE and MIC IE");
349 ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
350 sta->addr, wpa_s->own_addr, wpa_s->own_addr,
351 wpabuf_head(buf), wpabuf_len(buf), 0);
353 wpa_msg(wpa_s, MSG_INFO,
354 "Mesh MPM: failed to send peering frame");
361 /* configure peering state in ours and driver's station entry */
362 void wpa_mesh_set_plink_state(struct wpa_supplicant *wpa_s,
363 struct sta_info *sta,
364 enum mesh_plink_state state)
366 struct hostapd_sta_add_params params;
369 sta->plink_state = state;
371 os_memset(¶ms, 0, sizeof(params));
372 params.addr = sta->addr;
373 params.plink_state = state;
376 wpa_msg(wpa_s, MSG_DEBUG, "MPM set " MACSTR " into %s",
377 MAC2STR(sta->addr), mplstate[state]);
378 ret = wpa_drv_sta_add(wpa_s, ¶ms);
380 wpa_msg(wpa_s, MSG_ERROR, "Driver failed to set " MACSTR
381 ": %d", MAC2STR(sta->addr), ret);
386 static void mesh_mpm_fsm_restart(struct wpa_supplicant *wpa_s,
387 struct sta_info *sta)
389 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
391 eloop_cancel_timeout(plink_timer, wpa_s, sta);
393 ap_free_sta(hapd, sta);
397 static void plink_timer(void *eloop_ctx, void *user_data)
399 struct wpa_supplicant *wpa_s = eloop_ctx;
400 struct sta_info *sta = user_data;
402 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
404 switch (sta->plink_state) {
405 case PLINK_OPEN_RCVD:
406 case PLINK_OPEN_SENT:
408 if (sta->mpm_retries < conf->dot11MeshMaxRetries) {
409 eloop_register_timeout(
410 conf->dot11MeshRetryTimeout / 1000,
411 (conf->dot11MeshRetryTimeout % 1000) * 1000,
412 plink_timer, wpa_s, sta);
413 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_OPEN, 0);
417 reason = WLAN_REASON_MESH_MAX_RETRIES;
418 /* fall through on else */
423 reason = WLAN_REASON_MESH_CONFIRM_TIMEOUT;
424 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
425 eloop_register_timeout(conf->dot11MeshHoldingTimeout / 1000,
426 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
427 plink_timer, wpa_s, sta);
428 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CLOSE, reason);
432 mesh_mpm_fsm_restart(wpa_s, sta);
440 /* initiate peering with station */
442 mesh_mpm_plink_open(struct wpa_supplicant *wpa_s, struct sta_info *sta,
443 enum mesh_plink_state next_state)
445 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
447 eloop_cancel_timeout(plink_timer, wpa_s, sta);
448 eloop_register_timeout(conf->dot11MeshRetryTimeout / 1000,
449 (conf->dot11MeshRetryTimeout % 1000) * 1000,
450 plink_timer, wpa_s, sta);
451 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_OPEN, 0);
452 wpa_mesh_set_plink_state(wpa_s, sta, next_state);
456 int mesh_mpm_plink_close(struct hostapd_data *hapd,
457 struct sta_info *sta, void *ctx)
459 struct wpa_supplicant *wpa_s = ctx;
460 int reason = WLAN_REASON_MESH_PEERING_CANCELLED;
463 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
464 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CLOSE, reason);
465 wpa_printf(MSG_DEBUG, "MPM closing plink sta=" MACSTR,
467 eloop_cancel_timeout(plink_timer, wpa_s, sta);
475 void mesh_mpm_deinit(struct wpa_supplicant *wpa_s, struct hostapd_iface *ifmsh)
477 struct hostapd_data *hapd = ifmsh->bss[0];
479 /* notify peers we're leaving */
480 ap_for_each_sta(hapd, mesh_mpm_plink_close, wpa_s);
482 hapd->num_plinks = 0;
483 hostapd_free_stas(hapd);
487 /* for mesh_rsn to indicate this peer has completed authentication, and we're
488 * ready to start AMPE */
489 void mesh_mpm_auth_peer(struct wpa_supplicant *wpa_s, const u8 *addr)
491 struct hostapd_data *data = wpa_s->ifmsh->bss[0];
492 struct hostapd_sta_add_params params;
493 struct sta_info *sta;
496 sta = ap_get_sta(data, addr);
498 wpa_msg(wpa_s, MSG_DEBUG, "no such mesh peer");
502 /* TODO: Should do nothing if this STA is already authenticated, but
503 * the AP code already sets this flag. */
504 sta->flags |= WLAN_STA_AUTH;
506 mesh_rsn_init_ampe_sta(wpa_s, sta);
508 os_memset(¶ms, 0, sizeof(params));
509 params.addr = sta->addr;
510 params.flags = WPA_STA_AUTHENTICATED | WPA_STA_AUTHORIZED;
513 wpa_msg(wpa_s, MSG_DEBUG, "MPM authenticating " MACSTR,
515 ret = wpa_drv_sta_add(wpa_s, ¶ms);
517 wpa_msg(wpa_s, MSG_ERROR,
518 "Driver failed to set " MACSTR ": %d",
519 MAC2STR(sta->addr), ret);
523 mesh_mpm_init_link(wpa_s, sta);
525 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPEN_SENT);
529 * Initialize a sta_info structure for a peer and upload it into the driver
530 * in preparation for beginning authentication or peering. This is done when a
531 * Beacon (secure or open mesh) or a peering open frame (for open mesh) is
532 * received from the peer for the first time.
534 static struct sta_info * mesh_mpm_add_peer(struct wpa_supplicant *wpa_s,
536 struct ieee802_11_elems *elems)
538 struct hostapd_sta_add_params params;
539 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
540 struct hostapd_data *data = wpa_s->ifmsh->bss[0];
541 struct sta_info *sta;
544 sta = ap_get_sta(data, addr);
546 sta = ap_sta_add(data, addr);
551 /* Set WMM by default since Mesh STAs are QoS STAs */
552 sta->flags |= WLAN_STA_WMM;
555 if (copy_supp_rates(wpa_s, sta, elems)) {
556 ap_free_sta(data, sta);
560 mesh_mpm_init_link(wpa_s, sta);
562 #ifdef CONFIG_IEEE80211N
563 copy_sta_ht_capab(data, sta, elems->ht_capabilities);
564 update_ht_state(data, sta);
565 #endif /* CONFIG_IEEE80211N */
567 if (hostapd_get_aid(data, sta) < 0) {
568 wpa_msg(wpa_s, MSG_ERROR, "No AIDs available");
569 ap_free_sta(data, sta);
573 /* insert into driver */
574 os_memset(¶ms, 0, sizeof(params));
575 params.supp_rates = sta->supported_rates;
576 params.supp_rates_len = sta->supported_rates_len;
578 params.plink_state = sta->plink_state;
579 params.aid = sta->aid;
580 params.listen_interval = 100;
581 params.ht_capabilities = sta->ht_capabilities;
582 params.flags |= WPA_STA_WMM;
583 params.flags_mask |= WPA_STA_AUTHENTICATED;
584 if (conf->security == MESH_CONF_SEC_NONE) {
585 params.flags |= WPA_STA_AUTHORIZED;
586 params.flags |= WPA_STA_AUTHENTICATED;
588 sta->flags |= WLAN_STA_MFP;
589 params.flags |= WPA_STA_MFP;
592 ret = wpa_drv_sta_add(wpa_s, ¶ms);
594 wpa_msg(wpa_s, MSG_ERROR,
595 "Driver failed to insert " MACSTR ": %d",
597 ap_free_sta(data, sta);
605 void wpa_mesh_new_mesh_peer(struct wpa_supplicant *wpa_s, const u8 *addr,
606 struct ieee802_11_elems *elems)
608 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
609 struct hostapd_data *data = wpa_s->ifmsh->bss[0];
610 struct sta_info *sta;
611 struct wpa_ssid *ssid = wpa_s->current_ssid;
613 sta = mesh_mpm_add_peer(wpa_s, addr, elems);
617 if (ssid && ssid->no_auto_peer) {
618 wpa_msg(wpa_s, MSG_INFO, "will not initiate new peer link with "
619 MACSTR " because of no_auto_peer", MAC2STR(addr));
620 if (data->mesh_pending_auth) {
621 struct os_reltime age;
622 const struct ieee80211_mgmt *mgmt;
623 struct hostapd_frame_info fi;
625 mgmt = wpabuf_head(data->mesh_pending_auth);
626 os_reltime_age(&data->mesh_pending_auth_time, &age);
628 os_memcmp(mgmt->sa, addr, ETH_ALEN) == 0) {
629 wpa_printf(MSG_DEBUG,
630 "mesh: Process pending Authentication frame from %u.%06u seconds ago",
631 (unsigned int) age.sec,
632 (unsigned int) age.usec);
633 os_memset(&fi, 0, sizeof(fi));
636 wpabuf_head(data->mesh_pending_auth),
637 wpabuf_len(data->mesh_pending_auth),
640 wpabuf_free(data->mesh_pending_auth);
641 data->mesh_pending_auth = NULL;
646 if (conf->security == MESH_CONF_SEC_NONE)
647 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPEN_SENT);
649 mesh_rsn_auth_sae_sta(wpa_s, sta);
653 void mesh_mpm_mgmt_rx(struct wpa_supplicant *wpa_s, struct rx_mgmt *rx_mgmt)
655 struct hostapd_frame_info fi;
657 os_memset(&fi, 0, sizeof(fi));
658 fi.datarate = rx_mgmt->datarate;
659 fi.ssi_signal = rx_mgmt->ssi_signal;
660 ieee802_11_mgmt(wpa_s->ifmsh->bss[0], rx_mgmt->frame,
661 rx_mgmt->frame_len, &fi);
665 static void mesh_mpm_plink_estab(struct wpa_supplicant *wpa_s,
666 struct sta_info *sta)
668 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
669 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
672 wpa_msg(wpa_s, MSG_INFO, "mesh plink with " MACSTR " established",
675 if (conf->security & MESH_CONF_SEC_AMPE) {
676 wpa_drv_set_key(wpa_s, WPA_ALG_CCMP, sta->addr, 0, 0,
677 seq, sizeof(seq), sta->mtk, sizeof(sta->mtk));
678 wpa_drv_set_key(wpa_s, WPA_ALG_CCMP, sta->addr, 1, 0,
680 sta->mgtk, sizeof(sta->mgtk));
681 wpa_drv_set_key(wpa_s, WPA_ALG_IGTK, sta->addr, 4, 0,
683 sta->mgtk, sizeof(sta->mgtk));
685 wpa_hexdump_key(MSG_DEBUG, "mtk:", sta->mtk, sizeof(sta->mtk));
686 wpa_hexdump_key(MSG_DEBUG, "mgtk:",
687 sta->mgtk, sizeof(sta->mgtk));
690 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_ESTAB);
693 sta->flags |= WLAN_STA_ASSOC;
695 eloop_cancel_timeout(plink_timer, wpa_s, sta);
697 /* Send ctrl event */
698 wpa_msg_ctrl(wpa_s, MSG_INFO, MESH_PEER_CONNECTED MACSTR,
703 static void mesh_mpm_fsm(struct wpa_supplicant *wpa_s, struct sta_info *sta,
704 enum plink_event event)
706 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
707 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
710 wpa_msg(wpa_s, MSG_DEBUG, "MPM " MACSTR " state %s event %s",
711 MAC2STR(sta->addr), mplstate[sta->plink_state],
714 switch (sta->plink_state) {
718 mesh_mpm_fsm_restart(wpa_s, sta);
721 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPEN_RCVD);
722 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CONFIRM,
729 case PLINK_OPEN_SENT:
733 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
736 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
738 reason = WLAN_REASON_MESH_CLOSE_RCVD;
739 eloop_register_timeout(
740 conf->dot11MeshHoldingTimeout / 1000,
741 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
742 plink_timer, wpa_s, sta);
743 mesh_mpm_send_plink_action(wpa_s, sta,
744 PLINK_CLOSE, reason);
747 /* retry timer is left untouched */
748 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_OPEN_RCVD);
749 mesh_mpm_send_plink_action(wpa_s, sta,
753 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_CNF_RCVD);
754 eloop_register_timeout(
755 conf->dot11MeshConfirmTimeout / 1000,
756 (conf->dot11MeshConfirmTimeout % 1000) * 1000,
757 plink_timer, wpa_s, sta);
763 case PLINK_OPEN_RCVD:
767 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
770 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
772 reason = WLAN_REASON_MESH_CLOSE_RCVD;
773 eloop_register_timeout(
774 conf->dot11MeshHoldingTimeout / 1000,
775 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
776 plink_timer, wpa_s, sta);
777 sta->mpm_close_reason = reason;
778 mesh_mpm_send_plink_action(wpa_s, sta,
779 PLINK_CLOSE, reason);
782 mesh_mpm_send_plink_action(wpa_s, sta,
786 if (conf->security & MESH_CONF_SEC_AMPE)
787 mesh_rsn_derive_mtk(wpa_s, sta);
788 mesh_mpm_plink_estab(wpa_s, sta);
798 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
801 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
803 reason = WLAN_REASON_MESH_CLOSE_RCVD;
804 eloop_register_timeout(
805 conf->dot11MeshHoldingTimeout / 1000,
806 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
807 plink_timer, wpa_s, sta);
808 sta->mpm_close_reason = reason;
809 mesh_mpm_send_plink_action(wpa_s, sta,
810 PLINK_CLOSE, reason);
813 mesh_mpm_plink_estab(wpa_s, sta);
814 mesh_mpm_send_plink_action(wpa_s, sta,
824 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
825 reason = WLAN_REASON_MESH_CLOSE_RCVD;
827 eloop_register_timeout(
828 conf->dot11MeshHoldingTimeout / 1000,
829 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
830 plink_timer, wpa_s, sta);
831 sta->mpm_close_reason = reason;
833 wpa_msg(wpa_s, MSG_INFO, "mesh plink with " MACSTR
834 " closed with reason %d",
835 MAC2STR(sta->addr), reason);
837 wpa_msg_ctrl(wpa_s, MSG_INFO,
838 MESH_PEER_DISCONNECTED MACSTR,
843 mesh_mpm_send_plink_action(wpa_s, sta,
844 PLINK_CLOSE, reason);
847 mesh_mpm_send_plink_action(wpa_s, sta,
857 mesh_mpm_fsm_restart(wpa_s, sta);
863 reason = sta->mpm_close_reason;
864 mesh_mpm_send_plink_action(wpa_s, sta,
865 PLINK_CLOSE, reason);
872 wpa_msg(wpa_s, MSG_DEBUG,
873 "Unsupported MPM event %s for state %s",
874 mplevent[event], mplstate[sta->plink_state]);
880 void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
881 const struct ieee80211_mgmt *mgmt, size_t len)
884 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
885 struct mesh_conf *mconf = wpa_s->ifmsh->mconf;
886 struct sta_info *sta;
887 u16 plid = 0, llid = 0;
888 enum plink_event event;
889 struct ieee802_11_elems elems;
890 struct mesh_peer_mgmt_ie peer_mgmt_ie;
895 if (mgmt->u.action.category != WLAN_ACTION_SELF_PROTECTED)
898 action_field = mgmt->u.action.u.slf_prot_action.action;
899 if (action_field != PLINK_OPEN &&
900 action_field != PLINK_CONFIRM &&
901 action_field != PLINK_CLOSE)
904 ies = mgmt->u.action.u.slf_prot_action.variable;
905 ie_len = (const u8 *) mgmt + len -
906 mgmt->u.action.u.slf_prot_action.variable;
908 /* at least expect mesh id and peering mgmt */
909 if (ie_len < 2 + 2) {
910 wpa_printf(MSG_DEBUG,
911 "MPM: Ignore too short action frame %u ie_len %u",
912 action_field, (unsigned int) ie_len);
915 wpa_printf(MSG_DEBUG, "MPM: Received PLINK action %u", action_field);
917 if (action_field == PLINK_OPEN || action_field == PLINK_CONFIRM) {
918 wpa_printf(MSG_DEBUG, "MPM: Capability 0x%x",
920 ies += 2; /* capability */
923 if (action_field == PLINK_CONFIRM) {
924 wpa_printf(MSG_DEBUG, "MPM: AID 0x%x", WPA_GET_LE16(ies));
929 /* check for mesh peering, mesh id and mesh config IEs */
930 if (ieee802_11_parse_elems(ies, ie_len, &elems, 0) == ParseFailed) {
931 wpa_printf(MSG_DEBUG, "MPM: Failed to parse PLINK IEs");
934 if (!elems.peer_mgmt) {
935 wpa_printf(MSG_DEBUG,
936 "MPM: No Mesh Peering Management element");
939 if (action_field != PLINK_CLOSE) {
940 if (!elems.mesh_id || !elems.mesh_config) {
941 wpa_printf(MSG_DEBUG,
942 "MPM: No Mesh ID or Mesh Configuration element");
946 if (!matches_local(wpa_s, &elems)) {
947 wpa_printf(MSG_DEBUG,
948 "MPM: Mesh ID or Mesh Configuration element do not match local MBSS");
953 ret = mesh_mpm_parse_peer_mgmt(wpa_s, action_field,
958 wpa_printf(MSG_DEBUG, "MPM: Mesh parsing rejected frame");
962 /* the sender's llid is our plid and vice-versa */
963 plid = WPA_GET_LE16(peer_mgmt_ie.llid);
964 if (peer_mgmt_ie.plid)
965 llid = WPA_GET_LE16(peer_mgmt_ie.plid);
966 wpa_printf(MSG_DEBUG, "MPM: plid=0x%x llid=0x%x", plid, llid);
968 sta = ap_get_sta(hapd, mgmt->sa);
971 * If this is an open frame from an unknown STA, and this is an
972 * open mesh, then go ahead and add the peer before proceeding.
974 if (!sta && action_field == PLINK_OPEN &&
975 !(mconf->security & MESH_CONF_SEC_AMPE))
976 sta = mesh_mpm_add_peer(wpa_s, mgmt->sa, &elems);
979 wpa_printf(MSG_DEBUG, "MPM: No STA entry for peer");
984 /* peer is in sae_accepted? */
985 if (sta->sae && sta->sae->state != SAE_ACCEPTED) {
986 wpa_printf(MSG_DEBUG, "MPM: SAE not yet accepted for peer");
989 #endif /* CONFIG_SAE */
992 mesh_mpm_init_link(wpa_s, sta);
994 if ((mconf->security & MESH_CONF_SEC_AMPE) &&
995 mesh_rsn_process_ampe(wpa_s, sta, &elems,
996 &mgmt->u.action.category,
998 wpa_printf(MSG_DEBUG, "MPM: RSN process rejected frame");
1002 if (sta->plink_state == PLINK_BLOCKED) {
1003 wpa_printf(MSG_DEBUG, "MPM: PLINK_BLOCKED");
1007 /* Now we will figure out the appropriate event... */
1008 switch (action_field) {
1010 if (plink_free_count(hapd) == 0) {
1012 wpa_printf(MSG_INFO,
1013 "MPM: Peer link num over quota(%d)",
1015 } else if (sta->peer_lid && sta->peer_lid != plid) {
1018 sta->peer_lid = plid;
1023 if (plink_free_count(hapd) == 0) {
1025 wpa_printf(MSG_INFO,
1026 "MPM: Peer link num over quota(%d)",
1028 } else if (sta->my_lid != llid ||
1029 (sta->peer_lid && sta->peer_lid != plid)) {
1033 sta->peer_lid = plid;
1038 if (sta->plink_state == PLINK_ESTAB)
1039 /* Do not check for llid or plid. This does not
1040 * follow the standard but since multiple plinks
1041 * per cand are not supported, it is necessary in
1042 * order to avoid a livelock when MP A sees an
1043 * establish peer link to MP B but MP B does not
1044 * see it. This can be caused by a timeout in
1045 * B's peer link establishment or B being
1049 else if (sta->peer_lid != plid)
1051 else if (peer_mgmt_ie.plid && sta->my_lid != llid)
1058 * This cannot be hit due to the action_field check above, but
1059 * compilers may not be able to figure that out and can warn
1060 * about uninitialized event below.
1064 mesh_mpm_fsm(wpa_s, sta, event);
1068 /* called by ap_free_sta */
1069 void mesh_mpm_free_sta(struct sta_info *sta)
1071 eloop_cancel_timeout(plink_timer, ELOOP_ALL_CTX, sta);
1072 eloop_cancel_timeout(mesh_auth_timer, ELOOP_ALL_CTX, sta);