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)
767 struct wifi_data *wifi;
771 wifi = g_supplicant_interface_get_data(interface);
777 static void scan_finished(GSupplicantInterface *interface)
779 struct wifi_data *wifi;
783 wifi = g_supplicant_interface_get_data(interface);
789 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
791 unsigned char strength;
793 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
800 static void network_added(GSupplicantNetwork *supplicant_network)
802 struct connman_network *network;
803 GSupplicantInterface *interface;
804 struct wifi_data *wifi;
805 const char *name, *identifier, *security, *group;
806 const unsigned char *ssid;
807 unsigned int ssid_len;
812 interface = g_supplicant_network_get_interface(supplicant_network);
813 wifi = g_supplicant_interface_get_data(interface);
814 name = g_supplicant_network_get_name(supplicant_network);
815 identifier = g_supplicant_network_get_identifier(supplicant_network);
816 security = g_supplicant_network_get_security(supplicant_network);
817 group = g_supplicant_network_get_identifier(supplicant_network);
818 wps = g_supplicant_network_get_wps(supplicant_network);
823 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
825 network = connman_device_get_network(wifi->device, identifier);
827 if (network == NULL) {
828 network = connman_network_create(identifier,
829 CONNMAN_NETWORK_TYPE_WIFI);
833 connman_network_set_index(network, wifi->index);
835 if (connman_device_add_network(wifi->device, network) < 0) {
836 connman_network_unref(network);
840 wifi->networks = g_slist_append(wifi->networks, network);
843 if (name != NULL && name[0] != '\0')
844 connman_network_set_name(network, name);
846 connman_network_set_blob(network, "WiFi.SSID",
848 connman_network_set_string(network, "WiFi.Security", security);
849 connman_network_set_strength(network,
850 calculate_strength(supplicant_network));
851 connman_network_set_bool(network, "WiFi.WPS", wps);
853 connman_network_set_available(network, TRUE);
856 connman_network_set_group(network, group);
859 static void network_removed(GSupplicantNetwork *network)
861 GSupplicantInterface *interface;
862 struct wifi_data *wifi;
863 const char *name, *identifier;
864 struct connman_network *connman_network;
866 interface = g_supplicant_network_get_interface(network);
867 wifi = g_supplicant_interface_get_data(interface);
868 identifier = g_supplicant_network_get_identifier(network);
869 name = g_supplicant_network_get_name(network);
871 DBG("name %s", name);
876 connman_network = connman_device_get_network(wifi->device, identifier);
877 if (connman_network == NULL)
880 wifi->networks = g_slist_remove(wifi->networks, connman_network);
882 connman_device_remove_network(wifi->device, connman_network);
883 connman_network_unref(connman_network);
886 static void debug(const char *str)
888 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
889 connman_debug("%s", str);
892 static const GSupplicantCallbacks callbacks = {
893 .system_ready = system_ready,
894 .system_killed = system_killed,
895 .interface_added = interface_added,
896 .interface_state = interface_state,
897 .interface_removed = interface_removed,
898 .scan_started = scan_started,
899 .scan_finished = scan_finished,
900 .network_added = network_added,
901 .network_removed = network_removed,
906 static int tech_probe(struct connman_technology *technology)
908 wifi_technology = technology;
913 static void tech_remove(struct connman_technology *technology)
915 wifi_technology = NULL;
918 struct wifi_tethering_info {
919 struct wifi_data *wifi;
920 struct connman_technology *technology;
922 GSupplicantSSID *ssid;
925 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
929 ap = g_try_malloc0(sizeof(GSupplicantSSID));
933 ap->mode = G_SUPPLICANT_MODE_MASTER;
935 ap->ssid_len = strlen(ssid);
939 if (passphrase == NULL || strlen(passphrase) == 0) {
940 ap->security = G_SUPPLICANT_SECURITY_NONE;
941 ap->passphrase = NULL;
943 ap->security = G_SUPPLICANT_SECURITY_PSK;
944 ap->protocol = G_SUPPLICANT_PROTO_RSN;
945 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
946 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
947 ap->passphrase = passphrase;
953 static void ap_start_callback(int result, GSupplicantInterface *interface,
956 struct wifi_tethering_info *info = user_data;
958 DBG("result %d index %d bridge %s",
959 result, info->wifi->index, info->wifi->bridge);
962 connman_inet_remove_from_bridge(info->wifi->index,
964 connman_technology_tethering_notify(info->technology, FALSE);
967 g_free(info->ifname);
971 static void ap_create_callback(int result,
972 GSupplicantInterface *interface,
975 struct wifi_tethering_info *info = user_data;
977 DBG("result %d ifname %s", result,
978 g_supplicant_interface_get_ifname(interface));
981 connman_inet_remove_from_bridge(info->wifi->index,
983 connman_technology_tethering_notify(info->technology, FALSE);
985 g_free(info->ifname);
990 info->wifi->interface = interface;
991 g_supplicant_interface_set_data(interface, info->wifi);
993 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
994 connman_error("Failed to set interface ap_scan property");
996 g_supplicant_interface_connect(interface, info->ssid,
997 ap_start_callback, info);
1000 static void sta_remove_callback(int result,
1001 GSupplicantInterface *interface,
1004 struct wifi_tethering_info *info = user_data;
1005 const char *driver = connman_option_get_string("wifi");
1007 DBG("ifname %s result %d ", info->ifname, result);
1010 info->wifi->tethering = TRUE;
1012 g_free(info->ifname);
1017 info->wifi->interface = NULL;
1019 connman_technology_tethering_notify(info->technology, TRUE);
1021 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
1026 static int tech_set_tethering(struct connman_technology *technology,
1027 const char *identifier, const char *passphrase,
1028 const char *bridge, connman_bool_t enabled)
1031 GSupplicantInterface *interface;
1032 struct wifi_data *wifi;
1033 struct wifi_tethering_info *info;
1040 if (enabled == FALSE) {
1041 for (list = iface_list; list; list = list->next) {
1044 if (wifi->tethering == TRUE) {
1045 wifi->tethering = FALSE;
1047 connman_inet_remove_from_bridge(wifi->index,
1049 wifi->bridged = FALSE;
1053 connman_technology_tethering_notify(technology, FALSE);
1058 for (list = iface_list; list; list = list->next) {
1061 interface = wifi->interface;
1063 if (interface == NULL)
1066 ifname = g_supplicant_interface_get_ifname(wifi->interface);
1068 mode = g_supplicant_interface_get_mode(interface);
1069 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
1070 DBG("%s does not support AP mode", ifname);
1074 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
1079 info->technology = technology;
1080 info->wifi->bridge = bridge;
1081 info->ssid = ssid_ap_init(identifier, passphrase);
1082 if (info->ssid == NULL) {
1086 info->ifname = g_strdup(ifname);
1087 if (info->ifname == NULL) {
1092 info->wifi->tethering = TRUE;
1094 err = g_supplicant_interface_remove(interface,
1095 sta_remove_callback,
1104 static void regdom_callback(void *user_data)
1106 char *alpha2 = user_data;
1110 if (wifi_technology == NULL)
1113 connman_technology_regdom_notify(wifi_technology, alpha2);
1116 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
1118 return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
1121 static struct connman_technology_driver tech_driver = {
1123 .type = CONNMAN_SERVICE_TYPE_WIFI,
1124 .probe = tech_probe,
1125 .remove = tech_remove,
1126 .set_tethering = tech_set_tethering,
1127 .set_regdom = tech_set_regdom,
1130 static int wifi_init(void)
1134 err = connman_network_driver_register(&network_driver);
1138 err = g_supplicant_register(&callbacks);
1140 connman_network_driver_unregister(&network_driver);
1144 err = connman_technology_driver_register(&tech_driver);
1146 g_supplicant_unregister(&callbacks);
1147 connman_network_driver_unregister(&network_driver);
1154 static void wifi_exit(void)
1158 connman_technology_driver_unregister(&tech_driver);
1160 g_supplicant_unregister(&callbacks);
1162 connman_network_driver_unregister(&network_driver);
1165 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
1166 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)