mesh: Avoid use of hardcoded cipher
[mech_eap.git] / wpa_supplicant / mesh.c
1 /*
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
30 static 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
42 void 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);
50                 if (ifmsh->mconf->rsn_ie) {
51                         ifmsh->mconf->rsn_ie = NULL;
52                         /* 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
69 static struct mesh_conf * mesh_config_create(struct wpa_supplicant *wpa_s,
70                                              struct wpa_ssid *ssid)
71 {
72         struct mesh_conf *conf;
73
74         conf = os_zalloc(sizeof(struct mesh_conf));
75         if (!conf)
76                 return NULL;
77
78         os_memcpy(conf->meshid, ssid->ssid, ssid->ssid_len);
79         conf->meshid_len = ssid->ssid_len;
80
81         if (ssid->key_mgmt & WPA_KEY_MGMT_SAE)
82                 conf->security |= MESH_CONF_SEC_AUTH |
83                         MESH_CONF_SEC_AMPE;
84         else
85                 conf->security |= MESH_CONF_SEC_NONE;
86         conf->ieee80211w = ssid->ieee80211w;
87         if (conf->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT) {
88                 if (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_BIP)
89                         conf->ieee80211w = wpa_s->conf->pmf;
90                 else
91                         conf->ieee80211w = NO_MGMT_FRAME_PROTECTION;
92         }
93         conf->pairwise_cipher = WPA_CIPHER_CCMP;
94         conf->group_cipher = WPA_CIPHER_CCMP;
95         if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION)
96                 conf->mgmt_group_cipher = WPA_CIPHER_AES_128_CMAC;
97
98         /* defaults */
99         conf->mesh_pp_id = MESH_PATH_PROTOCOL_HWMP;
100         conf->mesh_pm_id = MESH_PATH_METRIC_AIRTIME;
101         conf->mesh_cc_id = 0;
102         conf->mesh_sp_id = MESH_SYNC_METHOD_NEIGHBOR_OFFSET;
103         conf->mesh_auth_id = (conf->security & MESH_CONF_SEC_AUTH) ? 1 : 0;
104         conf->dot11MeshMaxRetries = ssid->dot11MeshMaxRetries;
105         conf->dot11MeshRetryTimeout = ssid->dot11MeshRetryTimeout;
106         conf->dot11MeshConfirmTimeout = ssid->dot11MeshConfirmTimeout;
107         conf->dot11MeshHoldingTimeout = ssid->dot11MeshHoldingTimeout;
108
109         return conf;
110 }
111
112
113 static void wpas_mesh_copy_groups(struct hostapd_data *bss,
114                                   struct wpa_supplicant *wpa_s)
115 {
116         int num_groups;
117         size_t groups_size;
118
119         for (num_groups = 0; wpa_s->conf->sae_groups[num_groups] > 0;
120              num_groups++)
121                 ;
122
123         groups_size = (num_groups + 1) * sizeof(wpa_s->conf->sae_groups[0]);
124         bss->conf->sae_groups = os_malloc(groups_size);
125         if (bss->conf->sae_groups)
126                 os_memcpy(bss->conf->sae_groups, wpa_s->conf->sae_groups,
127                           groups_size);
128 }
129
130
131 static int wpa_supplicant_mesh_init(struct wpa_supplicant *wpa_s,
132                                     struct wpa_ssid *ssid)
133 {
134         struct hostapd_iface *ifmsh;
135         struct hostapd_data *bss;
136         struct hostapd_config *conf;
137         struct mesh_conf *mconf;
138         int basic_rates_erp[] = { 10, 20, 55, 60, 110, 120, 240, -1 };
139         static int default_groups[] = { 19, 20, 21, 25, 26, -1 };
140         size_t len;
141         int rate_len;
142
143         if (!wpa_s->conf->user_mpm) {
144                 /* not much for us to do here */
145                 wpa_msg(wpa_s, MSG_WARNING,
146                         "user_mpm is not enabled in configuration");
147                 return 0;
148         }
149
150         wpa_s->ifmsh = ifmsh = os_zalloc(sizeof(*wpa_s->ifmsh));
151         if (!ifmsh)
152                 return -ENOMEM;
153
154         ifmsh->drv_flags = wpa_s->drv_flags;
155         ifmsh->num_bss = 1;
156         ifmsh->bss = os_calloc(wpa_s->ifmsh->num_bss,
157                                sizeof(struct hostapd_data *));
158         if (!ifmsh->bss)
159                 goto out_free;
160
161         ifmsh->bss[0] = bss = os_zalloc(sizeof(struct hostapd_data));
162         if (!bss)
163                 goto out_free;
164
165         os_memcpy(bss->own_addr, wpa_s->own_addr, ETH_ALEN);
166         bss->driver = wpa_s->driver;
167         bss->drv_priv = wpa_s->drv_priv;
168         bss->iface = ifmsh;
169         bss->mesh_sta_free_cb = mesh_mpm_free_sta;
170         wpa_s->assoc_freq = ssid->frequency;
171         wpa_s->current_ssid = ssid;
172
173         /* setup an AP config for auth processing */
174         conf = hostapd_config_defaults();
175         if (!conf)
176                 goto out_free;
177
178         bss->conf = *conf->bss;
179         bss->conf->start_disabled = 1;
180         bss->conf->mesh = MESH_ENABLED;
181         bss->conf->ap_max_inactivity = wpa_s->conf->mesh_max_inactivity;
182         bss->iconf = conf;
183         ifmsh->conf = conf;
184
185         ifmsh->bss[0]->max_plinks = wpa_s->conf->max_peer_links;
186         ifmsh->bss[0]->dot11RSNASAERetransPeriod =
187                 wpa_s->conf->dot11RSNASAERetransPeriod;
188         os_strlcpy(bss->conf->iface, wpa_s->ifname, sizeof(bss->conf->iface));
189
190         mconf = mesh_config_create(wpa_s, ssid);
191         if (!mconf)
192                 goto out_free;
193         ifmsh->mconf = mconf;
194
195         /* need conf->hw_mode for supported rates. */
196         conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency, &conf->channel);
197         if (conf->hw_mode == NUM_HOSTAPD_MODES) {
198                 wpa_printf(MSG_ERROR, "Unsupported mesh mode frequency: %d MHz",
199                            ssid->frequency);
200                 goto out_free;
201         }
202         if (ssid->ht40)
203                 conf->secondary_channel = ssid->ht40;
204         if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A && ssid->vht) {
205                 conf->vht_oper_chwidth = ssid->max_oper_chwidth;
206                 switch (conf->vht_oper_chwidth) {
207                 case VHT_CHANWIDTH_80MHZ:
208                 case VHT_CHANWIDTH_80P80MHZ:
209                         ieee80211_freq_to_chan(
210                                 ssid->frequency,
211                                 &conf->vht_oper_centr_freq_seg0_idx);
212                         conf->vht_oper_centr_freq_seg0_idx += ssid->ht40 * 2;
213                         break;
214                 case VHT_CHANWIDTH_160MHZ:
215                         ieee80211_freq_to_chan(
216                                 ssid->frequency,
217                                 &conf->vht_oper_centr_freq_seg0_idx);
218                         conf->vht_oper_centr_freq_seg0_idx += ssid->ht40 * 2;
219                         conf->vht_oper_centr_freq_seg0_idx += 40 / 5;
220                         break;
221                 }
222                 ieee80211_freq_to_chan(ssid->vht_center_freq2,
223                                        &conf->vht_oper_centr_freq_seg1_idx);
224         }
225
226         if (ssid->mesh_basic_rates == NULL) {
227                 /*
228                  * XXX: Hack! This is so an MPM which correctly sets the ERP
229                  * mandatory rates as BSSBasicRateSet doesn't reject us. We
230                  * could add a new hw_mode HOSTAPD_MODE_IEEE80211G_ERP, but
231                  * this is way easier. This also makes our BSSBasicRateSet
232                  * advertised in beacons match the one in peering frames, sigh.
233                  */
234                 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
235                         conf->basic_rates = os_malloc(sizeof(basic_rates_erp));
236                         if (!conf->basic_rates)
237                                 goto out_free;
238                         os_memcpy(conf->basic_rates, basic_rates_erp,
239                                   sizeof(basic_rates_erp));
240                 }
241         } else {
242                 rate_len = 0;
243                 while (1) {
244                         if (ssid->mesh_basic_rates[rate_len] < 1)
245                                 break;
246                         rate_len++;
247                 }
248                 conf->basic_rates = os_calloc(rate_len + 1, sizeof(int));
249                 if (conf->basic_rates == NULL)
250                         goto out_free;
251                 os_memcpy(conf->basic_rates, ssid->mesh_basic_rates,
252                           rate_len * sizeof(int));
253                 conf->basic_rates[rate_len] = -1;
254         }
255
256         if (hostapd_setup_interface(ifmsh)) {
257                 wpa_printf(MSG_ERROR,
258                            "Failed to initialize hostapd interface for mesh");
259                 return -1;
260         }
261
262         if (wpa_drv_init_mesh(wpa_s)) {
263                 wpa_msg(wpa_s, MSG_ERROR, "Failed to init mesh in driver");
264                 return -1;
265         }
266
267         if (mconf->security != MESH_CONF_SEC_NONE) {
268                 if (ssid->passphrase == NULL) {
269                         wpa_printf(MSG_ERROR,
270                                    "mesh: Passphrase for SAE not configured");
271                         goto out_free;
272                 }
273
274                 bss->conf->wpa = ssid->proto;
275                 bss->conf->wpa_key_mgmt = ssid->key_mgmt;
276
277                 if (wpa_s->conf->sae_groups &&
278                     wpa_s->conf->sae_groups[0] > 0) {
279                         wpas_mesh_copy_groups(bss, wpa_s);
280                 } else {
281                         bss->conf->sae_groups =
282                                 os_malloc(sizeof(default_groups));
283                         if (!bss->conf->sae_groups)
284                                 goto out_free;
285                         os_memcpy(bss->conf->sae_groups, default_groups,
286                                   sizeof(default_groups));
287                 }
288
289                 len = os_strlen(ssid->passphrase);
290                 bss->conf->ssid.wpa_passphrase =
291                         dup_binstr(ssid->passphrase, len);
292
293                 wpa_s->mesh_rsn = mesh_rsn_auth_init(wpa_s, mconf);
294                 if (!wpa_s->mesh_rsn)
295                         goto out_free;
296         }
297
298         wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf);
299
300         return 0;
301 out_free:
302         wpa_supplicant_mesh_deinit(wpa_s);
303         return -ENOMEM;
304 }
305
306
307 void wpa_mesh_notify_peer(struct wpa_supplicant *wpa_s, const u8 *addr,
308                           const u8 *ies, size_t ie_len)
309 {
310         struct ieee802_11_elems elems;
311
312         wpa_msg(wpa_s, MSG_INFO,
313                 "new peer notification for " MACSTR, MAC2STR(addr));
314
315         if (ieee802_11_parse_elems(ies, ie_len, &elems, 0) == ParseFailed) {
316                 wpa_msg(wpa_s, MSG_INFO, "Could not parse beacon from " MACSTR,
317                         MAC2STR(addr));
318                 return;
319         }
320         wpa_mesh_new_mesh_peer(wpa_s, addr, &elems);
321 }
322
323
324 void wpa_supplicant_mesh_add_scan_ie(struct wpa_supplicant *wpa_s,
325                                      struct wpabuf **extra_ie)
326 {
327         /* EID + 0-length (wildcard) mesh-id */
328         size_t ielen = 2;
329
330         if (wpabuf_resize(extra_ie, ielen) == 0) {
331                 wpabuf_put_u8(*extra_ie, WLAN_EID_MESH_ID);
332                 wpabuf_put_u8(*extra_ie, 0);
333         }
334 }
335
336
337 int wpa_supplicant_join_mesh(struct wpa_supplicant *wpa_s,
338                              struct wpa_ssid *ssid)
339 {
340         struct wpa_driver_mesh_join_params params;
341         int ret = 0;
342
343         if (!ssid || !ssid->ssid || !ssid->ssid_len || !ssid->frequency) {
344                 ret = -ENOENT;
345                 goto out;
346         }
347
348         wpa_supplicant_mesh_deinit(wpa_s);
349
350         wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
351         wpa_s->group_cipher = WPA_CIPHER_NONE;
352         wpa_s->mgmt_group_cipher = 0;
353
354         os_memset(&params, 0, sizeof(params));
355         params.meshid = ssid->ssid;
356         params.meshid_len = ssid->ssid_len;
357         ibss_mesh_setup_freq(wpa_s, ssid, &params.freq);
358         wpa_s->mesh_ht_enabled = !!params.freq.ht_enabled;
359         wpa_s->mesh_vht_enabled = !!params.freq.vht_enabled;
360         if (params.freq.ht_enabled && params.freq.sec_channel_offset)
361                 ssid->ht40 = params.freq.sec_channel_offset;
362         if (wpa_s->mesh_vht_enabled) {
363                 ssid->vht = 1;
364                 switch (params.freq.bandwidth) {
365                 case 80:
366                         if (params.freq.center_freq2) {
367                                 ssid->max_oper_chwidth = VHT_CHANWIDTH_80P80MHZ;
368                                 ssid->vht_center_freq2 =
369                                         params.freq.center_freq2;
370                         } else {
371                                 ssid->max_oper_chwidth = VHT_CHANWIDTH_80MHZ;
372                         }
373                         break;
374                 case 160:
375                         ssid->max_oper_chwidth = VHT_CHANWIDTH_160MHZ;
376                         break;
377                 default:
378                         ssid->max_oper_chwidth = VHT_CHANWIDTH_USE_HT;
379                         break;
380                 }
381         }
382         if (ssid->beacon_int > 0)
383                 params.beacon_int = ssid->beacon_int;
384         else if (wpa_s->conf->beacon_int > 0)
385                 params.beacon_int = wpa_s->conf->beacon_int;
386         params.max_peer_links = wpa_s->conf->max_peer_links;
387
388         if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
389                 params.flags |= WPA_DRIVER_MESH_FLAG_SAE_AUTH;
390                 params.flags |= WPA_DRIVER_MESH_FLAG_AMPE;
391                 wpa_s->conf->user_mpm = 1;
392         }
393
394         if (wpa_s->conf->user_mpm) {
395                 params.flags |= WPA_DRIVER_MESH_FLAG_USER_MPM;
396                 params.conf.flags &= ~WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS;
397         } else {
398                 params.flags |= WPA_DRIVER_MESH_FLAG_DRIVER_MPM;
399                 params.conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS;
400         }
401         params.conf.peer_link_timeout = wpa_s->conf->mesh_max_inactivity;
402
403         if (wpa_supplicant_mesh_init(wpa_s, ssid)) {
404                 wpa_msg(wpa_s, MSG_ERROR, "Failed to init mesh");
405                 wpa_drv_leave_mesh(wpa_s);
406                 ret = -1;
407                 goto out;
408         }
409
410         if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
411                 wpa_s->pairwise_cipher = wpa_s->mesh_rsn->pairwise_cipher;
412                 wpa_s->group_cipher = wpa_s->mesh_rsn->group_cipher;
413                 wpa_s->mgmt_group_cipher = wpa_s->mesh_rsn->mgmt_group_cipher;
414         }
415
416         if (wpa_s->ifmsh) {
417                 params.ies = wpa_s->ifmsh->mconf->rsn_ie;
418                 params.ie_len = wpa_s->ifmsh->mconf->rsn_ie_len;
419                 params.basic_rates = wpa_s->ifmsh->basic_rates;
420         }
421
422         wpa_msg(wpa_s, MSG_INFO, "joining mesh %s",
423                 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
424         ret = wpa_drv_join_mesh(wpa_s, &params);
425         if (ret)
426                 wpa_msg(wpa_s, MSG_ERROR, "mesh join error=%d", ret);
427
428         /* hostapd sets the interface down until we associate */
429         wpa_drv_set_operstate(wpa_s, 1);
430
431 out:
432         return ret;
433 }
434
435
436 int wpa_supplicant_leave_mesh(struct wpa_supplicant *wpa_s)
437 {
438         int ret = 0;
439
440         wpa_msg(wpa_s, MSG_INFO, "leaving mesh");
441
442         /* Need to send peering close messages first */
443         wpa_supplicant_mesh_deinit(wpa_s);
444
445         ret = wpa_drv_leave_mesh(wpa_s);
446         if (ret)
447                 wpa_msg(wpa_s, MSG_ERROR, "mesh leave error=%d", ret);
448
449         wpa_drv_set_operstate(wpa_s, 1);
450
451         return ret;
452 }
453
454
455 static int mesh_attr_text(const u8 *ies, size_t ies_len, char *buf, char *end)
456 {
457         struct ieee802_11_elems elems;
458         char *mesh_id, *pos = buf;
459         u8 *bss_basic_rate_set;
460         int bss_basic_rate_set_len, ret, i;
461
462         if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) == ParseFailed)
463                 return -1;
464
465         if (elems.mesh_id_len < 1)
466                 return 0;
467
468         mesh_id = os_malloc(elems.mesh_id_len + 1);
469         if (mesh_id == NULL)
470                 return -1;
471
472         os_memcpy(mesh_id, elems.mesh_id, elems.mesh_id_len);
473         mesh_id[elems.mesh_id_len] = '\0';
474         ret = os_snprintf(pos, end - pos, "mesh_id=%s\n", mesh_id);
475         os_free(mesh_id);
476         if (os_snprintf_error(end - pos, ret))
477                 return pos - buf;
478         pos += ret;
479
480         if (elems.mesh_config_len > 6) {
481                 ret = os_snprintf(pos, end - pos,
482                                   "active_path_selection_protocol_id=0x%02x\n"
483                                   "active_path_selection_metric_id=0x%02x\n"
484                                   "congestion_control_mode_id=0x%02x\n"
485                                   "synchronization_method_id=0x%02x\n"
486                                   "authentication_protocol_id=0x%02x\n"
487                                   "mesh_formation_info=0x%02x\n"
488                                   "mesh_capability=0x%02x\n",
489                                   elems.mesh_config[0], elems.mesh_config[1],
490                                   elems.mesh_config[2], elems.mesh_config[3],
491                                   elems.mesh_config[4], elems.mesh_config[5],
492                                   elems.mesh_config[6]);
493                 if (os_snprintf_error(end - pos, ret))
494                         return pos - buf;
495                 pos += ret;
496         }
497
498         bss_basic_rate_set = os_malloc(elems.supp_rates_len +
499                 elems.ext_supp_rates_len);
500         if (bss_basic_rate_set == NULL)
501                 return -1;
502
503         bss_basic_rate_set_len = 0;
504         for (i = 0; i < elems.supp_rates_len; i++) {
505                 if (elems.supp_rates[i] & 0x80) {
506                         bss_basic_rate_set[bss_basic_rate_set_len++] =
507                                 (elems.supp_rates[i] & 0x7f) * 5;
508                 }
509         }
510         for (i = 0; i < elems.ext_supp_rates_len; i++) {
511                 if (elems.ext_supp_rates[i] & 0x80) {
512                         bss_basic_rate_set[bss_basic_rate_set_len++] =
513                                 (elems.ext_supp_rates[i] & 0x7f) * 5;
514                 }
515         }
516         if (bss_basic_rate_set_len > 0) {
517                 ret = os_snprintf(pos, end - pos, "bss_basic_rate_set=%d",
518                                   bss_basic_rate_set[0]);
519                 if (os_snprintf_error(end - pos, ret))
520                         goto fail;
521                 pos += ret;
522
523                 for (i = 1; i < bss_basic_rate_set_len; i++) {
524                         ret = os_snprintf(pos, end - pos, " %d",
525                                           bss_basic_rate_set[i]);
526                         if (os_snprintf_error(end - pos, ret))
527                                 goto fail;
528                         pos += ret;
529                 }
530
531                 ret = os_snprintf(pos, end - pos, "\n");
532                 if (os_snprintf_error(end - pos, ret))
533                         goto fail;
534                 pos += ret;
535         }
536 fail:
537         os_free(bss_basic_rate_set);
538
539         return pos - buf;
540 }
541
542
543 int wpas_mesh_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
544                                char *end)
545 {
546         return mesh_attr_text(ies, ies_len, buf, end);
547 }
548
549
550 static int wpas_mesh_get_ifname(struct wpa_supplicant *wpa_s, char *ifname,
551                                 size_t len)
552 {
553         char *ifname_ptr = wpa_s->ifname;
554         int res;
555
556         res = os_snprintf(ifname, len, "mesh-%s-%d", ifname_ptr,
557                           wpa_s->mesh_if_idx);
558         if (os_snprintf_error(len, res) ||
559             (os_strlen(ifname) >= IFNAMSIZ &&
560              os_strlen(wpa_s->ifname) < IFNAMSIZ)) {
561                 /* Try to avoid going over the IFNAMSIZ length limit */
562                 res = os_snprintf(ifname, len, "mesh-%d", wpa_s->mesh_if_idx);
563                 if (os_snprintf_error(len, res))
564                         return -1;
565         }
566         wpa_s->mesh_if_idx++;
567         return 0;
568 }
569
570
571 int wpas_mesh_add_interface(struct wpa_supplicant *wpa_s, char *ifname,
572                             size_t len)
573 {
574         struct wpa_interface iface;
575         struct wpa_supplicant *mesh_wpa_s;
576         u8 addr[ETH_ALEN];
577
578         if (ifname[0] == '\0' && wpas_mesh_get_ifname(wpa_s, ifname, len) < 0)
579                 return -1;
580
581         if (wpa_drv_if_add(wpa_s, WPA_IF_MESH, ifname, NULL, NULL, NULL, addr,
582                            NULL) < 0) {
583                 wpa_printf(MSG_ERROR,
584                            "mesh: Failed to create new mesh interface");
585                 return -1;
586         }
587         wpa_printf(MSG_INFO, "mesh: Created virtual interface %s addr "
588                    MACSTR, ifname, MAC2STR(addr));
589
590         os_memset(&iface, 0, sizeof(iface));
591         iface.ifname = ifname;
592         iface.driver = wpa_s->driver->name;
593         iface.driver_param = wpa_s->conf->driver_param;
594         iface.ctrl_interface = wpa_s->conf->ctrl_interface;
595
596         mesh_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface, wpa_s);
597         if (!mesh_wpa_s) {
598                 wpa_printf(MSG_ERROR,
599                            "mesh: Failed to create new wpa_supplicant interface");
600                 wpa_drv_if_remove(wpa_s, WPA_IF_MESH, ifname);
601                 return -1;
602         }
603         mesh_wpa_s->mesh_if_created = 1;
604         return 0;
605 }
606
607
608 int wpas_mesh_peer_remove(struct wpa_supplicant *wpa_s, const u8 *addr)
609 {
610         return mesh_mpm_close_peer(wpa_s, addr);
611 }
612
613
614 int wpas_mesh_peer_add(struct wpa_supplicant *wpa_s, const u8 *addr,
615                        int duration)
616 {
617         return mesh_mpm_connect_peer(wpa_s, addr, duration);
618 }