5 * Copyright (C) 2007-2014 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
31 #include <sys/ioctl.h>
32 #include <sys/socket.h>
33 #include <net/ethernet.h>
34 #include <linux/wireless.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/service.h>
50 #include <connman/peer.h>
51 #include <connman/log.h>
52 #include <connman/option.h>
53 #include <connman/storage.h>
54 #include <include/setting.h>
55 #include <connman/provision.h>
56 #include <connman/utsname.h>
57 #include <connman/machine.h>
58 #include <connman/tethering.h>
60 #include <gsupplicant/gsupplicant.h>
62 #include "src/shared/util.h"
64 #define CLEANUP_TIMEOUT 8 /* in seconds */
65 #define INACTIVE_TIMEOUT 12 /* in seconds */
66 #define FAVORITE_MAXIMUM_RETRIES 2
68 #define BGSCAN_DEFAULT "simple:30:-65:300"
69 #define AUTOSCAN_EXPONENTIAL "exponential:3:300"
70 #define AUTOSCAN_SINGLE "single:3"
72 #define P2P_FIND_TIMEOUT 30
73 #define P2P_CONNECTION_TIMEOUT 100
74 #define P2P_LISTEN_PERIOD 500
75 #define P2P_LISTEN_INTERVAL 2000
77 #define ASSOC_STATUS_NO_CLIENT 17
79 #define LOAD_SHAPING_MAX_RETRIES 7
81 #define LOAD_SHAPING_MAX_RETRIES 3
85 #define WIFI_EAP_FAST_PAC_FILE "/var/lib/wifi/wifi.pac" /* path of Pac file for EAP-FAST */
87 /* Wi-Fi Signal Strength (for 2.4G (dB))
91 * Very weak : -83 ~ -88
94 * Wi-Fi Signal Strength (for 5G (dB))
98 * Very weak : -83 ~ -88
101 #define RSSI_LEVEL_2_5G -77
102 #define RSSI_LEVEL_2_24G -75
103 #define RSSI_LEVEL_3_5G -68
104 #define RSSI_LEVEL_3_24G -64
105 #define WIFI_BSSID_STR_LEN 18
106 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
107 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
108 #define ROAM_SCAN_INTERVAL 60 /* 60 seconds */
111 static struct connman_technology *wifi_technology = NULL;
112 static struct connman_technology *p2p_technology = NULL;
114 enum wifi_ap_capability{
116 WIFI_AP_SUPPORTED = 1,
117 WIFI_AP_NOT_SUPPORTED = 2,
120 enum wifi_scanning_type {
121 WIFI_SCANNING_UNKNOWN = 0,
122 WIFI_SCANNING_PASSIVE = 1,
123 WIFI_SCANNING_ACTIVE = 2,
126 struct hidden_params {
128 unsigned int ssid_len;
130 char *anonymous_identity;
132 char *altsubject_match;
133 char *domain_suffix_match;
137 GSupplicantScanParams *scan_params;
142 * Used for autoscan "emulation".
143 * Should be removed when wpa_s autoscan support will be by default.
145 struct autoscan_params {
149 unsigned int timeout;
152 struct wifi_tethering_info {
153 struct wifi_data *wifi;
154 struct connman_technology *technology;
156 GSupplicantSSID *ssid;
161 struct connman_device *device;
162 struct connman_network *network;
163 struct connman_network *pending_network;
165 GSupplicantInterface *interface;
166 GSupplicantState state;
170 enum wifi_ap_capability ap_supported;
172 bool interface_ready;
178 int load_shaping_retries;
179 struct hidden_params *hidden;
180 bool postpone_hidden;
181 struct wifi_tethering_info *tethering_param;
183 * autoscan "emulation".
185 struct autoscan_params *autoscan;
186 enum wifi_scanning_type scanning_type;
187 GSupplicantScanParams *scan_params;
188 unsigned int p2p_find_timeout;
189 unsigned int p2p_connection_timeout;
190 struct connman_peer *pending_peer;
195 #if defined TIZEN_EXT
196 int assoc_retry_count;
197 struct connman_network *scan_pending_network;
198 bool allow_full_scan;
199 unsigned int automaxspeed_timeout;
200 GSupplicantScanParams *hidden_scan_params;
201 unsigned int mac_policy;
202 unsigned int preassoc_mac_policy;
203 unsigned int mac_lifetime;
207 #if defined TIZEN_EXT_WIFI_MESH
209 struct wifi_mesh_info *mesh_info;
213 #if defined TIZEN_EXT
217 #define TIZEN_ASSOC_RETRY_COUNT 4
219 static gboolean wifi_first_scan = false;
220 static gboolean found_with_first_scan = false;
221 static gboolean is_wifi_notifier_registered = false;
222 static GHashTable *failed_bssids = NULL;
223 static unsigned char buff_bssid[WIFI_BSSID_LEN_MAX] = { 0, };
227 static GList *iface_list = NULL;
229 static GList *pending_wifi_device = NULL;
230 static GList *p2p_iface_list = NULL;
231 static bool wfd_service_registered = false;
233 static void start_autoscan(struct connman_device *device);
234 static int tech_set_tethering(struct connman_technology *technology,
235 const char *identifier, const char *passphrase,
236 const char *bridge, bool enabled);
238 #if defined TIZEN_EXT
239 #define NETCONFIG_SERVICE "net.netconfig"
240 #define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
241 #define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
243 struct enc_method_call_data {
244 DBusConnection *connection;
245 struct connman_network *network;
248 static struct enc_method_call_data encrypt_request_data;
250 static void encryption_request_reply(DBusPendingCall *call,
255 DBusMessageIter args;
257 struct connman_service *service;
258 gchar* encrypted_value = NULL;
259 struct connman_network *network = encrypt_request_data.network;
263 reply = dbus_pending_call_steal_reply(call);
265 dbus_error_init(&error);
266 if (dbus_set_error_from_message(&error, reply)) {
267 DBG("send_encryption_request() %s %s", error.name, error.message);
268 dbus_error_free(&error);
272 if (dbus_message_iter_init(reply, &args) == FALSE)
275 dbus_message_iter_get_basic(&args, &out_data);
277 encrypted_value = g_strdup((const gchar *)out_data);
278 service = connman_service_lookup_from_network(network);
281 DBG("encryption result: no service");
285 if (connman_service_get_favorite(service)) {
286 __connman_service_set_passphrase(service, encrypted_value);
287 __connman_service_save(service);
289 connman_network_set_string(network, "WiFi.Passphrase",
292 DBG("encryption result: succeeded");
295 dbus_message_unref(reply);
296 dbus_pending_call_unref(call);
297 dbus_connection_unref(encrypt_request_data.connection);
298 g_free(encrypted_value);
300 encrypt_request_data.connection = NULL;
301 encrypt_request_data.network = NULL;
304 static int send_encryption_request(const char *passphrase,
305 struct connman_network *network)
307 DBusConnection *connection = NULL;
308 DBusMessage *msg = NULL;
309 DBusPendingCall *call;
312 DBG("Invalid parameter");
316 connection = connman_dbus_get_connection();
318 DBG("dbus connection does not exist");
322 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
323 NETCONFIG_WIFI_INTERFACE, "EncryptPassphrase");
325 dbus_connection_unref(connection);
329 dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
332 if (!dbus_connection_send_with_reply(connection, msg,
333 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
334 dbus_message_unref(msg);
335 dbus_connection_unref(connection);
340 dbus_message_unref(msg);
341 dbus_connection_unref(connection);
345 encrypt_request_data.connection = connection;
346 encrypt_request_data.network = network;
348 dbus_pending_call_set_notify(call, encryption_request_reply, NULL, NULL);
349 dbus_message_unref(msg);
355 static int p2p_tech_probe(struct connman_technology *technology)
357 p2p_technology = technology;
362 static void p2p_tech_remove(struct connman_technology *technology)
364 p2p_technology = NULL;
367 static struct connman_technology_driver p2p_tech_driver = {
369 .type = CONNMAN_SERVICE_TYPE_P2P,
370 .probe = p2p_tech_probe,
371 .remove = p2p_tech_remove,
374 static bool is_p2p_connecting(void)
378 for (list = iface_list; list; list = list->next) {
379 struct wifi_data *wifi = list->data;
381 if (wifi->p2p_connecting)
388 static void add_pending_wifi_device(struct wifi_data *wifi)
390 if (g_list_find(pending_wifi_device, wifi))
393 pending_wifi_device = g_list_append(pending_wifi_device, wifi);
396 #if defined TIZEN_EXT_WIFI_MESH
397 struct wifi_mesh_info {
398 struct wifi_data *wifi;
399 GSupplicantInterface *interface;
400 struct connman_mesh *mesh;
407 struct mesh_change_peer_status_info {
409 enum connman_mesh_peer_status peer_status;
410 mesh_change_peer_status_cb_t callback;
414 static struct connman_technology_driver mesh_tech_driver = {
416 .type = CONNMAN_SERVICE_TYPE_MESH,
419 static void mesh_interface_create_callback(int result,
420 GSupplicantInterface *interface,
423 struct wifi_mesh_info *mesh_info = user_data;
424 struct wifi_data *wifi;
425 bool success = false;
427 DBG("result %d ifname %s, mesh_info %p", result,
428 g_supplicant_interface_get_ifname(interface),
431 if (result < 0 || !mesh_info)
434 wifi = mesh_info->wifi;
436 mesh_info->interface = interface;
437 mesh_info->identifier = connman_inet_ifaddr(mesh_info->ifname);
438 mesh_info->index = connman_inet_ifindex(mesh_info->ifname);
439 DBG("Mesh Interface identifier %s", mesh_info->identifier);
440 wifi->mesh_interface = true;
441 wifi->mesh_info = mesh_info;
442 g_supplicant_interface_set_data(interface, wifi);
446 connman_mesh_notify_interface_create(success);
449 static int add_mesh_interface(const char *ifname, const char *parent_ifname)
452 struct wifi_data *wifi;
453 struct wifi_mesh_info *mesh_info;
454 const char *wifi_ifname;
455 bool parent_found = false;
456 const char *driver = "nl80211";
458 for (list = iface_list; list; list = list->next) {
461 if (!g_supplicant_interface_has_mesh(wifi->interface))
464 wifi_ifname = g_supplicant_interface_get_ifname(wifi->interface);
468 if (!g_strcmp0(wifi_ifname, parent_ifname)) {
475 DBG("Parent interface %s doesn't exist", parent_ifname);
479 mesh_info = g_try_malloc0(sizeof(struct wifi_mesh_info));
483 mesh_info->wifi = wifi;
484 mesh_info->ifname = g_strdup(ifname);
485 mesh_info->parent_ifname = g_strdup(parent_ifname);
487 g_supplicant_mesh_interface_create(ifname, driver, NULL, parent_ifname,
488 mesh_interface_create_callback, mesh_info);
492 static void mesh_interface_remove_callback(int result,
493 GSupplicantInterface *interface,
496 struct wifi_data *wifi = user_data;
497 struct wifi_mesh_info *mesh_info = wifi->mesh_info;
498 bool success = false;
500 DBG("result %d mesh_info %p", result, mesh_info);
502 if (result < 0 || !mesh_info)
505 mesh_info->interface = NULL;
506 g_free(mesh_info->parent_ifname);
507 g_free(mesh_info->ifname);
508 g_free(mesh_info->identifier);
510 wifi->mesh_interface = false;
511 wifi->mesh_info = NULL;
515 connman_mesh_notify_interface_remove(success);
518 static int remove_mesh_interface(const char *ifname)
521 struct wifi_data *wifi;
522 struct wifi_mesh_info *mesh_info;
523 bool mesh_if_found = false;
526 for (list = iface_list; list; list = list->next) {
529 if (wifi->mesh_interface) {
530 mesh_if_found = true;
535 if (!mesh_if_found) {
536 DBG("Mesh interface %s doesn't exist", ifname);
540 mesh_info = wifi->mesh_info;
541 ret = g_supplicant_interface_remove(mesh_info->interface,
542 mesh_interface_remove_callback, wifi);
549 static void mesh_disconnect_callback(int result,
550 GSupplicantInterface *interface, void *user_data)
552 struct connman_mesh *mesh = user_data;
554 DBG("result %d interface %p mesh %p", result, interface, mesh);
557 static int mesh_peer_disconnect(struct connman_mesh *mesh)
560 struct wifi_data *wifi;
561 struct wifi_mesh_info *mesh_info;
562 bool mesh_if_found = false;
563 GSupplicantInterface *interface;
565 for (list = iface_list; list; list = list->next) {
568 if (wifi->mesh_interface) {
569 mesh_if_found = true;
574 if (!mesh_if_found) {
575 DBG("Mesh interface is not created");
579 mesh_info = wifi->mesh_info;
581 interface = mesh_info->interface;
582 return g_supplicant_interface_disconnect(interface,
583 mesh_disconnect_callback, mesh);
586 static void mesh_connect_callback(int result, GSupplicantInterface *interface,
589 struct connman_mesh *mesh = user_data;
590 DBG("mesh %p result %d", mesh, result);
593 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_FAILURE);
595 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_ASSOCIATION);
598 static GSupplicantSecurity mesh_network_security(const char *security)
600 if (g_str_equal(security, "none"))
601 return G_SUPPLICANT_SECURITY_NONE;
602 else if (g_str_equal(security, "sae"))
603 return G_SUPPLICANT_SECURITY_SAE;
605 return G_SUPPLICANT_SECURITY_UNKNOWN;
608 static void mesh_ssid_init(GSupplicantSSID *ssid, struct connman_mesh *mesh)
611 const char *security;
616 memset(ssid, 0, sizeof(*ssid));
617 ssid->mode = G_SUPPLICANT_MODE_MESH;
619 security = connman_mesh_get_security(mesh);
620 ssid->security = mesh_network_security(security);
622 if (ssid->security == G_SUPPLICANT_SECURITY_SAE)
623 ssid->passphrase = connman_mesh_get_passphrase(mesh);
625 ssid->freq = connman_mesh_get_frequency(mesh);
626 name = connman_mesh_get_name(mesh);
628 ssid->ssid_len = strlen(name);
629 ssid->ssid = g_malloc0(ssid->ssid_len + 1);
630 memcpy(ssid->ssid, name, ssid->ssid_len);
635 static int mesh_peer_connect(struct connman_mesh *mesh)
638 struct wifi_data *wifi;
639 struct wifi_mesh_info *mesh_info;
640 bool mesh_if_found = false;
641 GSupplicantInterface *interface;
642 GSupplicantSSID *ssid;
644 for (list = iface_list; list; list = list->next) {
647 if (wifi->mesh_interface) {
648 mesh_if_found = true;
653 if (!mesh_if_found) {
654 DBG("Mesh interface is not created");
658 mesh_info = wifi->mesh_info;
660 interface = mesh_info->interface;
662 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
666 mesh_info->mesh = mesh;
668 mesh_ssid_init(ssid, mesh);
669 return g_supplicant_interface_connect(interface, ssid,
670 mesh_connect_callback, mesh);
673 static void mesh_peer_change_status_callback(int result,
674 GSupplicantInterface *interface,
677 struct mesh_change_peer_status_info *data = user_data;
679 DBG("result %d Peer Status %d", result, data->peer_status);
681 if (result == 0 && data->peer_status == CONNMAN_MESH_PEER_REMOVE) {
682 /* WLAN_REASON_MESH_PEERING_CANCELLED = 52 */
683 connman_mesh_remove_connected_peer(data->peer_address, 52);
687 data->callback(result, data->user_data);
689 g_free(data->peer_address);
694 static int mesh_change_peer_status(const char *peer_address,
695 enum connman_mesh_peer_status status,
696 mesh_change_peer_status_cb_t callback, void *user_data)
699 struct wifi_data *wifi;
700 struct wifi_mesh_info *mesh_info;
701 bool mesh_if_found = false;
702 GSupplicantInterface *interface;
703 struct mesh_change_peer_status_info *data;
706 for (list = iface_list; list; list = list->next) {
709 if (wifi->mesh_interface) {
710 mesh_if_found = true;
715 if (!mesh_if_found) {
716 DBG("Mesh interface is not created");
720 mesh_info = wifi->mesh_info;
722 interface = mesh_info->interface;
725 case CONNMAN_MESH_PEER_ADD:
726 method = "MeshPeerAdd";
728 case CONNMAN_MESH_PEER_REMOVE:
729 method = "MeshPeerRemove";
732 DBG("Invalid method");
736 data = g_try_malloc0(sizeof(struct mesh_change_peer_status_info));
738 DBG("Memory allocation failed");
742 data->peer_address = g_strdup(peer_address);
743 data->peer_status = status;
744 data->callback = callback;
745 data->user_data = user_data;
747 return g_supplicant_interface_mesh_peer_change_status(interface,
748 mesh_peer_change_status_callback, peer_address, method,
752 static struct connman_mesh_driver mesh_driver = {
753 .add_interface = add_mesh_interface,
754 .remove_interface = remove_mesh_interface,
755 .connect = mesh_peer_connect,
756 .disconnect = mesh_peer_disconnect,
757 .change_peer_status = mesh_change_peer_status,
760 static void mesh_support(GSupplicantInterface *interface)
764 if (!g_supplicant_interface_has_mesh(interface))
767 if (connman_technology_driver_register(&mesh_tech_driver) < 0) {
768 DBG("Could not register Mesh technology driver");
772 connman_mesh_driver_register(&mesh_driver);
775 static void check_mesh_technology(void)
777 bool mesh_exists = false;
780 for (list = iface_list; list; list = list->next) {
781 struct wifi_data *w = list->data;
784 g_supplicant_interface_has_mesh(w->interface))
789 connman_technology_driver_unregister(&mesh_tech_driver);
790 connman_mesh_driver_unregister(&mesh_driver);
794 static void mesh_group_started(GSupplicantInterface *interface)
796 struct wifi_data *wifi;
797 struct wifi_mesh_info *mesh_info;
798 struct connman_mesh *mesh;
799 const unsigned char *ssid;
800 unsigned int ssid_len;
803 ssid = g_supplicant_interface_get_mesh_group_ssid(interface, &ssid_len);
804 memcpy(name, ssid, ssid_len);
805 name[ssid_len] = '\0';
806 DBG("name %s", name);
807 wifi = g_supplicant_interface_get_data(interface);
808 DBG("wifi %p", wifi);
813 mesh_info = wifi->mesh_info;
817 mesh = mesh_info->mesh;
821 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_CONFIGURATION);
824 static void mesh_group_removed(GSupplicantInterface *interface)
826 struct wifi_data *wifi;
827 struct wifi_mesh_info *mesh_info;
828 struct connman_mesh *mesh;
829 const unsigned char *ssid;
830 unsigned int ssid_len;
831 int disconnect_reason;
834 ssid = g_supplicant_interface_get_mesh_group_ssid(interface, &ssid_len);
835 memcpy(name, ssid, ssid_len);
836 name[ssid_len] = '\0';
837 DBG("name %s", name);
839 disconnect_reason = g_supplicant_mesh_get_disconnect_reason(interface);
840 DBG("Disconnect Reason %d", disconnect_reason);
842 wifi = g_supplicant_interface_get_data(interface);
843 DBG("wifi %p", wifi);
848 mesh_info = wifi->mesh_info;
852 mesh = connman_get_connected_mesh_from_name(name);
854 DBG("%s is not connected", name);
855 mesh = connman_get_connecting_mesh_from_name(name);
857 DBG("%s is not connecting", name);
862 connman_mesh_peer_set_disconnect_reason(mesh, disconnect_reason);
863 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_DISCONNECT);
866 static void mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
868 const char *peer_address;
870 peer_address = g_supplicant_mesh_peer_get_address(mesh_peer);
875 DBG("Peer %s connected", peer_address);
876 connman_mesh_add_connected_peer(peer_address);
879 static void mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
881 const char *peer_address;
884 peer_address = g_supplicant_mesh_peer_get_address(mesh_peer);
889 reason = g_supplicant_mesh_peer_get_disconnect_reason(mesh_peer);
891 DBG("Peer %s disconnected with reason %d", peer_address, reason);
892 connman_mesh_remove_connected_peer(peer_address, reason);
896 static struct wifi_data *get_pending_wifi_data(const char *ifname)
900 for (list = pending_wifi_device; list; list = list->next) {
901 struct wifi_data *wifi;
902 const char *dev_name;
905 if (!wifi || !wifi->device)
908 dev_name = connman_device_get_string(wifi->device, "Interface");
909 if (!g_strcmp0(ifname, dev_name)) {
910 pending_wifi_device = g_list_delete_link(
911 pending_wifi_device, list);
919 static void remove_pending_wifi_device(struct wifi_data *wifi)
923 link = g_list_find(pending_wifi_device, wifi);
928 pending_wifi_device = g_list_delete_link(pending_wifi_device, link);
931 static void peer_cancel_timeout(struct wifi_data *wifi)
933 if (wifi->p2p_connection_timeout > 0)
934 g_source_remove(wifi->p2p_connection_timeout);
936 wifi->p2p_connection_timeout = 0;
937 wifi->p2p_connecting = false;
939 if (wifi->pending_peer) {
940 connman_peer_unref(wifi->pending_peer);
941 wifi->pending_peer = NULL;
945 static gboolean peer_connect_timeout(gpointer data)
947 struct wifi_data *wifi = data;
951 if (wifi->p2p_connecting) {
952 enum connman_peer_state state = CONNMAN_PEER_STATE_FAILURE;
953 GSupplicantPeer *gs_peer =
954 g_supplicant_interface_peer_lookup(wifi->interface,
955 connman_peer_get_identifier(wifi->pending_peer));
957 if (g_supplicant_peer_has_requested_connection(gs_peer))
958 state = CONNMAN_PEER_STATE_IDLE;
960 connman_peer_set_state(wifi->pending_peer, state);
963 peer_cancel_timeout(wifi);
968 static void peer_connect_callback(int result, GSupplicantInterface *interface,
971 struct wifi_data *wifi = user_data;
972 struct connman_peer *peer = wifi->pending_peer;
974 DBG("peer %p - %d", peer, result);
980 peer_connect_timeout(wifi);
984 connman_peer_set_state(peer, CONNMAN_PEER_STATE_ASSOCIATION);
986 wifi->p2p_connection_timeout = g_timeout_add_seconds(
987 P2P_CONNECTION_TIMEOUT,
988 peer_connect_timeout, wifi);
991 static int peer_connect(struct connman_peer *peer,
992 enum connman_peer_wps_method wps_method,
995 struct connman_device *device = connman_peer_get_device(peer);
996 GSupplicantPeerParams *peer_params;
997 GSupplicantPeer *gs_peer;
998 struct wifi_data *wifi;
1002 DBG("peer %p", peer);
1007 wifi = connman_device_get_data(device);
1008 if (!wifi || !wifi->interface)
1011 if (wifi->p2p_connecting)
1014 gs_peer = g_supplicant_interface_peer_lookup(wifi->interface,
1015 connman_peer_get_identifier(peer));
1019 pbc = g_supplicant_peer_is_wps_pbc(gs_peer);
1020 pin = g_supplicant_peer_is_wps_pin(gs_peer);
1022 switch (wps_method) {
1023 case CONNMAN_PEER_WPS_UNKNOWN:
1024 if ((pbc && pin) || pin)
1027 case CONNMAN_PEER_WPS_PBC:
1032 case CONNMAN_PEER_WPS_PIN:
1033 if (!pin || !wps_pin)
1038 peer_params = g_try_malloc0(sizeof(GSupplicantPeerParams));
1042 peer_params->path = g_strdup(g_supplicant_peer_get_path(gs_peer));
1044 peer_params->wps_pin = g_strdup(wps_pin);
1046 peer_params->master = connman_peer_service_is_master();
1048 ret = g_supplicant_interface_p2p_connect(wifi->interface, peer_params,
1049 peer_connect_callback, wifi);
1050 if (ret == -EINPROGRESS) {
1051 wifi->pending_peer = connman_peer_ref(peer);
1052 wifi->p2p_connecting = true;
1053 } else if (ret < 0) {
1054 g_free(peer_params->path);
1055 g_free(peer_params->wps_pin);
1056 g_free(peer_params);
1062 static int peer_disconnect(struct connman_peer *peer)
1064 struct connman_device *device = connman_peer_get_device(peer);
1065 GSupplicantPeerParams peer_params = {};
1066 GSupplicantPeer *gs_peer;
1067 struct wifi_data *wifi;
1070 DBG("peer %p", peer);
1075 wifi = connman_device_get_data(device);
1079 gs_peer = g_supplicant_interface_peer_lookup(wifi->interface,
1080 connman_peer_get_identifier(peer));
1084 peer_params.path = g_strdup(g_supplicant_peer_get_path(gs_peer));
1086 ret = g_supplicant_interface_p2p_disconnect(wifi->interface,
1088 g_free(peer_params.path);
1090 if (ret == -EINPROGRESS) {
1091 peer_cancel_timeout(wifi);
1092 wifi->p2p_device = false;
1098 struct peer_service_registration {
1099 peer_service_registration_cb_t callback;
1103 static bool is_service_wfd(const unsigned char *specs, int length)
1105 if (length < 9 || specs[0] != 0 || specs[1] != 0 || specs[2] != 6)
1111 static void apply_p2p_listen_on_iface(gpointer data, gpointer user_data)
1113 struct wifi_data *wifi = data;
1115 if (!wifi->interface ||
1116 !g_supplicant_interface_has_p2p(wifi->interface))
1119 if (!wifi->servicing) {
1120 g_supplicant_interface_p2p_listen(wifi->interface,
1121 P2P_LISTEN_PERIOD, P2P_LISTEN_INTERVAL);
1127 static void register_wfd_service_cb(int result,
1128 GSupplicantInterface *iface, void *user_data)
1130 struct peer_service_registration *reg_data = user_data;
1135 g_list_foreach(iface_list, apply_p2p_listen_on_iface, NULL);
1137 if (reg_data && reg_data->callback) {
1138 reg_data->callback(result, reg_data->user_data);
1143 static GSupplicantP2PServiceParams *fill_in_peer_service_params(
1144 const unsigned char *spec,
1145 int spec_length, const unsigned char *query,
1146 int query_length, int version)
1148 GSupplicantP2PServiceParams *params;
1150 params = g_try_malloc0(sizeof(GSupplicantP2PServiceParams));
1155 params->version = version;
1156 params->service = g_memdup(spec, spec_length);
1157 } else if (query_length > 0 && spec_length > 0) {
1158 params->query = g_memdup(query, query_length);
1159 params->query_length = query_length;
1161 params->response = g_memdup(spec, spec_length);
1162 params->response_length = spec_length;
1164 params->wfd_ies = g_memdup(spec, spec_length);
1165 params->wfd_ies_length = spec_length;
1171 static void free_peer_service_params(GSupplicantP2PServiceParams *params)
1176 g_free(params->service);
1177 g_free(params->query);
1178 g_free(params->response);
1179 g_free(params->wfd_ies);
1184 static int peer_register_wfd_service(const unsigned char *specification,
1185 int specification_length,
1186 peer_service_registration_cb_t callback,
1189 struct peer_service_registration *reg_data = NULL;
1190 static GSupplicantP2PServiceParams *params;
1195 if (wfd_service_registered)
1198 params = fill_in_peer_service_params(specification,
1199 specification_length, NULL, 0, 0);
1203 reg_data = g_try_malloc0(sizeof(*reg_data));
1209 reg_data->callback = callback;
1210 reg_data->user_data = user_data;
1212 ret = g_supplicant_set_widi_ies(params,
1213 register_wfd_service_cb, reg_data);
1214 if (ret < 0 && ret != -EINPROGRESS)
1217 wfd_service_registered = true;
1221 free_peer_service_params(params);
1227 static void register_peer_service_cb(int result,
1228 GSupplicantInterface *iface, void *user_data)
1230 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
1231 struct peer_service_registration *reg_data = user_data;
1233 #if defined TIZEN_EXT
1241 apply_p2p_listen_on_iface(wifi, NULL);
1243 if (reg_data->callback)
1244 reg_data->callback(result, reg_data->user_data);
1249 static int peer_register_service(const unsigned char *specification,
1250 int specification_length,
1251 const unsigned char *query,
1252 int query_length, int version,
1253 peer_service_registration_cb_t callback,
1256 struct peer_service_registration *reg_data;
1257 GSupplicantP2PServiceParams *params;
1264 if (specification && !version && !query &&
1265 is_service_wfd(specification, specification_length)) {
1266 return peer_register_wfd_service(specification,
1267 specification_length, callback, user_data);
1270 reg_data = g_try_malloc0(sizeof(*reg_data));
1274 reg_data->callback = callback;
1275 reg_data->user_data = user_data;
1277 ret_f = -EOPNOTSUPP;
1279 for (list = iface_list; list; list = list->next) {
1280 struct wifi_data *wifi = list->data;
1281 GSupplicantInterface *iface = wifi->interface;
1283 if (!g_supplicant_interface_has_p2p(iface))
1286 params = fill_in_peer_service_params(specification,
1287 specification_length, query,
1288 query_length, version);
1293 ret_f = g_supplicant_interface_p2p_add_service(iface,
1294 register_peer_service_cb, params, reg_data);
1295 if (ret_f == 0 || ret_f == -EINPROGRESS)
1299 ret = g_supplicant_interface_p2p_add_service(iface,
1300 register_peer_service_cb, params, NULL);
1301 if (ret != 0 && ret != -EINPROGRESS)
1302 free_peer_service_params(params);
1305 if (ret_f != 0 && ret_f != -EINPROGRESS)
1311 static int peer_unregister_wfd_service(void)
1313 GSupplicantP2PServiceParams *params;
1316 if (!wfd_service_registered)
1319 params = fill_in_peer_service_params(NULL, 0, NULL, 0, 0);
1323 wfd_service_registered = false;
1325 g_supplicant_set_widi_ies(params, NULL, NULL);
1327 for (list = iface_list; list; list = list->next) {
1328 struct wifi_data *wifi = list->data;
1330 if (!g_supplicant_interface_has_p2p(wifi->interface))
1334 if (!wifi->servicing || wifi->servicing < 0) {
1335 g_supplicant_interface_p2p_listen(wifi->interface,
1337 wifi->servicing = 0;
1344 static int peer_unregister_service(const unsigned char *specification,
1345 int specification_length,
1346 const unsigned char *query,
1347 int query_length, int version)
1349 GSupplicantP2PServiceParams *params;
1354 if (specification && !version && !query &&
1355 is_service_wfd(specification, specification_length)) {
1356 ret = peer_unregister_wfd_service();
1357 if (ret != 0 && ret != -EINPROGRESS)
1362 for (list = iface_list; list; list = list->next) {
1363 struct wifi_data *wifi = list->data;
1364 GSupplicantInterface *iface = wifi->interface;
1367 goto stop_listening;
1369 if (!g_supplicant_interface_has_p2p(iface))
1372 params = fill_in_peer_service_params(specification,
1373 specification_length, query,
1374 query_length, version);
1378 ret = g_supplicant_interface_p2p_del_service(iface, params);
1379 if (ret != 0 && ret != -EINPROGRESS)
1380 free_peer_service_params(params);
1383 if (!wifi->servicing || wifi->servicing < 0) {
1384 g_supplicant_interface_p2p_listen(iface, 0, 0);
1385 wifi->servicing = 0;
1392 static struct connman_peer_driver peer_driver = {
1393 .connect = peer_connect,
1394 .disconnect = peer_disconnect,
1395 .register_service = peer_register_service,
1396 .unregister_service = peer_unregister_service,
1399 static void handle_tethering(struct wifi_data *wifi)
1401 if (!wifi->tethering)
1410 DBG("index %d bridge %s", wifi->index, wifi->bridge);
1412 if (connman_inet_add_to_bridge(wifi->index, wifi->bridge) < 0)
1415 wifi->bridged = true;
1418 static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
1420 struct connman_device *device = user_data;
1421 struct wifi_data *wifi = connman_device_get_data(device);
1426 DBG("index %d flags %d change %d", wifi->index, flags, change);
1428 if ((wifi->flags & IFF_UP) != (flags & IFF_UP)) {
1430 DBG("interface up");
1432 DBG("interface down");
1435 if ((wifi->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
1436 if (flags & IFF_LOWER_UP) {
1439 handle_tethering(wifi);
1444 wifi->flags = flags;
1447 static int wifi_probe(struct connman_device *device)
1449 struct wifi_data *wifi;
1451 DBG("device %p", device);
1453 wifi = g_try_new0(struct wifi_data, 1);
1457 wifi->state = G_SUPPLICANT_STATE_INACTIVE;
1458 wifi->ap_supported = WIFI_AP_UNKNOWN;
1459 wifi->tethering_param = NULL;
1461 connman_device_set_data(device, wifi);
1462 wifi->device = connman_device_ref(device);
1464 wifi->index = connman_device_get_index(device);
1467 wifi->watch = connman_rtnl_add_newlink_watch(wifi->index,
1468 wifi_newlink, device);
1469 if (is_p2p_connecting())
1470 add_pending_wifi_device(wifi);
1472 iface_list = g_list_append(iface_list, wifi);
1477 static void remove_networks(struct connman_device *device,
1478 struct wifi_data *wifi)
1482 for (list = wifi->networks; list; list = list->next) {
1483 struct connman_network *network = list->data;
1485 connman_device_remove_network(device, network);
1486 connman_network_unref(network);
1489 g_slist_free(wifi->networks);
1490 wifi->networks = NULL;
1493 static void remove_peers(struct wifi_data *wifi)
1497 for (list = wifi->peers; list; list = list->next) {
1498 struct connman_peer *peer = list->data;
1500 connman_peer_unregister(peer);
1501 connman_peer_unref(peer);
1504 g_slist_free(wifi->peers);
1508 static void reset_autoscan(struct connman_device *device)
1510 struct wifi_data *wifi = connman_device_get_data(device);
1511 struct autoscan_params *autoscan;
1515 if (!wifi || !wifi->autoscan)
1518 autoscan = wifi->autoscan;
1520 autoscan->interval = 0;
1522 if (autoscan->timeout == 0)
1525 g_source_remove(autoscan->timeout);
1526 autoscan->timeout = 0;
1528 connman_device_unref(device);
1531 static void stop_autoscan(struct connman_device *device)
1533 const struct wifi_data *wifi = connman_device_get_data(device);
1535 if (!wifi || !wifi->autoscan)
1538 reset_autoscan(device);
1540 connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_WIFI, false);
1543 static void check_p2p_technology(void)
1545 bool p2p_exists = false;
1548 for (list = iface_list; list; list = list->next) {
1549 struct wifi_data *w = list->data;
1552 g_supplicant_interface_has_p2p(w->interface))
1557 connman_technology_driver_unregister(&p2p_tech_driver);
1558 connman_peer_driver_unregister(&peer_driver);
1562 struct last_connected {
1568 static gint sort_entry(gconstpointer a, gconstpointer b, gpointer user_data)
1570 GTimeVal *aval = (GTimeVal *)a;
1571 GTimeVal *bval = (GTimeVal *)b;
1573 /* Note that the sort order is descending */
1574 if (aval->tv_sec < bval->tv_sec)
1577 if (aval->tv_sec > bval->tv_sec)
1583 static void free_entry(gpointer data)
1585 struct last_connected *entry = data;
1587 g_free(entry->ssid);
1591 static void wifi_remove(struct connman_device *device)
1593 struct wifi_data *wifi = connman_device_get_data(device);
1595 DBG("device %p wifi %p", device, wifi);
1600 stop_autoscan(device);
1602 if (wifi->p2p_device)
1603 p2p_iface_list = g_list_remove(p2p_iface_list, wifi);
1605 iface_list = g_list_remove(iface_list, wifi);
1607 check_p2p_technology();
1608 #if defined TIZEN_EXT_WIFI_MESH
1609 check_mesh_technology();
1612 remove_pending_wifi_device(wifi);
1614 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_P2P)) {
1615 g_source_remove(wifi->p2p_find_timeout);
1616 connman_device_unref(wifi->device);
1619 if (wifi->p2p_connection_timeout)
1620 g_source_remove(wifi->p2p_connection_timeout);
1622 #if defined TIZEN_EXT
1623 if (wifi->automaxspeed_timeout != 0) {
1624 g_source_remove(wifi->automaxspeed_timeout);
1625 wifi->automaxspeed_timeout = 0;
1629 remove_networks(device, wifi);
1632 connman_device_set_powered(device, false);
1633 connman_device_set_data(device, NULL);
1634 connman_device_unref(wifi->device);
1635 connman_rtnl_remove_watch(wifi->watch);
1637 g_supplicant_interface_set_data(wifi->interface, NULL);
1639 g_supplicant_interface_cancel(wifi->interface);
1641 if (wifi->scan_params)
1642 g_supplicant_free_scan_params(wifi->scan_params);
1643 #if defined TIZEN_EXT
1644 if (wifi->hidden_scan_params) {
1645 while (wifi->hidden_scan_params->ssids) {
1646 struct scan_ssid *ssid;
1647 ssid = wifi->hidden_scan_params->ssids->data;
1648 wifi->hidden_scan_params->ssids = g_slist_remove(wifi->hidden_scan_params->ssids, ssid);
1650 g_supplicant_free_scan_params(wifi->hidden_scan_params);
1654 g_free(wifi->autoscan);
1655 g_free(wifi->identifier);
1659 static bool is_duplicate(GSList *list, gchar *ssid, int ssid_len)
1663 for (iter = list; iter; iter = g_slist_next(iter)) {
1664 struct scan_ssid *scan_ssid = iter->data;
1666 if (ssid_len == scan_ssid->ssid_len &&
1667 memcmp(ssid, scan_ssid->ssid, ssid_len) == 0)
1674 static int add_scan_param(gchar *hex_ssid, char *raw_ssid, int ssid_len,
1675 int freq, GSupplicantScanParams *scan_data,
1676 int driver_max_scan_ssids, char *ssid_name)
1679 struct scan_ssid *scan_ssid;
1681 if ((driver_max_scan_ssids == 0 ||
1682 driver_max_scan_ssids > scan_data->num_ssids) &&
1683 (hex_ssid || raw_ssid)) {
1685 unsigned int j = 0, hex;
1688 size_t hex_ssid_len = strlen(hex_ssid);
1690 ssid = g_try_malloc0(hex_ssid_len / 2);
1694 for (i = 0; i < hex_ssid_len; i += 2) {
1695 sscanf(hex_ssid + i, "%02x", &hex);
1704 * If we have already added hidden AP to the list,
1705 * then do not do it again. This might happen if you have
1706 * used or are using multiple wifi cards, so in that case
1707 * you might have multiple service files for same AP.
1709 if (is_duplicate(scan_data->ssids, ssid, j)) {
1715 scan_ssid = g_try_new(struct scan_ssid, 1);
1722 memcpy(scan_ssid->ssid, ssid, j);
1723 scan_ssid->ssid_len = j;
1724 scan_data->ssids = g_slist_prepend(scan_data->ssids,
1727 scan_data->num_ssids++;
1729 DBG("SSID %s added to scanned list of %d entries", ssid_name,
1730 scan_data->num_ssids);
1737 scan_data->ssids = g_slist_reverse(scan_data->ssids);
1739 if (!scan_data->freqs) {
1740 scan_data->freqs = g_try_malloc0(sizeof(uint16_t));
1741 if (!scan_data->freqs) {
1742 g_slist_free_full(scan_data->ssids, g_free);
1746 scan_data->num_freqs = 1;
1747 scan_data->freqs[0] = freq;
1749 bool duplicate = false;
1751 /* Don't add duplicate entries */
1752 for (i = 0; i < scan_data->num_freqs; i++) {
1753 if (scan_data->freqs[i] == freq) {
1760 scan_data->num_freqs++;
1761 scan_data->freqs = g_try_realloc(scan_data->freqs,
1762 sizeof(uint16_t) * scan_data->num_freqs);
1763 if (!scan_data->freqs) {
1764 g_slist_free_full(scan_data->ssids, g_free);
1767 scan_data->freqs[scan_data->num_freqs - 1] = freq;
1774 static int get_hidden_connections(GSupplicantScanParams *scan_data)
1776 struct connman_config_entry **entries;
1778 #if defined TIZEN_EXT
1779 gchar **services = NULL;
1782 #endif /* defined TIZEN_EXT */
1786 int num_ssids = 0, add_param_failed = 0;
1787 #if defined TIZEN_EXT
1788 GSequenceIter *iter;
1789 GSequence *latest_list;
1790 struct last_connected *entry;
1793 latest_list = g_sequence_new(free_entry);
1797 services = connman_storage_get_services();
1798 for (i = 0; services && services[i]; i++) {
1799 if (strncmp(services[i], "wifi_", 5) != 0)
1802 keyfile = connman_storage_load_service(services[i]);
1806 value = g_key_file_get_boolean(keyfile,
1807 services[i], "Hidden", NULL);
1809 g_key_file_free(keyfile);
1813 value = g_key_file_get_boolean(keyfile,
1814 services[i], "Favorite", NULL);
1816 g_key_file_free(keyfile);
1820 #if defined TIZEN_EXT
1821 value = g_key_file_get_boolean(keyfile,
1822 services[i], "AutoConnect", NULL);
1824 g_key_file_free(keyfile);
1828 gchar *str = g_key_file_get_string(keyfile,
1829 services[i], "Modified", NULL);
1831 g_key_file_free(keyfile);
1834 g_time_val_from_iso8601(str, &modified);
1838 ssid = g_key_file_get_string(keyfile,
1839 services[i], "SSID", NULL);
1841 name = g_key_file_get_string(keyfile, services[i], "Name",
1844 #if defined TIZEN_EXT
1845 entry = g_try_new(struct last_connected, 1);
1847 g_sequence_free(latest_list);
1850 g_key_file_free(keyfile);
1854 entry->modified = modified;
1857 g_sequence_insert_sorted(latest_list, entry,
1860 ret = add_scan_param(ssid, NULL, 0, 0, scan_data, 0, name);
1869 g_key_file_free(keyfile);
1872 #if defined TIZEN_EXT
1873 gint length = g_sequence_get_length(latest_list);
1874 iter = g_sequence_get_begin_iter(latest_list);
1876 for (i = 0; i < length; i++) {
1877 entry = g_sequence_get(iter);
1879 ret = add_scan_param(entry->ssid, NULL, 0, 0, scan_data, 0, entry->ssid);
1885 iter = g_sequence_iter_next(iter);
1888 g_sequence_free(latest_list);
1892 * Check if there are any hidden AP that needs to be provisioned.
1894 entries = connman_config_get_entries("wifi");
1895 for (i = 0; entries && entries[i]; i++) {
1898 if (!entries[i]->hidden)
1901 if (!entries[i]->ssid) {
1902 ssid = entries[i]->name;
1905 ssid = entries[i]->ssid;
1906 len = entries[i]->ssid_len;
1912 ret = add_scan_param(NULL, ssid, len, 0, scan_data, 0, ssid);
1919 connman_config_free_entries(entries);
1921 if (add_param_failed > 0)
1922 DBG("Unable to scan %d out of %d SSIDs",
1923 add_param_failed, num_ssids);
1925 g_strfreev(services);
1930 static int get_hidden_connections_params(struct wifi_data *wifi,
1931 GSupplicantScanParams *scan_params)
1933 int driver_max_ssids, i;
1934 GSupplicantScanParams *orig_params;
1937 * Scan hidden networks so that we can autoconnect to them.
1938 * We will assume 1 as a default number of ssid to scan.
1940 driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
1942 if (driver_max_ssids == 0)
1943 driver_max_ssids = 1;
1945 DBG("max ssids %d", driver_max_ssids);
1947 #if defined TIZEN_EXT
1948 if (!wifi->hidden_scan_params) {
1949 wifi->hidden_scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
1950 if (!wifi->hidden_scan_params)
1953 if (get_hidden_connections(wifi->hidden_scan_params) == 0) {
1954 g_supplicant_free_scan_params(wifi->hidden_scan_params);
1955 wifi->hidden_scan_params = NULL;
1961 orig_params = wifi->hidden_scan_params;
1963 if (!wifi->scan_params) {
1964 wifi->scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
1965 if (!wifi->scan_params)
1968 if (get_hidden_connections(wifi->scan_params) == 0) {
1969 g_supplicant_free_scan_params(wifi->scan_params);
1970 wifi->scan_params = NULL;
1976 orig_params = wifi->scan_params;
1979 /* Let's transfer driver_max_ssids params */
1980 for (i = 0; i < driver_max_ssids; i++) {
1981 struct scan_ssid *ssid;
1983 #if defined TIZEN_EXT
1984 if (!wifi->hidden_scan_params->ssids)
1986 if (!wifi->scan_params->ssids)
1990 ssid = orig_params->ssids->data;
1991 orig_params->ssids = g_slist_remove(orig_params->ssids, ssid);
1992 scan_params->ssids = g_slist_prepend(scan_params->ssids, ssid);
1996 scan_params->num_ssids = i;
1997 scan_params->ssids = g_slist_reverse(scan_params->ssids);
1999 scan_params->freqs = g_memdup(orig_params->freqs,
2000 sizeof(uint16_t) * orig_params->num_freqs);
2001 if (!scan_params->freqs)
2004 scan_params->num_freqs = orig_params->num_freqs;
2009 orig_params->num_ssids -= scan_params->num_ssids;
2011 return scan_params->num_ssids;
2014 g_slist_free_full(scan_params->ssids, g_free);
2015 #if defined TIZEN_EXT
2016 g_supplicant_free_scan_params(wifi->hidden_scan_params);
2017 wifi->hidden_scan_params = NULL;
2019 g_supplicant_free_scan_params(wifi->scan_params);
2020 wifi->scan_params = NULL;
2026 static int throw_wifi_scan(struct connman_device *device,
2027 GSupplicantInterfaceCallback callback)
2029 struct wifi_data *wifi = connman_device_get_data(device);
2035 DBG("device %p %p", device, wifi->interface);
2037 if (wifi->tethering)
2040 #if defined TIZEN_EXT
2041 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI)
2042 && !wifi->allow_full_scan)
2044 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI))
2048 connman_device_ref(device);
2050 ret = g_supplicant_interface_scan(wifi->interface, NULL,
2053 connman_device_set_scanning(device,
2054 CONNMAN_SERVICE_TYPE_WIFI, true);
2056 connman_device_unref(device);
2061 static void hidden_free(struct hidden_params *hidden)
2066 if (hidden->scan_params)
2067 g_supplicant_free_scan_params(hidden->scan_params);
2068 g_free(hidden->identity);
2069 g_free(hidden->passphrase);
2070 g_free(hidden->security);
2074 #if defined TIZEN_EXT
2075 static void service_state_changed(struct connman_service *service,
2076 enum connman_service_state state);
2078 static int network_connect(struct connman_network *network);
2080 static struct connman_notifier notifier = {
2082 .priority = CONNMAN_NOTIFIER_PRIORITY_DEFAULT,
2083 .service_state_changed = service_state_changed,
2086 static void service_state_changed(struct connman_service *service,
2087 enum connman_service_state state)
2089 enum connman_service_type type;
2091 type = connman_service_get_type(service);
2092 if (type != CONNMAN_SERVICE_TYPE_WIFI)
2095 DBG("service %p state %d", service, state);
2098 case CONNMAN_SERVICE_STATE_READY:
2099 case CONNMAN_SERVICE_STATE_ONLINE:
2100 case CONNMAN_SERVICE_STATE_FAILURE:
2101 connman_notifier_unregister(¬ifier);
2102 is_wifi_notifier_registered = FALSE;
2104 __connman_device_request_scan(type);
2112 static gboolean need_bss_transition(uint16_t freq, int snr, int strength)
2115 * Since bssid->strength is a positive value,
2116 * it need to be changed to its original value.
2118 int signal = strength - 120;
2121 * If the currently connected AP matches the following conditions,
2122 * scan for BSS transition is started.
2123 * - SNR is less than 20 or RSSI level is less than 3
2125 if (snr < 20 && snr != 0)
2127 else if (freq > 4900 && signal <= RSSI_LEVEL_2_5G)
2129 else if (freq <= 4900 && signal <= RSSI_LEVEL_2_24G)
2135 static gboolean check_bss_condition(uint16_t freq, int snr, uint16_t strength)
2138 * Since bssid->strength is a positive value,
2139 * it need to be changed to its original value.
2141 int signal = strength - 120;
2144 * If the AP that matches the following conditions exists in the SCAN result,
2145 * BSS transition is started.
2146 * - SNR is 25 or more and RSSI level is greater than 3
2148 if (snr < 25 && snr != 0)
2151 if (freq > 4900 && signal > RSSI_LEVEL_3_5G)
2153 else if (freq <= 4900 && signal > RSSI_LEVEL_3_24G)
2159 static void scan_callback_hidden(int result,
2160 GSupplicantInterface *interface, void *user_data);
2162 static int network_disconnect(struct connman_network *network);
2165 static void scan_callback(int result, GSupplicantInterface *interface,
2168 struct connman_device *device = user_data;
2169 struct wifi_data *wifi = connman_device_get_data(device);
2171 #if defined TIZEN_EXT
2172 bool roaming_needed = false;
2173 bool roaming_ap_found = false;
2174 GSList *list = NULL;
2175 GSList *bssid_list = NULL;
2176 bool favorite_exists = false;
2177 struct connman_network *network = NULL;
2178 struct connman_service *service = NULL;
2181 DBG("result %d wifi %p", result, wifi);
2184 if (wifi->hidden && !wifi->postpone_hidden) {
2185 connman_network_clear_hidden(wifi->hidden->user_data);
2186 hidden_free(wifi->hidden);
2187 wifi->hidden = NULL;
2190 if (wifi->scan_params) {
2191 g_supplicant_free_scan_params(wifi->scan_params);
2192 wifi->scan_params = NULL;
2195 #if defined TIZEN_EXT
2196 if (wifi->hidden_scan_params && !wifi->hidden_scan_params->ssids) {
2197 g_supplicant_free_scan_params(wifi->hidden_scan_params);
2198 wifi->hidden_scan_params = NULL;
2204 connman_device_reset_scanning(device);
2206 /* User is connecting to a hidden AP, let's wait for finished event */
2207 if (wifi && wifi->hidden && wifi->postpone_hidden) {
2208 GSupplicantScanParams *scan_params;
2211 wifi->postpone_hidden = false;
2212 scan_params = wifi->hidden->scan_params;
2213 wifi->hidden->scan_params = NULL;
2215 reset_autoscan(device);
2217 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
2218 scan_callback, device);
2222 /* On error, let's recall scan_callback, which will cleanup */
2223 return scan_callback(ret, interface, user_data);
2226 #if defined TIZEN_EXT
2228 for (list = wifi->networks; list; list = list->next) {
2229 network = list->data;
2230 service = connman_service_lookup_from_network(network);
2232 if (service != NULL &&
2233 (connman_service_get_favorite(service) == true) &&
2234 (connman_service_get_autoconnect(service) == true)) {
2235 DBG("Favorite service exists [%s]",
2236 connman_network_get_string(network, "Name"));
2237 favorite_exists = true;
2243 if (favorite_exists == false) {
2244 if (wifi && wifi->allow_full_scan) {
2246 DBG("Trigger full channel scan");
2247 wifi->allow_full_scan = false;
2249 ret = g_supplicant_interface_scan(wifi->interface, NULL,
2250 scan_callback_hidden, device);
2254 /* On error, let's recall scan_callback, which will cleanup */
2255 return scan_callback(ret, interface, user_data);
2258 wifi->allow_full_scan = false;
2261 scanning = connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI);
2264 connman_device_set_scanning(device,
2265 CONNMAN_SERVICE_TYPE_WIFI, false);
2268 if (result != -ENOLINK)
2269 #if defined TIZEN_EXT
2272 start_autoscan(device);
2275 * If we are here then we were scanning; however, if we are
2276 * also mid-flight disabling the interface, then wifi_disable
2277 * has already cleared the device scanning state and
2278 * unreferenced the device, obviating the need to do it here.
2282 connman_device_unref(device);
2284 #if defined TIZEN_EXT
2285 if (wifi && wifi->scan_pending_network && result != -EIO) {
2286 network_connect(wifi->scan_pending_network);
2287 wifi->scan_pending_network = NULL;
2288 connman_network_set_connecting(wifi->network);
2289 } else if (connman_setting_get_bool("WifiRoaming") && wifi->network) {
2290 bssid_list = connman_network_get_bssid_list(wifi->network);
2292 if (g_slist_length(bssid_list) <= 1)
2295 if (!connman_network_get_connected(wifi->network))
2298 if (connman_network_get_bool(wifi->network, "WiFi.Roaming"))
2301 if (!need_bss_transition(
2302 connman_network_get_frequency(wifi->network),
2303 connman_network_get_snr(wifi->network),
2304 connman_network_get_strength(wifi->network)))
2307 for (bssid_list; bssid_list; bssid_list = bssid_list->next) {
2308 struct g_connman_bssids *bssid = bssid_list->data;
2310 if (check_bss_condition(bssid->frequency,
2311 bssid->score_snr, bssid->strength))
2312 roaming_ap_found = true;
2315 if (roaming_ap_found) {
2316 char bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
2317 char *bssid_str = bssid_buff;
2318 unsigned char *bssid;
2320 bssid = connman_network_get_bssid(wifi->network);
2321 snprintf(bssid_str, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(bssid));
2322 connman_network_set_string(wifi->network,
2323 "WiFi.RoamingCurBSSID", bssid_str);
2325 network_disconnect(wifi->network);
2326 wifi->pending_network = wifi->network;
2327 connman_network_set_bool(wifi->network, "WiFi.Roaming", true);
2332 if (is_wifi_notifier_registered != true &&
2333 wifi_first_scan == true && found_with_first_scan == true) {
2334 wifi_first_scan = false;
2335 found_with_first_scan = false;
2337 connman_notifier_register(¬ifier);
2338 is_wifi_notifier_registered = true;
2343 static void scan_callback_hidden(int result,
2344 GSupplicantInterface *interface, void *user_data)
2346 struct connman_device *device = user_data;
2347 struct wifi_data *wifi = connman_device_get_data(device);
2348 GSupplicantScanParams *scan_params;
2351 DBG("result %d wifi %p", result, wifi);
2356 /* User is trying to connect to a hidden AP */
2357 if (wifi->hidden && wifi->postpone_hidden)
2360 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2364 if (get_hidden_connections_params(wifi, scan_params) > 0) {
2365 ret = g_supplicant_interface_scan(wifi->interface,
2367 #if defined TIZEN_EXT
2370 scan_callback_hidden,
2377 g_supplicant_free_scan_params(scan_params);
2380 scan_callback(result, interface, user_data);
2383 static gboolean autoscan_timeout(gpointer data)
2385 struct connman_device *device = data;
2386 struct wifi_data *wifi = connman_device_get_data(device);
2387 struct autoscan_params *autoscan;
2393 autoscan = wifi->autoscan;
2395 #if defined TIZEN_EXT
2400 if (autoscan->interval <= 0) {
2401 interval = autoscan->base;
2404 interval = autoscan->interval * autoscan->base;
2406 #if defined TIZEN_EXT
2407 if (autoscan->interval >= autoscan->limit)
2409 if (interval > autoscan->limit)
2411 interval = autoscan->limit;
2413 throw_wifi_scan(wifi->device, scan_callback_hidden);
2416 * In case BackgroundScanning is disabled, interval will reach the
2417 * limit exactly after the very first passive scanning. It allows
2418 * to ensure at most one passive scan is performed in such cases.
2420 if (!connman_setting_get_bool("BackgroundScanning") &&
2421 interval == autoscan->limit) {
2422 g_source_remove(autoscan->timeout);
2423 autoscan->timeout = 0;
2425 connman_device_unref(device);
2431 DBG("interval %d", interval);
2433 autoscan->interval = interval;
2435 autoscan->timeout = g_timeout_add_seconds(interval,
2436 autoscan_timeout, device);
2441 static void start_autoscan(struct connman_device *device)
2443 struct wifi_data *wifi = connman_device_get_data(device);
2444 struct autoscan_params *autoscan;
2451 if (wifi->p2p_device)
2454 if (wifi->connected)
2457 autoscan = wifi->autoscan;
2461 if (autoscan->timeout > 0 || autoscan->interval > 0)
2464 connman_device_ref(device);
2466 autoscan_timeout(device);
2469 static struct autoscan_params *parse_autoscan_params(const char *params)
2471 struct autoscan_params *autoscan;
2478 list_params = g_strsplit(params, ":", 0);
2479 if (list_params == 0)
2482 if (!g_strcmp0(list_params[0], "exponential") &&
2483 g_strv_length(list_params) == 3) {
2484 base = atoi(list_params[1]);
2485 limit = atoi(list_params[2]);
2486 } else if (!g_strcmp0(list_params[0], "single") &&
2487 g_strv_length(list_params) == 2)
2488 base = limit = atoi(list_params[1]);
2490 g_strfreev(list_params);
2494 DBG("Setup %s autoscanning", list_params[0]);
2496 g_strfreev(list_params);
2498 autoscan = g_try_malloc0(sizeof(struct autoscan_params));
2500 DBG("Could not allocate memory for autoscan");
2504 DBG("base %d - limit %d", base, limit);
2505 autoscan->base = base;
2506 autoscan->limit = limit;
2511 static void setup_autoscan(struct wifi_data *wifi)
2514 * If BackgroundScanning is enabled, setup exponential
2515 * autoscanning if it has not been previously done.
2517 if (connman_setting_get_bool("BackgroundScanning")) {
2518 wifi->autoscan = parse_autoscan_params(AUTOSCAN_EXPONENTIAL);
2521 #if defined TIZEN_EXT
2523 if (wifi->autoscan) {
2524 g_free(wifi->autoscan);
2525 wifi->autoscan = NULL;
2528 DBG("BackgroundScanning is disabled");
2535 * On the contrary, if BackgroundScanning is disabled, update autoscan
2536 * parameters based on the type of scanning that is being performed.
2538 if (wifi->autoscan) {
2539 g_free(wifi->autoscan);
2540 wifi->autoscan = NULL;
2543 switch (wifi->scanning_type) {
2544 case WIFI_SCANNING_PASSIVE:
2545 /* Do not setup autoscan. */
2547 case WIFI_SCANNING_ACTIVE:
2548 /* Setup one single passive scan after active. */
2549 wifi->autoscan = parse_autoscan_params(AUTOSCAN_SINGLE);
2551 case WIFI_SCANNING_UNKNOWN:
2552 /* Setup autoscan in this case but we should never fall here. */
2553 wifi->autoscan = parse_autoscan_params(AUTOSCAN_SINGLE);
2559 static void finalize_interface_creation(struct wifi_data *wifi)
2561 DBG("interface is ready wifi %p tethering %d", wifi, wifi->tethering);
2563 if (!wifi->device) {
2564 connman_error("WiFi device not set");
2568 connman_device_set_powered(wifi->device, true);
2570 if (wifi->p2p_device)
2573 if (!wifi->autoscan)
2574 setup_autoscan(wifi);
2576 start_autoscan(wifi->device);
2579 static void interface_create_callback(int result,
2580 GSupplicantInterface *interface,
2583 struct wifi_data *wifi = user_data;
2585 DBG("result %d ifname %s, wifi %p", result,
2586 g_supplicant_interface_get_ifname(interface),
2589 if (result < 0 || !wifi)
2592 wifi->interface = interface;
2593 g_supplicant_interface_set_data(interface, wifi);
2595 if (g_supplicant_interface_get_ready(interface)) {
2596 wifi->interface_ready = true;
2597 finalize_interface_creation(wifi);
2601 static int wifi_enable(struct connman_device *device)
2603 struct wifi_data *wifi = connman_device_get_data(device);
2606 const char *driver = connman_option_get_string("wifi");
2609 DBG("device %p %p", device, wifi);
2611 index = connman_device_get_index(device);
2612 if (!wifi || index < 0)
2615 if (is_p2p_connecting())
2616 return -EINPROGRESS;
2618 interface = connman_inet_ifname(index);
2619 ret = g_supplicant_interface_create(interface, driver, NULL,
2621 connman_device_get_mac_policy(device),
2622 connman_device_get_preassoc_mac_policy(device),
2623 connman_device_get_random_mac_lifetime(device),
2624 #endif /* TIZEN_EXT */
2625 interface_create_callback,
2632 return -EINPROGRESS;
2635 static int wifi_disable(struct connman_device *device)
2637 struct wifi_data *wifi = connman_device_get_data(device);
2640 DBG("device %p wifi %p", device, wifi);
2645 wifi->connected = false;
2646 wifi->disconnecting = false;
2648 if (wifi->pending_network)
2649 wifi->pending_network = NULL;
2651 #if !defined TIZEN_EXT
2652 stop_autoscan(device);
2655 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_P2P)) {
2656 g_source_remove(wifi->p2p_find_timeout);
2657 wifi->p2p_find_timeout = 0;
2658 connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_P2P, false);
2659 connman_device_unref(wifi->device);
2662 #if defined TIZEN_EXT
2663 if (wifi->automaxspeed_timeout != 0) {
2664 g_source_remove(wifi->automaxspeed_timeout);
2665 wifi->automaxspeed_timeout = 0;
2669 /* In case of a user scan, device is still referenced */
2670 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI)) {
2671 connman_device_set_scanning(device,
2672 CONNMAN_SERVICE_TYPE_WIFI, false);
2673 connman_device_unref(wifi->device);
2676 #if defined TIZEN_EXT
2677 stop_autoscan(device);
2680 remove_networks(device, wifi);
2683 #if defined TIZEN_EXT
2684 wifi->scan_pending_network = NULL;
2686 if (is_wifi_notifier_registered == true) {
2687 connman_notifier_unregister(¬ifier);
2688 is_wifi_notifier_registered = false;
2692 ret = g_supplicant_interface_remove(wifi->interface, NULL, NULL);
2696 return -EINPROGRESS;
2699 static int get_latest_connections(int max_ssids,
2700 GSupplicantScanParams *scan_data)
2702 GSequenceIter *iter;
2703 GSequence *latest_list;
2704 struct last_connected *entry;
2713 latest_list = g_sequence_new(free_entry);
2717 services = connman_storage_get_services();
2718 for (i = 0; services && services[i]; i++) {
2719 if (strncmp(services[i], "wifi_", 5) != 0)
2722 keyfile = connman_storage_load_service(services[i]);
2726 str = g_key_file_get_string(keyfile,
2727 services[i], "Favorite", NULL);
2728 if (!str || g_strcmp0(str, "true")) {
2730 g_key_file_free(keyfile);
2735 str = g_key_file_get_string(keyfile,
2736 services[i], "AutoConnect", NULL);
2737 if (!str || g_strcmp0(str, "true")) {
2739 g_key_file_free(keyfile);
2744 str = g_key_file_get_string(keyfile,
2745 services[i], "Modified", NULL);
2747 g_key_file_free(keyfile);
2750 util_iso8601_to_timeval(str, &modified);
2753 ssid = g_key_file_get_string(keyfile,
2754 services[i], "SSID", NULL);
2756 freq = g_key_file_get_integer(keyfile, services[i],
2759 entry = g_try_new(struct last_connected, 1);
2761 g_sequence_free(latest_list);
2762 g_key_file_free(keyfile);
2764 #if defined TIZEN_EXT
2765 g_strfreev(services);
2771 entry->modified = modified;
2774 g_sequence_insert_sorted(latest_list, entry,
2780 g_key_file_free(keyfile);
2783 g_strfreev(services);
2785 num_ssids = num_ssids > max_ssids ? max_ssids : num_ssids;
2787 iter = g_sequence_get_begin_iter(latest_list);
2789 for (i = 0; i < num_ssids; i++) {
2790 entry = g_sequence_get(iter);
2792 DBG("ssid %s freq %d modified %lu", entry->ssid, entry->freq,
2793 entry->modified.tv_sec);
2795 add_scan_param(entry->ssid, NULL, 0, entry->freq, scan_data,
2796 max_ssids, entry->ssid);
2798 iter = g_sequence_iter_next(iter);
2801 g_sequence_free(latest_list);
2805 static void wifi_update_scanner_type(struct wifi_data *wifi,
2806 enum wifi_scanning_type new_type)
2810 if (!wifi || wifi->scanning_type == new_type)
2813 wifi->scanning_type = new_type;
2815 setup_autoscan(wifi);
2818 static int wifi_scan_simple(struct connman_device *device)
2820 struct wifi_data *wifi = connman_device_get_data(device);
2822 reset_autoscan(device);
2824 /* Distinguish between devices performing passive and active scanning */
2826 wifi_update_scanner_type(wifi, WIFI_SCANNING_PASSIVE);
2828 return throw_wifi_scan(device, scan_callback_hidden);
2831 static gboolean p2p_find_stop(gpointer data)
2833 struct connman_device *device = data;
2834 struct wifi_data *wifi = connman_device_get_data(device);
2839 wifi->p2p_find_timeout = 0;
2841 g_supplicant_interface_p2p_stop_find(wifi->interface);
2844 connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_P2P, false);
2846 connman_device_unref(device);
2847 start_autoscan(device);
2852 static void p2p_find_callback(int result, GSupplicantInterface *interface,
2855 struct connman_device *device = user_data;
2856 struct wifi_data *wifi = connman_device_get_data(device);
2858 DBG("result %d wifi %p", result, wifi);
2863 if (wifi->p2p_find_timeout) {
2864 g_source_remove(wifi->p2p_find_timeout);
2865 wifi->p2p_find_timeout = 0;
2871 wifi->p2p_find_timeout = g_timeout_add_seconds(P2P_FIND_TIMEOUT,
2872 p2p_find_stop, device);
2873 if (!wifi->p2p_find_timeout)
2878 p2p_find_stop(device);
2881 static int p2p_find(struct connman_device *device)
2883 struct wifi_data *wifi;
2888 if (!p2p_technology)
2891 wifi = connman_device_get_data(device);
2893 if (g_supplicant_interface_is_p2p_finding(wifi->interface))
2896 reset_autoscan(device);
2897 connman_device_ref(device);
2899 ret = g_supplicant_interface_p2p_find(wifi->interface,
2900 p2p_find_callback, device);
2902 connman_device_unref(device);
2903 start_autoscan(device);
2905 connman_device_set_scanning(device,
2906 CONNMAN_SERVICE_TYPE_P2P, true);
2912 #if defined TIZEN_EXT
2913 static void specific_scan_callback(int result, GSupplicantInterface *interface,
2916 struct connman_device *device = user_data;
2917 struct wifi_data *wifi = connman_device_get_data(device);
2920 DBG("result %d wifi %p", result, wifi);
2922 if (wifi && wifi->scan_params) {
2923 g_supplicant_free_scan_params(wifi->scan_params);
2924 wifi->scan_params = NULL;
2927 scanning = connman_device_get_scanning(device,
2928 CONNMAN_SERVICE_TYPE_WIFI);
2930 connman_device_set_scanning(device,
2931 CONNMAN_SERVICE_TYPE_WIFI, false);
2932 connman_device_unref(device);
2936 static int wifi_specific_scan(enum connman_service_type type,
2937 struct connman_device *device, int scan_type,
2938 GSList *specific_scan_list, void *user_data)
2940 GSList *list = NULL;
2942 struct wifi_data *wifi = connman_device_get_data(device);
2943 GSupplicantScanParams *scan_params = NULL;
2944 struct scan_ssid *scan_ssid = NULL;
2953 if (wifi->p2p_device)
2956 if (type == CONNMAN_SERVICE_TYPE_P2P)
2957 return p2p_find(device);
2959 if (wifi->tethering)
2963 connman_device_get_scanning(device,
2964 CONNMAN_SERVICE_TYPE_WIFI);
2968 DBG("scan_type: %d", scan_type);
2969 if (scan_type == CONNMAN_MULTI_SCAN_SSID) { /* ssid based scan */
2970 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2972 DBG("Failed to allocate memory.");
2976 for (list = specific_scan_list; list; list = list->next) {
2977 ssid = (char *)list->data;
2978 int ssid_len = strlen(ssid);
2980 scan_ssid = g_try_new0(struct scan_ssid, 1);
2982 DBG("Failed to allocate memory.");
2983 g_supplicant_free_scan_params(scan_params);
2987 memcpy(scan_ssid->ssid, ssid, (ssid_len + 1));
2988 /* DBG("scan ssid %s len: %d", scan_ssid->ssid, ssid_len); */
2989 scan_ssid->ssid_len = ssid_len;
2990 scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
2993 scan_params->num_ssids = count;
2995 } else if (scan_type == CONNMAN_MULTI_SCAN_FREQ) { /* frequency based scan */
2997 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2999 DBG("Failed to allocate memory.");
3003 guint num_freqs = g_slist_length(specific_scan_list);
3004 DBG("num_freqs: %d", num_freqs);
3006 scan_params->freqs = g_try_new0(uint16_t, num_freqs);
3007 if (!scan_params->freqs) {
3008 DBG("Failed to allocate memory.");
3009 g_free(scan_params);
3014 for (list = specific_scan_list; list; list = list->next) {
3015 freq = (int)list->data;
3017 scan_params->freqs[count] = freq;
3018 DBG("scan_params->freqs[%d]: %d", count, scan_params->freqs[count]);
3021 scan_params->num_freqs = count;
3023 } else if (scan_type == CONNMAN_MULTI_SCAN_SSID_FREQ) { /* SSID & Frequency mixed scan */
3024 int freq_count, ap_count;
3025 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
3027 DBG("Failed to allocate memory.");
3031 guint size = g_slist_length(specific_scan_list);
3033 scan_params->freqs = g_try_new0(uint16_t, size/2);
3034 if (!scan_params->freqs) {
3035 DBG("Failed to allocate memory.");
3036 g_free(scan_params);
3040 ap_count = freq_count = 0;
3041 for (list = specific_scan_list; list; list = list->next) {
3042 if (((connman_multi_scan_ap_s *)list->data)->flag == true) { /** ssid */
3043 ssid = ((connman_multi_scan_ap_s *)list->data)->str;
3044 int ssid_len = strlen(ssid);
3046 scan_ssid = g_try_new0(struct scan_ssid, 1);
3048 DBG("Failed to allocate memory.");
3049 g_supplicant_free_scan_params(scan_params);
3053 memcpy(scan_ssid->ssid, ssid, (ssid_len + 1));
3054 /* DBG("scan ssid %s len: %d", scan_ssid->ssid, ssid_len); */
3055 scan_ssid->ssid_len = ssid_len;
3056 scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
3060 freq = atoi(((connman_multi_scan_ap_s *)list->data)->str);
3061 scan_params->freqs[freq_count] = freq;
3062 DBG("scan_params->freqs[%d]: %d", freq_count, scan_params->freqs[freq_count]);
3066 scan_params->num_ssids = ap_count;
3067 scan_params->num_freqs = freq_count;
3069 DBG("Invalid scan");
3073 reset_autoscan(device);
3074 connman_device_ref(device);
3076 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
3077 specific_scan_callback, device);
3080 connman_device_set_scanning(device,
3081 CONNMAN_SERVICE_TYPE_WIFI, true);
3083 g_supplicant_free_scan_params(scan_params);
3084 connman_device_unref(device);
3090 static void wifi_mac_policy_callback(int result,
3091 unsigned int policy,
3094 struct connman_device *device = user_data;
3097 connman_device_mac_policy_notify(device, result, policy);
3099 connman_device_unref(device);
3102 int wifi_set_mac_policy(struct connman_device *device, unsigned int policy)
3104 struct wifi_data *wifi = connman_device_get_data(device);
3110 connman_device_ref(device);
3112 ret = g_supplicant_interface_set_mac_policy(wifi->interface,
3113 wifi_mac_policy_callback,
3116 connman_device_unref(device);
3121 static void wifi_preassoc_mac_policy_callback(int result,
3122 unsigned int policy,
3125 struct connman_device *device = user_data;
3128 connman_device_preassoc_mac_policy_notify(device, result, policy);
3130 connman_device_unref(device);
3133 int wifi_set_preassoc_mac_policy(struct connman_device *device, unsigned int policy)
3135 struct wifi_data *wifi = connman_device_get_data(device);
3141 connman_device_ref(device);
3143 ret = g_supplicant_interface_set_preassoc_mac_policy(wifi->interface,
3144 wifi_preassoc_mac_policy_callback,
3147 connman_device_unref(device);
3152 static void wifi_random_mac_lifetime_callback(int result,
3153 unsigned int lifetime,
3156 struct connman_device *device = user_data;
3159 connman_device_random_mac_lifetime_notify(device, result, lifetime);
3161 connman_device_unref(device);
3164 int wifi_set_random_mac_lifetime(struct connman_device *device, unsigned int lifetime)
3166 struct wifi_data *wifi = connman_device_get_data(device);
3172 connman_device_ref(device);
3174 ret = g_supplicant_interface_set_random_mac_lifetime(wifi->interface,
3175 wifi_random_mac_lifetime_callback,
3178 connman_device_unref(device);
3184 #if defined TIZEN_EXT_WIFI_MESH
3185 static void mesh_scan_callback(int result, GSupplicantInterface *interface,
3188 struct connman_device *device = user_data;
3189 struct wifi_data *wifi = connman_device_get_data(device);
3192 DBG("result %d wifi %p", result, wifi);
3194 scanning = connman_device_get_scanning(device,
3195 CONNMAN_SERVICE_TYPE_MESH);
3197 connman_device_set_scanning(device,
3198 CONNMAN_SERVICE_TYPE_MESH, false);
3201 connman_device_unref(device);
3204 static int mesh_scan(struct connman_device *device)
3206 struct wifi_data *wifi;
3207 struct wifi_mesh_info *mesh_info;
3212 wifi = connman_device_get_data(device);
3214 if (!wifi || !wifi->mesh_interface)
3217 mesh_info = wifi->mesh_info;
3218 reset_autoscan(device);
3219 connman_device_ref(device);
3221 ret = g_supplicant_interface_scan(mesh_info->interface, NULL,
3222 mesh_scan_callback, device);
3224 connman_device_unref(device);
3226 connman_device_set_scanning(device,
3227 CONNMAN_SERVICE_TYPE_MESH, true);
3232 static void abort_scan_callback(int result, GSupplicantInterface *interface,
3235 struct connman_device *device = user_data;
3236 struct wifi_data *wifi = connman_device_get_data(device);
3238 DBG("result %d wifi %p", result, wifi);
3240 __connman_technology_notify_abort_scan(CONNMAN_SERVICE_TYPE_MESH, result);
3243 static int mesh_abort_scan(enum connman_service_type type,
3244 struct connman_device *device)
3246 struct wifi_data *wifi = connman_device_get_data(device);
3247 struct wifi_mesh_info *mesh_info;
3251 if (!wifi || !wifi->mesh_interface)
3254 if (type != CONNMAN_SERVICE_TYPE_MESH)
3257 mesh_info = wifi->mesh_info;
3259 scanning = connman_device_get_scanning(device,
3260 CONNMAN_SERVICE_TYPE_MESH);
3264 ret = g_supplicant_interface_abort_scan(mesh_info->interface,
3265 abort_scan_callback, device);
3270 static int mesh_specific_scan(enum connman_service_type type,
3271 struct connman_device *device, const char *ssid,
3272 unsigned int freq, void *user_data)
3274 struct wifi_data *wifi = connman_device_get_data(device);
3275 GSupplicantScanParams *scan_params = NULL;
3276 struct wifi_mesh_info *mesh_info;
3277 struct scan_ssid *scan_ssid;
3281 if (!wifi || !wifi->mesh_interface)
3284 if (type != CONNMAN_SERVICE_TYPE_MESH)
3287 if (wifi->p2p_device)
3290 mesh_info = wifi->mesh_info;
3292 scanning = connman_device_get_scanning(device,
3293 CONNMAN_SERVICE_TYPE_MESH);
3297 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
3301 scan_ssid = g_try_new(struct scan_ssid, 1);
3303 g_free(scan_params);
3307 scan_ssid->ssid_len = strlen(ssid);
3308 memcpy(scan_ssid->ssid, ssid, scan_ssid->ssid_len);
3309 scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
3310 scan_params->num_ssids = 1;
3312 scan_params->freqs = g_try_new(uint16_t, 1);
3313 if (!scan_params->freqs) {
3314 g_slist_free_full(scan_params->ssids, g_free);
3315 g_free(scan_params);
3319 scan_params->freqs[0] = freq;
3320 scan_params->num_freqs = 1;
3322 reset_autoscan(device);
3323 connman_device_ref(device);
3325 ret = g_supplicant_interface_scan(mesh_info->interface, scan_params,
3326 mesh_scan_callback, device);
3329 connman_device_set_scanning(device,
3330 CONNMAN_SERVICE_TYPE_MESH, true);
3332 g_supplicant_free_scan_params(scan_params);
3333 connman_device_unref(device);
3341 * Note that the hidden scan is only used when connecting to this specific
3342 * hidden AP first time. It is not used when system autoconnects to hidden AP.
3344 static int wifi_scan(struct connman_device *device,
3345 struct connman_device_scan_params *params)
3347 struct wifi_data *wifi = connman_device_get_data(device);
3348 GSupplicantScanParams *scan_params = NULL;
3349 struct scan_ssid *scan_ssid;
3350 struct hidden_params *hidden;
3352 int driver_max_ssids = 0;
3359 if (wifi->p2p_device)
3362 if (wifi->tethering)
3365 if (params->type == CONNMAN_SERVICE_TYPE_P2P)
3366 return p2p_find(device);
3368 #if defined TIZEN_EXT_WIFI_MESH
3369 if (params->type == CONNMAN_SERVICE_TYPE_MESH)
3370 return mesh_scan(device);
3373 DBG("device %p wifi %p hidden ssid %s", device, wifi->interface,
3376 scanning = connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI);
3378 if (!params->ssid || params->ssid_len == 0 || params->ssid_len > 32) {
3382 driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
3384 DBG("max ssids %d", driver_max_ssids);
3385 if (driver_max_ssids == 0)
3386 return wifi_scan_simple(device);
3390 if (scanning && wifi->hidden && wifi->postpone_hidden)
3396 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
3401 scan_ssid = g_try_new(struct scan_ssid, 1);
3403 g_free(scan_params);
3407 memcpy(scan_ssid->ssid, params->ssid, params->ssid_len);
3408 scan_ssid->ssid_len = params->ssid_len;
3409 scan_params->ssids = g_slist_prepend(scan_params->ssids,
3411 scan_params->num_ssids = 1;
3413 hidden = g_try_new0(struct hidden_params, 1);
3415 g_supplicant_free_scan_params(scan_params);
3420 hidden_free(wifi->hidden);
3421 wifi->hidden = NULL;
3424 memcpy(hidden->ssid, params->ssid, params->ssid_len);
3425 hidden->ssid_len = params->ssid_len;
3426 hidden->identity = g_strdup(params->identity);
3427 hidden->passphrase = g_strdup(params->passphrase);
3428 hidden->security = g_strdup(params->security);
3429 hidden->user_data = params->user_data;
3430 wifi->hidden = hidden;
3433 /* Let's keep this active scan for later,
3434 * when current scan will be over. */
3435 wifi->postpone_hidden = TRUE;
3436 hidden->scan_params = scan_params;
3440 } else if (wifi->connected) {
3441 g_supplicant_free_scan_params(scan_params);
3442 return wifi_scan_simple(device);
3443 } else if (!params->force_full_scan) {
3444 ret = get_latest_connections(driver_max_ssids, scan_params);
3446 g_supplicant_free_scan_params(scan_params);
3447 return wifi_scan_simple(device);
3451 /* Distinguish between devices performing passive and active scanning */
3452 wifi_update_scanner_type(wifi, WIFI_SCANNING_ACTIVE);
3454 connman_device_ref(device);
3456 reset_autoscan(device);
3457 #if defined TIZEN_EXT
3459 * When doing a full scan, stored hidden networks also need to be scanned
3460 * so that we can autoconnect to them.
3462 if (params->force_full_scan)
3463 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
3464 scan_callback_hidden, device);
3467 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
3468 scan_callback, device);
3470 connman_device_set_scanning(device,
3471 CONNMAN_SERVICE_TYPE_WIFI, true);
3472 #if defined TIZEN_EXT
3474 * To allow the Full Scan after ssid based scan, set the flag here
3475 * It is required because Tizen does not use the ConnMan specific
3476 * backgroung Scan feature.Tizen has added the BG Scan feature in
3477 * net-config. To sync with up ConnMan, we need to issue the Full Scan
3478 * after SSID specific scan.
3480 if (!params->force_full_scan && !do_hidden)
3481 wifi->allow_full_scan = TRUE;
3484 g_supplicant_free_scan_params(scan_params);
3485 connman_device_unref(device);
3488 hidden_free(wifi->hidden);
3489 wifi->hidden = NULL;
3496 static void wifi_stop_scan(enum connman_service_type type,
3497 struct connman_device *device)
3499 struct wifi_data *wifi = connman_device_get_data(device);
3501 DBG("device %p wifi %p", device, wifi);
3506 if (type == CONNMAN_SERVICE_TYPE_P2P) {
3507 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_P2P)) {
3508 g_source_remove(wifi->p2p_find_timeout);
3509 p2p_find_stop(device);
3514 static void wifi_regdom_callback(int result,
3518 struct connman_device *device = user_data;
3520 connman_device_regdom_notify(device, result, alpha2);
3522 connman_device_unref(device);
3525 static int wifi_set_regdom(struct connman_device *device, const char *alpha2)
3527 struct wifi_data *wifi = connman_device_get_data(device);
3533 connman_device_ref(device);
3535 ret = g_supplicant_interface_set_country(wifi->interface,
3536 wifi_regdom_callback,
3539 connman_device_unref(device);
3544 static struct connman_device_driver wifi_ng_driver = {
3546 .type = CONNMAN_DEVICE_TYPE_WIFI,
3547 .priority = CONNMAN_DEVICE_PRIORITY_LOW,
3548 .probe = wifi_probe,
3549 .remove = wifi_remove,
3550 .enable = wifi_enable,
3551 .disable = wifi_disable,
3553 .stop_scan = wifi_stop_scan,
3554 .set_regdom = wifi_set_regdom,
3555 #if defined TIZEN_EXT
3556 .specific_scan = wifi_specific_scan,
3557 .set_mac_policy = wifi_set_mac_policy,
3558 .set_preassoc_mac_policy = wifi_set_preassoc_mac_policy,
3559 .set_random_mac_lifetime = wifi_set_random_mac_lifetime,
3561 #if defined TIZEN_EXT_WIFI_MESH
3562 .abort_scan = mesh_abort_scan,
3563 .mesh_specific_scan = mesh_specific_scan,
3567 static void system_ready(void)
3571 if (connman_device_driver_register(&wifi_ng_driver) < 0)
3572 connman_error("Failed to register WiFi driver");
3575 static void system_killed(void)
3579 connman_device_driver_unregister(&wifi_ng_driver);
3582 static int network_probe(struct connman_network *network)
3584 #if defined TIZEN_EXT
3585 if (!simplified_log)
3587 DBG("network %p", network);
3592 static void network_remove(struct connman_network *network)
3594 struct connman_device *device = connman_network_get_device(network);
3595 struct wifi_data *wifi;
3597 DBG("network %p", network);
3599 wifi = connman_device_get_data(device);
3603 if (wifi->network != network)
3606 wifi->network = NULL;
3608 #if defined TIZEN_EXT
3609 wifi->disconnecting = false;
3611 if (wifi->pending_network == network)
3612 wifi->pending_network = NULL;
3614 if (wifi->scan_pending_network == network)
3615 wifi->scan_pending_network = NULL;
3619 static void connect_callback(int result, GSupplicantInterface *interface,
3622 #if defined TIZEN_EXT
3624 struct wifi_data *wifi;
3626 struct connman_network *network = user_data;
3628 DBG("network %p result %d", network, result);
3630 #if defined TIZEN_EXT
3631 const char *ifname = g_supplicant_interface_get_ifname(interface);
3632 set_connman_bssid(RESET_BSSID, NULL, ifname);
3634 for (list = iface_list; list; list = list->next) {
3637 if (wifi && wifi->network == network)
3641 /* wifi_data may be invalid because wifi is already disabled */
3645 if (connman_network_get_bool(network, "WiFi.Roaming")) {
3647 connman_network_set_bool(network, "WiFi.Roaming", false);
3648 connman_network_set_string(network,
3649 "WiFi.RoamingCurBSSID", NULL);
3651 char bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
3652 char *bssid_str = bssid_buff;
3653 unsigned char *bssid;
3654 const char *cur_bssid;
3656 bssid = g_supplicant_interface_get_add_network_bssid(interface);
3658 connman_network_set_bool(network, "WiFi.Roaming", false);
3659 connman_network_set_string(network,
3660 "WiFi.RoamingCurBSSID", NULL);
3664 MACSTR, MAC2STR(bssid));
3666 connman_network_set_string(network,
3667 "WiFi.RoamingDstBSSID", bssid_str);
3669 cur_bssid = connman_network_get_string(network,
3670 "WiFi.RoamingCurBSSID");
3672 __connman_technology_notify_roaming_state(ifname,
3673 "started", cur_bssid, bssid_str);
3678 if (result == -ENOKEY) {
3679 connman_network_set_error(network,
3680 CONNMAN_NETWORK_ERROR_INVALID_KEY);
3681 } else if (result < 0) {
3682 connman_network_set_error(network,
3683 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
3686 connman_network_unref(network);
3689 static GSupplicantSecurity network_security(const char *security)
3691 if (g_str_equal(security, "none"))
3692 return G_SUPPLICANT_SECURITY_NONE;
3693 else if (g_str_equal(security, "wep"))
3694 return G_SUPPLICANT_SECURITY_WEP;
3695 else if (g_str_equal(security, "psk"))
3696 return G_SUPPLICANT_SECURITY_PSK;
3697 else if (g_str_equal(security, "wpa"))
3698 return G_SUPPLICANT_SECURITY_PSK;
3699 else if (g_str_equal(security, "rsn"))
3700 return G_SUPPLICANT_SECURITY_PSK;
3701 else if (g_str_equal(security, "ieee8021x"))
3702 return G_SUPPLICANT_SECURITY_IEEE8021X;
3703 #if defined TIZEN_EXT
3704 else if (g_str_equal(security, "ft_psk") == TRUE)
3705 return G_SUPPLICANT_SECURITY_FT_PSK;
3706 else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
3707 return G_SUPPLICANT_SECURITY_FT_IEEE8021X;
3708 else if (g_str_equal(security, "sae"))
3709 return G_SUPPLICANT_SECURITY_SAE;
3710 else if (g_str_equal(security, "owe"))
3711 return G_SUPPLICANT_SECURITY_OWE;
3712 else if (g_str_equal(security, "dpp"))
3713 return G_SUPPLICANT_SECURITY_DPP;
3716 return G_SUPPLICANT_SECURITY_UNKNOWN;
3719 #if defined TIZEN_EXT
3720 static GSupplicantEapKeymgmt network_eap_keymgmt(const char *security)
3722 if (security == NULL)
3723 return G_SUPPLICANT_EAP_KEYMGMT_NONE;
3725 if (g_str_equal(security, "FT") == TRUE)
3726 return G_SUPPLICANT_EAP_KEYMGMT_FT;
3727 else if (g_str_equal(security, "CCKM") == TRUE)
3728 return G_SUPPLICANT_EAP_KEYMGMT_CCKM;
3730 return G_SUPPLICANT_EAP_KEYMGMT_NONE;
3734 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
3736 const char *security;
3737 #if defined TIZEN_EXT
3738 const void *ssid_data;
3741 memset(ssid, 0, sizeof(*ssid));
3742 ssid->mode = G_SUPPLICANT_MODE_INFRA;
3743 #if defined TIZEN_EXT
3744 ssid_data = connman_network_get_blob(network, "WiFi.SSID",
3746 ssid->ssid = g_try_malloc0(ssid->ssid_len);
3751 memcpy(ssid->ssid, ssid_data, ssid->ssid_len);
3753 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
3756 ssid->scan_ssid = 1;
3757 security = connman_network_get_string(network, "WiFi.Security");
3758 ssid->security = network_security(security);
3759 #if defined TIZEN_EXT
3760 ssid->ieee80211w = 1;
3762 ssid->passphrase = connman_network_get_string(network,
3765 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
3768 * If our private key password is unset,
3769 * we use the supplied passphrase. That is needed
3770 * for PEAP where 2 passphrases (identity and client
3771 * cert may have to be provided.
3773 if (!connman_network_get_string(network, "WiFi.PrivateKeyPassphrase"))
3774 connman_network_set_string(network,
3775 "WiFi.PrivateKeyPassphrase",
3777 /* We must have an identity for both PEAP and TLS */
3778 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
3780 /* Use agent provided identity as a fallback */
3781 if (!ssid->identity || strlen(ssid->identity) == 0)
3782 ssid->identity = connman_network_get_string(network,
3783 "WiFi.AgentIdentity");
3785 ssid->anonymous_identity = connman_network_get_string(network,
3786 "WiFi.AnonymousIdentity");
3787 ssid->ca_cert_path = connman_network_get_string(network,
3789 ssid->subject_match = connman_network_get_string(network,
3790 "WiFi.SubjectMatch");
3791 ssid->altsubject_match = connman_network_get_string(network,
3792 "WiFi.AltSubjectMatch");
3793 ssid->domain_suffix_match = connman_network_get_string(network,
3794 "WiFi.DomainSuffixMatch");
3795 ssid->domain_match = connman_network_get_string(network,
3796 "WiFi.DomainMatch");
3797 ssid->client_cert_path = connman_network_get_string(network,
3798 "WiFi.ClientCertFile");
3799 ssid->private_key_path = connman_network_get_string(network,
3800 "WiFi.PrivateKeyFile");
3801 ssid->private_key_passphrase = connman_network_get_string(network,
3802 "WiFi.PrivateKeyPassphrase");
3803 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
3805 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
3806 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
3807 #if defined TIZEN_EXT
3808 ssid->connector = connman_network_get_string(network,
3810 ssid->c_sign_key = connman_network_get_string(network,
3812 ssid->net_access_key = connman_network_get_string(network,
3813 "WiFi.NetAccessKey");
3816 #if defined TIZEN_EXT
3817 const char *ifname = connman_device_get_string(
3818 connman_network_get_device(network), "Interface");
3819 if (set_connman_bssid(CHECK_BSSID, NULL, ifname) == 6) {
3820 ssid->bssid_for_connect_len = 6;
3821 set_connman_bssid(GET_BSSID, (char *)ssid->bssid_for_connect, ifname);
3822 DBG("BSSID : %02x:%02x:%02x:%02x:%02x:%02x",
3823 ssid->bssid_for_connect[0], ssid->bssid_for_connect[1],
3824 ssid->bssid_for_connect[2], ssid->bssid_for_connect[3],
3825 ssid->bssid_for_connect[4], ssid->bssid_for_connect[5]);
3827 ssid->freq = connman_network_get_frequency(network);
3830 GSList *bssid_list = (GSList *)connman_network_get_bssid_list(network);
3831 if (bssid_list && g_slist_length(bssid_list) > 1) {
3833 /* If there are more than one bssid,
3834 * the user-specified bssid is tried only once at the beginning.
3835 * After that, the bssids in the list are tried in order.
3837 if (set_connman_bssid(CHECK_BSSID, NULL, ifname) == 6) {
3838 set_connman_bssid(RESET_BSSID, NULL, ifname);
3843 char buff[MAC_ADDRESS_LENGTH];
3844 for (list = bssid_list; list; list = list->next) {
3845 struct connman_bssids * bssids = (struct connman_bssids *)list->data;
3847 g_snprintf(buff, MAC_ADDRESS_LENGTH, "%02x:%02x:%02x:%02x:%02x:%02x",
3848 bssids->bssid[0], bssids->bssid[1], bssids->bssid[2],
3849 bssids->bssid[3], bssids->bssid[4], bssids->bssid[5]);
3850 buff[MAC_ADDRESS_LENGTH - 1] = '\0';
3852 gchar *curr_bssid = g_strdup((const gchar *)buff);
3854 if (g_hash_table_contains(failed_bssids, curr_bssid)) {
3855 DBG("bssid match, try next bssid");
3859 g_hash_table_add(failed_bssids, curr_bssid);
3861 memcpy(buff_bssid, bssids->bssid, WIFI_BSSID_LEN_MAX);
3862 ssid->bssid = buff_bssid;
3863 ssid->freq = (unsigned int)bssids->frequency;
3869 ssid->bssid = connman_network_get_bssid(network);
3870 g_hash_table_remove_all(failed_bssids);
3873 ssid->bssid = connman_network_get_bssid(network);
3876 ssid->eap_keymgmt = network_eap_keymgmt(
3877 connman_network_get_string(network, "WiFi.KeymgmtType"));
3878 ssid->phase1 = connman_network_get_string(network, "WiFi.Phase1");
3880 if(g_strcmp0(ssid->eap, "fast") == 0)
3881 ssid->pac_file = g_strdup(WIFI_EAP_FAST_PAC_FILE);
3883 ssid->keymgmt = connman_network_get_keymgmt(network);
3886 if (connman_setting_get_bool("BackgroundScanning"))
3887 ssid->bgscan = BGSCAN_DEFAULT;
3890 static int network_connect(struct connman_network *network)
3892 struct connman_device *device = connman_network_get_device(network);
3893 struct wifi_data *wifi;
3894 GSupplicantInterface *interface;
3895 GSupplicantSSID *ssid;
3897 DBG("network %p", network);
3902 wifi = connman_device_get_data(device);
3906 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
3910 interface = wifi->interface;
3912 ssid_init(ssid, network);
3914 if (wifi->disconnecting) {
3915 wifi->pending_network = network;
3916 #if defined TIZEN_EXT
3921 wifi->network = connman_network_ref(network);
3923 #if defined TIZEN_EXT
3924 wifi->scan_pending_network = NULL;
3927 return g_supplicant_interface_connect(interface, ssid,
3928 connect_callback, network);
3931 return -EINPROGRESS;
3934 static void disconnect_callback(int result, GSupplicantInterface *interface,
3937 #if defined TIZEN_EXT
3939 struct wifi_data *wifi;
3940 struct connman_network *network = user_data;
3942 DBG("network %p result %d", network, result);
3944 for (list = iface_list; list; list = list->next) {
3947 if (wifi->network == NULL && wifi->disconnecting == true)
3948 wifi->disconnecting = false;
3950 if (wifi->network == network)
3954 /* wifi_data may be invalid because wifi is already disabled */
3959 struct wifi_data *wifi = user_data;
3962 DBG("result %d supplicant interface %p wifi %p",
3963 result, interface, wifi);
3965 if (result == -ECONNABORTED) {
3966 DBG("wifi interface no longer available");
3970 #if defined TIZEN_EXT
3971 if (wifi->network &&
3972 (wifi->network != wifi->pending_network ||
3973 connman_network_get_bool(wifi->network, "WiFi.Roaming")))
3975 if (wifi->network && wifi->network != wifi->pending_network)
3977 connman_network_set_connected(wifi->network, false);
3978 wifi->network = NULL;
3980 wifi->disconnecting = false;
3981 wifi->connected = false;
3983 if (wifi->pending_network) {
3984 network_connect(wifi->pending_network);
3985 wifi->pending_network = NULL;
3988 start_autoscan(wifi->device);
3991 static int network_disconnect(struct connman_network *network)
3993 struct connman_device *device = connman_network_get_device(network);
3994 struct wifi_data *wifi;
3996 #if defined TIZEN_EXT
3997 struct connman_service *service;
4000 DBG("network %p", network);
4002 wifi = connman_device_get_data(device);
4003 if (!wifi || !wifi->interface)
4006 #if defined TIZEN_EXT
4007 if (connman_network_get_associating(network) == true) {
4008 connman_network_clear_associating(network);
4009 connman_network_set_bool(network, "WiFi.UseWPS", false);
4011 service = connman_service_lookup_from_network(network);
4013 if (service != NULL &&
4014 (__connman_service_is_connected_state(service,
4015 CONNMAN_IPCONFIG_TYPE_IPV4) == false &&
4016 __connman_service_is_connected_state(service,
4017 CONNMAN_IPCONFIG_TYPE_IPV6) == false) &&
4018 (connman_service_get_favorite(service) == false))
4019 __connman_service_set_passphrase(service, NULL);
4022 if (wifi->pending_network == network)
4023 wifi->pending_network = NULL;
4025 if (wifi->scan_pending_network == network)
4026 wifi->scan_pending_network = NULL;
4029 connman_network_set_associating(network, false);
4031 if (wifi->disconnecting)
4034 wifi->disconnecting = true;
4036 #if defined TIZEN_EXT
4037 err = g_supplicant_interface_disconnect(wifi->interface,
4038 disconnect_callback, network);
4040 err = g_supplicant_interface_disconnect(wifi->interface,
4041 disconnect_callback, wifi);
4045 wifi->disconnecting = false;
4050 #if defined TIZEN_EXT
4051 static void set_connection_mode(struct connman_network *network,
4054 ieee80211_modes_e phy_mode;
4055 connection_mode_e conn_mode;
4057 phy_mode = connman_network_get_phy_mode(network);
4059 case IEEE80211_MODE_B:
4060 if (linkspeed > 0 && linkspeed <= 11)
4061 conn_mode = CONNECTION_MODE_IEEE80211B;
4063 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
4066 case IEEE80211_MODE_BG:
4067 if (linkspeed > 0 && linkspeed <= 11)
4068 conn_mode = CONNECTION_MODE_IEEE80211B;
4069 else if (linkspeed > 11 && linkspeed <= 54)
4070 conn_mode = CONNECTION_MODE_IEEE80211G;
4072 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
4075 case IEEE80211_MODE_BGN:
4076 if (linkspeed > 0 && linkspeed <= 11)
4077 conn_mode = CONNECTION_MODE_IEEE80211B;
4078 else if (linkspeed > 11 && linkspeed <= 54)
4079 conn_mode = CONNECTION_MODE_IEEE80211G;
4080 else if (linkspeed > 54 && linkspeed <= 450)
4081 conn_mode = CONNECTION_MODE_IEEE80211N;
4083 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
4086 case IEEE80211_MODE_A:
4087 if (linkspeed > 0 && linkspeed <= 54)
4088 conn_mode = CONNECTION_MODE_IEEE80211A;
4090 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
4093 case IEEE80211_MODE_AN:
4094 if (linkspeed > 0 && linkspeed <= 54)
4095 conn_mode = CONNECTION_MODE_IEEE80211A;
4096 else if (linkspeed > 54 && linkspeed <= 450)
4097 conn_mode = CONNECTION_MODE_IEEE80211N;
4099 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
4102 case IEEE80211_MODE_ANAC:
4103 if (linkspeed > 0 && linkspeed <= 54)
4104 conn_mode = CONNECTION_MODE_IEEE80211A;
4105 else if (linkspeed > 54 && linkspeed <= 450)
4106 conn_mode = CONNECTION_MODE_IEEE80211N;
4107 else if (linkspeed > 450 && linkspeed <= 1300)
4108 conn_mode = CONNECTION_MODE_IEEE80211AC;
4110 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
4114 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
4118 DBG("connection mode(%d)", conn_mode);
4119 connman_network_set_connection_mode(network, conn_mode);
4122 static void signalpoll_callback(int result, int maxspeed, int strength,
4123 int snr, void *user_data)
4125 char bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
4126 char *bssid_str = bssid_buff;
4127 unsigned char *bssid;
4128 struct timespec curr_time = {0};
4129 __time_t roam_scan_time;
4130 const char *interface = NULL;
4131 struct connman_device *device;
4132 struct connman_network *network = user_data;
4133 uint16_t freq = connman_network_get_frequency(network);
4136 DBG("Failed to get maxspeed from signalpoll !");
4137 connman_network_unref(network);
4145 DBG("freq = %u, maxspeed = %d, strength = %d, snr = %d", freq, maxspeed, strength, snr);
4147 connman_network_set_strength(network, (uint8_t)strength);
4148 connman_network_set_snr(network, snr);
4149 connman_network_set_maxspeed(network, maxspeed);
4150 set_connection_mode(network, maxspeed);
4152 clock_gettime(CLOCK_MONOTONIC, &curr_time);
4153 roam_scan_time = connman_network_get_roam_scan_time(network);
4154 if (curr_time.tv_sec <= roam_scan_time + ROAM_SCAN_INTERVAL)
4157 if (need_bss_transition(freq, snr, strength)) {
4158 device = connman_network_get_device(network);
4160 interface = connman_device_get_string(device, "Interface");
4162 bssid = connman_network_get_bssid(network);
4163 snprintf(bssid_str, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(bssid));
4164 __connman_technology_notify_roaming_state(interface, "required", bssid_str, NULL);
4166 if (connman_setting_get_bool("WifiRoamingScan") == false)
4169 throw_wifi_scan(device, scan_callback);
4170 connman_network_set_roam_scan_time(network, curr_time.tv_sec);
4174 connman_network_unref(network);
4177 static int network_signalpoll(struct wifi_data *wifi)
4179 GSupplicantInterface *interface;
4180 struct connman_network *network;
4182 if (!wifi || !wifi->network)
4185 wifi->network = connman_network_ref(wifi->network);
4187 interface = wifi->interface;
4188 network = wifi->network;
4190 DBG("network %p", network);
4192 return g_supplicant_interface_signalpoll(interface, signalpoll_callback, network);
4195 static gboolean autosignalpoll_timeout(gpointer data)
4197 struct wifi_data *wifi = data;
4199 if (!wifi || !wifi->automaxspeed_timeout) {
4200 DBG("automaxspeed_timeout is found to be zero. i.e. currently in disconnected state. !!");
4204 int ret = network_signalpoll(wifi);
4206 DBG("Fail to get max speed !!");
4207 wifi->automaxspeed_timeout = 0;
4210 connman_network_unref(wifi->network);
4219 static struct connman_network_driver network_driver = {
4221 .type = CONNMAN_NETWORK_TYPE_WIFI,
4222 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
4223 .probe = network_probe,
4224 .remove = network_remove,
4225 .connect = network_connect,
4226 .disconnect = network_disconnect,
4229 static void interface_added(GSupplicantInterface *interface)
4231 const char *ifname = g_supplicant_interface_get_ifname(interface);
4232 const char *driver = g_supplicant_interface_get_driver(interface);
4233 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4235 * Note: If supplicant interface's driver is wired then skip it,
4236 * because it meanti only for ethernet not Wi-Fi.
4238 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4240 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4242 #if defined TIZEN_EXT
4243 bool is_5_0_ghz_supported = g_supplicant_interface_get_is_5_0_ghz_supported(interface);
4246 struct wifi_data *wifi;
4248 wifi = g_supplicant_interface_get_data(interface);
4250 wifi = get_pending_wifi_data(ifname);
4254 wifi->interface = interface;
4255 g_supplicant_interface_set_data(interface, wifi);
4256 p2p_iface_list = g_list_append(p2p_iface_list, wifi);
4257 wifi->p2p_device = true;
4260 DBG("ifname %s driver %s wifi %p tethering %d",
4261 ifname, driver, wifi, wifi->tethering);
4263 if (!wifi->device) {
4264 connman_error("WiFi device not set");
4268 connman_device_set_powered(wifi->device, true);
4269 #if defined TIZEN_EXT
4270 connman_device_set_wifi_5ghz_supported(wifi->device, is_5_0_ghz_supported);
4271 /* Max number of SSIDs supported by wlan chipset that can be scanned */
4272 int max_scan_ssids = g_supplicant_interface_get_max_scan_ssids(interface);
4273 connman_device_set_max_scan_ssids(wifi->device, max_scan_ssids);
4277 static bool is_idle(struct wifi_data *wifi)
4279 DBG("state %d", wifi->state);
4281 switch (wifi->state) {
4282 case G_SUPPLICANT_STATE_UNKNOWN:
4283 case G_SUPPLICANT_STATE_DISABLED:
4284 case G_SUPPLICANT_STATE_DISCONNECTED:
4285 case G_SUPPLICANT_STATE_INACTIVE:
4286 case G_SUPPLICANT_STATE_SCANNING:
4289 case G_SUPPLICANT_STATE_AUTHENTICATING:
4290 case G_SUPPLICANT_STATE_ASSOCIATING:
4291 case G_SUPPLICANT_STATE_ASSOCIATED:
4292 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4293 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4294 case G_SUPPLICANT_STATE_COMPLETED:
4301 static bool is_idle_wps(GSupplicantInterface *interface,
4302 struct wifi_data *wifi)
4304 /* First, let's check if WPS processing did not went wrong */
4305 if (g_supplicant_interface_get_wps_state(interface) ==
4306 G_SUPPLICANT_WPS_STATE_FAIL)
4309 /* Unlike normal connection, being associated while processing wps
4310 * actually means that we are idling. */
4311 switch (wifi->state) {
4312 case G_SUPPLICANT_STATE_UNKNOWN:
4313 case G_SUPPLICANT_STATE_DISABLED:
4314 case G_SUPPLICANT_STATE_DISCONNECTED:
4315 case G_SUPPLICANT_STATE_INACTIVE:
4316 case G_SUPPLICANT_STATE_SCANNING:
4317 case G_SUPPLICANT_STATE_ASSOCIATED:
4319 case G_SUPPLICANT_STATE_AUTHENTICATING:
4320 case G_SUPPLICANT_STATE_ASSOCIATING:
4321 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4322 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4323 case G_SUPPLICANT_STATE_COMPLETED:
4330 static bool handle_wps_completion(GSupplicantInterface *interface,
4331 struct connman_network *network,
4332 struct connman_device *device,
4333 struct wifi_data *wifi)
4337 wps = connman_network_get_bool(network, "WiFi.UseWPS");
4339 const unsigned char *ssid, *wps_ssid;
4340 unsigned int ssid_len, wps_ssid_len;
4341 const char *wps_key;
4343 /* Checking if we got associated with requested
4345 ssid = connman_network_get_blob(network, "WiFi.SSID",
4348 wps_ssid = g_supplicant_interface_get_wps_ssid(
4349 interface, &wps_ssid_len);
4351 if (!wps_ssid || wps_ssid_len != ssid_len ||
4352 memcmp(ssid, wps_ssid, ssid_len) != 0) {
4353 connman_network_set_associating(network, false);
4354 #if defined TIZEN_EXT
4355 g_supplicant_interface_disconnect(wifi->interface,
4356 disconnect_callback, wifi->network);
4358 connman_network_set_bool(network, "WiFi.UseWPS", false);
4359 connman_network_set_string(network, "WiFi.PinWPS", NULL);
4361 g_supplicant_interface_disconnect(wifi->interface,
4362 disconnect_callback, wifi);
4367 wps_key = g_supplicant_interface_get_wps_key(interface);
4368 #if defined TIZEN_EXT
4369 /* Check the passphrase and encrypt it
4372 gchar *passphrase = g_strdup(wps_key);
4374 connman_network_set_string(network, "WiFi.PinWPS", NULL);
4376 if (check_passphrase_ext(network, passphrase) < 0) {
4377 DBG("[WPS] Invalid passphrase");
4382 ret = send_encryption_request(passphrase, network);
4387 DBG("[WPS] Encryption request succeeded");
4389 DBG("[WPS] Encryption request failed %d", ret);
4392 connman_network_set_string(network, "WiFi.Passphrase",
4395 connman_network_set_string(network, "WiFi.PinWPS", NULL);
4402 static bool handle_assoc_status_code(GSupplicantInterface *interface,
4403 struct wifi_data *wifi)
4405 if (wifi->state == G_SUPPLICANT_STATE_ASSOCIATING &&
4406 #if defined TIZEN_EXT
4407 wifi->assoc_code > 0 &&
4409 wifi->assoc_code == ASSOC_STATUS_NO_CLIENT &&
4411 wifi->load_shaping_retries < LOAD_SHAPING_MAX_RETRIES) {
4412 wifi->load_shaping_retries ++;
4415 wifi->load_shaping_retries = 0;
4419 static bool handle_4way_handshake_failure(GSupplicantInterface *interface,
4420 struct connman_network *network,
4421 struct wifi_data *wifi)
4423 #if defined TIZEN_EXT
4424 const char *security;
4425 struct connman_service *service;
4427 if (wifi->connected)
4430 security = connman_network_get_string(network, "WiFi.Security");
4432 if (security && g_str_equal(security, "ieee8021x") == true &&
4433 wifi->state == G_SUPPLICANT_STATE_ASSOCIATED) {
4435 connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
4440 if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
4443 struct connman_service *service;
4445 if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
4448 if (wifi->connected)
4452 service = connman_service_lookup_from_network(network);
4458 if (connman_service_get_favorite(service)) {
4459 if (wifi->retries < FAVORITE_MAXIMUM_RETRIES)
4464 connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
4469 #if defined TIZEN_EXT
4470 static bool handle_wifi_assoc_retry(struct connman_network *network,
4471 struct wifi_data *wifi)
4473 const char *security;
4475 if (!wifi->network || wifi->connected || wifi->disconnecting ||
4476 connman_network_get_connecting(network) != true) {
4477 wifi->assoc_retry_count = 0;
4481 if (wifi->state != G_SUPPLICANT_STATE_ASSOCIATING &&
4482 wifi->state != G_SUPPLICANT_STATE_ASSOCIATED) {
4483 wifi->assoc_retry_count = 0;
4487 security = connman_network_get_string(network, "WiFi.Security");
4488 if (security && g_str_equal(security, "ieee8021x") == true &&
4489 wifi->state == G_SUPPLICANT_STATE_ASSOCIATED) {
4490 wifi->assoc_retry_count = 0;
4494 if (++wifi->assoc_retry_count >= TIZEN_ASSOC_RETRY_COUNT) {
4495 wifi->assoc_retry_count = 0;
4497 /* Honestly it's not an invalid-key error,
4498 * however QA team recommends that the invalid-key error
4499 * might be better to display for user experience.
4501 connman_network_set_error(network, CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
4510 static void interface_state(GSupplicantInterface *interface)
4512 struct connman_network *network;
4513 struct connman_device *device;
4514 struct wifi_data *wifi;
4515 GSupplicantState state = g_supplicant_interface_get_state(interface);
4516 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4518 * Note: If supplicant interface's driver is wired then skip it,
4519 * because it meanti only for ethernet not Wi-Fi.
4521 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4523 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4528 wifi = g_supplicant_interface_get_data(interface);
4530 DBG("wifi %p interface state %d", wifi, state);
4535 device = wifi->device;
4539 if (state == G_SUPPLICANT_STATE_COMPLETED) {
4540 if (wifi->tethering_param) {
4541 g_free(wifi->tethering_param->ssid);
4542 g_free(wifi->tethering_param);
4543 wifi->tethering_param = NULL;
4546 if (wifi->tethering)
4547 stop_autoscan(device);
4550 if (g_supplicant_interface_get_ready(interface) &&
4551 !wifi->interface_ready) {
4552 wifi->interface_ready = true;
4553 finalize_interface_creation(wifi);
4556 network = wifi->network;
4561 case G_SUPPLICANT_STATE_SCANNING:
4562 #if defined TIZEN_EXT
4563 if (wifi->automaxspeed_timeout != 0) {
4564 g_source_remove(wifi->automaxspeed_timeout);
4565 wifi->automaxspeed_timeout = 0;
4566 DBG("Remove signalpoll timer!!");
4569 if (wifi->connected)
4570 connman_network_set_connected(network, false);
4574 case G_SUPPLICANT_STATE_AUTHENTICATING:
4575 case G_SUPPLICANT_STATE_ASSOCIATING:
4576 #if defined TIZEN_EXT
4577 reset_autoscan(device);
4579 stop_autoscan(device);
4582 if (!wifi->connected)
4583 connman_network_set_associating(network, true);
4587 case G_SUPPLICANT_STATE_COMPLETED:
4588 #if defined TIZEN_EXT
4589 /* though it should be already reset: */
4590 reset_autoscan(device);
4592 wifi->assoc_retry_count = 0;
4594 wifi->scan_pending_network = NULL;
4596 /* should be cleared scanning flag */
4597 bool scanning = connman_device_get_scanning(device,
4598 CONNMAN_SERVICE_TYPE_WIFI);
4600 connman_device_set_scanning(device,
4601 CONNMAN_SERVICE_TYPE_WIFI, false);
4602 connman_device_unref(device);
4605 if (!wifi->automaxspeed_timeout) {
4606 DBG("Going to start signalpoll timer!!");
4607 int ret = network_signalpoll(wifi);
4609 DBG("Fail to get max speed !!");
4611 wifi->automaxspeed_timeout = g_timeout_add_seconds(10, autosignalpoll_timeout, wifi);
4614 g_hash_table_remove_all(failed_bssids);
4616 /* though it should be already stopped: */
4617 stop_autoscan(device);
4620 if (!handle_wps_completion(interface, network, device, wifi))
4623 connman_network_set_connected(network, true);
4625 wifi->disconnect_code = 0;
4626 wifi->assoc_code = 0;
4627 wifi->load_shaping_retries = 0;
4630 case G_SUPPLICANT_STATE_DISCONNECTED:
4631 #if defined TIZEN_EXT
4632 connman_network_set_strength(network, 0);
4633 connman_network_set_maxspeed(network, 0);
4635 if (wifi->automaxspeed_timeout != 0) {
4636 g_source_remove(wifi->automaxspeed_timeout);
4637 wifi->automaxspeed_timeout = 0;
4638 DBG("Remove signalpoll timer!!");
4642 * If we're in one of the idle modes, we have
4643 * not started association yet and thus setting
4644 * those ones to FALSE could cancel an association
4647 wps = connman_network_get_bool(network, "WiFi.UseWPS");
4649 if (is_idle_wps(interface, wifi))
4655 #if defined TIZEN_EXT
4656 if (handle_assoc_status_code(interface, wifi)) {
4657 const char *group = connman_network_get_group(network);
4658 GSupplicantNetwork *supplicant_network;
4659 GSList *bssid_list = NULL;
4660 guint bssid_length = 0;
4663 supplicant_network = g_supplicant_interface_get_network(interface, group);
4665 connman_network_set_assoc_reject_table(network,
4666 g_supplicant_network_get_assoc_reject_table(supplicant_network));
4668 g_supplicant_network_update_assoc_reject(interface, supplicant_network);
4671 bssid_list = (GSList *)connman_network_get_bssid_list(network);
4673 bssid_length = g_slist_length(bssid_list);
4675 if (bssid_length > 1 && bssid_length > g_hash_table_size(failed_bssids)) {
4676 network_connect(network);
4680 wifi->load_shaping_retries = 0;
4683 g_hash_table_remove_all(failed_bssids);
4685 if (handle_assoc_status_code(interface, wifi))
4689 /* If previous state was 4way-handshake, then
4690 * it's either: psk was incorrect and thus we retry
4691 * or if we reach the maximum retries we declare the
4693 if (handle_4way_handshake_failure(interface,
4697 /* See table 8-36 Reason codes in IEEE Std 802.11 */
4698 switch (wifi->disconnect_code) {
4699 case 1: /* Unspecified reason */
4700 /* Let's assume it's because we got blocked */
4702 case 6: /* Class 2 frame received from nonauthenticated STA */
4703 connman_network_set_error(network,
4704 CONNMAN_NETWORK_ERROR_BLOCKED);
4711 #if defined TIZEN_EXT
4712 /* Some of Wi-Fi networks are not comply Wi-Fi specification.
4713 * Retry association until its retry count is expired */
4714 if (handle_wifi_assoc_retry(network, wifi) == true) {
4715 throw_wifi_scan(wifi->device, scan_callback);
4716 wifi->scan_pending_network = wifi->network;
4720 if(wifi->disconnect_code > 0){
4721 DBG("Set disconnect reason code(%d)", wifi->disconnect_code);
4722 connman_network_set_disconnect_reason(network, wifi->disconnect_code);
4726 if (network != wifi->pending_network) {
4727 connman_network_set_connected(network, false);
4728 connman_network_set_associating(network, false);
4730 wifi->disconnecting = false;
4732 start_autoscan(device);
4736 case G_SUPPLICANT_STATE_INACTIVE:
4737 #if defined TIZEN_EXT
4738 if (handle_wps_completion(interface, network, device, wifi) == false)
4741 connman_network_set_associating(network, false);
4742 start_autoscan(device);
4746 case G_SUPPLICANT_STATE_UNKNOWN:
4747 case G_SUPPLICANT_STATE_DISABLED:
4748 case G_SUPPLICANT_STATE_ASSOCIATED:
4749 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4750 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4754 old_connected = wifi->connected;
4755 wifi->state = state;
4757 /* Saving wpa_s state policy:
4758 * If connected and if the state changes are roaming related:
4759 * --> We stay connected
4761 * --> We are connected
4763 * --> We are not connected
4766 case G_SUPPLICANT_STATE_AUTHENTICATING:
4767 case G_SUPPLICANT_STATE_ASSOCIATING:
4768 case G_SUPPLICANT_STATE_ASSOCIATED:
4769 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4770 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4771 if (wifi->connected)
4772 connman_warn("Probably roaming right now!"
4773 " Staying connected...");
4775 case G_SUPPLICANT_STATE_SCANNING:
4776 wifi->connected = false;
4779 start_autoscan(device);
4781 case G_SUPPLICANT_STATE_COMPLETED:
4782 wifi->connected = true;
4785 wifi->connected = false;
4792 static void interface_removed(GSupplicantInterface *interface)
4794 const char *ifname = g_supplicant_interface_get_ifname(interface);
4795 struct wifi_data *wifi;
4796 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4798 * Note: If supplicant interface's driver is wired then skip it,
4799 * because it meanti only for ethernet not Wi-Fi.
4801 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4803 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4806 DBG("ifname %s", ifname);
4808 wifi = g_supplicant_interface_get_data(interface);
4810 #if defined TIZEN_EXT_WIFI_MESH
4811 if (wifi && wifi->mesh_interface) {
4812 DBG("Notify mesh interface remove");
4813 connman_mesh_notify_interface_remove(true);
4814 struct wifi_mesh_info *mesh_info = wifi->mesh_info;
4815 g_free(mesh_info->parent_ifname);
4816 g_free(mesh_info->ifname);
4817 g_free(mesh_info->identifier);
4819 wifi->mesh_interface = false;
4820 wifi->mesh_info = NULL;
4826 wifi->interface = NULL;
4828 if (wifi && wifi->tethering)
4831 if (!wifi || !wifi->device) {
4832 DBG("wifi interface already removed");
4836 connman_device_set_powered(wifi->device, false);
4838 check_p2p_technology();
4839 #if defined TIZEN_EXT_WIFI_MESH
4840 check_mesh_technology();
4844 static void set_device_type(const char *type, char dev_type[17])
4846 const char *oui = "0050F204";
4847 const char *category = "0001";
4848 const char *sub_category = "0000";
4850 if (!g_strcmp0(type, "handset")) {
4852 sub_category = "0005";
4853 } else if (!g_strcmp0(type, "vm") || !g_strcmp0(type, "container"))
4854 sub_category = "0001";
4855 else if (!g_strcmp0(type, "server"))
4856 sub_category = "0002";
4857 else if (!g_strcmp0(type, "laptop"))
4858 sub_category = "0005";
4859 else if (!g_strcmp0(type, "desktop"))
4860 sub_category = "0006";
4861 else if (!g_strcmp0(type, "tablet"))
4862 sub_category = "0009";
4863 else if (!g_strcmp0(type, "watch"))
4866 snprintf(dev_type, 17, "%s%s%s", category, oui, sub_category);
4869 static void p2p_support(GSupplicantInterface *interface)
4871 char dev_type[17] = {};
4872 const char *hostname;
4873 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4875 * Note: If supplicant interface's driver is wired then skip it,
4876 * because it meanti only for ethernet not Wi-Fi.
4878 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4880 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4888 if (!g_supplicant_interface_has_p2p(interface))
4891 if (connman_technology_driver_register(&p2p_tech_driver) < 0) {
4892 DBG("Could not register P2P technology driver");
4896 hostname = connman_utsname_get_hostname();
4898 hostname = "ConnMan";
4900 set_device_type(connman_machine_get_type(), dev_type);
4901 g_supplicant_interface_set_p2p_device_config(interface,
4902 hostname, dev_type);
4903 connman_peer_driver_register(&peer_driver);
4906 static void scan_started(GSupplicantInterface *interface)
4908 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4910 * Note: If supplicant interface's driver is wired then skip it,
4911 * because it meanti only for ethernet not Wi-Fi.
4913 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4915 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4920 static void scan_finished(GSupplicantInterface *interface)
4922 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4924 * Note: If supplicant interface's driver is wired then skip it,
4925 * because it meanti only for ethernet not Wi-Fi.
4927 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4929 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4931 #if defined TIZEN_EXT
4932 struct wifi_data *wifi;
4933 bool is_associating = false;
4934 static bool is_scanning = true;
4939 #if defined TIZEN_EXT
4940 wifi = g_supplicant_interface_get_data(interface);
4941 if (wifi && wifi->scan_pending_network) {
4942 network_connect(wifi->scan_pending_network);
4943 wifi->scan_pending_network = NULL;
4946 //service state - associating
4947 if(!wifi || !wifi->network)
4950 is_associating = connman_network_get_associating(wifi->network);
4951 if(is_associating && is_scanning){
4952 is_scanning = false;
4953 DBG("send scan for connecting");
4954 throw_wifi_scan(wifi->device, scan_callback);
4965 static void ap_create_fail(GSupplicantInterface *interface)
4967 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4969 * Note: If supplicant interface's driver is wired then skip it,
4970 * because it meanti only for ethernet not Wi-Fi.
4972 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4974 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4976 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
4979 if ((wifi->tethering) && (wifi->tethering_param)) {
4980 DBG("%s create AP fail \n",
4981 g_supplicant_interface_get_ifname(wifi->interface));
4983 connman_inet_remove_from_bridge(wifi->index, wifi->bridge);
4984 wifi->ap_supported = WIFI_AP_NOT_SUPPORTED;
4985 wifi->tethering = false;
4987 ret = tech_set_tethering(wifi->tethering_param->technology,
4988 wifi->tethering_param->ssid->ssid,
4989 wifi->tethering_param->ssid->passphrase,
4990 wifi->bridge, true);
4992 if ((ret == -EOPNOTSUPP) && (wifi_technology)) {
4993 connman_technology_tethering_notify(wifi_technology,false);
4996 g_free(wifi->tethering_param->ssid);
4997 g_free(wifi->tethering_param);
4998 wifi->tethering_param = NULL;
5002 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
5004 unsigned char strength;
5006 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
5007 #if !defined TIZEN_EXT
5015 #if defined TIZEN_EXT_WIFI_MESH
5016 static void mesh_peer_added(GSupplicantNetwork *supplicant_network)
5018 GSupplicantInterface *interface;
5019 struct wifi_data *wifi;
5020 const char *name, *security;
5021 struct connman_mesh *connman_mesh;
5022 struct wifi_mesh_info *mesh_info;
5023 const unsigned char *bssid;
5024 const char *identifier;
5029 interface = g_supplicant_network_get_interface(supplicant_network);
5030 wifi = g_supplicant_interface_get_data(interface);
5031 if (!wifi || !wifi->mesh_interface) {
5032 DBG("Virtual Mesh interface not created");
5036 bssid = g_supplicant_network_get_bssid(supplicant_network);
5037 address = g_malloc0(19);
5038 snprintf(address, 19, "%02x:%02x:%02x:%02x:%02x:%02x", bssid[0], bssid[1],
5039 bssid[2], bssid[3], bssid[4], bssid[5]);
5041 identifier = g_supplicant_network_get_identifier(supplicant_network);
5042 name = g_supplicant_network_get_name(supplicant_network);
5043 security = g_supplicant_network_get_security(supplicant_network);
5044 frequency = g_supplicant_network_get_frequency(supplicant_network);
5046 mesh_info = wifi->mesh_info;
5047 connman_mesh = connman_mesh_get(mesh_info->identifier, identifier);
5051 DBG("Mesh Peer name %s identifier %s security %s added", name, identifier,
5053 connman_mesh = connman_mesh_create(mesh_info->identifier, identifier);
5054 connman_mesh_set_name(connman_mesh, name);
5055 connman_mesh_set_security(connman_mesh, security);
5056 connman_mesh_set_frequency(connman_mesh, frequency);
5057 connman_mesh_set_address(connman_mesh, address);
5058 connman_mesh_set_index(connman_mesh, mesh_info->index);
5059 connman_mesh_set_strength(connman_mesh,
5060 calculate_strength(supplicant_network));
5061 connman_mesh_set_peer_type(connman_mesh, CONNMAN_MESH_PEER_TYPE_DISCOVERED);
5063 ret = connman_mesh_register(connman_mesh);
5064 if (ret == -EALREADY)
5065 DBG("Mesh Peer is already registered");
5071 static void mesh_peer_removed(GSupplicantNetwork *supplicant_network)
5073 GSupplicantInterface *interface;
5074 struct wifi_data *wifi;
5075 struct connman_mesh *connman_mesh;
5076 struct wifi_mesh_info *mesh_info;
5077 const char *identifier;
5079 interface = g_supplicant_network_get_interface(supplicant_network);
5080 wifi = g_supplicant_interface_get_data(interface);
5081 if (!wifi || !wifi->mesh_interface) {
5082 DBG("Virtual Mesh interface not created");
5086 identifier = g_supplicant_network_get_identifier(supplicant_network);
5088 DBG("Failed to get Mesh Peer identifier");
5092 mesh_info = wifi->mesh_info;
5093 connman_mesh = connman_mesh_get(mesh_info->identifier, identifier);
5095 /* Do not unregister connected mesh peer */
5096 if (connman_mesh_peer_is_connected_state(connman_mesh)) {
5097 DBG("Mesh Peer %s is connected", identifier);
5100 DBG("Mesh Peer identifier %s removed", identifier);
5101 connman_mesh_unregister(connman_mesh);
5107 #if defined TIZEN_EXT
5108 static GSList *get_supported_security_list(unsigned int keymgmt,
5109 bool owe_transition_mode,
5110 GSupplicantNetwork *supplicant_network)
5112 GSList *sec_list = NULL;
5113 dbus_bool_t privacy = g_supplicant_network_get_privacy(supplicant_network);
5114 const char *enc_mode = g_supplicant_network_get_enc_mode(supplicant_network);
5117 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
5118 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
5119 sec_list = g_slist_prepend (sec_list, "ieee8021x");
5120 else if (keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_EAP)
5121 sec_list = g_slist_prepend (sec_list, "ft_ieee8021x");
5127 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
5128 G_SUPPLICANT_KEYMGMT_WPA_PSK_256)) {
5129 if (!g_strcmp0(enc_mode, "aes"))
5130 sec_list = g_slist_prepend (sec_list, "rsn");
5131 else if (!g_strcmp0(enc_mode, "tkip"))
5132 sec_list = g_slist_prepend (sec_list, "psk");
5133 else if (!g_strcmp0(enc_mode, "mixed")) {
5134 sec_list = g_slist_prepend (sec_list, "psk");
5135 sec_list = g_slist_prepend (sec_list, "rsn");
5137 } else if (keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
5138 sec_list = g_slist_prepend (sec_list, "ft_psk");
5140 if (keymgmt & G_SUPPLICANT_KEYMGMT_SAE)
5141 sec_list = g_slist_prepend (sec_list, "sae");
5142 if (keymgmt & G_SUPPLICANT_KEYMGMT_OWE || owe_transition_mode)
5143 sec_list = g_slist_prepend (sec_list, "owe");
5144 if (keymgmt & G_SUPPLICANT_KEYMGMT_DPP)
5145 sec_list = g_slist_prepend (sec_list, "dpp");
5151 sec_list = g_slist_prepend (sec_list, "wep");
5153 sec_list = g_slist_prepend (sec_list, "none");
5159 static void network_added(GSupplicantNetwork *supplicant_network)
5161 struct connman_network *network;
5162 GSupplicantInterface *interface;
5163 struct wifi_data *wifi;
5164 const char *name, *identifier, *security, *group, *mode;
5165 const unsigned char *ssid;
5166 unsigned int ssid_len;
5170 bool wps_advertizing;
5172 #if defined TIZEN_EXT
5173 bool owe_transition_mode;
5174 const unsigned char *transition_mode_ssid;
5175 const unsigned char *transition_mode_bssid;
5176 unsigned int transition_mode_ssid_len;
5177 unsigned int keymgmt;
5178 GSList *vsie_list = NULL;
5179 GSList *sec_list = NULL;
5180 const unsigned char *country_code;
5181 ieee80211_modes_e phy_mode;
5184 mode = g_supplicant_network_get_mode(supplicant_network);
5185 identifier = g_supplicant_network_get_identifier(supplicant_network);
5186 #if defined TIZEN_EXT
5187 if (!simplified_log)
5189 DBG("%s", identifier);
5191 if (!g_strcmp0(mode, "adhoc"))
5194 #if defined TIZEN_EXT_WIFI_MESH
5195 if (!g_strcmp0(mode, "mesh")) {
5196 mesh_peer_added(supplicant_network);
5201 interface = g_supplicant_network_get_interface(supplicant_network);
5202 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5204 * Note: If supplicant interface's driver is wired then skip it,
5205 * because it meanti only for ethernet not Wi-Fi.
5207 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5209 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5211 wifi = g_supplicant_interface_get_data(interface);
5212 name = g_supplicant_network_get_name(supplicant_network);
5213 security = g_supplicant_network_get_security(supplicant_network);
5214 group = g_supplicant_network_get_identifier(supplicant_network);
5215 wps = g_supplicant_network_get_wps(supplicant_network);
5216 wps_pbc = g_supplicant_network_is_wps_pbc(supplicant_network);
5217 wps_ready = g_supplicant_network_is_wps_active(supplicant_network);
5218 wps_advertizing = g_supplicant_network_is_wps_advertizing(
5219 supplicant_network);
5224 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
5226 network = connman_device_get_network(wifi->device, identifier);
5229 network = connman_network_create(identifier,
5230 CONNMAN_NETWORK_TYPE_WIFI);
5234 connman_network_set_index(network, wifi->index);
5236 if (connman_device_add_network(wifi->device, network) < 0) {
5237 connman_network_unref(network);
5241 wifi->networks = g_slist_prepend(wifi->networks, network);
5244 if (name && name[0] != '\0')
5245 connman_network_set_name(network, name);
5247 connman_network_set_blob(network, "WiFi.SSID",
5249 #if defined TIZEN_EXT
5250 vsie_list = (GSList *)g_supplicant_network_get_wifi_vsie(supplicant_network);
5252 connman_network_set_vsie_list(network, vsie_list);
5254 DBG("vsie_list is NULL");
5255 country_code = g_supplicant_network_get_countrycode(supplicant_network);
5256 connman_network_set_countrycode(network, country_code);
5257 phy_mode = g_supplicant_network_get_phy_mode(supplicant_network);
5258 connman_network_set_phy_mode(network, phy_mode);
5260 connman_network_set_string(network, "WiFi.Security", security);
5261 connman_network_set_strength(network,
5262 calculate_strength(supplicant_network));
5263 connman_network_set_bool(network, "WiFi.WPS", wps);
5264 connman_network_set_bool(network, "WiFi.WPSAdvertising",
5268 /* Is AP advertizing for WPS association?
5269 * If so, we decide to use WPS by default */
5270 if (wps_ready && wps_pbc &&
5272 #if !defined TIZEN_EXT
5273 connman_network_set_bool(network, "WiFi.UseWPS", true);
5275 DBG("wps is activating by ap but ignore it.");
5279 connman_network_set_frequency(network,
5280 g_supplicant_network_get_frequency(supplicant_network));
5282 #if defined TIZEN_EXT
5283 keymgmt = g_supplicant_network_get_keymgmt(supplicant_network);
5284 connman_network_set_bssid(network,
5285 g_supplicant_network_get_bssid(supplicant_network));
5286 owe_transition_mode = (bool)g_supplicant_network_get_transition_mode(supplicant_network);
5287 connman_network_set_bool(network, "WiFi.TRANSITION_MODE", owe_transition_mode);
5288 if (owe_transition_mode) {
5289 transition_mode_ssid = (unsigned char *)g_supplicant_network_get_transition_mode_ssid(supplicant_network, &transition_mode_ssid_len);
5290 connman_network_set_blob(network, "WiFi.TRANSITION_MODE_SSID",
5291 transition_mode_ssid, transition_mode_ssid_len);
5292 transition_mode_bssid = g_supplicant_network_get_transition_mode_bssid(supplicant_network);
5293 connman_network_set_transition_mode_bssid(network, transition_mode_bssid);
5296 sec_list = get_supported_security_list(keymgmt,
5297 owe_transition_mode, supplicant_network);
5299 connman_network_set_sec_list(network, sec_list);
5300 connman_network_set_maxrate(network,
5301 g_supplicant_network_get_maxrate(supplicant_network));
5302 connman_network_set_enc_mode(network,
5303 g_supplicant_network_get_enc_mode(supplicant_network));
5304 connman_network_set_rsn_mode(network,
5305 g_supplicant_network_get_rsn_mode(supplicant_network));
5306 connman_network_set_keymgmt(network, keymgmt);
5307 connman_network_set_bool(network, "WiFi.HS20AP",
5308 g_supplicant_network_is_hs20AP(supplicant_network));
5309 connman_network_set_bssid_list(network,
5310 (GSList *)g_supplicant_network_get_bssid_list(supplicant_network));
5311 connman_network_set_last_connected_bssid(network,
5312 g_supplicant_network_get_last_connected_bssid(supplicant_network));
5313 connman_network_set_assoc_reject_table(network,
5314 g_supplicant_network_get_assoc_reject_table(supplicant_network));
5316 connman_network_set_available(network, true);
5317 connman_network_set_string(network, "WiFi.Mode", mode);
5319 #if defined TIZEN_EXT
5324 connman_network_set_group(network, group);
5326 #if defined TIZEN_EXT
5327 g_supplicant_network_set_last_connected_bssid(supplicant_network,
5328 connman_network_get_last_connected_bssid(network));
5331 #if defined TIZEN_EXT
5332 if (wifi_first_scan == true)
5333 found_with_first_scan = true;
5336 if (wifi->hidden && ssid) {
5337 #if defined TIZEN_EXT
5338 if (network_security(wifi->hidden->security) ==
5339 network_security(security) &&
5341 if (!g_strcmp0(wifi->hidden->security, security) &&
5343 wifi->hidden->ssid_len == ssid_len &&
5344 !memcmp(wifi->hidden->ssid, ssid, ssid_len)) {
5345 connman_network_connect_hidden(network,
5346 wifi->hidden->identity,
5347 wifi->hidden->passphrase,
5348 wifi->hidden->user_data);
5349 wifi->hidden->user_data = NULL;
5350 hidden_free(wifi->hidden);
5351 wifi->hidden = NULL;
5356 static void network_removed(GSupplicantNetwork *network)
5358 GSupplicantInterface *interface;
5359 struct wifi_data *wifi;
5360 const char *name, *identifier;
5361 struct connman_network *connman_network;
5363 #if defined TIZEN_EXT_WIFI_MESH
5365 mode = g_supplicant_network_get_mode(network);
5366 if (!g_strcmp0(mode, "mesh")) {
5367 mesh_peer_removed(network);
5372 interface = g_supplicant_network_get_interface(network);
5373 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5375 * Note: If supplicant interface's driver is wired then skip it,
5376 * because it meanti only for ethernet not Wi-Fi.
5378 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5380 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5382 wifi = g_supplicant_interface_get_data(interface);
5383 identifier = g_supplicant_network_get_identifier(network);
5384 name = g_supplicant_network_get_name(network);
5386 DBG("name %s", name);
5391 connman_network = connman_device_get_network(wifi->device, identifier);
5392 if (!connman_network)
5395 #if defined TIZEN_EXT
5396 if (connman_network == wifi->scan_pending_network)
5397 wifi->scan_pending_network = NULL;
5399 if (connman_network == wifi->pending_network)
5400 wifi->pending_network = NULL;
5402 if(connman_network_get_connecting(connman_network) == true){
5403 connman_network_set_connected(connman_network, false);
5407 wifi->networks = g_slist_remove(wifi->networks, connman_network);
5409 connman_device_remove_network(wifi->device, connman_network);
5410 connman_network_unref(connman_network);
5413 static void network_changed(GSupplicantNetwork *network, const char *property)
5415 GSupplicantInterface *interface;
5416 struct wifi_data *wifi;
5417 const char *name, *identifier;
5418 struct connman_network *connman_network;
5421 #if defined TIZEN_EXT
5422 const unsigned char *bssid;
5423 unsigned int maxrate;
5426 const unsigned char *country_code;
5427 ieee80211_modes_e phy_mode;
5431 interface = g_supplicant_network_get_interface(network);
5432 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5434 * Note: If supplicant interface's driver is wired then skip it,
5435 * because it meanti only for ethernet not Wi-Fi.
5437 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5439 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5441 wifi = g_supplicant_interface_get_data(interface);
5442 identifier = g_supplicant_network_get_identifier(network);
5443 name = g_supplicant_network_get_name(network);
5445 #if defined TIZEN_EXT
5446 if (!simplified_log)
5447 DBG("name %s property %s", name, property);
5449 DBG("name %s", name);
5455 connman_network = connman_device_get_network(wifi->device, identifier);
5456 if (!connman_network)
5459 if (g_str_equal(property, "WPSCapabilities")) {
5463 bool wps_advertizing;
5465 wps = g_supplicant_network_get_wps(network);
5466 wps_pbc = g_supplicant_network_is_wps_pbc(network);
5467 wps_ready = g_supplicant_network_is_wps_active(network);
5469 g_supplicant_network_is_wps_advertizing(network);
5471 connman_network_set_bool(connman_network, "WiFi.WPS", wps);
5472 connman_network_set_bool(connman_network,
5473 "WiFi.WPSAdvertising", wps_advertizing);
5477 * Is AP advertizing for WPS association?
5478 * If so, we decide to use WPS by default
5480 if (wps_ready && wps_pbc && wps_advertizing)
5481 connman_network_set_bool(connman_network,
5482 "WiFi.UseWPS", true);
5485 update_needed = true;
5486 } else if (g_str_equal(property, "Signal")) {
5487 connman_network_set_strength(connman_network,
5488 calculate_strength(network));
5489 update_needed = true;
5491 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
5492 else if (g_str_equal(property, "LastConnectedBSSID")) {
5493 const char *ident, *group;
5494 char *service_ident;
5497 ident = connman_device_get_ident(wifi->device);
5498 group = connman_network_get_group(connman_network);
5499 if (ident && group) {
5500 service_ident = g_strdup_printf("%s_%s_%s",
5501 __connman_network_get_type(connman_network), ident, group);
5503 need_save = connman_device_set_last_connected_ident(wifi->device, service_ident);
5505 connman_device_save_last_connected(wifi->device);
5507 g_free(service_ident);
5510 connman_network_set_last_connected_bssid(connman_network,
5511 g_supplicant_network_get_last_connected_bssid(network));
5513 update_needed = true;
5515 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
5516 #if defined TIZEN_EXT
5517 else if (g_str_equal(property, "UpdateAssocReject")) {
5518 connman_network_set_assoc_reject_table(connman_network,
5519 g_supplicant_network_get_assoc_reject_table(network));
5520 update_needed = true;
5524 update_needed = false;
5527 connman_network_update(connman_network);
5529 #if defined TIZEN_EXT
5530 bssid = g_supplicant_network_get_bssid(network);
5531 maxrate = g_supplicant_network_get_maxrate(network);
5532 frequency = g_supplicant_network_get_frequency(network);
5533 wps = g_supplicant_network_get_wps(network);
5534 phy_mode = g_supplicant_network_get_phy_mode(network);
5536 connman_network_set_bssid(connman_network, bssid);
5537 connman_network_set_maxrate(connman_network, maxrate);
5538 connman_network_set_frequency(connman_network, frequency);
5539 connman_network_set_bool(connman_network, "WiFi.WPS", wps);
5540 country_code = g_supplicant_network_get_countrycode(network);
5541 connman_network_set_countrycode(connman_network, country_code);
5542 bssid_list = (GSList *)g_supplicant_network_get_bssid_list(network);
5543 connman_network_set_bssid_list(connman_network, bssid_list);
5544 connman_network_set_phy_mode(connman_network, phy_mode);
5546 if (g_str_equal(property, "CheckMultiBssidConnect") &&
5547 connman_network_get_associating(connman_network))
5548 network_connect(connman_network);
5552 static void network_associated(GSupplicantNetwork *network)
5554 GSupplicantInterface *interface;
5555 struct wifi_data *wifi;
5556 struct connman_network *connman_network;
5557 const char *identifier;
5561 interface = g_supplicant_network_get_interface(network);
5564 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5566 * Note: If supplicant interface's driver is wired then skip it,
5567 * because it meanti only for ethernet not Wi-Fi.
5569 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5571 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5574 wifi = g_supplicant_interface_get_data(interface);
5578 /* P2P networks must not be treated as WiFi networks */
5579 if (wifi->p2p_connecting || wifi->p2p_device)
5582 identifier = g_supplicant_network_get_identifier(network);
5584 connman_network = connman_device_get_network(wifi->device, identifier);
5585 if (!connman_network)
5588 if (wifi->network) {
5589 if (wifi->network == connman_network)
5592 unsigned int ssid_len;
5593 DBG("network1 ssid[%s] , OWE[%d],ssid[%s]",
5594 (char *)connman_network_get_blob(wifi->network,"WiFi.SSID", &ssid_len),
5595 connman_network_get_bool(wifi->network,"WiFi.TRANSITION_MODE"),
5596 (char *)connman_network_get_blob(wifi->network,"WiFi.TRANSITION_MODE_SSID", &ssid_len));
5598 DBG("network1 ssid[%s], OWE[%d], ssid[%s]",
5599 (char *)connman_network_get_blob(connman_network,"WiFi.SSID",&ssid_len),
5600 connman_network_get_bool(connman_network,"WiFi.TRANSITION_MODE"),
5601 (char *)connman_network_get_blob(connman_network,"WiFi.TRANSITION_MODE_SSID", &ssid_len));
5602 if (connman_network_check_transition_mode(wifi->network, connman_network)) {//OWE trasition mode check
5603 DBG("OWE transition mode is TRUE");
5608 * This should never happen, we got associated with
5609 * a network different than the one we were expecting.
5611 DBG("Associated to %p while expecting %p",
5612 connman_network, wifi->network);
5614 connman_network_set_associating(wifi->network, false);
5617 DBG("Reconnecting to previous network %p from wpa_s", connman_network);
5619 wifi->network = connman_network_ref(connman_network);
5623 * Interface state changes callback (interface_state) is always
5624 * called before network_associated callback thus we need to call
5625 * interface_state again in order to process the new state now that
5626 * we have the network properly set.
5628 interface_state(interface);
5631 static void sta_authorized(GSupplicantInterface *interface,
5634 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5636 * Note: If supplicant interface's driver is wired then skip it,
5637 * because it meanti only for ethernet not Wi-Fi.
5639 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5641 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5643 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5645 DBG("wifi %p station %s authorized", wifi, addr);
5647 if (!wifi || !wifi->tethering)
5650 __connman_tethering_client_register(addr);
5653 static void sta_deauthorized(GSupplicantInterface *interface,
5656 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5658 * Note: If supplicant interface's driver is wired then skip it,
5659 * because it meanti only for ethernet not Wi-Fi.
5661 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5663 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5665 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5667 DBG("wifi %p station %s deauthorized", wifi, addr);
5669 if (!wifi || !wifi->tethering)
5672 __connman_tethering_client_unregister(addr);
5675 static void apply_peer_services(GSupplicantPeer *peer,
5676 struct connman_peer *connman_peer)
5678 const unsigned char *data;
5683 connman_peer_reset_services(connman_peer);
5685 data = g_supplicant_peer_get_widi_ies(peer, &length);
5687 connman_peer_add_service(connman_peer,
5688 CONNMAN_PEER_SERVICE_WIFI_DISPLAY, data, length);
5692 static void peer_found(GSupplicantPeer *peer)
5694 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5695 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5696 struct connman_peer *connman_peer;
5697 const char *identifier, *name;
5700 #if defined TIZEN_EXT
5704 identifier = g_supplicant_peer_get_identifier(peer);
5705 name = g_supplicant_peer_get_name(peer);
5707 DBG("ident: %s", identifier);
5709 connman_peer = connman_peer_get(wifi->device, identifier);
5713 connman_peer = connman_peer_create(identifier);
5714 connman_peer_set_name(connman_peer, name);
5715 connman_peer_set_device(connman_peer, wifi->device);
5716 apply_peer_services(peer, connman_peer);
5718 ret = connman_peer_register(connman_peer);
5719 if (ret < 0 && ret != -EALREADY)
5720 connman_peer_unref(connman_peer);
5722 wifi->peers = g_slist_prepend(wifi->peers, connman_peer);
5725 static void peer_lost(GSupplicantPeer *peer)
5727 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5728 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5729 struct connman_peer *connman_peer;
5730 const char *identifier;
5735 identifier = g_supplicant_peer_get_identifier(peer);
5737 DBG("ident: %s", identifier);
5739 connman_peer = connman_peer_get(wifi->device, identifier);
5741 if (wifi->p2p_connecting &&
5742 wifi->pending_peer == connman_peer) {
5743 peer_connect_timeout(wifi);
5745 connman_peer_unregister(connman_peer);
5746 connman_peer_unref(connman_peer);
5749 wifi->peers = g_slist_remove(wifi->peers, connman_peer);
5752 static void peer_changed(GSupplicantPeer *peer, GSupplicantPeerState state)
5754 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5755 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5756 enum connman_peer_state p_state = CONNMAN_PEER_STATE_UNKNOWN;
5757 struct connman_peer *connman_peer;
5758 const char *identifier;
5760 identifier = g_supplicant_peer_get_identifier(peer);
5762 DBG("ident: %s", identifier);
5767 connman_peer = connman_peer_get(wifi->device, identifier);
5772 case G_SUPPLICANT_PEER_SERVICES_CHANGED:
5773 apply_peer_services(peer, connman_peer);
5774 connman_peer_services_changed(connman_peer);
5776 case G_SUPPLICANT_PEER_GROUP_CHANGED:
5777 if (!g_supplicant_peer_is_in_a_group(peer))
5778 p_state = CONNMAN_PEER_STATE_IDLE;
5780 p_state = CONNMAN_PEER_STATE_CONFIGURATION;
5782 case G_SUPPLICANT_PEER_GROUP_STARTED:
5784 case G_SUPPLICANT_PEER_GROUP_FINISHED:
5785 p_state = CONNMAN_PEER_STATE_IDLE;
5787 case G_SUPPLICANT_PEER_GROUP_JOINED:
5788 connman_peer_set_iface_address(connman_peer,
5789 g_supplicant_peer_get_iface_address(peer));
5791 case G_SUPPLICANT_PEER_GROUP_DISCONNECTED:
5792 p_state = CONNMAN_PEER_STATE_IDLE;
5794 case G_SUPPLICANT_PEER_GROUP_FAILED:
5795 if (g_supplicant_peer_has_requested_connection(peer))
5796 p_state = CONNMAN_PEER_STATE_IDLE;
5798 p_state = CONNMAN_PEER_STATE_FAILURE;
5802 if (p_state == CONNMAN_PEER_STATE_CONFIGURATION ||
5803 p_state == CONNMAN_PEER_STATE_FAILURE) {
5804 if (wifi->p2p_connecting
5805 && connman_peer == wifi->pending_peer)
5806 peer_cancel_timeout(wifi);
5808 p_state = CONNMAN_PEER_STATE_UNKNOWN;
5811 if (p_state == CONNMAN_PEER_STATE_UNKNOWN)
5814 if (p_state == CONNMAN_PEER_STATE_CONFIGURATION) {
5815 GSupplicantInterface *g_iface;
5816 struct wifi_data *g_wifi;
5818 g_iface = g_supplicant_peer_get_group_interface(peer);
5822 g_wifi = g_supplicant_interface_get_data(g_iface);
5826 connman_peer_set_as_master(connman_peer,
5827 !g_supplicant_peer_is_client(peer));
5828 connman_peer_set_sub_device(connman_peer, g_wifi->device);
5831 * If wpa_supplicant didn't create a dedicated p2p-group
5832 * interface then mark this interface as p2p_device to avoid
5833 * scan and auto-scan are launched on it while P2P is connected.
5835 if (!g_list_find(p2p_iface_list, g_wifi))
5836 wifi->p2p_device = true;
5839 connman_peer_set_state(connman_peer, p_state);
5842 static void peer_request(GSupplicantPeer *peer)
5844 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5845 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5846 struct connman_peer *connman_peer;
5847 const char *identifier;
5849 #if defined TIZEN_EXT
5854 identifier = g_supplicant_peer_get_identifier(peer);
5856 DBG("ident: %s", identifier);
5858 connman_peer = connman_peer_get(wifi->device, identifier);
5862 connman_peer_request_connection(connman_peer);
5865 #if defined TIZEN_EXT
5866 static void system_power_off(void)
5869 struct wifi_data *wifi;
5870 struct connman_service *service;
5871 struct connman_ipconfig *ipconfig_ipv4;
5873 if (connman_setting_get_bool("WiFiDHCPRelease") == true) {
5874 for (list = iface_list; list; list = list->next) {
5877 if (wifi->network != NULL) {
5878 service = connman_service_lookup_from_network(wifi->network);
5879 ipconfig_ipv4 = __connman_service_get_ip4config(service);
5880 __connman_dhcp_stop(ipconfig_ipv4);
5886 static void network_merged(GSupplicantNetwork *network)
5888 GSupplicantInterface *interface;
5889 GSupplicantState state;
5890 struct wifi_data *wifi;
5891 const char *identifier;
5892 struct connman_network *connman_network;
5896 interface = g_supplicant_network_get_interface(network);
5900 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5902 * Note: If supplicant interface's driver is wired then skip it,
5903 * because it meanti only for ethernet not Wi-Fi.
5905 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5907 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5909 state = g_supplicant_interface_get_state(interface);
5910 if (state < G_SUPPLICANT_STATE_AUTHENTICATING)
5913 wifi = g_supplicant_interface_get_data(interface);
5917 identifier = g_supplicant_network_get_identifier(network);
5919 connman_network = connman_device_get_network(wifi->device, identifier);
5920 if (!connman_network)
5923 DBG("merged identifier %s", identifier);
5925 if (wifi->connected == FALSE) {
5927 case G_SUPPLICANT_STATE_AUTHENTICATING:
5928 case G_SUPPLICANT_STATE_ASSOCIATING:
5929 case G_SUPPLICANT_STATE_ASSOCIATED:
5930 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
5931 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
5932 connman_network_set_associating(connman_network, TRUE);
5934 case G_SUPPLICANT_STATE_COMPLETED:
5935 connman_network_set_connected(connman_network, TRUE);
5938 DBG("Not handled the state : %d", state);
5943 ishs20AP = g_supplicant_network_is_hs20AP(network);
5946 g_strcmp0(g_supplicant_network_get_security(network), "ieee8021x") == 0) {
5947 temp = g_ascii_strdown(g_supplicant_network_get_eap(network), -1);
5948 connman_network_set_string(connman_network, "WiFi.EAP",
5950 connman_network_set_string(connman_network, "WiFi.Identity",
5951 g_supplicant_network_get_identity(network));
5952 connman_network_set_string(connman_network, "WiFi.Phase2",
5953 g_supplicant_network_get_phase2(network));
5958 wifi->network = connman_network;
5961 static void assoc_failed(void *user_data)
5963 struct connman_network *network = user_data;
5964 connman_network_set_associating(network, false);
5967 static void scan_done(GSupplicantInterface *interface)
5969 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5971 * Note: If supplicant interface's driver is wired then skip it,
5972 * because it meanti only for ethernet not Wi-Fi.
5974 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5976 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5979 int scan_type = CONNMAN_SCAN_TYPE_WPA_SUPPLICANT;
5980 struct wifi_data *wifi;
5983 for (list = iface_list; list; list = list->next) {
5986 if (interface == wifi->interface) {
5987 scanning = connman_device_get_scanning(wifi->device,
5988 CONNMAN_SERVICE_TYPE_WIFI);
5990 __connman_technology_notify_scan_done(
5991 connman_device_get_string(wifi->device, "Interface"), scan_type);
5998 static void debug(const char *str)
6000 #if defined TIZEN_EXT
6001 if (connman_setting_get_bool("ConnmanSupplicantDebug"))
6003 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
6005 connman_debug("%s", str);
6008 static void disconnect_reasoncode(GSupplicantInterface *interface,
6011 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
6013 * Note: If supplicant interface's driver is wired then skip it,
6014 * because it meanti only for ethernet not Wi-Fi.
6016 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
6018 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
6020 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
6023 wifi->disconnect_code = reasoncode;
6027 static void assoc_status_code(GSupplicantInterface *interface, int status_code)
6029 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
6031 * Note: If supplicant interface's driver is wired then skip it,
6032 * because it meanti only for ethernet not Wi-Fi.
6034 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
6036 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
6038 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
6041 wifi->assoc_code = status_code;
6045 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
6046 static GSupplicantCallbacks callbacks = {
6047 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
6048 static const GSupplicantCallbacks callbacks = {
6049 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
6050 .system_ready = system_ready,
6051 .system_killed = system_killed,
6052 .interface_added = interface_added,
6053 .interface_state = interface_state,
6054 .interface_removed = interface_removed,
6055 .p2p_support = p2p_support,
6056 .scan_started = scan_started,
6057 .scan_finished = scan_finished,
6058 .ap_create_fail = ap_create_fail,
6059 .network_added = network_added,
6060 .network_removed = network_removed,
6061 .network_changed = network_changed,
6062 .network_associated = network_associated,
6063 .sta_authorized = sta_authorized,
6064 .sta_deauthorized = sta_deauthorized,
6065 .peer_found = peer_found,
6066 .peer_lost = peer_lost,
6067 .peer_changed = peer_changed,
6068 .peer_request = peer_request,
6069 #if defined TIZEN_EXT
6070 .system_power_off = system_power_off,
6071 .network_merged = network_merged,
6072 .assoc_failed = assoc_failed,
6073 .scan_done = scan_done,
6076 .disconnect_reasoncode = disconnect_reasoncode,
6077 .assoc_status_code = assoc_status_code,
6078 #if defined TIZEN_EXT_WIFI_MESH
6079 .mesh_support = mesh_support,
6080 .mesh_group_started = mesh_group_started,
6081 .mesh_group_removed = mesh_group_removed,
6082 .mesh_peer_connected = mesh_peer_connected,
6083 .mesh_peer_disconnected = mesh_peer_disconnected,
6088 static int tech_probe(struct connman_technology *technology)
6090 wifi_technology = technology;
6095 static void tech_remove(struct connman_technology *technology)
6097 wifi_technology = NULL;
6100 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
6102 GSupplicantSSID *ap;
6104 ap = g_try_malloc0(sizeof(GSupplicantSSID));
6108 ap->mode = G_SUPPLICANT_MODE_MASTER;
6109 #if defined TIZEN_EXT
6110 ap->ssid = (void *) ssid;
6114 ap->ssid_len = strlen(ssid);
6118 if (!passphrase || strlen(passphrase) == 0) {
6119 ap->security = G_SUPPLICANT_SECURITY_NONE;
6120 ap->passphrase = NULL;
6122 ap->security = G_SUPPLICANT_SECURITY_PSK;
6123 ap->protocol = G_SUPPLICANT_PROTO_RSN;
6124 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
6125 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
6126 ap->passphrase = passphrase;
6132 static void ap_start_callback(int result, GSupplicantInterface *interface,
6135 struct wifi_tethering_info *info = user_data;
6137 DBG("result %d index %d bridge %s",
6138 result, info->wifi->index, info->wifi->bridge);
6140 if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
6141 connman_inet_remove_from_bridge(info->wifi->index,
6142 info->wifi->bridge);
6144 if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
6145 connman_technology_tethering_notify(info->technology, false);
6146 g_free(info->wifi->tethering_param->ssid);
6147 g_free(info->wifi->tethering_param);
6148 info->wifi->tethering_param = NULL;
6152 g_free(info->ifname);
6156 static void ap_create_callback(int result,
6157 GSupplicantInterface *interface,
6160 struct wifi_tethering_info *info = user_data;
6162 DBG("result %d ifname %s", result,
6163 g_supplicant_interface_get_ifname(interface));
6165 if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
6166 connman_inet_remove_from_bridge(info->wifi->index,
6167 info->wifi->bridge);
6169 if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
6170 connman_technology_tethering_notify(info->technology, false);
6171 g_free(info->wifi->tethering_param->ssid);
6172 g_free(info->wifi->tethering_param);
6173 info->wifi->tethering_param = NULL;
6177 g_free(info->ifname);
6183 info->wifi->interface = interface;
6184 g_supplicant_interface_set_data(interface, info->wifi);
6186 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
6187 connman_error("Failed to set interface ap_scan property");
6189 g_supplicant_interface_connect(interface, info->ssid,
6190 ap_start_callback, info);
6193 static void sta_remove_callback(int result,
6194 GSupplicantInterface *interface,
6197 struct wifi_tethering_info *info = user_data;
6198 const char *driver = connman_option_get_string("wifi");
6200 DBG("ifname %s result %d ", info->ifname, result);
6202 if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
6203 info->wifi->tethering = false;
6204 connman_technology_tethering_notify(info->technology, false);
6206 if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
6207 g_free(info->wifi->tethering_param->ssid);
6208 g_free(info->wifi->tethering_param);
6209 info->wifi->tethering_param = NULL;
6212 g_free(info->ifname);
6218 info->wifi->interface = NULL;
6220 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
6223 #endif /* TIZEN_EXT */
6228 static int enable_wifi_tethering(struct connman_technology *technology,
6229 const char *bridge, const char *identifier,
6230 const char *passphrase, bool available)
6233 GSupplicantInterface *interface;
6234 struct wifi_data *wifi;
6235 struct wifi_tethering_info *info;
6240 for (list = iface_list; list; list = list->next) {
6243 DBG("wifi %p network %p pending_network %p", wifi,
6244 wifi->network, wifi->pending_network);
6246 interface = wifi->interface;
6251 ifname = g_supplicant_interface_get_ifname(wifi->interface);
6255 if (wifi->ap_supported == WIFI_AP_NOT_SUPPORTED) {
6256 DBG("%s does not support AP mode (detected)", ifname);
6260 mode = g_supplicant_interface_get_mode(interface);
6261 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
6262 wifi->ap_supported = WIFI_AP_NOT_SUPPORTED;
6263 DBG("%s does not support AP mode (capability)", ifname);
6267 if (wifi->network && available)
6270 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
6274 wifi->tethering_param = g_try_malloc0(sizeof(struct wifi_tethering_info));
6275 if (!wifi->tethering_param) {
6281 info->technology = technology;
6282 info->wifi->bridge = bridge;
6283 info->ssid = ssid_ap_init(identifier, passphrase);
6287 info->ifname = g_strdup(ifname);
6289 wifi->tethering_param->technology = technology;
6290 wifi->tethering_param->ssid = ssid_ap_init(identifier, passphrase);
6291 if (!wifi->tethering_param->ssid)
6294 info->wifi->tethering = true;
6295 info->wifi->ap_supported = WIFI_AP_SUPPORTED;
6297 berr = connman_technology_tethering_notify(technology, true);
6301 err = g_supplicant_interface_remove(interface,
6302 sta_remove_callback,
6305 DBG("tethering wifi %p ifname %s", wifi, ifname);
6310 g_free(info->ifname);
6313 g_free(wifi->tethering_param);
6314 wifi->tethering_param = NULL;
6317 * Remove bridge if it was correctly created but remove
6318 * operation failed. Instead, if bridge creation failed then
6319 * break out and do not try again on another interface,
6320 * bridge set-up does not depend on it.
6323 connman_technology_tethering_notify(technology, false);
6331 static int tech_set_tethering(struct connman_technology *technology,
6332 const char *identifier, const char *passphrase,
6333 const char *bridge, bool enabled)
6336 struct wifi_data *wifi;
6342 for (list = iface_list; list; list = list->next) {
6345 if (wifi->tethering) {
6346 wifi->tethering = false;
6348 connman_inet_remove_from_bridge(wifi->index,
6350 wifi->bridged = false;
6354 connman_technology_tethering_notify(technology, false);
6359 DBG("trying tethering for available devices");
6360 err = enable_wifi_tethering(technology, bridge, identifier, passphrase,
6364 DBG("trying tethering for any device");
6365 err = enable_wifi_tethering(technology, bridge, identifier,
6372 static void regdom_callback(int result, const char *alpha2, void *user_data)
6376 if (!wifi_technology)
6382 connman_technology_regdom_notify(wifi_technology, alpha2);
6385 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
6387 return g_supplicant_set_country(alpha2, regdom_callback, NULL);
6390 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
6391 static void supp_ins_init(void)
6394 GSupplicantINSPreferredFreq preferred_freq;
6396 string = connman_option_get_string("INSPreferredFreqBSSID");
6397 if (g_strcmp0(string, "5GHz") == 0)
6398 preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_5GHZ;
6399 else if (g_strcmp0(string, "2.4GHz") == 0)
6400 preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_24GHZ;
6402 preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_UNKNOWN;
6404 g_supplicant_set_ins_settings(preferred_freq,
6405 connman_setting_get_bool("INSLastConnectedBSSID"),
6406 connman_setting_get_bool("INSAssocReject"),
6407 connman_setting_get_bool("INSSignalBSSID"),
6408 connman_setting_get_uint("INSPreferredFreqBSSIDScore"),
6409 connman_setting_get_uint("INSLastConnectedBSSIDScore"),
6410 connman_setting_get_uint("INSAssocRejectScore"),
6411 connman_setting_get_int("INSSignalLevel3_5GHz"),
6412 connman_setting_get_int("INSSignalLevel3_24GHz")
6415 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
6417 static struct connman_technology_driver tech_driver = {
6419 .type = CONNMAN_SERVICE_TYPE_WIFI,
6420 .probe = tech_probe,
6421 .remove = tech_remove,
6422 .set_tethering = tech_set_tethering,
6423 .set_regdom = tech_set_regdom,
6426 static int wifi_init(void)
6430 err = connman_network_driver_register(&network_driver);
6434 err = g_supplicant_register(&callbacks);
6436 connman_network_driver_unregister(&network_driver);
6440 err = connman_technology_driver_register(&tech_driver);
6442 g_supplicant_unregister(&callbacks);
6443 connman_network_driver_unregister(&network_driver);
6447 #if defined TIZEN_EXT
6448 failed_bssids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
6451 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
6453 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
6457 static void wifi_exit(void)
6461 connman_technology_driver_unregister(&tech_driver);
6463 g_supplicant_unregister(&callbacks);
6465 connman_network_driver_unregister(&network_driver);
6467 #if defined TIZEN_EXT
6468 g_hash_table_unref(failed_bssids);
6472 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
6473 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)