5 * Copyright (C) 2007-2014 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <sys/ioctl.h>
32 #include <sys/socket.h>
33 #include <net/ethernet.h>
34 #include <linux/wireless.h>
37 #define IFF_LOWER_UP 0x10000
40 #include <dbus/dbus.h>
43 #define CONNMAN_API_SUBJECT_TO_CHANGE
44 #include <connman/plugin.h>
45 #include <connman/inet.h>
46 #include <connman/device.h>
47 #include <connman/rtnl.h>
48 #include <connman/technology.h>
49 #include <connman/service.h>
50 #include <connman/peer.h>
51 #include <connman/log.h>
52 #include <connman/option.h>
53 #include <connman/storage.h>
54 #include <include/setting.h>
55 #include <connman/provision.h>
56 #include <connman/utsname.h>
57 #include <connman/machine.h>
58 #include <connman/tethering.h>
60 #include <gsupplicant/gsupplicant.h>
62 #include "src/shared/util.h"
64 #define CLEANUP_TIMEOUT 8 /* in seconds */
65 #define INACTIVE_TIMEOUT 12 /* in seconds */
66 #define FAVORITE_MAXIMUM_RETRIES 2
68 #define BGSCAN_DEFAULT "simple:30:-65:300"
69 #define AUTOSCAN_EXPONENTIAL "exponential:3:300"
70 #define AUTOSCAN_SINGLE "single:3"
72 #define P2P_FIND_TIMEOUT 30
73 #define P2P_CONNECTION_TIMEOUT 100
74 #define P2P_LISTEN_PERIOD 500
75 #define P2P_LISTEN_INTERVAL 2000
77 #define ASSOC_STATUS_NO_CLIENT 17
79 #define LOAD_SHAPING_MAX_RETRIES 7
81 #define LOAD_SHAPING_MAX_RETRIES 3
85 #define WIFI_EAP_FAST_PAC_FILE "/var/lib/wifi/wifi.pac" /* path of Pac file for EAP-FAST */
88 static struct connman_technology *wifi_technology = NULL;
89 static struct connman_technology *p2p_technology = NULL;
91 enum wifi_ap_capability{
93 WIFI_AP_SUPPORTED = 1,
94 WIFI_AP_NOT_SUPPORTED = 2,
97 enum wifi_scanning_type {
98 WIFI_SCANNING_UNKNOWN = 0,
99 WIFI_SCANNING_PASSIVE = 1,
100 WIFI_SCANNING_ACTIVE = 2,
103 struct hidden_params {
105 unsigned int ssid_len;
107 char *anonymous_identity;
109 char *altsubject_match;
110 char *domain_suffix_match;
114 GSupplicantScanParams *scan_params;
119 * Used for autoscan "emulation".
120 * Should be removed when wpa_s autoscan support will be by default.
122 struct autoscan_params {
126 unsigned int timeout;
129 struct wifi_tethering_info {
130 struct wifi_data *wifi;
131 struct connman_technology *technology;
133 GSupplicantSSID *ssid;
138 struct connman_device *device;
139 struct connman_network *network;
140 struct connman_network *pending_network;
142 GSupplicantInterface *interface;
143 GSupplicantState state;
147 enum wifi_ap_capability ap_supported;
149 bool interface_ready;
155 int load_shaping_retries;
156 struct hidden_params *hidden;
157 bool postpone_hidden;
158 struct wifi_tethering_info *tethering_param;
160 * autoscan "emulation".
162 struct autoscan_params *autoscan;
163 enum wifi_scanning_type scanning_type;
164 GSupplicantScanParams *scan_params;
165 unsigned int p2p_find_timeout;
166 unsigned int p2p_connection_timeout;
167 struct connman_peer *pending_peer;
172 #if defined TIZEN_EXT
173 int assoc_retry_count;
174 struct connman_network *scan_pending_network;
175 bool allow_full_scan;
176 unsigned int automaxspeed_timeout;
177 GSupplicantScanParams *hidden_scan_params;
178 unsigned int mac_policy;
179 unsigned int preassoc_mac_policy;
180 unsigned int mac_lifetime;
184 #if defined TIZEN_EXT_WIFI_MESH
186 struct wifi_mesh_info *mesh_info;
190 #if defined TIZEN_EXT
194 #define TIZEN_ASSOC_RETRY_COUNT 4
196 static gboolean wifi_first_scan = false;
197 static gboolean found_with_first_scan = false;
198 static gboolean is_wifi_notifier_registered = false;
199 static GHashTable *failed_bssids = NULL;
200 static unsigned char buff_bssid[WIFI_BSSID_LEN_MAX] = { 0, };
204 static GList *iface_list = NULL;
206 static GList *pending_wifi_device = NULL;
207 static GList *p2p_iface_list = NULL;
208 static bool wfd_service_registered = false;
210 static void start_autoscan(struct connman_device *device);
211 static int tech_set_tethering(struct connman_technology *technology,
212 const char *identifier, const char *passphrase,
213 const char *bridge, bool enabled);
215 #if defined TIZEN_EXT
216 #define NETCONFIG_SERVICE "net.netconfig"
217 #define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
218 #define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
220 struct enc_method_call_data {
221 DBusConnection *connection;
222 struct connman_network *network;
225 static struct enc_method_call_data encrypt_request_data;
227 static void encryption_request_reply(DBusPendingCall *call,
232 DBusMessageIter args;
234 struct connman_service *service;
235 gchar* encrypted_value = NULL;
236 struct connman_network *network = encrypt_request_data.network;
240 reply = dbus_pending_call_steal_reply(call);
242 dbus_error_init(&error);
243 if (dbus_set_error_from_message(&error, reply)) {
244 DBG("send_encryption_request() %s %s", error.name, error.message);
245 dbus_error_free(&error);
249 if (dbus_message_iter_init(reply, &args) == FALSE)
252 dbus_message_iter_get_basic(&args, &out_data);
254 encrypted_value = g_strdup((const gchar *)out_data);
255 service = connman_service_lookup_from_network(network);
258 DBG("encryption result: no service");
262 if (connman_service_get_favorite(service)) {
263 __connman_service_set_passphrase(service, encrypted_value);
264 __connman_service_save(service);
266 connman_network_set_string(network, "WiFi.Passphrase",
269 DBG("encryption result: succeeded");
272 dbus_message_unref(reply);
273 dbus_pending_call_unref(call);
274 dbus_connection_unref(encrypt_request_data.connection);
275 g_free(encrypted_value);
277 encrypt_request_data.connection = NULL;
278 encrypt_request_data.network = NULL;
281 static int send_encryption_request(const char *passphrase,
282 struct connman_network *network)
284 DBusConnection *connection = NULL;
285 DBusMessage *msg = NULL;
286 DBusPendingCall *call;
289 DBG("Invalid parameter");
293 connection = connman_dbus_get_connection();
295 DBG("dbus connection does not exist");
299 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
300 NETCONFIG_WIFI_INTERFACE, "EncryptPassphrase");
302 dbus_connection_unref(connection);
306 dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
309 if (!dbus_connection_send_with_reply(connection, msg,
310 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
311 dbus_message_unref(msg);
312 dbus_connection_unref(connection);
317 dbus_message_unref(msg);
318 dbus_connection_unref(connection);
322 encrypt_request_data.connection = connection;
323 encrypt_request_data.network = network;
325 dbus_pending_call_set_notify(call, encryption_request_reply, NULL, NULL);
326 dbus_message_unref(msg);
332 static int p2p_tech_probe(struct connman_technology *technology)
334 p2p_technology = technology;
339 static void p2p_tech_remove(struct connman_technology *technology)
341 p2p_technology = NULL;
344 static struct connman_technology_driver p2p_tech_driver = {
346 .type = CONNMAN_SERVICE_TYPE_P2P,
347 .probe = p2p_tech_probe,
348 .remove = p2p_tech_remove,
351 static bool is_p2p_connecting(void)
355 for (list = iface_list; list; list = list->next) {
356 struct wifi_data *wifi = list->data;
358 if (wifi->p2p_connecting)
365 static void add_pending_wifi_device(struct wifi_data *wifi)
367 if (g_list_find(pending_wifi_device, wifi))
370 pending_wifi_device = g_list_append(pending_wifi_device, wifi);
373 #if defined TIZEN_EXT_WIFI_MESH
374 struct wifi_mesh_info {
375 struct wifi_data *wifi;
376 GSupplicantInterface *interface;
377 struct connman_mesh *mesh;
384 struct mesh_change_peer_status_info {
386 enum connman_mesh_peer_status peer_status;
387 mesh_change_peer_status_cb_t callback;
391 static struct connman_technology_driver mesh_tech_driver = {
393 .type = CONNMAN_SERVICE_TYPE_MESH,
396 static void mesh_interface_create_callback(int result,
397 GSupplicantInterface *interface,
400 struct wifi_mesh_info *mesh_info = user_data;
401 struct wifi_data *wifi;
402 bool success = false;
404 DBG("result %d ifname %s, mesh_info %p", result,
405 g_supplicant_interface_get_ifname(interface),
408 if (result < 0 || !mesh_info)
411 wifi = mesh_info->wifi;
413 mesh_info->interface = interface;
414 mesh_info->identifier = connman_inet_ifaddr(mesh_info->ifname);
415 mesh_info->index = connman_inet_ifindex(mesh_info->ifname);
416 DBG("Mesh Interface identifier %s", mesh_info->identifier);
417 wifi->mesh_interface = true;
418 wifi->mesh_info = mesh_info;
419 g_supplicant_interface_set_data(interface, wifi);
423 connman_mesh_notify_interface_create(success);
426 static int add_mesh_interface(const char *ifname, const char *parent_ifname)
429 struct wifi_data *wifi;
430 struct wifi_mesh_info *mesh_info;
431 const char *wifi_ifname;
432 bool parent_found = false;
433 const char *driver = "nl80211";
435 for (list = iface_list; list; list = list->next) {
438 if (!g_supplicant_interface_has_mesh(wifi->interface))
441 wifi_ifname = g_supplicant_interface_get_ifname(wifi->interface);
445 if (!g_strcmp0(wifi_ifname, parent_ifname)) {
452 DBG("Parent interface %s doesn't exist", parent_ifname);
456 mesh_info = g_try_malloc0(sizeof(struct wifi_mesh_info));
460 mesh_info->wifi = wifi;
461 mesh_info->ifname = g_strdup(ifname);
462 mesh_info->parent_ifname = g_strdup(parent_ifname);
464 g_supplicant_mesh_interface_create(ifname, driver, NULL, parent_ifname,
465 mesh_interface_create_callback, mesh_info);
469 static void mesh_interface_remove_callback(int result,
470 GSupplicantInterface *interface,
473 struct wifi_data *wifi = user_data;
474 struct wifi_mesh_info *mesh_info = wifi->mesh_info;
475 bool success = false;
477 DBG("result %d mesh_info %p", result, mesh_info);
479 if (result < 0 || !mesh_info)
482 mesh_info->interface = NULL;
483 g_free(mesh_info->parent_ifname);
484 g_free(mesh_info->ifname);
485 g_free(mesh_info->identifier);
487 wifi->mesh_interface = false;
488 wifi->mesh_info = NULL;
492 connman_mesh_notify_interface_remove(success);
495 static int remove_mesh_interface(const char *ifname)
498 struct wifi_data *wifi;
499 struct wifi_mesh_info *mesh_info;
500 bool mesh_if_found = false;
503 for (list = iface_list; list; list = list->next) {
506 if (wifi->mesh_interface) {
507 mesh_if_found = true;
512 if (!mesh_if_found) {
513 DBG("Mesh interface %s doesn't exist", ifname);
517 mesh_info = wifi->mesh_info;
518 ret = g_supplicant_interface_remove(mesh_info->interface,
519 mesh_interface_remove_callback, wifi);
526 static void mesh_disconnect_callback(int result,
527 GSupplicantInterface *interface, void *user_data)
529 struct connman_mesh *mesh = user_data;
531 DBG("result %d interface %p mesh %p", result, interface, mesh);
534 static int mesh_peer_disconnect(struct connman_mesh *mesh)
537 struct wifi_data *wifi;
538 struct wifi_mesh_info *mesh_info;
539 bool mesh_if_found = false;
540 GSupplicantInterface *interface;
542 for (list = iface_list; list; list = list->next) {
545 if (wifi->mesh_interface) {
546 mesh_if_found = true;
551 if (!mesh_if_found) {
552 DBG("Mesh interface is not created");
556 mesh_info = wifi->mesh_info;
558 interface = mesh_info->interface;
559 return g_supplicant_interface_disconnect(interface,
560 mesh_disconnect_callback, mesh);
563 static void mesh_connect_callback(int result, GSupplicantInterface *interface,
566 struct connman_mesh *mesh = user_data;
567 DBG("mesh %p result %d", mesh, result);
570 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_FAILURE);
572 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_ASSOCIATION);
575 static GSupplicantSecurity mesh_network_security(const char *security)
577 if (g_str_equal(security, "none"))
578 return G_SUPPLICANT_SECURITY_NONE;
579 else if (g_str_equal(security, "sae"))
580 return G_SUPPLICANT_SECURITY_SAE;
582 return G_SUPPLICANT_SECURITY_UNKNOWN;
585 static void mesh_ssid_init(GSupplicantSSID *ssid, struct connman_mesh *mesh)
588 const char *security;
593 memset(ssid, 0, sizeof(*ssid));
594 ssid->mode = G_SUPPLICANT_MODE_MESH;
596 security = connman_mesh_get_security(mesh);
597 ssid->security = mesh_network_security(security);
599 if (ssid->security == G_SUPPLICANT_SECURITY_SAE)
600 ssid->passphrase = connman_mesh_get_passphrase(mesh);
602 ssid->freq = connman_mesh_get_frequency(mesh);
603 name = connman_mesh_get_name(mesh);
605 ssid->ssid_len = strlen(name);
606 ssid->ssid = g_malloc0(ssid->ssid_len + 1);
607 memcpy(ssid->ssid, name, ssid->ssid_len);
612 static int mesh_peer_connect(struct connman_mesh *mesh)
615 struct wifi_data *wifi;
616 struct wifi_mesh_info *mesh_info;
617 bool mesh_if_found = false;
618 GSupplicantInterface *interface;
619 GSupplicantSSID *ssid;
621 for (list = iface_list; list; list = list->next) {
624 if (wifi->mesh_interface) {
625 mesh_if_found = true;
630 if (!mesh_if_found) {
631 DBG("Mesh interface is not created");
635 mesh_info = wifi->mesh_info;
637 interface = mesh_info->interface;
639 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
643 mesh_info->mesh = mesh;
645 mesh_ssid_init(ssid, mesh);
646 return g_supplicant_interface_connect(interface, ssid,
647 mesh_connect_callback, mesh);
650 static void mesh_peer_change_status_callback(int result,
651 GSupplicantInterface *interface,
654 struct mesh_change_peer_status_info *data = user_data;
656 DBG("result %d Peer Status %d", result, data->peer_status);
658 if (result == 0 && data->peer_status == CONNMAN_MESH_PEER_REMOVE) {
659 /* WLAN_REASON_MESH_PEERING_CANCELLED = 52 */
660 connman_mesh_remove_connected_peer(data->peer_address, 52);
664 data->callback(result, data->user_data);
666 g_free(data->peer_address);
671 static int mesh_change_peer_status(const char *peer_address,
672 enum connman_mesh_peer_status status,
673 mesh_change_peer_status_cb_t callback, void *user_data)
676 struct wifi_data *wifi;
677 struct wifi_mesh_info *mesh_info;
678 bool mesh_if_found = false;
679 GSupplicantInterface *interface;
680 struct mesh_change_peer_status_info *data;
683 for (list = iface_list; list; list = list->next) {
686 if (wifi->mesh_interface) {
687 mesh_if_found = true;
692 if (!mesh_if_found) {
693 DBG("Mesh interface is not created");
697 mesh_info = wifi->mesh_info;
699 interface = mesh_info->interface;
702 case CONNMAN_MESH_PEER_ADD:
703 method = "MeshPeerAdd";
705 case CONNMAN_MESH_PEER_REMOVE:
706 method = "MeshPeerRemove";
709 DBG("Invalid method");
713 data = g_try_malloc0(sizeof(struct mesh_change_peer_status_info));
715 DBG("Memory allocation failed");
719 data->peer_address = g_strdup(peer_address);
720 data->peer_status = status;
721 data->callback = callback;
722 data->user_data = user_data;
724 return g_supplicant_interface_mesh_peer_change_status(interface,
725 mesh_peer_change_status_callback, peer_address, method,
729 static struct connman_mesh_driver mesh_driver = {
730 .add_interface = add_mesh_interface,
731 .remove_interface = remove_mesh_interface,
732 .connect = mesh_peer_connect,
733 .disconnect = mesh_peer_disconnect,
734 .change_peer_status = mesh_change_peer_status,
737 static void mesh_support(GSupplicantInterface *interface)
741 if (!g_supplicant_interface_has_mesh(interface))
744 if (connman_technology_driver_register(&mesh_tech_driver) < 0) {
745 DBG("Could not register Mesh technology driver");
749 connman_mesh_driver_register(&mesh_driver);
752 static void check_mesh_technology(void)
754 bool mesh_exists = false;
757 for (list = iface_list; list; list = list->next) {
758 struct wifi_data *w = list->data;
761 g_supplicant_interface_has_mesh(w->interface))
766 connman_technology_driver_unregister(&mesh_tech_driver);
767 connman_mesh_driver_unregister(&mesh_driver);
771 static void mesh_group_started(GSupplicantInterface *interface)
773 struct wifi_data *wifi;
774 struct wifi_mesh_info *mesh_info;
775 struct connman_mesh *mesh;
776 const unsigned char *ssid;
777 unsigned int ssid_len;
780 ssid = g_supplicant_interface_get_mesh_group_ssid(interface, &ssid_len);
781 memcpy(name, ssid, ssid_len);
782 name[ssid_len] = '\0';
783 DBG("name %s", name);
784 wifi = g_supplicant_interface_get_data(interface);
785 DBG("wifi %p", wifi);
790 mesh_info = wifi->mesh_info;
794 mesh = mesh_info->mesh;
798 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_CONFIGURATION);
801 static void mesh_group_removed(GSupplicantInterface *interface)
803 struct wifi_data *wifi;
804 struct wifi_mesh_info *mesh_info;
805 struct connman_mesh *mesh;
806 const unsigned char *ssid;
807 unsigned int ssid_len;
808 int disconnect_reason;
811 ssid = g_supplicant_interface_get_mesh_group_ssid(interface, &ssid_len);
812 memcpy(name, ssid, ssid_len);
813 name[ssid_len] = '\0';
814 DBG("name %s", name);
816 disconnect_reason = g_supplicant_mesh_get_disconnect_reason(interface);
817 DBG("Disconnect Reason %d", disconnect_reason);
819 wifi = g_supplicant_interface_get_data(interface);
820 DBG("wifi %p", wifi);
825 mesh_info = wifi->mesh_info;
829 mesh = connman_get_connected_mesh_from_name(name);
831 DBG("%s is not connected", name);
832 mesh = connman_get_connecting_mesh_from_name(name);
834 DBG("%s is not connecting", name);
839 connman_mesh_peer_set_disconnect_reason(mesh, disconnect_reason);
840 connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_DISCONNECT);
843 static void mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
845 const char *peer_address;
847 peer_address = g_supplicant_mesh_peer_get_address(mesh_peer);
852 DBG("Peer %s connected", peer_address);
853 connman_mesh_add_connected_peer(peer_address);
856 static void mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
858 const char *peer_address;
861 peer_address = g_supplicant_mesh_peer_get_address(mesh_peer);
866 reason = g_supplicant_mesh_peer_get_disconnect_reason(mesh_peer);
868 DBG("Peer %s disconnected with reason %d", peer_address, reason);
869 connman_mesh_remove_connected_peer(peer_address, reason);
873 static struct wifi_data *get_pending_wifi_data(const char *ifname)
877 for (list = pending_wifi_device; list; list = list->next) {
878 struct wifi_data *wifi;
879 const char *dev_name;
882 if (!wifi || !wifi->device)
885 dev_name = connman_device_get_string(wifi->device, "Interface");
886 if (!g_strcmp0(ifname, dev_name)) {
887 pending_wifi_device = g_list_delete_link(
888 pending_wifi_device, list);
896 static void remove_pending_wifi_device(struct wifi_data *wifi)
900 link = g_list_find(pending_wifi_device, wifi);
905 pending_wifi_device = g_list_delete_link(pending_wifi_device, link);
908 static void peer_cancel_timeout(struct wifi_data *wifi)
910 if (wifi->p2p_connection_timeout > 0)
911 g_source_remove(wifi->p2p_connection_timeout);
913 wifi->p2p_connection_timeout = 0;
914 wifi->p2p_connecting = false;
916 if (wifi->pending_peer) {
917 connman_peer_unref(wifi->pending_peer);
918 wifi->pending_peer = NULL;
922 static gboolean peer_connect_timeout(gpointer data)
924 struct wifi_data *wifi = data;
928 if (wifi->p2p_connecting) {
929 enum connman_peer_state state = CONNMAN_PEER_STATE_FAILURE;
930 GSupplicantPeer *gs_peer =
931 g_supplicant_interface_peer_lookup(wifi->interface,
932 connman_peer_get_identifier(wifi->pending_peer));
934 if (g_supplicant_peer_has_requested_connection(gs_peer))
935 state = CONNMAN_PEER_STATE_IDLE;
937 connman_peer_set_state(wifi->pending_peer, state);
940 peer_cancel_timeout(wifi);
945 static void peer_connect_callback(int result, GSupplicantInterface *interface,
948 struct wifi_data *wifi = user_data;
949 struct connman_peer *peer = wifi->pending_peer;
951 DBG("peer %p - %d", peer, result);
957 peer_connect_timeout(wifi);
961 connman_peer_set_state(peer, CONNMAN_PEER_STATE_ASSOCIATION);
963 wifi->p2p_connection_timeout = g_timeout_add_seconds(
964 P2P_CONNECTION_TIMEOUT,
965 peer_connect_timeout, wifi);
968 static int peer_connect(struct connman_peer *peer,
969 enum connman_peer_wps_method wps_method,
972 struct connman_device *device = connman_peer_get_device(peer);
973 GSupplicantPeerParams *peer_params;
974 GSupplicantPeer *gs_peer;
975 struct wifi_data *wifi;
979 DBG("peer %p", peer);
984 wifi = connman_device_get_data(device);
985 if (!wifi || !wifi->interface)
988 if (wifi->p2p_connecting)
991 gs_peer = g_supplicant_interface_peer_lookup(wifi->interface,
992 connman_peer_get_identifier(peer));
996 pbc = g_supplicant_peer_is_wps_pbc(gs_peer);
997 pin = g_supplicant_peer_is_wps_pin(gs_peer);
999 switch (wps_method) {
1000 case CONNMAN_PEER_WPS_UNKNOWN:
1001 if ((pbc && pin) || pin)
1004 case CONNMAN_PEER_WPS_PBC:
1009 case CONNMAN_PEER_WPS_PIN:
1010 if (!pin || !wps_pin)
1015 peer_params = g_try_malloc0(sizeof(GSupplicantPeerParams));
1019 peer_params->path = g_strdup(g_supplicant_peer_get_path(gs_peer));
1021 peer_params->wps_pin = g_strdup(wps_pin);
1023 peer_params->master = connman_peer_service_is_master();
1025 ret = g_supplicant_interface_p2p_connect(wifi->interface, peer_params,
1026 peer_connect_callback, wifi);
1027 if (ret == -EINPROGRESS) {
1028 wifi->pending_peer = connman_peer_ref(peer);
1029 wifi->p2p_connecting = true;
1030 } else if (ret < 0) {
1031 g_free(peer_params->path);
1032 g_free(peer_params->wps_pin);
1033 g_free(peer_params);
1039 static int peer_disconnect(struct connman_peer *peer)
1041 struct connman_device *device = connman_peer_get_device(peer);
1042 GSupplicantPeerParams peer_params = {};
1043 GSupplicantPeer *gs_peer;
1044 struct wifi_data *wifi;
1047 DBG("peer %p", peer);
1052 wifi = connman_device_get_data(device);
1056 gs_peer = g_supplicant_interface_peer_lookup(wifi->interface,
1057 connman_peer_get_identifier(peer));
1061 peer_params.path = g_strdup(g_supplicant_peer_get_path(gs_peer));
1063 ret = g_supplicant_interface_p2p_disconnect(wifi->interface,
1065 g_free(peer_params.path);
1067 if (ret == -EINPROGRESS) {
1068 peer_cancel_timeout(wifi);
1069 wifi->p2p_device = false;
1075 struct peer_service_registration {
1076 peer_service_registration_cb_t callback;
1080 static bool is_service_wfd(const unsigned char *specs, int length)
1082 if (length < 9 || specs[0] != 0 || specs[1] != 0 || specs[2] != 6)
1088 static void apply_p2p_listen_on_iface(gpointer data, gpointer user_data)
1090 struct wifi_data *wifi = data;
1092 if (!wifi->interface ||
1093 !g_supplicant_interface_has_p2p(wifi->interface))
1096 if (!wifi->servicing) {
1097 g_supplicant_interface_p2p_listen(wifi->interface,
1098 P2P_LISTEN_PERIOD, P2P_LISTEN_INTERVAL);
1104 static void register_wfd_service_cb(int result,
1105 GSupplicantInterface *iface, void *user_data)
1107 struct peer_service_registration *reg_data = user_data;
1112 g_list_foreach(iface_list, apply_p2p_listen_on_iface, NULL);
1114 if (reg_data && reg_data->callback) {
1115 reg_data->callback(result, reg_data->user_data);
1120 static GSupplicantP2PServiceParams *fill_in_peer_service_params(
1121 const unsigned char *spec,
1122 int spec_length, const unsigned char *query,
1123 int query_length, int version)
1125 GSupplicantP2PServiceParams *params;
1127 params = g_try_malloc0(sizeof(GSupplicantP2PServiceParams));
1132 params->version = version;
1133 params->service = g_memdup(spec, spec_length);
1134 } else if (query_length > 0 && spec_length > 0) {
1135 params->query = g_memdup(query, query_length);
1136 params->query_length = query_length;
1138 params->response = g_memdup(spec, spec_length);
1139 params->response_length = spec_length;
1141 params->wfd_ies = g_memdup(spec, spec_length);
1142 params->wfd_ies_length = spec_length;
1148 static void free_peer_service_params(GSupplicantP2PServiceParams *params)
1153 g_free(params->service);
1154 g_free(params->query);
1155 g_free(params->response);
1156 g_free(params->wfd_ies);
1161 static int peer_register_wfd_service(const unsigned char *specification,
1162 int specification_length,
1163 peer_service_registration_cb_t callback,
1166 struct peer_service_registration *reg_data = NULL;
1167 static GSupplicantP2PServiceParams *params;
1172 if (wfd_service_registered)
1175 params = fill_in_peer_service_params(specification,
1176 specification_length, NULL, 0, 0);
1180 reg_data = g_try_malloc0(sizeof(*reg_data));
1186 reg_data->callback = callback;
1187 reg_data->user_data = user_data;
1189 ret = g_supplicant_set_widi_ies(params,
1190 register_wfd_service_cb, reg_data);
1191 if (ret < 0 && ret != -EINPROGRESS)
1194 wfd_service_registered = true;
1198 free_peer_service_params(params);
1204 static void register_peer_service_cb(int result,
1205 GSupplicantInterface *iface, void *user_data)
1207 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
1208 struct peer_service_registration *reg_data = user_data;
1210 #if defined TIZEN_EXT
1218 apply_p2p_listen_on_iface(wifi, NULL);
1220 if (reg_data->callback)
1221 reg_data->callback(result, reg_data->user_data);
1226 static int peer_register_service(const unsigned char *specification,
1227 int specification_length,
1228 const unsigned char *query,
1229 int query_length, int version,
1230 peer_service_registration_cb_t callback,
1233 struct peer_service_registration *reg_data;
1234 GSupplicantP2PServiceParams *params;
1241 if (specification && !version && !query &&
1242 is_service_wfd(specification, specification_length)) {
1243 return peer_register_wfd_service(specification,
1244 specification_length, callback, user_data);
1247 reg_data = g_try_malloc0(sizeof(*reg_data));
1251 reg_data->callback = callback;
1252 reg_data->user_data = user_data;
1254 ret_f = -EOPNOTSUPP;
1256 for (list = iface_list; list; list = list->next) {
1257 struct wifi_data *wifi = list->data;
1258 GSupplicantInterface *iface = wifi->interface;
1260 if (!g_supplicant_interface_has_p2p(iface))
1263 params = fill_in_peer_service_params(specification,
1264 specification_length, query,
1265 query_length, version);
1270 ret_f = g_supplicant_interface_p2p_add_service(iface,
1271 register_peer_service_cb, params, reg_data);
1272 if (ret_f == 0 || ret_f == -EINPROGRESS)
1276 ret = g_supplicant_interface_p2p_add_service(iface,
1277 register_peer_service_cb, params, NULL);
1278 if (ret != 0 && ret != -EINPROGRESS)
1279 free_peer_service_params(params);
1282 if (ret_f != 0 && ret_f != -EINPROGRESS)
1288 static int peer_unregister_wfd_service(void)
1290 GSupplicantP2PServiceParams *params;
1293 if (!wfd_service_registered)
1296 params = fill_in_peer_service_params(NULL, 0, NULL, 0, 0);
1300 wfd_service_registered = false;
1302 g_supplicant_set_widi_ies(params, NULL, NULL);
1304 for (list = iface_list; list; list = list->next) {
1305 struct wifi_data *wifi = list->data;
1307 if (!g_supplicant_interface_has_p2p(wifi->interface))
1311 if (!wifi->servicing || wifi->servicing < 0) {
1312 g_supplicant_interface_p2p_listen(wifi->interface,
1314 wifi->servicing = 0;
1321 static int peer_unregister_service(const unsigned char *specification,
1322 int specification_length,
1323 const unsigned char *query,
1324 int query_length, int version)
1326 GSupplicantP2PServiceParams *params;
1331 if (specification && !version && !query &&
1332 is_service_wfd(specification, specification_length)) {
1333 ret = peer_unregister_wfd_service();
1334 if (ret != 0 && ret != -EINPROGRESS)
1339 for (list = iface_list; list; list = list->next) {
1340 struct wifi_data *wifi = list->data;
1341 GSupplicantInterface *iface = wifi->interface;
1344 goto stop_listening;
1346 if (!g_supplicant_interface_has_p2p(iface))
1349 params = fill_in_peer_service_params(specification,
1350 specification_length, query,
1351 query_length, version);
1355 ret = g_supplicant_interface_p2p_del_service(iface, params);
1356 if (ret != 0 && ret != -EINPROGRESS)
1357 free_peer_service_params(params);
1360 if (!wifi->servicing || wifi->servicing < 0) {
1361 g_supplicant_interface_p2p_listen(iface, 0, 0);
1362 wifi->servicing = 0;
1369 static struct connman_peer_driver peer_driver = {
1370 .connect = peer_connect,
1371 .disconnect = peer_disconnect,
1372 .register_service = peer_register_service,
1373 .unregister_service = peer_unregister_service,
1376 static void handle_tethering(struct wifi_data *wifi)
1378 if (!wifi->tethering)
1387 DBG("index %d bridge %s", wifi->index, wifi->bridge);
1389 if (connman_inet_add_to_bridge(wifi->index, wifi->bridge) < 0)
1392 wifi->bridged = true;
1395 static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
1397 struct connman_device *device = user_data;
1398 struct wifi_data *wifi = connman_device_get_data(device);
1403 DBG("index %d flags %d change %d", wifi->index, flags, change);
1405 if ((wifi->flags & IFF_UP) != (flags & IFF_UP)) {
1407 DBG("interface up");
1409 DBG("interface down");
1412 if ((wifi->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
1413 if (flags & IFF_LOWER_UP) {
1416 handle_tethering(wifi);
1421 wifi->flags = flags;
1424 static int wifi_probe(struct connman_device *device)
1426 struct wifi_data *wifi;
1428 DBG("device %p", device);
1430 wifi = g_try_new0(struct wifi_data, 1);
1434 wifi->state = G_SUPPLICANT_STATE_INACTIVE;
1435 wifi->ap_supported = WIFI_AP_UNKNOWN;
1436 wifi->tethering_param = NULL;
1438 connman_device_set_data(device, wifi);
1439 wifi->device = connman_device_ref(device);
1441 wifi->index = connman_device_get_index(device);
1444 wifi->watch = connman_rtnl_add_newlink_watch(wifi->index,
1445 wifi_newlink, device);
1446 if (is_p2p_connecting())
1447 add_pending_wifi_device(wifi);
1449 iface_list = g_list_append(iface_list, wifi);
1454 static void remove_networks(struct connman_device *device,
1455 struct wifi_data *wifi)
1459 for (list = wifi->networks; list; list = list->next) {
1460 struct connman_network *network = list->data;
1462 connman_device_remove_network(device, network);
1463 connman_network_unref(network);
1466 g_slist_free(wifi->networks);
1467 wifi->networks = NULL;
1470 static void remove_peers(struct wifi_data *wifi)
1474 for (list = wifi->peers; list; list = list->next) {
1475 struct connman_peer *peer = list->data;
1477 connman_peer_unregister(peer);
1478 connman_peer_unref(peer);
1481 g_slist_free(wifi->peers);
1485 static void reset_autoscan(struct connman_device *device)
1487 struct wifi_data *wifi = connman_device_get_data(device);
1488 struct autoscan_params *autoscan;
1492 if (!wifi || !wifi->autoscan)
1495 autoscan = wifi->autoscan;
1497 autoscan->interval = 0;
1499 if (autoscan->timeout == 0)
1502 g_source_remove(autoscan->timeout);
1503 autoscan->timeout = 0;
1505 connman_device_unref(device);
1508 static void stop_autoscan(struct connman_device *device)
1510 const struct wifi_data *wifi = connman_device_get_data(device);
1512 if (!wifi || !wifi->autoscan)
1515 reset_autoscan(device);
1517 connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_WIFI, false);
1520 static void check_p2p_technology(void)
1522 bool p2p_exists = false;
1525 for (list = iface_list; list; list = list->next) {
1526 struct wifi_data *w = list->data;
1529 g_supplicant_interface_has_p2p(w->interface))
1534 connman_technology_driver_unregister(&p2p_tech_driver);
1535 connman_peer_driver_unregister(&peer_driver);
1539 struct last_connected {
1545 static gint sort_entry(gconstpointer a, gconstpointer b, gpointer user_data)
1547 GTimeVal *aval = (GTimeVal *)a;
1548 GTimeVal *bval = (GTimeVal *)b;
1550 /* Note that the sort order is descending */
1551 if (aval->tv_sec < bval->tv_sec)
1554 if (aval->tv_sec > bval->tv_sec)
1560 static void free_entry(gpointer data)
1562 struct last_connected *entry = data;
1564 g_free(entry->ssid);
1568 static void wifi_remove(struct connman_device *device)
1570 struct wifi_data *wifi = connman_device_get_data(device);
1572 DBG("device %p wifi %p", device, wifi);
1577 stop_autoscan(device);
1579 if (wifi->p2p_device)
1580 p2p_iface_list = g_list_remove(p2p_iface_list, wifi);
1582 iface_list = g_list_remove(iface_list, wifi);
1584 check_p2p_technology();
1585 #if defined TIZEN_EXT_WIFI_MESH
1586 check_mesh_technology();
1589 remove_pending_wifi_device(wifi);
1591 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_P2P)) {
1592 g_source_remove(wifi->p2p_find_timeout);
1593 connman_device_unref(wifi->device);
1596 if (wifi->p2p_connection_timeout)
1597 g_source_remove(wifi->p2p_connection_timeout);
1599 #if defined TIZEN_EXT
1600 if (wifi->automaxspeed_timeout != 0) {
1601 g_source_remove(wifi->automaxspeed_timeout);
1602 wifi->automaxspeed_timeout = 0;
1606 remove_networks(device, wifi);
1609 connman_device_set_powered(device, false);
1610 connman_device_set_data(device, NULL);
1611 connman_device_unref(wifi->device);
1612 connman_rtnl_remove_watch(wifi->watch);
1614 g_supplicant_interface_set_data(wifi->interface, NULL);
1616 g_supplicant_interface_cancel(wifi->interface);
1618 if (wifi->scan_params)
1619 g_supplicant_free_scan_params(wifi->scan_params);
1620 #if defined TIZEN_EXT
1621 if (wifi->hidden_scan_params) {
1622 while (wifi->hidden_scan_params->ssids) {
1623 struct scan_ssid *ssid;
1624 ssid = wifi->hidden_scan_params->ssids->data;
1625 wifi->hidden_scan_params->ssids = g_slist_remove(wifi->hidden_scan_params->ssids, ssid);
1627 g_supplicant_free_scan_params(wifi->hidden_scan_params);
1631 g_free(wifi->autoscan);
1632 g_free(wifi->identifier);
1636 static bool is_duplicate(GSList *list, gchar *ssid, int ssid_len)
1640 for (iter = list; iter; iter = g_slist_next(iter)) {
1641 struct scan_ssid *scan_ssid = iter->data;
1643 if (ssid_len == scan_ssid->ssid_len &&
1644 memcmp(ssid, scan_ssid->ssid, ssid_len) == 0)
1651 static int add_scan_param(gchar *hex_ssid, char *raw_ssid, int ssid_len,
1652 int freq, GSupplicantScanParams *scan_data,
1653 int driver_max_scan_ssids, char *ssid_name)
1656 struct scan_ssid *scan_ssid;
1658 if ((driver_max_scan_ssids == 0 ||
1659 driver_max_scan_ssids > scan_data->num_ssids) &&
1660 (hex_ssid || raw_ssid)) {
1662 unsigned int j = 0, hex;
1665 size_t hex_ssid_len = strlen(hex_ssid);
1667 ssid = g_try_malloc0(hex_ssid_len / 2);
1671 for (i = 0; i < hex_ssid_len; i += 2) {
1672 sscanf(hex_ssid + i, "%02x", &hex);
1681 * If we have already added hidden AP to the list,
1682 * then do not do it again. This might happen if you have
1683 * used or are using multiple wifi cards, so in that case
1684 * you might have multiple service files for same AP.
1686 if (is_duplicate(scan_data->ssids, ssid, j)) {
1692 scan_ssid = g_try_new(struct scan_ssid, 1);
1699 memcpy(scan_ssid->ssid, ssid, j);
1700 scan_ssid->ssid_len = j;
1701 scan_data->ssids = g_slist_prepend(scan_data->ssids,
1704 scan_data->num_ssids++;
1706 DBG("SSID %s added to scanned list of %d entries", ssid_name,
1707 scan_data->num_ssids);
1714 scan_data->ssids = g_slist_reverse(scan_data->ssids);
1716 if (!scan_data->freqs) {
1717 scan_data->freqs = g_try_malloc0(sizeof(uint16_t));
1718 if (!scan_data->freqs) {
1719 g_slist_free_full(scan_data->ssids, g_free);
1723 scan_data->num_freqs = 1;
1724 scan_data->freqs[0] = freq;
1726 bool duplicate = false;
1728 /* Don't add duplicate entries */
1729 for (i = 0; i < scan_data->num_freqs; i++) {
1730 if (scan_data->freqs[i] == freq) {
1737 scan_data->num_freqs++;
1738 scan_data->freqs = g_try_realloc(scan_data->freqs,
1739 sizeof(uint16_t) * scan_data->num_freqs);
1740 if (!scan_data->freqs) {
1741 g_slist_free_full(scan_data->ssids, g_free);
1744 scan_data->freqs[scan_data->num_freqs - 1] = freq;
1751 static int get_hidden_connections(GSupplicantScanParams *scan_data)
1753 struct connman_config_entry **entries;
1755 #if defined TIZEN_EXT
1756 gchar **services = NULL;
1759 #endif /* defined TIZEN_EXT */
1763 int num_ssids = 0, add_param_failed = 0;
1764 #if defined TIZEN_EXT
1765 GSequenceIter *iter;
1766 GSequence *latest_list;
1767 struct last_connected *entry;
1770 latest_list = g_sequence_new(free_entry);
1774 services = connman_storage_get_services();
1775 for (i = 0; services && services[i]; i++) {
1776 if (strncmp(services[i], "wifi_", 5) != 0)
1779 keyfile = connman_storage_load_service(services[i]);
1783 value = g_key_file_get_boolean(keyfile,
1784 services[i], "Hidden", NULL);
1786 g_key_file_free(keyfile);
1790 value = g_key_file_get_boolean(keyfile,
1791 services[i], "Favorite", NULL);
1793 g_key_file_free(keyfile);
1797 #if defined TIZEN_EXT
1798 value = g_key_file_get_boolean(keyfile,
1799 services[i], "AutoConnect", NULL);
1801 g_key_file_free(keyfile);
1805 gchar *str = g_key_file_get_string(keyfile,
1806 services[i], "Modified", NULL);
1808 g_key_file_free(keyfile);
1811 g_time_val_from_iso8601(str, &modified);
1815 ssid = g_key_file_get_string(keyfile,
1816 services[i], "SSID", NULL);
1818 name = g_key_file_get_string(keyfile, services[i], "Name",
1821 #if defined TIZEN_EXT
1822 entry = g_try_new(struct last_connected, 1);
1824 g_sequence_free(latest_list);
1827 g_key_file_free(keyfile);
1831 entry->modified = modified;
1834 g_sequence_insert_sorted(latest_list, entry,
1837 ret = add_scan_param(ssid, NULL, 0, 0, scan_data, 0, name);
1846 g_key_file_free(keyfile);
1849 #if defined TIZEN_EXT
1850 gint length = g_sequence_get_length(latest_list);
1851 iter = g_sequence_get_begin_iter(latest_list);
1853 for (i = 0; i < length; i++) {
1854 entry = g_sequence_get(iter);
1856 ret = add_scan_param(entry->ssid, NULL, 0, 0, scan_data, 0, entry->ssid);
1862 iter = g_sequence_iter_next(iter);
1865 g_sequence_free(latest_list);
1869 * Check if there are any hidden AP that needs to be provisioned.
1871 entries = connman_config_get_entries("wifi");
1872 for (i = 0; entries && entries[i]; i++) {
1875 if (!entries[i]->hidden)
1878 if (!entries[i]->ssid) {
1879 ssid = entries[i]->name;
1882 ssid = entries[i]->ssid;
1883 len = entries[i]->ssid_len;
1889 ret = add_scan_param(NULL, ssid, len, 0, scan_data, 0, ssid);
1896 connman_config_free_entries(entries);
1898 if (add_param_failed > 0)
1899 DBG("Unable to scan %d out of %d SSIDs",
1900 add_param_failed, num_ssids);
1902 g_strfreev(services);
1907 static int get_hidden_connections_params(struct wifi_data *wifi,
1908 GSupplicantScanParams *scan_params)
1910 int driver_max_ssids, i;
1911 GSupplicantScanParams *orig_params;
1914 * Scan hidden networks so that we can autoconnect to them.
1915 * We will assume 1 as a default number of ssid to scan.
1917 driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
1919 if (driver_max_ssids == 0)
1920 driver_max_ssids = 1;
1922 DBG("max ssids %d", driver_max_ssids);
1924 #if defined TIZEN_EXT
1925 if (!wifi->hidden_scan_params) {
1926 wifi->hidden_scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
1927 if (!wifi->hidden_scan_params)
1930 if (get_hidden_connections(wifi->hidden_scan_params) == 0) {
1931 g_supplicant_free_scan_params(wifi->hidden_scan_params);
1932 wifi->hidden_scan_params = NULL;
1938 orig_params = wifi->hidden_scan_params;
1940 if (!wifi->scan_params) {
1941 wifi->scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
1942 if (!wifi->scan_params)
1945 if (get_hidden_connections(wifi->scan_params) == 0) {
1946 g_supplicant_free_scan_params(wifi->scan_params);
1947 wifi->scan_params = NULL;
1953 orig_params = wifi->scan_params;
1956 /* Let's transfer driver_max_ssids params */
1957 for (i = 0; i < driver_max_ssids; i++) {
1958 struct scan_ssid *ssid;
1960 #if defined TIZEN_EXT
1961 if (!wifi->hidden_scan_params->ssids)
1963 if (!wifi->scan_params->ssids)
1967 ssid = orig_params->ssids->data;
1968 orig_params->ssids = g_slist_remove(orig_params->ssids, ssid);
1969 scan_params->ssids = g_slist_prepend(scan_params->ssids, ssid);
1973 scan_params->num_ssids = i;
1974 scan_params->ssids = g_slist_reverse(scan_params->ssids);
1976 scan_params->freqs = g_memdup(orig_params->freqs,
1977 sizeof(uint16_t) * orig_params->num_freqs);
1978 if (!scan_params->freqs)
1981 scan_params->num_freqs = orig_params->num_freqs;
1986 orig_params->num_ssids -= scan_params->num_ssids;
1988 return scan_params->num_ssids;
1991 g_slist_free_full(scan_params->ssids, g_free);
1992 #if defined TIZEN_EXT
1993 g_supplicant_free_scan_params(wifi->hidden_scan_params);
1994 wifi->hidden_scan_params = NULL;
1996 g_supplicant_free_scan_params(wifi->scan_params);
1997 wifi->scan_params = NULL;
2003 static int throw_wifi_scan(struct connman_device *device,
2004 GSupplicantInterfaceCallback callback)
2006 struct wifi_data *wifi = connman_device_get_data(device);
2012 DBG("device %p %p", device, wifi->interface);
2014 if (wifi->tethering)
2017 #if defined TIZEN_EXT
2018 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI)
2019 && !wifi->allow_full_scan)
2021 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI))
2025 connman_device_ref(device);
2027 ret = g_supplicant_interface_scan(wifi->interface, NULL,
2030 connman_device_set_scanning(device,
2031 CONNMAN_SERVICE_TYPE_WIFI, true);
2033 connman_device_unref(device);
2038 static void hidden_free(struct hidden_params *hidden)
2043 if (hidden->scan_params)
2044 g_supplicant_free_scan_params(hidden->scan_params);
2045 g_free(hidden->identity);
2046 g_free(hidden->passphrase);
2047 g_free(hidden->security);
2051 #if defined TIZEN_EXT
2052 static void service_state_changed(struct connman_service *service,
2053 enum connman_service_state state);
2055 static int network_connect(struct connman_network *network);
2057 static struct connman_notifier notifier = {
2059 .priority = CONNMAN_NOTIFIER_PRIORITY_DEFAULT,
2060 .service_state_changed = service_state_changed,
2063 static void service_state_changed(struct connman_service *service,
2064 enum connman_service_state state)
2066 enum connman_service_type type;
2068 type = connman_service_get_type(service);
2069 if (type != CONNMAN_SERVICE_TYPE_WIFI)
2072 DBG("service %p state %d", service, state);
2075 case CONNMAN_SERVICE_STATE_READY:
2076 case CONNMAN_SERVICE_STATE_ONLINE:
2077 case CONNMAN_SERVICE_STATE_FAILURE:
2078 connman_notifier_unregister(¬ifier);
2079 is_wifi_notifier_registered = FALSE;
2081 __connman_device_request_scan(type);
2089 static void scan_callback_hidden(int result,
2090 GSupplicantInterface *interface, void *user_data);
2093 static void scan_callback(int result, GSupplicantInterface *interface,
2096 struct connman_device *device = user_data;
2097 struct wifi_data *wifi = connman_device_get_data(device);
2099 #if defined TIZEN_EXT
2100 GSList *list = NULL;
2101 bool favorite_exists = false;
2102 struct connman_network *network = NULL;
2103 struct connman_service *service = NULL;
2106 DBG("result %d wifi %p", result, wifi);
2109 if (wifi->hidden && !wifi->postpone_hidden) {
2110 connman_network_clear_hidden(wifi->hidden->user_data);
2111 hidden_free(wifi->hidden);
2112 wifi->hidden = NULL;
2115 if (wifi->scan_params) {
2116 g_supplicant_free_scan_params(wifi->scan_params);
2117 wifi->scan_params = NULL;
2120 #if defined TIZEN_EXT
2121 if (wifi->hidden_scan_params && !wifi->hidden_scan_params->ssids) {
2122 g_supplicant_free_scan_params(wifi->hidden_scan_params);
2123 wifi->hidden_scan_params = NULL;
2129 connman_device_reset_scanning(device);
2131 /* User is connecting to a hidden AP, let's wait for finished event */
2132 if (wifi && wifi->hidden && wifi->postpone_hidden) {
2133 GSupplicantScanParams *scan_params;
2136 wifi->postpone_hidden = false;
2137 scan_params = wifi->hidden->scan_params;
2138 wifi->hidden->scan_params = NULL;
2140 reset_autoscan(device);
2142 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
2143 scan_callback, device);
2147 /* On error, let's recall scan_callback, which will cleanup */
2148 return scan_callback(ret, interface, user_data);
2151 #if defined TIZEN_EXT
2153 for (list = wifi->networks; list; list = list->next) {
2154 network = list->data;
2155 service = connman_service_lookup_from_network(network);
2157 if (service != NULL &&
2158 (connman_service_get_favorite(service) == true) &&
2159 (connman_service_get_autoconnect(service) == true)) {
2160 DBG("Favorite service exists [%s]", connman_network_get_string(network, "Name"));
2161 favorite_exists = true;
2167 if (favorite_exists == false) {
2168 if (wifi && wifi->allow_full_scan) {
2170 DBG("Trigger full channel scan");
2171 wifi->allow_full_scan = false;
2173 ret = g_supplicant_interface_scan(wifi->interface, NULL,
2174 scan_callback_hidden, device);
2178 /* On error, let's recall scan_callback, which will cleanup */
2179 return scan_callback(ret, interface, user_data);
2184 scanning = connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI);
2187 connman_device_set_scanning(device,
2188 CONNMAN_SERVICE_TYPE_WIFI, false);
2191 if (result != -ENOLINK)
2192 #if defined TIZEN_EXT
2195 start_autoscan(device);
2198 * If we are here then we were scanning; however, if we are
2199 * also mid-flight disabling the interface, then wifi_disable
2200 * has already cleared the device scanning state and
2201 * unreferenced the device, obviating the need to do it here.
2205 connman_device_unref(device);
2207 #if defined TIZEN_EXT
2208 if (wifi && wifi->scan_pending_network && result != -EIO) {
2209 network_connect(wifi->scan_pending_network);
2210 wifi->scan_pending_network = NULL;
2211 connman_network_set_connecting(wifi->network);
2214 if (is_wifi_notifier_registered != true &&
2215 wifi_first_scan == true && found_with_first_scan == true) {
2216 wifi_first_scan = false;
2217 found_with_first_scan = false;
2219 connman_notifier_register(¬ifier);
2220 is_wifi_notifier_registered = true;
2225 static void scan_callback_hidden(int result,
2226 GSupplicantInterface *interface, void *user_data)
2228 struct connman_device *device = user_data;
2229 struct wifi_data *wifi = connman_device_get_data(device);
2230 GSupplicantScanParams *scan_params;
2233 DBG("result %d wifi %p", result, wifi);
2238 /* User is trying to connect to a hidden AP */
2239 if (wifi->hidden && wifi->postpone_hidden)
2242 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2246 if (get_hidden_connections_params(wifi, scan_params) > 0) {
2247 ret = g_supplicant_interface_scan(wifi->interface,
2249 #if defined TIZEN_EXT
2252 scan_callback_hidden,
2259 g_supplicant_free_scan_params(scan_params);
2262 scan_callback(result, interface, user_data);
2265 static gboolean autoscan_timeout(gpointer data)
2267 struct connman_device *device = data;
2268 struct wifi_data *wifi = connman_device_get_data(device);
2269 struct autoscan_params *autoscan;
2275 autoscan = wifi->autoscan;
2277 #if defined TIZEN_EXT
2282 if (autoscan->interval <= 0) {
2283 interval = autoscan->base;
2286 interval = autoscan->interval * autoscan->base;
2288 #if defined TIZEN_EXT
2289 if (autoscan->interval >= autoscan->limit)
2291 if (interval > autoscan->limit)
2293 interval = autoscan->limit;
2295 throw_wifi_scan(wifi->device, scan_callback_hidden);
2298 * In case BackgroundScanning is disabled, interval will reach the
2299 * limit exactly after the very first passive scanning. It allows
2300 * to ensure at most one passive scan is performed in such cases.
2302 if (!connman_setting_get_bool("BackgroundScanning") &&
2303 interval == autoscan->limit) {
2304 g_source_remove(autoscan->timeout);
2305 autoscan->timeout = 0;
2307 connman_device_unref(device);
2313 DBG("interval %d", interval);
2315 autoscan->interval = interval;
2317 autoscan->timeout = g_timeout_add_seconds(interval,
2318 autoscan_timeout, device);
2323 static void start_autoscan(struct connman_device *device)
2325 struct wifi_data *wifi = connman_device_get_data(device);
2326 struct autoscan_params *autoscan;
2333 if (wifi->p2p_device)
2336 if (wifi->connected)
2339 autoscan = wifi->autoscan;
2343 if (autoscan->timeout > 0 || autoscan->interval > 0)
2346 connman_device_ref(device);
2348 autoscan_timeout(device);
2351 static struct autoscan_params *parse_autoscan_params(const char *params)
2353 struct autoscan_params *autoscan;
2360 list_params = g_strsplit(params, ":", 0);
2361 if (list_params == 0)
2364 if (!g_strcmp0(list_params[0], "exponential") &&
2365 g_strv_length(list_params) == 3) {
2366 base = atoi(list_params[1]);
2367 limit = atoi(list_params[2]);
2368 } else if (!g_strcmp0(list_params[0], "single") &&
2369 g_strv_length(list_params) == 2)
2370 base = limit = atoi(list_params[1]);
2372 g_strfreev(list_params);
2376 DBG("Setup %s autoscanning", list_params[0]);
2378 g_strfreev(list_params);
2380 autoscan = g_try_malloc0(sizeof(struct autoscan_params));
2382 DBG("Could not allocate memory for autoscan");
2386 DBG("base %d - limit %d", base, limit);
2387 autoscan->base = base;
2388 autoscan->limit = limit;
2393 static void setup_autoscan(struct wifi_data *wifi)
2396 * If BackgroundScanning is enabled, setup exponential
2397 * autoscanning if it has not been previously done.
2399 if (connman_setting_get_bool("BackgroundScanning")) {
2400 wifi->autoscan = parse_autoscan_params(AUTOSCAN_EXPONENTIAL);
2403 #if defined TIZEN_EXT
2405 if (wifi->autoscan) {
2406 g_free(wifi->autoscan);
2407 wifi->autoscan = NULL;
2410 DBG("BackgroundScanning is disabled");
2417 * On the contrary, if BackgroundScanning is disabled, update autoscan
2418 * parameters based on the type of scanning that is being performed.
2420 if (wifi->autoscan) {
2421 g_free(wifi->autoscan);
2422 wifi->autoscan = NULL;
2425 switch (wifi->scanning_type) {
2426 case WIFI_SCANNING_PASSIVE:
2427 /* Do not setup autoscan. */
2429 case WIFI_SCANNING_ACTIVE:
2430 /* Setup one single passive scan after active. */
2431 wifi->autoscan = parse_autoscan_params(AUTOSCAN_SINGLE);
2433 case WIFI_SCANNING_UNKNOWN:
2434 /* Setup autoscan in this case but we should never fall here. */
2435 wifi->autoscan = parse_autoscan_params(AUTOSCAN_SINGLE);
2441 static void finalize_interface_creation(struct wifi_data *wifi)
2443 DBG("interface is ready wifi %p tethering %d", wifi, wifi->tethering);
2445 if (!wifi->device) {
2446 connman_error("WiFi device not set");
2450 connman_device_set_powered(wifi->device, true);
2452 if (wifi->p2p_device)
2455 if (!wifi->autoscan)
2456 setup_autoscan(wifi);
2458 start_autoscan(wifi->device);
2461 static void interface_create_callback(int result,
2462 GSupplicantInterface *interface,
2465 struct wifi_data *wifi = user_data;
2467 DBG("result %d ifname %s, wifi %p", result,
2468 g_supplicant_interface_get_ifname(interface),
2471 if (result < 0 || !wifi)
2474 wifi->interface = interface;
2475 g_supplicant_interface_set_data(interface, wifi);
2477 if (g_supplicant_interface_get_ready(interface)) {
2478 wifi->interface_ready = true;
2479 finalize_interface_creation(wifi);
2483 static int wifi_enable(struct connman_device *device)
2485 struct wifi_data *wifi = connman_device_get_data(device);
2488 const char *driver = connman_option_get_string("wifi");
2491 DBG("device %p %p", device, wifi);
2493 index = connman_device_get_index(device);
2494 if (!wifi || index < 0)
2497 if (is_p2p_connecting())
2498 return -EINPROGRESS;
2500 interface = connman_inet_ifname(index);
2501 ret = g_supplicant_interface_create(interface, driver, NULL,
2503 connman_device_get_mac_policy(device),
2504 connman_device_get_preassoc_mac_policy(device),
2505 connman_device_get_random_mac_lifetime(device),
2506 #endif /* TIZEN_EXT */
2507 interface_create_callback,
2514 return -EINPROGRESS;
2517 static int wifi_disable(struct connman_device *device)
2519 struct wifi_data *wifi = connman_device_get_data(device);
2522 DBG("device %p wifi %p", device, wifi);
2527 wifi->connected = false;
2528 wifi->disconnecting = false;
2530 if (wifi->pending_network)
2531 wifi->pending_network = NULL;
2533 #if !defined TIZEN_EXT
2534 stop_autoscan(device);
2537 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_P2P)) {
2538 g_source_remove(wifi->p2p_find_timeout);
2539 wifi->p2p_find_timeout = 0;
2540 connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_P2P, false);
2541 connman_device_unref(wifi->device);
2544 #if defined TIZEN_EXT
2545 if (wifi->automaxspeed_timeout != 0) {
2546 g_source_remove(wifi->automaxspeed_timeout);
2547 wifi->automaxspeed_timeout = 0;
2551 /* In case of a user scan, device is still referenced */
2552 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI)) {
2553 connman_device_set_scanning(device,
2554 CONNMAN_SERVICE_TYPE_WIFI, false);
2555 connman_device_unref(wifi->device);
2558 #if defined TIZEN_EXT
2559 stop_autoscan(device);
2562 remove_networks(device, wifi);
2565 #if defined TIZEN_EXT
2566 wifi->scan_pending_network = NULL;
2568 if (is_wifi_notifier_registered == true) {
2569 connman_notifier_unregister(¬ifier);
2570 is_wifi_notifier_registered = false;
2574 ret = g_supplicant_interface_remove(wifi->interface, NULL, NULL);
2578 return -EINPROGRESS;
2581 static int get_latest_connections(int max_ssids,
2582 GSupplicantScanParams *scan_data)
2584 GSequenceIter *iter;
2585 GSequence *latest_list;
2586 struct last_connected *entry;
2595 latest_list = g_sequence_new(free_entry);
2599 services = connman_storage_get_services();
2600 for (i = 0; services && services[i]; i++) {
2601 if (strncmp(services[i], "wifi_", 5) != 0)
2604 keyfile = connman_storage_load_service(services[i]);
2608 str = g_key_file_get_string(keyfile,
2609 services[i], "Favorite", NULL);
2610 if (!str || g_strcmp0(str, "true")) {
2612 g_key_file_free(keyfile);
2617 str = g_key_file_get_string(keyfile,
2618 services[i], "AutoConnect", NULL);
2619 if (!str || g_strcmp0(str, "true")) {
2621 g_key_file_free(keyfile);
2626 str = g_key_file_get_string(keyfile,
2627 services[i], "Modified", NULL);
2629 g_key_file_free(keyfile);
2632 util_iso8601_to_timeval(str, &modified);
2635 ssid = g_key_file_get_string(keyfile,
2636 services[i], "SSID", NULL);
2638 freq = g_key_file_get_integer(keyfile, services[i],
2641 entry = g_try_new(struct last_connected, 1);
2643 g_sequence_free(latest_list);
2644 g_key_file_free(keyfile);
2646 #if defined TIZEN_EXT
2647 g_strfreev(services);
2653 entry->modified = modified;
2656 g_sequence_insert_sorted(latest_list, entry,
2662 g_key_file_free(keyfile);
2665 g_strfreev(services);
2667 num_ssids = num_ssids > max_ssids ? max_ssids : num_ssids;
2669 iter = g_sequence_get_begin_iter(latest_list);
2671 for (i = 0; i < num_ssids; i++) {
2672 entry = g_sequence_get(iter);
2674 DBG("ssid %s freq %d modified %lu", entry->ssid, entry->freq,
2675 entry->modified.tv_sec);
2677 add_scan_param(entry->ssid, NULL, 0, entry->freq, scan_data,
2678 max_ssids, entry->ssid);
2680 iter = g_sequence_iter_next(iter);
2683 g_sequence_free(latest_list);
2687 static void wifi_update_scanner_type(struct wifi_data *wifi,
2688 enum wifi_scanning_type new_type)
2692 if (!wifi || wifi->scanning_type == new_type)
2695 wifi->scanning_type = new_type;
2697 setup_autoscan(wifi);
2700 static int wifi_scan_simple(struct connman_device *device)
2702 struct wifi_data *wifi = connman_device_get_data(device);
2704 reset_autoscan(device);
2706 /* Distinguish between devices performing passive and active scanning */
2708 wifi_update_scanner_type(wifi, WIFI_SCANNING_PASSIVE);
2710 return throw_wifi_scan(device, scan_callback_hidden);
2713 static gboolean p2p_find_stop(gpointer data)
2715 struct connman_device *device = data;
2716 struct wifi_data *wifi = connman_device_get_data(device);
2721 wifi->p2p_find_timeout = 0;
2723 g_supplicant_interface_p2p_stop_find(wifi->interface);
2726 connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_P2P, false);
2728 connman_device_unref(device);
2729 start_autoscan(device);
2734 static void p2p_find_callback(int result, GSupplicantInterface *interface,
2737 struct connman_device *device = user_data;
2738 struct wifi_data *wifi = connman_device_get_data(device);
2740 DBG("result %d wifi %p", result, wifi);
2745 if (wifi->p2p_find_timeout) {
2746 g_source_remove(wifi->p2p_find_timeout);
2747 wifi->p2p_find_timeout = 0;
2753 wifi->p2p_find_timeout = g_timeout_add_seconds(P2P_FIND_TIMEOUT,
2754 p2p_find_stop, device);
2755 if (!wifi->p2p_find_timeout)
2760 p2p_find_stop(device);
2763 static int p2p_find(struct connman_device *device)
2765 struct wifi_data *wifi;
2770 if (!p2p_technology)
2773 wifi = connman_device_get_data(device);
2775 if (g_supplicant_interface_is_p2p_finding(wifi->interface))
2778 reset_autoscan(device);
2779 connman_device_ref(device);
2781 ret = g_supplicant_interface_p2p_find(wifi->interface,
2782 p2p_find_callback, device);
2784 connman_device_unref(device);
2785 start_autoscan(device);
2787 connman_device_set_scanning(device,
2788 CONNMAN_SERVICE_TYPE_P2P, true);
2794 #if defined TIZEN_EXT
2795 static void specific_scan_callback(int result, GSupplicantInterface *interface,
2798 struct connman_device *device = user_data;
2799 struct wifi_data *wifi = connman_device_get_data(device);
2802 DBG("result %d wifi %p", result, wifi);
2804 if (wifi && wifi->scan_params) {
2805 g_supplicant_free_scan_params(wifi->scan_params);
2806 wifi->scan_params = NULL;
2809 scanning = connman_device_get_scanning(device,
2810 CONNMAN_SERVICE_TYPE_WIFI);
2812 connman_device_set_scanning(device,
2813 CONNMAN_SERVICE_TYPE_WIFI, false);
2814 connman_device_unref(device);
2818 static int wifi_specific_scan(enum connman_service_type type,
2819 struct connman_device *device, int scan_type,
2820 GSList *specific_scan_list, void *user_data)
2822 GSList *list = NULL;
2824 struct wifi_data *wifi = connman_device_get_data(device);
2825 GSupplicantScanParams *scan_params = NULL;
2826 struct scan_ssid *scan_ssid = NULL;
2835 if (wifi->p2p_device)
2838 if (type == CONNMAN_SERVICE_TYPE_P2P)
2839 return p2p_find(device);
2841 if (wifi->tethering)
2845 connman_device_get_scanning(device,
2846 CONNMAN_SERVICE_TYPE_WIFI);
2850 DBG("scan_type: %d", scan_type);
2851 if (scan_type == CONNMAN_MULTI_SCAN_SSID) { /* ssid based scan */
2852 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2854 DBG("Failed to allocate memory.");
2858 for (list = specific_scan_list; list; list = list->next) {
2859 ssid = (char *)list->data;
2860 int ssid_len = strlen(ssid);
2862 scan_ssid = g_try_new0(struct scan_ssid, 1);
2864 DBG("Failed to allocate memory.");
2865 g_supplicant_free_scan_params(scan_params);
2869 memcpy(scan_ssid->ssid, ssid, (ssid_len + 1));
2870 /* DBG("scan ssid %s len: %d", scan_ssid->ssid, ssid_len); */
2871 scan_ssid->ssid_len = ssid_len;
2872 scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
2875 scan_params->num_ssids = count;
2877 } else if (scan_type == CONNMAN_MULTI_SCAN_FREQ) { /* frequency based scan */
2879 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2881 DBG("Failed to allocate memory.");
2885 guint num_freqs = g_slist_length(specific_scan_list);
2886 DBG("num_freqs: %d", num_freqs);
2888 scan_params->freqs = g_try_new0(uint16_t, num_freqs);
2889 if (!scan_params->freqs) {
2890 DBG("Failed to allocate memory.");
2891 g_free(scan_params);
2896 for (list = specific_scan_list; list; list = list->next) {
2897 freq = (int)list->data;
2899 scan_params->freqs[count] = freq;
2900 DBG("scan_params->freqs[%d]: %d", count, scan_params->freqs[count]);
2903 scan_params->num_freqs = count;
2905 } else if (scan_type == CONNMAN_MULTI_SCAN_SSID_FREQ) { /* SSID & Frequency mixed scan */
2906 int freq_count, ap_count;
2907 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
2909 DBG("Failed to allocate memory.");
2913 guint size = g_slist_length(specific_scan_list);
2915 scan_params->freqs = g_try_new0(uint16_t, size/2);
2916 if (!scan_params->freqs) {
2917 DBG("Failed to allocate memory.");
2918 g_free(scan_params);
2922 ap_count = freq_count = 0;
2923 for (list = specific_scan_list; list; list = list->next) {
2924 if (((connman_multi_scan_ap_s *)list->data)->flag == true) { /** ssid */
2925 ssid = ((connman_multi_scan_ap_s *)list->data)->str;
2926 int ssid_len = strlen(ssid);
2928 scan_ssid = g_try_new0(struct scan_ssid, 1);
2930 DBG("Failed to allocate memory.");
2931 g_supplicant_free_scan_params(scan_params);
2935 memcpy(scan_ssid->ssid, ssid, (ssid_len + 1));
2936 /* DBG("scan ssid %s len: %d", scan_ssid->ssid, ssid_len); */
2937 scan_ssid->ssid_len = ssid_len;
2938 scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
2942 freq = atoi(((connman_multi_scan_ap_s *)list->data)->str);
2943 scan_params->freqs[freq_count] = freq;
2944 DBG("scan_params->freqs[%d]: %d", freq_count, scan_params->freqs[freq_count]);
2948 scan_params->num_ssids = ap_count;
2949 scan_params->num_freqs = freq_count;
2951 DBG("Invalid scan");
2955 reset_autoscan(device);
2956 connman_device_ref(device);
2958 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
2959 specific_scan_callback, device);
2962 connman_device_set_scanning(device,
2963 CONNMAN_SERVICE_TYPE_WIFI, true);
2965 g_supplicant_free_scan_params(scan_params);
2966 connman_device_unref(device);
2972 static void wifi_mac_policy_callback(int result,
2973 unsigned int policy,
2976 struct connman_device *device = user_data;
2979 connman_device_mac_policy_notify(device, result, policy);
2981 connman_device_unref(device);
2984 int wifi_set_mac_policy(struct connman_device *device, unsigned int policy)
2986 struct wifi_data *wifi = connman_device_get_data(device);
2992 connman_device_ref(device);
2994 ret = g_supplicant_interface_set_mac_policy(wifi->interface,
2995 wifi_mac_policy_callback,
2998 connman_device_unref(device);
3003 static void wifi_preassoc_mac_policy_callback(int result,
3004 unsigned int policy,
3007 struct connman_device *device = user_data;
3010 connman_device_preassoc_mac_policy_notify(device, result, policy);
3012 connman_device_unref(device);
3015 int wifi_set_preassoc_mac_policy(struct connman_device *device, unsigned int policy)
3017 struct wifi_data *wifi = connman_device_get_data(device);
3023 connman_device_ref(device);
3025 ret = g_supplicant_interface_set_preassoc_mac_policy(wifi->interface,
3026 wifi_preassoc_mac_policy_callback,
3029 connman_device_unref(device);
3034 static void wifi_random_mac_lifetime_callback(int result,
3035 unsigned int lifetime,
3038 struct connman_device *device = user_data;
3041 connman_device_random_mac_lifetime_notify(device, result, lifetime);
3043 connman_device_unref(device);
3046 int wifi_set_random_mac_lifetime(struct connman_device *device, unsigned int lifetime)
3048 struct wifi_data *wifi = connman_device_get_data(device);
3054 connman_device_ref(device);
3056 ret = g_supplicant_interface_set_random_mac_lifetime(wifi->interface,
3057 wifi_random_mac_lifetime_callback,
3060 connman_device_unref(device);
3066 #if defined TIZEN_EXT_WIFI_MESH
3067 static void mesh_scan_callback(int result, GSupplicantInterface *interface,
3070 struct connman_device *device = user_data;
3071 struct wifi_data *wifi = connman_device_get_data(device);
3074 DBG("result %d wifi %p", result, wifi);
3076 scanning = connman_device_get_scanning(device,
3077 CONNMAN_SERVICE_TYPE_MESH);
3079 connman_device_set_scanning(device,
3080 CONNMAN_SERVICE_TYPE_MESH, false);
3083 connman_device_unref(device);
3086 static int mesh_scan(struct connman_device *device)
3088 struct wifi_data *wifi;
3089 struct wifi_mesh_info *mesh_info;
3094 wifi = connman_device_get_data(device);
3096 if (!wifi || !wifi->mesh_interface)
3099 mesh_info = wifi->mesh_info;
3100 reset_autoscan(device);
3101 connman_device_ref(device);
3103 ret = g_supplicant_interface_scan(mesh_info->interface, NULL,
3104 mesh_scan_callback, device);
3106 connman_device_unref(device);
3108 connman_device_set_scanning(device,
3109 CONNMAN_SERVICE_TYPE_MESH, true);
3114 static void abort_scan_callback(int result, GSupplicantInterface *interface,
3117 struct connman_device *device = user_data;
3118 struct wifi_data *wifi = connman_device_get_data(device);
3120 DBG("result %d wifi %p", result, wifi);
3122 __connman_technology_notify_abort_scan(CONNMAN_SERVICE_TYPE_MESH, result);
3125 static int mesh_abort_scan(enum connman_service_type type,
3126 struct connman_device *device)
3128 struct wifi_data *wifi = connman_device_get_data(device);
3129 struct wifi_mesh_info *mesh_info;
3133 if (!wifi || !wifi->mesh_interface)
3136 if (type != CONNMAN_SERVICE_TYPE_MESH)
3139 mesh_info = wifi->mesh_info;
3141 scanning = connman_device_get_scanning(device,
3142 CONNMAN_SERVICE_TYPE_MESH);
3146 ret = g_supplicant_interface_abort_scan(mesh_info->interface,
3147 abort_scan_callback, device);
3152 static int mesh_specific_scan(enum connman_service_type type,
3153 struct connman_device *device, const char *ssid,
3154 unsigned int freq, void *user_data)
3156 struct wifi_data *wifi = connman_device_get_data(device);
3157 GSupplicantScanParams *scan_params = NULL;
3158 struct wifi_mesh_info *mesh_info;
3159 struct scan_ssid *scan_ssid;
3163 if (!wifi || !wifi->mesh_interface)
3166 if (type != CONNMAN_SERVICE_TYPE_MESH)
3169 if (wifi->p2p_device)
3172 mesh_info = wifi->mesh_info;
3174 scanning = connman_device_get_scanning(device,
3175 CONNMAN_SERVICE_TYPE_MESH);
3179 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
3183 scan_ssid = g_try_new(struct scan_ssid, 1);
3185 g_free(scan_params);
3189 scan_ssid->ssid_len = strlen(ssid);
3190 memcpy(scan_ssid->ssid, ssid, scan_ssid->ssid_len);
3191 scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
3192 scan_params->num_ssids = 1;
3194 scan_params->freqs = g_try_new(uint16_t, 1);
3195 if (!scan_params->freqs) {
3196 g_slist_free_full(scan_params->ssids, g_free);
3197 g_free(scan_params);
3201 scan_params->freqs[0] = freq;
3202 scan_params->num_freqs = 1;
3204 reset_autoscan(device);
3205 connman_device_ref(device);
3207 ret = g_supplicant_interface_scan(mesh_info->interface, scan_params,
3208 mesh_scan_callback, device);
3211 connman_device_set_scanning(device,
3212 CONNMAN_SERVICE_TYPE_MESH, true);
3214 g_supplicant_free_scan_params(scan_params);
3215 connman_device_unref(device);
3223 * Note that the hidden scan is only used when connecting to this specific
3224 * hidden AP first time. It is not used when system autoconnects to hidden AP.
3226 static int wifi_scan(struct connman_device *device,
3227 struct connman_device_scan_params *params)
3229 struct wifi_data *wifi = connman_device_get_data(device);
3230 GSupplicantScanParams *scan_params = NULL;
3231 struct scan_ssid *scan_ssid;
3232 struct hidden_params *hidden;
3234 int driver_max_ssids = 0;
3241 if (wifi->p2p_device)
3244 if (wifi->tethering)
3247 if (params->type == CONNMAN_SERVICE_TYPE_P2P)
3248 return p2p_find(device);
3250 #if defined TIZEN_EXT_WIFI_MESH
3251 if (params->type == CONNMAN_SERVICE_TYPE_MESH)
3252 return mesh_scan(device);
3255 DBG("device %p wifi %p hidden ssid %s", device, wifi->interface,
3258 scanning = connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI);
3260 if (!params->ssid || params->ssid_len == 0 || params->ssid_len > 32) {
3264 driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
3266 DBG("max ssids %d", driver_max_ssids);
3267 if (driver_max_ssids == 0)
3268 return wifi_scan_simple(device);
3272 if (scanning && wifi->hidden && wifi->postpone_hidden)
3278 scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
3283 scan_ssid = g_try_new(struct scan_ssid, 1);
3285 g_free(scan_params);
3289 memcpy(scan_ssid->ssid, params->ssid, params->ssid_len);
3290 scan_ssid->ssid_len = params->ssid_len;
3291 scan_params->ssids = g_slist_prepend(scan_params->ssids,
3293 scan_params->num_ssids = 1;
3295 hidden = g_try_new0(struct hidden_params, 1);
3297 g_supplicant_free_scan_params(scan_params);
3302 hidden_free(wifi->hidden);
3303 wifi->hidden = NULL;
3306 memcpy(hidden->ssid, params->ssid, params->ssid_len);
3307 hidden->ssid_len = params->ssid_len;
3308 hidden->identity = g_strdup(params->identity);
3309 hidden->passphrase = g_strdup(params->passphrase);
3310 hidden->security = g_strdup(params->security);
3311 hidden->user_data = params->user_data;
3312 wifi->hidden = hidden;
3315 /* Let's keep this active scan for later,
3316 * when current scan will be over. */
3317 wifi->postpone_hidden = TRUE;
3318 hidden->scan_params = scan_params;
3322 } else if (wifi->connected) {
3323 g_supplicant_free_scan_params(scan_params);
3324 return wifi_scan_simple(device);
3325 } else if (!params->force_full_scan) {
3326 ret = get_latest_connections(driver_max_ssids, scan_params);
3328 g_supplicant_free_scan_params(scan_params);
3329 return wifi_scan_simple(device);
3333 /* Distinguish between devices performing passive and active scanning */
3334 wifi_update_scanner_type(wifi, WIFI_SCANNING_ACTIVE);
3336 connman_device_ref(device);
3338 reset_autoscan(device);
3339 #if defined TIZEN_EXT
3341 * When doing a full scan, stored hidden networks also need to be scanned
3342 * so that we can autoconnect to them.
3344 if (params->force_full_scan)
3345 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
3346 scan_callback_hidden, device);
3349 ret = g_supplicant_interface_scan(wifi->interface, scan_params,
3350 scan_callback, device);
3352 connman_device_set_scanning(device,
3353 CONNMAN_SERVICE_TYPE_WIFI, true);
3354 #if defined TIZEN_EXT
3356 * To allow the Full Scan after ssid based scan, set the flag here
3357 * It is required because Tizen does not use the ConnMan specific
3358 * backgroung Scan feature.Tizen has added the BG Scan feature in
3359 * net-config. To sync with up ConnMan, we need to issue the Full Scan
3360 * after SSID specific scan.
3362 if (!params->force_full_scan && !do_hidden)
3363 wifi->allow_full_scan = TRUE;
3366 g_supplicant_free_scan_params(scan_params);
3367 connman_device_unref(device);
3370 hidden_free(wifi->hidden);
3371 wifi->hidden = NULL;
3378 static void wifi_stop_scan(enum connman_service_type type,
3379 struct connman_device *device)
3381 struct wifi_data *wifi = connman_device_get_data(device);
3383 DBG("device %p wifi %p", device, wifi);
3388 if (type == CONNMAN_SERVICE_TYPE_P2P) {
3389 if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_P2P)) {
3390 g_source_remove(wifi->p2p_find_timeout);
3391 p2p_find_stop(device);
3396 static void wifi_regdom_callback(int result,
3400 struct connman_device *device = user_data;
3402 connman_device_regdom_notify(device, result, alpha2);
3404 connman_device_unref(device);
3407 static int wifi_set_regdom(struct connman_device *device, const char *alpha2)
3409 struct wifi_data *wifi = connman_device_get_data(device);
3415 connman_device_ref(device);
3417 ret = g_supplicant_interface_set_country(wifi->interface,
3418 wifi_regdom_callback,
3421 connman_device_unref(device);
3426 static struct connman_device_driver wifi_ng_driver = {
3428 .type = CONNMAN_DEVICE_TYPE_WIFI,
3429 .priority = CONNMAN_DEVICE_PRIORITY_LOW,
3430 .probe = wifi_probe,
3431 .remove = wifi_remove,
3432 .enable = wifi_enable,
3433 .disable = wifi_disable,
3435 .stop_scan = wifi_stop_scan,
3436 .set_regdom = wifi_set_regdom,
3437 #if defined TIZEN_EXT
3438 .specific_scan = wifi_specific_scan,
3439 .set_mac_policy = wifi_set_mac_policy,
3440 .set_preassoc_mac_policy = wifi_set_preassoc_mac_policy,
3441 .set_random_mac_lifetime = wifi_set_random_mac_lifetime,
3443 #if defined TIZEN_EXT_WIFI_MESH
3444 .abort_scan = mesh_abort_scan,
3445 .mesh_specific_scan = mesh_specific_scan,
3449 static void system_ready(void)
3453 if (connman_device_driver_register(&wifi_ng_driver) < 0)
3454 connman_error("Failed to register WiFi driver");
3457 static void system_killed(void)
3461 connman_device_driver_unregister(&wifi_ng_driver);
3464 static int network_probe(struct connman_network *network)
3466 #if defined TIZEN_EXT
3467 if (!simplified_log)
3469 DBG("network %p", network);
3474 static void network_remove(struct connman_network *network)
3476 struct connman_device *device = connman_network_get_device(network);
3477 struct wifi_data *wifi;
3479 DBG("network %p", network);
3481 wifi = connman_device_get_data(device);
3485 if (wifi->network != network)
3488 wifi->network = NULL;
3490 #if defined TIZEN_EXT
3491 wifi->disconnecting = false;
3493 if (wifi->pending_network == network)
3494 wifi->pending_network = NULL;
3496 if (wifi->scan_pending_network == network)
3497 wifi->scan_pending_network = NULL;
3501 static void connect_callback(int result, GSupplicantInterface *interface,
3504 #if defined TIZEN_EXT
3506 struct wifi_data *wifi;
3508 struct connman_network *network = user_data;
3510 DBG("network %p result %d", network, result);
3512 #if defined TIZEN_EXT
3513 const char *ifname = g_supplicant_interface_get_ifname(interface);
3514 set_connman_bssid(RESET_BSSID, NULL, ifname);
3516 for (list = iface_list; list; list = list->next) {
3519 if (wifi && wifi->network == network)
3523 /* wifi_data may be invalid because wifi is already disabled */
3528 if (result == -ENOKEY) {
3529 connman_network_set_error(network,
3530 CONNMAN_NETWORK_ERROR_INVALID_KEY);
3531 } else if (result < 0) {
3532 connman_network_set_error(network,
3533 CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
3536 connman_network_unref(network);
3539 static GSupplicantSecurity network_security(const char *security)
3541 if (g_str_equal(security, "none"))
3542 return G_SUPPLICANT_SECURITY_NONE;
3543 else if (g_str_equal(security, "wep"))
3544 return G_SUPPLICANT_SECURITY_WEP;
3545 else if (g_str_equal(security, "psk"))
3546 return G_SUPPLICANT_SECURITY_PSK;
3547 else if (g_str_equal(security, "wpa"))
3548 return G_SUPPLICANT_SECURITY_PSK;
3549 else if (g_str_equal(security, "rsn"))
3550 return G_SUPPLICANT_SECURITY_PSK;
3551 else if (g_str_equal(security, "ieee8021x"))
3552 return G_SUPPLICANT_SECURITY_IEEE8021X;
3553 #if defined TIZEN_EXT
3554 else if (g_str_equal(security, "ft_psk") == TRUE)
3555 return G_SUPPLICANT_SECURITY_FT_PSK;
3556 else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
3557 return G_SUPPLICANT_SECURITY_FT_IEEE8021X;
3558 else if (g_str_equal(security, "sae"))
3559 return G_SUPPLICANT_SECURITY_SAE;
3560 else if (g_str_equal(security, "owe"))
3561 return G_SUPPLICANT_SECURITY_OWE;
3562 else if (g_str_equal(security, "dpp"))
3563 return G_SUPPLICANT_SECURITY_DPP;
3566 return G_SUPPLICANT_SECURITY_UNKNOWN;
3569 #if defined TIZEN_EXT
3570 static GSupplicantEapKeymgmt network_eap_keymgmt(const char *security)
3572 if (security == NULL)
3573 return G_SUPPLICANT_EAP_KEYMGMT_NONE;
3575 if (g_str_equal(security, "FT") == TRUE)
3576 return G_SUPPLICANT_EAP_KEYMGMT_FT;
3577 else if (g_str_equal(security, "CCKM") == TRUE)
3578 return G_SUPPLICANT_EAP_KEYMGMT_CCKM;
3580 return G_SUPPLICANT_EAP_KEYMGMT_NONE;
3584 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
3586 const char *security;
3587 #if defined TIZEN_EXT
3588 const void *ssid_data;
3591 memset(ssid, 0, sizeof(*ssid));
3592 ssid->mode = G_SUPPLICANT_MODE_INFRA;
3593 #if defined TIZEN_EXT
3594 ssid_data = connman_network_get_blob(network, "WiFi.SSID",
3596 ssid->ssid = g_try_malloc0(ssid->ssid_len);
3601 memcpy(ssid->ssid, ssid_data, ssid->ssid_len);
3603 ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
3606 ssid->scan_ssid = 1;
3607 security = connman_network_get_string(network, "WiFi.Security");
3608 ssid->security = network_security(security);
3609 #if defined TIZEN_EXT
3610 ssid->ieee80211w = 1;
3612 ssid->passphrase = connman_network_get_string(network,
3615 ssid->eap = connman_network_get_string(network, "WiFi.EAP");
3618 * If our private key password is unset,
3619 * we use the supplied passphrase. That is needed
3620 * for PEAP where 2 passphrases (identity and client
3621 * cert may have to be provided.
3623 if (!connman_network_get_string(network, "WiFi.PrivateKeyPassphrase"))
3624 connman_network_set_string(network,
3625 "WiFi.PrivateKeyPassphrase",
3627 /* We must have an identity for both PEAP and TLS */
3628 ssid->identity = connman_network_get_string(network, "WiFi.Identity");
3630 /* Use agent provided identity as a fallback */
3631 if (!ssid->identity || strlen(ssid->identity) == 0)
3632 ssid->identity = connman_network_get_string(network,
3633 "WiFi.AgentIdentity");
3635 ssid->anonymous_identity = connman_network_get_string(network,
3636 "WiFi.AnonymousIdentity");
3637 ssid->ca_cert_path = connman_network_get_string(network,
3639 ssid->subject_match = connman_network_get_string(network,
3640 "WiFi.SubjectMatch");
3641 ssid->altsubject_match = connman_network_get_string(network,
3642 "WiFi.AltSubjectMatch");
3643 ssid->domain_suffix_match = connman_network_get_string(network,
3644 "WiFi.DomainSuffixMatch");
3645 ssid->domain_match = connman_network_get_string(network,
3646 "WiFi.DomainMatch");
3647 ssid->client_cert_path = connman_network_get_string(network,
3648 "WiFi.ClientCertFile");
3649 ssid->private_key_path = connman_network_get_string(network,
3650 "WiFi.PrivateKeyFile");
3651 ssid->private_key_passphrase = connman_network_get_string(network,
3652 "WiFi.PrivateKeyPassphrase");
3653 ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
3655 ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
3656 ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
3657 #if defined TIZEN_EXT
3658 ssid->connector = connman_network_get_string(network,
3660 ssid->c_sign_key = connman_network_get_string(network,
3662 ssid->net_access_key = connman_network_get_string(network,
3663 "WiFi.NetAccessKey");
3666 #if defined TIZEN_EXT
3667 const char *ifname = connman_device_get_string(
3668 connman_network_get_device(network), "Interface");
3669 if (set_connman_bssid(CHECK_BSSID, NULL, ifname) == 6) {
3670 ssid->bssid_for_connect_len = 6;
3671 set_connman_bssid(GET_BSSID, (char *)ssid->bssid_for_connect, ifname);
3672 DBG("BSSID : %02x:%02x:%02x:%02x:%02x:%02x",
3673 ssid->bssid_for_connect[0], ssid->bssid_for_connect[1],
3674 ssid->bssid_for_connect[2], ssid->bssid_for_connect[3],
3675 ssid->bssid_for_connect[4], ssid->bssid_for_connect[5]);
3677 ssid->freq = connman_network_get_frequency(network);
3680 GSList *bssid_list = (GSList *)connman_network_get_bssid_list(network);
3681 if (bssid_list && g_slist_length(bssid_list) > 1) {
3683 /* If there are more than one bssid,
3684 * the user-specified bssid is tried only once at the beginning.
3685 * After that, the bssids in the list are tried in order.
3687 if (set_connman_bssid(CHECK_BSSID, NULL, ifname) == 6) {
3688 set_connman_bssid(RESET_BSSID, NULL, ifname);
3693 char buff[MAC_ADDRESS_LENGTH];
3694 for (list = bssid_list; list; list = list->next) {
3695 struct connman_bssids * bssids = (struct connman_bssids *)list->data;
3697 g_snprintf(buff, MAC_ADDRESS_LENGTH, "%02x:%02x:%02x:%02x:%02x:%02x",
3698 bssids->bssid[0], bssids->bssid[1], bssids->bssid[2],
3699 bssids->bssid[3], bssids->bssid[4], bssids->bssid[5]);
3700 buff[MAC_ADDRESS_LENGTH - 1] = '\0';
3702 gchar *curr_bssid = g_strdup((const gchar *)buff);
3704 if (g_hash_table_contains(failed_bssids, curr_bssid)) {
3705 DBG("bssid match, try next bssid");
3709 g_hash_table_add(failed_bssids, curr_bssid);
3711 memcpy(buff_bssid, bssids->bssid, WIFI_BSSID_LEN_MAX);
3712 ssid->bssid = buff_bssid;
3713 ssid->freq = (unsigned int)bssids->frequency;
3719 ssid->bssid = connman_network_get_bssid(network);
3720 g_hash_table_remove_all(failed_bssids);
3723 ssid->bssid = connman_network_get_bssid(network);
3726 ssid->eap_keymgmt = network_eap_keymgmt(
3727 connman_network_get_string(network, "WiFi.KeymgmtType"));
3728 ssid->phase1 = connman_network_get_string(network, "WiFi.Phase1");
3730 if(g_strcmp0(ssid->eap, "fast") == 0)
3731 ssid->pac_file = g_strdup(WIFI_EAP_FAST_PAC_FILE);
3733 ssid->keymgmt = connman_network_get_keymgmt(network);
3736 if (connman_setting_get_bool("BackgroundScanning"))
3737 ssid->bgscan = BGSCAN_DEFAULT;
3740 static int network_connect(struct connman_network *network)
3742 struct connman_device *device = connman_network_get_device(network);
3743 struct wifi_data *wifi;
3744 GSupplicantInterface *interface;
3745 GSupplicantSSID *ssid;
3747 DBG("network %p", network);
3752 wifi = connman_device_get_data(device);
3756 ssid = g_try_malloc0(sizeof(GSupplicantSSID));
3760 interface = wifi->interface;
3762 ssid_init(ssid, network);
3764 if (wifi->disconnecting) {
3765 wifi->pending_network = network;
3766 #if defined TIZEN_EXT
3771 wifi->network = connman_network_ref(network);
3773 #if defined TIZEN_EXT
3774 wifi->scan_pending_network = NULL;
3777 return g_supplicant_interface_connect(interface, ssid,
3778 connect_callback, network);
3781 return -EINPROGRESS;
3784 static void disconnect_callback(int result, GSupplicantInterface *interface,
3787 #if defined TIZEN_EXT
3789 struct wifi_data *wifi;
3790 struct connman_network *network = user_data;
3792 DBG("network %p result %d", network, result);
3794 for (list = iface_list; list; list = list->next) {
3797 if (wifi->network == NULL && wifi->disconnecting == true)
3798 wifi->disconnecting = false;
3800 if (wifi->network == network)
3804 /* wifi_data may be invalid because wifi is already disabled */
3809 struct wifi_data *wifi = user_data;
3812 DBG("result %d supplicant interface %p wifi %p",
3813 result, interface, wifi);
3815 if (result == -ECONNABORTED) {
3816 DBG("wifi interface no longer available");
3820 if (wifi->network && wifi->network != wifi->pending_network)
3821 connman_network_set_connected(wifi->network, false);
3822 wifi->network = NULL;
3824 wifi->disconnecting = false;
3825 wifi->connected = false;
3827 if (wifi->pending_network) {
3828 network_connect(wifi->pending_network);
3829 wifi->pending_network = NULL;
3832 start_autoscan(wifi->device);
3835 static int network_disconnect(struct connman_network *network)
3837 struct connman_device *device = connman_network_get_device(network);
3838 struct wifi_data *wifi;
3840 #if defined TIZEN_EXT
3841 struct connman_service *service;
3844 DBG("network %p", network);
3846 wifi = connman_device_get_data(device);
3847 if (!wifi || !wifi->interface)
3850 #if defined TIZEN_EXT
3851 if (connman_network_get_associating(network) == true) {
3852 connman_network_clear_associating(network);
3853 connman_network_set_bool(network, "WiFi.UseWPS", false);
3855 service = connman_service_lookup_from_network(network);
3857 if (service != NULL &&
3858 (__connman_service_is_connected_state(service,
3859 CONNMAN_IPCONFIG_TYPE_IPV4) == false &&
3860 __connman_service_is_connected_state(service,
3861 CONNMAN_IPCONFIG_TYPE_IPV6) == false) &&
3862 (connman_service_get_favorite(service) == false))
3863 __connman_service_set_passphrase(service, NULL);
3866 if (wifi->pending_network == network)
3867 wifi->pending_network = NULL;
3869 if (wifi->scan_pending_network == network)
3870 wifi->scan_pending_network = NULL;
3873 connman_network_set_associating(network, false);
3875 if (wifi->disconnecting)
3878 wifi->disconnecting = true;
3880 #if defined TIZEN_EXT
3881 err = g_supplicant_interface_disconnect(wifi->interface,
3882 disconnect_callback, network);
3884 err = g_supplicant_interface_disconnect(wifi->interface,
3885 disconnect_callback, wifi);
3889 wifi->disconnecting = false;
3894 #if defined TIZEN_EXT
3895 static void set_connection_mode(struct connman_network *network,
3898 ieee80211_modes_e phy_mode;
3899 connection_mode_e conn_mode;
3901 phy_mode = connman_network_get_phy_mode(network);
3903 case IEEE80211_MODE_B:
3904 if (linkspeed > 0 && linkspeed <= 11)
3905 conn_mode = CONNECTION_MODE_IEEE80211B;
3907 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3910 case IEEE80211_MODE_BG:
3911 if (linkspeed > 0 && linkspeed <= 11)
3912 conn_mode = CONNECTION_MODE_IEEE80211B;
3913 else if (linkspeed > 11 && linkspeed <= 54)
3914 conn_mode = CONNECTION_MODE_IEEE80211G;
3916 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3919 case IEEE80211_MODE_BGN:
3920 if (linkspeed > 0 && linkspeed <= 11)
3921 conn_mode = CONNECTION_MODE_IEEE80211B;
3922 else if (linkspeed > 11 && linkspeed <= 54)
3923 conn_mode = CONNECTION_MODE_IEEE80211G;
3924 else if (linkspeed > 54 && linkspeed <= 450)
3925 conn_mode = CONNECTION_MODE_IEEE80211N;
3927 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3930 case IEEE80211_MODE_A:
3931 if (linkspeed > 0 && linkspeed <= 54)
3932 conn_mode = CONNECTION_MODE_IEEE80211A;
3934 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3937 case IEEE80211_MODE_AN:
3938 if (linkspeed > 0 && linkspeed <= 54)
3939 conn_mode = CONNECTION_MODE_IEEE80211A;
3940 else if (linkspeed > 54 && linkspeed <= 450)
3941 conn_mode = CONNECTION_MODE_IEEE80211N;
3943 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3946 case IEEE80211_MODE_ANAC:
3947 if (linkspeed > 0 && linkspeed <= 54)
3948 conn_mode = CONNECTION_MODE_IEEE80211A;
3949 else if (linkspeed > 54 && linkspeed <= 450)
3950 conn_mode = CONNECTION_MODE_IEEE80211N;
3951 else if (linkspeed > 450 && linkspeed <= 1300)
3952 conn_mode = CONNECTION_MODE_IEEE80211AC;
3954 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3958 conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
3962 DBG("connection mode(%d)", conn_mode);
3963 connman_network_set_connection_mode(network, conn_mode);
3966 static void signalpoll_callback(int result, int maxspeed, int strength,
3969 struct connman_network *network = user_data;
3972 DBG("Failed to get maxspeed from signalpoll !");
3973 connman_network_unref(network);
3981 DBG("maxspeed = %d, strength = %d", maxspeed, strength);
3983 connman_network_set_strength(network, (uint8_t)strength);
3984 connman_network_set_maxspeed(network, maxspeed);
3985 set_connection_mode(network, maxspeed);
3987 connman_network_unref(network);
3990 static int network_signalpoll(struct wifi_data *wifi)
3992 GSupplicantInterface *interface;
3993 struct connman_network *network;
3995 if (!wifi || !wifi->network)
3998 wifi->network = connman_network_ref(wifi->network);
4000 interface = wifi->interface;
4001 network = wifi->network;
4003 DBG("network %p", network);
4005 return g_supplicant_interface_signalpoll(interface, signalpoll_callback, network);
4008 static gboolean autosignalpoll_timeout(gpointer data)
4010 struct wifi_data *wifi = data;
4012 if (!wifi || !wifi->automaxspeed_timeout) {
4013 DBG("automaxspeed_timeout is found to be zero. i.e. currently in disconnected state. !!");
4017 int ret = network_signalpoll(wifi);
4019 DBG("Fail to get max speed !!");
4020 wifi->automaxspeed_timeout = 0;
4023 connman_network_unref(wifi->network);
4031 static struct connman_network_driver network_driver = {
4033 .type = CONNMAN_NETWORK_TYPE_WIFI,
4034 .priority = CONNMAN_NETWORK_PRIORITY_LOW,
4035 .probe = network_probe,
4036 .remove = network_remove,
4037 .connect = network_connect,
4038 .disconnect = network_disconnect,
4041 static void interface_added(GSupplicantInterface *interface)
4043 const char *ifname = g_supplicant_interface_get_ifname(interface);
4044 const char *driver = g_supplicant_interface_get_driver(interface);
4045 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4047 * Note: If supplicant interface's driver is wired then skip it,
4048 * because it meanti only for ethernet not Wi-Fi.
4050 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4052 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4054 #if defined TIZEN_EXT
4055 bool is_5_0_ghz_supported = g_supplicant_interface_get_is_5_0_ghz_supported(interface);
4058 struct wifi_data *wifi;
4060 wifi = g_supplicant_interface_get_data(interface);
4062 wifi = get_pending_wifi_data(ifname);
4066 wifi->interface = interface;
4067 g_supplicant_interface_set_data(interface, wifi);
4068 p2p_iface_list = g_list_append(p2p_iface_list, wifi);
4069 wifi->p2p_device = true;
4072 DBG("ifname %s driver %s wifi %p tethering %d",
4073 ifname, driver, wifi, wifi->tethering);
4075 if (!wifi->device) {
4076 connman_error("WiFi device not set");
4080 connman_device_set_powered(wifi->device, true);
4081 #if defined TIZEN_EXT
4082 connman_device_set_wifi_5ghz_supported(wifi->device, is_5_0_ghz_supported);
4083 /* Max number of SSIDs supported by wlan chipset that can be scanned */
4084 int max_scan_ssids = g_supplicant_interface_get_max_scan_ssids(interface);
4085 connman_device_set_max_scan_ssids(wifi->device, max_scan_ssids);
4089 static bool is_idle(struct wifi_data *wifi)
4091 DBG("state %d", wifi->state);
4093 switch (wifi->state) {
4094 case G_SUPPLICANT_STATE_UNKNOWN:
4095 case G_SUPPLICANT_STATE_DISABLED:
4096 case G_SUPPLICANT_STATE_DISCONNECTED:
4097 case G_SUPPLICANT_STATE_INACTIVE:
4098 case G_SUPPLICANT_STATE_SCANNING:
4101 case G_SUPPLICANT_STATE_AUTHENTICATING:
4102 case G_SUPPLICANT_STATE_ASSOCIATING:
4103 case G_SUPPLICANT_STATE_ASSOCIATED:
4104 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4105 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4106 case G_SUPPLICANT_STATE_COMPLETED:
4113 static bool is_idle_wps(GSupplicantInterface *interface,
4114 struct wifi_data *wifi)
4116 /* First, let's check if WPS processing did not went wrong */
4117 if (g_supplicant_interface_get_wps_state(interface) ==
4118 G_SUPPLICANT_WPS_STATE_FAIL)
4121 /* Unlike normal connection, being associated while processing wps
4122 * actually means that we are idling. */
4123 switch (wifi->state) {
4124 case G_SUPPLICANT_STATE_UNKNOWN:
4125 case G_SUPPLICANT_STATE_DISABLED:
4126 case G_SUPPLICANT_STATE_DISCONNECTED:
4127 case G_SUPPLICANT_STATE_INACTIVE:
4128 case G_SUPPLICANT_STATE_SCANNING:
4129 case G_SUPPLICANT_STATE_ASSOCIATED:
4131 case G_SUPPLICANT_STATE_AUTHENTICATING:
4132 case G_SUPPLICANT_STATE_ASSOCIATING:
4133 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4134 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4135 case G_SUPPLICANT_STATE_COMPLETED:
4142 static bool handle_wps_completion(GSupplicantInterface *interface,
4143 struct connman_network *network,
4144 struct connman_device *device,
4145 struct wifi_data *wifi)
4149 wps = connman_network_get_bool(network, "WiFi.UseWPS");
4151 const unsigned char *ssid, *wps_ssid;
4152 unsigned int ssid_len, wps_ssid_len;
4153 const char *wps_key;
4155 /* Checking if we got associated with requested
4157 ssid = connman_network_get_blob(network, "WiFi.SSID",
4160 wps_ssid = g_supplicant_interface_get_wps_ssid(
4161 interface, &wps_ssid_len);
4163 if (!wps_ssid || wps_ssid_len != ssid_len ||
4164 memcmp(ssid, wps_ssid, ssid_len) != 0) {
4165 connman_network_set_associating(network, false);
4166 #if defined TIZEN_EXT
4167 g_supplicant_interface_disconnect(wifi->interface,
4168 disconnect_callback, wifi->network);
4170 connman_network_set_bool(network, "WiFi.UseWPS", false);
4171 connman_network_set_string(network, "WiFi.PinWPS", NULL);
4173 g_supplicant_interface_disconnect(wifi->interface,
4174 disconnect_callback, wifi);
4179 wps_key = g_supplicant_interface_get_wps_key(interface);
4180 #if defined TIZEN_EXT
4181 /* Check the passphrase and encrypt it
4184 gchar *passphrase = g_strdup(wps_key);
4186 connman_network_set_string(network, "WiFi.PinWPS", NULL);
4188 if (check_passphrase_ext(network, passphrase) < 0) {
4189 DBG("[WPS] Invalid passphrase");
4194 ret = send_encryption_request(passphrase, network);
4199 DBG("[WPS] Encryption request succeeded");
4201 DBG("[WPS] Encryption request failed %d", ret);
4204 connman_network_set_string(network, "WiFi.Passphrase",
4207 connman_network_set_string(network, "WiFi.PinWPS", NULL);
4214 static bool handle_assoc_status_code(GSupplicantInterface *interface,
4215 struct wifi_data *wifi)
4217 if (wifi->state == G_SUPPLICANT_STATE_ASSOCIATING &&
4218 #if defined TIZEN_EXT
4219 wifi->assoc_code > 0 &&
4221 wifi->assoc_code == ASSOC_STATUS_NO_CLIENT &&
4223 wifi->load_shaping_retries < LOAD_SHAPING_MAX_RETRIES) {
4224 wifi->load_shaping_retries ++;
4227 wifi->load_shaping_retries = 0;
4231 static bool handle_4way_handshake_failure(GSupplicantInterface *interface,
4232 struct connman_network *network,
4233 struct wifi_data *wifi)
4235 #if defined TIZEN_EXT
4236 const char *security;
4237 struct connman_service *service;
4239 if (wifi->connected)
4242 security = connman_network_get_string(network, "WiFi.Security");
4244 if (security && g_str_equal(security, "ieee8021x") == true &&
4245 wifi->state == G_SUPPLICANT_STATE_ASSOCIATED) {
4247 connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
4252 if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
4255 struct connman_service *service;
4257 if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
4260 if (wifi->connected)
4264 service = connman_service_lookup_from_network(network);
4270 if (connman_service_get_favorite(service)) {
4271 if (wifi->retries < FAVORITE_MAXIMUM_RETRIES)
4276 connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
4281 #if defined TIZEN_EXT
4282 static bool handle_wifi_assoc_retry(struct connman_network *network,
4283 struct wifi_data *wifi)
4285 const char *security;
4287 if (!wifi->network || wifi->connected || wifi->disconnecting ||
4288 connman_network_get_connecting(network) != true) {
4289 wifi->assoc_retry_count = 0;
4293 if (wifi->state != G_SUPPLICANT_STATE_ASSOCIATING &&
4294 wifi->state != G_SUPPLICANT_STATE_ASSOCIATED) {
4295 wifi->assoc_retry_count = 0;
4299 security = connman_network_get_string(network, "WiFi.Security");
4300 if (security && g_str_equal(security, "ieee8021x") == true &&
4301 wifi->state == G_SUPPLICANT_STATE_ASSOCIATED) {
4302 wifi->assoc_retry_count = 0;
4306 if (++wifi->assoc_retry_count >= TIZEN_ASSOC_RETRY_COUNT) {
4307 wifi->assoc_retry_count = 0;
4309 /* Honestly it's not an invalid-key error,
4310 * however QA team recommends that the invalid-key error
4311 * might be better to display for user experience.
4313 connman_network_set_error(network, CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
4322 static void interface_state(GSupplicantInterface *interface)
4324 struct connman_network *network;
4325 struct connman_device *device;
4326 struct wifi_data *wifi;
4327 GSupplicantState state = g_supplicant_interface_get_state(interface);
4328 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4330 * Note: If supplicant interface's driver is wired then skip it,
4331 * because it meanti only for ethernet not Wi-Fi.
4333 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4335 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4340 wifi = g_supplicant_interface_get_data(interface);
4342 DBG("wifi %p interface state %d", wifi, state);
4347 device = wifi->device;
4351 if (state == G_SUPPLICANT_STATE_COMPLETED) {
4352 if (wifi->tethering_param) {
4353 g_free(wifi->tethering_param->ssid);
4354 g_free(wifi->tethering_param);
4355 wifi->tethering_param = NULL;
4358 if (wifi->tethering)
4359 stop_autoscan(device);
4362 if (g_supplicant_interface_get_ready(interface) &&
4363 !wifi->interface_ready) {
4364 wifi->interface_ready = true;
4365 finalize_interface_creation(wifi);
4368 network = wifi->network;
4373 case G_SUPPLICANT_STATE_SCANNING:
4374 if (wifi->connected)
4375 connman_network_set_connected(network, false);
4379 case G_SUPPLICANT_STATE_AUTHENTICATING:
4380 case G_SUPPLICANT_STATE_ASSOCIATING:
4381 #if defined TIZEN_EXT
4382 reset_autoscan(device);
4384 stop_autoscan(device);
4387 if (!wifi->connected)
4388 connman_network_set_associating(network, true);
4392 case G_SUPPLICANT_STATE_COMPLETED:
4393 #if defined TIZEN_EXT
4394 /* though it should be already reset: */
4395 reset_autoscan(device);
4397 wifi->assoc_retry_count = 0;
4399 wifi->scan_pending_network = NULL;
4401 /* should be cleared scanning flag */
4402 bool scanning = connman_device_get_scanning(device,
4403 CONNMAN_SERVICE_TYPE_WIFI);
4405 connman_device_set_scanning(device,
4406 CONNMAN_SERVICE_TYPE_WIFI, false);
4407 connman_device_unref(device);
4410 if (!wifi->automaxspeed_timeout) {
4411 DBG("Going to start signalpoll timer!!");
4412 int ret = network_signalpoll(wifi);
4414 DBG("Fail to get max speed !!");
4416 wifi->automaxspeed_timeout = g_timeout_add_seconds(10, autosignalpoll_timeout, wifi);
4419 g_hash_table_remove_all(failed_bssids);
4421 /* though it should be already stopped: */
4422 stop_autoscan(device);
4425 if (!handle_wps_completion(interface, network, device, wifi))
4428 connman_network_set_connected(network, true);
4430 wifi->disconnect_code = 0;
4431 wifi->assoc_code = 0;
4432 wifi->load_shaping_retries = 0;
4435 case G_SUPPLICANT_STATE_DISCONNECTED:
4436 #if defined TIZEN_EXT
4437 connman_network_set_strength(network, 0);
4438 connman_network_set_maxspeed(network, 0);
4440 if (wifi->automaxspeed_timeout != 0) {
4441 g_source_remove(wifi->automaxspeed_timeout);
4442 wifi->automaxspeed_timeout = 0;
4443 DBG("Remove signalpoll timer!!");
4447 * If we're in one of the idle modes, we have
4448 * not started association yet and thus setting
4449 * those ones to FALSE could cancel an association
4452 wps = connman_network_get_bool(network, "WiFi.UseWPS");
4454 if (is_idle_wps(interface, wifi))
4460 #if defined TIZEN_EXT
4461 if (handle_assoc_status_code(interface, wifi)) {
4462 const char *group = connman_network_get_group(network);
4463 GSupplicantNetwork *supplicant_network;
4464 GSList *bssid_list = NULL;
4465 guint bssid_length = 0;
4468 supplicant_network = g_supplicant_interface_get_network(interface, group);
4470 connman_network_set_assoc_reject_table(network,
4471 g_supplicant_network_get_assoc_reject_table(supplicant_network));
4473 g_supplicant_network_update_assoc_reject(interface, supplicant_network);
4476 bssid_list = (GSList *)connman_network_get_bssid_list(network);
4478 bssid_length = g_slist_length(bssid_list);
4480 if (bssid_length > 1 && bssid_length > g_hash_table_size(failed_bssids)) {
4481 network_connect(network);
4485 wifi->load_shaping_retries = 0;
4488 g_hash_table_remove_all(failed_bssids);
4490 if (handle_assoc_status_code(interface, wifi))
4494 /* If previous state was 4way-handshake, then
4495 * it's either: psk was incorrect and thus we retry
4496 * or if we reach the maximum retries we declare the
4498 if (handle_4way_handshake_failure(interface,
4502 /* See table 8-36 Reason codes in IEEE Std 802.11 */
4503 switch (wifi->disconnect_code) {
4504 case 1: /* Unspecified reason */
4505 /* Let's assume it's because we got blocked */
4507 case 6: /* Class 2 frame received from nonauthenticated STA */
4508 connman_network_set_error(network,
4509 CONNMAN_NETWORK_ERROR_BLOCKED);
4516 #if defined TIZEN_EXT
4517 /* Some of Wi-Fi networks are not comply Wi-Fi specification.
4518 * Retry association until its retry count is expired */
4519 if (handle_wifi_assoc_retry(network, wifi) == true) {
4520 throw_wifi_scan(wifi->device, scan_callback);
4521 wifi->scan_pending_network = wifi->network;
4525 if(wifi->disconnect_code > 0){
4526 DBG("Set disconnect reason code(%d)", wifi->disconnect_code);
4527 connman_network_set_disconnect_reason(network, wifi->disconnect_code);
4531 if (network != wifi->pending_network) {
4532 connman_network_set_connected(network, false);
4533 connman_network_set_associating(network, false);
4535 wifi->disconnecting = false;
4537 start_autoscan(device);
4541 case G_SUPPLICANT_STATE_INACTIVE:
4542 #if defined TIZEN_EXT
4543 if (handle_wps_completion(interface, network, device, wifi) == false)
4546 connman_network_set_associating(network, false);
4547 start_autoscan(device);
4551 case G_SUPPLICANT_STATE_UNKNOWN:
4552 case G_SUPPLICANT_STATE_DISABLED:
4553 case G_SUPPLICANT_STATE_ASSOCIATED:
4554 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4555 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4559 old_connected = wifi->connected;
4560 wifi->state = state;
4562 /* Saving wpa_s state policy:
4563 * If connected and if the state changes are roaming related:
4564 * --> We stay connected
4566 * --> We are connected
4568 * --> We are not connected
4571 case G_SUPPLICANT_STATE_AUTHENTICATING:
4572 case G_SUPPLICANT_STATE_ASSOCIATING:
4573 case G_SUPPLICANT_STATE_ASSOCIATED:
4574 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4575 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4576 if (wifi->connected)
4577 connman_warn("Probably roaming right now!"
4578 " Staying connected...");
4580 case G_SUPPLICANT_STATE_SCANNING:
4581 wifi->connected = false;
4584 start_autoscan(device);
4586 case G_SUPPLICANT_STATE_COMPLETED:
4587 wifi->connected = true;
4590 wifi->connected = false;
4597 static void interface_removed(GSupplicantInterface *interface)
4599 const char *ifname = g_supplicant_interface_get_ifname(interface);
4600 struct wifi_data *wifi;
4601 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4603 * Note: If supplicant interface's driver is wired then skip it,
4604 * because it meanti only for ethernet not Wi-Fi.
4606 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4608 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4611 DBG("ifname %s", ifname);
4613 wifi = g_supplicant_interface_get_data(interface);
4615 #if defined TIZEN_EXT_WIFI_MESH
4616 if (wifi && wifi->mesh_interface) {
4617 DBG("Notify mesh interface remove");
4618 connman_mesh_notify_interface_remove(true);
4619 struct wifi_mesh_info *mesh_info = wifi->mesh_info;
4620 g_free(mesh_info->parent_ifname);
4621 g_free(mesh_info->ifname);
4622 g_free(mesh_info->identifier);
4624 wifi->mesh_interface = false;
4625 wifi->mesh_info = NULL;
4631 wifi->interface = NULL;
4633 if (wifi && wifi->tethering)
4636 if (!wifi || !wifi->device) {
4637 DBG("wifi interface already removed");
4641 connman_device_set_powered(wifi->device, false);
4643 check_p2p_technology();
4644 #if defined TIZEN_EXT_WIFI_MESH
4645 check_mesh_technology();
4649 static void set_device_type(const char *type, char dev_type[17])
4651 const char *oui = "0050F204";
4652 const char *category = "0001";
4653 const char *sub_category = "0000";
4655 if (!g_strcmp0(type, "handset")) {
4657 sub_category = "0005";
4658 } else if (!g_strcmp0(type, "vm") || !g_strcmp0(type, "container"))
4659 sub_category = "0001";
4660 else if (!g_strcmp0(type, "server"))
4661 sub_category = "0002";
4662 else if (!g_strcmp0(type, "laptop"))
4663 sub_category = "0005";
4664 else if (!g_strcmp0(type, "desktop"))
4665 sub_category = "0006";
4666 else if (!g_strcmp0(type, "tablet"))
4667 sub_category = "0009";
4668 else if (!g_strcmp0(type, "watch"))
4671 snprintf(dev_type, 17, "%s%s%s", category, oui, sub_category);
4674 static void p2p_support(GSupplicantInterface *interface)
4676 char dev_type[17] = {};
4677 const char *hostname;
4678 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4680 * Note: If supplicant interface's driver is wired then skip it,
4681 * because it meanti only for ethernet not Wi-Fi.
4683 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4685 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4693 if (!g_supplicant_interface_has_p2p(interface))
4696 if (connman_technology_driver_register(&p2p_tech_driver) < 0) {
4697 DBG("Could not register P2P technology driver");
4701 hostname = connman_utsname_get_hostname();
4703 hostname = "ConnMan";
4705 set_device_type(connman_machine_get_type(), dev_type);
4706 g_supplicant_interface_set_p2p_device_config(interface,
4707 hostname, dev_type);
4708 connman_peer_driver_register(&peer_driver);
4711 static void scan_started(GSupplicantInterface *interface)
4713 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4715 * Note: If supplicant interface's driver is wired then skip it,
4716 * because it meanti only for ethernet not Wi-Fi.
4718 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4720 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4725 static void scan_finished(GSupplicantInterface *interface)
4727 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4729 * Note: If supplicant interface's driver is wired then skip it,
4730 * because it meanti only for ethernet not Wi-Fi.
4732 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4734 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4736 #if defined TIZEN_EXT
4737 struct wifi_data *wifi;
4738 bool is_associating = false;
4739 static bool is_scanning = true;
4744 #if defined TIZEN_EXT
4745 wifi = g_supplicant_interface_get_data(interface);
4746 if (wifi && wifi->scan_pending_network) {
4747 network_connect(wifi->scan_pending_network);
4748 wifi->scan_pending_network = NULL;
4751 //service state - associating
4752 if(!wifi || !wifi->network)
4755 is_associating = connman_network_get_associating(wifi->network);
4756 if(is_associating && is_scanning){
4757 is_scanning = false;
4758 DBG("send scan for connecting");
4759 throw_wifi_scan(wifi->device, scan_callback);
4770 static void ap_create_fail(GSupplicantInterface *interface)
4772 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4774 * Note: If supplicant interface's driver is wired then skip it,
4775 * because it meanti only for ethernet not Wi-Fi.
4777 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
4779 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4781 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
4784 if ((wifi->tethering) && (wifi->tethering_param)) {
4785 DBG("%s create AP fail \n",
4786 g_supplicant_interface_get_ifname(wifi->interface));
4788 connman_inet_remove_from_bridge(wifi->index, wifi->bridge);
4789 wifi->ap_supported = WIFI_AP_NOT_SUPPORTED;
4790 wifi->tethering = false;
4792 ret = tech_set_tethering(wifi->tethering_param->technology,
4793 wifi->tethering_param->ssid->ssid,
4794 wifi->tethering_param->ssid->passphrase,
4795 wifi->bridge, true);
4797 if ((ret == -EOPNOTSUPP) && (wifi_technology)) {
4798 connman_technology_tethering_notify(wifi_technology,false);
4801 g_free(wifi->tethering_param->ssid);
4802 g_free(wifi->tethering_param);
4803 wifi->tethering_param = NULL;
4807 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
4809 unsigned char strength;
4811 strength = 120 + g_supplicant_network_get_signal(supplicant_network);
4812 #if !defined TIZEN_EXT
4820 #if defined TIZEN_EXT_WIFI_MESH
4821 static void mesh_peer_added(GSupplicantNetwork *supplicant_network)
4823 GSupplicantInterface *interface;
4824 struct wifi_data *wifi;
4825 const char *name, *security;
4826 struct connman_mesh *connman_mesh;
4827 struct wifi_mesh_info *mesh_info;
4828 const unsigned char *bssid;
4829 const char *identifier;
4834 interface = g_supplicant_network_get_interface(supplicant_network);
4835 wifi = g_supplicant_interface_get_data(interface);
4836 if (!wifi || !wifi->mesh_interface) {
4837 DBG("Virtual Mesh interface not created");
4841 bssid = g_supplicant_network_get_bssid(supplicant_network);
4842 address = g_malloc0(19);
4843 snprintf(address, 19, "%02x:%02x:%02x:%02x:%02x:%02x", bssid[0], bssid[1],
4844 bssid[2], bssid[3], bssid[4], bssid[5]);
4846 identifier = g_supplicant_network_get_identifier(supplicant_network);
4847 name = g_supplicant_network_get_name(supplicant_network);
4848 security = g_supplicant_network_get_security(supplicant_network);
4849 frequency = g_supplicant_network_get_frequency(supplicant_network);
4851 mesh_info = wifi->mesh_info;
4852 connman_mesh = connman_mesh_get(mesh_info->identifier, identifier);
4856 DBG("Mesh Peer name %s identifier %s security %s added", name, identifier,
4858 connman_mesh = connman_mesh_create(mesh_info->identifier, identifier);
4859 connman_mesh_set_name(connman_mesh, name);
4860 connman_mesh_set_security(connman_mesh, security);
4861 connman_mesh_set_frequency(connman_mesh, frequency);
4862 connman_mesh_set_address(connman_mesh, address);
4863 connman_mesh_set_index(connman_mesh, mesh_info->index);
4864 connman_mesh_set_strength(connman_mesh,
4865 calculate_strength(supplicant_network));
4866 connman_mesh_set_peer_type(connman_mesh, CONNMAN_MESH_PEER_TYPE_DISCOVERED);
4868 ret = connman_mesh_register(connman_mesh);
4869 if (ret == -EALREADY)
4870 DBG("Mesh Peer is already registered");
4876 static void mesh_peer_removed(GSupplicantNetwork *supplicant_network)
4878 GSupplicantInterface *interface;
4879 struct wifi_data *wifi;
4880 struct connman_mesh *connman_mesh;
4881 struct wifi_mesh_info *mesh_info;
4882 const char *identifier;
4884 interface = g_supplicant_network_get_interface(supplicant_network);
4885 wifi = g_supplicant_interface_get_data(interface);
4886 if (!wifi || !wifi->mesh_interface) {
4887 DBG("Virtual Mesh interface not created");
4891 identifier = g_supplicant_network_get_identifier(supplicant_network);
4893 DBG("Failed to get Mesh Peer identifier");
4897 mesh_info = wifi->mesh_info;
4898 connman_mesh = connman_mesh_get(mesh_info->identifier, identifier);
4900 /* Do not unregister connected mesh peer */
4901 if (connman_mesh_peer_is_connected_state(connman_mesh)) {
4902 DBG("Mesh Peer %s is connected", identifier);
4905 DBG("Mesh Peer identifier %s removed", identifier);
4906 connman_mesh_unregister(connman_mesh);
4912 #if defined TIZEN_EXT
4913 static GSList *get_supported_security_list(unsigned int keymgmt,
4914 bool owe_transition_mode,
4915 GSupplicantNetwork *supplicant_network)
4917 GSList *sec_list = NULL;
4918 dbus_bool_t privacy = g_supplicant_network_get_privacy(supplicant_network);
4919 const char *enc_mode = g_supplicant_network_get_enc_mode(supplicant_network);
4922 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
4923 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
4924 sec_list = g_slist_prepend (sec_list, "ieee8021x");
4925 else if (keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_EAP)
4926 sec_list = g_slist_prepend (sec_list, "ft_ieee8021x");
4932 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
4933 G_SUPPLICANT_KEYMGMT_WPA_PSK_256)) {
4934 if (!g_strcmp0(enc_mode, "aes"))
4935 sec_list = g_slist_prepend (sec_list, "rsn");
4936 else if (!g_strcmp0(enc_mode, "tkip"))
4937 sec_list = g_slist_prepend (sec_list, "psk");
4938 else if (!g_strcmp0(enc_mode, "mixed")) {
4939 sec_list = g_slist_prepend (sec_list, "psk");
4940 sec_list = g_slist_prepend (sec_list, "rsn");
4942 } else if (keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
4943 sec_list = g_slist_prepend (sec_list, "ft_psk");
4945 if (keymgmt & G_SUPPLICANT_KEYMGMT_SAE)
4946 sec_list = g_slist_prepend (sec_list, "sae");
4947 if (keymgmt & G_SUPPLICANT_KEYMGMT_OWE || owe_transition_mode)
4948 sec_list = g_slist_prepend (sec_list, "owe");
4949 if (keymgmt & G_SUPPLICANT_KEYMGMT_DPP)
4950 sec_list = g_slist_prepend (sec_list, "dpp");
4956 sec_list = g_slist_prepend (sec_list, "wep");
4958 sec_list = g_slist_prepend (sec_list, "none");
4964 static void network_added(GSupplicantNetwork *supplicant_network)
4966 struct connman_network *network;
4967 GSupplicantInterface *interface;
4968 struct wifi_data *wifi;
4969 const char *name, *identifier, *security, *group, *mode;
4970 const unsigned char *ssid;
4971 unsigned int ssid_len;
4975 bool wps_advertizing;
4977 #if defined TIZEN_EXT
4978 bool owe_transition_mode;
4979 const unsigned char *transition_mode_ssid;
4980 const unsigned char *transition_mode_bssid;
4981 unsigned int transition_mode_ssid_len;
4982 unsigned int keymgmt;
4983 GSList *vsie_list = NULL;
4984 GSList *sec_list = NULL;
4985 const unsigned char *country_code;
4986 ieee80211_modes_e phy_mode;
4989 mode = g_supplicant_network_get_mode(supplicant_network);
4990 identifier = g_supplicant_network_get_identifier(supplicant_network);
4991 #if defined TIZEN_EXT
4992 if (!simplified_log)
4994 DBG("%s", identifier);
4996 if (!g_strcmp0(mode, "adhoc"))
4999 #if defined TIZEN_EXT_WIFI_MESH
5000 if (!g_strcmp0(mode, "mesh")) {
5001 mesh_peer_added(supplicant_network);
5006 interface = g_supplicant_network_get_interface(supplicant_network);
5007 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5009 * Note: If supplicant interface's driver is wired then skip it,
5010 * because it meanti only for ethernet not Wi-Fi.
5012 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5014 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5016 wifi = g_supplicant_interface_get_data(interface);
5017 name = g_supplicant_network_get_name(supplicant_network);
5018 security = g_supplicant_network_get_security(supplicant_network);
5019 group = g_supplicant_network_get_identifier(supplicant_network);
5020 wps = g_supplicant_network_get_wps(supplicant_network);
5021 wps_pbc = g_supplicant_network_is_wps_pbc(supplicant_network);
5022 wps_ready = g_supplicant_network_is_wps_active(supplicant_network);
5023 wps_advertizing = g_supplicant_network_is_wps_advertizing(
5024 supplicant_network);
5029 ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
5031 network = connman_device_get_network(wifi->device, identifier);
5034 network = connman_network_create(identifier,
5035 CONNMAN_NETWORK_TYPE_WIFI);
5039 connman_network_set_index(network, wifi->index);
5041 if (connman_device_add_network(wifi->device, network) < 0) {
5042 connman_network_unref(network);
5046 wifi->networks = g_slist_prepend(wifi->networks, network);
5049 if (name && name[0] != '\0')
5050 connman_network_set_name(network, name);
5052 connman_network_set_blob(network, "WiFi.SSID",
5054 #if defined TIZEN_EXT
5055 vsie_list = (GSList *)g_supplicant_network_get_wifi_vsie(supplicant_network);
5057 connman_network_set_vsie_list(network, vsie_list);
5059 DBG("vsie_list is NULL");
5060 country_code = g_supplicant_network_get_countrycode(supplicant_network);
5061 connman_network_set_countrycode(network, country_code);
5062 phy_mode = g_supplicant_network_get_phy_mode(supplicant_network);
5063 connman_network_set_phy_mode(network, phy_mode);
5065 connman_network_set_string(network, "WiFi.Security", security);
5066 connman_network_set_strength(network,
5067 calculate_strength(supplicant_network));
5068 connman_network_set_bool(network, "WiFi.WPS", wps);
5069 connman_network_set_bool(network, "WiFi.WPSAdvertising",
5073 /* Is AP advertizing for WPS association?
5074 * If so, we decide to use WPS by default */
5075 if (wps_ready && wps_pbc &&
5077 #if !defined TIZEN_EXT
5078 connman_network_set_bool(network, "WiFi.UseWPS", true);
5080 DBG("wps is activating by ap but ignore it.");
5084 connman_network_set_frequency(network,
5085 g_supplicant_network_get_frequency(supplicant_network));
5087 #if defined TIZEN_EXT
5088 keymgmt = g_supplicant_network_get_keymgmt(supplicant_network);
5089 connman_network_set_bssid(network,
5090 g_supplicant_network_get_bssid(supplicant_network));
5091 owe_transition_mode = (bool)g_supplicant_network_get_transition_mode(supplicant_network);
5092 connman_network_set_bool(network, "WiFi.TRANSITION_MODE", owe_transition_mode);
5093 if (owe_transition_mode) {
5094 transition_mode_ssid = (unsigned char *)g_supplicant_network_get_transition_mode_ssid(supplicant_network, &transition_mode_ssid_len);
5095 connman_network_set_blob(network, "WiFi.TRANSITION_MODE_SSID",
5096 transition_mode_ssid, transition_mode_ssid_len);
5097 transition_mode_bssid = g_supplicant_network_get_transition_mode_bssid(supplicant_network);
5098 connman_network_set_transition_mode_bssid(network, transition_mode_bssid);
5101 sec_list = get_supported_security_list(keymgmt,
5102 owe_transition_mode, supplicant_network);
5104 connman_network_set_sec_list(network, sec_list);
5105 connman_network_set_maxrate(network,
5106 g_supplicant_network_get_maxrate(supplicant_network));
5107 connman_network_set_enc_mode(network,
5108 g_supplicant_network_get_enc_mode(supplicant_network));
5109 connman_network_set_rsn_mode(network,
5110 g_supplicant_network_get_rsn_mode(supplicant_network));
5111 connman_network_set_keymgmt(network, keymgmt);
5112 connman_network_set_bool(network, "WiFi.HS20AP",
5113 g_supplicant_network_is_hs20AP(supplicant_network));
5114 connman_network_set_bssid_list(network,
5115 (GSList *)g_supplicant_network_get_bssid_list(supplicant_network));
5116 connman_network_set_last_connected_bssid(network,
5117 g_supplicant_network_get_last_connected_bssid(supplicant_network));
5118 connman_network_set_assoc_reject_table(network,
5119 g_supplicant_network_get_assoc_reject_table(supplicant_network));
5121 connman_network_set_available(network, true);
5122 connman_network_set_string(network, "WiFi.Mode", mode);
5124 #if defined TIZEN_EXT
5129 connman_network_set_group(network, group);
5131 #if defined TIZEN_EXT
5132 g_supplicant_network_set_last_connected_bssid(supplicant_network,
5133 connman_network_get_last_connected_bssid(network));
5136 #if defined TIZEN_EXT
5137 if (wifi_first_scan == true)
5138 found_with_first_scan = true;
5141 if (wifi->hidden && ssid) {
5142 #if defined TIZEN_EXT
5143 if (network_security(wifi->hidden->security) ==
5144 network_security(security) &&
5146 if (!g_strcmp0(wifi->hidden->security, security) &&
5148 wifi->hidden->ssid_len == ssid_len &&
5149 !memcmp(wifi->hidden->ssid, ssid, ssid_len)) {
5150 connman_network_connect_hidden(network,
5151 wifi->hidden->identity,
5152 wifi->hidden->passphrase,
5153 wifi->hidden->user_data);
5154 wifi->hidden->user_data = NULL;
5155 hidden_free(wifi->hidden);
5156 wifi->hidden = NULL;
5161 static void network_removed(GSupplicantNetwork *network)
5163 GSupplicantInterface *interface;
5164 struct wifi_data *wifi;
5165 const char *name, *identifier;
5166 struct connman_network *connman_network;
5168 #if defined TIZEN_EXT_WIFI_MESH
5170 mode = g_supplicant_network_get_mode(network);
5171 if (!g_strcmp0(mode, "mesh")) {
5172 mesh_peer_removed(network);
5177 interface = g_supplicant_network_get_interface(network);
5178 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5180 * Note: If supplicant interface's driver is wired then skip it,
5181 * because it meanti only for ethernet not Wi-Fi.
5183 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5185 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5187 wifi = g_supplicant_interface_get_data(interface);
5188 identifier = g_supplicant_network_get_identifier(network);
5189 name = g_supplicant_network_get_name(network);
5191 DBG("name %s", name);
5196 connman_network = connman_device_get_network(wifi->device, identifier);
5197 if (!connman_network)
5200 #if defined TIZEN_EXT
5201 if (connman_network == wifi->scan_pending_network)
5202 wifi->scan_pending_network = NULL;
5204 if (connman_network == wifi->pending_network)
5205 wifi->pending_network = NULL;
5207 if(connman_network_get_connecting(connman_network) == true){
5208 connman_network_set_connected(connman_network, false);
5212 wifi->networks = g_slist_remove(wifi->networks, connman_network);
5214 connman_device_remove_network(wifi->device, connman_network);
5215 connman_network_unref(connman_network);
5218 static void network_changed(GSupplicantNetwork *network, const char *property)
5220 GSupplicantInterface *interface;
5221 struct wifi_data *wifi;
5222 const char *name, *identifier;
5223 struct connman_network *connman_network;
5226 #if defined TIZEN_EXT
5227 const unsigned char *bssid;
5228 unsigned int maxrate;
5231 const unsigned char *country_code;
5232 ieee80211_modes_e phy_mode;
5236 interface = g_supplicant_network_get_interface(network);
5237 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5239 * Note: If supplicant interface's driver is wired then skip it,
5240 * because it meanti only for ethernet not Wi-Fi.
5242 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5244 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5246 wifi = g_supplicant_interface_get_data(interface);
5247 identifier = g_supplicant_network_get_identifier(network);
5248 name = g_supplicant_network_get_name(network);
5250 #if defined TIZEN_EXT
5251 if (!simplified_log)
5252 DBG("name %s property %s", name, property);
5254 DBG("name %s", name);
5260 connman_network = connman_device_get_network(wifi->device, identifier);
5261 if (!connman_network)
5264 if (g_str_equal(property, "WPSCapabilities")) {
5268 bool wps_advertizing;
5270 wps = g_supplicant_network_get_wps(network);
5271 wps_pbc = g_supplicant_network_is_wps_pbc(network);
5272 wps_ready = g_supplicant_network_is_wps_active(network);
5274 g_supplicant_network_is_wps_advertizing(network);
5276 connman_network_set_bool(connman_network, "WiFi.WPS", wps);
5277 connman_network_set_bool(connman_network,
5278 "WiFi.WPSAdvertising", wps_advertizing);
5282 * Is AP advertizing for WPS association?
5283 * If so, we decide to use WPS by default
5285 if (wps_ready && wps_pbc && wps_advertizing)
5286 connman_network_set_bool(connman_network,
5287 "WiFi.UseWPS", true);
5290 update_needed = true;
5291 } else if (g_str_equal(property, "Signal")) {
5292 connman_network_set_strength(connman_network,
5293 calculate_strength(network));
5294 update_needed = true;
5296 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
5297 else if (g_str_equal(property, "LastConnectedBSSID")) {
5298 const char *ident, *group;
5299 char *service_ident;
5302 ident = connman_device_get_ident(wifi->device);
5303 group = connman_network_get_group(connman_network);
5304 if (ident && group) {
5305 service_ident = g_strdup_printf("%s_%s_%s",
5306 __connman_network_get_type(connman_network), ident, group);
5308 need_save = connman_device_set_last_connected_ident(wifi->device, service_ident);
5310 connman_device_save_last_connected(wifi->device);
5312 g_free(service_ident);
5315 connman_network_set_last_connected_bssid(connman_network,
5316 g_supplicant_network_get_last_connected_bssid(network));
5318 update_needed = true;
5320 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
5321 #if defined TIZEN_EXT
5322 else if (g_str_equal(property, "UpdateAssocReject")) {
5323 connman_network_set_assoc_reject_table(connman_network,
5324 g_supplicant_network_get_assoc_reject_table(network));
5325 update_needed = true;
5329 update_needed = false;
5332 connman_network_update(connman_network);
5334 #if defined TIZEN_EXT
5335 bssid = g_supplicant_network_get_bssid(network);
5336 maxrate = g_supplicant_network_get_maxrate(network);
5337 frequency = g_supplicant_network_get_frequency(network);
5338 wps = g_supplicant_network_get_wps(network);
5339 phy_mode = g_supplicant_network_get_phy_mode(network);
5341 connman_network_set_bssid(connman_network, bssid);
5342 connman_network_set_maxrate(connman_network, maxrate);
5343 connman_network_set_frequency(connman_network, frequency);
5344 connman_network_set_bool(connman_network, "WiFi.WPS", wps);
5345 country_code = g_supplicant_network_get_countrycode(network);
5346 connman_network_set_countrycode(connman_network, country_code);
5347 bssid_list = (GSList *)g_supplicant_network_get_bssid_list(network);
5348 connman_network_set_bssid_list(connman_network, bssid_list);
5349 connman_network_set_phy_mode(connman_network, phy_mode);
5351 if (g_str_equal(property, "CheckMultiBssidConnect") &&
5352 connman_network_get_associating(connman_network))
5353 network_connect(connman_network);
5357 static void network_associated(GSupplicantNetwork *network)
5359 GSupplicantInterface *interface;
5360 struct wifi_data *wifi;
5361 struct connman_network *connman_network;
5362 const char *identifier;
5366 interface = g_supplicant_network_get_interface(network);
5369 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5371 * Note: If supplicant interface's driver is wired then skip it,
5372 * because it meanti only for ethernet not Wi-Fi.
5374 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5376 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5379 wifi = g_supplicant_interface_get_data(interface);
5383 /* P2P networks must not be treated as WiFi networks */
5384 if (wifi->p2p_connecting || wifi->p2p_device)
5387 identifier = g_supplicant_network_get_identifier(network);
5389 connman_network = connman_device_get_network(wifi->device, identifier);
5390 if (!connman_network)
5393 if (wifi->network) {
5394 if (wifi->network == connman_network)
5397 unsigned int ssid_len;
5398 DBG("network1 ssid[%s] , OWE[%d],ssid[%s]",
5399 (char *)connman_network_get_blob(wifi->network,"WiFi.SSID", &ssid_len),
5400 connman_network_get_bool(wifi->network,"WiFi.TRANSITION_MODE"),
5401 (char *)connman_network_get_blob(wifi->network,"WiFi.TRANSITION_MODE_SSID", &ssid_len));
5403 DBG("network1 ssid[%s], OWE[%d], ssid[%s]",
5404 (char *)connman_network_get_blob(connman_network,"WiFi.SSID",&ssid_len),
5405 connman_network_get_bool(connman_network,"WiFi.TRANSITION_MODE"),
5406 (char *)connman_network_get_blob(connman_network,"WiFi.TRANSITION_MODE_SSID", &ssid_len));
5407 if (connman_network_check_transition_mode(wifi->network, connman_network)) {//OWE trasition mode check
5408 DBG("OWE transition mode is TRUE");
5413 * This should never happen, we got associated with
5414 * a network different than the one we were expecting.
5416 DBG("Associated to %p while expecting %p",
5417 connman_network, wifi->network);
5419 connman_network_set_associating(wifi->network, false);
5422 DBG("Reconnecting to previous network %p from wpa_s", connman_network);
5424 wifi->network = connman_network_ref(connman_network);
5428 * Interface state changes callback (interface_state) is always
5429 * called before network_associated callback thus we need to call
5430 * interface_state again in order to process the new state now that
5431 * we have the network properly set.
5433 interface_state(interface);
5436 static void sta_authorized(GSupplicantInterface *interface,
5439 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5441 * Note: If supplicant interface's driver is wired then skip it,
5442 * because it meanti only for ethernet not Wi-Fi.
5444 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5446 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5448 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5450 DBG("wifi %p station %s authorized", wifi, addr);
5452 if (!wifi || !wifi->tethering)
5455 __connman_tethering_client_register(addr);
5458 static void sta_deauthorized(GSupplicantInterface *interface,
5461 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5463 * Note: If supplicant interface's driver is wired then skip it,
5464 * because it meanti only for ethernet not Wi-Fi.
5466 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5468 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5470 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5472 DBG("wifi %p station %s deauthorized", wifi, addr);
5474 if (!wifi || !wifi->tethering)
5477 __connman_tethering_client_unregister(addr);
5480 static void apply_peer_services(GSupplicantPeer *peer,
5481 struct connman_peer *connman_peer)
5483 const unsigned char *data;
5488 connman_peer_reset_services(connman_peer);
5490 data = g_supplicant_peer_get_widi_ies(peer, &length);
5492 connman_peer_add_service(connman_peer,
5493 CONNMAN_PEER_SERVICE_WIFI_DISPLAY, data, length);
5497 static void peer_found(GSupplicantPeer *peer)
5499 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5500 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5501 struct connman_peer *connman_peer;
5502 const char *identifier, *name;
5505 #if defined TIZEN_EXT
5509 identifier = g_supplicant_peer_get_identifier(peer);
5510 name = g_supplicant_peer_get_name(peer);
5512 DBG("ident: %s", identifier);
5514 connman_peer = connman_peer_get(wifi->device, identifier);
5518 connman_peer = connman_peer_create(identifier);
5519 connman_peer_set_name(connman_peer, name);
5520 connman_peer_set_device(connman_peer, wifi->device);
5521 apply_peer_services(peer, connman_peer);
5523 ret = connman_peer_register(connman_peer);
5524 if (ret < 0 && ret != -EALREADY)
5525 connman_peer_unref(connman_peer);
5527 wifi->peers = g_slist_prepend(wifi->peers, connman_peer);
5530 static void peer_lost(GSupplicantPeer *peer)
5532 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5533 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5534 struct connman_peer *connman_peer;
5535 const char *identifier;
5540 identifier = g_supplicant_peer_get_identifier(peer);
5542 DBG("ident: %s", identifier);
5544 connman_peer = connman_peer_get(wifi->device, identifier);
5546 if (wifi->p2p_connecting &&
5547 wifi->pending_peer == connman_peer) {
5548 peer_connect_timeout(wifi);
5550 connman_peer_unregister(connman_peer);
5551 connman_peer_unref(connman_peer);
5554 wifi->peers = g_slist_remove(wifi->peers, connman_peer);
5557 static void peer_changed(GSupplicantPeer *peer, GSupplicantPeerState state)
5559 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5560 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5561 enum connman_peer_state p_state = CONNMAN_PEER_STATE_UNKNOWN;
5562 struct connman_peer *connman_peer;
5563 const char *identifier;
5565 identifier = g_supplicant_peer_get_identifier(peer);
5567 DBG("ident: %s", identifier);
5572 connman_peer = connman_peer_get(wifi->device, identifier);
5577 case G_SUPPLICANT_PEER_SERVICES_CHANGED:
5578 apply_peer_services(peer, connman_peer);
5579 connman_peer_services_changed(connman_peer);
5581 case G_SUPPLICANT_PEER_GROUP_CHANGED:
5582 if (!g_supplicant_peer_is_in_a_group(peer))
5583 p_state = CONNMAN_PEER_STATE_IDLE;
5585 p_state = CONNMAN_PEER_STATE_CONFIGURATION;
5587 case G_SUPPLICANT_PEER_GROUP_STARTED:
5589 case G_SUPPLICANT_PEER_GROUP_FINISHED:
5590 p_state = CONNMAN_PEER_STATE_IDLE;
5592 case G_SUPPLICANT_PEER_GROUP_JOINED:
5593 connman_peer_set_iface_address(connman_peer,
5594 g_supplicant_peer_get_iface_address(peer));
5596 case G_SUPPLICANT_PEER_GROUP_DISCONNECTED:
5597 p_state = CONNMAN_PEER_STATE_IDLE;
5599 case G_SUPPLICANT_PEER_GROUP_FAILED:
5600 if (g_supplicant_peer_has_requested_connection(peer))
5601 p_state = CONNMAN_PEER_STATE_IDLE;
5603 p_state = CONNMAN_PEER_STATE_FAILURE;
5607 if (p_state == CONNMAN_PEER_STATE_CONFIGURATION ||
5608 p_state == CONNMAN_PEER_STATE_FAILURE) {
5609 if (wifi->p2p_connecting
5610 && connman_peer == wifi->pending_peer)
5611 peer_cancel_timeout(wifi);
5613 p_state = CONNMAN_PEER_STATE_UNKNOWN;
5616 if (p_state == CONNMAN_PEER_STATE_UNKNOWN)
5619 if (p_state == CONNMAN_PEER_STATE_CONFIGURATION) {
5620 GSupplicantInterface *g_iface;
5621 struct wifi_data *g_wifi;
5623 g_iface = g_supplicant_peer_get_group_interface(peer);
5627 g_wifi = g_supplicant_interface_get_data(g_iface);
5631 connman_peer_set_as_master(connman_peer,
5632 !g_supplicant_peer_is_client(peer));
5633 connman_peer_set_sub_device(connman_peer, g_wifi->device);
5636 * If wpa_supplicant didn't create a dedicated p2p-group
5637 * interface then mark this interface as p2p_device to avoid
5638 * scan and auto-scan are launched on it while P2P is connected.
5640 if (!g_list_find(p2p_iface_list, g_wifi))
5641 wifi->p2p_device = true;
5644 connman_peer_set_state(connman_peer, p_state);
5647 static void peer_request(GSupplicantPeer *peer)
5649 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
5650 struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
5651 struct connman_peer *connman_peer;
5652 const char *identifier;
5654 #if defined TIZEN_EXT
5659 identifier = g_supplicant_peer_get_identifier(peer);
5661 DBG("ident: %s", identifier);
5663 connman_peer = connman_peer_get(wifi->device, identifier);
5667 connman_peer_request_connection(connman_peer);
5670 #if defined TIZEN_EXT
5671 static void system_power_off(void)
5674 struct wifi_data *wifi;
5675 struct connman_service *service;
5676 struct connman_ipconfig *ipconfig_ipv4;
5678 if (connman_setting_get_bool("WiFiDHCPRelease") == true) {
5679 for (list = iface_list; list; list = list->next) {
5682 if (wifi->network != NULL) {
5683 service = connman_service_lookup_from_network(wifi->network);
5684 ipconfig_ipv4 = __connman_service_get_ip4config(service);
5685 __connman_dhcp_stop(ipconfig_ipv4);
5691 static void network_merged(GSupplicantNetwork *network)
5693 GSupplicantInterface *interface;
5694 GSupplicantState state;
5695 struct wifi_data *wifi;
5696 const char *identifier;
5697 struct connman_network *connman_network;
5701 interface = g_supplicant_network_get_interface(network);
5705 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5707 * Note: If supplicant interface's driver is wired then skip it,
5708 * because it meanti only for ethernet not Wi-Fi.
5710 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5712 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5714 state = g_supplicant_interface_get_state(interface);
5715 if (state < G_SUPPLICANT_STATE_AUTHENTICATING)
5718 wifi = g_supplicant_interface_get_data(interface);
5722 identifier = g_supplicant_network_get_identifier(network);
5724 connman_network = connman_device_get_network(wifi->device, identifier);
5725 if (!connman_network)
5728 DBG("merged identifier %s", identifier);
5730 if (wifi->connected == FALSE) {
5732 case G_SUPPLICANT_STATE_AUTHENTICATING:
5733 case G_SUPPLICANT_STATE_ASSOCIATING:
5734 case G_SUPPLICANT_STATE_ASSOCIATED:
5735 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
5736 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
5737 connman_network_set_associating(connman_network, TRUE);
5739 case G_SUPPLICANT_STATE_COMPLETED:
5740 connman_network_set_connected(connman_network, TRUE);
5743 DBG("Not handled the state : %d", state);
5748 ishs20AP = g_supplicant_network_is_hs20AP(network);
5751 g_strcmp0(g_supplicant_network_get_security(network), "ieee8021x") == 0) {
5752 temp = g_ascii_strdown(g_supplicant_network_get_eap(network), -1);
5753 connman_network_set_string(connman_network, "WiFi.EAP",
5755 connman_network_set_string(connman_network, "WiFi.Identity",
5756 g_supplicant_network_get_identity(network));
5757 connman_network_set_string(connman_network, "WiFi.Phase2",
5758 g_supplicant_network_get_phase2(network));
5763 wifi->network = connman_network;
5766 static void assoc_failed(void *user_data)
5768 struct connman_network *network = user_data;
5769 connman_network_set_associating(network, false);
5772 static void scan_done(GSupplicantInterface *interface)
5774 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5776 * Note: If supplicant interface's driver is wired then skip it,
5777 * because it meanti only for ethernet not Wi-Fi.
5779 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5781 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5784 int scan_type = CONNMAN_SCAN_TYPE_WPA_SUPPLICANT;
5785 struct wifi_data *wifi;
5788 for (list = iface_list; list; list = list->next) {
5791 if (interface == wifi->interface) {
5792 scanning = connman_device_get_scanning(wifi->device,
5793 CONNMAN_SERVICE_TYPE_WIFI);
5795 __connman_technology_notify_scan_done(
5796 connman_device_get_string(wifi->device, "Interface"), scan_type);
5803 static void debug(const char *str)
5805 #if defined TIZEN_EXT
5806 if (connman_setting_get_bool("ConnmanSupplicantDebug"))
5808 if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
5810 connman_debug("%s", str);
5813 static void disconnect_reasoncode(GSupplicantInterface *interface,
5816 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5818 * Note: If supplicant interface's driver is wired then skip it,
5819 * because it meanti only for ethernet not Wi-Fi.
5821 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5823 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5825 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5828 wifi->disconnect_code = reasoncode;
5832 static void assoc_status_code(GSupplicantInterface *interface, int status_code)
5834 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5836 * Note: If supplicant interface's driver is wired then skip it,
5837 * because it meanti only for ethernet not Wi-Fi.
5839 if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
5841 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5843 struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
5846 wifi->assoc_code = status_code;
5850 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5851 static GSupplicantCallbacks callbacks = {
5852 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5853 static const GSupplicantCallbacks callbacks = {
5854 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5855 .system_ready = system_ready,
5856 .system_killed = system_killed,
5857 .interface_added = interface_added,
5858 .interface_state = interface_state,
5859 .interface_removed = interface_removed,
5860 .p2p_support = p2p_support,
5861 .scan_started = scan_started,
5862 .scan_finished = scan_finished,
5863 .ap_create_fail = ap_create_fail,
5864 .network_added = network_added,
5865 .network_removed = network_removed,
5866 .network_changed = network_changed,
5867 .network_associated = network_associated,
5868 .sta_authorized = sta_authorized,
5869 .sta_deauthorized = sta_deauthorized,
5870 .peer_found = peer_found,
5871 .peer_lost = peer_lost,
5872 .peer_changed = peer_changed,
5873 .peer_request = peer_request,
5874 #if defined TIZEN_EXT
5875 .system_power_off = system_power_off,
5876 .network_merged = network_merged,
5877 .assoc_failed = assoc_failed,
5878 .scan_done = scan_done,
5881 .disconnect_reasoncode = disconnect_reasoncode,
5882 .assoc_status_code = assoc_status_code,
5883 #if defined TIZEN_EXT_WIFI_MESH
5884 .mesh_support = mesh_support,
5885 .mesh_group_started = mesh_group_started,
5886 .mesh_group_removed = mesh_group_removed,
5887 .mesh_peer_connected = mesh_peer_connected,
5888 .mesh_peer_disconnected = mesh_peer_disconnected,
5893 static int tech_probe(struct connman_technology *technology)
5895 wifi_technology = technology;
5900 static void tech_remove(struct connman_technology *technology)
5902 wifi_technology = NULL;
5905 static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
5907 GSupplicantSSID *ap;
5909 ap = g_try_malloc0(sizeof(GSupplicantSSID));
5913 ap->mode = G_SUPPLICANT_MODE_MASTER;
5914 #if defined TIZEN_EXT
5915 ap->ssid = (void *) ssid;
5919 ap->ssid_len = strlen(ssid);
5923 if (!passphrase || strlen(passphrase) == 0) {
5924 ap->security = G_SUPPLICANT_SECURITY_NONE;
5925 ap->passphrase = NULL;
5927 ap->security = G_SUPPLICANT_SECURITY_PSK;
5928 ap->protocol = G_SUPPLICANT_PROTO_RSN;
5929 ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
5930 ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
5931 ap->passphrase = passphrase;
5937 static void ap_start_callback(int result, GSupplicantInterface *interface,
5940 struct wifi_tethering_info *info = user_data;
5942 DBG("result %d index %d bridge %s",
5943 result, info->wifi->index, info->wifi->bridge);
5945 if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
5946 connman_inet_remove_from_bridge(info->wifi->index,
5947 info->wifi->bridge);
5949 if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
5950 connman_technology_tethering_notify(info->technology, false);
5951 g_free(info->wifi->tethering_param->ssid);
5952 g_free(info->wifi->tethering_param);
5953 info->wifi->tethering_param = NULL;
5957 g_free(info->ifname);
5961 static void ap_create_callback(int result,
5962 GSupplicantInterface *interface,
5965 struct wifi_tethering_info *info = user_data;
5967 DBG("result %d ifname %s", result,
5968 g_supplicant_interface_get_ifname(interface));
5970 if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
5971 connman_inet_remove_from_bridge(info->wifi->index,
5972 info->wifi->bridge);
5974 if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
5975 connman_technology_tethering_notify(info->technology, false);
5976 g_free(info->wifi->tethering_param->ssid);
5977 g_free(info->wifi->tethering_param);
5978 info->wifi->tethering_param = NULL;
5982 g_free(info->ifname);
5988 info->wifi->interface = interface;
5989 g_supplicant_interface_set_data(interface, info->wifi);
5991 if (g_supplicant_interface_set_apscan(interface, 2) < 0)
5992 connman_error("Failed to set interface ap_scan property");
5994 g_supplicant_interface_connect(interface, info->ssid,
5995 ap_start_callback, info);
5998 static void sta_remove_callback(int result,
5999 GSupplicantInterface *interface,
6002 struct wifi_tethering_info *info = user_data;
6003 const char *driver = connman_option_get_string("wifi");
6005 DBG("ifname %s result %d ", info->ifname, result);
6007 if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
6008 info->wifi->tethering = false;
6009 connman_technology_tethering_notify(info->technology, false);
6011 if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
6012 g_free(info->wifi->tethering_param->ssid);
6013 g_free(info->wifi->tethering_param);
6014 info->wifi->tethering_param = NULL;
6017 g_free(info->ifname);
6023 info->wifi->interface = NULL;
6025 g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
6028 #endif /* TIZEN_EXT */
6033 static int enable_wifi_tethering(struct connman_technology *technology,
6034 const char *bridge, const char *identifier,
6035 const char *passphrase, bool available)
6038 GSupplicantInterface *interface;
6039 struct wifi_data *wifi;
6040 struct wifi_tethering_info *info;
6045 for (list = iface_list; list; list = list->next) {
6048 DBG("wifi %p network %p pending_network %p", wifi,
6049 wifi->network, wifi->pending_network);
6051 interface = wifi->interface;
6056 ifname = g_supplicant_interface_get_ifname(wifi->interface);
6060 if (wifi->ap_supported == WIFI_AP_NOT_SUPPORTED) {
6061 DBG("%s does not support AP mode (detected)", ifname);
6065 mode = g_supplicant_interface_get_mode(interface);
6066 if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
6067 wifi->ap_supported = WIFI_AP_NOT_SUPPORTED;
6068 DBG("%s does not support AP mode (capability)", ifname);
6072 if (wifi->network && available)
6075 info = g_try_malloc0(sizeof(struct wifi_tethering_info));
6079 wifi->tethering_param = g_try_malloc0(sizeof(struct wifi_tethering_info));
6080 if (!wifi->tethering_param) {
6086 info->technology = technology;
6087 info->wifi->bridge = bridge;
6088 info->ssid = ssid_ap_init(identifier, passphrase);
6092 info->ifname = g_strdup(ifname);
6094 wifi->tethering_param->technology = technology;
6095 wifi->tethering_param->ssid = ssid_ap_init(identifier, passphrase);
6096 if (!wifi->tethering_param->ssid)
6099 info->wifi->tethering = true;
6100 info->wifi->ap_supported = WIFI_AP_SUPPORTED;
6102 berr = connman_technology_tethering_notify(technology, true);
6106 err = g_supplicant_interface_remove(interface,
6107 sta_remove_callback,
6110 DBG("tethering wifi %p ifname %s", wifi, ifname);
6115 g_free(info->ifname);
6118 g_free(wifi->tethering_param);
6119 wifi->tethering_param = NULL;
6122 * Remove bridge if it was correctly created but remove
6123 * operation failed. Instead, if bridge creation failed then
6124 * break out and do not try again on another interface,
6125 * bridge set-up does not depend on it.
6128 connman_technology_tethering_notify(technology, false);
6136 static int tech_set_tethering(struct connman_technology *technology,
6137 const char *identifier, const char *passphrase,
6138 const char *bridge, bool enabled)
6141 struct wifi_data *wifi;
6147 for (list = iface_list; list; list = list->next) {
6150 if (wifi->tethering) {
6151 wifi->tethering = false;
6153 connman_inet_remove_from_bridge(wifi->index,
6155 wifi->bridged = false;
6159 connman_technology_tethering_notify(technology, false);
6164 DBG("trying tethering for available devices");
6165 err = enable_wifi_tethering(technology, bridge, identifier, passphrase,
6169 DBG("trying tethering for any device");
6170 err = enable_wifi_tethering(technology, bridge, identifier,
6177 static void regdom_callback(int result, const char *alpha2, void *user_data)
6181 if (!wifi_technology)
6187 connman_technology_regdom_notify(wifi_technology, alpha2);
6190 static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
6192 return g_supplicant_set_country(alpha2, regdom_callback, NULL);
6195 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
6196 static void supp_ins_init(void)
6199 GSupplicantINSPreferredFreq preferred_freq;
6201 string = connman_option_get_string("INSPreferredFreqBSSID");
6202 if (g_strcmp0(string, "5GHz") == 0)
6203 preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_5GHZ;
6204 else if (g_strcmp0(string, "2.4GHz") == 0)
6205 preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_24GHZ;
6207 preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_UNKNOWN;
6209 g_supplicant_set_ins_settings(preferred_freq,
6210 connman_setting_get_bool("INSLastConnectedBSSID"),
6211 connman_setting_get_bool("INSAssocReject"),
6212 connman_setting_get_bool("INSSignalBSSID"),
6213 connman_setting_get_uint("INSPreferredFreqBSSIDScore"),
6214 connman_setting_get_uint("INSLastConnectedBSSIDScore"),
6215 connman_setting_get_uint("INSAssocRejectScore"),
6216 connman_setting_get_int("INSSignalLevel3_5GHz"),
6217 connman_setting_get_int("INSSignalLevel3_24GHz")
6220 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
6222 static struct connman_technology_driver tech_driver = {
6224 .type = CONNMAN_SERVICE_TYPE_WIFI,
6225 .probe = tech_probe,
6226 .remove = tech_remove,
6227 .set_tethering = tech_set_tethering,
6228 .set_regdom = tech_set_regdom,
6231 static int wifi_init(void)
6235 err = connman_network_driver_register(&network_driver);
6239 err = g_supplicant_register(&callbacks);
6241 connman_network_driver_unregister(&network_driver);
6245 err = connman_technology_driver_register(&tech_driver);
6247 g_supplicant_unregister(&callbacks);
6248 connman_network_driver_unregister(&network_driver);
6252 #if defined TIZEN_EXT
6253 failed_bssids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
6256 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
6258 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
6262 static void wifi_exit(void)
6266 connman_technology_driver_unregister(&tech_driver);
6268 g_supplicant_unregister(&callbacks);
6270 connman_network_driver_unregister(&network_driver);
6272 #if defined TIZEN_EXT
6273 g_hash_table_unref(failed_bssids);
6277 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
6278 CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)