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 #define CLEANUP_TIMEOUT 8 /* in seconds */
63 #define INACTIVE_TIMEOUT 12 /* in seconds */
64 #define FAVORITE_MAXIMUM_RETRIES 2
66 #define BGSCAN_DEFAULT "simple:30:-45:300"
67 #define AUTOSCAN_EXPONENTIAL "exponential:3:300"
68 #define AUTOSCAN_SINGLE "single:3"
70 #define P2P_FIND_TIMEOUT 30
71 #define P2P_CONNECTION_TIMEOUT 100
72 #define P2P_LISTEN_PERIOD 500
73 #define P2P_LISTEN_INTERVAL 2000
75 #define ASSOC_STATUS_NO_CLIENT 17
77 #define LOAD_SHAPING_MAX_RETRIES 7
79 #define LOAD_SHAPING_MAX_RETRIES 3
83 #define WIFI_EAP_FAST_PAC_FILE "/var/lib/wifi/wifi.pac" /* path of Pac file for EAP-FAST */
86 static struct connman_technology *wifi_technology = NULL;
87 static struct connman_technology *p2p_technology = NULL;
89 enum wifi_ap_capability{
91 WIFI_AP_SUPPORTED = 1,
92 WIFI_AP_NOT_SUPPORTED = 2,
95 enum wifi_scanning_type {
96 WIFI_SCANNING_UNKNOWN = 0,
97 WIFI_SCANNING_PASSIVE = 1,
98 WIFI_SCANNING_ACTIVE = 2,
101 struct hidden_params {
103 unsigned int ssid_len;
105 char *anonymous_identity;
107 char *altsubject_match;
108 char *domain_suffix_match;
112 GSupplicantScanParams *scan_params;
117 * Used for autoscan "emulation".
118 * Should be removed when wpa_s autoscan support will be by default.
120 struct autoscan_params {
124 unsigned int timeout;
127 struct wifi_tethering_info {
128 struct wifi_data *wifi;
129 struct connman_technology *technology;
131 GSupplicantSSID *ssid;
136 struct connman_device *device;
137 struct connman_network *network;
138 struct connman_network *pending_network;
140 GSupplicantInterface *interface;
141 GSupplicantState state;
145 enum wifi_ap_capability ap_supported;
147 bool interface_ready;
153 int load_shaping_retries;
154 struct hidden_params *hidden;
155 bool postpone_hidden;
156 struct wifi_tethering_info *tethering_param;
158 * autoscan "emulation".
160 struct autoscan_params *autoscan;
161 enum wifi_scanning_type scanning_type;
162 GSupplicantScanParams *scan_params;
163 unsigned int p2p_find_timeout;
164 unsigned int p2p_connection_timeout;
165 struct connman_peer *pending_peer;
170 #if defined TIZEN_EXT
171 int assoc_retry_count;
172 struct connman_network *scan_pending_network;
173 bool allow_full_scan;
174 unsigned int automaxspeed_timeout;
175 GSupplicantScanParams *hidden_scan_params;
179 #if defined TIZEN_EXT_WIFI_MESH
181 struct wifi_mesh_info *mesh_info;
185 #if defined TIZEN_EXT
189 #define TIZEN_ASSOC_RETRY_COUNT 4
191 static gboolean wifi_first_scan = false;
192 static gboolean found_with_first_scan = false;
193 static gboolean is_wifi_notifier_registered = false;
194 static GHashTable *failed_bssids = NULL;
195 static unsigned char buff_bssid[WIFI_BSSID_LEN_MAX] = { 0, };
199 static GList *iface_list = NULL;
201 static GList *pending_wifi_device = NULL;
202 static GList *p2p_iface_list = NULL;
203 static bool wfd_service_registered = false;
205 static void start_autoscan(struct connman_device *device);
206 static int tech_set_tethering(struct connman_technology *technology,
207 const char *identifier, const char *passphrase,
208 const char *bridge, bool enabled);
210 #if defined TIZEN_EXT
211 #define NETCONFIG_SERVICE "net.netconfig"
212 #define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
213 #define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
215 struct enc_method_call_data {
216 DBusConnection *connection;
217 struct connman_network *network;
220 static struct enc_method_call_data encrypt_request_data;
222 static void encryption_request_reply(DBusPendingCall *call,
227 DBusMessageIter args;
229 struct connman_service *service;
230 gchar* encrypted_value = NULL;
231 struct connman_network *network = encrypt_request_data.network;
235 reply = dbus_pending_call_steal_reply(call);
237 dbus_error_init(&error);
238 if (dbus_set_error_from_message(&error, reply)) {
239 DBG("send_encryption_request() %s %s", error.name, error.message);
240 dbus_error_free(&error);
244 if (dbus_message_iter_init(reply, &args) == FALSE)
247 dbus_message_iter_get_basic(&args, &out_data);
249 encrypted_value = g_strdup((const gchar *)out_data);
250 service = connman_service_lookup_from_network(network);
253 DBG("encryption result: no service");
257 if (connman_service_get_favorite(service)) {
258 __connman_service_set_passphrase(service, encrypted_value);
259 __connman_service_save(service);
261 connman_network_set_string(network, "WiFi.Passphrase",
264 DBG("encryption result: succeeded");
267 dbus_message_unref(reply);
268 dbus_pending_call_unref(call);
269 dbus_connection_unref(encrypt_request_data.connection);
270 g_free(encrypted_value);
272 encrypt_request_data.connection = NULL;
273 encrypt_request_data.network = NULL;
276 static int send_encryption_request(const char *passphrase,
277 struct connman_network *network)
279 DBusConnection *connection = NULL;
280 DBusMessage *msg = NULL;
281 DBusPendingCall *call;
284 DBG("Invalid parameter");
288 connection = connman_dbus_get_connection();
290 DBG("dbus connection does not exist");
294 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
295 NETCONFIG_WIFI_INTERFACE, "EncryptPassphrase");
297 dbus_connection_unref(connection);
301 dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
304 if (!dbus_connection_send_with_reply(connection, msg,
305 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
306 dbus_message_unref(msg);
307 dbus_connection_unref(connection);
312 dbus_message_unref(msg);
313 dbus_connection_unref(connection);
317 encrypt_request_data.connection = connection;
318 encrypt_request_data.network = network;
320 dbus_pending_call_set_notify(call, encryption_request_reply, NULL, NULL);
321 dbus_message_unref(msg);
327 static int p2p_tech_probe(struct connman_technology *technology)
329 p2p_technology = technology;
334 static void p2p_tech_remove(struct connman_technology *technology)
336 p2p_technology = NULL;
339 static struct connman_technology_driver p2p_tech_driver = {
341 .type = CONNMAN_SERVICE_TYPE_P2P,
342 .probe = p2p_tech_probe,
343 .remove = p2p_tech_remove,
346 static bool is_p2p_connecting(void)
350 for (list = iface_list; list; list = list->next) {
351 struct wifi_data *wifi = list->data;
353 if (wifi->p2p_connecting)
360 static void add_pending_wifi_device(struct wifi_data *wifi)
362 if (g_list_find(pending_wifi_device, wifi))
365 pending_wifi_device = g_list_append(pending_wifi_device, wifi);
368 #if defined TIZEN_EXT_WIFI_MESH
369 struct wifi_mesh_info {
370 struct wifi_data *wifi;
371 GSupplicantInterface *interface;
372 struct connman_mesh *mesh;
379 struct mesh_change_peer_status_info {
381 enum connman_mesh_peer_status peer_status;
382 mesh_change_peer_status_cb_t callback;
386 static struct connman_technology_driver mesh_tech_driver = {
388 .type = CONNMAN_SERVICE_TYPE_MESH,
391 static void mesh_interface_create_callback(int result,
392 GSupplicantInterface *interface,
395 struct wifi_mesh_info *mesh_info = user_data;
396 struct wifi_data *wifi;
397 bool success = false;
399 DBG("result %d ifname %s, mesh_info %p", result,
400 g_supplicant_interface_get_ifname(interface),
403 if (result < 0 || !mesh_info)
406 wifi = mesh_info->wifi;
408 mesh_info->interface = interface;
409 mesh_info->identifier = connman_inet_ifaddr(mesh_info->ifname);
410 mesh_info->index = connman_inet_ifindex(mesh_info->ifname);
411 DBG("Mesh Interface identifier %s", mesh_info->identifier);
412 wifi->mesh_interface = true;
413 wifi->mesh_info = mesh_info;
414 g_supplicant_interface_set_data(interface, wifi);
418 connman_mesh_notify_interface_create(success);
421 static int add_mesh_interface(const char *ifname, const char *parent_ifname)
424 struct wifi_data *wifi;
425 struct wifi_mesh_info *mesh_info;
426 const char *wifi_ifname;
427 bool parent_found = false;
428 const char *driver = "nl80211";
430 for (list = iface_list; list; list = list->next) {
433 if (!g_supplicant_interface_has_mesh(wifi->interface))
436 wifi_ifname = g_supplicant_interface_get_ifname(wifi->interface);
440 if (!g_strcmp0(wifi_ifname, parent_ifname)) {
447 DBG("Parent interface %s doesn't exist", parent_ifname);
451 mesh_info = g_try_malloc0(sizeof(struct wifi_mesh_info));
455 mesh_info->wifi = wifi;
456 mesh_info->ifname = g_strdup(ifname);
457 mesh_info->parent_ifname = g_strdup(parent_ifname);
459 g_supplicant_mesh_interface_create(ifname, driver, NULL, parent_ifname,
460 mesh_interface_create_callback, mesh_info);
464 static void mesh_interface_remove_callback(int result,
465 GSupplicantInterface *interface,
468 struct wifi_data *wifi = user_data;
469 struct wifi_mesh_info *mesh_info = wifi->mesh_info;
470 bool success = false;
472 DBG("result %d mesh_info %p", result, mesh_info);
474 if (result < 0 || !mesh_info)
477 mesh_info->interface = NULL;
478 g_free(mesh_info->parent_ifname);
479 g_free(mesh_info->ifname);
480 g_free(mesh_info->identifier);
482 wifi->mesh_interface = false;
483 wifi->mesh_info = NULL;
487 connman_mesh_notify_interface_remove(success);
490 static int remove_mesh_interface(const char *ifname)
493 struct wifi_data *wifi;
494 struct wifi_mesh_info *mesh_info;
495 bool mesh_if_found = false;
498 for (list = iface_list; list; list = list->next) {
501 if (wifi->mesh_interface) {
502 mesh_if_found = true;
507 if (!mesh_if_found) {
508 DBG("Mesh interface %s doesn't exist", ifname);
512 mesh_info = wifi->mesh_info;
513 ret = g_supplicant_interface_remove(mesh_info->interface,
514 mesh_interface_remove_callback, wifi);
521 static void mesh_disconnect_callback(int result,
522 GSupplicantInterface *interface, void *user_data)
524 struct connman_mesh *mesh = user_data;
526 DBG("result %d interface %p mesh %p", result, interface, mesh);
529 static int mesh_peer_disconnect(struct connman_mesh *mesh)
532 struct wifi_data *wifi;
533 struct wifi_mesh_info *mesh_info;
534 bool mesh_if_found = false;
535 GSupplicantInterface *interface;
537 for (list = iface_list; list; list = list->next) {
540 if (wifi->mesh_interface) {
541 mesh_if_found = true;
546 if (!mesh_if_found) {
547 DBG("Mesh interface is not created");
551 mesh_info = wifi->mesh_info;
553 interface = mesh_info->interface;
554 return g_supplicant_interface_disconnect(interface,
555 mesh_disconnect_callback, mesh);
558 static void mesh_connect_callback(int result, GSupplicantInterface *interface,
561 struct connman_mesh *mesh = user_data;
562 DBG("mesh %p result %d", mesh, result);
565 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_FAILURE);
567 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_ASSOCIATION);
570 static GSupplicantSecurity mesh_network_security(const char *security)
572 if (g_str_equal(security, "none"))
573 return G_SUPPLICANT_SECURITY_NONE;
574 else if (g_str_equal(security, "sae"))
575 return G_SUPPLICANT_SECURITY_SAE;
577 return G_SUPPLICANT_SECURITY_UNKNOWN;
580 static void mesh_ssid_init(GSupplicantSSID *ssid, struct connman_mesh *mesh)
583 const char *security;
588 memset(ssid, 0, sizeof(*ssid));
589 ssid->mode = G_SUPPLICANT_MODE_MESH;
591 security = connman_mesh_get_security(mesh);
592 ssid->security = mesh_network_security(security);
594 if (ssid->security == G_SUPPLICANT_SECURITY_SAE)
595 ssid->passphrase = connman_mesh_get_passphrase(mesh);
597 ssid->freq = connman_mesh_get_frequency(mesh);
598 name = connman_mesh_get_name(mesh);
600 ssid->ssid_len = strlen(name);
601 ssid->ssid = g_malloc0(ssid->ssid_len + 1);
602 memcpy(ssid->ssid, name, ssid->ssid_len);
607 static int mesh_peer_connect(struct connman_mesh *mesh)
610 struct wifi_data *wifi;
611 struct wifi_mesh_info *mesh_info;
612 bool mesh_if_found = false;
613 GSupplicantInterface *interface;
614 GSupplicantSSID *ssid;
616 for (list = iface_list; list; list = list->next) {
619 if (wifi->mesh_interface) {
620 mesh_if_found = true;
625 if (!mesh_if_found) {
626 DBG("Mesh interface is not created");
630 mesh_info = wifi->mesh_info;
632 interface = mesh_info->interface;
634 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
638 mesh_info->mesh = mesh;
640 mesh_ssid_init(ssid, mesh);
641 return g_supplicant_interface_connect(interface, ssid,
642 mesh_connect_callback, mesh);
645 static void mesh_peer_change_status_callback(int result,
646 GSupplicantInterface *interface,
649 struct mesh_change_peer_status_info *data = user_data;
651 DBG("result %d Peer Status %d", result, data->peer_status);
653 if (result == 0 && data->peer_status == CONNMAN_MESH_PEER_REMOVE) {
654 /* WLAN_REASON_MESH_PEERING_CANCELLED = 52 */
655 connman_mesh_remove_connected_peer(data->peer_address, 52);
659 data->callback(result, data->user_data);
661 g_free(data->peer_address);
666 static int mesh_change_peer_status(const char *peer_address,
667 enum connman_mesh_peer_status status,
668 mesh_change_peer_status_cb_t callback, void *user_data)
671 struct wifi_data *wifi;
672 struct wifi_mesh_info *mesh_info;
673 bool mesh_if_found = false;
674 GSupplicantInterface *interface;
675 struct mesh_change_peer_status_info *data;
678 for (list = iface_list; list; list = list->next) {
681 if (wifi->mesh_interface) {
682 mesh_if_found = true;
687 if (!mesh_if_found) {
688 DBG("Mesh interface is not created");
692 mesh_info = wifi->mesh_info;
694 interface = mesh_info->interface;
697 case CONNMAN_MESH_PEER_ADD:
698 method = "MeshPeerAdd";
700 case CONNMAN_MESH_PEER_REMOVE:
701 method = "MeshPeerRemove";
704 DBG("Invalid method");
708 data = g_try_malloc0(sizeof(struct mesh_change_peer_status_info));
710 DBG("Memory allocation failed");
714 data->peer_address = g_strdup(peer_address);
715 data->peer_status = status;
716 data->callback = callback;
717 data->user_data = user_data;
719 return g_supplicant_interface_mesh_peer_change_status(interface,
720 mesh_peer_change_status_callback, peer_address, method,
724 static struct connman_mesh_driver mesh_driver = {
725 .add_interface = add_mesh_interface,
726 .remove_interface = remove_mesh_interface,
727 .connect = mesh_peer_connect,
728 .disconnect = mesh_peer_disconnect,
729 .change_peer_status = mesh_change_peer_status,
732 static void mesh_support(GSupplicantInterface *interface)
736 if (!g_supplicant_interface_has_mesh(interface))
739 if (connman_technology_driver_register(&mesh_tech_driver) < 0) {
740 DBG("Could not register Mesh technology driver");
744 connman_mesh_driver_register(&mesh_driver);
747 static void check_mesh_technology(void)
749 bool mesh_exists = false;
752 for (list = iface_list; list; list = list->next) {
753 struct wifi_data *w = list->data;
756 g_supplicant_interface_has_mesh(w->interface))
761 connman_technology_driver_unregister(&mesh_tech_driver);
762 connman_mesh_driver_unregister(&mesh_driver);
766 static void mesh_group_started(GSupplicantInterface *interface)
768 struct wifi_data *wifi;
769 struct wifi_mesh_info *mesh_info;
770 struct connman_mesh *mesh;
771 const unsigned char *ssid;
772 unsigned int ssid_len;
775 ssid = g_supplicant_interface_get_mesh_group_ssid(interface, &ssid_len);
776 memcpy(name, ssid, ssid_len);
777 name[ssid_len] = '\0';
778 DBG("name %s", name);
779 wifi = g_supplicant_interface_get_data(interface);
780 DBG("wifi %p", wifi);
785 mesh_info = wifi->mesh_info;
789 mesh = mesh_info->mesh;
793 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_CONFIGURATION);
796 static void mesh_group_removed(GSupplicantInterface *interface)
798 struct wifi_data *wifi;
799 struct wifi_mesh_info *mesh_info;
800 struct connman_mesh *mesh;
801 const unsigned char *ssid;
802 unsigned int ssid_len;
803 int disconnect_reason;
806 ssid = g_supplicant_interface_get_mesh_group_ssid(interface, &ssid_len);
807 memcpy(name, ssid, ssid_len);
808 name[ssid_len] = '\0';
809 DBG("name %s", name);
811 disconnect_reason = g_supplicant_mesh_get_disconnect_reason(interface);
812 DBG("Disconnect Reason %d", disconnect_reason);
814 wifi = g_supplicant_interface_get_data(interface);
815 DBG("wifi %p", wifi);
820 mesh_info = wifi->mesh_info;
824 mesh = connman_get_connected_mesh_from_name(name);
826 DBG("%s is not connected", name);
827 mesh = connman_get_connecting_mesh_from_name(name);
829 DBG("%s is not connecting", name);
834 connman_mesh_peer_set_disconnect_reason(mesh, disconnect_reason);
835 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_DISCONNECT);
838 static void mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
840 const char *peer_address;
842 peer_address = g_supplicant_mesh_peer_get_address(mesh_peer);
847 DBG("Peer %s connected", peer_address);
848 connman_mesh_add_connected_peer(peer_address);
851 static void mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
853 const char *peer_address;
856 peer_address = g_supplicant_mesh_peer_get_address(mesh_peer);
861 reason = g_supplicant_mesh_peer_get_disconnect_reason(mesh_peer);
863 DBG("Peer %s disconnected with reason %d", peer_address, reason);
864 connman_mesh_remove_connected_peer(peer_address, reason);
868 static struct wifi_data *get_pending_wifi_data(const char *ifname)
872 for (list = pending_wifi_device; list; list = list->next) {
873 struct wifi_data *wifi;
874 const char *dev_name;
877 if (!wifi || !wifi->device)
880 dev_name = connman_device_get_string(wifi->device, "Interface");
881 if (!g_strcmp0(ifname, dev_name)) {
882 pending_wifi_device = g_list_delete_link(
883 pending_wifi_device, list);
891 static void remove_pending_wifi_device(struct wifi_data *wifi)
895 link = g_list_find(pending_wifi_device, wifi);
900 pending_wifi_device = g_list_delete_link(pending_wifi_device, link);
903 static void peer_cancel_timeout(struct wifi_data *wifi)
905 if (wifi->p2p_connection_timeout > 0)
906 g_source_remove(wifi->p2p_connection_timeout);
908 wifi->p2p_connection_timeout = 0;
909 wifi->p2p_connecting = false;
911 if (wifi->pending_peer) {
912 connman_peer_unref(wifi->pending_peer);
913 wifi->pending_peer = NULL;
917 static gboolean peer_connect_timeout(gpointer data)
919 struct wifi_data *wifi = data;
923 if (wifi->p2p_connecting) {
924 enum connman_peer_state state = CONNMAN_PEER_STATE_FAILURE;
925 GSupplicantPeer *gs_peer =
926 g_supplicant_interface_peer_lookup(wifi->interface,
927 connman_peer_get_identifier(wifi->pending_peer));
929 if (g_supplicant_peer_has_requested_connection(gs_peer))
930 state = CONNMAN_PEER_STATE_IDLE;
932 connman_peer_set_state(wifi->pending_peer, state);
935 peer_cancel_timeout(wifi);
940 static void peer_connect_callback(int result, GSupplicantInterface *interface,
943 struct wifi_data *wifi = user_data;
944 struct connman_peer *peer = wifi->pending_peer;
946 DBG("peer %p - %d", peer, result);
952 peer_connect_timeout(wifi);
956 connman_peer_set_state(peer, CONNMAN_PEER_STATE_ASSOCIATION);
958 wifi->p2p_connection_timeout = g_timeout_add_seconds(
959 P2P_CONNECTION_TIMEOUT,
960 peer_connect_timeout, wifi);
963 static int peer_connect(struct connman_peer *peer,
964 enum connman_peer_wps_method wps_method,
967 struct connman_device *device = connman_peer_get_device(peer);
968 GSupplicantPeerParams *peer_params;
969 GSupplicantPeer *gs_peer;
970 struct wifi_data *wifi;
974 DBG("peer %p", peer);
979 wifi = connman_device_get_data(device);
980 if (!wifi || !wifi->interface)
983 if (wifi->p2p_connecting)
986 gs_peer = g_supplicant_interface_peer_lookup(wifi->interface,
987 connman_peer_get_identifier(peer));
991 pbc = g_supplicant_peer_is_wps_pbc(gs_peer);
992 pin = g_supplicant_peer_is_wps_pin(gs_peer);
994 switch (wps_method) {
995 case CONNMAN_PEER_WPS_UNKNOWN:
996 if ((pbc && pin) || pin)
999 case CONNMAN_PEER_WPS_PBC:
1004 case CONNMAN_PEER_WPS_PIN:
1005 if (!pin || !wps_pin)
1010 peer_params = g_try_malloc0(sizeof(GSupplicantPeerParams));
1014 peer_params->path = g_strdup(g_supplicant_peer_get_path(gs_peer));
1016 peer_params->wps_pin = g_strdup(wps_pin);
1018 peer_params->master = connman_peer_service_is_master();
1020 ret = g_supplicant_interface_p2p_connect(wifi->interface, peer_params,
1021 peer_connect_callback, wifi);
1022 if (ret == -EINPROGRESS) {
1023 wifi->pending_peer = connman_peer_ref(peer);
1024 wifi->p2p_connecting = true;
1025 } else if (ret < 0) {
1026 g_free(peer_params->path);
1027 g_free(peer_params->wps_pin);
1028 g_free(peer_params);
1034 static int peer_disconnect(struct connman_peer *peer)
1036 struct connman_device *device = connman_peer_get_device(peer);
1037 GSupplicantPeerParams peer_params = {};
1038 GSupplicantPeer *gs_peer;
1039 struct wifi_data *wifi;
1042 DBG("peer %p", peer);
1047 wifi = connman_device_get_data(device);
1051 gs_peer = g_supplicant_interface_peer_lookup(wifi->interface,
1052 connman_peer_get_identifier(peer));
1056 peer_params.path = g_strdup(g_supplicant_peer_get_path(gs_peer));
1058 ret = g_supplicant_interface_p2p_disconnect(wifi->interface,
1060 g_free(peer_params.path);
1062 if (ret == -EINPROGRESS) {
1063 peer_cancel_timeout(wifi);
1064 wifi->p2p_device = false;
1070 struct peer_service_registration {
1071 peer_service_registration_cb_t callback;
1075 static bool is_service_wfd(const unsigned char *specs, int length)
1077 if (length < 9 || specs[0] != 0 || specs[1] != 0 || specs[2] != 6)
1083 static void apply_p2p_listen_on_iface(gpointer data, gpointer user_data)
1085 struct wifi_data *wifi = data;
1087 if (!wifi->interface ||
1088 !g_supplicant_interface_has_p2p(wifi->interface))
1091 if (!wifi->servicing) {
1092 g_supplicant_interface_p2p_listen(wifi->interface,
1093 P2P_LISTEN_PERIOD, P2P_LISTEN_INTERVAL);
1099 static void register_wfd_service_cb(int result,
1100 GSupplicantInterface *iface, void *user_data)
1102 struct peer_service_registration *reg_data = user_data;
1107 g_list_foreach(iface_list, apply_p2p_listen_on_iface, NULL);
1109 if (reg_data && reg_data->callback) {
1110 reg_data->callback(result, reg_data->user_data);
1115 static GSupplicantP2PServiceParams *fill_in_peer_service_params(
1116 const unsigned char *spec,
1117 int spec_length, const unsigned char *query,
1118 int query_length, int version)
1120 GSupplicantP2PServiceParams *params;
1122 params = g_try_malloc0(sizeof(GSupplicantP2PServiceParams));
1127 params->version = version;
1128 params->service = g_memdup(spec, spec_length);
1129 } else if (query_length > 0 && spec_length > 0) {
1130 params->query = g_memdup(query, query_length);
1131 params->query_length = query_length;
1133 params->response = g_memdup(spec, spec_length);
1134 params->response_length = spec_length;
1136 params->wfd_ies = g_memdup(spec, spec_length);
1137 params->wfd_ies_length = spec_length;
1143 static void free_peer_service_params(GSupplicantP2PServiceParams *params)
1148 g_free(params->service);
1149 g_free(params->query);
1150 g_free(params->response);
1151 g_free(params->wfd_ies);
1156 static int peer_register_wfd_service(const unsigned char *specification,
1157 int specification_length,
1158 peer_service_registration_cb_t callback,
1161 struct peer_service_registration *reg_data = NULL;
1162 static GSupplicantP2PServiceParams *params;
1167 if (wfd_service_registered)
1170 params = fill_in_peer_service_params(specification,
1171 specification_length, NULL, 0, 0);
1175 reg_data = g_try_malloc0(sizeof(*reg_data));
1181 reg_data->callback = callback;
1182 reg_data->user_data = user_data;
1184 ret = g_supplicant_set_widi_ies(params,
1185 register_wfd_service_cb, reg_data);
1186 if (ret < 0 && ret != -EINPROGRESS)
1189 wfd_service_registered = true;
1193 free_peer_service_params(params);
1199 static void register_peer_service_cb(int result,
1200 GSupplicantInterface *iface, void *user_data)
1202 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
1203 struct peer_service_registration *reg_data = user_data;
1205 #if defined TIZEN_EXT
1213 apply_p2p_listen_on_iface(wifi, NULL);
1215 if (reg_data->callback)
1216 reg_data->callback(result, reg_data->user_data);
1221 static int peer_register_service(const unsigned char *specification,
1222 int specification_length,
1223 const unsigned char *query,
1224 int query_length, int version,
1225 peer_service_registration_cb_t callback,
1228 struct peer_service_registration *reg_data;
1229 GSupplicantP2PServiceParams *params;
1236 if (specification && !version && !query &&
1237 is_service_wfd(specification, specification_length)) {
1238 return peer_register_wfd_service(specification,
1239 specification_length, callback, user_data);
1242 reg_data = g_try_malloc0(sizeof(*reg_data));
1246 reg_data->callback = callback;
1247 reg_data->user_data = user_data;
1249 ret_f = -EOPNOTSUPP;
1251 for (list = iface_list; list; list = list->next) {
1252 struct wifi_data *wifi = list->data;
1253 GSupplicantInterface *iface = wifi->interface;
1255 if (!g_supplicant_interface_has_p2p(iface))
1258 params = fill_in_peer_service_params(specification,
1259 specification_length, query,
1260 query_length, version);
1265 ret_f = g_supplicant_interface_p2p_add_service(iface,
1266 register_peer_service_cb, params, reg_data);
1267 if (ret_f == 0 || ret_f == -EINPROGRESS)
1271 ret = g_supplicant_interface_p2p_add_service(iface,
1272 register_peer_service_cb, params, NULL);
1273 if (ret != 0 && ret != -EINPROGRESS)
1274 free_peer_service_params(params);
1277 if (ret_f != 0 && ret_f != -EINPROGRESS)
1283 static int peer_unregister_wfd_service(void)
1285 GSupplicantP2PServiceParams *params;
1288 if (!wfd_service_registered)
1291 params = fill_in_peer_service_params(NULL, 0, NULL, 0, 0);
1295 wfd_service_registered = false;
1297 g_supplicant_set_widi_ies(params, NULL, NULL);
1299 for (list = iface_list; list; list = list->next) {
1300 struct wifi_data *wifi = list->data;
1302 if (!g_supplicant_interface_has_p2p(wifi->interface))
1306 if (!wifi->servicing || wifi->servicing < 0) {
1307 g_supplicant_interface_p2p_listen(wifi->interface,
1309 wifi->servicing = 0;
1316 static int peer_unregister_service(const unsigned char *specification,
1317 int specification_length,
1318 const unsigned char *query,
1319 int query_length, int version)
1321 GSupplicantP2PServiceParams *params;
1326 if (specification && !version && !query &&
1327 is_service_wfd(specification, specification_length)) {
1328 ret = peer_unregister_wfd_service();
1329 if (ret != 0 && ret != -EINPROGRESS)
1334 for (list = iface_list; list; list = list->next) {
1335 struct wifi_data *wifi = list->data;
1336 GSupplicantInterface *iface = wifi->interface;
1339 goto stop_listening;
1341 if (!g_supplicant_interface_has_p2p(iface))
1344 params = fill_in_peer_service_params(specification,
1345 specification_length, query,
1346 query_length, version);
1350 ret = g_supplicant_interface_p2p_del_service(iface, params);
1351 if (ret != 0 && ret != -EINPROGRESS)
1352 free_peer_service_params(params);
1355 if (!wifi->servicing || wifi->servicing < 0) {
1356 g_supplicant_interface_p2p_listen(iface, 0, 0);
1357 wifi->servicing = 0;
1364 static struct connman_peer_driver peer_driver = {
1365 .connect = peer_connect,
1366 .disconnect = peer_disconnect,
1367 .register_service = peer_register_service,
1368 .unregister_service = peer_unregister_service,
1371 static void handle_tethering(struct wifi_data *wifi)
1373 if (!wifi->tethering)
1382 DBG("index %d bridge %s", wifi->index, wifi->bridge);
1384 if (connman_inet_add_to_bridge(wifi->index, wifi->bridge) < 0)
1387 wifi->bridged = true;
1390 static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
1392 struct connman_device *device = user_data;
1393 struct wifi_data *wifi = connman_device_get_data(device);
1398 DBG("index %d flags %d change %d", wifi->index, flags, change);
1400 if ((wifi->flags & IFF_UP) != (flags & IFF_UP)) {
1402 DBG("interface up");
1404 DBG("interface down");
1407 if ((wifi->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
1408 if (flags & IFF_LOWER_UP) {
1411 handle_tethering(wifi);
1416 wifi->flags = flags;
1419 static int wifi_probe(struct connman_device *device)
1421 struct wifi_data *wifi;
1423 DBG("device %p", device);
1425 wifi = g_try_new0(struct wifi_data, 1);
1429 wifi->state = G_SUPPLICANT_STATE_INACTIVE;
1430 wifi->ap_supported = WIFI_AP_UNKNOWN;
1431 wifi->tethering_param = NULL;
1433 connman_device_set_data(device, wifi);
1434 wifi->device = connman_device_ref(device);
1436 wifi->index = connman_device_get_index(device);
1439 wifi->watch = connman_rtnl_add_newlink_watch(wifi->index,
1440 wifi_newlink, device);
1441 if (is_p2p_connecting())
1442 add_pending_wifi_device(wifi);
1444 iface_list = g_list_append(iface_list, wifi);
1449 static void remove_networks(struct connman_device *device,
1450 struct wifi_data *wifi)
1454 for (list = wifi->networks; list; list = list->next) {
1455 struct connman_network *network = list->data;
1457 connman_device_remove_network(device, network);
1458 connman_network_unref(network);
1461 g_slist_free(wifi->networks);
1462 wifi->networks = NULL;
1465 static void remove_peers(struct wifi_data *wifi)
1469 for (list = wifi->peers; list; list = list->next) {
1470 struct connman_peer *peer = list->data;
1472 connman_peer_unregister(peer);
1473 connman_peer_unref(peer);
1476 g_slist_free(wifi->peers);
1480 static void reset_autoscan(struct connman_device *device)
1482 struct wifi_data *wifi = connman_device_get_data(device);
1483 struct autoscan_params *autoscan;
1487 if (!wifi || !wifi->autoscan)
1490 autoscan = wifi->autoscan;
1492 autoscan->interval = 0;
1494 if (autoscan->timeout == 0)
1497 g_source_remove(autoscan->timeout);
1498 autoscan->timeout = 0;
1500 connman_device_unref(device);
1503 static void stop_autoscan(struct connman_device *device)
1505 const struct wifi_data *wifi = connman_device_get_data(device);
1507 if (!wifi || !wifi->autoscan)
1510 reset_autoscan(device);
1512 connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_WIFI, false);
1515 static void check_p2p_technology(void)
1517 bool p2p_exists = false;
1520 for (list = iface_list; list; list = list->next) {
1521 struct wifi_data *w = list->data;
1524 g_supplicant_interface_has_p2p(w->interface))
1529 connman_technology_driver_unregister(&p2p_tech_driver);
1530 connman_peer_driver_unregister(&peer_driver);
1534 struct last_connected {
1540 static gint sort_entry(gconstpointer a, gconstpointer b, gpointer user_data)
1542 GTimeVal *aval = (GTimeVal *)a;
1543 GTimeVal *bval = (GTimeVal *)b;
1545 /* Note that the sort order is descending */
1546 if (aval->tv_sec < bval->tv_sec)
1549 if (aval->tv_sec > bval->tv_sec)
1555 static void free_entry(gpointer data)
1557 struct last_connected *entry = data;
1559 g_free(entry->ssid);
1563 static void wifi_remove(struct connman_device *device)
1565 struct wifi_data *wifi = connman_device_get_data(device);
1567 DBG("device %p wifi %p", device, wifi);
1572 stop_autoscan(device);
1574 if (wifi->p2p_device)
1575 p2p_iface_list = g_list_remove(p2p_iface_list, wifi);
1577 iface_list = g_list_remove(iface_list, wifi);
1579 check_p2p_technology();
1580 #if defined TIZEN_EXT_WIFI_MESH
1581 check_mesh_technology();
1584 remove_pending_wifi_device(wifi);
1586 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_P2P)) {
1587 g_source_remove(wifi->p2p_find_timeout);
1588 connman_device_unref(wifi->device);
1591 if (wifi->p2p_connection_timeout)
1592 g_source_remove(wifi->p2p_connection_timeout);
1594 #if defined TIZEN_EXT
1595 if (wifi->automaxspeed_timeout != 0) {
1596 g_source_remove(wifi->automaxspeed_timeout);
1597 wifi->automaxspeed_timeout = 0;
1601 remove_networks(device, wifi);
1604 connman_device_set_powered(device, false);
1605 connman_device_set_data(device, NULL);
1606 connman_device_unref(wifi->device);
1607 connman_rtnl_remove_watch(wifi->watch);
1609 g_supplicant_interface_set_data(wifi->interface, NULL);
1611 g_supplicant_interface_cancel(wifi->interface);
1613 if (wifi->scan_params)
1614 g_supplicant_free_scan_params(wifi->scan_params);
1615 #if defined TIZEN_EXT
1616 if (wifi->hidden_scan_params) {
1617 while (wifi->hidden_scan_params->ssids) {
1618 struct scan_ssid *ssid;
1619 ssid = wifi->hidden_scan_params->ssids->data;
1620 wifi->hidden_scan_params->ssids = g_slist_remove(wifi->hidden_scan_params->ssids, ssid);
1622 g_supplicant_free_scan_params(wifi->hidden_scan_params);
1626 g_free(wifi->autoscan);
1627 g_free(wifi->identifier);
1631 static bool is_duplicate(GSList *list, gchar *ssid, int ssid_len)
1635 for (iter = list; iter; iter = g_slist_next(iter)) {
1636 struct scan_ssid *scan_ssid = iter->data;
1638 if (ssid_len == scan_ssid->ssid_len &&
1639 memcmp(ssid, scan_ssid->ssid, ssid_len) == 0)
1646 static int add_scan_param(gchar *hex_ssid, char *raw_ssid, int ssid_len,
1647 int freq, GSupplicantScanParams *scan_data,
1648 int driver_max_scan_ssids, char *ssid_name)
1651 struct scan_ssid *scan_ssid;
1653 if ((driver_max_scan_ssids == 0 ||
1654 driver_max_scan_ssids > scan_data->num_ssids) &&
1655 (hex_ssid || raw_ssid)) {
1657 unsigned int j = 0, hex;
1660 size_t hex_ssid_len = strlen(hex_ssid);
1662 ssid = g_try_malloc0(hex_ssid_len / 2);
1666 for (i = 0; i < hex_ssid_len; i += 2) {
1667 sscanf(hex_ssid + i, "%02x", &hex);
1676 * If we have already added hidden AP to the list,
1677 * then do not do it again. This might happen if you have
1678 * used or are using multiple wifi cards, so in that case
1679 * you might have multiple service files for same AP.
1681 if (is_duplicate(scan_data->ssids, ssid, j)) {
1687 scan_ssid = g_try_new(struct scan_ssid, 1);
1694 memcpy(scan_ssid->ssid, ssid, j);
1695 scan_ssid->ssid_len = j;
1696 scan_data->ssids = g_slist_prepend(scan_data->ssids,
1699 scan_data->num_ssids++;
1701 DBG("SSID %s added to scanned list of %d entries", ssid_name,
1702 scan_data->num_ssids);
1709 scan_data->ssids = g_slist_reverse(scan_data->ssids);
1711 if (!scan_data->freqs) {
1712 scan_data->freqs = g_try_malloc0(sizeof(uint16_t));
1713 if (!scan_data->freqs) {
1714 g_slist_free_full(scan_data->ssids, g_free);
1718 scan_data->num_freqs = 1;
1719 scan_data->freqs[0] = freq;
1721 bool duplicate = false;
1723 /* Don't add duplicate entries */
1724 for (i = 0; i < scan_data->num_freqs; i++) {
1725 if (scan_data->freqs[i] == freq) {
1732 scan_data->num_freqs++;
1733 scan_data->freqs = g_try_realloc(scan_data->freqs,
1734 sizeof(uint16_t) * scan_data->num_freqs);
1735 if (!scan_data->freqs) {
1736 g_slist_free_full(scan_data->ssids, g_free);
1739 scan_data->freqs[scan_data->num_freqs - 1] = freq;
1746 static int get_hidden_connections(GSupplicantScanParams *scan_data)
1748 struct connman_config_entry **entries;
1750 #if defined TIZEN_EXT
1751 gchar **services = NULL;
1754 #endif /* defined TIZEN_EXT */
1758 int num_ssids = 0, add_param_failed = 0;
1759 #if defined TIZEN_EXT
1760 GSequenceIter *iter;
1761 GSequence *latest_list;
1762 struct last_connected *entry;
1765 latest_list = g_sequence_new(free_entry);
1769 services = connman_storage_get_services();
1770 for (i = 0; services && services[i]; i++) {
1771 if (strncmp(services[i], "wifi_", 5) != 0)
1774 keyfile = connman_storage_load_service(services[i]);
1778 value = g_key_file_get_boolean(keyfile,
1779 services[i], "Hidden", NULL);
1781 g_key_file_free(keyfile);
1785 value = g_key_file_get_boolean(keyfile,
1786 services[i], "Favorite", NULL);
1788 g_key_file_free(keyfile);
1792 #if defined TIZEN_EXT
1793 value = g_key_file_get_boolean(keyfile,
1794 services[i], "AutoConnect", NULL);
1796 g_key_file_free(keyfile);
1800 gchar *str = g_key_file_get_string(keyfile,
1801 services[i], "Modified", NULL);
1803 g_key_file_free(keyfile);
1806 g_time_val_from_iso8601(str, &modified);
1810 ssid = g_key_file_get_string(keyfile,
1811 services[i], "SSID", NULL);
1813 name = g_key_file_get_string(keyfile, services[i], "Name",
1816 #if defined TIZEN_EXT
1817 entry = g_try_new(struct last_connected, 1);
1819 g_sequence_free(latest_list);
1822 g_key_file_free(keyfile);
1826 entry->modified = modified;
1829 g_sequence_insert_sorted(latest_list, entry,
1832 ret = add_scan_param(ssid, NULL, 0, 0, scan_data, 0, name);
1841 g_key_file_free(keyfile);
1844 #if defined TIZEN_EXT
1845 gint length = g_sequence_get_length(latest_list);
1846 iter = g_sequence_get_begin_iter(latest_list);
1848 for (i = 0; i < length; i++) {
1849 entry = g_sequence_get(iter);
1851 ret = add_scan_param(entry->ssid, NULL, 0, 0, scan_data, 0, entry->ssid);
1857 iter = g_sequence_iter_next(iter);
1860 g_sequence_free(latest_list);
1864 * Check if there are any hidden AP that needs to be provisioned.
1866 entries = connman_config_get_entries("wifi");
1867 for (i = 0; entries && entries[i]; i++) {
1870 if (!entries[i]->hidden)
1873 if (!entries[i]->ssid) {
1874 ssid = entries[i]->name;
1877 ssid = entries[i]->ssid;
1878 len = entries[i]->ssid_len;
1884 ret = add_scan_param(NULL, ssid, len, 0, scan_data, 0, ssid);
1891 connman_config_free_entries(entries);
1893 if (add_param_failed > 0)
1894 DBG("Unable to scan %d out of %d SSIDs",
1895 add_param_failed, num_ssids);
1897 g_strfreev(services);
1902 static int get_hidden_connections_params(struct wifi_data *wifi,
1903 GSupplicantScanParams *scan_params)
1905 int driver_max_ssids, i;
1906 GSupplicantScanParams *orig_params;
1909 * Scan hidden networks so that we can autoconnect to them.
1910 * We will assume 1 as a default number of ssid to scan.
1912 driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
1914 if (driver_max_ssids == 0)
1915 driver_max_ssids = 1;
1917 DBG("max ssids %d", driver_max_ssids);
1919 #if defined TIZEN_EXT
1920 if (!wifi->hidden_scan_params) {
1921 wifi->hidden_scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
1922 if (!wifi->hidden_scan_params)
1925 if (get_hidden_connections(wifi->hidden_scan_params) == 0) {
1926 g_supplicant_free_scan_params(wifi->hidden_scan_params);
1927 wifi->hidden_scan_params = NULL;
1933 orig_params = wifi->hidden_scan_params;
1935 if (!wifi->scan_params) {
1936 wifi->scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
1937 if (!wifi->scan_params)
1940 if (get_hidden_connections(wifi->scan_params) == 0) {
1941 g_supplicant_free_scan_params(wifi->scan_params);
1942 wifi->scan_params = NULL;
1948 orig_params = wifi->scan_params;
1951 /* Let's transfer driver_max_ssids params */
1952 for (i = 0; i < driver_max_ssids; i++) {
1953 struct scan_ssid *ssid;
1955 #if defined TIZEN_EXT
1956 if (!wifi->hidden_scan_params->ssids)
1958 if (!wifi->scan_params->ssids)
1962 ssid = orig_params->ssids->data;
1963 orig_params->ssids = g_slist_remove(orig_params->ssids, ssid);
1964 scan_params->ssids = g_slist_prepend(scan_params->ssids, ssid);
1968 scan_params->num_ssids = i;
1969 scan_params->ssids = g_slist_reverse(scan_params->ssids);
1971 scan_params->freqs = g_memdup(orig_params->freqs,
1972 sizeof(uint16_t) * orig_params->num_freqs);
1973 if (!scan_params->freqs)
1976 scan_params->num_freqs = orig_params->num_freqs;
1981 orig_params->num_ssids -= scan_params->num_ssids;
1983 return scan_params->num_ssids;
1986 g_slist_free_full(scan_params->ssids, g_free);
1987 #if defined TIZEN_EXT
1988 g_supplicant_free_scan_params(wifi->hidden_scan_params);
1989 wifi->hidden_scan_params = NULL;
1991 g_supplicant_free_scan_params(wifi->scan_params);
1992 wifi->scan_params = NULL;
1998 static int throw_wifi_scan(struct connman_device *device,
1999 GSupplicantInterfaceCallback callback)
2001 struct wifi_data *wifi = connman_device_get_data(device);
2007 DBG("device %p %p", device, wifi->interface);
2009 if (wifi->tethering)
2012 #if defined TIZEN_EXT
2013 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI)
2014 && !wifi->allow_full_scan)
2016 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI))
2020 connman_device_ref(device);
2022 ret = g_supplicant_interface_scan(wifi->interface, NULL,
2025 connman_device_set_scanning(device,
2026 CONNMAN_SERVICE_TYPE_WIFI, true);
2028 connman_device_unref(device);
2033 static void hidden_free(struct hidden_params *hidden)
2038 if (hidden->scan_params)
2039 g_supplicant_free_scan_params(hidden->scan_params);
2040 g_free(hidden->identity);
2041 g_free(hidden->passphrase);
2042 g_free(hidden->security);
2046 #if defined TIZEN_EXT
2047 static void service_state_changed(struct connman_service *service,
2048 enum connman_service_state state);
2050 static int network_connect(struct connman_network *network);
2052 static struct connman_notifier notifier = {
2054 .priority = CONNMAN_NOTIFIER_PRIORITY_DEFAULT,
2055 .service_state_changed = service_state_changed,
2058 static void service_state_changed(struct connman_service *service,
2059 enum connman_service_state state)
2061 enum connman_service_type type;
2063 type = connman_service_get_type(service);
2064 if (type != CONNMAN_SERVICE_TYPE_WIFI)
2067 DBG("service %p state %d", service, state);
2070 case CONNMAN_SERVICE_STATE_READY:
2071 case CONNMAN_SERVICE_STATE_ONLINE:
2072 case CONNMAN_SERVICE_STATE_FAILURE:
2073 connman_notifier_unregister(¬ifier);
2074 is_wifi_notifier_registered = FALSE;
2076 __connman_device_request_scan(type);
2084 static void scan_callback_hidden(int result,
2085 GSupplicantInterface *interface, void *user_data);
2088 static void scan_callback(int result, GSupplicantInterface *interface,
2091 struct connman_device *device = user_data;
2092 struct wifi_data *wifi = connman_device_get_data(device);
2094 #if defined TIZEN_EXT
2095 GSList *list = NULL;
2096 bool favorite_exists = false;
2097 struct connman_network *network = NULL;
2098 struct connman_service *service = NULL;
2101 DBG("result %d wifi %p", result, wifi);
2104 if (wifi->hidden && !wifi->postpone_hidden) {
2105 connman_network_clear_hidden(wifi->hidden->user_data);
2106 hidden_free(wifi->hidden);
2107 wifi->hidden = NULL;
2110 if (wifi->scan_params) {
2111 g_supplicant_free_scan_params(wifi->scan_params);
2112 wifi->scan_params = NULL;
2115 #if defined TIZEN_EXT
2116 if (wifi->hidden_scan_params && !wifi->hidden_scan_params->ssids) {
2117 g_supplicant_free_scan_params(wifi->hidden_scan_params);
2118 wifi->hidden_scan_params = NULL;
2124 connman_device_reset_scanning(device);
2126 /* User is connecting to a hidden AP, let's wait for finished event */
2127 if (wifi && wifi->hidden && wifi->postpone_hidden) {
2128 GSupplicantScanParams *scan_params;
2131 wifi->postpone_hidden = false;
2132 scan_params = wifi->hidden->scan_params;
2133 wifi->hidden->scan_params = NULL;
2135 reset_autoscan(device);
2137 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
2138 scan_callback, device);
2142 /* On error, let's recall scan_callback, which will cleanup */
2143 return scan_callback(ret, interface, user_data);
2146 #if defined TIZEN_EXT
2148 for (list = wifi->networks; list; list = list->next) {
2149 network = list->data;
2150 service = connman_service_lookup_from_network(network);
2152 if (service != NULL &&
2153 (connman_service_get_favorite(service) == true) &&
2154 (connman_service_get_autoconnect(service) == true)) {
2155 DBG("Favorite service exists [%s]", connman_network_get_string(network, "Name"));
2156 favorite_exists = true;
2162 if (favorite_exists == false) {
2163 if (wifi && wifi->allow_full_scan) {
2165 DBG("Trigger full channel scan");
2166 wifi->allow_full_scan = false;
2168 ret = g_supplicant_interface_scan(wifi->interface, NULL,
2169 scan_callback_hidden, device);
2173 /* On error, let's recall scan_callback, which will cleanup */
2174 return scan_callback(ret, interface, user_data);
2179 scanning = connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI);
2182 connman_device_set_scanning(device,
2183 CONNMAN_SERVICE_TYPE_WIFI, false);
2186 if (result != -ENOLINK)
2187 #if defined TIZEN_EXT
2190 start_autoscan(device);
2193 * If we are here then we were scanning; however, if we are
2194 * also mid-flight disabling the interface, then wifi_disable
2195 * has already cleared the device scanning state and
2196 * unreferenced the device, obviating the need to do it here.
2200 connman_device_unref(device);
2202 #if defined TIZEN_EXT
2203 if (wifi && wifi->scan_pending_network && result != -EIO) {
2204 network_connect(wifi->scan_pending_network);
2205 wifi->scan_pending_network = NULL;
2206 connman_network_set_connecting(wifi->network);
2209 if (is_wifi_notifier_registered != true &&
2210 wifi_first_scan == true && found_with_first_scan == true) {
2211 wifi_first_scan = false;
2212 found_with_first_scan = false;
2214 connman_notifier_register(¬ifier);
2215 is_wifi_notifier_registered = true;
2220 static void scan_callback_hidden(int result,
2221 GSupplicantInterface *interface, void *user_data)
2223 struct connman_device *device = user_data;
2224 struct wifi_data *wifi = connman_device_get_data(device);
2225 GSupplicantScanParams *scan_params;
2228 DBG("result %d wifi %p", result, wifi);
2233 /* User is trying to connect to a hidden AP */
2234 if (wifi->hidden && wifi->postpone_hidden)
2237 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2241 if (get_hidden_connections_params(wifi, scan_params) > 0) {
2242 ret = g_supplicant_interface_scan(wifi->interface,
2244 #if defined TIZEN_EXT
2247 scan_callback_hidden,
2254 g_supplicant_free_scan_params(scan_params);
2257 scan_callback(result, interface, user_data);
2260 static gboolean autoscan_timeout(gpointer data)
2262 struct connman_device *device = data;
2263 struct wifi_data *wifi = connman_device_get_data(device);
2264 struct autoscan_params *autoscan;
2270 autoscan = wifi->autoscan;
2272 #if defined TIZEN_EXT
2277 if (autoscan->interval <= 0) {
2278 interval = autoscan->base;
2281 interval = autoscan->interval * autoscan->base;
2283 #if defined TIZEN_EXT
2284 if (autoscan->interval >= autoscan->limit)
2286 if (interval > autoscan->limit)
2288 interval = autoscan->limit;
2290 throw_wifi_scan(wifi->device, scan_callback_hidden);
2293 * In case BackgroundScanning is disabled, interval will reach the
2294 * limit exactly after the very first passive scanning. It allows
2295 * to ensure at most one passive scan is performed in such cases.
2297 if (!connman_setting_get_bool("BackgroundScanning") &&
2298 interval == autoscan->limit) {
2299 g_source_remove(autoscan->timeout);
2300 autoscan->timeout = 0;
2302 connman_device_unref(device);
2308 DBG("interval %d", interval);
2310 autoscan->interval = interval;
2312 autoscan->timeout = g_timeout_add_seconds(interval,
2313 autoscan_timeout, device);
2318 static void start_autoscan(struct connman_device *device)
2320 struct wifi_data *wifi = connman_device_get_data(device);
2321 struct autoscan_params *autoscan;
2328 if (wifi->p2p_device)
2331 if (wifi->connected)
2334 autoscan = wifi->autoscan;
2338 if (autoscan->timeout > 0 || autoscan->interval > 0)
2341 connman_device_ref(device);
2343 autoscan_timeout(device);
2346 static struct autoscan_params *parse_autoscan_params(const char *params)
2348 struct autoscan_params *autoscan;
2355 list_params = g_strsplit(params, ":", 0);
2356 if (list_params == 0)
2359 if (!g_strcmp0(list_params[0], "exponential") &&
2360 g_strv_length(list_params) == 3) {
2361 base = atoi(list_params[1]);
2362 limit = atoi(list_params[2]);
2363 } else if (!g_strcmp0(list_params[0], "single") &&
2364 g_strv_length(list_params) == 2)
2365 base = limit = atoi(list_params[1]);
2367 g_strfreev(list_params);
2371 DBG("Setup %s autoscanning", list_params[0]);
2373 g_strfreev(list_params);
2375 autoscan = g_try_malloc0(sizeof(struct autoscan_params));
2377 DBG("Could not allocate memory for autoscan");
2381 DBG("base %d - limit %d", base, limit);
2382 autoscan->base = base;
2383 autoscan->limit = limit;
2388 static void setup_autoscan(struct wifi_data *wifi)
2391 * If BackgroundScanning is enabled, setup exponential
2392 * autoscanning if it has not been previously done.
2394 if (connman_setting_get_bool("BackgroundScanning")) {
2395 wifi->autoscan = parse_autoscan_params(AUTOSCAN_EXPONENTIAL);
2398 #if defined TIZEN_EXT
2400 if (wifi->autoscan) {
2401 g_free(wifi->autoscan);
2402 wifi->autoscan = NULL;
2405 DBG("BackgroundScanning is disabled");
2412 * On the contrary, if BackgroundScanning is disabled, update autoscan
2413 * parameters based on the type of scanning that is being performed.
2415 if (wifi->autoscan) {
2416 g_free(wifi->autoscan);
2417 wifi->autoscan = NULL;
2420 switch (wifi->scanning_type) {
2421 case WIFI_SCANNING_PASSIVE:
2422 /* Do not setup autoscan. */
2424 case WIFI_SCANNING_ACTIVE:
2425 /* Setup one single passive scan after active. */
2426 wifi->autoscan = parse_autoscan_params(AUTOSCAN_SINGLE);
2428 case WIFI_SCANNING_UNKNOWN:
2429 /* Setup autoscan in this case but we should never fall here. */
2430 wifi->autoscan = parse_autoscan_params(AUTOSCAN_SINGLE);
2435 static void finalize_interface_creation(struct wifi_data *wifi)
2437 DBG("interface is ready wifi %p tethering %d", wifi, wifi->tethering);
2439 if (!wifi->device) {
2440 connman_error("WiFi device not set");
2444 connman_device_set_powered(wifi->device, true);
2446 if (wifi->p2p_device)
2449 if (!wifi->autoscan)
2450 setup_autoscan(wifi);
2452 start_autoscan(wifi->device);
2455 static void interface_create_callback(int result,
2456 GSupplicantInterface *interface,
2459 struct wifi_data *wifi = user_data;
2461 DBG("result %d ifname %s, wifi %p", result,
2462 g_supplicant_interface_get_ifname(interface),
2465 if (result < 0 || !wifi)
2468 wifi->interface = interface;
2469 g_supplicant_interface_set_data(interface, wifi);
2471 if (g_supplicant_interface_get_ready(interface)) {
2472 wifi->interface_ready = true;
2473 finalize_interface_creation(wifi);
2477 static int wifi_enable(struct connman_device *device)
2479 struct wifi_data *wifi = connman_device_get_data(device);
2482 const char *driver = connman_option_get_string("wifi");
2485 DBG("device %p %p", device, wifi);
2487 index = connman_device_get_index(device);
2488 if (!wifi || index < 0)
2491 if (is_p2p_connecting())
2492 return -EINPROGRESS;
2494 interface = connman_inet_ifname(index);
2495 ret = g_supplicant_interface_create(interface, driver, NULL,
2496 interface_create_callback,
2503 return -EINPROGRESS;
2506 static int wifi_disable(struct connman_device *device)
2508 struct wifi_data *wifi = connman_device_get_data(device);
2511 DBG("device %p wifi %p", device, wifi);
2516 wifi->connected = false;
2517 wifi->disconnecting = false;
2519 if (wifi->pending_network)
2520 wifi->pending_network = NULL;
2522 #if !defined TIZEN_EXT
2523 stop_autoscan(device);
2526 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_P2P)) {
2527 g_source_remove(wifi->p2p_find_timeout);
2528 wifi->p2p_find_timeout = 0;
2529 connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_P2P, false);
2530 connman_device_unref(wifi->device);
2533 #if defined TIZEN_EXT
2534 if (wifi->automaxspeed_timeout != 0) {
2535 g_source_remove(wifi->automaxspeed_timeout);
2536 wifi->automaxspeed_timeout = 0;
2540 /* In case of a user scan, device is still referenced */
2541 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI)) {
2542 connman_device_set_scanning(device,
2543 CONNMAN_SERVICE_TYPE_WIFI, false);
2544 connman_device_unref(wifi->device);
2547 #if defined TIZEN_EXT
2548 stop_autoscan(device);
2551 remove_networks(device, wifi);
2554 #if defined TIZEN_EXT
2555 wifi->scan_pending_network = NULL;
2557 if (is_wifi_notifier_registered == true) {
2558 connman_notifier_unregister(¬ifier);
2559 is_wifi_notifier_registered = false;
2563 ret = g_supplicant_interface_remove(wifi->interface, NULL, NULL);
2567 return -EINPROGRESS;
2570 static int get_latest_connections(int max_ssids,
2571 GSupplicantScanParams *scan_data)
2573 GSequenceIter *iter;
2574 GSequence *latest_list;
2575 struct last_connected *entry;
2584 latest_list = g_sequence_new(free_entry);
2588 services = connman_storage_get_services();
2589 for (i = 0; services && services[i]; i++) {
2590 if (strncmp(services[i], "wifi_", 5) != 0)
2593 keyfile = connman_storage_load_service(services[i]);
2597 str = g_key_file_get_string(keyfile,
2598 services[i], "Favorite", NULL);
2599 if (!str || g_strcmp0(str, "true")) {
2601 g_key_file_free(keyfile);
2606 str = g_key_file_get_string(keyfile,
2607 services[i], "AutoConnect", NULL);
2608 if (!str || g_strcmp0(str, "true")) {
2610 g_key_file_free(keyfile);
2615 str = g_key_file_get_string(keyfile,
2616 services[i], "Modified", NULL);
2618 g_key_file_free(keyfile);
2621 g_time_val_from_iso8601(str, &modified);
2624 ssid = g_key_file_get_string(keyfile,
2625 services[i], "SSID", NULL);
2627 freq = g_key_file_get_integer(keyfile, services[i],
2630 entry = g_try_new(struct last_connected, 1);
2632 g_sequence_free(latest_list);
2633 g_key_file_free(keyfile);
2639 entry->modified = modified;
2642 g_sequence_insert_sorted(latest_list, entry,
2648 g_key_file_free(keyfile);
2651 g_strfreev(services);
2653 num_ssids = num_ssids > max_ssids ? max_ssids : num_ssids;
2655 iter = g_sequence_get_begin_iter(latest_list);
2657 for (i = 0; i < num_ssids; i++) {
2658 entry = g_sequence_get(iter);
2660 DBG("ssid %s freq %d modified %lu", entry->ssid, entry->freq,
2661 entry->modified.tv_sec);
2663 add_scan_param(entry->ssid, NULL, 0, entry->freq, scan_data,
2664 max_ssids, entry->ssid);
2666 iter = g_sequence_iter_next(iter);
2669 g_sequence_free(latest_list);
2673 static void wifi_update_scanner_type(struct wifi_data *wifi,
2674 enum wifi_scanning_type new_type)
2678 if (!wifi || wifi->scanning_type == new_type)
2681 wifi->scanning_type = new_type;
2683 setup_autoscan(wifi);
2686 static int wifi_scan_simple(struct connman_device *device)
2688 struct wifi_data *wifi = connman_device_get_data(device);
2690 reset_autoscan(device);
2692 /* Distinguish between devices performing passive and active scanning */
2694 wifi_update_scanner_type(wifi, WIFI_SCANNING_PASSIVE);
2696 return throw_wifi_scan(device, scan_callback_hidden);
2699 static gboolean p2p_find_stop(gpointer data)
2701 struct connman_device *device = data;
2702 struct wifi_data *wifi = connman_device_get_data(device);
2707 wifi->p2p_find_timeout = 0;
2709 g_supplicant_interface_p2p_stop_find(wifi->interface);
2712 connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_P2P, false);
2714 connman_device_unref(device);
2715 start_autoscan(device);
2720 static void p2p_find_callback(int result, GSupplicantInterface *interface,
2723 struct connman_device *device = user_data;
2724 struct wifi_data *wifi = connman_device_get_data(device);
2726 DBG("result %d wifi %p", result, wifi);
2731 if (wifi->p2p_find_timeout) {
2732 g_source_remove(wifi->p2p_find_timeout);
2733 wifi->p2p_find_timeout = 0;
2739 wifi->p2p_find_timeout = g_timeout_add_seconds(P2P_FIND_TIMEOUT,
2740 p2p_find_stop, device);
2741 if (!wifi->p2p_find_timeout)
2746 p2p_find_stop(device);
2749 static int p2p_find(struct connman_device *device)
2751 struct wifi_data *wifi;
2756 if (!p2p_technology)
2759 wifi = connman_device_get_data(device);
2761 if (g_supplicant_interface_is_p2p_finding(wifi->interface))
2764 reset_autoscan(device);
2765 connman_device_ref(device);
2767 ret = g_supplicant_interface_p2p_find(wifi->interface,
2768 p2p_find_callback, device);
2770 connman_device_unref(device);
2771 start_autoscan(device);
2773 connman_device_set_scanning(device,
2774 CONNMAN_SERVICE_TYPE_P2P, true);
2780 #if defined TIZEN_EXT
2781 static void specific_scan_callback(int result, GSupplicantInterface *interface,
2784 struct connman_device *device = user_data;
2785 struct wifi_data *wifi = connman_device_get_data(device);
2788 DBG("result %d wifi %p", result, wifi);
2790 if (wifi && wifi->scan_params) {
2791 g_supplicant_free_scan_params(wifi->scan_params);
2792 wifi->scan_params = NULL;
2795 scanning = connman_device_get_scanning(device,
2796 CONNMAN_SERVICE_TYPE_WIFI);
2798 connman_device_set_scanning(device,
2799 CONNMAN_SERVICE_TYPE_WIFI, false);
2800 connman_device_unref(device);
2804 static int wifi_specific_scan(enum connman_service_type type,
2805 struct connman_device *device, int scan_type,
2806 GSList *specific_scan_list, void *user_data)
2808 GSList *list = NULL;
2810 struct wifi_data *wifi = connman_device_get_data(device);
2811 GSupplicantScanParams *scan_params = NULL;
2812 struct scan_ssid *scan_ssid = NULL;
2821 if (wifi->p2p_device)
2824 if (type == CONNMAN_SERVICE_TYPE_P2P)
2825 return p2p_find(device);
2827 if (wifi->tethering)
2831 connman_device_get_scanning(device,
2832 CONNMAN_SERVICE_TYPE_WIFI);
2836 DBG("scan_type: %d", scan_type);
2837 if (scan_type == CONNMAN_MULTI_SCAN_SSID) { /* ssid based scan */
2838 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2840 DBG("Failed to allocate memory.");
2844 for (list = specific_scan_list; list; list = list->next) {
2845 ssid = (char *)list->data;
2846 int ssid_len = strlen(ssid);
2848 scan_ssid = g_try_new0(struct scan_ssid, 1);
2850 DBG("Failed to allocate memory.");
2851 g_supplicant_free_scan_params(scan_params);
2855 memcpy(scan_ssid->ssid, ssid, (ssid_len + 1));
2856 /* DBG("scan ssid %s len: %d", scan_ssid->ssid, ssid_len); */
2857 scan_ssid->ssid_len = ssid_len;
2858 scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
2861 scan_params->num_ssids = count;
2863 } else if (scan_type == CONNMAN_MULTI_SCAN_FREQ) { /* frequency based scan */
2865 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2867 DBG("Failed to allocate memory.");
2871 guint num_freqs = g_slist_length(specific_scan_list);
2872 DBG("num_freqs: %d", num_freqs);
2874 scan_params->freqs = g_try_new0(uint16_t, num_freqs);
2875 if (!scan_params->freqs) {
2876 DBG("Failed to allocate memory.");
2877 g_free(scan_params);
2882 for (list = specific_scan_list; list; list = list->next) {
2883 freq = (int)list->data;
2885 scan_params->freqs[count] = freq;
2886 DBG("scan_params->freqs[%d]: %d", count, scan_params->freqs[count]);
2889 scan_params->num_freqs = count;
2891 } else if (scan_type == CONNMAN_MULTI_SCAN_SSID_FREQ) { /* SSID & Frequency mixed scan */
2892 int freq_count, ap_count;
2893 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2895 DBG("Failed to allocate memory.");
2899 guint size = g_slist_length(specific_scan_list);
2901 scan_params->freqs = g_try_new0(uint16_t, size/2);
2902 if (!scan_params->freqs) {
2903 DBG("Failed to allocate memory.");
2904 g_free(scan_params);
2908 ap_count = freq_count = 0;
2909 for (list = specific_scan_list; list; list = list->next) {
2910 if (((connman_multi_scan_ap_s *)list->data)->flag == true) { /** ssid */
2911 ssid = ((connman_multi_scan_ap_s *)list->data)->str;
2912 int ssid_len = strlen(ssid);
2914 scan_ssid = g_try_new0(struct scan_ssid, 1);
2916 DBG("Failed to allocate memory.");
2917 g_supplicant_free_scan_params(scan_params);
2921 memcpy(scan_ssid->ssid, ssid, (ssid_len + 1));
2922 /* DBG("scan ssid %s len: %d", scan_ssid->ssid, ssid_len); */
2923 scan_ssid->ssid_len = ssid_len;
2924 scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
2928 freq = atoi(((connman_multi_scan_ap_s *)list->data)->str);
2929 scan_params->freqs[freq_count] = freq;
2930 DBG("scan_params->freqs[%d]: %d", freq_count, scan_params->freqs[freq_count]);
2934 scan_params->num_ssids = ap_count;
2935 scan_params->num_freqs = freq_count;
2937 DBG("Invalid scan");
2941 reset_autoscan(device);
2942 connman_device_ref(device);
2944 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
2945 specific_scan_callback, device);
2948 connman_device_set_scanning(device,
2949 CONNMAN_SERVICE_TYPE_WIFI, true);
2951 g_supplicant_free_scan_params(scan_params);
2952 connman_device_unref(device);
2959 #if defined TIZEN_EXT_WIFI_MESH
2960 static void mesh_scan_callback(int result, GSupplicantInterface *interface,
2963 struct connman_device *device = user_data;
2964 struct wifi_data *wifi = connman_device_get_data(device);
2967 DBG("result %d wifi %p", result, wifi);
2969 scanning = connman_device_get_scanning(device,
2970 CONNMAN_SERVICE_TYPE_MESH);
2972 connman_device_set_scanning(device,
2973 CONNMAN_SERVICE_TYPE_MESH, false);
2976 connman_device_unref(device);
2979 static int mesh_scan(struct connman_device *device)
2981 struct wifi_data *wifi;
2982 struct wifi_mesh_info *mesh_info;
2987 wifi = connman_device_get_data(device);
2989 if (!wifi || !wifi->mesh_interface)
2992 mesh_info = wifi->mesh_info;
2993 reset_autoscan(device);
2994 connman_device_ref(device);
2996 ret = g_supplicant_interface_scan(mesh_info->interface, NULL,
2997 mesh_scan_callback, device);
2999 connman_device_unref(device);
3001 connman_device_set_scanning(device,
3002 CONNMAN_SERVICE_TYPE_MESH, true);
3007 static void abort_scan_callback(int result, GSupplicantInterface *interface,
3010 struct connman_device *device = user_data;
3011 struct wifi_data *wifi = connman_device_get_data(device);
3013 DBG("result %d wifi %p", result, wifi);
3015 __connman_technology_notify_abort_scan(CONNMAN_SERVICE_TYPE_MESH, result);
3018 static int mesh_abort_scan(enum connman_service_type type,
3019 struct connman_device *device)
3021 struct wifi_data *wifi = connman_device_get_data(device);
3022 struct wifi_mesh_info *mesh_info;
3026 if (!wifi || !wifi->mesh_interface)
3029 if (type != CONNMAN_SERVICE_TYPE_MESH)
3032 mesh_info = wifi->mesh_info;
3034 scanning = connman_device_get_scanning(device,
3035 CONNMAN_SERVICE_TYPE_MESH);
3039 ret = g_supplicant_interface_abort_scan(mesh_info->interface,
3040 abort_scan_callback, device);
3045 static int mesh_specific_scan(enum connman_service_type type,
3046 struct connman_device *device, const char *ssid,
3047 unsigned int freq, void *user_data)
3049 struct wifi_data *wifi = connman_device_get_data(device);
3050 GSupplicantScanParams *scan_params = NULL;
3051 struct wifi_mesh_info *mesh_info;
3052 struct scan_ssid *scan_ssid;
3056 if (!wifi || !wifi->mesh_interface)
3059 if (type != CONNMAN_SERVICE_TYPE_MESH)
3062 if (wifi->p2p_device)
3065 mesh_info = wifi->mesh_info;
3067 scanning = connman_device_get_scanning(device,
3068 CONNMAN_SERVICE_TYPE_MESH);
3072 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
3076 scan_ssid = g_try_new(struct scan_ssid, 1);
3078 g_free(scan_params);
3082 scan_ssid->ssid_len = strlen(ssid);
3083 memcpy(scan_ssid->ssid, ssid, scan_ssid->ssid_len);
3084 scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
3085 scan_params->num_ssids = 1;
3087 scan_params->freqs = g_try_new(uint16_t, 1);
3088 if (!scan_params->freqs) {
3089 g_slist_free_full(scan_params->ssids, g_free);
3090 g_free(scan_params);
3094 scan_params->freqs[0] = freq;
3095 scan_params->num_freqs = 1;
3097 reset_autoscan(device);
3098 connman_device_ref(device);
3100 ret = g_supplicant_interface_scan(mesh_info->interface, scan_params,
3101 mesh_scan_callback, device);
3104 connman_device_set_scanning(device,
3105 CONNMAN_SERVICE_TYPE_MESH, true);
3107 g_supplicant_free_scan_params(scan_params);
3108 connman_device_unref(device);
3116 * Note that the hidden scan is only used when connecting to this specific
3117 * hidden AP first time. It is not used when system autoconnects to hidden AP.
3119 static int wifi_scan(struct connman_device *device,
3120 struct connman_device_scan_params *params)
3122 struct wifi_data *wifi = connman_device_get_data(device);
3123 GSupplicantScanParams *scan_params = NULL;
3124 struct scan_ssid *scan_ssid;
3125 struct hidden_params *hidden;
3127 int driver_max_ssids = 0;
3134 if (wifi->p2p_device)
3137 if (wifi->tethering)
3140 if (params->type == CONNMAN_SERVICE_TYPE_P2P)
3141 return p2p_find(device);
3143 #if defined TIZEN_EXT_WIFI_MESH
3144 if (params->type == CONNMAN_SERVICE_TYPE_MESH)
3145 return mesh_scan(device);
3148 DBG("device %p wifi %p hidden ssid %s", device, wifi->interface,
3151 scanning = connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI);
3153 if (!params->ssid || params->ssid_len == 0 || params->ssid_len > 32) {
3157 driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
3159 DBG("max ssids %d", driver_max_ssids);
3160 if (driver_max_ssids == 0)
3161 return wifi_scan_simple(device);
3165 if (scanning && wifi->hidden && wifi->postpone_hidden)
3171 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
3176 scan_ssid = g_try_new(struct scan_ssid, 1);
3178 g_free(scan_params);
3182 memcpy(scan_ssid->ssid, params->ssid, params->ssid_len);
3183 scan_ssid->ssid_len = params->ssid_len;
3184 scan_params->ssids = g_slist_prepend(scan_params->ssids,
3186 scan_params->num_ssids = 1;
3188 hidden = g_try_new0(struct hidden_params, 1);
3190 g_supplicant_free_scan_params(scan_params);
3195 hidden_free(wifi->hidden);
3196 wifi->hidden = NULL;
3199 memcpy(hidden->ssid, params->ssid, params->ssid_len);
3200 hidden->ssid_len = params->ssid_len;
3201 hidden->identity = g_strdup(params->identity);
3202 hidden->passphrase = g_strdup(params->passphrase);
3203 hidden->security = g_strdup(params->security);
3204 hidden->user_data = params->user_data;
3205 wifi->hidden = hidden;
3208 /* Let's keep this active scan for later,
3209 * when current scan will be over. */
3210 wifi->postpone_hidden = TRUE;
3211 hidden->scan_params = scan_params;
3215 } else if (wifi->connected) {
3216 g_supplicant_free_scan_params(scan_params);
3217 return wifi_scan_simple(device);
3218 } else if (!params->force_full_scan) {
3219 ret = get_latest_connections(driver_max_ssids, scan_params);
3221 g_supplicant_free_scan_params(scan_params);
3222 return wifi_scan_simple(device);
3226 /* Distinguish between devices performing passive and active scanning */
3227 wifi_update_scanner_type(wifi, WIFI_SCANNING_ACTIVE);
3229 connman_device_ref(device);
3231 reset_autoscan(device);
3232 #if defined TIZEN_EXT
3234 * When doing a full scan, stored hidden networks also need to be scanned
3235 * so that we can autoconnect to them.
3237 if (params->force_full_scan)
3238 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
3239 scan_callback_hidden, device);
3242 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
3243 scan_callback, device);
3245 connman_device_set_scanning(device,
3246 CONNMAN_SERVICE_TYPE_WIFI, true);
3247 #if defined TIZEN_EXT
3249 * To allow the Full Scan after ssid based scan, set the flag here
3250 * It is required because Tizen does not use the ConnMan specific
3251 * backgroung Scan feature.Tizen has added the BG Scan feature in
3252 * net-config. To sync with up ConnMan, we need to issue the Full Scan
3253 * after SSID specific scan.
3255 if (!params->force_full_scan && !do_hidden)
3256 wifi->allow_full_scan = TRUE;
3259 g_supplicant_free_scan_params(scan_params);
3260 connman_device_unref(device);
3263 hidden_free(wifi->hidden);
3264 wifi->hidden = NULL;
3271 static void wifi_stop_scan(enum connman_service_type type,
3272 struct connman_device *device)
3274 struct wifi_data *wifi = connman_device_get_data(device);
3276 DBG("device %p wifi %p", device, wifi);
3281 if (type == CONNMAN_SERVICE_TYPE_P2P) {
3282 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_P2P)) {
3283 g_source_remove(wifi->p2p_find_timeout);
3284 p2p_find_stop(device);
3289 static void wifi_regdom_callback(int result,
3293 struct connman_device *device = user_data;
3295 connman_device_regdom_notify(device, result, alpha2);
3297 connman_device_unref(device);
3300 static int wifi_set_regdom(struct connman_device *device, const char *alpha2)
3302 struct wifi_data *wifi = connman_device_get_data(device);
3308 connman_device_ref(device);
3310 ret = g_supplicant_interface_set_country(wifi->interface,
3311 wifi_regdom_callback,
3314 connman_device_unref(device);
3319 static struct connman_device_driver wifi_ng_driver = {
3321 .type = CONNMAN_DEVICE_TYPE_WIFI,
3322 .priority = CONNMAN_DEVICE_PRIORITY_LOW,
3323 .probe = wifi_probe,
3324 .remove = wifi_remove,
3325 .enable = wifi_enable,
3326 .disable = wifi_disable,
3328 .stop_scan = wifi_stop_scan,
3329 .set_regdom = wifi_set_regdom,
3330 #if defined TIZEN_EXT
3331 .specific_scan = wifi_specific_scan,
3333 #if defined TIZEN_EXT_WIFI_MESH
3334 .abort_scan = mesh_abort_scan,
3335 .mesh_specific_scan = mesh_specific_scan,
3339 static void system_ready(void)
3343 if (connman_device_driver_register(&wifi_ng_driver) < 0)
3344 connman_error("Failed to register WiFi driver");
3347 static void system_killed(void)
3351 connman_device_driver_unregister(&wifi_ng_driver);
3354 static int network_probe(struct connman_network *network)
3356 DBG("network %p", network);
3361 static void network_remove(struct connman_network *network)
3363 struct connman_device *device = connman_network_get_device(network);
3364 struct wifi_data *wifi;
3366 DBG("network %p", network);
3368 wifi = connman_device_get_data(device);
3372 if (wifi->network != network)
3375 wifi->network = NULL;
3377 #if defined TIZEN_EXT
3378 wifi->disconnecting = false;
3380 if (wifi->pending_network == network)
3381 wifi->pending_network = NULL;
3383 if (wifi->scan_pending_network == network)
3384 wifi->scan_pending_network = NULL;
3388 static void connect_callback(int result, GSupplicantInterface *interface,
3391 #if defined TIZEN_EXT
3393 struct wifi_data *wifi;
3395 struct connman_network *network = user_data;
3397 DBG("network %p result %d", network, result);
3399 #if defined TIZEN_EXT
3400 char *ifname = g_supplicant_interface_get_ifname(interface);
3401 set_connman_bssid(RESET_BSSID, NULL, ifname);
3403 for (list = iface_list; list; list = list->next) {
3406 if (wifi && wifi->network == network)
3410 /* wifi_data may be invalid because wifi is already disabled */
3415 if (result == -ENOKEY) {
3416 connman_network_set_error(network,
3417 CONNMAN_NETWORK_ERROR_INVALID_KEY);
3418 } else if (result < 0) {
3419 connman_network_set_error(network,
3420 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
3423 connman_network_unref(network);
3426 static GSupplicantSecurity network_security(const char *security)
3428 if (g_str_equal(security, "none"))
3429 return G_SUPPLICANT_SECURITY_NONE;
3430 else if (g_str_equal(security, "wep"))
3431 return G_SUPPLICANT_SECURITY_WEP;
3432 else if (g_str_equal(security, "psk"))
3433 return G_SUPPLICANT_SECURITY_PSK;
3434 else if (g_str_equal(security, "wpa"))
3435 return G_SUPPLICANT_SECURITY_PSK;
3436 else if (g_str_equal(security, "rsn"))
3437 return G_SUPPLICANT_SECURITY_PSK;
3438 else if (g_str_equal(security, "ieee8021x"))
3439 return G_SUPPLICANT_SECURITY_IEEE8021X;
3440 #if defined TIZEN_EXT
3441 else if (g_str_equal(security, "ft_psk") == TRUE)
3442 return G_SUPPLICANT_SECURITY_FT_PSK;
3443 else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
3444 return G_SUPPLICANT_SECURITY_FT_IEEE8021X;
3445 else if (g_str_equal(security, "sae"))
3446 return G_SUPPLICANT_SECURITY_SAE;
3447 else if (g_str_equal(security, "owe"))
3448 return G_SUPPLICANT_SECURITY_OWE;
3449 else if (g_str_equal(security, "dpp"))
3450 return G_SUPPLICANT_SECURITY_DPP;
3453 return G_SUPPLICANT_SECURITY_UNKNOWN;
3456 #if defined TIZEN_EXT
3457 static GSupplicantEapKeymgmt network_eap_keymgmt(const char *security)
3459 if (security == NULL)
3460 return G_SUPPLICANT_EAP_KEYMGMT_NONE;
3462 if (g_str_equal(security, "FT") == TRUE)
3463 return G_SUPPLICANT_EAP_KEYMGMT_FT;
3464 else if (g_str_equal(security, "CCKM") == TRUE)
3465 return G_SUPPLICANT_EAP_KEYMGMT_CCKM;
3467 return G_SUPPLICANT_EAP_KEYMGMT_NONE;
3471 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
3473 const char *security;
3474 #if defined TIZEN_EXT
3475 const void *ssid_data;
3478 memset(ssid, 0, sizeof(*ssid));
3479 ssid->mode = G_SUPPLICANT_MODE_INFRA;
3480 #if defined TIZEN_EXT
3481 ssid_data = connman_network_get_blob(network, "WiFi.SSID",
3483 ssid->ssid = g_try_malloc0(ssid->ssid_len);
3488 memcpy(ssid->ssid, ssid_data, ssid->ssid_len);
3490 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
3493 ssid->scan_ssid = 1;
3494 security = connman_network_get_string(network, "WiFi.Security");
3495 ssid->security = network_security(security);
3496 #if defined TIZEN_EXT
3497 ssid->ieee80211w = 1;
3499 ssid->passphrase = connman_network_get_string(network,
3502 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
3505 * If our private key password is unset,
3506 * we use the supplied passphrase. That is needed
3507 * for PEAP where 2 passphrases (identity and client
3508 * cert may have to be provided.
3510 if (!connman_network_get_string(network, "WiFi.PrivateKeyPassphrase"))
3511 connman_network_set_string(network,
3512 "WiFi.PrivateKeyPassphrase",
3514 /* We must have an identity for both PEAP and TLS */
3515 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
3517 /* Use agent provided identity as a fallback */
3518 if (!ssid->identity || strlen(ssid->identity) == 0)
3519 ssid->identity = connman_network_get_string(network,
3520 "WiFi.AgentIdentity");
3522 ssid->anonymous_identity = connman_network_get_string(network,
3523 "WiFi.AnonymousIdentity");
3524 ssid->ca_cert_path = connman_network_get_string(network,
3526 ssid->subject_match = connman_network_get_string(network,
3527 "WiFi.SubjectMatch");
3528 ssid->altsubject_match = connman_network_get_string(network,
3529 "WiFi.AltSubjectMatch");
3530 ssid->domain_suffix_match = connman_network_get_string(network,
3531 "WiFi.DomainSuffixMatch");
3532 ssid->domain_match = connman_network_get_string(network,
3533 "WiFi.DomainMatch");
3534 ssid->client_cert_path = connman_network_get_string(network,
3535 "WiFi.ClientCertFile");
3536 ssid->private_key_path = connman_network_get_string(network,
3537 "WiFi.PrivateKeyFile");
3538 ssid->private_key_passphrase = connman_network_get_string(network,
3539 "WiFi.PrivateKeyPassphrase");
3540 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
3542 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
3543 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
3544 #if defined TIZEN_EXT
3545 ssid->connector = connman_network_get_string(network,
3547 ssid->c_sign_key = connman_network_get_string(network,
3549 ssid->net_access_key = connman_network_get_string(network,
3550 "WiFi.NetAccessKey");
3553 #if defined TIZEN_EXT
3554 const char *ifname = connman_device_get_string(
3555 connman_network_get_device(network), "Interface");
3556 if (set_connman_bssid(CHECK_BSSID, NULL, ifname) == 6) {
3557 ssid->bssid_for_connect_len = 6;
3558 set_connman_bssid(GET_BSSID, (char *)ssid->bssid_for_connect, ifname);
3559 DBG("BSSID : %02x:%02x:%02x:%02x:%02x:%02x",
3560 ssid->bssid_for_connect[0], ssid->bssid_for_connect[1],
3561 ssid->bssid_for_connect[2], ssid->bssid_for_connect[3],
3562 ssid->bssid_for_connect[4], ssid->bssid_for_connect[5]);
3564 ssid->freq = connman_network_get_frequency(network);
3567 GSList *bssid_list = (GSList *)connman_network_get_bssid_list(network);
3568 if (bssid_list && g_slist_length(bssid_list) > 1) {
3570 /* If there are more than one bssid,
3571 * the user-specified bssid is tried only once at the beginning.
3572 * After that, the bssids in the list are tried in order.
3574 if (set_connman_bssid(CHECK_BSSID, NULL, ifname) == 6) {
3575 set_connman_bssid(RESET_BSSID, NULL, ifname);
3580 char buff[MAC_ADDRESS_LENGTH];
3581 for (list = bssid_list; list; list = list->next) {
3582 struct connman_bssids * bssids = (struct connman_bssids *)list->data;
3584 g_snprintf(buff, MAC_ADDRESS_LENGTH, "%02x:%02x:%02x:%02x:%02x:%02x",
3585 bssids->bssid[0], bssids->bssid[1], bssids->bssid[2],
3586 bssids->bssid[3], bssids->bssid[4], bssids->bssid[5]);
3587 buff[MAC_ADDRESS_LENGTH - 1] = '\0';
3589 gchar *curr_bssid = g_strdup((const gchar *)buff);
3591 if (g_hash_table_contains(failed_bssids, curr_bssid)) {
3592 DBG("bssid match, try next bssid");
3596 g_hash_table_add(failed_bssids, curr_bssid);
3598 memcpy(buff_bssid, bssids->bssid, WIFI_BSSID_LEN_MAX);
3599 ssid->bssid = buff_bssid;
3600 ssid->freq = (unsigned int)bssids->frequency;
3606 ssid->bssid = connman_network_get_bssid(network);
3607 g_hash_table_remove_all(failed_bssids);
3610 ssid->bssid = connman_network_get_bssid(network);
3613 ssid->eap_keymgmt = network_eap_keymgmt(
3614 connman_network_get_string(network, "WiFi.KeymgmtType"));
3615 ssid->phase1 = connman_network_get_string(network, "WiFi.Phase1");
3617 if(g_strcmp0(ssid->eap, "fast") == 0)
3618 ssid->pac_file = g_strdup(WIFI_EAP_FAST_PAC_FILE);
3620 ssid->keymgmt = connman_network_get_keymgmt(network);
3623 if (connman_setting_get_bool("BackgroundScanning"))
3624 ssid->bgscan = BGSCAN_DEFAULT;
3627 static int network_connect(struct connman_network *network)
3629 struct connman_device *device = connman_network_get_device(network);
3630 struct wifi_data *wifi;
3631 GSupplicantInterface *interface;
3632 GSupplicantSSID *ssid;
3634 DBG("network %p", network);
3639 wifi = connman_device_get_data(device);
3643 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
3647 interface = wifi->interface;
3649 ssid_init(ssid, network);
3651 if (wifi->disconnecting) {
3652 wifi->pending_network = network;
3653 #if defined TIZEN_EXT
3658 wifi->network = connman_network_ref(network);
3660 #if defined TIZEN_EXT
3661 wifi->scan_pending_network = NULL;
3664 return g_supplicant_interface_connect(interface, ssid,
3665 connect_callback, network);
3668 return -EINPROGRESS;
3671 static void disconnect_callback(int result, GSupplicantInterface *interface,
3674 #if defined TIZEN_EXT
3676 struct wifi_data *wifi;
3677 struct connman_network *network = user_data;
3679 DBG("network %p result %d", network, result);
3681 for (list = iface_list; list; list = list->next) {
3684 if (wifi->network == NULL && wifi->disconnecting == true)
3685 wifi->disconnecting = false;
3687 if (wifi->network == network)
3691 /* wifi_data may be invalid because wifi is already disabled */
3696 struct wifi_data *wifi = user_data;
3699 DBG("result %d supplicant interface %p wifi %p",
3700 result, interface, wifi);
3702 if (result == -ECONNABORTED) {
3703 DBG("wifi interface no longer available");
3707 if (wifi->network != wifi->pending_network)
3708 connman_network_set_connected(wifi->network, false);
3709 wifi->network = NULL;
3711 wifi->disconnecting = false;
3712 wifi->connected = false;
3714 if (wifi->pending_network) {
3715 network_connect(wifi->pending_network);
3716 wifi->pending_network = NULL;
3719 start_autoscan(wifi->device);
3722 static int network_disconnect(struct connman_network *network)
3724 struct connman_device *device = connman_network_get_device(network);
3725 struct wifi_data *wifi;
3727 #if defined TIZEN_EXT
3728 struct connman_service *service;
3731 DBG("network %p", network);
3733 wifi = connman_device_get_data(device);
3734 if (!wifi || !wifi->interface)
3737 #if defined TIZEN_EXT
3738 if (connman_network_get_associating(network) == true) {
3739 connman_network_clear_associating(network);
3740 connman_network_set_bool(network, "WiFi.UseWPS", false);
3742 service = connman_service_lookup_from_network(network);
3744 if (service != NULL &&
3745 (__connman_service_is_connected_state(service,
3746 CONNMAN_IPCONFIG_TYPE_IPV4) == false &&
3747 __connman_service_is_connected_state(service,
3748 CONNMAN_IPCONFIG_TYPE_IPV6) == false) &&
3749 (connman_service_get_favorite(service) == false))
3750 __connman_service_set_passphrase(service, NULL);
3753 if (wifi->pending_network == network)
3754 wifi->pending_network = NULL;
3756 if (wifi->scan_pending_network == network)
3757 wifi->scan_pending_network = NULL;
3760 connman_network_set_associating(network, false);
3762 if (wifi->disconnecting)
3765 wifi->disconnecting = true;
3767 #if defined TIZEN_EXT
3768 err = g_supplicant_interface_disconnect(wifi->interface,
3769 disconnect_callback, network);
3771 err = g_supplicant_interface_disconnect(wifi->interface,
3772 disconnect_callback, wifi);
3776 wifi->disconnecting = false;
3781 #if defined TIZEN_EXT
3782 static void set_connection_mode(struct connman_network *network,
3785 ieee80211_modes_e phy_mode;
3786 connection_mode_e conn_mode;
3788 phy_mode = connman_network_get_phy_mode(network);
3790 case IEEE80211_MODE_B:
3791 if (linkspeed > 0 && linkspeed <= 11)
3792 conn_mode = CONNECTION_MODE_IEEE80211B;
3794 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3797 case IEEE80211_MODE_BG:
3798 if (linkspeed > 0 && linkspeed <= 11)
3799 conn_mode = CONNECTION_MODE_IEEE80211B;
3800 else if (linkspeed > 11 && linkspeed <= 54)
3801 conn_mode = CONNECTION_MODE_IEEE80211G;
3803 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3806 case IEEE80211_MODE_BGN:
3807 if (linkspeed > 0 && linkspeed <= 11)
3808 conn_mode = CONNECTION_MODE_IEEE80211B;
3809 else if (linkspeed > 11 && linkspeed <= 54)
3810 conn_mode = CONNECTION_MODE_IEEE80211G;
3811 else if (linkspeed > 54 && linkspeed <= 450)
3812 conn_mode = CONNECTION_MODE_IEEE80211N;
3814 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3817 case IEEE80211_MODE_A:
3818 if (linkspeed > 0 && linkspeed <= 54)
3819 conn_mode = CONNECTION_MODE_IEEE80211A;
3821 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3824 case IEEE80211_MODE_AN:
3825 if (linkspeed > 0 && linkspeed <= 54)
3826 conn_mode = CONNECTION_MODE_IEEE80211A;
3827 else if (linkspeed > 54 && linkspeed <= 450)
3828 conn_mode = CONNECTION_MODE_IEEE80211N;
3830 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3833 case IEEE80211_MODE_ANAC:
3834 if (linkspeed > 0 && linkspeed <= 54)
3835 conn_mode = CONNECTION_MODE_IEEE80211A;
3836 else if (linkspeed > 54 && linkspeed <= 450)
3837 conn_mode = CONNECTION_MODE_IEEE80211N;
3838 else if (linkspeed > 450 && linkspeed <= 1300)
3839 conn_mode = CONNECTION_MODE_IEEE80211AC;
3841 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3845 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3849 DBG("connection mode(%d)", conn_mode);
3850 connman_network_set_connection_mode(network, conn_mode);
3853 static void signalpoll_callback(int result, int maxspeed, int strength,
3856 struct connman_network *network = user_data;
3859 DBG("Failed to get maxspeed from signalpoll !");
3860 connman_network_unref(network);
3868 DBG("maxspeed = %d, strength = %d", maxspeed, strength);
3870 connman_network_set_strength(network, (uint8_t)strength);
3871 connman_network_set_maxspeed(network, maxspeed);
3872 set_connection_mode(network, maxspeed);
3874 connman_network_unref(network);
3877 static int network_signalpoll(struct wifi_data *wifi)
3879 GSupplicantInterface *interface;
3880 struct connman_network *network;
3882 if (!wifi || !wifi->network)
3885 wifi->network = connman_network_ref(wifi->network);
3887 interface = wifi->interface;
3888 network = wifi->network;
3890 DBG("network %p", network);
3892 return g_supplicant_interface_signalpoll(interface, signalpoll_callback, network);
3895 static gboolean autosignalpoll_timeout(gpointer data)
3897 struct wifi_data *wifi = data;
3899 if (!wifi || !wifi->automaxspeed_timeout) {
3900 DBG("automaxspeed_timeout is found to be zero. i.e. currently in disconnected state. !!");
3904 int ret = network_signalpoll(wifi);
3906 DBG("Fail to get max speed !!");
3907 wifi->automaxspeed_timeout = 0;
3908 connman_network_unref(wifi->network);
3916 static struct connman_network_driver network_driver = {
3918 .type = CONNMAN_NETWORK_TYPE_WIFI,
3919 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
3920 .probe = network_probe,
3921 .remove = network_remove,
3922 .connect = network_connect,
3923 .disconnect = network_disconnect,
3926 static void interface_added(GSupplicantInterface *interface)
3928 const char *ifname = g_supplicant_interface_get_ifname(interface);
3929 const char *driver = g_supplicant_interface_get_driver(interface);
3930 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
3932 * Note: If supplicant interface's driver is wired then skip it,
3933 * because it meanti only for ethernet not Wi-Fi.
3935 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
3937 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
3939 #if defined TIZEN_EXT
3940 bool is_5_0_ghz_supported = g_supplicant_interface_get_is_5_0_ghz_supported(interface);
3943 struct wifi_data *wifi;
3945 wifi = g_supplicant_interface_get_data(interface);
3947 wifi = get_pending_wifi_data(ifname);
3951 wifi->interface = interface;
3952 g_supplicant_interface_set_data(interface, wifi);
3953 p2p_iface_list = g_list_append(p2p_iface_list, wifi);
3954 wifi->p2p_device = true;
3957 DBG("ifname %s driver %s wifi %p tethering %d",
3958 ifname, driver, wifi, wifi->tethering);
3960 if (!wifi->device) {
3961 connman_error("WiFi device not set");
3965 connman_device_set_powered(wifi->device, true);
3966 #if defined TIZEN_EXT
3967 connman_device_set_wifi_5ghz_supported(wifi->device, is_5_0_ghz_supported);
3968 /* Max number of SSIDs supported by wlan chipset that can be scanned */
3969 int max_scan_ssids = g_supplicant_interface_get_max_scan_ssids(interface);
3970 connman_device_set_max_scan_ssids(wifi->device, max_scan_ssids);
3974 static bool is_idle(struct wifi_data *wifi)
3976 DBG("state %d", wifi->state);
3978 switch (wifi->state) {
3979 case G_SUPPLICANT_STATE_UNKNOWN:
3980 case G_SUPPLICANT_STATE_DISABLED:
3981 case G_SUPPLICANT_STATE_DISCONNECTED:
3982 case G_SUPPLICANT_STATE_INACTIVE:
3983 case G_SUPPLICANT_STATE_SCANNING:
3986 case G_SUPPLICANT_STATE_AUTHENTICATING:
3987 case G_SUPPLICANT_STATE_ASSOCIATING:
3988 case G_SUPPLICANT_STATE_ASSOCIATED:
3989 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
3990 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
3991 case G_SUPPLICANT_STATE_COMPLETED:
3998 static bool is_idle_wps(GSupplicantInterface *interface,
3999 struct wifi_data *wifi)
4001 /* First, let's check if WPS processing did not went wrong */
4002 if (g_supplicant_interface_get_wps_state(interface) ==
4003 G_SUPPLICANT_WPS_STATE_FAIL)
4006 /* Unlike normal connection, being associated while processing wps
4007 * actually means that we are idling. */
4008 switch (wifi->state) {
4009 case G_SUPPLICANT_STATE_UNKNOWN:
4010 case G_SUPPLICANT_STATE_DISABLED:
4011 case G_SUPPLICANT_STATE_DISCONNECTED:
4012 case G_SUPPLICANT_STATE_INACTIVE:
4013 case G_SUPPLICANT_STATE_SCANNING:
4014 case G_SUPPLICANT_STATE_ASSOCIATED:
4016 case G_SUPPLICANT_STATE_AUTHENTICATING:
4017 case G_SUPPLICANT_STATE_ASSOCIATING:
4018 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4019 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4020 case G_SUPPLICANT_STATE_COMPLETED:
4027 static bool handle_wps_completion(GSupplicantInterface *interface,
4028 struct connman_network *network,
4029 struct connman_device *device,
4030 struct wifi_data *wifi)
4034 wps = connman_network_get_bool(network, "WiFi.UseWPS");
4036 const unsigned char *ssid, *wps_ssid;
4037 unsigned int ssid_len, wps_ssid_len;
4038 const char *wps_key;
4040 /* Checking if we got associated with requested
4042 ssid = connman_network_get_blob(network, "WiFi.SSID",
4045 wps_ssid = g_supplicant_interface_get_wps_ssid(
4046 interface, &wps_ssid_len);
4048 if (!wps_ssid || wps_ssid_len != ssid_len ||
4049 memcmp(ssid, wps_ssid, ssid_len) != 0) {
4050 connman_network_set_associating(network, false);
4051 #if defined TIZEN_EXT
4052 g_supplicant_interface_disconnect(wifi->interface,
4053 disconnect_callback, wifi->network);
4055 connman_network_set_bool(network, "WiFi.UseWPS", false);
4056 connman_network_set_string(network, "WiFi.PinWPS", NULL);
4058 g_supplicant_interface_disconnect(wifi->interface,
4059 disconnect_callback, wifi);
4064 wps_key = g_supplicant_interface_get_wps_key(interface);
4065 #if defined TIZEN_EXT
4066 /* Check the passphrase and encrypt it
4069 gchar *passphrase = g_strdup(wps_key);
4071 connman_network_set_string(network, "WiFi.PinWPS", NULL);
4073 if (check_passphrase_ext(network, passphrase) < 0) {
4074 DBG("[WPS] Invalid passphrase");
4079 ret = send_encryption_request(passphrase, network);
4084 DBG("[WPS] Encryption request succeeded");
4086 DBG("[WPS] Encryption request failed %d", ret);
4089 connman_network_set_string(network, "WiFi.Passphrase",
4092 connman_network_set_string(network, "WiFi.PinWPS", NULL);
4099 static bool handle_assoc_status_code(GSupplicantInterface *interface,
4100 struct wifi_data *wifi)
4102 if (wifi->state == G_SUPPLICANT_STATE_ASSOCIATING &&
4103 #if defined TIZEN_EXT
4104 wifi->assoc_code > 0 &&
4106 wifi->assoc_code == ASSOC_STATUS_NO_CLIENT &&
4108 wifi->load_shaping_retries < LOAD_SHAPING_MAX_RETRIES) {
4109 wifi->load_shaping_retries ++;
4112 wifi->load_shaping_retries = 0;
4116 static bool handle_4way_handshake_failure(GSupplicantInterface *interface,
4117 struct connman_network *network,
4118 struct wifi_data *wifi)
4120 #if defined TIZEN_EXT
4121 const char *security;
4122 struct connman_service *service;
4124 if (wifi->connected)
4127 security = connman_network_get_string(network, "WiFi.Security");
4129 if (security && g_str_equal(security, "ieee8021x") == true &&
4130 wifi->state == G_SUPPLICANT_STATE_ASSOCIATED) {
4132 connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
4137 if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
4140 struct connman_service *service;
4142 if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
4145 if (wifi->connected)
4149 service = connman_service_lookup_from_network(network);
4155 if (connman_service_get_favorite(service)) {
4156 if (wifi->retries < FAVORITE_MAXIMUM_RETRIES)
4161 connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
4166 #if defined TIZEN_EXT
4167 static bool handle_wifi_assoc_retry(struct connman_network *network,
4168 struct wifi_data *wifi)
4170 const char *security;
4172 if (!wifi->network || wifi->connected || wifi->disconnecting ||
4173 connman_network_get_connecting(network) != true) {
4174 wifi->assoc_retry_count = 0;
4178 if (wifi->state != G_SUPPLICANT_STATE_ASSOCIATING &&
4179 wifi->state != G_SUPPLICANT_STATE_ASSOCIATED) {
4180 wifi->assoc_retry_count = 0;
4184 security = connman_network_get_string(network, "WiFi.Security");
4185 if (security && g_str_equal(security, "ieee8021x") == true &&
4186 wifi->state == G_SUPPLICANT_STATE_ASSOCIATED) {
4187 wifi->assoc_retry_count = 0;
4191 if (++wifi->assoc_retry_count >= TIZEN_ASSOC_RETRY_COUNT) {
4192 wifi->assoc_retry_count = 0;
4194 /* Honestly it's not an invalid-key error,
4195 * however QA team recommends that the invalid-key error
4196 * might be better to display for user experience.
4198 connman_network_set_error(network, CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
4207 static void interface_state(GSupplicantInterface *interface)
4209 struct connman_network *network;
4210 struct connman_device *device;
4211 struct wifi_data *wifi;
4212 GSupplicantState state = g_supplicant_interface_get_state(interface);
4213 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4215 * Note: If supplicant interface's driver is wired then skip it,
4216 * because it meanti only for ethernet not Wi-Fi.
4218 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4220 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4225 wifi = g_supplicant_interface_get_data(interface);
4227 DBG("wifi %p interface state %d", wifi, state);
4232 device = wifi->device;
4236 if (state == G_SUPPLICANT_STATE_COMPLETED) {
4237 if (wifi->tethering_param) {
4238 g_free(wifi->tethering_param->ssid);
4239 g_free(wifi->tethering_param);
4240 wifi->tethering_param = NULL;
4243 if (wifi->tethering)
4244 stop_autoscan(device);
4247 if (g_supplicant_interface_get_ready(interface) &&
4248 !wifi->interface_ready) {
4249 wifi->interface_ready = true;
4250 finalize_interface_creation(wifi);
4253 network = wifi->network;
4258 case G_SUPPLICANT_STATE_SCANNING:
4259 if (wifi->connected)
4260 connman_network_set_connected(network, false);
4264 case G_SUPPLICANT_STATE_AUTHENTICATING:
4265 case G_SUPPLICANT_STATE_ASSOCIATING:
4266 #if defined TIZEN_EXT
4267 reset_autoscan(device);
4269 stop_autoscan(device);
4272 if (!wifi->connected)
4273 connman_network_set_associating(network, true);
4277 case G_SUPPLICANT_STATE_COMPLETED:
4278 #if defined TIZEN_EXT
4279 /* though it should be already reset: */
4280 reset_autoscan(device);
4282 wifi->assoc_retry_count = 0;
4284 wifi->scan_pending_network = NULL;
4286 /* should be cleared scanning flag */
4287 bool scanning = connman_device_get_scanning(device,
4288 CONNMAN_SERVICE_TYPE_WIFI);
4290 connman_device_set_scanning(device,
4291 CONNMAN_SERVICE_TYPE_WIFI, false);
4292 connman_device_unref(device);
4295 if (!wifi->automaxspeed_timeout) {
4296 DBG("Going to start signalpoll timer!!");
4297 int ret = network_signalpoll(wifi);
4299 DBG("Fail to get max speed !!");
4301 wifi->automaxspeed_timeout = g_timeout_add_seconds(10, autosignalpoll_timeout, wifi);
4304 g_hash_table_remove_all(failed_bssids);
4306 /* though it should be already stopped: */
4307 stop_autoscan(device);
4310 if (!handle_wps_completion(interface, network, device, wifi))
4313 connman_network_set_connected(network, true);
4315 wifi->disconnect_code = 0;
4316 wifi->assoc_code = 0;
4317 wifi->load_shaping_retries = 0;
4320 case G_SUPPLICANT_STATE_DISCONNECTED:
4321 #if defined TIZEN_EXT
4322 connman_network_set_strength(network, 0);
4323 connman_network_set_maxspeed(network, 0);
4325 if (wifi->automaxspeed_timeout != 0) {
4326 g_source_remove(wifi->automaxspeed_timeout);
4327 wifi->automaxspeed_timeout = 0;
4328 DBG("Remove signalpoll timer!!");
4332 * If we're in one of the idle modes, we have
4333 * not started association yet and thus setting
4334 * those ones to FALSE could cancel an association
4337 wps = connman_network_get_bool(network, "WiFi.UseWPS");
4339 if (is_idle_wps(interface, wifi))
4345 #if defined TIZEN_EXT
4346 if (handle_assoc_status_code(interface, wifi)) {
4347 GSList *bssid_list = (GSList *)connman_network_get_bssid_list(network);
4348 const char *group = connman_network_get_group(network);
4349 GSupplicantNetwork *supplicant_network;
4350 guint bssid_length = 0;
4353 supplicant_network = g_supplicant_interface_get_network(interface, group);
4355 connman_network_set_assoc_reject_table(network,
4356 g_supplicant_network_get_assoc_reject_table(supplicant_network));
4358 g_supplicant_network_update_assoc_reject(interface, supplicant_network);
4362 bssid_length = g_slist_length(bssid_list);
4364 if (bssid_length > 1 && bssid_length > g_hash_table_size(failed_bssids)) {
4365 network_connect(network);
4369 wifi->load_shaping_retries = 0;
4372 g_hash_table_remove_all(failed_bssids);
4374 if (handle_assoc_status_code(interface, wifi))
4378 /* If previous state was 4way-handshake, then
4379 * it's either: psk was incorrect and thus we retry
4380 * or if we reach the maximum retries we declare the
4382 if (handle_4way_handshake_failure(interface,
4386 /* See table 8-36 Reason codes in IEEE Std 802.11 */
4387 switch (wifi->disconnect_code) {
4388 case 1: /* Unspecified reason */
4389 /* Let's assume it's because we got blocked */
4391 case 6: /* Class 2 frame received from nonauthenticated STA */
4392 connman_network_set_error(network,
4393 CONNMAN_NETWORK_ERROR_BLOCKED);
4400 #if defined TIZEN_EXT
4401 /* Some of Wi-Fi networks are not comply Wi-Fi specification.
4402 * Retry association until its retry count is expired */
4403 if (handle_wifi_assoc_retry(network, wifi) == true) {
4404 throw_wifi_scan(wifi->device, scan_callback);
4405 wifi->scan_pending_network = wifi->network;
4409 if(wifi->disconnect_code > 0){
4410 DBG("Set disconnect reason code(%d)", wifi->disconnect_code);
4411 connman_network_set_disconnect_reason(network, wifi->disconnect_code);
4415 if (network != wifi->pending_network) {
4416 connman_network_set_connected(network, false);
4417 connman_network_set_associating(network, false);
4419 wifi->disconnecting = false;
4421 start_autoscan(device);
4425 case G_SUPPLICANT_STATE_INACTIVE:
4426 #if defined TIZEN_EXT
4427 if (handle_wps_completion(interface, network, device, wifi) == false)
4430 connman_network_set_associating(network, false);
4431 start_autoscan(device);
4435 case G_SUPPLICANT_STATE_UNKNOWN:
4436 case G_SUPPLICANT_STATE_DISABLED:
4437 case G_SUPPLICANT_STATE_ASSOCIATED:
4438 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4439 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4443 old_connected = wifi->connected;
4444 wifi->state = state;
4446 /* Saving wpa_s state policy:
4447 * If connected and if the state changes are roaming related:
4448 * --> We stay connected
4450 * --> We are connected
4452 * --> We are not connected
4455 case G_SUPPLICANT_STATE_AUTHENTICATING:
4456 case G_SUPPLICANT_STATE_ASSOCIATING:
4457 case G_SUPPLICANT_STATE_ASSOCIATED:
4458 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4459 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4460 if (wifi->connected)
4461 connman_warn("Probably roaming right now!"
4462 " Staying connected...");
4464 case G_SUPPLICANT_STATE_SCANNING:
4465 wifi->connected = false;
4468 start_autoscan(device);
4470 case G_SUPPLICANT_STATE_COMPLETED:
4471 wifi->connected = true;
4474 wifi->connected = false;
4481 static void interface_removed(GSupplicantInterface *interface)
4483 const char *ifname = g_supplicant_interface_get_ifname(interface);
4484 struct wifi_data *wifi;
4485 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4487 * Note: If supplicant interface's driver is wired then skip it,
4488 * because it meanti only for ethernet not Wi-Fi.
4490 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4492 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4495 DBG("ifname %s", ifname);
4497 wifi = g_supplicant_interface_get_data(interface);
4499 #if defined TIZEN_EXT_WIFI_MESH
4500 if (wifi && wifi->mesh_interface) {
4501 DBG("Notify mesh interface remove");
4502 connman_mesh_notify_interface_remove(true);
4503 struct wifi_mesh_info *mesh_info = wifi->mesh_info;
4504 g_free(mesh_info->parent_ifname);
4505 g_free(mesh_info->ifname);
4506 g_free(mesh_info->identifier);
4508 wifi->mesh_interface = false;
4509 wifi->mesh_info = NULL;
4515 wifi->interface = NULL;
4517 if (wifi && wifi->tethering)
4520 if (!wifi || !wifi->device) {
4521 DBG("wifi interface already removed");
4525 connman_device_set_powered(wifi->device, false);
4527 check_p2p_technology();
4528 #if defined TIZEN_EXT_WIFI_MESH
4529 check_mesh_technology();
4533 static void set_device_type(const char *type, char dev_type[17])
4535 const char *oui = "0050F204";
4536 const char *category = "0001";
4537 const char *sub_category = "0000";
4539 if (!g_strcmp0(type, "handset")) {
4541 sub_category = "0005";
4542 } else if (!g_strcmp0(type, "vm") || !g_strcmp0(type, "container"))
4543 sub_category = "0001";
4544 else if (!g_strcmp0(type, "server"))
4545 sub_category = "0002";
4546 else if (!g_strcmp0(type, "laptop"))
4547 sub_category = "0005";
4548 else if (!g_strcmp0(type, "desktop"))
4549 sub_category = "0006";
4550 else if (!g_strcmp0(type, "tablet"))
4551 sub_category = "0009";
4552 else if (!g_strcmp0(type, "watch"))
4555 snprintf(dev_type, 17, "%s%s%s", category, oui, sub_category);
4558 static void p2p_support(GSupplicantInterface *interface)
4560 char dev_type[17] = {};
4561 const char *hostname;
4562 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4564 * Note: If supplicant interface's driver is wired then skip it,
4565 * because it meanti only for ethernet not Wi-Fi.
4567 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4569 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4577 if (!g_supplicant_interface_has_p2p(interface))
4580 if (connman_technology_driver_register(&p2p_tech_driver) < 0) {
4581 DBG("Could not register P2P technology driver");
4585 hostname = connman_utsname_get_hostname();
4587 hostname = "ConnMan";
4589 set_device_type(connman_machine_get_type(), dev_type);
4590 g_supplicant_interface_set_p2p_device_config(interface,
4591 hostname, dev_type);
4592 connman_peer_driver_register(&peer_driver);
4595 static void scan_started(GSupplicantInterface *interface)
4597 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4599 * Note: If supplicant interface's driver is wired then skip it,
4600 * because it meanti only for ethernet not Wi-Fi.
4602 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4604 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4609 static void scan_finished(GSupplicantInterface *interface)
4611 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4613 * Note: If supplicant interface's driver is wired then skip it,
4614 * because it meanti only for ethernet not Wi-Fi.
4616 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4618 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4620 #if defined TIZEN_EXT
4621 struct wifi_data *wifi;
4622 bool is_associating = false;
4623 static bool is_scanning = true;
4628 #if defined TIZEN_EXT
4629 wifi = g_supplicant_interface_get_data(interface);
4630 if (wifi && wifi->scan_pending_network) {
4631 network_connect(wifi->scan_pending_network);
4632 wifi->scan_pending_network = NULL;
4635 //service state - associating
4636 if(!wifi || !wifi->network)
4639 is_associating = connman_network_get_associating(wifi->network);
4640 if(is_associating && is_scanning){
4641 is_scanning = false;
4642 DBG("send scan for connecting");
4643 throw_wifi_scan(wifi->device, scan_callback);
4654 static void ap_create_fail(GSupplicantInterface *interface)
4656 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4658 * Note: If supplicant interface's driver is wired then skip it,
4659 * because it meanti only for ethernet not Wi-Fi.
4661 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4663 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4665 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
4668 if ((wifi->tethering) && (wifi->tethering_param)) {
4669 DBG("%s create AP fail \n",
4670 g_supplicant_interface_get_ifname(wifi->interface));
4672 connman_inet_remove_from_bridge(wifi->index, wifi->bridge);
4673 wifi->ap_supported = WIFI_AP_NOT_SUPPORTED;
4674 wifi->tethering = false;
4676 ret = tech_set_tethering(wifi->tethering_param->technology,
4677 wifi->tethering_param->ssid->ssid,
4678 wifi->tethering_param->ssid->passphrase,
4679 wifi->bridge, true);
4681 if ((ret == -EOPNOTSUPP) && (wifi_technology)) {
4682 connman_technology_tethering_notify(wifi_technology,false);
4685 g_free(wifi->tethering_param->ssid);
4686 g_free(wifi->tethering_param);
4687 wifi->tethering_param = NULL;
4691 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
4693 unsigned char strength;
4695 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
4696 #if !defined TIZEN_EXT
4704 #if defined TIZEN_EXT_WIFI_MESH
4705 static void mesh_peer_added(GSupplicantNetwork *supplicant_network)
4707 GSupplicantInterface *interface;
4708 struct wifi_data *wifi;
4709 const char *name, *security;
4710 struct connman_mesh *connman_mesh;
4711 struct wifi_mesh_info *mesh_info;
4712 const unsigned char *bssid;
4713 const char *identifier;
4718 interface = g_supplicant_network_get_interface(supplicant_network);
4719 wifi = g_supplicant_interface_get_data(interface);
4720 if (!wifi || !wifi->mesh_interface) {
4721 DBG("Virtual Mesh interface not created");
4725 bssid = g_supplicant_network_get_bssid(supplicant_network);
4726 address = g_malloc0(19);
4727 snprintf(address, 19, "%02x:%02x:%02x:%02x:%02x:%02x", bssid[0], bssid[1],
4728 bssid[2], bssid[3], bssid[4], bssid[5]);
4730 identifier = g_supplicant_network_get_identifier(supplicant_network);
4731 name = g_supplicant_network_get_name(supplicant_network);
4732 security = g_supplicant_network_get_security(supplicant_network);
4733 frequency = g_supplicant_network_get_frequency(supplicant_network);
4735 mesh_info = wifi->mesh_info;
4736 connman_mesh = connman_mesh_get(mesh_info->identifier, identifier);
4740 DBG("Mesh Peer name %s identifier %s security %s added", name, identifier,
4742 connman_mesh = connman_mesh_create(mesh_info->identifier, identifier);
4743 connman_mesh_set_name(connman_mesh, name);
4744 connman_mesh_set_security(connman_mesh, security);
4745 connman_mesh_set_frequency(connman_mesh, frequency);
4746 connman_mesh_set_address(connman_mesh, address);
4747 connman_mesh_set_index(connman_mesh, mesh_info->index);
4748 connman_mesh_set_strength(connman_mesh,
4749 calculate_strength(supplicant_network));
4750 connman_mesh_set_peer_type(connman_mesh, CONNMAN_MESH_PEER_TYPE_DISCOVERED);
4752 ret = connman_mesh_register(connman_mesh);
4753 if (ret == -EALREADY)
4754 DBG("Mesh Peer is already registered");
4760 static void mesh_peer_removed(GSupplicantNetwork *supplicant_network)
4762 GSupplicantInterface *interface;
4763 struct wifi_data *wifi;
4764 struct connman_mesh *connman_mesh;
4765 struct wifi_mesh_info *mesh_info;
4766 const char *identifier;
4768 interface = g_supplicant_network_get_interface(supplicant_network);
4769 wifi = g_supplicant_interface_get_data(interface);
4770 if (!wifi || !wifi->mesh_interface) {
4771 DBG("Virtual Mesh interface not created");
4775 identifier = g_supplicant_network_get_identifier(supplicant_network);
4777 DBG("Failed to get Mesh Peer identifier");
4781 mesh_info = wifi->mesh_info;
4782 connman_mesh = connman_mesh_get(mesh_info->identifier, identifier);
4784 /* Do not unregister connected mesh peer */
4785 if (connman_mesh_peer_is_connected_state(connman_mesh)) {
4786 DBG("Mesh Peer %s is connected", identifier);
4789 DBG("Mesh Peer identifier %s removed", identifier);
4790 connman_mesh_unregister(connman_mesh);
4795 static void network_added(GSupplicantNetwork *supplicant_network)
4797 struct connman_network *network;
4798 GSupplicantInterface *interface;
4799 struct wifi_data *wifi;
4800 const char *name, *identifier, *security, *group, *mode;
4801 const unsigned char *ssid;
4802 unsigned int ssid_len;
4806 bool wps_advertizing;
4808 #if defined TIZEN_EXT
4809 bool owe_transition_mode;
4810 const unsigned char *transition_mode_ssid;
4811 const unsigned char *transition_mode_bssid;
4812 unsigned int transition_mode_ssid_len;
4813 GSList *vsie_list = NULL;
4814 const unsigned char *country_code;
4815 ieee80211_modes_e phy_mode;
4818 mode = g_supplicant_network_get_mode(supplicant_network);
4819 identifier = g_supplicant_network_get_identifier(supplicant_network);
4821 DBG("%s", identifier);
4823 if (!g_strcmp0(mode, "adhoc"))
4826 #if defined TIZEN_EXT_WIFI_MESH
4827 if (!g_strcmp0(mode, "mesh")) {
4828 mesh_peer_added(supplicant_network);
4833 interface = g_supplicant_network_get_interface(supplicant_network);
4834 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4836 * Note: If supplicant interface's driver is wired then skip it,
4837 * because it meanti only for ethernet not Wi-Fi.
4839 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4841 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4843 wifi = g_supplicant_interface_get_data(interface);
4844 name = g_supplicant_network_get_name(supplicant_network);
4845 security = g_supplicant_network_get_security(supplicant_network);
4846 group = g_supplicant_network_get_identifier(supplicant_network);
4847 wps = g_supplicant_network_get_wps(supplicant_network);
4848 wps_pbc = g_supplicant_network_is_wps_pbc(supplicant_network);
4849 wps_ready = g_supplicant_network_is_wps_active(supplicant_network);
4850 wps_advertizing = g_supplicant_network_is_wps_advertizing(
4851 supplicant_network);
4856 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
4858 network = connman_device_get_network(wifi->device, identifier);
4861 network = connman_network_create(identifier,
4862 CONNMAN_NETWORK_TYPE_WIFI);
4866 connman_network_set_index(network, wifi->index);
4868 if (connman_device_add_network(wifi->device, network) < 0) {
4869 connman_network_unref(network);
4873 wifi->networks = g_slist_prepend(wifi->networks, network);
4876 if (name && name[0] != '\0')
4877 connman_network_set_name(network, name);
4879 connman_network_set_blob(network, "WiFi.SSID",
4881 #if defined TIZEN_EXT
4882 vsie_list = (GSList *)g_supplicant_network_get_wifi_vsie(supplicant_network);
4884 connman_network_set_vsie_list(network, vsie_list);
4886 DBG("vsie_list is NULL");
4887 country_code = g_supplicant_network_get_countrycode(supplicant_network);
4888 connman_network_set_countrycode(network, country_code);
4889 phy_mode = g_supplicant_network_get_phy_mode(supplicant_network);
4890 connman_network_set_phy_mode(network, phy_mode);
4892 connman_network_set_string(network, "WiFi.Security", security);
4893 connman_network_set_strength(network,
4894 calculate_strength(supplicant_network));
4895 connman_network_set_bool(network, "WiFi.WPS", wps);
4896 connman_network_set_bool(network, "WiFi.WPSAdvertising",
4900 /* Is AP advertizing for WPS association?
4901 * If so, we decide to use WPS by default */
4902 if (wps_ready && wps_pbc &&
4904 #if !defined TIZEN_EXT
4905 connman_network_set_bool(network, "WiFi.UseWPS", true);
4907 DBG("wps is activating by ap but ignore it.");
4911 connman_network_set_frequency(network,
4912 g_supplicant_network_get_frequency(supplicant_network));
4914 #if defined TIZEN_EXT
4915 connman_network_set_bssid(network,
4916 g_supplicant_network_get_bssid(supplicant_network));
4917 owe_transition_mode = (bool)g_supplicant_network_get_transition_mode(supplicant_network);
4918 connman_network_set_bool(network, "WiFi.TRANSITION_MODE", owe_transition_mode);
4919 if (owe_transition_mode) {
4920 transition_mode_ssid = (unsigned char *)g_supplicant_network_get_transition_mode_ssid(supplicant_network, &transition_mode_ssid_len);
4921 connman_network_set_blob(network, "WiFi.TRANSITION_MODE_SSID",
4922 transition_mode_ssid, transition_mode_ssid_len);
4923 transition_mode_bssid = g_supplicant_network_get_transition_mode_bssid(supplicant_network);
4924 connman_network_set_transition_mode_bssid(network, transition_mode_bssid);
4926 connman_network_set_maxrate(network,
4927 g_supplicant_network_get_maxrate(supplicant_network));
4928 connman_network_set_enc_mode(network,
4929 g_supplicant_network_get_enc_mode(supplicant_network));
4930 connman_network_set_rsn_mode(network,
4931 g_supplicant_network_get_rsn_mode(supplicant_network));
4932 connman_network_set_keymgmt(network,
4933 g_supplicant_network_get_keymgmt(supplicant_network));
4934 connman_network_set_bool(network, "WiFi.HS20AP",
4935 g_supplicant_network_is_hs20AP(supplicant_network));
4936 connman_network_set_bssid_list(network,
4937 (GSList *)g_supplicant_network_get_bssid_list(supplicant_network));
4938 connman_network_set_last_connected_bssid(network,
4939 g_supplicant_network_get_last_connected_bssid(supplicant_network));
4940 connman_network_set_assoc_reject_table(network,
4941 g_supplicant_network_get_assoc_reject_table(supplicant_network));
4943 connman_network_set_available(network, true);
4944 connman_network_set_string(network, "WiFi.Mode", mode);
4946 #if defined TIZEN_EXT
4951 connman_network_set_group(network, group);
4953 #if defined TIZEN_EXT
4954 g_supplicant_network_set_last_connected_bssid(supplicant_network,
4955 connman_network_get_last_connected_bssid(network));
4958 #if defined TIZEN_EXT
4959 if (wifi_first_scan == true)
4960 found_with_first_scan = true;
4963 if (wifi->hidden && ssid) {
4964 #if defined TIZEN_EXT
4965 if (network_security(wifi->hidden->security) ==
4966 network_security(security) &&
4968 if (!g_strcmp0(wifi->hidden->security, security) &&
4970 wifi->hidden->ssid_len == ssid_len &&
4971 !memcmp(wifi->hidden->ssid, ssid, ssid_len)) {
4972 connman_network_connect_hidden(network,
4973 wifi->hidden->identity,
4974 wifi->hidden->passphrase,
4975 wifi->hidden->user_data);
4976 wifi->hidden->user_data = NULL;
4977 hidden_free(wifi->hidden);
4978 wifi->hidden = NULL;
4983 static void network_removed(GSupplicantNetwork *network)
4985 GSupplicantInterface *interface;
4986 struct wifi_data *wifi;
4987 const char *name, *identifier;
4988 struct connman_network *connman_network;
4990 #if defined TIZEN_EXT_WIFI_MESH
4992 mode = g_supplicant_network_get_mode(network);
4993 if (!g_strcmp0(mode, "mesh")) {
4994 mesh_peer_removed(network);
4999 interface = g_supplicant_network_get_interface(network);
5000 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5002 * Note: If supplicant interface's driver is wired then skip it,
5003 * because it meanti only for ethernet not Wi-Fi.
5005 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5007 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5009 wifi = g_supplicant_interface_get_data(interface);
5010 identifier = g_supplicant_network_get_identifier(network);
5011 name = g_supplicant_network_get_name(network);
5013 DBG("name %s", name);
5018 connman_network = connman_device_get_network(wifi->device, identifier);
5019 if (!connman_network)
5022 #if defined TIZEN_EXT
5023 if (connman_network == wifi->scan_pending_network)
5024 wifi->scan_pending_network = NULL;
5026 if (connman_network == wifi->pending_network)
5027 wifi->pending_network = NULL;
5029 if(connman_network_get_connecting(connman_network) == true){
5030 connman_network_set_connected(connman_network, false);
5034 wifi->networks = g_slist_remove(wifi->networks, connman_network);
5036 connman_device_remove_network(wifi->device, connman_network);
5037 connman_network_unref(connman_network);
5040 static void network_changed(GSupplicantNetwork *network, const char *property)
5042 GSupplicantInterface *interface;
5043 struct wifi_data *wifi;
5044 const char *name, *identifier;
5045 struct connman_network *connman_network;
5048 #if defined TIZEN_EXT
5049 const unsigned char *bssid;
5050 unsigned int maxrate;
5053 const unsigned char *country_code;
5054 ieee80211_modes_e phy_mode;
5058 interface = g_supplicant_network_get_interface(network);
5059 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5061 * Note: If supplicant interface's driver is wired then skip it,
5062 * because it meanti only for ethernet not Wi-Fi.
5064 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5066 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5068 wifi = g_supplicant_interface_get_data(interface);
5069 identifier = g_supplicant_network_get_identifier(network);
5070 name = g_supplicant_network_get_name(network);
5072 #if defined TIZEN_EXT
5073 DBG("name %s property %s", name, property);
5075 DBG("name %s", name);
5081 connman_network = connman_device_get_network(wifi->device, identifier);
5082 if (!connman_network)
5085 if (g_str_equal(property, "WPSCapabilities")) {
5089 bool wps_advertizing;
5091 wps = g_supplicant_network_get_wps(network);
5092 wps_pbc = g_supplicant_network_is_wps_pbc(network);
5093 wps_ready = g_supplicant_network_is_wps_active(network);
5095 g_supplicant_network_is_wps_advertizing(network);
5097 connman_network_set_bool(connman_network, "WiFi.WPS", wps);
5098 connman_network_set_bool(connman_network,
5099 "WiFi.WPSAdvertising", wps_advertizing);
5103 * Is AP advertizing for WPS association?
5104 * If so, we decide to use WPS by default
5106 if (wps_ready && wps_pbc && wps_advertizing)
5107 connman_network_set_bool(connman_network,
5108 "WiFi.UseWPS", true);
5111 update_needed = true;
5112 } else if (g_str_equal(property, "Signal")) {
5113 connman_network_set_strength(connman_network,
5114 calculate_strength(network));
5115 update_needed = true;
5117 #if defined TIZEN_EXT
5118 else if (g_str_equal(property, "LastConnectedBSSID")) {
5119 const char *ident, *group;
5120 char *service_ident;
5123 ident = connman_device_get_ident(wifi->device);
5124 group = connman_network_get_group(connman_network);
5125 if (ident && group) {
5126 service_ident = g_strdup_printf("%s_%s_%s",
5127 __connman_network_get_type(connman_network), ident, group);
5129 need_save = connman_device_set_last_connected_ident(wifi->device, service_ident);
5131 connman_device_save_last_connected(wifi->device);
5134 connman_network_set_last_connected_bssid(connman_network,
5135 g_supplicant_network_get_last_connected_bssid(network));
5137 update_needed = true;
5138 } else if (g_str_equal(property, "UpdateAssocReject")) {
5139 connman_network_set_assoc_reject_table(connman_network,
5140 g_supplicant_network_get_assoc_reject_table(network));
5141 update_needed = true;
5145 update_needed = false;
5148 connman_network_update(connman_network);
5150 #if defined TIZEN_EXT
5151 bssid = g_supplicant_network_get_bssid(network);
5152 maxrate = g_supplicant_network_get_maxrate(network);
5153 frequency = g_supplicant_network_get_frequency(network);
5154 wps = g_supplicant_network_get_wps(network);
5155 phy_mode = g_supplicant_network_get_phy_mode(network);
5157 connman_network_set_bssid(connman_network, bssid);
5158 connman_network_set_maxrate(connman_network, maxrate);
5159 connman_network_set_frequency(connman_network, frequency);
5160 connman_network_set_bool(connman_network, "WiFi.WPS", wps);
5161 country_code = g_supplicant_network_get_countrycode(network);
5162 connman_network_set_countrycode(connman_network, country_code);
5163 bssid_list = (GSList *)g_supplicant_network_get_bssid_list(network);
5164 connman_network_set_bssid_list(connman_network, bssid_list);
5165 connman_network_set_phy_mode(connman_network, phy_mode);
5167 if (g_str_equal(property, "CheckMultiBssidConnect") &&
5168 connman_network_get_associating(connman_network))
5169 network_connect(connman_network);
5173 static void network_associated(GSupplicantNetwork *network)
5175 GSupplicantInterface *interface;
5176 struct wifi_data *wifi;
5177 struct connman_network *connman_network;
5178 const char *identifier;
5182 interface = g_supplicant_network_get_interface(network);
5185 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5187 * Note: If supplicant interface's driver is wired then skip it,
5188 * because it meanti only for ethernet not Wi-Fi.
5190 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5192 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5195 wifi = g_supplicant_interface_get_data(interface);
5199 /* P2P networks must not be treated as WiFi networks */
5200 if (wifi->p2p_connecting || wifi->p2p_device)
5203 identifier = g_supplicant_network_get_identifier(network);
5205 connman_network = connman_device_get_network(wifi->device, identifier);
5206 if (!connman_network)
5209 if (wifi->network) {
5210 if (wifi->network == connman_network)
5213 unsigned int ssid_len;
5214 DBG("network1 ssid[%s] , OWE[%d],ssid[%s]",
5215 (char *)connman_network_get_blob(wifi->network,"WiFi.SSID", &ssid_len),
5216 connman_network_get_bool(wifi->network,"WiFi.TRANSITION_MODE"),
5217 (char *)connman_network_get_blob(wifi->network,"WiFi.TRANSITION_MODE_SSID", &ssid_len));
5219 DBG("network1 ssid[%s], OWE[%d], ssid[%s]",
5220 (char *)connman_network_get_blob(connman_network,"WiFi.SSID",&ssid_len),
5221 connman_network_get_bool(connman_network,"WiFi.TRANSITION_MODE"),
5222 (char *)connman_network_get_blob(connman_network,"WiFi.TRANSITION_MODE_SSID", &ssid_len));
5223 if (connman_network_check_transition_mode(wifi->network, connman_network)) {//OWE trasition mode check
5224 DBG("OWE transition mode is TRUE");
5229 * This should never happen, we got associated with
5230 * a network different than the one we were expecting.
5232 DBG("Associated to %p while expecting %p",
5233 connman_network, wifi->network);
5235 connman_network_set_associating(wifi->network, false);
5238 DBG("Reconnecting to previous network %p from wpa_s", connman_network);
5240 wifi->network = connman_network_ref(connman_network);
5244 * Interface state changes callback (interface_state) is always
5245 * called before network_associated callback thus we need to call
5246 * interface_state again in order to process the new state now that
5247 * we have the network properly set.
5249 interface_state(interface);
5252 static void sta_authorized(GSupplicantInterface *interface,
5255 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5257 * Note: If supplicant interface's driver is wired then skip it,
5258 * because it meanti only for ethernet not Wi-Fi.
5260 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5262 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5264 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5266 DBG("wifi %p station %s authorized", wifi, addr);
5268 if (!wifi || !wifi->tethering)
5271 __connman_tethering_client_register(addr);
5274 static void sta_deauthorized(GSupplicantInterface *interface,
5277 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5279 * Note: If supplicant interface's driver is wired then skip it,
5280 * because it meanti only for ethernet not Wi-Fi.
5282 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5284 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5286 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5288 DBG("wifi %p station %s deauthorized", wifi, addr);
5290 if (!wifi || !wifi->tethering)
5293 __connman_tethering_client_unregister(addr);
5296 static void apply_peer_services(GSupplicantPeer *peer,
5297 struct connman_peer *connman_peer)
5299 const unsigned char *data;
5304 connman_peer_reset_services(connman_peer);
5306 data = g_supplicant_peer_get_widi_ies(peer, &length);
5308 connman_peer_add_service(connman_peer,
5309 CONNMAN_PEER_SERVICE_WIFI_DISPLAY, data, length);
5313 static void peer_found(GSupplicantPeer *peer)
5315 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5316 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5317 struct connman_peer *connman_peer;
5318 const char *identifier, *name;
5321 #if defined TIZEN_EXT
5325 identifier = g_supplicant_peer_get_identifier(peer);
5326 name = g_supplicant_peer_get_name(peer);
5328 DBG("ident: %s", identifier);
5330 connman_peer = connman_peer_get(wifi->device, identifier);
5334 connman_peer = connman_peer_create(identifier);
5335 connman_peer_set_name(connman_peer, name);
5336 connman_peer_set_device(connman_peer, wifi->device);
5337 apply_peer_services(peer, connman_peer);
5339 ret = connman_peer_register(connman_peer);
5340 if (ret < 0 && ret != -EALREADY)
5341 connman_peer_unref(connman_peer);
5343 wifi->peers = g_slist_prepend(wifi->peers, connman_peer);
5346 static void peer_lost(GSupplicantPeer *peer)
5348 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5349 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5350 struct connman_peer *connman_peer;
5351 const char *identifier;
5356 identifier = g_supplicant_peer_get_identifier(peer);
5358 DBG("ident: %s", identifier);
5360 connman_peer = connman_peer_get(wifi->device, identifier);
5362 if (wifi->p2p_connecting &&
5363 wifi->pending_peer == connman_peer) {
5364 peer_connect_timeout(wifi);
5366 connman_peer_unregister(connman_peer);
5367 connman_peer_unref(connman_peer);
5370 wifi->peers = g_slist_remove(wifi->peers, connman_peer);
5373 static void peer_changed(GSupplicantPeer *peer, GSupplicantPeerState state)
5375 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5376 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5377 enum connman_peer_state p_state = CONNMAN_PEER_STATE_UNKNOWN;
5378 struct connman_peer *connman_peer;
5379 const char *identifier;
5381 identifier = g_supplicant_peer_get_identifier(peer);
5383 DBG("ident: %s", identifier);
5388 connman_peer = connman_peer_get(wifi->device, identifier);
5393 case G_SUPPLICANT_PEER_SERVICES_CHANGED:
5394 apply_peer_services(peer, connman_peer);
5395 connman_peer_services_changed(connman_peer);
5397 case G_SUPPLICANT_PEER_GROUP_CHANGED:
5398 if (!g_supplicant_peer_is_in_a_group(peer))
5399 p_state = CONNMAN_PEER_STATE_IDLE;
5401 p_state = CONNMAN_PEER_STATE_CONFIGURATION;
5403 case G_SUPPLICANT_PEER_GROUP_STARTED:
5405 case G_SUPPLICANT_PEER_GROUP_FINISHED:
5406 p_state = CONNMAN_PEER_STATE_IDLE;
5408 case G_SUPPLICANT_PEER_GROUP_JOINED:
5409 connman_peer_set_iface_address(connman_peer,
5410 g_supplicant_peer_get_iface_address(peer));
5412 case G_SUPPLICANT_PEER_GROUP_DISCONNECTED:
5413 p_state = CONNMAN_PEER_STATE_IDLE;
5415 case G_SUPPLICANT_PEER_GROUP_FAILED:
5416 if (g_supplicant_peer_has_requested_connection(peer))
5417 p_state = CONNMAN_PEER_STATE_IDLE;
5419 p_state = CONNMAN_PEER_STATE_FAILURE;
5423 if (p_state == CONNMAN_PEER_STATE_CONFIGURATION ||
5424 p_state == CONNMAN_PEER_STATE_FAILURE) {
5425 if (wifi->p2p_connecting
5426 && connman_peer == wifi->pending_peer)
5427 peer_cancel_timeout(wifi);
5429 p_state = CONNMAN_PEER_STATE_UNKNOWN;
5432 if (p_state == CONNMAN_PEER_STATE_UNKNOWN)
5435 if (p_state == CONNMAN_PEER_STATE_CONFIGURATION) {
5436 GSupplicantInterface *g_iface;
5437 struct wifi_data *g_wifi;
5439 g_iface = g_supplicant_peer_get_group_interface(peer);
5443 g_wifi = g_supplicant_interface_get_data(g_iface);
5447 connman_peer_set_as_master(connman_peer,
5448 !g_supplicant_peer_is_client(peer));
5449 connman_peer_set_sub_device(connman_peer, g_wifi->device);
5452 * If wpa_supplicant didn't create a dedicated p2p-group
5453 * interface then mark this interface as p2p_device to avoid
5454 * scan and auto-scan are launched on it while P2P is connected.
5456 if (!g_list_find(p2p_iface_list, g_wifi))
5457 wifi->p2p_device = true;
5460 connman_peer_set_state(connman_peer, p_state);
5463 static void peer_request(GSupplicantPeer *peer)
5465 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5466 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5467 struct connman_peer *connman_peer;
5468 const char *identifier;
5470 #if defined TIZEN_EXT
5475 identifier = g_supplicant_peer_get_identifier(peer);
5477 DBG("ident: %s", identifier);
5479 connman_peer = connman_peer_get(wifi->device, identifier);
5483 connman_peer_request_connection(connman_peer);
5486 #if defined TIZEN_EXT
5487 static void system_power_off(void)
5490 struct wifi_data *wifi;
5491 struct connman_service *service;
5492 struct connman_ipconfig *ipconfig_ipv4;
5494 if (connman_setting_get_bool("WiFiDHCPRelease") == true) {
5495 for (list = iface_list; list; list = list->next) {
5498 if (wifi->network != NULL) {
5499 service = connman_service_lookup_from_network(wifi->network);
5500 ipconfig_ipv4 = __connman_service_get_ip4config(service);
5501 __connman_dhcp_stop(ipconfig_ipv4);
5507 static void network_merged(GSupplicantNetwork *network)
5509 GSupplicantInterface *interface;
5510 GSupplicantState state;
5511 struct wifi_data *wifi;
5512 const char *identifier;
5513 struct connman_network *connman_network;
5517 interface = g_supplicant_network_get_interface(network);
5521 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5523 * Note: If supplicant interface's driver is wired then skip it,
5524 * because it meanti only for ethernet not Wi-Fi.
5526 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5528 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5530 state = g_supplicant_interface_get_state(interface);
5531 if (state < G_SUPPLICANT_STATE_AUTHENTICATING)
5534 wifi = g_supplicant_interface_get_data(interface);
5538 identifier = g_supplicant_network_get_identifier(network);
5540 connman_network = connman_device_get_network(wifi->device, identifier);
5541 if (!connman_network)
5544 DBG("merged identifier %s", identifier);
5546 if (wifi->connected == FALSE) {
5548 case G_SUPPLICANT_STATE_AUTHENTICATING:
5549 case G_SUPPLICANT_STATE_ASSOCIATING:
5550 case G_SUPPLICANT_STATE_ASSOCIATED:
5551 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
5552 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
5553 connman_network_set_associating(connman_network, TRUE);
5555 case G_SUPPLICANT_STATE_COMPLETED:
5556 connman_network_set_connected(connman_network, TRUE);
5559 DBG("Not handled the state : %d", state);
5564 ishs20AP = g_supplicant_network_is_hs20AP(network);
5567 g_strcmp0(g_supplicant_network_get_security(network), "ieee8021x") == 0) {
5568 temp = g_ascii_strdown(g_supplicant_network_get_eap(network), -1);
5569 connman_network_set_string(connman_network, "WiFi.EAP",
5571 connman_network_set_string(connman_network, "WiFi.Identity",
5572 g_supplicant_network_get_identity(network));
5573 connman_network_set_string(connman_network, "WiFi.Phase2",
5574 g_supplicant_network_get_phase2(network));
5579 wifi->network = connman_network;
5582 static void assoc_failed(void *user_data)
5584 struct connman_network *network = user_data;
5585 connman_network_set_associating(network, false);
5588 static void scan_done(GSupplicantInterface *interface)
5590 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5592 * Note: If supplicant interface's driver is wired then skip it,
5593 * because it meanti only for ethernet not Wi-Fi.
5595 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5597 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5600 int scan_type = CONNMAN_SCAN_TYPE_WPA_SUPPLICANT;
5601 struct wifi_data *wifi;
5604 for (list = iface_list; list; list = list->next) {
5607 if (interface == wifi->interface) {
5608 scanning = connman_device_get_scanning(wifi->device,
5609 CONNMAN_SERVICE_TYPE_WIFI);
5611 __connman_technology_notify_scan_done(
5612 connman_device_get_string(wifi->device, "Interface"), scan_type);
5619 static void debug(const char *str)
5621 #if defined TIZEN_EXT
5622 if (connman_setting_get_bool("ConnmanSupplicantDebug"))
5624 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
5626 connman_debug("%s", str);
5629 static void disconnect_reasoncode(GSupplicantInterface *interface,
5632 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5634 * Note: If supplicant interface's driver is wired then skip it,
5635 * because it meanti only for ethernet not Wi-Fi.
5637 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5639 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5641 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5644 wifi->disconnect_code = reasoncode;
5648 static void assoc_status_code(GSupplicantInterface *interface, int status_code)
5650 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5652 * Note: If supplicant interface's driver is wired then skip it,
5653 * because it meanti only for ethernet not Wi-Fi.
5655 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5657 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5659 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5662 wifi->assoc_code = status_code;
5666 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5667 static GSupplicantCallbacks callbacks = {
5668 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5669 static const GSupplicantCallbacks callbacks = {
5670 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5671 .system_ready = system_ready,
5672 .system_killed = system_killed,
5673 .interface_added = interface_added,
5674 .interface_state = interface_state,
5675 .interface_removed = interface_removed,
5676 .p2p_support = p2p_support,
5677 .scan_started = scan_started,
5678 .scan_finished = scan_finished,
5679 .ap_create_fail = ap_create_fail,
5680 .network_added = network_added,
5681 .network_removed = network_removed,
5682 .network_changed = network_changed,
5683 .network_associated = network_associated,
5684 .sta_authorized = sta_authorized,
5685 .sta_deauthorized = sta_deauthorized,
5686 .peer_found = peer_found,
5687 .peer_lost = peer_lost,
5688 .peer_changed = peer_changed,
5689 .peer_request = peer_request,
5690 #if defined TIZEN_EXT
5691 .system_power_off = system_power_off,
5692 .network_merged = network_merged,
5693 .assoc_failed = assoc_failed,
5694 .scan_done = scan_done,
5697 .disconnect_reasoncode = disconnect_reasoncode,
5698 .assoc_status_code = assoc_status_code,
5699 #if defined TIZEN_EXT_WIFI_MESH
5700 .mesh_support = mesh_support,
5701 .mesh_group_started = mesh_group_started,
5702 .mesh_group_removed = mesh_group_removed,
5703 .mesh_peer_connected = mesh_peer_connected,
5704 .mesh_peer_disconnected = mesh_peer_disconnected,
5709 static int tech_probe(struct connman_technology *technology)
5711 wifi_technology = technology;
5716 static void tech_remove(struct connman_technology *technology)
5718 wifi_technology = NULL;
5721 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
5723 GSupplicantSSID *ap;
5725 ap = g_try_malloc0(sizeof(GSupplicantSSID));
5729 ap->mode = G_SUPPLICANT_MODE_MASTER;
5730 #if defined TIZEN_EXT
5731 ap->ssid = (void *) ssid;
5735 ap->ssid_len = strlen(ssid);
5739 if (!passphrase || strlen(passphrase) == 0) {
5740 ap->security = G_SUPPLICANT_SECURITY_NONE;
5741 ap->passphrase = NULL;
5743 ap->security = G_SUPPLICANT_SECURITY_PSK;
5744 ap->protocol = G_SUPPLICANT_PROTO_RSN;
5745 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
5746 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
5747 ap->passphrase = passphrase;
5753 static void ap_start_callback(int result, GSupplicantInterface *interface,
5756 struct wifi_tethering_info *info = user_data;
5758 DBG("result %d index %d bridge %s",
5759 result, info->wifi->index, info->wifi->bridge);
5761 if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
5762 connman_inet_remove_from_bridge(info->wifi->index,
5763 info->wifi->bridge);
5765 if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
5766 connman_technology_tethering_notify(info->technology, false);
5767 g_free(info->wifi->tethering_param->ssid);
5768 g_free(info->wifi->tethering_param);
5769 info->wifi->tethering_param = NULL;
5773 g_free(info->ifname);
5777 static void ap_create_callback(int result,
5778 GSupplicantInterface *interface,
5781 struct wifi_tethering_info *info = user_data;
5783 DBG("result %d ifname %s", result,
5784 g_supplicant_interface_get_ifname(interface));
5786 if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
5787 connman_inet_remove_from_bridge(info->wifi->index,
5788 info->wifi->bridge);
5790 if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
5791 connman_technology_tethering_notify(info->technology, false);
5792 g_free(info->wifi->tethering_param->ssid);
5793 g_free(info->wifi->tethering_param);
5794 info->wifi->tethering_param = NULL;
5798 g_free(info->ifname);
5804 info->wifi->interface = interface;
5805 g_supplicant_interface_set_data(interface, info->wifi);
5807 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
5808 connman_error("Failed to set interface ap_scan property");
5810 g_supplicant_interface_connect(interface, info->ssid,
5811 ap_start_callback, info);
5814 static void sta_remove_callback(int result,
5815 GSupplicantInterface *interface,
5818 struct wifi_tethering_info *info = user_data;
5819 const char *driver = connman_option_get_string("wifi");
5821 DBG("ifname %s result %d ", info->ifname, result);
5823 if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
5824 info->wifi->tethering = false;
5825 connman_technology_tethering_notify(info->technology, false);
5827 if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
5828 g_free(info->wifi->tethering_param->ssid);
5829 g_free(info->wifi->tethering_param);
5830 info->wifi->tethering_param = NULL;
5833 g_free(info->ifname);
5839 info->wifi->interface = NULL;
5841 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
5846 static int enable_wifi_tethering(struct connman_technology *technology,
5847 const char *bridge, const char *identifier,
5848 const char *passphrase, bool available)
5851 GSupplicantInterface *interface;
5852 struct wifi_data *wifi;
5853 struct wifi_tethering_info *info;
5858 for (list = iface_list; list; list = list->next) {
5861 DBG("wifi %p network %p pending_network %p", wifi,
5862 wifi->network, wifi->pending_network);
5864 interface = wifi->interface;
5869 ifname = g_supplicant_interface_get_ifname(wifi->interface);
5873 if (wifi->ap_supported == WIFI_AP_NOT_SUPPORTED) {
5874 DBG("%s does not support AP mode (detected)", ifname);
5878 mode = g_supplicant_interface_get_mode(interface);
5879 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
5880 wifi->ap_supported = WIFI_AP_NOT_SUPPORTED;
5881 DBG("%s does not support AP mode (capability)", ifname);
5885 if (wifi->network && available)
5888 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
5892 wifi->tethering_param = g_try_malloc0(sizeof(struct wifi_tethering_info));
5893 if (!wifi->tethering_param) {
5899 info->technology = technology;
5900 info->wifi->bridge = bridge;
5901 info->ssid = ssid_ap_init(identifier, passphrase);
5905 info->ifname = g_strdup(ifname);
5907 wifi->tethering_param->technology = technology;
5908 wifi->tethering_param->ssid = ssid_ap_init(identifier, passphrase);
5909 if (!wifi->tethering_param->ssid)
5912 info->wifi->tethering = true;
5913 info->wifi->ap_supported = WIFI_AP_SUPPORTED;
5915 berr = connman_technology_tethering_notify(technology, true);
5919 err = g_supplicant_interface_remove(interface,
5920 sta_remove_callback,
5923 DBG("tethering wifi %p ifname %s", wifi, ifname);
5928 g_free(info->ifname);
5931 g_free(wifi->tethering_param);
5932 wifi->tethering_param = NULL;
5935 * Remove bridge if it was correctly created but remove
5936 * operation failed. Instead, if bridge creation failed then
5937 * break out and do not try again on another interface,
5938 * bridge set-up does not depend on it.
5941 connman_technology_tethering_notify(technology, false);
5949 static int tech_set_tethering(struct connman_technology *technology,
5950 const char *identifier, const char *passphrase,
5951 const char *bridge, bool enabled)
5954 struct wifi_data *wifi;
5960 for (list = iface_list; list; list = list->next) {
5963 if (wifi->tethering) {
5964 wifi->tethering = false;
5966 connman_inet_remove_from_bridge(wifi->index,
5968 wifi->bridged = false;
5972 connman_technology_tethering_notify(technology, false);
5977 DBG("trying tethering for available devices");
5978 err = enable_wifi_tethering(technology, bridge, identifier, passphrase,
5982 DBG("trying tethering for any device");
5983 err = enable_wifi_tethering(technology, bridge, identifier,
5990 static void regdom_callback(int result, const char *alpha2, void *user_data)
5994 if (!wifi_technology)
6000 connman_technology_regdom_notify(wifi_technology, alpha2);
6003 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
6005 return g_supplicant_set_country(alpha2, regdom_callback, NULL);
6008 #if defined TIZEN_EXT
6009 static void supp_ins_init(void)
6012 GSupplicantINSPreferredFreq preferred_freq;
6014 string = connman_option_get_string("INSPreferredFreqBSSID");
6015 if (g_strcmp0(string, "5GHz") == 0)
6016 preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_5GHZ;
6017 else if (g_strcmp0(string, "2.4GHz") == 0)
6018 preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_24GHZ;
6020 preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_UNKNOWN;
6022 g_supplicant_set_ins_settings(preferred_freq,
6023 connman_setting_get_bool("INSLastConnectedBSSID"),
6024 connman_setting_get_bool("INSAssocReject"),
6025 connman_setting_get_bool("INSSignalBSSID"),
6026 connman_setting_get_uint("INSPreferredFreqBSSIDScore"),
6027 connman_setting_get_uint("INSLastConnectedBSSIDScore"),
6028 connman_setting_get_uint("INSAssocRejectScore"),
6029 connman_setting_get_int("INSSignalLevel3_5GHz"),
6030 connman_setting_get_int("INSSignalLevel3_24GHz")
6035 static struct connman_technology_driver tech_driver = {
6037 .type = CONNMAN_SERVICE_TYPE_WIFI,
6038 .probe = tech_probe,
6039 .remove = tech_remove,
6040 .set_tethering = tech_set_tethering,
6041 .set_regdom = tech_set_regdom,
6044 static int wifi_init(void)
6048 err = connman_network_driver_register(&network_driver);
6052 err = g_supplicant_register(&callbacks);
6054 connman_network_driver_unregister(&network_driver);
6058 err = connman_technology_driver_register(&tech_driver);
6060 g_supplicant_unregister(&callbacks);
6061 connman_network_driver_unregister(&network_driver);
6065 #if defined TIZEN_EXT
6066 failed_bssids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
6069 #if defined TIZEN_EXT
6075 static void wifi_exit(void)
6079 connman_technology_driver_unregister(&tech_driver);
6081 g_supplicant_unregister(&callbacks);
6083 connman_network_driver_unregister(&network_driver);
6085 #if defined TIZEN_EXT
6086 g_hash_table_unref(failed_bssids);
6090 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
6091 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)