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 struct connman_device *device = connman_network_get_device(network);
337 struct wifi_data *wifi;
339 DBG("network %p", network);
341 wifi = connman_device_get_data(device);
345 if (wifi->network != network)
348 wifi->network = NULL;
351 static void connect_callback(int result, GSupplicantInterface *interface,
354 struct connman_network *network = user_data;
356 DBG("network %p result %d", network, result);
358 if (result == -ENOKEY) {
359 connman_network_set_error(network,
360 CONNMAN_NETWORK_ERROR_INVALID_KEY);
361 } else if (result < 0) {
362 connman_network_set_error(network,
363 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
367 static GSupplicantSecurity network_security(const char *security)
369 if (g_str_equal(security, "none") == TRUE)
370 return G_SUPPLICANT_SECURITY_NONE;
371 else if (g_str_equal(security, "wep") == TRUE)
372 return G_SUPPLICANT_SECURITY_WEP;
373 else if (g_str_equal(security, "psk") == TRUE)
374 return G_SUPPLICANT_SECURITY_PSK;
375 else if (g_str_equal(security, "wpa") == TRUE)
376 return G_SUPPLICANT_SECURITY_PSK;
377 else if (g_str_equal(security, "rsn") == TRUE)
378 return G_SUPPLICANT_SECURITY_PSK;
379 else if (g_str_equal(security, "ieee8021x") == TRUE)
380 return G_SUPPLICANT_SECURITY_IEEE8021X;
382 return G_SUPPLICANT_SECURITY_UNKNOWN;
385 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
387 const char *security, *passphrase, *agent_passphrase;
389 memset(ssid, 0, sizeof(*ssid));
390 ssid->mode = G_SUPPLICANT_MODE_INFRA;
391 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
394 security = connman_network_get_string(network, "WiFi.Security");
395 ssid->security = network_security(security);
396 passphrase = connman_network_get_string(network,
398 if (passphrase == NULL || strlen(passphrase) == 0) {
400 /* Use agent provided passphrase as a fallback */
401 agent_passphrase = connman_network_get_string(network,
402 "WiFi.AgentPassphrase");
404 if (agent_passphrase == NULL || strlen(agent_passphrase) == 0)
405 ssid->passphrase = NULL;
407 ssid->passphrase = agent_passphrase;
409 ssid->passphrase = passphrase;
411 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
414 * If our private key password is unset,
415 * we use the supplied passphrase. That is needed
416 * for PEAP where 2 passphrases (identity and client
417 * cert may have to be provided.
419 if (connman_network_get_string(network,
420 "WiFi.PrivateKeyPassphrase") == NULL)
421 connman_network_set_string(network,
422 "WiFi.PrivateKeyPassphrase",
424 /* We must have an identity for both PEAP and TLS */
425 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
427 /* Use agent provided identity as a fallback */
428 if (ssid->identity == NULL || strlen(ssid->identity) == 0)
429 ssid->identity = connman_network_get_string(network,
430 "WiFi.AgentIdentity");
432 ssid->ca_cert_path = connman_network_get_string(network,
434 ssid->client_cert_path = connman_network_get_string(network,
435 "WiFi.ClientCertFile");
436 ssid->private_key_path = connman_network_get_string(network,
437 "WiFi.PrivateKeyFile");
438 ssid->private_key_passphrase = connman_network_get_string(network,
439 "WiFi.PrivateKeyPassphrase");
440 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
442 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
443 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
447 static int network_connect(struct connman_network *network)
449 struct connman_device *device = connman_network_get_device(network);
450 struct wifi_data *wifi;
451 GSupplicantInterface *interface;
452 GSupplicantSSID *ssid;
454 DBG("network %p", network);
459 wifi = connman_device_get_data(device);
463 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
467 interface = wifi->interface;
469 ssid_init(ssid, network);
471 if (wifi->disconnecting == TRUE)
472 wifi->pending_network = network;
474 wifi->network = network;
476 return g_supplicant_interface_connect(interface, ssid,
477 connect_callback, network);
483 static void disconnect_callback(int result, GSupplicantInterface *interface,
486 struct wifi_data *wifi = user_data;
488 if (wifi->network != NULL) {
490 * if result < 0 supplican return an error because
491 * the network is not current.
492 * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
493 * failed, call connman_network_set_connected to report
494 * disconnect is completed.
497 connman_network_set_connected(wifi->network, FALSE);
500 wifi->network = NULL;
502 wifi->disconnecting = FALSE;
504 if (wifi->pending_network != NULL) {
505 network_connect(wifi->pending_network);
506 wifi->pending_network = NULL;
511 static int network_disconnect(struct connman_network *network)
513 struct connman_device *device = connman_network_get_device(network);
514 struct wifi_data *wifi;
517 DBG("network %p", network);
519 wifi = connman_device_get_data(device);
520 if (wifi == NULL || wifi->interface == NULL)
523 connman_network_set_associating(network, FALSE);
525 if (wifi->disconnecting == TRUE)
528 wifi->disconnecting = TRUE;
530 err = g_supplicant_interface_disconnect(wifi->interface,
531 disconnect_callback, wifi);
533 wifi->disconnecting = FALSE;
538 static struct connman_network_driver network_driver = {
540 .type = CONNMAN_NETWORK_TYPE_WIFI,
541 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
542 .probe = network_probe,
543 .remove = network_remove,
544 .connect = network_connect,
545 .disconnect = network_disconnect,
548 static void interface_added(GSupplicantInterface *interface)
550 const char *ifname = g_supplicant_interface_get_ifname(interface);
551 const char *driver = g_supplicant_interface_get_driver(interface);
552 struct wifi_data *wifi;
554 wifi = g_supplicant_interface_get_data(interface);
557 * We can get here with a NULL wifi pointer when
558 * the interface added signal is sent before the
559 * interface creation callback is called.
564 DBG("ifname %s driver %s wifi %p tethering %d",
565 ifname, driver, wifi, wifi->tethering);
567 if (wifi->device == NULL) {
568 connman_error("WiFi device not set");
572 connman_device_set_powered(wifi->device, TRUE);
574 if (wifi->tethering == TRUE)
577 wifi_scan(wifi->device);
580 static connman_bool_t is_idle(struct wifi_data *wifi)
582 DBG("state %d", wifi->state);
584 switch (wifi->state) {
585 case G_SUPPLICANT_STATE_UNKNOWN:
586 case G_SUPPLICANT_STATE_DISCONNECTED:
587 case G_SUPPLICANT_STATE_INACTIVE:
588 case G_SUPPLICANT_STATE_SCANNING:
591 case G_SUPPLICANT_STATE_AUTHENTICATING:
592 case G_SUPPLICANT_STATE_ASSOCIATING:
593 case G_SUPPLICANT_STATE_ASSOCIATED:
594 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
595 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
596 case G_SUPPLICANT_STATE_COMPLETED:
603 static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
604 struct wifi_data *wifi)
606 /* First, let's check if WPS processing did not went wrong */
607 if (g_supplicant_interface_get_wps_state(interface) ==
608 G_SUPPLICANT_WPS_STATE_FAIL)
611 /* Unlike normal connection, being associated while processing wps
612 * actually means that we are idling. */
613 switch (wifi->state) {
614 case G_SUPPLICANT_STATE_UNKNOWN:
615 case G_SUPPLICANT_STATE_DISCONNECTED:
616 case G_SUPPLICANT_STATE_INACTIVE:
617 case G_SUPPLICANT_STATE_SCANNING:
618 case G_SUPPLICANT_STATE_ASSOCIATED:
620 case G_SUPPLICANT_STATE_AUTHENTICATING:
621 case G_SUPPLICANT_STATE_ASSOCIATING:
622 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
623 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
624 case G_SUPPLICANT_STATE_COMPLETED:
631 static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
632 struct connman_network *network,
633 struct connman_device *device,
634 struct wifi_data *wifi)
638 wps = connman_network_get_bool(network, "WiFi.UseWPS");
640 const unsigned char *ssid, *wps_ssid;
641 unsigned int ssid_len, wps_ssid_len;
644 /* Checking if we got associated with requested
646 ssid = connman_network_get_blob(network, "WiFi.SSID",
649 wps_ssid = g_supplicant_interface_get_wps_ssid(
650 interface, &wps_ssid_len);
652 if (wps_ssid == NULL || wps_ssid_len != ssid_len ||
653 memcmp(ssid, wps_ssid, ssid_len) != 0) {
654 connman_network_set_associating(network, FALSE);
655 g_supplicant_interface_disconnect(wifi->interface,
656 disconnect_callback, wifi);
660 wps_key = g_supplicant_interface_get_wps_key(interface);
661 connman_network_set_string(network, "WiFi.Passphrase",
664 connman_network_set_string(network, "WiFi.PinWPS", NULL);
670 static void interface_state(GSupplicantInterface *interface)
672 struct connman_network *network;
673 struct connman_device *device;
674 struct wifi_data *wifi;
675 GSupplicantState state = g_supplicant_interface_get_state(interface);
678 wifi = g_supplicant_interface_get_data(interface);
680 DBG("wifi %p interface state %d", wifi, state);
685 network = wifi->network;
686 device = wifi->device;
688 if (device == NULL || network == NULL)
692 case G_SUPPLICANT_STATE_SCANNING:
695 case G_SUPPLICANT_STATE_AUTHENTICATING:
696 case G_SUPPLICANT_STATE_ASSOCIATING:
697 connman_network_set_associating(network, TRUE);
700 case G_SUPPLICANT_STATE_COMPLETED:
701 if (handle_wps_completion(interface, network, device, wifi) ==
705 /* reset scan trigger and schedule background scan */
706 connman_device_schedule_scan(device);
708 connman_network_set_connected(network, TRUE);
711 case G_SUPPLICANT_STATE_DISCONNECTED:
713 * If we're in one of the idle modes, we have
714 * not started association yet and thus setting
715 * those ones to FALSE could cancel an association
718 wps = connman_network_get_bool(network, "WiFi.UseWPS");
720 if (is_idle_wps(interface, wifi) == TRUE)
725 connman_network_set_associating(network, FALSE);
726 connman_network_set_connected(network, FALSE);
729 case G_SUPPLICANT_STATE_INACTIVE:
730 connman_network_set_associating(network, FALSE);
733 case G_SUPPLICANT_STATE_UNKNOWN:
734 case G_SUPPLICANT_STATE_ASSOCIATED:
735 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
736 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
745 static void interface_removed(GSupplicantInterface *interface)
747 const char *ifname = g_supplicant_interface_get_ifname(interface);
748 struct wifi_data *wifi;
750 DBG("ifname %s", ifname);
752 wifi = g_supplicant_interface_get_data(interface);
754 if (wifi != NULL && wifi->tethering == TRUE)
757 if (wifi == NULL || wifi->device == NULL) {
758 connman_error("Wrong wifi pointer");
762 connman_device_set_powered(wifi->device, FALSE);
765 static void scan_started(GSupplicantInterface *interface)
770 static void scan_finished(GSupplicantInterface *interface)
775 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
777 unsigned char strength;
779 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
786 static void network_added(GSupplicantNetwork *supplicant_network)
788 struct connman_network *network;
789 GSupplicantInterface *interface;
790 struct wifi_data *wifi;
791 const char *name, *identifier, *security, *group;
792 const unsigned char *ssid;
793 unsigned int ssid_len;
798 interface = g_supplicant_network_get_interface(supplicant_network);
799 wifi = g_supplicant_interface_get_data(interface);
800 name = g_supplicant_network_get_name(supplicant_network);
801 identifier = g_supplicant_network_get_identifier(supplicant_network);
802 security = g_supplicant_network_get_security(supplicant_network);
803 group = g_supplicant_network_get_identifier(supplicant_network);
804 wps = g_supplicant_network_get_wps(supplicant_network);
809 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
811 network = connman_device_get_network(wifi->device, identifier);
813 if (network == NULL) {
814 network = connman_network_create(identifier,
815 CONNMAN_NETWORK_TYPE_WIFI);
819 connman_network_set_index(network, wifi->index);
821 if (connman_device_add_network(wifi->device, network) < 0) {
822 connman_network_unref(network);
826 wifi->networks = g_slist_append(wifi->networks, network);
829 if (name != NULL && name[0] != '\0')
830 connman_network_set_name(network, name);
832 connman_network_set_blob(network, "WiFi.SSID",
834 connman_network_set_string(network, "WiFi.Security", security);
835 connman_network_set_strength(network,
836 calculate_strength(supplicant_network));
837 connman_network_set_bool(network, "WiFi.WPS", wps);
839 connman_network_set_available(network, TRUE);
842 connman_network_set_group(network, group);
845 static void network_removed(GSupplicantNetwork *network)
847 GSupplicantInterface *interface;
848 struct wifi_data *wifi;
849 const char *name, *identifier;
850 struct connman_network *connman_network;
852 interface = g_supplicant_network_get_interface(network);
853 wifi = g_supplicant_interface_get_data(interface);
854 identifier = g_supplicant_network_get_identifier(network);
855 name = g_supplicant_network_get_name(network);
857 DBG("name %s", name);
862 connman_network = connman_device_get_network(wifi->device, identifier);
863 if (connman_network == NULL)
866 wifi->networks = g_slist_remove(wifi->networks, connman_network);
868 connman_device_remove_network(wifi->device, connman_network);
869 connman_network_unref(connman_network);
872 static void network_changed(GSupplicantNetwork *network, const char *property)
874 GSupplicantInterface *interface;
875 struct wifi_data *wifi;
876 const char *name, *identifier;
877 struct connman_network *connman_network;
879 interface = g_supplicant_network_get_interface(network);
880 wifi = g_supplicant_interface_get_data(interface);
881 identifier = g_supplicant_network_get_identifier(network);
882 name = g_supplicant_network_get_name(network);
884 DBG("name %s", name);
889 connman_network = connman_device_get_network(wifi->device, identifier);
890 if (connman_network == NULL)
893 if (g_str_equal(property, "Signal") == TRUE) {
894 connman_network_set_strength(connman_network,
895 calculate_strength(network));
896 connman_network_update(connman_network);
900 static void debug(const char *str)
902 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
903 connman_debug("%s", str);
906 static const GSupplicantCallbacks callbacks = {
907 .system_ready = system_ready,
908 .system_killed = system_killed,
909 .interface_added = interface_added,
910 .interface_state = interface_state,
911 .interface_removed = interface_removed,
912 .scan_started = scan_started,
913 .scan_finished = scan_finished,
914 .network_added = network_added,
915 .network_removed = network_removed,
916 .network_changed = network_changed,
921 static int tech_probe(struct connman_technology *technology)
923 wifi_technology = technology;
928 static void tech_remove(struct connman_technology *technology)
930 wifi_technology = NULL;
933 struct wifi_tethering_info {
934 struct wifi_data *wifi;
935 struct connman_technology *technology;
937 GSupplicantSSID *ssid;
940 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
944 ap = g_try_malloc0(sizeof(GSupplicantSSID));
948 ap->mode = G_SUPPLICANT_MODE_MASTER;
950 ap->ssid_len = strlen(ssid);
954 if (passphrase == NULL || strlen(passphrase) == 0) {
955 ap->security = G_SUPPLICANT_SECURITY_NONE;
956 ap->passphrase = NULL;
958 ap->security = G_SUPPLICANT_SECURITY_PSK;
959 ap->protocol = G_SUPPLICANT_PROTO_RSN;
960 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
961 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
962 ap->passphrase = passphrase;
968 static void ap_start_callback(int result, GSupplicantInterface *interface,
971 struct wifi_tethering_info *info = user_data;
973 DBG("result %d index %d bridge %s",
974 result, info->wifi->index, info->wifi->bridge);
977 connman_inet_remove_from_bridge(info->wifi->index,
979 connman_technology_tethering_notify(info->technology, FALSE);
982 g_free(info->ifname);
986 static void ap_create_callback(int result,
987 GSupplicantInterface *interface,
990 struct wifi_tethering_info *info = user_data;
992 DBG("result %d ifname %s", result,
993 g_supplicant_interface_get_ifname(interface));
996 connman_inet_remove_from_bridge(info->wifi->index,
998 connman_technology_tethering_notify(info->technology, FALSE);
1000 g_free(info->ifname);
1005 info->wifi->interface = interface;
1006 g_supplicant_interface_set_data(interface, info->wifi);
1008 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
1009 connman_error("Failed to set interface ap_scan property");
1011 g_supplicant_interface_connect(interface, info->ssid,
1012 ap_start_callback, info);
1015 static void sta_remove_callback(int result,
1016 GSupplicantInterface *interface,
1019 struct wifi_tethering_info *info = user_data;
1020 const char *driver = connman_option_get_string("wifi");
1022 DBG("ifname %s result %d ", info->ifname, result);
1025 info->wifi->tethering = TRUE;
1027 g_free(info->ifname);
1032 info->wifi->interface = NULL;
1034 connman_technology_tethering_notify(info->technology, TRUE);
1036 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
1041 static int tech_set_tethering(struct connman_technology *technology,
1042 const char *identifier, const char *passphrase,
1043 const char *bridge, connman_bool_t enabled)
1046 GSupplicantInterface *interface;
1047 struct wifi_data *wifi;
1048 struct wifi_tethering_info *info;
1055 if (enabled == FALSE) {
1056 for (list = iface_list; list; list = list->next) {
1059 if (wifi->tethering == TRUE) {
1060 wifi->tethering = FALSE;
1062 connman_inet_remove_from_bridge(wifi->index,
1064 wifi->bridged = FALSE;
1068 connman_technology_tethering_notify(technology, FALSE);
1073 for (list = iface_list; list; list = list->next) {
1076 interface = wifi->interface;
1078 if (interface == NULL)
1081 ifname = g_supplicant_interface_get_ifname(wifi->interface);
1083 mode = g_supplicant_interface_get_mode(interface);
1084 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
1085 DBG("%s does not support AP mode", ifname);
1089 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
1094 info->technology = technology;
1095 info->wifi->bridge = bridge;
1096 info->ssid = ssid_ap_init(identifier, passphrase);
1097 if (info->ssid == NULL) {
1101 info->ifname = g_strdup(ifname);
1102 if (info->ifname == NULL) {
1107 info->wifi->tethering = TRUE;
1109 err = g_supplicant_interface_remove(interface,
1110 sta_remove_callback,
1119 static void regdom_callback(void *user_data)
1121 char *alpha2 = user_data;
1125 if (wifi_technology == NULL)
1128 connman_technology_regdom_notify(wifi_technology, alpha2);
1131 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
1133 return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
1136 static struct connman_technology_driver tech_driver = {
1138 .type = CONNMAN_SERVICE_TYPE_WIFI,
1139 .probe = tech_probe,
1140 .remove = tech_remove,
1141 .set_tethering = tech_set_tethering,
1142 .set_regdom = tech_set_regdom,
1145 static int wifi_init(void)
1149 err = connman_network_driver_register(&network_driver);
1153 err = g_supplicant_register(&callbacks);
1155 connman_network_driver_unregister(&network_driver);
1159 err = connman_technology_driver_register(&tech_driver);
1161 g_supplicant_unregister(&callbacks);
1162 connman_network_driver_unregister(&network_driver);
1169 static void wifi_exit(void)
1173 connman_technology_driver_unregister(&tech_driver);
1175 g_supplicant_unregister(&callbacks);
1177 connman_network_driver_unregister(&network_driver);
1180 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
1181 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)