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");
221 DBG("device %p %p", device, wifi);
223 ret = g_supplicant_interface_create(interface, driver, NULL,
224 interface_create_callback,
232 static int wifi_disable(struct connman_device *device)
234 struct wifi_data *wifi = connman_device_get_data(device);
237 DBG("device %p", device);
239 wifi->connected = FALSE;
240 wifi->disconnecting = FALSE;
242 if (wifi->pending_network != NULL) {
243 connman_network_unref(wifi->pending_network);
244 wifi->pending_network = NULL;
247 ret = g_supplicant_interface_remove(wifi->interface,
248 interface_remove_callback,
256 static void scan_callback(int result, GSupplicantInterface *interface,
259 struct connman_device *device = user_data;
261 DBG("result %d", result);
264 connman_device_reset_scanning(device);
266 connman_device_set_scanning(device, FALSE);
269 static int wifi_scan(struct connman_device *device)
271 struct wifi_data *wifi = connman_device_get_data(device);
274 DBG("device %p %p", device, wifi->interface);
276 if (wifi->tethering == TRUE)
279 ret = g_supplicant_interface_scan(wifi->interface, scan_callback,
282 connman_device_set_scanning(device, TRUE);
287 static struct connman_device_driver wifi_ng_driver = {
289 .type = CONNMAN_DEVICE_TYPE_WIFI,
290 .priority = CONNMAN_DEVICE_PRIORITY_LOW,
292 .remove = wifi_remove,
293 .enable = wifi_enable,
294 .disable = wifi_disable,
298 static void system_ready(void)
302 if (connman_device_driver_register(&wifi_ng_driver) < 0)
303 connman_error("Failed to register WiFi driver");
306 static void system_killed(void)
310 connman_device_driver_unregister(&wifi_ng_driver);
313 static int network_probe(struct connman_network *network)
315 DBG("network %p", network);
320 static void network_remove(struct connman_network *network)
322 DBG("network %p", network);
325 static void connect_callback(int result, GSupplicantInterface *interface,
328 struct connman_network *network = user_data;
330 DBG("network %p result %d", network, result);
332 if (result == -ENOKEY) {
333 connman_network_set_error(network,
334 CONNMAN_NETWORK_ERROR_INVALID_KEY);
335 } else if (result < 0) {
336 connman_network_set_error(network,
337 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
341 static GSupplicantSecurity network_security(const char *security)
343 if (g_str_equal(security, "none") == TRUE)
344 return G_SUPPLICANT_SECURITY_NONE;
345 else if (g_str_equal(security, "wep") == TRUE)
346 return G_SUPPLICANT_SECURITY_WEP;
347 else if (g_str_equal(security, "psk") == TRUE)
348 return G_SUPPLICANT_SECURITY_PSK;
349 else if (g_str_equal(security, "wpa") == TRUE)
350 return G_SUPPLICANT_SECURITY_PSK;
351 else if (g_str_equal(security, "rsn") == TRUE)
352 return G_SUPPLICANT_SECURITY_PSK;
353 else if (g_str_equal(security, "ieee8021x") == TRUE)
354 return G_SUPPLICANT_SECURITY_IEEE8021X;
356 return G_SUPPLICANT_SECURITY_UNKNOWN;
359 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
361 const char *security, *passphrase;
363 memset(ssid, 0, sizeof(*ssid));
364 ssid->mode = G_SUPPLICANT_MODE_INFRA;
365 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
368 security = connman_network_get_string(network, "WiFi.Security");
369 ssid->security = network_security(security);
370 passphrase = connman_network_get_string(network,
372 if (passphrase == NULL || strlen(passphrase) == 0)
373 ssid->passphrase = NULL;
375 ssid->passphrase = passphrase;
377 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
380 * If our private key password is unset,
381 * we use the supplied passphrase. That is needed
382 * for PEAP where 2 passphrases (identity and client
383 * cert may have to be provided.
385 if (connman_network_get_string(network,
386 "WiFi.PrivateKeyPassphrase") == NULL)
387 connman_network_set_string(network,
388 "WiFi.PrivateKeyPassphrase",
390 /* We must have an identity for both PEAP and TLS */
391 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
392 ssid->ca_cert_path = connman_network_get_string(network,
394 ssid->client_cert_path = connman_network_get_string(network,
395 "WiFi.ClientCertFile");
396 ssid->private_key_path = connman_network_get_string(network,
397 "WiFi.PrivateKeyFile");
398 ssid->private_key_passphrase = connman_network_get_string(network,
399 "WiFi.PrivateKeyPassphrase");
400 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
402 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
403 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
407 static int network_connect(struct connman_network *network)
409 struct connman_device *device = connman_network_get_device(network);
410 struct wifi_data *wifi;
411 GSupplicantInterface *interface;
412 GSupplicantSSID *ssid;
414 DBG("network %p", network);
419 wifi = connman_device_get_data(device);
423 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
427 interface = wifi->interface;
429 ssid_init(ssid, network);
431 if (wifi->disconnecting == TRUE)
432 wifi->pending_network = connman_network_ref(network);
434 wifi->network = connman_network_ref(network);
436 return g_supplicant_interface_connect(interface, ssid,
437 connect_callback, network);
443 static void disconnect_callback(int result, GSupplicantInterface *interface,
446 struct wifi_data *wifi = user_data;
448 if (wifi->network != NULL) {
450 * if result < 0 supplican return an error because
451 * the network is not current.
452 * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
453 * failed, call connman_network_set_connected to report
454 * disconnect is completed.
457 connman_network_set_connected(wifi->network, FALSE);
459 connman_network_unref(wifi->network);
462 wifi->network = NULL;
464 wifi->disconnecting = FALSE;
466 if (wifi->pending_network != NULL) {
467 network_connect(wifi->pending_network);
468 connman_network_unref(wifi->pending_network);
469 wifi->pending_network = NULL;
474 static int network_disconnect(struct connman_network *network)
476 struct connman_device *device = connman_network_get_device(network);
477 struct wifi_data *wifi;
480 DBG("network %p", network);
482 wifi = connman_device_get_data(device);
483 if (wifi == NULL || wifi->interface == NULL)
486 connman_network_set_associating(network, FALSE);
488 if (wifi->disconnecting == TRUE)
491 wifi->disconnecting = TRUE;
493 err = g_supplicant_interface_disconnect(wifi->interface,
494 disconnect_callback, wifi);
496 wifi->disconnecting = FALSE;
501 static struct connman_network_driver network_driver = {
503 .type = CONNMAN_NETWORK_TYPE_WIFI,
504 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
505 .probe = network_probe,
506 .remove = network_remove,
507 .connect = network_connect,
508 .disconnect = network_disconnect,
511 static void interface_added(GSupplicantInterface *interface)
513 const char *ifname = g_supplicant_interface_get_ifname(interface);
514 const char *driver = g_supplicant_interface_get_driver(interface);
515 struct wifi_data *wifi;
517 wifi = g_supplicant_interface_get_data(interface);
520 * We can get here with a NULL wifi pointer when
521 * the interface added signal is sent before the
522 * interface creation callback is called.
527 DBG("ifname %s driver %s wifi %p tethering %d",
528 ifname, driver, wifi, wifi->tethering);
530 if (wifi->device == NULL) {
531 connman_error("WiFi device not set");
535 connman_device_set_powered(wifi->device, TRUE);
537 if (wifi->tethering == TRUE)
540 wifi_scan(wifi->device);
543 static connman_bool_t is_idle(struct wifi_data *wifi)
545 DBG("state %d", wifi->state);
547 switch (wifi->state) {
548 case G_SUPPLICANT_STATE_UNKNOWN:
549 case G_SUPPLICANT_STATE_DISCONNECTED:
550 case G_SUPPLICANT_STATE_INACTIVE:
551 case G_SUPPLICANT_STATE_SCANNING:
554 case G_SUPPLICANT_STATE_AUTHENTICATING:
555 case G_SUPPLICANT_STATE_ASSOCIATING:
556 case G_SUPPLICANT_STATE_ASSOCIATED:
557 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
558 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
559 case G_SUPPLICANT_STATE_COMPLETED:
566 static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
567 struct wifi_data *wifi)
569 /* First, let's check if WPS processing did not went wrong */
570 if (g_supplicant_interface_get_wps_state(interface) ==
571 G_SUPPLICANT_WPS_STATE_FAIL)
574 /* Unlike normal connection, being associated while processing wps
575 * actually means that we are idling. */
576 switch (wifi->state) {
577 case G_SUPPLICANT_STATE_UNKNOWN:
578 case G_SUPPLICANT_STATE_DISCONNECTED:
579 case G_SUPPLICANT_STATE_INACTIVE:
580 case G_SUPPLICANT_STATE_SCANNING:
581 case G_SUPPLICANT_STATE_ASSOCIATED:
583 case G_SUPPLICANT_STATE_AUTHENTICATING:
584 case G_SUPPLICANT_STATE_ASSOCIATING:
585 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
586 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
587 case G_SUPPLICANT_STATE_COMPLETED:
594 static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
595 struct connman_network *network,
596 struct connman_device *device,
597 struct wifi_data *wifi)
601 wps = connman_network_get_bool(network, "WiFi.UseWPS");
603 const unsigned char *ssid, *wps_ssid;
604 unsigned int ssid_len, wps_ssid_len;
607 /* Checking if we got associated with requested
609 ssid = connman_network_get_blob(network, "WiFi.SSID",
612 wps_ssid = g_supplicant_interface_get_wps_ssid(
613 interface, &wps_ssid_len);
615 if (wps_ssid == NULL || wps_ssid_len != ssid_len ||
616 memcmp(ssid, wps_ssid, ssid_len) != 0) {
617 connman_network_set_associating(network, FALSE);
618 g_supplicant_interface_disconnect(wifi->interface,
619 disconnect_callback, wifi);
623 wps_key = g_supplicant_interface_get_wps_key(interface);
624 connman_network_set_string(network, "WiFi.Passphrase",
627 connman_network_set_string(network, "WiFi.PinWPS", NULL);
633 static void interface_state(GSupplicantInterface *interface)
635 struct connman_network *network;
636 struct connman_device *device;
637 struct wifi_data *wifi;
638 GSupplicantState state = g_supplicant_interface_get_state(interface);
641 wifi = g_supplicant_interface_get_data(interface);
643 DBG("wifi %p interface state %d", wifi, state);
648 network = wifi->network;
649 device = wifi->device;
651 if (device == NULL || network == NULL)
655 case G_SUPPLICANT_STATE_SCANNING:
658 case G_SUPPLICANT_STATE_AUTHENTICATING:
659 case G_SUPPLICANT_STATE_ASSOCIATING:
660 connman_network_set_associating(network, TRUE);
663 case G_SUPPLICANT_STATE_COMPLETED:
664 if (handle_wps_completion(interface, network, device, wifi) ==
668 /* reset scan trigger and schedule background scan */
669 connman_device_schedule_scan(device);
671 connman_network_set_connected(network, TRUE);
674 case G_SUPPLICANT_STATE_DISCONNECTED:
676 * If we're in one of the idle modes, we have
677 * not started association yet and thus setting
678 * those ones to FALSE could cancel an association
681 wps = connman_network_get_bool(network, "WiFi.UseWPS");
683 if (is_idle_wps(interface, wifi) == TRUE)
688 connman_network_set_associating(network, FALSE);
689 connman_network_set_connected(network, FALSE);
692 case G_SUPPLICANT_STATE_INACTIVE:
693 connman_network_set_associating(network, FALSE);
696 case G_SUPPLICANT_STATE_UNKNOWN:
697 case G_SUPPLICANT_STATE_ASSOCIATED:
698 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
699 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
708 static void interface_removed(GSupplicantInterface *interface)
710 const char *ifname = g_supplicant_interface_get_ifname(interface);
711 struct wifi_data *wifi;
713 DBG("ifname %s", ifname);
715 wifi = g_supplicant_interface_get_data(interface);
717 if (wifi != NULL && wifi->tethering == TRUE)
720 if (wifi == NULL || wifi->device == NULL) {
721 connman_error("Wrong wifi pointer");
725 connman_device_set_powered(wifi->device, FALSE);
728 static void scan_started(GSupplicantInterface *interface)
730 struct wifi_data *wifi;
734 wifi = g_supplicant_interface_get_data(interface);
740 static void scan_finished(GSupplicantInterface *interface)
742 struct wifi_data *wifi;
746 wifi = g_supplicant_interface_get_data(interface);
752 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
754 unsigned char strength;
756 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
763 static void network_added(GSupplicantNetwork *supplicant_network)
765 struct connman_network *network;
766 GSupplicantInterface *interface;
767 struct wifi_data *wifi;
768 const char *name, *identifier, *security, *group;
769 const unsigned char *ssid;
770 unsigned int ssid_len;
775 interface = g_supplicant_network_get_interface(supplicant_network);
776 wifi = g_supplicant_interface_get_data(interface);
777 name = g_supplicant_network_get_name(supplicant_network);
778 identifier = g_supplicant_network_get_identifier(supplicant_network);
779 security = g_supplicant_network_get_security(supplicant_network);
780 group = g_supplicant_network_get_identifier(supplicant_network);
781 wps = g_supplicant_network_get_wps(supplicant_network);
786 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
788 network = connman_device_get_network(wifi->device, identifier);
790 if (network == NULL) {
791 network = connman_network_create(identifier,
792 CONNMAN_NETWORK_TYPE_WIFI);
796 connman_network_set_index(network, wifi->index);
798 if (connman_device_add_network(wifi->device, network) < 0) {
799 connman_network_unref(network);
804 if (name != NULL && name[0] != '\0')
805 connman_network_set_name(network, name);
807 connman_network_set_blob(network, "WiFi.SSID",
809 connman_network_set_string(network, "WiFi.Security", security);
810 connman_network_set_strength(network,
811 calculate_strength(supplicant_network));
812 connman_network_set_bool(network, "WiFi.WPS", wps);
814 connman_network_set_available(network, TRUE);
817 connman_network_set_group(network, group);
820 static void network_removed(GSupplicantNetwork *network)
822 GSupplicantInterface *interface;
823 struct wifi_data *wifi;
824 const char *name, *identifier;
825 struct connman_network *connman_network;
827 interface = g_supplicant_network_get_interface(network);
828 wifi = g_supplicant_interface_get_data(interface);
829 identifier = g_supplicant_network_get_identifier(network);
830 name = g_supplicant_network_get_name(network);
832 DBG("name %s", name);
837 connman_network = connman_device_get_network(wifi->device, identifier);
838 if (connman_network == NULL)
841 connman_device_remove_network(wifi->device, connman_network);
842 connman_network_unref(connman_network);
845 static void debug(const char *str)
847 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
848 connman_debug("%s", str);
851 static const GSupplicantCallbacks callbacks = {
852 .system_ready = system_ready,
853 .system_killed = system_killed,
854 .interface_added = interface_added,
855 .interface_state = interface_state,
856 .interface_removed = interface_removed,
857 .scan_started = scan_started,
858 .scan_finished = scan_finished,
859 .network_added = network_added,
860 .network_removed = network_removed,
865 static int tech_probe(struct connman_technology *technology)
867 wifi_technology = technology;
872 static void tech_remove(struct connman_technology *technology)
874 wifi_technology = NULL;
877 struct wifi_tethering_info {
878 struct wifi_data *wifi;
879 struct connman_technology *technology;
881 GSupplicantSSID *ssid;
884 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
888 ap = g_try_malloc0(sizeof(GSupplicantSSID));
892 ap->mode = G_SUPPLICANT_MODE_MASTER;
894 ap->ssid_len = strlen(ssid);
898 if (passphrase == NULL || strlen(passphrase) == 0) {
899 ap->security = G_SUPPLICANT_SECURITY_NONE;
900 ap->passphrase = NULL;
902 ap->security = G_SUPPLICANT_SECURITY_PSK;
903 ap->protocol = G_SUPPLICANT_PROTO_RSN;
904 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
905 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
906 ap->passphrase = passphrase;
912 static void ap_start_callback(int result, GSupplicantInterface *interface,
915 struct wifi_tethering_info *info = user_data;
917 DBG("result %d index %d bridge %s",
918 result, info->wifi->index, info->wifi->bridge);
921 connman_inet_remove_from_bridge(info->wifi->index,
923 connman_technology_tethering_notify(info->technology, FALSE);
926 g_free(info->ifname);
930 static void ap_create_callback(int result,
931 GSupplicantInterface *interface,
934 struct wifi_tethering_info *info = user_data;
936 DBG("result %d ifname %s", result,
937 g_supplicant_interface_get_ifname(interface));
940 connman_inet_remove_from_bridge(info->wifi->index,
942 connman_technology_tethering_notify(info->technology, FALSE);
944 g_free(info->ifname);
949 info->wifi->interface = interface;
950 g_supplicant_interface_set_data(interface, info->wifi);
952 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
953 connman_error("Failed to set interface ap_scan property");
955 g_supplicant_interface_connect(interface, info->ssid,
956 ap_start_callback, info);
959 static void sta_remove_callback(int result,
960 GSupplicantInterface *interface,
963 struct wifi_tethering_info *info = user_data;
964 const char *driver = connman_option_get_string("wifi");
966 DBG("ifname %s result %d ", info->ifname, result);
969 info->wifi->tethering = TRUE;
971 g_free(info->ifname);
976 info->wifi->interface = NULL;
978 connman_technology_tethering_notify(info->technology, TRUE);
980 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
985 static int tech_set_tethering(struct connman_technology *technology,
986 const char *identifier, const char *passphrase,
987 const char *bridge, connman_bool_t enabled)
990 GSupplicantInterface *interface;
991 struct wifi_data *wifi;
992 struct wifi_tethering_info *info;
999 if (enabled == FALSE) {
1000 for (list = iface_list; list; list = list->next) {
1003 if (wifi->tethering == TRUE) {
1004 wifi->tethering = FALSE;
1006 connman_inet_remove_from_bridge(wifi->index,
1008 wifi->bridged = FALSE;
1012 connman_technology_tethering_notify(technology, FALSE);
1017 for (list = iface_list; list; list = list->next) {
1020 interface = wifi->interface;
1022 if (interface == NULL)
1025 ifname = g_supplicant_interface_get_ifname(wifi->interface);
1027 mode = g_supplicant_interface_get_mode(interface);
1028 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
1029 DBG("%s does not support AP mode", ifname);
1033 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
1038 info->technology = technology;
1039 info->wifi->bridge = bridge;
1040 info->ssid = ssid_ap_init(identifier, passphrase);
1041 if (info->ssid == NULL) {
1045 info->ifname = g_strdup(ifname);
1046 if (info->ifname == NULL) {
1051 info->wifi->tethering = TRUE;
1053 err = g_supplicant_interface_remove(interface,
1054 sta_remove_callback,
1063 static void regdom_callback(void *user_data)
1065 char *alpha2 = user_data;
1069 if (wifi_technology == NULL)
1072 connman_technology_regdom_notify(wifi_technology, alpha2);
1075 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
1077 return g_supplicant_set_country(alpha2, regdom_callback, alpha2);
1080 static struct connman_technology_driver tech_driver = {
1082 .type = CONNMAN_SERVICE_TYPE_WIFI,
1083 .probe = tech_probe,
1084 .remove = tech_remove,
1085 .set_tethering = tech_set_tethering,
1086 .set_regdom = tech_set_regdom,
1089 static int wifi_init(void)
1093 err = connman_network_driver_register(&network_driver);
1097 err = g_supplicant_register(&callbacks);
1099 connman_network_driver_unregister(&network_driver);
1103 err = connman_technology_driver_register(&tech_driver);
1105 g_supplicant_unregister(&callbacks);
1106 connman_network_driver_unregister(&network_driver);
1113 static void wifi_exit(void)
1117 connman_technology_driver_unregister(&tech_driver);
1119 g_supplicant_unregister(&callbacks);
1121 connman_network_driver_unregister(&network_driver);
1124 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
1125 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)