5 * Copyright (C) 2007-2010 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
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>
37 #define IFF_LOWER_UP 0x10000
40 #include <dbus/dbus.h>
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>
52 #include <gsupplicant/gsupplicant.h>
54 #define CLEANUP_TIMEOUT 8 /* in seconds */
55 #define INACTIVE_TIMEOUT 12 /* in seconds */
57 struct connman_technology *wifi_technology = NULL;
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 connman_bool_t tethering;
74 static GList *iface_list = NULL;
76 static int get_bssid(struct connman_device *device,
77 unsigned char *bssid, unsigned int *bssid_len)
84 ifindex = connman_device_get_index(device);
88 ifname = connman_inet_ifname(ifindex);
92 fd = socket(PF_INET, SOCK_DGRAM, 0);
98 memset(&wrq, 0, sizeof(wrq));
99 strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
101 err = ioctl(fd, SIOCGIWAP, &wrq);
109 memcpy(bssid, wrq.u.ap_addr.sa_data, ETH_ALEN);
110 *bssid_len = ETH_ALEN;
115 static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
117 struct connman_device *device = user_data;
118 struct wifi_data *wifi = connman_device_get_data(device);
120 DBG("index %d flags %d change %d", wifi->index, flags, change);
125 if ((wifi->flags & IFF_UP) != (flags & IFF_UP)) {
129 DBG("interface down");
132 if ((wifi->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
133 if (flags & IFF_LOWER_UP)
142 static int wifi_probe(struct connman_device *device)
144 struct wifi_data *wifi;
146 DBG("device %p", device);
148 wifi = g_try_new0(struct wifi_data, 1);
152 wifi->connected = FALSE;
153 wifi->disconnecting = FALSE;
154 wifi->tethering = FALSE;
155 wifi->state = G_SUPPLICANT_STATE_INACTIVE;
157 connman_device_set_data(device, wifi);
158 wifi->device = connman_device_ref(device);
160 wifi->index = connman_device_get_index(device);
163 wifi->watch = connman_rtnl_add_newlink_watch(wifi->index,
164 wifi_newlink, device);
166 iface_list = g_list_append(iface_list, wifi);
171 static void wifi_remove(struct connman_device *device)
173 struct wifi_data *wifi = connman_device_get_data(device);
175 DBG("device %p", device);
180 iface_list = g_list_remove(iface_list, wifi);
182 if (wifi->pending_network != NULL) {
183 connman_network_unref(wifi->pending_network);
184 wifi->pending_network = NULL;
187 connman_device_set_data(device, NULL);
188 connman_device_unref(wifi->device);
189 connman_rtnl_remove_watch(wifi->watch);
191 g_supplicant_interface_set_data(wifi->interface, NULL);
193 g_free(wifi->identifier);
197 static void interface_create_callback(int result,
198 GSupplicantInterface *interface,
201 struct wifi_data *wifi = user_data;
203 DBG("result %d ifname %s", result,
204 g_supplicant_interface_get_ifname(interface));
209 wifi->interface = interface;
210 g_supplicant_interface_set_data(interface, wifi);
213 static void interface_remove_callback(int result,
214 GSupplicantInterface *interface,
217 struct wifi_data *wifi = user_data;
219 DBG("result %d", result);
224 wifi->interface = NULL;
228 static int wifi_enable(struct connman_device *device)
230 struct wifi_data *wifi = connman_device_get_data(device);
231 const char *interface = connman_device_get_string(device, "Interface");
232 const char *driver = connman_option_get_string("wifi");
234 DBG("device %p %p", device, wifi);
236 return g_supplicant_interface_create(interface, driver, NULL,
237 interface_create_callback,
241 static int wifi_disable(struct connman_device *device)
243 struct wifi_data *wifi = connman_device_get_data(device);
245 DBG("device %p", device);
247 wifi->connected = FALSE;
248 wifi->disconnecting = FALSE;
250 if (wifi->pending_network != NULL) {
251 connman_network_unref(wifi->pending_network);
252 wifi->pending_network = NULL;
255 return g_supplicant_interface_remove(wifi->interface,
256 interface_remove_callback,
260 static void scan_callback(int result, GSupplicantInterface *interface,
263 struct connman_device *device = user_data;
265 DBG("result %d", result);
268 connman_device_reset_scanning(device);
270 connman_device_set_scanning(device, FALSE);
273 static int wifi_scan(struct connman_device *device)
275 struct wifi_data *wifi = connman_device_get_data(device);
278 DBG("device %p %p", device, wifi->interface);
280 if (wifi->tethering == TRUE)
283 ret = g_supplicant_interface_scan(wifi->interface, scan_callback,
286 connman_device_set_scanning(device, TRUE);
291 static struct connman_device_driver wifi_ng_driver = {
293 .type = CONNMAN_DEVICE_TYPE_WIFI,
294 .priority = CONNMAN_DEVICE_PRIORITY_LOW,
296 .remove = wifi_remove,
297 .enable = wifi_enable,
298 .disable = wifi_disable,
302 static void system_ready(void)
306 if (connman_device_driver_register(&wifi_ng_driver) < 0)
307 connman_error("Failed to register WiFi driver");
310 static void system_killed(void)
314 connman_device_driver_unregister(&wifi_ng_driver);
317 static int network_probe(struct connman_network *network)
319 DBG("network %p", network);
324 static void network_remove(struct connman_network *network)
326 DBG("network %p", network);
329 static void connect_callback(int result, GSupplicantInterface *interface,
332 struct connman_network *network = user_data;
334 DBG("network %p result %d", network, result);
336 if (result == -ENOKEY) {
337 connman_network_set_error(network,
338 CONNMAN_NETWORK_ERROR_INVALID_KEY);
339 } else if (result < 0) {
340 connman_network_set_error(network,
341 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
345 static GSupplicantSecurity network_security(const char *security)
347 if (g_str_equal(security, "none") == TRUE)
348 return G_SUPPLICANT_SECURITY_NONE;
349 else if (g_str_equal(security, "wep") == TRUE)
350 return G_SUPPLICANT_SECURITY_WEP;
351 else if (g_str_equal(security, "psk") == TRUE)
352 return G_SUPPLICANT_SECURITY_PSK;
353 else if (g_str_equal(security, "wpa") == TRUE)
354 return G_SUPPLICANT_SECURITY_PSK;
355 else if (g_str_equal(security, "rsn") == TRUE)
356 return G_SUPPLICANT_SECURITY_PSK;
357 else if (g_str_equal(security, "ieee8021x") == TRUE)
358 return G_SUPPLICANT_SECURITY_IEEE8021X;
360 return G_SUPPLICANT_SECURITY_UNKNOWN;
363 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
365 const char *security, *passphrase;
367 memset(ssid, 0, sizeof(*ssid));
368 ssid->mode = G_SUPPLICANT_MODE_INFRA;
369 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
372 security = connman_network_get_string(network, "WiFi.Security");
373 ssid->security = network_security(security);
374 passphrase = connman_network_get_string(network,
376 if (passphrase == NULL || strlen(passphrase) == 0)
377 ssid->passphrase = NULL;
379 ssid->passphrase = passphrase;
381 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
384 * If our private key password is unset,
385 * we use the supplied passphrase. That is needed
386 * for PEAP where 2 passphrases (identity and client
387 * cert may have to be provided.
389 if (connman_network_get_string(network,
390 "WiFi.PrivateKeyPassphrase") == NULL)
391 connman_network_set_string(network,
392 "WiFi.PrivateKeyPassphrase",
394 /* We must have an identity for both PEAP and TLS */
395 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
396 ssid->ca_cert_path = connman_network_get_string(network,
398 ssid->client_cert_path = connman_network_get_string(network,
399 "WiFi.ClientCertFile");
400 ssid->private_key_path = connman_network_get_string(network,
401 "WiFi.PrivateKeyFile");
402 ssid->private_key_passphrase = connman_network_get_string(network,
403 "WiFi.PrivateKeyPassphrase");
404 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
406 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
407 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
411 static int network_connect(struct connman_network *network)
413 struct connman_device *device = connman_network_get_device(network);
414 struct wifi_data *wifi;
415 GSupplicantInterface *interface;
416 GSupplicantSSID *ssid;
418 DBG("network %p", network);
423 wifi = connman_device_get_data(device);
427 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
431 interface = wifi->interface;
433 ssid_init(ssid, network);
435 if (wifi->disconnecting == TRUE)
436 wifi->pending_network = connman_network_ref(network);
438 wifi->network = connman_network_ref(network);
440 return g_supplicant_interface_connect(interface, ssid,
441 connect_callback, network);
447 static void disconnect_callback(int result, GSupplicantInterface *interface,
450 struct wifi_data *wifi = user_data;
452 if (wifi->network != NULL) {
454 * if result < 0 supplican return an error because
455 * the network is not current.
456 * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
457 * failed, call connman_network_set_connected to report
458 * disconnect is completed.
461 connman_network_set_connected(wifi->network, FALSE);
463 connman_network_unref(wifi->network);
466 wifi->network = NULL;
468 wifi->disconnecting = FALSE;
470 if (wifi->pending_network != NULL) {
471 network_connect(wifi->pending_network);
472 connman_network_unref(wifi->pending_network);
473 wifi->pending_network = NULL;
478 static int network_disconnect(struct connman_network *network)
480 struct connman_device *device = connman_network_get_device(network);
481 struct wifi_data *wifi;
484 DBG("network %p", network);
486 wifi = connman_device_get_data(device);
487 if (wifi == NULL || wifi->interface == NULL)
490 connman_network_set_associating(network, FALSE);
492 if (wifi->disconnecting == TRUE)
495 wifi->disconnecting = TRUE;
497 err = g_supplicant_interface_disconnect(wifi->interface,
498 disconnect_callback, wifi);
500 wifi->disconnecting = FALSE;
505 static struct connman_network_driver network_driver = {
507 .type = CONNMAN_NETWORK_TYPE_WIFI,
508 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
509 .probe = network_probe,
510 .remove = network_remove,
511 .connect = network_connect,
512 .disconnect = network_disconnect,
515 static void interface_added(GSupplicantInterface *interface)
517 const char *ifname = g_supplicant_interface_get_ifname(interface);
518 const char *driver = g_supplicant_interface_get_driver(interface);
519 struct wifi_data *wifi;
521 wifi = g_supplicant_interface_get_data(interface);
524 * We can get here with a NULL wifi pointer when
525 * the interface added signal is sent before the
526 * interface creation callback is called.
531 DBG("ifname %s driver %s wifi %p tethering %d",
532 ifname, driver, wifi, wifi->tethering);
534 if (wifi->device == NULL) {
535 connman_error("WiFi device not set");
539 connman_device_set_powered(wifi->device, TRUE);
541 if (wifi->tethering == TRUE)
544 wifi_scan(wifi->device);
547 static connman_bool_t is_idle(struct wifi_data *wifi)
549 DBG("state %d", wifi->state);
551 switch (wifi->state) {
552 case G_SUPPLICANT_STATE_UNKNOWN:
553 case G_SUPPLICANT_STATE_DISCONNECTED:
554 case G_SUPPLICANT_STATE_INACTIVE:
555 case G_SUPPLICANT_STATE_SCANNING:
558 case G_SUPPLICANT_STATE_AUTHENTICATING:
559 case G_SUPPLICANT_STATE_ASSOCIATING:
560 case G_SUPPLICANT_STATE_ASSOCIATED:
561 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
562 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
563 case G_SUPPLICANT_STATE_COMPLETED:
570 static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
571 struct wifi_data *wifi)
573 /* First, let's check if WPS processing did not went wrong */
574 if (g_supplicant_interface_get_wps_state(interface) ==
575 G_SUPPLICANT_WPS_STATE_FAIL)
578 /* Unlike normal connection, being associated while processing wps
579 * actually means that we are idling. */
580 switch (wifi->state) {
581 case G_SUPPLICANT_STATE_UNKNOWN:
582 case G_SUPPLICANT_STATE_DISCONNECTED:
583 case G_SUPPLICANT_STATE_INACTIVE:
584 case G_SUPPLICANT_STATE_SCANNING:
585 case G_SUPPLICANT_STATE_ASSOCIATED:
587 case G_SUPPLICANT_STATE_AUTHENTICATING:
588 case G_SUPPLICANT_STATE_ASSOCIATING:
589 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
590 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
591 case G_SUPPLICANT_STATE_COMPLETED:
598 static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
599 struct connman_network *network,
600 struct connman_device *device,
601 struct wifi_data *wifi)
605 wps = connman_network_get_bool(network, "WiFi.UseWPS");
607 const unsigned char *ssid, *wps_ssid;
608 unsigned int ssid_len, wps_ssid_len;
611 /* Checking if we got associated with requested
613 ssid = connman_network_get_blob(network, "WiFi.SSID",
616 wps_ssid = g_supplicant_interface_get_wps_ssid(
617 interface, &wps_ssid_len);
619 if (wps_ssid == NULL || wps_ssid_len != ssid_len ||
620 memcmp(ssid, wps_ssid, ssid_len) != 0) {
621 connman_network_set_associating(network, FALSE);
622 g_supplicant_interface_disconnect(wifi->interface,
623 disconnect_callback, wifi);
627 wps_key = g_supplicant_interface_get_wps_key(interface);
628 connman_network_set_string(network, "WiFi.Passphrase",
631 connman_network_set_string(network, "WiFi.PinWPS", NULL);
637 static void interface_state(GSupplicantInterface *interface)
639 struct connman_network *network;
640 struct connman_device *device;
641 struct wifi_data *wifi;
642 GSupplicantState state = g_supplicant_interface_get_state(interface);
643 unsigned char bssid[ETH_ALEN];
644 unsigned int bssid_len;
647 wifi = g_supplicant_interface_get_data(interface);
649 DBG("wifi %p interface state %d", wifi, state);
654 network = wifi->network;
655 device = wifi->device;
657 if (device == NULL || network == NULL)
661 case G_SUPPLICANT_STATE_SCANNING:
664 case G_SUPPLICANT_STATE_AUTHENTICATING:
665 case G_SUPPLICANT_STATE_ASSOCIATING:
666 connman_network_set_associating(network, TRUE);
669 case G_SUPPLICANT_STATE_COMPLETED:
670 if (handle_wps_completion(interface, network, device, wifi) ==
674 /* reset scan trigger and schedule background scan */
675 connman_device_schedule_scan(device);
677 if (get_bssid(device, bssid, &bssid_len) == 0)
678 connman_network_set_address(network,
680 connman_network_set_connected(network, TRUE);
683 case G_SUPPLICANT_STATE_DISCONNECTED:
685 * If we're in one of the idle modes, we have
686 * not started association yet and thus setting
687 * those ones to FALSE could cancel an association
690 wps = connman_network_get_bool(network, "WiFi.UseWPS");
692 if (is_idle_wps(interface, wifi) == TRUE)
697 connman_network_set_associating(network, FALSE);
698 connman_network_set_connected(network, FALSE);
701 case G_SUPPLICANT_STATE_INACTIVE:
702 connman_network_set_associating(network, FALSE);
705 case G_SUPPLICANT_STATE_UNKNOWN:
706 case G_SUPPLICANT_STATE_ASSOCIATED:
707 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
708 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
717 static void interface_removed(GSupplicantInterface *interface)
719 const char *ifname = g_supplicant_interface_get_ifname(interface);
720 struct wifi_data *wifi;
722 DBG("ifname %s", ifname);
724 wifi = g_supplicant_interface_get_data(interface);
726 if (wifi != NULL && wifi->tethering == TRUE)
729 if (wifi == NULL || wifi->device == NULL) {
730 connman_error("Wrong wifi pointer");
734 connman_device_set_powered(wifi->device, FALSE);
737 static void scan_started(GSupplicantInterface *interface)
739 struct wifi_data *wifi;
743 wifi = g_supplicant_interface_get_data(interface);
749 static void scan_finished(GSupplicantInterface *interface)
751 struct wifi_data *wifi;
755 wifi = g_supplicant_interface_get_data(interface);
761 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
763 unsigned char strength;
765 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
772 static void network_added(GSupplicantNetwork *supplicant_network)
774 struct connman_network *network;
775 GSupplicantInterface *interface;
776 struct wifi_data *wifi;
777 const char *name, *identifier, *mode, *security, *group;
778 const unsigned char *ssid;
779 unsigned int ssid_len;
784 interface = g_supplicant_network_get_interface(supplicant_network);
785 wifi = g_supplicant_interface_get_data(interface);
786 name = g_supplicant_network_get_name(supplicant_network);
787 identifier = g_supplicant_network_get_identifier(supplicant_network);
788 mode = g_supplicant_network_get_mode(supplicant_network);
789 security = g_supplicant_network_get_security(supplicant_network);
790 group = g_supplicant_network_get_identifier(supplicant_network);
791 wps = g_supplicant_network_get_wps(supplicant_network);
796 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
798 network = connman_device_get_network(wifi->device, identifier);
800 if (network == NULL) {
801 network = connman_network_create(identifier,
802 CONNMAN_NETWORK_TYPE_WIFI);
806 connman_network_set_index(network, wifi->index);
808 if (connman_device_add_network(wifi->device, network) < 0) {
809 connman_network_unref(network);
814 if (name != NULL && name[0] != '\0')
815 connman_network_set_name(network, name);
817 connman_network_set_blob(network, "WiFi.SSID",
819 connman_network_set_string(network, "WiFi.Mode", mode);
820 connman_network_set_string(network, "WiFi.Security", security);
821 connman_network_set_strength(network,
822 calculate_strength(supplicant_network));
823 connman_network_set_bool(network, "WiFi.WPS", wps);
825 connman_network_set_available(network, TRUE);
828 connman_network_set_group(network, group);
831 static void network_removed(GSupplicantNetwork *network)
833 GSupplicantInterface *interface;
834 struct wifi_data *wifi;
835 const char *name, *identifier;
837 interface = g_supplicant_network_get_interface(network);
838 wifi = g_supplicant_interface_get_data(interface);
839 identifier = g_supplicant_network_get_identifier(network);
840 name = g_supplicant_network_get_name(network);
842 DBG("name %s", name);
845 connman_device_remove_network(wifi->device, identifier);
848 static void debug(const char *str)
850 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
851 connman_debug("%s", str);
854 static const GSupplicantCallbacks callbacks = {
855 .system_ready = system_ready,
856 .system_killed = system_killed,
857 .interface_added = interface_added,
858 .interface_state = interface_state,
859 .interface_removed = interface_removed,
860 .scan_started = scan_started,
861 .scan_finished = scan_finished,
862 .network_added = network_added,
863 .network_removed = network_removed,
868 static int tech_probe(struct connman_technology *technology)
870 wifi_technology = technology;
875 static void tech_remove(struct connman_technology *technology)
877 wifi_technology = NULL;
880 struct wifi_tethering_info {
881 struct wifi_data *wifi;
882 struct connman_technology *technology;
885 GSupplicantSSID *ssid;
888 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
892 ap = g_try_malloc0(sizeof(GSupplicantSSID));
896 ap->mode = G_SUPPLICANT_MODE_MASTER;
898 ap->ssid_len = strlen(ssid);
902 if (passphrase == NULL || strlen(passphrase) == 0) {
903 ap->security = G_SUPPLICANT_SECURITY_NONE;
904 ap->passphrase = NULL;
906 ap->security = G_SUPPLICANT_SECURITY_PSK;
907 ap->protocol = G_SUPPLICANT_PROTO_RSN;
908 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
909 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
910 ap->passphrase = passphrase;
916 static void ap_start_callback(int result, GSupplicantInterface *interface,
919 struct wifi_tethering_info *info = user_data;
921 DBG("result %d index %d bridge %s",
922 result, info->wifi->index, info->bridge);
925 connman_inet_remove_from_bridge(info->wifi->index,
927 connman_technology_tethering_notify(info->technology, FALSE);
930 g_free(info->ifname);
934 static void ap_create_callback(int result,
935 GSupplicantInterface *interface,
938 struct wifi_tethering_info *info = user_data;
939 struct connman_technology *technology;
941 DBG("result %d ifname %s", result,
942 g_supplicant_interface_get_ifname(interface));
945 connman_inet_remove_from_bridge(info->wifi->index,
947 connman_technology_tethering_notify(info->technology, FALSE);
949 g_free(info->ifname);
954 info->wifi->interface = interface;
955 technology = info->technology;
956 g_supplicant_interface_set_data(interface, info->wifi);
958 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
959 connman_error("Failed to set interface ap_scan property");
961 g_supplicant_interface_connect(interface, info->ssid,
962 ap_start_callback, info);
965 static void sta_remove_callback(int result,
966 GSupplicantInterface *interface,
969 struct wifi_tethering_info *info = user_data;
970 const char *driver = connman_option_get_string("wifi");
972 DBG("ifname %s result %d ", info->ifname, result);
975 info->wifi->tethering = TRUE;
977 g_free(info->ifname);
982 info->wifi->interface = NULL;
984 connman_technology_tethering_notify(info->technology, TRUE);
985 connman_inet_add_to_bridge(info->wifi->index, info->bridge);
987 g_supplicant_interface_create(info->ifname, driver, info->bridge,
992 static int tech_set_tethering(struct connman_technology *technology,
993 const char *identifier, const char *passphrase,
994 const char *bridge, connman_bool_t enabled)
997 GSupplicantInterface *interface;
998 struct wifi_data *wifi;
999 struct wifi_tethering_info *info;
1006 if (enabled == FALSE) {
1007 for (list = iface_list; list; list = list->next) {
1010 if (wifi->tethering == TRUE) {
1011 wifi->tethering = FALSE;
1013 connman_inet_remove_from_bridge(wifi->index,
1018 connman_technology_tethering_notify(technology, FALSE);
1023 for (list = iface_list; list; list = list->next) {
1026 interface = wifi->interface;
1028 if (interface == NULL)
1031 ifname = g_supplicant_interface_get_ifname(wifi->interface);
1033 mode = g_supplicant_interface_get_mode(interface);
1034 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
1035 DBG("%s does not support AP mode", ifname);
1039 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
1044 info->technology = technology;
1045 info->bridge = bridge;
1046 info->ssid = ssid_ap_init(identifier, passphrase);
1047 if (info->ssid == NULL) {
1051 info->ifname = g_strdup(ifname);
1052 if (info->ifname == NULL) {
1057 info->wifi->tethering = TRUE;
1059 err = g_supplicant_interface_remove(interface,
1060 sta_remove_callback,
1069 static void regdom_callback(void *user_data)
1071 char *alpha2 = user_data;
1075 if (wifi_technology == NULL)
1078 connman_technology_regdom_notify(wifi_technology, alpha2);
1081 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
1083 return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
1086 static struct connman_technology_driver tech_driver = {
1088 .type = CONNMAN_SERVICE_TYPE_WIFI,
1089 .probe = tech_probe,
1090 .remove = tech_remove,
1091 .set_tethering = tech_set_tethering,
1092 .set_regdom = tech_set_regdom,
1095 static int wifi_init(void)
1099 err = connman_network_driver_register(&network_driver);
1103 err = g_supplicant_register(&callbacks);
1105 connman_network_driver_unregister(&network_driver);
1109 err = connman_technology_driver_register(&tech_driver);
1111 g_supplicant_unregister(&callbacks);
1112 connman_network_driver_unregister(&network_driver);
1119 static void wifi_exit(void)
1123 connman_technology_driver_unregister(&tech_driver);
1125 g_supplicant_unregister(&callbacks);
1127 connman_network_driver_unregister(&network_driver);
1130 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
1131 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)