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 "common/hw_features_common.h"
15 #include "ap/hostapd.h"
16 #include "ap/sta_info.h"
17 #include "ap/ieee802_11.h"
18 #include "ap/wpa_auth.h"
19 #include "wpa_supplicant_i.h"
24 struct mesh_peer_mgmt_ie
{
25 const u8
*proto_id
; /* Mesh Peering Protocol Identifier (2 octets) */
26 const u8
*llid
; /* Local Link ID (2 octets) */
27 const u8
*plid
; /* Peer Link ID (conditional, 2 octets) */
28 const u8
*reason
; /* Reason Code (conditional, 2 octets) */
29 const u8
*chosen_pmk
; /* Chosen PMK (optional, 16 octets) */
32 static void plink_timer(void *eloop_ctx
, void *user_data
);
45 static const char * const mplstate
[] = {
46 [0] = "UNINITIALIZED",
47 [PLINK_IDLE
] = "IDLE",
48 [PLINK_OPN_SNT
] = "OPN_SNT",
49 [PLINK_OPN_RCVD
] = "OPN_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 [CNF_ACPT
] = "CNF_ACPT",
61 [CNF_RJCT
] = "CNF_RJCT",
62 [CLS_ACPT
] = "CLS_ACPT",
63 [REQ_RJCT
] = "REQ_RJCT",
67 static int mesh_mpm_parse_peer_mgmt(struct wpa_supplicant
*wpa_s
,
69 const u8
*ie
, size_t len
,
70 struct mesh_peer_mgmt_ie
*mpm_ie
)
72 os_memset(mpm_ie
, 0, sizeof(*mpm_ie
));
74 /* Remove optional Chosen PMK field at end */
75 if (len
>= SAE_PMKID_LEN
) {
76 mpm_ie
->chosen_pmk
= ie
+ len
- SAE_PMKID_LEN
;
80 if ((action_field
== PLINK_OPEN
&& len
!= 4) ||
81 (action_field
== PLINK_CONFIRM
&& len
!= 6) ||
82 (action_field
== PLINK_CLOSE
&& len
!= 6 && len
!= 8)) {
83 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM: Invalid peer mgmt ie");
90 mpm_ie
->proto_id
= ie
;
91 mpm_ie
->llid
= ie
+ 2;
95 /* close reason is always present at end for close */
96 if (action_field
== PLINK_CLOSE
) {
99 mpm_ie
->reason
= ie
+ len
- 2;
103 /* Peer Link ID, present for confirm, and possibly close */
111 static int plink_free_count(struct hostapd_data
*hapd
)
113 if (hapd
->max_plinks
> hapd
->num_plinks
)
114 return hapd
->max_plinks
- hapd
->num_plinks
;
119 static u16
copy_supp_rates(struct wpa_supplicant
*wpa_s
,
120 struct sta_info
*sta
,
121 struct ieee802_11_elems
*elems
)
123 if (!elems
->supp_rates
) {
124 wpa_msg(wpa_s
, MSG_ERROR
, "no supported rates from " MACSTR
,
126 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
129 if (elems
->supp_rates_len
+ elems
->ext_supp_rates_len
>
130 sizeof(sta
->supported_rates
)) {
131 wpa_msg(wpa_s
, MSG_ERROR
,
132 "Invalid supported rates element length " MACSTR
133 " %d+%d", MAC2STR(sta
->addr
), elems
->supp_rates_len
,
134 elems
->ext_supp_rates_len
);
135 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
138 sta
->supported_rates_len
= merge_byte_arrays(
139 sta
->supported_rates
, sizeof(sta
->supported_rates
),
140 elems
->supp_rates
, elems
->supp_rates_len
,
141 elems
->ext_supp_rates
, elems
->ext_supp_rates_len
);
143 return WLAN_STATUS_SUCCESS
;
147 /* return true if elems from a neighbor match this MBSS */
148 static Boolean
matches_local(struct wpa_supplicant
*wpa_s
,
149 struct ieee802_11_elems
*elems
)
151 struct mesh_conf
*mconf
= wpa_s
->ifmsh
->mconf
;
153 if (elems
->mesh_config_len
< 5)
156 return (mconf
->meshid_len
== elems
->mesh_id_len
&&
157 os_memcmp(mconf
->meshid
, elems
->mesh_id
,
158 elems
->mesh_id_len
) == 0 &&
159 mconf
->mesh_pp_id
== elems
->mesh_config
[0] &&
160 mconf
->mesh_pm_id
== elems
->mesh_config
[1] &&
161 mconf
->mesh_cc_id
== elems
->mesh_config
[2] &&
162 mconf
->mesh_sp_id
== elems
->mesh_config
[3] &&
163 mconf
->mesh_auth_id
== elems
->mesh_config
[4]);
167 /* check if local link id is already used with another peer */
168 static Boolean
llid_in_use(struct wpa_supplicant
*wpa_s
, u16 llid
)
170 struct sta_info
*sta
;
171 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
173 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
174 if (sta
->my_lid
== llid
)
182 /* generate an llid for a link and set to initial state */
183 static void mesh_mpm_init_link(struct wpa_supplicant
*wpa_s
,
184 struct sta_info
*sta
)
189 if (os_get_random((u8
*) &llid
, sizeof(llid
)) < 0)
191 } 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_IDLE
;
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];
216 u8 ie_len
, add_plid
= 0;
218 int ampe
= conf
->security
& MESH_CONF_SEC_AMPE
;
224 buf_len
= 2 + /* capability info */
226 2 + 8 + /* supported rates */
228 2 + 32 + /* mesh ID */
229 2 + 7 + /* mesh config */
230 2 + 23 + /* peering management */
233 #ifdef CONFIG_IEEE80211N
234 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_ht_enabled
) {
235 buf_len
+= 2 + 26 + /* HT capabilities */
236 2 + 22; /* HT operation */
238 #endif /* CONFIG_IEEE80211N */
239 #ifdef CONFIG_IEEE80211AC
240 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_vht_enabled
) {
241 buf_len
+= 2 + 12 + /* VHT Capabilities */
242 2 + 5; /* VHT Operation */
244 #endif /* CONFIG_IEEE80211AC */
245 if (type
!= PLINK_CLOSE
)
246 buf_len
+= conf
->rsn_ie_len
; /* RSN IE */
248 buf
= wpabuf_alloc(buf_len
);
252 cat
= wpabuf_mhead_u8(buf
);
253 wpabuf_put_u8(buf
, WLAN_ACTION_SELF_PROTECTED
);
254 wpabuf_put_u8(buf
, type
);
256 if (type
!= PLINK_CLOSE
) {
259 /* capability info */
260 wpabuf_put_le16(buf
, ampe
? IEEE80211_CAP_PRIVACY
: 0);
263 if (type
== PLINK_CONFIRM
)
264 wpabuf_put_le16(buf
, sta
->aid
);
266 /* IE: supp + ext. supp rates */
267 pos
= hostapd_eid_supp_rates(bss
, supp_rates
);
268 pos
= hostapd_eid_ext_supp_rates(bss
, pos
);
269 wpabuf_put_data(buf
, supp_rates
, pos
- supp_rates
);
272 wpabuf_put_data(buf
, conf
->rsn_ie
, conf
->rsn_ie_len
);
275 wpabuf_put_u8(buf
, WLAN_EID_MESH_ID
);
276 wpabuf_put_u8(buf
, conf
->meshid_len
);
277 wpabuf_put_data(buf
, conf
->meshid
, conf
->meshid_len
);
280 wpabuf_put_u8(buf
, WLAN_EID_MESH_CONFIG
);
281 wpabuf_put_u8(buf
, 7);
282 wpabuf_put_u8(buf
, conf
->mesh_pp_id
);
283 wpabuf_put_u8(buf
, conf
->mesh_pm_id
);
284 wpabuf_put_u8(buf
, conf
->mesh_cc_id
);
285 wpabuf_put_u8(buf
, conf
->mesh_sp_id
);
286 wpabuf_put_u8(buf
, conf
->mesh_auth_id
);
287 info
= (bss
->num_plinks
> 63 ? 63 : bss
->num_plinks
) << 1;
288 /* TODO: Add Connected to Mesh Gate/AS subfields */
289 wpabuf_put_u8(buf
, info
);
290 /* always forwarding & accepting plinks for now */
291 wpabuf_put_u8(buf
, MESH_CAP_ACCEPT_ADDITIONAL_PEER
|
292 MESH_CAP_FORWARDING
);
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
, 0);
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
;
395 params
.peer_aid
= sta
->peer_aid
;
398 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
400 wpa_msg(wpa_s
, MSG_ERROR
, "Driver failed to set " MACSTR
401 ": %d", MAC2STR(sta
->addr
), ret
);
406 static void mesh_mpm_fsm_restart(struct wpa_supplicant
*wpa_s
,
407 struct sta_info
*sta
)
409 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
411 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
413 ap_free_sta(hapd
, sta
);
417 static void plink_timer(void *eloop_ctx
, void *user_data
)
419 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
420 struct sta_info
*sta
= user_data
;
422 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
423 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
425 switch (sta
->plink_state
) {
429 if (sta
->mpm_retries
< conf
->dot11MeshMaxRetries
) {
430 eloop_register_timeout(
431 conf
->dot11MeshRetryTimeout
/ 1000,
432 (conf
->dot11MeshRetryTimeout
% 1000) * 1000,
433 plink_timer
, wpa_s
, sta
);
434 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_OPEN
, 0);
438 reason
= WLAN_REASON_MESH_MAX_RETRIES
;
439 /* fall through on else */
444 reason
= WLAN_REASON_MESH_CONFIRM_TIMEOUT
;
445 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
446 eloop_register_timeout(conf
->dot11MeshHoldingTimeout
/ 1000,
447 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
448 plink_timer
, wpa_s
, sta
);
449 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CLOSE
, reason
);
454 if (sta
->mesh_sae_pmksa_caching
) {
455 wpa_printf(MSG_DEBUG
, "MPM: Peer " MACSTR
456 " looks like it does not support mesh SAE PMKSA caching, so remove the cached entry for it",
458 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
460 mesh_mpm_fsm_restart(wpa_s
, sta
);
468 /* initiate peering with station */
470 mesh_mpm_plink_open(struct wpa_supplicant
*wpa_s
, struct sta_info
*sta
,
471 enum mesh_plink_state next_state
)
473 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
475 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
476 eloop_register_timeout(conf
->dot11MeshRetryTimeout
/ 1000,
477 (conf
->dot11MeshRetryTimeout
% 1000) * 1000,
478 plink_timer
, wpa_s
, sta
);
479 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_OPEN
, 0);
480 wpa_mesh_set_plink_state(wpa_s
, sta
, next_state
);
484 static int mesh_mpm_plink_close(struct hostapd_data
*hapd
, struct sta_info
*sta
,
487 struct wpa_supplicant
*wpa_s
= ctx
;
488 int reason
= WLAN_REASON_MESH_PEERING_CANCELLED
;
491 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
492 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CLOSE
, reason
);
493 wpa_printf(MSG_DEBUG
, "MPM closing plink sta=" MACSTR
,
495 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
503 int mesh_mpm_close_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
505 struct hostapd_data
*hapd
;
506 struct sta_info
*sta
;
509 wpa_msg(wpa_s
, MSG_INFO
, "Mesh is not prepared yet");
513 hapd
= wpa_s
->ifmsh
->bss
[0];
514 sta
= ap_get_sta(hapd
, addr
);
516 wpa_msg(wpa_s
, MSG_INFO
, "No such mesh peer");
520 return mesh_mpm_plink_close(hapd
, sta
, wpa_s
) == 0 ? 0 : -1;
524 static void peer_add_timer(void *eloop_ctx
, void *user_data
)
526 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
527 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
529 os_memset(hapd
->mesh_required_peer
, 0, ETH_ALEN
);
533 int mesh_mpm_connect_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
536 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
537 struct hostapd_data
*hapd
;
538 struct sta_info
*sta
;
539 struct mesh_conf
*conf
;
542 wpa_msg(wpa_s
, MSG_INFO
, "Mesh is not prepared yet");
546 if (!ssid
|| !ssid
->no_auto_peer
) {
547 wpa_msg(wpa_s
, MSG_INFO
,
548 "This command is available only with no_auto_peer mesh network");
552 hapd
= wpa_s
->ifmsh
->bss
[0];
553 conf
= wpa_s
->ifmsh
->mconf
;
555 sta
= ap_get_sta(hapd
, addr
);
557 wpa_msg(wpa_s
, MSG_INFO
, "No such mesh peer");
561 if ((PLINK_OPN_SNT
<= sta
->plink_state
&&
562 sta
->plink_state
<= PLINK_ESTAB
) ||
563 (sta
->sae
&& sta
->sae
->state
> SAE_NOTHING
)) {
564 wpa_msg(wpa_s
, MSG_INFO
,
565 "Specified peer is connecting/connected");
569 if (conf
->security
== MESH_CONF_SEC_NONE
) {
570 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPN_SNT
);
572 mesh_rsn_auth_sae_sta(wpa_s
, sta
);
573 os_memcpy(hapd
->mesh_required_peer
, addr
, ETH_ALEN
);
574 eloop_register_timeout(duration
== -1 ? 10 : duration
, 0,
575 peer_add_timer
, wpa_s
, NULL
);
582 void mesh_mpm_deinit(struct wpa_supplicant
*wpa_s
, struct hostapd_iface
*ifmsh
)
584 struct hostapd_data
*hapd
= ifmsh
->bss
[0];
586 /* notify peers we're leaving */
587 ap_for_each_sta(hapd
, mesh_mpm_plink_close
, wpa_s
);
589 hapd
->num_plinks
= 0;
590 hostapd_free_stas(hapd
);
591 eloop_cancel_timeout(peer_add_timer
, wpa_s
, NULL
);
595 /* for mesh_rsn to indicate this peer has completed authentication, and we're
596 * ready to start AMPE */
597 void mesh_mpm_auth_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
599 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
600 struct hostapd_sta_add_params params
;
601 struct sta_info
*sta
;
604 sta
= ap_get_sta(data
, addr
);
606 wpa_msg(wpa_s
, MSG_DEBUG
, "no such mesh peer");
610 /* TODO: Should do nothing if this STA is already authenticated, but
611 * the AP code already sets this flag. */
612 sta
->flags
|= WLAN_STA_AUTH
;
614 mesh_rsn_init_ampe_sta(wpa_s
, sta
);
616 os_memset(¶ms
, 0, sizeof(params
));
617 params
.addr
= sta
->addr
;
618 params
.flags
= WPA_STA_AUTHENTICATED
| WPA_STA_AUTHORIZED
;
621 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM authenticating " MACSTR
,
623 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
625 wpa_msg(wpa_s
, MSG_ERROR
,
626 "Driver failed to set " MACSTR
": %d",
627 MAC2STR(sta
->addr
), ret
);
631 mesh_mpm_init_link(wpa_s
, sta
);
633 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPN_SNT
);
637 * Initialize a sta_info structure for a peer and upload it into the driver
638 * in preparation for beginning authentication or peering. This is done when a
639 * Beacon (secure or open mesh) or a peering open frame (for open mesh) is
640 * received from the peer for the first time.
642 static struct sta_info
* mesh_mpm_add_peer(struct wpa_supplicant
*wpa_s
,
644 struct ieee802_11_elems
*elems
)
646 struct hostapd_sta_add_params params
;
647 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
648 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
649 struct sta_info
*sta
;
650 #ifdef CONFIG_IEEE80211N
651 struct ieee80211_ht_operation
*oper
;
652 #endif /* CONFIG_IEEE80211N */
655 if (elems
->mesh_config_len
>= 7 &&
656 !(elems
->mesh_config
[6] & MESH_CAP_ACCEPT_ADDITIONAL_PEER
)) {
657 wpa_msg(wpa_s
, MSG_DEBUG
,
658 "mesh: Ignore a crowded peer " MACSTR
,
663 sta
= ap_get_sta(data
, addr
);
665 sta
= ap_sta_add(data
, addr
);
670 /* Set WMM by default since Mesh STAs are QoS STAs */
671 sta
->flags
|= WLAN_STA_WMM
;
674 if (copy_supp_rates(wpa_s
, sta
, elems
)) {
675 ap_free_sta(data
, sta
);
680 mesh_mpm_init_link(wpa_s
, sta
);
682 #ifdef CONFIG_IEEE80211N
683 copy_sta_ht_capab(data
, sta
, elems
->ht_capabilities
);
685 oper
= (struct ieee80211_ht_operation
*) elems
->ht_operation
;
687 !(oper
->ht_param
& HT_INFO_HT_PARAM_STA_CHNL_WIDTH
)) {
688 wpa_msg(wpa_s
, MSG_DEBUG
, MACSTR
689 " does not support 40 MHz bandwidth",
691 set_disable_ht40(sta
->ht_capabilities
, 1);
694 update_ht_state(data
, sta
);
695 #endif /* CONFIG_IEEE80211N */
697 #ifdef CONFIG_IEEE80211AC
698 copy_sta_vht_capab(data
, sta
, elems
->vht_capabilities
);
699 set_sta_vht_opmode(data
, sta
, elems
->vht_opmode_notif
);
700 #endif /* CONFIG_IEEE80211AC */
702 if (hostapd_get_aid(data
, sta
) < 0) {
703 wpa_msg(wpa_s
, MSG_ERROR
, "No AIDs available");
704 ap_free_sta(data
, sta
);
708 /* insert into driver */
709 os_memset(¶ms
, 0, sizeof(params
));
710 params
.supp_rates
= sta
->supported_rates
;
711 params
.supp_rates_len
= sta
->supported_rates_len
;
713 params
.plink_state
= sta
->plink_state
;
714 params
.aid
= sta
->aid
;
715 params
.peer_aid
= sta
->peer_aid
;
716 params
.listen_interval
= 100;
717 params
.ht_capabilities
= sta
->ht_capabilities
;
718 params
.vht_capabilities
= sta
->vht_capabilities
;
719 params
.flags
|= WPA_STA_WMM
;
720 params
.flags_mask
|= WPA_STA_AUTHENTICATED
;
721 if (conf
->security
== MESH_CONF_SEC_NONE
) {
722 params
.flags
|= WPA_STA_AUTHORIZED
;
723 params
.flags
|= WPA_STA_AUTHENTICATED
;
725 sta
->flags
|= WLAN_STA_MFP
;
726 params
.flags
|= WPA_STA_MFP
;
729 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
731 wpa_msg(wpa_s
, MSG_ERROR
,
732 "Driver failed to insert " MACSTR
": %d",
734 ap_free_sta(data
, sta
);
742 void wpa_mesh_new_mesh_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
743 struct ieee802_11_elems
*elems
)
745 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
746 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
747 struct sta_info
*sta
;
748 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
750 sta
= mesh_mpm_add_peer(wpa_s
, addr
, elems
);
754 if (ssid
&& ssid
->no_auto_peer
&&
755 (is_zero_ether_addr(data
->mesh_required_peer
) ||
756 os_memcmp(data
->mesh_required_peer
, addr
, ETH_ALEN
) != 0)) {
757 wpa_msg(wpa_s
, MSG_INFO
, "will not initiate new peer link with "
758 MACSTR
" because of no_auto_peer", MAC2STR(addr
));
759 if (data
->mesh_pending_auth
) {
760 struct os_reltime age
;
761 const struct ieee80211_mgmt
*mgmt
;
762 struct hostapd_frame_info fi
;
764 mgmt
= wpabuf_head(data
->mesh_pending_auth
);
765 os_reltime_age(&data
->mesh_pending_auth_time
, &age
);
767 os_memcmp(mgmt
->sa
, addr
, ETH_ALEN
) == 0) {
768 wpa_printf(MSG_DEBUG
,
769 "mesh: Process pending Authentication frame from %u.%06u seconds ago",
770 (unsigned int) age
.sec
,
771 (unsigned int) age
.usec
);
772 os_memset(&fi
, 0, sizeof(fi
));
775 wpabuf_head(data
->mesh_pending_auth
),
776 wpabuf_len(data
->mesh_pending_auth
),
779 wpabuf_free(data
->mesh_pending_auth
);
780 data
->mesh_pending_auth
= NULL
;
785 if (conf
->security
== MESH_CONF_SEC_NONE
) {
786 if (sta
->plink_state
< PLINK_OPN_SNT
||
787 sta
->plink_state
> PLINK_ESTAB
)
788 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPN_SNT
);
790 mesh_rsn_auth_sae_sta(wpa_s
, sta
);
795 void mesh_mpm_mgmt_rx(struct wpa_supplicant
*wpa_s
, struct rx_mgmt
*rx_mgmt
)
797 struct hostapd_frame_info fi
;
799 os_memset(&fi
, 0, sizeof(fi
));
800 fi
.datarate
= rx_mgmt
->datarate
;
801 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
802 ieee802_11_mgmt(wpa_s
->ifmsh
->bss
[0], rx_mgmt
->frame
,
803 rx_mgmt
->frame_len
, &fi
);
807 static void mesh_mpm_plink_estab(struct wpa_supplicant
*wpa_s
,
808 struct sta_info
*sta
)
810 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
811 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
814 wpa_msg(wpa_s
, MSG_INFO
, "mesh plink with " MACSTR
" established",
817 if (conf
->security
& MESH_CONF_SEC_AMPE
) {
818 wpa_hexdump_key(MSG_DEBUG
, "mesh: MTK", sta
->mtk
, sta
->mtk_len
);
819 wpa_drv_set_key(wpa_s
, wpa_cipher_to_alg(conf
->pairwise_cipher
),
820 sta
->addr
, 0, 0, seq
, sizeof(seq
),
821 sta
->mtk
, sta
->mtk_len
);
823 wpa_hexdump_key(MSG_DEBUG
, "mesh: RX MGTK Key RSC",
824 sta
->mgtk_rsc
, sizeof(sta
->mgtk_rsc
));
825 wpa_hexdump_key(MSG_DEBUG
, "mesh: RX MGTK",
826 sta
->mgtk
, sta
->mgtk_len
);
827 wpa_drv_set_key(wpa_s
, wpa_cipher_to_alg(conf
->group_cipher
),
828 sta
->addr
, sta
->mgtk_key_id
, 0,
829 sta
->mgtk_rsc
, sizeof(sta
->mgtk_rsc
),
830 sta
->mgtk
, sta
->mgtk_len
);
833 wpa_hexdump_key(MSG_DEBUG
, "mesh: RX IGTK Key RSC",
834 sta
->igtk_rsc
, sizeof(sta
->igtk_rsc
));
835 wpa_hexdump_key(MSG_DEBUG
, "mesh: RX IGTK",
836 sta
->igtk
, sta
->igtk_len
);
839 wpa_cipher_to_alg(conf
->mgmt_group_cipher
),
840 sta
->addr
, sta
->igtk_key_id
, 0,
841 sta
->igtk_rsc
, sizeof(sta
->igtk_rsc
),
842 sta
->igtk
, sta
->igtk_len
);
846 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_ESTAB
);
849 sta
->flags
|= WLAN_STA_ASSOC
;
850 sta
->mesh_sae_pmksa_caching
= 0;
852 eloop_cancel_timeout(peer_add_timer
, wpa_s
, NULL
);
853 peer_add_timer(wpa_s
, NULL
);
854 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
856 /* Send ctrl event */
857 wpa_msg(wpa_s
, MSG_INFO
, MESH_PEER_CONNECTED MACSTR
,
862 static void mesh_mpm_fsm(struct wpa_supplicant
*wpa_s
, struct sta_info
*sta
,
863 enum plink_event event
, u16 reason
)
865 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
866 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
868 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM " MACSTR
" state %s event %s",
869 MAC2STR(sta
->addr
), mplstate
[sta
->plink_state
],
872 switch (sta
->plink_state
) {
876 mesh_mpm_fsm_restart(wpa_s
, sta
);
879 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPN_RCVD
);
880 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CONFIRM
,
884 mesh_mpm_send_plink_action(wpa_s
, sta
,
885 PLINK_CLOSE
, reason
);
896 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
899 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
901 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
902 eloop_register_timeout(
903 conf
->dot11MeshHoldingTimeout
/ 1000,
904 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
905 plink_timer
, wpa_s
, sta
);
906 mesh_mpm_send_plink_action(wpa_s
, sta
,
907 PLINK_CLOSE
, reason
);
910 /* retry timer is left untouched */
911 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_OPN_RCVD
);
912 mesh_mpm_send_plink_action(wpa_s
, sta
,
916 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_CNF_RCVD
);
917 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
918 eloop_register_timeout(
919 conf
->dot11MeshConfirmTimeout
/ 1000,
920 (conf
->dot11MeshConfirmTimeout
% 1000) * 1000,
921 plink_timer
, wpa_s
, sta
);
932 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
935 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
937 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
938 eloop_register_timeout(
939 conf
->dot11MeshHoldingTimeout
/ 1000,
940 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
941 plink_timer
, wpa_s
, sta
);
942 sta
->mpm_close_reason
= reason
;
943 mesh_mpm_send_plink_action(wpa_s
, sta
,
944 PLINK_CLOSE
, reason
);
947 mesh_mpm_send_plink_action(wpa_s
, sta
,
951 if (conf
->security
& MESH_CONF_SEC_AMPE
)
952 mesh_rsn_derive_mtk(wpa_s
, sta
);
953 mesh_mpm_plink_estab(wpa_s
, sta
);
964 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
967 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
969 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
970 eloop_register_timeout(
971 conf
->dot11MeshHoldingTimeout
/ 1000,
972 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
973 plink_timer
, wpa_s
, sta
);
974 sta
->mpm_close_reason
= reason
;
975 mesh_mpm_send_plink_action(wpa_s
, sta
,
976 PLINK_CLOSE
, reason
);
979 if (conf
->security
& MESH_CONF_SEC_AMPE
)
980 mesh_rsn_derive_mtk(wpa_s
, sta
);
981 mesh_mpm_plink_estab(wpa_s
, sta
);
982 mesh_mpm_send_plink_action(wpa_s
, sta
,
994 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
996 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
998 eloop_register_timeout(
999 conf
->dot11MeshHoldingTimeout
/ 1000,
1000 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
1001 plink_timer
, wpa_s
, sta
);
1002 sta
->mpm_close_reason
= reason
;
1004 wpa_msg(wpa_s
, MSG_INFO
, "mesh plink with " MACSTR
1005 " closed with reason %d",
1006 MAC2STR(sta
->addr
), reason
);
1008 wpa_msg(wpa_s
, MSG_INFO
, MESH_PEER_DISCONNECTED MACSTR
,
1009 MAC2STR(sta
->addr
));
1013 mesh_mpm_send_plink_action(wpa_s
, sta
,
1014 PLINK_CLOSE
, reason
);
1017 mesh_mpm_send_plink_action(wpa_s
, sta
,
1027 mesh_mpm_fsm_restart(wpa_s
, sta
);
1033 reason
= sta
->mpm_close_reason
;
1034 mesh_mpm_send_plink_action(wpa_s
, sta
,
1035 PLINK_CLOSE
, reason
);
1042 wpa_msg(wpa_s
, MSG_DEBUG
,
1043 "Unsupported MPM event %s for state %s",
1044 mplevent
[event
], mplstate
[sta
->plink_state
]);
1050 void mesh_mpm_action_rx(struct wpa_supplicant
*wpa_s
,
1051 const struct ieee80211_mgmt
*mgmt
, size_t len
)
1054 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
1055 struct mesh_conf
*mconf
= wpa_s
->ifmsh
->mconf
;
1056 struct sta_info
*sta
;
1057 u16 plid
= 0, llid
= 0, aid
= 0;
1058 enum plink_event event
;
1059 struct ieee802_11_elems elems
;
1060 struct mesh_peer_mgmt_ie peer_mgmt_ie
;
1066 if (mgmt
->u
.action
.category
!= WLAN_ACTION_SELF_PROTECTED
)
1069 action_field
= mgmt
->u
.action
.u
.slf_prot_action
.action
;
1070 if (action_field
!= PLINK_OPEN
&&
1071 action_field
!= PLINK_CONFIRM
&&
1072 action_field
!= PLINK_CLOSE
)
1075 ies
= mgmt
->u
.action
.u
.slf_prot_action
.variable
;
1076 ie_len
= (const u8
*) mgmt
+ len
-
1077 mgmt
->u
.action
.u
.slf_prot_action
.variable
;
1079 /* at least expect mesh id and peering mgmt */
1080 if (ie_len
< 2 + 2) {
1081 wpa_printf(MSG_DEBUG
,
1082 "MPM: Ignore too short action frame %u ie_len %u",
1083 action_field
, (unsigned int) ie_len
);
1086 wpa_printf(MSG_DEBUG
, "MPM: Received PLINK action %u", action_field
);
1088 if (action_field
== PLINK_OPEN
|| action_field
== PLINK_CONFIRM
) {
1089 wpa_printf(MSG_DEBUG
, "MPM: Capability 0x%x",
1091 ies
+= 2; /* capability */
1094 if (action_field
== PLINK_CONFIRM
) {
1095 aid
= WPA_GET_LE16(ies
);
1096 wpa_printf(MSG_DEBUG
, "MPM: AID 0x%x", aid
);
1101 /* check for mesh peering, mesh id and mesh config IEs */
1102 if (ieee802_11_parse_elems(ies
, ie_len
, &elems
, 0) == ParseFailed
) {
1103 wpa_printf(MSG_DEBUG
, "MPM: Failed to parse PLINK IEs");
1106 if (!elems
.peer_mgmt
) {
1107 wpa_printf(MSG_DEBUG
,
1108 "MPM: No Mesh Peering Management element");
1111 if (action_field
!= PLINK_CLOSE
) {
1112 if (!elems
.mesh_id
|| !elems
.mesh_config
) {
1113 wpa_printf(MSG_DEBUG
,
1114 "MPM: No Mesh ID or Mesh Configuration element");
1118 if (!matches_local(wpa_s
, &elems
)) {
1119 wpa_printf(MSG_DEBUG
,
1120 "MPM: Mesh ID or Mesh Configuration element do not match local MBSS");
1125 ret
= mesh_mpm_parse_peer_mgmt(wpa_s
, action_field
,
1127 elems
.peer_mgmt_len
,
1130 wpa_printf(MSG_DEBUG
, "MPM: Mesh parsing rejected frame");
1134 /* the sender's llid is our plid and vice-versa */
1135 plid
= WPA_GET_LE16(peer_mgmt_ie
.llid
);
1136 if (peer_mgmt_ie
.plid
)
1137 llid
= WPA_GET_LE16(peer_mgmt_ie
.plid
);
1138 wpa_printf(MSG_DEBUG
, "MPM: plid=0x%x llid=0x%x", plid
, llid
);
1140 if (action_field
== PLINK_CLOSE
)
1141 wpa_printf(MSG_DEBUG
, "MPM: close reason=%u",
1142 WPA_GET_LE16(peer_mgmt_ie
.reason
));
1144 sta
= ap_get_sta(hapd
, mgmt
->sa
);
1147 * If this is an open frame from an unknown STA, and this is an
1148 * open mesh, then go ahead and add the peer before proceeding.
1150 if (!sta
&& action_field
== PLINK_OPEN
&&
1151 (!(mconf
->security
& MESH_CONF_SEC_AMPE
) ||
1152 wpa_auth_pmksa_get(hapd
->wpa_auth
, mgmt
->sa
, NULL
)))
1153 sta
= mesh_mpm_add_peer(wpa_s
, mgmt
->sa
, &elems
);
1156 wpa_printf(MSG_DEBUG
, "MPM: No STA entry for peer");
1161 /* peer is in sae_accepted? */
1162 if (sta
->sae
&& sta
->sae
->state
!= SAE_ACCEPTED
) {
1163 wpa_printf(MSG_DEBUG
, "MPM: SAE not yet accepted for peer");
1166 #endif /* CONFIG_SAE */
1169 mesh_mpm_init_link(wpa_s
, sta
);
1171 if (mconf
->security
& MESH_CONF_SEC_AMPE
) {
1174 res
= mesh_rsn_process_ampe(wpa_s
, sta
, &elems
,
1175 &mgmt
->u
.action
.category
,
1176 peer_mgmt_ie
.chosen_pmk
,
1179 wpa_printf(MSG_DEBUG
,
1180 "MPM: RSN process rejected frame (res=%d)",
1182 if (action_field
== PLINK_OPEN
&& res
== -2) {
1183 /* AES-SIV decryption failed */
1184 mesh_mpm_fsm(wpa_s
, sta
, OPN_RJCT
,
1185 WLAN_REASON_MESH_INVALID_GTK
);
1191 if (sta
->plink_state
== PLINK_BLOCKED
) {
1192 wpa_printf(MSG_DEBUG
, "MPM: PLINK_BLOCKED");
1196 /* Now we will figure out the appropriate event... */
1197 switch (action_field
) {
1199 if (plink_free_count(hapd
) == 0) {
1201 reason
= WLAN_REASON_MESH_MAX_PEERS
;
1202 wpa_printf(MSG_INFO
,
1203 "MPM: Peer link num over quota(%d)",
1205 } else if (sta
->peer_lid
&& sta
->peer_lid
!= plid
) {
1206 wpa_printf(MSG_DEBUG
,
1207 "MPM: peer_lid mismatch: 0x%x != 0x%x",
1208 sta
->peer_lid
, plid
);
1209 return; /* no FSM event */
1211 sta
->peer_lid
= plid
;
1216 if (plink_free_count(hapd
) == 0) {
1218 reason
= WLAN_REASON_MESH_MAX_PEERS
;
1219 wpa_printf(MSG_INFO
,
1220 "MPM: Peer link num over quota(%d)",
1222 } else if (sta
->my_lid
!= llid
||
1223 (sta
->peer_lid
&& sta
->peer_lid
!= plid
)) {
1224 wpa_printf(MSG_DEBUG
,
1225 "MPM: lid mismatch: my_lid: 0x%x != 0x%x or peer_lid: 0x%x != 0x%x",
1226 sta
->my_lid
, llid
, sta
->peer_lid
, plid
);
1227 return; /* no FSM event */
1230 sta
->peer_lid
= plid
;
1231 sta
->peer_aid
= aid
;
1236 if (sta
->plink_state
== PLINK_ESTAB
)
1237 /* Do not check for llid or plid. This does not
1238 * follow the standard but since multiple plinks
1239 * per cand are not supported, it is necessary in
1240 * order to avoid a livelock when MP A sees an
1241 * establish peer link to MP B but MP B does not
1242 * see it. This can be caused by a timeout in
1243 * B's peer link establishment or B being
1247 else if (sta
->peer_lid
!= plid
) {
1248 wpa_printf(MSG_DEBUG
,
1249 "MPM: peer_lid mismatch: 0x%x != 0x%x",
1250 sta
->peer_lid
, plid
);
1251 return; /* no FSM event */
1252 } else if (peer_mgmt_ie
.plid
&& sta
->my_lid
!= llid
) {
1253 wpa_printf(MSG_DEBUG
,
1254 "MPM: my_lid mismatch: 0x%x != 0x%x",
1256 return; /* no FSM event */
1263 * This cannot be hit due to the action_field check above, but
1264 * compilers may not be able to figure that out and can warn
1265 * about uninitialized event below.
1269 mesh_mpm_fsm(wpa_s
, sta
, event
, reason
);
1273 /* called by ap_free_sta */
1274 void mesh_mpm_free_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1276 if (sta
->plink_state
== PLINK_ESTAB
)
1278 eloop_cancel_timeout(plink_timer
, ELOOP_ALL_CTX
, sta
);
1279 eloop_cancel_timeout(mesh_auth_timer
, ELOOP_ALL_CTX
, sta
);