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 "ap/wpa_auth.h"
18 #include "wpa_supplicant_i.h"
23 struct mesh_peer_mgmt_ie
{
24 const u8
*proto_id
; /* Mesh Peering Protocol Identifier (2 octets) */
25 const u8
*llid
; /* Local Link ID (2 octets) */
26 const u8
*plid
; /* Peer Link ID (conditional, 2 octets) */
27 const u8
*reason
; /* Reason Code (conditional, 2 octets) */
28 const u8
*chosen_pmk
; /* Chosen PMK (optional, 16 octets) */
31 static void plink_timer(void *eloop_ctx
, void *user_data
);
44 static const char * const mplstate
[] = {
45 [0] = "UNINITIALIZED",
46 [PLINK_IDLE
] = "IDLE",
47 [PLINK_OPN_SNT
] = "OPN_SNT",
48 [PLINK_OPN_RCVD
] = "OPN_RCVD",
49 [PLINK_CNF_RCVD
] = "CNF_RCVD",
50 [PLINK_ESTAB
] = "ESTAB",
51 [PLINK_HOLDING
] = "HOLDING",
52 [PLINK_BLOCKED
] = "BLOCKED"
55 static const char * const mplevent
[] = {
56 [PLINK_UNDEFINED
] = "UNDEFINED",
57 [OPN_ACPT
] = "OPN_ACPT",
58 [OPN_RJCT
] = "OPN_RJCT",
59 [CNF_ACPT
] = "CNF_ACPT",
60 [CNF_RJCT
] = "CNF_RJCT",
61 [CLS_ACPT
] = "CLS_ACPT",
62 [REQ_RJCT
] = "REQ_RJCT",
66 static int mesh_mpm_parse_peer_mgmt(struct wpa_supplicant
*wpa_s
,
68 const u8
*ie
, size_t len
,
69 struct mesh_peer_mgmt_ie
*mpm_ie
)
71 os_memset(mpm_ie
, 0, sizeof(*mpm_ie
));
73 /* Remove optional Chosen PMK field at end */
74 if (len
>= SAE_PMKID_LEN
) {
75 mpm_ie
->chosen_pmk
= ie
+ len
- SAE_PMKID_LEN
;
79 if ((action_field
== PLINK_OPEN
&& len
!= 4) ||
80 (action_field
== PLINK_CONFIRM
&& len
!= 6) ||
81 (action_field
== PLINK_CLOSE
&& len
!= 6 && len
!= 8)) {
82 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM: Invalid peer mgmt ie");
89 mpm_ie
->proto_id
= ie
;
90 mpm_ie
->llid
= ie
+ 2;
94 /* close reason is always present at end for close */
95 if (action_field
== PLINK_CLOSE
) {
98 mpm_ie
->reason
= ie
+ len
- 2;
102 /* Peer Link ID, present for confirm, and possibly close */
110 static int plink_free_count(struct hostapd_data
*hapd
)
112 if (hapd
->max_plinks
> hapd
->num_plinks
)
113 return hapd
->max_plinks
- hapd
->num_plinks
;
118 static u16
copy_supp_rates(struct wpa_supplicant
*wpa_s
,
119 struct sta_info
*sta
,
120 struct ieee802_11_elems
*elems
)
122 if (!elems
->supp_rates
) {
123 wpa_msg(wpa_s
, MSG_ERROR
, "no supported rates from " MACSTR
,
125 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
128 if (elems
->supp_rates_len
+ elems
->ext_supp_rates_len
>
129 sizeof(sta
->supported_rates
)) {
130 wpa_msg(wpa_s
, MSG_ERROR
,
131 "Invalid supported rates element length " MACSTR
132 " %d+%d", MAC2STR(sta
->addr
), elems
->supp_rates_len
,
133 elems
->ext_supp_rates_len
);
134 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
137 sta
->supported_rates_len
= merge_byte_arrays(
138 sta
->supported_rates
, sizeof(sta
->supported_rates
),
139 elems
->supp_rates
, elems
->supp_rates_len
,
140 elems
->ext_supp_rates
, elems
->ext_supp_rates_len
);
142 return WLAN_STATUS_SUCCESS
;
146 /* return true if elems from a neighbor match this MBSS */
147 static Boolean
matches_local(struct wpa_supplicant
*wpa_s
,
148 struct ieee802_11_elems
*elems
)
150 struct mesh_conf
*mconf
= wpa_s
->ifmsh
->mconf
;
152 if (elems
->mesh_config_len
< 5)
155 return (mconf
->meshid_len
== elems
->mesh_id_len
&&
156 os_memcmp(mconf
->meshid
, elems
->mesh_id
,
157 elems
->mesh_id_len
) == 0 &&
158 mconf
->mesh_pp_id
== elems
->mesh_config
[0] &&
159 mconf
->mesh_pm_id
== elems
->mesh_config
[1] &&
160 mconf
->mesh_cc_id
== elems
->mesh_config
[2] &&
161 mconf
->mesh_sp_id
== elems
->mesh_config
[3] &&
162 mconf
->mesh_auth_id
== elems
->mesh_config
[4]);
166 /* check if local link id is already used with another peer */
167 static Boolean
llid_in_use(struct wpa_supplicant
*wpa_s
, u16 llid
)
169 struct sta_info
*sta
;
170 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
172 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
173 if (sta
->my_lid
== llid
)
181 /* generate an llid for a link and set to initial state */
182 static void mesh_mpm_init_link(struct wpa_supplicant
*wpa_s
,
183 struct sta_info
*sta
)
188 if (os_get_random((u8
*) &llid
, sizeof(llid
)) < 0)
190 } while (!llid
|| llid_in_use(wpa_s
, llid
));
197 * We do not use wpa_mesh_set_plink_state() here because there is no
198 * entry in kernel yet.
200 sta
->plink_state
= PLINK_IDLE
;
204 static void mesh_mpm_send_plink_action(struct wpa_supplicant
*wpa_s
,
205 struct sta_info
*sta
,
206 enum plink_action_field type
,
210 struct hostapd_iface
*ifmsh
= wpa_s
->ifmsh
;
211 struct hostapd_data
*bss
= ifmsh
->bss
[0];
212 struct mesh_conf
*conf
= ifmsh
->mconf
;
213 u8 supp_rates
[2 + 2 + 32];
215 u8 ie_len
, add_plid
= 0;
217 int ampe
= conf
->security
& MESH_CONF_SEC_AMPE
;
223 buf_len
= 2 + /* capability info */
225 2 + 8 + /* supported rates */
227 2 + 32 + /* mesh ID */
228 2 + 7 + /* mesh config */
229 2 + 23 + /* peering management */
232 #ifdef CONFIG_IEEE80211N
233 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_ht_enabled
) {
234 buf_len
+= 2 + 26 + /* HT capabilities */
235 2 + 22; /* HT operation */
237 #endif /* CONFIG_IEEE80211N */
238 #ifdef CONFIG_IEEE80211AC
239 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_vht_enabled
) {
240 buf_len
+= 2 + 12 + /* VHT Capabilities */
241 2 + 5; /* VHT Operation */
243 #endif /* CONFIG_IEEE80211AC */
244 if (type
!= PLINK_CLOSE
)
245 buf_len
+= conf
->rsn_ie_len
; /* RSN IE */
247 buf
= wpabuf_alloc(buf_len
);
251 cat
= wpabuf_mhead_u8(buf
);
252 wpabuf_put_u8(buf
, WLAN_ACTION_SELF_PROTECTED
);
253 wpabuf_put_u8(buf
, type
);
255 if (type
!= PLINK_CLOSE
) {
258 /* capability info */
259 wpabuf_put_le16(buf
, ampe
? IEEE80211_CAP_PRIVACY
: 0);
262 if (type
== PLINK_CONFIRM
)
263 wpabuf_put_le16(buf
, sta
->aid
);
265 /* IE: supp + ext. supp rates */
266 pos
= hostapd_eid_supp_rates(bss
, supp_rates
);
267 pos
= hostapd_eid_ext_supp_rates(bss
, pos
);
268 wpabuf_put_data(buf
, supp_rates
, pos
- supp_rates
);
271 wpabuf_put_data(buf
, conf
->rsn_ie
, conf
->rsn_ie_len
);
274 wpabuf_put_u8(buf
, WLAN_EID_MESH_ID
);
275 wpabuf_put_u8(buf
, conf
->meshid_len
);
276 wpabuf_put_data(buf
, conf
->meshid
, conf
->meshid_len
);
279 wpabuf_put_u8(buf
, WLAN_EID_MESH_CONFIG
);
280 wpabuf_put_u8(buf
, 7);
281 wpabuf_put_u8(buf
, conf
->mesh_pp_id
);
282 wpabuf_put_u8(buf
, conf
->mesh_pm_id
);
283 wpabuf_put_u8(buf
, conf
->mesh_cc_id
);
284 wpabuf_put_u8(buf
, conf
->mesh_sp_id
);
285 wpabuf_put_u8(buf
, conf
->mesh_auth_id
);
286 info
= (bss
->num_plinks
> 63 ? 63 : bss
->num_plinks
) << 1;
287 /* TODO: Add Connected to Mesh Gate/AS subfields */
288 wpabuf_put_u8(buf
, info
);
289 /* always forwarding & accepting plinks for now */
290 wpabuf_put_u8(buf
, MESH_CAP_ACCEPT_ADDITIONAL_PEER
|
291 MESH_CAP_FORWARDING
);
292 } else { /* Peer closing frame */
294 wpabuf_put_u8(buf
, WLAN_EID_MESH_ID
);
295 wpabuf_put_u8(buf
, conf
->meshid_len
);
296 wpabuf_put_data(buf
, conf
->meshid
, conf
->meshid_len
);
299 /* IE: Mesh Peering Management element */
313 ie_len
+= 2; /* reason code */
317 wpabuf_put_u8(buf
, WLAN_EID_PEER_MGMT
);
318 wpabuf_put_u8(buf
, ie_len
);
319 /* peering protocol */
321 wpabuf_put_le16(buf
, 1);
323 wpabuf_put_le16(buf
, 0);
324 wpabuf_put_le16(buf
, sta
->my_lid
);
326 wpabuf_put_le16(buf
, sta
->peer_lid
);
327 if (type
== PLINK_CLOSE
)
328 wpabuf_put_le16(buf
, close_reason
);
330 if (sta
->sae
== NULL
) {
331 wpa_msg(wpa_s
, MSG_INFO
, "Mesh MPM: no SAE session");
334 mesh_rsn_get_pmkid(wpa_s
->mesh_rsn
, sta
,
335 wpabuf_put(buf
, PMKID_LEN
));
338 #ifdef CONFIG_IEEE80211N
339 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_ht_enabled
) {
340 u8 ht_capa_oper
[2 + 26 + 2 + 22];
342 pos
= hostapd_eid_ht_capabilities(bss
, ht_capa_oper
);
343 pos
= hostapd_eid_ht_operation(bss
, pos
);
344 wpabuf_put_data(buf
, ht_capa_oper
, pos
- ht_capa_oper
);
346 #endif /* CONFIG_IEEE80211N */
347 #ifdef CONFIG_IEEE80211AC
348 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_vht_enabled
) {
349 u8 vht_capa_oper
[2 + 12 + 2 + 5];
351 pos
= hostapd_eid_vht_capabilities(bss
, vht_capa_oper
);
352 pos
= hostapd_eid_vht_operation(bss
, pos
);
353 wpabuf_put_data(buf
, vht_capa_oper
, pos
- vht_capa_oper
);
355 #endif /* CONFIG_IEEE80211AC */
357 if (ampe
&& mesh_rsn_protect_frame(wpa_s
->mesh_rsn
, sta
, cat
, buf
)) {
358 wpa_msg(wpa_s
, MSG_INFO
,
359 "Mesh MPM: failed to add AMPE and MIC IE");
363 wpa_msg(wpa_s
, MSG_DEBUG
, "Mesh MPM: Sending peering frame type %d to "
364 MACSTR
" (my_lid=0x%x peer_lid=0x%x)",
365 type
, MAC2STR(sta
->addr
), sta
->my_lid
, sta
->peer_lid
);
366 ret
= wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0,
367 sta
->addr
, wpa_s
->own_addr
, wpa_s
->own_addr
,
368 wpabuf_head(buf
), wpabuf_len(buf
), 0);
370 wpa_msg(wpa_s
, MSG_INFO
,
371 "Mesh MPM: failed to send peering frame");
378 /* configure peering state in ours and driver's station entry */
379 void wpa_mesh_set_plink_state(struct wpa_supplicant
*wpa_s
,
380 struct sta_info
*sta
,
381 enum mesh_plink_state state
)
383 struct hostapd_sta_add_params params
;
386 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM set " MACSTR
" from %s into %s",
387 MAC2STR(sta
->addr
), mplstate
[sta
->plink_state
],
389 sta
->plink_state
= state
;
391 os_memset(¶ms
, 0, sizeof(params
));
392 params
.addr
= sta
->addr
;
393 params
.plink_state
= state
;
394 params
.peer_aid
= sta
->peer_aid
;
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
;
422 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
424 switch (sta
->plink_state
) {
428 if (sta
->mpm_retries
< conf
->dot11MeshMaxRetries
) {
429 eloop_register_timeout(
430 conf
->dot11MeshRetryTimeout
/ 1000,
431 (conf
->dot11MeshRetryTimeout
% 1000) * 1000,
432 plink_timer
, wpa_s
, sta
);
433 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_OPEN
, 0);
437 reason
= WLAN_REASON_MESH_MAX_RETRIES
;
438 /* fall through on else */
443 reason
= WLAN_REASON_MESH_CONFIRM_TIMEOUT
;
444 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
445 eloop_register_timeout(conf
->dot11MeshHoldingTimeout
/ 1000,
446 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
447 plink_timer
, wpa_s
, sta
);
448 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CLOSE
, reason
);
453 if (sta
->mesh_sae_pmksa_caching
) {
454 wpa_printf(MSG_DEBUG
, "MPM: Peer " MACSTR
455 " looks like it does not support mesh SAE PMKSA caching, so remove the cached entry for it",
457 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
459 mesh_mpm_fsm_restart(wpa_s
, sta
);
467 /* initiate peering with station */
469 mesh_mpm_plink_open(struct wpa_supplicant
*wpa_s
, struct sta_info
*sta
,
470 enum mesh_plink_state next_state
)
472 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
474 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
475 eloop_register_timeout(conf
->dot11MeshRetryTimeout
/ 1000,
476 (conf
->dot11MeshRetryTimeout
% 1000) * 1000,
477 plink_timer
, wpa_s
, sta
);
478 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_OPEN
, 0);
479 wpa_mesh_set_plink_state(wpa_s
, sta
, next_state
);
483 static int mesh_mpm_plink_close(struct hostapd_data
*hapd
, struct sta_info
*sta
,
486 struct wpa_supplicant
*wpa_s
= ctx
;
487 int reason
= WLAN_REASON_MESH_PEERING_CANCELLED
;
490 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
491 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CLOSE
, reason
);
492 wpa_printf(MSG_DEBUG
, "MPM closing plink sta=" MACSTR
,
494 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
502 int mesh_mpm_close_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
504 struct hostapd_data
*hapd
;
505 struct sta_info
*sta
;
508 wpa_msg(wpa_s
, MSG_INFO
, "Mesh is not prepared yet");
512 hapd
= wpa_s
->ifmsh
->bss
[0];
513 sta
= ap_get_sta(hapd
, addr
);
515 wpa_msg(wpa_s
, MSG_INFO
, "No such mesh peer");
519 return mesh_mpm_plink_close(hapd
, sta
, wpa_s
) == 0 ? 0 : -1;
523 static void peer_add_timer(void *eloop_ctx
, void *user_data
)
525 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
526 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
528 os_memset(hapd
->mesh_required_peer
, 0, ETH_ALEN
);
532 int mesh_mpm_connect_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
535 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
536 struct hostapd_data
*hapd
;
537 struct sta_info
*sta
;
538 struct mesh_conf
*conf
;
541 wpa_msg(wpa_s
, MSG_INFO
, "Mesh is not prepared yet");
545 if (!ssid
|| !ssid
->no_auto_peer
) {
546 wpa_msg(wpa_s
, MSG_INFO
,
547 "This command is available only with no_auto_peer mesh network");
551 hapd
= wpa_s
->ifmsh
->bss
[0];
552 conf
= wpa_s
->ifmsh
->mconf
;
554 sta
= ap_get_sta(hapd
, addr
);
556 wpa_msg(wpa_s
, MSG_INFO
, "No such mesh peer");
560 if ((PLINK_OPN_SNT
<= sta
->plink_state
&&
561 sta
->plink_state
<= PLINK_ESTAB
) ||
562 (sta
->sae
&& sta
->sae
->state
> SAE_NOTHING
)) {
563 wpa_msg(wpa_s
, MSG_INFO
,
564 "Specified peer is connecting/connected");
568 if (conf
->security
== MESH_CONF_SEC_NONE
) {
569 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPN_SNT
);
571 mesh_rsn_auth_sae_sta(wpa_s
, sta
);
572 os_memcpy(hapd
->mesh_required_peer
, addr
, ETH_ALEN
);
573 eloop_register_timeout(duration
== -1 ? 10 : duration
, 0,
574 peer_add_timer
, wpa_s
, NULL
);
581 void mesh_mpm_deinit(struct wpa_supplicant
*wpa_s
, struct hostapd_iface
*ifmsh
)
583 struct hostapd_data
*hapd
= ifmsh
->bss
[0];
585 /* notify peers we're leaving */
586 ap_for_each_sta(hapd
, mesh_mpm_plink_close
, wpa_s
);
588 hapd
->num_plinks
= 0;
589 hostapd_free_stas(hapd
);
590 eloop_cancel_timeout(peer_add_timer
, wpa_s
, NULL
);
594 /* for mesh_rsn to indicate this peer has completed authentication, and we're
595 * ready to start AMPE */
596 void mesh_mpm_auth_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
598 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
599 struct hostapd_sta_add_params params
;
600 struct sta_info
*sta
;
603 sta
= ap_get_sta(data
, addr
);
605 wpa_msg(wpa_s
, MSG_DEBUG
, "no such mesh peer");
609 /* TODO: Should do nothing if this STA is already authenticated, but
610 * the AP code already sets this flag. */
611 sta
->flags
|= WLAN_STA_AUTH
;
613 mesh_rsn_init_ampe_sta(wpa_s
, sta
);
615 os_memset(¶ms
, 0, sizeof(params
));
616 params
.addr
= sta
->addr
;
617 params
.flags
= WPA_STA_AUTHENTICATED
| WPA_STA_AUTHORIZED
;
620 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM authenticating " MACSTR
,
622 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
624 wpa_msg(wpa_s
, MSG_ERROR
,
625 "Driver failed to set " MACSTR
": %d",
626 MAC2STR(sta
->addr
), ret
);
630 mesh_mpm_init_link(wpa_s
, sta
);
632 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPN_SNT
);
636 * Initialize a sta_info structure for a peer and upload it into the driver
637 * in preparation for beginning authentication or peering. This is done when a
638 * Beacon (secure or open mesh) or a peering open frame (for open mesh) is
639 * received from the peer for the first time.
641 static struct sta_info
* mesh_mpm_add_peer(struct wpa_supplicant
*wpa_s
,
643 struct ieee802_11_elems
*elems
)
645 struct hostapd_sta_add_params params
;
646 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
647 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
648 struct sta_info
*sta
;
651 if (elems
->mesh_config_len
>= 7 &&
652 !(elems
->mesh_config
[6] & MESH_CAP_ACCEPT_ADDITIONAL_PEER
)) {
653 wpa_msg(wpa_s
, MSG_DEBUG
,
654 "mesh: Ignore a crowded peer " MACSTR
,
659 sta
= ap_get_sta(data
, addr
);
661 sta
= ap_sta_add(data
, addr
);
666 /* Set WMM by default since Mesh STAs are QoS STAs */
667 sta
->flags
|= WLAN_STA_WMM
;
670 if (copy_supp_rates(wpa_s
, sta
, elems
)) {
671 ap_free_sta(data
, sta
);
676 mesh_mpm_init_link(wpa_s
, sta
);
678 #ifdef CONFIG_IEEE80211N
679 copy_sta_ht_capab(data
, sta
, elems
->ht_capabilities
);
680 update_ht_state(data
, sta
);
681 #endif /* CONFIG_IEEE80211N */
683 #ifdef CONFIG_IEEE80211AC
684 copy_sta_vht_capab(data
, sta
, elems
->vht_capabilities
);
685 set_sta_vht_opmode(data
, sta
, elems
->vht_opmode_notif
);
686 #endif /* CONFIG_IEEE80211AC */
688 if (hostapd_get_aid(data
, sta
) < 0) {
689 wpa_msg(wpa_s
, MSG_ERROR
, "No AIDs available");
690 ap_free_sta(data
, sta
);
694 /* insert into driver */
695 os_memset(¶ms
, 0, sizeof(params
));
696 params
.supp_rates
= sta
->supported_rates
;
697 params
.supp_rates_len
= sta
->supported_rates_len
;
699 params
.plink_state
= sta
->plink_state
;
700 params
.aid
= sta
->aid
;
701 params
.peer_aid
= sta
->peer_aid
;
702 params
.listen_interval
= 100;
703 params
.ht_capabilities
= sta
->ht_capabilities
;
704 params
.vht_capabilities
= sta
->vht_capabilities
;
705 params
.flags
|= WPA_STA_WMM
;
706 params
.flags_mask
|= WPA_STA_AUTHENTICATED
;
707 if (conf
->security
== MESH_CONF_SEC_NONE
) {
708 params
.flags
|= WPA_STA_AUTHORIZED
;
709 params
.flags
|= WPA_STA_AUTHENTICATED
;
711 sta
->flags
|= WLAN_STA_MFP
;
712 params
.flags
|= WPA_STA_MFP
;
715 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
717 wpa_msg(wpa_s
, MSG_ERROR
,
718 "Driver failed to insert " MACSTR
": %d",
720 ap_free_sta(data
, sta
);
728 void wpa_mesh_new_mesh_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
729 struct ieee802_11_elems
*elems
)
731 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
732 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
733 struct sta_info
*sta
;
734 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
736 sta
= mesh_mpm_add_peer(wpa_s
, addr
, elems
);
740 if (ssid
&& ssid
->no_auto_peer
&&
741 (is_zero_ether_addr(data
->mesh_required_peer
) ||
742 os_memcmp(data
->mesh_required_peer
, addr
, ETH_ALEN
) != 0)) {
743 wpa_msg(wpa_s
, MSG_INFO
, "will not initiate new peer link with "
744 MACSTR
" because of no_auto_peer", MAC2STR(addr
));
745 if (data
->mesh_pending_auth
) {
746 struct os_reltime age
;
747 const struct ieee80211_mgmt
*mgmt
;
748 struct hostapd_frame_info fi
;
750 mgmt
= wpabuf_head(data
->mesh_pending_auth
);
751 os_reltime_age(&data
->mesh_pending_auth_time
, &age
);
753 os_memcmp(mgmt
->sa
, addr
, ETH_ALEN
) == 0) {
754 wpa_printf(MSG_DEBUG
,
755 "mesh: Process pending Authentication frame from %u.%06u seconds ago",
756 (unsigned int) age
.sec
,
757 (unsigned int) age
.usec
);
758 os_memset(&fi
, 0, sizeof(fi
));
761 wpabuf_head(data
->mesh_pending_auth
),
762 wpabuf_len(data
->mesh_pending_auth
),
765 wpabuf_free(data
->mesh_pending_auth
);
766 data
->mesh_pending_auth
= NULL
;
771 if (conf
->security
== MESH_CONF_SEC_NONE
) {
772 if (sta
->plink_state
< PLINK_OPN_SNT
||
773 sta
->plink_state
> PLINK_ESTAB
)
774 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPN_SNT
);
776 mesh_rsn_auth_sae_sta(wpa_s
, sta
);
781 void mesh_mpm_mgmt_rx(struct wpa_supplicant
*wpa_s
, struct rx_mgmt
*rx_mgmt
)
783 struct hostapd_frame_info fi
;
785 os_memset(&fi
, 0, sizeof(fi
));
786 fi
.datarate
= rx_mgmt
->datarate
;
787 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
788 ieee802_11_mgmt(wpa_s
->ifmsh
->bss
[0], rx_mgmt
->frame
,
789 rx_mgmt
->frame_len
, &fi
);
793 static void mesh_mpm_plink_estab(struct wpa_supplicant
*wpa_s
,
794 struct sta_info
*sta
)
796 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
797 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
800 wpa_msg(wpa_s
, MSG_INFO
, "mesh plink with " MACSTR
" established",
803 if (conf
->security
& MESH_CONF_SEC_AMPE
) {
804 wpa_hexdump_key(MSG_DEBUG
, "mesh: MTK", sta
->mtk
, sta
->mtk_len
);
805 wpa_drv_set_key(wpa_s
, wpa_cipher_to_alg(conf
->pairwise_cipher
),
806 sta
->addr
, 0, 0, seq
, sizeof(seq
),
807 sta
->mtk
, sta
->mtk_len
);
809 wpa_hexdump_key(MSG_DEBUG
, "mesh: RX MGTK Key RSC",
810 sta
->mgtk_rsc
, sizeof(sta
->mgtk_rsc
));
811 wpa_hexdump_key(MSG_DEBUG
, "mesh: RX MGTK",
812 sta
->mgtk
, sta
->mgtk_len
);
813 wpa_drv_set_key(wpa_s
, wpa_cipher_to_alg(conf
->group_cipher
),
814 sta
->addr
, sta
->mgtk_key_id
, 0,
815 sta
->mgtk_rsc
, sizeof(sta
->mgtk_rsc
),
816 sta
->mgtk
, sta
->mgtk_len
);
819 wpa_hexdump_key(MSG_DEBUG
, "mesh: RX IGTK Key RSC",
820 sta
->igtk_rsc
, sizeof(sta
->igtk_rsc
));
821 wpa_hexdump_key(MSG_DEBUG
, "mesh: RX IGTK",
822 sta
->igtk
, sta
->igtk_len
);
825 wpa_cipher_to_alg(conf
->mgmt_group_cipher
),
826 sta
->addr
, sta
->igtk_key_id
, 0,
827 sta
->igtk_rsc
, sizeof(sta
->igtk_rsc
),
828 sta
->igtk
, sta
->igtk_len
);
832 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_ESTAB
);
835 sta
->flags
|= WLAN_STA_ASSOC
;
836 sta
->mesh_sae_pmksa_caching
= 0;
838 eloop_cancel_timeout(peer_add_timer
, wpa_s
, NULL
);
839 peer_add_timer(wpa_s
, NULL
);
840 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
842 /* Send ctrl event */
843 wpa_msg(wpa_s
, MSG_INFO
, MESH_PEER_CONNECTED MACSTR
,
848 static void mesh_mpm_fsm(struct wpa_supplicant
*wpa_s
, struct sta_info
*sta
,
849 enum plink_event event
, u16 reason
)
851 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
852 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
854 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM " MACSTR
" state %s event %s",
855 MAC2STR(sta
->addr
), mplstate
[sta
->plink_state
],
858 switch (sta
->plink_state
) {
862 mesh_mpm_fsm_restart(wpa_s
, sta
);
865 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPN_RCVD
);
866 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CONFIRM
,
870 mesh_mpm_send_plink_action(wpa_s
, sta
,
871 PLINK_CLOSE
, reason
);
882 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
885 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
887 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
888 eloop_register_timeout(
889 conf
->dot11MeshHoldingTimeout
/ 1000,
890 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
891 plink_timer
, wpa_s
, sta
);
892 mesh_mpm_send_plink_action(wpa_s
, sta
,
893 PLINK_CLOSE
, reason
);
896 /* retry timer is left untouched */
897 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_OPN_RCVD
);
898 mesh_mpm_send_plink_action(wpa_s
, sta
,
902 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_CNF_RCVD
);
903 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
904 eloop_register_timeout(
905 conf
->dot11MeshConfirmTimeout
/ 1000,
906 (conf
->dot11MeshConfirmTimeout
% 1000) * 1000,
907 plink_timer
, wpa_s
, sta
);
918 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
921 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
923 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
924 eloop_register_timeout(
925 conf
->dot11MeshHoldingTimeout
/ 1000,
926 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
927 plink_timer
, wpa_s
, sta
);
928 sta
->mpm_close_reason
= reason
;
929 mesh_mpm_send_plink_action(wpa_s
, sta
,
930 PLINK_CLOSE
, reason
);
933 mesh_mpm_send_plink_action(wpa_s
, sta
,
937 if (conf
->security
& MESH_CONF_SEC_AMPE
)
938 mesh_rsn_derive_mtk(wpa_s
, sta
);
939 mesh_mpm_plink_estab(wpa_s
, sta
);
950 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
953 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
955 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
956 eloop_register_timeout(
957 conf
->dot11MeshHoldingTimeout
/ 1000,
958 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
959 plink_timer
, wpa_s
, sta
);
960 sta
->mpm_close_reason
= reason
;
961 mesh_mpm_send_plink_action(wpa_s
, sta
,
962 PLINK_CLOSE
, reason
);
965 if (conf
->security
& MESH_CONF_SEC_AMPE
)
966 mesh_rsn_derive_mtk(wpa_s
, sta
);
967 mesh_mpm_plink_estab(wpa_s
, sta
);
968 mesh_mpm_send_plink_action(wpa_s
, sta
,
980 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
982 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
984 eloop_register_timeout(
985 conf
->dot11MeshHoldingTimeout
/ 1000,
986 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
987 plink_timer
, wpa_s
, sta
);
988 sta
->mpm_close_reason
= reason
;
990 wpa_msg(wpa_s
, MSG_INFO
, "mesh plink with " MACSTR
991 " closed with reason %d",
992 MAC2STR(sta
->addr
), reason
);
994 wpa_msg(wpa_s
, MSG_INFO
, MESH_PEER_DISCONNECTED MACSTR
,
999 mesh_mpm_send_plink_action(wpa_s
, sta
,
1000 PLINK_CLOSE
, reason
);
1003 mesh_mpm_send_plink_action(wpa_s
, sta
,
1013 mesh_mpm_fsm_restart(wpa_s
, sta
);
1019 reason
= sta
->mpm_close_reason
;
1020 mesh_mpm_send_plink_action(wpa_s
, sta
,
1021 PLINK_CLOSE
, reason
);
1028 wpa_msg(wpa_s
, MSG_DEBUG
,
1029 "Unsupported MPM event %s for state %s",
1030 mplevent
[event
], mplstate
[sta
->plink_state
]);
1036 void mesh_mpm_action_rx(struct wpa_supplicant
*wpa_s
,
1037 const struct ieee80211_mgmt
*mgmt
, size_t len
)
1040 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
1041 struct mesh_conf
*mconf
= wpa_s
->ifmsh
->mconf
;
1042 struct sta_info
*sta
;
1043 u16 plid
= 0, llid
= 0, aid
= 0;
1044 enum plink_event event
;
1045 struct ieee802_11_elems elems
;
1046 struct mesh_peer_mgmt_ie peer_mgmt_ie
;
1052 if (mgmt
->u
.action
.category
!= WLAN_ACTION_SELF_PROTECTED
)
1055 action_field
= mgmt
->u
.action
.u
.slf_prot_action
.action
;
1056 if (action_field
!= PLINK_OPEN
&&
1057 action_field
!= PLINK_CONFIRM
&&
1058 action_field
!= PLINK_CLOSE
)
1061 ies
= mgmt
->u
.action
.u
.slf_prot_action
.variable
;
1062 ie_len
= (const u8
*) mgmt
+ len
-
1063 mgmt
->u
.action
.u
.slf_prot_action
.variable
;
1065 /* at least expect mesh id and peering mgmt */
1066 if (ie_len
< 2 + 2) {
1067 wpa_printf(MSG_DEBUG
,
1068 "MPM: Ignore too short action frame %u ie_len %u",
1069 action_field
, (unsigned int) ie_len
);
1072 wpa_printf(MSG_DEBUG
, "MPM: Received PLINK action %u", action_field
);
1074 if (action_field
== PLINK_OPEN
|| action_field
== PLINK_CONFIRM
) {
1075 wpa_printf(MSG_DEBUG
, "MPM: Capability 0x%x",
1077 ies
+= 2; /* capability */
1080 if (action_field
== PLINK_CONFIRM
) {
1081 aid
= WPA_GET_LE16(ies
);
1082 wpa_printf(MSG_DEBUG
, "MPM: AID 0x%x", aid
);
1087 /* check for mesh peering, mesh id and mesh config IEs */
1088 if (ieee802_11_parse_elems(ies
, ie_len
, &elems
, 0) == ParseFailed
) {
1089 wpa_printf(MSG_DEBUG
, "MPM: Failed to parse PLINK IEs");
1092 if (!elems
.peer_mgmt
) {
1093 wpa_printf(MSG_DEBUG
,
1094 "MPM: No Mesh Peering Management element");
1097 if (action_field
!= PLINK_CLOSE
) {
1098 if (!elems
.mesh_id
|| !elems
.mesh_config
) {
1099 wpa_printf(MSG_DEBUG
,
1100 "MPM: No Mesh ID or Mesh Configuration element");
1104 if (!matches_local(wpa_s
, &elems
)) {
1105 wpa_printf(MSG_DEBUG
,
1106 "MPM: Mesh ID or Mesh Configuration element do not match local MBSS");
1111 ret
= mesh_mpm_parse_peer_mgmt(wpa_s
, action_field
,
1113 elems
.peer_mgmt_len
,
1116 wpa_printf(MSG_DEBUG
, "MPM: Mesh parsing rejected frame");
1120 /* the sender's llid is our plid and vice-versa */
1121 plid
= WPA_GET_LE16(peer_mgmt_ie
.llid
);
1122 if (peer_mgmt_ie
.plid
)
1123 llid
= WPA_GET_LE16(peer_mgmt_ie
.plid
);
1124 wpa_printf(MSG_DEBUG
, "MPM: plid=0x%x llid=0x%x", plid
, llid
);
1126 if (action_field
== PLINK_CLOSE
)
1127 wpa_printf(MSG_DEBUG
, "MPM: close reason=%u",
1128 WPA_GET_LE16(peer_mgmt_ie
.reason
));
1130 sta
= ap_get_sta(hapd
, mgmt
->sa
);
1133 * If this is an open frame from an unknown STA, and this is an
1134 * open mesh, then go ahead and add the peer before proceeding.
1136 if (!sta
&& action_field
== PLINK_OPEN
&&
1137 (!(mconf
->security
& MESH_CONF_SEC_AMPE
) ||
1138 wpa_auth_pmksa_get(hapd
->wpa_auth
, mgmt
->sa
)))
1139 sta
= mesh_mpm_add_peer(wpa_s
, mgmt
->sa
, &elems
);
1142 wpa_printf(MSG_DEBUG
, "MPM: No STA entry for peer");
1147 /* peer is in sae_accepted? */
1148 if (sta
->sae
&& sta
->sae
->state
!= SAE_ACCEPTED
) {
1149 wpa_printf(MSG_DEBUG
, "MPM: SAE not yet accepted for peer");
1152 #endif /* CONFIG_SAE */
1155 mesh_mpm_init_link(wpa_s
, sta
);
1157 if (mconf
->security
& MESH_CONF_SEC_AMPE
) {
1160 res
= mesh_rsn_process_ampe(wpa_s
, sta
, &elems
,
1161 &mgmt
->u
.action
.category
,
1162 peer_mgmt_ie
.chosen_pmk
,
1165 wpa_printf(MSG_DEBUG
,
1166 "MPM: RSN process rejected frame (res=%d)",
1168 if (action_field
== PLINK_OPEN
&& res
== -2) {
1169 /* AES-SIV decryption failed */
1170 mesh_mpm_fsm(wpa_s
, sta
, OPN_RJCT
,
1171 WLAN_REASON_MESH_INVALID_GTK
);
1177 if (sta
->plink_state
== PLINK_BLOCKED
) {
1178 wpa_printf(MSG_DEBUG
, "MPM: PLINK_BLOCKED");
1182 /* Now we will figure out the appropriate event... */
1183 switch (action_field
) {
1185 if (plink_free_count(hapd
) == 0) {
1187 reason
= WLAN_REASON_MESH_MAX_PEERS
;
1188 wpa_printf(MSG_INFO
,
1189 "MPM: Peer link num over quota(%d)",
1191 } else if (sta
->peer_lid
&& sta
->peer_lid
!= plid
) {
1192 wpa_printf(MSG_DEBUG
,
1193 "MPM: peer_lid mismatch: 0x%x != 0x%x",
1194 sta
->peer_lid
, plid
);
1195 return; /* no FSM event */
1197 sta
->peer_lid
= plid
;
1202 if (plink_free_count(hapd
) == 0) {
1204 reason
= WLAN_REASON_MESH_MAX_PEERS
;
1205 wpa_printf(MSG_INFO
,
1206 "MPM: Peer link num over quota(%d)",
1208 } else if (sta
->my_lid
!= llid
||
1209 (sta
->peer_lid
&& sta
->peer_lid
!= plid
)) {
1210 wpa_printf(MSG_DEBUG
,
1211 "MPM: lid mismatch: my_lid: 0x%x != 0x%x or peer_lid: 0x%x != 0x%x",
1212 sta
->my_lid
, llid
, sta
->peer_lid
, plid
);
1213 return; /* no FSM event */
1216 sta
->peer_lid
= plid
;
1217 sta
->peer_aid
= aid
;
1222 if (sta
->plink_state
== PLINK_ESTAB
)
1223 /* Do not check for llid or plid. This does not
1224 * follow the standard but since multiple plinks
1225 * per cand are not supported, it is necessary in
1226 * order to avoid a livelock when MP A sees an
1227 * establish peer link to MP B but MP B does not
1228 * see it. This can be caused by a timeout in
1229 * B's peer link establishment or B being
1233 else if (sta
->peer_lid
!= plid
) {
1234 wpa_printf(MSG_DEBUG
,
1235 "MPM: peer_lid mismatch: 0x%x != 0x%x",
1236 sta
->peer_lid
, plid
);
1237 return; /* no FSM event */
1238 } else if (peer_mgmt_ie
.plid
&& sta
->my_lid
!= llid
) {
1239 wpa_printf(MSG_DEBUG
,
1240 "MPM: my_lid mismatch: 0x%x != 0x%x",
1242 return; /* no FSM event */
1249 * This cannot be hit due to the action_field check above, but
1250 * compilers may not be able to figure that out and can warn
1251 * about uninitialized event below.
1255 mesh_mpm_fsm(wpa_s
, sta
, event
, reason
);
1259 /* called by ap_free_sta */
1260 void mesh_mpm_free_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
)
1262 if (sta
->plink_state
== PLINK_ESTAB
)
1264 eloop_cancel_timeout(plink_timer
, ELOOP_ALL_CTX
, sta
);
1265 eloop_cancel_timeout(mesh_auth_timer
, ELOOP_ALL_CTX
, sta
);