blob: c1ed8c4b553ca4dee6cb2332a9f33dfab71f03f5 [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 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800266
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800267 buf = wpabuf_alloc(buf_len);
268 if (!buf)
269 return;
270
271 cat = wpabuf_mhead_u8(buf);
272 wpabuf_put_u8(buf, WLAN_ACTION_SELF_PROTECTED);
273 wpabuf_put_u8(buf, type);
274
275 if (type != PLINK_CLOSE) {
276 u8 info;
277
278 /* capability info */
279 wpabuf_put_le16(buf, ampe ? IEEE80211_CAP_PRIVACY : 0);
280
281 /* aid */
282 if (type == PLINK_CONFIRM)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800283 wpabuf_put_le16(buf, sta->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800284
285 /* IE: supp + ext. supp rates */
286 pos = hostapd_eid_supp_rates(bss, supp_rates);
287 pos = hostapd_eid_ext_supp_rates(bss, pos);
288 wpabuf_put_data(buf, supp_rates, pos - supp_rates);
289
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800290 /* IE: RSN IE */
291 wpabuf_put_data(buf, conf->rsn_ie, conf->rsn_ie_len);
292
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800293 /* IE: Mesh ID */
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);
297
298 /* IE: mesh conf */
299 wpabuf_put_u8(buf, WLAN_EID_MESH_CONFIG);
300 wpabuf_put_u8(buf, 7);
301 wpabuf_put_u8(buf, conf->mesh_pp_id);
302 wpabuf_put_u8(buf, conf->mesh_pm_id);
303 wpabuf_put_u8(buf, conf->mesh_cc_id);
304 wpabuf_put_u8(buf, conf->mesh_sp_id);
305 wpabuf_put_u8(buf, conf->mesh_auth_id);
306 info = (bss->num_plinks > 63 ? 63 : bss->num_plinks) << 1;
307 /* TODO: Add Connected to Mesh Gate/AS subfields */
308 wpabuf_put_u8(buf, info);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800309 /* Set forwarding based on configuration and always accept
310 * plinks for now */
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700311 wpabuf_put_u8(buf, MESH_CAP_ACCEPT_ADDITIONAL_PEER |
Hai Shaloma20dcd72022-02-04 13:43:00 -0800312 (conf->mesh_fwding ? MESH_CAP_FORWARDING : 0));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800313 } else { /* Peer closing frame */
314 /* IE: Mesh ID */
315 wpabuf_put_u8(buf, WLAN_EID_MESH_ID);
316 wpabuf_put_u8(buf, conf->meshid_len);
317 wpabuf_put_data(buf, conf->meshid, conf->meshid_len);
318 }
319
320 /* IE: Mesh Peering Management element */
321 ie_len = 4;
322 if (ampe)
323 ie_len += PMKID_LEN;
324 switch (type) {
325 case PLINK_OPEN:
326 break;
327 case PLINK_CONFIRM:
328 ie_len += 2;
329 add_plid = 1;
330 break;
331 case PLINK_CLOSE:
332 ie_len += 2;
333 add_plid = 1;
334 ie_len += 2; /* reason code */
335 break;
336 }
337
338 wpabuf_put_u8(buf, WLAN_EID_PEER_MGMT);
339 wpabuf_put_u8(buf, ie_len);
340 /* peering protocol */
341 if (ampe)
342 wpabuf_put_le16(buf, 1);
343 else
344 wpabuf_put_le16(buf, 0);
345 wpabuf_put_le16(buf, sta->my_lid);
346 if (add_plid)
347 wpabuf_put_le16(buf, sta->peer_lid);
348 if (type == PLINK_CLOSE)
349 wpabuf_put_le16(buf, close_reason);
350 if (ampe) {
351 if (sta->sae == NULL) {
352 wpa_msg(wpa_s, MSG_INFO, "Mesh MPM: no SAE session");
353 goto fail;
354 }
355 mesh_rsn_get_pmkid(wpa_s->mesh_rsn, sta,
356 wpabuf_put(buf, PMKID_LEN));
357 }
358
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800359 if (type != PLINK_CLOSE && wpa_s->mesh_ht_enabled) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800360 u8 ht_capa_oper[2 + 26 + 2 + 22];
361
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800362 pos = hostapd_eid_ht_capabilities(bss, ht_capa_oper);
363 pos = hostapd_eid_ht_operation(bss, pos);
364 wpabuf_put_data(buf, ht_capa_oper, pos - ht_capa_oper);
365 }
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800366#ifdef CONFIG_IEEE80211AC
367 if (type != PLINK_CLOSE && wpa_s->mesh_vht_enabled) {
368 u8 vht_capa_oper[2 + 12 + 2 + 5];
369
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700370 pos = hostapd_eid_vht_capabilities(bss, vht_capa_oper, 0);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800371 pos = hostapd_eid_vht_operation(bss, pos);
372 wpabuf_put_data(buf, vht_capa_oper, pos - vht_capa_oper);
373 }
374#endif /* CONFIG_IEEE80211AC */
Hai Shalom81f62d82019-07-22 12:10:00 -0700375#ifdef CONFIG_IEEE80211AX
376 if (type != PLINK_CLOSE && wpa_s->mesh_he_enabled) {
377 u8 he_capa_oper[3 +
378 HE_MAX_MAC_CAPAB_SIZE +
379 HE_MAX_PHY_CAPAB_SIZE +
380 HE_MAX_MCS_CAPAB_SIZE +
381 HE_MAX_PPET_CAPAB_SIZE +
Hai Shaloma20dcd72022-02-04 13:43:00 -0800382 3 + sizeof(struct ieee80211_he_operation) +
383 sizeof(struct ieee80211_he_6ghz_oper_info) +
384 3 + sizeof(struct ieee80211_he_6ghz_band_cap)];
Hai Shalom81f62d82019-07-22 12:10:00 -0700385
386 pos = hostapd_eid_he_capab(bss, he_capa_oper,
387 IEEE80211_MODE_MESH);
388 pos = hostapd_eid_he_operation(bss, pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800389 pos = hostapd_eid_he_6ghz_band_cap(bss, pos);
Hai Shalom81f62d82019-07-22 12:10:00 -0700390 wpabuf_put_data(buf, he_capa_oper, pos - he_capa_oper);
391 }
392#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800393
Hai Shalom74f70d42019-02-11 14:42:39 -0800394#ifdef CONFIG_OCV
395 if (type != PLINK_CLOSE && conf->ocv) {
396 struct wpa_channel_info ci;
397
398 if (wpa_drv_channel_info(wpa_s, &ci) != 0) {
399 wpa_printf(MSG_WARNING,
400 "Mesh MPM: Failed to get channel info for OCI element");
401 goto fail;
402 }
403
404 pos = wpabuf_put(buf, OCV_OCI_EXTENDED_LEN);
405 if (ocv_insert_extended_oci(&ci, pos) < 0)
406 goto fail;
407 }
408#endif /* CONFIG_OCV */
409
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800410 if (ampe && mesh_rsn_protect_frame(wpa_s->mesh_rsn, sta, cat, buf)) {
411 wpa_msg(wpa_s, MSG_INFO,
412 "Mesh MPM: failed to add AMPE and MIC IE");
413 goto fail;
414 }
415
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800416 wpa_msg(wpa_s, MSG_DEBUG, "Mesh MPM: Sending peering frame type %d to "
417 MACSTR " (my_lid=0x%x peer_lid=0x%x)",
418 type, MAC2STR(sta->addr), sta->my_lid, sta->peer_lid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800419 ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
420 sta->addr, wpa_s->own_addr, wpa_s->own_addr,
421 wpabuf_head(buf), wpabuf_len(buf), 0);
422 if (ret < 0)
423 wpa_msg(wpa_s, MSG_INFO,
424 "Mesh MPM: failed to send peering frame");
425
426fail:
427 wpabuf_free(buf);
428}
429
430
431/* configure peering state in ours and driver's station entry */
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800432void wpa_mesh_set_plink_state(struct wpa_supplicant *wpa_s,
433 struct sta_info *sta,
434 enum mesh_plink_state state)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800435{
436 struct hostapd_sta_add_params params;
437 int ret;
438
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800439 wpa_msg(wpa_s, MSG_DEBUG, "MPM set " MACSTR " from %s into %s",
440 MAC2STR(sta->addr), mplstate[sta->plink_state],
441 mplstate[state]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800442 sta->plink_state = state;
443
444 os_memset(&params, 0, sizeof(params));
445 params.addr = sta->addr;
446 params.plink_state = state;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700447 params.peer_aid = sta->peer_aid;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800448 params.set = 1;
449
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800450 ret = wpa_drv_sta_add(wpa_s, &params);
451 if (ret) {
452 wpa_msg(wpa_s, MSG_ERROR, "Driver failed to set " MACSTR
453 ": %d", MAC2STR(sta->addr), ret);
454 }
455}
456
457
458static void mesh_mpm_fsm_restart(struct wpa_supplicant *wpa_s,
459 struct sta_info *sta)
460{
461 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
462
463 eloop_cancel_timeout(plink_timer, wpa_s, sta);
464
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800465 ap_free_sta(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800466}
467
468
469static void plink_timer(void *eloop_ctx, void *user_data)
470{
471 struct wpa_supplicant *wpa_s = eloop_ctx;
472 struct sta_info *sta = user_data;
473 u16 reason = 0;
474 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700475 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800476
477 switch (sta->plink_state) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700478 case PLINK_OPN_RCVD:
479 case PLINK_OPN_SNT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800480 /* retry timer */
481 if (sta->mpm_retries < conf->dot11MeshMaxRetries) {
482 eloop_register_timeout(
483 conf->dot11MeshRetryTimeout / 1000,
484 (conf->dot11MeshRetryTimeout % 1000) * 1000,
485 plink_timer, wpa_s, sta);
486 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_OPEN, 0);
487 sta->mpm_retries++;
488 break;
489 }
490 reason = WLAN_REASON_MESH_MAX_RETRIES;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700491 /* fall through */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800492
493 case PLINK_CNF_RCVD:
494 /* confirm timer */
495 if (!reason)
496 reason = WLAN_REASON_MESH_CONFIRM_TIMEOUT;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800497 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800498 eloop_register_timeout(conf->dot11MeshHoldingTimeout / 1000,
499 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
500 plink_timer, wpa_s, sta);
501 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CLOSE, reason);
502 break;
503 case PLINK_HOLDING:
504 /* holding timer */
Dmitry Shmidte4663042016-04-04 10:07:49 -0700505
506 if (sta->mesh_sae_pmksa_caching) {
507 wpa_printf(MSG_DEBUG, "MPM: Peer " MACSTR
508 " looks like it does not support mesh SAE PMKSA caching, so remove the cached entry for it",
509 MAC2STR(sta->addr));
510 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
511 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800512 mesh_mpm_fsm_restart(wpa_s, sta);
513 break;
514 default:
515 break;
516 }
517}
518
519
520/* initiate peering with station */
521static void
522mesh_mpm_plink_open(struct wpa_supplicant *wpa_s, struct sta_info *sta,
523 enum mesh_plink_state next_state)
524{
525 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
526
527 eloop_cancel_timeout(plink_timer, wpa_s, sta);
528 eloop_register_timeout(conf->dot11MeshRetryTimeout / 1000,
529 (conf->dot11MeshRetryTimeout % 1000) * 1000,
530 plink_timer, wpa_s, sta);
531 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_OPEN, 0);
532 wpa_mesh_set_plink_state(wpa_s, sta, next_state);
533}
534
535
Dmitry Shmidte4663042016-04-04 10:07:49 -0700536static int mesh_mpm_plink_close(struct hostapd_data *hapd, struct sta_info *sta,
537 void *ctx)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800538{
539 struct wpa_supplicant *wpa_s = ctx;
540 int reason = WLAN_REASON_MESH_PEERING_CANCELLED;
541
542 if (sta) {
Hai Shalom899fcc72020-10-19 14:38:18 -0700543 if (sta->plink_state == PLINK_ESTAB)
544 hapd->num_plinks--;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800545 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
546 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CLOSE, reason);
547 wpa_printf(MSG_DEBUG, "MPM closing plink sta=" MACSTR,
548 MAC2STR(sta->addr));
549 eloop_cancel_timeout(plink_timer, wpa_s, sta);
Hai Shalom899fcc72020-10-19 14:38:18 -0700550 eloop_cancel_timeout(mesh_auth_timer, wpa_s, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800551 return 0;
552 }
553
554 return 1;
555}
556
557
Dmitry Shmidte4663042016-04-04 10:07:49 -0700558int mesh_mpm_close_peer(struct wpa_supplicant *wpa_s, const u8 *addr)
559{
560 struct hostapd_data *hapd;
561 struct sta_info *sta;
562
563 if (!wpa_s->ifmsh) {
564 wpa_msg(wpa_s, MSG_INFO, "Mesh is not prepared yet");
565 return -1;
566 }
567
568 hapd = wpa_s->ifmsh->bss[0];
569 sta = ap_get_sta(hapd, addr);
570 if (!sta) {
571 wpa_msg(wpa_s, MSG_INFO, "No such mesh peer");
572 return -1;
573 }
574
575 return mesh_mpm_plink_close(hapd, sta, wpa_s) == 0 ? 0 : -1;
576}
577
578
579static void peer_add_timer(void *eloop_ctx, void *user_data)
580{
581 struct wpa_supplicant *wpa_s = eloop_ctx;
582 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
583
584 os_memset(hapd->mesh_required_peer, 0, ETH_ALEN);
585}
586
587
588int mesh_mpm_connect_peer(struct wpa_supplicant *wpa_s, const u8 *addr,
589 int duration)
590{
591 struct wpa_ssid *ssid = wpa_s->current_ssid;
592 struct hostapd_data *hapd;
593 struct sta_info *sta;
594 struct mesh_conf *conf;
595
596 if (!wpa_s->ifmsh) {
597 wpa_msg(wpa_s, MSG_INFO, "Mesh is not prepared yet");
598 return -1;
599 }
600
601 if (!ssid || !ssid->no_auto_peer) {
602 wpa_msg(wpa_s, MSG_INFO,
603 "This command is available only with no_auto_peer mesh network");
604 return -1;
605 }
606
607 hapd = wpa_s->ifmsh->bss[0];
608 conf = wpa_s->ifmsh->mconf;
609
610 sta = ap_get_sta(hapd, addr);
611 if (!sta) {
612 wpa_msg(wpa_s, MSG_INFO, "No such mesh peer");
613 return -1;
614 }
615
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700616 if ((PLINK_OPN_SNT <= sta->plink_state &&
Dmitry Shmidte4663042016-04-04 10:07:49 -0700617 sta->plink_state <= PLINK_ESTAB) ||
618 (sta->sae && sta->sae->state > SAE_NOTHING)) {
619 wpa_msg(wpa_s, MSG_INFO,
620 "Specified peer is connecting/connected");
621 return -1;
622 }
623
624 if (conf->security == MESH_CONF_SEC_NONE) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700625 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPN_SNT);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700626 } else {
627 mesh_rsn_auth_sae_sta(wpa_s, sta);
628 os_memcpy(hapd->mesh_required_peer, addr, ETH_ALEN);
629 eloop_register_timeout(duration == -1 ? 10 : duration, 0,
630 peer_add_timer, wpa_s, NULL);
631 }
632
633 return 0;
634}
635
636
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800637void mesh_mpm_deinit(struct wpa_supplicant *wpa_s, struct hostapd_iface *ifmsh)
638{
639 struct hostapd_data *hapd = ifmsh->bss[0];
640
641 /* notify peers we're leaving */
642 ap_for_each_sta(hapd, mesh_mpm_plink_close, wpa_s);
643
644 hapd->num_plinks = 0;
645 hostapd_free_stas(hapd);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700646 eloop_cancel_timeout(peer_add_timer, wpa_s, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800647}
648
649
650/* for mesh_rsn to indicate this peer has completed authentication, and we're
651 * ready to start AMPE */
652void mesh_mpm_auth_peer(struct wpa_supplicant *wpa_s, const u8 *addr)
653{
654 struct hostapd_data *data = wpa_s->ifmsh->bss[0];
655 struct hostapd_sta_add_params params;
656 struct sta_info *sta;
657 int ret;
658
659 sta = ap_get_sta(data, addr);
660 if (!sta) {
661 wpa_msg(wpa_s, MSG_DEBUG, "no such mesh peer");
662 return;
663 }
664
665 /* TODO: Should do nothing if this STA is already authenticated, but
666 * the AP code already sets this flag. */
667 sta->flags |= WLAN_STA_AUTH;
668
669 mesh_rsn_init_ampe_sta(wpa_s, sta);
670
671 os_memset(&params, 0, sizeof(params));
672 params.addr = sta->addr;
673 params.flags = WPA_STA_AUTHENTICATED | WPA_STA_AUTHORIZED;
674 params.set = 1;
675
676 wpa_msg(wpa_s, MSG_DEBUG, "MPM authenticating " MACSTR,
677 MAC2STR(sta->addr));
678 ret = wpa_drv_sta_add(wpa_s, &params);
679 if (ret) {
680 wpa_msg(wpa_s, MSG_ERROR,
681 "Driver failed to set " MACSTR ": %d",
682 MAC2STR(sta->addr), ret);
683 }
684
685 if (!sta->my_lid)
686 mesh_mpm_init_link(wpa_s, sta);
687
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700688 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPN_SNT);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800689}
690
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800691/*
692 * Initialize a sta_info structure for a peer and upload it into the driver
693 * in preparation for beginning authentication or peering. This is done when a
694 * Beacon (secure or open mesh) or a peering open frame (for open mesh) is
695 * received from the peer for the first time.
696 */
697static struct sta_info * mesh_mpm_add_peer(struct wpa_supplicant *wpa_s,
698 const u8 *addr,
699 struct ieee802_11_elems *elems)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800700{
701 struct hostapd_sta_add_params params;
702 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
703 struct hostapd_data *data = wpa_s->ifmsh->bss[0];
704 struct sta_info *sta;
Paul Stewart092955c2017-02-06 09:13:09 -0800705 struct ieee80211_ht_operation *oper;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800706 int ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800707
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700708 if (elems->mesh_config_len >= 7 &&
709 !(elems->mesh_config[6] & MESH_CAP_ACCEPT_ADDITIONAL_PEER)) {
710 wpa_msg(wpa_s, MSG_DEBUG,
711 "mesh: Ignore a crowded peer " MACSTR,
712 MAC2STR(addr));
713 return NULL;
714 }
715
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800716 sta = ap_get_sta(data, addr);
Hai Shalomfdcde762020-04-02 11:19:20 -0700717 if (sta)
718 return NULL;
719
720 sta = ap_sta_add(data, addr);
721 if (!sta)
722 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800723
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800724 /* Set WMM by default since Mesh STAs are QoS STAs */
725 sta->flags |= WLAN_STA_WMM;
726
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800727 /* initialize sta */
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800728 if (copy_supp_rates(wpa_s, sta, elems)) {
729 ap_free_sta(data, sta);
730 return NULL;
731 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800732
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800733 if (!sta->my_lid)
734 mesh_mpm_init_link(wpa_s, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800735
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700736 copy_sta_ht_capab(data, sta, elems->ht_capabilities);
Paul Stewart092955c2017-02-06 09:13:09 -0800737
738 oper = (struct ieee80211_ht_operation *) elems->ht_operation;
739 if (oper &&
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800740 !(oper->ht_param & HT_INFO_HT_PARAM_STA_CHNL_WIDTH) &&
741 sta->ht_capabilities) {
Paul Stewart092955c2017-02-06 09:13:09 -0800742 wpa_msg(wpa_s, MSG_DEBUG, MACSTR
743 " does not support 40 MHz bandwidth",
744 MAC2STR(sta->addr));
745 set_disable_ht40(sta->ht_capabilities, 1);
746 }
747
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800748 update_ht_state(data, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800749
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800750#ifdef CONFIG_IEEE80211AC
751 copy_sta_vht_capab(data, sta, elems->vht_capabilities);
Hai Shalom74f70d42019-02-11 14:42:39 -0800752 copy_sta_vht_oper(data, sta, elems->vht_operation);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800753 set_sta_vht_opmode(data, sta, elems->vht_opmode_notif);
754#endif /* CONFIG_IEEE80211AC */
755
Hai Shalom81f62d82019-07-22 12:10:00 -0700756#ifdef CONFIG_IEEE80211AX
757 copy_sta_he_capab(data, sta, IEEE80211_MODE_MESH,
758 elems->he_capabilities, elems->he_capabilities_len);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800759 copy_sta_he_6ghz_capab(data, sta, elems->he_6ghz_band_cap);
Hai Shalom81f62d82019-07-22 12:10:00 -0700760#endif /* CONFIG_IEEE80211AX */
761
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800762 if (hostapd_get_aid(data, sta) < 0) {
763 wpa_msg(wpa_s, MSG_ERROR, "No AIDs available");
764 ap_free_sta(data, sta);
765 return NULL;
766 }
767
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800768 /* insert into driver */
769 os_memset(&params, 0, sizeof(params));
770 params.supp_rates = sta->supported_rates;
771 params.supp_rates_len = sta->supported_rates_len;
772 params.addr = addr;
773 params.plink_state = sta->plink_state;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800774 params.aid = sta->aid;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700775 params.peer_aid = sta->peer_aid;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800776 params.listen_interval = 100;
777 params.ht_capabilities = sta->ht_capabilities;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800778 params.vht_capabilities = sta->vht_capabilities;
Hai Shalom81f62d82019-07-22 12:10:00 -0700779 params.he_capab = sta->he_capab;
780 params.he_capab_len = sta->he_capab_len;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800781 params.he_6ghz_capab = sta->he_6ghz_capab;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800782 params.flags |= WPA_STA_WMM;
783 params.flags_mask |= WPA_STA_AUTHENTICATED;
784 if (conf->security == MESH_CONF_SEC_NONE) {
785 params.flags |= WPA_STA_AUTHORIZED;
786 params.flags |= WPA_STA_AUTHENTICATED;
787 } else {
788 sta->flags |= WLAN_STA_MFP;
789 params.flags |= WPA_STA_MFP;
790 }
791
792 ret = wpa_drv_sta_add(wpa_s, &params);
793 if (ret) {
794 wpa_msg(wpa_s, MSG_ERROR,
795 "Driver failed to insert " MACSTR ": %d",
796 MAC2STR(addr), ret);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800797 ap_free_sta(data, sta);
798 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800799 }
800
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800801 return sta;
802}
803
804
805void wpa_mesh_new_mesh_peer(struct wpa_supplicant *wpa_s, const u8 *addr,
806 struct ieee802_11_elems *elems)
807{
808 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
809 struct hostapd_data *data = wpa_s->ifmsh->bss[0];
810 struct sta_info *sta;
811 struct wpa_ssid *ssid = wpa_s->current_ssid;
812
813 sta = mesh_mpm_add_peer(wpa_s, addr, elems);
814 if (!sta)
815 return;
816
Dmitry Shmidte4663042016-04-04 10:07:49 -0700817 if (ssid && ssid->no_auto_peer &&
818 (is_zero_ether_addr(data->mesh_required_peer) ||
819 os_memcmp(data->mesh_required_peer, addr, ETH_ALEN) != 0)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800820 wpa_msg(wpa_s, MSG_INFO, "will not initiate new peer link with "
821 MACSTR " because of no_auto_peer", MAC2STR(addr));
822 if (data->mesh_pending_auth) {
823 struct os_reltime age;
824 const struct ieee80211_mgmt *mgmt;
825 struct hostapd_frame_info fi;
826
827 mgmt = wpabuf_head(data->mesh_pending_auth);
828 os_reltime_age(&data->mesh_pending_auth_time, &age);
829 if (age.sec < 2 &&
830 os_memcmp(mgmt->sa, addr, ETH_ALEN) == 0) {
831 wpa_printf(MSG_DEBUG,
832 "mesh: Process pending Authentication frame from %u.%06u seconds ago",
833 (unsigned int) age.sec,
834 (unsigned int) age.usec);
835 os_memset(&fi, 0, sizeof(fi));
836 ieee802_11_mgmt(
837 data,
838 wpabuf_head(data->mesh_pending_auth),
839 wpabuf_len(data->mesh_pending_auth),
840 &fi);
841 }
842 wpabuf_free(data->mesh_pending_auth);
843 data->mesh_pending_auth = NULL;
844 }
845 return;
846 }
847
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800848 if (conf->security == MESH_CONF_SEC_NONE) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700849 if (sta->plink_state < PLINK_OPN_SNT ||
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800850 sta->plink_state > PLINK_ESTAB)
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700851 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPN_SNT);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800852 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800853 mesh_rsn_auth_sae_sta(wpa_s, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800854 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800855}
856
857
858void mesh_mpm_mgmt_rx(struct wpa_supplicant *wpa_s, struct rx_mgmt *rx_mgmt)
859{
860 struct hostapd_frame_info fi;
861
862 os_memset(&fi, 0, sizeof(fi));
863 fi.datarate = rx_mgmt->datarate;
864 fi.ssi_signal = rx_mgmt->ssi_signal;
865 ieee802_11_mgmt(wpa_s->ifmsh->bss[0], rx_mgmt->frame,
866 rx_mgmt->frame_len, &fi);
867}
868
869
870static void mesh_mpm_plink_estab(struct wpa_supplicant *wpa_s,
871 struct sta_info *sta)
872{
873 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
874 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
875 u8 seq[6] = {};
876
877 wpa_msg(wpa_s, MSG_INFO, "mesh plink with " MACSTR " established",
878 MAC2STR(sta->addr));
879
880 if (conf->security & MESH_CONF_SEC_AMPE) {
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700881 wpa_hexdump_key(MSG_DEBUG, "mesh: MTK", sta->mtk, sta->mtk_len);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000882 wpa_drv_set_key(wpa_s, -1,
883 wpa_cipher_to_alg(conf->pairwise_cipher),
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700884 sta->addr, 0, 0, seq, sizeof(seq),
Hai Shalomfdcde762020-04-02 11:19:20 -0700885 sta->mtk, sta->mtk_len,
886 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800887
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700888 wpa_hexdump_key(MSG_DEBUG, "mesh: RX MGTK Key RSC",
889 sta->mgtk_rsc, sizeof(sta->mgtk_rsc));
890 wpa_hexdump_key(MSG_DEBUG, "mesh: RX MGTK",
891 sta->mgtk, sta->mgtk_len);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000892 wpa_drv_set_key(wpa_s, -1,
893 wpa_cipher_to_alg(conf->group_cipher),
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700894 sta->addr, sta->mgtk_key_id, 0,
895 sta->mgtk_rsc, sizeof(sta->mgtk_rsc),
Hai Shalomfdcde762020-04-02 11:19:20 -0700896 sta->mgtk, sta->mgtk_len,
897 KEY_FLAG_GROUP_RX);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700898
899 if (sta->igtk_len) {
900 wpa_hexdump_key(MSG_DEBUG, "mesh: RX IGTK Key RSC",
901 sta->igtk_rsc, sizeof(sta->igtk_rsc));
902 wpa_hexdump_key(MSG_DEBUG, "mesh: RX IGTK",
903 sta->igtk, sta->igtk_len);
904 wpa_drv_set_key(
Sunil Ravi77d572f2023-01-17 23:58:31 +0000905 wpa_s, -1,
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700906 wpa_cipher_to_alg(conf->mgmt_group_cipher),
907 sta->addr, sta->igtk_key_id, 0,
908 sta->igtk_rsc, sizeof(sta->igtk_rsc),
Hai Shalomfdcde762020-04-02 11:19:20 -0700909 sta->igtk, sta->igtk_len,
910 KEY_FLAG_GROUP_RX);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700911 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800912 }
913
914 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_ESTAB);
915 hapd->num_plinks++;
916
917 sta->flags |= WLAN_STA_ASSOC;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700918 sta->mesh_sae_pmksa_caching = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800919
Dmitry Shmidte4663042016-04-04 10:07:49 -0700920 eloop_cancel_timeout(peer_add_timer, wpa_s, NULL);
921 peer_add_timer(wpa_s, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800922 eloop_cancel_timeout(plink_timer, wpa_s, sta);
923
924 /* Send ctrl event */
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800925 wpa_msg(wpa_s, MSG_INFO, MESH_PEER_CONNECTED MACSTR,
926 MAC2STR(sta->addr));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700927
928 /* Send D-Bus event */
929 wpas_notify_mesh_peer_connected(wpa_s, sta->addr);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800930}
931
932
933static void mesh_mpm_fsm(struct wpa_supplicant *wpa_s, struct sta_info *sta,
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700934 enum plink_event event, u16 reason)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800935{
936 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
937 struct mesh_conf *conf = wpa_s->ifmsh->mconf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800938
939 wpa_msg(wpa_s, MSG_DEBUG, "MPM " MACSTR " state %s event %s",
940 MAC2STR(sta->addr), mplstate[sta->plink_state],
941 mplevent[event]);
942
943 switch (sta->plink_state) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700944 case PLINK_IDLE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800945 switch (event) {
946 case CLS_ACPT:
947 mesh_mpm_fsm_restart(wpa_s, sta);
948 break;
949 case OPN_ACPT:
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700950 mesh_mpm_plink_open(wpa_s, sta, PLINK_OPN_RCVD);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800951 mesh_mpm_send_plink_action(wpa_s, sta, PLINK_CONFIRM,
952 0);
953 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700954 case REQ_RJCT:
955 mesh_mpm_send_plink_action(wpa_s, sta,
956 PLINK_CLOSE, reason);
957 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800958 default:
959 break;
960 }
961 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700962 case PLINK_OPN_SNT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800963 switch (event) {
964 case OPN_RJCT:
965 case CNF_RJCT:
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700966 if (!reason)
967 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800968 /* fall-through */
969 case CLS_ACPT:
970 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
971 if (!reason)
972 reason = WLAN_REASON_MESH_CLOSE_RCVD;
973 eloop_register_timeout(
974 conf->dot11MeshHoldingTimeout / 1000,
975 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
976 plink_timer, wpa_s, sta);
977 mesh_mpm_send_plink_action(wpa_s, sta,
978 PLINK_CLOSE, reason);
979 break;
980 case OPN_ACPT:
981 /* retry timer is left untouched */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700982 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_OPN_RCVD);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800983 mesh_mpm_send_plink_action(wpa_s, sta,
984 PLINK_CONFIRM, 0);
985 break;
986 case CNF_ACPT:
987 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_CNF_RCVD);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700988 eloop_cancel_timeout(plink_timer, wpa_s, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800989 eloop_register_timeout(
990 conf->dot11MeshConfirmTimeout / 1000,
991 (conf->dot11MeshConfirmTimeout % 1000) * 1000,
992 plink_timer, wpa_s, sta);
993 break;
994 default:
995 break;
996 }
997 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700998 case PLINK_OPN_RCVD:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800999 switch (event) {
1000 case OPN_RJCT:
1001 case CNF_RJCT:
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001002 if (!reason)
1003 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001004 /* fall-through */
1005 case CLS_ACPT:
1006 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
1007 if (!reason)
1008 reason = WLAN_REASON_MESH_CLOSE_RCVD;
1009 eloop_register_timeout(
1010 conf->dot11MeshHoldingTimeout / 1000,
1011 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
1012 plink_timer, wpa_s, sta);
1013 sta->mpm_close_reason = reason;
1014 mesh_mpm_send_plink_action(wpa_s, sta,
1015 PLINK_CLOSE, reason);
1016 break;
1017 case OPN_ACPT:
1018 mesh_mpm_send_plink_action(wpa_s, sta,
1019 PLINK_CONFIRM, 0);
1020 break;
1021 case CNF_ACPT:
1022 if (conf->security & MESH_CONF_SEC_AMPE)
1023 mesh_rsn_derive_mtk(wpa_s, sta);
1024 mesh_mpm_plink_estab(wpa_s, sta);
1025 break;
1026 default:
1027 break;
1028 }
1029 break;
1030 case PLINK_CNF_RCVD:
1031 switch (event) {
1032 case OPN_RJCT:
1033 case CNF_RJCT:
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001034 if (!reason)
1035 reason = WLAN_REASON_MESH_CONFIG_POLICY_VIOLATION;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001036 /* fall-through */
1037 case CLS_ACPT:
1038 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
1039 if (!reason)
1040 reason = WLAN_REASON_MESH_CLOSE_RCVD;
1041 eloop_register_timeout(
1042 conf->dot11MeshHoldingTimeout / 1000,
1043 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
1044 plink_timer, wpa_s, sta);
1045 sta->mpm_close_reason = reason;
1046 mesh_mpm_send_plink_action(wpa_s, sta,
1047 PLINK_CLOSE, reason);
1048 break;
1049 case OPN_ACPT:
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001050 if (conf->security & MESH_CONF_SEC_AMPE)
1051 mesh_rsn_derive_mtk(wpa_s, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001052 mesh_mpm_plink_estab(wpa_s, sta);
1053 mesh_mpm_send_plink_action(wpa_s, sta,
1054 PLINK_CONFIRM, 0);
1055 break;
1056 default:
1057 break;
1058 }
1059 break;
1060 case PLINK_ESTAB:
1061 switch (event) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001062 case OPN_RJCT:
1063 case CNF_RJCT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001064 case CLS_ACPT:
1065 wpa_mesh_set_plink_state(wpa_s, sta, PLINK_HOLDING);
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001066 if (!reason)
1067 reason = WLAN_REASON_MESH_CLOSE_RCVD;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001068
1069 eloop_register_timeout(
1070 conf->dot11MeshHoldingTimeout / 1000,
1071 (conf->dot11MeshHoldingTimeout % 1000) * 1000,
1072 plink_timer, wpa_s, sta);
1073 sta->mpm_close_reason = reason;
1074
1075 wpa_msg(wpa_s, MSG_INFO, "mesh plink with " MACSTR
1076 " closed with reason %d",
1077 MAC2STR(sta->addr), reason);
1078
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001079 wpa_msg(wpa_s, MSG_INFO, MESH_PEER_DISCONNECTED MACSTR,
1080 MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001081
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001082 /* Send D-Bus event */
1083 wpas_notify_mesh_peer_disconnected(wpa_s, sta->addr,
1084 reason);
1085
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001086 hapd->num_plinks--;
1087
1088 mesh_mpm_send_plink_action(wpa_s, sta,
1089 PLINK_CLOSE, reason);
1090 break;
1091 case OPN_ACPT:
1092 mesh_mpm_send_plink_action(wpa_s, sta,
1093 PLINK_CONFIRM, 0);
1094 break;
1095 default:
1096 break;
1097 }
1098 break;
1099 case PLINK_HOLDING:
1100 switch (event) {
1101 case CLS_ACPT:
1102 mesh_mpm_fsm_restart(wpa_s, sta);
1103 break;
1104 case OPN_ACPT:
1105 case CNF_ACPT:
1106 case OPN_RJCT:
1107 case CNF_RJCT:
1108 reason = sta->mpm_close_reason;
1109 mesh_mpm_send_plink_action(wpa_s, sta,
1110 PLINK_CLOSE, reason);
1111 break;
1112 default:
1113 break;
1114 }
1115 break;
1116 default:
1117 wpa_msg(wpa_s, MSG_DEBUG,
1118 "Unsupported MPM event %s for state %s",
1119 mplevent[event], mplstate[sta->plink_state]);
1120 break;
1121 }
1122}
1123
1124
1125void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
1126 const struct ieee80211_mgmt *mgmt, size_t len)
1127{
1128 u8 action_field;
1129 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
1130 struct mesh_conf *mconf = wpa_s->ifmsh->mconf;
1131 struct sta_info *sta;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001132 u16 plid = 0, llid = 0, aid = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001133 enum plink_event event;
1134 struct ieee802_11_elems elems;
1135 struct mesh_peer_mgmt_ie peer_mgmt_ie;
1136 const u8 *ies;
1137 size_t ie_len;
1138 int ret;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001139 u16 reason = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001140
1141 if (mgmt->u.action.category != WLAN_ACTION_SELF_PROTECTED)
1142 return;
1143
1144 action_field = mgmt->u.action.u.slf_prot_action.action;
1145 if (action_field != PLINK_OPEN &&
1146 action_field != PLINK_CONFIRM &&
1147 action_field != PLINK_CLOSE)
1148 return;
1149
1150 ies = mgmt->u.action.u.slf_prot_action.variable;
1151 ie_len = (const u8 *) mgmt + len -
1152 mgmt->u.action.u.slf_prot_action.variable;
1153
1154 /* at least expect mesh id and peering mgmt */
1155 if (ie_len < 2 + 2) {
1156 wpa_printf(MSG_DEBUG,
1157 "MPM: Ignore too short action frame %u ie_len %u",
1158 action_field, (unsigned int) ie_len);
1159 return;
1160 }
1161 wpa_printf(MSG_DEBUG, "MPM: Received PLINK action %u", action_field);
1162
1163 if (action_field == PLINK_OPEN || action_field == PLINK_CONFIRM) {
1164 wpa_printf(MSG_DEBUG, "MPM: Capability 0x%x",
1165 WPA_GET_LE16(ies));
1166 ies += 2; /* capability */
1167 ie_len -= 2;
1168 }
1169 if (action_field == PLINK_CONFIRM) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001170 aid = WPA_GET_LE16(ies);
1171 wpa_printf(MSG_DEBUG, "MPM: AID 0x%x", aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001172 ies += 2; /* aid */
1173 ie_len -= 2;
1174 }
1175
1176 /* check for mesh peering, mesh id and mesh config IEs */
1177 if (ieee802_11_parse_elems(ies, ie_len, &elems, 0) == ParseFailed) {
1178 wpa_printf(MSG_DEBUG, "MPM: Failed to parse PLINK IEs");
1179 return;
1180 }
1181 if (!elems.peer_mgmt) {
1182 wpa_printf(MSG_DEBUG,
1183 "MPM: No Mesh Peering Management element");
1184 return;
1185 }
1186 if (action_field != PLINK_CLOSE) {
1187 if (!elems.mesh_id || !elems.mesh_config) {
1188 wpa_printf(MSG_DEBUG,
1189 "MPM: No Mesh ID or Mesh Configuration element");
1190 return;
1191 }
1192
1193 if (!matches_local(wpa_s, &elems)) {
1194 wpa_printf(MSG_DEBUG,
1195 "MPM: Mesh ID or Mesh Configuration element do not match local MBSS");
1196 return;
1197 }
1198 }
1199
1200 ret = mesh_mpm_parse_peer_mgmt(wpa_s, action_field,
1201 elems.peer_mgmt,
1202 elems.peer_mgmt_len,
1203 &peer_mgmt_ie);
1204 if (ret) {
1205 wpa_printf(MSG_DEBUG, "MPM: Mesh parsing rejected frame");
1206 return;
1207 }
1208
1209 /* the sender's llid is our plid and vice-versa */
1210 plid = WPA_GET_LE16(peer_mgmt_ie.llid);
1211 if (peer_mgmt_ie.plid)
1212 llid = WPA_GET_LE16(peer_mgmt_ie.plid);
1213 wpa_printf(MSG_DEBUG, "MPM: plid=0x%x llid=0x%x", plid, llid);
1214
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001215 if (action_field == PLINK_CLOSE)
1216 wpa_printf(MSG_DEBUG, "MPM: close reason=%u",
1217 WPA_GET_LE16(peer_mgmt_ie.reason));
1218
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001219 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001220
1221 /*
1222 * If this is an open frame from an unknown STA, and this is an
1223 * open mesh, then go ahead and add the peer before proceeding.
1224 */
1225 if (!sta && action_field == PLINK_OPEN &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07001226 (!(mconf->security & MESH_CONF_SEC_AMPE) ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001227 wpa_auth_pmksa_get(hapd->wpa_auth, mgmt->sa, NULL)))
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001228 sta = mesh_mpm_add_peer(wpa_s, mgmt->sa, &elems);
1229
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001230 if (!sta) {
1231 wpa_printf(MSG_DEBUG, "MPM: No STA entry for peer");
1232 return;
1233 }
1234
1235#ifdef CONFIG_SAE
1236 /* peer is in sae_accepted? */
1237 if (sta->sae && sta->sae->state != SAE_ACCEPTED) {
1238 wpa_printf(MSG_DEBUG, "MPM: SAE not yet accepted for peer");
1239 return;
1240 }
1241#endif /* CONFIG_SAE */
1242
1243 if (!sta->my_lid)
1244 mesh_mpm_init_link(wpa_s, sta);
1245
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001246 if (mconf->security & MESH_CONF_SEC_AMPE) {
1247 int res;
1248
1249 res = mesh_rsn_process_ampe(wpa_s, sta, &elems,
1250 &mgmt->u.action.category,
1251 peer_mgmt_ie.chosen_pmk,
1252 ies, ie_len);
1253 if (res) {
1254 wpa_printf(MSG_DEBUG,
1255 "MPM: RSN process rejected frame (res=%d)",
1256 res);
1257 if (action_field == PLINK_OPEN && res == -2) {
1258 /* AES-SIV decryption failed */
1259 mesh_mpm_fsm(wpa_s, sta, OPN_RJCT,
1260 WLAN_REASON_MESH_INVALID_GTK);
1261 }
1262 return;
1263 }
Hai Shalom74f70d42019-02-11 14:42:39 -08001264
1265#ifdef CONFIG_OCV
1266 if (action_field == PLINK_OPEN && elems.rsn_ie) {
1267 struct wpa_state_machine *sm = sta->wpa_sm;
1268 struct wpa_ie_data data;
1269
1270 res = wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2,
1271 elems.rsn_ie_len + 2,
1272 &data);
1273 if (res) {
1274 wpa_printf(MSG_DEBUG,
1275 "Failed to parse RSN IE (res=%d)",
1276 res);
1277 wpa_hexdump(MSG_DEBUG, "RSN IE", elems.rsn_ie,
1278 elems.rsn_ie_len);
1279 return;
1280 }
1281
1282 wpa_auth_set_ocv(sm, mconf->ocv &&
1283 (data.capabilities &
1284 WPA_CAPABILITY_OCVC));
1285 }
1286
1287 if (action_field != PLINK_CLOSE &&
1288 wpa_auth_uses_ocv(sta->wpa_sm)) {
1289 struct wpa_channel_info ci;
1290 int tx_chanwidth;
1291 int tx_seg1_idx;
1292
1293 if (wpa_drv_channel_info(wpa_s, &ci) != 0) {
1294 wpa_printf(MSG_WARNING,
1295 "MPM: Failed to get channel info to validate received OCI in MPM Confirm");
1296 return;
1297 }
1298
1299 if (get_tx_parameters(
1300 sta, channel_width_to_int(ci.chanwidth),
1301 ci.seg1_idx, &tx_chanwidth,
1302 &tx_seg1_idx) < 0)
1303 return;
1304
1305 if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci,
1306 tx_chanwidth, tx_seg1_idx) !=
Hai Shalom899fcc72020-10-19 14:38:18 -07001307 OCI_SUCCESS) {
1308 wpa_printf(MSG_WARNING, "MPM: OCV failed: %s",
Hai Shalom74f70d42019-02-11 14:42:39 -08001309 ocv_errorstr);
1310 return;
1311 }
1312 }
1313#endif /* CONFIG_OCV */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001314 }
1315
1316 if (sta->plink_state == PLINK_BLOCKED) {
1317 wpa_printf(MSG_DEBUG, "MPM: PLINK_BLOCKED");
1318 return;
1319 }
1320
1321 /* Now we will figure out the appropriate event... */
1322 switch (action_field) {
1323 case PLINK_OPEN:
1324 if (plink_free_count(hapd) == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001325 event = REQ_RJCT;
1326 reason = WLAN_REASON_MESH_MAX_PEERS;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001327 wpa_printf(MSG_INFO,
1328 "MPM: Peer link num over quota(%d)",
1329 hapd->max_plinks);
1330 } else if (sta->peer_lid && sta->peer_lid != plid) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001331 wpa_printf(MSG_DEBUG,
1332 "MPM: peer_lid mismatch: 0x%x != 0x%x",
1333 sta->peer_lid, plid);
1334 return; /* no FSM event */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001335 } else {
1336 sta->peer_lid = plid;
1337 event = OPN_ACPT;
1338 }
1339 break;
1340 case PLINK_CONFIRM:
1341 if (plink_free_count(hapd) == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001342 event = REQ_RJCT;
1343 reason = WLAN_REASON_MESH_MAX_PEERS;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001344 wpa_printf(MSG_INFO,
1345 "MPM: Peer link num over quota(%d)",
1346 hapd->max_plinks);
1347 } else if (sta->my_lid != llid ||
1348 (sta->peer_lid && sta->peer_lid != plid)) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001349 wpa_printf(MSG_DEBUG,
1350 "MPM: lid mismatch: my_lid: 0x%x != 0x%x or peer_lid: 0x%x != 0x%x",
1351 sta->my_lid, llid, sta->peer_lid, plid);
1352 return; /* no FSM event */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001353 } else {
1354 if (!sta->peer_lid)
1355 sta->peer_lid = plid;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001356 sta->peer_aid = aid;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001357 event = CNF_ACPT;
1358 }
1359 break;
1360 case PLINK_CLOSE:
1361 if (sta->plink_state == PLINK_ESTAB)
1362 /* Do not check for llid or plid. This does not
1363 * follow the standard but since multiple plinks
1364 * per cand are not supported, it is necessary in
1365 * order to avoid a livelock when MP A sees an
1366 * establish peer link to MP B but MP B does not
1367 * see it. This can be caused by a timeout in
1368 * B's peer link establishment or B being
1369 * restarted.
1370 */
1371 event = CLS_ACPT;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001372 else if (sta->peer_lid != plid) {
1373 wpa_printf(MSG_DEBUG,
1374 "MPM: peer_lid mismatch: 0x%x != 0x%x",
1375 sta->peer_lid, plid);
1376 return; /* no FSM event */
1377 } else if (peer_mgmt_ie.plid && sta->my_lid != llid) {
1378 wpa_printf(MSG_DEBUG,
1379 "MPM: my_lid mismatch: 0x%x != 0x%x",
1380 sta->my_lid, llid);
1381 return; /* no FSM event */
1382 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001383 event = CLS_ACPT;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001384 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001385 break;
1386 default:
1387 /*
1388 * This cannot be hit due to the action_field check above, but
1389 * compilers may not be able to figure that out and can warn
1390 * about uninitialized event below.
1391 */
1392 return;
1393 }
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001394 mesh_mpm_fsm(wpa_s, sta, event, reason);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001395}
1396
1397
1398/* called by ap_free_sta */
Dmitry Shmidtb97e4282016-02-08 10:16:07 -08001399void mesh_mpm_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001400{
Dmitry Shmidtb97e4282016-02-08 10:16:07 -08001401 if (sta->plink_state == PLINK_ESTAB)
1402 hapd->num_plinks--;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001403 eloop_cancel_timeout(plink_timer, ELOOP_ALL_CTX, sta);
1404 eloop_cancel_timeout(mesh_auth_timer, ELOOP_ALL_CTX, sta);
1405}