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 struct connman_device_driver wifi_ng_driver = {
308 .type = CONNMAN_DEVICE_TYPE_WIFI,
309 .priority = CONNMAN_DEVICE_PRIORITY_LOW,
311 .remove = wifi_remove,
312 .enable = wifi_enable,
313 .disable = wifi_disable,
317 static void system_ready(void)
321 if (connman_device_driver_register(&wifi_ng_driver) < 0)
322 connman_error("Failed to register WiFi driver");
325 static void system_killed(void)
329 connman_device_driver_unregister(&wifi_ng_driver);
332 static int network_probe(struct connman_network *network)
334 DBG("network %p", network);
339 static void network_remove(struct connman_network *network)
341 struct connman_device *device = connman_network_get_device(network);
342 struct wifi_data *wifi;
344 DBG("network %p", network);
346 wifi = connman_device_get_data(device);
350 if (wifi->network != network)
353 wifi->network = NULL;
356 static void connect_callback(int result, GSupplicantInterface *interface,
359 struct connman_network *network = user_data;
361 DBG("network %p result %d", network, result);
363 if (result == -ENOKEY) {
364 connman_network_set_error(network,
365 CONNMAN_NETWORK_ERROR_INVALID_KEY);
366 } else if (result < 0) {
367 connman_network_set_error(network,
368 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
372 static GSupplicantSecurity network_security(const char *security)
374 if (g_str_equal(security, "none") == TRUE)
375 return G_SUPPLICANT_SECURITY_NONE;
376 else if (g_str_equal(security, "wep") == TRUE)
377 return G_SUPPLICANT_SECURITY_WEP;
378 else if (g_str_equal(security, "psk") == TRUE)
379 return G_SUPPLICANT_SECURITY_PSK;
380 else if (g_str_equal(security, "wpa") == TRUE)
381 return G_SUPPLICANT_SECURITY_PSK;
382 else if (g_str_equal(security, "rsn") == TRUE)
383 return G_SUPPLICANT_SECURITY_PSK;
384 else if (g_str_equal(security, "ieee8021x") == TRUE)
385 return G_SUPPLICANT_SECURITY_IEEE8021X;
387 return G_SUPPLICANT_SECURITY_UNKNOWN;
390 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
392 const char *security, *passphrase, *agent_passphrase;
394 memset(ssid, 0, sizeof(*ssid));
395 ssid->mode = G_SUPPLICANT_MODE_INFRA;
396 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
399 security = connman_network_get_string(network, "WiFi.Security");
400 ssid->security = network_security(security);
401 passphrase = connman_network_get_string(network,
403 if (passphrase == NULL || strlen(passphrase) == 0) {
405 /* Use agent provided passphrase as a fallback */
406 agent_passphrase = connman_network_get_string(network,
407 "WiFi.AgentPassphrase");
409 if (agent_passphrase == NULL || strlen(agent_passphrase) == 0)
410 ssid->passphrase = NULL;
412 ssid->passphrase = agent_passphrase;
414 ssid->passphrase = passphrase;
416 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
419 * If our private key password is unset,
420 * we use the supplied passphrase. That is needed
421 * for PEAP where 2 passphrases (identity and client
422 * cert may have to be provided.
424 if (connman_network_get_string(network,
425 "WiFi.PrivateKeyPassphrase") == NULL)
426 connman_network_set_string(network,
427 "WiFi.PrivateKeyPassphrase",
429 /* We must have an identity for both PEAP and TLS */
430 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
432 /* Use agent provided identity as a fallback */
433 if (ssid->identity == NULL || strlen(ssid->identity) == 0)
434 ssid->identity = connman_network_get_string(network,
435 "WiFi.AgentIdentity");
437 ssid->ca_cert_path = connman_network_get_string(network,
439 ssid->client_cert_path = connman_network_get_string(network,
440 "WiFi.ClientCertFile");
441 ssid->private_key_path = connman_network_get_string(network,
442 "WiFi.PrivateKeyFile");
443 ssid->private_key_passphrase = connman_network_get_string(network,
444 "WiFi.PrivateKeyPassphrase");
445 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
447 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
448 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
452 static int network_connect(struct connman_network *network)
454 struct connman_device *device = connman_network_get_device(network);
455 struct wifi_data *wifi;
456 GSupplicantInterface *interface;
457 GSupplicantSSID *ssid;
459 DBG("network %p", network);
464 wifi = connman_device_get_data(device);
468 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
472 interface = wifi->interface;
474 ssid_init(ssid, network);
476 if (wifi->disconnecting == TRUE)
477 wifi->pending_network = network;
479 wifi->network = network;
481 return g_supplicant_interface_connect(interface, ssid,
482 connect_callback, network);
488 static void disconnect_callback(int result, GSupplicantInterface *interface,
491 struct wifi_data *wifi = user_data;
493 if (wifi->network != NULL) {
495 * if result < 0 supplican return an error because
496 * the network is not current.
497 * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
498 * failed, call connman_network_set_connected to report
499 * disconnect is completed.
502 connman_network_set_connected(wifi->network, FALSE);
505 wifi->network = NULL;
507 wifi->disconnecting = FALSE;
509 if (wifi->pending_network != NULL) {
510 network_connect(wifi->pending_network);
511 wifi->pending_network = NULL;
516 static int network_disconnect(struct connman_network *network)
518 struct connman_device *device = connman_network_get_device(network);
519 struct wifi_data *wifi;
522 DBG("network %p", network);
524 wifi = connman_device_get_data(device);
525 if (wifi == NULL || wifi->interface == NULL)
528 connman_network_set_associating(network, FALSE);
530 if (wifi->disconnecting == TRUE)
533 wifi->disconnecting = TRUE;
535 err = g_supplicant_interface_disconnect(wifi->interface,
536 disconnect_callback, wifi);
538 wifi->disconnecting = FALSE;
543 static struct connman_network_driver network_driver = {
545 .type = CONNMAN_NETWORK_TYPE_WIFI,
546 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
547 .probe = network_probe,
548 .remove = network_remove,
549 .connect = network_connect,
550 .disconnect = network_disconnect,
553 static void interface_added(GSupplicantInterface *interface)
555 const char *ifname = g_supplicant_interface_get_ifname(interface);
556 const char *driver = g_supplicant_interface_get_driver(interface);
557 struct wifi_data *wifi;
559 wifi = g_supplicant_interface_get_data(interface);
562 * We can get here with a NULL wifi pointer when
563 * the interface added signal is sent before the
564 * interface creation callback is called.
569 DBG("ifname %s driver %s wifi %p tethering %d",
570 ifname, driver, wifi, wifi->tethering);
572 if (wifi->device == NULL) {
573 connman_error("WiFi device not set");
577 connman_device_set_powered(wifi->device, TRUE);
579 if (wifi->tethering == TRUE)
582 wifi_scan(wifi->device);
585 static connman_bool_t is_idle(struct wifi_data *wifi)
587 DBG("state %d", wifi->state);
589 switch (wifi->state) {
590 case G_SUPPLICANT_STATE_UNKNOWN:
591 case G_SUPPLICANT_STATE_DISCONNECTED:
592 case G_SUPPLICANT_STATE_INACTIVE:
593 case G_SUPPLICANT_STATE_SCANNING:
596 case G_SUPPLICANT_STATE_AUTHENTICATING:
597 case G_SUPPLICANT_STATE_ASSOCIATING:
598 case G_SUPPLICANT_STATE_ASSOCIATED:
599 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
600 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
601 case G_SUPPLICANT_STATE_COMPLETED:
608 static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
609 struct wifi_data *wifi)
611 /* First, let's check if WPS processing did not went wrong */
612 if (g_supplicant_interface_get_wps_state(interface) ==
613 G_SUPPLICANT_WPS_STATE_FAIL)
616 /* Unlike normal connection, being associated while processing wps
617 * actually means that we are idling. */
618 switch (wifi->state) {
619 case G_SUPPLICANT_STATE_UNKNOWN:
620 case G_SUPPLICANT_STATE_DISCONNECTED:
621 case G_SUPPLICANT_STATE_INACTIVE:
622 case G_SUPPLICANT_STATE_SCANNING:
623 case G_SUPPLICANT_STATE_ASSOCIATED:
625 case G_SUPPLICANT_STATE_AUTHENTICATING:
626 case G_SUPPLICANT_STATE_ASSOCIATING:
627 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
628 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
629 case G_SUPPLICANT_STATE_COMPLETED:
636 static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
637 struct connman_network *network,
638 struct connman_device *device,
639 struct wifi_data *wifi)
643 wps = connman_network_get_bool(network, "WiFi.UseWPS");
645 const unsigned char *ssid, *wps_ssid;
646 unsigned int ssid_len, wps_ssid_len;
649 /* Checking if we got associated with requested
651 ssid = connman_network_get_blob(network, "WiFi.SSID",
654 wps_ssid = g_supplicant_interface_get_wps_ssid(
655 interface, &wps_ssid_len);
657 if (wps_ssid == NULL || wps_ssid_len != ssid_len ||
658 memcmp(ssid, wps_ssid, ssid_len) != 0) {
659 connman_network_set_associating(network, FALSE);
660 g_supplicant_interface_disconnect(wifi->interface,
661 disconnect_callback, wifi);
665 wps_key = g_supplicant_interface_get_wps_key(interface);
666 connman_network_set_string(network, "WiFi.Passphrase",
669 connman_network_set_string(network, "WiFi.PinWPS", NULL);
675 static void interface_state(GSupplicantInterface *interface)
677 struct connman_network *network;
678 struct connman_device *device;
679 struct wifi_data *wifi;
680 GSupplicantState state = g_supplicant_interface_get_state(interface);
683 wifi = g_supplicant_interface_get_data(interface);
685 DBG("wifi %p interface state %d", wifi, state);
690 network = wifi->network;
691 device = wifi->device;
693 if (device == NULL || network == NULL)
697 case G_SUPPLICANT_STATE_SCANNING:
700 case G_SUPPLICANT_STATE_AUTHENTICATING:
701 case G_SUPPLICANT_STATE_ASSOCIATING:
702 connman_network_set_associating(network, TRUE);
705 case G_SUPPLICANT_STATE_COMPLETED:
706 if (handle_wps_completion(interface, network, device, wifi) ==
710 /* reset scan trigger and schedule background scan */
711 connman_device_schedule_scan(device);
713 connman_network_set_connected(network, TRUE);
716 case G_SUPPLICANT_STATE_DISCONNECTED:
718 * If we're in one of the idle modes, we have
719 * not started association yet and thus setting
720 * those ones to FALSE could cancel an association
723 wps = connman_network_get_bool(network, "WiFi.UseWPS");
725 if (is_idle_wps(interface, wifi) == TRUE)
730 connman_network_set_associating(network, FALSE);
731 connman_network_set_connected(network, FALSE);
734 case G_SUPPLICANT_STATE_INACTIVE:
735 connman_network_set_associating(network, FALSE);
738 case G_SUPPLICANT_STATE_UNKNOWN:
739 case G_SUPPLICANT_STATE_ASSOCIATED:
740 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
741 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
750 static void interface_removed(GSupplicantInterface *interface)
752 const char *ifname = g_supplicant_interface_get_ifname(interface);
753 struct wifi_data *wifi;
755 DBG("ifname %s", ifname);
757 wifi = g_supplicant_interface_get_data(interface);
759 if (wifi != NULL && wifi->tethering == TRUE)
762 if (wifi == NULL || wifi->device == NULL) {
763 connman_error("Wrong wifi pointer");
767 connman_device_set_powered(wifi->device, FALSE);
770 static void scan_started(GSupplicantInterface *interface)
775 static void scan_finished(GSupplicantInterface *interface)
780 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
782 unsigned char strength;
784 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
791 static void network_added(GSupplicantNetwork *supplicant_network)
793 struct connman_network *network;
794 GSupplicantInterface *interface;
795 struct wifi_data *wifi;
796 const char *name, *identifier, *security, *group;
797 const unsigned char *ssid;
798 unsigned int ssid_len;
803 interface = g_supplicant_network_get_interface(supplicant_network);
804 wifi = g_supplicant_interface_get_data(interface);
805 name = g_supplicant_network_get_name(supplicant_network);
806 identifier = g_supplicant_network_get_identifier(supplicant_network);
807 security = g_supplicant_network_get_security(supplicant_network);
808 group = g_supplicant_network_get_identifier(supplicant_network);
809 wps = g_supplicant_network_get_wps(supplicant_network);
814 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
816 network = connman_device_get_network(wifi->device, identifier);
818 if (network == NULL) {
819 network = connman_network_create(identifier,
820 CONNMAN_NETWORK_TYPE_WIFI);
824 connman_network_set_index(network, wifi->index);
826 if (connman_device_add_network(wifi->device, network) < 0) {
827 connman_network_unref(network);
831 wifi->networks = g_slist_append(wifi->networks, network);
834 if (name != NULL && name[0] != '\0')
835 connman_network_set_name(network, name);
837 connman_network_set_blob(network, "WiFi.SSID",
839 connman_network_set_string(network, "WiFi.Security", security);
840 connman_network_set_strength(network,
841 calculate_strength(supplicant_network));
842 connman_network_set_bool(network, "WiFi.WPS", wps);
844 connman_network_set_available(network, TRUE);
847 connman_network_set_group(network, group);
850 static void network_removed(GSupplicantNetwork *network)
852 GSupplicantInterface *interface;
853 struct wifi_data *wifi;
854 const char *name, *identifier;
855 struct connman_network *connman_network;
857 interface = g_supplicant_network_get_interface(network);
858 wifi = g_supplicant_interface_get_data(interface);
859 identifier = g_supplicant_network_get_identifier(network);
860 name = g_supplicant_network_get_name(network);
862 DBG("name %s", name);
867 connman_network = connman_device_get_network(wifi->device, identifier);
868 if (connman_network == NULL)
871 wifi->networks = g_slist_remove(wifi->networks, connman_network);
873 connman_device_remove_network(wifi->device, connman_network);
874 connman_network_unref(connman_network);
877 static void network_changed(GSupplicantNetwork *network, const char *property)
879 GSupplicantInterface *interface;
880 struct wifi_data *wifi;
881 const char *name, *identifier;
882 struct connman_network *connman_network;
884 interface = g_supplicant_network_get_interface(network);
885 wifi = g_supplicant_interface_get_data(interface);
886 identifier = g_supplicant_network_get_identifier(network);
887 name = g_supplicant_network_get_name(network);
889 DBG("name %s", name);
894 connman_network = connman_device_get_network(wifi->device, identifier);
895 if (connman_network == NULL)
898 if (g_str_equal(property, "Signal") == TRUE) {
899 connman_network_set_strength(connman_network,
900 calculate_strength(network));
901 connman_network_update(connman_network);
905 static void debug(const char *str)
907 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
908 connman_debug("%s", str);
911 static const GSupplicantCallbacks callbacks = {
912 .system_ready = system_ready,
913 .system_killed = system_killed,
914 .interface_added = interface_added,
915 .interface_state = interface_state,
916 .interface_removed = interface_removed,
917 .scan_started = scan_started,
918 .scan_finished = scan_finished,
919 .network_added = network_added,
920 .network_removed = network_removed,
921 .network_changed = network_changed,
926 static int tech_probe(struct connman_technology *technology)
928 wifi_technology = technology;
933 static void tech_remove(struct connman_technology *technology)
935 wifi_technology = NULL;
938 struct wifi_tethering_info {
939 struct wifi_data *wifi;
940 struct connman_technology *technology;
942 GSupplicantSSID *ssid;
945 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
949 ap = g_try_malloc0(sizeof(GSupplicantSSID));
953 ap->mode = G_SUPPLICANT_MODE_MASTER;
955 ap->ssid_len = strlen(ssid);
959 if (passphrase == NULL || strlen(passphrase) == 0) {
960 ap->security = G_SUPPLICANT_SECURITY_NONE;
961 ap->passphrase = NULL;
963 ap->security = G_SUPPLICANT_SECURITY_PSK;
964 ap->protocol = G_SUPPLICANT_PROTO_RSN;
965 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
966 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
967 ap->passphrase = passphrase;
973 static void ap_start_callback(int result, GSupplicantInterface *interface,
976 struct wifi_tethering_info *info = user_data;
978 DBG("result %d index %d bridge %s",
979 result, info->wifi->index, info->wifi->bridge);
982 connman_inet_remove_from_bridge(info->wifi->index,
984 connman_technology_tethering_notify(info->technology, FALSE);
987 g_free(info->ifname);
991 static void ap_create_callback(int result,
992 GSupplicantInterface *interface,
995 struct wifi_tethering_info *info = user_data;
997 DBG("result %d ifname %s", result,
998 g_supplicant_interface_get_ifname(interface));
1001 connman_inet_remove_from_bridge(info->wifi->index,
1002 info->wifi->bridge);
1003 connman_technology_tethering_notify(info->technology, FALSE);
1005 g_free(info->ifname);
1010 info->wifi->interface = interface;
1011 g_supplicant_interface_set_data(interface, info->wifi);
1013 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
1014 connman_error("Failed to set interface ap_scan property");
1016 g_supplicant_interface_connect(interface, info->ssid,
1017 ap_start_callback, info);
1020 static void sta_remove_callback(int result,
1021 GSupplicantInterface *interface,
1024 struct wifi_tethering_info *info = user_data;
1025 const char *driver = connman_option_get_string("wifi");
1027 DBG("ifname %s result %d ", info->ifname, result);
1030 info->wifi->tethering = TRUE;
1032 g_free(info->ifname);
1037 info->wifi->interface = NULL;
1039 connman_technology_tethering_notify(info->technology, TRUE);
1041 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
1046 static int tech_set_tethering(struct connman_technology *technology,
1047 const char *identifier, const char *passphrase,
1048 const char *bridge, connman_bool_t enabled)
1051 GSupplicantInterface *interface;
1052 struct wifi_data *wifi;
1053 struct wifi_tethering_info *info;
1060 if (enabled == FALSE) {
1061 for (list = iface_list; list; list = list->next) {
1064 if (wifi->tethering == TRUE) {
1065 wifi->tethering = FALSE;
1067 connman_inet_remove_from_bridge(wifi->index,
1069 wifi->bridged = FALSE;
1073 connman_technology_tethering_notify(technology, FALSE);
1078 for (list = iface_list; list; list = list->next) {
1081 interface = wifi->interface;
1083 if (interface == NULL)
1086 ifname = g_supplicant_interface_get_ifname(wifi->interface);
1088 mode = g_supplicant_interface_get_mode(interface);
1089 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
1090 DBG("%s does not support AP mode", ifname);
1094 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
1099 info->technology = technology;
1100 info->wifi->bridge = bridge;
1101 info->ssid = ssid_ap_init(identifier, passphrase);
1102 if (info->ssid == NULL) {
1106 info->ifname = g_strdup(ifname);
1107 if (info->ifname == NULL) {
1112 info->wifi->tethering = TRUE;
1114 err = g_supplicant_interface_remove(interface,
1115 sta_remove_callback,
1124 static void regdom_callback(void *user_data)
1126 char *alpha2 = user_data;
1130 if (wifi_technology == NULL)
1133 connman_technology_regdom_notify(wifi_technology, alpha2);
1136 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
1138 return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
1141 static struct connman_technology_driver tech_driver = {
1143 .type = CONNMAN_SERVICE_TYPE_WIFI,
1144 .probe = tech_probe,
1145 .remove = tech_remove,
1146 .set_tethering = tech_set_tethering,
1147 .set_regdom = tech_set_regdom,
1150 static int wifi_init(void)
1154 err = connman_network_driver_register(&network_driver);
1158 err = g_supplicant_register(&callbacks);
1160 connman_network_driver_unregister(&network_driver);
1164 err = connman_technology_driver_register(&tech_driver);
1166 g_supplicant_unregister(&callbacks);
1167 connman_network_driver_unregister(&network_driver);
1174 static void wifi_exit(void)
1178 connman_technology_driver_unregister(&tech_driver);
1180 g_supplicant_unregister(&callbacks);
1182 connman_network_driver_unregister(&network_driver);
1185 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
1186 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)