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 "common/ocv.h"
16 #include "ap/hostapd.h"
17 #include "ap/sta_info.h"
18 #include "ap/ieee802_11.h"
19 #include "ap/wpa_auth.h"
20 #include "wpa_supplicant_i.h"
26 struct mesh_peer_mgmt_ie
{
27 const u8
*proto_id
; /* Mesh Peering Protocol Identifier (2 octets) */
28 const u8
*llid
; /* Local Link ID (2 octets) */
29 const u8
*plid
; /* Peer Link ID (conditional, 2 octets) */
30 const u8
*reason
; /* Reason Code (conditional, 2 octets) */
31 const u8
*chosen_pmk
; /* Chosen PMK (optional, 16 octets) */
34 static void plink_timer(void *eloop_ctx
, void *user_data
);
47 static const char * const mplstate
[] = {
48 [0] = "UNINITIALIZED",
49 [PLINK_IDLE
] = "IDLE",
50 [PLINK_OPN_SNT
] = "OPN_SNT",
51 [PLINK_OPN_RCVD
] = "OPN_RCVD",
52 [PLINK_CNF_RCVD
] = "CNF_RCVD",
53 [PLINK_ESTAB
] = "ESTAB",
54 [PLINK_HOLDING
] = "HOLDING",
55 [PLINK_BLOCKED
] = "BLOCKED"
58 static const char * const mplevent
[] = {
59 [PLINK_UNDEFINED
] = "UNDEFINED",
60 [OPN_ACPT
] = "OPN_ACPT",
61 [OPN_RJCT
] = "OPN_RJCT",
62 [CNF_ACPT
] = "CNF_ACPT",
63 [CNF_RJCT
] = "CNF_RJCT",
64 [CLS_ACPT
] = "CLS_ACPT",
65 [REQ_RJCT
] = "REQ_RJCT",
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
));
200 * We do not use wpa_mesh_set_plink_state() here because there is no
201 * entry in kernel yet.
203 sta
->plink_state
= PLINK_IDLE
;
207 static void mesh_mpm_send_plink_action(struct wpa_supplicant
*wpa_s
,
208 struct sta_info
*sta
,
209 enum plink_action_field type
,
213 struct hostapd_iface
*ifmsh
= wpa_s
->ifmsh
;
214 struct hostapd_data
*bss
= ifmsh
->bss
[0];
215 struct mesh_conf
*conf
= ifmsh
->mconf
;
216 u8 supp_rates
[2 + 2 + 32];
218 u8 ie_len
, add_plid
= 0;
220 int ampe
= conf
->security
& MESH_CONF_SEC_AMPE
;
226 buf_len
= 2 + /* Category and Action */
227 2 + /* capability info */
229 2 + 8 + /* supported rates */
231 2 + 32 + /* mesh ID */
232 2 + 7 + /* mesh config */
233 2 + 24 + /* 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 #ifdef CONFIG_IEEE80211AC
243 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_vht_enabled
) {
244 buf_len
+= 2 + 12 + /* VHT Capabilities */
245 2 + 5; /* VHT Operation */
247 #endif /* CONFIG_IEEE80211AC */
248 if (type
!= PLINK_CLOSE
)
249 buf_len
+= conf
->rsn_ie_len
; /* RSN IE */
251 /* OCI is included even when the other STA doesn't support OCV */
252 if (type
!= PLINK_CLOSE
&& conf
->ocv
)
253 buf_len
+= OCV_OCI_EXTENDED_LEN
;
254 #endif /* CONFIG_OCV */
256 buf
= wpabuf_alloc(buf_len
);
260 cat
= wpabuf_mhead_u8(buf
);
261 wpabuf_put_u8(buf
, WLAN_ACTION_SELF_PROTECTED
);
262 wpabuf_put_u8(buf
, type
);
264 if (type
!= PLINK_CLOSE
) {
267 /* capability info */
268 wpabuf_put_le16(buf
, ampe
? IEEE80211_CAP_PRIVACY
: 0);
271 if (type
== PLINK_CONFIRM
)
272 wpabuf_put_le16(buf
, sta
->aid
);
274 /* IE: supp + ext. supp rates */
275 pos
= hostapd_eid_supp_rates(bss
, supp_rates
);
276 pos
= hostapd_eid_ext_supp_rates(bss
, pos
);
277 wpabuf_put_data(buf
, supp_rates
, pos
- supp_rates
);
280 wpabuf_put_data(buf
, conf
->rsn_ie
, conf
->rsn_ie_len
);
283 wpabuf_put_u8(buf
, WLAN_EID_MESH_ID
);
284 wpabuf_put_u8(buf
, conf
->meshid_len
);
285 wpabuf_put_data(buf
, conf
->meshid
, conf
->meshid_len
);
288 wpabuf_put_u8(buf
, WLAN_EID_MESH_CONFIG
);
289 wpabuf_put_u8(buf
, 7);
290 wpabuf_put_u8(buf
, conf
->mesh_pp_id
);
291 wpabuf_put_u8(buf
, conf
->mesh_pm_id
);
292 wpabuf_put_u8(buf
, conf
->mesh_cc_id
);
293 wpabuf_put_u8(buf
, conf
->mesh_sp_id
);
294 wpabuf_put_u8(buf
, conf
->mesh_auth_id
);
295 info
= (bss
->num_plinks
> 63 ? 63 : bss
->num_plinks
) << 1;
296 /* TODO: Add Connected to Mesh Gate/AS subfields */
297 wpabuf_put_u8(buf
, info
);
298 /* always forwarding & accepting plinks for now */
299 wpabuf_put_u8(buf
, MESH_CAP_ACCEPT_ADDITIONAL_PEER
|
300 MESH_CAP_FORWARDING
);
301 } else { /* Peer closing frame */
303 wpabuf_put_u8(buf
, WLAN_EID_MESH_ID
);
304 wpabuf_put_u8(buf
, conf
->meshid_len
);
305 wpabuf_put_data(buf
, conf
->meshid
, conf
->meshid_len
);
308 /* IE: Mesh Peering Management element */
322 ie_len
+= 2; /* reason code */
326 wpabuf_put_u8(buf
, WLAN_EID_PEER_MGMT
);
327 wpabuf_put_u8(buf
, ie_len
);
328 /* peering protocol */
330 wpabuf_put_le16(buf
, 1);
332 wpabuf_put_le16(buf
, 0);
333 wpabuf_put_le16(buf
, sta
->my_lid
);
335 wpabuf_put_le16(buf
, sta
->peer_lid
);
336 if (type
== PLINK_CLOSE
)
337 wpabuf_put_le16(buf
, close_reason
);
339 if (sta
->sae
== NULL
) {
340 wpa_msg(wpa_s
, MSG_INFO
, "Mesh MPM: no SAE session");
343 mesh_rsn_get_pmkid(wpa_s
->mesh_rsn
, sta
,
344 wpabuf_put(buf
, PMKID_LEN
));
347 #ifdef CONFIG_IEEE80211N
348 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_ht_enabled
) {
349 u8 ht_capa_oper
[2 + 26 + 2 + 22];
351 pos
= hostapd_eid_ht_capabilities(bss
, ht_capa_oper
);
352 pos
= hostapd_eid_ht_operation(bss
, pos
);
353 wpabuf_put_data(buf
, ht_capa_oper
, pos
- ht_capa_oper
);
355 #endif /* CONFIG_IEEE80211N */
356 #ifdef CONFIG_IEEE80211AC
357 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_vht_enabled
) {
358 u8 vht_capa_oper
[2 + 12 + 2 + 5];
360 pos
= hostapd_eid_vht_capabilities(bss
, vht_capa_oper
, 0);
361 pos
= hostapd_eid_vht_operation(bss
, pos
);
362 wpabuf_put_data(buf
, vht_capa_oper
, pos
- vht_capa_oper
);
364 #endif /* CONFIG_IEEE80211AC */
367 if (type
!= PLINK_CLOSE
&& conf
->ocv
) {
368 struct wpa_channel_info ci
;
370 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
371 wpa_printf(MSG_WARNING
,
372 "Mesh MPM: Failed to get channel info for OCI element");
376 pos
= wpabuf_put(buf
, OCV_OCI_EXTENDED_LEN
);
377 if (ocv_insert_extended_oci(&ci
, pos
) < 0)
380 #endif /* CONFIG_OCV */
382 if (ampe
&& mesh_rsn_protect_frame(wpa_s
->mesh_rsn
, sta
, cat
, buf
)) {
383 wpa_msg(wpa_s
, MSG_INFO
,
384 "Mesh MPM: failed to add AMPE and MIC IE");
388 wpa_msg(wpa_s
, MSG_DEBUG
, "Mesh MPM: Sending peering frame type %d to "
389 MACSTR
" (my_lid=0x%x peer_lid=0x%x)",
390 type
, MAC2STR(sta
->addr
), sta
->my_lid
, sta
->peer_lid
);
391 ret
= wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0,
392 sta
->addr
, wpa_s
->own_addr
, wpa_s
->own_addr
,
393 wpabuf_head(buf
), wpabuf_len(buf
), 0);
395 wpa_msg(wpa_s
, MSG_INFO
,
396 "Mesh MPM: failed to send peering frame");
403 /* configure peering state in ours and driver's station entry */
404 void wpa_mesh_set_plink_state(struct wpa_supplicant
*wpa_s
,
405 struct sta_info
*sta
,
406 enum mesh_plink_state state
)
408 struct hostapd_sta_add_params params
;
411 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM set " MACSTR
" from %s into %s",
412 MAC2STR(sta
->addr
), mplstate
[sta
->plink_state
],
414 sta
->plink_state
= state
;
416 os_memset(¶ms
, 0, sizeof(params
));
417 params
.addr
= sta
->addr
;
418 params
.plink_state
= state
;
419 params
.peer_aid
= sta
->peer_aid
;
422 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
424 wpa_msg(wpa_s
, MSG_ERROR
, "Driver failed to set " MACSTR
425 ": %d", MAC2STR(sta
->addr
), ret
);
430 static void mesh_mpm_fsm_restart(struct wpa_supplicant
*wpa_s
,
431 struct sta_info
*sta
)
433 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
435 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
437 ap_free_sta(hapd
, sta
);
441 static void plink_timer(void *eloop_ctx
, void *user_data
)
443 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
444 struct sta_info
*sta
= user_data
;
446 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
447 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
449 switch (sta
->plink_state
) {
453 if (sta
->mpm_retries
< conf
->dot11MeshMaxRetries
) {
454 eloop_register_timeout(
455 conf
->dot11MeshRetryTimeout
/ 1000,
456 (conf
->dot11MeshRetryTimeout
% 1000) * 1000,
457 plink_timer
, wpa_s
, sta
);
458 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_OPEN
, 0);
462 reason
= WLAN_REASON_MESH_MAX_RETRIES
;
468 reason
= WLAN_REASON_MESH_CONFIRM_TIMEOUT
;
469 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
470 eloop_register_timeout(conf
->dot11MeshHoldingTimeout
/ 1000,
471 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
472 plink_timer
, wpa_s
, sta
);
473 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CLOSE
, reason
);
478 if (sta
->mesh_sae_pmksa_caching
) {
479 wpa_printf(MSG_DEBUG
, "MPM: Peer " MACSTR
480 " looks like it does not support mesh SAE PMKSA caching, so remove the cached entry for it",
482 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
484 mesh_mpm_fsm_restart(wpa_s
, sta
);
492 /* initiate peering with station */
494 mesh_mpm_plink_open(struct wpa_supplicant
*wpa_s
, struct sta_info
*sta
,
495 enum mesh_plink_state next_state
)
497 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
499 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
500 eloop_register_timeout(conf
->dot11MeshRetryTimeout
/ 1000,
501 (conf
->dot11MeshRetryTimeout
% 1000) * 1000,
502 plink_timer
, wpa_s
, sta
);
503 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_OPEN
, 0);
504 wpa_mesh_set_plink_state(wpa_s
, sta
, next_state
);
508 static int mesh_mpm_plink_close(struct hostapd_data
*hapd
, struct sta_info
*sta
,
511 struct wpa_supplicant
*wpa_s
= ctx
;
512 int reason
= WLAN_REASON_MESH_PEERING_CANCELLED
;
515 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
516 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CLOSE
, reason
);
517 wpa_printf(MSG_DEBUG
, "MPM closing plink sta=" MACSTR
,
519 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
527 int mesh_mpm_close_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
529 struct hostapd_data
*hapd
;
530 struct sta_info
*sta
;
533 wpa_msg(wpa_s
, MSG_INFO
, "Mesh is not prepared yet");
537 hapd
= wpa_s
->ifmsh
->bss
[0];
538 sta
= ap_get_sta(hapd
, addr
);
540 wpa_msg(wpa_s
, MSG_INFO
, "No such mesh peer");
544 return mesh_mpm_plink_close(hapd
, sta
, wpa_s
) == 0 ? 0 : -1;
548 static void peer_add_timer(void *eloop_ctx
, void *user_data
)
550 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
551 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
553 os_memset(hapd
->mesh_required_peer
, 0, ETH_ALEN
);
557 int mesh_mpm_connect_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
560 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
561 struct hostapd_data
*hapd
;
562 struct sta_info
*sta
;
563 struct mesh_conf
*conf
;
566 wpa_msg(wpa_s
, MSG_INFO
, "Mesh is not prepared yet");
570 if (!ssid
|| !ssid
->no_auto_peer
) {
571 wpa_msg(wpa_s
, MSG_INFO
,
572 "This command is available only with no_auto_peer mesh network");
576 hapd
= wpa_s
->ifmsh
->bss
[0];
577 conf
= wpa_s
->ifmsh
->mconf
;
579 sta
= ap_get_sta(hapd
, addr
);
581 wpa_msg(wpa_s
, MSG_INFO
, "No such mesh peer");
585 if ((PLINK_OPN_SNT
<= sta
->plink_state
&&
586 sta
->plink_state
<= PLINK_ESTAB
) ||
587 (sta
->sae
&& sta
->sae
->state
> SAE_NOTHING
)) {
588 wpa_msg(wpa_s
, MSG_INFO
,
589 "Specified peer is connecting/connected");
593 if (conf
->security
== MESH_CONF_SEC_NONE
) {
594 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPN_SNT
);
596 mesh_rsn_auth_sae_sta(wpa_s
, sta
);
597 os_memcpy(hapd
->mesh_required_peer
, addr
, ETH_ALEN
);
598 eloop_register_timeout(duration
== -1 ? 10 : duration
, 0,
599 peer_add_timer
, wpa_s
, NULL
);
606 void mesh_mpm_deinit(struct wpa_supplicant
*wpa_s
, struct hostapd_iface
*ifmsh
)
608 struct hostapd_data
*hapd
= ifmsh
->bss
[0];
610 /* notify peers we're leaving */
611 ap_for_each_sta(hapd
, mesh_mpm_plink_close
, wpa_s
);
613 hapd
->num_plinks
= 0;
614 hostapd_free_stas(hapd
);
615 eloop_cancel_timeout(peer_add_timer
, wpa_s
, NULL
);
619 /* for mesh_rsn to indicate this peer has completed authentication, and we're
620 * ready to start AMPE */
621 void mesh_mpm_auth_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
623 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
624 struct hostapd_sta_add_params params
;
625 struct sta_info
*sta
;
628 sta
= ap_get_sta(data
, addr
);
630 wpa_msg(wpa_s
, MSG_DEBUG
, "no such mesh peer");
634 /* TODO: Should do nothing if this STA is already authenticated, but
635 * the AP code already sets this flag. */
636 sta
->flags
|= WLAN_STA_AUTH
;
638 mesh_rsn_init_ampe_sta(wpa_s
, sta
);
640 os_memset(¶ms
, 0, sizeof(params
));
641 params
.addr
= sta
->addr
;
642 params
.flags
= WPA_STA_AUTHENTICATED
| WPA_STA_AUTHORIZED
;
645 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM authenticating " MACSTR
,
647 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
649 wpa_msg(wpa_s
, MSG_ERROR
,
650 "Driver failed to set " MACSTR
": %d",
651 MAC2STR(sta
->addr
), ret
);
655 mesh_mpm_init_link(wpa_s
, sta
);
657 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPN_SNT
);
661 * Initialize a sta_info structure for a peer and upload it into the driver
662 * in preparation for beginning authentication or peering. This is done when a
663 * Beacon (secure or open mesh) or a peering open frame (for open mesh) is
664 * received from the peer for the first time.
666 static struct sta_info
* mesh_mpm_add_peer(struct wpa_supplicant
*wpa_s
,
668 struct ieee802_11_elems
*elems
)
670 struct hostapd_sta_add_params params
;
671 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
672 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
673 struct sta_info
*sta
;
674 #ifdef CONFIG_IEEE80211N
675 struct ieee80211_ht_operation
*oper
;
676 #endif /* CONFIG_IEEE80211N */
679 if (elems
->mesh_config_len
>= 7 &&
680 !(elems
->mesh_config
[6] & MESH_CAP_ACCEPT_ADDITIONAL_PEER
)) {
681 wpa_msg(wpa_s
, MSG_DEBUG
,
682 "mesh: Ignore a crowded peer " MACSTR
,
687 sta
= ap_get_sta(data
, addr
);
689 sta
= ap_sta_add(data
, addr
);
694 /* Set WMM by default since Mesh STAs are QoS STAs */
695 sta
->flags
|= WLAN_STA_WMM
;
698 if (copy_supp_rates(wpa_s
, sta
, elems
)) {
699 ap_free_sta(data
, sta
);
704 mesh_mpm_init_link(wpa_s
, sta
);
706 #ifdef CONFIG_IEEE80211N
707 copy_sta_ht_capab(data
, sta
, elems
->ht_capabilities
);
709 oper
= (struct ieee80211_ht_operation
*) elems
->ht_operation
;
711 !(oper
->ht_param
& HT_INFO_HT_PARAM_STA_CHNL_WIDTH
) &&
712 sta
->ht_capabilities
) {
713 wpa_msg(wpa_s
, MSG_DEBUG
, MACSTR
714 " does not support 40 MHz bandwidth",
716 set_disable_ht40(sta
->ht_capabilities
, 1);
719 update_ht_state(data
, sta
);
720 #endif /* CONFIG_IEEE80211N */
722 #ifdef CONFIG_IEEE80211AC
723 copy_sta_vht_capab(data
, sta
, elems
->vht_capabilities
);
724 copy_sta_vht_oper(data
, sta
, elems
->vht_operation
);
725 set_sta_vht_opmode(data
, sta
, elems
->vht_opmode_notif
);
726 #endif /* CONFIG_IEEE80211AC */
728 if (hostapd_get_aid(data
, sta
) < 0) {
729 wpa_msg(wpa_s
, MSG_ERROR
, "No AIDs available");
730 ap_free_sta(data
, sta
);
734 /* insert into driver */
735 os_memset(¶ms
, 0, sizeof(params
));
736 params
.supp_rates
= sta
->supported_rates
;
737 params
.supp_rates_len
= sta
->supported_rates_len
;
739 params
.plink_state
= sta
->plink_state
;
740 params
.aid
= sta
->aid
;
741 params
.peer_aid
= sta
->peer_aid
;
742 params
.listen_interval
= 100;
743 params
.ht_capabilities
= sta
->ht_capabilities
;
744 params
.vht_capabilities
= sta
->vht_capabilities
;
745 params
.flags
|= WPA_STA_WMM
;
746 params
.flags_mask
|= WPA_STA_AUTHENTICATED
;
747 if (conf
->security
== MESH_CONF_SEC_NONE
) {
748 params
.flags
|= WPA_STA_AUTHORIZED
;
749 params
.flags
|= WPA_STA_AUTHENTICATED
;
751 sta
->flags
|= WLAN_STA_MFP
;
752 params
.flags
|= WPA_STA_MFP
;
755 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
757 wpa_msg(wpa_s
, MSG_ERROR
,
758 "Driver failed to insert " MACSTR
": %d",
760 ap_free_sta(data
, sta
);
768 void wpa_mesh_new_mesh_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
769 struct ieee802_11_elems
*elems
)
771 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
772 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
773 struct sta_info
*sta
;
774 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
776 sta
= mesh_mpm_add_peer(wpa_s
, addr
, elems
);
780 if (ssid
&& ssid
->no_auto_peer
&&
781 (is_zero_ether_addr(data
->mesh_required_peer
) ||
782 os_memcmp(data
->mesh_required_peer
, addr
, ETH_ALEN
) != 0)) {
783 wpa_msg(wpa_s
, MSG_INFO
, "will not initiate new peer link with "
784 MACSTR
" because of no_auto_peer", MAC2STR(addr
));
785 if (data
->mesh_pending_auth
) {
786 struct os_reltime age
;
787 const struct ieee80211_mgmt
*mgmt
;
788 struct hostapd_frame_info fi
;
790 mgmt
= wpabuf_head(data
->mesh_pending_auth
);
791 os_reltime_age(&data
->mesh_pending_auth_time
, &age
);
793 os_memcmp(mgmt
->sa
, addr
, ETH_ALEN
) == 0) {
794 wpa_printf(MSG_DEBUG
,
795 "mesh: Process pending Authentication frame from %u.%06u seconds ago",
796 (unsigned int) age
.sec
,
797 (unsigned int) age
.usec
);
798 os_memset(&fi
, 0, sizeof(fi
));
801 wpabuf_head(data
->mesh_pending_auth
),
802 wpabuf_len(data
->mesh_pending_auth
),
805 wpabuf_free(data
->mesh_pending_auth
);
806 data
->mesh_pending_auth
= NULL
;
811 if (conf
->security
== MESH_CONF_SEC_NONE
) {
812 if (sta
->plink_state
< PLINK_OPN_SNT
||
813 sta
->plink_state
> PLINK_ESTAB
)
814 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPN_SNT
);
816 mesh_rsn_auth_sae_sta(wpa_s
, sta
);
821 void mesh_mpm_mgmt_rx(struct wpa_supplicant
*wpa_s
, struct rx_mgmt
*rx_mgmt
)
823 struct hostapd_frame_info fi
;
825 os_memset(&fi
, 0, sizeof(fi
));
826 fi
.datarate
= rx_mgmt
->datarate
;
827 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
828 ieee802_11_mgmt(wpa_s
->ifmsh
->bss
[0], rx_mgmt
->frame
,
829 rx_mgmt
->frame_len
, &fi
);
833 static void mesh_mpm_plink_estab(struct wpa_supplicant
*wpa_s
,
834 struct sta_info
*sta
)
836 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
837 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
840 wpa_msg(wpa_s
, MSG_INFO
, "mesh plink with " MACSTR
" established",
843 if (conf
->security
& MESH_CONF_SEC_AMPE
) {
844 wpa_hexdump_key(MSG_DEBUG
, "mesh: MTK", sta
->mtk
, sta
->mtk_len
);
845 wpa_drv_set_key(wpa_s
, wpa_cipher_to_alg(conf
->pairwise_cipher
),
846 sta
->addr
, 0, 0, seq
, sizeof(seq
),
847 sta
->mtk
, sta
->mtk_len
);
849 wpa_hexdump_key(MSG_DEBUG
, "mesh: RX MGTK Key RSC",
850 sta
->mgtk_rsc
, sizeof(sta
->mgtk_rsc
));
851 wpa_hexdump_key(MSG_DEBUG
, "mesh: RX MGTK",
852 sta
->mgtk
, sta
->mgtk_len
);
853 wpa_drv_set_key(wpa_s
, wpa_cipher_to_alg(conf
->group_cipher
),
854 sta
->addr
, sta
->mgtk_key_id
, 0,
855 sta
->mgtk_rsc
, sizeof(sta
->mgtk_rsc
),
856 sta
->mgtk
, sta
->mgtk_len
);
859 wpa_hexdump_key(MSG_DEBUG
, "mesh: RX IGTK Key RSC",
860 sta
->igtk_rsc
, sizeof(sta
->igtk_rsc
));
861 wpa_hexdump_key(MSG_DEBUG
, "mesh: RX IGTK",
862 sta
->igtk
, sta
->igtk_len
);
865 wpa_cipher_to_alg(conf
->mgmt_group_cipher
),
866 sta
->addr
, sta
->igtk_key_id
, 0,
867 sta
->igtk_rsc
, sizeof(sta
->igtk_rsc
),
868 sta
->igtk
, sta
->igtk_len
);
872 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_ESTAB
);
875 sta
->flags
|= WLAN_STA_ASSOC
;
876 sta
->mesh_sae_pmksa_caching
= 0;
878 eloop_cancel_timeout(peer_add_timer
, wpa_s
, NULL
);
879 peer_add_timer(wpa_s
, NULL
);
880 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
882 /* Send ctrl event */
883 wpa_msg(wpa_s
, MSG_INFO
, MESH_PEER_CONNECTED MACSTR
,
886 /* Send D-Bus event */
887 wpas_notify_mesh_peer_connected(wpa_s
, sta
->addr
);
891 static void mesh_mpm_fsm(struct wpa_supplicant
*wpa_s
, struct sta_info
*sta
,
892 enum plink_event event
, u16 reason
)
894 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
895 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
897 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM " MACSTR
" state %s event %s",
898 MAC2STR(sta
->addr
), mplstate
[sta
->plink_state
],
901 switch (sta
->plink_state
) {
905 mesh_mpm_fsm_restart(wpa_s
, sta
);
908 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPN_RCVD
);
909 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CONFIRM
,
913 mesh_mpm_send_plink_action(wpa_s
, sta
,
914 PLINK_CLOSE
, reason
);
925 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
928 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
930 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
931 eloop_register_timeout(
932 conf
->dot11MeshHoldingTimeout
/ 1000,
933 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
934 plink_timer
, wpa_s
, sta
);
935 mesh_mpm_send_plink_action(wpa_s
, sta
,
936 PLINK_CLOSE
, reason
);
939 /* retry timer is left untouched */
940 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_OPN_RCVD
);
941 mesh_mpm_send_plink_action(wpa_s
, sta
,
945 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_CNF_RCVD
);
946 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
947 eloop_register_timeout(
948 conf
->dot11MeshConfirmTimeout
/ 1000,
949 (conf
->dot11MeshConfirmTimeout
% 1000) * 1000,
950 plink_timer
, wpa_s
, sta
);
961 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
964 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
966 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
967 eloop_register_timeout(
968 conf
->dot11MeshHoldingTimeout
/ 1000,
969 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
970 plink_timer
, wpa_s
, sta
);
971 sta
->mpm_close_reason
= reason
;
972 mesh_mpm_send_plink_action(wpa_s
, sta
,
973 PLINK_CLOSE
, reason
);
976 mesh_mpm_send_plink_action(wpa_s
, sta
,
980 if (conf
->security
& MESH_CONF_SEC_AMPE
)
981 mesh_rsn_derive_mtk(wpa_s
, sta
);
982 mesh_mpm_plink_estab(wpa_s
, sta
);
993 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
996 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
998 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
999 eloop_register_timeout(
1000 conf
->dot11MeshHoldingTimeout
/ 1000,
1001 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
1002 plink_timer
, wpa_s
, sta
);
1003 sta
->mpm_close_reason
= reason
;
1004 mesh_mpm_send_plink_action(wpa_s
, sta
,
1005 PLINK_CLOSE
, reason
);
1008 if (conf
->security
& MESH_CONF_SEC_AMPE
)
1009 mesh_rsn_derive_mtk(wpa_s
, sta
);
1010 mesh_mpm_plink_estab(wpa_s
, sta
);
1011 mesh_mpm_send_plink_action(wpa_s
, sta
,
1023 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
1025 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
1027 eloop_register_timeout(
1028 conf
->dot11MeshHoldingTimeout
/ 1000,
1029 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
1030 plink_timer
, wpa_s
, sta
);
1031 sta
->mpm_close_reason
= reason
;
1033 wpa_msg(wpa_s
, MSG_INFO
, "mesh plink with " MACSTR
1034 " closed with reason %d",
1035 MAC2STR(sta
->addr
), reason
);
1037 wpa_msg(wpa_s
, MSG_INFO
, MESH_PEER_DISCONNECTED MACSTR
,
1038 MAC2STR(sta
->addr
));
1040 /* Send D-Bus event */
1041 wpas_notify_mesh_peer_disconnected(wpa_s
, sta
->addr
,
1046 mesh_mpm_send_plink_action(wpa_s
, sta
,
1047 PLINK_CLOSE
, reason
);
1050 mesh_mpm_send_plink_action(wpa_s
, sta
,
1060 mesh_mpm_fsm_restart(wpa_s
, sta
);
1066 reason
= sta
->mpm_close_reason
;
1067 mesh_mpm_send_plink_action(wpa_s
, sta
,
1068 PLINK_CLOSE
, reason
);
1075 wpa_msg(wpa_s
, MSG_DEBUG
,
1076 "Unsupported MPM event %s for state %s",
1077 mplevent
[event
], mplstate
[sta
->plink_state
]);
1083 void mesh_mpm_action_rx(struct wpa_supplicant
*wpa_s
,
1084 const struct ieee80211_mgmt
*mgmt
, size_t len
)
1087 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
1088 struct mesh_conf
*mconf
= wpa_s
->ifmsh
->mconf
;
1089 struct sta_info
*sta
;
1090 u16 plid
= 0, llid
= 0, aid
= 0;
1091 enum plink_event event
;
1092 struct ieee802_11_elems elems
;
1093 struct mesh_peer_mgmt_ie peer_mgmt_ie
;
1099 if (mgmt
->u
.action
.category
!= WLAN_ACTION_SELF_PROTECTED
)
1102 action_field
= mgmt
->u
.action
.u
.slf_prot_action
.action
;
1103 if (action_field
!= PLINK_OPEN
&&
1104 action_field
!= PLINK_CONFIRM
&&
1105 action_field
!= PLINK_CLOSE
)
1108 ies
= mgmt
->u
.action
.u
.slf_prot_action
.variable
;
1109 ie_len
= (const u8
*) mgmt
+ len
-
1110 mgmt
->u
.action
.u
.slf_prot_action
.variable
;
1112 /* at least expect mesh id and peering mgmt */
1113 if (ie_len
< 2 + 2) {
1114 wpa_printf(MSG_DEBUG
,
1115 "MPM: Ignore too short action frame %u ie_len %u",
1116 action_field
, (unsigned int) ie_len
);
1119 wpa_printf(MSG_DEBUG
, "MPM: Received PLINK action %u", action_field
);
1121 if (action_field
== PLINK_OPEN
|| action_field
== PLINK_CONFIRM
) {
1122 wpa_printf(MSG_DEBUG
, "MPM: Capability 0x%x",
1124 ies
+= 2; /* capability */
1127 if (action_field
== PLINK_CONFIRM
) {
1128 aid
= WPA_GET_LE16(ies
);
1129 wpa_printf(MSG_DEBUG
, "MPM: AID 0x%x", aid
);
1134 /* check for mesh peering, mesh id and mesh config IEs */
1135 if (ieee802_11_parse_elems(ies
, ie_len
, &elems
, 0) == ParseFailed
) {
1136 wpa_printf(MSG_DEBUG
, "MPM: Failed to parse PLINK IEs");
1139 if (!elems
.peer_mgmt
) {
1140 wpa_printf(MSG_DEBUG
,
1141 "MPM: No Mesh Peering Management element");
1144 if (action_field
!= PLINK_CLOSE
) {
1145 if (!elems
.mesh_id
|| !elems
.mesh_config
) {
1146 wpa_printf(MSG_DEBUG
,
1147 "MPM: No Mesh ID or Mesh Configuration element");
1151 if (!matches_local(wpa_s
, &elems
)) {
1152 wpa_printf(MSG_DEBUG
,
1153 "MPM: Mesh ID or Mesh Configuration element do not match local MBSS");
1158 ret
= mesh_mpm_parse_peer_mgmt(wpa_s
, action_field
,
1160 elems
.peer_mgmt_len
,
1163 wpa_printf(MSG_DEBUG
, "MPM: Mesh parsing rejected frame");
1167 /* the sender's llid is our plid and vice-versa */
1168 plid
= WPA_GET_LE16(peer_mgmt_ie
.llid
);
1169 if (peer_mgmt_ie
.plid
)
1170 llid
= WPA_GET_LE16(peer_mgmt_ie
.plid
);
1171 wpa_printf(MSG_DEBUG
, "MPM: plid=0x%x llid=0x%x", plid
, llid
);
1173 if (action_field
== PLINK_CLOSE
)
1174 wpa_printf(MSG_DEBUG
, "MPM: close reason=%u",
1175 WPA_GET_LE16(peer_mgmt_ie
.reason
));
1177 sta
= ap_get_sta(hapd
, mgmt
->sa
);
1180 * If this is an open frame from an unknown STA, and this is an
1181 * open mesh, then go ahead and add the peer before proceeding.
1183 if (!sta
&& action_field
== PLINK_OPEN
&&
1184 (!(mconf
->security
& MESH_CONF_SEC_AMPE
) ||
1185 wpa_auth_pmksa_get(hapd
->wpa_auth
, mgmt
->sa
, NULL
)))
1186 sta
= mesh_mpm_add_peer(wpa_s
, mgmt
->sa
, &elems
);
1189 wpa_printf(MSG_DEBUG
, "MPM: No STA entry for peer");
1194 /* peer is in sae_accepted? */
1195 if (sta
->sae
&& sta
->sae
->state
!= SAE_ACCEPTED
) {
1196 wpa_printf(MSG_DEBUG
, "MPM: SAE not yet accepted for peer");
1199 #endif /* CONFIG_SAE */
1202 mesh_mpm_init_link(wpa_s
, sta
);
1204 if (mconf
->security
& MESH_CONF_SEC_AMPE
) {
1207 res
= mesh_rsn_process_ampe(wpa_s
, sta
, &elems
,
1208 &mgmt
->u
.action
.category
,
1209 peer_mgmt_ie
.chosen_pmk
,
1212 wpa_printf(MSG_DEBUG
,
1213 "MPM: RSN process rejected frame (res=%d)",
1215 if (action_field
== PLINK_OPEN
&& res
== -2) {
1216 /* AES-SIV decryption failed */
1217 mesh_mpm_fsm(wpa_s
, sta
, OPN_RJCT
,
1218 WLAN_REASON_MESH_INVALID_GTK
);
1224 if (action_field
== PLINK_OPEN
&& elems
.rsn_ie
) {
1225 struct wpa_state_machine
*sm
= sta
->wpa_sm
;
1226 struct wpa_ie_data data
;
1228 res
= wpa_parse_wpa_ie_rsn(elems
.rsn_ie
- 2,
1229 elems
.rsn_ie_len
+ 2,
1232 wpa_printf(MSG_DEBUG
,
1233 "Failed to parse RSN IE (res=%d)",
1235 wpa_hexdump(MSG_DEBUG
, "RSN IE", elems
.rsn_ie
,
1240 wpa_auth_set_ocv(sm
, mconf
->ocv
&&
1241 (data
.capabilities
&
1242 WPA_CAPABILITY_OCVC
));
1245 if (action_field
!= PLINK_CLOSE
&&
1246 wpa_auth_uses_ocv(sta
->wpa_sm
)) {
1247 struct wpa_channel_info ci
;
1251 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
1252 wpa_printf(MSG_WARNING
,
1253 "MPM: Failed to get channel info to validate received OCI in MPM Confirm");
1257 if (get_tx_parameters(
1258 sta
, channel_width_to_int(ci
.chanwidth
),
1259 ci
.seg1_idx
, &tx_chanwidth
,
1263 if (ocv_verify_tx_params(elems
.oci
, elems
.oci_len
, &ci
,
1264 tx_chanwidth
, tx_seg1_idx
) !=
1266 wpa_printf(MSG_WARNING
, "MPM: %s",
1271 #endif /* CONFIG_OCV */
1274 if (sta
->plink_state
== PLINK_BLOCKED
) {
1275 wpa_printf(MSG_DEBUG
, "MPM: PLINK_BLOCKED");
1279 /* Now we will figure out the appropriate event... */
1280 switch (action_field
) {
1282 if (plink_free_count(hapd
) == 0) {
1284 reason
= WLAN_REASON_MESH_MAX_PEERS
;
1285 wpa_printf(MSG_INFO
,
1286 "MPM: Peer link num over quota(%d)",
1288 } else if (sta
->peer_lid
&& sta
->peer_lid
!= plid
) {
1289 wpa_printf(MSG_DEBUG
,
1290 "MPM: peer_lid mismatch: 0x%x != 0x%x",
1291 sta
->peer_lid
, plid
);
1292 return; /* no FSM event */
1294 sta
->peer_lid
= plid
;
1299 if (plink_free_count(hapd
) == 0) {
1301 reason
= WLAN_REASON_MESH_MAX_PEERS
;
1302 wpa_printf(MSG_INFO
,
1303 "MPM: Peer link num over quota(%d)",
1305 } else if (sta
->my_lid
!= llid
||
1306 (sta
->peer_lid
&& sta
->peer_lid
!= plid
)) {
1307 wpa_printf(MSG_DEBUG
,
1308 "MPM: lid mismatch: my_lid: 0x%x != 0x%x or peer_lid: 0x%x != 0x%x",
1309 sta
->my_lid
, llid
, sta
->peer_lid
, plid
);
1310 return; /* no FSM event */
1313 sta
->peer_lid
= plid
;
1314 sta
->peer_aid
= aid
;
1319 if (sta
->plink_state
== PLINK_ESTAB
)
1320 /* Do not check for llid or plid. This does not
1321 * follow the standard but since multiple plinks
1322 * per cand are not supported, it is necessary in
1323 * order to avoid a livelock when MP A sees an
1324 * establish peer link to MP B but MP B does not
1325 * see it. This can be caused by a timeout in
1326 * B's peer link establishment or B being
1330 else if (sta
->peer_lid
!= plid
) {
1331 wpa_printf(MSG_DEBUG
,
1332 "MPM: peer_lid mismatch: 0x%x != 0x%x",
1333 sta
->peer_lid
, plid
);
1334 return; /* no FSM event */
1335 } else if (peer_mgmt_ie
.plid
&& sta
->my_lid
!= llid
) {
1336 wpa_printf(MSG_DEBUG
,
1337 "MPM: my_lid mismatch: 0x%x != 0x%x",
1339 return; /* no FSM event */
1346 * This cannot be hit due to the action_field check above, but
1347 * compilers may not be able to figure that out and can warn
1348 * about uninitialized event below.
1352 mesh_mpm_fsm(wpa_s
, sta
, event
, reason
);
1356 /* called by ap_free_sta */
1357 void mesh_mpm_free_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1359 if (sta
->plink_state
== PLINK_ESTAB
)
1361 eloop_cancel_timeout(plink_timer
, ELOOP_ALL_CTX
, sta
);
1362 eloop_cancel_timeout(mesh_auth_timer
, ELOOP_ALL_CTX
, sta
);