wifi: Balance scanning states
[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 <string.h>
30 #include <sys/ioctl.h>
31 #include <sys/socket.h>
32 #include <linux/if_arp.h>
33 #include <linux/wireless.h>
34 #include <net/ethernet.h>
35
36 #ifndef IFF_LOWER_UP
37 #define IFF_LOWER_UP    0x10000
38 #endif
39
40 #include <dbus/dbus.h>
41 #include <glib.h>
42
43 #define CONNMAN_API_SUBJECT_TO_CHANGE
44 #include <connman/plugin.h>
45 #include <connman/inet.h>
46 #include <connman/device.h>
47 #include <connman/rtnl.h>
48 #include <connman/technology.h>
49 #include <connman/log.h>
50 #include <connman/option.h>
51
52 #include <gsupplicant/gsupplicant.h>
53
54 #define CLEANUP_TIMEOUT   8     /* in seconds */
55 #define INACTIVE_TIMEOUT  12    /* in seconds */
56
57 struct connman_technology *wifi_technology = NULL;
58
59 struct wifi_data {
60         char *identifier;
61         struct connman_device *device;
62         struct connman_network *network;
63         struct connman_network *pending_network;
64         GSupplicantInterface *interface;
65         GSupplicantState state;
66         connman_bool_t connected;
67         connman_bool_t disconnecting;
68         int index;
69         unsigned flags;
70         unsigned int watch;
71 };
72
73 static int get_bssid(struct connman_device *device,
74                                 unsigned char *bssid, unsigned int *bssid_len)
75 {
76         struct iwreq wrq;
77         char *ifname;
78         int ifindex;
79         int fd, err;
80
81         ifindex = connman_device_get_index(device);
82         if (ifindex < 0)
83                 return -EINVAL;
84
85         ifname = connman_inet_ifname(ifindex);
86         if (ifname == NULL)
87                 return -EINVAL;
88
89         fd = socket(PF_INET, SOCK_DGRAM, 0);
90         if (fd < 0) {
91                 g_free(ifname);
92                 return -EINVAL;
93         }
94
95         memset(&wrq, 0, sizeof(wrq));
96         strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
97
98         err = ioctl(fd, SIOCGIWAP, &wrq);
99
100         g_free(ifname);
101         close(fd);
102
103         if (err < 0)
104                 return -EIO;
105
106         memcpy(bssid, wrq.u.ap_addr.sa_data, ETH_ALEN);
107         *bssid_len = ETH_ALEN;
108
109         return 0;
110 }
111
112 static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
113 {
114         struct connman_device *device = user_data;
115         struct wifi_data *wifi = connman_device_get_data(device);
116
117         DBG("index %d flags %d change %d", wifi->index, flags, change);
118
119         if (!change)
120                 return;
121
122         if ((wifi->flags & IFF_UP) != (flags & IFF_UP)) {
123                 if (flags & IFF_UP)
124                         DBG("interface up");
125                 else
126                         DBG("interface down");
127         }
128
129         if ((wifi->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
130                 if (flags & IFF_LOWER_UP)
131                         DBG("carrier on");
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->state = G_SUPPLICANT_STATE_INACTIVE;
152
153         connman_device_set_data(device, wifi);
154         wifi->device = connman_device_ref(device);
155
156         wifi->index = connman_device_get_index(device);
157         wifi->flags = 0;
158
159         wifi->watch = connman_rtnl_add_newlink_watch(wifi->index,
160                                                         wifi_newlink, device);
161
162         return 0;
163 }
164
165 static void wifi_remove(struct connman_device *device)
166 {
167         struct wifi_data *wifi = connman_device_get_data(device);
168
169         DBG("device %p", device);
170
171         if (wifi->pending_network != NULL) {
172                 connman_network_unref(wifi->pending_network);
173                 wifi->pending_network = NULL;
174         }
175
176         connman_device_set_data(device, NULL);
177         connman_device_unref(wifi->device);
178         connman_rtnl_remove_watch(wifi->watch);
179
180         g_supplicant_interface_set_data(wifi->interface, NULL);
181
182         g_free(wifi->identifier);
183         g_free(wifi);
184 }
185
186 static void interface_create_callback(int result,
187                                         GSupplicantInterface *interface,
188                                                         void *user_data)
189 {
190         struct wifi_data *wifi = user_data;
191
192         DBG("result %d ifname %s", result,
193                                 g_supplicant_interface_get_ifname(interface));
194
195         if (result < 0)
196                 return;
197
198         wifi->interface = interface;
199         g_supplicant_interface_set_data(interface, wifi);
200 }
201
202 static void interface_remove_callback(int result,
203                                         GSupplicantInterface *interface,
204                                                         void *user_data)
205 {
206         struct wifi_data *wifi = user_data;
207
208         DBG("result %d", result);
209
210         if (result < 0)
211                 return;
212
213         wifi->interface = NULL;
214 }
215
216
217 static int wifi_enable(struct connman_device *device)
218 {
219         struct wifi_data *wifi = connman_device_get_data(device);
220         const char *interface = connman_device_get_string(device, "Interface");
221         const char *driver = connman_option_get_string("wifi");
222
223         DBG("device %p %p", device, wifi);
224
225         return g_supplicant_interface_create(interface, driver,
226                                                 interface_create_callback,
227                                                         wifi);
228 }
229
230 static int wifi_disable(struct connman_device *device)
231 {
232         struct wifi_data *wifi = connman_device_get_data(device);
233
234         DBG("device %p", device);
235
236         wifi->connected = FALSE;
237         wifi->disconnecting = FALSE;
238
239         if (wifi->pending_network != NULL) {
240                 connman_network_unref(wifi->pending_network);
241                 wifi->pending_network = NULL;
242         }
243
244         return g_supplicant_interface_remove(wifi->interface,
245                                                 interface_remove_callback,
246                                                         wifi);
247 }
248
249 static void scan_callback(int result, GSupplicantInterface *interface,
250                                                 void *user_data)
251 {
252         struct connman_device *device = user_data;
253
254         DBG("result %d", result);
255
256         if (result < 0)
257                 connman_device_reset_scanning(device);
258         else
259                 connman_device_set_scanning(device, FALSE);
260 }
261
262 static int wifi_scan(struct connman_device *device)
263 {
264         struct wifi_data *wifi = connman_device_get_data(device);
265         int ret;
266
267         DBG("device %p %p", device, wifi->interface);
268
269         ret = g_supplicant_interface_scan(wifi->interface, scan_callback,
270                                                                 device);
271         if (ret == 0)
272                 connman_device_set_scanning(device, TRUE);
273
274         return ret;
275 }
276
277 static struct connman_device_driver wifi_ng_driver = {
278         .name           = "wifi",
279         .type           = CONNMAN_DEVICE_TYPE_WIFI,
280         .priority       = CONNMAN_DEVICE_PRIORITY_LOW,
281         .probe          = wifi_probe,
282         .remove         = wifi_remove,
283         .enable         = wifi_enable,
284         .disable        = wifi_disable,
285         .scan           = wifi_scan,
286 };
287
288 static void system_ready(void)
289 {
290         DBG("");
291
292         if (connman_device_driver_register(&wifi_ng_driver) < 0)
293                 connman_error("Failed to register WiFi driver");
294 }
295
296 static void system_killed(void)
297 {
298         DBG("");
299
300         connman_device_driver_unregister(&wifi_ng_driver);
301 }
302
303 static void interface_added(GSupplicantInterface *interface)
304 {
305         const char *ifname = g_supplicant_interface_get_ifname(interface);
306         const char *driver = g_supplicant_interface_get_driver(interface);
307         struct wifi_data *wifi;
308
309         wifi = g_supplicant_interface_get_data(interface);
310
311         /*
312          * We can get here with a NULL wifi pointer when
313          * the interface added signal is sent before the
314          * interface creation callback is called.
315          */
316         if (wifi == NULL)
317                 return;
318
319         DBG("ifname %s driver %s wifi %p", ifname, driver, wifi);
320
321         if (wifi->device == NULL) {
322                 connman_error("WiFi device not set");
323                 return;
324         }
325
326         connman_device_set_powered(wifi->device, TRUE);
327         wifi_scan(wifi->device);
328 }
329
330 static connman_bool_t is_idle(struct wifi_data *wifi)
331 {
332         DBG("state %d", wifi->state);
333
334         switch (wifi->state) {
335         case G_SUPPLICANT_STATE_UNKNOWN:
336         case G_SUPPLICANT_STATE_DISCONNECTED:
337         case G_SUPPLICANT_STATE_INACTIVE:
338         case G_SUPPLICANT_STATE_SCANNING:
339                 return TRUE;
340
341         case G_SUPPLICANT_STATE_AUTHENTICATING:
342         case G_SUPPLICANT_STATE_ASSOCIATING:
343         case G_SUPPLICANT_STATE_ASSOCIATED:
344         case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
345         case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
346         case G_SUPPLICANT_STATE_COMPLETED:
347                 return FALSE;
348         }
349
350         return FALSE;
351 }
352
353 static void interface_state(GSupplicantInterface *interface)
354 {
355         struct connman_network *network;
356         struct connman_device *device;
357         struct wifi_data *wifi;
358         GSupplicantState state = g_supplicant_interface_get_state(interface);
359         unsigned char bssid[ETH_ALEN];
360         unsigned int bssid_len;
361
362         wifi = g_supplicant_interface_get_data(interface);
363
364         DBG("wifi %p interface state %d", wifi, state);
365
366         if (wifi == NULL)
367                 return;
368
369         network = wifi->network;
370         device = wifi->device;
371
372         if (device == NULL || network == NULL)
373                 return;
374
375         switch (state) {
376         case G_SUPPLICANT_STATE_SCANNING:
377                 break;
378
379         case G_SUPPLICANT_STATE_AUTHENTICATING:
380         case G_SUPPLICANT_STATE_ASSOCIATING:
381                 connman_network_set_associating(network, TRUE);
382                 break;
383
384         case G_SUPPLICANT_STATE_COMPLETED:
385                 /* reset scan trigger and schedule background scan */
386                 connman_device_schedule_scan(device);
387
388                 if (get_bssid(device, bssid, &bssid_len) == 0)
389                         connman_network_set_address(network,
390                                                         bssid, bssid_len);
391                 connman_network_set_connected(network, TRUE);
392                 break;
393
394         case G_SUPPLICANT_STATE_DISCONNECTED:
395                 /*
396                  * If we're in one of the idle modes, we have
397                  * not started association yet and thus setting
398                  * those ones to FALSE could cancel an association
399                  * in progress.
400                  */
401                 if (is_idle(wifi))
402                         break;
403                 connman_network_set_associating(network, FALSE);
404                 connman_network_set_connected(network, FALSE);
405                 break;
406
407         case G_SUPPLICANT_STATE_INACTIVE:
408                 connman_network_set_associating(network, FALSE);
409                 break;
410
411         case G_SUPPLICANT_STATE_UNKNOWN:
412         case G_SUPPLICANT_STATE_ASSOCIATED:
413         case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
414         case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
415                 break;
416         }
417
418         wifi->state = state;
419
420         DBG("DONE");
421 }
422
423 static void interface_removed(GSupplicantInterface *interface)
424 {
425         const char *ifname = g_supplicant_interface_get_ifname(interface);
426         struct wifi_data *wifi;
427
428         DBG("ifname %s", ifname);
429
430         wifi = g_supplicant_interface_get_data(interface);
431
432         if (wifi == NULL || wifi->device == NULL) {
433                 connman_error("Wrong wifi pointer");
434                 return;
435         }
436
437         connman_device_set_powered(wifi->device, FALSE);
438 }
439
440 static void scan_started(GSupplicantInterface *interface)
441 {
442         struct wifi_data *wifi;
443
444         DBG("");
445
446         wifi = g_supplicant_interface_get_data(interface);
447
448         if (wifi == NULL)
449                 return;
450 }
451
452 static void scan_finished(GSupplicantInterface *interface)
453 {
454         struct wifi_data *wifi;
455
456         DBG("");
457
458         wifi = g_supplicant_interface_get_data(interface);
459
460         if (wifi == NULL)
461                 return;
462 }
463
464 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
465 {
466         unsigned char strength;
467
468         strength = 120 + g_supplicant_network_get_signal(supplicant_network);
469         if (strength > 100)
470                 strength = 100;
471
472         return strength;
473 }
474
475 static void network_added(GSupplicantNetwork *supplicant_network)
476 {
477         struct connman_network *network;
478         GSupplicantInterface *interface;
479         struct wifi_data *wifi;
480         const char *name, *identifier, *mode, *security, *group;
481         const unsigned char *ssid;
482         unsigned int ssid_len;
483
484         DBG("");
485
486         interface = g_supplicant_network_get_interface(supplicant_network);
487         wifi = g_supplicant_interface_get_data(interface);
488         name = g_supplicant_network_get_name(supplicant_network);
489         identifier = g_supplicant_network_get_identifier(supplicant_network);
490         mode = g_supplicant_network_get_mode(supplicant_network);
491         security = g_supplicant_network_get_security(supplicant_network);
492         group = g_supplicant_network_get_identifier(supplicant_network);
493
494         if (wifi == NULL)
495                 return;
496
497         ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
498
499         network = connman_device_get_network(wifi->device, identifier);
500
501         if (network == NULL) {
502                 network = connman_network_create(identifier,
503                                                 CONNMAN_NETWORK_TYPE_WIFI);
504                 if (network == NULL)
505                         return;
506
507                 connman_network_set_index(network, wifi->index);
508
509                 if (connman_device_add_network(wifi->device, network) < 0) {
510                         connman_network_unref(network);
511                         return;
512                 }
513         }
514
515         if (name != NULL && name[0] != '\0')
516                 connman_network_set_name(network, name);
517
518         connman_network_set_blob(network, "WiFi.SSID",
519                                                 ssid, ssid_len);
520         connman_network_set_string(network, "WiFi.Mode", mode);
521         connman_network_set_string(network, "WiFi.Security", security);
522         connman_network_set_strength(network,
523                                 calculate_strength(supplicant_network));
524
525         connman_network_set_available(network, TRUE);
526
527         if (ssid != NULL)
528                 connman_network_set_group(network, group);
529 }
530
531 static void network_removed(GSupplicantNetwork *network)
532 {
533         GSupplicantInterface *interface;
534         struct wifi_data *wifi;
535         const char *name, *identifier;
536
537         interface = g_supplicant_network_get_interface(network);
538         wifi = g_supplicant_interface_get_data(interface);
539         identifier = g_supplicant_network_get_identifier(network);
540         name = g_supplicant_network_get_name(network);
541
542         DBG("name %s", name);
543
544         if (wifi != NULL)
545                 connman_device_remove_network(wifi->device, identifier);
546 }
547
548 static void debug(const char *str)
549 {
550         if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
551                 connman_debug("%s", str);
552 }
553
554 static const GSupplicantCallbacks callbacks = {
555         .system_ready           = system_ready,
556         .system_killed          = system_killed,
557         .interface_added        = interface_added,
558         .interface_state        = interface_state,
559         .interface_removed      = interface_removed,
560         .scan_started           = scan_started,
561         .scan_finished          = scan_finished,
562         .network_added          = network_added,
563         .network_removed        = network_removed,
564         .debug                  = debug,
565 };
566
567
568 static int network_probe(struct connman_network *network)
569 {
570         DBG("network %p", network);
571
572         return 0;
573 }
574
575 static void network_remove(struct connman_network *network)
576 {
577         DBG("network %p", network);
578 }
579
580 static void connect_callback(int result, GSupplicantInterface *interface,
581                                                         void *user_data)
582 {
583         connman_error("%s", __func__);
584 }
585
586 static GSupplicantSecurity network_security(const char *security)
587 {
588         if (g_str_equal(security, "none") == TRUE)
589                 return G_SUPPLICANT_SECURITY_NONE;
590         else if (g_str_equal(security, "wep") == TRUE)
591                 return G_SUPPLICANT_SECURITY_WEP;
592         else if (g_str_equal(security, "psk") == TRUE)
593                 return G_SUPPLICANT_SECURITY_PSK;
594         else if (g_str_equal(security, "wpa") == TRUE)
595                 return G_SUPPLICANT_SECURITY_PSK;
596         else if (g_str_equal(security, "rsn") == TRUE)
597                 return G_SUPPLICANT_SECURITY_PSK;
598         else if (g_str_equal(security, "ieee8021x") == TRUE)
599                 return G_SUPPLICANT_SECURITY_IEEE8021X;
600
601         return G_SUPPLICANT_SECURITY_UNKNOWN;
602 }
603
604 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
605 {
606         const char *security, *passphrase;
607
608         memset(ssid, 0, sizeof(*ssid));
609         ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
610                                                 &ssid->ssid_len);
611         security = connman_network_get_string(network, "WiFi.Security");
612         ssid->security = network_security(security);
613         passphrase = connman_network_get_string(network,
614                                                 "WiFi.Passphrase");
615         if (passphrase == NULL || strlen(passphrase) == 0)
616                 ssid->passphrase = NULL;
617         else
618                 ssid->passphrase = passphrase;
619
620         ssid->eap = connman_network_get_string(network, "WiFi.EAP");
621
622         /*
623          * If our private key password is unset,
624          * we use the supplied passphrase. That is needed
625          * for PEAP where 2 passphrases (identity and client
626          * cert may have to be provided.
627          */
628         if (connman_network_get_string(network,
629                                         "WiFi.PrivateKeyPassphrase") == NULL)
630                 connman_network_set_string(network,
631                                                 "WiFi.PrivateKeyPassphrase",
632                                                 ssid->passphrase);
633         /* We must have an identity for both PEAP and TLS */
634         ssid->identity = connman_network_get_string(network, "WiFi.Identity");
635         ssid->ca_cert_path = connman_network_get_string(network,
636                                                         "WiFi.CACertFile");
637         ssid->client_cert_path = connman_network_get_string(network,
638                                                         "WiFi.ClientCertFile");
639         ssid->private_key_path = connman_network_get_string(network,
640                                                         "WiFi.PrivateKeyFile");
641         ssid->private_key_passphrase = connman_network_get_string(network,
642                                                 "WiFi.PrivateKeyPassphrase");
643         ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
644
645 }
646
647 static int network_connect(struct connman_network *network)
648 {
649         struct connman_device *device = connman_network_get_device(network);
650         struct wifi_data *wifi;
651         GSupplicantInterface *interface;
652         GSupplicantSSID *ssid;
653
654         DBG("network %p", network);
655
656         if (device == NULL)
657                 return -ENODEV;
658
659         wifi = connman_device_get_data(device);
660         if (wifi == NULL)
661                 return -ENODEV;
662
663         ssid = g_try_malloc0(sizeof(GSupplicantSSID));
664         if (ssid == NULL)
665                 return -ENOMEM;
666
667         interface = wifi->interface;
668
669         ssid_init(ssid, network);
670
671         if (wifi->disconnecting == TRUE)
672                 wifi->pending_network = connman_network_ref(network);
673         else {
674                 wifi->network = connman_network_ref(network);
675
676                 return g_supplicant_interface_connect(interface, ssid,
677                                                 connect_callback, NULL);
678         }
679
680         return -EINPROGRESS;
681 }
682
683 static void disconnect_callback(int result, GSupplicantInterface *interface,
684                                                                 void *user_data)
685 {
686         struct wifi_data *wifi = user_data;
687
688         if (wifi->network != NULL) {
689                 /*
690                  * if result < 0 supplican return an error because
691                  * the network is not current.
692                  * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
693                  * failed, call connman_network_set_connected to report
694                  * disconnect is completed.
695                  */
696                 if (result < 0)
697                         connman_network_set_connected(wifi->network, FALSE);
698
699                 connman_network_unref(wifi->network);
700         }
701
702         wifi->network = NULL;
703
704         wifi->disconnecting = FALSE;
705
706         if (wifi->pending_network != NULL) {
707                 network_connect(wifi->pending_network);
708                 connman_network_unref(wifi->pending_network);
709                 wifi->pending_network = NULL;
710         }
711
712 }
713
714 static int network_disconnect(struct connman_network *network)
715 {
716         struct connman_device *device = connman_network_get_device(network);
717         struct wifi_data *wifi;
718         int err;
719
720         DBG("network %p", network);
721
722         wifi = connman_device_get_data(device);
723         if (wifi == NULL || wifi->interface == NULL)
724                 return -ENODEV;
725
726         connman_network_set_associating(network, FALSE);
727
728         if (wifi->disconnecting == TRUE)
729                 return -EALREADY;
730
731         wifi->disconnecting = TRUE;
732
733         err = g_supplicant_interface_disconnect(wifi->interface,
734                                                 disconnect_callback, wifi);
735         if (err < 0)
736                 wifi->disconnecting = FALSE;
737
738         return err;
739 }
740
741 static struct connman_network_driver network_driver = {
742         .name           = "wifi",
743         .type           = CONNMAN_NETWORK_TYPE_WIFI,
744         .priority       = CONNMAN_NETWORK_PRIORITY_LOW,
745         .probe          = network_probe,
746         .remove         = network_remove,
747         .connect        = network_connect,
748         .disconnect     = network_disconnect,
749 };
750
751 static int tech_probe(struct connman_technology *technology)
752 {
753         wifi_technology = technology;
754
755         return 0;
756 }
757
758 static void tech_remove(struct connman_technology *technology)
759 {
760         wifi_technology = NULL;
761 }
762
763 static void regdom_callback(void *user_data)
764 {
765         char *alpha2 = user_data;
766
767         DBG("");
768
769         if (wifi_technology == NULL)
770                 return;
771
772         connman_technology_regdom_notify(wifi_technology, alpha2);
773 }
774
775 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
776 {
777         return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
778 }
779
780 static struct connman_technology_driver tech_driver = {
781         .name           = "wifi",
782         .type           = CONNMAN_SERVICE_TYPE_WIFI,
783         .probe          = tech_probe,
784         .remove         = tech_remove,
785         .set_regdom     = tech_set_regdom,
786 };
787
788 static int wifi_init(void)
789 {
790         int err;
791
792         err = connman_network_driver_register(&network_driver);
793         if (err < 0)
794                 return err;
795
796         err = g_supplicant_register(&callbacks);
797         if (err < 0) {
798                 connman_network_driver_unregister(&network_driver);
799                 return err;
800         }
801
802         err = connman_technology_driver_register(&tech_driver);
803         if (err < 0) {
804                 g_supplicant_unregister(&callbacks);
805                 connman_network_driver_unregister(&network_driver);
806                 return err;
807         }
808
809         return 0;
810 }
811
812 static void wifi_exit(void)
813 {
814         DBG();
815
816         connman_technology_driver_unregister(&tech_driver);
817
818         g_supplicant_unregister(&callbacks);
819
820         connman_network_driver_unregister(&network_driver);
821 }
822
823 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
824                 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)