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