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];
217 u8 ie_len
, add_plid
= 0;
219 int ampe
= conf
->security
& MESH_CONF_SEC_AMPE
;
224 buf
= wpabuf_alloc(2 + /* capability info */
226 2 + 8 + /* supported rates */
228 2 + 32 + /* mesh ID */
229 2 + 7 + /* mesh config */
230 2 + 26 + /* HT capabilities */
231 2 + 22 + /* HT operation */
232 2 + 23 + /* peering management */
238 cat
= wpabuf_mhead_u8(buf
);
239 wpabuf_put_u8(buf
, WLAN_ACTION_SELF_PROTECTED
);
240 wpabuf_put_u8(buf
, type
);
242 if (type
!= PLINK_CLOSE
) {
243 /* capability info */
244 wpabuf_put_le16(buf
, ampe
? IEEE80211_CAP_PRIVACY
: 0);
246 if (type
== PLINK_CONFIRM
)
247 wpabuf_put_le16(buf
, sta
->peer_lid
);
249 /* IE: supp + ext. supp rates */
250 pos
= hostapd_eid_supp_rates(bss
, supp_rates
);
251 pos
= hostapd_eid_ext_supp_rates(bss
, pos
);
252 wpabuf_put_data(buf
, supp_rates
, pos
- supp_rates
);
255 wpabuf_put_u8(buf
, WLAN_EID_MESH_ID
);
256 wpabuf_put_u8(buf
, conf
->meshid_len
);
257 wpabuf_put_data(buf
, conf
->meshid
, conf
->meshid_len
);
260 wpabuf_put_u8(buf
, WLAN_EID_MESH_CONFIG
);
261 wpabuf_put_u8(buf
, 7);
262 wpabuf_put_u8(buf
, conf
->mesh_pp_id
);
263 wpabuf_put_u8(buf
, conf
->mesh_pm_id
);
264 wpabuf_put_u8(buf
, conf
->mesh_cc_id
);
265 wpabuf_put_u8(buf
, conf
->mesh_sp_id
);
266 wpabuf_put_u8(buf
, conf
->mesh_auth_id
);
267 /* TODO: formation info */
268 wpabuf_put_u8(buf
, 0);
269 /* always forwarding & accepting plinks for now */
270 wpabuf_put_u8(buf
, 0x1 | 0x8);
271 } else { /* Peer closing frame */
273 wpabuf_put_u8(buf
, WLAN_EID_MESH_ID
);
274 wpabuf_put_u8(buf
, conf
->meshid_len
);
275 wpabuf_put_data(buf
, conf
->meshid
, conf
->meshid_len
);
278 /* IE: Mesh Peering Management element */
292 ie_len
+= 2; /* reason code */
296 wpabuf_put_u8(buf
, WLAN_EID_PEER_MGMT
);
297 wpabuf_put_u8(buf
, ie_len
);
298 /* peering protocol */
300 wpabuf_put_le16(buf
, 1);
302 wpabuf_put_le16(buf
, 0);
303 wpabuf_put_le16(buf
, sta
->my_lid
);
305 wpabuf_put_le16(buf
, sta
->peer_lid
);
306 if (type
== PLINK_CLOSE
)
307 wpabuf_put_le16(buf
, close_reason
);
309 mesh_rsn_get_pmkid(wpa_s
->mesh_rsn
, sta
,
310 wpabuf_put(buf
, PMKID_LEN
));
314 if (ampe
&& mesh_rsn_protect_frame(wpa_s
->mesh_rsn
, sta
, cat
, buf
)) {
315 wpa_msg(wpa_s
, MSG_INFO
,
316 "Mesh MPM: failed to add AMPE and MIC IE");
320 ret
= wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0,
321 sta
->addr
, wpa_s
->own_addr
, wpa_s
->own_addr
,
322 wpabuf_head(buf
), wpabuf_len(buf
), 0);
324 wpa_msg(wpa_s
, MSG_INFO
,
325 "Mesh MPM: failed to send peering frame");
332 /* configure peering state in ours and driver's station entry */
334 wpa_mesh_set_plink_state(struct wpa_supplicant
*wpa_s
, struct sta_info
*sta
,
335 enum mesh_plink_state state
)
337 struct hostapd_sta_add_params params
;
340 sta
->plink_state
= state
;
342 os_memset(¶ms
, 0, sizeof(params
));
343 params
.addr
= sta
->addr
;
344 params
.plink_state
= state
;
347 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM set " MACSTR
" into %s",
348 MAC2STR(sta
->addr
), mplstate
[state
]);
349 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
351 wpa_msg(wpa_s
, MSG_ERROR
, "Driver failed to set " MACSTR
352 ": %d", MAC2STR(sta
->addr
), ret
);
357 static void mesh_mpm_fsm_restart(struct wpa_supplicant
*wpa_s
,
358 struct sta_info
*sta
)
360 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
362 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
364 if (sta
->mpm_close_reason
== WLAN_REASON_MESH_CLOSE_RCVD
) {
365 ap_free_sta(hapd
, sta
);
369 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_LISTEN
);
370 sta
->my_lid
= sta
->peer_lid
= sta
->mpm_close_reason
= 0;
371 sta
->mpm_retries
= 0;
375 static void plink_timer(void *eloop_ctx
, void *user_data
)
377 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
378 struct sta_info
*sta
= user_data
;
381 switch (sta
->plink_state
) {
382 case PLINK_OPEN_RCVD
:
383 case PLINK_OPEN_SENT
:
385 if (sta
->mpm_retries
< dot11MeshMaxRetries
) {
386 eloop_register_timeout(dot11MeshRetryTimeout
, 0,
387 plink_timer
, wpa_s
, sta
);
388 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_OPEN
, 0);
392 reason
= WLAN_REASON_MESH_MAX_RETRIES
;
393 /* fall through on else */
398 reason
= WLAN_REASON_MESH_CONFIRM_TIMEOUT
;
399 sta
->plink_state
= PLINK_HOLDING
;
400 eloop_register_timeout(dot11MeshHoldingTimeout
, 0,
401 plink_timer
, wpa_s
, sta
);
402 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CLOSE
, reason
);
406 mesh_mpm_fsm_restart(wpa_s
, sta
);
414 /* initiate peering with station */
416 mesh_mpm_plink_open(struct wpa_supplicant
*wpa_s
, struct sta_info
*sta
,
417 enum mesh_plink_state next_state
)
419 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
420 eloop_register_timeout(dot11MeshRetryTimeout
, 0, plink_timer
,
422 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_OPEN
, 0);
423 wpa_mesh_set_plink_state(wpa_s
, sta
, next_state
);
427 int mesh_mpm_plink_close(struct hostapd_data
*hapd
,
428 struct sta_info
*sta
, void *ctx
)
430 struct wpa_supplicant
*wpa_s
= ctx
;
431 int reason
= WLAN_REASON_MESH_PEERING_CANCELLED
;
434 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
435 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CLOSE
, reason
);
436 wpa_printf(MSG_DEBUG
, "MPM closing plink sta=" MACSTR
,
438 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
446 void mesh_mpm_deinit(struct wpa_supplicant
*wpa_s
, struct hostapd_iface
*ifmsh
)
448 struct hostapd_data
*hapd
= ifmsh
->bss
[0];
450 /* notify peers we're leaving */
451 ap_for_each_sta(hapd
, mesh_mpm_plink_close
, wpa_s
);
453 hapd
->num_plinks
= 0;
454 hostapd_free_stas(hapd
);
458 /* for mesh_rsn to indicate this peer has completed authentication, and we're
459 * ready to start AMPE */
460 void mesh_mpm_auth_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
462 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
463 struct hostapd_sta_add_params params
;
464 struct sta_info
*sta
;
467 sta
= ap_get_sta(data
, addr
);
469 wpa_msg(wpa_s
, MSG_DEBUG
, "no such mesh peer");
473 /* TODO: Should do nothing if this STA is already authenticated, but
474 * the AP code already sets this flag. */
475 sta
->flags
|= WLAN_STA_AUTH
;
477 mesh_rsn_init_ampe_sta(wpa_s
, sta
);
479 os_memset(¶ms
, 0, sizeof(params
));
480 params
.addr
= sta
->addr
;
481 params
.flags
= WPA_STA_AUTHENTICATED
| WPA_STA_AUTHORIZED
;
484 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM authenticating " MACSTR
,
486 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
488 wpa_msg(wpa_s
, MSG_ERROR
,
489 "Driver failed to set " MACSTR
": %d",
490 MAC2STR(sta
->addr
), ret
);
494 mesh_mpm_init_link(wpa_s
, sta
);
496 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPEN_SENT
);
500 void wpa_mesh_new_mesh_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
501 struct ieee802_11_elems
*elems
)
503 struct hostapd_sta_add_params params
;
504 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
505 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
506 struct sta_info
*sta
;
507 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
510 sta
= ap_get_sta(data
, addr
);
512 sta
= ap_sta_add(data
, addr
);
518 if (copy_supp_rates(wpa_s
, sta
, elems
))
521 mesh_mpm_init_link(wpa_s
, sta
);
523 /* insert into driver */
524 os_memset(¶ms
, 0, sizeof(params
));
525 params
.supp_rates
= sta
->supported_rates
;
526 params
.supp_rates_len
= sta
->supported_rates_len
;
528 params
.plink_state
= sta
->plink_state
;
529 params
.aid
= sta
->peer_lid
;
530 params
.listen_interval
= 100;
531 /* TODO: HT capabilities */
532 params
.flags
|= WPA_STA_WMM
;
533 params
.flags_mask
|= WPA_STA_AUTHENTICATED
;
534 if (conf
->security
== MESH_CONF_SEC_NONE
) {
535 params
.flags
|= WPA_STA_AUTHORIZED
;
536 params
.flags
|= WPA_STA_AUTHENTICATED
;
538 sta
->flags
|= WLAN_STA_MFP
;
539 params
.flags
|= WPA_STA_MFP
;
542 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
544 wpa_msg(wpa_s
, MSG_ERROR
,
545 "Driver failed to insert " MACSTR
": %d",
550 if (ssid
&& ssid
->no_auto_peer
) {
551 wpa_msg(wpa_s
, MSG_INFO
, "will not initiate new peer link with "
552 MACSTR
" because of no_auto_peer", MAC2STR(addr
));
556 if (conf
->security
== MESH_CONF_SEC_NONE
)
557 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPEN_SENT
);
559 mesh_rsn_auth_sae_sta(wpa_s
, sta
);
563 void mesh_mpm_mgmt_rx(struct wpa_supplicant
*wpa_s
, struct rx_mgmt
*rx_mgmt
)
565 struct hostapd_frame_info fi
;
567 os_memset(&fi
, 0, sizeof(fi
));
568 fi
.datarate
= rx_mgmt
->datarate
;
569 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
570 ieee802_11_mgmt(wpa_s
->ifmsh
->bss
[0], rx_mgmt
->frame
,
571 rx_mgmt
->frame_len
, &fi
);
575 static void mesh_mpm_plink_estab(struct wpa_supplicant
*wpa_s
,
576 struct sta_info
*sta
)
578 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
579 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
582 wpa_msg(wpa_s
, MSG_INFO
, "mesh plink with " MACSTR
" established",
585 if (conf
->security
& MESH_CONF_SEC_AMPE
) {
586 wpa_drv_set_key(wpa_s
, WPA_ALG_CCMP
, sta
->addr
, 0, 0,
587 seq
, sizeof(seq
), sta
->mtk
, sizeof(sta
->mtk
));
588 wpa_drv_set_key(wpa_s
, WPA_ALG_CCMP
, sta
->addr
, 1, 0,
590 sta
->mgtk
, sizeof(sta
->mgtk
));
591 wpa_drv_set_key(wpa_s
, WPA_ALG_IGTK
, sta
->addr
, 4, 0,
593 sta
->mgtk
, sizeof(sta
->mgtk
));
595 wpa_hexdump_key(MSG_DEBUG
, "mtk:", sta
->mtk
, sizeof(sta
->mtk
));
596 wpa_hexdump_key(MSG_DEBUG
, "mgtk:",
597 sta
->mgtk
, sizeof(sta
->mgtk
));
600 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_ESTAB
);
603 sta
->flags
|= WLAN_STA_ASSOC
;
605 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
607 /* Send ctrl event */
608 wpa_msg_ctrl(wpa_s
, MSG_INFO
, MESH_PEER_CONNECTED MACSTR
,
613 static void mesh_mpm_fsm(struct wpa_supplicant
*wpa_s
, struct sta_info
*sta
,
614 enum plink_event event
)
616 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
617 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
620 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM " MACSTR
" state %s event %s",
621 MAC2STR(sta
->addr
), mplstate
[sta
->plink_state
],
624 switch (sta
->plink_state
) {
628 mesh_mpm_fsm_restart(wpa_s
, sta
);
631 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPEN_RCVD
);
632 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CONFIRM
,
639 case PLINK_OPEN_SENT
:
643 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
646 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
648 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
649 eloop_register_timeout(dot11MeshHoldingTimeout
, 0,
650 plink_timer
, wpa_s
, sta
);
651 mesh_mpm_send_plink_action(wpa_s
, sta
,
652 PLINK_CLOSE
, reason
);
655 /* retry timer is left untouched */
656 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_OPEN_RCVD
);
657 mesh_mpm_send_plink_action(wpa_s
, sta
,
661 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_CNF_RCVD
);
662 eloop_register_timeout(dot11MeshConfirmTimeout
, 0,
663 plink_timer
, wpa_s
, sta
);
669 case PLINK_OPEN_RCVD
:
673 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
676 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
678 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
679 eloop_register_timeout(dot11MeshHoldingTimeout
, 0,
680 plink_timer
, wpa_s
, sta
);
681 sta
->mpm_close_reason
= reason
;
682 mesh_mpm_send_plink_action(wpa_s
, sta
,
683 PLINK_CLOSE
, reason
);
686 mesh_mpm_send_plink_action(wpa_s
, sta
,
690 if (conf
->security
& MESH_CONF_SEC_AMPE
)
691 mesh_rsn_derive_mtk(wpa_s
, sta
);
692 mesh_mpm_plink_estab(wpa_s
, sta
);
702 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
705 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
707 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
708 eloop_register_timeout(dot11MeshHoldingTimeout
, 0,
709 plink_timer
, wpa_s
, sta
);
710 sta
->mpm_close_reason
= reason
;
711 mesh_mpm_send_plink_action(wpa_s
, sta
,
712 PLINK_CLOSE
, reason
);
715 mesh_mpm_plink_estab(wpa_s
, sta
);
716 mesh_mpm_send_plink_action(wpa_s
, sta
,
726 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
727 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
729 eloop_register_timeout(dot11MeshHoldingTimeout
, 0,
730 plink_timer
, wpa_s
, sta
);
731 sta
->mpm_close_reason
= reason
;
733 wpa_msg(wpa_s
, MSG_INFO
, "mesh plink with " MACSTR
734 " closed with reason %d",
735 MAC2STR(sta
->addr
), reason
);
737 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
738 MESH_PEER_DISCONNECTED MACSTR
,
743 mesh_mpm_send_plink_action(wpa_s
, sta
,
744 PLINK_CLOSE
, reason
);
747 mesh_mpm_send_plink_action(wpa_s
, sta
,
757 mesh_mpm_fsm_restart(wpa_s
, sta
);
763 reason
= sta
->mpm_close_reason
;
764 mesh_mpm_send_plink_action(wpa_s
, sta
,
765 PLINK_CLOSE
, reason
);
772 wpa_msg(wpa_s
, MSG_DEBUG
,
773 "Unsupported MPM event %s for state %s",
774 mplevent
[event
], mplstate
[sta
->plink_state
]);
780 void mesh_mpm_action_rx(struct wpa_supplicant
*wpa_s
,
781 const struct ieee80211_mgmt
*mgmt
, size_t len
)
784 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
785 struct mesh_conf
*mconf
= wpa_s
->ifmsh
->mconf
;
786 struct sta_info
*sta
;
787 u16 plid
= 0, llid
= 0;
788 enum plink_event event
;
789 struct ieee802_11_elems elems
;
790 struct mesh_peer_mgmt_ie peer_mgmt_ie
;
795 if (mgmt
->u
.action
.category
!= WLAN_ACTION_SELF_PROTECTED
)
798 action_field
= mgmt
->u
.action
.u
.slf_prot_action
.action
;
800 ies
= mgmt
->u
.action
.u
.slf_prot_action
.variable
;
801 ie_len
= (const u8
*) mgmt
+ len
-
802 mgmt
->u
.action
.u
.slf_prot_action
.variable
;
804 /* at least expect mesh id and peering mgmt */
808 if (action_field
== PLINK_OPEN
|| action_field
== PLINK_CONFIRM
) {
809 ies
+= 2; /* capability */
812 if (action_field
== PLINK_CONFIRM
) {
817 /* check for mesh peering, mesh id and mesh config IEs */
818 if (ieee802_11_parse_elems(ies
, ie_len
, &elems
, 0) == ParseFailed
)
820 if (!elems
.peer_mgmt
)
822 if ((action_field
!= PLINK_CLOSE
) &&
823 (!elems
.mesh_id
|| !elems
.mesh_config
))
826 if (action_field
!= PLINK_CLOSE
&& !matches_local(wpa_s
, &elems
))
829 ret
= mesh_mpm_parse_peer_mgmt(wpa_s
, action_field
,
836 /* the sender's llid is our plid and vice-versa */
837 plid
= WPA_GET_LE16(peer_mgmt_ie
.llid
);
838 if (peer_mgmt_ie
.plid
)
839 llid
= WPA_GET_LE16(peer_mgmt_ie
.plid
);
841 sta
= ap_get_sta(hapd
, mgmt
->sa
);
846 /* peer is in sae_accepted? */
847 if (sta
->sae
&& sta
->sae
->state
!= SAE_ACCEPTED
)
849 #endif /* CONFIG_SAE */
852 mesh_mpm_init_link(wpa_s
, sta
);
854 if (mconf
->security
& MESH_CONF_SEC_AMPE
)
855 if (mesh_rsn_process_ampe(wpa_s
, sta
, &elems
,
856 &mgmt
->u
.action
.category
,
860 if (sta
->plink_state
== PLINK_BLOCKED
)
863 /* Now we will figure out the appropriate event... */
864 switch (action_field
) {
866 if (!plink_free_count(hapd
) ||
867 (sta
->peer_lid
&& sta
->peer_lid
!= plid
)) {
870 sta
->peer_lid
= plid
;
875 if (!plink_free_count(hapd
) ||
876 sta
->my_lid
!= llid
||
877 (sta
->peer_lid
&& sta
->peer_lid
!= plid
)) {
881 sta
->peer_lid
= plid
;
886 if (sta
->plink_state
== PLINK_ESTAB
)
887 /* Do not check for llid or plid. This does not
888 * follow the standard but since multiple plinks
889 * per cand are not supported, it is necessary in
890 * order to avoid a livelock when MP A sees an
891 * establish peer link to MP B but MP B does not
892 * see it. This can be caused by a timeout in
893 * B's peer link establishment or B being
897 else if (sta
->peer_lid
!= plid
)
899 else if (peer_mgmt_ie
.plid
&& sta
->my_lid
!= llid
)
905 wpa_msg(wpa_s
, MSG_ERROR
,
906 "Mesh plink: unknown frame subtype");
909 mesh_mpm_fsm(wpa_s
, sta
, event
);
913 /* called by ap_free_sta */
914 void mesh_mpm_free_sta(struct sta_info
*sta
)
916 eloop_cancel_timeout(plink_timer
, ELOOP_ALL_CTX
, sta
);
917 eloop_cancel_timeout(mesh_auth_timer
, ELOOP_ALL_CTX
, sta
);