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 connman_error("%s", __func__);
335 static GSupplicantSecurity network_security(const char *security)
337 if (g_str_equal(security, "none") == TRUE)
338 return G_SUPPLICANT_SECURITY_NONE;
339 else if (g_str_equal(security, "wep") == TRUE)
340 return G_SUPPLICANT_SECURITY_WEP;
341 else if (g_str_equal(security, "psk") == TRUE)
342 return G_SUPPLICANT_SECURITY_PSK;
343 else if (g_str_equal(security, "wpa") == TRUE)
344 return G_SUPPLICANT_SECURITY_PSK;
345 else if (g_str_equal(security, "rsn") == TRUE)
346 return G_SUPPLICANT_SECURITY_PSK;
347 else if (g_str_equal(security, "ieee8021x") == TRUE)
348 return G_SUPPLICANT_SECURITY_IEEE8021X;
350 return G_SUPPLICANT_SECURITY_UNKNOWN;
353 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
355 const char *security, *passphrase;
357 memset(ssid, 0, sizeof(*ssid));
358 ssid->mode = G_SUPPLICANT_MODE_INFRA;
359 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
362 security = connman_network_get_string(network, "WiFi.Security");
363 ssid->security = network_security(security);
364 passphrase = connman_network_get_string(network,
366 if (passphrase == NULL || strlen(passphrase) == 0)
367 ssid->passphrase = NULL;
369 ssid->passphrase = passphrase;
371 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
374 * If our private key password is unset,
375 * we use the supplied passphrase. That is needed
376 * for PEAP where 2 passphrases (identity and client
377 * cert may have to be provided.
379 if (connman_network_get_string(network,
380 "WiFi.PrivateKeyPassphrase") == NULL)
381 connman_network_set_string(network,
382 "WiFi.PrivateKeyPassphrase",
384 /* We must have an identity for both PEAP and TLS */
385 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
386 ssid->ca_cert_path = connman_network_get_string(network,
388 ssid->client_cert_path = connman_network_get_string(network,
389 "WiFi.ClientCertFile");
390 ssid->private_key_path = connman_network_get_string(network,
391 "WiFi.PrivateKeyFile");
392 ssid->private_key_passphrase = connman_network_get_string(network,
393 "WiFi.PrivateKeyPassphrase");
394 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
396 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
397 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
401 static int network_connect(struct connman_network *network)
403 struct connman_device *device = connman_network_get_device(network);
404 struct wifi_data *wifi;
405 GSupplicantInterface *interface;
406 GSupplicantSSID *ssid;
408 DBG("network %p", network);
413 wifi = connman_device_get_data(device);
417 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
421 interface = wifi->interface;
423 ssid_init(ssid, network);
425 if (wifi->disconnecting == TRUE)
426 wifi->pending_network = connman_network_ref(network);
428 wifi->network = connman_network_ref(network);
430 return g_supplicant_interface_connect(interface, ssid,
431 connect_callback, NULL);
437 static void disconnect_callback(int result, GSupplicantInterface *interface,
440 struct wifi_data *wifi = user_data;
442 if (wifi->network != NULL) {
444 * if result < 0 supplican return an error because
445 * the network is not current.
446 * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
447 * failed, call connman_network_set_connected to report
448 * disconnect is completed.
451 connman_network_set_connected(wifi->network, FALSE);
453 connman_network_unref(wifi->network);
456 wifi->network = NULL;
458 wifi->disconnecting = FALSE;
460 if (wifi->pending_network != NULL) {
461 network_connect(wifi->pending_network);
462 connman_network_unref(wifi->pending_network);
463 wifi->pending_network = NULL;
468 static int network_disconnect(struct connman_network *network)
470 struct connman_device *device = connman_network_get_device(network);
471 struct wifi_data *wifi;
474 DBG("network %p", network);
476 wifi = connman_device_get_data(device);
477 if (wifi == NULL || wifi->interface == NULL)
480 connman_network_set_associating(network, FALSE);
482 if (wifi->disconnecting == TRUE)
485 wifi->disconnecting = TRUE;
487 err = g_supplicant_interface_disconnect(wifi->interface,
488 disconnect_callback, wifi);
490 wifi->disconnecting = FALSE;
495 static struct connman_network_driver network_driver = {
497 .type = CONNMAN_NETWORK_TYPE_WIFI,
498 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
499 .probe = network_probe,
500 .remove = network_remove,
501 .connect = network_connect,
502 .disconnect = network_disconnect,
505 static void interface_added(GSupplicantInterface *interface)
507 const char *ifname = g_supplicant_interface_get_ifname(interface);
508 const char *driver = g_supplicant_interface_get_driver(interface);
509 struct wifi_data *wifi;
511 wifi = g_supplicant_interface_get_data(interface);
514 * We can get here with a NULL wifi pointer when
515 * the interface added signal is sent before the
516 * interface creation callback is called.
521 DBG("ifname %s driver %s wifi %p tethering %d",
522 ifname, driver, wifi, wifi->tethering);
524 if (wifi->device == NULL) {
525 connman_error("WiFi device not set");
529 connman_device_set_powered(wifi->device, TRUE);
531 if (wifi->tethering == TRUE)
534 wifi_scan(wifi->device);
537 static connman_bool_t is_idle(struct wifi_data *wifi)
539 DBG("state %d", wifi->state);
541 switch (wifi->state) {
542 case G_SUPPLICANT_STATE_UNKNOWN:
543 case G_SUPPLICANT_STATE_DISCONNECTED:
544 case G_SUPPLICANT_STATE_INACTIVE:
545 case G_SUPPLICANT_STATE_SCANNING:
548 case G_SUPPLICANT_STATE_AUTHENTICATING:
549 case G_SUPPLICANT_STATE_ASSOCIATING:
550 case G_SUPPLICANT_STATE_ASSOCIATED:
551 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
552 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
553 case G_SUPPLICANT_STATE_COMPLETED:
560 static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
561 struct wifi_data *wifi)
563 /* First, let's check if WPS processing did not went wrong */
564 if (g_supplicant_interface_get_wps_state(interface) ==
565 G_SUPPLICANT_WPS_STATE_FAIL)
568 /* Unlike normal connection, being associated while processing wps
569 * actually means that we are idling. */
570 switch (wifi->state) {
571 case G_SUPPLICANT_STATE_UNKNOWN:
572 case G_SUPPLICANT_STATE_DISCONNECTED:
573 case G_SUPPLICANT_STATE_INACTIVE:
574 case G_SUPPLICANT_STATE_SCANNING:
575 case G_SUPPLICANT_STATE_ASSOCIATED:
577 case G_SUPPLICANT_STATE_AUTHENTICATING:
578 case G_SUPPLICANT_STATE_ASSOCIATING:
579 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
580 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
581 case G_SUPPLICANT_STATE_COMPLETED:
588 static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
589 struct connman_network *network,
590 struct connman_device *device,
591 struct wifi_data *wifi)
595 wps = connman_network_get_bool(network, "WiFi.UseWPS");
597 const unsigned char *ssid, *wps_ssid;
598 unsigned int ssid_len, wps_ssid_len;
601 /* Checking if we got associated with requested
603 ssid = connman_network_get_blob(network, "WiFi.SSID",
606 wps_ssid = g_supplicant_interface_get_wps_ssid(
607 interface, &wps_ssid_len);
609 if (wps_ssid == NULL || wps_ssid_len != ssid_len ||
610 memcmp(ssid, wps_ssid, ssid_len) != 0) {
611 connman_network_set_associating(network, FALSE);
612 g_supplicant_interface_disconnect(wifi->interface,
613 disconnect_callback, wifi);
617 wps_key = g_supplicant_interface_get_wps_key(interface);
618 connman_network_set_string(network, "WiFi.Passphrase",
621 connman_network_set_string(network, "WiFi.PinWPS", NULL);
627 static void interface_state(GSupplicantInterface *interface)
629 struct connman_network *network;
630 struct connman_device *device;
631 struct wifi_data *wifi;
632 GSupplicantState state = g_supplicant_interface_get_state(interface);
633 unsigned char bssid[ETH_ALEN];
634 unsigned int bssid_len;
637 wifi = g_supplicant_interface_get_data(interface);
639 DBG("wifi %p interface state %d", wifi, state);
644 network = wifi->network;
645 device = wifi->device;
647 if (device == NULL || network == NULL)
651 case G_SUPPLICANT_STATE_SCANNING:
654 case G_SUPPLICANT_STATE_AUTHENTICATING:
655 case G_SUPPLICANT_STATE_ASSOCIATING:
656 connman_network_set_associating(network, TRUE);
659 case G_SUPPLICANT_STATE_COMPLETED:
660 if (handle_wps_completion(interface, network, device, wifi) ==
664 /* reset scan trigger and schedule background scan */
665 connman_device_schedule_scan(device);
667 if (get_bssid(device, bssid, &bssid_len) == 0)
668 connman_network_set_address(network,
670 connman_network_set_connected(network, TRUE);
673 case G_SUPPLICANT_STATE_DISCONNECTED:
675 * If we're in one of the idle modes, we have
676 * not started association yet and thus setting
677 * those ones to FALSE could cancel an association
680 wps = connman_network_get_bool(network, "WiFi.UseWPS");
682 if (is_idle_wps(interface, wifi) == TRUE)
687 connman_network_set_associating(network, FALSE);
688 connman_network_set_connected(network, FALSE);
691 case G_SUPPLICANT_STATE_INACTIVE:
692 connman_network_set_associating(network, FALSE);
695 case G_SUPPLICANT_STATE_UNKNOWN:
696 case G_SUPPLICANT_STATE_ASSOCIATED:
697 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
698 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
707 static void interface_removed(GSupplicantInterface *interface)
709 const char *ifname = g_supplicant_interface_get_ifname(interface);
710 struct wifi_data *wifi;
712 DBG("ifname %s", ifname);
714 wifi = g_supplicant_interface_get_data(interface);
716 if (wifi != NULL && wifi->tethering == TRUE)
719 if (wifi == NULL || wifi->device == NULL) {
720 connman_error("Wrong wifi pointer");
724 connman_device_set_powered(wifi->device, FALSE);
727 static void scan_started(GSupplicantInterface *interface)
729 struct wifi_data *wifi;
733 wifi = g_supplicant_interface_get_data(interface);
739 static void scan_finished(GSupplicantInterface *interface)
741 struct wifi_data *wifi;
745 wifi = g_supplicant_interface_get_data(interface);
751 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
753 unsigned char strength;
755 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
762 static void network_added(GSupplicantNetwork *supplicant_network)
764 struct connman_network *network;
765 GSupplicantInterface *interface;
766 struct wifi_data *wifi;
767 const char *name, *identifier, *mode, *security, *group;
768 const unsigned char *ssid;
769 unsigned int ssid_len;
774 interface = g_supplicant_network_get_interface(supplicant_network);
775 wifi = g_supplicant_interface_get_data(interface);
776 name = g_supplicant_network_get_name(supplicant_network);
777 identifier = g_supplicant_network_get_identifier(supplicant_network);
778 mode = g_supplicant_network_get_mode(supplicant_network);
779 security = g_supplicant_network_get_security(supplicant_network);
780 group = g_supplicant_network_get_identifier(supplicant_network);
781 wps = g_supplicant_network_get_wps(supplicant_network);
786 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
788 network = connman_device_get_network(wifi->device, identifier);
790 if (network == NULL) {
791 network = connman_network_create(identifier,
792 CONNMAN_NETWORK_TYPE_WIFI);
796 connman_network_set_index(network, wifi->index);
798 if (connman_device_add_network(wifi->device, network) < 0) {
799 connman_network_unref(network);
804 if (name != NULL && name[0] != '\0')
805 connman_network_set_name(network, name);
807 connman_network_set_blob(network, "WiFi.SSID",
809 connman_network_set_string(network, "WiFi.Mode", mode);
810 connman_network_set_string(network, "WiFi.Security", security);
811 connman_network_set_strength(network,
812 calculate_strength(supplicant_network));
813 connman_network_set_bool(network, "WiFi.WPS", wps);
815 connman_network_set_available(network, TRUE);
818 connman_network_set_group(network, group);
821 static void network_removed(GSupplicantNetwork *network)
823 GSupplicantInterface *interface;
824 struct wifi_data *wifi;
825 const char *name, *identifier;
827 interface = g_supplicant_network_get_interface(network);
828 wifi = g_supplicant_interface_get_data(interface);
829 identifier = g_supplicant_network_get_identifier(network);
830 name = g_supplicant_network_get_name(network);
832 DBG("name %s", name);
835 connman_device_remove_network(wifi->device, identifier);
838 static void debug(const char *str)
840 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
841 connman_debug("%s", str);
844 static const GSupplicantCallbacks callbacks = {
845 .system_ready = system_ready,
846 .system_killed = system_killed,
847 .interface_added = interface_added,
848 .interface_state = interface_state,
849 .interface_removed = interface_removed,
850 .scan_started = scan_started,
851 .scan_finished = scan_finished,
852 .network_added = network_added,
853 .network_removed = network_removed,
858 static int tech_probe(struct connman_technology *technology)
860 wifi_technology = technology;
865 static void tech_remove(struct connman_technology *technology)
867 wifi_technology = NULL;
870 struct wifi_tethering_info {
871 struct wifi_data *wifi;
872 struct connman_technology *technology;
875 GSupplicantSSID *ssid;
878 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
882 ap = g_try_malloc0(sizeof(GSupplicantSSID));
886 ap->mode = G_SUPPLICANT_MODE_MASTER;
888 ap->ssid_len = strlen(ssid);
892 if (passphrase == NULL || strlen(passphrase) == 0) {
893 ap->security = G_SUPPLICANT_SECURITY_NONE;
894 ap->passphrase = NULL;
896 ap->security = G_SUPPLICANT_SECURITY_PSK;
897 ap->protocol = G_SUPPLICANT_PROTO_RSN;
898 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
899 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
900 ap->passphrase = passphrase;
906 static void ap_start_callback(int result, GSupplicantInterface *interface,
909 struct wifi_tethering_info *info = user_data;
911 DBG("result %d index %d bridge %s",
912 result, info->wifi->index, info->bridge);
915 connman_inet_remove_from_bridge(info->wifi->index,
917 connman_technology_tethering_notify(info->technology, FALSE);
920 g_free(info->ifname);
924 static void ap_create_callback(int result,
925 GSupplicantInterface *interface,
928 struct wifi_tethering_info *info = user_data;
929 struct connman_technology *technology;
931 DBG("result %d ifname %s", result,
932 g_supplicant_interface_get_ifname(interface));
935 connman_inet_remove_from_bridge(info->wifi->index,
937 connman_technology_tethering_notify(info->technology, FALSE);
939 g_free(info->ifname);
944 info->wifi->interface = interface;
945 technology = info->technology;
946 g_supplicant_interface_set_data(interface, info->wifi);
948 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
949 connman_error("Failed to set interface ap_scan property");
951 g_supplicant_interface_connect(interface, info->ssid,
952 ap_start_callback, info);
955 static void sta_remove_callback(int result,
956 GSupplicantInterface *interface,
959 struct wifi_tethering_info *info = user_data;
960 const char *driver = connman_option_get_string("wifi");
962 DBG("ifname %s result %d ", info->ifname, result);
965 info->wifi->tethering = TRUE;
967 g_free(info->ifname);
972 info->wifi->interface = NULL;
974 connman_technology_tethering_notify(info->technology, TRUE);
975 connman_inet_add_to_bridge(info->wifi->index, info->bridge);
977 g_supplicant_interface_create(info->ifname, driver, info->bridge,
982 static int tech_set_tethering(struct connman_technology *technology,
983 const char *identifier, const char *passphrase,
984 const char *bridge, connman_bool_t enabled)
987 GSupplicantInterface *interface;
988 struct wifi_data *wifi;
989 struct wifi_tethering_info *info;
995 if (enabled == FALSE) {
996 for (list = iface_list; list; list = list->next) {
999 if (wifi->tethering == TRUE)
1000 wifi->tethering = FALSE;
1003 connman_technology_tethering_notify(technology, FALSE);
1008 for (list = iface_list; list; list = list->next) {
1011 interface = wifi->interface;
1013 if (interface == NULL)
1016 ifname = g_supplicant_interface_get_ifname(wifi->interface);
1018 mode = g_supplicant_interface_get_mode(interface);
1019 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
1020 DBG("ifname does not support AP mode");
1024 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
1029 info->technology = technology;
1030 info->bridge = bridge;
1031 info->ssid = ssid_ap_init(identifier, passphrase);
1032 if (info->ssid == NULL) {
1036 info->ifname = g_strdup(ifname);
1037 if (info->ifname == NULL) {
1042 info->wifi->tethering = TRUE;
1044 return g_supplicant_interface_remove(interface,
1045 sta_remove_callback,
1052 static void regdom_callback(void *user_data)
1054 char *alpha2 = user_data;
1058 if (wifi_technology == NULL)
1061 connman_technology_regdom_notify(wifi_technology, alpha2);
1064 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
1066 return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
1069 static struct connman_technology_driver tech_driver = {
1071 .type = CONNMAN_SERVICE_TYPE_WIFI,
1072 .probe = tech_probe,
1073 .remove = tech_remove,
1074 .set_tethering = tech_set_tethering,
1075 .set_regdom = tech_set_regdom,
1078 static int wifi_init(void)
1082 err = connman_network_driver_register(&network_driver);
1086 err = g_supplicant_register(&callbacks);
1088 connman_network_driver_unregister(&network_driver);
1092 err = connman_technology_driver_register(&tech_driver);
1094 g_supplicant_unregister(&callbacks);
1095 connman_network_driver_unregister(&network_driver);
1102 static void wifi_exit(void)
1106 connman_technology_driver_unregister(&tech_driver);
1108 g_supplicant_unregister(&callbacks);
1110 connman_network_driver_unregister(&network_driver);
1113 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
1114 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)