blob: 602ed2eb2840849bfe4dd9a09f8bca8eb4878cdf [file] [log] [blame]
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001/*
2 * WPA Supplicant - Basic mesh mode routines
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 "utils/uuid.h"
14#include "common/ieee802_11_defs.h"
15#include "common/wpa_ctrl.h"
16#include "ap/sta_info.h"
17#include "ap/hostapd.h"
18#include "ap/ieee802_11.h"
19#include "config_ssid.h"
20#include "config.h"
21#include "wpa_supplicant_i.h"
22#include "driver_i.h"
23#include "notify.h"
24#include "ap.h"
25#include "mesh_mpm.h"
26#include "mesh_rsn.h"
27#include "mesh.h"
28
29
30static void wpa_supplicant_mesh_deinit(struct wpa_supplicant *wpa_s)
31{
32 wpa_supplicant_mesh_iface_deinit(wpa_s, wpa_s->ifmsh);
33 wpa_s->ifmsh = NULL;
34 wpa_s->current_ssid = NULL;
35 os_free(wpa_s->mesh_rsn);
36 wpa_s->mesh_rsn = NULL;
37 /* TODO: leave mesh (stop beacon). This will happen on link down
38 * anyway, so it's not urgent */
39}
40
41
42void wpa_supplicant_mesh_iface_deinit(struct wpa_supplicant *wpa_s,
43 struct hostapd_iface *ifmsh)
44{
45 if (!ifmsh)
46 return;
47
48 if (ifmsh->mconf) {
49 mesh_mpm_deinit(wpa_s, ifmsh);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080050 if (ifmsh->mconf->rsn_ie) {
51 ifmsh->mconf->rsn_ie = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080052 /* We cannot free this struct
53 * because wpa_authenticator on
54 * hostapd side is also using it
55 * for now just set to NULL and
56 * let hostapd code free it.
57 */
58 }
59 os_free(ifmsh->mconf);
60 ifmsh->mconf = NULL;
61 }
62
63 /* take care of shared data */
64 hostapd_interface_deinit(ifmsh);
65 hostapd_interface_free(ifmsh);
66}
67
68
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070069static struct mesh_conf * mesh_config_create(struct wpa_supplicant *wpa_s,
70 struct wpa_ssid *ssid)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080071{
72 struct mesh_conf *conf;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070073 int cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080074
75 conf = os_zalloc(sizeof(struct mesh_conf));
76 if (!conf)
77 return NULL;
78
79 os_memcpy(conf->meshid, ssid->ssid, ssid->ssid_len);
80 conf->meshid_len = ssid->ssid_len;
81
82 if (ssid->key_mgmt & WPA_KEY_MGMT_SAE)
83 conf->security |= MESH_CONF_SEC_AUTH |
84 MESH_CONF_SEC_AMPE;
85 else
86 conf->security |= MESH_CONF_SEC_NONE;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070087 conf->ieee80211w = ssid->ieee80211w;
88 if (conf->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT) {
89 if (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_BIP)
90 conf->ieee80211w = wpa_s->conf->pmf;
91 else
92 conf->ieee80211w = NO_MGMT_FRAME_PROTECTION;
93 }
94
95 cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher, 0);
96 if (cipher < 0 || cipher == WPA_CIPHER_TKIP) {
97 wpa_msg(wpa_s, MSG_INFO, "mesh: Invalid pairwise cipher");
98 os_free(conf);
99 return NULL;
100 }
101 conf->pairwise_cipher = cipher;
102
103 cipher = wpa_pick_group_cipher(ssid->group_cipher);
104 if (cipher < 0 || cipher == WPA_CIPHER_TKIP ||
105 cipher == WPA_CIPHER_GTK_NOT_USED) {
106 wpa_msg(wpa_s, MSG_INFO, "mesh: Invalid group cipher");
107 os_free(conf);
108 return NULL;
109 }
110
111 conf->group_cipher = cipher;
112 if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION)
113 conf->mgmt_group_cipher = WPA_CIPHER_AES_128_CMAC;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800114
115 /* defaults */
116 conf->mesh_pp_id = MESH_PATH_PROTOCOL_HWMP;
117 conf->mesh_pm_id = MESH_PATH_METRIC_AIRTIME;
118 conf->mesh_cc_id = 0;
119 conf->mesh_sp_id = MESH_SYNC_METHOD_NEIGHBOR_OFFSET;
120 conf->mesh_auth_id = (conf->security & MESH_CONF_SEC_AUTH) ? 1 : 0;
121 conf->dot11MeshMaxRetries = ssid->dot11MeshMaxRetries;
122 conf->dot11MeshRetryTimeout = ssid->dot11MeshRetryTimeout;
123 conf->dot11MeshConfirmTimeout = ssid->dot11MeshConfirmTimeout;
124 conf->dot11MeshHoldingTimeout = ssid->dot11MeshHoldingTimeout;
125
126 return conf;
127}
128
129
130static void wpas_mesh_copy_groups(struct hostapd_data *bss,
131 struct wpa_supplicant *wpa_s)
132{
133 int num_groups;
134 size_t groups_size;
135
136 for (num_groups = 0; wpa_s->conf->sae_groups[num_groups] > 0;
137 num_groups++)
138 ;
139
140 groups_size = (num_groups + 1) * sizeof(wpa_s->conf->sae_groups[0]);
141 bss->conf->sae_groups = os_malloc(groups_size);
142 if (bss->conf->sae_groups)
143 os_memcpy(bss->conf->sae_groups, wpa_s->conf->sae_groups,
144 groups_size);
145}
146
147
148static int wpa_supplicant_mesh_init(struct wpa_supplicant *wpa_s,
Dmitry Shmidt29333592017-01-09 12:27:11 -0800149 struct wpa_ssid *ssid,
150 struct hostapd_freq_params *freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800151{
152 struct hostapd_iface *ifmsh;
153 struct hostapd_data *bss;
154 struct hostapd_config *conf;
155 struct mesh_conf *mconf;
156 int basic_rates_erp[] = { 10, 20, 55, 60, 110, 120, 240, -1 };
157 static int default_groups[] = { 19, 20, 21, 25, 26, -1 };
158 size_t len;
159 int rate_len;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800160 int frequency;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800161
162 if (!wpa_s->conf->user_mpm) {
163 /* not much for us to do here */
164 wpa_msg(wpa_s, MSG_WARNING,
165 "user_mpm is not enabled in configuration");
166 return 0;
167 }
168
169 wpa_s->ifmsh = ifmsh = os_zalloc(sizeof(*wpa_s->ifmsh));
170 if (!ifmsh)
171 return -ENOMEM;
172
173 ifmsh->drv_flags = wpa_s->drv_flags;
174 ifmsh->num_bss = 1;
175 ifmsh->bss = os_calloc(wpa_s->ifmsh->num_bss,
176 sizeof(struct hostapd_data *));
177 if (!ifmsh->bss)
178 goto out_free;
179
180 ifmsh->bss[0] = bss = os_zalloc(sizeof(struct hostapd_data));
181 if (!bss)
182 goto out_free;
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700183 dl_list_init(&bss->nr_db);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800184
185 os_memcpy(bss->own_addr, wpa_s->own_addr, ETH_ALEN);
186 bss->driver = wpa_s->driver;
187 bss->drv_priv = wpa_s->drv_priv;
188 bss->iface = ifmsh;
189 bss->mesh_sta_free_cb = mesh_mpm_free_sta;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800190 frequency = ssid->frequency;
191 if (frequency != freq->freq &&
192 frequency == freq->freq + freq->sec_channel_offset * 20) {
193 wpa_printf(MSG_DEBUG, "mesh: pri/sec channels switched");
194 frequency = freq->freq;
195 }
196 wpa_s->assoc_freq = frequency;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800197 wpa_s->current_ssid = ssid;
198
199 /* setup an AP config for auth processing */
200 conf = hostapd_config_defaults();
201 if (!conf)
202 goto out_free;
203
204 bss->conf = *conf->bss;
205 bss->conf->start_disabled = 1;
206 bss->conf->mesh = MESH_ENABLED;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800207 bss->conf->ap_max_inactivity = wpa_s->conf->mesh_max_inactivity;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800208 bss->iconf = conf;
209 ifmsh->conf = conf;
210
211 ifmsh->bss[0]->max_plinks = wpa_s->conf->max_peer_links;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800212 ifmsh->bss[0]->dot11RSNASAERetransPeriod =
213 wpa_s->conf->dot11RSNASAERetransPeriod;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800214 os_strlcpy(bss->conf->iface, wpa_s->ifname, sizeof(bss->conf->iface));
215
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700216 mconf = mesh_config_create(wpa_s, ssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800217 if (!mconf)
218 goto out_free;
219 ifmsh->mconf = mconf;
220
221 /* need conf->hw_mode for supported rates. */
Dmitry Shmidt29333592017-01-09 12:27:11 -0800222 conf->hw_mode = ieee80211_freq_to_chan(frequency, &conf->channel);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800223 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
224 wpa_printf(MSG_ERROR, "Unsupported mesh mode frequency: %d MHz",
Dmitry Shmidt29333592017-01-09 12:27:11 -0800225 frequency);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800226 goto out_free;
227 }
Dmitry Shmidt0e58d9b2015-12-22 10:59:44 -0800228 if (ssid->ht40)
229 conf->secondary_channel = ssid->ht40;
230 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A && ssid->vht) {
231 conf->vht_oper_chwidth = ssid->max_oper_chwidth;
232 switch (conf->vht_oper_chwidth) {
233 case VHT_CHANWIDTH_80MHZ:
234 case VHT_CHANWIDTH_80P80MHZ:
235 ieee80211_freq_to_chan(
Dmitry Shmidt29333592017-01-09 12:27:11 -0800236 frequency,
Dmitry Shmidt0e58d9b2015-12-22 10:59:44 -0800237 &conf->vht_oper_centr_freq_seg0_idx);
238 conf->vht_oper_centr_freq_seg0_idx += ssid->ht40 * 2;
239 break;
240 case VHT_CHANWIDTH_160MHZ:
241 ieee80211_freq_to_chan(
Dmitry Shmidt29333592017-01-09 12:27:11 -0800242 frequency,
Dmitry Shmidt0e58d9b2015-12-22 10:59:44 -0800243 &conf->vht_oper_centr_freq_seg0_idx);
244 conf->vht_oper_centr_freq_seg0_idx += ssid->ht40 * 2;
245 conf->vht_oper_centr_freq_seg0_idx += 40 / 5;
246 break;
247 }
248 ieee80211_freq_to_chan(ssid->vht_center_freq2,
249 &conf->vht_oper_centr_freq_seg1_idx);
250 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800251
252 if (ssid->mesh_basic_rates == NULL) {
253 /*
254 * XXX: Hack! This is so an MPM which correctly sets the ERP
255 * mandatory rates as BSSBasicRateSet doesn't reject us. We
256 * could add a new hw_mode HOSTAPD_MODE_IEEE80211G_ERP, but
257 * this is way easier. This also makes our BSSBasicRateSet
258 * advertised in beacons match the one in peering frames, sigh.
259 */
260 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
261 conf->basic_rates = os_malloc(sizeof(basic_rates_erp));
262 if (!conf->basic_rates)
263 goto out_free;
264 os_memcpy(conf->basic_rates, basic_rates_erp,
265 sizeof(basic_rates_erp));
266 }
267 } else {
268 rate_len = 0;
269 while (1) {
270 if (ssid->mesh_basic_rates[rate_len] < 1)
271 break;
272 rate_len++;
273 }
274 conf->basic_rates = os_calloc(rate_len + 1, sizeof(int));
275 if (conf->basic_rates == NULL)
276 goto out_free;
277 os_memcpy(conf->basic_rates, ssid->mesh_basic_rates,
278 rate_len * sizeof(int));
279 conf->basic_rates[rate_len] = -1;
280 }
281
282 if (hostapd_setup_interface(ifmsh)) {
283 wpa_printf(MSG_ERROR,
284 "Failed to initialize hostapd interface for mesh");
285 return -1;
286 }
287
288 if (wpa_drv_init_mesh(wpa_s)) {
289 wpa_msg(wpa_s, MSG_ERROR, "Failed to init mesh in driver");
290 return -1;
291 }
292
293 if (mconf->security != MESH_CONF_SEC_NONE) {
294 if (ssid->passphrase == NULL) {
295 wpa_printf(MSG_ERROR,
296 "mesh: Passphrase for SAE not configured");
297 goto out_free;
298 }
299
300 bss->conf->wpa = ssid->proto;
301 bss->conf->wpa_key_mgmt = ssid->key_mgmt;
302
303 if (wpa_s->conf->sae_groups &&
304 wpa_s->conf->sae_groups[0] > 0) {
305 wpas_mesh_copy_groups(bss, wpa_s);
306 } else {
307 bss->conf->sae_groups =
308 os_malloc(sizeof(default_groups));
309 if (!bss->conf->sae_groups)
310 goto out_free;
311 os_memcpy(bss->conf->sae_groups, default_groups,
312 sizeof(default_groups));
313 }
314
315 len = os_strlen(ssid->passphrase);
316 bss->conf->ssid.wpa_passphrase =
317 dup_binstr(ssid->passphrase, len);
318
319 wpa_s->mesh_rsn = mesh_rsn_auth_init(wpa_s, mconf);
320 if (!wpa_s->mesh_rsn)
321 goto out_free;
322 }
323
324 wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf);
325
326 return 0;
327out_free:
328 wpa_supplicant_mesh_deinit(wpa_s);
329 return -ENOMEM;
330}
331
332
333void wpa_mesh_notify_peer(struct wpa_supplicant *wpa_s, const u8 *addr,
334 const u8 *ies, size_t ie_len)
335{
336 struct ieee802_11_elems elems;
337
338 wpa_msg(wpa_s, MSG_INFO,
339 "new peer notification for " MACSTR, MAC2STR(addr));
340
341 if (ieee802_11_parse_elems(ies, ie_len, &elems, 0) == ParseFailed) {
342 wpa_msg(wpa_s, MSG_INFO, "Could not parse beacon from " MACSTR,
343 MAC2STR(addr));
344 return;
345 }
346 wpa_mesh_new_mesh_peer(wpa_s, addr, &elems);
347}
348
349
350void wpa_supplicant_mesh_add_scan_ie(struct wpa_supplicant *wpa_s,
351 struct wpabuf **extra_ie)
352{
353 /* EID + 0-length (wildcard) mesh-id */
354 size_t ielen = 2;
355
356 if (wpabuf_resize(extra_ie, ielen) == 0) {
357 wpabuf_put_u8(*extra_ie, WLAN_EID_MESH_ID);
358 wpabuf_put_u8(*extra_ie, 0);
359 }
360}
361
362
363int wpa_supplicant_join_mesh(struct wpa_supplicant *wpa_s,
364 struct wpa_ssid *ssid)
365{
366 struct wpa_driver_mesh_join_params params;
367 int ret = 0;
368
369 if (!ssid || !ssid->ssid || !ssid->ssid_len || !ssid->frequency) {
370 ret = -ENOENT;
371 goto out;
372 }
373
374 wpa_supplicant_mesh_deinit(wpa_s);
375
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700376 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
377 wpa_s->group_cipher = WPA_CIPHER_NONE;
378 wpa_s->mgmt_group_cipher = 0;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800379
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800380 os_memset(&params, 0, sizeof(params));
381 params.meshid = ssid->ssid;
382 params.meshid_len = ssid->ssid_len;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800383 ibss_mesh_setup_freq(wpa_s, ssid, &params.freq);
384 wpa_s->mesh_ht_enabled = !!params.freq.ht_enabled;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800385 wpa_s->mesh_vht_enabled = !!params.freq.vht_enabled;
Dmitry Shmidt0e58d9b2015-12-22 10:59:44 -0800386 if (params.freq.ht_enabled && params.freq.sec_channel_offset)
387 ssid->ht40 = params.freq.sec_channel_offset;
388 if (wpa_s->mesh_vht_enabled) {
389 ssid->vht = 1;
390 switch (params.freq.bandwidth) {
391 case 80:
392 if (params.freq.center_freq2) {
393 ssid->max_oper_chwidth = VHT_CHANWIDTH_80P80MHZ;
394 ssid->vht_center_freq2 =
395 params.freq.center_freq2;
396 } else {
397 ssid->max_oper_chwidth = VHT_CHANWIDTH_80MHZ;
398 }
399 break;
400 case 160:
401 ssid->max_oper_chwidth = VHT_CHANWIDTH_160MHZ;
402 break;
403 default:
404 ssid->max_oper_chwidth = VHT_CHANWIDTH_USE_HT;
405 break;
406 }
407 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800408 if (ssid->beacon_int > 0)
409 params.beacon_int = ssid->beacon_int;
410 else if (wpa_s->conf->beacon_int > 0)
411 params.beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700412 if (ssid->dtim_period > 0)
413 params.dtim_period = ssid->dtim_period;
414 else if (wpa_s->conf->dtim_period > 0)
415 params.dtim_period = wpa_s->conf->dtim_period;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -0700416 params.conf.max_peer_links = wpa_s->conf->max_peer_links;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800417
418 if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
419 params.flags |= WPA_DRIVER_MESH_FLAG_SAE_AUTH;
420 params.flags |= WPA_DRIVER_MESH_FLAG_AMPE;
421 wpa_s->conf->user_mpm = 1;
422 }
423
424 if (wpa_s->conf->user_mpm) {
425 params.flags |= WPA_DRIVER_MESH_FLAG_USER_MPM;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -0700426 params.conf.auto_plinks = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800427 } else {
428 params.flags |= WPA_DRIVER_MESH_FLAG_DRIVER_MPM;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -0700429 params.conf.auto_plinks = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800430 }
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800431 params.conf.peer_link_timeout = wpa_s->conf->mesh_max_inactivity;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800432
Dmitry Shmidt29333592017-01-09 12:27:11 -0800433 if (wpa_supplicant_mesh_init(wpa_s, ssid, &params.freq)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800434 wpa_msg(wpa_s, MSG_ERROR, "Failed to init mesh");
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -0700435 wpa_drv_leave_mesh(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800436 ret = -1;
437 goto out;
438 }
439
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700440 if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
441 wpa_s->pairwise_cipher = wpa_s->mesh_rsn->pairwise_cipher;
442 wpa_s->group_cipher = wpa_s->mesh_rsn->group_cipher;
443 wpa_s->mgmt_group_cipher = wpa_s->mesh_rsn->mgmt_group_cipher;
444 }
445
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800446 if (wpa_s->ifmsh) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800447 params.ies = wpa_s->ifmsh->mconf->rsn_ie;
448 params.ie_len = wpa_s->ifmsh->mconf->rsn_ie_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800449 params.basic_rates = wpa_s->ifmsh->basic_rates;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -0700450 params.conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE;
451 params.conf.ht_opmode = wpa_s->ifmsh->bss[0]->iface->ht_op_mode;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800452 }
453
454 wpa_msg(wpa_s, MSG_INFO, "joining mesh %s",
455 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
456 ret = wpa_drv_join_mesh(wpa_s, &params);
457 if (ret)
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700458 wpa_msg(wpa_s, MSG_ERROR, "mesh join error=%d", ret);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800459
460 /* hostapd sets the interface down until we associate */
461 wpa_drv_set_operstate(wpa_s, 1);
462
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -0700463 if (!ret)
464 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
465
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800466out:
467 return ret;
468}
469
470
471int wpa_supplicant_leave_mesh(struct wpa_supplicant *wpa_s)
472{
473 int ret = 0;
474
475 wpa_msg(wpa_s, MSG_INFO, "leaving mesh");
476
477 /* Need to send peering close messages first */
478 wpa_supplicant_mesh_deinit(wpa_s);
479
480 ret = wpa_drv_leave_mesh(wpa_s);
481 if (ret)
482 wpa_msg(wpa_s, MSG_ERROR, "mesh leave error=%d", ret);
483
484 wpa_drv_set_operstate(wpa_s, 1);
485
486 return ret;
487}
488
489
490static int mesh_attr_text(const u8 *ies, size_t ies_len, char *buf, char *end)
491{
492 struct ieee802_11_elems elems;
493 char *mesh_id, *pos = buf;
494 u8 *bss_basic_rate_set;
495 int bss_basic_rate_set_len, ret, i;
496
497 if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) == ParseFailed)
498 return -1;
499
500 if (elems.mesh_id_len < 1)
501 return 0;
502
503 mesh_id = os_malloc(elems.mesh_id_len + 1);
504 if (mesh_id == NULL)
505 return -1;
506
507 os_memcpy(mesh_id, elems.mesh_id, elems.mesh_id_len);
508 mesh_id[elems.mesh_id_len] = '\0';
509 ret = os_snprintf(pos, end - pos, "mesh_id=%s\n", mesh_id);
510 os_free(mesh_id);
511 if (os_snprintf_error(end - pos, ret))
512 return pos - buf;
513 pos += ret;
514
515 if (elems.mesh_config_len > 6) {
516 ret = os_snprintf(pos, end - pos,
517 "active_path_selection_protocol_id=0x%02x\n"
518 "active_path_selection_metric_id=0x%02x\n"
519 "congestion_control_mode_id=0x%02x\n"
520 "synchronization_method_id=0x%02x\n"
521 "authentication_protocol_id=0x%02x\n"
522 "mesh_formation_info=0x%02x\n"
523 "mesh_capability=0x%02x\n",
524 elems.mesh_config[0], elems.mesh_config[1],
525 elems.mesh_config[2], elems.mesh_config[3],
526 elems.mesh_config[4], elems.mesh_config[5],
527 elems.mesh_config[6]);
528 if (os_snprintf_error(end - pos, ret))
529 return pos - buf;
530 pos += ret;
531 }
532
533 bss_basic_rate_set = os_malloc(elems.supp_rates_len +
534 elems.ext_supp_rates_len);
535 if (bss_basic_rate_set == NULL)
536 return -1;
537
538 bss_basic_rate_set_len = 0;
539 for (i = 0; i < elems.supp_rates_len; i++) {
540 if (elems.supp_rates[i] & 0x80) {
541 bss_basic_rate_set[bss_basic_rate_set_len++] =
542 (elems.supp_rates[i] & 0x7f) * 5;
543 }
544 }
545 for (i = 0; i < elems.ext_supp_rates_len; i++) {
546 if (elems.ext_supp_rates[i] & 0x80) {
547 bss_basic_rate_set[bss_basic_rate_set_len++] =
548 (elems.ext_supp_rates[i] & 0x7f) * 5;
549 }
550 }
551 if (bss_basic_rate_set_len > 0) {
552 ret = os_snprintf(pos, end - pos, "bss_basic_rate_set=%d",
553 bss_basic_rate_set[0]);
554 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700555 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800556 pos += ret;
557
558 for (i = 1; i < bss_basic_rate_set_len; i++) {
559 ret = os_snprintf(pos, end - pos, " %d",
560 bss_basic_rate_set[i]);
561 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700562 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800563 pos += ret;
564 }
565
566 ret = os_snprintf(pos, end - pos, "\n");
567 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700568 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800569 pos += ret;
570 }
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700571fail:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800572 os_free(bss_basic_rate_set);
573
574 return pos - buf;
575}
576
577
578int wpas_mesh_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
579 char *end)
580{
581 return mesh_attr_text(ies, ies_len, buf, end);
582}
583
584
585static int wpas_mesh_get_ifname(struct wpa_supplicant *wpa_s, char *ifname,
586 size_t len)
587{
588 char *ifname_ptr = wpa_s->ifname;
589 int res;
590
591 res = os_snprintf(ifname, len, "mesh-%s-%d", ifname_ptr,
592 wpa_s->mesh_if_idx);
593 if (os_snprintf_error(len, res) ||
594 (os_strlen(ifname) >= IFNAMSIZ &&
595 os_strlen(wpa_s->ifname) < IFNAMSIZ)) {
596 /* Try to avoid going over the IFNAMSIZ length limit */
597 res = os_snprintf(ifname, len, "mesh-%d", wpa_s->mesh_if_idx);
598 if (os_snprintf_error(len, res))
599 return -1;
600 }
601 wpa_s->mesh_if_idx++;
602 return 0;
603}
604
605
606int wpas_mesh_add_interface(struct wpa_supplicant *wpa_s, char *ifname,
607 size_t len)
608{
609 struct wpa_interface iface;
610 struct wpa_supplicant *mesh_wpa_s;
611 u8 addr[ETH_ALEN];
612
613 if (ifname[0] == '\0' && wpas_mesh_get_ifname(wpa_s, ifname, len) < 0)
614 return -1;
615
616 if (wpa_drv_if_add(wpa_s, WPA_IF_MESH, ifname, NULL, NULL, NULL, addr,
617 NULL) < 0) {
618 wpa_printf(MSG_ERROR,
619 "mesh: Failed to create new mesh interface");
620 return -1;
621 }
622 wpa_printf(MSG_INFO, "mesh: Created virtual interface %s addr "
623 MACSTR, ifname, MAC2STR(addr));
624
625 os_memset(&iface, 0, sizeof(iface));
626 iface.ifname = ifname;
627 iface.driver = wpa_s->driver->name;
628 iface.driver_param = wpa_s->conf->driver_param;
629 iface.ctrl_interface = wpa_s->conf->ctrl_interface;
630
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800631 mesh_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface, wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800632 if (!mesh_wpa_s) {
633 wpa_printf(MSG_ERROR,
634 "mesh: Failed to create new wpa_supplicant interface");
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700635 wpa_drv_if_remove(wpa_s, WPA_IF_MESH, ifname);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800636 return -1;
637 }
638 mesh_wpa_s->mesh_if_created = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800639 return 0;
640}
Dmitry Shmidte4663042016-04-04 10:07:49 -0700641
642
643int wpas_mesh_peer_remove(struct wpa_supplicant *wpa_s, const u8 *addr)
644{
645 return mesh_mpm_close_peer(wpa_s, addr);
646}
647
648
649int wpas_mesh_peer_add(struct wpa_supplicant *wpa_s, const u8 *addr,
650 int duration)
651{
652 return mesh_mpm_connect_peer(wpa_s, addr, duration);
653}