2 * WPA Supplicant - Basic mesh peer management
3 * Copyright (c) 2013-2014, cozybit, Inc. All rights reserved.
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
14 #include "ap/hostapd.h"
15 #include "ap/sta_info.h"
16 #include "ap/ieee802_11.h"
17 #include "wpa_supplicant_i.h"
22 struct mesh_peer_mgmt_ie
{
30 static void plink_timer(void *eloop_ctx
, void *user_data
);
45 static const char * const mplstate
[] = {
46 [PLINK_LISTEN
] = "LISTEN",
47 [PLINK_OPEN_SENT
] = "OPEN_SENT",
48 [PLINK_OPEN_RCVD
] = "OPEN_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 [OPN_IGNR
] = "OPN_IGNR",
60 [CNF_ACPT
] = "CNF_ACPT",
61 [CNF_RJCT
] = "CNF_RJCT",
62 [CNF_IGNR
] = "CNF_IGNR",
63 [CLS_ACPT
] = "CLS_ACPT",
64 [CLS_IGNR
] = "CLS_IGNR"
68 static int mesh_mpm_parse_peer_mgmt(struct wpa_supplicant
*wpa_s
,
70 const u8
*ie
, size_t len
,
71 struct mesh_peer_mgmt_ie
*mpm_ie
)
73 os_memset(mpm_ie
, 0, sizeof(*mpm_ie
));
75 /* remove optional PMK at end */
78 mpm_ie
->pmk
= ie
+ len
- 16;
81 if ((action_field
== PLINK_OPEN
&& len
!= 4) ||
82 (action_field
== PLINK_CONFIRM
&& len
!= 6) ||
83 (action_field
== PLINK_CLOSE
&& len
!= 6 && len
!= 8)) {
84 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM: Invalid peer mgmt ie");
91 mpm_ie
->proto_id
= ie
;
92 mpm_ie
->llid
= ie
+ 2;
96 /* close reason is always present at end for close */
97 if (action_field
== PLINK_CLOSE
) {
100 mpm_ie
->reason
= ie
+ len
- 2;
104 /* plid, present for confirm, and possibly close */
112 static int plink_free_count(struct hostapd_data
*hapd
)
114 if (hapd
->max_plinks
> hapd
->num_plinks
)
115 return hapd
->max_plinks
- hapd
->num_plinks
;
120 static u16
copy_supp_rates(struct wpa_supplicant
*wpa_s
,
121 struct sta_info
*sta
,
122 struct ieee802_11_elems
*elems
)
124 if (!elems
->supp_rates
) {
125 wpa_msg(wpa_s
, MSG_ERROR
, "no supported rates from " MACSTR
,
127 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
130 if (elems
->supp_rates_len
+ elems
->ext_supp_rates_len
>
131 sizeof(sta
->supported_rates
)) {
132 wpa_msg(wpa_s
, MSG_ERROR
,
133 "Invalid supported rates element length " MACSTR
134 " %d+%d", MAC2STR(sta
->addr
), elems
->supp_rates_len
,
135 elems
->ext_supp_rates_len
);
136 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
139 sta
->supported_rates_len
= merge_byte_arrays(
140 sta
->supported_rates
, sizeof(sta
->supported_rates
),
141 elems
->supp_rates
, elems
->supp_rates_len
,
142 elems
->ext_supp_rates
, elems
->ext_supp_rates_len
);
144 return WLAN_STATUS_SUCCESS
;
148 /* return true if elems from a neighbor match this MBSS */
149 static Boolean
matches_local(struct wpa_supplicant
*wpa_s
,
150 struct ieee802_11_elems
*elems
)
152 struct mesh_conf
*mconf
= wpa_s
->ifmsh
->mconf
;
154 if (elems
->mesh_config_len
< 5)
157 return (mconf
->meshid_len
== elems
->mesh_id_len
&&
158 os_memcmp(mconf
->meshid
, elems
->mesh_id
,
159 elems
->mesh_id_len
) == 0 &&
160 mconf
->mesh_pp_id
== elems
->mesh_config
[0] &&
161 mconf
->mesh_pm_id
== elems
->mesh_config
[1] &&
162 mconf
->mesh_cc_id
== elems
->mesh_config
[2] &&
163 mconf
->mesh_sp_id
== elems
->mesh_config
[3] &&
164 mconf
->mesh_auth_id
== elems
->mesh_config
[4]);
168 /* check if local link id is already used with another peer */
169 static Boolean
llid_in_use(struct wpa_supplicant
*wpa_s
, u16 llid
)
171 struct sta_info
*sta
;
172 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
174 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
175 if (sta
->my_lid
== llid
)
183 /* generate an llid for a link and set to initial state */
184 static void mesh_mpm_init_link(struct wpa_supplicant
*wpa_s
,
185 struct sta_info
*sta
)
190 if (os_get_random((u8
*) &llid
, sizeof(llid
)) < 0)
192 } 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_LISTEN
;
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];
215 #ifdef CONFIG_IEEE80211N
216 u8 ht_capa_oper
[2 + 26 + 2 + 22];
217 #endif /* CONFIG_IEEE80211N */
219 u8 ie_len
, add_plid
= 0;
221 int ampe
= conf
->security
& MESH_CONF_SEC_AMPE
;
227 buf_len
= 2 + /* capability info */
229 2 + 8 + /* supported rates */
231 2 + 32 + /* mesh ID */
232 2 + 7 + /* mesh config */
233 2 + 23 + /* 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 buf
= wpabuf_alloc(buf_len
);
246 cat
= wpabuf_mhead_u8(buf
);
247 wpabuf_put_u8(buf
, WLAN_ACTION_SELF_PROTECTED
);
248 wpabuf_put_u8(buf
, type
);
250 if (type
!= PLINK_CLOSE
) {
253 /* capability info */
254 wpabuf_put_le16(buf
, ampe
? IEEE80211_CAP_PRIVACY
: 0);
257 if (type
== PLINK_CONFIRM
)
258 wpabuf_put_le16(buf
, sta
->peer_lid
);
260 /* IE: supp + ext. supp rates */
261 pos
= hostapd_eid_supp_rates(bss
, supp_rates
);
262 pos
= hostapd_eid_ext_supp_rates(bss
, pos
);
263 wpabuf_put_data(buf
, supp_rates
, pos
- supp_rates
);
266 wpabuf_put_u8(buf
, WLAN_EID_MESH_ID
);
267 wpabuf_put_u8(buf
, conf
->meshid_len
);
268 wpabuf_put_data(buf
, conf
->meshid
, conf
->meshid_len
);
271 wpabuf_put_u8(buf
, WLAN_EID_MESH_CONFIG
);
272 wpabuf_put_u8(buf
, 7);
273 wpabuf_put_u8(buf
, conf
->mesh_pp_id
);
274 wpabuf_put_u8(buf
, conf
->mesh_pm_id
);
275 wpabuf_put_u8(buf
, conf
->mesh_cc_id
);
276 wpabuf_put_u8(buf
, conf
->mesh_sp_id
);
277 wpabuf_put_u8(buf
, conf
->mesh_auth_id
);
278 info
= (bss
->num_plinks
> 63 ? 63 : bss
->num_plinks
) << 1;
279 /* TODO: Add Connected to Mesh Gate/AS subfields */
280 wpabuf_put_u8(buf
, info
);
281 /* always forwarding & accepting plinks for now */
282 wpabuf_put_u8(buf
, 0x1 | 0x8);
283 } else { /* Peer closing frame */
285 wpabuf_put_u8(buf
, WLAN_EID_MESH_ID
);
286 wpabuf_put_u8(buf
, conf
->meshid_len
);
287 wpabuf_put_data(buf
, conf
->meshid
, conf
->meshid_len
);
290 /* IE: Mesh Peering Management element */
304 ie_len
+= 2; /* reason code */
308 wpabuf_put_u8(buf
, WLAN_EID_PEER_MGMT
);
309 wpabuf_put_u8(buf
, ie_len
);
310 /* peering protocol */
312 wpabuf_put_le16(buf
, 1);
314 wpabuf_put_le16(buf
, 0);
315 wpabuf_put_le16(buf
, sta
->my_lid
);
317 wpabuf_put_le16(buf
, sta
->peer_lid
);
318 if (type
== PLINK_CLOSE
)
319 wpabuf_put_le16(buf
, close_reason
);
321 if (sta
->sae
== NULL
) {
322 wpa_msg(wpa_s
, MSG_INFO
, "Mesh MPM: no SAE session");
325 mesh_rsn_get_pmkid(wpa_s
->mesh_rsn
, sta
,
326 wpabuf_put(buf
, PMKID_LEN
));
329 #ifdef CONFIG_IEEE80211N
330 if (type
!= PLINK_CLOSE
&& wpa_s
->mesh_ht_enabled
) {
331 pos
= hostapd_eid_ht_capabilities(bss
, ht_capa_oper
);
332 pos
= hostapd_eid_ht_operation(bss
, pos
);
333 wpabuf_put_data(buf
, ht_capa_oper
, pos
- ht_capa_oper
);
335 #endif /* CONFIG_IEEE80211N */
337 if (ampe
&& mesh_rsn_protect_frame(wpa_s
->mesh_rsn
, sta
, cat
, buf
)) {
338 wpa_msg(wpa_s
, MSG_INFO
,
339 "Mesh MPM: failed to add AMPE and MIC IE");
343 ret
= wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0,
344 sta
->addr
, wpa_s
->own_addr
, wpa_s
->own_addr
,
345 wpabuf_head(buf
), wpabuf_len(buf
), 0);
347 wpa_msg(wpa_s
, MSG_INFO
,
348 "Mesh MPM: failed to send peering frame");
355 /* configure peering state in ours and driver's station entry */
356 void wpa_mesh_set_plink_state(struct wpa_supplicant
*wpa_s
,
357 struct sta_info
*sta
,
358 enum mesh_plink_state state
)
360 struct hostapd_sta_add_params params
;
363 sta
->plink_state
= state
;
365 os_memset(¶ms
, 0, sizeof(params
));
366 params
.addr
= sta
->addr
;
367 params
.plink_state
= state
;
370 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM set " MACSTR
" into %s",
371 MAC2STR(sta
->addr
), mplstate
[state
]);
372 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
374 wpa_msg(wpa_s
, MSG_ERROR
, "Driver failed to set " MACSTR
375 ": %d", MAC2STR(sta
->addr
), ret
);
380 static void mesh_mpm_fsm_restart(struct wpa_supplicant
*wpa_s
,
381 struct sta_info
*sta
)
383 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
385 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
387 if (sta
->mpm_close_reason
== WLAN_REASON_MESH_CLOSE_RCVD
) {
388 ap_free_sta(hapd
, sta
);
392 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_LISTEN
);
393 sta
->my_lid
= sta
->peer_lid
= sta
->mpm_close_reason
= 0;
394 sta
->mpm_retries
= 0;
398 static void plink_timer(void *eloop_ctx
, void *user_data
)
400 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
401 struct sta_info
*sta
= user_data
;
403 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
405 switch (sta
->plink_state
) {
406 case PLINK_OPEN_RCVD
:
407 case PLINK_OPEN_SENT
:
409 if (sta
->mpm_retries
< conf
->dot11MeshMaxRetries
) {
410 eloop_register_timeout(
411 conf
->dot11MeshRetryTimeout
/ 1000,
412 (conf
->dot11MeshRetryTimeout
% 1000) * 1000,
413 plink_timer
, wpa_s
, sta
);
414 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_OPEN
, 0);
418 reason
= WLAN_REASON_MESH_MAX_RETRIES
;
419 /* fall through on else */
424 reason
= WLAN_REASON_MESH_CONFIRM_TIMEOUT
;
425 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
426 eloop_register_timeout(conf
->dot11MeshHoldingTimeout
/ 1000,
427 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
428 plink_timer
, wpa_s
, sta
);
429 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CLOSE
, reason
);
433 mesh_mpm_fsm_restart(wpa_s
, sta
);
441 /* initiate peering with station */
443 mesh_mpm_plink_open(struct wpa_supplicant
*wpa_s
, struct sta_info
*sta
,
444 enum mesh_plink_state next_state
)
446 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
448 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
449 eloop_register_timeout(conf
->dot11MeshRetryTimeout
/ 1000,
450 (conf
->dot11MeshRetryTimeout
% 1000) * 1000,
451 plink_timer
, wpa_s
, sta
);
452 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_OPEN
, 0);
453 wpa_mesh_set_plink_state(wpa_s
, sta
, next_state
);
457 int mesh_mpm_plink_close(struct hostapd_data
*hapd
,
458 struct sta_info
*sta
, void *ctx
)
460 struct wpa_supplicant
*wpa_s
= ctx
;
461 int reason
= WLAN_REASON_MESH_PEERING_CANCELLED
;
464 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
465 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CLOSE
, reason
);
466 wpa_printf(MSG_DEBUG
, "MPM closing plink sta=" MACSTR
,
468 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
476 void mesh_mpm_deinit(struct wpa_supplicant
*wpa_s
, struct hostapd_iface
*ifmsh
)
478 struct hostapd_data
*hapd
= ifmsh
->bss
[0];
480 /* notify peers we're leaving */
481 ap_for_each_sta(hapd
, mesh_mpm_plink_close
, wpa_s
);
483 hapd
->num_plinks
= 0;
484 hostapd_free_stas(hapd
);
488 /* for mesh_rsn to indicate this peer has completed authentication, and we're
489 * ready to start AMPE */
490 void mesh_mpm_auth_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
492 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
493 struct hostapd_sta_add_params params
;
494 struct sta_info
*sta
;
497 sta
= ap_get_sta(data
, addr
);
499 wpa_msg(wpa_s
, MSG_DEBUG
, "no such mesh peer");
503 /* TODO: Should do nothing if this STA is already authenticated, but
504 * the AP code already sets this flag. */
505 sta
->flags
|= WLAN_STA_AUTH
;
507 mesh_rsn_init_ampe_sta(wpa_s
, sta
);
509 os_memset(¶ms
, 0, sizeof(params
));
510 params
.addr
= sta
->addr
;
511 params
.flags
= WPA_STA_AUTHENTICATED
| WPA_STA_AUTHORIZED
;
514 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM authenticating " MACSTR
,
516 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
518 wpa_msg(wpa_s
, MSG_ERROR
,
519 "Driver failed to set " MACSTR
": %d",
520 MAC2STR(sta
->addr
), ret
);
524 mesh_mpm_init_link(wpa_s
, sta
);
526 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPEN_SENT
);
530 void wpa_mesh_new_mesh_peer(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
531 struct ieee802_11_elems
*elems
)
533 struct hostapd_sta_add_params params
;
534 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
535 struct hostapd_data
*data
= wpa_s
->ifmsh
->bss
[0];
536 struct sta_info
*sta
;
537 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
540 sta
= ap_get_sta(data
, addr
);
542 sta
= ap_sta_add(data
, addr
);
548 if (copy_supp_rates(wpa_s
, sta
, elems
))
551 mesh_mpm_init_link(wpa_s
, sta
);
553 #ifdef CONFIG_IEEE80211N
554 copy_sta_ht_capab(data
, sta
, elems
->ht_capabilities
,
555 elems
->ht_capabilities_len
);
556 update_ht_state(data
, sta
);
557 #endif /* CONFIG_IEEE80211N */
559 /* insert into driver */
560 os_memset(¶ms
, 0, sizeof(params
));
561 params
.supp_rates
= sta
->supported_rates
;
562 params
.supp_rates_len
= sta
->supported_rates_len
;
564 params
.plink_state
= sta
->plink_state
;
565 params
.aid
= sta
->peer_lid
;
566 params
.listen_interval
= 100;
567 params
.ht_capabilities
= sta
->ht_capabilities
;
568 params
.flags
|= WPA_STA_WMM
;
569 params
.flags_mask
|= WPA_STA_AUTHENTICATED
;
570 if (conf
->security
== MESH_CONF_SEC_NONE
) {
571 params
.flags
|= WPA_STA_AUTHORIZED
;
572 params
.flags
|= WPA_STA_AUTHENTICATED
;
574 sta
->flags
|= WLAN_STA_MFP
;
575 params
.flags
|= WPA_STA_MFP
;
578 ret
= wpa_drv_sta_add(wpa_s
, ¶ms
);
580 wpa_msg(wpa_s
, MSG_ERROR
,
581 "Driver failed to insert " MACSTR
": %d",
586 if (ssid
&& ssid
->no_auto_peer
) {
587 wpa_msg(wpa_s
, MSG_INFO
, "will not initiate new peer link with "
588 MACSTR
" because of no_auto_peer", MAC2STR(addr
));
589 if (data
->mesh_pending_auth
) {
590 struct os_reltime age
;
591 const struct ieee80211_mgmt
*mgmt
;
592 struct hostapd_frame_info fi
;
594 mgmt
= wpabuf_head(data
->mesh_pending_auth
);
595 os_reltime_age(&data
->mesh_pending_auth_time
, &age
);
597 os_memcmp(mgmt
->sa
, addr
, ETH_ALEN
) == 0) {
598 wpa_printf(MSG_DEBUG
,
599 "mesh: Process pending Authentication frame from %u.%06u seconds ago",
600 (unsigned int) age
.sec
,
601 (unsigned int) age
.usec
);
602 os_memset(&fi
, 0, sizeof(fi
));
605 wpabuf_head(data
->mesh_pending_auth
),
606 wpabuf_len(data
->mesh_pending_auth
),
609 wpabuf_free(data
->mesh_pending_auth
);
610 data
->mesh_pending_auth
= NULL
;
615 if (conf
->security
== MESH_CONF_SEC_NONE
)
616 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPEN_SENT
);
618 mesh_rsn_auth_sae_sta(wpa_s
, sta
);
622 void mesh_mpm_mgmt_rx(struct wpa_supplicant
*wpa_s
, struct rx_mgmt
*rx_mgmt
)
624 struct hostapd_frame_info fi
;
626 os_memset(&fi
, 0, sizeof(fi
));
627 fi
.datarate
= rx_mgmt
->datarate
;
628 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
629 ieee802_11_mgmt(wpa_s
->ifmsh
->bss
[0], rx_mgmt
->frame
,
630 rx_mgmt
->frame_len
, &fi
);
634 static void mesh_mpm_plink_estab(struct wpa_supplicant
*wpa_s
,
635 struct sta_info
*sta
)
637 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
638 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
641 wpa_msg(wpa_s
, MSG_INFO
, "mesh plink with " MACSTR
" established",
644 if (conf
->security
& MESH_CONF_SEC_AMPE
) {
645 wpa_drv_set_key(wpa_s
, WPA_ALG_CCMP
, sta
->addr
, 0, 0,
646 seq
, sizeof(seq
), sta
->mtk
, sizeof(sta
->mtk
));
647 wpa_drv_set_key(wpa_s
, WPA_ALG_CCMP
, sta
->addr
, 1, 0,
649 sta
->mgtk
, sizeof(sta
->mgtk
));
650 wpa_drv_set_key(wpa_s
, WPA_ALG_IGTK
, sta
->addr
, 4, 0,
652 sta
->mgtk
, sizeof(sta
->mgtk
));
654 wpa_hexdump_key(MSG_DEBUG
, "mtk:", sta
->mtk
, sizeof(sta
->mtk
));
655 wpa_hexdump_key(MSG_DEBUG
, "mgtk:",
656 sta
->mgtk
, sizeof(sta
->mgtk
));
659 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_ESTAB
);
662 sta
->flags
|= WLAN_STA_ASSOC
;
664 eloop_cancel_timeout(plink_timer
, wpa_s
, sta
);
666 /* Send ctrl event */
667 wpa_msg_ctrl(wpa_s
, MSG_INFO
, MESH_PEER_CONNECTED MACSTR
,
672 static void mesh_mpm_fsm(struct wpa_supplicant
*wpa_s
, struct sta_info
*sta
,
673 enum plink_event event
)
675 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
676 struct mesh_conf
*conf
= wpa_s
->ifmsh
->mconf
;
679 wpa_msg(wpa_s
, MSG_DEBUG
, "MPM " MACSTR
" state %s event %s",
680 MAC2STR(sta
->addr
), mplstate
[sta
->plink_state
],
683 switch (sta
->plink_state
) {
687 mesh_mpm_fsm_restart(wpa_s
, sta
);
690 mesh_mpm_plink_open(wpa_s
, sta
, PLINK_OPEN_RCVD
);
691 mesh_mpm_send_plink_action(wpa_s
, sta
, PLINK_CONFIRM
,
698 case PLINK_OPEN_SENT
:
702 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
705 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
707 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
708 eloop_register_timeout(
709 conf
->dot11MeshHoldingTimeout
/ 1000,
710 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
711 plink_timer
, wpa_s
, sta
);
712 mesh_mpm_send_plink_action(wpa_s
, sta
,
713 PLINK_CLOSE
, reason
);
716 /* retry timer is left untouched */
717 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_OPEN_RCVD
);
718 mesh_mpm_send_plink_action(wpa_s
, sta
,
722 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_CNF_RCVD
);
723 eloop_register_timeout(
724 conf
->dot11MeshConfirmTimeout
/ 1000,
725 (conf
->dot11MeshConfirmTimeout
% 1000) * 1000,
726 plink_timer
, wpa_s
, sta
);
732 case PLINK_OPEN_RCVD
:
736 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
739 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
741 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
742 eloop_register_timeout(
743 conf
->dot11MeshHoldingTimeout
/ 1000,
744 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
745 plink_timer
, wpa_s
, sta
);
746 sta
->mpm_close_reason
= reason
;
747 mesh_mpm_send_plink_action(wpa_s
, sta
,
748 PLINK_CLOSE
, reason
);
751 mesh_mpm_send_plink_action(wpa_s
, sta
,
755 if (conf
->security
& MESH_CONF_SEC_AMPE
)
756 mesh_rsn_derive_mtk(wpa_s
, sta
);
757 mesh_mpm_plink_estab(wpa_s
, sta
);
767 reason
= WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION
;
770 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
772 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
773 eloop_register_timeout(
774 conf
->dot11MeshHoldingTimeout
/ 1000,
775 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
776 plink_timer
, wpa_s
, sta
);
777 sta
->mpm_close_reason
= reason
;
778 mesh_mpm_send_plink_action(wpa_s
, sta
,
779 PLINK_CLOSE
, reason
);
782 mesh_mpm_plink_estab(wpa_s
, sta
);
783 mesh_mpm_send_plink_action(wpa_s
, sta
,
793 wpa_mesh_set_plink_state(wpa_s
, sta
, PLINK_HOLDING
);
794 reason
= WLAN_REASON_MESH_CLOSE_RCVD
;
796 eloop_register_timeout(
797 conf
->dot11MeshHoldingTimeout
/ 1000,
798 (conf
->dot11MeshHoldingTimeout
% 1000) * 1000,
799 plink_timer
, wpa_s
, sta
);
800 sta
->mpm_close_reason
= reason
;
802 wpa_msg(wpa_s
, MSG_INFO
, "mesh plink with " MACSTR
803 " closed with reason %d",
804 MAC2STR(sta
->addr
), reason
);
806 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
807 MESH_PEER_DISCONNECTED MACSTR
,
812 mesh_mpm_send_plink_action(wpa_s
, sta
,
813 PLINK_CLOSE
, reason
);
816 mesh_mpm_send_plink_action(wpa_s
, sta
,
826 mesh_mpm_fsm_restart(wpa_s
, sta
);
832 reason
= sta
->mpm_close_reason
;
833 mesh_mpm_send_plink_action(wpa_s
, sta
,
834 PLINK_CLOSE
, reason
);
841 wpa_msg(wpa_s
, MSG_DEBUG
,
842 "Unsupported MPM event %s for state %s",
843 mplevent
[event
], mplstate
[sta
->plink_state
]);
849 void mesh_mpm_action_rx(struct wpa_supplicant
*wpa_s
,
850 const struct ieee80211_mgmt
*mgmt
, size_t len
)
853 struct hostapd_data
*hapd
= wpa_s
->ifmsh
->bss
[0];
854 struct mesh_conf
*mconf
= wpa_s
->ifmsh
->mconf
;
855 struct sta_info
*sta
;
856 u16 plid
= 0, llid
= 0;
857 enum plink_event event
;
858 struct ieee802_11_elems elems
;
859 struct mesh_peer_mgmt_ie peer_mgmt_ie
;
864 if (mgmt
->u
.action
.category
!= WLAN_ACTION_SELF_PROTECTED
)
867 action_field
= mgmt
->u
.action
.u
.slf_prot_action
.action
;
868 if (action_field
!= PLINK_OPEN
&&
869 action_field
!= PLINK_CONFIRM
&&
870 action_field
!= PLINK_CLOSE
)
873 ies
= mgmt
->u
.action
.u
.slf_prot_action
.variable
;
874 ie_len
= (const u8
*) mgmt
+ len
-
875 mgmt
->u
.action
.u
.slf_prot_action
.variable
;
877 /* at least expect mesh id and peering mgmt */
878 if (ie_len
< 2 + 2) {
879 wpa_printf(MSG_DEBUG
,
880 "MPM: Ignore too short action frame %u ie_len %u",
881 action_field
, (unsigned int) ie_len
);
884 wpa_printf(MSG_DEBUG
, "MPM: Received PLINK action %u", action_field
);
886 if (action_field
== PLINK_OPEN
|| action_field
== PLINK_CONFIRM
) {
887 wpa_printf(MSG_DEBUG
, "MPM: Capability 0x%x",
889 ies
+= 2; /* capability */
892 if (action_field
== PLINK_CONFIRM
) {
893 wpa_printf(MSG_DEBUG
, "MPM: AID 0x%x", WPA_GET_LE16(ies
));
898 /* check for mesh peering, mesh id and mesh config IEs */
899 if (ieee802_11_parse_elems(ies
, ie_len
, &elems
, 0) == ParseFailed
) {
900 wpa_printf(MSG_DEBUG
, "MPM: Failed to parse PLINK IEs");
903 if (!elems
.peer_mgmt
) {
904 wpa_printf(MSG_DEBUG
,
905 "MPM: No Mesh Peering Management element");
908 if (action_field
!= PLINK_CLOSE
) {
909 if (!elems
.mesh_id
|| !elems
.mesh_config
) {
910 wpa_printf(MSG_DEBUG
,
911 "MPM: No Mesh ID or Mesh Configuration element");
915 if (!matches_local(wpa_s
, &elems
)) {
916 wpa_printf(MSG_DEBUG
,
917 "MPM: Mesh ID or Mesh Configuration element do not match local MBSS");
922 ret
= mesh_mpm_parse_peer_mgmt(wpa_s
, action_field
,
927 wpa_printf(MSG_DEBUG
, "MPM: Mesh parsing rejected frame");
931 /* the sender's llid is our plid and vice-versa */
932 plid
= WPA_GET_LE16(peer_mgmt_ie
.llid
);
933 if (peer_mgmt_ie
.plid
)
934 llid
= WPA_GET_LE16(peer_mgmt_ie
.plid
);
935 wpa_printf(MSG_DEBUG
, "MPM: plid=0x%x llid=0x%x", plid
, llid
);
937 sta
= ap_get_sta(hapd
, mgmt
->sa
);
939 wpa_printf(MSG_DEBUG
, "MPM: No STA entry for peer");
944 /* peer is in sae_accepted? */
945 if (sta
->sae
&& sta
->sae
->state
!= SAE_ACCEPTED
) {
946 wpa_printf(MSG_DEBUG
, "MPM: SAE not yet accepted for peer");
949 #endif /* CONFIG_SAE */
952 mesh_mpm_init_link(wpa_s
, sta
);
954 if ((mconf
->security
& MESH_CONF_SEC_AMPE
) &&
955 mesh_rsn_process_ampe(wpa_s
, sta
, &elems
,
956 &mgmt
->u
.action
.category
,
958 wpa_printf(MSG_DEBUG
, "MPM: RSN process rejected frame");
962 if (sta
->plink_state
== PLINK_BLOCKED
) {
963 wpa_printf(MSG_DEBUG
, "MPM: PLINK_BLOCKED");
967 /* Now we will figure out the appropriate event... */
968 switch (action_field
) {
970 if (plink_free_count(hapd
) == 0) {
973 "MPM: Peer link num over quota(%d)",
975 } else if (sta
->peer_lid
&& sta
->peer_lid
!= plid
) {
978 sta
->peer_lid
= plid
;
983 if (plink_free_count(hapd
) == 0) {
986 "MPM: Peer link num over quota(%d)",
988 } else if (sta
->my_lid
!= llid
||
989 (sta
->peer_lid
&& sta
->peer_lid
!= plid
)) {
993 sta
->peer_lid
= plid
;
998 if (sta
->plink_state
== PLINK_ESTAB
)
999 /* Do not check for llid or plid. This does not
1000 * follow the standard but since multiple plinks
1001 * per cand are not supported, it is necessary in
1002 * order to avoid a livelock when MP A sees an
1003 * establish peer link to MP B but MP B does not
1004 * see it. This can be caused by a timeout in
1005 * B's peer link establishment or B being
1009 else if (sta
->peer_lid
!= plid
)
1011 else if (peer_mgmt_ie
.plid
&& sta
->my_lid
!= llid
)
1018 * This cannot be hit due to the action_field check above, but
1019 * compilers may not be able to figure that out and can warn
1020 * about uninitialized event below.
1024 mesh_mpm_fsm(wpa_s
, sta
, event
);
1028 /* called by ap_free_sta */
1029 void mesh_mpm_free_sta(struct sta_info
*sta
)
1031 eloop_cancel_timeout(plink_timer
, ELOOP_ALL_CTX
, sta
);
1032 eloop_cancel_timeout(mesh_auth_timer
, ELOOP_ALL_CTX
, sta
);