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 */
86 #define RSSI_LEVEL_2_5G -77
87 #define RSSI_LEVEL_2_24G -75
90 static struct connman_technology *wifi_technology = NULL;
91 static struct connman_technology *p2p_technology = NULL;
93 enum wifi_ap_capability{
95 WIFI_AP_SUPPORTED = 1,
96 WIFI_AP_NOT_SUPPORTED = 2,
99 enum wifi_scanning_type {
100 WIFI_SCANNING_UNKNOWN = 0,
101 WIFI_SCANNING_PASSIVE = 1,
102 WIFI_SCANNING_ACTIVE = 2,
105 struct hidden_params {
107 unsigned int ssid_len;
109 char *anonymous_identity;
111 char *altsubject_match;
112 char *domain_suffix_match;
116 GSupplicantScanParams *scan_params;
121 * Used for autoscan "emulation".
122 * Should be removed when wpa_s autoscan support will be by default.
124 struct autoscan_params {
128 unsigned int timeout;
131 struct wifi_tethering_info {
132 struct wifi_data *wifi;
133 struct connman_technology *technology;
135 GSupplicantSSID *ssid;
140 struct connman_device *device;
141 struct connman_network *network;
142 struct connman_network *pending_network;
144 GSupplicantInterface *interface;
145 GSupplicantState state;
149 enum wifi_ap_capability ap_supported;
151 bool interface_ready;
157 int load_shaping_retries;
158 struct hidden_params *hidden;
159 bool postpone_hidden;
160 struct wifi_tethering_info *tethering_param;
162 * autoscan "emulation".
164 struct autoscan_params *autoscan;
165 enum wifi_scanning_type scanning_type;
166 GSupplicantScanParams *scan_params;
167 unsigned int p2p_find_timeout;
168 unsigned int p2p_connection_timeout;
169 struct connman_peer *pending_peer;
174 #if defined TIZEN_EXT
175 int assoc_retry_count;
176 struct connman_network *scan_pending_network;
177 bool allow_full_scan;
178 unsigned int automaxspeed_timeout;
179 GSupplicantScanParams *hidden_scan_params;
180 unsigned int mac_policy;
181 unsigned int preassoc_mac_policy;
182 unsigned int mac_lifetime;
186 #if defined TIZEN_EXT_WIFI_MESH
188 struct wifi_mesh_info *mesh_info;
192 #if defined TIZEN_EXT
196 #define TIZEN_ASSOC_RETRY_COUNT 4
198 static gboolean wifi_first_scan = false;
199 static gboolean found_with_first_scan = false;
200 static gboolean is_wifi_notifier_registered = false;
201 static GHashTable *failed_bssids = NULL;
202 static unsigned char buff_bssid[WIFI_BSSID_LEN_MAX] = { 0, };
206 static GList *iface_list = NULL;
208 static GList *pending_wifi_device = NULL;
209 static GList *p2p_iface_list = NULL;
210 static bool wfd_service_registered = false;
212 static void start_autoscan(struct connman_device *device);
213 static int tech_set_tethering(struct connman_technology *technology,
214 const char *identifier, const char *passphrase,
215 const char *bridge, bool enabled);
217 #if defined TIZEN_EXT
218 #define NETCONFIG_SERVICE "net.netconfig"
219 #define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
220 #define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
222 struct enc_method_call_data {
223 DBusConnection *connection;
224 struct connman_network *network;
227 static struct enc_method_call_data encrypt_request_data;
229 static void encryption_request_reply(DBusPendingCall *call,
234 DBusMessageIter args;
236 struct connman_service *service;
237 gchar* encrypted_value = NULL;
238 struct connman_network *network = encrypt_request_data.network;
242 reply = dbus_pending_call_steal_reply(call);
244 dbus_error_init(&error);
245 if (dbus_set_error_from_message(&error, reply)) {
246 DBG("send_encryption_request() %s %s", error.name, error.message);
247 dbus_error_free(&error);
251 if (dbus_message_iter_init(reply, &args) == FALSE)
254 dbus_message_iter_get_basic(&args, &out_data);
256 encrypted_value = g_strdup((const gchar *)out_data);
257 service = connman_service_lookup_from_network(network);
260 DBG("encryption result: no service");
264 if (connman_service_get_favorite(service)) {
265 __connman_service_set_passphrase(service, encrypted_value);
266 __connman_service_save(service);
268 connman_network_set_string(network, "WiFi.Passphrase",
271 DBG("encryption result: succeeded");
274 dbus_message_unref(reply);
275 dbus_pending_call_unref(call);
276 dbus_connection_unref(encrypt_request_data.connection);
277 g_free(encrypted_value);
279 encrypt_request_data.connection = NULL;
280 encrypt_request_data.network = NULL;
283 static int send_encryption_request(const char *passphrase,
284 struct connman_network *network)
286 DBusConnection *connection = NULL;
287 DBusMessage *msg = NULL;
288 DBusPendingCall *call;
291 DBG("Invalid parameter");
295 connection = connman_dbus_get_connection();
297 DBG("dbus connection does not exist");
301 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
302 NETCONFIG_WIFI_INTERFACE, "EncryptPassphrase");
304 dbus_connection_unref(connection);
308 dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
311 if (!dbus_connection_send_with_reply(connection, msg,
312 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
313 dbus_message_unref(msg);
314 dbus_connection_unref(connection);
319 dbus_message_unref(msg);
320 dbus_connection_unref(connection);
324 encrypt_request_data.connection = connection;
325 encrypt_request_data.network = network;
327 dbus_pending_call_set_notify(call, encryption_request_reply, NULL, NULL);
328 dbus_message_unref(msg);
334 static int p2p_tech_probe(struct connman_technology *technology)
336 p2p_technology = technology;
341 static void p2p_tech_remove(struct connman_technology *technology)
343 p2p_technology = NULL;
346 static struct connman_technology_driver p2p_tech_driver = {
348 .type = CONNMAN_SERVICE_TYPE_P2P,
349 .probe = p2p_tech_probe,
350 .remove = p2p_tech_remove,
353 static bool is_p2p_connecting(void)
357 for (list = iface_list; list; list = list->next) {
358 struct wifi_data *wifi = list->data;
360 if (wifi->p2p_connecting)
367 static void add_pending_wifi_device(struct wifi_data *wifi)
369 if (g_list_find(pending_wifi_device, wifi))
372 pending_wifi_device = g_list_append(pending_wifi_device, wifi);
375 #if defined TIZEN_EXT_WIFI_MESH
376 struct wifi_mesh_info {
377 struct wifi_data *wifi;
378 GSupplicantInterface *interface;
379 struct connman_mesh *mesh;
386 struct mesh_change_peer_status_info {
388 enum connman_mesh_peer_status peer_status;
389 mesh_change_peer_status_cb_t callback;
393 static struct connman_technology_driver mesh_tech_driver = {
395 .type = CONNMAN_SERVICE_TYPE_MESH,
398 static void mesh_interface_create_callback(int result,
399 GSupplicantInterface *interface,
402 struct wifi_mesh_info *mesh_info = user_data;
403 struct wifi_data *wifi;
404 bool success = false;
406 DBG("result %d ifname %s, mesh_info %p", result,
407 g_supplicant_interface_get_ifname(interface),
410 if (result < 0 || !mesh_info)
413 wifi = mesh_info->wifi;
415 mesh_info->interface = interface;
416 mesh_info->identifier = connman_inet_ifaddr(mesh_info->ifname);
417 mesh_info->index = connman_inet_ifindex(mesh_info->ifname);
418 DBG("Mesh Interface identifier %s", mesh_info->identifier);
419 wifi->mesh_interface = true;
420 wifi->mesh_info = mesh_info;
421 g_supplicant_interface_set_data(interface, wifi);
425 connman_mesh_notify_interface_create(success);
428 static int add_mesh_interface(const char *ifname, const char *parent_ifname)
431 struct wifi_data *wifi;
432 struct wifi_mesh_info *mesh_info;
433 const char *wifi_ifname;
434 bool parent_found = false;
435 const char *driver = "nl80211";
437 for (list = iface_list; list; list = list->next) {
440 if (!g_supplicant_interface_has_mesh(wifi->interface))
443 wifi_ifname = g_supplicant_interface_get_ifname(wifi->interface);
447 if (!g_strcmp0(wifi_ifname, parent_ifname)) {
454 DBG("Parent interface %s doesn't exist", parent_ifname);
458 mesh_info = g_try_malloc0(sizeof(struct wifi_mesh_info));
462 mesh_info->wifi = wifi;
463 mesh_info->ifname = g_strdup(ifname);
464 mesh_info->parent_ifname = g_strdup(parent_ifname);
466 g_supplicant_mesh_interface_create(ifname, driver, NULL, parent_ifname,
467 mesh_interface_create_callback, mesh_info);
471 static void mesh_interface_remove_callback(int result,
472 GSupplicantInterface *interface,
475 struct wifi_data *wifi = user_data;
476 struct wifi_mesh_info *mesh_info = wifi->mesh_info;
477 bool success = false;
479 DBG("result %d mesh_info %p", result, mesh_info);
481 if (result < 0 || !mesh_info)
484 mesh_info->interface = NULL;
485 g_free(mesh_info->parent_ifname);
486 g_free(mesh_info->ifname);
487 g_free(mesh_info->identifier);
489 wifi->mesh_interface = false;
490 wifi->mesh_info = NULL;
494 connman_mesh_notify_interface_remove(success);
497 static int remove_mesh_interface(const char *ifname)
500 struct wifi_data *wifi;
501 struct wifi_mesh_info *mesh_info;
502 bool mesh_if_found = false;
505 for (list = iface_list; list; list = list->next) {
508 if (wifi->mesh_interface) {
509 mesh_if_found = true;
514 if (!mesh_if_found) {
515 DBG("Mesh interface %s doesn't exist", ifname);
519 mesh_info = wifi->mesh_info;
520 ret = g_supplicant_interface_remove(mesh_info->interface,
521 mesh_interface_remove_callback, wifi);
528 static void mesh_disconnect_callback(int result,
529 GSupplicantInterface *interface, void *user_data)
531 struct connman_mesh *mesh = user_data;
533 DBG("result %d interface %p mesh %p", result, interface, mesh);
536 static int mesh_peer_disconnect(struct connman_mesh *mesh)
539 struct wifi_data *wifi;
540 struct wifi_mesh_info *mesh_info;
541 bool mesh_if_found = false;
542 GSupplicantInterface *interface;
544 for (list = iface_list; list; list = list->next) {
547 if (wifi->mesh_interface) {
548 mesh_if_found = true;
553 if (!mesh_if_found) {
554 DBG("Mesh interface is not created");
558 mesh_info = wifi->mesh_info;
560 interface = mesh_info->interface;
561 return g_supplicant_interface_disconnect(interface,
562 mesh_disconnect_callback, mesh);
565 static void mesh_connect_callback(int result, GSupplicantInterface *interface,
568 struct connman_mesh *mesh = user_data;
569 DBG("mesh %p result %d", mesh, result);
572 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_FAILURE);
574 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_ASSOCIATION);
577 static GSupplicantSecurity mesh_network_security(const char *security)
579 if (g_str_equal(security, "none"))
580 return G_SUPPLICANT_SECURITY_NONE;
581 else if (g_str_equal(security, "sae"))
582 return G_SUPPLICANT_SECURITY_SAE;
584 return G_SUPPLICANT_SECURITY_UNKNOWN;
587 static void mesh_ssid_init(GSupplicantSSID *ssid, struct connman_mesh *mesh)
590 const char *security;
595 memset(ssid, 0, sizeof(*ssid));
596 ssid->mode = G_SUPPLICANT_MODE_MESH;
598 security = connman_mesh_get_security(mesh);
599 ssid->security = mesh_network_security(security);
601 if (ssid->security == G_SUPPLICANT_SECURITY_SAE)
602 ssid->passphrase = connman_mesh_get_passphrase(mesh);
604 ssid->freq = connman_mesh_get_frequency(mesh);
605 name = connman_mesh_get_name(mesh);
607 ssid->ssid_len = strlen(name);
608 ssid->ssid = g_malloc0(ssid->ssid_len + 1);
609 memcpy(ssid->ssid, name, ssid->ssid_len);
614 static int mesh_peer_connect(struct connman_mesh *mesh)
617 struct wifi_data *wifi;
618 struct wifi_mesh_info *mesh_info;
619 bool mesh_if_found = false;
620 GSupplicantInterface *interface;
621 GSupplicantSSID *ssid;
623 for (list = iface_list; list; list = list->next) {
626 if (wifi->mesh_interface) {
627 mesh_if_found = true;
632 if (!mesh_if_found) {
633 DBG("Mesh interface is not created");
637 mesh_info = wifi->mesh_info;
639 interface = mesh_info->interface;
641 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
645 mesh_info->mesh = mesh;
647 mesh_ssid_init(ssid, mesh);
648 return g_supplicant_interface_connect(interface, ssid,
649 mesh_connect_callback, mesh);
652 static void mesh_peer_change_status_callback(int result,
653 GSupplicantInterface *interface,
656 struct mesh_change_peer_status_info *data = user_data;
658 DBG("result %d Peer Status %d", result, data->peer_status);
660 if (result == 0 && data->peer_status == CONNMAN_MESH_PEER_REMOVE) {
661 /* WLAN_REASON_MESH_PEERING_CANCELLED = 52 */
662 connman_mesh_remove_connected_peer(data->peer_address, 52);
666 data->callback(result, data->user_data);
668 g_free(data->peer_address);
673 static int mesh_change_peer_status(const char *peer_address,
674 enum connman_mesh_peer_status status,
675 mesh_change_peer_status_cb_t callback, void *user_data)
678 struct wifi_data *wifi;
679 struct wifi_mesh_info *mesh_info;
680 bool mesh_if_found = false;
681 GSupplicantInterface *interface;
682 struct mesh_change_peer_status_info *data;
685 for (list = iface_list; list; list = list->next) {
688 if (wifi->mesh_interface) {
689 mesh_if_found = true;
694 if (!mesh_if_found) {
695 DBG("Mesh interface is not created");
699 mesh_info = wifi->mesh_info;
701 interface = mesh_info->interface;
704 case CONNMAN_MESH_PEER_ADD:
705 method = "MeshPeerAdd";
707 case CONNMAN_MESH_PEER_REMOVE:
708 method = "MeshPeerRemove";
711 DBG("Invalid method");
715 data = g_try_malloc0(sizeof(struct mesh_change_peer_status_info));
717 DBG("Memory allocation failed");
721 data->peer_address = g_strdup(peer_address);
722 data->peer_status = status;
723 data->callback = callback;
724 data->user_data = user_data;
726 return g_supplicant_interface_mesh_peer_change_status(interface,
727 mesh_peer_change_status_callback, peer_address, method,
731 static struct connman_mesh_driver mesh_driver = {
732 .add_interface = add_mesh_interface,
733 .remove_interface = remove_mesh_interface,
734 .connect = mesh_peer_connect,
735 .disconnect = mesh_peer_disconnect,
736 .change_peer_status = mesh_change_peer_status,
739 static void mesh_support(GSupplicantInterface *interface)
743 if (!g_supplicant_interface_has_mesh(interface))
746 if (connman_technology_driver_register(&mesh_tech_driver) < 0) {
747 DBG("Could not register Mesh technology driver");
751 connman_mesh_driver_register(&mesh_driver);
754 static void check_mesh_technology(void)
756 bool mesh_exists = false;
759 for (list = iface_list; list; list = list->next) {
760 struct wifi_data *w = list->data;
763 g_supplicant_interface_has_mesh(w->interface))
768 connman_technology_driver_unregister(&mesh_tech_driver);
769 connman_mesh_driver_unregister(&mesh_driver);
773 static void mesh_group_started(GSupplicantInterface *interface)
775 struct wifi_data *wifi;
776 struct wifi_mesh_info *mesh_info;
777 struct connman_mesh *mesh;
778 const unsigned char *ssid;
779 unsigned int ssid_len;
782 ssid = g_supplicant_interface_get_mesh_group_ssid(interface, &ssid_len);
783 memcpy(name, ssid, ssid_len);
784 name[ssid_len] = '\0';
785 DBG("name %s", name);
786 wifi = g_supplicant_interface_get_data(interface);
787 DBG("wifi %p", wifi);
792 mesh_info = wifi->mesh_info;
796 mesh = mesh_info->mesh;
800 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_CONFIGURATION);
803 static void mesh_group_removed(GSupplicantInterface *interface)
805 struct wifi_data *wifi;
806 struct wifi_mesh_info *mesh_info;
807 struct connman_mesh *mesh;
808 const unsigned char *ssid;
809 unsigned int ssid_len;
810 int disconnect_reason;
813 ssid = g_supplicant_interface_get_mesh_group_ssid(interface, &ssid_len);
814 memcpy(name, ssid, ssid_len);
815 name[ssid_len] = '\0';
816 DBG("name %s", name);
818 disconnect_reason = g_supplicant_mesh_get_disconnect_reason(interface);
819 DBG("Disconnect Reason %d", disconnect_reason);
821 wifi = g_supplicant_interface_get_data(interface);
822 DBG("wifi %p", wifi);
827 mesh_info = wifi->mesh_info;
831 mesh = connman_get_connected_mesh_from_name(name);
833 DBG("%s is not connected", name);
834 mesh = connman_get_connecting_mesh_from_name(name);
836 DBG("%s is not connecting", name);
841 connman_mesh_peer_set_disconnect_reason(mesh, disconnect_reason);
842 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_DISCONNECT);
845 static void mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
847 const char *peer_address;
849 peer_address = g_supplicant_mesh_peer_get_address(mesh_peer);
854 DBG("Peer %s connected", peer_address);
855 connman_mesh_add_connected_peer(peer_address);
858 static void mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
860 const char *peer_address;
863 peer_address = g_supplicant_mesh_peer_get_address(mesh_peer);
868 reason = g_supplicant_mesh_peer_get_disconnect_reason(mesh_peer);
870 DBG("Peer %s disconnected with reason %d", peer_address, reason);
871 connman_mesh_remove_connected_peer(peer_address, reason);
875 static struct wifi_data *get_pending_wifi_data(const char *ifname)
879 for (list = pending_wifi_device; list; list = list->next) {
880 struct wifi_data *wifi;
881 const char *dev_name;
884 if (!wifi || !wifi->device)
887 dev_name = connman_device_get_string(wifi->device, "Interface");
888 if (!g_strcmp0(ifname, dev_name)) {
889 pending_wifi_device = g_list_delete_link(
890 pending_wifi_device, list);
898 static void remove_pending_wifi_device(struct wifi_data *wifi)
902 link = g_list_find(pending_wifi_device, wifi);
907 pending_wifi_device = g_list_delete_link(pending_wifi_device, link);
910 static void peer_cancel_timeout(struct wifi_data *wifi)
912 if (wifi->p2p_connection_timeout > 0)
913 g_source_remove(wifi->p2p_connection_timeout);
915 wifi->p2p_connection_timeout = 0;
916 wifi->p2p_connecting = false;
918 if (wifi->pending_peer) {
919 connman_peer_unref(wifi->pending_peer);
920 wifi->pending_peer = NULL;
924 static gboolean peer_connect_timeout(gpointer data)
926 struct wifi_data *wifi = data;
930 if (wifi->p2p_connecting) {
931 enum connman_peer_state state = CONNMAN_PEER_STATE_FAILURE;
932 GSupplicantPeer *gs_peer =
933 g_supplicant_interface_peer_lookup(wifi->interface,
934 connman_peer_get_identifier(wifi->pending_peer));
936 if (g_supplicant_peer_has_requested_connection(gs_peer))
937 state = CONNMAN_PEER_STATE_IDLE;
939 connman_peer_set_state(wifi->pending_peer, state);
942 peer_cancel_timeout(wifi);
947 static void peer_connect_callback(int result, GSupplicantInterface *interface,
950 struct wifi_data *wifi = user_data;
951 struct connman_peer *peer = wifi->pending_peer;
953 DBG("peer %p - %d", peer, result);
959 peer_connect_timeout(wifi);
963 connman_peer_set_state(peer, CONNMAN_PEER_STATE_ASSOCIATION);
965 wifi->p2p_connection_timeout = g_timeout_add_seconds(
966 P2P_CONNECTION_TIMEOUT,
967 peer_connect_timeout, wifi);
970 static int peer_connect(struct connman_peer *peer,
971 enum connman_peer_wps_method wps_method,
974 struct connman_device *device = connman_peer_get_device(peer);
975 GSupplicantPeerParams *peer_params;
976 GSupplicantPeer *gs_peer;
977 struct wifi_data *wifi;
981 DBG("peer %p", peer);
986 wifi = connman_device_get_data(device);
987 if (!wifi || !wifi->interface)
990 if (wifi->p2p_connecting)
993 gs_peer = g_supplicant_interface_peer_lookup(wifi->interface,
994 connman_peer_get_identifier(peer));
998 pbc = g_supplicant_peer_is_wps_pbc(gs_peer);
999 pin = g_supplicant_peer_is_wps_pin(gs_peer);
1001 switch (wps_method) {
1002 case CONNMAN_PEER_WPS_UNKNOWN:
1003 if ((pbc && pin) || pin)
1006 case CONNMAN_PEER_WPS_PBC:
1011 case CONNMAN_PEER_WPS_PIN:
1012 if (!pin || !wps_pin)
1017 peer_params = g_try_malloc0(sizeof(GSupplicantPeerParams));
1021 peer_params->path = g_strdup(g_supplicant_peer_get_path(gs_peer));
1023 peer_params->wps_pin = g_strdup(wps_pin);
1025 peer_params->master = connman_peer_service_is_master();
1027 ret = g_supplicant_interface_p2p_connect(wifi->interface, peer_params,
1028 peer_connect_callback, wifi);
1029 if (ret == -EINPROGRESS) {
1030 wifi->pending_peer = connman_peer_ref(peer);
1031 wifi->p2p_connecting = true;
1032 } else if (ret < 0) {
1033 g_free(peer_params->path);
1034 g_free(peer_params->wps_pin);
1035 g_free(peer_params);
1041 static int peer_disconnect(struct connman_peer *peer)
1043 struct connman_device *device = connman_peer_get_device(peer);
1044 GSupplicantPeerParams peer_params = {};
1045 GSupplicantPeer *gs_peer;
1046 struct wifi_data *wifi;
1049 DBG("peer %p", peer);
1054 wifi = connman_device_get_data(device);
1058 gs_peer = g_supplicant_interface_peer_lookup(wifi->interface,
1059 connman_peer_get_identifier(peer));
1063 peer_params.path = g_strdup(g_supplicant_peer_get_path(gs_peer));
1065 ret = g_supplicant_interface_p2p_disconnect(wifi->interface,
1067 g_free(peer_params.path);
1069 if (ret == -EINPROGRESS) {
1070 peer_cancel_timeout(wifi);
1071 wifi->p2p_device = false;
1077 struct peer_service_registration {
1078 peer_service_registration_cb_t callback;
1082 static bool is_service_wfd(const unsigned char *specs, int length)
1084 if (length < 9 || specs[0] != 0 || specs[1] != 0 || specs[2] != 6)
1090 static void apply_p2p_listen_on_iface(gpointer data, gpointer user_data)
1092 struct wifi_data *wifi = data;
1094 if (!wifi->interface ||
1095 !g_supplicant_interface_has_p2p(wifi->interface))
1098 if (!wifi->servicing) {
1099 g_supplicant_interface_p2p_listen(wifi->interface,
1100 P2P_LISTEN_PERIOD, P2P_LISTEN_INTERVAL);
1106 static void register_wfd_service_cb(int result,
1107 GSupplicantInterface *iface, void *user_data)
1109 struct peer_service_registration *reg_data = user_data;
1114 g_list_foreach(iface_list, apply_p2p_listen_on_iface, NULL);
1116 if (reg_data && reg_data->callback) {
1117 reg_data->callback(result, reg_data->user_data);
1122 static GSupplicantP2PServiceParams *fill_in_peer_service_params(
1123 const unsigned char *spec,
1124 int spec_length, const unsigned char *query,
1125 int query_length, int version)
1127 GSupplicantP2PServiceParams *params;
1129 params = g_try_malloc0(sizeof(GSupplicantP2PServiceParams));
1134 params->version = version;
1135 params->service = g_memdup(spec, spec_length);
1136 } else if (query_length > 0 && spec_length > 0) {
1137 params->query = g_memdup(query, query_length);
1138 params->query_length = query_length;
1140 params->response = g_memdup(spec, spec_length);
1141 params->response_length = spec_length;
1143 params->wfd_ies = g_memdup(spec, spec_length);
1144 params->wfd_ies_length = spec_length;
1150 static void free_peer_service_params(GSupplicantP2PServiceParams *params)
1155 g_free(params->service);
1156 g_free(params->query);
1157 g_free(params->response);
1158 g_free(params->wfd_ies);
1163 static int peer_register_wfd_service(const unsigned char *specification,
1164 int specification_length,
1165 peer_service_registration_cb_t callback,
1168 struct peer_service_registration *reg_data = NULL;
1169 static GSupplicantP2PServiceParams *params;
1174 if (wfd_service_registered)
1177 params = fill_in_peer_service_params(specification,
1178 specification_length, NULL, 0, 0);
1182 reg_data = g_try_malloc0(sizeof(*reg_data));
1188 reg_data->callback = callback;
1189 reg_data->user_data = user_data;
1191 ret = g_supplicant_set_widi_ies(params,
1192 register_wfd_service_cb, reg_data);
1193 if (ret < 0 && ret != -EINPROGRESS)
1196 wfd_service_registered = true;
1200 free_peer_service_params(params);
1206 static void register_peer_service_cb(int result,
1207 GSupplicantInterface *iface, void *user_data)
1209 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
1210 struct peer_service_registration *reg_data = user_data;
1212 #if defined TIZEN_EXT
1220 apply_p2p_listen_on_iface(wifi, NULL);
1222 if (reg_data->callback)
1223 reg_data->callback(result, reg_data->user_data);
1228 static int peer_register_service(const unsigned char *specification,
1229 int specification_length,
1230 const unsigned char *query,
1231 int query_length, int version,
1232 peer_service_registration_cb_t callback,
1235 struct peer_service_registration *reg_data;
1236 GSupplicantP2PServiceParams *params;
1243 if (specification && !version && !query &&
1244 is_service_wfd(specification, specification_length)) {
1245 return peer_register_wfd_service(specification,
1246 specification_length, callback, user_data);
1249 reg_data = g_try_malloc0(sizeof(*reg_data));
1253 reg_data->callback = callback;
1254 reg_data->user_data = user_data;
1256 ret_f = -EOPNOTSUPP;
1258 for (list = iface_list; list; list = list->next) {
1259 struct wifi_data *wifi = list->data;
1260 GSupplicantInterface *iface = wifi->interface;
1262 if (!g_supplicant_interface_has_p2p(iface))
1265 params = fill_in_peer_service_params(specification,
1266 specification_length, query,
1267 query_length, version);
1272 ret_f = g_supplicant_interface_p2p_add_service(iface,
1273 register_peer_service_cb, params, reg_data);
1274 if (ret_f == 0 || ret_f == -EINPROGRESS)
1278 ret = g_supplicant_interface_p2p_add_service(iface,
1279 register_peer_service_cb, params, NULL);
1280 if (ret != 0 && ret != -EINPROGRESS)
1281 free_peer_service_params(params);
1284 if (ret_f != 0 && ret_f != -EINPROGRESS)
1290 static int peer_unregister_wfd_service(void)
1292 GSupplicantP2PServiceParams *params;
1295 if (!wfd_service_registered)
1298 params = fill_in_peer_service_params(NULL, 0, NULL, 0, 0);
1302 wfd_service_registered = false;
1304 g_supplicant_set_widi_ies(params, NULL, NULL);
1306 for (list = iface_list; list; list = list->next) {
1307 struct wifi_data *wifi = list->data;
1309 if (!g_supplicant_interface_has_p2p(wifi->interface))
1313 if (!wifi->servicing || wifi->servicing < 0) {
1314 g_supplicant_interface_p2p_listen(wifi->interface,
1316 wifi->servicing = 0;
1323 static int peer_unregister_service(const unsigned char *specification,
1324 int specification_length,
1325 const unsigned char *query,
1326 int query_length, int version)
1328 GSupplicantP2PServiceParams *params;
1333 if (specification && !version && !query &&
1334 is_service_wfd(specification, specification_length)) {
1335 ret = peer_unregister_wfd_service();
1336 if (ret != 0 && ret != -EINPROGRESS)
1341 for (list = iface_list; list; list = list->next) {
1342 struct wifi_data *wifi = list->data;
1343 GSupplicantInterface *iface = wifi->interface;
1346 goto stop_listening;
1348 if (!g_supplicant_interface_has_p2p(iface))
1351 params = fill_in_peer_service_params(specification,
1352 specification_length, query,
1353 query_length, version);
1357 ret = g_supplicant_interface_p2p_del_service(iface, params);
1358 if (ret != 0 && ret != -EINPROGRESS)
1359 free_peer_service_params(params);
1362 if (!wifi->servicing || wifi->servicing < 0) {
1363 g_supplicant_interface_p2p_listen(iface, 0, 0);
1364 wifi->servicing = 0;
1371 static struct connman_peer_driver peer_driver = {
1372 .connect = peer_connect,
1373 .disconnect = peer_disconnect,
1374 .register_service = peer_register_service,
1375 .unregister_service = peer_unregister_service,
1378 static void handle_tethering(struct wifi_data *wifi)
1380 if (!wifi->tethering)
1389 DBG("index %d bridge %s", wifi->index, wifi->bridge);
1391 if (connman_inet_add_to_bridge(wifi->index, wifi->bridge) < 0)
1394 wifi->bridged = true;
1397 static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
1399 struct connman_device *device = user_data;
1400 struct wifi_data *wifi = connman_device_get_data(device);
1405 DBG("index %d flags %d change %d", wifi->index, flags, change);
1407 if ((wifi->flags & IFF_UP) != (flags & IFF_UP)) {
1409 DBG("interface up");
1411 DBG("interface down");
1414 if ((wifi->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
1415 if (flags & IFF_LOWER_UP) {
1418 handle_tethering(wifi);
1423 wifi->flags = flags;
1426 static int wifi_probe(struct connman_device *device)
1428 struct wifi_data *wifi;
1430 DBG("device %p", device);
1432 wifi = g_try_new0(struct wifi_data, 1);
1436 wifi->state = G_SUPPLICANT_STATE_INACTIVE;
1437 wifi->ap_supported = WIFI_AP_UNKNOWN;
1438 wifi->tethering_param = NULL;
1440 connman_device_set_data(device, wifi);
1441 wifi->device = connman_device_ref(device);
1443 wifi->index = connman_device_get_index(device);
1446 wifi->watch = connman_rtnl_add_newlink_watch(wifi->index,
1447 wifi_newlink, device);
1448 if (is_p2p_connecting())
1449 add_pending_wifi_device(wifi);
1451 iface_list = g_list_append(iface_list, wifi);
1456 static void remove_networks(struct connman_device *device,
1457 struct wifi_data *wifi)
1461 for (list = wifi->networks; list; list = list->next) {
1462 struct connman_network *network = list->data;
1464 connman_device_remove_network(device, network);
1465 connman_network_unref(network);
1468 g_slist_free(wifi->networks);
1469 wifi->networks = NULL;
1472 static void remove_peers(struct wifi_data *wifi)
1476 for (list = wifi->peers; list; list = list->next) {
1477 struct connman_peer *peer = list->data;
1479 connman_peer_unregister(peer);
1480 connman_peer_unref(peer);
1483 g_slist_free(wifi->peers);
1487 static void reset_autoscan(struct connman_device *device)
1489 struct wifi_data *wifi = connman_device_get_data(device);
1490 struct autoscan_params *autoscan;
1494 if (!wifi || !wifi->autoscan)
1497 autoscan = wifi->autoscan;
1499 autoscan->interval = 0;
1501 if (autoscan->timeout == 0)
1504 g_source_remove(autoscan->timeout);
1505 autoscan->timeout = 0;
1507 connman_device_unref(device);
1510 static void stop_autoscan(struct connman_device *device)
1512 const struct wifi_data *wifi = connman_device_get_data(device);
1514 if (!wifi || !wifi->autoscan)
1517 reset_autoscan(device);
1519 connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_WIFI, false);
1522 static void check_p2p_technology(void)
1524 bool p2p_exists = false;
1527 for (list = iface_list; list; list = list->next) {
1528 struct wifi_data *w = list->data;
1531 g_supplicant_interface_has_p2p(w->interface))
1536 connman_technology_driver_unregister(&p2p_tech_driver);
1537 connman_peer_driver_unregister(&peer_driver);
1541 struct last_connected {
1547 static gint sort_entry(gconstpointer a, gconstpointer b, gpointer user_data)
1549 GTimeVal *aval = (GTimeVal *)a;
1550 GTimeVal *bval = (GTimeVal *)b;
1552 /* Note that the sort order is descending */
1553 if (aval->tv_sec < bval->tv_sec)
1556 if (aval->tv_sec > bval->tv_sec)
1562 static void free_entry(gpointer data)
1564 struct last_connected *entry = data;
1566 g_free(entry->ssid);
1570 static void wifi_remove(struct connman_device *device)
1572 struct wifi_data *wifi = connman_device_get_data(device);
1574 DBG("device %p wifi %p", device, wifi);
1579 stop_autoscan(device);
1581 if (wifi->p2p_device)
1582 p2p_iface_list = g_list_remove(p2p_iface_list, wifi);
1584 iface_list = g_list_remove(iface_list, wifi);
1586 check_p2p_technology();
1587 #if defined TIZEN_EXT_WIFI_MESH
1588 check_mesh_technology();
1591 remove_pending_wifi_device(wifi);
1593 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_P2P)) {
1594 g_source_remove(wifi->p2p_find_timeout);
1595 connman_device_unref(wifi->device);
1598 if (wifi->p2p_connection_timeout)
1599 g_source_remove(wifi->p2p_connection_timeout);
1601 #if defined TIZEN_EXT
1602 if (wifi->automaxspeed_timeout != 0) {
1603 g_source_remove(wifi->automaxspeed_timeout);
1604 wifi->automaxspeed_timeout = 0;
1608 remove_networks(device, wifi);
1611 connman_device_set_powered(device, false);
1612 connman_device_set_data(device, NULL);
1613 connman_device_unref(wifi->device);
1614 connman_rtnl_remove_watch(wifi->watch);
1616 g_supplicant_interface_set_data(wifi->interface, NULL);
1618 g_supplicant_interface_cancel(wifi->interface);
1620 if (wifi->scan_params)
1621 g_supplicant_free_scan_params(wifi->scan_params);
1622 #if defined TIZEN_EXT
1623 if (wifi->hidden_scan_params) {
1624 while (wifi->hidden_scan_params->ssids) {
1625 struct scan_ssid *ssid;
1626 ssid = wifi->hidden_scan_params->ssids->data;
1627 wifi->hidden_scan_params->ssids = g_slist_remove(wifi->hidden_scan_params->ssids, ssid);
1629 g_supplicant_free_scan_params(wifi->hidden_scan_params);
1633 g_free(wifi->autoscan);
1634 g_free(wifi->identifier);
1638 static bool is_duplicate(GSList *list, gchar *ssid, int ssid_len)
1642 for (iter = list; iter; iter = g_slist_next(iter)) {
1643 struct scan_ssid *scan_ssid = iter->data;
1645 if (ssid_len == scan_ssid->ssid_len &&
1646 memcmp(ssid, scan_ssid->ssid, ssid_len) == 0)
1653 static int add_scan_param(gchar *hex_ssid, char *raw_ssid, int ssid_len,
1654 int freq, GSupplicantScanParams *scan_data,
1655 int driver_max_scan_ssids, char *ssid_name)
1658 struct scan_ssid *scan_ssid;
1660 if ((driver_max_scan_ssids == 0 ||
1661 driver_max_scan_ssids > scan_data->num_ssids) &&
1662 (hex_ssid || raw_ssid)) {
1664 unsigned int j = 0, hex;
1667 size_t hex_ssid_len = strlen(hex_ssid);
1669 ssid = g_try_malloc0(hex_ssid_len / 2);
1673 for (i = 0; i < hex_ssid_len; i += 2) {
1674 sscanf(hex_ssid + i, "%02x", &hex);
1683 * If we have already added hidden AP to the list,
1684 * then do not do it again. This might happen if you have
1685 * used or are using multiple wifi cards, so in that case
1686 * you might have multiple service files for same AP.
1688 if (is_duplicate(scan_data->ssids, ssid, j)) {
1694 scan_ssid = g_try_new(struct scan_ssid, 1);
1701 memcpy(scan_ssid->ssid, ssid, j);
1702 scan_ssid->ssid_len = j;
1703 scan_data->ssids = g_slist_prepend(scan_data->ssids,
1706 scan_data->num_ssids++;
1708 DBG("SSID %s added to scanned list of %d entries", ssid_name,
1709 scan_data->num_ssids);
1716 scan_data->ssids = g_slist_reverse(scan_data->ssids);
1718 if (!scan_data->freqs) {
1719 scan_data->freqs = g_try_malloc0(sizeof(uint16_t));
1720 if (!scan_data->freqs) {
1721 g_slist_free_full(scan_data->ssids, g_free);
1725 scan_data->num_freqs = 1;
1726 scan_data->freqs[0] = freq;
1728 bool duplicate = false;
1730 /* Don't add duplicate entries */
1731 for (i = 0; i < scan_data->num_freqs; i++) {
1732 if (scan_data->freqs[i] == freq) {
1739 scan_data->num_freqs++;
1740 scan_data->freqs = g_try_realloc(scan_data->freqs,
1741 sizeof(uint16_t) * scan_data->num_freqs);
1742 if (!scan_data->freqs) {
1743 g_slist_free_full(scan_data->ssids, g_free);
1746 scan_data->freqs[scan_data->num_freqs - 1] = freq;
1753 static int get_hidden_connections(GSupplicantScanParams *scan_data)
1755 struct connman_config_entry **entries;
1757 #if defined TIZEN_EXT
1758 gchar **services = NULL;
1761 #endif /* defined TIZEN_EXT */
1765 int num_ssids = 0, add_param_failed = 0;
1766 #if defined TIZEN_EXT
1767 GSequenceIter *iter;
1768 GSequence *latest_list;
1769 struct last_connected *entry;
1772 latest_list = g_sequence_new(free_entry);
1776 services = connman_storage_get_services();
1777 for (i = 0; services && services[i]; i++) {
1778 if (strncmp(services[i], "wifi_", 5) != 0)
1781 keyfile = connman_storage_load_service(services[i]);
1785 value = g_key_file_get_boolean(keyfile,
1786 services[i], "Hidden", NULL);
1788 g_key_file_free(keyfile);
1792 value = g_key_file_get_boolean(keyfile,
1793 services[i], "Favorite", NULL);
1795 g_key_file_free(keyfile);
1799 #if defined TIZEN_EXT
1800 value = g_key_file_get_boolean(keyfile,
1801 services[i], "AutoConnect", NULL);
1803 g_key_file_free(keyfile);
1807 gchar *str = g_key_file_get_string(keyfile,
1808 services[i], "Modified", NULL);
1810 g_key_file_free(keyfile);
1813 g_time_val_from_iso8601(str, &modified);
1817 ssid = g_key_file_get_string(keyfile,
1818 services[i], "SSID", NULL);
1820 name = g_key_file_get_string(keyfile, services[i], "Name",
1823 #if defined TIZEN_EXT
1824 entry = g_try_new(struct last_connected, 1);
1826 g_sequence_free(latest_list);
1829 g_key_file_free(keyfile);
1833 entry->modified = modified;
1836 g_sequence_insert_sorted(latest_list, entry,
1839 ret = add_scan_param(ssid, NULL, 0, 0, scan_data, 0, name);
1848 g_key_file_free(keyfile);
1851 #if defined TIZEN_EXT
1852 gint length = g_sequence_get_length(latest_list);
1853 iter = g_sequence_get_begin_iter(latest_list);
1855 for (i = 0; i < length; i++) {
1856 entry = g_sequence_get(iter);
1858 ret = add_scan_param(entry->ssid, NULL, 0, 0, scan_data, 0, entry->ssid);
1864 iter = g_sequence_iter_next(iter);
1867 g_sequence_free(latest_list);
1871 * Check if there are any hidden AP that needs to be provisioned.
1873 entries = connman_config_get_entries("wifi");
1874 for (i = 0; entries && entries[i]; i++) {
1877 if (!entries[i]->hidden)
1880 if (!entries[i]->ssid) {
1881 ssid = entries[i]->name;
1884 ssid = entries[i]->ssid;
1885 len = entries[i]->ssid_len;
1891 ret = add_scan_param(NULL, ssid, len, 0, scan_data, 0, ssid);
1898 connman_config_free_entries(entries);
1900 if (add_param_failed > 0)
1901 DBG("Unable to scan %d out of %d SSIDs",
1902 add_param_failed, num_ssids);
1904 g_strfreev(services);
1909 static int get_hidden_connections_params(struct wifi_data *wifi,
1910 GSupplicantScanParams *scan_params)
1912 int driver_max_ssids, i;
1913 GSupplicantScanParams *orig_params;
1916 * Scan hidden networks so that we can autoconnect to them.
1917 * We will assume 1 as a default number of ssid to scan.
1919 driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
1921 if (driver_max_ssids == 0)
1922 driver_max_ssids = 1;
1924 DBG("max ssids %d", driver_max_ssids);
1926 #if defined TIZEN_EXT
1927 if (!wifi->hidden_scan_params) {
1928 wifi->hidden_scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
1929 if (!wifi->hidden_scan_params)
1932 if (get_hidden_connections(wifi->hidden_scan_params) == 0) {
1933 g_supplicant_free_scan_params(wifi->hidden_scan_params);
1934 wifi->hidden_scan_params = NULL;
1940 orig_params = wifi->hidden_scan_params;
1942 if (!wifi->scan_params) {
1943 wifi->scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
1944 if (!wifi->scan_params)
1947 if (get_hidden_connections(wifi->scan_params) == 0) {
1948 g_supplicant_free_scan_params(wifi->scan_params);
1949 wifi->scan_params = NULL;
1955 orig_params = wifi->scan_params;
1958 /* Let's transfer driver_max_ssids params */
1959 for (i = 0; i < driver_max_ssids; i++) {
1960 struct scan_ssid *ssid;
1962 #if defined TIZEN_EXT
1963 if (!wifi->hidden_scan_params->ssids)
1965 if (!wifi->scan_params->ssids)
1969 ssid = orig_params->ssids->data;
1970 orig_params->ssids = g_slist_remove(orig_params->ssids, ssid);
1971 scan_params->ssids = g_slist_prepend(scan_params->ssids, ssid);
1975 scan_params->num_ssids = i;
1976 scan_params->ssids = g_slist_reverse(scan_params->ssids);
1978 scan_params->freqs = g_memdup(orig_params->freqs,
1979 sizeof(uint16_t) * orig_params->num_freqs);
1980 if (!scan_params->freqs)
1983 scan_params->num_freqs = orig_params->num_freqs;
1988 orig_params->num_ssids -= scan_params->num_ssids;
1990 return scan_params->num_ssids;
1993 g_slist_free_full(scan_params->ssids, g_free);
1994 #if defined TIZEN_EXT
1995 g_supplicant_free_scan_params(wifi->hidden_scan_params);
1996 wifi->hidden_scan_params = NULL;
1998 g_supplicant_free_scan_params(wifi->scan_params);
1999 wifi->scan_params = NULL;
2005 static int throw_wifi_scan(struct connman_device *device,
2006 GSupplicantInterfaceCallback callback)
2008 struct wifi_data *wifi = connman_device_get_data(device);
2014 DBG("device %p %p", device, wifi->interface);
2016 if (wifi->tethering)
2019 #if defined TIZEN_EXT
2020 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI)
2021 && !wifi->allow_full_scan)
2023 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI))
2027 connman_device_ref(device);
2029 ret = g_supplicant_interface_scan(wifi->interface, NULL,
2032 connman_device_set_scanning(device,
2033 CONNMAN_SERVICE_TYPE_WIFI, true);
2035 connman_device_unref(device);
2040 static void hidden_free(struct hidden_params *hidden)
2045 if (hidden->scan_params)
2046 g_supplicant_free_scan_params(hidden->scan_params);
2047 g_free(hidden->identity);
2048 g_free(hidden->passphrase);
2049 g_free(hidden->security);
2053 #if defined TIZEN_EXT
2054 static void service_state_changed(struct connman_service *service,
2055 enum connman_service_state state);
2057 static int network_connect(struct connman_network *network);
2059 static struct connman_notifier notifier = {
2061 .priority = CONNMAN_NOTIFIER_PRIORITY_DEFAULT,
2062 .service_state_changed = service_state_changed,
2065 static void service_state_changed(struct connman_service *service,
2066 enum connman_service_state state)
2068 enum connman_service_type type;
2070 type = connman_service_get_type(service);
2071 if (type != CONNMAN_SERVICE_TYPE_WIFI)
2074 DBG("service %p state %d", service, state);
2077 case CONNMAN_SERVICE_STATE_READY:
2078 case CONNMAN_SERVICE_STATE_ONLINE:
2079 case CONNMAN_SERVICE_STATE_FAILURE:
2080 connman_notifier_unregister(¬ifier);
2081 is_wifi_notifier_registered = FALSE;
2083 __connman_device_request_scan(type);
2091 static void scan_callback_hidden(int result,
2092 GSupplicantInterface *interface, void *user_data);
2095 static void scan_callback(int result, GSupplicantInterface *interface,
2098 struct connman_device *device = user_data;
2099 struct wifi_data *wifi = connman_device_get_data(device);
2101 #if defined TIZEN_EXT
2102 GSList *list = NULL;
2103 bool favorite_exists = false;
2104 struct connman_network *network = NULL;
2105 struct connman_service *service = NULL;
2108 DBG("result %d wifi %p", result, wifi);
2111 if (wifi->hidden && !wifi->postpone_hidden) {
2112 connman_network_clear_hidden(wifi->hidden->user_data);
2113 hidden_free(wifi->hidden);
2114 wifi->hidden = NULL;
2117 if (wifi->scan_params) {
2118 g_supplicant_free_scan_params(wifi->scan_params);
2119 wifi->scan_params = NULL;
2122 #if defined TIZEN_EXT
2123 if (wifi->hidden_scan_params && !wifi->hidden_scan_params->ssids) {
2124 g_supplicant_free_scan_params(wifi->hidden_scan_params);
2125 wifi->hidden_scan_params = NULL;
2131 connman_device_reset_scanning(device);
2133 /* User is connecting to a hidden AP, let's wait for finished event */
2134 if (wifi && wifi->hidden && wifi->postpone_hidden) {
2135 GSupplicantScanParams *scan_params;
2138 wifi->postpone_hidden = false;
2139 scan_params = wifi->hidden->scan_params;
2140 wifi->hidden->scan_params = NULL;
2142 reset_autoscan(device);
2144 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
2145 scan_callback, device);
2149 /* On error, let's recall scan_callback, which will cleanup */
2150 return scan_callback(ret, interface, user_data);
2153 #if defined TIZEN_EXT
2155 for (list = wifi->networks; list; list = list->next) {
2156 network = list->data;
2157 service = connman_service_lookup_from_network(network);
2159 if (service != NULL &&
2160 (connman_service_get_favorite(service) == true) &&
2161 (connman_service_get_autoconnect(service) == true)) {
2162 DBG("Favorite service exists [%s]", connman_network_get_string(network, "Name"));
2163 favorite_exists = true;
2169 if (favorite_exists == false) {
2170 if (wifi && wifi->allow_full_scan) {
2172 DBG("Trigger full channel scan");
2173 wifi->allow_full_scan = false;
2175 ret = g_supplicant_interface_scan(wifi->interface, NULL,
2176 scan_callback_hidden, device);
2180 /* On error, let's recall scan_callback, which will cleanup */
2181 return scan_callback(ret, interface, user_data);
2184 wifi->allow_full_scan = false;
2187 scanning = connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI);
2190 connman_device_set_scanning(device,
2191 CONNMAN_SERVICE_TYPE_WIFI, false);
2194 if (result != -ENOLINK)
2195 #if defined TIZEN_EXT
2198 start_autoscan(device);
2201 * If we are here then we were scanning; however, if we are
2202 * also mid-flight disabling the interface, then wifi_disable
2203 * has already cleared the device scanning state and
2204 * unreferenced the device, obviating the need to do it here.
2208 connman_device_unref(device);
2210 #if defined TIZEN_EXT
2211 if (wifi && wifi->scan_pending_network && result != -EIO) {
2212 network_connect(wifi->scan_pending_network);
2213 wifi->scan_pending_network = NULL;
2214 connman_network_set_connecting(wifi->network);
2217 if (is_wifi_notifier_registered != true &&
2218 wifi_first_scan == true && found_with_first_scan == true) {
2219 wifi_first_scan = false;
2220 found_with_first_scan = false;
2222 connman_notifier_register(¬ifier);
2223 is_wifi_notifier_registered = true;
2228 static void scan_callback_hidden(int result,
2229 GSupplicantInterface *interface, void *user_data)
2231 struct connman_device *device = user_data;
2232 struct wifi_data *wifi = connman_device_get_data(device);
2233 GSupplicantScanParams *scan_params;
2236 DBG("result %d wifi %p", result, wifi);
2241 /* User is trying to connect to a hidden AP */
2242 if (wifi->hidden && wifi->postpone_hidden)
2245 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2249 if (get_hidden_connections_params(wifi, scan_params) > 0) {
2250 ret = g_supplicant_interface_scan(wifi->interface,
2252 #if defined TIZEN_EXT
2255 scan_callback_hidden,
2262 g_supplicant_free_scan_params(scan_params);
2265 scan_callback(result, interface, user_data);
2268 static gboolean autoscan_timeout(gpointer data)
2270 struct connman_device *device = data;
2271 struct wifi_data *wifi = connman_device_get_data(device);
2272 struct autoscan_params *autoscan;
2278 autoscan = wifi->autoscan;
2280 #if defined TIZEN_EXT
2285 if (autoscan->interval <= 0) {
2286 interval = autoscan->base;
2289 interval = autoscan->interval * autoscan->base;
2291 #if defined TIZEN_EXT
2292 if (autoscan->interval >= autoscan->limit)
2294 if (interval > autoscan->limit)
2296 interval = autoscan->limit;
2298 throw_wifi_scan(wifi->device, scan_callback_hidden);
2301 * In case BackgroundScanning is disabled, interval will reach the
2302 * limit exactly after the very first passive scanning. It allows
2303 * to ensure at most one passive scan is performed in such cases.
2305 if (!connman_setting_get_bool("BackgroundScanning") &&
2306 interval == autoscan->limit) {
2307 g_source_remove(autoscan->timeout);
2308 autoscan->timeout = 0;
2310 connman_device_unref(device);
2316 DBG("interval %d", interval);
2318 autoscan->interval = interval;
2320 autoscan->timeout = g_timeout_add_seconds(interval,
2321 autoscan_timeout, device);
2326 static void start_autoscan(struct connman_device *device)
2328 struct wifi_data *wifi = connman_device_get_data(device);
2329 struct autoscan_params *autoscan;
2336 if (wifi->p2p_device)
2339 if (wifi->connected)
2342 autoscan = wifi->autoscan;
2346 if (autoscan->timeout > 0 || autoscan->interval > 0)
2349 connman_device_ref(device);
2351 autoscan_timeout(device);
2354 static struct autoscan_params *parse_autoscan_params(const char *params)
2356 struct autoscan_params *autoscan;
2363 list_params = g_strsplit(params, ":", 0);
2364 if (list_params == 0)
2367 if (!g_strcmp0(list_params[0], "exponential") &&
2368 g_strv_length(list_params) == 3) {
2369 base = atoi(list_params[1]);
2370 limit = atoi(list_params[2]);
2371 } else if (!g_strcmp0(list_params[0], "single") &&
2372 g_strv_length(list_params) == 2)
2373 base = limit = atoi(list_params[1]);
2375 g_strfreev(list_params);
2379 DBG("Setup %s autoscanning", list_params[0]);
2381 g_strfreev(list_params);
2383 autoscan = g_try_malloc0(sizeof(struct autoscan_params));
2385 DBG("Could not allocate memory for autoscan");
2389 DBG("base %d - limit %d", base, limit);
2390 autoscan->base = base;
2391 autoscan->limit = limit;
2396 static void setup_autoscan(struct wifi_data *wifi)
2399 * If BackgroundScanning is enabled, setup exponential
2400 * autoscanning if it has not been previously done.
2402 if (connman_setting_get_bool("BackgroundScanning")) {
2403 wifi->autoscan = parse_autoscan_params(AUTOSCAN_EXPONENTIAL);
2406 #if defined TIZEN_EXT
2408 if (wifi->autoscan) {
2409 g_free(wifi->autoscan);
2410 wifi->autoscan = NULL;
2413 DBG("BackgroundScanning is disabled");
2420 * On the contrary, if BackgroundScanning is disabled, update autoscan
2421 * parameters based on the type of scanning that is being performed.
2423 if (wifi->autoscan) {
2424 g_free(wifi->autoscan);
2425 wifi->autoscan = NULL;
2428 switch (wifi->scanning_type) {
2429 case WIFI_SCANNING_PASSIVE:
2430 /* Do not setup autoscan. */
2432 case WIFI_SCANNING_ACTIVE:
2433 /* Setup one single passive scan after active. */
2434 wifi->autoscan = parse_autoscan_params(AUTOSCAN_SINGLE);
2436 case WIFI_SCANNING_UNKNOWN:
2437 /* Setup autoscan in this case but we should never fall here. */
2438 wifi->autoscan = parse_autoscan_params(AUTOSCAN_SINGLE);
2444 static void finalize_interface_creation(struct wifi_data *wifi)
2446 DBG("interface is ready wifi %p tethering %d", wifi, wifi->tethering);
2448 if (!wifi->device) {
2449 connman_error("WiFi device not set");
2453 connman_device_set_powered(wifi->device, true);
2455 if (wifi->p2p_device)
2458 if (!wifi->autoscan)
2459 setup_autoscan(wifi);
2461 start_autoscan(wifi->device);
2464 static void interface_create_callback(int result,
2465 GSupplicantInterface *interface,
2468 struct wifi_data *wifi = user_data;
2470 DBG("result %d ifname %s, wifi %p", result,
2471 g_supplicant_interface_get_ifname(interface),
2474 if (result < 0 || !wifi)
2477 wifi->interface = interface;
2478 g_supplicant_interface_set_data(interface, wifi);
2480 if (g_supplicant_interface_get_ready(interface)) {
2481 wifi->interface_ready = true;
2482 finalize_interface_creation(wifi);
2486 static int wifi_enable(struct connman_device *device)
2488 struct wifi_data *wifi = connman_device_get_data(device);
2491 const char *driver = connman_option_get_string("wifi");
2494 DBG("device %p %p", device, wifi);
2496 index = connman_device_get_index(device);
2497 if (!wifi || index < 0)
2500 if (is_p2p_connecting())
2501 return -EINPROGRESS;
2503 interface = connman_inet_ifname(index);
2504 ret = g_supplicant_interface_create(interface, driver, NULL,
2506 connman_device_get_mac_policy(device),
2507 connman_device_get_preassoc_mac_policy(device),
2508 connman_device_get_random_mac_lifetime(device),
2509 #endif /* TIZEN_EXT */
2510 interface_create_callback,
2517 return -EINPROGRESS;
2520 static int wifi_disable(struct connman_device *device)
2522 struct wifi_data *wifi = connman_device_get_data(device);
2525 DBG("device %p wifi %p", device, wifi);
2530 wifi->connected = false;
2531 wifi->disconnecting = false;
2533 if (wifi->pending_network)
2534 wifi->pending_network = NULL;
2536 #if !defined TIZEN_EXT
2537 stop_autoscan(device);
2540 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_P2P)) {
2541 g_source_remove(wifi->p2p_find_timeout);
2542 wifi->p2p_find_timeout = 0;
2543 connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_P2P, false);
2544 connman_device_unref(wifi->device);
2547 #if defined TIZEN_EXT
2548 if (wifi->automaxspeed_timeout != 0) {
2549 g_source_remove(wifi->automaxspeed_timeout);
2550 wifi->automaxspeed_timeout = 0;
2554 /* In case of a user scan, device is still referenced */
2555 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI)) {
2556 connman_device_set_scanning(device,
2557 CONNMAN_SERVICE_TYPE_WIFI, false);
2558 connman_device_unref(wifi->device);
2561 #if defined TIZEN_EXT
2562 stop_autoscan(device);
2565 remove_networks(device, wifi);
2568 #if defined TIZEN_EXT
2569 wifi->scan_pending_network = NULL;
2571 if (is_wifi_notifier_registered == true) {
2572 connman_notifier_unregister(¬ifier);
2573 is_wifi_notifier_registered = false;
2577 ret = g_supplicant_interface_remove(wifi->interface, NULL, NULL);
2581 return -EINPROGRESS;
2584 static int get_latest_connections(int max_ssids,
2585 GSupplicantScanParams *scan_data)
2587 GSequenceIter *iter;
2588 GSequence *latest_list;
2589 struct last_connected *entry;
2598 latest_list = g_sequence_new(free_entry);
2602 services = connman_storage_get_services();
2603 for (i = 0; services && services[i]; i++) {
2604 if (strncmp(services[i], "wifi_", 5) != 0)
2607 keyfile = connman_storage_load_service(services[i]);
2611 str = g_key_file_get_string(keyfile,
2612 services[i], "Favorite", NULL);
2613 if (!str || g_strcmp0(str, "true")) {
2615 g_key_file_free(keyfile);
2620 str = g_key_file_get_string(keyfile,
2621 services[i], "AutoConnect", NULL);
2622 if (!str || g_strcmp0(str, "true")) {
2624 g_key_file_free(keyfile);
2629 str = g_key_file_get_string(keyfile,
2630 services[i], "Modified", NULL);
2632 g_key_file_free(keyfile);
2635 util_iso8601_to_timeval(str, &modified);
2638 ssid = g_key_file_get_string(keyfile,
2639 services[i], "SSID", NULL);
2641 freq = g_key_file_get_integer(keyfile, services[i],
2644 entry = g_try_new(struct last_connected, 1);
2646 g_sequence_free(latest_list);
2647 g_key_file_free(keyfile);
2649 #if defined TIZEN_EXT
2650 g_strfreev(services);
2656 entry->modified = modified;
2659 g_sequence_insert_sorted(latest_list, entry,
2665 g_key_file_free(keyfile);
2668 g_strfreev(services);
2670 num_ssids = num_ssids > max_ssids ? max_ssids : num_ssids;
2672 iter = g_sequence_get_begin_iter(latest_list);
2674 for (i = 0; i < num_ssids; i++) {
2675 entry = g_sequence_get(iter);
2677 DBG("ssid %s freq %d modified %lu", entry->ssid, entry->freq,
2678 entry->modified.tv_sec);
2680 add_scan_param(entry->ssid, NULL, 0, entry->freq, scan_data,
2681 max_ssids, entry->ssid);
2683 iter = g_sequence_iter_next(iter);
2686 g_sequence_free(latest_list);
2690 static void wifi_update_scanner_type(struct wifi_data *wifi,
2691 enum wifi_scanning_type new_type)
2695 if (!wifi || wifi->scanning_type == new_type)
2698 wifi->scanning_type = new_type;
2700 setup_autoscan(wifi);
2703 static int wifi_scan_simple(struct connman_device *device)
2705 struct wifi_data *wifi = connman_device_get_data(device);
2707 reset_autoscan(device);
2709 /* Distinguish between devices performing passive and active scanning */
2711 wifi_update_scanner_type(wifi, WIFI_SCANNING_PASSIVE);
2713 return throw_wifi_scan(device, scan_callback_hidden);
2716 static gboolean p2p_find_stop(gpointer data)
2718 struct connman_device *device = data;
2719 struct wifi_data *wifi = connman_device_get_data(device);
2724 wifi->p2p_find_timeout = 0;
2726 g_supplicant_interface_p2p_stop_find(wifi->interface);
2729 connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_P2P, false);
2731 connman_device_unref(device);
2732 start_autoscan(device);
2737 static void p2p_find_callback(int result, GSupplicantInterface *interface,
2740 struct connman_device *device = user_data;
2741 struct wifi_data *wifi = connman_device_get_data(device);
2743 DBG("result %d wifi %p", result, wifi);
2748 if (wifi->p2p_find_timeout) {
2749 g_source_remove(wifi->p2p_find_timeout);
2750 wifi->p2p_find_timeout = 0;
2756 wifi->p2p_find_timeout = g_timeout_add_seconds(P2P_FIND_TIMEOUT,
2757 p2p_find_stop, device);
2758 if (!wifi->p2p_find_timeout)
2763 p2p_find_stop(device);
2766 static int p2p_find(struct connman_device *device)
2768 struct wifi_data *wifi;
2773 if (!p2p_technology)
2776 wifi = connman_device_get_data(device);
2778 if (g_supplicant_interface_is_p2p_finding(wifi->interface))
2781 reset_autoscan(device);
2782 connman_device_ref(device);
2784 ret = g_supplicant_interface_p2p_find(wifi->interface,
2785 p2p_find_callback, device);
2787 connman_device_unref(device);
2788 start_autoscan(device);
2790 connman_device_set_scanning(device,
2791 CONNMAN_SERVICE_TYPE_P2P, true);
2797 #if defined TIZEN_EXT
2798 static void specific_scan_callback(int result, GSupplicantInterface *interface,
2801 struct connman_device *device = user_data;
2802 struct wifi_data *wifi = connman_device_get_data(device);
2805 DBG("result %d wifi %p", result, wifi);
2807 if (wifi && wifi->scan_params) {
2808 g_supplicant_free_scan_params(wifi->scan_params);
2809 wifi->scan_params = NULL;
2812 scanning = connman_device_get_scanning(device,
2813 CONNMAN_SERVICE_TYPE_WIFI);
2815 connman_device_set_scanning(device,
2816 CONNMAN_SERVICE_TYPE_WIFI, false);
2817 connman_device_unref(device);
2821 static int wifi_specific_scan(enum connman_service_type type,
2822 struct connman_device *device, int scan_type,
2823 GSList *specific_scan_list, void *user_data)
2825 GSList *list = NULL;
2827 struct wifi_data *wifi = connman_device_get_data(device);
2828 GSupplicantScanParams *scan_params = NULL;
2829 struct scan_ssid *scan_ssid = NULL;
2838 if (wifi->p2p_device)
2841 if (type == CONNMAN_SERVICE_TYPE_P2P)
2842 return p2p_find(device);
2844 if (wifi->tethering)
2848 connman_device_get_scanning(device,
2849 CONNMAN_SERVICE_TYPE_WIFI);
2853 DBG("scan_type: %d", scan_type);
2854 if (scan_type == CONNMAN_MULTI_SCAN_SSID) { /* ssid based scan */
2855 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2857 DBG("Failed to allocate memory.");
2861 for (list = specific_scan_list; list; list = list->next) {
2862 ssid = (char *)list->data;
2863 int ssid_len = strlen(ssid);
2865 scan_ssid = g_try_new0(struct scan_ssid, 1);
2867 DBG("Failed to allocate memory.");
2868 g_supplicant_free_scan_params(scan_params);
2872 memcpy(scan_ssid->ssid, ssid, (ssid_len + 1));
2873 /* DBG("scan ssid %s len: %d", scan_ssid->ssid, ssid_len); */
2874 scan_ssid->ssid_len = ssid_len;
2875 scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
2878 scan_params->num_ssids = count;
2880 } else if (scan_type == CONNMAN_MULTI_SCAN_FREQ) { /* frequency based scan */
2882 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2884 DBG("Failed to allocate memory.");
2888 guint num_freqs = g_slist_length(specific_scan_list);
2889 DBG("num_freqs: %d", num_freqs);
2891 scan_params->freqs = g_try_new0(uint16_t, num_freqs);
2892 if (!scan_params->freqs) {
2893 DBG("Failed to allocate memory.");
2894 g_free(scan_params);
2899 for (list = specific_scan_list; list; list = list->next) {
2900 freq = (int)list->data;
2902 scan_params->freqs[count] = freq;
2903 DBG("scan_params->freqs[%d]: %d", count, scan_params->freqs[count]);
2906 scan_params->num_freqs = count;
2908 } else if (scan_type == CONNMAN_MULTI_SCAN_SSID_FREQ) { /* SSID & Frequency mixed scan */
2909 int freq_count, ap_count;
2910 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2912 DBG("Failed to allocate memory.");
2916 guint size = g_slist_length(specific_scan_list);
2918 scan_params->freqs = g_try_new0(uint16_t, size/2);
2919 if (!scan_params->freqs) {
2920 DBG("Failed to allocate memory.");
2921 g_free(scan_params);
2925 ap_count = freq_count = 0;
2926 for (list = specific_scan_list; list; list = list->next) {
2927 if (((connman_multi_scan_ap_s *)list->data)->flag == true) { /** ssid */
2928 ssid = ((connman_multi_scan_ap_s *)list->data)->str;
2929 int ssid_len = strlen(ssid);
2931 scan_ssid = g_try_new0(struct scan_ssid, 1);
2933 DBG("Failed to allocate memory.");
2934 g_supplicant_free_scan_params(scan_params);
2938 memcpy(scan_ssid->ssid, ssid, (ssid_len + 1));
2939 /* DBG("scan ssid %s len: %d", scan_ssid->ssid, ssid_len); */
2940 scan_ssid->ssid_len = ssid_len;
2941 scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
2945 freq = atoi(((connman_multi_scan_ap_s *)list->data)->str);
2946 scan_params->freqs[freq_count] = freq;
2947 DBG("scan_params->freqs[%d]: %d", freq_count, scan_params->freqs[freq_count]);
2951 scan_params->num_ssids = ap_count;
2952 scan_params->num_freqs = freq_count;
2954 DBG("Invalid scan");
2958 reset_autoscan(device);
2959 connman_device_ref(device);
2961 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
2962 specific_scan_callback, device);
2965 connman_device_set_scanning(device,
2966 CONNMAN_SERVICE_TYPE_WIFI, true);
2968 g_supplicant_free_scan_params(scan_params);
2969 connman_device_unref(device);
2975 static void wifi_mac_policy_callback(int result,
2976 unsigned int policy,
2979 struct connman_device *device = user_data;
2982 connman_device_mac_policy_notify(device, result, policy);
2984 connman_device_unref(device);
2987 int wifi_set_mac_policy(struct connman_device *device, unsigned int policy)
2989 struct wifi_data *wifi = connman_device_get_data(device);
2995 connman_device_ref(device);
2997 ret = g_supplicant_interface_set_mac_policy(wifi->interface,
2998 wifi_mac_policy_callback,
3001 connman_device_unref(device);
3006 static void wifi_preassoc_mac_policy_callback(int result,
3007 unsigned int policy,
3010 struct connman_device *device = user_data;
3013 connman_device_preassoc_mac_policy_notify(device, result, policy);
3015 connman_device_unref(device);
3018 int wifi_set_preassoc_mac_policy(struct connman_device *device, unsigned int policy)
3020 struct wifi_data *wifi = connman_device_get_data(device);
3026 connman_device_ref(device);
3028 ret = g_supplicant_interface_set_preassoc_mac_policy(wifi->interface,
3029 wifi_preassoc_mac_policy_callback,
3032 connman_device_unref(device);
3037 static void wifi_random_mac_lifetime_callback(int result,
3038 unsigned int lifetime,
3041 struct connman_device *device = user_data;
3044 connman_device_random_mac_lifetime_notify(device, result, lifetime);
3046 connman_device_unref(device);
3049 int wifi_set_random_mac_lifetime(struct connman_device *device, unsigned int lifetime)
3051 struct wifi_data *wifi = connman_device_get_data(device);
3057 connman_device_ref(device);
3059 ret = g_supplicant_interface_set_random_mac_lifetime(wifi->interface,
3060 wifi_random_mac_lifetime_callback,
3063 connman_device_unref(device);
3069 #if defined TIZEN_EXT_WIFI_MESH
3070 static void mesh_scan_callback(int result, GSupplicantInterface *interface,
3073 struct connman_device *device = user_data;
3074 struct wifi_data *wifi = connman_device_get_data(device);
3077 DBG("result %d wifi %p", result, wifi);
3079 scanning = connman_device_get_scanning(device,
3080 CONNMAN_SERVICE_TYPE_MESH);
3082 connman_device_set_scanning(device,
3083 CONNMAN_SERVICE_TYPE_MESH, false);
3086 connman_device_unref(device);
3089 static int mesh_scan(struct connman_device *device)
3091 struct wifi_data *wifi;
3092 struct wifi_mesh_info *mesh_info;
3097 wifi = connman_device_get_data(device);
3099 if (!wifi || !wifi->mesh_interface)
3102 mesh_info = wifi->mesh_info;
3103 reset_autoscan(device);
3104 connman_device_ref(device);
3106 ret = g_supplicant_interface_scan(mesh_info->interface, NULL,
3107 mesh_scan_callback, device);
3109 connman_device_unref(device);
3111 connman_device_set_scanning(device,
3112 CONNMAN_SERVICE_TYPE_MESH, true);
3117 static void abort_scan_callback(int result, GSupplicantInterface *interface,
3120 struct connman_device *device = user_data;
3121 struct wifi_data *wifi = connman_device_get_data(device);
3123 DBG("result %d wifi %p", result, wifi);
3125 __connman_technology_notify_abort_scan(CONNMAN_SERVICE_TYPE_MESH, result);
3128 static int mesh_abort_scan(enum connman_service_type type,
3129 struct connman_device *device)
3131 struct wifi_data *wifi = connman_device_get_data(device);
3132 struct wifi_mesh_info *mesh_info;
3136 if (!wifi || !wifi->mesh_interface)
3139 if (type != CONNMAN_SERVICE_TYPE_MESH)
3142 mesh_info = wifi->mesh_info;
3144 scanning = connman_device_get_scanning(device,
3145 CONNMAN_SERVICE_TYPE_MESH);
3149 ret = g_supplicant_interface_abort_scan(mesh_info->interface,
3150 abort_scan_callback, device);
3155 static int mesh_specific_scan(enum connman_service_type type,
3156 struct connman_device *device, const char *ssid,
3157 unsigned int freq, void *user_data)
3159 struct wifi_data *wifi = connman_device_get_data(device);
3160 GSupplicantScanParams *scan_params = NULL;
3161 struct wifi_mesh_info *mesh_info;
3162 struct scan_ssid *scan_ssid;
3166 if (!wifi || !wifi->mesh_interface)
3169 if (type != CONNMAN_SERVICE_TYPE_MESH)
3172 if (wifi->p2p_device)
3175 mesh_info = wifi->mesh_info;
3177 scanning = connman_device_get_scanning(device,
3178 CONNMAN_SERVICE_TYPE_MESH);
3182 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
3186 scan_ssid = g_try_new(struct scan_ssid, 1);
3188 g_free(scan_params);
3192 scan_ssid->ssid_len = strlen(ssid);
3193 memcpy(scan_ssid->ssid, ssid, scan_ssid->ssid_len);
3194 scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
3195 scan_params->num_ssids = 1;
3197 scan_params->freqs = g_try_new(uint16_t, 1);
3198 if (!scan_params->freqs) {
3199 g_slist_free_full(scan_params->ssids, g_free);
3200 g_free(scan_params);
3204 scan_params->freqs[0] = freq;
3205 scan_params->num_freqs = 1;
3207 reset_autoscan(device);
3208 connman_device_ref(device);
3210 ret = g_supplicant_interface_scan(mesh_info->interface, scan_params,
3211 mesh_scan_callback, device);
3214 connman_device_set_scanning(device,
3215 CONNMAN_SERVICE_TYPE_MESH, true);
3217 g_supplicant_free_scan_params(scan_params);
3218 connman_device_unref(device);
3226 * Note that the hidden scan is only used when connecting to this specific
3227 * hidden AP first time. It is not used when system autoconnects to hidden AP.
3229 static int wifi_scan(struct connman_device *device,
3230 struct connman_device_scan_params *params)
3232 struct wifi_data *wifi = connman_device_get_data(device);
3233 GSupplicantScanParams *scan_params = NULL;
3234 struct scan_ssid *scan_ssid;
3235 struct hidden_params *hidden;
3237 int driver_max_ssids = 0;
3244 if (wifi->p2p_device)
3247 if (wifi->tethering)
3250 if (params->type == CONNMAN_SERVICE_TYPE_P2P)
3251 return p2p_find(device);
3253 #if defined TIZEN_EXT_WIFI_MESH
3254 if (params->type == CONNMAN_SERVICE_TYPE_MESH)
3255 return mesh_scan(device);
3258 DBG("device %p wifi %p hidden ssid %s", device, wifi->interface,
3261 scanning = connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI);
3263 if (!params->ssid || params->ssid_len == 0 || params->ssid_len > 32) {
3267 driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
3269 DBG("max ssids %d", driver_max_ssids);
3270 if (driver_max_ssids == 0)
3271 return wifi_scan_simple(device);
3275 if (scanning && wifi->hidden && wifi->postpone_hidden)
3281 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
3286 scan_ssid = g_try_new(struct scan_ssid, 1);
3288 g_free(scan_params);
3292 memcpy(scan_ssid->ssid, params->ssid, params->ssid_len);
3293 scan_ssid->ssid_len = params->ssid_len;
3294 scan_params->ssids = g_slist_prepend(scan_params->ssids,
3296 scan_params->num_ssids = 1;
3298 hidden = g_try_new0(struct hidden_params, 1);
3300 g_supplicant_free_scan_params(scan_params);
3305 hidden_free(wifi->hidden);
3306 wifi->hidden = NULL;
3309 memcpy(hidden->ssid, params->ssid, params->ssid_len);
3310 hidden->ssid_len = params->ssid_len;
3311 hidden->identity = g_strdup(params->identity);
3312 hidden->passphrase = g_strdup(params->passphrase);
3313 hidden->security = g_strdup(params->security);
3314 hidden->user_data = params->user_data;
3315 wifi->hidden = hidden;
3318 /* Let's keep this active scan for later,
3319 * when current scan will be over. */
3320 wifi->postpone_hidden = TRUE;
3321 hidden->scan_params = scan_params;
3325 } else if (wifi->connected) {
3326 g_supplicant_free_scan_params(scan_params);
3327 return wifi_scan_simple(device);
3328 } else if (!params->force_full_scan) {
3329 ret = get_latest_connections(driver_max_ssids, scan_params);
3331 g_supplicant_free_scan_params(scan_params);
3332 return wifi_scan_simple(device);
3336 /* Distinguish between devices performing passive and active scanning */
3337 wifi_update_scanner_type(wifi, WIFI_SCANNING_ACTIVE);
3339 connman_device_ref(device);
3341 reset_autoscan(device);
3342 #if defined TIZEN_EXT
3344 * When doing a full scan, stored hidden networks also need to be scanned
3345 * so that we can autoconnect to them.
3347 if (params->force_full_scan)
3348 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
3349 scan_callback_hidden, device);
3352 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
3353 scan_callback, device);
3355 connman_device_set_scanning(device,
3356 CONNMAN_SERVICE_TYPE_WIFI, true);
3357 #if defined TIZEN_EXT
3359 * To allow the Full Scan after ssid based scan, set the flag here
3360 * It is required because Tizen does not use the ConnMan specific
3361 * backgroung Scan feature.Tizen has added the BG Scan feature in
3362 * net-config. To sync with up ConnMan, we need to issue the Full Scan
3363 * after SSID specific scan.
3365 if (!params->force_full_scan && !do_hidden)
3366 wifi->allow_full_scan = TRUE;
3369 g_supplicant_free_scan_params(scan_params);
3370 connman_device_unref(device);
3373 hidden_free(wifi->hidden);
3374 wifi->hidden = NULL;
3381 static void wifi_stop_scan(enum connman_service_type type,
3382 struct connman_device *device)
3384 struct wifi_data *wifi = connman_device_get_data(device);
3386 DBG("device %p wifi %p", device, wifi);
3391 if (type == CONNMAN_SERVICE_TYPE_P2P) {
3392 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_P2P)) {
3393 g_source_remove(wifi->p2p_find_timeout);
3394 p2p_find_stop(device);
3399 static void wifi_regdom_callback(int result,
3403 struct connman_device *device = user_data;
3405 connman_device_regdom_notify(device, result, alpha2);
3407 connman_device_unref(device);
3410 static int wifi_set_regdom(struct connman_device *device, const char *alpha2)
3412 struct wifi_data *wifi = connman_device_get_data(device);
3418 connman_device_ref(device);
3420 ret = g_supplicant_interface_set_country(wifi->interface,
3421 wifi_regdom_callback,
3424 connman_device_unref(device);
3429 static struct connman_device_driver wifi_ng_driver = {
3431 .type = CONNMAN_DEVICE_TYPE_WIFI,
3432 .priority = CONNMAN_DEVICE_PRIORITY_LOW,
3433 .probe = wifi_probe,
3434 .remove = wifi_remove,
3435 .enable = wifi_enable,
3436 .disable = wifi_disable,
3438 .stop_scan = wifi_stop_scan,
3439 .set_regdom = wifi_set_regdom,
3440 #if defined TIZEN_EXT
3441 .specific_scan = wifi_specific_scan,
3442 .set_mac_policy = wifi_set_mac_policy,
3443 .set_preassoc_mac_policy = wifi_set_preassoc_mac_policy,
3444 .set_random_mac_lifetime = wifi_set_random_mac_lifetime,
3446 #if defined TIZEN_EXT_WIFI_MESH
3447 .abort_scan = mesh_abort_scan,
3448 .mesh_specific_scan = mesh_specific_scan,
3452 static void system_ready(void)
3456 if (connman_device_driver_register(&wifi_ng_driver) < 0)
3457 connman_error("Failed to register WiFi driver");
3460 static void system_killed(void)
3464 connman_device_driver_unregister(&wifi_ng_driver);
3467 static int network_probe(struct connman_network *network)
3469 #if defined TIZEN_EXT
3470 if (!simplified_log)
3472 DBG("network %p", network);
3477 static void network_remove(struct connman_network *network)
3479 struct connman_device *device = connman_network_get_device(network);
3480 struct wifi_data *wifi;
3482 DBG("network %p", network);
3484 wifi = connman_device_get_data(device);
3488 if (wifi->network != network)
3491 wifi->network = NULL;
3493 #if defined TIZEN_EXT
3494 wifi->disconnecting = false;
3496 if (wifi->pending_network == network)
3497 wifi->pending_network = NULL;
3499 if (wifi->scan_pending_network == network)
3500 wifi->scan_pending_network = NULL;
3504 static void connect_callback(int result, GSupplicantInterface *interface,
3507 #if defined TIZEN_EXT
3509 struct wifi_data *wifi;
3511 struct connman_network *network = user_data;
3513 DBG("network %p result %d", network, result);
3515 #if defined TIZEN_EXT
3516 const char *ifname = g_supplicant_interface_get_ifname(interface);
3517 set_connman_bssid(RESET_BSSID, NULL, ifname);
3519 for (list = iface_list; list; list = list->next) {
3522 if (wifi && wifi->network == network)
3526 /* wifi_data may be invalid because wifi is already disabled */
3531 if (result == -ENOKEY) {
3532 connman_network_set_error(network,
3533 CONNMAN_NETWORK_ERROR_INVALID_KEY);
3534 } else if (result < 0) {
3535 connman_network_set_error(network,
3536 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
3539 connman_network_unref(network);
3542 static GSupplicantSecurity network_security(const char *security)
3544 if (g_str_equal(security, "none"))
3545 return G_SUPPLICANT_SECURITY_NONE;
3546 else if (g_str_equal(security, "wep"))
3547 return G_SUPPLICANT_SECURITY_WEP;
3548 else if (g_str_equal(security, "psk"))
3549 return G_SUPPLICANT_SECURITY_PSK;
3550 else if (g_str_equal(security, "wpa"))
3551 return G_SUPPLICANT_SECURITY_PSK;
3552 else if (g_str_equal(security, "rsn"))
3553 return G_SUPPLICANT_SECURITY_PSK;
3554 else if (g_str_equal(security, "ieee8021x"))
3555 return G_SUPPLICANT_SECURITY_IEEE8021X;
3556 #if defined TIZEN_EXT
3557 else if (g_str_equal(security, "ft_psk") == TRUE)
3558 return G_SUPPLICANT_SECURITY_FT_PSK;
3559 else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
3560 return G_SUPPLICANT_SECURITY_FT_IEEE8021X;
3561 else if (g_str_equal(security, "sae"))
3562 return G_SUPPLICANT_SECURITY_SAE;
3563 else if (g_str_equal(security, "owe"))
3564 return G_SUPPLICANT_SECURITY_OWE;
3565 else if (g_str_equal(security, "dpp"))
3566 return G_SUPPLICANT_SECURITY_DPP;
3569 return G_SUPPLICANT_SECURITY_UNKNOWN;
3572 #if defined TIZEN_EXT
3573 static GSupplicantEapKeymgmt network_eap_keymgmt(const char *security)
3575 if (security == NULL)
3576 return G_SUPPLICANT_EAP_KEYMGMT_NONE;
3578 if (g_str_equal(security, "FT") == TRUE)
3579 return G_SUPPLICANT_EAP_KEYMGMT_FT;
3580 else if (g_str_equal(security, "CCKM") == TRUE)
3581 return G_SUPPLICANT_EAP_KEYMGMT_CCKM;
3583 return G_SUPPLICANT_EAP_KEYMGMT_NONE;
3587 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
3589 const char *security;
3590 #if defined TIZEN_EXT
3591 const void *ssid_data;
3594 memset(ssid, 0, sizeof(*ssid));
3595 ssid->mode = G_SUPPLICANT_MODE_INFRA;
3596 #if defined TIZEN_EXT
3597 ssid_data = connman_network_get_blob(network, "WiFi.SSID",
3599 ssid->ssid = g_try_malloc0(ssid->ssid_len);
3604 memcpy(ssid->ssid, ssid_data, ssid->ssid_len);
3606 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
3609 ssid->scan_ssid = 1;
3610 security = connman_network_get_string(network, "WiFi.Security");
3611 ssid->security = network_security(security);
3612 #if defined TIZEN_EXT
3613 ssid->ieee80211w = 1;
3615 ssid->passphrase = connman_network_get_string(network,
3618 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
3621 * If our private key password is unset,
3622 * we use the supplied passphrase. That is needed
3623 * for PEAP where 2 passphrases (identity and client
3624 * cert may have to be provided.
3626 if (!connman_network_get_string(network, "WiFi.PrivateKeyPassphrase"))
3627 connman_network_set_string(network,
3628 "WiFi.PrivateKeyPassphrase",
3630 /* We must have an identity for both PEAP and TLS */
3631 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
3633 /* Use agent provided identity as a fallback */
3634 if (!ssid->identity || strlen(ssid->identity) == 0)
3635 ssid->identity = connman_network_get_string(network,
3636 "WiFi.AgentIdentity");
3638 ssid->anonymous_identity = connman_network_get_string(network,
3639 "WiFi.AnonymousIdentity");
3640 ssid->ca_cert_path = connman_network_get_string(network,
3642 ssid->subject_match = connman_network_get_string(network,
3643 "WiFi.SubjectMatch");
3644 ssid->altsubject_match = connman_network_get_string(network,
3645 "WiFi.AltSubjectMatch");
3646 ssid->domain_suffix_match = connman_network_get_string(network,
3647 "WiFi.DomainSuffixMatch");
3648 ssid->domain_match = connman_network_get_string(network,
3649 "WiFi.DomainMatch");
3650 ssid->client_cert_path = connman_network_get_string(network,
3651 "WiFi.ClientCertFile");
3652 ssid->private_key_path = connman_network_get_string(network,
3653 "WiFi.PrivateKeyFile");
3654 ssid->private_key_passphrase = connman_network_get_string(network,
3655 "WiFi.PrivateKeyPassphrase");
3656 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
3658 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
3659 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
3660 #if defined TIZEN_EXT
3661 ssid->connector = connman_network_get_string(network,
3663 ssid->c_sign_key = connman_network_get_string(network,
3665 ssid->net_access_key = connman_network_get_string(network,
3666 "WiFi.NetAccessKey");
3669 #if defined TIZEN_EXT
3670 const char *ifname = connman_device_get_string(
3671 connman_network_get_device(network), "Interface");
3672 if (set_connman_bssid(CHECK_BSSID, NULL, ifname) == 6) {
3673 ssid->bssid_for_connect_len = 6;
3674 set_connman_bssid(GET_BSSID, (char *)ssid->bssid_for_connect, ifname);
3675 DBG("BSSID : %02x:%02x:%02x:%02x:%02x:%02x",
3676 ssid->bssid_for_connect[0], ssid->bssid_for_connect[1],
3677 ssid->bssid_for_connect[2], ssid->bssid_for_connect[3],
3678 ssid->bssid_for_connect[4], ssid->bssid_for_connect[5]);
3680 ssid->freq = connman_network_get_frequency(network);
3683 GSList *bssid_list = (GSList *)connman_network_get_bssid_list(network);
3684 if (bssid_list && g_slist_length(bssid_list) > 1) {
3686 /* If there are more than one bssid,
3687 * the user-specified bssid is tried only once at the beginning.
3688 * After that, the bssids in the list are tried in order.
3690 if (set_connman_bssid(CHECK_BSSID, NULL, ifname) == 6) {
3691 set_connman_bssid(RESET_BSSID, NULL, ifname);
3696 char buff[MAC_ADDRESS_LENGTH];
3697 for (list = bssid_list; list; list = list->next) {
3698 struct connman_bssids * bssids = (struct connman_bssids *)list->data;
3700 g_snprintf(buff, MAC_ADDRESS_LENGTH, "%02x:%02x:%02x:%02x:%02x:%02x",
3701 bssids->bssid[0], bssids->bssid[1], bssids->bssid[2],
3702 bssids->bssid[3], bssids->bssid[4], bssids->bssid[5]);
3703 buff[MAC_ADDRESS_LENGTH - 1] = '\0';
3705 gchar *curr_bssid = g_strdup((const gchar *)buff);
3707 if (g_hash_table_contains(failed_bssids, curr_bssid)) {
3708 DBG("bssid match, try next bssid");
3712 g_hash_table_add(failed_bssids, curr_bssid);
3714 memcpy(buff_bssid, bssids->bssid, WIFI_BSSID_LEN_MAX);
3715 ssid->bssid = buff_bssid;
3716 ssid->freq = (unsigned int)bssids->frequency;
3722 ssid->bssid = connman_network_get_bssid(network);
3723 g_hash_table_remove_all(failed_bssids);
3726 ssid->bssid = connman_network_get_bssid(network);
3729 ssid->eap_keymgmt = network_eap_keymgmt(
3730 connman_network_get_string(network, "WiFi.KeymgmtType"));
3731 ssid->phase1 = connman_network_get_string(network, "WiFi.Phase1");
3733 if(g_strcmp0(ssid->eap, "fast") == 0)
3734 ssid->pac_file = g_strdup(WIFI_EAP_FAST_PAC_FILE);
3736 ssid->keymgmt = connman_network_get_keymgmt(network);
3739 if (connman_setting_get_bool("BackgroundScanning"))
3740 ssid->bgscan = BGSCAN_DEFAULT;
3743 static int network_connect(struct connman_network *network)
3745 struct connman_device *device = connman_network_get_device(network);
3746 struct wifi_data *wifi;
3747 GSupplicantInterface *interface;
3748 GSupplicantSSID *ssid;
3750 DBG("network %p", network);
3755 wifi = connman_device_get_data(device);
3759 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
3763 interface = wifi->interface;
3765 ssid_init(ssid, network);
3767 if (wifi->disconnecting) {
3768 wifi->pending_network = network;
3769 #if defined TIZEN_EXT
3774 wifi->network = connman_network_ref(network);
3776 #if defined TIZEN_EXT
3777 wifi->scan_pending_network = NULL;
3780 return g_supplicant_interface_connect(interface, ssid,
3781 connect_callback, network);
3784 return -EINPROGRESS;
3787 static void disconnect_callback(int result, GSupplicantInterface *interface,
3790 #if defined TIZEN_EXT
3792 struct wifi_data *wifi;
3793 struct connman_network *network = user_data;
3795 DBG("network %p result %d", network, result);
3797 for (list = iface_list; list; list = list->next) {
3800 if (wifi->network == NULL && wifi->disconnecting == true)
3801 wifi->disconnecting = false;
3803 if (wifi->network == network)
3807 /* wifi_data may be invalid because wifi is already disabled */
3812 struct wifi_data *wifi = user_data;
3815 DBG("result %d supplicant interface %p wifi %p",
3816 result, interface, wifi);
3818 if (result == -ECONNABORTED) {
3819 DBG("wifi interface no longer available");
3823 if (wifi->network && wifi->network != wifi->pending_network)
3824 connman_network_set_connected(wifi->network, false);
3825 wifi->network = NULL;
3827 wifi->disconnecting = false;
3828 wifi->connected = false;
3830 if (wifi->pending_network) {
3831 network_connect(wifi->pending_network);
3832 wifi->pending_network = NULL;
3835 start_autoscan(wifi->device);
3838 static int network_disconnect(struct connman_network *network)
3840 struct connman_device *device = connman_network_get_device(network);
3841 struct wifi_data *wifi;
3843 #if defined TIZEN_EXT
3844 struct connman_service *service;
3847 DBG("network %p", network);
3849 wifi = connman_device_get_data(device);
3850 if (!wifi || !wifi->interface)
3853 #if defined TIZEN_EXT
3854 if (connman_network_get_associating(network) == true) {
3855 connman_network_clear_associating(network);
3856 connman_network_set_bool(network, "WiFi.UseWPS", false);
3858 service = connman_service_lookup_from_network(network);
3860 if (service != NULL &&
3861 (__connman_service_is_connected_state(service,
3862 CONNMAN_IPCONFIG_TYPE_IPV4) == false &&
3863 __connman_service_is_connected_state(service,
3864 CONNMAN_IPCONFIG_TYPE_IPV6) == false) &&
3865 (connman_service_get_favorite(service) == false))
3866 __connman_service_set_passphrase(service, NULL);
3869 if (wifi->pending_network == network)
3870 wifi->pending_network = NULL;
3872 if (wifi->scan_pending_network == network)
3873 wifi->scan_pending_network = NULL;
3876 connman_network_set_associating(network, false);
3878 if (wifi->disconnecting)
3881 wifi->disconnecting = true;
3883 #if defined TIZEN_EXT
3884 err = g_supplicant_interface_disconnect(wifi->interface,
3885 disconnect_callback, network);
3887 err = g_supplicant_interface_disconnect(wifi->interface,
3888 disconnect_callback, wifi);
3892 wifi->disconnecting = false;
3897 #if defined TIZEN_EXT
3898 static void set_connection_mode(struct connman_network *network,
3901 ieee80211_modes_e phy_mode;
3902 connection_mode_e conn_mode;
3904 phy_mode = connman_network_get_phy_mode(network);
3906 case IEEE80211_MODE_B:
3907 if (linkspeed > 0 && linkspeed <= 11)
3908 conn_mode = CONNECTION_MODE_IEEE80211B;
3910 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3913 case IEEE80211_MODE_BG:
3914 if (linkspeed > 0 && linkspeed <= 11)
3915 conn_mode = CONNECTION_MODE_IEEE80211B;
3916 else if (linkspeed > 11 && linkspeed <= 54)
3917 conn_mode = CONNECTION_MODE_IEEE80211G;
3919 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3922 case IEEE80211_MODE_BGN:
3923 if (linkspeed > 0 && linkspeed <= 11)
3924 conn_mode = CONNECTION_MODE_IEEE80211B;
3925 else if (linkspeed > 11 && linkspeed <= 54)
3926 conn_mode = CONNECTION_MODE_IEEE80211G;
3927 else if (linkspeed > 54 && linkspeed <= 450)
3928 conn_mode = CONNECTION_MODE_IEEE80211N;
3930 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3933 case IEEE80211_MODE_A:
3934 if (linkspeed > 0 && linkspeed <= 54)
3935 conn_mode = CONNECTION_MODE_IEEE80211A;
3937 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3940 case IEEE80211_MODE_AN:
3941 if (linkspeed > 0 && linkspeed <= 54)
3942 conn_mode = CONNECTION_MODE_IEEE80211A;
3943 else if (linkspeed > 54 && linkspeed <= 450)
3944 conn_mode = CONNECTION_MODE_IEEE80211N;
3946 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3949 case IEEE80211_MODE_ANAC:
3950 if (linkspeed > 0 && linkspeed <= 54)
3951 conn_mode = CONNECTION_MODE_IEEE80211A;
3952 else if (linkspeed > 54 && linkspeed <= 450)
3953 conn_mode = CONNECTION_MODE_IEEE80211N;
3954 else if (linkspeed > 450 && linkspeed <= 1300)
3955 conn_mode = CONNECTION_MODE_IEEE80211AC;
3957 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3961 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3965 DBG("connection mode(%d)", conn_mode);
3966 connman_network_set_connection_mode(network, conn_mode);
3969 static void signalpoll_callback(int result, int maxspeed, int strength,
3970 int snr, void *user_data)
3972 struct connman_network *network = user_data;
3973 uint16_t freq = connman_network_get_frequency(network);
3976 DBG("Failed to get maxspeed from signalpoll !");
3977 connman_network_unref(network);
3985 DBG("maxspeed = %d, strength = %d, snr = %d", maxspeed, strength, snr);
3987 connman_network_set_strength(network, (uint8_t)strength);
3988 connman_network_set_maxspeed(network, maxspeed);
3989 set_connection_mode(network, maxspeed);
3991 connman_network_unref(network);
3993 /* If SNR is less than 20 or RSSI level is less than 3,
3994 * scan for BSS transition is started.
3996 if (connman_setting_get_bool("WifiRoamingScan") == false)
3999 if (snr < 20 && snr != 0)
4001 else if (freq > 4900 && strength <= RSSI_LEVEL_2_5G)
4003 else if (freq <= 4900 && strength <= RSSI_LEVEL_2_24G)
4009 throw_wifi_scan(connman_network_get_device(network), scan_callback);
4012 static int network_signalpoll(struct wifi_data *wifi)
4014 GSupplicantInterface *interface;
4015 struct connman_network *network;
4017 if (!wifi || !wifi->network)
4020 wifi->network = connman_network_ref(wifi->network);
4022 interface = wifi->interface;
4023 network = wifi->network;
4025 DBG("network %p", network);
4027 return g_supplicant_interface_signalpoll(interface, signalpoll_callback, network);
4030 static gboolean autosignalpoll_timeout(gpointer data)
4032 struct wifi_data *wifi = data;
4034 if (!wifi || !wifi->automaxspeed_timeout) {
4035 DBG("automaxspeed_timeout is found to be zero. i.e. currently in disconnected state. !!");
4039 int ret = network_signalpoll(wifi);
4041 DBG("Fail to get max speed !!");
4042 wifi->automaxspeed_timeout = 0;
4045 connman_network_unref(wifi->network);
4053 static struct connman_network_driver network_driver = {
4055 .type = CONNMAN_NETWORK_TYPE_WIFI,
4056 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
4057 .probe = network_probe,
4058 .remove = network_remove,
4059 .connect = network_connect,
4060 .disconnect = network_disconnect,
4063 static void interface_added(GSupplicantInterface *interface)
4065 const char *ifname = g_supplicant_interface_get_ifname(interface);
4066 const char *driver = g_supplicant_interface_get_driver(interface);
4067 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4069 * Note: If supplicant interface's driver is wired then skip it,
4070 * because it meanti only for ethernet not Wi-Fi.
4072 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4074 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4076 #if defined TIZEN_EXT
4077 bool is_5_0_ghz_supported = g_supplicant_interface_get_is_5_0_ghz_supported(interface);
4080 struct wifi_data *wifi;
4082 wifi = g_supplicant_interface_get_data(interface);
4084 wifi = get_pending_wifi_data(ifname);
4088 wifi->interface = interface;
4089 g_supplicant_interface_set_data(interface, wifi);
4090 p2p_iface_list = g_list_append(p2p_iface_list, wifi);
4091 wifi->p2p_device = true;
4094 DBG("ifname %s driver %s wifi %p tethering %d",
4095 ifname, driver, wifi, wifi->tethering);
4097 if (!wifi->device) {
4098 connman_error("WiFi device not set");
4102 connman_device_set_powered(wifi->device, true);
4103 #if defined TIZEN_EXT
4104 connman_device_set_wifi_5ghz_supported(wifi->device, is_5_0_ghz_supported);
4105 /* Max number of SSIDs supported by wlan chipset that can be scanned */
4106 int max_scan_ssids = g_supplicant_interface_get_max_scan_ssids(interface);
4107 connman_device_set_max_scan_ssids(wifi->device, max_scan_ssids);
4111 static bool is_idle(struct wifi_data *wifi)
4113 DBG("state %d", wifi->state);
4115 switch (wifi->state) {
4116 case G_SUPPLICANT_STATE_UNKNOWN:
4117 case G_SUPPLICANT_STATE_DISABLED:
4118 case G_SUPPLICANT_STATE_DISCONNECTED:
4119 case G_SUPPLICANT_STATE_INACTIVE:
4120 case G_SUPPLICANT_STATE_SCANNING:
4123 case G_SUPPLICANT_STATE_AUTHENTICATING:
4124 case G_SUPPLICANT_STATE_ASSOCIATING:
4125 case G_SUPPLICANT_STATE_ASSOCIATED:
4126 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4127 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4128 case G_SUPPLICANT_STATE_COMPLETED:
4135 static bool is_idle_wps(GSupplicantInterface *interface,
4136 struct wifi_data *wifi)
4138 /* First, let's check if WPS processing did not went wrong */
4139 if (g_supplicant_interface_get_wps_state(interface) ==
4140 G_SUPPLICANT_WPS_STATE_FAIL)
4143 /* Unlike normal connection, being associated while processing wps
4144 * actually means that we are idling. */
4145 switch (wifi->state) {
4146 case G_SUPPLICANT_STATE_UNKNOWN:
4147 case G_SUPPLICANT_STATE_DISABLED:
4148 case G_SUPPLICANT_STATE_DISCONNECTED:
4149 case G_SUPPLICANT_STATE_INACTIVE:
4150 case G_SUPPLICANT_STATE_SCANNING:
4151 case G_SUPPLICANT_STATE_ASSOCIATED:
4153 case G_SUPPLICANT_STATE_AUTHENTICATING:
4154 case G_SUPPLICANT_STATE_ASSOCIATING:
4155 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4156 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4157 case G_SUPPLICANT_STATE_COMPLETED:
4164 static bool handle_wps_completion(GSupplicantInterface *interface,
4165 struct connman_network *network,
4166 struct connman_device *device,
4167 struct wifi_data *wifi)
4171 wps = connman_network_get_bool(network, "WiFi.UseWPS");
4173 const unsigned char *ssid, *wps_ssid;
4174 unsigned int ssid_len, wps_ssid_len;
4175 const char *wps_key;
4177 /* Checking if we got associated with requested
4179 ssid = connman_network_get_blob(network, "WiFi.SSID",
4182 wps_ssid = g_supplicant_interface_get_wps_ssid(
4183 interface, &wps_ssid_len);
4185 if (!wps_ssid || wps_ssid_len != ssid_len ||
4186 memcmp(ssid, wps_ssid, ssid_len) != 0) {
4187 connman_network_set_associating(network, false);
4188 #if defined TIZEN_EXT
4189 g_supplicant_interface_disconnect(wifi->interface,
4190 disconnect_callback, wifi->network);
4192 connman_network_set_bool(network, "WiFi.UseWPS", false);
4193 connman_network_set_string(network, "WiFi.PinWPS", NULL);
4195 g_supplicant_interface_disconnect(wifi->interface,
4196 disconnect_callback, wifi);
4201 wps_key = g_supplicant_interface_get_wps_key(interface);
4202 #if defined TIZEN_EXT
4203 /* Check the passphrase and encrypt it
4206 gchar *passphrase = g_strdup(wps_key);
4208 connman_network_set_string(network, "WiFi.PinWPS", NULL);
4210 if (check_passphrase_ext(network, passphrase) < 0) {
4211 DBG("[WPS] Invalid passphrase");
4216 ret = send_encryption_request(passphrase, network);
4221 DBG("[WPS] Encryption request succeeded");
4223 DBG("[WPS] Encryption request failed %d", ret);
4226 connman_network_set_string(network, "WiFi.Passphrase",
4229 connman_network_set_string(network, "WiFi.PinWPS", NULL);
4236 static bool handle_assoc_status_code(GSupplicantInterface *interface,
4237 struct wifi_data *wifi)
4239 if (wifi->state == G_SUPPLICANT_STATE_ASSOCIATING &&
4240 #if defined TIZEN_EXT
4241 wifi->assoc_code > 0 &&
4243 wifi->assoc_code == ASSOC_STATUS_NO_CLIENT &&
4245 wifi->load_shaping_retries < LOAD_SHAPING_MAX_RETRIES) {
4246 wifi->load_shaping_retries ++;
4249 wifi->load_shaping_retries = 0;
4253 static bool handle_4way_handshake_failure(GSupplicantInterface *interface,
4254 struct connman_network *network,
4255 struct wifi_data *wifi)
4257 #if defined TIZEN_EXT
4258 const char *security;
4259 struct connman_service *service;
4261 if (wifi->connected)
4264 security = connman_network_get_string(network, "WiFi.Security");
4266 if (security && g_str_equal(security, "ieee8021x") == true &&
4267 wifi->state == G_SUPPLICANT_STATE_ASSOCIATED) {
4269 connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
4274 if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
4277 struct connman_service *service;
4279 if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
4282 if (wifi->connected)
4286 service = connman_service_lookup_from_network(network);
4292 if (connman_service_get_favorite(service)) {
4293 if (wifi->retries < FAVORITE_MAXIMUM_RETRIES)
4298 connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
4303 #if defined TIZEN_EXT
4304 static bool handle_wifi_assoc_retry(struct connman_network *network,
4305 struct wifi_data *wifi)
4307 const char *security;
4309 if (!wifi->network || wifi->connected || wifi->disconnecting ||
4310 connman_network_get_connecting(network) != true) {
4311 wifi->assoc_retry_count = 0;
4315 if (wifi->state != G_SUPPLICANT_STATE_ASSOCIATING &&
4316 wifi->state != G_SUPPLICANT_STATE_ASSOCIATED) {
4317 wifi->assoc_retry_count = 0;
4321 security = connman_network_get_string(network, "WiFi.Security");
4322 if (security && g_str_equal(security, "ieee8021x") == true &&
4323 wifi->state == G_SUPPLICANT_STATE_ASSOCIATED) {
4324 wifi->assoc_retry_count = 0;
4328 if (++wifi->assoc_retry_count >= TIZEN_ASSOC_RETRY_COUNT) {
4329 wifi->assoc_retry_count = 0;
4331 /* Honestly it's not an invalid-key error,
4332 * however QA team recommends that the invalid-key error
4333 * might be better to display for user experience.
4335 connman_network_set_error(network, CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
4344 static void interface_state(GSupplicantInterface *interface)
4346 struct connman_network *network;
4347 struct connman_device *device;
4348 struct wifi_data *wifi;
4349 GSupplicantState state = g_supplicant_interface_get_state(interface);
4350 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4352 * Note: If supplicant interface's driver is wired then skip it,
4353 * because it meanti only for ethernet not Wi-Fi.
4355 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4357 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4362 wifi = g_supplicant_interface_get_data(interface);
4364 DBG("wifi %p interface state %d", wifi, state);
4369 device = wifi->device;
4373 if (state == G_SUPPLICANT_STATE_COMPLETED) {
4374 if (wifi->tethering_param) {
4375 g_free(wifi->tethering_param->ssid);
4376 g_free(wifi->tethering_param);
4377 wifi->tethering_param = NULL;
4380 if (wifi->tethering)
4381 stop_autoscan(device);
4384 if (g_supplicant_interface_get_ready(interface) &&
4385 !wifi->interface_ready) {
4386 wifi->interface_ready = true;
4387 finalize_interface_creation(wifi);
4390 network = wifi->network;
4395 case G_SUPPLICANT_STATE_SCANNING:
4396 if (wifi->connected)
4397 connman_network_set_connected(network, false);
4401 case G_SUPPLICANT_STATE_AUTHENTICATING:
4402 case G_SUPPLICANT_STATE_ASSOCIATING:
4403 #if defined TIZEN_EXT
4404 reset_autoscan(device);
4406 stop_autoscan(device);
4409 if (!wifi->connected)
4410 connman_network_set_associating(network, true);
4414 case G_SUPPLICANT_STATE_COMPLETED:
4415 #if defined TIZEN_EXT
4416 /* though it should be already reset: */
4417 reset_autoscan(device);
4419 wifi->assoc_retry_count = 0;
4421 wifi->scan_pending_network = NULL;
4423 /* should be cleared scanning flag */
4424 bool scanning = connman_device_get_scanning(device,
4425 CONNMAN_SERVICE_TYPE_WIFI);
4427 connman_device_set_scanning(device,
4428 CONNMAN_SERVICE_TYPE_WIFI, false);
4429 connman_device_unref(device);
4432 if (!wifi->automaxspeed_timeout) {
4433 DBG("Going to start signalpoll timer!!");
4434 int ret = network_signalpoll(wifi);
4436 DBG("Fail to get max speed !!");
4438 wifi->automaxspeed_timeout = g_timeout_add_seconds(10, autosignalpoll_timeout, wifi);
4441 g_hash_table_remove_all(failed_bssids);
4443 /* though it should be already stopped: */
4444 stop_autoscan(device);
4447 if (!handle_wps_completion(interface, network, device, wifi))
4450 connman_network_set_connected(network, true);
4452 wifi->disconnect_code = 0;
4453 wifi->assoc_code = 0;
4454 wifi->load_shaping_retries = 0;
4457 case G_SUPPLICANT_STATE_DISCONNECTED:
4458 #if defined TIZEN_EXT
4459 connman_network_set_strength(network, 0);
4460 connman_network_set_maxspeed(network, 0);
4462 if (wifi->automaxspeed_timeout != 0) {
4463 g_source_remove(wifi->automaxspeed_timeout);
4464 wifi->automaxspeed_timeout = 0;
4465 DBG("Remove signalpoll timer!!");
4469 * If we're in one of the idle modes, we have
4470 * not started association yet and thus setting
4471 * those ones to FALSE could cancel an association
4474 wps = connman_network_get_bool(network, "WiFi.UseWPS");
4476 if (is_idle_wps(interface, wifi))
4482 #if defined TIZEN_EXT
4483 if (handle_assoc_status_code(interface, wifi)) {
4484 const char *group = connman_network_get_group(network);
4485 GSupplicantNetwork *supplicant_network;
4486 GSList *bssid_list = NULL;
4487 guint bssid_length = 0;
4490 supplicant_network = g_supplicant_interface_get_network(interface, group);
4492 connman_network_set_assoc_reject_table(network,
4493 g_supplicant_network_get_assoc_reject_table(supplicant_network));
4495 g_supplicant_network_update_assoc_reject(interface, supplicant_network);
4498 bssid_list = (GSList *)connman_network_get_bssid_list(network);
4500 bssid_length = g_slist_length(bssid_list);
4502 if (bssid_length > 1 && bssid_length > g_hash_table_size(failed_bssids)) {
4503 network_connect(network);
4507 wifi->load_shaping_retries = 0;
4510 g_hash_table_remove_all(failed_bssids);
4512 if (handle_assoc_status_code(interface, wifi))
4516 /* If previous state was 4way-handshake, then
4517 * it's either: psk was incorrect and thus we retry
4518 * or if we reach the maximum retries we declare the
4520 if (handle_4way_handshake_failure(interface,
4524 /* See table 8-36 Reason codes in IEEE Std 802.11 */
4525 switch (wifi->disconnect_code) {
4526 case 1: /* Unspecified reason */
4527 /* Let's assume it's because we got blocked */
4529 case 6: /* Class 2 frame received from nonauthenticated STA */
4530 connman_network_set_error(network,
4531 CONNMAN_NETWORK_ERROR_BLOCKED);
4538 #if defined TIZEN_EXT
4539 /* Some of Wi-Fi networks are not comply Wi-Fi specification.
4540 * Retry association until its retry count is expired */
4541 if (handle_wifi_assoc_retry(network, wifi) == true) {
4542 throw_wifi_scan(wifi->device, scan_callback);
4543 wifi->scan_pending_network = wifi->network;
4547 if(wifi->disconnect_code > 0){
4548 DBG("Set disconnect reason code(%d)", wifi->disconnect_code);
4549 connman_network_set_disconnect_reason(network, wifi->disconnect_code);
4553 if (network != wifi->pending_network) {
4554 connman_network_set_connected(network, false);
4555 connman_network_set_associating(network, false);
4557 wifi->disconnecting = false;
4559 start_autoscan(device);
4563 case G_SUPPLICANT_STATE_INACTIVE:
4564 #if defined TIZEN_EXT
4565 if (handle_wps_completion(interface, network, device, wifi) == false)
4568 connman_network_set_associating(network, false);
4569 start_autoscan(device);
4573 case G_SUPPLICANT_STATE_UNKNOWN:
4574 case G_SUPPLICANT_STATE_DISABLED:
4575 case G_SUPPLICANT_STATE_ASSOCIATED:
4576 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4577 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4581 old_connected = wifi->connected;
4582 wifi->state = state;
4584 /* Saving wpa_s state policy:
4585 * If connected and if the state changes are roaming related:
4586 * --> We stay connected
4588 * --> We are connected
4590 * --> We are not connected
4593 case G_SUPPLICANT_STATE_AUTHENTICATING:
4594 case G_SUPPLICANT_STATE_ASSOCIATING:
4595 case G_SUPPLICANT_STATE_ASSOCIATED:
4596 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4597 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4598 if (wifi->connected)
4599 connman_warn("Probably roaming right now!"
4600 " Staying connected...");
4602 case G_SUPPLICANT_STATE_SCANNING:
4603 wifi->connected = false;
4606 start_autoscan(device);
4608 case G_SUPPLICANT_STATE_COMPLETED:
4609 wifi->connected = true;
4612 wifi->connected = false;
4619 static void interface_removed(GSupplicantInterface *interface)
4621 const char *ifname = g_supplicant_interface_get_ifname(interface);
4622 struct wifi_data *wifi;
4623 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4625 * Note: If supplicant interface's driver is wired then skip it,
4626 * because it meanti only for ethernet not Wi-Fi.
4628 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4630 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4633 DBG("ifname %s", ifname);
4635 wifi = g_supplicant_interface_get_data(interface);
4637 #if defined TIZEN_EXT_WIFI_MESH
4638 if (wifi && wifi->mesh_interface) {
4639 DBG("Notify mesh interface remove");
4640 connman_mesh_notify_interface_remove(true);
4641 struct wifi_mesh_info *mesh_info = wifi->mesh_info;
4642 g_free(mesh_info->parent_ifname);
4643 g_free(mesh_info->ifname);
4644 g_free(mesh_info->identifier);
4646 wifi->mesh_interface = false;
4647 wifi->mesh_info = NULL;
4653 wifi->interface = NULL;
4655 if (wifi && wifi->tethering)
4658 if (!wifi || !wifi->device) {
4659 DBG("wifi interface already removed");
4663 connman_device_set_powered(wifi->device, false);
4665 check_p2p_technology();
4666 #if defined TIZEN_EXT_WIFI_MESH
4667 check_mesh_technology();
4671 static void set_device_type(const char *type, char dev_type[17])
4673 const char *oui = "0050F204";
4674 const char *category = "0001";
4675 const char *sub_category = "0000";
4677 if (!g_strcmp0(type, "handset")) {
4679 sub_category = "0005";
4680 } else if (!g_strcmp0(type, "vm") || !g_strcmp0(type, "container"))
4681 sub_category = "0001";
4682 else if (!g_strcmp0(type, "server"))
4683 sub_category = "0002";
4684 else if (!g_strcmp0(type, "laptop"))
4685 sub_category = "0005";
4686 else if (!g_strcmp0(type, "desktop"))
4687 sub_category = "0006";
4688 else if (!g_strcmp0(type, "tablet"))
4689 sub_category = "0009";
4690 else if (!g_strcmp0(type, "watch"))
4693 snprintf(dev_type, 17, "%s%s%s", category, oui, sub_category);
4696 static void p2p_support(GSupplicantInterface *interface)
4698 char dev_type[17] = {};
4699 const char *hostname;
4700 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4702 * Note: If supplicant interface's driver is wired then skip it,
4703 * because it meanti only for ethernet not Wi-Fi.
4705 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4707 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4715 if (!g_supplicant_interface_has_p2p(interface))
4718 if (connman_technology_driver_register(&p2p_tech_driver) < 0) {
4719 DBG("Could not register P2P technology driver");
4723 hostname = connman_utsname_get_hostname();
4725 hostname = "ConnMan";
4727 set_device_type(connman_machine_get_type(), dev_type);
4728 g_supplicant_interface_set_p2p_device_config(interface,
4729 hostname, dev_type);
4730 connman_peer_driver_register(&peer_driver);
4733 static void scan_started(GSupplicantInterface *interface)
4735 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4737 * Note: If supplicant interface's driver is wired then skip it,
4738 * because it meanti only for ethernet not Wi-Fi.
4740 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4742 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4747 static void scan_finished(GSupplicantInterface *interface)
4749 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4751 * Note: If supplicant interface's driver is wired then skip it,
4752 * because it meanti only for ethernet not Wi-Fi.
4754 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4756 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4758 #if defined TIZEN_EXT
4759 struct wifi_data *wifi;
4760 bool is_associating = false;
4761 static bool is_scanning = true;
4766 #if defined TIZEN_EXT
4767 wifi = g_supplicant_interface_get_data(interface);
4768 if (wifi && wifi->scan_pending_network) {
4769 network_connect(wifi->scan_pending_network);
4770 wifi->scan_pending_network = NULL;
4773 //service state - associating
4774 if(!wifi || !wifi->network)
4777 is_associating = connman_network_get_associating(wifi->network);
4778 if(is_associating && is_scanning){
4779 is_scanning = false;
4780 DBG("send scan for connecting");
4781 throw_wifi_scan(wifi->device, scan_callback);
4792 static void ap_create_fail(GSupplicantInterface *interface)
4794 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4796 * Note: If supplicant interface's driver is wired then skip it,
4797 * because it meanti only for ethernet not Wi-Fi.
4799 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4801 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4803 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
4806 if ((wifi->tethering) && (wifi->tethering_param)) {
4807 DBG("%s create AP fail \n",
4808 g_supplicant_interface_get_ifname(wifi->interface));
4810 connman_inet_remove_from_bridge(wifi->index, wifi->bridge);
4811 wifi->ap_supported = WIFI_AP_NOT_SUPPORTED;
4812 wifi->tethering = false;
4814 ret = tech_set_tethering(wifi->tethering_param->technology,
4815 wifi->tethering_param->ssid->ssid,
4816 wifi->tethering_param->ssid->passphrase,
4817 wifi->bridge, true);
4819 if ((ret == -EOPNOTSUPP) && (wifi_technology)) {
4820 connman_technology_tethering_notify(wifi_technology,false);
4823 g_free(wifi->tethering_param->ssid);
4824 g_free(wifi->tethering_param);
4825 wifi->tethering_param = NULL;
4829 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
4831 unsigned char strength;
4833 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
4834 #if !defined TIZEN_EXT
4842 #if defined TIZEN_EXT_WIFI_MESH
4843 static void mesh_peer_added(GSupplicantNetwork *supplicant_network)
4845 GSupplicantInterface *interface;
4846 struct wifi_data *wifi;
4847 const char *name, *security;
4848 struct connman_mesh *connman_mesh;
4849 struct wifi_mesh_info *mesh_info;
4850 const unsigned char *bssid;
4851 const char *identifier;
4856 interface = g_supplicant_network_get_interface(supplicant_network);
4857 wifi = g_supplicant_interface_get_data(interface);
4858 if (!wifi || !wifi->mesh_interface) {
4859 DBG("Virtual Mesh interface not created");
4863 bssid = g_supplicant_network_get_bssid(supplicant_network);
4864 address = g_malloc0(19);
4865 snprintf(address, 19, "%02x:%02x:%02x:%02x:%02x:%02x", bssid[0], bssid[1],
4866 bssid[2], bssid[3], bssid[4], bssid[5]);
4868 identifier = g_supplicant_network_get_identifier(supplicant_network);
4869 name = g_supplicant_network_get_name(supplicant_network);
4870 security = g_supplicant_network_get_security(supplicant_network);
4871 frequency = g_supplicant_network_get_frequency(supplicant_network);
4873 mesh_info = wifi->mesh_info;
4874 connman_mesh = connman_mesh_get(mesh_info->identifier, identifier);
4878 DBG("Mesh Peer name %s identifier %s security %s added", name, identifier,
4880 connman_mesh = connman_mesh_create(mesh_info->identifier, identifier);
4881 connman_mesh_set_name(connman_mesh, name);
4882 connman_mesh_set_security(connman_mesh, security);
4883 connman_mesh_set_frequency(connman_mesh, frequency);
4884 connman_mesh_set_address(connman_mesh, address);
4885 connman_mesh_set_index(connman_mesh, mesh_info->index);
4886 connman_mesh_set_strength(connman_mesh,
4887 calculate_strength(supplicant_network));
4888 connman_mesh_set_peer_type(connman_mesh, CONNMAN_MESH_PEER_TYPE_DISCOVERED);
4890 ret = connman_mesh_register(connman_mesh);
4891 if (ret == -EALREADY)
4892 DBG("Mesh Peer is already registered");
4898 static void mesh_peer_removed(GSupplicantNetwork *supplicant_network)
4900 GSupplicantInterface *interface;
4901 struct wifi_data *wifi;
4902 struct connman_mesh *connman_mesh;
4903 struct wifi_mesh_info *mesh_info;
4904 const char *identifier;
4906 interface = g_supplicant_network_get_interface(supplicant_network);
4907 wifi = g_supplicant_interface_get_data(interface);
4908 if (!wifi || !wifi->mesh_interface) {
4909 DBG("Virtual Mesh interface not created");
4913 identifier = g_supplicant_network_get_identifier(supplicant_network);
4915 DBG("Failed to get Mesh Peer identifier");
4919 mesh_info = wifi->mesh_info;
4920 connman_mesh = connman_mesh_get(mesh_info->identifier, identifier);
4922 /* Do not unregister connected mesh peer */
4923 if (connman_mesh_peer_is_connected_state(connman_mesh)) {
4924 DBG("Mesh Peer %s is connected", identifier);
4927 DBG("Mesh Peer identifier %s removed", identifier);
4928 connman_mesh_unregister(connman_mesh);
4933 static void network_added(GSupplicantNetwork *supplicant_network)
4935 struct connman_network *network;
4936 GSupplicantInterface *interface;
4937 struct wifi_data *wifi;
4938 const char *name, *identifier, *security, *group, *mode;
4939 const unsigned char *ssid;
4940 unsigned int ssid_len;
4944 bool wps_advertizing;
4946 #if defined TIZEN_EXT
4947 bool owe_transition_mode;
4948 const unsigned char *transition_mode_ssid;
4949 const unsigned char *transition_mode_bssid;
4950 unsigned int transition_mode_ssid_len;
4951 GSList *vsie_list = NULL;
4952 const unsigned char *country_code;
4953 ieee80211_modes_e phy_mode;
4956 mode = g_supplicant_network_get_mode(supplicant_network);
4957 identifier = g_supplicant_network_get_identifier(supplicant_network);
4958 #if defined TIZEN_EXT
4959 if (!simplified_log)
4961 DBG("%s", identifier);
4963 if (!g_strcmp0(mode, "adhoc"))
4966 #if defined TIZEN_EXT_WIFI_MESH
4967 if (!g_strcmp0(mode, "mesh")) {
4968 mesh_peer_added(supplicant_network);
4973 interface = g_supplicant_network_get_interface(supplicant_network);
4974 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4976 * Note: If supplicant interface's driver is wired then skip it,
4977 * because it meanti only for ethernet not Wi-Fi.
4979 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4981 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4983 wifi = g_supplicant_interface_get_data(interface);
4984 name = g_supplicant_network_get_name(supplicant_network);
4985 security = g_supplicant_network_get_security(supplicant_network);
4986 group = g_supplicant_network_get_identifier(supplicant_network);
4987 wps = g_supplicant_network_get_wps(supplicant_network);
4988 wps_pbc = g_supplicant_network_is_wps_pbc(supplicant_network);
4989 wps_ready = g_supplicant_network_is_wps_active(supplicant_network);
4990 wps_advertizing = g_supplicant_network_is_wps_advertizing(
4991 supplicant_network);
4996 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
4998 network = connman_device_get_network(wifi->device, identifier);
5001 network = connman_network_create(identifier,
5002 CONNMAN_NETWORK_TYPE_WIFI);
5006 connman_network_set_index(network, wifi->index);
5008 if (connman_device_add_network(wifi->device, network) < 0) {
5009 connman_network_unref(network);
5013 wifi->networks = g_slist_prepend(wifi->networks, network);
5016 if (name && name[0] != '\0')
5017 connman_network_set_name(network, name);
5019 connman_network_set_blob(network, "WiFi.SSID",
5021 #if defined TIZEN_EXT
5022 vsie_list = (GSList *)g_supplicant_network_get_wifi_vsie(supplicant_network);
5024 connman_network_set_vsie_list(network, vsie_list);
5026 DBG("vsie_list is NULL");
5027 country_code = g_supplicant_network_get_countrycode(supplicant_network);
5028 connman_network_set_countrycode(network, country_code);
5029 phy_mode = g_supplicant_network_get_phy_mode(supplicant_network);
5030 connman_network_set_phy_mode(network, phy_mode);
5032 connman_network_set_string(network, "WiFi.Security", security);
5033 connman_network_set_strength(network,
5034 calculate_strength(supplicant_network));
5035 connman_network_set_bool(network, "WiFi.WPS", wps);
5036 connman_network_set_bool(network, "WiFi.WPSAdvertising",
5040 /* Is AP advertizing for WPS association?
5041 * If so, we decide to use WPS by default */
5042 if (wps_ready && wps_pbc &&
5044 #if !defined TIZEN_EXT
5045 connman_network_set_bool(network, "WiFi.UseWPS", true);
5047 DBG("wps is activating by ap but ignore it.");
5051 connman_network_set_frequency(network,
5052 g_supplicant_network_get_frequency(supplicant_network));
5054 #if defined TIZEN_EXT
5055 connman_network_set_bssid(network,
5056 g_supplicant_network_get_bssid(supplicant_network));
5057 owe_transition_mode = (bool)g_supplicant_network_get_transition_mode(supplicant_network);
5058 connman_network_set_bool(network, "WiFi.TRANSITION_MODE", owe_transition_mode);
5059 if (owe_transition_mode) {
5060 transition_mode_ssid = (unsigned char *)g_supplicant_network_get_transition_mode_ssid(supplicant_network, &transition_mode_ssid_len);
5061 connman_network_set_blob(network, "WiFi.TRANSITION_MODE_SSID",
5062 transition_mode_ssid, transition_mode_ssid_len);
5063 transition_mode_bssid = g_supplicant_network_get_transition_mode_bssid(supplicant_network);
5064 connman_network_set_transition_mode_bssid(network, transition_mode_bssid);
5066 connman_network_set_maxrate(network,
5067 g_supplicant_network_get_maxrate(supplicant_network));
5068 connman_network_set_enc_mode(network,
5069 g_supplicant_network_get_enc_mode(supplicant_network));
5070 connman_network_set_rsn_mode(network,
5071 g_supplicant_network_get_rsn_mode(supplicant_network));
5072 connman_network_set_keymgmt(network,
5073 g_supplicant_network_get_keymgmt(supplicant_network));
5074 connman_network_set_bool(network, "WiFi.HS20AP",
5075 g_supplicant_network_is_hs20AP(supplicant_network));
5076 connman_network_set_bssid_list(network,
5077 (GSList *)g_supplicant_network_get_bssid_list(supplicant_network));
5078 connman_network_set_last_connected_bssid(network,
5079 g_supplicant_network_get_last_connected_bssid(supplicant_network));
5080 connman_network_set_assoc_reject_table(network,
5081 g_supplicant_network_get_assoc_reject_table(supplicant_network));
5083 connman_network_set_available(network, true);
5084 connman_network_set_string(network, "WiFi.Mode", mode);
5086 #if defined TIZEN_EXT
5091 connman_network_set_group(network, group);
5093 #if defined TIZEN_EXT
5094 g_supplicant_network_set_last_connected_bssid(supplicant_network,
5095 connman_network_get_last_connected_bssid(network));
5098 #if defined TIZEN_EXT
5099 if (wifi_first_scan == true)
5100 found_with_first_scan = true;
5103 if (wifi->hidden && ssid) {
5104 #if defined TIZEN_EXT
5105 if (network_security(wifi->hidden->security) ==
5106 network_security(security) &&
5108 if (!g_strcmp0(wifi->hidden->security, security) &&
5110 wifi->hidden->ssid_len == ssid_len &&
5111 !memcmp(wifi->hidden->ssid, ssid, ssid_len)) {
5112 connman_network_connect_hidden(network,
5113 wifi->hidden->identity,
5114 wifi->hidden->passphrase,
5115 wifi->hidden->user_data);
5116 wifi->hidden->user_data = NULL;
5117 hidden_free(wifi->hidden);
5118 wifi->hidden = NULL;
5123 static void network_removed(GSupplicantNetwork *network)
5125 GSupplicantInterface *interface;
5126 struct wifi_data *wifi;
5127 const char *name, *identifier;
5128 struct connman_network *connman_network;
5130 #if defined TIZEN_EXT_WIFI_MESH
5132 mode = g_supplicant_network_get_mode(network);
5133 if (!g_strcmp0(mode, "mesh")) {
5134 mesh_peer_removed(network);
5139 interface = g_supplicant_network_get_interface(network);
5140 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5142 * Note: If supplicant interface's driver is wired then skip it,
5143 * because it meanti only for ethernet not Wi-Fi.
5145 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5147 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5149 wifi = g_supplicant_interface_get_data(interface);
5150 identifier = g_supplicant_network_get_identifier(network);
5151 name = g_supplicant_network_get_name(network);
5153 DBG("name %s", name);
5158 connman_network = connman_device_get_network(wifi->device, identifier);
5159 if (!connman_network)
5162 #if defined TIZEN_EXT
5163 if (connman_network == wifi->scan_pending_network)
5164 wifi->scan_pending_network = NULL;
5166 if (connman_network == wifi->pending_network)
5167 wifi->pending_network = NULL;
5169 if(connman_network_get_connecting(connman_network) == true){
5170 connman_network_set_connected(connman_network, false);
5174 wifi->networks = g_slist_remove(wifi->networks, connman_network);
5176 connman_device_remove_network(wifi->device, connman_network);
5177 connman_network_unref(connman_network);
5180 static void network_changed(GSupplicantNetwork *network, const char *property)
5182 GSupplicantInterface *interface;
5183 struct wifi_data *wifi;
5184 const char *name, *identifier;
5185 struct connman_network *connman_network;
5188 #if defined TIZEN_EXT
5189 const unsigned char *bssid;
5190 unsigned int maxrate;
5193 const unsigned char *country_code;
5194 ieee80211_modes_e phy_mode;
5198 interface = g_supplicant_network_get_interface(network);
5199 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5201 * Note: If supplicant interface's driver is wired then skip it,
5202 * because it meanti only for ethernet not Wi-Fi.
5204 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5206 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5208 wifi = g_supplicant_interface_get_data(interface);
5209 identifier = g_supplicant_network_get_identifier(network);
5210 name = g_supplicant_network_get_name(network);
5212 #if defined TIZEN_EXT
5213 if (!simplified_log)
5214 DBG("name %s property %s", name, property);
5216 DBG("name %s", name);
5222 connman_network = connman_device_get_network(wifi->device, identifier);
5223 if (!connman_network)
5226 if (g_str_equal(property, "WPSCapabilities")) {
5230 bool wps_advertizing;
5232 wps = g_supplicant_network_get_wps(network);
5233 wps_pbc = g_supplicant_network_is_wps_pbc(network);
5234 wps_ready = g_supplicant_network_is_wps_active(network);
5236 g_supplicant_network_is_wps_advertizing(network);
5238 connman_network_set_bool(connman_network, "WiFi.WPS", wps);
5239 connman_network_set_bool(connman_network,
5240 "WiFi.WPSAdvertising", wps_advertizing);
5244 * Is AP advertizing for WPS association?
5245 * If so, we decide to use WPS by default
5247 if (wps_ready && wps_pbc && wps_advertizing)
5248 connman_network_set_bool(connman_network,
5249 "WiFi.UseWPS", true);
5252 update_needed = true;
5253 } else if (g_str_equal(property, "Signal")) {
5254 connman_network_set_strength(connman_network,
5255 calculate_strength(network));
5256 update_needed = true;
5258 #if defined TIZEN_EXT
5259 else if (g_str_equal(property, "LastConnectedBSSID")) {
5260 const char *ident, *group;
5261 char *service_ident;
5264 ident = connman_device_get_ident(wifi->device);
5265 group = connman_network_get_group(connman_network);
5266 if (ident && group) {
5267 service_ident = g_strdup_printf("%s_%s_%s",
5268 __connman_network_get_type(connman_network), ident, group);
5270 need_save = connman_device_set_last_connected_ident(wifi->device, service_ident);
5272 connman_device_save_last_connected(wifi->device);
5274 g_free(service_ident);
5277 connman_network_set_last_connected_bssid(connman_network,
5278 g_supplicant_network_get_last_connected_bssid(network));
5280 update_needed = true;
5281 } else if (g_str_equal(property, "UpdateAssocReject")) {
5282 connman_network_set_assoc_reject_table(connman_network,
5283 g_supplicant_network_get_assoc_reject_table(network));
5284 update_needed = true;
5288 update_needed = false;
5291 connman_network_update(connman_network);
5293 #if defined TIZEN_EXT
5294 bssid = g_supplicant_network_get_bssid(network);
5295 maxrate = g_supplicant_network_get_maxrate(network);
5296 frequency = g_supplicant_network_get_frequency(network);
5297 wps = g_supplicant_network_get_wps(network);
5298 phy_mode = g_supplicant_network_get_phy_mode(network);
5300 connman_network_set_bssid(connman_network, bssid);
5301 connman_network_set_maxrate(connman_network, maxrate);
5302 connman_network_set_frequency(connman_network, frequency);
5303 connman_network_set_bool(connman_network, "WiFi.WPS", wps);
5304 country_code = g_supplicant_network_get_countrycode(network);
5305 connman_network_set_countrycode(connman_network, country_code);
5306 bssid_list = (GSList *)g_supplicant_network_get_bssid_list(network);
5307 connman_network_set_bssid_list(connman_network, bssid_list);
5308 connman_network_set_phy_mode(connman_network, phy_mode);
5310 if (g_str_equal(property, "CheckMultiBssidConnect") &&
5311 connman_network_get_associating(connman_network))
5312 network_connect(connman_network);
5316 static void network_associated(GSupplicantNetwork *network)
5318 GSupplicantInterface *interface;
5319 struct wifi_data *wifi;
5320 struct connman_network *connman_network;
5321 const char *identifier;
5325 interface = g_supplicant_network_get_interface(network);
5328 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5330 * Note: If supplicant interface's driver is wired then skip it,
5331 * because it meanti only for ethernet not Wi-Fi.
5333 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5335 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5338 wifi = g_supplicant_interface_get_data(interface);
5342 /* P2P networks must not be treated as WiFi networks */
5343 if (wifi->p2p_connecting || wifi->p2p_device)
5346 identifier = g_supplicant_network_get_identifier(network);
5348 connman_network = connman_device_get_network(wifi->device, identifier);
5349 if (!connman_network)
5352 if (wifi->network) {
5353 if (wifi->network == connman_network)
5356 unsigned int ssid_len;
5357 DBG("network1 ssid[%s] , OWE[%d],ssid[%s]",
5358 (char *)connman_network_get_blob(wifi->network,"WiFi.SSID", &ssid_len),
5359 connman_network_get_bool(wifi->network,"WiFi.TRANSITION_MODE"),
5360 (char *)connman_network_get_blob(wifi->network,"WiFi.TRANSITION_MODE_SSID", &ssid_len));
5362 DBG("network1 ssid[%s], OWE[%d], ssid[%s]",
5363 (char *)connman_network_get_blob(connman_network,"WiFi.SSID",&ssid_len),
5364 connman_network_get_bool(connman_network,"WiFi.TRANSITION_MODE"),
5365 (char *)connman_network_get_blob(connman_network,"WiFi.TRANSITION_MODE_SSID", &ssid_len));
5366 if (connman_network_check_transition_mode(wifi->network, connman_network)) {//OWE trasition mode check
5367 DBG("OWE transition mode is TRUE");
5372 * This should never happen, we got associated with
5373 * a network different than the one we were expecting.
5375 DBG("Associated to %p while expecting %p",
5376 connman_network, wifi->network);
5378 connman_network_set_associating(wifi->network, false);
5381 DBG("Reconnecting to previous network %p from wpa_s", connman_network);
5383 wifi->network = connman_network_ref(connman_network);
5387 * Interface state changes callback (interface_state) is always
5388 * called before network_associated callback thus we need to call
5389 * interface_state again in order to process the new state now that
5390 * we have the network properly set.
5392 interface_state(interface);
5395 static void sta_authorized(GSupplicantInterface *interface,
5398 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5400 * Note: If supplicant interface's driver is wired then skip it,
5401 * because it meanti only for ethernet not Wi-Fi.
5403 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5405 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5407 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5409 DBG("wifi %p station %s authorized", wifi, addr);
5411 if (!wifi || !wifi->tethering)
5414 __connman_tethering_client_register(addr);
5417 static void sta_deauthorized(GSupplicantInterface *interface,
5420 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5422 * Note: If supplicant interface's driver is wired then skip it,
5423 * because it meanti only for ethernet not Wi-Fi.
5425 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5427 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5429 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5431 DBG("wifi %p station %s deauthorized", wifi, addr);
5433 if (!wifi || !wifi->tethering)
5436 __connman_tethering_client_unregister(addr);
5439 static void apply_peer_services(GSupplicantPeer *peer,
5440 struct connman_peer *connman_peer)
5442 const unsigned char *data;
5447 connman_peer_reset_services(connman_peer);
5449 data = g_supplicant_peer_get_widi_ies(peer, &length);
5451 connman_peer_add_service(connman_peer,
5452 CONNMAN_PEER_SERVICE_WIFI_DISPLAY, data, length);
5456 static void peer_found(GSupplicantPeer *peer)
5458 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5459 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5460 struct connman_peer *connman_peer;
5461 const char *identifier, *name;
5464 #if defined TIZEN_EXT
5468 identifier = g_supplicant_peer_get_identifier(peer);
5469 name = g_supplicant_peer_get_name(peer);
5471 DBG("ident: %s", identifier);
5473 connman_peer = connman_peer_get(wifi->device, identifier);
5477 connman_peer = connman_peer_create(identifier);
5478 connman_peer_set_name(connman_peer, name);
5479 connman_peer_set_device(connman_peer, wifi->device);
5480 apply_peer_services(peer, connman_peer);
5482 ret = connman_peer_register(connman_peer);
5483 if (ret < 0 && ret != -EALREADY)
5484 connman_peer_unref(connman_peer);
5486 wifi->peers = g_slist_prepend(wifi->peers, connman_peer);
5489 static void peer_lost(GSupplicantPeer *peer)
5491 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5492 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5493 struct connman_peer *connman_peer;
5494 const char *identifier;
5499 identifier = g_supplicant_peer_get_identifier(peer);
5501 DBG("ident: %s", identifier);
5503 connman_peer = connman_peer_get(wifi->device, identifier);
5505 if (wifi->p2p_connecting &&
5506 wifi->pending_peer == connman_peer) {
5507 peer_connect_timeout(wifi);
5509 connman_peer_unregister(connman_peer);
5510 connman_peer_unref(connman_peer);
5513 wifi->peers = g_slist_remove(wifi->peers, connman_peer);
5516 static void peer_changed(GSupplicantPeer *peer, GSupplicantPeerState state)
5518 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5519 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5520 enum connman_peer_state p_state = CONNMAN_PEER_STATE_UNKNOWN;
5521 struct connman_peer *connman_peer;
5522 const char *identifier;
5524 identifier = g_supplicant_peer_get_identifier(peer);
5526 DBG("ident: %s", identifier);
5531 connman_peer = connman_peer_get(wifi->device, identifier);
5536 case G_SUPPLICANT_PEER_SERVICES_CHANGED:
5537 apply_peer_services(peer, connman_peer);
5538 connman_peer_services_changed(connman_peer);
5540 case G_SUPPLICANT_PEER_GROUP_CHANGED:
5541 if (!g_supplicant_peer_is_in_a_group(peer))
5542 p_state = CONNMAN_PEER_STATE_IDLE;
5544 p_state = CONNMAN_PEER_STATE_CONFIGURATION;
5546 case G_SUPPLICANT_PEER_GROUP_STARTED:
5548 case G_SUPPLICANT_PEER_GROUP_FINISHED:
5549 p_state = CONNMAN_PEER_STATE_IDLE;
5551 case G_SUPPLICANT_PEER_GROUP_JOINED:
5552 connman_peer_set_iface_address(connman_peer,
5553 g_supplicant_peer_get_iface_address(peer));
5555 case G_SUPPLICANT_PEER_GROUP_DISCONNECTED:
5556 p_state = CONNMAN_PEER_STATE_IDLE;
5558 case G_SUPPLICANT_PEER_GROUP_FAILED:
5559 if (g_supplicant_peer_has_requested_connection(peer))
5560 p_state = CONNMAN_PEER_STATE_IDLE;
5562 p_state = CONNMAN_PEER_STATE_FAILURE;
5566 if (p_state == CONNMAN_PEER_STATE_CONFIGURATION ||
5567 p_state == CONNMAN_PEER_STATE_FAILURE) {
5568 if (wifi->p2p_connecting
5569 && connman_peer == wifi->pending_peer)
5570 peer_cancel_timeout(wifi);
5572 p_state = CONNMAN_PEER_STATE_UNKNOWN;
5575 if (p_state == CONNMAN_PEER_STATE_UNKNOWN)
5578 if (p_state == CONNMAN_PEER_STATE_CONFIGURATION) {
5579 GSupplicantInterface *g_iface;
5580 struct wifi_data *g_wifi;
5582 g_iface = g_supplicant_peer_get_group_interface(peer);
5586 g_wifi = g_supplicant_interface_get_data(g_iface);
5590 connman_peer_set_as_master(connman_peer,
5591 !g_supplicant_peer_is_client(peer));
5592 connman_peer_set_sub_device(connman_peer, g_wifi->device);
5595 * If wpa_supplicant didn't create a dedicated p2p-group
5596 * interface then mark this interface as p2p_device to avoid
5597 * scan and auto-scan are launched on it while P2P is connected.
5599 if (!g_list_find(p2p_iface_list, g_wifi))
5600 wifi->p2p_device = true;
5603 connman_peer_set_state(connman_peer, p_state);
5606 static void peer_request(GSupplicantPeer *peer)
5608 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5609 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5610 struct connman_peer *connman_peer;
5611 const char *identifier;
5613 #if defined TIZEN_EXT
5618 identifier = g_supplicant_peer_get_identifier(peer);
5620 DBG("ident: %s", identifier);
5622 connman_peer = connman_peer_get(wifi->device, identifier);
5626 connman_peer_request_connection(connman_peer);
5629 #if defined TIZEN_EXT
5630 static void system_power_off(void)
5633 struct wifi_data *wifi;
5634 struct connman_service *service;
5635 struct connman_ipconfig *ipconfig_ipv4;
5637 if (connman_setting_get_bool("WiFiDHCPRelease") == true) {
5638 for (list = iface_list; list; list = list->next) {
5641 if (wifi->network != NULL) {
5642 service = connman_service_lookup_from_network(wifi->network);
5643 ipconfig_ipv4 = __connman_service_get_ip4config(service);
5644 __connman_dhcp_stop(ipconfig_ipv4);
5650 static void network_merged(GSupplicantNetwork *network)
5652 GSupplicantInterface *interface;
5653 GSupplicantState state;
5654 struct wifi_data *wifi;
5655 const char *identifier;
5656 struct connman_network *connman_network;
5660 interface = g_supplicant_network_get_interface(network);
5664 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5666 * Note: If supplicant interface's driver is wired then skip it,
5667 * because it meanti only for ethernet not Wi-Fi.
5669 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5671 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5673 state = g_supplicant_interface_get_state(interface);
5674 if (state < G_SUPPLICANT_STATE_AUTHENTICATING)
5677 wifi = g_supplicant_interface_get_data(interface);
5681 identifier = g_supplicant_network_get_identifier(network);
5683 connman_network = connman_device_get_network(wifi->device, identifier);
5684 if (!connman_network)
5687 DBG("merged identifier %s", identifier);
5689 if (wifi->connected == FALSE) {
5691 case G_SUPPLICANT_STATE_AUTHENTICATING:
5692 case G_SUPPLICANT_STATE_ASSOCIATING:
5693 case G_SUPPLICANT_STATE_ASSOCIATED:
5694 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
5695 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
5696 connman_network_set_associating(connman_network, TRUE);
5698 case G_SUPPLICANT_STATE_COMPLETED:
5699 connman_network_set_connected(connman_network, TRUE);
5702 DBG("Not handled the state : %d", state);
5707 ishs20AP = g_supplicant_network_is_hs20AP(network);
5710 g_strcmp0(g_supplicant_network_get_security(network), "ieee8021x") == 0) {
5711 temp = g_ascii_strdown(g_supplicant_network_get_eap(network), -1);
5712 connman_network_set_string(connman_network, "WiFi.EAP",
5714 connman_network_set_string(connman_network, "WiFi.Identity",
5715 g_supplicant_network_get_identity(network));
5716 connman_network_set_string(connman_network, "WiFi.Phase2",
5717 g_supplicant_network_get_phase2(network));
5722 wifi->network = connman_network;
5725 static void assoc_failed(void *user_data)
5727 struct connman_network *network = user_data;
5728 connman_network_set_associating(network, false);
5731 static void scan_done(GSupplicantInterface *interface)
5733 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5735 * Note: If supplicant interface's driver is wired then skip it,
5736 * because it meanti only for ethernet not Wi-Fi.
5738 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5740 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5743 int scan_type = CONNMAN_SCAN_TYPE_WPA_SUPPLICANT;
5744 struct wifi_data *wifi;
5747 for (list = iface_list; list; list = list->next) {
5750 if (interface == wifi->interface) {
5751 scanning = connman_device_get_scanning(wifi->device,
5752 CONNMAN_SERVICE_TYPE_WIFI);
5754 __connman_technology_notify_scan_done(
5755 connman_device_get_string(wifi->device, "Interface"), scan_type);
5762 static void debug(const char *str)
5764 #if defined TIZEN_EXT
5765 if (connman_setting_get_bool("ConnmanSupplicantDebug"))
5767 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
5769 connman_debug("%s", str);
5772 static void disconnect_reasoncode(GSupplicantInterface *interface,
5775 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5777 * Note: If supplicant interface's driver is wired then skip it,
5778 * because it meanti only for ethernet not Wi-Fi.
5780 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5782 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5784 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5787 wifi->disconnect_code = reasoncode;
5791 static void assoc_status_code(GSupplicantInterface *interface, int status_code)
5793 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5795 * Note: If supplicant interface's driver is wired then skip it,
5796 * because it meanti only for ethernet not Wi-Fi.
5798 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5800 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5802 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5805 wifi->assoc_code = status_code;
5809 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5810 static GSupplicantCallbacks callbacks = {
5811 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5812 static const GSupplicantCallbacks callbacks = {
5813 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5814 .system_ready = system_ready,
5815 .system_killed = system_killed,
5816 .interface_added = interface_added,
5817 .interface_state = interface_state,
5818 .interface_removed = interface_removed,
5819 .p2p_support = p2p_support,
5820 .scan_started = scan_started,
5821 .scan_finished = scan_finished,
5822 .ap_create_fail = ap_create_fail,
5823 .network_added = network_added,
5824 .network_removed = network_removed,
5825 .network_changed = network_changed,
5826 .network_associated = network_associated,
5827 .sta_authorized = sta_authorized,
5828 .sta_deauthorized = sta_deauthorized,
5829 .peer_found = peer_found,
5830 .peer_lost = peer_lost,
5831 .peer_changed = peer_changed,
5832 .peer_request = peer_request,
5833 #if defined TIZEN_EXT
5834 .system_power_off = system_power_off,
5835 .network_merged = network_merged,
5836 .assoc_failed = assoc_failed,
5837 .scan_done = scan_done,
5840 .disconnect_reasoncode = disconnect_reasoncode,
5841 .assoc_status_code = assoc_status_code,
5842 #if defined TIZEN_EXT_WIFI_MESH
5843 .mesh_support = mesh_support,
5844 .mesh_group_started = mesh_group_started,
5845 .mesh_group_removed = mesh_group_removed,
5846 .mesh_peer_connected = mesh_peer_connected,
5847 .mesh_peer_disconnected = mesh_peer_disconnected,
5852 static int tech_probe(struct connman_technology *technology)
5854 wifi_technology = technology;
5859 static void tech_remove(struct connman_technology *technology)
5861 wifi_technology = NULL;
5864 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
5866 GSupplicantSSID *ap;
5868 ap = g_try_malloc0(sizeof(GSupplicantSSID));
5872 ap->mode = G_SUPPLICANT_MODE_MASTER;
5873 #if defined TIZEN_EXT
5874 ap->ssid = (void *) ssid;
5878 ap->ssid_len = strlen(ssid);
5882 if (!passphrase || strlen(passphrase) == 0) {
5883 ap->security = G_SUPPLICANT_SECURITY_NONE;
5884 ap->passphrase = NULL;
5886 ap->security = G_SUPPLICANT_SECURITY_PSK;
5887 ap->protocol = G_SUPPLICANT_PROTO_RSN;
5888 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
5889 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
5890 ap->passphrase = passphrase;
5896 static void ap_start_callback(int result, GSupplicantInterface *interface,
5899 struct wifi_tethering_info *info = user_data;
5901 DBG("result %d index %d bridge %s",
5902 result, info->wifi->index, info->wifi->bridge);
5904 if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
5905 connman_inet_remove_from_bridge(info->wifi->index,
5906 info->wifi->bridge);
5908 if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
5909 connman_technology_tethering_notify(info->technology, false);
5910 g_free(info->wifi->tethering_param->ssid);
5911 g_free(info->wifi->tethering_param);
5912 info->wifi->tethering_param = NULL;
5916 g_free(info->ifname);
5920 static void ap_create_callback(int result,
5921 GSupplicantInterface *interface,
5924 struct wifi_tethering_info *info = user_data;
5926 DBG("result %d ifname %s", result,
5927 g_supplicant_interface_get_ifname(interface));
5929 if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
5930 connman_inet_remove_from_bridge(info->wifi->index,
5931 info->wifi->bridge);
5933 if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
5934 connman_technology_tethering_notify(info->technology, false);
5935 g_free(info->wifi->tethering_param->ssid);
5936 g_free(info->wifi->tethering_param);
5937 info->wifi->tethering_param = NULL;
5941 g_free(info->ifname);
5947 info->wifi->interface = interface;
5948 g_supplicant_interface_set_data(interface, info->wifi);
5950 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
5951 connman_error("Failed to set interface ap_scan property");
5953 g_supplicant_interface_connect(interface, info->ssid,
5954 ap_start_callback, info);
5957 static void sta_remove_callback(int result,
5958 GSupplicantInterface *interface,
5961 struct wifi_tethering_info *info = user_data;
5962 const char *driver = connman_option_get_string("wifi");
5964 DBG("ifname %s result %d ", info->ifname, result);
5966 if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
5967 info->wifi->tethering = false;
5968 connman_technology_tethering_notify(info->technology, false);
5970 if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
5971 g_free(info->wifi->tethering_param->ssid);
5972 g_free(info->wifi->tethering_param);
5973 info->wifi->tethering_param = NULL;
5976 g_free(info->ifname);
5982 info->wifi->interface = NULL;
5984 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
5987 #endif /* TIZEN_EXT */
5992 static int enable_wifi_tethering(struct connman_technology *technology,
5993 const char *bridge, const char *identifier,
5994 const char *passphrase, bool available)
5997 GSupplicantInterface *interface;
5998 struct wifi_data *wifi;
5999 struct wifi_tethering_info *info;
6004 for (list = iface_list; list; list = list->next) {
6007 DBG("wifi %p network %p pending_network %p", wifi,
6008 wifi->network, wifi->pending_network);
6010 interface = wifi->interface;
6015 ifname = g_supplicant_interface_get_ifname(wifi->interface);
6019 if (wifi->ap_supported == WIFI_AP_NOT_SUPPORTED) {
6020 DBG("%s does not support AP mode (detected)", ifname);
6024 mode = g_supplicant_interface_get_mode(interface);
6025 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
6026 wifi->ap_supported = WIFI_AP_NOT_SUPPORTED;
6027 DBG("%s does not support AP mode (capability)", ifname);
6031 if (wifi->network && available)
6034 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
6038 wifi->tethering_param = g_try_malloc0(sizeof(struct wifi_tethering_info));
6039 if (!wifi->tethering_param) {
6045 info->technology = technology;
6046 info->wifi->bridge = bridge;
6047 info->ssid = ssid_ap_init(identifier, passphrase);
6051 info->ifname = g_strdup(ifname);
6053 wifi->tethering_param->technology = technology;
6054 wifi->tethering_param->ssid = ssid_ap_init(identifier, passphrase);
6055 if (!wifi->tethering_param->ssid)
6058 info->wifi->tethering = true;
6059 info->wifi->ap_supported = WIFI_AP_SUPPORTED;
6061 berr = connman_technology_tethering_notify(technology, true);
6065 err = g_supplicant_interface_remove(interface,
6066 sta_remove_callback,
6069 DBG("tethering wifi %p ifname %s", wifi, ifname);
6074 g_free(info->ifname);
6077 g_free(wifi->tethering_param);
6078 wifi->tethering_param = NULL;
6081 * Remove bridge if it was correctly created but remove
6082 * operation failed. Instead, if bridge creation failed then
6083 * break out and do not try again on another interface,
6084 * bridge set-up does not depend on it.
6087 connman_technology_tethering_notify(technology, false);
6095 static int tech_set_tethering(struct connman_technology *technology,
6096 const char *identifier, const char *passphrase,
6097 const char *bridge, bool enabled)
6100 struct wifi_data *wifi;
6106 for (list = iface_list; list; list = list->next) {
6109 if (wifi->tethering) {
6110 wifi->tethering = false;
6112 connman_inet_remove_from_bridge(wifi->index,
6114 wifi->bridged = false;
6118 connman_technology_tethering_notify(technology, false);
6123 DBG("trying tethering for available devices");
6124 err = enable_wifi_tethering(technology, bridge, identifier, passphrase,
6128 DBG("trying tethering for any device");
6129 err = enable_wifi_tethering(technology, bridge, identifier,
6136 static void regdom_callback(int result, const char *alpha2, void *user_data)
6140 if (!wifi_technology)
6146 connman_technology_regdom_notify(wifi_technology, alpha2);
6149 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
6151 return g_supplicant_set_country(alpha2, regdom_callback, NULL);
6154 #if defined TIZEN_EXT
6155 static void supp_ins_init(void)
6158 GSupplicantINSPreferredFreq preferred_freq;
6160 string = connman_option_get_string("INSPreferredFreqBSSID");
6161 if (g_strcmp0(string, "5GHz") == 0)
6162 preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_5GHZ;
6163 else if (g_strcmp0(string, "2.4GHz") == 0)
6164 preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_24GHZ;
6166 preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_UNKNOWN;
6168 g_supplicant_set_ins_settings(preferred_freq,
6169 connman_setting_get_bool("INSLastConnectedBSSID"),
6170 connman_setting_get_bool("INSAssocReject"),
6171 connman_setting_get_bool("INSSignalBSSID"),
6172 connman_setting_get_uint("INSPreferredFreqBSSIDScore"),
6173 connman_setting_get_uint("INSLastConnectedBSSIDScore"),
6174 connman_setting_get_uint("INSAssocRejectScore"),
6175 connman_setting_get_int("INSSignalLevel3_5GHz"),
6176 connman_setting_get_int("INSSignalLevel3_24GHz")
6181 static struct connman_technology_driver tech_driver = {
6183 .type = CONNMAN_SERVICE_TYPE_WIFI,
6184 .probe = tech_probe,
6185 .remove = tech_remove,
6186 .set_tethering = tech_set_tethering,
6187 .set_regdom = tech_set_regdom,
6190 static int wifi_init(void)
6194 err = connman_network_driver_register(&network_driver);
6198 err = g_supplicant_register(&callbacks);
6200 connman_network_driver_unregister(&network_driver);
6204 err = connman_technology_driver_register(&tech_driver);
6206 g_supplicant_unregister(&callbacks);
6207 connman_network_driver_unregister(&network_driver);
6211 #if defined TIZEN_EXT
6212 failed_bssids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
6215 #if defined TIZEN_EXT
6221 static void wifi_exit(void)
6225 connman_technology_driver_unregister(&tech_driver);
6227 g_supplicant_unregister(&callbacks);
6229 connman_network_driver_unregister(&network_driver);
6231 #if defined TIZEN_EXT
6232 g_hash_table_unref(failed_bssids);
6236 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
6237 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)