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;
64 GSupplicantInterface *interface;
65 GSupplicantState state;
66 connman_bool_t connected;
67 connman_bool_t disconnecting;
68 connman_bool_t tethering;
69 connman_bool_t bridged;
76 static GList *iface_list = NULL;
78 static void handle_tethering(struct wifi_data *wifi)
80 if (wifi->tethering == FALSE)
83 if (wifi->bridge == NULL)
86 if (wifi->bridged == TRUE)
89 DBG("index %d bridge %s", wifi->index, wifi->bridge);
91 if (connman_inet_add_to_bridge(wifi->index, wifi->bridge) < 0)
97 static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
99 struct connman_device *device = user_data;
100 struct wifi_data *wifi = connman_device_get_data(device);
102 DBG("index %d flags %d change %d", wifi->index, flags, change);
107 if ((wifi->flags & IFF_UP) != (flags & IFF_UP)) {
111 DBG("interface down");
114 if ((wifi->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
115 if (flags & IFF_LOWER_UP) {
118 handle_tethering(wifi);
126 static int wifi_probe(struct connman_device *device)
128 struct wifi_data *wifi;
130 DBG("device %p", device);
132 wifi = g_try_new0(struct wifi_data, 1);
136 wifi->connected = FALSE;
137 wifi->disconnecting = FALSE;
138 wifi->tethering = FALSE;
139 wifi->bridged = FALSE;
141 wifi->state = G_SUPPLICANT_STATE_INACTIVE;
143 connman_device_set_data(device, wifi);
144 wifi->device = connman_device_ref(device);
146 wifi->index = connman_device_get_index(device);
149 wifi->watch = connman_rtnl_add_newlink_watch(wifi->index,
150 wifi_newlink, device);
152 iface_list = g_list_append(iface_list, wifi);
157 static void wifi_remove(struct connman_device *device)
159 struct wifi_data *wifi = connman_device_get_data(device);
161 DBG("device %p", device);
166 iface_list = g_list_remove(iface_list, wifi);
168 if (wifi->pending_network != NULL) {
169 connman_network_unref(wifi->pending_network);
170 wifi->pending_network = NULL;
173 connman_device_set_data(device, NULL);
174 connman_device_unref(wifi->device);
175 connman_rtnl_remove_watch(wifi->watch);
177 g_supplicant_interface_set_data(wifi->interface, NULL);
179 g_free(wifi->identifier);
183 static void interface_create_callback(int result,
184 GSupplicantInterface *interface,
187 struct wifi_data *wifi = user_data;
189 DBG("result %d ifname %s", result,
190 g_supplicant_interface_get_ifname(interface));
195 wifi->interface = interface;
196 g_supplicant_interface_set_data(interface, wifi);
199 static void interface_remove_callback(int result,
200 GSupplicantInterface *interface,
203 struct wifi_data *wifi = user_data;
205 DBG("result %d", result);
210 wifi->interface = NULL;
214 static int wifi_enable(struct connman_device *device)
216 struct wifi_data *wifi = connman_device_get_data(device);
217 const char *interface = connman_device_get_string(device, "Interface");
218 const char *driver = connman_option_get_string("wifi");
220 DBG("device %p %p", device, wifi);
222 return g_supplicant_interface_create(interface, driver, NULL,
223 interface_create_callback,
227 static int wifi_disable(struct connman_device *device)
229 struct wifi_data *wifi = connman_device_get_data(device);
231 DBG("device %p", device);
233 wifi->connected = FALSE;
234 wifi->disconnecting = FALSE;
236 if (wifi->pending_network != NULL) {
237 connman_network_unref(wifi->pending_network);
238 wifi->pending_network = NULL;
241 return g_supplicant_interface_remove(wifi->interface,
242 interface_remove_callback,
246 static void scan_callback(int result, GSupplicantInterface *interface,
249 struct connman_device *device = user_data;
251 DBG("result %d", result);
254 connman_device_reset_scanning(device);
256 connman_device_set_scanning(device, FALSE);
259 static int wifi_scan(struct connman_device *device)
261 struct wifi_data *wifi = connman_device_get_data(device);
264 DBG("device %p %p", device, wifi->interface);
266 if (wifi->tethering == TRUE)
269 ret = g_supplicant_interface_scan(wifi->interface, scan_callback,
272 connman_device_set_scanning(device, TRUE);
277 static struct connman_device_driver wifi_ng_driver = {
279 .type = CONNMAN_DEVICE_TYPE_WIFI,
280 .priority = CONNMAN_DEVICE_PRIORITY_LOW,
282 .remove = wifi_remove,
283 .enable = wifi_enable,
284 .disable = wifi_disable,
288 static void system_ready(void)
292 if (connman_device_driver_register(&wifi_ng_driver) < 0)
293 connman_error("Failed to register WiFi driver");
296 static void system_killed(void)
300 connman_device_driver_unregister(&wifi_ng_driver);
303 static int network_probe(struct connman_network *network)
305 DBG("network %p", network);
310 static void network_remove(struct connman_network *network)
312 DBG("network %p", network);
315 static void connect_callback(int result, GSupplicantInterface *interface,
318 struct connman_network *network = user_data;
320 DBG("network %p result %d", network, result);
322 if (result == -ENOKEY) {
323 connman_network_set_error(network,
324 CONNMAN_NETWORK_ERROR_INVALID_KEY);
325 } else if (result < 0) {
326 connman_network_set_error(network,
327 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
331 static GSupplicantSecurity network_security(const char *security)
333 if (g_str_equal(security, "none") == TRUE)
334 return G_SUPPLICANT_SECURITY_NONE;
335 else if (g_str_equal(security, "wep") == TRUE)
336 return G_SUPPLICANT_SECURITY_WEP;
337 else if (g_str_equal(security, "psk") == TRUE)
338 return G_SUPPLICANT_SECURITY_PSK;
339 else if (g_str_equal(security, "wpa") == TRUE)
340 return G_SUPPLICANT_SECURITY_PSK;
341 else if (g_str_equal(security, "rsn") == TRUE)
342 return G_SUPPLICANT_SECURITY_PSK;
343 else if (g_str_equal(security, "ieee8021x") == TRUE)
344 return G_SUPPLICANT_SECURITY_IEEE8021X;
346 return G_SUPPLICANT_SECURITY_UNKNOWN;
349 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
351 const char *security, *passphrase;
353 memset(ssid, 0, sizeof(*ssid));
354 ssid->mode = G_SUPPLICANT_MODE_INFRA;
355 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
358 security = connman_network_get_string(network, "WiFi.Security");
359 ssid->security = network_security(security);
360 passphrase = connman_network_get_string(network,
362 if (passphrase == NULL || strlen(passphrase) == 0)
363 ssid->passphrase = NULL;
365 ssid->passphrase = passphrase;
367 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
370 * If our private key password is unset,
371 * we use the supplied passphrase. That is needed
372 * for PEAP where 2 passphrases (identity and client
373 * cert may have to be provided.
375 if (connman_network_get_string(network,
376 "WiFi.PrivateKeyPassphrase") == NULL)
377 connman_network_set_string(network,
378 "WiFi.PrivateKeyPassphrase",
380 /* We must have an identity for both PEAP and TLS */
381 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
382 ssid->ca_cert_path = connman_network_get_string(network,
384 ssid->client_cert_path = connman_network_get_string(network,
385 "WiFi.ClientCertFile");
386 ssid->private_key_path = connman_network_get_string(network,
387 "WiFi.PrivateKeyFile");
388 ssid->private_key_passphrase = connman_network_get_string(network,
389 "WiFi.PrivateKeyPassphrase");
390 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
392 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
393 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
397 static int network_connect(struct connman_network *network)
399 struct connman_device *device = connman_network_get_device(network);
400 struct wifi_data *wifi;
401 GSupplicantInterface *interface;
402 GSupplicantSSID *ssid;
404 DBG("network %p", network);
409 wifi = connman_device_get_data(device);
413 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
417 interface = wifi->interface;
419 ssid_init(ssid, network);
421 if (wifi->disconnecting == TRUE)
422 wifi->pending_network = connman_network_ref(network);
424 wifi->network = connman_network_ref(network);
426 return g_supplicant_interface_connect(interface, ssid,
427 connect_callback, network);
433 static void disconnect_callback(int result, GSupplicantInterface *interface,
436 struct wifi_data *wifi = user_data;
438 if (wifi->network != NULL) {
440 * if result < 0 supplican return an error because
441 * the network is not current.
442 * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
443 * failed, call connman_network_set_connected to report
444 * disconnect is completed.
447 connman_network_set_connected(wifi->network, FALSE);
449 connman_network_unref(wifi->network);
452 wifi->network = NULL;
454 wifi->disconnecting = FALSE;
456 if (wifi->pending_network != NULL) {
457 network_connect(wifi->pending_network);
458 connman_network_unref(wifi->pending_network);
459 wifi->pending_network = NULL;
464 static int network_disconnect(struct connman_network *network)
466 struct connman_device *device = connman_network_get_device(network);
467 struct wifi_data *wifi;
470 DBG("network %p", network);
472 wifi = connman_device_get_data(device);
473 if (wifi == NULL || wifi->interface == NULL)
476 connman_network_set_associating(network, FALSE);
478 if (wifi->disconnecting == TRUE)
481 wifi->disconnecting = TRUE;
483 err = g_supplicant_interface_disconnect(wifi->interface,
484 disconnect_callback, wifi);
486 wifi->disconnecting = FALSE;
491 static struct connman_network_driver network_driver = {
493 .type = CONNMAN_NETWORK_TYPE_WIFI,
494 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
495 .probe = network_probe,
496 .remove = network_remove,
497 .connect = network_connect,
498 .disconnect = network_disconnect,
501 static void interface_added(GSupplicantInterface *interface)
503 const char *ifname = g_supplicant_interface_get_ifname(interface);
504 const char *driver = g_supplicant_interface_get_driver(interface);
505 struct wifi_data *wifi;
507 wifi = g_supplicant_interface_get_data(interface);
510 * We can get here with a NULL wifi pointer when
511 * the interface added signal is sent before the
512 * interface creation callback is called.
517 DBG("ifname %s driver %s wifi %p tethering %d",
518 ifname, driver, wifi, wifi->tethering);
520 if (wifi->device == NULL) {
521 connman_error("WiFi device not set");
525 connman_device_set_powered(wifi->device, TRUE);
527 if (wifi->tethering == TRUE)
530 wifi_scan(wifi->device);
533 static connman_bool_t is_idle(struct wifi_data *wifi)
535 DBG("state %d", wifi->state);
537 switch (wifi->state) {
538 case G_SUPPLICANT_STATE_UNKNOWN:
539 case G_SUPPLICANT_STATE_DISCONNECTED:
540 case G_SUPPLICANT_STATE_INACTIVE:
541 case G_SUPPLICANT_STATE_SCANNING:
544 case G_SUPPLICANT_STATE_AUTHENTICATING:
545 case G_SUPPLICANT_STATE_ASSOCIATING:
546 case G_SUPPLICANT_STATE_ASSOCIATED:
547 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
548 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
549 case G_SUPPLICANT_STATE_COMPLETED:
556 static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
557 struct wifi_data *wifi)
559 /* First, let's check if WPS processing did not went wrong */
560 if (g_supplicant_interface_get_wps_state(interface) ==
561 G_SUPPLICANT_WPS_STATE_FAIL)
564 /* Unlike normal connection, being associated while processing wps
565 * actually means that we are idling. */
566 switch (wifi->state) {
567 case G_SUPPLICANT_STATE_UNKNOWN:
568 case G_SUPPLICANT_STATE_DISCONNECTED:
569 case G_SUPPLICANT_STATE_INACTIVE:
570 case G_SUPPLICANT_STATE_SCANNING:
571 case G_SUPPLICANT_STATE_ASSOCIATED:
573 case G_SUPPLICANT_STATE_AUTHENTICATING:
574 case G_SUPPLICANT_STATE_ASSOCIATING:
575 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
576 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
577 case G_SUPPLICANT_STATE_COMPLETED:
584 static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
585 struct connman_network *network,
586 struct connman_device *device,
587 struct wifi_data *wifi)
591 wps = connman_network_get_bool(network, "WiFi.UseWPS");
593 const unsigned char *ssid, *wps_ssid;
594 unsigned int ssid_len, wps_ssid_len;
597 /* Checking if we got associated with requested
599 ssid = connman_network_get_blob(network, "WiFi.SSID",
602 wps_ssid = g_supplicant_interface_get_wps_ssid(
603 interface, &wps_ssid_len);
605 if (wps_ssid == NULL || wps_ssid_len != ssid_len ||
606 memcmp(ssid, wps_ssid, ssid_len) != 0) {
607 connman_network_set_associating(network, FALSE);
608 g_supplicant_interface_disconnect(wifi->interface,
609 disconnect_callback, wifi);
613 wps_key = g_supplicant_interface_get_wps_key(interface);
614 connman_network_set_string(network, "WiFi.Passphrase",
617 connman_network_set_string(network, "WiFi.PinWPS", NULL);
623 static void interface_state(GSupplicantInterface *interface)
625 struct connman_network *network;
626 struct connman_device *device;
627 struct wifi_data *wifi;
628 GSupplicantState state = g_supplicant_interface_get_state(interface);
631 wifi = g_supplicant_interface_get_data(interface);
633 DBG("wifi %p interface state %d", wifi, state);
638 network = wifi->network;
639 device = wifi->device;
641 if (device == NULL || network == NULL)
645 case G_SUPPLICANT_STATE_SCANNING:
648 case G_SUPPLICANT_STATE_AUTHENTICATING:
649 case G_SUPPLICANT_STATE_ASSOCIATING:
650 connman_network_set_associating(network, TRUE);
653 case G_SUPPLICANT_STATE_COMPLETED:
654 if (handle_wps_completion(interface, network, device, wifi) ==
658 /* reset scan trigger and schedule background scan */
659 connman_device_schedule_scan(device);
661 connman_network_set_connected(network, TRUE);
664 case G_SUPPLICANT_STATE_DISCONNECTED:
666 * If we're in one of the idle modes, we have
667 * not started association yet and thus setting
668 * those ones to FALSE could cancel an association
671 wps = connman_network_get_bool(network, "WiFi.UseWPS");
673 if (is_idle_wps(interface, wifi) == TRUE)
678 connman_network_set_associating(network, FALSE);
679 connman_network_set_connected(network, FALSE);
682 case G_SUPPLICANT_STATE_INACTIVE:
683 connman_network_set_associating(network, FALSE);
686 case G_SUPPLICANT_STATE_UNKNOWN:
687 case G_SUPPLICANT_STATE_ASSOCIATED:
688 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
689 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
698 static void interface_removed(GSupplicantInterface *interface)
700 const char *ifname = g_supplicant_interface_get_ifname(interface);
701 struct wifi_data *wifi;
703 DBG("ifname %s", ifname);
705 wifi = g_supplicant_interface_get_data(interface);
707 if (wifi != NULL && wifi->tethering == TRUE)
710 if (wifi == NULL || wifi->device == NULL) {
711 connman_error("Wrong wifi pointer");
715 connman_device_set_powered(wifi->device, FALSE);
718 static void scan_started(GSupplicantInterface *interface)
720 struct wifi_data *wifi;
724 wifi = g_supplicant_interface_get_data(interface);
730 static void scan_finished(GSupplicantInterface *interface)
732 struct wifi_data *wifi;
736 wifi = g_supplicant_interface_get_data(interface);
742 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
744 unsigned char strength;
746 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
753 static void network_added(GSupplicantNetwork *supplicant_network)
755 struct connman_network *network;
756 GSupplicantInterface *interface;
757 struct wifi_data *wifi;
758 const char *name, *identifier, *mode, *security, *group;
759 const unsigned char *ssid;
760 unsigned int ssid_len;
765 interface = g_supplicant_network_get_interface(supplicant_network);
766 wifi = g_supplicant_interface_get_data(interface);
767 name = g_supplicant_network_get_name(supplicant_network);
768 identifier = g_supplicant_network_get_identifier(supplicant_network);
769 mode = g_supplicant_network_get_mode(supplicant_network);
770 security = g_supplicant_network_get_security(supplicant_network);
771 group = g_supplicant_network_get_identifier(supplicant_network);
772 wps = g_supplicant_network_get_wps(supplicant_network);
777 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
779 network = connman_device_get_network(wifi->device, identifier);
781 if (network == NULL) {
782 network = connman_network_create(identifier,
783 CONNMAN_NETWORK_TYPE_WIFI);
787 connman_network_set_index(network, wifi->index);
789 if (connman_device_add_network(wifi->device, network) < 0) {
790 connman_network_unref(network);
795 if (name != NULL && name[0] != '\0')
796 connman_network_set_name(network, name);
798 connman_network_set_blob(network, "WiFi.SSID",
800 connman_network_set_string(network, "WiFi.Mode", mode);
801 connman_network_set_string(network, "WiFi.Security", security);
802 connman_network_set_strength(network,
803 calculate_strength(supplicant_network));
804 connman_network_set_bool(network, "WiFi.WPS", wps);
806 connman_network_set_available(network, TRUE);
809 connman_network_set_group(network, group);
812 static void network_removed(GSupplicantNetwork *network)
814 GSupplicantInterface *interface;
815 struct wifi_data *wifi;
816 const char *name, *identifier;
818 interface = g_supplicant_network_get_interface(network);
819 wifi = g_supplicant_interface_get_data(interface);
820 identifier = g_supplicant_network_get_identifier(network);
821 name = g_supplicant_network_get_name(network);
823 DBG("name %s", name);
826 connman_device_remove_network(wifi->device, identifier);
829 static void debug(const char *str)
831 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
832 connman_debug("%s", str);
835 static const GSupplicantCallbacks callbacks = {
836 .system_ready = system_ready,
837 .system_killed = system_killed,
838 .interface_added = interface_added,
839 .interface_state = interface_state,
840 .interface_removed = interface_removed,
841 .scan_started = scan_started,
842 .scan_finished = scan_finished,
843 .network_added = network_added,
844 .network_removed = network_removed,
849 static int tech_probe(struct connman_technology *technology)
851 wifi_technology = technology;
856 static void tech_remove(struct connman_technology *technology)
858 wifi_technology = NULL;
861 struct wifi_tethering_info {
862 struct wifi_data *wifi;
863 struct connman_technology *technology;
865 GSupplicantSSID *ssid;
868 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
872 ap = g_try_malloc0(sizeof(GSupplicantSSID));
876 ap->mode = G_SUPPLICANT_MODE_MASTER;
878 ap->ssid_len = strlen(ssid);
882 if (passphrase == NULL || strlen(passphrase) == 0) {
883 ap->security = G_SUPPLICANT_SECURITY_NONE;
884 ap->passphrase = NULL;
886 ap->security = G_SUPPLICANT_SECURITY_PSK;
887 ap->protocol = G_SUPPLICANT_PROTO_RSN;
888 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
889 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
890 ap->passphrase = passphrase;
896 static void ap_start_callback(int result, GSupplicantInterface *interface,
899 struct wifi_tethering_info *info = user_data;
901 DBG("result %d index %d bridge %s",
902 result, info->wifi->index, info->wifi->bridge);
905 connman_inet_remove_from_bridge(info->wifi->index,
907 connman_technology_tethering_notify(info->technology, FALSE);
910 g_free(info->ifname);
914 static void ap_create_callback(int result,
915 GSupplicantInterface *interface,
918 struct wifi_tethering_info *info = user_data;
920 DBG("result %d ifname %s", result,
921 g_supplicant_interface_get_ifname(interface));
924 connman_inet_remove_from_bridge(info->wifi->index,
926 connman_technology_tethering_notify(info->technology, FALSE);
928 g_free(info->ifname);
933 info->wifi->interface = interface;
934 g_supplicant_interface_set_data(interface, info->wifi);
936 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
937 connman_error("Failed to set interface ap_scan property");
939 g_supplicant_interface_connect(interface, info->ssid,
940 ap_start_callback, info);
943 static void sta_remove_callback(int result,
944 GSupplicantInterface *interface,
947 struct wifi_tethering_info *info = user_data;
948 const char *driver = connman_option_get_string("wifi");
950 DBG("ifname %s result %d ", info->ifname, result);
953 info->wifi->tethering = TRUE;
955 g_free(info->ifname);
960 info->wifi->interface = NULL;
962 connman_technology_tethering_notify(info->technology, TRUE);
964 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
969 static int tech_set_tethering(struct connman_technology *technology,
970 const char *identifier, const char *passphrase,
971 const char *bridge, connman_bool_t enabled)
974 GSupplicantInterface *interface;
975 struct wifi_data *wifi;
976 struct wifi_tethering_info *info;
983 if (enabled == FALSE) {
984 for (list = iface_list; list; list = list->next) {
987 if (wifi->tethering == TRUE) {
988 wifi->tethering = FALSE;
990 connman_inet_remove_from_bridge(wifi->index,
992 wifi->bridged = FALSE;
996 connman_technology_tethering_notify(technology, FALSE);
1001 for (list = iface_list; list; list = list->next) {
1004 interface = wifi->interface;
1006 if (interface == NULL)
1009 ifname = g_supplicant_interface_get_ifname(wifi->interface);
1011 mode = g_supplicant_interface_get_mode(interface);
1012 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
1013 DBG("%s does not support AP mode", ifname);
1017 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
1022 info->technology = technology;
1023 info->wifi->bridge = bridge;
1024 info->ssid = ssid_ap_init(identifier, passphrase);
1025 if (info->ssid == NULL) {
1029 info->ifname = g_strdup(ifname);
1030 if (info->ifname == NULL) {
1035 info->wifi->tethering = TRUE;
1037 err = g_supplicant_interface_remove(interface,
1038 sta_remove_callback,
1047 static void regdom_callback(void *user_data)
1049 char *alpha2 = user_data;
1053 if (wifi_technology == NULL)
1056 connman_technology_regdom_notify(wifi_technology, alpha2);
1059 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
1061 return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
1064 static struct connman_technology_driver tech_driver = {
1066 .type = CONNMAN_SERVICE_TYPE_WIFI,
1067 .probe = tech_probe,
1068 .remove = tech_remove,
1069 .set_tethering = tech_set_tethering,
1070 .set_regdom = tech_set_regdom,
1073 static int wifi_init(void)
1077 err = connman_network_driver_register(&network_driver);
1081 err = g_supplicant_register(&callbacks);
1083 connman_network_driver_unregister(&network_driver);
1087 err = connman_technology_driver_register(&tech_driver);
1089 g_supplicant_unregister(&callbacks);
1090 connman_network_driver_unregister(&network_driver);
1097 static void wifi_exit(void)
1101 connman_technology_driver_unregister(&tech_driver);
1103 g_supplicant_unregister(&callbacks);
1105 connman_network_driver_unregister(&network_driver);
1108 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
1109 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)