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);
284 static int wifi_scan(struct connman_device *device)
286 struct wifi_data *wifi = connman_device_get_data(device);
289 DBG("device %p %p", device, wifi->interface);
291 if (wifi->tethering == TRUE)
294 ret = g_supplicant_interface_scan(wifi->interface, scan_callback,
297 connman_device_set_scanning(device, TRUE);
302 static struct connman_device_driver wifi_ng_driver = {
304 .type = CONNMAN_DEVICE_TYPE_WIFI,
305 .priority = CONNMAN_DEVICE_PRIORITY_LOW,
307 .remove = wifi_remove,
308 .enable = wifi_enable,
309 .disable = wifi_disable,
313 static void system_ready(void)
317 if (connman_device_driver_register(&wifi_ng_driver) < 0)
318 connman_error("Failed to register WiFi driver");
321 static void system_killed(void)
325 connman_device_driver_unregister(&wifi_ng_driver);
328 static int network_probe(struct connman_network *network)
330 DBG("network %p", network);
335 static void network_remove(struct connman_network *network)
337 struct connman_device *device = connman_network_get_device(network);
338 struct wifi_data *wifi;
340 DBG("network %p", network);
342 wifi = connman_device_get_data(device);
346 if (wifi->network != network)
349 wifi->network = NULL;
352 static void connect_callback(int result, GSupplicantInterface *interface,
355 struct connman_network *network = user_data;
357 DBG("network %p result %d", network, result);
359 if (result == -ENOKEY) {
360 connman_network_set_error(network,
361 CONNMAN_NETWORK_ERROR_INVALID_KEY);
362 } else if (result < 0) {
363 connman_network_set_error(network,
364 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
368 static GSupplicantSecurity network_security(const char *security)
370 if (g_str_equal(security, "none") == TRUE)
371 return G_SUPPLICANT_SECURITY_NONE;
372 else if (g_str_equal(security, "wep") == TRUE)
373 return G_SUPPLICANT_SECURITY_WEP;
374 else if (g_str_equal(security, "psk") == TRUE)
375 return G_SUPPLICANT_SECURITY_PSK;
376 else if (g_str_equal(security, "wpa") == TRUE)
377 return G_SUPPLICANT_SECURITY_PSK;
378 else if (g_str_equal(security, "rsn") == TRUE)
379 return G_SUPPLICANT_SECURITY_PSK;
380 else if (g_str_equal(security, "ieee8021x") == TRUE)
381 return G_SUPPLICANT_SECURITY_IEEE8021X;
383 return G_SUPPLICANT_SECURITY_UNKNOWN;
386 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
388 const char *security, *passphrase, *agent_passphrase;
390 memset(ssid, 0, sizeof(*ssid));
391 ssid->mode = G_SUPPLICANT_MODE_INFRA;
392 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
395 security = connman_network_get_string(network, "WiFi.Security");
396 ssid->security = network_security(security);
397 passphrase = connman_network_get_string(network,
399 if (passphrase == NULL || strlen(passphrase) == 0) {
401 /* Use agent provided passphrase as a fallback */
402 agent_passphrase = connman_network_get_string(network,
403 "WiFi.AgentPassphrase");
405 if (agent_passphrase == NULL || strlen(agent_passphrase) == 0)
406 ssid->passphrase = NULL;
408 ssid->passphrase = agent_passphrase;
410 ssid->passphrase = passphrase;
412 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
415 * If our private key password is unset,
416 * we use the supplied passphrase. That is needed
417 * for PEAP where 2 passphrases (identity and client
418 * cert may have to be provided.
420 if (connman_network_get_string(network,
421 "WiFi.PrivateKeyPassphrase") == NULL)
422 connman_network_set_string(network,
423 "WiFi.PrivateKeyPassphrase",
425 /* We must have an identity for both PEAP and TLS */
426 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
428 /* Use agent provided identity as a fallback */
429 if (ssid->identity == NULL || strlen(ssid->identity) == 0)
430 ssid->identity = connman_network_get_string(network,
431 "WiFi.AgentIdentity");
433 ssid->ca_cert_path = connman_network_get_string(network,
435 ssid->client_cert_path = connman_network_get_string(network,
436 "WiFi.ClientCertFile");
437 ssid->private_key_path = connman_network_get_string(network,
438 "WiFi.PrivateKeyFile");
439 ssid->private_key_passphrase = connman_network_get_string(network,
440 "WiFi.PrivateKeyPassphrase");
441 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
443 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
444 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
448 static int network_connect(struct connman_network *network)
450 struct connman_device *device = connman_network_get_device(network);
451 struct wifi_data *wifi;
452 GSupplicantInterface *interface;
453 GSupplicantSSID *ssid;
455 DBG("network %p", network);
460 wifi = connman_device_get_data(device);
464 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
468 interface = wifi->interface;
470 ssid_init(ssid, network);
472 if (wifi->disconnecting == TRUE)
473 wifi->pending_network = network;
475 wifi->network = network;
477 return g_supplicant_interface_connect(interface, ssid,
478 connect_callback, network);
484 static void disconnect_callback(int result, GSupplicantInterface *interface,
487 struct wifi_data *wifi = user_data;
489 if (wifi->network != NULL) {
491 * if result < 0 supplican return an error because
492 * the network is not current.
493 * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
494 * failed, call connman_network_set_connected to report
495 * disconnect is completed.
498 connman_network_set_connected(wifi->network, FALSE);
501 wifi->network = NULL;
503 wifi->disconnecting = FALSE;
505 if (wifi->pending_network != NULL) {
506 network_connect(wifi->pending_network);
507 wifi->pending_network = NULL;
512 static int network_disconnect(struct connman_network *network)
514 struct connman_device *device = connman_network_get_device(network);
515 struct wifi_data *wifi;
518 DBG("network %p", network);
520 wifi = connman_device_get_data(device);
521 if (wifi == NULL || wifi->interface == NULL)
524 connman_network_set_associating(network, FALSE);
526 if (wifi->disconnecting == TRUE)
529 wifi->disconnecting = TRUE;
531 err = g_supplicant_interface_disconnect(wifi->interface,
532 disconnect_callback, wifi);
534 wifi->disconnecting = FALSE;
539 static struct connman_network_driver network_driver = {
541 .type = CONNMAN_NETWORK_TYPE_WIFI,
542 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
543 .probe = network_probe,
544 .remove = network_remove,
545 .connect = network_connect,
546 .disconnect = network_disconnect,
549 static void interface_added(GSupplicantInterface *interface)
551 const char *ifname = g_supplicant_interface_get_ifname(interface);
552 const char *driver = g_supplicant_interface_get_driver(interface);
553 struct wifi_data *wifi;
555 wifi = g_supplicant_interface_get_data(interface);
558 * We can get here with a NULL wifi pointer when
559 * the interface added signal is sent before the
560 * interface creation callback is called.
565 DBG("ifname %s driver %s wifi %p tethering %d",
566 ifname, driver, wifi, wifi->tethering);
568 if (wifi->device == NULL) {
569 connman_error("WiFi device not set");
573 connman_device_set_powered(wifi->device, TRUE);
575 if (wifi->tethering == TRUE)
578 wifi_scan(wifi->device);
581 static connman_bool_t is_idle(struct wifi_data *wifi)
583 DBG("state %d", wifi->state);
585 switch (wifi->state) {
586 case G_SUPPLICANT_STATE_UNKNOWN:
587 case G_SUPPLICANT_STATE_DISCONNECTED:
588 case G_SUPPLICANT_STATE_INACTIVE:
589 case G_SUPPLICANT_STATE_SCANNING:
592 case G_SUPPLICANT_STATE_AUTHENTICATING:
593 case G_SUPPLICANT_STATE_ASSOCIATING:
594 case G_SUPPLICANT_STATE_ASSOCIATED:
595 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
596 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
597 case G_SUPPLICANT_STATE_COMPLETED:
604 static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
605 struct wifi_data *wifi)
607 /* First, let's check if WPS processing did not went wrong */
608 if (g_supplicant_interface_get_wps_state(interface) ==
609 G_SUPPLICANT_WPS_STATE_FAIL)
612 /* Unlike normal connection, being associated while processing wps
613 * actually means that we are idling. */
614 switch (wifi->state) {
615 case G_SUPPLICANT_STATE_UNKNOWN:
616 case G_SUPPLICANT_STATE_DISCONNECTED:
617 case G_SUPPLICANT_STATE_INACTIVE:
618 case G_SUPPLICANT_STATE_SCANNING:
619 case G_SUPPLICANT_STATE_ASSOCIATED:
621 case G_SUPPLICANT_STATE_AUTHENTICATING:
622 case G_SUPPLICANT_STATE_ASSOCIATING:
623 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
624 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
625 case G_SUPPLICANT_STATE_COMPLETED:
632 static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
633 struct connman_network *network,
634 struct connman_device *device,
635 struct wifi_data *wifi)
639 wps = connman_network_get_bool(network, "WiFi.UseWPS");
641 const unsigned char *ssid, *wps_ssid;
642 unsigned int ssid_len, wps_ssid_len;
645 /* Checking if we got associated with requested
647 ssid = connman_network_get_blob(network, "WiFi.SSID",
650 wps_ssid = g_supplicant_interface_get_wps_ssid(
651 interface, &wps_ssid_len);
653 if (wps_ssid == NULL || wps_ssid_len != ssid_len ||
654 memcmp(ssid, wps_ssid, ssid_len) != 0) {
655 connman_network_set_associating(network, FALSE);
656 g_supplicant_interface_disconnect(wifi->interface,
657 disconnect_callback, wifi);
661 wps_key = g_supplicant_interface_get_wps_key(interface);
662 connman_network_set_string(network, "WiFi.Passphrase",
665 connman_network_set_string(network, "WiFi.PinWPS", NULL);
671 static void interface_state(GSupplicantInterface *interface)
673 struct connman_network *network;
674 struct connman_device *device;
675 struct wifi_data *wifi;
676 GSupplicantState state = g_supplicant_interface_get_state(interface);
679 wifi = g_supplicant_interface_get_data(interface);
681 DBG("wifi %p interface state %d", wifi, state);
686 network = wifi->network;
687 device = wifi->device;
689 if (device == NULL || network == NULL)
693 case G_SUPPLICANT_STATE_SCANNING:
696 case G_SUPPLICANT_STATE_AUTHENTICATING:
697 case G_SUPPLICANT_STATE_ASSOCIATING:
698 connman_network_set_associating(network, TRUE);
701 case G_SUPPLICANT_STATE_COMPLETED:
702 if (handle_wps_completion(interface, network, device, wifi) ==
706 /* reset scan trigger and schedule background scan */
707 connman_device_schedule_scan(device);
709 connman_network_set_connected(network, TRUE);
712 case G_SUPPLICANT_STATE_DISCONNECTED:
714 * If we're in one of the idle modes, we have
715 * not started association yet and thus setting
716 * those ones to FALSE could cancel an association
719 wps = connman_network_get_bool(network, "WiFi.UseWPS");
721 if (is_idle_wps(interface, wifi) == TRUE)
726 connman_network_set_associating(network, FALSE);
727 connman_network_set_connected(network, FALSE);
730 case G_SUPPLICANT_STATE_INACTIVE:
731 connman_network_set_associating(network, FALSE);
734 case G_SUPPLICANT_STATE_UNKNOWN:
735 case G_SUPPLICANT_STATE_ASSOCIATED:
736 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
737 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
746 static void interface_removed(GSupplicantInterface *interface)
748 const char *ifname = g_supplicant_interface_get_ifname(interface);
749 struct wifi_data *wifi;
751 DBG("ifname %s", ifname);
753 wifi = g_supplicant_interface_get_data(interface);
755 if (wifi != NULL && wifi->tethering == TRUE)
758 if (wifi == NULL || wifi->device == NULL) {
759 connman_error("Wrong wifi pointer");
763 connman_device_set_powered(wifi->device, FALSE);
766 static void scan_started(GSupplicantInterface *interface)
771 static void scan_finished(GSupplicantInterface *interface)
776 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
778 unsigned char strength;
780 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
787 static void network_added(GSupplicantNetwork *supplicant_network)
789 struct connman_network *network;
790 GSupplicantInterface *interface;
791 struct wifi_data *wifi;
792 const char *name, *identifier, *security, *group;
793 const unsigned char *ssid;
794 unsigned int ssid_len;
799 interface = g_supplicant_network_get_interface(supplicant_network);
800 wifi = g_supplicant_interface_get_data(interface);
801 name = g_supplicant_network_get_name(supplicant_network);
802 identifier = g_supplicant_network_get_identifier(supplicant_network);
803 security = g_supplicant_network_get_security(supplicant_network);
804 group = g_supplicant_network_get_identifier(supplicant_network);
805 wps = g_supplicant_network_get_wps(supplicant_network);
810 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
812 network = connman_device_get_network(wifi->device, identifier);
814 if (network == NULL) {
815 network = connman_network_create(identifier,
816 CONNMAN_NETWORK_TYPE_WIFI);
820 connman_network_set_index(network, wifi->index);
822 if (connman_device_add_network(wifi->device, network) < 0) {
823 connman_network_unref(network);
827 wifi->networks = g_slist_append(wifi->networks, network);
830 if (name != NULL && name[0] != '\0')
831 connman_network_set_name(network, name);
833 connman_network_set_blob(network, "WiFi.SSID",
835 connman_network_set_string(network, "WiFi.Security", security);
836 connman_network_set_strength(network,
837 calculate_strength(supplicant_network));
838 connman_network_set_bool(network, "WiFi.WPS", wps);
840 connman_network_set_available(network, TRUE);
843 connman_network_set_group(network, group);
846 static void network_removed(GSupplicantNetwork *network)
848 GSupplicantInterface *interface;
849 struct wifi_data *wifi;
850 const char *name, *identifier;
851 struct connman_network *connman_network;
853 interface = g_supplicant_network_get_interface(network);
854 wifi = g_supplicant_interface_get_data(interface);
855 identifier = g_supplicant_network_get_identifier(network);
856 name = g_supplicant_network_get_name(network);
858 DBG("name %s", name);
863 connman_network = connman_device_get_network(wifi->device, identifier);
864 if (connman_network == NULL)
867 wifi->networks = g_slist_remove(wifi->networks, connman_network);
869 connman_device_remove_network(wifi->device, connman_network);
870 connman_network_unref(connman_network);
873 static void network_changed(GSupplicantNetwork *network, const char *property)
875 GSupplicantInterface *interface;
876 struct wifi_data *wifi;
877 const char *name, *identifier;
878 struct connman_network *connman_network;
880 interface = g_supplicant_network_get_interface(network);
881 wifi = g_supplicant_interface_get_data(interface);
882 identifier = g_supplicant_network_get_identifier(network);
883 name = g_supplicant_network_get_name(network);
885 DBG("name %s", name);
890 connman_network = connman_device_get_network(wifi->device, identifier);
891 if (connman_network == NULL)
894 if (g_str_equal(property, "Signal") == TRUE) {
895 connman_network_set_strength(connman_network,
896 calculate_strength(network));
897 connman_network_update(connman_network);
901 static void debug(const char *str)
903 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
904 connman_debug("%s", str);
907 static const GSupplicantCallbacks callbacks = {
908 .system_ready = system_ready,
909 .system_killed = system_killed,
910 .interface_added = interface_added,
911 .interface_state = interface_state,
912 .interface_removed = interface_removed,
913 .scan_started = scan_started,
914 .scan_finished = scan_finished,
915 .network_added = network_added,
916 .network_removed = network_removed,
917 .network_changed = network_changed,
922 static int tech_probe(struct connman_technology *technology)
924 wifi_technology = technology;
929 static void tech_remove(struct connman_technology *technology)
931 wifi_technology = NULL;
934 struct wifi_tethering_info {
935 struct wifi_data *wifi;
936 struct connman_technology *technology;
938 GSupplicantSSID *ssid;
941 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
945 ap = g_try_malloc0(sizeof(GSupplicantSSID));
949 ap->mode = G_SUPPLICANT_MODE_MASTER;
951 ap->ssid_len = strlen(ssid);
955 if (passphrase == NULL || strlen(passphrase) == 0) {
956 ap->security = G_SUPPLICANT_SECURITY_NONE;
957 ap->passphrase = NULL;
959 ap->security = G_SUPPLICANT_SECURITY_PSK;
960 ap->protocol = G_SUPPLICANT_PROTO_RSN;
961 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
962 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
963 ap->passphrase = passphrase;
969 static void ap_start_callback(int result, GSupplicantInterface *interface,
972 struct wifi_tethering_info *info = user_data;
974 DBG("result %d index %d bridge %s",
975 result, info->wifi->index, info->wifi->bridge);
978 connman_inet_remove_from_bridge(info->wifi->index,
980 connman_technology_tethering_notify(info->technology, FALSE);
983 g_free(info->ifname);
987 static void ap_create_callback(int result,
988 GSupplicantInterface *interface,
991 struct wifi_tethering_info *info = user_data;
993 DBG("result %d ifname %s", result,
994 g_supplicant_interface_get_ifname(interface));
997 connman_inet_remove_from_bridge(info->wifi->index,
999 connman_technology_tethering_notify(info->technology, FALSE);
1001 g_free(info->ifname);
1006 info->wifi->interface = interface;
1007 g_supplicant_interface_set_data(interface, info->wifi);
1009 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
1010 connman_error("Failed to set interface ap_scan property");
1012 g_supplicant_interface_connect(interface, info->ssid,
1013 ap_start_callback, info);
1016 static void sta_remove_callback(int result,
1017 GSupplicantInterface *interface,
1020 struct wifi_tethering_info *info = user_data;
1021 const char *driver = connman_option_get_string("wifi");
1023 DBG("ifname %s result %d ", info->ifname, result);
1026 info->wifi->tethering = TRUE;
1028 g_free(info->ifname);
1033 info->wifi->interface = NULL;
1035 connman_technology_tethering_notify(info->technology, TRUE);
1037 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
1042 static int tech_set_tethering(struct connman_technology *technology,
1043 const char *identifier, const char *passphrase,
1044 const char *bridge, connman_bool_t enabled)
1047 GSupplicantInterface *interface;
1048 struct wifi_data *wifi;
1049 struct wifi_tethering_info *info;
1056 if (enabled == FALSE) {
1057 for (list = iface_list; list; list = list->next) {
1060 if (wifi->tethering == TRUE) {
1061 wifi->tethering = FALSE;
1063 connman_inet_remove_from_bridge(wifi->index,
1065 wifi->bridged = FALSE;
1069 connman_technology_tethering_notify(technology, FALSE);
1074 for (list = iface_list; list; list = list->next) {
1077 interface = wifi->interface;
1079 if (interface == NULL)
1082 ifname = g_supplicant_interface_get_ifname(wifi->interface);
1084 mode = g_supplicant_interface_get_mode(interface);
1085 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
1086 DBG("%s does not support AP mode", ifname);
1090 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
1095 info->technology = technology;
1096 info->wifi->bridge = bridge;
1097 info->ssid = ssid_ap_init(identifier, passphrase);
1098 if (info->ssid == NULL) {
1102 info->ifname = g_strdup(ifname);
1103 if (info->ifname == NULL) {
1108 info->wifi->tethering = TRUE;
1110 err = g_supplicant_interface_remove(interface,
1111 sta_remove_callback,
1120 static void regdom_callback(void *user_data)
1122 char *alpha2 = user_data;
1126 if (wifi_technology == NULL)
1129 connman_technology_regdom_notify(wifi_technology, alpha2);
1132 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
1134 return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
1137 static struct connman_technology_driver tech_driver = {
1139 .type = CONNMAN_SERVICE_TYPE_WIFI,
1140 .probe = tech_probe,
1141 .remove = tech_remove,
1142 .set_tethering = tech_set_tethering,
1143 .set_regdom = tech_set_regdom,
1146 static int wifi_init(void)
1150 err = connman_network_driver_register(&network_driver);
1154 err = g_supplicant_register(&callbacks);
1156 connman_network_driver_unregister(&network_driver);
1160 err = connman_technology_driver_register(&tech_driver);
1162 g_supplicant_unregister(&callbacks);
1163 connman_network_driver_unregister(&network_driver);
1170 static void wifi_exit(void)
1174 connman_technology_driver_unregister(&tech_driver);
1176 g_supplicant_unregister(&callbacks);
1178 connman_network_driver_unregister(&network_driver);
1181 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
1182 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)