wifi: Set wifi device powered FALSE when removed
[framework/connectivity/connman.git] / plugins / wifi.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <errno.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <sys/ioctl.h>
32 #include <sys/socket.h>
33 #include <linux/if_arp.h>
34 #include <linux/wireless.h>
35 #include <net/ethernet.h>
36
37 #ifndef IFF_LOWER_UP
38 #define IFF_LOWER_UP    0x10000
39 #endif
40
41 #include <dbus/dbus.h>
42 #include <glib.h>
43
44 #define CONNMAN_API_SUBJECT_TO_CHANGE
45 #include <connman/plugin.h>
46 #include <connman/inet.h>
47 #include <connman/device.h>
48 #include <connman/rtnl.h>
49 #include <connman/technology.h>
50 #include <connman/log.h>
51 #include <connman/option.h>
52 #include <connman/storage.h>
53
54 #include <gsupplicant/gsupplicant.h>
55
56 #define CLEANUP_TIMEOUT   8     /* in seconds */
57 #define INACTIVE_TIMEOUT  12    /* in seconds */
58 #define MAXIMUM_RETRIES   4
59
60 struct connman_technology *wifi_technology = NULL;
61
62 struct hidden_params {
63         char ssid[32];
64         unsigned int ssid_len;
65         char *identity;
66         char *passphrase;
67 };
68
69 struct wifi_data {
70         char *identifier;
71         struct connman_device *device;
72         struct connman_network *network;
73         struct connman_network *pending_network;
74         GSList *networks;
75         GSupplicantInterface *interface;
76         GSupplicantState state;
77         connman_bool_t connected;
78         connman_bool_t disconnecting;
79         connman_bool_t tethering;
80         connman_bool_t bridged;
81         const char *bridge;
82         int index;
83         unsigned flags;
84         unsigned int watch;
85         int retries;
86         struct hidden_params *hidden;
87 };
88
89 static GList *iface_list = NULL;
90
91 static void handle_tethering(struct wifi_data *wifi)
92 {
93         if (wifi->tethering == FALSE)
94                 return;
95
96         if (wifi->bridge == NULL)
97                 return;
98
99         if (wifi->bridged == TRUE)
100                 return;
101
102         DBG("index %d bridge %s", wifi->index, wifi->bridge);
103
104         if (connman_inet_add_to_bridge(wifi->index, wifi->bridge) < 0)
105                 return;
106
107         wifi->bridged = TRUE;
108 }
109
110 static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
111 {
112         struct connman_device *device = user_data;
113         struct wifi_data *wifi = connman_device_get_data(device);
114
115         DBG("index %d flags %d change %d", wifi->index, flags, change);
116
117         if (!change)
118                 return;
119
120         if ((wifi->flags & IFF_UP) != (flags & IFF_UP)) {
121                 if (flags & IFF_UP)
122                         DBG("interface up");
123                 else
124                         DBG("interface down");
125         }
126
127         if ((wifi->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
128                 if (flags & IFF_LOWER_UP) {
129                         DBG("carrier on");
130
131                         handle_tethering(wifi);
132                 } else
133                         DBG("carrier off");
134         }
135
136         wifi->flags = flags;
137 }
138
139 static int wifi_probe(struct connman_device *device)
140 {
141         struct wifi_data *wifi;
142
143         DBG("device %p", device);
144
145         wifi = g_try_new0(struct wifi_data, 1);
146         if (wifi == NULL)
147                 return -ENOMEM;
148
149         wifi->connected = FALSE;
150         wifi->disconnecting = FALSE;
151         wifi->tethering = FALSE;
152         wifi->bridged = FALSE;
153         wifi->bridge = NULL;
154         wifi->state = G_SUPPLICANT_STATE_INACTIVE;
155
156         connman_device_set_data(device, wifi);
157         wifi->device = connman_device_ref(device);
158
159         wifi->index = connman_device_get_index(device);
160         wifi->flags = 0;
161
162         wifi->watch = connman_rtnl_add_newlink_watch(wifi->index,
163                                                         wifi_newlink, device);
164
165         iface_list = g_list_append(iface_list, wifi);
166
167         return 0;
168 }
169
170 static void remove_networks(struct connman_device *device,
171                                 struct wifi_data *wifi)
172 {
173         GSList *list;
174
175         for (list = wifi->networks; list != NULL; list = list->next) {
176                 struct connman_network *network = list->data;
177
178                 connman_device_remove_network(device, network);
179                 connman_network_unref(network);
180         }
181
182         g_slist_free(wifi->networks);
183         wifi->networks = NULL;
184 }
185
186 static void wifi_remove(struct connman_device *device)
187 {
188         struct wifi_data *wifi = connman_device_get_data(device);
189
190         DBG("device %p wifi %p", device, wifi);
191
192         if (wifi == NULL)
193                 return;
194
195         iface_list = g_list_remove(iface_list, wifi);
196
197         remove_networks(device, wifi);
198
199         connman_device_set_powered(device, FALSE);
200         connman_device_set_data(device, NULL);
201         connman_device_unref(wifi->device);
202         connman_rtnl_remove_watch(wifi->watch);
203
204         g_supplicant_interface_set_data(wifi->interface, NULL);
205
206         g_free(wifi->identifier);
207         g_free(wifi);
208 }
209
210 static void interface_create_callback(int result,
211                                         GSupplicantInterface *interface,
212                                                         void *user_data)
213 {
214         struct wifi_data *wifi = user_data;
215
216         DBG("result %d ifname %s, wifi %p", result,
217                                 g_supplicant_interface_get_ifname(interface),
218                                 wifi);
219
220         if (result < 0 || wifi == NULL)
221                 return;
222
223         wifi->interface = interface;
224         g_supplicant_interface_set_data(interface, wifi);
225
226         if (g_supplicant_interface_get_ready(interface) == FALSE)
227                 return;
228
229         DBG("interface is ready wifi %p tethering %d", wifi, wifi->tethering);
230
231         if (wifi->device == NULL) {
232                 connman_error("WiFi device not set");
233                 return;
234         }
235
236         connman_device_set_powered(wifi->device, TRUE);
237 }
238
239 static void interface_remove_callback(int result,
240                                         GSupplicantInterface *interface,
241                                                         void *user_data)
242 {
243         struct wifi_data *wifi;
244
245         wifi = g_supplicant_interface_get_data(interface);
246
247         DBG("result %d wifi %p", result, wifi);
248
249         if (result < 0 || wifi == NULL)
250                 return;
251
252         wifi->interface = NULL;
253 }
254
255
256 static int wifi_enable(struct connman_device *device)
257 {
258         struct wifi_data *wifi = connman_device_get_data(device);
259         const char *interface = connman_device_get_string(device, "Interface");
260         const char *driver = connman_option_get_string("wifi");
261         int ret;
262
263         DBG("device %p %p", device, wifi);
264
265         ret = g_supplicant_interface_create(interface, driver, NULL,
266                                                 interface_create_callback,
267                                                         wifi);
268         if (ret < 0)
269                 return ret;
270
271         return -EINPROGRESS;
272 }
273
274 static int wifi_disable(struct connman_device *device)
275 {
276         struct wifi_data *wifi = connman_device_get_data(device);
277         int ret;
278
279         DBG("device %p", device);
280
281         wifi->connected = FALSE;
282         wifi->disconnecting = FALSE;
283
284         if (wifi->pending_network != NULL)
285                 wifi->pending_network = NULL;
286
287         remove_networks(device, wifi);
288
289         ret = g_supplicant_interface_remove(wifi->interface,
290                                                 interface_remove_callback,
291                                                 NULL);
292         if (ret < 0)
293                 return ret;
294
295         return -EINPROGRESS;
296 }
297
298 static void hidden_free(struct hidden_params *hidden)
299 {
300         if (hidden == NULL)
301                 return;
302
303         g_free(hidden->identity);
304         g_free(hidden->passphrase);
305         g_free(hidden);
306 }
307
308 static void scan_callback(int result, GSupplicantInterface *interface,
309                                                 void *user_data)
310 {
311         struct connman_device *device = user_data;
312         struct wifi_data *wifi = connman_device_get_data(device);
313
314         DBG("result %d", result);
315
316         if (wifi != NULL && wifi->hidden != NULL) {
317                 hidden_free(wifi->hidden);
318                 wifi->hidden = NULL;
319         }
320
321         if (result < 0)
322                 connman_device_reset_scanning(device);
323         else
324                 connman_device_set_scanning(device, FALSE);
325         connman_device_unref(device);
326 }
327
328 static int add_scan_param(gchar *hex_ssid, int freq,
329                         GSupplicantScanParams *scan_data,
330                         int driver_max_scan_ssids)
331 {
332         unsigned int i;
333
334         if (driver_max_scan_ssids > scan_data->num_ssids && hex_ssid != NULL) {
335                 gchar *ssid;
336                 unsigned int j = 0, hex;
337                 size_t hex_ssid_len = strlen(hex_ssid);
338
339                 ssid = g_try_malloc0(hex_ssid_len / 2);
340                 if (ssid == NULL)
341                         return -ENOMEM;
342
343                 for (i = 0; i < hex_ssid_len; i += 2) {
344                         sscanf(hex_ssid + i, "%02x", &hex);
345                         ssid[j++] = hex;
346                 }
347
348                 memcpy(scan_data->ssids[scan_data->num_ssids].ssid, ssid, j);
349                 scan_data->ssids[scan_data->num_ssids].ssid_len = j;
350                 scan_data->num_ssids++;
351
352                 g_free(ssid);
353         }
354
355         /* Don't add duplicate entries */
356         for (i = 0; i < G_SUPPLICANT_MAX_FAST_SCAN; i++) {
357                 if (scan_data->freqs[i] == 0) {
358                         scan_data->freqs[i] = freq;
359                         break;
360                 } else if (scan_data->freqs[i] == freq)
361                         break;
362         }
363
364         return 0;
365 }
366
367 struct last_connected {
368         GTimeVal modified;
369         gchar *ssid;
370         int freq;
371 };
372
373 static gint sort_entry(gconstpointer a, gconstpointer b, gpointer user_data)
374 {
375         GTimeVal *aval = (GTimeVal *)a;
376         GTimeVal *bval = (GTimeVal *)b;
377
378         /* Note that the sort order is descending */
379         if (aval->tv_sec < bval->tv_sec)
380                 return 1;
381
382         if (aval->tv_sec > bval->tv_sec)
383                 return -1;
384
385         return 0;
386 }
387
388 static void free_entry(gpointer data)
389 {
390         struct last_connected *entry = data;
391
392         g_free(entry->ssid);
393         g_free(entry);
394 }
395
396 static int get_latest_connections(int max_ssids,
397                                 GSupplicantScanParams *scan_data)
398 {
399         GSequenceIter *iter;
400         GSequence *latest_list;
401         struct last_connected *entry;
402         GKeyFile *keyfile;
403         GTimeVal modified;
404         gchar **services;
405         gchar *str;
406         char *ssid;
407         int i, freq;
408         int num_ssids = 0;
409
410         latest_list = g_sequence_new(free_entry);
411         if (latest_list == NULL)
412                 return -ENOMEM;
413
414         services = connman_storage_get_services();
415         for (i = 0; services && services[i]; i++) {
416                 if (strncmp(services[i], "wifi_", 5) != 0)
417                         continue;
418
419                 keyfile = connman_storage_load_service(services[i]);
420
421                 str = g_key_file_get_string(keyfile,
422                                         services[i], "Favorite", NULL);
423                 if (str == NULL || g_strcmp0(str, "true")) {
424                         if (str)
425                                 g_free(str);
426                         g_key_file_free(keyfile);
427                         continue;
428                 }
429                 g_free(str);
430
431                 str = g_key_file_get_string(keyfile,
432                                         services[i], "AutoConnect", NULL);
433                 if (str == NULL || g_strcmp0(str, "true")) {
434                         if (str)
435                                 g_free(str);
436                         g_key_file_free(keyfile);
437                         continue;
438                 }
439                 g_free(str);
440
441                 str = g_key_file_get_string(keyfile,
442                                         services[i], "Modified", NULL);
443                 if (str != NULL) {
444                         g_time_val_from_iso8601(str, &modified);
445                         g_free(str);
446                 }
447
448                 ssid = g_key_file_get_string(keyfile,
449                                         services[i], "SSID", NULL);
450
451                 freq = g_key_file_get_integer(keyfile, services[i],
452                                         "Frequency", NULL);
453                 if (freq) {
454                         entry = g_try_new(struct last_connected, 1);
455                         if (entry == NULL) {
456                                 g_sequence_free(latest_list);
457                                 g_key_file_free(keyfile);
458                                 g_free(ssid);
459                                 return -ENOMEM;
460                         }
461
462                         entry->ssid = ssid;
463                         entry->modified = modified;
464                         entry->freq = freq;
465
466                         g_sequence_insert_sorted(latest_list, entry,
467                                                 sort_entry, NULL);
468                         num_ssids++;
469                 } else
470                         g_free(ssid);
471
472                 g_key_file_free(keyfile);
473         }
474
475         g_strfreev(services);
476
477         num_ssids = num_ssids > G_SUPPLICANT_MAX_FAST_SCAN ?
478                 G_SUPPLICANT_MAX_FAST_SCAN : num_ssids;
479
480         iter = g_sequence_get_begin_iter(latest_list);
481
482         for (i = 0; i < num_ssids; i++) {
483                 entry = g_sequence_get(iter);
484
485                 DBG("ssid %s freq %d modified %lu", entry->ssid, entry->freq,
486                                                 entry->modified.tv_sec);
487
488                 add_scan_param(entry->ssid, entry->freq, scan_data, max_ssids);
489
490                 iter = g_sequence_iter_next(iter);
491         }
492
493         g_sequence_free(latest_list);
494         return num_ssids;
495 }
496
497 static int wifi_scan(struct connman_device *device)
498 {
499         struct wifi_data *wifi = connman_device_get_data(device);
500         int ret;
501
502         DBG("device %p %p", device, wifi->interface);
503
504         if (wifi->tethering == TRUE)
505                 return 0;
506
507         connman_device_ref(device);
508         ret = g_supplicant_interface_scan(wifi->interface, NULL,
509                                         scan_callback, device);
510         if (ret == 0)
511                 connman_device_set_scanning(device, TRUE);
512         else
513                 connman_device_unref(device);
514
515         return ret;
516 }
517
518 static int wifi_scan_fast(struct connman_device *device)
519 {
520         struct wifi_data *wifi = connman_device_get_data(device);
521         GSupplicantScanParams *scan_params = NULL;
522         int ret;
523         int driver_max_ssids = 0;
524
525         DBG("device %p %p", device, wifi->interface);
526
527         if (wifi->tethering == TRUE)
528                 return 0;
529
530         driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
531                                                         wifi->interface);
532         DBG("max ssids %d", driver_max_ssids);
533         if (driver_max_ssids == 0)
534                 return wifi_scan(device);
535
536         scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
537         if (scan_params == NULL)
538                 return -ENOMEM;
539
540         ret = get_latest_connections(driver_max_ssids, scan_params);
541         if (ret <= 0) {
542                 g_free(scan_params);
543                 return wifi_scan(device);
544         }
545
546         connman_device_ref(device);
547         ret = g_supplicant_interface_scan(wifi->interface, scan_params,
548                                                 scan_callback, device);
549         if (ret == 0)
550                 connman_device_set_scanning(device, TRUE);
551         else {
552                 g_free(scan_params);
553                 connman_device_unref(device);
554         }
555
556         return ret;
557 }
558
559 static int wifi_scan_hidden(struct connman_device *device,
560                 const char *ssid, unsigned int ssid_len,
561                 const char *identity, const char* passphrase)
562 {
563         struct wifi_data *wifi = connman_device_get_data(device);
564         GSupplicantScanParams *scan_params = NULL;
565         struct hidden_params *hidden;
566         int ret;
567
568         DBG("hidden SSID %s", ssid);
569
570         if (wifi->tethering == TRUE || wifi->hidden != NULL)
571                 return -EBUSY;
572
573         if (ssid == NULL || ssid_len == 0 || ssid_len > 32)
574                 return -EINVAL;
575
576         scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
577         if (scan_params == NULL)
578                 return -ENOMEM;
579         memcpy(scan_params->ssids[0].ssid, ssid, ssid_len);
580         scan_params->ssids[0].ssid_len = ssid_len;
581         scan_params->num_ssids = 1;
582
583         hidden = g_try_new0(struct hidden_params, 1);
584         if (hidden == NULL) {
585                 g_free(scan_params);
586                 return -ENOMEM;
587         }
588         memcpy(hidden->ssid, ssid, ssid_len);
589         hidden->ssid_len = ssid_len;
590         hidden->identity = g_strdup(identity);
591         hidden->passphrase = g_strdup(passphrase);
592         wifi->hidden = hidden;
593
594         connman_device_ref(device);
595         ret = g_supplicant_interface_scan(wifi->interface, scan_params,
596                         scan_callback, device);
597         if (ret == 0)
598                 connman_device_set_scanning(device, TRUE);
599         else {
600                 connman_device_unref(device);
601                 g_free(scan_params);
602                 hidden_free(wifi->hidden);
603                 wifi->hidden = NULL;
604         }
605
606         return ret;
607 }
608
609 static struct connman_device_driver wifi_ng_driver = {
610         .name           = "wifi",
611         .type           = CONNMAN_DEVICE_TYPE_WIFI,
612         .priority       = CONNMAN_DEVICE_PRIORITY_LOW,
613         .probe          = wifi_probe,
614         .remove         = wifi_remove,
615         .enable         = wifi_enable,
616         .disable        = wifi_disable,
617         .scan           = wifi_scan,
618         .scan_fast      = wifi_scan_fast,
619         .scan_hidden    = wifi_scan_hidden,
620 };
621
622 static void system_ready(void)
623 {
624         DBG("");
625
626         if (connman_device_driver_register(&wifi_ng_driver) < 0)
627                 connman_error("Failed to register WiFi driver");
628 }
629
630 static void system_killed(void)
631 {
632         DBG("");
633
634         connman_device_driver_unregister(&wifi_ng_driver);
635 }
636
637 static int network_probe(struct connman_network *network)
638 {
639         DBG("network %p", network);
640
641         return 0;
642 }
643
644 static void network_remove(struct connman_network *network)
645 {
646         struct connman_device *device = connman_network_get_device(network);
647         struct wifi_data *wifi;
648
649         DBG("network %p", network);
650
651         wifi = connman_device_get_data(device);
652         if (wifi == NULL)
653                 return;
654
655         if (wifi->network != network)
656                 return;
657
658         wifi->network = NULL;
659 }
660
661 static void connect_callback(int result, GSupplicantInterface *interface,
662                                                         void *user_data)
663 {
664         struct connman_network *network = user_data;
665
666         DBG("network %p result %d", network, result);
667
668         if (result == -ENOKEY) {
669                 connman_network_set_error(network,
670                                         CONNMAN_NETWORK_ERROR_INVALID_KEY);
671         } else if (result < 0) {
672                 connman_network_set_error(network,
673                                         CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
674         }
675 }
676
677 static GSupplicantSecurity network_security(const char *security)
678 {
679         if (g_str_equal(security, "none") == TRUE)
680                 return G_SUPPLICANT_SECURITY_NONE;
681         else if (g_str_equal(security, "wep") == TRUE)
682                 return G_SUPPLICANT_SECURITY_WEP;
683         else if (g_str_equal(security, "psk") == TRUE)
684                 return G_SUPPLICANT_SECURITY_PSK;
685         else if (g_str_equal(security, "wpa") == TRUE)
686                 return G_SUPPLICANT_SECURITY_PSK;
687         else if (g_str_equal(security, "rsn") == TRUE)
688                 return G_SUPPLICANT_SECURITY_PSK;
689         else if (g_str_equal(security, "ieee8021x") == TRUE)
690                 return G_SUPPLICANT_SECURITY_IEEE8021X;
691
692         return G_SUPPLICANT_SECURITY_UNKNOWN;
693 }
694
695 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
696 {
697         const char *security, *passphrase, *agent_passphrase;
698
699         memset(ssid, 0, sizeof(*ssid));
700         ssid->mode = G_SUPPLICANT_MODE_INFRA;
701         ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
702                                                 &ssid->ssid_len);
703         ssid->scan_ssid = 1;
704         security = connman_network_get_string(network, "WiFi.Security");
705         ssid->security = network_security(security);
706         passphrase = connman_network_get_string(network,
707                                                 "WiFi.Passphrase");
708         if (passphrase == NULL || strlen(passphrase) == 0) {
709
710                 /* Use agent provided passphrase as a fallback */
711                 agent_passphrase = connman_network_get_string(network,
712                                                 "WiFi.AgentPassphrase");
713
714                 if (agent_passphrase == NULL || strlen(agent_passphrase) == 0)
715                         ssid->passphrase = NULL;
716                 else
717                         ssid->passphrase = agent_passphrase;
718         } else
719                 ssid->passphrase = passphrase;
720
721         ssid->eap = connman_network_get_string(network, "WiFi.EAP");
722
723         /*
724          * If our private key password is unset,
725          * we use the supplied passphrase. That is needed
726          * for PEAP where 2 passphrases (identity and client
727          * cert may have to be provided.
728          */
729         if (connman_network_get_string(network,
730                                         "WiFi.PrivateKeyPassphrase") == NULL)
731                 connman_network_set_string(network,
732                                                 "WiFi.PrivateKeyPassphrase",
733                                                 ssid->passphrase);
734         /* We must have an identity for both PEAP and TLS */
735         ssid->identity = connman_network_get_string(network, "WiFi.Identity");
736
737         /* Use agent provided identity as a fallback */
738         if (ssid->identity == NULL || strlen(ssid->identity) == 0)
739                 ssid->identity = connman_network_get_string(network,
740                                                         "WiFi.AgentIdentity");
741
742         ssid->ca_cert_path = connman_network_get_string(network,
743                                                         "WiFi.CACertFile");
744         ssid->client_cert_path = connman_network_get_string(network,
745                                                         "WiFi.ClientCertFile");
746         ssid->private_key_path = connman_network_get_string(network,
747                                                         "WiFi.PrivateKeyFile");
748         ssid->private_key_passphrase = connman_network_get_string(network,
749                                                 "WiFi.PrivateKeyPassphrase");
750         ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
751
752         ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
753         ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
754
755 }
756
757 static int network_connect(struct connman_network *network)
758 {
759         struct connman_device *device = connman_network_get_device(network);
760         struct wifi_data *wifi;
761         GSupplicantInterface *interface;
762         GSupplicantSSID *ssid;
763
764         DBG("network %p", network);
765
766         if (device == NULL)
767                 return -ENODEV;
768
769         wifi = connman_device_get_data(device);
770         if (wifi == NULL)
771                 return -ENODEV;
772
773         ssid = g_try_malloc0(sizeof(GSupplicantSSID));
774         if (ssid == NULL)
775                 return -ENOMEM;
776
777         interface = wifi->interface;
778
779         ssid_init(ssid, network);
780
781         if (wifi->disconnecting == TRUE)
782                 wifi->pending_network = network;
783         else {
784                 wifi->network = network;
785                 wifi->retries = 0;
786
787                 return g_supplicant_interface_connect(interface, ssid,
788                                                 connect_callback, network);
789         }
790
791         return -EINPROGRESS;
792 }
793
794 static void disconnect_callback(int result, GSupplicantInterface *interface,
795                                                                 void *user_data)
796 {
797         struct wifi_data *wifi = user_data;
798
799         if (wifi->network != NULL) {
800                 /*
801                  * if result < 0 supplican return an error because
802                  * the network is not current.
803                  * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
804                  * failed, call connman_network_set_connected to report
805                  * disconnect is completed.
806                  */
807                 if (result < 0)
808                         connman_network_set_connected(wifi->network, FALSE);
809         }
810
811         wifi->network = NULL;
812
813         wifi->disconnecting = FALSE;
814
815         if (wifi->pending_network != NULL) {
816                 network_connect(wifi->pending_network);
817                 wifi->pending_network = NULL;
818         }
819
820 }
821
822 static int network_disconnect(struct connman_network *network)
823 {
824         struct connman_device *device = connman_network_get_device(network);
825         struct wifi_data *wifi;
826         int err;
827
828         DBG("network %p", network);
829
830         wifi = connman_device_get_data(device);
831         if (wifi == NULL || wifi->interface == NULL)
832                 return -ENODEV;
833
834         connman_network_set_associating(network, FALSE);
835
836         if (wifi->disconnecting == TRUE)
837                 return -EALREADY;
838
839         wifi->disconnecting = TRUE;
840
841         err = g_supplicant_interface_disconnect(wifi->interface,
842                                                 disconnect_callback, wifi);
843         if (err < 0)
844                 wifi->disconnecting = FALSE;
845
846         return err;
847 }
848
849 static struct connman_network_driver network_driver = {
850         .name           = "wifi",
851         .type           = CONNMAN_NETWORK_TYPE_WIFI,
852         .priority       = CONNMAN_NETWORK_PRIORITY_LOW,
853         .probe          = network_probe,
854         .remove         = network_remove,
855         .connect        = network_connect,
856         .disconnect     = network_disconnect,
857 };
858
859 static void interface_added(GSupplicantInterface *interface)
860 {
861         const char *ifname = g_supplicant_interface_get_ifname(interface);
862         const char *driver = g_supplicant_interface_get_driver(interface);
863         struct wifi_data *wifi;
864
865         wifi = g_supplicant_interface_get_data(interface);
866
867         /*
868          * We can get here with a NULL wifi pointer when
869          * the interface added signal is sent before the
870          * interface creation callback is called.
871          */
872         if (wifi == NULL)
873                 return;
874
875         DBG("ifname %s driver %s wifi %p tethering %d",
876                         ifname, driver, wifi, wifi->tethering);
877
878         if (wifi->device == NULL) {
879                 connman_error("WiFi device not set");
880                 return;
881         }
882
883         connman_device_set_powered(wifi->device, TRUE);
884
885         if (wifi->tethering == TRUE)
886                 return;
887 }
888
889 static connman_bool_t is_idle(struct wifi_data *wifi)
890 {
891         DBG("state %d", wifi->state);
892
893         switch (wifi->state) {
894         case G_SUPPLICANT_STATE_UNKNOWN:
895         case G_SUPPLICANT_STATE_DISCONNECTED:
896         case G_SUPPLICANT_STATE_INACTIVE:
897         case G_SUPPLICANT_STATE_SCANNING:
898                 return TRUE;
899
900         case G_SUPPLICANT_STATE_AUTHENTICATING:
901         case G_SUPPLICANT_STATE_ASSOCIATING:
902         case G_SUPPLICANT_STATE_ASSOCIATED:
903         case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
904         case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
905         case G_SUPPLICANT_STATE_COMPLETED:
906                 return FALSE;
907         }
908
909         return FALSE;
910 }
911
912 static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
913                                                 struct wifi_data *wifi)
914 {
915         /* First, let's check if WPS processing did not went wrong */
916         if (g_supplicant_interface_get_wps_state(interface) ==
917                 G_SUPPLICANT_WPS_STATE_FAIL)
918                 return FALSE;
919
920         /* Unlike normal connection, being associated while processing wps
921          * actually means that we are idling. */
922         switch (wifi->state) {
923         case G_SUPPLICANT_STATE_UNKNOWN:
924         case G_SUPPLICANT_STATE_DISCONNECTED:
925         case G_SUPPLICANT_STATE_INACTIVE:
926         case G_SUPPLICANT_STATE_SCANNING:
927         case G_SUPPLICANT_STATE_ASSOCIATED:
928                 return TRUE;
929         case G_SUPPLICANT_STATE_AUTHENTICATING:
930         case G_SUPPLICANT_STATE_ASSOCIATING:
931         case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
932         case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
933         case G_SUPPLICANT_STATE_COMPLETED:
934                 return FALSE;
935         }
936
937         return FALSE;
938 }
939
940 static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
941                                         struct connman_network *network,
942                                         struct connman_device *device,
943                                         struct wifi_data *wifi)
944 {
945         connman_bool_t wps;
946
947         wps = connman_network_get_bool(network, "WiFi.UseWPS");
948         if (wps == TRUE) {
949                 const unsigned char *ssid, *wps_ssid;
950                 unsigned int ssid_len, wps_ssid_len;
951                 const char *wps_key;
952
953                 /* Checking if we got associated with requested
954                  * network */
955                 ssid = connman_network_get_blob(network, "WiFi.SSID",
956                                                 &ssid_len);
957
958                 wps_ssid = g_supplicant_interface_get_wps_ssid(
959                         interface, &wps_ssid_len);
960
961                 if (wps_ssid == NULL || wps_ssid_len != ssid_len ||
962                                 memcmp(ssid, wps_ssid, ssid_len) != 0) {
963                         connman_network_set_associating(network, FALSE);
964                         g_supplicant_interface_disconnect(wifi->interface,
965                                                 disconnect_callback, wifi);
966                         return FALSE;
967                 }
968
969                 wps_key = g_supplicant_interface_get_wps_key(interface);
970                 connman_network_set_string(network, "WiFi.Passphrase",
971                                         wps_key);
972
973                 connman_network_set_string(network, "WiFi.PinWPS", NULL);
974         }
975
976         return TRUE;
977 }
978
979 static connman_bool_t handle_4way_handshake_failure(GSupplicantInterface *interface,
980                                         struct connman_network *network,
981                                         struct wifi_data *wifi)
982 {
983         if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
984                 return FALSE;
985
986         wifi->retries++;
987
988         if (wifi->retries < MAXIMUM_RETRIES)
989                 return TRUE;
990
991         connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
992
993         return FALSE;
994 }
995
996 static void interface_state(GSupplicantInterface *interface)
997 {
998         struct connman_network *network;
999         struct connman_device *device;
1000         struct wifi_data *wifi;
1001         GSupplicantState state = g_supplicant_interface_get_state(interface);
1002         connman_bool_t wps;
1003
1004         wifi = g_supplicant_interface_get_data(interface);
1005
1006         DBG("wifi %p interface state %d", wifi, state);
1007
1008         if (wifi == NULL)
1009                 return;
1010
1011         network = wifi->network;
1012         device = wifi->device;
1013
1014         if (device == NULL || network == NULL)
1015                 return;
1016
1017         switch (state) {
1018         case G_SUPPLICANT_STATE_SCANNING:
1019                 break;
1020
1021         case G_SUPPLICANT_STATE_AUTHENTICATING:
1022         case G_SUPPLICANT_STATE_ASSOCIATING:
1023                 connman_network_set_associating(network, TRUE);
1024                 break;
1025
1026         case G_SUPPLICANT_STATE_COMPLETED:
1027                 if (handle_wps_completion(interface, network, device, wifi) ==
1028                                                                         FALSE)
1029                         break;
1030
1031                 /* reset scan trigger and schedule background scan */
1032                 connman_device_schedule_scan(device);
1033
1034                 connman_network_set_connected(network, TRUE);
1035                 break;
1036
1037         case G_SUPPLICANT_STATE_DISCONNECTED:
1038                 /*
1039                  * If we're in one of the idle modes, we have
1040                  * not started association yet and thus setting
1041                  * those ones to FALSE could cancel an association
1042                  * in progress.
1043                  */
1044                 wps = connman_network_get_bool(network, "WiFi.UseWPS");
1045                 if (wps == TRUE)
1046                         if (is_idle_wps(interface, wifi) == TRUE)
1047                                 break;
1048
1049                 if (is_idle(wifi))
1050                         break;
1051
1052                 /* If previous state was 4way-handshake, then
1053                  * it's either: psk was incorrect and thus we retry
1054                  * or if we reach the maximum retries we declare the
1055                  * psk as wrong */
1056                 if (handle_4way_handshake_failure(interface,
1057                                                 network, wifi) == TRUE)
1058                         break;
1059
1060                 /* We disable the selected network, if not then
1061                  * wpa_supplicant will loop retrying */
1062                 if (g_supplicant_interface_enable_selected_network(interface,
1063                                                 FALSE) != 0)
1064                         DBG("Could not disables selected network");
1065
1066                 connman_network_set_associating(network, FALSE);
1067                 connman_network_set_connected(network, FALSE);
1068                 break;
1069
1070         case G_SUPPLICANT_STATE_INACTIVE:
1071                 connman_network_set_associating(network, FALSE);
1072                 break;
1073
1074         case G_SUPPLICANT_STATE_UNKNOWN:
1075         case G_SUPPLICANT_STATE_ASSOCIATED:
1076         case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
1077         case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
1078                 break;
1079         }
1080
1081         wifi->state = state;
1082
1083         DBG("DONE");
1084 }
1085
1086 static void interface_removed(GSupplicantInterface *interface)
1087 {
1088         const char *ifname = g_supplicant_interface_get_ifname(interface);
1089         struct wifi_data *wifi;
1090
1091         DBG("ifname %s", ifname);
1092
1093         wifi = g_supplicant_interface_get_data(interface);
1094
1095         if (wifi != NULL && wifi->tethering == TRUE)
1096                 return;
1097
1098         if (wifi == NULL || wifi->device == NULL) {
1099                 connman_error("Wrong wifi pointer");
1100                 return;
1101         }
1102
1103         connman_device_set_powered(wifi->device, FALSE);
1104 }
1105
1106 static void scan_started(GSupplicantInterface *interface)
1107 {
1108         DBG("");
1109 }
1110
1111 static void scan_finished(GSupplicantInterface *interface)
1112 {
1113         DBG("");
1114 }
1115
1116 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
1117 {
1118         unsigned char strength;
1119
1120         strength = 120 + g_supplicant_network_get_signal(supplicant_network);
1121         if (strength > 100)
1122                 strength = 100;
1123
1124         return strength;
1125 }
1126
1127 static void network_added(GSupplicantNetwork *supplicant_network)
1128 {
1129         struct connman_network *network;
1130         GSupplicantInterface *interface;
1131         struct wifi_data *wifi;
1132         const char *name, *identifier, *security, *group;
1133         const unsigned char *ssid;
1134         unsigned int ssid_len;
1135         connman_bool_t wps;
1136
1137         DBG("");
1138
1139         interface = g_supplicant_network_get_interface(supplicant_network);
1140         wifi = g_supplicant_interface_get_data(interface);
1141         name = g_supplicant_network_get_name(supplicant_network);
1142         identifier = g_supplicant_network_get_identifier(supplicant_network);
1143         security = g_supplicant_network_get_security(supplicant_network);
1144         group = g_supplicant_network_get_identifier(supplicant_network);
1145         wps = g_supplicant_network_get_wps(supplicant_network);
1146
1147         if (wifi == NULL)
1148                 return;
1149
1150         ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
1151
1152         network = connman_device_get_network(wifi->device, identifier);
1153
1154         if (network == NULL) {
1155                 network = connman_network_create(identifier,
1156                                                 CONNMAN_NETWORK_TYPE_WIFI);
1157                 if (network == NULL)
1158                         return;
1159
1160                 connman_network_set_index(network, wifi->index);
1161
1162                 if (connman_device_add_network(wifi->device, network) < 0) {
1163                         connman_network_unref(network);
1164                         return;
1165                 }
1166
1167                 wifi->networks = g_slist_append(wifi->networks, network);
1168         }
1169
1170         if (name != NULL && name[0] != '\0')
1171                 connman_network_set_name(network, name);
1172
1173         connman_network_set_blob(network, "WiFi.SSID",
1174                                                 ssid, ssid_len);
1175         connman_network_set_string(network, "WiFi.Security", security);
1176         connman_network_set_strength(network,
1177                                 calculate_strength(supplicant_network));
1178         connman_network_set_bool(network, "WiFi.WPS", wps);
1179
1180         connman_network_set_frequency(network,
1181                         g_supplicant_network_get_frequency(supplicant_network));
1182
1183         connman_network_set_available(network, TRUE);
1184
1185         if (ssid != NULL)
1186                 connman_network_set_group(network, group);
1187
1188         if (wifi->hidden != NULL) {
1189                 if (wifi->hidden->ssid_len == ssid_len &&
1190                                 memcmp(wifi->hidden->ssid, ssid,
1191                                                 ssid_len) == 0) {
1192                         connman_network_connect_hidden(network,
1193                                         wifi->hidden->identity,
1194                                         wifi->hidden->passphrase);
1195                         hidden_free(wifi->hidden);
1196                         wifi->hidden = NULL;
1197                 }
1198         }
1199 }
1200
1201 static void network_removed(GSupplicantNetwork *network)
1202 {
1203         GSupplicantInterface *interface;
1204         struct wifi_data *wifi;
1205         const char *name, *identifier;
1206         struct connman_network *connman_network;
1207
1208         interface = g_supplicant_network_get_interface(network);
1209         wifi = g_supplicant_interface_get_data(interface);
1210         identifier = g_supplicant_network_get_identifier(network);
1211         name = g_supplicant_network_get_name(network);
1212
1213         DBG("name %s", name);
1214
1215         if (wifi == NULL)
1216                 return;
1217
1218         connman_network = connman_device_get_network(wifi->device, identifier);
1219         if (connman_network == NULL)
1220                 return;
1221
1222         wifi->networks = g_slist_remove(wifi->networks, connman_network);
1223
1224         connman_device_remove_network(wifi->device, connman_network);
1225         connman_network_unref(connman_network);
1226 }
1227
1228 static void network_changed(GSupplicantNetwork *network, const char *property)
1229 {
1230         GSupplicantInterface *interface;
1231         struct wifi_data *wifi;
1232         const char *name, *identifier;
1233         struct connman_network *connman_network;
1234
1235         interface = g_supplicant_network_get_interface(network);
1236         wifi = g_supplicant_interface_get_data(interface);
1237         identifier = g_supplicant_network_get_identifier(network);
1238         name = g_supplicant_network_get_name(network);
1239
1240         DBG("name %s", name);
1241
1242         if (wifi == NULL)
1243                 return;
1244
1245         connman_network = connman_device_get_network(wifi->device, identifier);
1246         if (connman_network == NULL)
1247                 return;
1248
1249         if (g_str_equal(property, "Signal") == TRUE) {
1250                connman_network_set_strength(connman_network,
1251                                         calculate_strength(network));
1252                connman_network_update(connman_network);
1253         }
1254 }
1255
1256 static void debug(const char *str)
1257 {
1258         if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
1259                 connman_debug("%s", str);
1260 }
1261
1262 static const GSupplicantCallbacks callbacks = {
1263         .system_ready           = system_ready,
1264         .system_killed          = system_killed,
1265         .interface_added        = interface_added,
1266         .interface_state        = interface_state,
1267         .interface_removed      = interface_removed,
1268         .scan_started           = scan_started,
1269         .scan_finished          = scan_finished,
1270         .network_added          = network_added,
1271         .network_removed        = network_removed,
1272         .network_changed        = network_changed,
1273         .debug                  = debug,
1274 };
1275
1276
1277 static int tech_probe(struct connman_technology *technology)
1278 {
1279         wifi_technology = technology;
1280
1281         return 0;
1282 }
1283
1284 static void tech_remove(struct connman_technology *technology)
1285 {
1286         wifi_technology = NULL;
1287 }
1288
1289 struct wifi_tethering_info {
1290         struct wifi_data *wifi;
1291         struct connman_technology *technology;
1292         char *ifname;
1293         GSupplicantSSID *ssid;
1294 };
1295
1296 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
1297 {
1298         GSupplicantSSID *ap;
1299
1300         ap = g_try_malloc0(sizeof(GSupplicantSSID));
1301         if (ap == NULL)
1302                 return NULL;
1303
1304         ap->mode = G_SUPPLICANT_MODE_MASTER;
1305         ap->ssid = ssid;
1306         ap->ssid_len = strlen(ssid);
1307         ap->scan_ssid = 0;
1308         ap->freq = 2412;
1309
1310         if (passphrase == NULL || strlen(passphrase) == 0) {
1311                 ap->security = G_SUPPLICANT_SECURITY_NONE;
1312                 ap->passphrase = NULL;
1313         } else {
1314                ap->security = G_SUPPLICANT_SECURITY_PSK;
1315                ap->protocol = G_SUPPLICANT_PROTO_RSN;
1316                ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
1317                ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
1318                ap->passphrase = passphrase;
1319         }
1320
1321         return ap;
1322 }
1323
1324 static void ap_start_callback(int result, GSupplicantInterface *interface,
1325                                                         void *user_data)
1326 {
1327         struct wifi_tethering_info *info = user_data;
1328
1329         DBG("result %d index %d bridge %s",
1330                 result, info->wifi->index, info->wifi->bridge);
1331
1332         if (result < 0) {
1333                 connman_inet_remove_from_bridge(info->wifi->index,
1334                                                         info->wifi->bridge);
1335                 connman_technology_tethering_notify(info->technology, FALSE);
1336         }
1337
1338         g_free(info->ifname);
1339         g_free(info);
1340 }
1341
1342 static void ap_create_callback(int result,
1343                                 GSupplicantInterface *interface,
1344                                         void *user_data)
1345 {
1346         struct wifi_tethering_info *info = user_data;
1347
1348         DBG("result %d ifname %s", result,
1349                                 g_supplicant_interface_get_ifname(interface));
1350
1351         if (result < 0) {
1352                 connman_inet_remove_from_bridge(info->wifi->index,
1353                                                         info->wifi->bridge);
1354                 connman_technology_tethering_notify(info->technology, FALSE);
1355
1356                 g_free(info->ifname);
1357                 g_free(info);
1358                 return;
1359         }
1360
1361         info->wifi->interface = interface;
1362         g_supplicant_interface_set_data(interface, info->wifi);
1363
1364         if (g_supplicant_interface_set_apscan(interface, 2) < 0)
1365                 connman_error("Failed to set interface ap_scan property");
1366
1367         g_supplicant_interface_connect(interface, info->ssid,
1368                                                 ap_start_callback, info);
1369 }
1370
1371 static void sta_remove_callback(int result,
1372                                 GSupplicantInterface *interface,
1373                                         void *user_data)
1374 {
1375         struct wifi_tethering_info *info = user_data;
1376         const char *driver = connman_option_get_string("wifi");
1377
1378         DBG("ifname %s result %d ", info->ifname, result);
1379
1380         if (result < 0) {
1381                 info->wifi->tethering = TRUE;
1382
1383                 g_free(info->ifname);
1384                 g_free(info);
1385                 return;
1386         }
1387
1388         info->wifi->interface = NULL;
1389
1390         connman_technology_tethering_notify(info->technology, TRUE);
1391
1392         g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
1393                                                 ap_create_callback,
1394                                                         info);
1395 }
1396
1397 static int tech_set_tethering(struct connman_technology *technology,
1398                                 const char *identifier, const char *passphrase,
1399                                 const char *bridge, connman_bool_t enabled)
1400 {
1401         GList *list;
1402         GSupplicantInterface *interface;
1403         struct wifi_data *wifi;
1404         struct wifi_tethering_info *info;
1405         const char *ifname;
1406         unsigned int mode;
1407         int err;
1408
1409         DBG("");
1410
1411         if (enabled == FALSE) {
1412                 for (list = iface_list; list; list = list->next) {
1413                         wifi = list->data;
1414
1415                         if (wifi->tethering == TRUE) {
1416                                 wifi->tethering = FALSE;
1417
1418                                 connman_inet_remove_from_bridge(wifi->index,
1419                                                                         bridge);
1420                                 wifi->bridged = FALSE;
1421                         }
1422                 }
1423
1424                 connman_technology_tethering_notify(technology, FALSE);
1425
1426                 return 0;
1427         }
1428
1429         for (list = iface_list; list; list = list->next) {
1430                 wifi = list->data;
1431
1432                 interface = wifi->interface;
1433
1434                 if (interface == NULL)
1435                         continue;
1436
1437                 ifname = g_supplicant_interface_get_ifname(wifi->interface);
1438
1439                 mode = g_supplicant_interface_get_mode(interface);
1440                 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
1441                         DBG("%s does not support AP mode", ifname);
1442                         continue;
1443                 }
1444
1445                 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
1446                 if (info == NULL)
1447                         return -ENOMEM;
1448
1449                 info->wifi = wifi;
1450                 info->technology = technology;
1451                 info->wifi->bridge = bridge;
1452                 info->ssid = ssid_ap_init(identifier, passphrase);
1453                 if (info->ssid == NULL) {
1454                         g_free(info);
1455                         continue;
1456                 }
1457                 info->ifname = g_strdup(ifname);
1458                 if (info->ifname == NULL) {
1459                         g_free(info);
1460                         continue;
1461                 }
1462
1463                 info->wifi->tethering = TRUE;
1464
1465                 err = g_supplicant_interface_remove(interface,
1466                                                 sta_remove_callback,
1467                                                         info);
1468                 if (err == 0)
1469                         return err;
1470         }
1471
1472         return -EOPNOTSUPP;
1473 }
1474
1475 static void regdom_callback(void *user_data)
1476 {
1477         char *alpha2 = user_data;
1478
1479         DBG("");
1480
1481         if (wifi_technology == NULL)
1482                 return;
1483
1484         connman_technology_regdom_notify(wifi_technology, alpha2);
1485 }
1486
1487 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
1488 {
1489         return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
1490 }
1491
1492 static struct connman_technology_driver tech_driver = {
1493         .name           = "wifi",
1494         .type           = CONNMAN_SERVICE_TYPE_WIFI,
1495         .probe          = tech_probe,
1496         .remove         = tech_remove,
1497         .set_tethering  = tech_set_tethering,
1498         .set_regdom     = tech_set_regdom,
1499 };
1500
1501 static int wifi_init(void)
1502 {
1503         int err;
1504
1505         err = connman_network_driver_register(&network_driver);
1506         if (err < 0)
1507                 return err;
1508
1509         err = g_supplicant_register(&callbacks);
1510         if (err < 0) {
1511                 connman_network_driver_unregister(&network_driver);
1512                 return err;
1513         }
1514
1515         err = connman_technology_driver_register(&tech_driver);
1516         if (err < 0) {
1517                 g_supplicant_unregister(&callbacks);
1518                 connman_network_driver_unregister(&network_driver);
1519                 return err;
1520         }
1521
1522         return 0;
1523 }
1524
1525 static void wifi_exit(void)
1526 {
1527         DBG();
1528
1529         connman_technology_driver_unregister(&tech_driver);
1530
1531         g_supplicant_unregister(&callbacks);
1532
1533         connman_network_driver_unregister(&network_driver);
1534 }
1535
1536 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
1537                 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)