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
{
23 const u8
*proto_id
; /* Mesh Peering Protocol Identifier (2 octets) */
24 const u8
*llid
; /* Local Link ID (2 octets) */
25 const u8
*plid
; /* Peer Link ID (conditional, 2 octets) */
26 const u8
*reason
; /* Reason Code (conditional, 2 octets) */
27 const u8
*chosen_pmk
; /* Chosen PMK (optional, 16 octets) */
30 static void plink_timer(void *eloop_ctx
, void *user_data
);
45 static const char * const mplstate
[] = {
46 [0] = "UNINITIALIZED",
47 [PLINK_LISTEN
] = "LISTEN",
48 [PLINK_OPEN_SENT
] = "OPEN_SENT",
49 [PLINK_OPEN_RCVD
] = "OPEN_RCVD",
50 [PLINK_CNF_RCVD
] = "CNF_RCVD",
51 [PLINK_ESTAB
] = "ESTAB",
52 [PLINK_HOLDING
] = "HOLDING",
53 [PLINK_BLOCKED
] = "BLOCKED"
56 static const char * const mplevent
[] = {
57 [PLINK_UNDEFINED
] = "UNDEFINED",
58 [OPN_ACPT
] = "OPN_ACPT",
59 [OPN_RJCT
] = "OPN_RJCT",
60 [OPN_IGNR
] = "OPN_IGNR",
61 [CNF_ACPT
] = "CNF_ACPT",
62 [CNF_RJCT
] = "CNF_RJCT",
63 [CNF_IGNR
] = "CNF_IGNR",
64 [CLS_ACPT
] = "CLS_ACPT",
65 [CLS_IGNR
] = "CLS_IGNR"
69 static int mesh_mpm_parse_peer_mgmt(struct wpa_supplicant
*wpa_s
,
71 const u8
*ie
, size_t len
,
72 struct mesh_peer_mgmt_ie
*mpm_ie
)
74 os_memset(mpm_ie
, 0, sizeof(*mpm_ie
));
76 /* Remove optional Chosen PMK field at end */
77 if (len
>= SAE_PMKID_LEN
) {
78 mpm_ie
->chosen_pmk
= ie
+ len
- SAE_PMKID_LEN
;
82 if ((action_field
== PLINK_OPEN
&& len
!= 4) ||
83 (action_field
== PLINK_CONFIRM
&& len
!= 6) ||
84 (action_field
== PLINK_CLOSE
&& len
!= 6 && len
!= 8)) {
85 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM: Invalid peer mgmt ie");
92 mpm_ie
->proto_id
= ie
;
93 mpm_ie
->llid
= ie
+ 2;
97 /* close reason is always present at end for close */
98 if (action_field
== PLINK_CLOSE
) {
101 mpm_ie
->reason
= ie
+ len
- 2;
105 /* Peer Link ID, present for confirm, and possibly close */
113 static int plink_free_count(struct hostapd_data
*hapd
)
115 if (hapd
->max_plinks
> hapd
->num_plinks
)
116 return hapd
->max_plinks
- hapd
->num_plinks
;
121 static u16
copy_supp_rates(struct wpa_supplicant
*wpa_s
,
122 struct sta_info
*sta
,
123 struct ieee802_11_elems
*elems
)
125 if (!elems
->supp_rates
) {
126 wpa_msg(wpa_s
, MSG_ERROR
, "no supported rates from " MACSTR
,
128 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
131 if (elems
->supp_rates_len
+ elems
->ext_supp_rates_len
>
132 sizeof(sta
->supported_rates
)) {
133 wpa_msg(wpa_s
, MSG_ERROR
,
134 "Invalid supported rates element length " MACSTR
135 " %d+%d", MAC2STR(sta
->addr
), elems
->supp_rates_len
,
136 elems
->ext_supp_rates_len
);
137 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
140 sta
->supported_rates_len
= merge_byte_arrays(
141 sta
->supported_rates
, sizeof(sta
->supported_rates
),
142 elems
->supp_rates
, elems
->supp_rates_len
,
143 elems
->ext_supp_rates
, elems
->ext_supp_rates_len
);
145 return WLAN_STATUS_SUCCESS
;
149 /* return true if elems from a neighbor match this MBSS */
150 static Boolean
matches_local(struct wpa_supplicant
*wpa_s
,
151 struct ieee802_11_elems
*elems
)
153 struct mesh_conf
*mconf
= wpa_s
->ifmsh
->mconf
;
155 if (elems
->mesh_config_len
< 5)
158 return (mconf
->meshid_len
== elems
->mesh_id_len
&&
159 os_memcmp(mconf
->meshid
, elems
->mesh_id
,
160 elems
->mesh_id_len
) == 0 &&
161 mconf
->mesh_pp_id
== elems
->mesh_config
[0] &&
162 mconf
->mesh_pm_id
== elems
->mesh_config
[1] &&
163 mconf
->mesh_cc_id
== elems
->mesh_config
[2] &&
164 mconf
->mesh_sp_id
== elems
->mesh_config
[3] &&
165 mconf
->mesh_auth_id
== elems
->mesh_config
[4]);
169 /* check if local link id is already used with another peer */
170 static Boolean
llid_in_use(struct wpa_supplicant
*wpa_s
, u16 llid
)
172 struct sta_info
*sta
;
173 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
175 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
176 if (sta
->my_lid
== llid
)
184 /* generate an llid for a link and set to initial state */
185 static void mesh_mpm_init_link(struct wpa_supplicant
*wpa_s
,
186 struct sta_info
*sta
)
191 if (os_get_random((u8
*) &llid
, sizeof(llid
)) < 0)
193 } while (!llid
|| llid_in_use(wpa_s
, llid
));
199 * We do not use wpa_mesh_set_plink_state() here because there is no
200 * entry in kernel yet.
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
;
225 buf_len
= 2 + /* capability info */
227 2 + 8 + /* supported rates */
229 2 + 32 + /* mesh ID */
230 2 + 7 + /* mesh config */
231 2 + 23 + /* peering management */
234 #ifdef CONFIG_IEEE80211N
235 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_ht_enabled
) {
236 buf_len
+= 2 + 26 + /* HT capabilities */
237 2 + 22; /* HT operation */
239 #endif /* CONFIG_IEEE80211N */
240 #ifdef CONFIG_IEEE80211AC
241 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_vht_enabled
) {
242 buf_len
+= 2 + 12 + /* VHT Capabilities */
243 2 + 5; /* VHT Operation */
245 #endif /* CONFIG_IEEE80211AC */
246 if (type
!= PLINK_CLOSE
)
247 buf_len
+= conf
->rsn_ie_len
; /* RSN IE */
249 buf
= wpabuf_alloc(buf_len
);
253 cat
= wpabuf_mhead_u8(buf
);
254 wpabuf_put_u8(buf
, WLAN_ACTION_SELF_PROTECTED
);
255 wpabuf_put_u8(buf
, type
);
257 if (type
!= PLINK_CLOSE
) {
260 /* capability info */
261 wpabuf_put_le16(buf
, ampe
? IEEE80211_CAP_PRIVACY
: 0);
264 if (type
== PLINK_CONFIRM
)
265 wpabuf_put_le16(buf
, sta
->aid
);
267 /* IE: supp + ext. supp rates */
268 pos
= hostapd_eid_supp_rates(bss
, supp_rates
);
269 pos
= hostapd_eid_ext_supp_rates(bss
, pos
);
270 wpabuf_put_data(buf
, supp_rates
, pos
- supp_rates
);
273 wpabuf_put_data(buf
, conf
->rsn_ie
, conf
->rsn_ie_len
);
276 wpabuf_put_u8(buf
, WLAN_EID_MESH_ID
);
277 wpabuf_put_u8(buf
, conf
->meshid_len
);
278 wpabuf_put_data(buf
, conf
->meshid
, conf
->meshid_len
);
281 wpabuf_put_u8(buf
, WLAN_EID_MESH_CONFIG
);
282 wpabuf_put_u8(buf
, 7);
283 wpabuf_put_u8(buf
, conf
->mesh_pp_id
);
284 wpabuf_put_u8(buf
, conf
->mesh_pm_id
);
285 wpabuf_put_u8(buf
, conf
->mesh_cc_id
);
286 wpabuf_put_u8(buf
, conf
->mesh_sp_id
);
287 wpabuf_put_u8(buf
, conf
->mesh_auth_id
);
288 info
= (bss
->num_plinks
> 63 ? 63 : bss
->num_plinks
) << 1;
289 /* TODO: Add Connected to Mesh Gate/AS subfields */
290 wpabuf_put_u8(buf
, info
);
291 /* always forwarding & accepting plinks for now */
292 wpabuf_put_u8(buf
, 0x1 | 0x8);
293 } else { /* Peer closing frame */
295 wpabuf_put_u8(buf
, WLAN_EID_MESH_ID
);
296 wpabuf_put_u8(buf
, conf
->meshid_len
);
297 wpabuf_put_data(buf
, conf
->meshid
, conf
->meshid_len
);
300 /* IE: Mesh Peering Management element */
314 ie_len
+= 2; /* reason code */
318 wpabuf_put_u8(buf
, WLAN_EID_PEER_MGMT
);
319 wpabuf_put_u8(buf
, ie_len
);
320 /* peering protocol */
322 wpabuf_put_le16(buf
, 1);
324 wpabuf_put_le16(buf
, 0);
325 wpabuf_put_le16(buf
, sta
->my_lid
);
327 wpabuf_put_le16(buf
, sta
->peer_lid
);
328 if (type
== PLINK_CLOSE
)
329 wpabuf_put_le16(buf
, close_reason
);
331 if (sta
->sae
== NULL
) {
332 wpa_msg(wpa_s
, MSG_INFO
, "Mesh MPM: no SAE session");
335 mesh_rsn_get_pmkid(wpa_s
->mesh_rsn
, sta
,
336 wpabuf_put(buf
, PMKID_LEN
));
339 #ifdef CONFIG_IEEE80211N
340 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_ht_enabled
) {
341 u8 ht_capa_oper
[2 + 26 + 2 + 22];
343 pos
= hostapd_eid_ht_capabilities(bss
, ht_capa_oper
);
344 pos
= hostapd_eid_ht_operation(bss
, pos
);
345 wpabuf_put_data(buf
, ht_capa_oper
, pos
- ht_capa_oper
);
347 #endif /* CONFIG_IEEE80211N */
348 #ifdef CONFIG_IEEE80211AC
349 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_vht_enabled
) {
350 u8 vht_capa_oper
[2 + 12 + 2 + 5];
352 pos
= hostapd_eid_vht_capabilities(bss
, vht_capa_oper
);
353 pos
= hostapd_eid_vht_operation(bss
, pos
);
354 wpabuf_put_data(buf
, vht_capa_oper
, pos
- vht_capa_oper
);
356 #endif /* CONFIG_IEEE80211AC */
358 if (ampe
&& mesh_rsn_protect_frame(wpa_s
->mesh_rsn
, sta
, cat
, buf
)) {
359 wpa_msg(wpa_s
, MSG_INFO
,
360 "Mesh MPM: failed to add AMPE and MIC IE");
364 wpa_msg(wpa_s
, MSG_DEBUG
, "Mesh MPM: Sending peering frame type %d to "
365 MACSTR
" (my_lid=0x%x peer_lid=0x%x)",
366 type
, MAC2STR(sta
->addr
), sta
->my_lid
, sta
->peer_lid
);
367 ret
= wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0,
368 sta
->addr
, wpa_s
->own_addr
, wpa_s
->own_addr
,
369 wpabuf_head(buf
), wpabuf_len(buf
), 0);
371 wpa_msg(wpa_s
, MSG_INFO
,
372 "Mesh MPM: failed to send peering frame");
379 /* configure peering state in ours and driver's station entry */
380 void wpa_mesh_set_plink_state(struct wpa_supplicant
*wpa_s
,
381 struct sta_info
*sta
,
382 enum mesh_plink_state state
)
384 struct hostapd_sta_add_params params
;
387 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM set " MACSTR
" from %s into %s",
388 MAC2STR(sta
->addr
), mplstate
[sta
->plink_state
],
390 sta
->plink_state
= state
;
392 os_memset(¶ms
, 0, sizeof(params
));
393 params
.addr
= sta
->addr
;
394 params
.plink_state
= state
;
397 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
399 wpa_msg(wpa_s
, MSG_ERROR
, "Driver failed to set " MACSTR
400 ": %d", MAC2STR(sta
->addr
), ret
);
405 static void mesh_mpm_fsm_restart(struct wpa_supplicant
*wpa_s
,
406 struct sta_info
*sta
)
408 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
410 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
412 ap_free_sta(hapd
, sta
);
416 static void plink_timer(void *eloop_ctx
, void *user_data
)
418 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
419 struct sta_info
*sta
= user_data
;
421 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
423 switch (sta
->plink_state
) {
424 case PLINK_OPEN_RCVD
:
425 case PLINK_OPEN_SENT
:
427 if (sta
->mpm_retries
< conf
->dot11MeshMaxRetries
) {
428 eloop_register_timeout(
429 conf
->dot11MeshRetryTimeout
/ 1000,
430 (conf
->dot11MeshRetryTimeout
% 1000) * 1000,
431 plink_timer
, wpa_s
, sta
);
432 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_OPEN
, 0);
436 reason
= WLAN_REASON_MESH_MAX_RETRIES
;
437 /* fall through on else */
442 reason
= WLAN_REASON_MESH_CONFIRM_TIMEOUT
;
443 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
444 eloop_register_timeout(conf
->dot11MeshHoldingTimeout
/ 1000,
445 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
446 plink_timer
, wpa_s
, sta
);
447 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CLOSE
, reason
);
451 mesh_mpm_fsm_restart(wpa_s
, sta
);
459 /* initiate peering with station */
461 mesh_mpm_plink_open(struct wpa_supplicant
*wpa_s
, struct sta_info
*sta
,
462 enum mesh_plink_state next_state
)
464 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
466 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
467 eloop_register_timeout(conf
->dot11MeshRetryTimeout
/ 1000,
468 (conf
->dot11MeshRetryTimeout
% 1000) * 1000,
469 plink_timer
, wpa_s
, sta
);
470 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_OPEN
, 0);
471 wpa_mesh_set_plink_state(wpa_s
, sta
, next_state
);
475 static int mesh_mpm_plink_close(struct hostapd_data
*hapd
, struct sta_info
*sta
,
478 struct wpa_supplicant
*wpa_s
= ctx
;
479 int reason
= WLAN_REASON_MESH_PEERING_CANCELLED
;
482 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
483 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CLOSE
, reason
);
484 wpa_printf(MSG_DEBUG
, "MPM closing plink sta=" MACSTR
,
486 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
494 int mesh_mpm_close_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
496 struct hostapd_data
*hapd
;
497 struct sta_info
*sta
;
500 wpa_msg(wpa_s
, MSG_INFO
, "Mesh is not prepared yet");
504 hapd
= wpa_s
->ifmsh
->bss
[0];
505 sta
= ap_get_sta(hapd
, addr
);
507 wpa_msg(wpa_s
, MSG_INFO
, "No such mesh peer");
511 return mesh_mpm_plink_close(hapd
, sta
, wpa_s
) == 0 ? 0 : -1;
515 int mesh_mpm_connect_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
517 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
518 struct hostapd_data
*hapd
;
519 struct sta_info
*sta
;
520 struct mesh_conf
*conf
;
523 wpa_msg(wpa_s
, MSG_INFO
, "Mesh is not prepared yet");
527 if (!ssid
|| !ssid
->no_auto_peer
) {
528 wpa_msg(wpa_s
, MSG_INFO
,
529 "This command is available only with no_auto_peer mesh network");
533 hapd
= wpa_s
->ifmsh
->bss
[0];
534 conf
= wpa_s
->ifmsh
->mconf
;
536 sta
= ap_get_sta(hapd
, addr
);
538 wpa_msg(wpa_s
, MSG_INFO
, "No such mesh peer");
542 if ((PLINK_OPEN_SENT
<= sta
->plink_state
&&
543 sta
->plink_state
<= PLINK_ESTAB
) ||
544 (sta
->sae
&& sta
->sae
->state
> SAE_NOTHING
)) {
545 wpa_msg(wpa_s
, MSG_INFO
,
546 "Specified peer is connecting/connected");
550 if (conf
->security
== MESH_CONF_SEC_NONE
)
551 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPEN_SENT
);
553 mesh_rsn_auth_sae_sta(wpa_s
, sta
);
559 void mesh_mpm_deinit(struct wpa_supplicant
*wpa_s
, struct hostapd_iface
*ifmsh
)
561 struct hostapd_data
*hapd
= ifmsh
->bss
[0];
563 /* notify peers we're leaving */
564 ap_for_each_sta(hapd
, mesh_mpm_plink_close
, wpa_s
);
566 hapd
->num_plinks
= 0;
567 hostapd_free_stas(hapd
);
571 /* for mesh_rsn to indicate this peer has completed authentication, and we're
572 * ready to start AMPE */
573 void mesh_mpm_auth_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
575 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
576 struct hostapd_sta_add_params params
;
577 struct sta_info
*sta
;
580 sta
= ap_get_sta(data
, addr
);
582 wpa_msg(wpa_s
, MSG_DEBUG
, "no such mesh peer");
586 /* TODO: Should do nothing if this STA is already authenticated, but
587 * the AP code already sets this flag. */
588 sta
->flags
|= WLAN_STA_AUTH
;
590 mesh_rsn_init_ampe_sta(wpa_s
, sta
);
592 os_memset(¶ms
, 0, sizeof(params
));
593 params
.addr
= sta
->addr
;
594 params
.flags
= WPA_STA_AUTHENTICATED
| WPA_STA_AUTHORIZED
;
597 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM authenticating " MACSTR
,
599 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
601 wpa_msg(wpa_s
, MSG_ERROR
,
602 "Driver failed to set " MACSTR
": %d",
603 MAC2STR(sta
->addr
), ret
);
607 mesh_mpm_init_link(wpa_s
, sta
);
609 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPEN_SENT
);
613 * Initialize a sta_info structure for a peer and upload it into the driver
614 * in preparation for beginning authentication or peering. This is done when a
615 * Beacon (secure or open mesh) or a peering open frame (for open mesh) is
616 * received from the peer for the first time.
618 static struct sta_info
* mesh_mpm_add_peer(struct wpa_supplicant
*wpa_s
,
620 struct ieee802_11_elems
*elems
)
622 struct hostapd_sta_add_params params
;
623 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
624 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
625 struct sta_info
*sta
;
628 sta
= ap_get_sta(data
, addr
);
630 sta
= ap_sta_add(data
, addr
);
635 /* Set WMM by default since Mesh STAs are QoS STAs */
636 sta
->flags
|= WLAN_STA_WMM
;
639 if (copy_supp_rates(wpa_s
, sta
, elems
)) {
640 ap_free_sta(data
, sta
);
645 mesh_mpm_init_link(wpa_s
, sta
);
647 #ifdef CONFIG_IEEE80211N
648 copy_sta_ht_capab(data
, sta
, elems
->ht_capabilities
);
649 update_ht_state(data
, sta
);
650 #endif /* CONFIG_IEEE80211N */
652 #ifdef CONFIG_IEEE80211AC
653 copy_sta_vht_capab(data
, sta
, elems
->vht_capabilities
);
654 set_sta_vht_opmode(data
, sta
, elems
->vht_opmode_notif
);
655 #endif /* CONFIG_IEEE80211AC */
657 if (hostapd_get_aid(data
, sta
) < 0) {
658 wpa_msg(wpa_s
, MSG_ERROR
, "No AIDs available");
659 ap_free_sta(data
, sta
);
663 /* insert into driver */
664 os_memset(¶ms
, 0, sizeof(params
));
665 params
.supp_rates
= sta
->supported_rates
;
666 params
.supp_rates_len
= sta
->supported_rates_len
;
668 params
.plink_state
= sta
->plink_state
;
669 params
.aid
= sta
->aid
;
670 params
.listen_interval
= 100;
671 params
.ht_capabilities
= sta
->ht_capabilities
;
672 params
.vht_capabilities
= sta
->vht_capabilities
;
673 params
.flags
|= WPA_STA_WMM
;
674 params
.flags_mask
|= WPA_STA_AUTHENTICATED
;
675 if (conf
->security
== MESH_CONF_SEC_NONE
) {
676 params
.flags
|= WPA_STA_AUTHORIZED
;
677 params
.flags
|= WPA_STA_AUTHENTICATED
;
679 sta
->flags
|= WLAN_STA_MFP
;
680 params
.flags
|= WPA_STA_MFP
;
683 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
685 wpa_msg(wpa_s
, MSG_ERROR
,
686 "Driver failed to insert " MACSTR
": %d",
688 ap_free_sta(data
, sta
);
696 void wpa_mesh_new_mesh_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
697 struct ieee802_11_elems
*elems
)
699 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
700 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
701 struct sta_info
*sta
;
702 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
704 sta
= mesh_mpm_add_peer(wpa_s
, addr
, elems
);
708 if (ssid
&& ssid
->no_auto_peer
) {
709 wpa_msg(wpa_s
, MSG_INFO
, "will not initiate new peer link with "
710 MACSTR
" because of no_auto_peer", MAC2STR(addr
));
711 if (data
->mesh_pending_auth
) {
712 struct os_reltime age
;
713 const struct ieee80211_mgmt
*mgmt
;
714 struct hostapd_frame_info fi
;
716 mgmt
= wpabuf_head(data
->mesh_pending_auth
);
717 os_reltime_age(&data
->mesh_pending_auth_time
, &age
);
719 os_memcmp(mgmt
->sa
, addr
, ETH_ALEN
) == 0) {
720 wpa_printf(MSG_DEBUG
,
721 "mesh: Process pending Authentication frame from %u.%06u seconds ago",
722 (unsigned int) age
.sec
,
723 (unsigned int) age
.usec
);
724 os_memset(&fi
, 0, sizeof(fi
));
727 wpabuf_head(data
->mesh_pending_auth
),
728 wpabuf_len(data
->mesh_pending_auth
),
731 wpabuf_free(data
->mesh_pending_auth
);
732 data
->mesh_pending_auth
= NULL
;
737 if (conf
->security
== MESH_CONF_SEC_NONE
) {
738 if (sta
->plink_state
< PLINK_OPEN_SENT
||
739 sta
->plink_state
> PLINK_ESTAB
)
740 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPEN_SENT
);
742 mesh_rsn_auth_sae_sta(wpa_s
, sta
);
747 void mesh_mpm_mgmt_rx(struct wpa_supplicant
*wpa_s
, struct rx_mgmt
*rx_mgmt
)
749 struct hostapd_frame_info fi
;
751 os_memset(&fi
, 0, sizeof(fi
));
752 fi
.datarate
= rx_mgmt
->datarate
;
753 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
754 ieee802_11_mgmt(wpa_s
->ifmsh
->bss
[0], rx_mgmt
->frame
,
755 rx_mgmt
->frame_len
, &fi
);
759 static void mesh_mpm_plink_estab(struct wpa_supplicant
*wpa_s
,
760 struct sta_info
*sta
)
762 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
763 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
766 wpa_msg(wpa_s
, MSG_INFO
, "mesh plink with " MACSTR
" established",
769 if (conf
->security
& MESH_CONF_SEC_AMPE
) {
770 wpa_drv_set_key(wpa_s
, WPA_ALG_CCMP
, sta
->addr
, 0, 0,
771 seq
, sizeof(seq
), sta
->mtk
, sizeof(sta
->mtk
));
772 wpa_drv_set_key(wpa_s
, WPA_ALG_CCMP
, sta
->addr
, 1, 0,
774 sta
->mgtk
, sizeof(sta
->mgtk
));
775 wpa_drv_set_key(wpa_s
, WPA_ALG_IGTK
, sta
->addr
, 4, 0,
777 sta
->mgtk
, sizeof(sta
->mgtk
));
779 wpa_hexdump_key(MSG_DEBUG
, "mtk:", sta
->mtk
, sizeof(sta
->mtk
));
780 wpa_hexdump_key(MSG_DEBUG
, "mgtk:",
781 sta
->mgtk
, sizeof(sta
->mgtk
));
784 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_ESTAB
);
787 sta
->flags
|= WLAN_STA_ASSOC
;
789 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
791 /* Send ctrl event */
792 wpa_msg(wpa_s
, MSG_INFO
, MESH_PEER_CONNECTED MACSTR
,
797 static void mesh_mpm_fsm(struct wpa_supplicant
*wpa_s
, struct sta_info
*sta
,
798 enum plink_event event
)
800 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
801 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
804 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM " MACSTR
" state %s event %s",
805 MAC2STR(sta
->addr
), mplstate
[sta
->plink_state
],
808 switch (sta
->plink_state
) {
812 mesh_mpm_fsm_restart(wpa_s
, sta
);
815 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPEN_RCVD
);
816 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CONFIRM
,
823 case PLINK_OPEN_SENT
:
827 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
830 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
832 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
833 eloop_register_timeout(
834 conf
->dot11MeshHoldingTimeout
/ 1000,
835 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
836 plink_timer
, wpa_s
, sta
);
837 mesh_mpm_send_plink_action(wpa_s
, sta
,
838 PLINK_CLOSE
, reason
);
841 /* retry timer is left untouched */
842 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_OPEN_RCVD
);
843 mesh_mpm_send_plink_action(wpa_s
, sta
,
847 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_CNF_RCVD
);
848 eloop_register_timeout(
849 conf
->dot11MeshConfirmTimeout
/ 1000,
850 (conf
->dot11MeshConfirmTimeout
% 1000) * 1000,
851 plink_timer
, wpa_s
, sta
);
857 case PLINK_OPEN_RCVD
:
861 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
864 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
866 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
867 eloop_register_timeout(
868 conf
->dot11MeshHoldingTimeout
/ 1000,
869 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
870 plink_timer
, wpa_s
, sta
);
871 sta
->mpm_close_reason
= reason
;
872 mesh_mpm_send_plink_action(wpa_s
, sta
,
873 PLINK_CLOSE
, reason
);
876 mesh_mpm_send_plink_action(wpa_s
, sta
,
880 if (conf
->security
& MESH_CONF_SEC_AMPE
)
881 mesh_rsn_derive_mtk(wpa_s
, sta
);
882 mesh_mpm_plink_estab(wpa_s
, sta
);
892 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
895 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
897 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
898 eloop_register_timeout(
899 conf
->dot11MeshHoldingTimeout
/ 1000,
900 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
901 plink_timer
, wpa_s
, sta
);
902 sta
->mpm_close_reason
= reason
;
903 mesh_mpm_send_plink_action(wpa_s
, sta
,
904 PLINK_CLOSE
, reason
);
907 mesh_mpm_plink_estab(wpa_s
, sta
);
908 mesh_mpm_send_plink_action(wpa_s
, sta
,
918 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
919 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
921 eloop_register_timeout(
922 conf
->dot11MeshHoldingTimeout
/ 1000,
923 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
924 plink_timer
, wpa_s
, sta
);
925 sta
->mpm_close_reason
= reason
;
927 wpa_msg(wpa_s
, MSG_INFO
, "mesh plink with " MACSTR
928 " closed with reason %d",
929 MAC2STR(sta
->addr
), reason
);
931 wpa_msg(wpa_s
, MSG_INFO
, MESH_PEER_DISCONNECTED MACSTR
,
936 mesh_mpm_send_plink_action(wpa_s
, sta
,
937 PLINK_CLOSE
, reason
);
940 mesh_mpm_send_plink_action(wpa_s
, sta
,
950 mesh_mpm_fsm_restart(wpa_s
, sta
);
956 reason
= sta
->mpm_close_reason
;
957 mesh_mpm_send_plink_action(wpa_s
, sta
,
958 PLINK_CLOSE
, reason
);
965 wpa_msg(wpa_s
, MSG_DEBUG
,
966 "Unsupported MPM event %s for state %s",
967 mplevent
[event
], mplstate
[sta
->plink_state
]);
973 void mesh_mpm_action_rx(struct wpa_supplicant
*wpa_s
,
974 const struct ieee80211_mgmt
*mgmt
, size_t len
)
977 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
978 struct mesh_conf
*mconf
= wpa_s
->ifmsh
->mconf
;
979 struct sta_info
*sta
;
980 u16 plid
= 0, llid
= 0;
981 enum plink_event event
;
982 struct ieee802_11_elems elems
;
983 struct mesh_peer_mgmt_ie peer_mgmt_ie
;
988 if (mgmt
->u
.action
.category
!= WLAN_ACTION_SELF_PROTECTED
)
991 action_field
= mgmt
->u
.action
.u
.slf_prot_action
.action
;
992 if (action_field
!= PLINK_OPEN
&&
993 action_field
!= PLINK_CONFIRM
&&
994 action_field
!= PLINK_CLOSE
)
997 ies
= mgmt
->u
.action
.u
.slf_prot_action
.variable
;
998 ie_len
= (const u8
*) mgmt
+ len
-
999 mgmt
->u
.action
.u
.slf_prot_action
.variable
;
1001 /* at least expect mesh id and peering mgmt */
1002 if (ie_len
< 2 + 2) {
1003 wpa_printf(MSG_DEBUG
,
1004 "MPM: Ignore too short action frame %u ie_len %u",
1005 action_field
, (unsigned int) ie_len
);
1008 wpa_printf(MSG_DEBUG
, "MPM: Received PLINK action %u", action_field
);
1010 if (action_field
== PLINK_OPEN
|| action_field
== PLINK_CONFIRM
) {
1011 wpa_printf(MSG_DEBUG
, "MPM: Capability 0x%x",
1013 ies
+= 2; /* capability */
1016 if (action_field
== PLINK_CONFIRM
) {
1017 wpa_printf(MSG_DEBUG
, "MPM: AID 0x%x", WPA_GET_LE16(ies
));
1022 /* check for mesh peering, mesh id and mesh config IEs */
1023 if (ieee802_11_parse_elems(ies
, ie_len
, &elems
, 0) == ParseFailed
) {
1024 wpa_printf(MSG_DEBUG
, "MPM: Failed to parse PLINK IEs");
1027 if (!elems
.peer_mgmt
) {
1028 wpa_printf(MSG_DEBUG
,
1029 "MPM: No Mesh Peering Management element");
1032 if (action_field
!= PLINK_CLOSE
) {
1033 if (!elems
.mesh_id
|| !elems
.mesh_config
) {
1034 wpa_printf(MSG_DEBUG
,
1035 "MPM: No Mesh ID or Mesh Configuration element");
1039 if (!matches_local(wpa_s
, &elems
)) {
1040 wpa_printf(MSG_DEBUG
,
1041 "MPM: Mesh ID or Mesh Configuration element do not match local MBSS");
1046 ret
= mesh_mpm_parse_peer_mgmt(wpa_s
, action_field
,
1048 elems
.peer_mgmt_len
,
1051 wpa_printf(MSG_DEBUG
, "MPM: Mesh parsing rejected frame");
1055 /* the sender's llid is our plid and vice-versa */
1056 plid
= WPA_GET_LE16(peer_mgmt_ie
.llid
);
1057 if (peer_mgmt_ie
.plid
)
1058 llid
= WPA_GET_LE16(peer_mgmt_ie
.plid
);
1059 wpa_printf(MSG_DEBUG
, "MPM: plid=0x%x llid=0x%x", plid
, llid
);
1061 sta
= ap_get_sta(hapd
, mgmt
->sa
);
1064 * If this is an open frame from an unknown STA, and this is an
1065 * open mesh, then go ahead and add the peer before proceeding.
1067 if (!sta
&& action_field
== PLINK_OPEN
&&
1068 !(mconf
->security
& MESH_CONF_SEC_AMPE
))
1069 sta
= mesh_mpm_add_peer(wpa_s
, mgmt
->sa
, &elems
);
1072 wpa_printf(MSG_DEBUG
, "MPM: No STA entry for peer");
1077 /* peer is in sae_accepted? */
1078 if (sta
->sae
&& sta
->sae
->state
!= SAE_ACCEPTED
) {
1079 wpa_printf(MSG_DEBUG
, "MPM: SAE not yet accepted for peer");
1082 #endif /* CONFIG_SAE */
1085 mesh_mpm_init_link(wpa_s
, sta
);
1087 if ((mconf
->security
& MESH_CONF_SEC_AMPE
) &&
1088 mesh_rsn_process_ampe(wpa_s
, sta
, &elems
,
1089 &mgmt
->u
.action
.category
,
1090 peer_mgmt_ie
.chosen_pmk
,
1092 wpa_printf(MSG_DEBUG
, "MPM: RSN process rejected frame");
1096 if (sta
->plink_state
== PLINK_BLOCKED
) {
1097 wpa_printf(MSG_DEBUG
, "MPM: PLINK_BLOCKED");
1101 /* Now we will figure out the appropriate event... */
1102 switch (action_field
) {
1104 if (plink_free_count(hapd
) == 0) {
1106 wpa_printf(MSG_INFO
,
1107 "MPM: Peer link num over quota(%d)",
1109 } else if (sta
->peer_lid
&& sta
->peer_lid
!= plid
) {
1112 sta
->peer_lid
= plid
;
1117 if (plink_free_count(hapd
) == 0) {
1119 wpa_printf(MSG_INFO
,
1120 "MPM: Peer link num over quota(%d)",
1122 } else if (sta
->my_lid
!= llid
||
1123 (sta
->peer_lid
&& sta
->peer_lid
!= plid
)) {
1127 sta
->peer_lid
= plid
;
1132 if (sta
->plink_state
== PLINK_ESTAB
)
1133 /* Do not check for llid or plid. This does not
1134 * follow the standard but since multiple plinks
1135 * per cand are not supported, it is necessary in
1136 * order to avoid a livelock when MP A sees an
1137 * establish peer link to MP B but MP B does not
1138 * see it. This can be caused by a timeout in
1139 * B's peer link establishment or B being
1143 else if (sta
->peer_lid
!= plid
)
1145 else if (peer_mgmt_ie
.plid
&& sta
->my_lid
!= llid
)
1152 * This cannot be hit due to the action_field check above, but
1153 * compilers may not be able to figure that out and can warn
1154 * about uninitialized event below.
1158 mesh_mpm_fsm(wpa_s
, sta
, event
);
1162 /* called by ap_free_sta */
1163 void mesh_mpm_free_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1165 if (sta
->plink_state
== PLINK_ESTAB
)
1167 eloop_cancel_timeout(plink_timer
, ELOOP_ALL_CTX
, sta
);
1168 eloop_cancel_timeout(mesh_auth_timer
, ELOOP_ALL_CTX
, sta
);