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, wifi %p", result,
204 g_supplicant_interface_get_ifname(interface),
207 if (result < 0 || wifi == NULL)
210 wifi->interface = interface;
211 g_supplicant_interface_set_data(interface, wifi);
214 static void interface_remove_callback(int result,
215 GSupplicantInterface *interface,
218 struct wifi_data *wifi = user_data;
220 DBG("result %d wifi %p", result, wifi);
222 if (result < 0 || wifi == NULL)
225 wifi->interface = NULL;
229 static int wifi_enable(struct connman_device *device)
231 struct wifi_data *wifi = connman_device_get_data(device);
232 const char *interface = connman_device_get_string(device, "Interface");
233 const char *driver = connman_option_get_string("wifi");
236 DBG("device %p %p", device, wifi);
238 ret = g_supplicant_interface_create(interface, driver, NULL,
239 interface_create_callback,
247 static int wifi_disable(struct connman_device *device)
249 struct wifi_data *wifi = connman_device_get_data(device);
252 DBG("device %p", device);
254 wifi->connected = FALSE;
255 wifi->disconnecting = FALSE;
257 if (wifi->pending_network != NULL)
258 wifi->pending_network = NULL;
260 remove_networks(device, wifi);
262 ret = g_supplicant_interface_remove(wifi->interface,
263 interface_remove_callback,
271 static void scan_callback(int result, GSupplicantInterface *interface,
274 struct connman_device *device = user_data;
276 DBG("result %d", result);
279 connman_device_reset_scanning(device);
281 connman_device_set_scanning(device, FALSE);
282 connman_device_unref(device);
285 static int wifi_scan(struct connman_device *device)
287 struct wifi_data *wifi = connman_device_get_data(device);
290 DBG("device %p %p", device, wifi->interface);
292 if (wifi->tethering == TRUE)
295 connman_device_ref(device);
296 ret = g_supplicant_interface_scan(wifi->interface, scan_callback,
299 connman_device_set_scanning(device, TRUE);
301 connman_device_unref(device);
306 static int wifi_scan_fast(struct connman_device *device)
308 struct wifi_data *wifi = connman_device_get_data(device);
311 DBG("device %p %p", device, wifi->interface);
313 if (wifi->tethering == TRUE)
316 ret = g_supplicant_interface_scan(wifi->interface, scan_callback,
319 connman_device_set_scanning(device, TRUE);
324 static struct connman_device_driver wifi_ng_driver = {
326 .type = CONNMAN_DEVICE_TYPE_WIFI,
327 .priority = CONNMAN_DEVICE_PRIORITY_LOW,
329 .remove = wifi_remove,
330 .enable = wifi_enable,
331 .disable = wifi_disable,
333 .scan_fast = wifi_scan_fast,
336 static void system_ready(void)
340 if (connman_device_driver_register(&wifi_ng_driver) < 0)
341 connman_error("Failed to register WiFi driver");
344 static void system_killed(void)
348 connman_device_driver_unregister(&wifi_ng_driver);
351 static int network_probe(struct connman_network *network)
353 DBG("network %p", network);
358 static void network_remove(struct connman_network *network)
360 struct connman_device *device = connman_network_get_device(network);
361 struct wifi_data *wifi;
363 DBG("network %p", network);
365 wifi = connman_device_get_data(device);
369 if (wifi->network != network)
372 wifi->network = NULL;
375 static void connect_callback(int result, GSupplicantInterface *interface,
378 struct connman_network *network = user_data;
380 DBG("network %p result %d", network, result);
382 if (result == -ENOKEY) {
383 connman_network_set_error(network,
384 CONNMAN_NETWORK_ERROR_INVALID_KEY);
385 } else if (result < 0) {
386 connman_network_set_error(network,
387 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
391 static GSupplicantSecurity network_security(const char *security)
393 if (g_str_equal(security, "none") == TRUE)
394 return G_SUPPLICANT_SECURITY_NONE;
395 else if (g_str_equal(security, "wep") == TRUE)
396 return G_SUPPLICANT_SECURITY_WEP;
397 else if (g_str_equal(security, "psk") == TRUE)
398 return G_SUPPLICANT_SECURITY_PSK;
399 else if (g_str_equal(security, "wpa") == TRUE)
400 return G_SUPPLICANT_SECURITY_PSK;
401 else if (g_str_equal(security, "rsn") == TRUE)
402 return G_SUPPLICANT_SECURITY_PSK;
403 else if (g_str_equal(security, "ieee8021x") == TRUE)
404 return G_SUPPLICANT_SECURITY_IEEE8021X;
406 return G_SUPPLICANT_SECURITY_UNKNOWN;
409 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
411 const char *security, *passphrase, *agent_passphrase;
413 memset(ssid, 0, sizeof(*ssid));
414 ssid->mode = G_SUPPLICANT_MODE_INFRA;
415 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
418 security = connman_network_get_string(network, "WiFi.Security");
419 ssid->security = network_security(security);
420 passphrase = connman_network_get_string(network,
422 if (passphrase == NULL || strlen(passphrase) == 0) {
424 /* Use agent provided passphrase as a fallback */
425 agent_passphrase = connman_network_get_string(network,
426 "WiFi.AgentPassphrase");
428 if (agent_passphrase == NULL || strlen(agent_passphrase) == 0)
429 ssid->passphrase = NULL;
431 ssid->passphrase = agent_passphrase;
433 ssid->passphrase = passphrase;
435 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
438 * If our private key password is unset,
439 * we use the supplied passphrase. That is needed
440 * for PEAP where 2 passphrases (identity and client
441 * cert may have to be provided.
443 if (connman_network_get_string(network,
444 "WiFi.PrivateKeyPassphrase") == NULL)
445 connman_network_set_string(network,
446 "WiFi.PrivateKeyPassphrase",
448 /* We must have an identity for both PEAP and TLS */
449 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
451 /* Use agent provided identity as a fallback */
452 if (ssid->identity == NULL || strlen(ssid->identity) == 0)
453 ssid->identity = connman_network_get_string(network,
454 "WiFi.AgentIdentity");
456 ssid->ca_cert_path = connman_network_get_string(network,
458 ssid->client_cert_path = connman_network_get_string(network,
459 "WiFi.ClientCertFile");
460 ssid->private_key_path = connman_network_get_string(network,
461 "WiFi.PrivateKeyFile");
462 ssid->private_key_passphrase = connman_network_get_string(network,
463 "WiFi.PrivateKeyPassphrase");
464 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
466 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
467 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
471 static int network_connect(struct connman_network *network)
473 struct connman_device *device = connman_network_get_device(network);
474 struct wifi_data *wifi;
475 GSupplicantInterface *interface;
476 GSupplicantSSID *ssid;
478 DBG("network %p", network);
483 wifi = connman_device_get_data(device);
487 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
491 interface = wifi->interface;
493 ssid_init(ssid, network);
495 if (wifi->disconnecting == TRUE)
496 wifi->pending_network = network;
498 wifi->network = network;
500 return g_supplicant_interface_connect(interface, ssid,
501 connect_callback, network);
507 static void disconnect_callback(int result, GSupplicantInterface *interface,
510 struct wifi_data *wifi = user_data;
512 if (wifi->network != NULL) {
514 * if result < 0 supplican return an error because
515 * the network is not current.
516 * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
517 * failed, call connman_network_set_connected to report
518 * disconnect is completed.
521 connman_network_set_connected(wifi->network, FALSE);
524 wifi->network = NULL;
526 wifi->disconnecting = FALSE;
528 if (wifi->pending_network != NULL) {
529 network_connect(wifi->pending_network);
530 wifi->pending_network = NULL;
535 static int network_disconnect(struct connman_network *network)
537 struct connman_device *device = connman_network_get_device(network);
538 struct wifi_data *wifi;
541 DBG("network %p", network);
543 wifi = connman_device_get_data(device);
544 if (wifi == NULL || wifi->interface == NULL)
547 connman_network_set_associating(network, FALSE);
549 if (wifi->disconnecting == TRUE)
552 wifi->disconnecting = TRUE;
554 err = g_supplicant_interface_disconnect(wifi->interface,
555 disconnect_callback, wifi);
557 wifi->disconnecting = FALSE;
562 static struct connman_network_driver network_driver = {
564 .type = CONNMAN_NETWORK_TYPE_WIFI,
565 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
566 .probe = network_probe,
567 .remove = network_remove,
568 .connect = network_connect,
569 .disconnect = network_disconnect,
572 static void interface_added(GSupplicantInterface *interface)
574 const char *ifname = g_supplicant_interface_get_ifname(interface);
575 const char *driver = g_supplicant_interface_get_driver(interface);
576 struct wifi_data *wifi;
578 wifi = g_supplicant_interface_get_data(interface);
581 * We can get here with a NULL wifi pointer when
582 * the interface added signal is sent before the
583 * interface creation callback is called.
588 DBG("ifname %s driver %s wifi %p tethering %d",
589 ifname, driver, wifi, wifi->tethering);
591 if (wifi->device == NULL) {
592 connman_error("WiFi device not set");
596 connman_device_set_powered(wifi->device, TRUE);
598 if (wifi->tethering == TRUE)
602 static connman_bool_t is_idle(struct wifi_data *wifi)
604 DBG("state %d", wifi->state);
606 switch (wifi->state) {
607 case G_SUPPLICANT_STATE_UNKNOWN:
608 case G_SUPPLICANT_STATE_DISCONNECTED:
609 case G_SUPPLICANT_STATE_INACTIVE:
610 case G_SUPPLICANT_STATE_SCANNING:
613 case G_SUPPLICANT_STATE_AUTHENTICATING:
614 case G_SUPPLICANT_STATE_ASSOCIATING:
615 case G_SUPPLICANT_STATE_ASSOCIATED:
616 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
617 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
618 case G_SUPPLICANT_STATE_COMPLETED:
625 static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
626 struct wifi_data *wifi)
628 /* First, let's check if WPS processing did not went wrong */
629 if (g_supplicant_interface_get_wps_state(interface) ==
630 G_SUPPLICANT_WPS_STATE_FAIL)
633 /* Unlike normal connection, being associated while processing wps
634 * actually means that we are idling. */
635 switch (wifi->state) {
636 case G_SUPPLICANT_STATE_UNKNOWN:
637 case G_SUPPLICANT_STATE_DISCONNECTED:
638 case G_SUPPLICANT_STATE_INACTIVE:
639 case G_SUPPLICANT_STATE_SCANNING:
640 case G_SUPPLICANT_STATE_ASSOCIATED:
642 case G_SUPPLICANT_STATE_AUTHENTICATING:
643 case G_SUPPLICANT_STATE_ASSOCIATING:
644 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
645 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
646 case G_SUPPLICANT_STATE_COMPLETED:
653 static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
654 struct connman_network *network,
655 struct connman_device *device,
656 struct wifi_data *wifi)
660 wps = connman_network_get_bool(network, "WiFi.UseWPS");
662 const unsigned char *ssid, *wps_ssid;
663 unsigned int ssid_len, wps_ssid_len;
666 /* Checking if we got associated with requested
668 ssid = connman_network_get_blob(network, "WiFi.SSID",
671 wps_ssid = g_supplicant_interface_get_wps_ssid(
672 interface, &wps_ssid_len);
674 if (wps_ssid == NULL || wps_ssid_len != ssid_len ||
675 memcmp(ssid, wps_ssid, ssid_len) != 0) {
676 connman_network_set_associating(network, FALSE);
677 g_supplicant_interface_disconnect(wifi->interface,
678 disconnect_callback, wifi);
682 wps_key = g_supplicant_interface_get_wps_key(interface);
683 connman_network_set_string(network, "WiFi.Passphrase",
686 connman_network_set_string(network, "WiFi.PinWPS", NULL);
692 static void interface_state(GSupplicantInterface *interface)
694 struct connman_network *network;
695 struct connman_device *device;
696 struct wifi_data *wifi;
697 GSupplicantState state = g_supplicant_interface_get_state(interface);
700 wifi = g_supplicant_interface_get_data(interface);
702 DBG("wifi %p interface state %d", wifi, state);
707 network = wifi->network;
708 device = wifi->device;
710 if (device == NULL || network == NULL)
714 case G_SUPPLICANT_STATE_SCANNING:
717 case G_SUPPLICANT_STATE_AUTHENTICATING:
718 case G_SUPPLICANT_STATE_ASSOCIATING:
719 connman_network_set_associating(network, TRUE);
722 case G_SUPPLICANT_STATE_COMPLETED:
723 if (handle_wps_completion(interface, network, device, wifi) ==
727 /* reset scan trigger and schedule background scan */
728 connman_device_schedule_scan(device);
730 connman_network_set_connected(network, TRUE);
733 case G_SUPPLICANT_STATE_DISCONNECTED:
735 * If we're in one of the idle modes, we have
736 * not started association yet and thus setting
737 * those ones to FALSE could cancel an association
740 wps = connman_network_get_bool(network, "WiFi.UseWPS");
742 if (is_idle_wps(interface, wifi) == TRUE)
747 connman_network_set_associating(network, FALSE);
748 connman_network_set_connected(network, FALSE);
751 case G_SUPPLICANT_STATE_INACTIVE:
752 connman_network_set_associating(network, FALSE);
755 case G_SUPPLICANT_STATE_UNKNOWN:
756 case G_SUPPLICANT_STATE_ASSOCIATED:
757 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
758 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
767 static void interface_removed(GSupplicantInterface *interface)
769 const char *ifname = g_supplicant_interface_get_ifname(interface);
770 struct wifi_data *wifi;
772 DBG("ifname %s", ifname);
774 wifi = g_supplicant_interface_get_data(interface);
776 if (wifi != NULL && wifi->tethering == TRUE)
779 if (wifi == NULL || wifi->device == NULL) {
780 connman_error("Wrong wifi pointer");
784 connman_device_set_powered(wifi->device, FALSE);
787 static void scan_started(GSupplicantInterface *interface)
792 static void scan_finished(GSupplicantInterface *interface)
797 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
799 unsigned char strength;
801 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
808 static void network_added(GSupplicantNetwork *supplicant_network)
810 struct connman_network *network;
811 GSupplicantInterface *interface;
812 struct wifi_data *wifi;
813 const char *name, *identifier, *security, *group;
814 const unsigned char *ssid;
815 unsigned int ssid_len;
820 interface = g_supplicant_network_get_interface(supplicant_network);
821 wifi = g_supplicant_interface_get_data(interface);
822 name = g_supplicant_network_get_name(supplicant_network);
823 identifier = g_supplicant_network_get_identifier(supplicant_network);
824 security = g_supplicant_network_get_security(supplicant_network);
825 group = g_supplicant_network_get_identifier(supplicant_network);
826 wps = g_supplicant_network_get_wps(supplicant_network);
831 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
833 network = connman_device_get_network(wifi->device, identifier);
835 if (network == NULL) {
836 network = connman_network_create(identifier,
837 CONNMAN_NETWORK_TYPE_WIFI);
841 connman_network_set_index(network, wifi->index);
843 if (connman_device_add_network(wifi->device, network) < 0) {
844 connman_network_unref(network);
848 wifi->networks = g_slist_append(wifi->networks, network);
851 if (name != NULL && name[0] != '\0')
852 connman_network_set_name(network, name);
854 connman_network_set_blob(network, "WiFi.SSID",
856 connman_network_set_string(network, "WiFi.Security", security);
857 connman_network_set_strength(network,
858 calculate_strength(supplicant_network));
859 connman_network_set_bool(network, "WiFi.WPS", wps);
861 connman_network_set_frequency(network,
862 g_supplicant_network_get_frequency(supplicant_network));
864 connman_network_set_available(network, TRUE);
867 connman_network_set_group(network, group);
870 static void network_removed(GSupplicantNetwork *network)
872 GSupplicantInterface *interface;
873 struct wifi_data *wifi;
874 const char *name, *identifier;
875 struct connman_network *connman_network;
877 interface = g_supplicant_network_get_interface(network);
878 wifi = g_supplicant_interface_get_data(interface);
879 identifier = g_supplicant_network_get_identifier(network);
880 name = g_supplicant_network_get_name(network);
882 DBG("name %s", name);
887 connman_network = connman_device_get_network(wifi->device, identifier);
888 if (connman_network == NULL)
891 wifi->networks = g_slist_remove(wifi->networks, connman_network);
893 connman_device_remove_network(wifi->device, connman_network);
894 connman_network_unref(connman_network);
897 static void network_changed(GSupplicantNetwork *network, const char *property)
899 GSupplicantInterface *interface;
900 struct wifi_data *wifi;
901 const char *name, *identifier;
902 struct connman_network *connman_network;
904 interface = g_supplicant_network_get_interface(network);
905 wifi = g_supplicant_interface_get_data(interface);
906 identifier = g_supplicant_network_get_identifier(network);
907 name = g_supplicant_network_get_name(network);
909 DBG("name %s", name);
914 connman_network = connman_device_get_network(wifi->device, identifier);
915 if (connman_network == NULL)
918 if (g_str_equal(property, "Signal") == TRUE) {
919 connman_network_set_strength(connman_network,
920 calculate_strength(network));
921 connman_network_update(connman_network);
925 static void debug(const char *str)
927 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
928 connman_debug("%s", str);
931 static const GSupplicantCallbacks callbacks = {
932 .system_ready = system_ready,
933 .system_killed = system_killed,
934 .interface_added = interface_added,
935 .interface_state = interface_state,
936 .interface_removed = interface_removed,
937 .scan_started = scan_started,
938 .scan_finished = scan_finished,
939 .network_added = network_added,
940 .network_removed = network_removed,
941 .network_changed = network_changed,
946 static int tech_probe(struct connman_technology *technology)
948 wifi_technology = technology;
953 static void tech_remove(struct connman_technology *technology)
955 wifi_technology = NULL;
958 struct wifi_tethering_info {
959 struct wifi_data *wifi;
960 struct connman_technology *technology;
962 GSupplicantSSID *ssid;
965 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
969 ap = g_try_malloc0(sizeof(GSupplicantSSID));
973 ap->mode = G_SUPPLICANT_MODE_MASTER;
975 ap->ssid_len = strlen(ssid);
979 if (passphrase == NULL || strlen(passphrase) == 0) {
980 ap->security = G_SUPPLICANT_SECURITY_NONE;
981 ap->passphrase = NULL;
983 ap->security = G_SUPPLICANT_SECURITY_PSK;
984 ap->protocol = G_SUPPLICANT_PROTO_RSN;
985 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
986 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
987 ap->passphrase = passphrase;
993 static void ap_start_callback(int result, GSupplicantInterface *interface,
996 struct wifi_tethering_info *info = user_data;
998 DBG("result %d index %d bridge %s",
999 result, info->wifi->index, info->wifi->bridge);
1002 connman_inet_remove_from_bridge(info->wifi->index,
1003 info->wifi->bridge);
1004 connman_technology_tethering_notify(info->technology, FALSE);
1007 g_free(info->ifname);
1011 static void ap_create_callback(int result,
1012 GSupplicantInterface *interface,
1015 struct wifi_tethering_info *info = user_data;
1017 DBG("result %d ifname %s", result,
1018 g_supplicant_interface_get_ifname(interface));
1021 connman_inet_remove_from_bridge(info->wifi->index,
1022 info->wifi->bridge);
1023 connman_technology_tethering_notify(info->technology, FALSE);
1025 g_free(info->ifname);
1030 info->wifi->interface = interface;
1031 g_supplicant_interface_set_data(interface, info->wifi);
1033 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
1034 connman_error("Failed to set interface ap_scan property");
1036 g_supplicant_interface_connect(interface, info->ssid,
1037 ap_start_callback, info);
1040 static void sta_remove_callback(int result,
1041 GSupplicantInterface *interface,
1044 struct wifi_tethering_info *info = user_data;
1045 const char *driver = connman_option_get_string("wifi");
1047 DBG("ifname %s result %d ", info->ifname, result);
1050 info->wifi->tethering = TRUE;
1052 g_free(info->ifname);
1057 info->wifi->interface = NULL;
1059 connman_technology_tethering_notify(info->technology, TRUE);
1061 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
1066 static int tech_set_tethering(struct connman_technology *technology,
1067 const char *identifier, const char *passphrase,
1068 const char *bridge, connman_bool_t enabled)
1071 GSupplicantInterface *interface;
1072 struct wifi_data *wifi;
1073 struct wifi_tethering_info *info;
1080 if (enabled == FALSE) {
1081 for (list = iface_list; list; list = list->next) {
1084 if (wifi->tethering == TRUE) {
1085 wifi->tethering = FALSE;
1087 connman_inet_remove_from_bridge(wifi->index,
1089 wifi->bridged = FALSE;
1093 connman_technology_tethering_notify(technology, FALSE);
1098 for (list = iface_list; list; list = list->next) {
1101 interface = wifi->interface;
1103 if (interface == NULL)
1106 ifname = g_supplicant_interface_get_ifname(wifi->interface);
1108 mode = g_supplicant_interface_get_mode(interface);
1109 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
1110 DBG("%s does not support AP mode", ifname);
1114 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
1119 info->technology = technology;
1120 info->wifi->bridge = bridge;
1121 info->ssid = ssid_ap_init(identifier, passphrase);
1122 if (info->ssid == NULL) {
1126 info->ifname = g_strdup(ifname);
1127 if (info->ifname == NULL) {
1132 info->wifi->tethering = TRUE;
1134 err = g_supplicant_interface_remove(interface,
1135 sta_remove_callback,
1144 static void regdom_callback(void *user_data)
1146 char *alpha2 = user_data;
1150 if (wifi_technology == NULL)
1153 connman_technology_regdom_notify(wifi_technology, alpha2);
1156 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
1158 return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
1161 static struct connman_technology_driver tech_driver = {
1163 .type = CONNMAN_SERVICE_TYPE_WIFI,
1164 .probe = tech_probe,
1165 .remove = tech_remove,
1166 .set_tethering = tech_set_tethering,
1167 .set_regdom = tech_set_regdom,
1170 static int wifi_init(void)
1174 err = connman_network_driver_register(&network_driver);
1178 err = g_supplicant_register(&callbacks);
1180 connman_network_driver_unregister(&network_driver);
1184 err = connman_technology_driver_register(&tech_driver);
1186 g_supplicant_unregister(&callbacks);
1187 connman_network_driver_unregister(&network_driver);
1194 static void wifi_exit(void)
1198 connman_technology_driver_unregister(&tech_driver);
1200 g_supplicant_unregister(&callbacks);
1202 connman_network_driver_unregister(&network_driver);
1205 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
1206 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)