blob: c9e14d5c2d61749f4e25fae807c3d1352a3a640d [file] [log] [blame]
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001/*
2 * WPA Supplicant - Basic mesh peer management
3 * Copyright (c) 2013-2014, cozybit, Inc. All rights reserved.
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "utils/eloop.h"
13#include "common/ieee802_11_defs.h"
Paul Stewart092955c2017-02-06 09:13:09 -080014#include "common/hw_features_common.h"
Hai Shalom74f70d42019-02-11 14:42:39 -080015#include "common/ocv.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080016#include "ap/hostapd.h"
17#include "ap/sta_info.h"
18#include "ap/ieee802_11.h"
Dmitry Shmidte4663042016-04-04 10:07:49 -070019#include "ap/wpa_auth.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080020#include "wpa_supplicant_i.h"
21#include "driver_i.h"
22#include "mesh_mpm.h"
23#include "mesh_rsn.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070024#include "notify.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080025
26struct mesh_peer_mgmt_ie {
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -080027 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) */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080032};
33
34static void plink_timer(void *eloop_ctx, void *user_data);
35
36
37enum plink_event {
38 PLINK_UNDEFINED,
39 OPN_ACPT,
40 OPN_RJCT,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080041 CNF_ACPT,
42 CNF_RJCT,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080043 CLS_ACPT,
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070044 REQ_RJCT
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080045};
46
47static const char * const mplstate[] = {
Dmitry Shmidtde47be72016-01-07 12:52:55 -080048 [0] = "UNINITIALIZED",
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070049 [PLINK_IDLE] = "IDLE",
50 [PLINK_OPN_SNT] = "OPN_SNT",
51 [PLINK_OPN_RCVD] = "OPN_RCVD",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080052 [PLINK_CNF_RCVD] = "CNF_RCVD",
53 [PLINK_ESTAB] = "ESTAB",
54 [PLINK_HOLDING] = "HOLDING",
55 [PLINK_BLOCKED] = "BLOCKED"
56};
57
58static const char * const mplevent[] = {
59 [PLINK_UNDEFINED] = "UNDEFINED",
60 [OPN_ACPT] = "OPN_ACPT",
61 [OPN_RJCT] = "OPN_RJCT",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080062 [CNF_ACPT] = "CNF_ACPT",
63 [CNF_RJCT] = "CNF_RJCT",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080064 [CLS_ACPT] = "CLS_ACPT",
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070065 [REQ_RJCT] = "REQ_RJCT",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080066};
67
68
69static int mesh_mpm_parse_peer_mgmt(struct wpa_supplicant *wpa_s,
70 u8 action_field,
71 const u8 *ie, size_t len,
72 struct mesh_peer_mgmt_ie *mpm_ie)
73{
74 os_memset(mpm_ie, 0, sizeof(*mpm_ie));
75
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -080076 /* Remove optional Chosen PMK field at end */
77 if (len >= SAE_PMKID_LEN) {
78 mpm_ie->chosen_pmk = ie + len - SAE_PMKID_LEN;
79 len -= SAE_PMKID_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080080 }
81
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");
86 return -1;
87 }
88
89 /* required fields */
90 if (len < 4)
91 return -1;
92 mpm_ie->proto_id = ie;
93 mpm_ie->llid = ie + 2;
94 ie += 4;
95 len -= 4;
96
97 /* close reason is always present at end for close */
98 if (action_field == PLINK_CLOSE) {
99 if (len < 2)
100 return -1;
101 mpm_ie->reason = ie + len - 2;
102 len -= 2;
103 }
104
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800105 /* Peer Link ID, present for confirm, and possibly close */
106 if (len >= 2)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800107 mpm_ie->plid = ie;
108
109 return 0;
110}
111
112
113static int plink_free_count(struct hostapd_data *hapd)
114{
115 if (hapd->max_plinks > hapd->num_plinks)
116 return hapd->max_plinks - hapd->num_plinks;
117 return 0;
118}
119
120
121static u16 copy_supp_rates(struct wpa_supplicant *wpa_s,
122 struct sta_info *sta,
123 struct ieee802_11_elems *elems)
124{
125 if (!elems->supp_rates) {
126 wpa_msg(wpa_s, MSG_ERROR, "no supported rates from " MACSTR,
127 MAC2STR(sta->addr));
128 return WLAN_STATUS_UNSPECIFIED_FAILURE;
129 }
130
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;
138 }
139
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);
144
145 return WLAN_STATUS_SUCCESS;
146}
147
148
149/* return true if elems from a neighbor match this MBSS */
Hai Shalome21d4e82020-04-29 16:34:06 -0700150static bool matches_local(struct wpa_supplicant *wpa_s,
151 struct ieee802_11_elems *elems)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800152{
153 struct mesh_conf *mconf = wpa_s->ifmsh->mconf;
154
155 if (elems->mesh_config_len < 5)
Hai Shalome21d4e82020-04-29 16:34:06 -0700156 return false;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800157
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]);
166}
167
168
169/* check if local link id is already used with another peer */
Hai Shalome21d4e82020-04-29 16:34:06 -0700170static bool llid_in_use(struct wpa_supplicant *wpa_s, u16 llid)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800171{
172 struct sta_info *sta;
173 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
174
175 for (sta = hapd->sta_list; sta; sta = sta->next) {
176 if (sta->my_lid == llid)
Hai Shalome21d4e82020-04-29 16:34:06 -0700177 return true;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800178 }
179
Hai Shalome21d4e82020-04-29 16:34:06 -0700180 return false;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800181}
182
183
184/* generate an llid for a link and set to initial state */
185static void mesh_mpm_init_link(struct wpa_supplicant *wpa_s,
186 struct sta_info *sta)
187{
188 u16 llid;
189
190 do {
191 if (os_get_random((u8 *) &llid, sizeof(llid)) < 0)
Hai Shalom5f92bc92019-04-18 11:54:11 -0700192 llid = 0; /* continue */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800193 } while (!llid || llid_in_use(wpa_s, llid));
194
195 sta->my_lid = llid;
196 sta->peer_lid = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700197 sta->peer_aid = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800198
199 /*
200 * We do not use wpa_mesh_set_plink_state() here because there is no
201 * entry in kernel yet.
202 */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700203 sta->plink_state = PLINK_IDLE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800204}
205
206
207static void mesh_mpm_send_plink_action(struct wpa_supplicant *wpa_s,
208 struct sta_info *sta,
209 enum plink_action_field type,
210 u16 close_reason)
211{
212 struct wpabuf *buf;
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];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800217 u8 *pos, *cat;
218 u8 ie_len, add_plid = 0;
219 int ret;
220 int ampe = conf->security & MESH_CONF_SEC_AMPE;
221 size_t buf_len;
222
223 if (!sta)
224 return;
225
Hai Shalom74f70d42019-02-11 14:42:39 -0800226 buf_len = 2 + /* Category and Action */
227 2 + /* capability info */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800228 2 + /* AID */
229 2 + 8 + /* supported rates */
230 2 + (32 - 8) +
231 2 + 32 + /* mesh ID */
232 2 + 7 + /* mesh config */
Hai Shalom74f70d42019-02-11 14:42:39 -0800233 2 + 24 + /* peering management */
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800234 2 + 96 + 32 + 32 + /* AMPE (96 + max GTKlen + max IGTKlen) */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800235 2 + 16; /* MIC */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800236 if (type != PLINK_CLOSE && wpa_s->mesh_ht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800237 buf_len += 2 + 26 + /* HT capabilities */
238 2 + 22; /* HT operation */
239 }
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800240#ifdef CONFIG_IEEE80211AC
241 if (type != PLINK_CLOSE && wpa_s->mesh_vht_enabled) {
242 buf_len += 2 + 12 + /* VHT Capabilities */
243 2 + 5; /* VHT Operation */
244 }
245#endif /* CONFIG_IEEE80211AC */
Hai Shalom81f62d82019-07-22 12:10:00 -0700246#ifdef CONFIG_IEEE80211AX
247 if (type != PLINK_CLOSE && wpa_s->mesh_he_enabled) {
248 buf_len += 3 +
249 HE_MAX_MAC_CAPAB_SIZE +
250 HE_MAX_PHY_CAPAB_SIZE +
251 HE_MAX_MCS_CAPAB_SIZE +
252 HE_MAX_PPET_CAPAB_SIZE;
253 buf_len += 3 + sizeof(struct ieee80211_he_operation);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800254 if (is_6ghz_op_class(bss->iconf->op_class))
255 buf_len += sizeof(struct ieee80211_he_6ghz_oper_info) +
256 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Hai Shalom81f62d82019-07-22 12:10:00 -0700257 }
258#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800259 if (type != PLINK_CLOSE)
260 buf_len += conf->rsn_ie_len; /* RSN IE */
Hai Shalom74f70d42019-02-11 14:42:39 -0800261#ifdef CONFIG_OCV
262 /* OCI is included even when the other STA doesn't support OCV */
263 if (type != PLINK_CLOSE && conf->ocv)
264 buf_len += OCV_OCI_EXTENDED_LEN;
265#endif /* CONFIG_OCV */
Sunil Ravi036cec52023-03-29 11:35:17 -0700266#ifdef CONFIG_IEEE80211BE
267 if (type != PLINK_CLOSE && wpa_s->mesh_eht_enabled) {
268 buf_len += 3 + 2 + EHT_PHY_CAPAB_LEN + EHT_MCS_NSS_CAPAB_LEN +
269 EHT_PPE_THRESH_CAPAB_LEN;
270 buf_len += 3 + sizeof(struct ieee80211_eht_operation);
271}
272#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800273
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800274 buf = wpabuf_alloc(buf_len);
275 if (!buf)
276 return;
277
278 cat = wpabuf_mhead_u8(buf);
279 wpabuf_put_u8(buf, WLAN_ACTION_SELF_PROTECTED);
280 wpabuf_put_u8(buf, type);
281
282 if (type != PLINK_CLOSE) {
283 u8 info;
284
285 /* capability info */
286 wpabuf_put_le16(buf, ampe ? IEEE80211_CAP_PRIVACY : 0);
287
288 /* aid */
289 if (type == PLINK_CONFIRM)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800290 wpabuf_put_le16(buf, sta->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800291
292 /* IE: supp + ext. supp rates */
293 pos = hostapd_eid_supp_rates(bss, supp_rates);
294 pos = hostapd_eid_ext_supp_rates(bss, pos);
295 wpabuf_put_data(buf, supp_rates, pos - supp_rates);
296
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800297 /* IE: RSN IE */
298 wpabuf_put_data(buf, conf->rsn_ie, conf->rsn_ie_len);
299
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800300 /* IE: Mesh ID */
301 wpabuf_put_u8(buf, WLAN_EID_MESH_ID);
302 wpabuf_put_u8(buf, conf->meshid_len);
303 wpabuf_put_data(buf, conf->meshid, conf->meshid_len);
304
305 /* IE: mesh conf */
306 wpabuf_put_u8(buf, WLAN_EID_MESH_CONFIG);
307 wpabuf_put_u8(buf, 7);
308 wpabuf_put_u8(buf, conf->mesh_pp_id);
309 wpabuf_put_u8(buf, conf->mesh_pm_id);
310 wpabuf_put_u8(buf, conf->mesh_cc_id);
311 wpabuf_put_u8(buf, conf->mesh_sp_id);
312 wpabuf_put_u8(buf, conf->mesh_auth_id);
313 info = (bss->num_plinks > 63 ? 63 : bss->num_plinks) << 1;
314 /* TODO: Add Connected to Mesh Gate/AS subfields */
315 wpabuf_put_u8(buf, info);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800316 /* Set forwarding based on configuration and always accept
317 * plinks for now */
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700318 wpabuf_put_u8(buf, MESH_CAP_ACCEPT_ADDITIONAL_PEER |
Hai Shaloma20dcd72022-02-04 13:43:00 -0800319 (conf->mesh_fwding ? MESH_CAP_FORWARDING : 0));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800320 } else { /* Peer closing frame */
321 /* IE: Mesh ID */
322 wpabuf_put_u8(buf, WLAN_EID_MESH_ID);
323 wpabuf_put_u8(buf, conf->meshid_len);
324 wpabuf_put_data(buf, conf->meshid, conf->meshid_len);
325 }
326
327 /* IE: Mesh Peering Management element */
328 ie_len = 4;
329 if (ampe)
330 ie_len += PMKID_LEN;
331 switch (type) {
332 case PLINK_OPEN:
333 break;
334 case PLINK_CONFIRM:
335 ie_len += 2;
336 add_plid = 1;
337 break;
338 case PLINK_CLOSE:
339 ie_len += 2;
340 add_plid = 1;
341 ie_len += 2; /* reason code */
342 break;
343 }
344
345 wpabuf_put_u8(buf, WLAN_EID_PEER_MGMT);
346 wpabuf_put_u8(buf, ie_len);
347 /* peering protocol */
348 if (ampe)
349 wpabuf_put_le16(buf, 1);
350 else
351 wpabuf_put_le16(buf, 0);
352 wpabuf_put_le16(buf, sta->my_lid);
353 if (add_plid)
354 wpabuf_put_le16(buf, sta->peer_lid);
355 if (type == PLINK_CLOSE)
356 wpabuf_put_le16(buf, close_reason);
357 if (ampe) {
358 if (sta->sae == NULL) {
359 wpa_msg(wpa_s, MSG_INFO, "Mesh MPM: no SAE session");
360 goto fail;
361 }
362 mesh_rsn_get_pmkid(wpa_s->mesh_rsn, sta,
363 wpabuf_put(buf, PMKID_LEN));
364 }
365
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800366 if (type != PLINK_CLOSE && wpa_s->mesh_ht_enabled) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800367 u8 ht_capa_oper[2 + 26 + 2 + 22];
368
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800369 pos = hostapd_eid_ht_capabilities(bss, ht_capa_oper);
370 pos = hostapd_eid_ht_operation(bss, pos);
371 wpabuf_put_data(buf, ht_capa_oper, pos - ht_capa_oper);
372 }
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800373#ifdef CONFIG_IEEE80211AC
374 if (type != PLINK_CLOSE && wpa_s->mesh_vht_enabled) {
375 u8 vht_capa_oper[2 + 12 + 2 + 5];
376
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700377 pos = hostapd_eid_vht_capabilities(bss, vht_capa_oper, 0);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800378 pos = hostapd_eid_vht_operation(bss, pos);
379 wpabuf_put_data(buf, vht_capa_oper, pos - vht_capa_oper);
380 }
381#endif /* CONFIG_IEEE80211AC */
Hai Shalom81f62d82019-07-22 12:10:00 -0700382#ifdef CONFIG_IEEE80211AX
383 if (type != PLINK_CLOSE && wpa_s->mesh_he_enabled) {
384 u8 he_capa_oper[3 +
385 HE_MAX_MAC_CAPAB_SIZE +
386 HE_MAX_PHY_CAPAB_SIZE +
387 HE_MAX_MCS_CAPAB_SIZE +
388 HE_MAX_PPET_CAPAB_SIZE +
Hai Shaloma20dcd72022-02-04 13:43:00 -0800389 3 + sizeof(struct ieee80211_he_operation) +
390 sizeof(struct ieee80211_he_6ghz_oper_info) +
391 3 + sizeof(struct ieee80211_he_6ghz_band_cap)];
Hai Shalom81f62d82019-07-22 12:10:00 -0700392
393 pos = hostapd_eid_he_capab(bss, he_capa_oper,
394 IEEE80211_MODE_MESH);
395 pos = hostapd_eid_he_operation(bss, pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800396 pos = hostapd_eid_he_6ghz_band_cap(bss, pos);
Hai Shalom81f62d82019-07-22 12:10:00 -0700397 wpabuf_put_data(buf, he_capa_oper, pos - he_capa_oper);
398 }
399#endif /* CONFIG_IEEE80211AX */
Hai Shalom74f70d42019-02-11 14:42:39 -0800400#ifdef CONFIG_OCV
401 if (type != PLINK_CLOSE && conf->ocv) {
402 struct wpa_channel_info ci;
403
404 if (wpa_drv_channel_info(wpa_s, &ci) != 0) {
405 wpa_printf(MSG_WARNING,
406 "Mesh MPM: Failed to get channel info for OCI element");
407 goto fail;
408 }
409
410 pos = wpabuf_put(buf, OCV_OCI_EXTENDED_LEN);
411 if (ocv_insert_extended_oci(&ci, pos) < 0)
412 goto fail;
413 }
414#endif /* CONFIG_OCV */
415
Sunil Ravi036cec52023-03-29 11:35:17 -0700416#ifdef CONFIG_IEEE80211BE
417 if (type != PLINK_CLOSE && wpa_s->mesh_eht_enabled) {
418 u8 eht_capa_oper[3 +
419 2 +
420 EHT_PHY_CAPAB_LEN +
421 EHT_MCS_NSS_CAPAB_LEN +
422 EHT_PPE_THRESH_CAPAB_LEN +
423 3 + sizeof(struct ieee80211_eht_operation)];
424 pos = hostapd_eid_eht_capab(bss, eht_capa_oper,
425 IEEE80211_MODE_MESH);
426 pos = hostapd_eid_eht_operation(bss, pos);
427 wpabuf_put_data(buf, eht_capa_oper, pos - eht_capa_oper);
428 }
429#endif /* CONFIG_IEEE80211BE */
430
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800431 if (ampe && mesh_rsn_protect_frame(wpa_s->mesh_rsn, sta, cat, buf)) {
432 wpa_msg(wpa_s, MSG_INFO,
433 "Mesh MPM: failed to add AMPE and MIC IE");
434 goto fail;
435 }
436
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800437 wpa_msg(wpa_s, MSG_DEBUG, "Mesh MPM: Sending peering frame type %d to "
438 MACSTR " (my_lid=0x%x peer_lid=0x%x)",
439 type, MAC2STR(sta->addr), sta->my_lid, sta->peer_lid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800440 ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
441 sta->addr, wpa_s->own_addr, wpa_s->own_addr,
442 wpabuf_head(buf), wpabuf_len(buf), 0);
443 if (ret < 0)
444 wpa_msg(wpa_s, MSG_INFO,
445 "Mesh MPM: failed to send peering frame");
446
447fail:
448 wpabuf_free(buf);
449}
450
451
452/* configure peering state in ours and driver's station entry */
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800453void wpa_mesh_set_plink_state(struct wpa_supplicant *wpa_s,
454 struct sta_info *sta,
455 enum mesh_plink_state state)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800456{
457 struct hostapd_sta_add_params params;
458 int ret;
459
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800460 wpa_msg(wpa_s, MSG_DEBUG, "MPM set " MACSTR " from %s into %s",
461 MAC2STR(sta->addr), mplstate[sta->plink_state],
462 mplstate[state]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800463 sta->plink_state = state;
464
465 os_memset(&params, 0, sizeof(params));
466 params.addr = sta->addr;
467 params.plink_state = state;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700468 params.peer_aid = sta->peer_aid;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800469 params.set = 1;
470
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800471 ret = wpa_drv_sta_add(wpa_s, &params);
472 if (ret) {
473 wpa_msg(wpa_s, MSG_ERROR, "Driver failed to set " MACSTR
474 ": %d", MAC2STR(sta->addr), ret);
475 }
476}
477
478
479static void mesh_mpm_fsm_restart(struct wpa_supplicant *wpa_s,
480 struct sta_info *sta)
481{
482 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
483
484 eloop_cancel_timeout(plink_timer, wpa_s, sta);
485
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800486 ap_free_sta(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800487}
488
489
490static void plink_timer(void *eloop_ctx, void *user_data)
491{
492 struct wpa_supplicant *wpa_s = eloop_ctx;
493 struct sta_info *sta = user_data;
494 u16 reason = 0;
495 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700496 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800497
498 switch (sta->plink_state) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700499 case PLINK_OPN_RCVD:
500 case PLINK_OPN_SNT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800501 /* retry timer */
502 if (sta->mpm_retries < conf->dot11MeshMaxRetries) {
503 eloop_register_timeout(
504 conf->dot11MeshRetryTimeout / 1000,
505 (conf->dot11MeshRetryTimeout % 1000) * 1000,
506 plink_timer, wpa_s, sta);
507 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_OPEN, 0);
508 sta->mpm_retries++;
509 break;
510 }
511 reason = WLAN_REASON_MESH_MAX_RETRIES;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700512 /* fall through */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800513
514 case PLINK_CNF_RCVD:
515 /* confirm timer */
516 if (!reason)
517 reason = WLAN_REASON_MESH_CONFIRM_TIMEOUT;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800518 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800519 eloop_register_timeout(conf->dot11MeshHoldingTimeout / 1000,
520 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
521 plink_timer, wpa_s, sta);
522 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CLOSE, reason);
523 break;
524 case PLINK_HOLDING:
525 /* holding timer */
Dmitry Shmidte4663042016-04-04 10:07:49 -0700526
527 if (sta->mesh_sae_pmksa_caching) {
528 wpa_printf(MSG_DEBUG, "MPM: Peer " MACSTR
529 " looks like it does not support mesh SAE PMKSA caching, so remove the cached entry for it",
530 MAC2STR(sta->addr));
531 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
532 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800533 mesh_mpm_fsm_restart(wpa_s, sta);
534 break;
535 default:
536 break;
537 }
538}
539
540
541/* initiate peering with station */
542static void
543mesh_mpm_plink_open(struct wpa_supplicant *wpa_s, struct sta_info *sta,
544 enum mesh_plink_state next_state)
545{
546 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
547
548 eloop_cancel_timeout(plink_timer, wpa_s, sta);
549 eloop_register_timeout(conf->dot11MeshRetryTimeout / 1000,
550 (conf->dot11MeshRetryTimeout % 1000) * 1000,
551 plink_timer, wpa_s, sta);
552 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_OPEN, 0);
553 wpa_mesh_set_plink_state(wpa_s, sta, next_state);
554}
555
556
Dmitry Shmidte4663042016-04-04 10:07:49 -0700557static int mesh_mpm_plink_close(struct hostapd_data *hapd, struct sta_info *sta,
558 void *ctx)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800559{
560 struct wpa_supplicant *wpa_s = ctx;
561 int reason = WLAN_REASON_MESH_PEERING_CANCELLED;
562
563 if (sta) {
Hai Shalom899fcc72020-10-19 14:38:18 -0700564 if (sta->plink_state == PLINK_ESTAB)
565 hapd->num_plinks--;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800566 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
567 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CLOSE, reason);
568 wpa_printf(MSG_DEBUG, "MPM closing plink sta=" MACSTR,
569 MAC2STR(sta->addr));
570 eloop_cancel_timeout(plink_timer, wpa_s, sta);
Hai Shalom899fcc72020-10-19 14:38:18 -0700571 eloop_cancel_timeout(mesh_auth_timer, wpa_s, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800572 return 0;
573 }
574
575 return 1;
576}
577
578
Dmitry Shmidte4663042016-04-04 10:07:49 -0700579int mesh_mpm_close_peer(struct wpa_supplicant *wpa_s, const u8 *addr)
580{
581 struct hostapd_data *hapd;
582 struct sta_info *sta;
583
584 if (!wpa_s->ifmsh) {
585 wpa_msg(wpa_s, MSG_INFO, "Mesh is not prepared yet");
586 return -1;
587 }
588
589 hapd = wpa_s->ifmsh->bss[0];
590 sta = ap_get_sta(hapd, addr);
591 if (!sta) {
592 wpa_msg(wpa_s, MSG_INFO, "No such mesh peer");
593 return -1;
594 }
595
596 return mesh_mpm_plink_close(hapd, sta, wpa_s) == 0 ? 0 : -1;
597}
598
599
600static void peer_add_timer(void *eloop_ctx, void *user_data)
601{
602 struct wpa_supplicant *wpa_s = eloop_ctx;
603 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
604
605 os_memset(hapd->mesh_required_peer, 0, ETH_ALEN);
606}
607
608
609int mesh_mpm_connect_peer(struct wpa_supplicant *wpa_s, const u8 *addr,
610 int duration)
611{
612 struct wpa_ssid *ssid = wpa_s->current_ssid;
613 struct hostapd_data *hapd;
614 struct sta_info *sta;
615 struct mesh_conf *conf;
616
617 if (!wpa_s->ifmsh) {
618 wpa_msg(wpa_s, MSG_INFO, "Mesh is not prepared yet");
619 return -1;
620 }
621
622 if (!ssid || !ssid->no_auto_peer) {
623 wpa_msg(wpa_s, MSG_INFO,
624 "This command is available only with no_auto_peer mesh network");
625 return -1;
626 }
627
628 hapd = wpa_s->ifmsh->bss[0];
629 conf = wpa_s->ifmsh->mconf;
630
631 sta = ap_get_sta(hapd, addr);
632 if (!sta) {
633 wpa_msg(wpa_s, MSG_INFO, "No such mesh peer");
634 return -1;
635 }
636
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700637 if ((PLINK_OPN_SNT <= sta->plink_state &&
Dmitry Shmidte4663042016-04-04 10:07:49 -0700638 sta->plink_state <= PLINK_ESTAB) ||
639 (sta->sae && sta->sae->state > SAE_NOTHING)) {
640 wpa_msg(wpa_s, MSG_INFO,
641 "Specified peer is connecting/connected");
642 return -1;
643 }
644
645 if (conf->security == MESH_CONF_SEC_NONE) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700646 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPN_SNT);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700647 } else {
648 mesh_rsn_auth_sae_sta(wpa_s, sta);
649 os_memcpy(hapd->mesh_required_peer, addr, ETH_ALEN);
650 eloop_register_timeout(duration == -1 ? 10 : duration, 0,
651 peer_add_timer, wpa_s, NULL);
652 }
653
654 return 0;
655}
656
657
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800658void mesh_mpm_deinit(struct wpa_supplicant *wpa_s, struct hostapd_iface *ifmsh)
659{
660 struct hostapd_data *hapd = ifmsh->bss[0];
661
662 /* notify peers we're leaving */
663 ap_for_each_sta(hapd, mesh_mpm_plink_close, wpa_s);
664
665 hapd->num_plinks = 0;
666 hostapd_free_stas(hapd);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700667 eloop_cancel_timeout(peer_add_timer, wpa_s, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800668}
669
670
671/* for mesh_rsn to indicate this peer has completed authentication, and we're
672 * ready to start AMPE */
673void mesh_mpm_auth_peer(struct wpa_supplicant *wpa_s, const u8 *addr)
674{
675 struct hostapd_data *data = wpa_s->ifmsh->bss[0];
676 struct hostapd_sta_add_params params;
677 struct sta_info *sta;
678 int ret;
679
680 sta = ap_get_sta(data, addr);
681 if (!sta) {
682 wpa_msg(wpa_s, MSG_DEBUG, "no such mesh peer");
683 return;
684 }
685
686 /* TODO: Should do nothing if this STA is already authenticated, but
687 * the AP code already sets this flag. */
688 sta->flags |= WLAN_STA_AUTH;
689
690 mesh_rsn_init_ampe_sta(wpa_s, sta);
691
692 os_memset(&params, 0, sizeof(params));
693 params.addr = sta->addr;
694 params.flags = WPA_STA_AUTHENTICATED | WPA_STA_AUTHORIZED;
695 params.set = 1;
696
697 wpa_msg(wpa_s, MSG_DEBUG, "MPM authenticating " MACSTR,
698 MAC2STR(sta->addr));
699 ret = wpa_drv_sta_add(wpa_s, &params);
700 if (ret) {
701 wpa_msg(wpa_s, MSG_ERROR,
702 "Driver failed to set " MACSTR ": %d",
703 MAC2STR(sta->addr), ret);
704 }
705
706 if (!sta->my_lid)
707 mesh_mpm_init_link(wpa_s, sta);
708
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700709 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPN_SNT);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800710}
711
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800712/*
713 * Initialize a sta_info structure for a peer and upload it into the driver
714 * in preparation for beginning authentication or peering. This is done when a
715 * Beacon (secure or open mesh) or a peering open frame (for open mesh) is
716 * received from the peer for the first time.
717 */
718static struct sta_info * mesh_mpm_add_peer(struct wpa_supplicant *wpa_s,
719 const u8 *addr,
720 struct ieee802_11_elems *elems)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800721{
722 struct hostapd_sta_add_params params;
723 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
724 struct hostapd_data *data = wpa_s->ifmsh->bss[0];
725 struct sta_info *sta;
Paul Stewart092955c2017-02-06 09:13:09 -0800726 struct ieee80211_ht_operation *oper;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800727 int ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800728
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700729 if (elems->mesh_config_len >= 7 &&
730 !(elems->mesh_config[6] & MESH_CAP_ACCEPT_ADDITIONAL_PEER)) {
731 wpa_msg(wpa_s, MSG_DEBUG,
732 "mesh: Ignore a crowded peer " MACSTR,
733 MAC2STR(addr));
734 return NULL;
735 }
736
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800737 sta = ap_get_sta(data, addr);
Hai Shalomfdcde762020-04-02 11:19:20 -0700738 if (sta)
739 return NULL;
740
741 sta = ap_sta_add(data, addr);
742 if (!sta)
743 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800744
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800745 /* Set WMM by default since Mesh STAs are QoS STAs */
746 sta->flags |= WLAN_STA_WMM;
747
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800748 /* initialize sta */
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800749 if (copy_supp_rates(wpa_s, sta, elems)) {
750 ap_free_sta(data, sta);
751 return NULL;
752 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800753
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800754 if (!sta->my_lid)
755 mesh_mpm_init_link(wpa_s, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800756
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700757 copy_sta_ht_capab(data, sta, elems->ht_capabilities);
Paul Stewart092955c2017-02-06 09:13:09 -0800758
759 oper = (struct ieee80211_ht_operation *) elems->ht_operation;
760 if (oper &&
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800761 !(oper->ht_param & HT_INFO_HT_PARAM_STA_CHNL_WIDTH) &&
762 sta->ht_capabilities) {
Paul Stewart092955c2017-02-06 09:13:09 -0800763 wpa_msg(wpa_s, MSG_DEBUG, MACSTR
764 " does not support 40 MHz bandwidth",
765 MAC2STR(sta->addr));
766 set_disable_ht40(sta->ht_capabilities, 1);
767 }
768
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800769 update_ht_state(data, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800770
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800771#ifdef CONFIG_IEEE80211AC
772 copy_sta_vht_capab(data, sta, elems->vht_capabilities);
Hai Shalom74f70d42019-02-11 14:42:39 -0800773 copy_sta_vht_oper(data, sta, elems->vht_operation);
Sunil Ravi640215c2023-06-28 23:08:09 +0000774 set_sta_vht_opmode(data, sta, elems->opmode_notif);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800775#endif /* CONFIG_IEEE80211AC */
776
Hai Shalom81f62d82019-07-22 12:10:00 -0700777#ifdef CONFIG_IEEE80211AX
778 copy_sta_he_capab(data, sta, IEEE80211_MODE_MESH,
779 elems->he_capabilities, elems->he_capabilities_len);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800780 copy_sta_he_6ghz_capab(data, sta, elems->he_6ghz_band_cap);
Hai Shalom81f62d82019-07-22 12:10:00 -0700781#endif /* CONFIG_IEEE80211AX */
Sunil Ravi036cec52023-03-29 11:35:17 -0700782#ifdef CONFIG_IEEE80211BE
783 copy_sta_eht_capab(data, sta, IEEE80211_MODE_MESH,
784 elems->he_capabilities,
785 elems->he_capabilities_len,
786 elems->eht_capabilities,
787 elems->eht_capabilities_len);
788#endif /*CONFIG_IEEE80211BE */
Hai Shalom81f62d82019-07-22 12:10:00 -0700789
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800790 if (hostapd_get_aid(data, sta) < 0) {
791 wpa_msg(wpa_s, MSG_ERROR, "No AIDs available");
792 ap_free_sta(data, sta);
793 return NULL;
794 }
795
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800796 /* insert into driver */
797 os_memset(&params, 0, sizeof(params));
798 params.supp_rates = sta->supported_rates;
799 params.supp_rates_len = sta->supported_rates_len;
800 params.addr = addr;
801 params.plink_state = sta->plink_state;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800802 params.aid = sta->aid;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700803 params.peer_aid = sta->peer_aid;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800804 params.listen_interval = 100;
805 params.ht_capabilities = sta->ht_capabilities;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800806 params.vht_capabilities = sta->vht_capabilities;
Hai Shalom81f62d82019-07-22 12:10:00 -0700807 params.he_capab = sta->he_capab;
808 params.he_capab_len = sta->he_capab_len;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800809 params.he_6ghz_capab = sta->he_6ghz_capab;
Sunil Ravi036cec52023-03-29 11:35:17 -0700810 params.eht_capab = sta->eht_capab;
811 params.eht_capab_len = sta->eht_capab_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800812 params.flags |= WPA_STA_WMM;
813 params.flags_mask |= WPA_STA_AUTHENTICATED;
814 if (conf->security == MESH_CONF_SEC_NONE) {
815 params.flags |= WPA_STA_AUTHORIZED;
816 params.flags |= WPA_STA_AUTHENTICATED;
817 } else {
818 sta->flags |= WLAN_STA_MFP;
819 params.flags |= WPA_STA_MFP;
820 }
821
822 ret = wpa_drv_sta_add(wpa_s, &params);
823 if (ret) {
824 wpa_msg(wpa_s, MSG_ERROR,
825 "Driver failed to insert " MACSTR ": %d",
826 MAC2STR(addr), ret);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800827 ap_free_sta(data, sta);
828 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800829 }
830
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800831 return sta;
832}
833
834
835void wpa_mesh_new_mesh_peer(struct wpa_supplicant *wpa_s, const u8 *addr,
836 struct ieee802_11_elems *elems)
837{
838 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
839 struct hostapd_data *data = wpa_s->ifmsh->bss[0];
840 struct sta_info *sta;
841 struct wpa_ssid *ssid = wpa_s->current_ssid;
842
843 sta = mesh_mpm_add_peer(wpa_s, addr, elems);
844 if (!sta)
845 return;
846
Dmitry Shmidte4663042016-04-04 10:07:49 -0700847 if (ssid && ssid->no_auto_peer &&
848 (is_zero_ether_addr(data->mesh_required_peer) ||
849 os_memcmp(data->mesh_required_peer, addr, ETH_ALEN) != 0)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800850 wpa_msg(wpa_s, MSG_INFO, "will not initiate new peer link with "
851 MACSTR " because of no_auto_peer", MAC2STR(addr));
852 if (data->mesh_pending_auth) {
853 struct os_reltime age;
854 const struct ieee80211_mgmt *mgmt;
855 struct hostapd_frame_info fi;
856
857 mgmt = wpabuf_head(data->mesh_pending_auth);
858 os_reltime_age(&data->mesh_pending_auth_time, &age);
859 if (age.sec < 2 &&
860 os_memcmp(mgmt->sa, addr, ETH_ALEN) == 0) {
861 wpa_printf(MSG_DEBUG,
862 "mesh: Process pending Authentication frame from %u.%06u seconds ago",
863 (unsigned int) age.sec,
864 (unsigned int) age.usec);
865 os_memset(&fi, 0, sizeof(fi));
866 ieee802_11_mgmt(
867 data,
868 wpabuf_head(data->mesh_pending_auth),
869 wpabuf_len(data->mesh_pending_auth),
870 &fi);
871 }
872 wpabuf_free(data->mesh_pending_auth);
873 data->mesh_pending_auth = NULL;
874 }
875 return;
876 }
877
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800878 if (conf->security == MESH_CONF_SEC_NONE) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700879 if (sta->plink_state < PLINK_OPN_SNT ||
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800880 sta->plink_state > PLINK_ESTAB)
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700881 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPN_SNT);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800882 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800883 mesh_rsn_auth_sae_sta(wpa_s, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800884 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800885}
886
887
888void mesh_mpm_mgmt_rx(struct wpa_supplicant *wpa_s, struct rx_mgmt *rx_mgmt)
889{
890 struct hostapd_frame_info fi;
891
892 os_memset(&fi, 0, sizeof(fi));
893 fi.datarate = rx_mgmt->datarate;
894 fi.ssi_signal = rx_mgmt->ssi_signal;
895 ieee802_11_mgmt(wpa_s->ifmsh->bss[0], rx_mgmt->frame,
896 rx_mgmt->frame_len, &fi);
897}
898
899
900static void mesh_mpm_plink_estab(struct wpa_supplicant *wpa_s,
901 struct sta_info *sta)
902{
903 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
904 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
905 u8 seq[6] = {};
906
907 wpa_msg(wpa_s, MSG_INFO, "mesh plink with " MACSTR " established",
908 MAC2STR(sta->addr));
909
910 if (conf->security & MESH_CONF_SEC_AMPE) {
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700911 wpa_hexdump_key(MSG_DEBUG, "mesh: MTK", sta->mtk, sta->mtk_len);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000912 wpa_drv_set_key(wpa_s, -1,
913 wpa_cipher_to_alg(conf->pairwise_cipher),
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700914 sta->addr, 0, 0, seq, sizeof(seq),
Hai Shalomfdcde762020-04-02 11:19:20 -0700915 sta->mtk, sta->mtk_len,
916 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800917
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700918 wpa_hexdump_key(MSG_DEBUG, "mesh: RX MGTK Key RSC",
919 sta->mgtk_rsc, sizeof(sta->mgtk_rsc));
920 wpa_hexdump_key(MSG_DEBUG, "mesh: RX MGTK",
921 sta->mgtk, sta->mgtk_len);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000922 wpa_drv_set_key(wpa_s, -1,
923 wpa_cipher_to_alg(conf->group_cipher),
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700924 sta->addr, sta->mgtk_key_id, 0,
925 sta->mgtk_rsc, sizeof(sta->mgtk_rsc),
Hai Shalomfdcde762020-04-02 11:19:20 -0700926 sta->mgtk, sta->mgtk_len,
927 KEY_FLAG_GROUP_RX);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700928
929 if (sta->igtk_len) {
930 wpa_hexdump_key(MSG_DEBUG, "mesh: RX IGTK Key RSC",
931 sta->igtk_rsc, sizeof(sta->igtk_rsc));
932 wpa_hexdump_key(MSG_DEBUG, "mesh: RX IGTK",
933 sta->igtk, sta->igtk_len);
934 wpa_drv_set_key(
Sunil Ravi77d572f2023-01-17 23:58:31 +0000935 wpa_s, -1,
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700936 wpa_cipher_to_alg(conf->mgmt_group_cipher),
937 sta->addr, sta->igtk_key_id, 0,
938 sta->igtk_rsc, sizeof(sta->igtk_rsc),
Hai Shalomfdcde762020-04-02 11:19:20 -0700939 sta->igtk, sta->igtk_len,
940 KEY_FLAG_GROUP_RX);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700941 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800942 }
943
944 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_ESTAB);
945 hapd->num_plinks++;
946
947 sta->flags |= WLAN_STA_ASSOC;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700948 sta->mesh_sae_pmksa_caching = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800949
Dmitry Shmidte4663042016-04-04 10:07:49 -0700950 eloop_cancel_timeout(peer_add_timer, wpa_s, NULL);
951 peer_add_timer(wpa_s, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800952 eloop_cancel_timeout(plink_timer, wpa_s, sta);
953
954 /* Send ctrl event */
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800955 wpa_msg(wpa_s, MSG_INFO, MESH_PEER_CONNECTED MACSTR,
956 MAC2STR(sta->addr));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700957
958 /* Send D-Bus event */
959 wpas_notify_mesh_peer_connected(wpa_s, sta->addr);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800960}
961
962
963static void mesh_mpm_fsm(struct wpa_supplicant *wpa_s, struct sta_info *sta,
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700964 enum plink_event event, u16 reason)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800965{
966 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
967 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800968
969 wpa_msg(wpa_s, MSG_DEBUG, "MPM " MACSTR " state %s event %s",
970 MAC2STR(sta->addr), mplstate[sta->plink_state],
971 mplevent[event]);
972
973 switch (sta->plink_state) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700974 case PLINK_IDLE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800975 switch (event) {
976 case CLS_ACPT:
977 mesh_mpm_fsm_restart(wpa_s, sta);
978 break;
979 case OPN_ACPT:
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700980 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPN_RCVD);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800981 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CONFIRM,
982 0);
983 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700984 case REQ_RJCT:
985 mesh_mpm_send_plink_action(wpa_s, sta,
986 PLINK_CLOSE, reason);
987 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800988 default:
989 break;
990 }
991 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700992 case PLINK_OPN_SNT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800993 switch (event) {
994 case OPN_RJCT:
995 case CNF_RJCT:
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700996 if (!reason)
997 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800998 /* fall-through */
999 case CLS_ACPT:
1000 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
1001 if (!reason)
1002 reason = WLAN_REASON_MESH_CLOSE_RCVD;
1003 eloop_register_timeout(
1004 conf->dot11MeshHoldingTimeout / 1000,
1005 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
1006 plink_timer, wpa_s, sta);
1007 mesh_mpm_send_plink_action(wpa_s, sta,
1008 PLINK_CLOSE, reason);
1009 break;
1010 case OPN_ACPT:
1011 /* retry timer is left untouched */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001012 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_OPN_RCVD);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001013 mesh_mpm_send_plink_action(wpa_s, sta,
1014 PLINK_CONFIRM, 0);
1015 break;
1016 case CNF_ACPT:
1017 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_CNF_RCVD);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001018 eloop_cancel_timeout(plink_timer, wpa_s, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001019 eloop_register_timeout(
1020 conf->dot11MeshConfirmTimeout / 1000,
1021 (conf->dot11MeshConfirmTimeout % 1000) * 1000,
1022 plink_timer, wpa_s, sta);
1023 break;
1024 default:
1025 break;
1026 }
1027 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001028 case PLINK_OPN_RCVD:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001029 switch (event) {
1030 case OPN_RJCT:
1031 case CNF_RJCT:
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001032 if (!reason)
1033 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001034 /* fall-through */
1035 case CLS_ACPT:
1036 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
1037 if (!reason)
1038 reason = WLAN_REASON_MESH_CLOSE_RCVD;
1039 eloop_register_timeout(
1040 conf->dot11MeshHoldingTimeout / 1000,
1041 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
1042 plink_timer, wpa_s, sta);
1043 sta->mpm_close_reason = reason;
1044 mesh_mpm_send_plink_action(wpa_s, sta,
1045 PLINK_CLOSE, reason);
1046 break;
1047 case OPN_ACPT:
1048 mesh_mpm_send_plink_action(wpa_s, sta,
1049 PLINK_CONFIRM, 0);
1050 break;
1051 case CNF_ACPT:
1052 if (conf->security & MESH_CONF_SEC_AMPE)
1053 mesh_rsn_derive_mtk(wpa_s, sta);
1054 mesh_mpm_plink_estab(wpa_s, sta);
1055 break;
1056 default:
1057 break;
1058 }
1059 break;
1060 case PLINK_CNF_RCVD:
1061 switch (event) {
1062 case OPN_RJCT:
1063 case CNF_RJCT:
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001064 if (!reason)
1065 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001066 /* fall-through */
1067 case CLS_ACPT:
1068 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
1069 if (!reason)
1070 reason = WLAN_REASON_MESH_CLOSE_RCVD;
1071 eloop_register_timeout(
1072 conf->dot11MeshHoldingTimeout / 1000,
1073 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
1074 plink_timer, wpa_s, sta);
1075 sta->mpm_close_reason = reason;
1076 mesh_mpm_send_plink_action(wpa_s, sta,
1077 PLINK_CLOSE, reason);
1078 break;
1079 case OPN_ACPT:
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001080 if (conf->security & MESH_CONF_SEC_AMPE)
1081 mesh_rsn_derive_mtk(wpa_s, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001082 mesh_mpm_plink_estab(wpa_s, sta);
1083 mesh_mpm_send_plink_action(wpa_s, sta,
1084 PLINK_CONFIRM, 0);
1085 break;
1086 default:
1087 break;
1088 }
1089 break;
1090 case PLINK_ESTAB:
1091 switch (event) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001092 case OPN_RJCT:
1093 case CNF_RJCT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001094 case CLS_ACPT:
1095 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001096 if (!reason)
1097 reason = WLAN_REASON_MESH_CLOSE_RCVD;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001098
1099 eloop_register_timeout(
1100 conf->dot11MeshHoldingTimeout / 1000,
1101 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
1102 plink_timer, wpa_s, sta);
1103 sta->mpm_close_reason = reason;
1104
1105 wpa_msg(wpa_s, MSG_INFO, "mesh plink with " MACSTR
1106 " closed with reason %d",
1107 MAC2STR(sta->addr), reason);
1108
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001109 wpa_msg(wpa_s, MSG_INFO, MESH_PEER_DISCONNECTED MACSTR,
1110 MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001111
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001112 /* Send D-Bus event */
1113 wpas_notify_mesh_peer_disconnected(wpa_s, sta->addr,
1114 reason);
1115
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001116 hapd->num_plinks--;
1117
1118 mesh_mpm_send_plink_action(wpa_s, sta,
1119 PLINK_CLOSE, reason);
1120 break;
1121 case OPN_ACPT:
1122 mesh_mpm_send_plink_action(wpa_s, sta,
1123 PLINK_CONFIRM, 0);
1124 break;
1125 default:
1126 break;
1127 }
1128 break;
1129 case PLINK_HOLDING:
1130 switch (event) {
1131 case CLS_ACPT:
1132 mesh_mpm_fsm_restart(wpa_s, sta);
1133 break;
1134 case OPN_ACPT:
1135 case CNF_ACPT:
1136 case OPN_RJCT:
1137 case CNF_RJCT:
1138 reason = sta->mpm_close_reason;
1139 mesh_mpm_send_plink_action(wpa_s, sta,
1140 PLINK_CLOSE, reason);
1141 break;
1142 default:
1143 break;
1144 }
1145 break;
1146 default:
1147 wpa_msg(wpa_s, MSG_DEBUG,
1148 "Unsupported MPM event %s for state %s",
1149 mplevent[event], mplstate[sta->plink_state]);
1150 break;
1151 }
1152}
1153
1154
1155void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
1156 const struct ieee80211_mgmt *mgmt, size_t len)
1157{
1158 u8 action_field;
1159 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
1160 struct mesh_conf *mconf = wpa_s->ifmsh->mconf;
1161 struct sta_info *sta;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001162 u16 plid = 0, llid = 0, aid = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001163 enum plink_event event;
1164 struct ieee802_11_elems elems;
1165 struct mesh_peer_mgmt_ie peer_mgmt_ie;
1166 const u8 *ies;
1167 size_t ie_len;
1168 int ret;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001169 u16 reason = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001170
1171 if (mgmt->u.action.category != WLAN_ACTION_SELF_PROTECTED)
1172 return;
1173
1174 action_field = mgmt->u.action.u.slf_prot_action.action;
1175 if (action_field != PLINK_OPEN &&
1176 action_field != PLINK_CONFIRM &&
1177 action_field != PLINK_CLOSE)
1178 return;
1179
1180 ies = mgmt->u.action.u.slf_prot_action.variable;
1181 ie_len = (const u8 *) mgmt + len -
1182 mgmt->u.action.u.slf_prot_action.variable;
1183
1184 /* at least expect mesh id and peering mgmt */
1185 if (ie_len < 2 + 2) {
1186 wpa_printf(MSG_DEBUG,
1187 "MPM: Ignore too short action frame %u ie_len %u",
1188 action_field, (unsigned int) ie_len);
1189 return;
1190 }
1191 wpa_printf(MSG_DEBUG, "MPM: Received PLINK action %u", action_field);
1192
1193 if (action_field == PLINK_OPEN || action_field == PLINK_CONFIRM) {
1194 wpa_printf(MSG_DEBUG, "MPM: Capability 0x%x",
1195 WPA_GET_LE16(ies));
1196 ies += 2; /* capability */
1197 ie_len -= 2;
1198 }
1199 if (action_field == PLINK_CONFIRM) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001200 aid = WPA_GET_LE16(ies);
1201 wpa_printf(MSG_DEBUG, "MPM: AID 0x%x", aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001202 ies += 2; /* aid */
1203 ie_len -= 2;
1204 }
1205
1206 /* check for mesh peering, mesh id and mesh config IEs */
1207 if (ieee802_11_parse_elems(ies, ie_len, &elems, 0) == ParseFailed) {
1208 wpa_printf(MSG_DEBUG, "MPM: Failed to parse PLINK IEs");
1209 return;
1210 }
1211 if (!elems.peer_mgmt) {
1212 wpa_printf(MSG_DEBUG,
1213 "MPM: No Mesh Peering Management element");
1214 return;
1215 }
1216 if (action_field != PLINK_CLOSE) {
1217 if (!elems.mesh_id || !elems.mesh_config) {
1218 wpa_printf(MSG_DEBUG,
1219 "MPM: No Mesh ID or Mesh Configuration element");
1220 return;
1221 }
1222
1223 if (!matches_local(wpa_s, &elems)) {
1224 wpa_printf(MSG_DEBUG,
1225 "MPM: Mesh ID or Mesh Configuration element do not match local MBSS");
1226 return;
1227 }
1228 }
1229
1230 ret = mesh_mpm_parse_peer_mgmt(wpa_s, action_field,
1231 elems.peer_mgmt,
1232 elems.peer_mgmt_len,
1233 &peer_mgmt_ie);
1234 if (ret) {
1235 wpa_printf(MSG_DEBUG, "MPM: Mesh parsing rejected frame");
1236 return;
1237 }
1238
1239 /* the sender's llid is our plid and vice-versa */
1240 plid = WPA_GET_LE16(peer_mgmt_ie.llid);
1241 if (peer_mgmt_ie.plid)
1242 llid = WPA_GET_LE16(peer_mgmt_ie.plid);
1243 wpa_printf(MSG_DEBUG, "MPM: plid=0x%x llid=0x%x", plid, llid);
1244
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001245 if (action_field == PLINK_CLOSE)
1246 wpa_printf(MSG_DEBUG, "MPM: close reason=%u",
1247 WPA_GET_LE16(peer_mgmt_ie.reason));
1248
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001249 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001250
1251 /*
1252 * If this is an open frame from an unknown STA, and this is an
1253 * open mesh, then go ahead and add the peer before proceeding.
1254 */
1255 if (!sta && action_field == PLINK_OPEN &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07001256 (!(mconf->security & MESH_CONF_SEC_AMPE) ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001257 wpa_auth_pmksa_get(hapd->wpa_auth, mgmt->sa, NULL)))
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001258 sta = mesh_mpm_add_peer(wpa_s, mgmt->sa, &elems);
1259
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001260 if (!sta) {
1261 wpa_printf(MSG_DEBUG, "MPM: No STA entry for peer");
1262 return;
1263 }
1264
1265#ifdef CONFIG_SAE
1266 /* peer is in sae_accepted? */
1267 if (sta->sae && sta->sae->state != SAE_ACCEPTED) {
1268 wpa_printf(MSG_DEBUG, "MPM: SAE not yet accepted for peer");
1269 return;
1270 }
1271#endif /* CONFIG_SAE */
1272
1273 if (!sta->my_lid)
1274 mesh_mpm_init_link(wpa_s, sta);
1275
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001276 if (mconf->security & MESH_CONF_SEC_AMPE) {
1277 int res;
1278
1279 res = mesh_rsn_process_ampe(wpa_s, sta, &elems,
1280 &mgmt->u.action.category,
1281 peer_mgmt_ie.chosen_pmk,
1282 ies, ie_len);
1283 if (res) {
1284 wpa_printf(MSG_DEBUG,
1285 "MPM: RSN process rejected frame (res=%d)",
1286 res);
1287 if (action_field == PLINK_OPEN && res == -2) {
1288 /* AES-SIV decryption failed */
1289 mesh_mpm_fsm(wpa_s, sta, OPN_RJCT,
1290 WLAN_REASON_MESH_INVALID_GTK);
1291 }
1292 return;
1293 }
Hai Shalom74f70d42019-02-11 14:42:39 -08001294
1295#ifdef CONFIG_OCV
1296 if (action_field == PLINK_OPEN && elems.rsn_ie) {
1297 struct wpa_state_machine *sm = sta->wpa_sm;
1298 struct wpa_ie_data data;
1299
1300 res = wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2,
1301 elems.rsn_ie_len + 2,
1302 &data);
1303 if (res) {
1304 wpa_printf(MSG_DEBUG,
1305 "Failed to parse RSN IE (res=%d)",
1306 res);
1307 wpa_hexdump(MSG_DEBUG, "RSN IE", elems.rsn_ie,
1308 elems.rsn_ie_len);
1309 return;
1310 }
1311
1312 wpa_auth_set_ocv(sm, mconf->ocv &&
1313 (data.capabilities &
1314 WPA_CAPABILITY_OCVC));
1315 }
1316
1317 if (action_field != PLINK_CLOSE &&
1318 wpa_auth_uses_ocv(sta->wpa_sm)) {
1319 struct wpa_channel_info ci;
1320 int tx_chanwidth;
1321 int tx_seg1_idx;
1322
1323 if (wpa_drv_channel_info(wpa_s, &ci) != 0) {
1324 wpa_printf(MSG_WARNING,
1325 "MPM: Failed to get channel info to validate received OCI in MPM Confirm");
1326 return;
1327 }
1328
1329 if (get_tx_parameters(
1330 sta, channel_width_to_int(ci.chanwidth),
1331 ci.seg1_idx, &tx_chanwidth,
1332 &tx_seg1_idx) < 0)
1333 return;
1334
1335 if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci,
1336 tx_chanwidth, tx_seg1_idx) !=
Hai Shalom899fcc72020-10-19 14:38:18 -07001337 OCI_SUCCESS) {
1338 wpa_printf(MSG_WARNING, "MPM: OCV failed: %s",
Hai Shalom74f70d42019-02-11 14:42:39 -08001339 ocv_errorstr);
1340 return;
1341 }
1342 }
1343#endif /* CONFIG_OCV */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001344 }
1345
1346 if (sta->plink_state == PLINK_BLOCKED) {
1347 wpa_printf(MSG_DEBUG, "MPM: PLINK_BLOCKED");
1348 return;
1349 }
1350
1351 /* Now we will figure out the appropriate event... */
1352 switch (action_field) {
1353 case PLINK_OPEN:
1354 if (plink_free_count(hapd) == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001355 event = REQ_RJCT;
1356 reason = WLAN_REASON_MESH_MAX_PEERS;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001357 wpa_printf(MSG_INFO,
1358 "MPM: Peer link num over quota(%d)",
1359 hapd->max_plinks);
1360 } else if (sta->peer_lid && sta->peer_lid != plid) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001361 wpa_printf(MSG_DEBUG,
1362 "MPM: peer_lid mismatch: 0x%x != 0x%x",
1363 sta->peer_lid, plid);
1364 return; /* no FSM event */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001365 } else {
1366 sta->peer_lid = plid;
1367 event = OPN_ACPT;
1368 }
1369 break;
1370 case PLINK_CONFIRM:
1371 if (plink_free_count(hapd) == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001372 event = REQ_RJCT;
1373 reason = WLAN_REASON_MESH_MAX_PEERS;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001374 wpa_printf(MSG_INFO,
1375 "MPM: Peer link num over quota(%d)",
1376 hapd->max_plinks);
1377 } else if (sta->my_lid != llid ||
1378 (sta->peer_lid && sta->peer_lid != plid)) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001379 wpa_printf(MSG_DEBUG,
1380 "MPM: lid mismatch: my_lid: 0x%x != 0x%x or peer_lid: 0x%x != 0x%x",
1381 sta->my_lid, llid, sta->peer_lid, plid);
1382 return; /* no FSM event */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001383 } else {
1384 if (!sta->peer_lid)
1385 sta->peer_lid = plid;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001386 sta->peer_aid = aid;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001387 event = CNF_ACPT;
1388 }
1389 break;
1390 case PLINK_CLOSE:
1391 if (sta->plink_state == PLINK_ESTAB)
1392 /* Do not check for llid or plid. This does not
1393 * follow the standard but since multiple plinks
1394 * per cand are not supported, it is necessary in
1395 * order to avoid a livelock when MP A sees an
1396 * establish peer link to MP B but MP B does not
1397 * see it. This can be caused by a timeout in
1398 * B's peer link establishment or B being
1399 * restarted.
1400 */
1401 event = CLS_ACPT;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001402 else if (sta->peer_lid != plid) {
1403 wpa_printf(MSG_DEBUG,
1404 "MPM: peer_lid mismatch: 0x%x != 0x%x",
1405 sta->peer_lid, plid);
1406 return; /* no FSM event */
1407 } else if (peer_mgmt_ie.plid && sta->my_lid != llid) {
1408 wpa_printf(MSG_DEBUG,
1409 "MPM: my_lid mismatch: 0x%x != 0x%x",
1410 sta->my_lid, llid);
1411 return; /* no FSM event */
1412 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001413 event = CLS_ACPT;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001414 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001415 break;
1416 default:
1417 /*
1418 * This cannot be hit due to the action_field check above, but
1419 * compilers may not be able to figure that out and can warn
1420 * about uninitialized event below.
1421 */
1422 return;
1423 }
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001424 mesh_mpm_fsm(wpa_s, sta, event, reason);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001425}
1426
1427
1428/* called by ap_free_sta */
Dmitry Shmidtb97e4282016-02-08 10:16:07 -08001429void mesh_mpm_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001430{
Dmitry Shmidtb97e4282016-02-08 10:16:07 -08001431 if (sta->plink_state == PLINK_ESTAB)
1432 hapd->num_plinks--;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001433 eloop_cancel_timeout(plink_timer, ELOOP_ALL_CTX, sta);
1434 eloop_cancel_timeout(mesh_auth_timer, ELOOP_ALL_CTX, sta);
1435}