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;
65 GSupplicantInterface *interface;
66 GSupplicantState state;
67 connman_bool_t connected;
68 connman_bool_t disconnecting;
69 connman_bool_t tethering;
70 connman_bool_t bridged;
77 static GList *iface_list = NULL;
79 static void handle_tethering(struct wifi_data *wifi)
81 if (wifi->tethering == FALSE)
84 if (wifi->bridge == NULL)
87 if (wifi->bridged == TRUE)
90 DBG("index %d bridge %s", wifi->index, wifi->bridge);
92 if (connman_inet_add_to_bridge(wifi->index, wifi->bridge) < 0)
98 static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
100 struct connman_device *device = user_data;
101 struct wifi_data *wifi = connman_device_get_data(device);
103 DBG("index %d flags %d change %d", wifi->index, flags, change);
108 if ((wifi->flags & IFF_UP) != (flags & IFF_UP)) {
112 DBG("interface down");
115 if ((wifi->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
116 if (flags & IFF_LOWER_UP) {
119 handle_tethering(wifi);
127 static int wifi_probe(struct connman_device *device)
129 struct wifi_data *wifi;
131 DBG("device %p", device);
133 wifi = g_try_new0(struct wifi_data, 1);
137 wifi->connected = FALSE;
138 wifi->disconnecting = FALSE;
139 wifi->tethering = FALSE;
140 wifi->bridged = FALSE;
142 wifi->state = G_SUPPLICANT_STATE_INACTIVE;
144 connman_device_set_data(device, wifi);
145 wifi->device = connman_device_ref(device);
147 wifi->index = connman_device_get_index(device);
150 wifi->watch = connman_rtnl_add_newlink_watch(wifi->index,
151 wifi_newlink, device);
153 iface_list = g_list_append(iface_list, wifi);
158 static void remove_networks(struct connman_device *device,
159 struct wifi_data *wifi)
163 for (list = wifi->networks; list != NULL; list = list->next) {
164 struct connman_network *network = list->data;
166 connman_device_remove_network(device, network);
167 connman_network_unref(network);
170 g_slist_free(wifi->networks);
171 wifi->networks = NULL;
174 static void wifi_remove(struct connman_device *device)
176 struct wifi_data *wifi = connman_device_get_data(device);
178 DBG("device %p", device);
183 iface_list = g_list_remove(iface_list, wifi);
185 remove_networks(device, wifi);
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");
235 DBG("device %p %p", device, wifi);
237 ret = g_supplicant_interface_create(interface, driver, NULL,
238 interface_create_callback,
246 static int wifi_disable(struct connman_device *device)
248 struct wifi_data *wifi = connman_device_get_data(device);
251 DBG("device %p", device);
253 wifi->connected = FALSE;
254 wifi->disconnecting = FALSE;
256 if (wifi->pending_network != NULL)
257 wifi->pending_network = NULL;
259 remove_networks(device, wifi);
261 ret = g_supplicant_interface_remove(wifi->interface,
262 interface_remove_callback,
270 static void scan_callback(int result, GSupplicantInterface *interface,
273 struct connman_device *device = user_data;
275 DBG("result %d", result);
278 connman_device_reset_scanning(device);
280 connman_device_set_scanning(device, FALSE);
283 static int wifi_scan(struct connman_device *device)
285 struct wifi_data *wifi = connman_device_get_data(device);
288 DBG("device %p %p", device, wifi->interface);
290 if (wifi->tethering == TRUE)
293 ret = g_supplicant_interface_scan(wifi->interface, scan_callback,
296 connman_device_set_scanning(device, TRUE);
301 static struct connman_device_driver wifi_ng_driver = {
303 .type = CONNMAN_DEVICE_TYPE_WIFI,
304 .priority = CONNMAN_DEVICE_PRIORITY_LOW,
306 .remove = wifi_remove,
307 .enable = wifi_enable,
308 .disable = wifi_disable,
312 static void system_ready(void)
316 if (connman_device_driver_register(&wifi_ng_driver) < 0)
317 connman_error("Failed to register WiFi driver");
320 static void system_killed(void)
324 connman_device_driver_unregister(&wifi_ng_driver);
327 static int network_probe(struct connman_network *network)
329 DBG("network %p", network);
334 static void network_remove(struct connman_network *network)
336 DBG("network %p", network);
339 static void connect_callback(int result, GSupplicantInterface *interface,
342 struct connman_network *network = user_data;
344 DBG("network %p result %d", network, result);
346 if (result == -ENOKEY) {
347 connman_network_set_error(network,
348 CONNMAN_NETWORK_ERROR_INVALID_KEY);
349 } else if (result < 0) {
350 connman_network_set_error(network,
351 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
355 static GSupplicantSecurity network_security(const char *security)
357 if (g_str_equal(security, "none") == TRUE)
358 return G_SUPPLICANT_SECURITY_NONE;
359 else if (g_str_equal(security, "wep") == TRUE)
360 return G_SUPPLICANT_SECURITY_WEP;
361 else if (g_str_equal(security, "psk") == TRUE)
362 return G_SUPPLICANT_SECURITY_PSK;
363 else if (g_str_equal(security, "wpa") == TRUE)
364 return G_SUPPLICANT_SECURITY_PSK;
365 else if (g_str_equal(security, "rsn") == TRUE)
366 return G_SUPPLICANT_SECURITY_PSK;
367 else if (g_str_equal(security, "ieee8021x") == TRUE)
368 return G_SUPPLICANT_SECURITY_IEEE8021X;
370 return G_SUPPLICANT_SECURITY_UNKNOWN;
373 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
375 const char *security, *passphrase;
377 memset(ssid, 0, sizeof(*ssid));
378 ssid->mode = G_SUPPLICANT_MODE_INFRA;
379 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
382 security = connman_network_get_string(network, "WiFi.Security");
383 ssid->security = network_security(security);
384 passphrase = connman_network_get_string(network,
386 if (passphrase == NULL || strlen(passphrase) == 0)
387 ssid->passphrase = NULL;
389 ssid->passphrase = passphrase;
391 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
394 * If our private key password is unset,
395 * we use the supplied passphrase. That is needed
396 * for PEAP where 2 passphrases (identity and client
397 * cert may have to be provided.
399 if (connman_network_get_string(network,
400 "WiFi.PrivateKeyPassphrase") == NULL)
401 connman_network_set_string(network,
402 "WiFi.PrivateKeyPassphrase",
404 /* We must have an identity for both PEAP and TLS */
405 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
406 ssid->ca_cert_path = connman_network_get_string(network,
408 ssid->client_cert_path = connman_network_get_string(network,
409 "WiFi.ClientCertFile");
410 ssid->private_key_path = connman_network_get_string(network,
411 "WiFi.PrivateKeyFile");
412 ssid->private_key_passphrase = connman_network_get_string(network,
413 "WiFi.PrivateKeyPassphrase");
414 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
416 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
417 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
421 static int network_connect(struct connman_network *network)
423 struct connman_device *device = connman_network_get_device(network);
424 struct wifi_data *wifi;
425 GSupplicantInterface *interface;
426 GSupplicantSSID *ssid;
428 DBG("network %p", network);
433 wifi = connman_device_get_data(device);
437 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
441 interface = wifi->interface;
443 ssid_init(ssid, network);
445 if (wifi->disconnecting == TRUE)
446 wifi->pending_network = network;
448 wifi->network = network;
450 return g_supplicant_interface_connect(interface, ssid,
451 connect_callback, network);
457 static void disconnect_callback(int result, GSupplicantInterface *interface,
460 struct wifi_data *wifi = user_data;
462 if (wifi->network != NULL) {
464 * if result < 0 supplican return an error because
465 * the network is not current.
466 * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
467 * failed, call connman_network_set_connected to report
468 * disconnect is completed.
471 connman_network_set_connected(wifi->network, FALSE);
474 wifi->network = NULL;
476 wifi->disconnecting = FALSE;
478 if (wifi->pending_network != NULL) {
479 network_connect(wifi->pending_network);
480 wifi->pending_network = NULL;
485 static int network_disconnect(struct connman_network *network)
487 struct connman_device *device = connman_network_get_device(network);
488 struct wifi_data *wifi;
491 DBG("network %p", network);
493 wifi = connman_device_get_data(device);
494 if (wifi == NULL || wifi->interface == NULL)
497 connman_network_set_associating(network, FALSE);
499 if (wifi->disconnecting == TRUE)
502 wifi->disconnecting = TRUE;
504 err = g_supplicant_interface_disconnect(wifi->interface,
505 disconnect_callback, wifi);
507 wifi->disconnecting = FALSE;
512 static struct connman_network_driver network_driver = {
514 .type = CONNMAN_NETWORK_TYPE_WIFI,
515 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
516 .probe = network_probe,
517 .remove = network_remove,
518 .connect = network_connect,
519 .disconnect = network_disconnect,
522 static void interface_added(GSupplicantInterface *interface)
524 const char *ifname = g_supplicant_interface_get_ifname(interface);
525 const char *driver = g_supplicant_interface_get_driver(interface);
526 struct wifi_data *wifi;
528 wifi = g_supplicant_interface_get_data(interface);
531 * We can get here with a NULL wifi pointer when
532 * the interface added signal is sent before the
533 * interface creation callback is called.
538 DBG("ifname %s driver %s wifi %p tethering %d",
539 ifname, driver, wifi, wifi->tethering);
541 if (wifi->device == NULL) {
542 connman_error("WiFi device not set");
546 connman_device_set_powered(wifi->device, TRUE);
548 if (wifi->tethering == TRUE)
551 wifi_scan(wifi->device);
554 static connman_bool_t is_idle(struct wifi_data *wifi)
556 DBG("state %d", wifi->state);
558 switch (wifi->state) {
559 case G_SUPPLICANT_STATE_UNKNOWN:
560 case G_SUPPLICANT_STATE_DISCONNECTED:
561 case G_SUPPLICANT_STATE_INACTIVE:
562 case G_SUPPLICANT_STATE_SCANNING:
565 case G_SUPPLICANT_STATE_AUTHENTICATING:
566 case G_SUPPLICANT_STATE_ASSOCIATING:
567 case G_SUPPLICANT_STATE_ASSOCIATED:
568 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
569 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
570 case G_SUPPLICANT_STATE_COMPLETED:
577 static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
578 struct wifi_data *wifi)
580 /* First, let's check if WPS processing did not went wrong */
581 if (g_supplicant_interface_get_wps_state(interface) ==
582 G_SUPPLICANT_WPS_STATE_FAIL)
585 /* Unlike normal connection, being associated while processing wps
586 * actually means that we are idling. */
587 switch (wifi->state) {
588 case G_SUPPLICANT_STATE_UNKNOWN:
589 case G_SUPPLICANT_STATE_DISCONNECTED:
590 case G_SUPPLICANT_STATE_INACTIVE:
591 case G_SUPPLICANT_STATE_SCANNING:
592 case G_SUPPLICANT_STATE_ASSOCIATED:
594 case G_SUPPLICANT_STATE_AUTHENTICATING:
595 case G_SUPPLICANT_STATE_ASSOCIATING:
596 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
597 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
598 case G_SUPPLICANT_STATE_COMPLETED:
605 static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
606 struct connman_network *network,
607 struct connman_device *device,
608 struct wifi_data *wifi)
612 wps = connman_network_get_bool(network, "WiFi.UseWPS");
614 const unsigned char *ssid, *wps_ssid;
615 unsigned int ssid_len, wps_ssid_len;
618 /* Checking if we got associated with requested
620 ssid = connman_network_get_blob(network, "WiFi.SSID",
623 wps_ssid = g_supplicant_interface_get_wps_ssid(
624 interface, &wps_ssid_len);
626 if (wps_ssid == NULL || wps_ssid_len != ssid_len ||
627 memcmp(ssid, wps_ssid, ssid_len) != 0) {
628 connman_network_set_associating(network, FALSE);
629 g_supplicant_interface_disconnect(wifi->interface,
630 disconnect_callback, wifi);
634 wps_key = g_supplicant_interface_get_wps_key(interface);
635 connman_network_set_string(network, "WiFi.Passphrase",
638 connman_network_set_string(network, "WiFi.PinWPS", NULL);
644 static void interface_state(GSupplicantInterface *interface)
646 struct connman_network *network;
647 struct connman_device *device;
648 struct wifi_data *wifi;
649 GSupplicantState state = g_supplicant_interface_get_state(interface);
652 wifi = g_supplicant_interface_get_data(interface);
654 DBG("wifi %p interface state %d", wifi, state);
659 network = wifi->network;
660 device = wifi->device;
662 if (device == NULL || network == NULL)
666 case G_SUPPLICANT_STATE_SCANNING:
669 case G_SUPPLICANT_STATE_AUTHENTICATING:
670 case G_SUPPLICANT_STATE_ASSOCIATING:
671 connman_network_set_associating(network, TRUE);
674 case G_SUPPLICANT_STATE_COMPLETED:
675 if (handle_wps_completion(interface, network, device, wifi) ==
679 /* reset scan trigger and schedule background scan */
680 connman_device_schedule_scan(device);
682 connman_network_set_connected(network, TRUE);
685 case G_SUPPLICANT_STATE_DISCONNECTED:
687 * If we're in one of the idle modes, we have
688 * not started association yet and thus setting
689 * those ones to FALSE could cancel an association
692 wps = connman_network_get_bool(network, "WiFi.UseWPS");
694 if (is_idle_wps(interface, wifi) == TRUE)
699 connman_network_set_associating(network, FALSE);
700 connman_network_set_connected(network, FALSE);
703 case G_SUPPLICANT_STATE_INACTIVE:
704 connman_network_set_associating(network, FALSE);
707 case G_SUPPLICANT_STATE_UNKNOWN:
708 case G_SUPPLICANT_STATE_ASSOCIATED:
709 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
710 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
719 static void interface_removed(GSupplicantInterface *interface)
721 const char *ifname = g_supplicant_interface_get_ifname(interface);
722 struct wifi_data *wifi;
724 DBG("ifname %s", ifname);
726 wifi = g_supplicant_interface_get_data(interface);
728 if (wifi != NULL && wifi->tethering == TRUE)
731 if (wifi == NULL || wifi->device == NULL) {
732 connman_error("Wrong wifi pointer");
736 connman_device_set_powered(wifi->device, FALSE);
739 static void scan_started(GSupplicantInterface *interface)
741 struct wifi_data *wifi;
745 wifi = g_supplicant_interface_get_data(interface);
751 static void scan_finished(GSupplicantInterface *interface)
753 struct wifi_data *wifi;
757 wifi = g_supplicant_interface_get_data(interface);
763 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
765 unsigned char strength;
767 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
774 static void network_added(GSupplicantNetwork *supplicant_network)
776 struct connman_network *network;
777 GSupplicantInterface *interface;
778 struct wifi_data *wifi;
779 const char *name, *identifier, *security, *group;
780 const unsigned char *ssid;
781 unsigned int ssid_len;
786 interface = g_supplicant_network_get_interface(supplicant_network);
787 wifi = g_supplicant_interface_get_data(interface);
788 name = g_supplicant_network_get_name(supplicant_network);
789 identifier = g_supplicant_network_get_identifier(supplicant_network);
790 security = g_supplicant_network_get_security(supplicant_network);
791 group = g_supplicant_network_get_identifier(supplicant_network);
792 wps = g_supplicant_network_get_wps(supplicant_network);
797 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
799 network = connman_device_get_network(wifi->device, identifier);
801 if (network == NULL) {
802 network = connman_network_create(identifier,
803 CONNMAN_NETWORK_TYPE_WIFI);
807 connman_network_set_index(network, wifi->index);
809 if (connman_device_add_network(wifi->device, network) < 0) {
810 connman_network_unref(network);
814 wifi->networks = g_slist_append(wifi->networks, network);
817 if (name != NULL && name[0] != '\0')
818 connman_network_set_name(network, name);
820 connman_network_set_blob(network, "WiFi.SSID",
822 connman_network_set_string(network, "WiFi.Security", security);
823 connman_network_set_strength(network,
824 calculate_strength(supplicant_network));
825 connman_network_set_bool(network, "WiFi.WPS", wps);
827 connman_network_set_available(network, TRUE);
830 connman_network_set_group(network, group);
833 static void network_removed(GSupplicantNetwork *network)
835 GSupplicantInterface *interface;
836 struct wifi_data *wifi;
837 const char *name, *identifier;
838 struct connman_network *connman_network;
840 interface = g_supplicant_network_get_interface(network);
841 wifi = g_supplicant_interface_get_data(interface);
842 identifier = g_supplicant_network_get_identifier(network);
843 name = g_supplicant_network_get_name(network);
845 DBG("name %s", name);
850 connman_network = connman_device_get_network(wifi->device, identifier);
851 if (connman_network == NULL)
854 wifi->networks = g_slist_remove(wifi->networks, connman_network);
856 connman_device_remove_network(wifi->device, connman_network);
857 connman_network_unref(connman_network);
860 static void debug(const char *str)
862 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
863 connman_debug("%s", str);
866 static const GSupplicantCallbacks callbacks = {
867 .system_ready = system_ready,
868 .system_killed = system_killed,
869 .interface_added = interface_added,
870 .interface_state = interface_state,
871 .interface_removed = interface_removed,
872 .scan_started = scan_started,
873 .scan_finished = scan_finished,
874 .network_added = network_added,
875 .network_removed = network_removed,
880 static int tech_probe(struct connman_technology *technology)
882 wifi_technology = technology;
887 static void tech_remove(struct connman_technology *technology)
889 wifi_technology = NULL;
892 struct wifi_tethering_info {
893 struct wifi_data *wifi;
894 struct connman_technology *technology;
896 GSupplicantSSID *ssid;
899 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
903 ap = g_try_malloc0(sizeof(GSupplicantSSID));
907 ap->mode = G_SUPPLICANT_MODE_MASTER;
909 ap->ssid_len = strlen(ssid);
913 if (passphrase == NULL || strlen(passphrase) == 0) {
914 ap->security = G_SUPPLICANT_SECURITY_NONE;
915 ap->passphrase = NULL;
917 ap->security = G_SUPPLICANT_SECURITY_PSK;
918 ap->protocol = G_SUPPLICANT_PROTO_RSN;
919 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
920 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
921 ap->passphrase = passphrase;
927 static void ap_start_callback(int result, GSupplicantInterface *interface,
930 struct wifi_tethering_info *info = user_data;
932 DBG("result %d index %d bridge %s",
933 result, info->wifi->index, info->wifi->bridge);
936 connman_inet_remove_from_bridge(info->wifi->index,
938 connman_technology_tethering_notify(info->technology, FALSE);
941 g_free(info->ifname);
945 static void ap_create_callback(int result,
946 GSupplicantInterface *interface,
949 struct wifi_tethering_info *info = user_data;
951 DBG("result %d ifname %s", result,
952 g_supplicant_interface_get_ifname(interface));
955 connman_inet_remove_from_bridge(info->wifi->index,
957 connman_technology_tethering_notify(info->technology, FALSE);
959 g_free(info->ifname);
964 info->wifi->interface = interface;
965 g_supplicant_interface_set_data(interface, info->wifi);
967 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
968 connman_error("Failed to set interface ap_scan property");
970 g_supplicant_interface_connect(interface, info->ssid,
971 ap_start_callback, info);
974 static void sta_remove_callback(int result,
975 GSupplicantInterface *interface,
978 struct wifi_tethering_info *info = user_data;
979 const char *driver = connman_option_get_string("wifi");
981 DBG("ifname %s result %d ", info->ifname, result);
984 info->wifi->tethering = TRUE;
986 g_free(info->ifname);
991 info->wifi->interface = NULL;
993 connman_technology_tethering_notify(info->technology, TRUE);
995 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
1000 static int tech_set_tethering(struct connman_technology *technology,
1001 const char *identifier, const char *passphrase,
1002 const char *bridge, connman_bool_t enabled)
1005 GSupplicantInterface *interface;
1006 struct wifi_data *wifi;
1007 struct wifi_tethering_info *info;
1014 if (enabled == FALSE) {
1015 for (list = iface_list; list; list = list->next) {
1018 if (wifi->tethering == TRUE) {
1019 wifi->tethering = FALSE;
1021 connman_inet_remove_from_bridge(wifi->index,
1023 wifi->bridged = FALSE;
1027 connman_technology_tethering_notify(technology, FALSE);
1032 for (list = iface_list; list; list = list->next) {
1035 interface = wifi->interface;
1037 if (interface == NULL)
1040 ifname = g_supplicant_interface_get_ifname(wifi->interface);
1042 mode = g_supplicant_interface_get_mode(interface);
1043 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
1044 DBG("%s does not support AP mode", ifname);
1048 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
1053 info->technology = technology;
1054 info->wifi->bridge = bridge;
1055 info->ssid = ssid_ap_init(identifier, passphrase);
1056 if (info->ssid == NULL) {
1060 info->ifname = g_strdup(ifname);
1061 if (info->ifname == NULL) {
1066 info->wifi->tethering = TRUE;
1068 err = g_supplicant_interface_remove(interface,
1069 sta_remove_callback,
1078 static void regdom_callback(void *user_data)
1080 char *alpha2 = user_data;
1084 if (wifi_technology == NULL)
1087 connman_technology_regdom_notify(wifi_technology, alpha2);
1090 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
1092 return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
1095 static struct connman_technology_driver tech_driver = {
1097 .type = CONNMAN_SERVICE_TYPE_WIFI,
1098 .probe = tech_probe,
1099 .remove = tech_remove,
1100 .set_tethering = tech_set_tethering,
1101 .set_regdom = tech_set_regdom,
1104 static int wifi_init(void)
1108 err = connman_network_driver_register(&network_driver);
1112 err = g_supplicant_register(&callbacks);
1114 connman_network_driver_unregister(&network_driver);
1118 err = connman_technology_driver_register(&tech_driver);
1120 g_supplicant_unregister(&callbacks);
1121 connman_network_driver_unregister(&network_driver);
1128 static void wifi_exit(void)
1132 connman_technology_driver_unregister(&tech_driver);
1134 g_supplicant_unregister(&callbacks);
1136 connman_network_driver_unregister(&network_driver);
1139 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
1140 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)