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, *agent_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) {
388 /* Use agent provided passphrase as a fallback */
389 agent_passphrase = connman_network_get_string(network,
390 "WiFi.AgentPassphrase");
392 if (agent_passphrase == NULL || strlen(agent_passphrase) == 0)
393 ssid->passphrase = NULL;
395 ssid->passphrase = agent_passphrase;
397 ssid->passphrase = passphrase;
399 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
402 * If our private key password is unset,
403 * we use the supplied passphrase. That is needed
404 * for PEAP where 2 passphrases (identity and client
405 * cert may have to be provided.
407 if (connman_network_get_string(network,
408 "WiFi.PrivateKeyPassphrase") == NULL)
409 connman_network_set_string(network,
410 "WiFi.PrivateKeyPassphrase",
412 /* We must have an identity for both PEAP and TLS */
413 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
415 /* Use agent provided identity as a fallback */
416 if (ssid->identity == NULL || strlen(ssid->identity) == 0)
417 ssid->identity = connman_network_get_string(network,
418 "WiFi.AgentIdentity");
420 ssid->ca_cert_path = connman_network_get_string(network,
422 ssid->client_cert_path = connman_network_get_string(network,
423 "WiFi.ClientCertFile");
424 ssid->private_key_path = connman_network_get_string(network,
425 "WiFi.PrivateKeyFile");
426 ssid->private_key_passphrase = connman_network_get_string(network,
427 "WiFi.PrivateKeyPassphrase");
428 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
430 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
431 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
435 static int network_connect(struct connman_network *network)
437 struct connman_device *device = connman_network_get_device(network);
438 struct wifi_data *wifi;
439 GSupplicantInterface *interface;
440 GSupplicantSSID *ssid;
442 DBG("network %p", network);
447 wifi = connman_device_get_data(device);
451 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
455 interface = wifi->interface;
457 ssid_init(ssid, network);
459 if (wifi->disconnecting == TRUE)
460 wifi->pending_network = network;
462 wifi->network = network;
464 return g_supplicant_interface_connect(interface, ssid,
465 connect_callback, network);
471 static void disconnect_callback(int result, GSupplicantInterface *interface,
474 struct wifi_data *wifi = user_data;
476 if (wifi->network != NULL) {
478 * if result < 0 supplican return an error because
479 * the network is not current.
480 * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
481 * failed, call connman_network_set_connected to report
482 * disconnect is completed.
485 connman_network_set_connected(wifi->network, FALSE);
488 wifi->network = NULL;
490 wifi->disconnecting = FALSE;
492 if (wifi->pending_network != NULL) {
493 network_connect(wifi->pending_network);
494 wifi->pending_network = NULL;
499 static int network_disconnect(struct connman_network *network)
501 struct connman_device *device = connman_network_get_device(network);
502 struct wifi_data *wifi;
505 DBG("network %p", network);
507 wifi = connman_device_get_data(device);
508 if (wifi == NULL || wifi->interface == NULL)
511 connman_network_set_associating(network, FALSE);
513 if (wifi->disconnecting == TRUE)
516 wifi->disconnecting = TRUE;
518 err = g_supplicant_interface_disconnect(wifi->interface,
519 disconnect_callback, wifi);
521 wifi->disconnecting = FALSE;
526 static struct connman_network_driver network_driver = {
528 .type = CONNMAN_NETWORK_TYPE_WIFI,
529 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
530 .probe = network_probe,
531 .remove = network_remove,
532 .connect = network_connect,
533 .disconnect = network_disconnect,
536 static void interface_added(GSupplicantInterface *interface)
538 const char *ifname = g_supplicant_interface_get_ifname(interface);
539 const char *driver = g_supplicant_interface_get_driver(interface);
540 struct wifi_data *wifi;
542 wifi = g_supplicant_interface_get_data(interface);
545 * We can get here with a NULL wifi pointer when
546 * the interface added signal is sent before the
547 * interface creation callback is called.
552 DBG("ifname %s driver %s wifi %p tethering %d",
553 ifname, driver, wifi, wifi->tethering);
555 if (wifi->device == NULL) {
556 connman_error("WiFi device not set");
560 connman_device_set_powered(wifi->device, TRUE);
562 if (wifi->tethering == TRUE)
565 wifi_scan(wifi->device);
568 static connman_bool_t is_idle(struct wifi_data *wifi)
570 DBG("state %d", wifi->state);
572 switch (wifi->state) {
573 case G_SUPPLICANT_STATE_UNKNOWN:
574 case G_SUPPLICANT_STATE_DISCONNECTED:
575 case G_SUPPLICANT_STATE_INACTIVE:
576 case G_SUPPLICANT_STATE_SCANNING:
579 case G_SUPPLICANT_STATE_AUTHENTICATING:
580 case G_SUPPLICANT_STATE_ASSOCIATING:
581 case G_SUPPLICANT_STATE_ASSOCIATED:
582 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
583 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
584 case G_SUPPLICANT_STATE_COMPLETED:
591 static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
592 struct wifi_data *wifi)
594 /* First, let's check if WPS processing did not went wrong */
595 if (g_supplicant_interface_get_wps_state(interface) ==
596 G_SUPPLICANT_WPS_STATE_FAIL)
599 /* Unlike normal connection, being associated while processing wps
600 * actually means that we are idling. */
601 switch (wifi->state) {
602 case G_SUPPLICANT_STATE_UNKNOWN:
603 case G_SUPPLICANT_STATE_DISCONNECTED:
604 case G_SUPPLICANT_STATE_INACTIVE:
605 case G_SUPPLICANT_STATE_SCANNING:
606 case G_SUPPLICANT_STATE_ASSOCIATED:
608 case G_SUPPLICANT_STATE_AUTHENTICATING:
609 case G_SUPPLICANT_STATE_ASSOCIATING:
610 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
611 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
612 case G_SUPPLICANT_STATE_COMPLETED:
619 static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
620 struct connman_network *network,
621 struct connman_device *device,
622 struct wifi_data *wifi)
626 wps = connman_network_get_bool(network, "WiFi.UseWPS");
628 const unsigned char *ssid, *wps_ssid;
629 unsigned int ssid_len, wps_ssid_len;
632 /* Checking if we got associated with requested
634 ssid = connman_network_get_blob(network, "WiFi.SSID",
637 wps_ssid = g_supplicant_interface_get_wps_ssid(
638 interface, &wps_ssid_len);
640 if (wps_ssid == NULL || wps_ssid_len != ssid_len ||
641 memcmp(ssid, wps_ssid, ssid_len) != 0) {
642 connman_network_set_associating(network, FALSE);
643 g_supplicant_interface_disconnect(wifi->interface,
644 disconnect_callback, wifi);
648 wps_key = g_supplicant_interface_get_wps_key(interface);
649 connman_network_set_string(network, "WiFi.Passphrase",
652 connman_network_set_string(network, "WiFi.PinWPS", NULL);
658 static void interface_state(GSupplicantInterface *interface)
660 struct connman_network *network;
661 struct connman_device *device;
662 struct wifi_data *wifi;
663 GSupplicantState state = g_supplicant_interface_get_state(interface);
666 wifi = g_supplicant_interface_get_data(interface);
668 DBG("wifi %p interface state %d", wifi, state);
673 network = wifi->network;
674 device = wifi->device;
676 if (device == NULL || network == NULL)
680 case G_SUPPLICANT_STATE_SCANNING:
683 case G_SUPPLICANT_STATE_AUTHENTICATING:
684 case G_SUPPLICANT_STATE_ASSOCIATING:
685 connman_network_set_associating(network, TRUE);
688 case G_SUPPLICANT_STATE_COMPLETED:
689 if (handle_wps_completion(interface, network, device, wifi) ==
693 /* reset scan trigger and schedule background scan */
694 connman_device_schedule_scan(device);
696 connman_network_set_connected(network, TRUE);
699 case G_SUPPLICANT_STATE_DISCONNECTED:
701 * If we're in one of the idle modes, we have
702 * not started association yet and thus setting
703 * those ones to FALSE could cancel an association
706 wps = connman_network_get_bool(network, "WiFi.UseWPS");
708 if (is_idle_wps(interface, wifi) == TRUE)
713 connman_network_set_associating(network, FALSE);
714 connman_network_set_connected(network, FALSE);
717 case G_SUPPLICANT_STATE_INACTIVE:
718 connman_network_set_associating(network, FALSE);
721 case G_SUPPLICANT_STATE_UNKNOWN:
722 case G_SUPPLICANT_STATE_ASSOCIATED:
723 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
724 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
733 static void interface_removed(GSupplicantInterface *interface)
735 const char *ifname = g_supplicant_interface_get_ifname(interface);
736 struct wifi_data *wifi;
738 DBG("ifname %s", ifname);
740 wifi = g_supplicant_interface_get_data(interface);
742 if (wifi != NULL && wifi->tethering == TRUE)
745 if (wifi == NULL || wifi->device == NULL) {
746 connman_error("Wrong wifi pointer");
750 connman_device_set_powered(wifi->device, FALSE);
753 static void scan_started(GSupplicantInterface *interface)
755 struct wifi_data *wifi;
759 wifi = g_supplicant_interface_get_data(interface);
765 static void scan_finished(GSupplicantInterface *interface)
767 struct wifi_data *wifi;
771 wifi = g_supplicant_interface_get_data(interface);
777 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
779 unsigned char strength;
781 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
788 static void network_added(GSupplicantNetwork *supplicant_network)
790 struct connman_network *network;
791 GSupplicantInterface *interface;
792 struct wifi_data *wifi;
793 const char *name, *identifier, *security, *group;
794 const unsigned char *ssid;
795 unsigned int ssid_len;
800 interface = g_supplicant_network_get_interface(supplicant_network);
801 wifi = g_supplicant_interface_get_data(interface);
802 name = g_supplicant_network_get_name(supplicant_network);
803 identifier = g_supplicant_network_get_identifier(supplicant_network);
804 security = g_supplicant_network_get_security(supplicant_network);
805 group = g_supplicant_network_get_identifier(supplicant_network);
806 wps = g_supplicant_network_get_wps(supplicant_network);
811 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
813 network = connman_device_get_network(wifi->device, identifier);
815 if (network == NULL) {
816 network = connman_network_create(identifier,
817 CONNMAN_NETWORK_TYPE_WIFI);
821 connman_network_set_index(network, wifi->index);
823 if (connman_device_add_network(wifi->device, network) < 0) {
824 connman_network_unref(network);
828 wifi->networks = g_slist_append(wifi->networks, network);
831 if (name != NULL && name[0] != '\0')
832 connman_network_set_name(network, name);
834 connman_network_set_blob(network, "WiFi.SSID",
836 connman_network_set_string(network, "WiFi.Security", security);
837 connman_network_set_strength(network,
838 calculate_strength(supplicant_network));
839 connman_network_set_bool(network, "WiFi.WPS", wps);
841 connman_network_set_available(network, TRUE);
844 connman_network_set_group(network, group);
847 static void network_removed(GSupplicantNetwork *network)
849 GSupplicantInterface *interface;
850 struct wifi_data *wifi;
851 const char *name, *identifier;
852 struct connman_network *connman_network;
854 interface = g_supplicant_network_get_interface(network);
855 wifi = g_supplicant_interface_get_data(interface);
856 identifier = g_supplicant_network_get_identifier(network);
857 name = g_supplicant_network_get_name(network);
859 DBG("name %s", name);
864 connman_network = connman_device_get_network(wifi->device, identifier);
865 if (connman_network == NULL)
868 wifi->networks = g_slist_remove(wifi->networks, connman_network);
870 connman_device_remove_network(wifi->device, connman_network);
871 connman_network_unref(connman_network);
874 static void debug(const char *str)
876 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
877 connman_debug("%s", str);
880 static const GSupplicantCallbacks callbacks = {
881 .system_ready = system_ready,
882 .system_killed = system_killed,
883 .interface_added = interface_added,
884 .interface_state = interface_state,
885 .interface_removed = interface_removed,
886 .scan_started = scan_started,
887 .scan_finished = scan_finished,
888 .network_added = network_added,
889 .network_removed = network_removed,
894 static int tech_probe(struct connman_technology *technology)
896 wifi_technology = technology;
901 static void tech_remove(struct connman_technology *technology)
903 wifi_technology = NULL;
906 struct wifi_tethering_info {
907 struct wifi_data *wifi;
908 struct connman_technology *technology;
910 GSupplicantSSID *ssid;
913 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
917 ap = g_try_malloc0(sizeof(GSupplicantSSID));
921 ap->mode = G_SUPPLICANT_MODE_MASTER;
923 ap->ssid_len = strlen(ssid);
927 if (passphrase == NULL || strlen(passphrase) == 0) {
928 ap->security = G_SUPPLICANT_SECURITY_NONE;
929 ap->passphrase = NULL;
931 ap->security = G_SUPPLICANT_SECURITY_PSK;
932 ap->protocol = G_SUPPLICANT_PROTO_RSN;
933 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
934 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
935 ap->passphrase = passphrase;
941 static void ap_start_callback(int result, GSupplicantInterface *interface,
944 struct wifi_tethering_info *info = user_data;
946 DBG("result %d index %d bridge %s",
947 result, info->wifi->index, info->wifi->bridge);
950 connman_inet_remove_from_bridge(info->wifi->index,
952 connman_technology_tethering_notify(info->technology, FALSE);
955 g_free(info->ifname);
959 static void ap_create_callback(int result,
960 GSupplicantInterface *interface,
963 struct wifi_tethering_info *info = user_data;
965 DBG("result %d ifname %s", result,
966 g_supplicant_interface_get_ifname(interface));
969 connman_inet_remove_from_bridge(info->wifi->index,
971 connman_technology_tethering_notify(info->technology, FALSE);
973 g_free(info->ifname);
978 info->wifi->interface = interface;
979 g_supplicant_interface_set_data(interface, info->wifi);
981 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
982 connman_error("Failed to set interface ap_scan property");
984 g_supplicant_interface_connect(interface, info->ssid,
985 ap_start_callback, info);
988 static void sta_remove_callback(int result,
989 GSupplicantInterface *interface,
992 struct wifi_tethering_info *info = user_data;
993 const char *driver = connman_option_get_string("wifi");
995 DBG("ifname %s result %d ", info->ifname, result);
998 info->wifi->tethering = TRUE;
1000 g_free(info->ifname);
1005 info->wifi->interface = NULL;
1007 connman_technology_tethering_notify(info->technology, TRUE);
1009 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
1014 static int tech_set_tethering(struct connman_technology *technology,
1015 const char *identifier, const char *passphrase,
1016 const char *bridge, connman_bool_t enabled)
1019 GSupplicantInterface *interface;
1020 struct wifi_data *wifi;
1021 struct wifi_tethering_info *info;
1028 if (enabled == FALSE) {
1029 for (list = iface_list; list; list = list->next) {
1032 if (wifi->tethering == TRUE) {
1033 wifi->tethering = FALSE;
1035 connman_inet_remove_from_bridge(wifi->index,
1037 wifi->bridged = FALSE;
1041 connman_technology_tethering_notify(technology, FALSE);
1046 for (list = iface_list; list; list = list->next) {
1049 interface = wifi->interface;
1051 if (interface == NULL)
1054 ifname = g_supplicant_interface_get_ifname(wifi->interface);
1056 mode = g_supplicant_interface_get_mode(interface);
1057 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
1058 DBG("%s does not support AP mode", ifname);
1062 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
1067 info->technology = technology;
1068 info->wifi->bridge = bridge;
1069 info->ssid = ssid_ap_init(identifier, passphrase);
1070 if (info->ssid == NULL) {
1074 info->ifname = g_strdup(ifname);
1075 if (info->ifname == NULL) {
1080 info->wifi->tethering = TRUE;
1082 err = g_supplicant_interface_remove(interface,
1083 sta_remove_callback,
1092 static void regdom_callback(void *user_data)
1094 char *alpha2 = user_data;
1098 if (wifi_technology == NULL)
1101 connman_technology_regdom_notify(wifi_technology, alpha2);
1104 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
1106 return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
1109 static struct connman_technology_driver tech_driver = {
1111 .type = CONNMAN_SERVICE_TYPE_WIFI,
1112 .probe = tech_probe,
1113 .remove = tech_remove,
1114 .set_tethering = tech_set_tethering,
1115 .set_regdom = tech_set_regdom,
1118 static int wifi_init(void)
1122 err = connman_network_driver_register(&network_driver);
1126 err = g_supplicant_register(&callbacks);
1128 connman_network_driver_unregister(&network_driver);
1132 err = connman_technology_driver_register(&tech_driver);
1134 g_supplicant_unregister(&callbacks);
1135 connman_network_driver_unregister(&network_driver);
1142 static void wifi_exit(void)
1146 connman_technology_driver_unregister(&tech_driver);
1148 g_supplicant_unregister(&callbacks);
1150 connman_network_driver_unregister(&network_driver);
1153 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
1154 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)