5 * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
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.
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.
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
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>
38 #define IFF_LOWER_UP 0x10000
41 #include <dbus/dbus.h>
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/service.h>
51 #include <connman/log.h>
52 #include <connman/option.h>
53 #include <connman/storage.h>
54 #include <include/setting.h>
55 #include <connman/provision.h>
57 #include <gsupplicant/gsupplicant.h>
59 #define CLEANUP_TIMEOUT 8 /* in seconds */
60 #define INACTIVE_TIMEOUT 12 /* in seconds */
61 #define MAXIMUM_RETRIES 2
62 #define FAVORITE_MAXIMUM_RETRIES 4
64 #define BGSCAN_DEFAULT "simple:30:-45:300"
65 #define AUTOSCAN_DEFAULT "exponential:3:300"
67 static struct connman_technology *wifi_technology = NULL;
69 struct hidden_params {
71 unsigned int ssid_len;
78 * Used for autoscan "emulation".
79 * Should be removed when wpa_s autoscan support will be by default.
81 struct autoscan_params {
90 struct connman_device *device;
91 struct connman_network *network;
92 struct connman_network *pending_network;
94 GSupplicantInterface *interface;
95 GSupplicantState state;
96 connman_bool_t connected;
97 connman_bool_t disconnecting;
98 connman_bool_t tethering;
99 connman_bool_t bridged;
105 struct hidden_params *hidden;
107 * autoscan "emulation".
109 struct autoscan_params *autoscan;
112 static GList *iface_list = NULL;
114 static void start_autoscan(struct connman_device *device);
116 static void handle_tethering(struct wifi_data *wifi)
118 if (wifi->tethering == FALSE)
121 if (wifi->bridge == NULL)
124 if (wifi->bridged == TRUE)
127 DBG("index %d bridge %s", wifi->index, wifi->bridge);
129 if (connman_inet_add_to_bridge(wifi->index, wifi->bridge) < 0)
132 wifi->bridged = TRUE;
135 static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
137 struct connman_device *device = user_data;
138 struct wifi_data *wifi = connman_device_get_data(device);
143 DBG("index %d flags %d change %d", wifi->index, flags, change);
148 if ((wifi->flags & IFF_UP) != (flags & IFF_UP)) {
152 DBG("interface down");
155 if ((wifi->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
156 if (flags & IFF_LOWER_UP) {
159 handle_tethering(wifi);
167 static int wifi_probe(struct connman_device *device)
169 struct wifi_data *wifi;
171 DBG("device %p", device);
173 wifi = g_try_new0(struct wifi_data, 1);
177 wifi->connected = FALSE;
178 wifi->disconnecting = FALSE;
179 wifi->tethering = FALSE;
180 wifi->bridged = FALSE;
182 wifi->state = G_SUPPLICANT_STATE_INACTIVE;
184 connman_device_set_data(device, wifi);
185 wifi->device = connman_device_ref(device);
187 wifi->index = connman_device_get_index(device);
190 wifi->watch = connman_rtnl_add_newlink_watch(wifi->index,
191 wifi_newlink, device);
193 iface_list = g_list_append(iface_list, wifi);
198 static void remove_networks(struct connman_device *device,
199 struct wifi_data *wifi)
203 for (list = wifi->networks; list != NULL; list = list->next) {
204 struct connman_network *network = list->data;
206 connman_device_remove_network(device, network);
207 connman_network_unref(network);
210 g_slist_free(wifi->networks);
211 wifi->networks = NULL;
214 static void reset_autoscan(struct connman_device *device)
216 struct wifi_data *wifi = connman_device_get_data(device);
217 struct autoscan_params *autoscan;
221 if (wifi == NULL || wifi->autoscan == NULL)
224 autoscan = wifi->autoscan;
226 if (autoscan->timeout == 0 && autoscan->interval == 0)
229 g_source_remove(autoscan->timeout);
231 autoscan->timeout = 0;
232 autoscan->interval = 0;
234 connman_device_unref(device);
237 static void stop_autoscan(struct connman_device *device)
239 reset_autoscan(device);
241 connman_device_set_scanning(device, FALSE);
244 static void wifi_remove(struct connman_device *device)
246 struct wifi_data *wifi = connman_device_get_data(device);
248 DBG("device %p wifi %p", device, wifi);
253 iface_list = g_list_remove(iface_list, wifi);
255 remove_networks(device, wifi);
257 connman_device_set_powered(device, FALSE);
258 connman_device_set_data(device, NULL);
259 connman_device_unref(wifi->device);
260 connman_rtnl_remove_watch(wifi->watch);
262 g_supplicant_interface_set_data(wifi->interface, NULL);
264 g_free(wifi->autoscan);
265 g_free(wifi->identifier);
269 static int add_scan_param(gchar *hex_ssid, char *raw_ssid, int ssid_len,
270 int freq, GSupplicantScanParams *scan_data,
271 int driver_max_scan_ssids)
274 struct scan_ssid *scan_ssid;
276 if (driver_max_scan_ssids > scan_data->num_ssids &&
277 (hex_ssid != NULL || raw_ssid != NULL)) {
279 unsigned int j = 0, hex;
281 if (hex_ssid != NULL) {
282 size_t hex_ssid_len = strlen(hex_ssid);
284 ssid = g_try_malloc0(hex_ssid_len / 2);
288 for (i = 0; i < hex_ssid_len; i += 2) {
289 sscanf(hex_ssid + i, "%02x", &hex);
297 scan_ssid = g_try_new(struct scan_ssid, 1);
298 if (scan_ssid == NULL) {
303 memcpy(scan_ssid->ssid, ssid, j);
304 scan_ssid->ssid_len = j;
305 scan_data->ssids = g_slist_prepend(scan_data->ssids,
308 scan_data->num_ssids++;
310 if (hex_ssid != NULL)
315 scan_data->ssids = g_slist_reverse(scan_data->ssids);
317 if (scan_data->freqs == NULL) {
318 scan_data->freqs = g_try_malloc0(sizeof(uint16_t) *
319 scan_data->num_ssids);
320 if (scan_data->freqs == NULL) {
321 g_slist_free_full(scan_data->ssids, g_free);
325 scan_data->freqs = g_try_realloc(scan_data->freqs,
326 sizeof(uint16_t) * scan_data->num_ssids);
327 if (scan_data->freqs == NULL) {
328 g_slist_free_full(scan_data->ssids, g_free);
331 scan_data->freqs[scan_data->num_ssids - 1] = 0;
334 /* Don't add duplicate entries */
335 for (i = 0; i < scan_data->num_ssids; i++) {
336 if (scan_data->freqs[i] == 0) {
337 scan_data->freqs[i] = freq;
339 } else if (scan_data->freqs[i] == freq)
346 static int get_hidden_connections(int max_ssids,
347 GSupplicantScanParams *scan_data)
349 struct connman_config_entry **entries;
356 int num_ssids = 0, add_param_failed = 0;
358 services = connman_storage_get_services();
359 for (i = 0; services && services[i]; i++) {
360 if (strncmp(services[i], "wifi_", 5) != 0)
363 keyfile = connman_storage_load_service(services[i]);
365 value = g_key_file_get_boolean(keyfile,
366 services[i], "Hidden", NULL);
367 if (value == FALSE) {
368 g_key_file_free(keyfile);
372 value = g_key_file_get_boolean(keyfile,
373 services[i], "Favorite", NULL);
374 if (value == FALSE) {
375 g_key_file_free(keyfile);
379 ssid = g_key_file_get_string(keyfile,
380 services[i], "SSID", NULL);
382 freq = g_key_file_get_integer(keyfile, services[i],
385 if (add_scan_param(ssid, NULL, 0, freq, scan_data,
387 str = g_key_file_get_string(keyfile,
388 services[i], "Name", NULL);
389 DBG("Cannot scan %s (%s)", ssid, str);
396 g_key_file_free(keyfile);
400 * Check if there are any hidden AP that needs to be provisioned.
402 entries = connman_config_get_entries();
403 for (i = 0; entries && entries[i]; i++) {
406 if (entries[i]->hidden == FALSE)
409 if (entries[i]->ssid == NULL) {
410 ssid = entries[i]->name;
413 ssid = entries[i]->ssid;
414 len = entries[i]->ssid_len;
420 DBG("[%d]->ssid = %s", i, ssid);
422 if (add_scan_param(NULL, ssid, len, 0, scan_data,
424 DBG("Cannot scan %s (%s)", ssid, entries[i]->ident);
431 connman_config_free_entries(entries);
433 if (add_param_failed > 0)
434 DBG("Unable to scan %d out of %d SSIDs (max is %d)",
435 add_param_failed, num_ssids, max_ssids);
437 g_strfreev(services);
439 return num_ssids > max_ssids ? max_ssids : num_ssids;
442 static int throw_wifi_scan(struct connman_device *device,
443 GSupplicantInterfaceCallback callback)
445 struct wifi_data *wifi = connman_device_get_data(device);
451 DBG("device %p %p", device, wifi->interface);
453 if (wifi->tethering == TRUE)
456 if (connman_device_get_scanning(device) == TRUE)
459 connman_device_ref(device);
461 ret = g_supplicant_interface_scan(wifi->interface, NULL,
464 connman_device_set_scanning(device, TRUE);
466 connman_device_unref(device);
471 static void hidden_free(struct hidden_params *hidden)
476 g_free(hidden->identity);
477 g_free(hidden->passphrase);
481 static void scan_callback(int result, GSupplicantInterface *interface,
484 struct connman_device *device = user_data;
485 struct wifi_data *wifi = connman_device_get_data(device);
487 DBG("result %d wifi %p", result, wifi);
489 if (wifi != NULL && wifi->hidden != NULL) {
490 connman_network_clear_hidden(wifi->hidden->user_data);
491 hidden_free(wifi->hidden);
496 connman_device_reset_scanning(device);
498 connman_device_set_scanning(device, FALSE);
499 start_autoscan(device);
500 connman_device_unref(device);
503 static void scan_callback_hidden(int result,
504 GSupplicantInterface *interface, void *user_data)
506 struct connman_device *device = user_data;
507 struct wifi_data *wifi = connman_device_get_data(device);
508 int driver_max_ssids;
510 DBG("result %d wifi %p", result, wifi);
516 * Scan hidden networks so that we can autoconnect to them.
518 driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
520 DBG("max ssids %d", driver_max_ssids);
522 if (driver_max_ssids > 0) {
523 GSupplicantScanParams *scan_params;
526 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
527 if (scan_params == NULL)
530 if (get_hidden_connections(driver_max_ssids,
532 ret = g_supplicant_interface_scan(wifi->interface,
540 g_supplicant_free_scan_params(scan_params);
544 scan_callback(result, interface, user_data);
547 static gboolean autoscan_timeout(gpointer data)
549 struct connman_device *device = data;
550 struct wifi_data *wifi = connman_device_get_data(device);
551 struct autoscan_params *autoscan;
557 autoscan = wifi->autoscan;
559 if (autoscan->interval <= 0) {
560 interval = autoscan->base;
563 interval = autoscan->interval * autoscan->base;
565 if (autoscan->interval >= autoscan->limit)
566 interval = autoscan->limit;
568 throw_wifi_scan(wifi->device, scan_callback_hidden);
571 DBG("interval %d", interval);
573 autoscan->interval = interval;
575 autoscan->timeout = g_timeout_add_seconds(interval,
576 autoscan_timeout, device);
581 static void start_autoscan(struct connman_device *device)
583 struct wifi_data *wifi = connman_device_get_data(device);
584 struct autoscan_params *autoscan;
591 autoscan = wifi->autoscan;
592 if (autoscan == NULL)
595 if (autoscan->timeout > 0 || autoscan->interval > 0)
598 connman_device_ref(device);
600 autoscan_timeout(device);
603 static struct autoscan_params *parse_autoscan_params(const char *params)
605 struct autoscan_params *autoscan;
610 DBG("Emulating autoscan");
612 list_params = g_strsplit(params, ":", 0);
613 if (list_params == 0)
616 if (g_strv_length(list_params) < 3) {
617 g_strfreev(list_params);
621 base = atoi(list_params[1]);
622 limit = atoi(list_params[2]);
624 g_strfreev(list_params);
626 autoscan = g_try_malloc0(sizeof(struct autoscan_params));
627 if (autoscan == NULL) {
628 DBG("Could not allocate memory for autoscan");
632 DBG("base %d - limit %d", base, limit);
633 autoscan->base = base;
634 autoscan->limit = limit;
639 static void setup_autoscan(struct wifi_data *wifi)
641 if (wifi->autoscan == NULL)
642 wifi->autoscan = parse_autoscan_params(AUTOSCAN_DEFAULT);
644 start_autoscan(wifi->device);
647 static void interface_autoscan_callback(int result,
648 GSupplicantInterface *interface,
651 struct wifi_data *wifi = user_data;
654 DBG("Could not enable Autoscan, falling back...");
655 setup_autoscan(wifi);
659 static void interface_create_callback(int result,
660 GSupplicantInterface *interface,
663 struct wifi_data *wifi = user_data;
665 DBG("result %d ifname %s, wifi %p", result,
666 g_supplicant_interface_get_ifname(interface),
669 if (result < 0 || wifi == NULL)
672 wifi->interface = interface;
673 g_supplicant_interface_set_data(interface, wifi);
675 if (g_supplicant_interface_get_ready(interface) == FALSE)
678 DBG("interface is ready wifi %p tethering %d", wifi, wifi->tethering);
680 if (wifi->device == NULL) {
681 connman_error("WiFi device not set");
685 connman_device_set_powered(wifi->device, TRUE);
687 if (connman_setting_get_bool("BackgroundScanning") == FALSE)
690 /* Setting up automatic scanning */
691 if (g_supplicant_interface_autoscan(interface, AUTOSCAN_DEFAULT,
692 interface_autoscan_callback, wifi) < 0) {
693 DBG("Could not enable Autoscan, falling back...");
694 setup_autoscan(wifi);
698 static int wifi_enable(struct connman_device *device)
700 struct wifi_data *wifi = connman_device_get_data(device);
701 const char *interface = connman_device_get_string(device, "Interface");
702 const char *driver = connman_option_get_string("wifi");
705 DBG("device %p %p", device, wifi);
710 ret = g_supplicant_interface_create(interface, driver, NULL,
711 interface_create_callback,
719 static int wifi_disable(struct connman_device *device)
721 struct wifi_data *wifi = connman_device_get_data(device);
724 DBG("device %p wifi %p", device, wifi);
729 wifi->connected = FALSE;
730 wifi->disconnecting = FALSE;
732 if (wifi->pending_network != NULL)
733 wifi->pending_network = NULL;
735 stop_autoscan(device);
737 /* In case of a user scan, device is still referenced */
738 if (connman_device_get_scanning(device) == TRUE) {
739 connman_device_set_scanning(device, FALSE);
740 connman_device_unref(wifi->device);
743 remove_networks(device, wifi);
745 ret = g_supplicant_interface_remove(wifi->interface, NULL, NULL);
752 struct last_connected {
758 static gint sort_entry(gconstpointer a, gconstpointer b, gpointer user_data)
760 GTimeVal *aval = (GTimeVal *)a;
761 GTimeVal *bval = (GTimeVal *)b;
763 /* Note that the sort order is descending */
764 if (aval->tv_sec < bval->tv_sec)
767 if (aval->tv_sec > bval->tv_sec)
773 static void free_entry(gpointer data)
775 struct last_connected *entry = data;
781 static int get_latest_connections(int max_ssids,
782 GSupplicantScanParams *scan_data)
785 GSequence *latest_list;
786 struct last_connected *entry;
795 latest_list = g_sequence_new(free_entry);
796 if (latest_list == NULL)
799 services = connman_storage_get_services();
800 for (i = 0; services && services[i]; i++) {
801 if (strncmp(services[i], "wifi_", 5) != 0)
804 keyfile = connman_storage_load_service(services[i]);
806 str = g_key_file_get_string(keyfile,
807 services[i], "Favorite", NULL);
808 if (str == NULL || g_strcmp0(str, "true")) {
811 g_key_file_free(keyfile);
816 str = g_key_file_get_string(keyfile,
817 services[i], "AutoConnect", NULL);
818 if (str == NULL || g_strcmp0(str, "true")) {
821 g_key_file_free(keyfile);
826 str = g_key_file_get_string(keyfile,
827 services[i], "Modified", NULL);
829 g_time_val_from_iso8601(str, &modified);
833 ssid = g_key_file_get_string(keyfile,
834 services[i], "SSID", NULL);
836 freq = g_key_file_get_integer(keyfile, services[i],
839 entry = g_try_new(struct last_connected, 1);
841 g_sequence_free(latest_list);
842 g_key_file_free(keyfile);
848 entry->modified = modified;
851 g_sequence_insert_sorted(latest_list, entry,
857 g_key_file_free(keyfile);
860 g_strfreev(services);
862 num_ssids = num_ssids > max_ssids ? max_ssids : num_ssids;
864 iter = g_sequence_get_begin_iter(latest_list);
866 for (i = 0; i < num_ssids; i++) {
867 entry = g_sequence_get(iter);
869 DBG("ssid %s freq %d modified %lu", entry->ssid, entry->freq,
870 entry->modified.tv_sec);
872 add_scan_param(entry->ssid, NULL, 0, entry->freq, scan_data,
875 iter = g_sequence_iter_next(iter);
878 g_sequence_free(latest_list);
882 static int wifi_scan(struct connman_device *device)
884 reset_autoscan(device);
886 return throw_wifi_scan(device, scan_callback_hidden);
889 static int wifi_scan_fast(struct connman_device *device)
891 struct wifi_data *wifi = connman_device_get_data(device);
892 GSupplicantScanParams *scan_params = NULL;
894 int driver_max_ssids = 0;
899 DBG("device %p %p", device, wifi->interface);
901 if (wifi->tethering == TRUE)
904 if (connman_device_get_scanning(device) == TRUE)
907 driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
909 DBG("max ssids %d", driver_max_ssids);
910 if (driver_max_ssids == 0)
911 return wifi_scan(device);
913 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
914 if (scan_params == NULL)
917 ret = get_latest_connections(driver_max_ssids, scan_params);
919 g_supplicant_free_scan_params(scan_params);
920 return wifi_scan(device);
923 connman_device_ref(device);
924 reset_autoscan(device);
926 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
927 scan_callback, device);
929 connman_device_set_scanning(device, TRUE);
931 g_supplicant_free_scan_params(scan_params);
932 connman_device_unref(device);
939 * This func is only used when connecting to this specific AP first time.
940 * It is not used when system autoconnects to hidden AP.
942 static int wifi_scan_hidden(struct connman_device *device,
943 const char *ssid, unsigned int ssid_len,
944 const char *identity, const char* passphrase,
947 struct wifi_data *wifi = connman_device_get_data(device);
948 GSupplicantScanParams *scan_params = NULL;
949 struct scan_ssid *scan_ssid;
950 struct hidden_params *hidden;
956 DBG("hidden SSID %s", ssid);
958 if (wifi->tethering == TRUE || wifi->hidden != NULL)
961 if (ssid == NULL || ssid_len == 0 || ssid_len > 32)
964 if (connman_device_get_scanning(device) == TRUE)
967 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
968 if (scan_params == NULL)
971 scan_ssid = g_try_new(struct scan_ssid, 1);
972 if (scan_ssid == NULL) {
977 memcpy(scan_ssid->ssid, ssid, ssid_len);
978 scan_ssid->ssid_len = ssid_len;
979 scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
981 scan_params->num_ssids = 1;
983 hidden = g_try_new0(struct hidden_params, 1);
984 if (hidden == NULL) {
988 memcpy(hidden->ssid, ssid, ssid_len);
989 hidden->ssid_len = ssid_len;
990 hidden->identity = g_strdup(identity);
991 hidden->passphrase = g_strdup(passphrase);
992 hidden->user_data = user_data;
993 wifi->hidden = hidden;
995 connman_device_ref(device);
997 reset_autoscan(device);
999 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
1000 scan_callback, device);
1002 connman_device_set_scanning(device, TRUE);
1004 connman_device_unref(device);
1005 g_supplicant_free_scan_params(scan_params);
1006 hidden_free(wifi->hidden);
1007 wifi->hidden = NULL;
1013 static void wifi_regdom_callback(int result,
1017 struct connman_device *device = user_data;
1019 connman_device_regdom_notify(device, result, alpha2);
1021 connman_device_unref(device);
1024 static int wifi_set_regdom(struct connman_device *device, const char *alpha2)
1026 struct wifi_data *wifi = connman_device_get_data(device);
1032 connman_device_ref(device);
1034 ret = g_supplicant_interface_set_country(wifi->interface,
1035 wifi_regdom_callback,
1038 connman_device_unref(device);
1043 static struct connman_device_driver wifi_ng_driver = {
1045 .type = CONNMAN_DEVICE_TYPE_WIFI,
1046 .priority = CONNMAN_DEVICE_PRIORITY_LOW,
1047 .probe = wifi_probe,
1048 .remove = wifi_remove,
1049 .enable = wifi_enable,
1050 .disable = wifi_disable,
1052 .scan_fast = wifi_scan_fast,
1053 .scan_hidden = wifi_scan_hidden,
1054 .set_regdom = wifi_set_regdom,
1057 static void system_ready(void)
1061 if (connman_device_driver_register(&wifi_ng_driver) < 0)
1062 connman_error("Failed to register WiFi driver");
1065 static void system_killed(void)
1069 connman_device_driver_unregister(&wifi_ng_driver);
1072 static int network_probe(struct connman_network *network)
1074 DBG("network %p", network);
1079 static void network_remove(struct connman_network *network)
1081 struct connman_device *device = connman_network_get_device(network);
1082 struct wifi_data *wifi;
1084 DBG("network %p", network);
1086 wifi = connman_device_get_data(device);
1090 if (wifi->network != network)
1093 wifi->network = NULL;
1096 static void connect_callback(int result, GSupplicantInterface *interface,
1099 struct connman_network *network = user_data;
1101 DBG("network %p result %d", network, result);
1103 if (result == -ENOKEY) {
1104 connman_network_set_error(network,
1105 CONNMAN_NETWORK_ERROR_INVALID_KEY);
1106 } else if (result < 0) {
1107 connman_network_set_error(network,
1108 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
1112 static GSupplicantSecurity network_security(const char *security)
1114 if (g_str_equal(security, "none") == TRUE)
1115 return G_SUPPLICANT_SECURITY_NONE;
1116 else if (g_str_equal(security, "wep") == TRUE)
1117 return G_SUPPLICANT_SECURITY_WEP;
1118 else if (g_str_equal(security, "psk") == TRUE)
1119 return G_SUPPLICANT_SECURITY_PSK;
1120 else if (g_str_equal(security, "wpa") == TRUE)
1121 return G_SUPPLICANT_SECURITY_PSK;
1122 else if (g_str_equal(security, "rsn") == TRUE)
1123 return G_SUPPLICANT_SECURITY_PSK;
1124 else if (g_str_equal(security, "ieee8021x") == TRUE)
1125 return G_SUPPLICANT_SECURITY_IEEE8021X;
1127 return G_SUPPLICANT_SECURITY_UNKNOWN;
1130 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
1132 const char *security, *passphrase, *agent_passphrase;
1134 memset(ssid, 0, sizeof(*ssid));
1135 ssid->mode = G_SUPPLICANT_MODE_INFRA;
1136 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
1138 ssid->scan_ssid = 1;
1139 security = connman_network_get_string(network, "WiFi.Security");
1140 ssid->security = network_security(security);
1141 passphrase = connman_network_get_string(network,
1143 if (passphrase == NULL || strlen(passphrase) == 0) {
1145 /* Use agent provided passphrase as a fallback */
1146 agent_passphrase = connman_network_get_string(network,
1147 "WiFi.AgentPassphrase");
1149 if (agent_passphrase == NULL || strlen(agent_passphrase) == 0)
1150 ssid->passphrase = NULL;
1152 ssid->passphrase = agent_passphrase;
1154 ssid->passphrase = passphrase;
1156 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
1159 * If our private key password is unset,
1160 * we use the supplied passphrase. That is needed
1161 * for PEAP where 2 passphrases (identity and client
1162 * cert may have to be provided.
1164 if (connman_network_get_string(network,
1165 "WiFi.PrivateKeyPassphrase") == NULL)
1166 connman_network_set_string(network,
1167 "WiFi.PrivateKeyPassphrase",
1169 /* We must have an identity for both PEAP and TLS */
1170 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
1172 /* Use agent provided identity as a fallback */
1173 if (ssid->identity == NULL || strlen(ssid->identity) == 0)
1174 ssid->identity = connman_network_get_string(network,
1175 "WiFi.AgentIdentity");
1177 ssid->ca_cert_path = connman_network_get_string(network,
1179 ssid->client_cert_path = connman_network_get_string(network,
1180 "WiFi.ClientCertFile");
1181 ssid->private_key_path = connman_network_get_string(network,
1182 "WiFi.PrivateKeyFile");
1183 ssid->private_key_passphrase = connman_network_get_string(network,
1184 "WiFi.PrivateKeyPassphrase");
1185 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
1187 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
1188 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
1190 if (connman_setting_get_bool("BackgroundScanning") == TRUE)
1191 ssid->bgscan = BGSCAN_DEFAULT;
1194 static int network_connect(struct connman_network *network)
1196 struct connman_device *device = connman_network_get_device(network);
1197 struct wifi_data *wifi;
1198 GSupplicantInterface *interface;
1199 GSupplicantSSID *ssid;
1201 DBG("network %p", network);
1206 wifi = connman_device_get_data(device);
1210 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
1214 interface = wifi->interface;
1216 ssid_init(ssid, network);
1218 if (wifi->disconnecting == TRUE)
1219 wifi->pending_network = network;
1221 wifi->network = network;
1224 return g_supplicant_interface_connect(interface, ssid,
1225 connect_callback, network);
1228 return -EINPROGRESS;
1231 static void disconnect_callback(int result, GSupplicantInterface *interface,
1234 struct wifi_data *wifi = user_data;
1236 if (wifi->network != NULL) {
1238 * if result < 0 supplican return an error because
1239 * the network is not current.
1240 * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
1241 * failed, call connman_network_set_connected to report
1242 * disconnect is completed.
1245 connman_network_set_connected(wifi->network, FALSE);
1248 wifi->network = NULL;
1250 wifi->disconnecting = FALSE;
1252 if (wifi->pending_network != NULL) {
1253 network_connect(wifi->pending_network);
1254 wifi->pending_network = NULL;
1257 start_autoscan(wifi->device);
1260 static int network_disconnect(struct connman_network *network)
1262 struct connman_device *device = connman_network_get_device(network);
1263 struct wifi_data *wifi;
1266 DBG("network %p", network);
1268 wifi = connman_device_get_data(device);
1269 if (wifi == NULL || wifi->interface == NULL)
1272 connman_network_set_associating(network, FALSE);
1274 if (wifi->disconnecting == TRUE)
1277 wifi->disconnecting = TRUE;
1279 err = g_supplicant_interface_disconnect(wifi->interface,
1280 disconnect_callback, wifi);
1282 wifi->disconnecting = FALSE;
1287 static struct connman_network_driver network_driver = {
1289 .type = CONNMAN_NETWORK_TYPE_WIFI,
1290 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
1291 .probe = network_probe,
1292 .remove = network_remove,
1293 .connect = network_connect,
1294 .disconnect = network_disconnect,
1297 static void interface_added(GSupplicantInterface *interface)
1299 const char *ifname = g_supplicant_interface_get_ifname(interface);
1300 const char *driver = g_supplicant_interface_get_driver(interface);
1301 struct wifi_data *wifi;
1303 wifi = g_supplicant_interface_get_data(interface);
1306 * We can get here with a NULL wifi pointer when
1307 * the interface added signal is sent before the
1308 * interface creation callback is called.
1313 DBG("ifname %s driver %s wifi %p tethering %d",
1314 ifname, driver, wifi, wifi->tethering);
1316 if (wifi->device == NULL) {
1317 connman_error("WiFi device not set");
1321 connman_device_set_powered(wifi->device, TRUE);
1323 if (wifi->tethering == TRUE)
1327 static connman_bool_t is_idle(struct wifi_data *wifi)
1329 DBG("state %d", wifi->state);
1331 switch (wifi->state) {
1332 case G_SUPPLICANT_STATE_UNKNOWN:
1333 case G_SUPPLICANT_STATE_DISCONNECTED:
1334 case G_SUPPLICANT_STATE_INACTIVE:
1335 case G_SUPPLICANT_STATE_SCANNING:
1338 case G_SUPPLICANT_STATE_AUTHENTICATING:
1339 case G_SUPPLICANT_STATE_ASSOCIATING:
1340 case G_SUPPLICANT_STATE_ASSOCIATED:
1341 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
1342 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
1343 case G_SUPPLICANT_STATE_COMPLETED:
1350 static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
1351 struct wifi_data *wifi)
1353 /* First, let's check if WPS processing did not went wrong */
1354 if (g_supplicant_interface_get_wps_state(interface) ==
1355 G_SUPPLICANT_WPS_STATE_FAIL)
1358 /* Unlike normal connection, being associated while processing wps
1359 * actually means that we are idling. */
1360 switch (wifi->state) {
1361 case G_SUPPLICANT_STATE_UNKNOWN:
1362 case G_SUPPLICANT_STATE_DISCONNECTED:
1363 case G_SUPPLICANT_STATE_INACTIVE:
1364 case G_SUPPLICANT_STATE_SCANNING:
1365 case G_SUPPLICANT_STATE_ASSOCIATED:
1367 case G_SUPPLICANT_STATE_AUTHENTICATING:
1368 case G_SUPPLICANT_STATE_ASSOCIATING:
1369 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
1370 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
1371 case G_SUPPLICANT_STATE_COMPLETED:
1378 static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
1379 struct connman_network *network,
1380 struct connman_device *device,
1381 struct wifi_data *wifi)
1385 wps = connman_network_get_bool(network, "WiFi.UseWPS");
1387 const unsigned char *ssid, *wps_ssid;
1388 unsigned int ssid_len, wps_ssid_len;
1389 const char *wps_key;
1391 /* Checking if we got associated with requested
1393 ssid = connman_network_get_blob(network, "WiFi.SSID",
1396 wps_ssid = g_supplicant_interface_get_wps_ssid(
1397 interface, &wps_ssid_len);
1399 if (wps_ssid == NULL || wps_ssid_len != ssid_len ||
1400 memcmp(ssid, wps_ssid, ssid_len) != 0) {
1401 connman_network_set_associating(network, FALSE);
1402 g_supplicant_interface_disconnect(wifi->interface,
1403 disconnect_callback, wifi);
1407 wps_key = g_supplicant_interface_get_wps_key(interface);
1408 connman_network_set_string(network, "WiFi.Passphrase",
1411 connman_network_set_string(network, "WiFi.PinWPS", NULL);
1417 static connman_bool_t handle_4way_handshake_failure(GSupplicantInterface *interface,
1418 struct connman_network *network,
1419 struct wifi_data *wifi)
1421 struct connman_service *service;
1423 if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
1426 service = connman_service_lookup_from_network(network);
1427 if (service == NULL)
1432 if (connman_service_get_favorite(service) == TRUE) {
1433 if (wifi->retries < FAVORITE_MAXIMUM_RETRIES)
1435 } else if (wifi->retries < MAXIMUM_RETRIES)
1438 connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
1443 static void interface_state(GSupplicantInterface *interface)
1445 struct connman_network *network;
1446 struct connman_device *device;
1447 struct wifi_data *wifi;
1448 GSupplicantState state = g_supplicant_interface_get_state(interface);
1451 wifi = g_supplicant_interface_get_data(interface);
1453 DBG("wifi %p interface state %d", wifi, state);
1458 network = wifi->network;
1459 device = wifi->device;
1461 if (device == NULL || network == NULL)
1465 case G_SUPPLICANT_STATE_SCANNING:
1468 case G_SUPPLICANT_STATE_AUTHENTICATING:
1469 case G_SUPPLICANT_STATE_ASSOCIATING:
1470 stop_autoscan(device);
1472 if (wifi->connected == FALSE)
1473 connman_network_set_associating(network, TRUE);
1477 case G_SUPPLICANT_STATE_COMPLETED:
1478 /* though it should be already stopped: */
1479 stop_autoscan(device);
1481 if (handle_wps_completion(interface, network, device, wifi) ==
1485 connman_network_set_connected(network, TRUE);
1488 case G_SUPPLICANT_STATE_DISCONNECTED:
1490 * If we're in one of the idle modes, we have
1491 * not started association yet and thus setting
1492 * those ones to FALSE could cancel an association
1495 wps = connman_network_get_bool(network, "WiFi.UseWPS");
1497 if (is_idle_wps(interface, wifi) == TRUE)
1503 /* If previous state was 4way-handshake, then
1504 * it's either: psk was incorrect and thus we retry
1505 * or if we reach the maximum retries we declare the
1507 if (handle_4way_handshake_failure(interface,
1508 network, wifi) == TRUE)
1511 /* We disable the selected network, if not then
1512 * wpa_supplicant will loop retrying */
1513 if (g_supplicant_interface_enable_selected_network(interface,
1515 DBG("Could not disables selected network");
1517 connman_network_set_connected(network, FALSE);
1518 connman_network_set_associating(network, FALSE);
1519 wifi->disconnecting = FALSE;
1521 start_autoscan(device);
1525 case G_SUPPLICANT_STATE_INACTIVE:
1526 connman_network_set_associating(network, FALSE);
1527 start_autoscan(device);
1531 case G_SUPPLICANT_STATE_UNKNOWN:
1532 case G_SUPPLICANT_STATE_ASSOCIATED:
1533 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
1534 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
1538 wifi->state = state;
1540 /* Saving wpa_s state policy:
1541 * If connected and if the state changes are roaming related:
1542 * --> We stay connected
1544 * --> We are connected
1546 * --> We are not connected
1549 case G_SUPPLICANT_STATE_AUTHENTICATING:
1550 case G_SUPPLICANT_STATE_ASSOCIATING:
1551 case G_SUPPLICANT_STATE_ASSOCIATED:
1552 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
1553 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
1554 if (wifi->connected == TRUE)
1555 connman_warn("Probably roaming right now!"
1556 " Staying connected...");
1558 wifi->connected = FALSE;
1560 case G_SUPPLICANT_STATE_COMPLETED:
1561 wifi->connected = TRUE;
1564 wifi->connected = FALSE;
1571 static void interface_removed(GSupplicantInterface *interface)
1573 const char *ifname = g_supplicant_interface_get_ifname(interface);
1574 struct wifi_data *wifi;
1576 DBG("ifname %s", ifname);
1578 wifi = g_supplicant_interface_get_data(interface);
1580 if (wifi != NULL && wifi->tethering == TRUE)
1583 if (wifi == NULL || wifi->device == NULL) {
1584 DBG("wifi interface already removed");
1588 wifi->interface = NULL;
1589 connman_device_set_powered(wifi->device, FALSE);
1592 static void scan_started(GSupplicantInterface *interface)
1597 static void scan_finished(GSupplicantInterface *interface)
1602 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
1604 unsigned char strength;
1606 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
1613 static void network_added(GSupplicantNetwork *supplicant_network)
1615 struct connman_network *network;
1616 GSupplicantInterface *interface;
1617 struct wifi_data *wifi;
1618 const char *name, *identifier, *security, *group, *mode;
1619 const unsigned char *ssid;
1620 unsigned int ssid_len;
1622 connman_bool_t wps_pbc;
1623 connman_bool_t wps_ready;
1624 connman_bool_t wps_advertizing;
1628 interface = g_supplicant_network_get_interface(supplicant_network);
1629 wifi = g_supplicant_interface_get_data(interface);
1630 name = g_supplicant_network_get_name(supplicant_network);
1631 identifier = g_supplicant_network_get_identifier(supplicant_network);
1632 security = g_supplicant_network_get_security(supplicant_network);
1633 group = g_supplicant_network_get_identifier(supplicant_network);
1634 wps = g_supplicant_network_get_wps(supplicant_network);
1635 wps_pbc = g_supplicant_network_is_wps_pbc(supplicant_network);
1636 wps_ready = g_supplicant_network_is_wps_active(supplicant_network);
1637 wps_advertizing = g_supplicant_network_is_wps_advertizing(
1638 supplicant_network);
1639 mode = g_supplicant_network_get_mode(supplicant_network);
1644 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
1646 network = connman_device_get_network(wifi->device, identifier);
1648 if (network == NULL) {
1649 network = connman_network_create(identifier,
1650 CONNMAN_NETWORK_TYPE_WIFI);
1651 if (network == NULL)
1654 connman_network_set_index(network, wifi->index);
1656 if (connman_device_add_network(wifi->device, network) < 0) {
1657 connman_network_unref(network);
1661 wifi->networks = g_slist_append(wifi->networks, network);
1664 if (name != NULL && name[0] != '\0')
1665 connman_network_set_name(network, name);
1667 connman_network_set_blob(network, "WiFi.SSID",
1669 connman_network_set_string(network, "WiFi.Security", security);
1670 connman_network_set_strength(network,
1671 calculate_strength(supplicant_network));
1672 connman_network_set_bool(network, "WiFi.WPS", wps);
1675 /* Is AP advertizing for WPS association?
1676 * If so, we decide to use WPS by default */
1677 if (wps_ready == TRUE && wps_pbc == TRUE &&
1678 wps_advertizing == TRUE)
1679 connman_network_set_bool(network, "WiFi.UseWPS", TRUE);
1682 connman_network_set_frequency(network,
1683 g_supplicant_network_get_frequency(supplicant_network));
1685 connman_network_set_available(network, TRUE);
1686 connman_network_set_string(network, "WiFi.Mode", mode);
1689 connman_network_set_group(network, group);
1691 if (wifi->hidden != NULL && ssid != NULL) {
1692 if (wifi->hidden->ssid_len == ssid_len &&
1693 memcmp(wifi->hidden->ssid, ssid,
1695 connman_network_connect_hidden(network,
1696 wifi->hidden->identity,
1697 wifi->hidden->passphrase,
1698 wifi->hidden->user_data);
1699 wifi->hidden->user_data = NULL;
1700 hidden_free(wifi->hidden);
1701 wifi->hidden = NULL;
1706 static void network_removed(GSupplicantNetwork *network)
1708 GSupplicantInterface *interface;
1709 struct wifi_data *wifi;
1710 const char *name, *identifier;
1711 struct connman_network *connman_network;
1713 interface = g_supplicant_network_get_interface(network);
1714 wifi = g_supplicant_interface_get_data(interface);
1715 identifier = g_supplicant_network_get_identifier(network);
1716 name = g_supplicant_network_get_name(network);
1718 DBG("name %s", name);
1723 connman_network = connman_device_get_network(wifi->device, identifier);
1724 if (connman_network == NULL)
1727 wifi->networks = g_slist_remove(wifi->networks, connman_network);
1729 connman_device_remove_network(wifi->device, connman_network);
1730 connman_network_unref(connman_network);
1733 static void network_changed(GSupplicantNetwork *network, const char *property)
1735 GSupplicantInterface *interface;
1736 struct wifi_data *wifi;
1737 const char *name, *identifier;
1738 struct connman_network *connman_network;
1740 interface = g_supplicant_network_get_interface(network);
1741 wifi = g_supplicant_interface_get_data(interface);
1742 identifier = g_supplicant_network_get_identifier(network);
1743 name = g_supplicant_network_get_name(network);
1745 DBG("name %s", name);
1750 connman_network = connman_device_get_network(wifi->device, identifier);
1751 if (connman_network == NULL)
1754 if (g_str_equal(property, "Signal") == TRUE) {
1755 connman_network_set_strength(connman_network,
1756 calculate_strength(network));
1757 connman_network_update(connman_network);
1761 static void debug(const char *str)
1763 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
1764 connman_debug("%s", str);
1767 static const GSupplicantCallbacks callbacks = {
1768 .system_ready = system_ready,
1769 .system_killed = system_killed,
1770 .interface_added = interface_added,
1771 .interface_state = interface_state,
1772 .interface_removed = interface_removed,
1773 .scan_started = scan_started,
1774 .scan_finished = scan_finished,
1775 .network_added = network_added,
1776 .network_removed = network_removed,
1777 .network_changed = network_changed,
1782 static int tech_probe(struct connman_technology *technology)
1784 wifi_technology = technology;
1789 static void tech_remove(struct connman_technology *technology)
1791 wifi_technology = NULL;
1794 struct wifi_tethering_info {
1795 struct wifi_data *wifi;
1796 struct connman_technology *technology;
1798 GSupplicantSSID *ssid;
1801 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
1803 GSupplicantSSID *ap;
1805 ap = g_try_malloc0(sizeof(GSupplicantSSID));
1809 ap->mode = G_SUPPLICANT_MODE_MASTER;
1811 ap->ssid_len = strlen(ssid);
1815 if (passphrase == NULL || strlen(passphrase) == 0) {
1816 ap->security = G_SUPPLICANT_SECURITY_NONE;
1817 ap->passphrase = NULL;
1819 ap->security = G_SUPPLICANT_SECURITY_PSK;
1820 ap->protocol = G_SUPPLICANT_PROTO_RSN;
1821 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
1822 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
1823 ap->passphrase = passphrase;
1829 static void ap_start_callback(int result, GSupplicantInterface *interface,
1832 struct wifi_tethering_info *info = user_data;
1834 DBG("result %d index %d bridge %s",
1835 result, info->wifi->index, info->wifi->bridge);
1838 connman_inet_remove_from_bridge(info->wifi->index,
1839 info->wifi->bridge);
1840 connman_technology_tethering_notify(info->technology, FALSE);
1843 g_free(info->ifname);
1847 static void ap_create_callback(int result,
1848 GSupplicantInterface *interface,
1851 struct wifi_tethering_info *info = user_data;
1853 DBG("result %d ifname %s", result,
1854 g_supplicant_interface_get_ifname(interface));
1857 connman_inet_remove_from_bridge(info->wifi->index,
1858 info->wifi->bridge);
1859 connman_technology_tethering_notify(info->technology, FALSE);
1861 g_free(info->ifname);
1866 info->wifi->interface = interface;
1867 g_supplicant_interface_set_data(interface, info->wifi);
1869 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
1870 connman_error("Failed to set interface ap_scan property");
1872 g_supplicant_interface_connect(interface, info->ssid,
1873 ap_start_callback, info);
1876 static void sta_remove_callback(int result,
1877 GSupplicantInterface *interface,
1880 struct wifi_tethering_info *info = user_data;
1881 const char *driver = connman_option_get_string("wifi");
1883 DBG("ifname %s result %d ", info->ifname, result);
1886 info->wifi->tethering = TRUE;
1888 g_free(info->ifname);
1893 info->wifi->interface = NULL;
1895 connman_technology_tethering_notify(info->technology, TRUE);
1897 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
1902 static int tech_set_tethering(struct connman_technology *technology,
1903 const char *identifier, const char *passphrase,
1904 const char *bridge, connman_bool_t enabled)
1907 GSupplicantInterface *interface;
1908 struct wifi_data *wifi;
1909 struct wifi_tethering_info *info;
1916 if (enabled == FALSE) {
1917 for (list = iface_list; list; list = list->next) {
1920 if (wifi->tethering == TRUE) {
1921 wifi->tethering = FALSE;
1923 connman_inet_remove_from_bridge(wifi->index,
1925 wifi->bridged = FALSE;
1929 connman_technology_tethering_notify(technology, FALSE);
1934 for (list = iface_list; list; list = list->next) {
1937 interface = wifi->interface;
1939 if (interface == NULL)
1942 ifname = g_supplicant_interface_get_ifname(wifi->interface);
1944 mode = g_supplicant_interface_get_mode(interface);
1945 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
1946 DBG("%s does not support AP mode", ifname);
1950 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
1955 info->technology = technology;
1956 info->wifi->bridge = bridge;
1957 info->ssid = ssid_ap_init(identifier, passphrase);
1958 if (info->ssid == NULL) {
1962 info->ifname = g_strdup(ifname);
1963 if (info->ifname == NULL) {
1968 info->wifi->tethering = TRUE;
1970 err = g_supplicant_interface_remove(interface,
1971 sta_remove_callback,
1980 static void regdom_callback(int result, const char *alpha2, void *user_data)
1984 if (wifi_technology == NULL)
1990 connman_technology_regdom_notify(wifi_technology, alpha2);
1993 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
1995 return g_supplicant_set_country(alpha2, regdom_callback, NULL);
1998 static struct connman_technology_driver tech_driver = {
2000 .type = CONNMAN_SERVICE_TYPE_WIFI,
2001 .probe = tech_probe,
2002 .remove = tech_remove,
2003 .set_tethering = tech_set_tethering,
2004 .set_regdom = tech_set_regdom,
2007 static int wifi_init(void)
2011 err = connman_network_driver_register(&network_driver);
2015 err = g_supplicant_register(&callbacks);
2017 connman_network_driver_unregister(&network_driver);
2021 err = connman_technology_driver_register(&tech_driver);
2023 g_supplicant_unregister(&callbacks);
2024 connman_network_driver_unregister(&network_driver);
2031 static void wifi_exit(void)
2035 connman_technology_driver_unregister(&tech_driver);
2037 g_supplicant_unregister(&callbacks);
2039 connman_network_driver_unregister(&network_driver);
2042 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
2043 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)