2 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <system_info.h>
26 #include "wifi_internal.h"
28 #define WIFI_SECURITY_NONE "none"
29 #define WIFI_SECURITY_WEP "wep"
30 #define WIFI_SECURITY_WPA_PSK "psk"
31 #define WIFI_SECURITY_WPA_FT_PSK "ft_psk"
32 #define WIFI_SECURITY_SAE "sae"
33 #define WIFI_SECURITY_OWE "owe"
34 #define WIFI_SECURITY_DPP "dpp"
35 #define WIFI_SECURITY_EAP "ieee8021x"
37 #define WIFI_MAC_ADDR_PATH_LEN 32
38 #define WIFI_MAC_ADDR_PATH "/sys/class/net/%s/address"
40 /* DPP related DBus calls are sync method.
41 * If DPP is not allowed to start from net-config, there's no g_p_dpp_current for lib.
42 * So, we should take care about changing DPP DBus call mechanism
44 static wifi_dpp_s *g_p_dpp_current = NULL;
46 static GSList *wifi_manager_handle_list = NULL;
47 static GSList *multi_scan_handle_list = NULL;
48 static GSList *netlink_scan_handle_list = NULL;
49 static GSList *dpp_handle_list = NULL;
51 static gboolean multi_scan_type[WIFI_MULTI_SCAN_MAX] = {0, };
53 static bool wifi_is_feature_checked[WIFI_SUPPORTED_FEATURE_MAX] = {0, };
54 static bool wifi_feature_supported[WIFI_SUPPORTED_FEATURE_MAX] = {0, };
56 static pthread_mutex_t g_wifi_thread_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
59 static wifi_manager_error_e __convert_to_ap_error_type(net_err_e err_type)
63 return WIFI_MANAGER_ERROR_NONE;
64 case NET_ERR_APP_ALREADY_REGISTERED:
65 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
66 case NET_ERR_APP_NOT_REGISTERED:
67 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
68 case NET_ERR_NO_ACTIVE_CONNECTIONS:
69 return WIFI_MANAGER_ERROR_NO_CONNECTION;
70 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
71 case NET_ERR_ALREADY_EXISTS:
72 return WIFI_MANAGER_ERROR_ALREADY_EXISTS;
73 /*Connection Failure Error Codes*/
74 case NET_ERR_CONNECTION_OUT_OF_RANGE:
75 return WIFI_MANAGER_ERROR_OUT_OF_RANGE;
76 case NET_ERR_CONNECTION_PIN_MISSING:
77 return WIFI_MANAGER_ERROR_PIN_MISSING;
78 case NET_ERR_CONNECTION_DHCP_FAILED:
79 return WIFI_MANAGER_ERROR_DHCP_FAILED;
80 case NET_ERR_CONNECTION_CONNECT_FAILED:
81 return WIFI_MANAGER_ERROR_CONNECT_FAILED;
82 case NET_ERR_CONNECTION_LOGIN_FAILED:
83 return WIFI_MANAGER_ERROR_LOGIN_FAILED;
84 case NET_ERR_CONNECTION_AUTH_FAILED:
85 return WIFI_MANAGER_ERROR_AUTHENTICATION_FAILED;
86 case NET_ERR_CONNECTION_ASSOC_FAILED:
87 return WIFI_MANAGER_ERROR_ASSOCIATION_FAILED;
88 case NET_ERR_CONNECTION_INVALID_KEY:
89 return WIFI_MANAGER_ERROR_INVALID_KEY;
90 case NET_ERR_IN_PROGRESS:
91 return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS;
92 case NET_ERR_OPERATION_ABORTED:
93 return WIFI_MANAGER_ERROR_OPERATION_ABORTED;
94 case NET_ERR_TIME_OUT:
95 return WIFI_MANAGER_ERROR_NO_REPLY;
96 case NET_ERR_ACCESS_DENIED:
97 return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
98 case NET_ERR_CONNECTION_WPS_TIMEOUT:
99 return WIFI_MANAGER_ERROR_WPS_TIMEOUT;
100 case NET_ERR_CONNECTION_WPS_OVERLAP:
101 return WIFI_MANAGER_ERROR_WPS_OVERLAP;
102 case NET_ERR_CONNECTION_WPS_WEP_PROHIBITED:
103 return WIFI_MANAGER_ERROR_WPS_WEP_PROHIBITED;
105 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
109 static const char *__convert_ap_error_type_to_string(wifi_manager_error_e err_type)
112 case WIFI_MANAGER_ERROR_NONE:
114 case WIFI_MANAGER_ERROR_INVALID_PARAMETER:
115 return "INVALID_PARAMETER";
116 case WIFI_MANAGER_ERROR_OUT_OF_MEMORY:
117 return "OUT_OF_MEMORY";
118 case WIFI_MANAGER_ERROR_INVALID_OPERATION:
119 return "INVALID_OPERATION";
120 case WIFI_MANAGER_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
121 return "ADDRESS_FAMILY_NOT_SUPPORTED";
122 case WIFI_MANAGER_ERROR_OPERATION_FAILED:
123 return "OPERATION_FAILED";
124 case WIFI_MANAGER_ERROR_NO_CONNECTION:
125 return "NO_CONNECTION";
126 case WIFI_MANAGER_ERROR_NOW_IN_PROGRESS:
127 return "NOW_IN_PROGRESS";
128 case WIFI_MANAGER_ERROR_ALREADY_EXISTS:
129 return "ALREADY_EXISTS";
130 case WIFI_MANAGER_ERROR_OPERATION_ABORTED:
131 return "OPERATION_ABORTED";
132 case WIFI_MANAGER_ERROR_DHCP_FAILED:
133 return "DHCP_FAILED";
134 case WIFI_MANAGER_ERROR_INVALID_KEY:
135 return "INVALID_KEY";
136 case WIFI_MANAGER_ERROR_OUT_OF_RANGE:
137 return "OUT_OF_RANGE";
138 case WIFI_MANAGER_ERROR_PIN_MISSING:
139 return "PIN_MISSING";
140 case WIFI_MANAGER_ERROR_CONNECT_FAILED:
141 return "CONNECT_FAILED";
142 case WIFI_MANAGER_ERROR_LOGIN_FAILED:
143 return "LOGIN_FAILED";
144 case WIFI_MANAGER_ERROR_AUTHENTICATION_FAILED:
145 return "AUTH_FAILED";
146 case WIFI_MANAGER_ERROR_ASSOCIATION_FAILED:
147 return "ASSOC_FAILED";
148 case WIFI_MANAGER_ERROR_NO_REPLY:
150 case WIFI_MANAGER_ERROR_SECURITY_RESTRICTED:
151 return "SECURITY_RESTRICTED";
152 case WIFI_MANAGER_ERROR_ALREADY_INITIALIZED:
153 return "ALREADY_INITIALIZED";
154 case WIFI_MANAGER_ERROR_PERMISSION_DENIED:
155 return "PERMISSION_DENIED";
156 case WIFI_MANAGER_ERROR_NOT_SUPPORTED:
157 return "NOT_SUPPROTED";
158 case WIFI_MANAGER_ERROR_WPS_OVERLAP:
159 return "WPS_OVERLAP";
160 case WIFI_MANAGER_ERROR_WPS_TIMEOUT:
161 return "WPS_TIMEOUT";
162 case WIFI_MANAGER_ERROR_WPS_WEP_PROHIBITED:
163 return "WPS_WEP_PROHIBITED";
170 static const char *__convert_ap_state_to_string(wifi_manager_connection_state_e state)
173 case WIFI_MANAGER_CONNECTION_STATE_FAILURE:
175 case WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED:
176 return "DISCONNECTED";
177 case WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION:
178 return "ASSOCIATION";
179 case WIFI_MANAGER_CONNECTION_STATE_CONFIGURATION:
180 return "CONFIGURATION";
181 case WIFI_MANAGER_CONNECTION_STATE_CONNECTED:
189 static gchar *__wifi_change_name_to_hexadecimal(const gchar *name)
199 length = strlen(name);
201 string = g_string_sized_new((gsize)(length * 2));
205 for (i = 0; i < length; i++)
206 g_string_append_printf(string, "%02x", name[i]);
208 hex = g_strdup_printf("%s", string->str);
209 g_string_free(string, TRUE);
215 static gchar *__wifi_security_type_to_string(wifi_manager_security_type_e security_type)
217 switch (security_type) {
218 case WIFI_MANAGER_SECURITY_TYPE_NONE:
219 return WIFI_SECURITY_NONE;
221 case WIFI_MANAGER_SECURITY_TYPE_WEP:
222 return WIFI_SECURITY_WEP;
224 case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK:
225 case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK:
226 return WIFI_SECURITY_WPA_PSK;
228 case WIFI_MANAGER_SECURITY_TYPE_SAE:
229 return WIFI_SECURITY_SAE;
231 case WIFI_MANAGER_SECURITY_TYPE_OWE:
232 return WIFI_SECURITY_OWE;
234 case WIFI_MANAGER_SECURITY_TYPE_DPP:
235 return WIFI_SECURITY_DPP;
237 case WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK:
238 return WIFI_SECURITY_WPA_FT_PSK;
240 case WIFI_MANAGER_SECURITY_TYPE_EAP:
241 return WIFI_SECURITY_EAP;
248 gchar *_wifi_eap_type_to_string(wifi_manager_eap_type_e eap_type)
253 case WIFI_MANAGER_EAP_TYPE_PEAP:
254 type = g_strdup("PEAP");
256 case WIFI_MANAGER_EAP_TYPE_TLS:
257 type = g_strdup("TLS");
259 case WIFI_MANAGER_EAP_TYPE_TTLS:
260 type = g_strdup("TTLS");
262 case WIFI_MANAGER_EAP_TYPE_SIM:
263 type = g_strdup("SIM");
265 case WIFI_MANAGER_EAP_TYPE_AKA:
266 type = g_strdup("AKA");
268 case WIFI_MANAGER_EAP_TYPE_AKA_PRIME:
269 type = g_strdup("AKA'");
271 case WIFI_MANAGER_EAP_TYPE_FAST:
272 type = g_strdup("FAST");
274 case WIFI_MANAGER_EAP_TYPE_PWD:
275 type = g_strdup("PWD");
281 gchar *_wifi_eap_auth_type_to_string(wifi_manager_eap_auth_type_e eap_auth_type)
285 switch (eap_auth_type) {
286 case WIFI_MANAGER_EAP_AUTH_TYPE_PAP:
287 type = g_strdup("PAP");
289 case WIFI_MANAGER_EAP_AUTH_TYPE_MSCHAP:
290 type = g_strdup("MSCHAP");
292 case WIFI_MANAGER_EAP_AUTH_TYPE_MSCHAPV2:
293 type = g_strdup("MSCHAPV2");
295 case WIFI_MANAGER_EAP_AUTH_TYPE_GTC:
296 type = g_strdup("GTC");
298 case WIFI_MANAGER_EAP_AUTH_TYPE_MD5:
299 type = g_strdup("MD5");
302 case WIFI_MANAGER_EAP_AUTH_TYPE_NONE:
309 static void __clear_profile_internal_list(GSList *iterator)
313 for (list = iterator; list; list = list->next) {
314 net_profile_info_s *prof_info = (net_profile_info_s *)list->data;
316 if (prof_info->vsie_list) {
317 g_slist_free_full(prof_info->vsie_list, g_free);
318 prof_info->vsie_list = NULL;
321 if (prof_info->bssid_list) {
322 g_slist_free_full(prof_info->bssid_list, g_free);
323 prof_info->bssid_list = NULL;
328 void __clear_interface_list(GSList **iterator)
331 *iterator = g_slist_nth(*iterator, 0);
332 g_slist_free_full(*iterator, g_free);
338 void __clear_profile_list(GSList **iterator)
341 *iterator = g_slist_nth(*iterator, 0);
342 __clear_profile_internal_list(*iterator);
343 g_slist_free_full(*iterator, g_free);
348 gpointer _wifi_copy_vsie_list(gconstpointer data, gpointer user_data)
350 unsigned char *str = (unsigned char *)data;
352 vsie = g_try_malloc0(str[1]+2);
355 memcpy(vsie, str, str[1]+2);
357 WIFI_LOG(WIFI_ERROR, "Failed to allocate memory."); //LCOV_EXCL_LINE
362 gpointer _wifi_copy_bssid_list(gconstpointer data, gpointer user_data)
364 net_profile_bssid_list_s *org_data, *dst_data;
366 org_data = (net_profile_bssid_list_s *)data;
367 dst_data = g_try_malloc0(sizeof(net_profile_bssid_list_s));
369 g_strlcpy(dst_data->bssid, org_data->bssid, 18);
370 dst_data->strength = org_data->strength;
371 dst_data->frequency = org_data->frequency;
377 static int __update_profile_iterator(wifi_manager_handle_s *wifi_handle)
381 __clear_profile_list(&(wifi_handle->profile_iterator));
383 rv = net_get_profile_list(wifi_handle->network_info,
384 &(wifi_handle->profile_iterator));
385 if (rv == NET_ERR_ACCESS_DENIED) {
386 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
387 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
390 return WIFI_MANAGER_ERROR_NONE;
394 static int __update_interface_iterator(wifi_manager_handle_s *wifi_handle)
398 __clear_interface_list(&(wifi_handle->interface_iterator));
400 rv = net_get_interface_list(wifi_handle->network_info,
401 &(wifi_handle->interface_iterator));
402 if (rv == NET_ERR_ACCESS_DENIED) {
403 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
404 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
407 return WIFI_MANAGER_ERROR_NONE;
411 static void __update_specific_iterator(wifi_manager_handle_s *wifi_handle, GSList *bss_list)
414 GSList *list = bss_list;
415 net_profile_info_s *prof_info = NULL;
417 count = (int)g_slist_length(list);
419 WIFI_LOG(WIFI_INFO, "No hidden AP found"); //LCOV_EXCL_LINE
420 return; //LCOV_EXCL_LINE
423 for (i = 0; i < count; ++i) {
424 net_ssid_scan_bss_info_s *info = (net_ssid_scan_bss_info_s *)list->data;
425 prof_info = g_try_malloc0(sizeof(net_profile_info_s));
426 if (prof_info == NULL) {
427 WIFI_LOG(WIFI_ERROR, "Failed to alloc profile"); //LCOV_EXCL_LINE
428 return; //LCOV_EXCL_LINE
431 if (net_init_profile_info(wifi_handle->network_info, prof_info) != NET_ERR_NONE) {
432 WIFI_LOG(WIFI_ERROR, "Failed to init profile"); //LCOV_EXCL_LINE
433 g_free(prof_info); //LCOV_EXCL_LINE
434 return; //LCOV_EXCL_LINE
437 g_strlcpy(prof_info->essid, info->ssid, NET_WLAN_ESSID_LEN);
438 memcpy(prof_info->raw_ssid, info->raw_ssid, info->raw_ssid_len);
439 prof_info->raw_ssid_len = info->raw_ssid_len;
440 prof_info->security_info.sec_mode = info->security;
441 prof_info->security_info.wps_support = (char)info->wps;
443 wifi_handle->specific_profile_iterator =
444 g_slist_append(wifi_handle->specific_profile_iterator,
445 (net_profile_info_s *)prof_info);
449 static void __update_bss_profile_iterator(wifi_manager_handle_s *wifi_handle,
453 GSList *list = bss_list;
455 count = (int)g_slist_length(list);
457 WIFI_LOG(WIFI_INFO, "No AP found !!"); //LCOV_EXCL_LINE
458 return; //LCOV_EXCL_LINE
461 for (list = bss_list; list; list = list->next) {
463 net_bssid_scan_bss_info_s *ap = (net_bssid_scan_bss_info_s *)list->data;
464 net_profile_info_s *profile = g_try_malloc0(sizeof(net_profile_info_s));
465 if (profile == NULL) {
466 WIFI_LOG(WIFI_ERROR, "Failed to alloc profile"); //LCOV_EXCL_LINE
467 return; //LCOV_EXCL_LINE
470 if (net_init_profile_info(wifi_handle->network_info, profile) != NET_ERR_NONE) {
471 WIFI_LOG(WIFI_ERROR, "Failed to init profile"); //LCOV_EXCL_LINE
472 g_free(profile); //LCOV_EXCL_LINE
473 return; //LCOV_EXCL_LINE
476 g_strlcpy(profile->essid, (char *)ap->ssid, NET_WLAN_ESSID_LEN + 1);
477 g_strlcpy(profile->bssid, ap->bssid, WIFI_MAC_ADDR_LEN + 1);
479 profile->wlan_mode = ap->mode;
481 /* we receive the negative value of RSSI from the wpa supplicant.
482 * so modify the rssi value in same manner as done in connman. */
483 profile->Strength = 120 + ap->rssi;
484 profile->frequency = ap->freq;
486 wifi_handle->bss_profile_iterator =
487 g_slist_append(wifi_handle->bss_profile_iterator,
488 (net_profile_info_s *)profile);
493 static void __update_netlink_scan_profile_iterator(wifi_manager_handle_s *wifi_handle,
497 GSList *list = bss_list;
499 count = (int)g_slist_length(list);
501 WIFI_LOG(WIFI_INFO, "No AP found !!");
505 for (list = bss_list; list; list = list->next) {
507 net_netlink_scan_bss_info_s *ap = (net_netlink_scan_bss_info_s *)list->data;
508 net_profile_info_s *profile = g_try_malloc0(sizeof(net_profile_info_s));
509 if (profile == NULL) {
510 WIFI_LOG(WIFI_ERROR, "Failed to alloc profile");
514 if (net_init_profile_info(wifi_handle->network_info, profile) != NET_ERR_NONE) {
515 WIFI_LOG(WIFI_ERROR, "Failed to init profile");
520 g_strlcpy(profile->essid, ap->ssid, NET_WLAN_ESSID_LEN + 1);
521 g_strlcpy(profile->bssid, ap->bssid, WIFI_MAC_ADDR_LEN + 1);
526 for (l_list = ap->vsie_list; l_list; l_list = l_list->next) {
527 unsigned char *str = (unsigned char *)l_list->data;
529 vsie = g_try_malloc0(str[1]+2);
532 memcpy(vsie, str, str[1]+2);
533 profile->vsie_list = g_slist_append(profile->vsie_list, vsie);
535 WIFI_LOG(WIFI_ERROR, "Failed to allocate memory.");
538 g_slist_free_full(ap->vsie_list, g_free);
539 ap->vsie_list = NULL;
542 profile->frequency = (unsigned int)ap->freq;
543 profile->Strength = 120 + ap->rssi;
545 switch (ap->security_type) {
547 profile->security_info.sec_mode = WLAN_SEC_MODE_NONE;
550 profile->security_info.sec_mode = WLAN_SEC_MODE_WEP;
553 profile->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
556 profile->security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK;
559 profile->security_info.sec_mode = WLAN_SEC_MODE_SAE;
562 profile->security_info.sec_mode = WLAN_SEC_MODE_IEEE8021X;
565 profile->security_info.sec_mode = WLAN_SEC_MODE_NONE;
569 switch (ap->encryption_type) {
571 profile->security_info.enc_mode = WLAN_ENC_MODE_NONE;
574 profile->security_info.enc_mode = WLAN_ENC_MODE_WEP;
577 profile->security_info.enc_mode = WLAN_ENC_MODE_TKIP;
580 profile->security_info.enc_mode = WLAN_ENC_MODE_AES;
583 profile->security_info.enc_mode = WLAN_ENC_MODE_TKIP_AES_MIXED;
586 profile->security_info.enc_mode = WLAN_ENC_MODE_NONE;
590 wifi_handle->bss_profile_iterator = g_slist_append(wifi_handle->bss_profile_iterator,
591 (net_profile_info_s *)profile);
596 static void __convert_profile_info_to_wifi_info(net_wifi_connection_info_s *wifi_info,
597 net_profile_info_s *ap_info)
599 g_strlcpy(wifi_info->essid, ap_info->essid, NET_WLAN_ESSID_LEN+1);
600 memcpy(&wifi_info->raw_ssid, &ap_info->raw_ssid, NET_WLAN_RAW_SSID_LEN+1);
601 wifi_info->raw_ssid_len = ap_info->raw_ssid_len;
602 wifi_info->wlan_mode = ap_info->wlan_mode;
603 memcpy(&wifi_info->security_info, &ap_info->security_info, sizeof(wlan_security_info_s));
604 wifi_info->is_hidden = ap_info->is_hidden;
607 static int __connect_with_wifi_info(wifi_manager_handle_s *wifi_handle,
608 net_profile_info_s *ap_info)
610 net_wifi_connection_info_s wifi_info;
612 memset(&wifi_info, 0, sizeof(net_wifi_connection_info_s));
614 __convert_profile_info_to_wifi_info(&wifi_info, ap_info);
616 return net_open_connection_with_wifi_info(wifi_handle->network_info, &wifi_info);
619 static int __load_configurations(wifi_manager_handle_s *wifi_handle,
620 const gchar *config_id, wifi_config_s *config)
624 rv = net_config_load_configurations(wifi_handle->network_info,
625 config_id, &config->name, &config->passphrase,
626 &config->security_type, &config->proxy_address,
627 &config->is_hidden, (net_ip_info_config_s **)&config->ip_info,
628 &config->frequency, &config->last_error);
629 if (rv == NET_ERR_ACCESS_DENIED) {
630 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
631 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
632 } else if (rv == NET_ERR_NO_PROFILE) {
633 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
634 } else if (rv != NET_ERR_NONE)
635 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
637 return WIFI_MANAGER_ERROR_NONE;
640 static int __load_eap_configurations(wifi_manager_handle_s *wifi_handle,
641 const gchar *config_id, wifi_config_s *config)
645 rv = net_config_load_eap_configurations(wifi_handle->network_info,
646 config_id, &config->name, &config->security_type,
647 &config->proxy_address, &config->is_hidden,
648 (void **)&config->eap_config, &config->frequency,
649 &config->last_error);
650 if (rv == NET_ERR_ACCESS_DENIED) {
651 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
652 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
653 } else if (rv == NET_ERR_NO_PROFILE) {
654 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
655 } else if (rv != NET_ERR_NONE)
656 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
658 return WIFI_MANAGER_ERROR_NONE;
662 static void __state_changed_cb(wifi_manager_handle_s *wifi_handle, char *profile_name,
663 net_profile_info_s *profile_info, wifi_manager_connection_state_e state)
665 net_profile_info_s *ap_info = NULL;
667 if (profile_name == NULL)
670 WIFI_LOG(WIFI_INFO, "%s state changed : %s", profile_name, __convert_ap_state_to_string(state));
672 if (wifi_handle->connection_state_cb) {
673 ap_info = g_try_malloc0(sizeof(net_profile_info_s));
674 if (ap_info == NULL) {
675 WIFI_LOG(WIFI_ERROR, "Memory allocation error");
680 memcpy(ap_info, profile_info, sizeof(net_profile_info_s));
681 ap_info->vsie_list = g_slist_copy_deep(profile_info->vsie_list,
682 _wifi_copy_vsie_list,
685 ap_info->bssid_list = g_slist_copy_deep(profile_info->bssid_list,
686 _wifi_copy_bssid_list,
689 ap_info->network_info = wifi_handle->network_info;
692 WIFI_LOG(WIFI_INFO, "[Ap info] profile name(%s) essid(%s) bssid(%s)",
693 ap_info->ProfileName, ap_info->essid, ap_info->bssid);
695 _wifi_add_to_ap_list(ap_info);
697 wifi_handle->connection_state_cb(state, ap_info,
698 wifi_handle->connection_state_user_data);
700 _wifi_remove_from_ap_list(ap_info);
702 if (ap_info->vsie_list)
703 g_slist_free_full(ap_info->vsie_list, g_free);
704 if (ap_info->bssid_list)
705 g_slist_free_full(ap_info->bssid_list, g_free);
711 static void __set_activated_cb(wifi_manager_handle_s *wifi_handle,
712 wifi_manager_activated_cb user_cb, void *user_data)
714 wifi_handle->activated_cb = user_cb;
715 wifi_handle->activated_user_data = user_data;
718 static void __set_deactivated_cb(wifi_manager_handle_s *wifi_handle,
719 wifi_manager_deactivated_cb user_cb, void *user_data)
721 wifi_handle->deactivated_cb = user_cb;
722 wifi_handle->deactivated_user_data = user_data;
725 static void __power_on_off_cb(wifi_manager_handle_s *wifi_handle,
726 net_event_info_s *event_cb, bool is_requested)
728 wifi_manager_error_e error_code = WIFI_MANAGER_ERROR_NONE;
729 wifi_manager_device_state_e state = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED;
730 net_wifi_state_e *wifi_state = (net_wifi_state_e *)event_cb->Data;
732 if (wifi_handle->activated_cb == NULL &&
733 wifi_handle->deactivated_cb == NULL &&
734 wifi_handle->device_state_cb == NULL)
737 if (event_cb->Error == NET_ERR_NONE &&
738 event_cb->Datalength == sizeof(net_wifi_state_e)) {
739 if (*wifi_state == WIFI_ON) {
740 WIFI_LOG(WIFI_INFO, "Wi-Fi power on");
741 state = WIFI_MANAGER_DEVICE_STATE_ACTIVATED;
742 } else if (*wifi_state == WIFI_OFF) {
743 WIFI_LOG(WIFI_INFO, "Wi-Fi power off");
744 state = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED;
745 __clear_profile_list(&(wifi_handle->profile_iterator));
746 __clear_profile_list(&(wifi_handle->specific_profile_iterator));
747 __clear_profile_list(&(wifi_handle->bss_profile_iterator));
749 WIFI_LOG(WIFI_ERROR, "Error Wi-Fi state %d", *wifi_state);
750 error_code = WIFI_MANAGER_ERROR_OPERATION_FAILED;
751 state = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED;
754 WIFI_LOG(WIFI_ERROR, "Wi-Fi power request failed(%d)", event_cb->Error);
756 if (event_cb->Error == NET_ERR_SECURITY_RESTRICTED)
757 error_code = WIFI_MANAGER_ERROR_SECURITY_RESTRICTED;
759 error_code = WIFI_MANAGER_ERROR_OPERATION_FAILED;
761 state = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED;
764 if (wifi_handle->activated_cb)
765 wifi_handle->activated_cb(error_code, wifi_handle->activated_user_data);
767 wifi_handle->activated_cb = NULL;
768 wifi_handle->activated_user_data = NULL;
770 if (wifi_handle->deactivated_cb)
771 wifi_handle->deactivated_cb(error_code, wifi_handle->deactivated_user_data);
773 wifi_handle->deactivated_cb = NULL;
774 wifi_handle->deactivated_user_data = NULL;
776 if (error_code == WIFI_MANAGER_ERROR_NONE) {
777 if (wifi_handle->device_state_cb)
778 wifi_handle->device_state_cb(state, wifi_handle->device_state_user_data);
782 static void __set_scan_cb(wifi_manager_handle_s *wifi_handle,
783 wifi_manager_scan_finished_cb user_cb, void *user_data)
785 wifi_handle->scan_request_cb = user_cb;
786 wifi_handle->scan_request_user_data = user_data;
789 static void __set_specific_scan_cb(wifi_manager_handle_s *wifi_handle,
790 wifi_manager_scan_finished_cb user_cb, void *user_data)
792 wifi_handle->specific_scan_cb = user_cb;
793 wifi_handle->specific_scan_user_data = user_data;
796 static void __set_bssid_scan_cb(wifi_manager_handle_s *wifi_handle,
797 wifi_manager_bssid_scan_finished_cb user_cb, void *user_data)
799 wifi_handle->bssid_scan_cb = user_cb;
800 wifi_handle->bssid_scan_user_data = user_data;
803 static void __set_netlink_scan_cb(wifi_manager_handle_s *wifi_handle,
804 wifi_manager_netlink_scan_finished_cb user_cb, void *user_data)
806 wifi_handle->netlink_scan_cb = user_cb;
807 wifi_handle->netlink_scan_user_data = user_data;
810 static void __set_multi_scan_cb(wifi_manager_handle_s *wifi_handle,
811 wifi_manager_scan_finished_cb user_cb, void *user_data)
813 wifi_handle->multi_scan_cb = user_cb;
814 wifi_handle->multi_scan_user_data = user_data;
817 static void __scan_cb(wifi_manager_handle_s *wifi_handle,
818 net_event_info_s *event_cb, bool is_requested)
820 wifi_manager_error_e error_code = WIFI_MANAGER_ERROR_NONE;
822 if (event_cb->Error != NET_ERR_NONE) {
823 WIFI_LOG(WIFI_ERROR, "Scan failed[%d]", event_cb->Error);
824 error_code = WIFI_MANAGER_ERROR_OPERATION_FAILED;
827 if (wifi_handle->scan_request_cb) {
828 wifi_handle->scan_request_cb(error_code, wifi_handle->scan_request_user_data);
830 wifi_handle->scan_request_cb = NULL;
831 wifi_handle->scan_request_user_data = NULL;
836 if (wifi_handle->bg_scan_cb)
837 wifi_handle->bg_scan_cb(error_code, wifi_handle->bg_scan_user_data);
840 static void __scan_changed_cb(wifi_manager_handle_s *wifi_handle, wifi_manager_scan_state_e scan_state)
843 WIFI_LOG(WIFI_INFO, "scan state: Scan is in progress");
845 WIFI_LOG(WIFI_INFO, "scan state: Scan is not running");
847 if (wifi_handle->scan_changed_cb)
848 wifi_handle->scan_changed_cb(scan_state, wifi_handle->scan_changed_user_data);
851 static void __specific_scan_cb(wifi_manager_handle_s *wifi_handle, net_event_info_s *event_cb)
853 wifi_manager_error_e error_code = WIFI_MANAGER_ERROR_NONE;
855 __clear_profile_list(&(wifi_handle->specific_profile_iterator));
857 if (event_cb->Error != NET_ERR_NONE) {
858 WIFI_LOG(WIFI_ERROR, "Specific scan failed!, Error [%d]", event_cb->Error);
859 error_code = WIFI_MANAGER_ERROR_OPERATION_FAILED;
860 } else if (event_cb->Data) {
861 __update_specific_iterator(wifi_handle, (GSList *)event_cb->Data);
862 WIFI_LOG(WIFI_INFO, "Specific AP count : %d",
863 (int)g_slist_length(wifi_handle->specific_profile_iterator));
866 if (wifi_handle->specific_scan_cb)
867 wifi_handle->specific_scan_cb(error_code, wifi_handle->specific_scan_user_data);
869 wifi_handle->specific_scan_cb = NULL;
870 wifi_handle->specific_scan_user_data = NULL;
873 static void __bssid_scan_cb(wifi_manager_handle_s *wifi_handle, net_event_info_s *event_cb)
875 wifi_manager_error_e error_code = WIFI_MANAGER_ERROR_NONE;
877 __clear_profile_list(&(wifi_handle->bss_profile_iterator));
879 if (event_cb->Error != NET_ERR_NONE) {
880 WIFI_LOG(WIFI_ERROR, "BSSID scan failed!, Error [%d]",
882 error_code = WIFI_MANAGER_ERROR_OPERATION_FAILED;
883 } else if (event_cb->Data) {
884 __update_bss_profile_iterator(wifi_handle, (GSList *)event_cb->Data);
885 WIFI_LOG(WIFI_INFO, "BSS AP count : %d",
886 (int)g_slist_length(wifi_handle->bss_profile_iterator));
889 if (wifi_handle->bssid_scan_cb)
890 wifi_handle->bssid_scan_cb(error_code, wifi_handle->bssid_scan_user_data);
892 wifi_handle->bssid_scan_cb = NULL;
893 wifi_handle->bssid_scan_user_data = NULL;
896 static void __ip_conflict_cb(wifi_manager_handle_s *wifi_handle, net_event_info_s *event_cb)
900 net_ip_conflict_info_s *conflict_info = NULL;
901 wifi_manager_ip_conflict_state_e conflict_state = WIFI_MANAGER_IP_CONFLICT_STATE_UNKNOWN;
903 __clear_profile_list(&(wifi_handle->bss_profile_iterator));
905 if (event_cb->Data) {
906 conflict_info = (net_ip_conflict_info_s *)event_cb->Data;
907 state = conflict_info->state;
908 if (!strcmp(state, "conflict")) {
909 conflict_state = WIFI_MANAGER_IP_CONFLICT_STATE_CONFLICT_DETECTED;
910 mac = conflict_info->mac;
911 } else if (!strcmp(state, "unknown")) {
912 conflict_state = WIFI_MANAGER_IP_CONFLICT_STATE_UNKNOWN;
913 } else if (!strcmp(state, "resolved")) {
914 conflict_state = WIFI_MANAGER_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED;
918 if (wifi_handle->ip_conflict_cb)
919 wifi_handle->ip_conflict_cb(mac, conflict_state, wifi_handle->ip_conflict_user_data);
922 static void __netlink_scan_cb(wifi_manager_handle_s *wifi_handle, net_event_info_s *event_cb)
924 wifi_manager_error_e error_code = WIFI_MANAGER_ERROR_NONE;
926 __clear_profile_list(&(wifi_handle->bss_profile_iterator));
928 if (event_cb->Error != NET_ERR_NONE) {
929 WIFI_LOG(WIFI_ERROR, "NETLINK scan failed!, Error [%d]",
931 error_code = WIFI_MANAGER_ERROR_OPERATION_FAILED;
932 } else if (event_cb->Data) {
933 __update_netlink_scan_profile_iterator(wifi_handle, (GSList *)event_cb->Data);
934 WIFI_LOG(WIFI_INFO, "BSS AP count : %d",
935 (int)g_slist_length(wifi_handle->bss_profile_iterator));
938 if (wifi_handle->netlink_scan_cb)
939 wifi_handle->netlink_scan_cb(error_code, wifi_handle->netlink_scan_user_data);
941 wifi_handle->netlink_scan_cb = NULL;
942 wifi_handle->netlink_scan_user_data = NULL;
945 static void __multi_scan_cb(wifi_manager_handle_s *wifi_handle, net_event_info_s *event_cb)
947 wifi_manager_error_e error_code = WIFI_MANAGER_ERROR_NONE;
949 if (event_cb->Error != NET_ERR_NONE) {
950 WIFI_LOG(WIFI_ERROR, "Multi Scan failed[%d]", event_cb->Error);
951 error_code = WIFI_MANAGER_ERROR_OPERATION_FAILED;
954 if (wifi_handle->multi_scan_cb)
955 wifi_handle->multi_scan_cb(error_code, wifi_handle->multi_scan_user_data);
957 wifi_handle->multi_scan_cb = NULL;
958 wifi_handle->multi_scan_user_data = NULL;
961 static void __set_connected_cb(wifi_manager_handle_s *wifi_handle,
962 wifi_manager_connected_cb user_cb, void *user_data)
964 wifi_handle->connected_cb = user_cb;
965 wifi_handle->connected_user_data = user_data;
968 static void __connected_cb(wifi_manager_handle_s *wifi_handle, wifi_manager_error_e result)
970 if (wifi_handle->connected_cb)
971 wifi_handle->connected_cb(result, wifi_handle->connected_user_data);
973 wifi_handle->connected_cb = NULL;
974 wifi_handle->connected_user_data = NULL;
977 static void __set_disconnected_cb(wifi_manager_handle_s *wifi_handle,
978 wifi_manager_disconnected_cb user_cb, void *user_data)
980 wifi_handle->disconnected_cb = user_cb;
981 wifi_handle->disconnected_user_data = user_data;
984 static void __disconnected_cb(wifi_manager_handle_s *wifi_handle,
985 wifi_manager_error_e result)
987 if (wifi_handle->disconnected_cb)
988 wifi_handle->disconnected_cb(result, wifi_handle->disconnected_user_data);
990 wifi_handle->disconnected_cb = NULL;
991 wifi_handle->disconnected_user_data = NULL;
994 static void __tdls_discovered_cb(wifi_manager_handle_s *wifi_handle,
995 net_event_info_s *event_cb)
997 char *peer_mac_add = NULL;
998 net_tdls_discover_s *discover_info;
999 wifi_manager_tdls_discovery_state_e state;
1000 discover_info = (net_tdls_discover_s*)event_cb->Data;
1002 if (discover_info == NULL) {
1003 WIFI_LOG(WIFI_INFO, "Discover Data is NULL !!!");
1007 peer_mac_add = discover_info->mac_add;
1009 WIFI_LOG(WIFI_INFO, "Peer Mac Add %s , Type[%d] ", peer_mac_add, discover_info->type);
1011 if (discover_info->type == 0) //TDLS Discovery : Unicast
1012 state = WIFI_MANAGER_TDLS_DISCOVERY_STATE_FINISHED;
1014 else if (discover_info->type == 1 &&
1015 (NULL != strstr("00:00:00:00:00:00", peer_mac_add))) {
1017 WIFI_LOG(WIFI_INFO, "TDLS: Broadcast Discovery Timeout Event");
1018 state = WIFI_MANAGER_TDLS_DISCOVERY_STATE_FINISHED;
1020 state = WIFI_MANAGER_TDLS_DISCOVERY_STATE_ONGOING;
1022 if (wifi_handle->tdls_discovered_cb)
1023 wifi_handle->tdls_discovered_cb(state, peer_mac_add,
1024 wifi_handle->tdls_discovered_user_data);
1028 static void __tdls_state_changed_cb(wifi_manager_handle_s *wifi_handle,
1029 wifi_manager_tdls_state_e state, net_event_info_s *event_cb)
1031 char *peer_mac_add = NULL;
1032 peer_mac_add = (char*)event_cb->Data;
1034 WIFI_LOG(WIFI_INFO, "Peer Mac Add %s ", peer_mac_add);
1036 if (wifi_handle->tdls_state_changed_cb)
1037 wifi_handle->tdls_state_changed_cb(state, peer_mac_add,
1038 wifi_handle->tdls_state_changed_user_data);
1042 static void __set_forget_ap_cb(wifi_manager_handle_s *wifi_handle,
1043 wifi_manager_forget_ap_finished_cb user_cb, void *user_data)
1045 wifi_handle->forget_ap_cb = user_cb;
1046 wifi_handle->forget_ap_user_data = user_data;
1049 static void __forget_ap_cb(wifi_manager_handle_s *wifi_handle, wifi_manager_error_e result)
1051 if (wifi_handle->forget_ap_cb)
1052 wifi_handle->forget_ap_cb(result, wifi_handle->forget_ap_user_data);
1054 wifi_handle->forget_ap_cb = NULL;
1055 wifi_handle->forget_ap_user_data = NULL;
1058 static void __rssi_level_changed_cb(wifi_manager_handle_s *wifi_handle,
1059 net_rssi_info_s *rssi_info)
1061 if (wifi_handle->rssi_level_changed_cb) {
1062 if (!g_strcmp0(wifi_handle->interface_name, rssi_info->ifname))
1063 wifi_handle->rssi_level_changed_cb(rssi_info->rssi_level,
1064 wifi_handle->rssi_level_changed_user_data);
1069 static void __module_state_changed_cb(wifi_manager_handle_s *wifi_handle,
1070 net_module_info_s *module_info)
1072 if (wifi_handle->module_state_changed_cb) {
1073 if (!g_strcmp0(wifi_handle->interface_name, module_info->ifname))
1074 wifi_handle->module_state_changed_cb(module_info->status_uevent,
1075 wifi_handle->module_state_changed_user_data);
1079 static void __raise_dpp_event_callback(wifi_manager_handle_s *wifi_handle,
1080 wifi_manager_dpp_event_e event, wifi_manager_dpp_state_e state)
1082 if (wifi_handle->dpp_event_cb)
1083 wifi_handle->dpp_event_cb(event, state, g_p_dpp_current,
1084 wifi_handle->dpp_event_user_data);
1087 static void __dpp_uri_generated_cb(wifi_manager_handle_s *wifi_handle,
1088 net_dpp_event_info_s *dpp_event_info)
1090 if (g_p_dpp_current) {
1091 g_p_dpp_current->own_uri = g_strdup(dpp_event_info->own_uri);
1092 g_p_dpp_current->own_id = dpp_event_info->own_id;
1095 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_URI_GENERATED,
1096 WIFI_MANAGER_DPP_STATE_NONE);
1099 static void __dpp_bootstrapped_cb(wifi_manager_handle_s *wifi_handle,
1100 net_dpp_event_info_s *dpp_event_info)
1102 if (g_p_dpp_current) {
1103 g_p_dpp_current->peer_id = dpp_event_info->peer_id;
1104 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_BOOTSTRAPPED;
1107 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1108 WIFI_MANAGER_DPP_STATE_BOOTSTRAPPED);
1111 static void __dpp_awaiting_cb(wifi_manager_handle_s *wifi_handle,
1112 net_dpp_event_info_s *dpp_event_info)
1114 if (g_p_dpp_current)
1115 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_AWAITING;
1117 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1118 WIFI_MANAGER_DPP_STATE_AWAITING);
1121 static void __dpp_authenticating_cb(wifi_manager_handle_s *wifi_handle,
1122 net_dpp_event_info_s *dpp_event_info)
1124 if (g_p_dpp_current)
1125 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_AUTHENTICATING;
1127 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1128 WIFI_MANAGER_DPP_STATE_AUTHENTICATING);
1131 static void __dpp_auth_success_cb(wifi_manager_handle_s *wifi_handle,
1132 net_dpp_event_info_s *dpp_event_info)
1134 if (g_p_dpp_current)
1135 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_AUTHENTICATED;
1137 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1138 WIFI_MANAGER_DPP_STATE_AUTHENTICATED);
1141 static void __dpp_auth_failed_cb(wifi_manager_handle_s *wifi_handle,
1142 net_dpp_event_info_s *dpp_event_info)
1144 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_AUTH_FAILED,
1145 WIFI_MANAGER_DPP_STATE_NONE);
1148 static void __dpp_not_compatible_cb(wifi_manager_handle_s *wifi_handle,
1149 net_dpp_event_info_s *dpp_event_info)
1151 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_NOT_COMPATIBLE,
1152 WIFI_MANAGER_DPP_STATE_NONE);
1155 static void __dpp_conf_failed_cb(wifi_manager_handle_s *wifi_handle,
1156 net_dpp_event_info_s *dpp_event_info)
1158 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_CONF_FAILED,
1159 WIFI_MANAGER_DPP_STATE_NONE);
1162 static void __dpp_scan_peer_qr_cb(wifi_manager_handle_s *wifi_handle,
1163 net_dpp_event_info_s *dpp_event_info)
1165 if (g_p_dpp_current)
1166 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_URI_REQUESTED;
1168 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1169 WIFI_MANAGER_DPP_STATE_URI_REQUESTED);
1172 static void __dpp_network_id_cb(wifi_manager_handle_s *wifi_handle,
1173 net_dpp_event_info_s *dpp_event_info)
1175 if (g_p_dpp_current)
1176 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_CONFIGURED;
1178 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1179 WIFI_MANAGER_DPP_STATE_CONFIGURED);
1182 static void __dpp_conf_sent_cb(wifi_manager_handle_s *wifi_handle,
1183 net_dpp_event_info_s *dpp_event_info)
1185 if (g_p_dpp_current)
1186 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_CONFIGURING;
1188 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1189 WIFI_MANAGER_DPP_STATE_CONFIGURING);
1192 static void __dpp_conf_received_cb(wifi_manager_handle_s *wifi_handle,
1193 net_dpp_event_info_s *dpp_event_info)
1195 if (g_p_dpp_current)
1196 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_CONFIGURED;
1198 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1199 WIFI_MANAGER_DPP_STATE_CONFIGURED);
1202 static void __dpp_failed_cb(wifi_manager_handle_s *wifi_handle,
1203 net_dpp_event_info_s *dpp_event_info)
1205 if (g_p_dpp_current) {
1206 g_p_dpp_current->peer_id = 0;
1207 g_p_dpp_current->own_id = 0;
1208 g_free(g_p_dpp_current->own_uri);
1209 g_p_dpp_current->own_uri = NULL;
1210 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_NONE;
1213 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_REQUEST_FAILED,
1214 WIFI_MANAGER_DPP_STATE_NONE);
1216 g_p_dpp_current = NULL;
1219 static void __dpp_removed_cb(wifi_manager_handle_s *wifi_handle,
1220 net_dpp_event_info_s *dpp_event_info)
1222 if (g_p_dpp_current) {
1223 g_p_dpp_current->peer_id = 0;
1224 g_p_dpp_current->own_id = 0;
1225 g_free(g_p_dpp_current->own_uri);
1226 g_p_dpp_current->own_uri = NULL;
1227 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_NONE;
1230 __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1231 WIFI_MANAGER_DPP_STATE_NONE);
1233 g_p_dpp_current = NULL;
1236 static void __roaming_state_changed_cb(wifi_manager_handle_s *wifi_handle,
1237 net_roam_event_info_s *roam_event_info)
1239 char *cur_bssid = NULL;
1240 char *dst_bssid = NULL;
1241 char *state = roam_event_info->state;
1242 wifi_manager_roam_e roam_state = WIFI_MANAGER_ROAM_UNKNOWN;
1245 if (!strcmp(state, "required")) {
1246 roam_state = WIFI_MANAGER_ROAM_SCAN_REQUIRED;
1247 cur_bssid = roam_event_info->cur_bssid;
1248 } else if (!strcmp(state, "started")) {
1249 roam_state = WIFI_MANAGER_ROAM_STARTED;
1250 cur_bssid = roam_event_info->cur_bssid;
1251 dst_bssid = roam_event_info->dst_bssid;
1252 } else if (!strcmp(state, "failure")) {
1253 roam_state = WIFI_MANAGER_ROAM_FAILURE;
1254 cur_bssid = roam_event_info->cur_bssid;
1255 dst_bssid = roam_event_info->dst_bssid;
1256 } else if (!strcmp(state, "success")) {
1257 roam_state = WIFI_MANAGER_ROAM_SUCCESS;
1258 cur_bssid = roam_event_info->cur_bssid;
1259 dst_bssid = roam_event_info->dst_bssid;
1263 WIFI_LOG(WIFI_INFO, "Roaming state: %s, cur_bssid %s, dst_bssid %s",
1264 state, cur_bssid, dst_bssid);
1266 if (wifi_handle->roaming_state_changed_cb)
1267 wifi_handle->roaming_state_changed_cb(roam_state,
1268 cur_bssid, dst_bssid, wifi_handle->roaming_state_changed_user_data);
1272 static void _wifi_evt_cb(net_event_info_s *event_cb, void *user_data)
1275 bool is_requested = false;
1276 net_profile_info_s *prof_info_p = NULL;
1277 wifi_manager_error_e result = WIFI_MANAGER_ERROR_NONE;
1278 wifi_manager_handle_s *wifi_handle = user_data;
1280 if (!__wifi_check_handle_validity(wifi_handle)) {
1281 WIFI_LOG(WIFI_ERROR, "Wifi handle is not initialized");
1286 switch (event_cb->Event) {
1287 case NET_EVENT_OPEN_RSP:
1288 case NET_EVENT_WIFI_WPS_RSP:
1289 is_requested = true;
1291 case NET_EVENT_OPEN_IND:
1292 if ((_wifi_check_profile_name_validity(event_cb->ProfileName) !=
1293 true) && (event_cb->Error !=
1294 NET_ERR_CONNECTION_CONNECT_FAILED) &&
1296 NET_ERR_CONNECTION_WPS_TIMEOUT) &&
1298 NET_ERR_CONNECTION_WPS_OVERLAP) &&
1300 NET_ERR_CONNECTION_WPS_WEP_PROHIBITED)) {
1305 result = __convert_to_ap_error_type(event_cb->Error);
1306 WIFI_LOG(WIFI_INFO, "Connection open error %s",
1307 __convert_ap_error_type_to_string(result));
1310 __connected_cb(wifi_handle, result);
1312 switch (event_cb->Error) {
1314 if (event_cb->Datalength == sizeof(net_profile_info_s))
1315 prof_info_p = (net_profile_info_s *)event_cb->Data;
1317 __state_changed_cb(wifi_handle, event_cb->ProfileName, prof_info_p,
1318 WIFI_MANAGER_CONNECTION_STATE_CONNECTED);
1321 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
1325 if (event_cb->Datalength == sizeof(net_profile_info_s))
1326 prof_info_p = (net_profile_info_s *)event_cb->Data;
1328 __state_changed_cb(wifi_handle, event_cb->ProfileName, prof_info_p,
1329 WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED);
1335 case NET_EVENT_CLOSE_RSP:
1336 is_requested = true;
1338 case NET_EVENT_CLOSE_IND:
1339 if (_wifi_check_profile_name_validity(event_cb->ProfileName) != true) {
1344 result = __convert_to_ap_error_type(event_cb->Error);
1345 WIFI_LOG(WIFI_ERROR, "Connection close error %s",
1346 __convert_ap_error_type_to_string(result));
1349 __disconnected_cb(wifi_handle, result);
1351 switch (event_cb->Error) {
1353 if (event_cb->Datalength == sizeof(net_profile_info_s))
1354 prof_info_p = (net_profile_info_s *)event_cb->Data;
1356 __state_changed_cb(wifi_handle, event_cb->ProfileName, prof_info_p,
1357 WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED);
1359 WIFI_LOG(WIFI_INFO, "Connection close succeeded!");
1360 /* Checking if disconnection request was sent when WPS PBC connection
1361 * was requested, if true then start WPS PBC connection request */
1362 if (wifi_handle->is_disconnect_wps_pbc) {
1363 net_wifi_wps_info_s wps_info;
1364 memset(&wps_info, 0, sizeof(net_wifi_wps_info_s));
1365 wps_info.type = WIFI_WPS_PBC;
1366 if (net_wifi_enroll_wps_without_ssid(wifi_handle->network_info, &wps_info) != NET_ERR_NONE)
1367 __connected_cb(wifi_handle, WIFI_MANAGER_ERROR_OPERATION_FAILED);
1368 wifi_handle->is_disconnect_wps_pbc = false;
1370 /* Checking if disconnection request was sent when WPS PIN connection
1371 * was requested, if true then start WPS PIN connection request */
1372 else if (wifi_handle->is_disconnect_wps_pin) {
1373 net_wifi_wps_info_s wps_info;
1374 memset(&wps_info, 0, sizeof(net_wifi_wps_info_s));
1375 wps_info.type = WIFI_WPS_PIN;
1376 g_strlcpy(wps_info.pin, wifi_handle->wps_pin, NET_WLAN_MAX_WPSPIN_LEN + 1);
1377 if (net_wifi_enroll_wps_without_ssid(wifi_handle->network_info, &wps_info) != NET_ERR_NONE)
1378 __connected_cb(wifi_handle, WIFI_MANAGER_ERROR_OPERATION_FAILED);
1379 memset(wifi_handle->wps_pin, 0, sizeof(wifi_handle->wps_pin));
1380 wifi_handle->is_disconnect_wps_pin = false;
1390 case NET_EVENT_NET_STATE_IND:
1391 if (_wifi_check_profile_name_validity(event_cb->ProfileName) != true) {
1396 if (event_cb->Datalength != sizeof(net_profile_info_s)) {
1401 prof_info_p = (net_profile_info_s *)event_cb->Data;
1402 net_state_type_e profile_state = prof_info_p->ProfileState;
1403 wifi_manager_connection_state_e ap_state = _wifi_convert_to_ap_state(profile_state);
1405 WIFI_LOG(WIFI_INFO, "state: %s", __convert_ap_state_to_string(ap_state));
1406 WIFI_LOG(WIFI_INFO, "profile name: %s", event_cb->ProfileName);
1408 if (ap_state == WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED) {
1409 net_profile_info_s *profile = NULL;
1410 bool is_profile_exists = false;
1412 for (GSList *list = wifi_handle->profile_iterator; list; list = list->next) {
1413 profile = (net_profile_info_s *)list->data;
1414 if (!g_strcmp0(event_cb->ProfileName, profile->ProfileName)) {
1415 is_profile_exists = true;
1420 if (is_profile_exists == false)
1424 __state_changed_cb(wifi_handle, event_cb->ProfileName, prof_info_p, ap_state);
1426 case NET_EVENT_WIFI_SCAN_RSP:
1427 case NET_EVENT_WIFI_SCAN_IND:
1428 __scan_cb(wifi_handle, event_cb, is_requested);
1430 case NET_EVENT_WIFI_SPECIFIC_SCAN_RSP:
1431 WIFI_LOG(WIFI_INFO, "Got Wi-Fi specific scan RSP");
1432 __specific_scan_cb(wifi_handle, event_cb);
1434 case NET_EVENT_WIFI_SPECIFIC_SCAN_IND:
1435 WIFI_LOG(WIFI_INFO, "Got Wi-Fi specific scan IND");
1436 __specific_scan_cb(wifi_handle, event_cb);
1438 case NET_EVENT_WIFI_BSSID_SCAN_IND:
1439 WIFI_LOG(WIFI_INFO, "Got BSSID scan done IND");
1440 __bssid_scan_cb(wifi_handle, event_cb);
1442 case NET_EVENT_WIFI_IP_CONFLICT_IND:
1443 WIFI_LOG(WIFI_INFO, "Got ip conflict event IND"); //LCOV_EXCL_LINE
1444 __ip_conflict_cb(wifi_handle, event_cb); //LCOV_EXCL_LINE
1446 case NET_EVENT_WIFI_NETLINK_SCAN_IND:
1447 WIFI_LOG(WIFI_INFO, "Got NETLINK scan done IND"); //LCOV_EXCL_LINE
1448 __netlink_scan_cb(wifi_handle, event_cb); //LCOV_EXCL_LINE
1450 case NET_EVENT_WIFI_SCAN_CHANGED:
1451 WIFI_LOG(WIFI_INFO, "Got Wi-Fi ScanChanged event");
1452 wifi_manager_scan_state_e *scan_state = (wifi_manager_scan_state_e *)event_cb->Data;
1453 __scan_changed_cb(wifi_handle, *scan_state);
1455 case NET_EVENT_WIFI_POWER_RSP:
1456 is_requested = true;
1458 case NET_EVENT_WIFI_POWER_IND:
1459 __power_on_off_cb(wifi_handle, event_cb, is_requested);
1461 case NET_EVENT_WIFI_TDLS_DISCOVERED_IND:
1462 WIFI_LOG(WIFI_INFO, "Received TDLS Discover Ind"); //LCOV_EXCL_LINE
1463 __tdls_discovered_cb(wifi_handle, event_cb); //LCOV_EXCL_LINE
1465 case NET_EVENT_WIFI_TDLS_CONNECTED_IND:
1466 WIFI_LOG(WIFI_INFO, "Received TDLS Connected Ind"); //LCOV_EXCL_LINE
1467 __tdls_state_changed_cb(wifi_handle, WIFI_MANAGER_TDLS_STATE_CONNECTED, event_cb); //LCOV_EXCL_LINE
1469 case NET_EVENT_WIFI_TDLS_DISCONNECTED_IND:
1470 WIFI_LOG(WIFI_INFO, "Received TDLS Disconnected Ind"); //LCOV_EXCL_LINE
1471 __tdls_state_changed_cb(wifi_handle, WIFI_MANAGER_TDLS_STATE_DISCONNECTED, event_cb); //LCOV_EXCL_LINE
1473 case NET_EVENT_WIFI_MULTI_SCAN_RSP:
1474 WIFI_LOG(WIFI_INFO, "Got Wi-Fi multi scan RSP"); //LCOV_EXCL_LINE
1475 __multi_scan_cb(wifi_handle, event_cb); //LCOV_EXCL_LINE
1477 case NET_EVENT_WIFI_MULTI_SCAN_IND:
1478 WIFI_LOG(WIFI_INFO, "Got Wi-Fi multi scan IND"); //LCOV_EXCL_LINE
1479 __multi_scan_cb(wifi_handle, event_cb); //LCOV_EXCL_LINE
1481 case NET_EVENT_WIFI_FORGET_AP_IND:
1482 WIFI_LOG(WIFI_INFO, "Got Wi-Fi forget AP IND"); //LCOV_EXCL_LINE
1483 __forget_ap_cb(wifi_handle, event_cb->Error); //LCOV_EXCL_LINE
1485 case NET_EVENT_WIFI_RSSI_CHANGED:
1486 case NET_EVENT_WIFI_RSSI_LEVEL_CHANGED:
1487 __rssi_level_changed_cb(wifi_handle, (net_rssi_info_s *)event_cb->Data);
1490 case NET_EVENT_WIFI_MODULE_STATE_CHANGED:
1491 __module_state_changed_cb(wifi_handle, (net_module_info_s *)event_cb->Data);
1493 case NET_EVENT_WIFI_DPP_URI_GENERATED:
1494 __dpp_uri_generated_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1496 case NET_EVENT_WIFI_DPP_BOOTSTRAPPED:
1497 __dpp_bootstrapped_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1499 case NET_EVENT_WIFI_DPP_AWAITING:
1500 __dpp_awaiting_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1502 case NET_EVENT_WIFI_DPP_AUTHENTICATING:
1503 __dpp_authenticating_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1505 case NET_EVENT_WIFI_DPP_AUTH_SUCCESS:
1506 __dpp_auth_success_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1508 case NET_EVENT_WIFI_DPP_AUTH_FAILED:
1509 __dpp_auth_failed_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1511 case NET_EVENT_WIFI_DPP_NOT_COMPATIBLE:
1512 __dpp_not_compatible_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1514 case NET_EVENT_WIFI_DPP_CONF_FAILED:
1515 __dpp_conf_failed_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1517 case NET_EVENT_WIFI_DPP_SCAN_PEER_QR:
1518 __dpp_scan_peer_qr_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1520 case NET_EVENT_WIFI_DPP_NETWORK_ID:
1521 __dpp_network_id_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1523 case NET_EVENT_WIFI_DPP_CONF_SENT:
1524 __dpp_conf_sent_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1526 case NET_EVENT_WIFI_DPP_CONF_RECEIVED:
1527 __dpp_conf_received_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1529 case NET_EVENT_WIFI_DPP_FAILED:
1530 __dpp_failed_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1532 case NET_EVENT_WIFI_DPP_REMOVED:
1533 __dpp_removed_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1535 case NET_EVENT_WIFI_ROAM_STATE_IND:
1536 __roaming_state_changed_cb(wifi_handle, (net_roam_event_info_s *)event_cb->Data);
1546 int _wifi_init(wifi_manager_h wifi, const char *ifname)
1549 wifi_manager_handle_s *wifi_handle = wifi;
1551 rv = net_register_client_ext(&(wifi_handle->network_info),
1552 ifname, (net_event_cb)_wifi_evt_cb, wifi);
1553 if (rv != NET_ERR_NONE && rv != NET_ERR_APP_ALREADY_REGISTERED) {
1554 WIFI_LOG(WIFI_ERROR, "Failed to register client [%d]", rv); //LCOV_EXCL_LINE
1555 return rv; //LCOV_EXCL_LINE
1558 g_strlcpy(wifi_handle->interface_name,
1559 wifi_handle->network_info->interface_name, NET_WLAN_IF_NAME_LEN);
1560 wifi_handle->network_info->wifi_handle = wifi_handle;
1562 return WIFI_MANAGER_ERROR_NONE;
1565 int _wifi_create_handle(wifi_manager_h *wifi)
1567 wifi_manager_handle_s *wifi_handle = g_try_malloc0(sizeof(wifi_manager_handle_s));
1568 if (wifi_handle == NULL) {
1569 WIFI_LOG(WIFI_ERROR, "Failed to create wifi handle"); //LCOV_EXCL_LINE
1570 return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
1573 pthread_mutex_init(&(wifi_handle->mutex_ap_handle_list), NULL);
1574 wifi_handle->random_mac_lifetime = 60; /* default value */
1576 *wifi = wifi_handle;
1578 WIFI_LOG(WIFI_INFO, "New handle create[%p]", *wifi);
1580 return WIFI_MANAGER_ERROR_NONE;
1583 void _wifi_destroy_handle(wifi_manager_h wifi)
1588 wifi_manager_handle_s *wifi_handle = (wifi_manager_handle_s *)wifi;
1589 pthread_mutex_destroy(&(wifi_handle->mutex_ap_handle_list));
1593 void _wifi_add_to_handle_list(wifi_manager_h *wifi)
1595 wifi_manager_handle_list = g_slist_append(wifi_manager_handle_list, *wifi);
1598 void _wifi_remove_from_handle_list(wifi_manager_h wifi)
1600 wifi_manager_handle_list = g_slist_remove(wifi_manager_handle_list, wifi);
1603 int _wifi_length_from_handle_list(void)
1605 return g_slist_length(wifi_manager_handle_list);
1608 bool _wifi_find_from_handle_list(wifi_manager_h wifi)
1610 if (g_slist_find(wifi_manager_handle_list, wifi) != NULL)
1616 bool _wifi_find_network_info_from_handle_list(network_info_s *network_info)
1618 GSList *list = NULL;
1620 for (list = wifi_manager_handle_list; list; list = list->next) {
1621 wifi_manager_handle_s *wifi_handle = list->data;
1623 if (wifi_handle->network_info == network_info)
1630 void config_free(gpointer data)
1632 wifi_config_s *h = (wifi_config_s *)data;
1634 g_free(h->passphrase);
1635 g_free(h->proxy_address);
1636 if (h->eap_config) {
1637 g_free(h->eap_config->ca_cert);
1638 g_free(h->eap_config->client_cert);
1639 g_free(h->eap_config->private_key);
1640 g_free(h->eap_config->private_key_password);
1641 g_free(h->eap_config->anonymous_identity);
1642 g_free(h->eap_config->identity);
1643 g_free(h->eap_config->subject_match);
1644 g_free(h->eap_config);
1647 g_free(h->ip_info->ip_address);
1648 g_free(h->ip_info->subnet_mask);
1649 g_free(h->ip_info->gateway_address);
1650 for (int i = 0; i < h->ip_info->dns_count; ++i)
1651 g_free(h->ip_info->dns_address[i]);
1656 void __clear_config_list(GSList **iterator)
1659 g_slist_free_full(*iterator, config_free);
1665 static void __free_dpp(gpointer data)
1667 wifi_dpp_s *p_dpp = (wifi_dpp_s *)data;
1668 g_free(p_dpp->group_id);
1669 g_free(p_dpp->own_uri);
1670 g_free(p_dpp->peer_uri);
1671 g_free(p_dpp->ssid);
1676 static void _wifi_ap_handle_list_lock(wifi_manager_handle_s *wifi)
1681 int ret = pthread_mutex_lock(&(wifi->mutex_ap_handle_list));
1683 WIFI_LOG(WIFI_ERROR, "Failed to lock the ap_handle_list[%d]", ret);
1686 static void _wifi_ap_handle_list_unlock(wifi_manager_handle_s *wifi)
1691 int ret = pthread_mutex_unlock(&(wifi->mutex_ap_handle_list));
1693 WIFI_LOG(WIFI_ERROR, "Failed to unlock the ap_handle_list[%d]", ret);
1696 void _wifi_deinit(wifi_manager_h wifi)
1698 wifi_manager_handle_s *wifi_handle = wifi;
1700 net_deregister_client_ext(wifi_handle->network_info);
1702 _wifi_ap_handle_list_lock((wifi_manager_handle_s *)wifi);
1703 __clear_profile_list(&(wifi_handle->ap_handle_list));
1704 _wifi_ap_handle_list_unlock((wifi_manager_handle_s *)wifi);
1706 __clear_profile_list(&(wifi_handle->profile_iterator));
1707 __clear_profile_list(&(wifi_handle->specific_profile_iterator));
1708 __clear_profile_list(&(wifi_handle->bss_profile_iterator));
1710 __clear_config_list(&(wifi_handle->config_handle_list));
1711 __clear_config_list(&(wifi_handle->config_iterator));
1714 void _wifi_clear_profile_list(void)
1716 g_slist_free_full(dpp_handle_list, __free_dpp);
1717 g_p_dpp_current = NULL;
1721 void _wifi_set_cs_tid(wifi_manager_h wifi, int tid)
1723 wifi_manager_handle_s *wifi_handle = wifi;
1725 net_set_cs_tid(wifi_handle->network_info, tid);
1728 void _wifi_unset_cs_tid(int tid)
1730 net_unset_cs_tid(tid);
1734 int _wifi_activate(wifi_manager_h wifi, wifi_manager_activated_cb callback,
1735 gboolean wifi_picker_test, void *user_data)
1737 int rv = NET_ERR_NONE;
1738 wifi_manager_handle_s *wifi_handle = wifi;
1740 rv = net_wifi_power_on(wifi_handle->network_info, wifi_picker_test);
1741 rv = __convert_to_ap_error_type(rv);
1742 if (rv == WIFI_MANAGER_ERROR_NONE)
1743 __set_activated_cb(wifi_handle, callback, user_data);
1748 int _wifi_deactivate(wifi_manager_h wifi, wifi_manager_deactivated_cb callback, void *user_data)
1750 int rv = NET_ERR_NONE;
1751 wifi_manager_handle_s *wifi_handle = wifi;
1753 rv = net_wifi_power_off(wifi_handle->network_info);
1754 rv = __convert_to_ap_error_type(rv);
1755 if (rv == WIFI_MANAGER_ERROR_NONE)
1756 __set_deactivated_cb(wifi_handle, callback, user_data);
1761 int _wifi_get_mac_address(wifi_manager_h wifi, char **mac_address)
1764 char mac_path[WIFI_MAC_ADDR_PATH_LEN];
1765 char buf[WIFI_MAC_ADDR_LEN + 1];
1766 wifi_manager_handle_s *wifi_handle = wifi;
1768 g_snprintf(mac_path, WIFI_MAC_ADDR_PATH_LEN, WIFI_MAC_ADDR_PATH, wifi_handle->interface_name);
1770 if (access(mac_path, F_OK) == 0)
1771 fp = fopen(mac_path, "r");
1774 if (fgets(buf, sizeof(buf), fp) == NULL) {
1775 WIFI_LOG(WIFI_ERROR, "Failed to get MAC info from %s", mac_path); //LCOV_EXCL_LINE
1776 fclose(fp); //LCOV_EXCL_LINE
1777 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1780 WIFI_LOG(WIFI_INFO, "%s : %s", mac_path, buf);
1782 *mac_address = g_strdup(buf);
1785 *mac_address = _net_vconf_get_str(wifi_handle->network_info, VCONFKEY_WIFI_BSSID_ADDRESS);
1787 if (*mac_address == NULL) {
1788 WIFI_LOG(WIFI_ERROR, "Failed to get vconf" //LCOV_EXCL_LINE
1789 " from %s", VCONFKEY_WIFI_BSSID_ADDRESS);
1790 __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
1791 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1794 if (strlen(*mac_address) == 0) {
1795 WIFI_LOG(WIFI_ERROR, "Mac address is invalid" //LCOV_EXCL_LINE
1796 " from %s", VCONFKEY_WIFI_BSSID_ADDRESS);
1797 g_free(*mac_address); //LCOV_EXCL_LINE
1798 *mac_address = NULL; //LCOV_EXCL_LINE
1799 __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
1800 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1804 return WIFI_MANAGER_ERROR_NONE;
1807 int _wifi_ip_conflict_detect_enable_set(wifi_manager_h wifi, bool detect)
1809 int rv = NET_ERR_NONE;
1810 wifi_manager_handle_s *wifi_handle = wifi;
1812 rv = net_set_ip_conflict_detect_mode(wifi_handle->network_info, detect);
1813 if (rv == NET_ERR_ACCESS_DENIED) {
1814 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
1815 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1816 } else if (rv == NET_ERR_INVALID_OPERATION) {
1817 WIFI_LOG(WIFI_ERROR, "Mode was already set"); //LCOV_EXCL_LINE
1818 } else if (rv == NET_ERR_NONE) {
1819 return WIFI_MANAGER_ERROR_NONE;
1822 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1825 bool _wifi_check_ap_validity(net_profile_info_s *ap_info)
1827 if (ap_info == NULL)
1830 GSList *list = NULL;
1831 for (list = wifi_manager_handle_list; list; list = list->next) {
1832 wifi_manager_handle_s *wifi_handle = list->data;
1833 if (wifi_handle == NULL)
1836 _wifi_ap_handle_list_lock(wifi_handle);
1837 if (g_slist_find(wifi_handle->ap_handle_list, ap_info) != NULL) {
1838 _wifi_ap_handle_list_unlock(wifi_handle);
1841 _wifi_ap_handle_list_unlock(wifi_handle);
1843 if (g_slist_find(wifi_handle->profile_iterator, ap_info) != NULL)
1846 if (g_slist_find(wifi_handle->specific_profile_iterator, ap_info) != NULL)
1849 if (g_slist_find(wifi_handle->bss_profile_iterator, ap_info) != NULL)
1856 void _wifi_add_to_ap_list(net_profile_info_s *ap_info)
1858 network_info_s *network_info;
1859 wifi_manager_handle_s *wifi_handle;
1861 network_info = ap_info->network_info;
1862 if (network_info == NULL)
1865 wifi_handle = network_info->wifi_handle;
1867 _wifi_ap_handle_list_lock(wifi_handle);
1868 wifi_handle->ap_handle_list =
1869 g_slist_prepend(wifi_handle->ap_handle_list, ap_info);
1870 _wifi_ap_handle_list_unlock(wifi_handle);
1874 void _wifi_remove_from_ap_list(net_profile_info_s *ap_info)
1876 network_info_s *network_info;
1877 wifi_manager_handle_s *wifi_handle;
1879 network_info = ap_info->network_info;
1880 if (network_info == NULL)
1883 wifi_handle = network_info->wifi_handle;
1885 _wifi_ap_handle_list_lock(wifi_handle);
1886 wifi_handle->ap_handle_list =
1887 g_slist_remove(wifi_handle->ap_handle_list, ap_info);
1888 _wifi_ap_handle_list_unlock(wifi_handle);
1892 bool _wifi_check_profile_name_validity(const char *profile_name)
1894 const char *profile_prefix = "/net/connman/service/wifi_";
1897 if (profile_name == NULL ||
1898 g_str_has_prefix(profile_name, profile_prefix) != TRUE) {
1899 WIFI_LOG(WIFI_INFO, "The profile is a hidden or not a regular Wi-Fi profile");
1903 while (profile_name[i] != '\0') {
1904 if (isgraph(profile_name[i]) == 0) {
1905 WIFI_LOG(WIFI_INFO, "Invalid format: %s", profile_name); //LCOV_EXCL_LINE
1906 return false; //LCOV_EXCL_LINE
1914 bool _wifi_check_essid_validity(const char *essid)
1921 essid_len = strlen(essid);
1923 if (essid_len < 1 || essid_len > 32)
1926 if (!g_utf8_validate(essid, -1, NULL))
1932 int _wifi_get_wifi_device_state(wifi_manager_h wifi, wifi_manager_device_state_e *device_state)
1934 net_tech_info_s tech_info;
1935 wifi_manager_handle_s *wifi_handle = wifi;
1937 int rv = NET_ERR_NONE;
1938 rv = net_get_technology_properties(wifi_handle->network_info, &tech_info);
1939 if (rv == NET_ERR_ACCESS_DENIED) {
1940 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
1941 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1942 } else if (rv != NET_ERR_NONE) {
1943 WIFI_LOG(WIFI_ERROR, "Failed to get technology properties"); //LCOV_EXCL_LINE
1944 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1947 if (tech_info.powered)
1948 *device_state = WIFI_MANAGER_DEVICE_STATE_ACTIVATED;
1950 *device_state = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED;
1952 return WIFI_MANAGER_ERROR_NONE;
1955 int _wifi_get_wifi_state(wifi_manager_h wifi, wifi_manager_connection_state_e *connection_state)
1957 wifi_manager_handle_s *wifi_handle = wifi;
1958 wifi_tech_state_e tech_state = WIFI_TECH_UNKNOWN;
1959 wifi_service_state_e service_state = WIFI_SERVICE_STATE_UNKNOWN;
1961 tech_state = net_get_technology_state(wifi_handle->network_info);
1962 service_state = _wifi_get_service_state(wifi_handle);
1964 /* LCOV_EXCL_START */
1965 if (tech_state == WIFI_TECH_UNKNOWN)
1966 *connection_state = WIFI_MANAGER_ERROR_OPERATION_FAILED;
1967 else if (tech_state == WIFI_TECH_OFF ||
1968 tech_state == WIFI_TECH_WPS_ONLY)
1969 *connection_state = WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED;
1970 else if (tech_state == WIFI_TECH_CONNECTED)
1971 *connection_state = WIFI_MANAGER_CONNECTION_STATE_CONNECTED;
1973 switch (service_state) {
1974 case WIFI_SERVICE_STATE_ASSOCIATION:
1975 *connection_state = WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION;
1977 case WIFI_SERVICE_STATE_CONFIGURATION:
1978 *connection_state = WIFI_MANAGER_CONNECTION_STATE_CONFIGURATION;
1980 case WIFI_SERVICE_STATE_CONNECTED:
1981 *connection_state = WIFI_MANAGER_CONNECTION_STATE_CONNECTED;
1983 case WIFI_SERVICE_STATE_UNKNOWN:
1984 case WIFI_SERVICE_STATE_FAILURE:
1985 case WIFI_SERVICE_STATE_IDLE:
1987 *connection_state = WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED;
1990 /* LCOV_EXCL_STOP */
1992 return WIFI_MANAGER_ERROR_NONE;
1995 void _wifi_get_intf_name(wifi_manager_h wifi, char **name)
1997 wifi_manager_handle_s *wifi_handle = wifi;
1999 *name = g_strdup(wifi_handle->interface_name);
2002 int _wifi_ip_conflict_detect_is_enabled(wifi_manager_h wifi, bool *state)
2005 gboolean is_enabled = FALSE;
2006 wifi_manager_handle_s *wifi_handle = wifi;
2008 rv = net_ip_conflict_detect_is_enabled(wifi_handle->network_info, &is_enabled);
2009 if (rv == NET_ERR_ACCESS_DENIED) {
2010 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2011 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2012 } else if (rv == NET_ERR_NONE) {
2013 *state = is_enabled;
2014 return WIFI_MANAGER_ERROR_NONE;
2017 return WIFI_MANAGER_ERROR_NONE;
2020 int _wifi_scan_request(wifi_manager_h wifi,
2021 wifi_manager_scan_finished_cb callback, void *user_data)
2024 wifi_manager_handle_s *wifi_handle = wifi;
2026 rv = net_scan_wifi(wifi_handle->network_info);
2027 if (rv == NET_ERR_ACCESS_DENIED) {
2028 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2029 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2030 } else if (rv == NET_ERR_INVALID_OPERATION) {
2031 return WIFI_MANAGER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
2032 } else if (rv == NET_ERR_NONE) {
2033 __set_scan_cb(wifi_handle, callback, user_data);
2034 return WIFI_MANAGER_ERROR_NONE;
2037 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2040 int _wifi_get_scan_state(wifi_manager_h wifi, wifi_manager_scan_state_e *scan_state)
2044 wifi_manager_handle_s *wifi_handle = wifi;
2046 rv = net_wifi_get_scan_state(wifi_handle->network_info, &state);
2047 if (rv == NET_ERR_ACCESS_DENIED) {
2048 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2049 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2050 } else if (rv == NET_ERR_INVALID_OPERATION) {
2051 return WIFI_MANAGER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
2052 } else if (rv == NET_ERR_NONE) {
2053 *scan_state = state;
2054 return WIFI_MANAGER_ERROR_NONE;
2057 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2060 int _wifi_scan_specific_ap(wifi_manager_h wifi, const char *essid,
2061 wifi_manager_scan_finished_cb callback, void *user_data)
2064 wifi_manager_handle_s *wifi_handle = wifi;
2066 rv = net_specific_scan_wifi(wifi_handle->network_info, essid);
2067 if (rv == NET_ERR_ACCESS_DENIED) {
2068 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2069 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2070 } else if (rv == NET_ERR_INVALID_OPERATION) {
2071 return WIFI_MANAGER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
2072 } else if (rv == NET_ERR_NONE) {
2073 g_strlcpy(wifi_handle->specific_scan_essid, essid, NET_WLAN_ESSID_LEN + 1);
2074 __set_specific_scan_cb(wifi_handle, callback, user_data);
2075 return WIFI_MANAGER_ERROR_NONE;
2078 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2081 int _wifi_get_hidden_aps(wifi_manager_h wifi, const char *essid,
2082 wifi_manager_security_type_e sec_type, const char *passphrase,
2083 wifi_manager_connected_cb callback, void *user_data)
2086 bool is_available = false;
2087 wifi_manager_security_type_e type = 0;
2088 net_profile_info_s *profile_info = NULL;
2089 wifi_manager_handle_s *wifi_handle = wifi;
2092 rv = __update_profile_iterator(wifi_handle);
2093 if (rv == NET_ERR_ACCESS_DENIED) {
2094 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2095 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2098 if ((int)g_slist_length(wifi_handle->profile_iterator) == 0) {
2099 WIFI_LOG(WIFI_WARN, "There is no AP"); //LCOV_EXCL_LINE
2100 return WIFI_MANAGER_ERROR_NONE; //LCOV_EXCL_LINE
2103 if (sec_type == WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK ||
2104 sec_type == WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK)
2105 sec_type = WIFI_MANAGER_SECURITY_TYPE_WPA_PSK;
2107 for (list = wifi_handle->profile_iterator; list; list = list->next) {
2108 net_profile_info_s *prof_info = (net_profile_info_s *)list->data;
2109 switch (prof_info->security_info.sec_mode) {
2110 case WLAN_SEC_MODE_NONE:
2111 type = WIFI_MANAGER_SECURITY_TYPE_NONE;
2113 case WLAN_SEC_MODE_WEP:
2114 type = WIFI_MANAGER_SECURITY_TYPE_WEP;
2116 case WLAN_SEC_MODE_IEEE8021X:
2117 type = WIFI_MANAGER_SECURITY_TYPE_EAP;
2119 case WLAN_SEC_MODE_WPA_PSK:
2120 case WLAN_SEC_MODE_WPA2_PSK:
2121 case WLAN_SEC_MODE_WPA_FT_PSK:
2122 type = WIFI_MANAGER_SECURITY_TYPE_WPA_PSK;
2124 case WLAN_SEC_MODE_SAE:
2125 type = WIFI_MANAGER_SECURITY_TYPE_SAE;
2127 case WLAN_SEC_MODE_OWE:
2128 type = WIFI_MANAGER_SECURITY_TYPE_OWE;
2130 case WLAN_SEC_MODE_DPP:
2131 type = WIFI_MANAGER_SECURITY_TYPE_DPP;
2134 if (prof_info->is_hidden == TRUE) {
2135 if (type == sec_type) {
2136 WIFI_LOG(WIFI_INFO, "hidden profile %s",
2137 prof_info->ProfileName);
2138 is_available = true;
2139 profile_info = (wifi_manager_ap_h)prof_info;
2141 } else if (!g_strcmp0(prof_info->essid, essid) && type == sec_type) {
2142 WIFI_LOG(WIFI_INFO, "AP %s not hidden", essid);
2143 rv = wifi_manager_ap_set_passphrase((wifi_manager_ap_h)prof_info,
2145 if (rv != WIFI_MANAGER_ERROR_NONE)
2147 return _wifi_open_profile(wifi, (wifi_manager_ap_h)prof_info,
2148 callback, user_data);
2152 if (is_available == false) {
2153 WIFI_LOG(WIFI_INFO, "No hidden profiles found");
2154 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
2157 switch (profile_info->security_info.sec_mode) {
2158 case WLAN_SEC_MODE_WEP:
2159 g_strlcpy(profile_info->security_info.authentication.wep.wepKey,
2160 passphrase, NET_WLAN_MAX_WEP_KEY_LEN+1);
2162 case WLAN_SEC_MODE_WPA_PSK:
2163 case WLAN_SEC_MODE_WPA2_PSK:
2164 g_strlcpy(profile_info->security_info.authentication.psk.pskKey,
2165 passphrase, NET_WLAN_MAX_PSK_PASSPHRASE_LEN+1);
2167 case WLAN_SEC_MODE_SAE:
2168 g_strlcpy(profile_info->security_info.authentication.sae.saeKey,
2169 passphrase, NET_WLAN_MAX_SAE_PASSPHRASE_LEN+1);
2171 case WLAN_SEC_MODE_NONE:
2172 case WLAN_SEC_MODE_OWE:
2174 case WLAN_SEC_MODE_IEEE8021X:
2176 WIFI_LOG(WIFI_INFO, "Invalid security type"); //LCOV_EXCL_LINE
2177 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2180 g_strlcpy(profile_info->essid, essid, NET_WLAN_ESSID_LEN+1);
2182 return _wifi_open_profile(wifi, profile_info, callback, user_data);
2185 int _wifi_bssid_scan_request(wifi_manager_h wifi,
2186 wifi_manager_bssid_scan_finished_cb callback, void *user_data)
2189 wifi_manager_device_state_e device_state;
2190 wifi_manager_handle_s *wifi_handle = wifi;
2192 int flight_mode = -1;
2194 if (_net_vconf_get_bool(wifi_handle->network_info, VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode) != 0) {
2195 WIFI_LOG(WIFI_ERROR, "Failed to get vconf key of flight mode"); //LCOV_EXCL_LINE
2196 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2199 rv = _wifi_get_wifi_device_state(wifi, &device_state);
2200 if (rv == WIFI_MANAGER_ERROR_NONE) {
2201 if (WIFI_MANAGER_DEVICE_STATE_DEACTIVATED == device_state)
2207 WIFI_LOG(WIFI_INFO, "Activated: %d, flight mode: %d", activated, flight_mode);
2209 if (activated == 0 && flight_mode > 0) {
2210 WIFI_LOG(WIFI_INFO, "Invalid operation"); //LCOV_EXCL_LINE
2211 return WIFI_MANAGER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
2214 rv = net_bssid_scan_wifi(wifi_handle->network_info, activated);
2216 if (rv == NET_ERR_ACCESS_DENIED) {
2217 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2218 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2219 } else if (rv == NET_ERR_INVALID_OPERATION) {
2220 return WIFI_MANAGER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
2221 } else if (rv == NET_ERR_NONE) {
2222 __set_bssid_scan_cb(wifi_handle, callback, user_data);
2223 return WIFI_MANAGER_ERROR_NONE;
2226 WIFI_LOG(WIFI_ERROR, "Operation Failed"); //LCOV_EXCL_LINE
2227 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2231 bool _wifi_check_netlink_scan_validity(wifi_manager_netlink_scan_h netlink_scan)
2233 GSList *list = NULL;
2235 if (netlink_scan == NULL)
2238 for (list = netlink_scan_handle_list; list; list = list->next)
2239 if (netlink_scan == list->data) return true;
2244 void _wifi_add_to_netlink_scan_list(wifi_manager_netlink_scan_h *netlink_scan)
2246 netlink_scan_handle_list = g_slist_append(netlink_scan_handle_list, *netlink_scan);
2249 int _wifi_netlink_scan_create(wifi_manager_netlink_scan_h *netlink_scan)
2251 *netlink_scan = g_try_malloc0(sizeof(wifi_netlink_scan_s));
2253 if (*netlink_scan == NULL) {
2254 WIFI_LOG(WIFI_ERROR, "Failed to create netlink scan handle");
2255 return WIFI_MANAGER_ERROR_OUT_OF_MEMORY;
2258 WIFI_LOG(WIFI_INFO, "New netlink scan handle[%p]", *netlink_scan);
2259 return WIFI_MANAGER_ERROR_NONE;
2262 void _wifi_remove_from_netlink_scan_list(wifi_manager_netlink_scan_h netlink_scan)
2264 wifi_netlink_scan_s *list = (wifi_netlink_scan_s *)netlink_scan;
2266 g_slist_free_full(list->ssids, g_free);
2268 netlink_scan_handle_list = g_slist_remove(netlink_scan_handle_list, netlink_scan);
2269 g_free(netlink_scan);
2272 void _wifi_netlink_scan_set_ssid(wifi_manager_netlink_scan_h netlink_scan,
2275 wifi_netlink_scan_s *nl_scan = (wifi_netlink_scan_s *)netlink_scan;
2276 nl_scan->ssids = g_slist_append(nl_scan->ssids, g_strdup(essid));
2278 netlink_scan = (wifi_manager_netlink_scan_h)nl_scan;
2281 void _wifi_netlink_scan_set_vsie(wifi_manager_netlink_scan_h netlink_scan,
2284 wifi_netlink_scan_s *nl_scan = (wifi_netlink_scan_s *)netlink_scan;
2285 g_strlcpy(nl_scan->vsie, vsie, NET_WLAN_MAX_VSIE_LEN);
2287 netlink_scan = (wifi_manager_netlink_scan_h)nl_scan;
2290 int _wifi_netlink_scan_request(wifi_manager_h wifi, wifi_manager_netlink_scan_h netlink_scan,
2291 wifi_manager_netlink_scan_finished_cb callback, void *user_data)
2296 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP;
2297 wifi_manager_handle_s *wifi_handle = wifi;
2298 wifi_netlink_scan_s *nl_scan = (wifi_netlink_scan_s *)netlink_scan;
2300 /** When softap mode is enabled wifi device is in deactivated state,
2301 so to search APs wifi_manager_netlink_scan() API is used.
2302 When wifi device is in activated state use wifi_manager_scan() API instead. */
2303 if (_net_vconf_get_int(wifi_handle->network_info, VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0) {
2304 WIFI_LOG(WIFI_ERROR, "Failed to get vconf key of hotspot mode");
2305 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2308 enable = (is_on & vconf_type) ? true : false;
2310 if (enable == false) {
2311 WIFI_LOG(WIFI_ERROR, "SoftAP is not enabled");
2312 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
2315 rv = net_netlink_scan_wifi(wifi_handle->network_info, nl_scan->ssids, nl_scan->vsie);
2316 if (rv == NET_ERR_ACCESS_DENIED) {
2317 WIFI_LOG(WIFI_ERROR, "Access denied");
2318 return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
2319 } else if (rv == NET_ERR_INVALID_OPERATION) {
2320 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
2321 } else if (rv == NET_ERR_NONE) {
2322 __set_netlink_scan_cb(wifi_handle, callback, user_data);
2323 return WIFI_MANAGER_ERROR_NONE;
2326 WIFI_LOG(WIFI_ERROR, "Operation Failed");
2327 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2330 int _wifi_add_vsie(wifi_manager_h wifi, wifi_manager_vsie_frames_e frame_id, const char *vsie_str)
2333 net_vsie_frames_e f_id;
2334 wifi_manager_handle_s *wifi_handle = wifi;
2337 case WIFI_MANAGER_VSIE_FRAME_ASSOC_REQ:
2338 f_id = NET_VSIE_FRAME_ASSOC_REQ;
2340 case WIFI_MANAGER_VSIE_FRAME_PROBE_REQ:
2341 f_id = NET_VSIE_FRAME_PROBE_REQ;
2343 case WIFI_MANAGER_VSIE_FRAME_REASSOC:
2344 f_id = NET_VSIE_FRAME_REASSOC;
2346 case WIFI_MANAGER_VSIE_FRAME_AUTH_REQ:
2347 f_id = NET_VSIE_FRAME_AUTH_REQ;
2349 case WIFI_MANAGER_VSIE_FRAME_ACTION:
2350 f_id = NET_VSIE_FRAME_ACTION;
2353 WIFI_LOG(WIFI_ERROR, "Frame ID: [%d] not supported.", frame_id);
2354 return WIFI_MANAGER_ERROR_NOT_SUPPORTED;
2357 rv = net_wifi_add_vsie(wifi_handle->network_info, f_id, vsie_str);
2358 if (rv == NET_ERR_ACCESS_DENIED) {
2359 WIFI_LOG(WIFI_ERROR, "Access denied");
2360 return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
2361 } else if (rv == NET_ERR_INVALID_OPERATION) {
2362 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
2363 } else if (rv == NET_ERR_NONE) {
2364 return WIFI_MANAGER_ERROR_NONE;
2367 WIFI_LOG(WIFI_ERROR, "Operation Failed");
2368 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2371 int _wifi_get_vsie(wifi_manager_h wifi, wifi_manager_vsie_frames_e frame_id, char **vsie_str)
2374 net_vsie_frames_e f_id;
2375 wifi_manager_handle_s *wifi_handle = wifi;
2378 case WIFI_MANAGER_VSIE_FRAME_ASSOC_REQ:
2379 f_id = NET_VSIE_FRAME_ASSOC_REQ;
2381 case WIFI_MANAGER_VSIE_FRAME_PROBE_REQ:
2382 f_id = NET_VSIE_FRAME_PROBE_REQ;
2384 case WIFI_MANAGER_VSIE_FRAME_REASSOC:
2385 f_id = NET_VSIE_FRAME_REASSOC;
2387 case WIFI_MANAGER_VSIE_FRAME_AUTH_REQ:
2388 f_id = NET_VSIE_FRAME_AUTH_REQ;
2390 case WIFI_MANAGER_VSIE_FRAME_ACTION:
2391 f_id = NET_VSIE_FRAME_ACTION;
2394 WIFI_LOG(WIFI_ERROR, "Frame ID: [%d] not supported.", frame_id);
2395 return WIFI_MANAGER_ERROR_NOT_SUPPORTED;
2398 rv = net_wifi_get_vsie(wifi_handle->network_info, f_id, vsie_str);
2399 if (rv == NET_ERR_ACCESS_DENIED) {
2400 WIFI_LOG(WIFI_ERROR, "Access denied");
2401 return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
2402 } else if (rv == NET_ERR_INVALID_OPERATION) {
2403 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
2404 } else if (rv == NET_ERR_NONE) {
2405 return WIFI_MANAGER_ERROR_NONE;
2408 WIFI_LOG(WIFI_ERROR, "Operation Failed");
2409 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2412 int _wifi_remove_vsie(wifi_manager_h wifi, wifi_manager_vsie_frames_e frame_id, const char *vsie_str)
2415 net_vsie_frames_e f_id;
2416 wifi_manager_handle_s *wifi_handle = wifi;
2419 case WIFI_MANAGER_VSIE_FRAME_ASSOC_REQ:
2420 f_id = NET_VSIE_FRAME_ASSOC_REQ;
2422 case WIFI_MANAGER_VSIE_FRAME_PROBE_REQ:
2423 f_id = NET_VSIE_FRAME_PROBE_REQ;
2425 case WIFI_MANAGER_VSIE_FRAME_REASSOC:
2426 f_id = NET_VSIE_FRAME_REASSOC;
2428 case WIFI_MANAGER_VSIE_FRAME_AUTH_REQ:
2429 f_id = NET_VSIE_FRAME_AUTH_REQ;
2431 case WIFI_MANAGER_VSIE_FRAME_ACTION:
2432 f_id = NET_VSIE_FRAME_ACTION;
2435 WIFI_LOG(WIFI_ERROR, "Frame ID: [%d] not supported.", frame_id);
2436 return WIFI_MANAGER_ERROR_NOT_SUPPORTED;
2439 rv = net_wifi_remove_vsie(wifi_handle->network_info, f_id, vsie_str);
2440 if (rv == NET_ERR_ACCESS_DENIED) {
2441 WIFI_LOG(WIFI_ERROR, "Access denied");
2442 return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
2443 } else if (rv == NET_ERR_INVALID_OPERATION) {
2444 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
2445 } else if (rv == NET_ERR_NONE) {
2446 return WIFI_MANAGER_ERROR_NONE;
2449 WIFI_LOG(WIFI_ERROR, "Operation Failed");
2450 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2453 int _wifi_flush_bss(wifi_manager_h wifi)
2456 wifi_manager_handle_s *wifi_handle = wifi;
2458 rv = net_wifi_flush_bss(wifi_handle->network_info);
2459 if (rv != NET_ERR_NONE) {
2460 WIFI_LOG(WIFI_ERROR, "Failed to flush bss");
2461 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2464 return WIFI_MANAGER_ERROR_NONE;
2467 int _wifi_set_bssid(wifi_manager_h wifi, char *bssid)
2470 wifi_manager_handle_s *wifi_handle = wifi;
2472 rv = net_wifi_set_bssid(wifi_handle->network_info, bssid);
2473 if (rv != NET_ERR_NONE) {
2474 WIFI_LOG(WIFI_ERROR, "Failed to set bssid");
2475 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2478 return WIFI_MANAGER_ERROR_NONE;
2481 int _wifi_set_auto_connect(wifi_manager_h wifi, int connect_mode)
2484 wifi_manager_handle_s *wifi_handle = wifi;
2486 rv = net_wifi_set_auto_connect_mode(wifi_handle->network_info, connect_mode);
2488 if (rv != NET_ERR_NONE)
2489 WIFI_LOG(WIFI_ERROR, "Failed to set auto connection mode");
2494 int _wifi_get_auto_connect(wifi_manager_h wifi, int *connect_mode)
2497 wifi_manager_handle_s *wifi_handle = wifi;
2499 rv = net_wifi_get_auto_connect_mode(wifi_handle->network_info, connect_mode);
2501 if (rv != NET_ERR_NONE)
2502 WIFI_LOG(WIFI_ERROR, "Failed to get auto connection mode");
2507 int _wifi_get_5ghz_support(wifi_manager_h wifi, bool *supported)
2510 wifi_manager_handle_s *wifi_handle = wifi;
2511 gboolean is_supported = FALSE;
2513 rv = net_wifi_get_5ghz_support(wifi_handle->network_info, &is_supported);
2515 if (rv != NET_ERR_NONE)
2516 WIFI_LOG(WIFI_ERROR, "Failed to get 5 Ghz supported");
2518 *supported = is_supported;
2523 int _wifi_set_ap_auto_connect(wifi_manager_ap_h ap, bool autoconnect)
2526 net_profile_info_s *ap_info = ap;
2528 rv = net_wifi_set_ap_auto_connect(ap_info->network_info,
2529 ap_info->ProfileName, autoconnect);
2530 if (rv == NET_ERR_ACCESS_DENIED) {
2531 WIFI_LOG(WIFI_ERROR, "Access denied");
2532 return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
2533 } else if (rv != NET_ERR_NONE) {
2534 WIFI_LOG(WIFI_ERROR, "Failed to set auto connect [%d]", rv);
2535 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2538 return WIFI_MANAGER_ERROR_NONE;
2541 int _wifi_get_ap_auto_connect(wifi_manager_ap_h ap, bool *autoconnect)
2544 gboolean auto_connect = FALSE;
2545 net_profile_info_s *ap_info = ap;
2547 rv = net_wifi_get_ap_auto_connect(ap_info->network_info,
2548 ap_info->ProfileName, &auto_connect);
2549 if (rv == NET_ERR_ACCESS_DENIED) {
2550 WIFI_LOG(WIFI_ERROR, "Access denied");
2551 return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
2552 } else if (rv != NET_ERR_NONE) {
2553 WIFI_LOG(WIFI_ERROR, "Failed to get auto connect [%d]", rv);
2554 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2557 *autoconnect = auto_connect;
2558 return WIFI_MANAGER_ERROR_NONE;
2562 int _wifi_get_connected_profile(wifi_manager_h wifi, wifi_manager_ap_h *ap)
2565 wifi_manager_handle_s *wifi_handle = wifi;
2566 net_profile_info_s *ap_info = NULL;
2567 const char *ifname = wifi_handle->interface_name;
2569 ap_info = g_try_malloc0(sizeof(net_profile_info_s));
2570 if (ap_info == NULL)
2571 return WIFI_MANAGER_ERROR_OUT_OF_MEMORY;
2573 rv = net_get_connected_profile(wifi_handle->network_info, ifname, ap_info);
2574 if (rv != NET_ERR_NONE) {
2576 if (rv == NET_ERR_NO_PROFILE)
2577 return WIFI_MANAGER_ERROR_NO_CONNECTION; //LCOV_EXCL_LINE
2578 else if (rv == NET_ERR_ACCESS_DENIED) {
2579 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2580 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2581 } else if (rv == NET_ERR_INVALID_PARAM)
2582 return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
2584 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2587 _wifi_add_to_ap_list(ap_info);
2588 *ap = (wifi_manager_ap_h)ap_info;
2590 return WIFI_MANAGER_ERROR_NONE;
2594 int _wifi_foreach_available_interface(wifi_manager_h wifi,
2595 wifi_manager_interface_cb callback, void *user_data)
2599 wifi_manager_handle_s *wifi_handle = wifi;
2601 rv = __update_interface_iterator(wifi_handle);
2602 if (rv == NET_ERR_ACCESS_DENIED) {
2603 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2604 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2607 if ((int)g_slist_length(wifi_handle->interface_iterator) == 0) {
2608 WIFI_LOG(WIFI_WARN, "There is no interface"); //LCOV_EXCL_LINE
2609 return WIFI_MANAGER_ERROR_NONE; //LCOV_EXCL_LINE
2612 for (list = wifi_handle->interface_iterator; list; list = list->next) {
2613 char *interface_name = (char *)list->data;
2614 rv = callback(interface_name, user_data);
2615 if (rv == false) break;
2618 return WIFI_MANAGER_ERROR_NONE;
2622 int _wifi_foreach_found_ap(wifi_manager_h wifi,
2623 wifi_manager_found_ap_cb callback, void *user_data)
2627 wifi_manager_handle_s *wifi_handle = wifi;
2629 rv = __update_profile_iterator(wifi_handle);
2630 if (rv == NET_ERR_ACCESS_DENIED) {
2631 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2632 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2635 if ((int)g_slist_length(wifi_handle->profile_iterator) == 0) {
2636 WIFI_LOG(WIFI_WARN, "There is no AP"); //LCOV_EXCL_LINE
2637 return WIFI_MANAGER_ERROR_NONE; //LCOV_EXCL_LINE
2640 for (list = wifi_handle->profile_iterator; list; list = list->next) {
2641 net_profile_info_s *prof_info = (net_profile_info_s *)list->data;
2642 if (!g_strcmp0(prof_info->net_info.DevName, wifi_handle->interface_name)) {
2643 if (prof_info->is_hidden == TRUE)
2646 rv = callback((wifi_manager_ap_h)prof_info, user_data);
2647 if (rv == false) break;
2651 return WIFI_MANAGER_ERROR_NONE;
2655 int _wifi_foreach_found_ap_in_all_interfaces(wifi_manager_h wifi,
2656 wifi_manager_found_ap_cb callback, void *user_data)
2660 wifi_manager_handle_s *wifi_handle = wifi;
2662 rv = __update_profile_iterator(wifi_handle);
2663 if (rv == NET_ERR_ACCESS_DENIED) {
2664 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2665 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2668 if ((int)g_slist_length(wifi_handle->profile_iterator) == 0) {
2669 WIFI_LOG(WIFI_WARN, "There is no AP"); //LCOV_EXCL_LINE
2670 return WIFI_MANAGER_ERROR_NONE; //LCOV_EXCL_LINE
2673 for (list = wifi_handle->profile_iterator; list; list = list->next) {
2674 net_profile_info_s *prof_info = (net_profile_info_s *)list->data;
2675 if (prof_info->is_hidden == TRUE)
2678 rv = callback((wifi_manager_ap_h)prof_info, user_data);
2679 if (rv == false) break;
2682 return WIFI_MANAGER_ERROR_NONE;
2686 int _wifi_foreach_found_specific_ap(wifi_manager_h wifi,
2687 wifi_manager_found_ap_cb callback, void *user_data)
2691 wifi_manager_handle_s *wifi_handle = wifi;
2693 if ((int)g_slist_length(wifi_handle->specific_profile_iterator) == 0) {
2694 WIFI_LOG(WIFI_WARN, "There is no specific APs");
2696 rv = __update_profile_iterator(wifi_handle);
2697 if (rv == NET_ERR_ACCESS_DENIED) {
2698 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2699 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2702 if ((int)g_slist_length(wifi_handle->profile_iterator) == 0) {
2703 WIFI_LOG(WIFI_WARN, "There is no APs"); //LCOV_EXCL_LINE
2704 return WIFI_MANAGER_ERROR_NONE; //LCOV_EXCL_LINE
2707 for (list = wifi_handle->profile_iterator; list; list = list->next) {
2708 net_profile_info_s *prof_info = (net_profile_info_s *)list->data;
2709 if (!g_strcmp0(wifi_handle->specific_scan_essid, prof_info->essid)) {
2710 rv = callback((wifi_manager_ap_h)prof_info, user_data);
2711 if (rv == false) break;
2715 return WIFI_MANAGER_ERROR_NONE;
2718 for (list = wifi_handle->specific_profile_iterator; list; list = list->next) {
2719 net_profile_info_s *prof_info = (net_profile_info_s *)list->data;
2720 rv = callback((wifi_manager_ap_h)prof_info, user_data);
2721 if (rv == false) break;
2724 return WIFI_MANAGER_ERROR_NONE;
2727 int _wifi_foreach_found_bssid_ap(wifi_manager_h wifi,
2728 wifi_manager_found_ap_cb callback, void *user_data)
2732 wifi_manager_handle_s *wifi_handle = wifi;
2734 for (list = wifi_handle->bss_profile_iterator; list; list = list->next) {
2735 net_profile_info_s *prof_info = (net_profile_info_s *)list->data;
2736 rv = callback((wifi_manager_ap_h)prof_info, user_data);
2737 if (rv == false) break;
2740 return WIFI_MANAGER_ERROR_NONE;
2744 int _wifi_foreach_found_netlink_scan_ap(wifi_manager_h wifi,
2745 wifi_manager_found_ap_cb callback, void *user_data)
2749 wifi_manager_handle_s *wifi_handle = wifi;
2751 if (wifi_handle->bss_profile_iterator == NULL) {
2752 WIFI_LOG(WIFI_ERROR, "Failed to search APs");
2753 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2756 for (list = wifi_handle->bss_profile_iterator; list; list = list->next) {
2757 net_profile_info_s *prof_info = (net_profile_info_s *)list->data;
2758 rv = callback((wifi_manager_ap_h)prof_info, user_data);
2759 if (rv == false) break;
2762 __clear_profile_list(&(wifi_handle->bss_profile_iterator));
2764 return WIFI_MANAGER_ERROR_NONE;
2768 int _wifi_open_profile(wifi_manager_h wifi, wifi_manager_ap_h ap_h,
2769 wifi_manager_connected_cb callback, void *user_data)
2773 net_profile_info_s *ap_info = ap_h;
2774 wifi_manager_handle_s *wifi_handle = wifi;
2776 valid_profile = _wifi_check_profile_name_validity(ap_info->ProfileName);
2777 if (valid_profile == true && ap_info->Favourite)
2778 rv = net_open_connection(wifi_handle->network_info, ap_info->ProfileName);
2779 else if (valid_profile == true &&
2780 ap_info->is_hidden != TRUE &&
2781 ap_info->security_info.sec_mode == WLAN_SEC_MODE_NONE)
2782 rv = net_open_connection(wifi_handle->network_info, ap_info->ProfileName);
2784 rv = __connect_with_wifi_info(wifi_handle, ap_info);
2786 rv = __convert_to_ap_error_type(rv);
2787 if (rv == WIFI_MANAGER_ERROR_NONE)
2788 __set_connected_cb(wifi_handle, callback, user_data);
2793 int _wifi_close_profile(wifi_manager_h wifi, wifi_manager_ap_h ap_h,
2794 wifi_manager_disconnected_cb callback, void *user_data)
2797 net_profile_info_s *ap_info = ap_h;
2798 wifi_manager_handle_s *wifi_handle = wifi;
2800 rv = net_close_connection(wifi_handle->network_info, ap_info->ProfileName);
2801 if (rv == NET_ERR_ACCESS_DENIED) {
2802 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2803 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2804 } else if (rv != NET_ERR_NONE) {
2805 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2808 __set_disconnected_cb(wifi_handle, callback, user_data);
2810 return WIFI_MANAGER_ERROR_NONE;
2814 int _wifi_connect_with_wps_pbc(wifi_manager_h wifi, wifi_manager_ap_h ap_h,
2815 wifi_manager_connected_cb callback, void *user_data)
2818 wifi_manager_handle_s *wifi_handle = wifi;
2819 net_profile_info_s *ap_info = ap_h;
2820 net_wifi_wps_info_s wps_info;
2821 memset(&wps_info, 0, sizeof(net_wifi_wps_info_s));
2823 wps_info.type = WIFI_WPS_PBC;
2825 rv = net_wifi_enroll_wps(wifi_handle->network_info, ap_info->ProfileName, &wps_info);
2826 if (rv != NET_ERR_NONE)
2827 return __convert_to_ap_error_type(rv);
2829 __set_connected_cb(wifi_handle, callback, user_data);
2831 return WIFI_MANAGER_ERROR_NONE;
2834 int _wifi_connect_with_wps_pin(wifi_manager_h wifi, wifi_manager_ap_h ap_h,
2835 const char *pin, wifi_manager_connected_cb callback, void *user_data)
2838 wifi_manager_handle_s *wifi_handle = wifi;
2839 net_profile_info_s *ap_info = ap_h;
2840 net_wifi_wps_info_s wps_info;
2842 if (ap_info == NULL) {
2843 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
2844 return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
2847 memset(&wps_info, 0, sizeof(net_wifi_wps_info_s));
2848 wps_info.type = WIFI_WPS_PIN;
2849 g_strlcpy(wps_info.pin, pin, NET_WLAN_MAX_WPSPIN_LEN + 1);
2851 rv = net_wifi_enroll_wps(wifi_handle->network_info, ap_info->ProfileName, &wps_info);
2852 if (rv != NET_ERR_NONE)
2853 return __convert_to_ap_error_type(rv);
2855 __set_connected_cb(wifi_handle, callback, user_data);
2857 return WIFI_MANAGER_ERROR_NONE;
2861 int _wifi_forget_ap(wifi_manager_h wifi, wifi_manager_ap_h ap)
2864 wifi_manager_handle_s *wifi_handle = wifi;
2865 net_profile_info_s *ap_info = ap;
2867 if (ap_info == NULL) {
2868 WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
2869 return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
2872 rv = net_delete_profile(wifi_handle->network_info, ap_info->ProfileName);
2873 if (rv == NET_ERR_ACCESS_DENIED) {
2874 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2875 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2876 } else if (rv != NET_ERR_NONE) {
2877 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2880 ap_info->Favourite = (char)FALSE;
2882 return WIFI_MANAGER_ERROR_NONE;
2885 int _wifi_forget_ap_async(wifi_manager_h wifi, wifi_manager_ap_h ap,
2886 wifi_manager_forget_ap_finished_cb callback, void* user_data)
2889 wifi_manager_handle_s *wifi_handle = wifi;
2890 net_profile_info_s *ap_info = ap;
2892 if (ap_info == NULL) {
2893 WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
2894 return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
2897 rv = net_delete_profile_async(wifi_handle->network_info, ap_info->ProfileName);
2898 if (rv == NET_ERR_ACCESS_DENIED) {
2899 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2900 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2901 } else if (rv != NET_ERR_NONE) {
2902 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2905 ap_info->Favourite = (char)FALSE;
2906 __set_forget_ap_cb(wifi_handle, callback, user_data);
2908 return WIFI_MANAGER_ERROR_NONE;
2912 int _wifi_update_ap_info(wifi_manager_h wifi, net_profile_info_s *ap_info)
2914 int rv = NET_ERR_NONE;
2915 wifi_manager_handle_s *wifi_handle = wifi;
2917 rv = net_modify_profile(wifi_handle->network_info, ap_info->ProfileName, ap_info);
2918 if (rv == NET_ERR_ACCESS_DENIED) {
2919 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
2920 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
2921 } else if (rv == NET_ERR_SECURITY_RESTRICTED) {
2922 WIFI_LOG(WIFI_ERROR, "Security restricted"); //LCOV_EXCL_LINE
2923 return WIFI_MANAGER_ERROR_SECURITY_RESTRICTED; //LCOV_EXCL_LINE
2924 } else if (rv != NET_ERR_NONE) {
2925 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2928 return WIFI_MANAGER_ERROR_NONE;
2931 int _wifi_connect_with_wps_pbc_without_ssid(wifi_manager_h wifi,
2932 wifi_manager_connected_cb callback, void *user_data)
2935 wifi_manager_handle_s *wifi_handle = wifi;
2936 net_wifi_wps_info_s wps_info;
2937 net_profile_info_s *profile = NULL;
2940 memset(&wps_info, 0, sizeof(net_wifi_wps_info_s));
2942 wps_info.type = WIFI_WPS_PBC;
2944 WIFI_LOG(WIFI_INFO, "start");
2946 /* Disconnect if already connected to an AP */
2947 __update_profile_iterator(wifi_handle);
2949 for (list = wifi_handle->profile_iterator; list; list = list->next) {
2950 profile = (net_profile_info_s *)list->data;
2951 if (profile->ProfileState == NET_STATE_TYPE_ASSOCIATION ||
2952 profile->ProfileState == NET_STATE_TYPE_CONFIGURATION ||
2953 profile->ProfileState == NET_STATE_TYPE_READY ||
2954 profile->ProfileState == NET_STATE_TYPE_ONLINE) {
2955 rv = net_close_connection(wifi_handle->network_info, profile->ProfileName);
2956 if (rv != NET_ERR_NONE)
2957 return __convert_to_ap_error_type(rv);
2959 wifi_handle->is_disconnect_wps_pbc = true;
2963 if (!wifi_handle->is_disconnect_wps_pbc) {
2964 rv = net_wifi_enroll_wps_without_ssid(wifi_handle->network_info, &wps_info);
2965 if (rv != NET_ERR_NONE)
2966 return __convert_to_ap_error_type(rv);
2969 __set_connected_cb(wifi_handle, callback, user_data);
2971 return WIFI_MANAGER_ERROR_NONE;
2974 int _wifi_connect_with_wps_pin_without_ssid(wifi_manager_h wifi, const char *pin,
2975 wifi_manager_connected_cb callback, void* user_data)
2978 wifi_manager_handle_s *wifi_handle = wifi;
2979 net_wifi_wps_info_s wps_info;
2980 net_profile_info_s *profile = NULL;
2983 memset(&wps_info, 0, sizeof(net_wifi_wps_info_s));
2985 wps_info.type = WIFI_WPS_PIN;
2986 g_strlcpy(wps_info.pin, pin, NET_WLAN_MAX_WPSPIN_LEN + 1);
2988 WIFI_LOG(WIFI_INFO, "pin: %s", pin);
2990 /* Disconnect if already connected to an AP */
2991 __update_profile_iterator(wifi_handle);
2993 for (list = wifi_handle->profile_iterator; list; list = list->next) {
2994 profile = (net_profile_info_s *)list->data;
2995 if (profile->ProfileState == NET_STATE_TYPE_ASSOCIATION ||
2996 profile->ProfileState == NET_STATE_TYPE_CONFIGURATION ||
2997 profile->ProfileState == NET_STATE_TYPE_READY ||
2998 profile->ProfileState == NET_STATE_TYPE_ONLINE) {
2999 rv = net_close_connection(wifi_handle->network_info, profile->ProfileName);
3000 if (rv != NET_ERR_NONE)
3001 return __convert_to_ap_error_type(rv);
3002 g_strlcpy(wifi_handle->wps_pin, pin, NET_WLAN_MAX_WPSPIN_LEN + 1);
3003 wifi_handle->is_disconnect_wps_pin = true;
3007 if (!wifi_handle->is_disconnect_wps_pin) {
3008 rv = net_wifi_enroll_wps_without_ssid(wifi_handle->network_info, &wps_info);
3009 if (rv != NET_ERR_NONE)
3010 return __convert_to_ap_error_type(rv);
3013 __set_connected_cb(wifi_handle, callback, user_data);
3015 return WIFI_MANAGER_ERROR_NONE;
3018 int _wifi_cancel_wps(wifi_manager_h wifi)
3021 wifi_manager_handle_s *wifi_handle = wifi;
3023 rv = net_wifi_cancel_wps(wifi_handle->network_info);
3024 if (rv != NET_ERR_NONE)
3025 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
3027 __connected_cb(wifi_handle, WIFI_MANAGER_ERROR_OPERATION_ABORTED);
3029 return WIFI_MANAGER_ERROR_NONE;
3033 bool _wifi_check_config_validity(wifi_config_s *config)
3035 wifi_manager_handle_s *wifi_handle;
3040 wifi_handle = config->wifi_handle;
3041 if (wifi_handle == NULL)
3044 if (_wifi_find_from_handle_list(wifi_handle) == false)
3047 if (g_slist_find(wifi_handle->config_handle_list, config) != NULL)
3050 if (g_slist_find(wifi_handle->config_iterator, config) != NULL)
3056 void _wifi_add_to_config_list(wifi_config_s *config)
3058 wifi_manager_handle_s *wifi_handle = config->wifi_handle;
3061 wifi_handle->config_handle_list =
3062 g_slist_append(wifi_handle->config_handle_list, config);
3066 void _wifi_remove_from_config_list(wifi_config_s *config)
3068 wifi_manager_handle_s *wifi_handle = config->wifi_handle;
3071 wifi_handle->config_handle_list =
3072 g_slist_remove(wifi_handle->config_handle_list, config);
3076 gchar *_wifi_config_get_config_id(const gchar *name, wifi_manager_security_type_e security_type)
3078 gchar *config_id = NULL;
3082 ssid = __wifi_change_name_to_hexadecimal(name);
3083 type = g_strdup(__wifi_security_type_to_string(security_type));
3084 config_id = g_strdup_printf("%s_managed_%s", ssid, type);
3092 int _wifi_config_get_config_id_list(wifi_manager_h wifi, GSList **list)
3095 wifi_manager_handle_s *wifi_handle = wifi;
3097 rv = net_config_get_id_list(wifi_handle->network_info, list);
3098 if (rv == NET_ERR_ACCESS_DENIED) {
3099 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3100 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3101 } else if (rv == NET_ERR_NO_PROFILE) {
3102 WIFI_LOG(WIFI_ERROR, "There is no configuration"); //LCOV_EXCL_LINE
3103 return WIFI_MANAGER_ERROR_NONE; //LCOV_EXCL_LINE
3104 } else if (rv != NET_ERR_NONE) {
3105 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3108 return WIFI_MANAGER_ERROR_NONE;
3111 void destroy_wifi_config(wifi_config_s *h)
3117 g_free(h->passphrase);
3118 g_free(h->proxy_address);
3121 g_free(h->ip_info->ip_address);
3122 g_free(h->ip_info->subnet_mask);
3123 g_free(h->ip_info->gateway_address);
3124 for (i = 0; i < h->ip_info->dns_count; i++)
3125 g_free(h->ip_info->dns_address[i]);
3129 if (h->eap_config) {
3130 g_free(h->eap_config->ca_cert);
3131 g_free(h->eap_config->client_cert);
3132 g_free(h->eap_config->private_key);
3133 g_free(h->eap_config->private_key_password);
3134 g_free(h->eap_config->anonymous_identity);
3135 g_free(h->eap_config->identity);
3136 g_free(h->eap_config->subject_match);
3137 g_free(h->eap_config);
3144 int _wifi_save_configuration(wifi_manager_h wifi, wifi_config_s *config)
3147 wifi_manager_handle_s *wifi_handle = wifi;
3148 gchar *config_id = NULL;
3151 if (config->security_type != WIFI_MANAGER_SECURITY_TYPE_NONE) {
3152 if (config->passphrase == NULL) {
3153 WIFI_LOG(WIFI_ERROR, "Fail to wifi_save_configurations " //LCOV_EXCL_LINE
3154 "[secu_type is not NONE[%d] but passphrase is NULL]",
3155 config->security_type);
3156 return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
3158 if (strlen(config->passphrase) == 0) {
3159 WIFI_LOG(WIFI_ERROR, "Fail to wifi_save_configurations " //LCOV_EXCL_LINE
3160 "passphrase length is 0");
3161 return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
3166 config_id = _wifi_config_get_config_id(config->name, config->security_type);
3167 ssid = __wifi_change_name_to_hexadecimal(config->name);
3169 rv = net_config_save_configurations(wifi_handle->network_info,
3170 config_id, config->name, ssid, config->passphrase,
3171 config->proxy_address, (void *)config->ip_info,
3172 config->frequency, config->is_hidden, config->is_created);
3173 if (rv == NET_ERR_ACCESS_DENIED) {
3174 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3175 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3176 } else if (rv != NET_ERR_NONE) {
3177 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3180 return WIFI_MANAGER_ERROR_NONE;
3183 int _wifi_load_configurations(wifi_manager_h wifi)
3186 wifi_manager_handle_s *wifi_handle = wifi;
3187 GSList *config_ids = NULL;
3188 GSList *head_config_ids = NULL;
3190 __clear_config_list(&(wifi_handle->config_iterator));
3192 rv = _wifi_config_get_config_id_list(wifi, &config_ids);
3193 if (rv != WIFI_MANAGER_ERROR_NONE) {
3194 WIFI_LOG(WIFI_ERROR, "Fail to load configurations [%d]", rv); //LCOV_EXCL_LINE
3195 return rv; //LCOV_EXCL_LINE
3198 if (config_ids == NULL) {
3199 WIFI_LOG(WIFI_ERROR, "Fail to get config id list"); //LCOV_EXCL_LINE
3200 return WIFI_MANAGER_ERROR_NONE; //LCOV_EXCL_LINE
3203 head_config_ids = config_ids;
3204 while (config_ids) {
3206 gchar *id = config_ids->data;
3208 h = g_new0(wifi_config_s, 1);
3212 h->wifi_handle = wifi_handle;
3214 if (g_str_has_suffix(id, "ieee8021x") == TRUE) {
3215 h->eap_config = g_new0(wifi_eap_config_s, 1);
3216 if (h->eap_config == NULL) {
3217 g_free(h);//LCOV_EXCL_LINE
3218 break;//LCOV_EXCL_LINE
3220 rv = __load_eap_configurations(wifi_handle, id, h);
3222 h->ip_info = g_new0(wifi_config_ip_info_s, 1);
3223 if (h->ip_info == NULL) {
3224 g_free(h);//LCOV_EXCL_LINE
3225 break;//LCOV_EXCL_LINE
3227 rv = __load_configurations(wifi_handle, id, h);
3230 if (rv != WIFI_MANAGER_ERROR_NONE) {
3231 destroy_wifi_config(h);
3232 WIFI_LOG(WIFI_ERROR, "Fail to load configurations [%d]", rv); //LCOV_EXCL_LINE
3234 h->address_family = WIFI_MANAGER_ADDRESS_FAMILY_IPV4;
3237 wifi_handle->config_iterator = g_slist_append(wifi_handle->config_iterator,
3238 (wifi_manager_config_h)h);
3241 config_ids = config_ids->next;
3244 g_slist_free_full(head_config_ids, g_free);
3246 return WIFI_MANAGER_ERROR_NONE;
3249 int _wifi_foreach_configuration(wifi_manager_h wifi,
3250 wifi_manager_config_list_cb callback, void *user_data)
3254 wifi_manager_handle_s *wifi_handle = wifi;
3256 for (list = wifi_handle->config_iterator; list; list = list->next) {
3257 rv = callback((wifi_manager_config_h)list->data, user_data);
3262 return WIFI_MANAGER_ERROR_NONE;
3265 int _wifi_remove_configuration(wifi_manager_h wifi, const gchar *config_id)
3269 wifi_manager_handle_s *wifi_handle = wifi;
3271 rv = net_config_remove_configurations(wifi_handle->network_info, config_id);
3272 if (rv == NET_ERR_ACCESS_DENIED) {
3273 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3274 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3275 } else if (rv != NET_ERR_NONE)
3276 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3278 rv = __update_profile_iterator(wifi_handle);
3279 if (rv == NET_ERR_ACCESS_DENIED) {
3280 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3281 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3284 if ((int)g_slist_length(wifi_handle->profile_iterator) == 0) {
3285 WIFI_LOG(WIFI_WARN, "There is no AP"); //LCOV_EXCL_LINE
3286 return WIFI_MANAGER_ERROR_NONE; //LCOV_EXCL_LINE
3289 for (list = wifi_handle->profile_iterator; list; list = list->next) {
3290 net_profile_info_s *prof_info = (net_profile_info_s *)list->data;
3291 if (g_str_has_suffix((gchar*)(prof_info->ProfileName), config_id) == TRUE) {
3293 rv = net_delete_profile(wifi_handle->network_info, prof_info->ProfileName); //LCOV_EXCL_LINE
3294 if (rv == NET_ERR_ACCESS_DENIED) {
3295 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3296 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3297 } else if (rv != NET_ERR_NONE) {
3298 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3301 prof_info->Favourite = (char)FALSE; //LCOV_EXCL_LINE
3306 return WIFI_MANAGER_ERROR_NONE;
3310 int _wifi_save_eap_configurations(wifi_manager_h wifi, wifi_config_s *config)
3313 wifi_manager_handle_s *wifi_handle = wifi;
3314 gchar *config_id = NULL;
3317 if (config->security_type != WIFI_MANAGER_SECURITY_TYPE_EAP) {
3318 WIFI_LOG(WIFI_ERROR, "Fail to wifi_save_configurations "
3319 "[secu_type is not EAP[%d]]", config->security_type);
3320 return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
3323 if (config->passphrase == NULL) {
3324 WIFI_LOG(WIFI_ERROR, "Fail to wifi_save_configurations [secu_type is not NONE[%d] "
3325 "but passphrase is NULL]", config->security_type);
3326 return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
3328 if (strlen(config->passphrase) == 0) {
3329 WIFI_LOG(WIFI_ERROR, "Fail to wifi_save_configurations passphrase length is 0");
3330 return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
3334 config_id = _wifi_config_get_config_id(config->name, config->security_type);
3335 ssid = __wifi_change_name_to_hexadecimal(config->name);
3337 rv = net_config_save_eap_configurations(wifi_handle->network_info,
3338 config_id, config->name, ssid, config->passphrase,
3339 config->proxy_address, (void *)config->eap_config,
3340 config->frequency, config->is_hidden, config->is_created);
3341 if (rv == NET_ERR_ACCESS_DENIED) {
3342 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3343 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3344 } else if (rv != NET_ERR_NONE)
3345 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3347 return WIFI_MANAGER_ERROR_NONE;
3350 int _wifi_configuration_set_field(wifi_manager_h wifi,
3351 const gchar *config_id, const gchar *key, const gchar *value)
3354 wifi_manager_handle_s *wifi_handle = wifi;
3356 rv = net_config_set_field(wifi_handle->network_info, config_id, key, value);
3357 if (rv == NET_ERR_ACCESS_DENIED) {
3358 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3359 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3360 } else if (rv != NET_ERR_NONE)
3361 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3363 return WIFI_MANAGER_ERROR_NONE;
3366 int _wifi_configuration_get_passphrase(wifi_manager_h wifi,
3367 const gchar *config_id, gchar **passphrase)
3370 wifi_manager_handle_s *wifi_handle = wifi;
3372 rv = net_config_get_passphrase(wifi_handle->network_info, config_id, passphrase);
3373 if (rv == NET_ERR_ACCESS_DENIED) {
3374 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3375 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3376 } else if (rv != NET_ERR_NONE)
3377 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3379 return WIFI_MANAGER_ERROR_NONE;
3382 int _wifi_check_get_privilege(wifi_manager_h wifi)
3385 wifi_manager_handle_s *wifi_handle = wifi;
3387 rv = net_check_get_privilege(wifi_handle->network_info);
3388 if (rv == NET_ERR_ACCESS_DENIED) {
3389 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3390 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3391 } else if (rv != NET_ERR_NONE)
3392 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3394 return WIFI_MANAGER_ERROR_NONE;
3397 int _wifi_check_profile_privilege(wifi_manager_h wifi)
3400 wifi_manager_handle_s *wifi_handle = wifi;
3402 rv = net_check_profile_privilege(wifi_handle->network_info);
3403 if (rv == NET_ERR_ACCESS_DENIED) {
3404 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3405 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3406 } else if (rv != NET_ERR_NONE)
3407 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3409 return WIFI_MANAGER_ERROR_NONE;
3413 bool __check_feature_supported(const char *key, wifi_supported_feature_e feature)
3415 if (!wifi_is_feature_checked[feature]) {
3416 if (system_info_get_platform_bool(key, &wifi_feature_supported[feature]) < 0) {
3417 WIFI_LOG(WIFI_ERROR, "Error - Feature getting from System Info"); //LCOV_EXCL_LINE
3418 set_last_result(WIFI_MANAGER_ERROR_OPERATION_FAILED); //LCOV_EXCL_LINE
3419 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3421 wifi_is_feature_checked[feature] = true;
3423 return wifi_feature_supported[feature];
3426 int _wifi_check_feature_supported(const char *feature_name, ...)
3431 bool feature_supported = false;
3433 va_start(list, feature_name);
3436 if (g_strcmp0(key, WIFI_FEATURE) == 0)
3437 value = __check_feature_supported(key, WIFI_SUPPORTED_FEATURE_WIFI);
3438 else if (g_strcmp0(key, WIFI_TDLS_FEATURE) == 0)
3439 value = __check_feature_supported(key, WIFI_SUPPORTED_FEATURE_WIFI_TDLS);
3440 else if (g_strcmp0(key, WIFI_MAC_RANDOMIZATION_FEATURE) == 0)
3441 value = __check_feature_supported(key, WIFI_SUPPORTED_FEATURE_WIFI_MAC_RANDOMIZATION);
3443 feature_supported |= value;
3444 key = va_arg(list, const char *);
3447 if (!feature_supported) {
3448 if (g_strcmp0(feature_name, WIFI_FEATURE) == 0)
3449 WIFI_LOG(WIFI_ERROR, "http://tizen.org/feature/network.wifi Feature is not supported"); //LCOV_EXCL_LINE
3450 else if (g_strcmp0(feature_name, WIFI_TDLS_FEATURE) == 0)
3451 WIFI_LOG(WIFI_ERROR, "http://tizen.org/feature/network.wifi.tdls Feature is not supported"); //LCOV_EXCL_LINE
3453 WIFI_LOG(WIFI_ERROR, "http://tizen.org/feature/network.wifi.mac_randomization Feature is not supported"); //LCOV_EXCL_LINE
3454 set_last_result(WIFI_MANAGER_ERROR_NOT_SUPPORTED); //LCOV_EXCL_LINE
3456 return WIFI_MANAGER_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
3460 set_last_result(WIFI_MANAGER_ERROR_NONE);
3461 return WIFI_MANAGER_ERROR_NONE;
3465 tizen_profile_t _get_tizen_profile()
3467 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
3468 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
3472 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
3473 switch (*profileName) {
3476 profile = TIZEN_PROFILE_MOBILE;
3480 profile = TIZEN_PROFILE_WEARABLE; //LCOV_EXCL_LINE
3481 break; //LCOV_EXCL_LINE
3484 profile = TIZEN_PROFILE_TV; //LCOV_EXCL_LINE
3485 break; //LCOV_EXCL_LINE
3488 profile = TIZEN_PROFILE_IVI; //LCOV_EXCL_LINE
3489 break; //LCOV_EXCL_LINE
3490 default: // common or unknown ==> ALL ARE COMMON.
3491 profile = TIZEN_PROFILE_COMMON; //LCOV_EXCL_LINE
3498 int _wifi_set_autoscan(wifi_manager_h wifi, bool autoscan)
3501 wifi_manager_handle_s *wifi_handle = wifi;
3503 rv = net_wifi_set_autoscan(wifi_handle->network_info, autoscan);
3504 if (rv == NET_ERR_ACCESS_DENIED) {
3505 WIFI_LOG(WIFI_ERROR, "Access denied");
3506 return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
3507 } else if (rv != NET_ERR_NONE)
3508 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
3510 return WIFI_MANAGER_ERROR_NONE;
3513 int _wifi_set_background_scan_mode(wifi_manager_h wifi,
3514 wifi_manager_autoscan_mode_e mode)
3517 wifi_manager_handle_s *wifi_handle = wifi;
3519 rv = net_wifi_set_background_scan_mode(wifi_handle->network_info, mode);
3520 if (rv == NET_ERR_ACCESS_DENIED) {
3521 WIFI_LOG(WIFI_ERROR, "Access denied");
3522 return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
3523 } else if (rv != NET_ERR_NONE)
3524 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
3526 return WIFI_MANAGER_ERROR_NONE;
3529 int _wifi_set_ip_conflict_period(wifi_manager_h wifi, unsigned int initial_time)
3532 wifi_manager_handle_s *wifi_handle = wifi;
3534 rv = net_wifi_set_ip_conflict_period(wifi_handle->network_info, initial_time);
3535 if (rv == NET_ERR_ACCESS_DENIED) {
3536 WIFI_LOG(WIFI_ERROR, "Access denied");
3537 return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
3538 } else if (rv != NET_ERR_NONE)
3539 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
3541 return WIFI_MANAGER_ERROR_NONE;
3544 int _wifi_get_autoscan(wifi_manager_h wifi, bool *autoscan)
3547 gboolean auto_scan = 0;
3548 wifi_manager_handle_s *wifi_handle = wifi;
3550 rv = net_wifi_get_autoscan(wifi_handle->network_info, &auto_scan);
3551 if (rv == NET_ERR_ACCESS_DENIED) {
3552 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3553 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3554 } else if (rv != NET_ERR_NONE) {
3555 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
3556 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3559 *autoscan = auto_scan;
3560 return WIFI_MANAGER_ERROR_NONE;
3563 int _wifi_get_autoscanmode(wifi_manager_h wifi, wifi_manager_autoscan_mode_e *autoscanmode)
3566 wifi_manager_handle_s *wifi_handle = wifi;
3568 rv = net_wifi_get_autoscanmode(wifi_handle->network_info, autoscanmode);
3569 if (rv == NET_ERR_ACCESS_DENIED) {
3570 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3571 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3572 } else if (rv != NET_ERR_NONE) {
3573 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
3574 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3577 return WIFI_MANAGER_ERROR_NONE;
3580 int _wifi_set_passpoint(wifi_manager_h wifi, int passpoint)
3583 wifi_manager_handle_s *wifi_handle = wifi;
3585 rv = net_wifi_set_passpoint(wifi_handle->network_info, passpoint);
3586 if (rv != NET_ERR_NONE)
3587 WIFI_LOG(WIFI_ERROR, "Failed to set passpoint");
3592 int _wifi_get_passpoint(wifi_manager_h wifi, int *passpoint)
3595 wifi_manager_handle_s *wifi_handle = wifi;
3597 rv = net_wifi_get_passpoint(wifi_handle->network_info, passpoint);
3598 if (rv != NET_ERR_NONE)
3599 WIFI_LOG(WIFI_ERROR, "Failed to get passpoint state");
3604 int _wifi_get_ip_conflict_period(wifi_manager_h wifi, unsigned int* initial_time)
3607 wifi_manager_handle_s *wifi_handle = wifi;
3609 rv = net_wifi_get_ip_conflict_period(wifi_handle->network_info, initial_time);
3610 if (rv == NET_ERR_ACCESS_DENIED) {
3611 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3612 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3613 } else if (rv != NET_ERR_NONE) {
3614 WIFI_LOG(WIFI_ERROR, "Failed to get IP conflict detection period"); //LCOV_EXCL_LINE
3615 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3618 return WIFI_MANAGER_ERROR_NONE;
3621 int _wifi_get_ip_conflict_state(wifi_manager_h wifi, wifi_manager_ip_conflict_state_e *state)
3624 wifi_manager_handle_s *wifi_handle = wifi;
3626 rv = net_wifi_get_ip_conflict_state(wifi_handle->network_info, state);
3627 if (rv == NET_ERR_ACCESS_DENIED) {
3628 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3629 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3630 } else if (rv != NET_ERR_NONE) {
3631 WIFI_LOG(WIFI_ERROR, "Failed to get IP conflict state"); //LCOV_EXCL_LINE
3632 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3635 return WIFI_MANAGER_ERROR_NONE;
3638 int _wifi_get_wps_generated_pin(wifi_manager_h wifi, char **wps_pin)
3641 wifi_manager_handle_s *wifi_handle = wifi;
3643 rv = net_get_wps_generated_pin(wifi_handle->network_info, wps_pin);
3644 if (rv != NET_ERR_NONE)
3645 WIFI_LOG(WIFI_ERROR, "Failed to get WPS PIN");
3650 int _wifi_get_module_state(wifi_manager_h wifi, wifi_manager_module_state_e *state)
3653 int wifi_device_status = 0;
3654 wifi_manager_handle_s *wifi_handle = wifi;
3656 rv = net_wifi_get_module_state(wifi_handle->network_info, &wifi_device_status);
3657 if (rv == NET_ERR_ACCESS_DENIED) {
3658 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3659 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3660 } else if (rv != NET_ERR_NONE) {
3661 WIFI_LOG(WIFI_ERROR, "Failed to get module state"); //LCOV_EXCL_LINE
3662 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3665 if (wifi_device_status == 0) {
3666 WIFI_LOG(WIFI_INFO, "Wi-Fi Module is detached");
3667 *state = WIFI_MANAGER_MODULE_STATE_DETACHED;
3669 WIFI_LOG(WIFI_INFO, "Wi-Fi Module is attached");
3670 *state = WIFI_MANAGER_MODULE_STATE_ATTACHED;
3673 return WIFI_MANAGER_ERROR_NONE;
3677 bool _wifi_check_multi_scan_validity(wifi_manager_specific_scan_h specific_scan)
3679 GSList *list = NULL;
3681 if (specific_scan == NULL)
3684 for (list = multi_scan_handle_list; list; list = list->next)
3685 if (specific_scan == list->data) return true;
3690 void _wifi_add_to_multi_scan_list(wifi_manager_specific_scan_h *specific_scan)
3692 multi_scan_handle_list = g_slist_append(multi_scan_handle_list, *specific_scan);
3695 void _wifi_remove_from_multi_scan_list(wifi_manager_specific_scan_h specific_scan)
3697 GSList *multi_scan_list = (GSList *)specific_scan;
3699 g_slist_free_full(multi_scan_list, g_free);
3701 multi_scan_handle_list = g_slist_remove(multi_scan_handle_list, specific_scan);
3702 multi_scan_type[WIFI_MULTI_SCAN_SSID] = false;
3703 multi_scan_type[WIFI_MULTI_SCAN_FREQ] = false;
3706 int _wifi_specific_scan_create(wifi_manager_specific_scan_h *specific_scan)
3708 GSList *list = g_slist_alloc();
3711 WIFI_LOG(WIFI_ERROR, "Failed to create specific scan handle"); //LCOV_EXCL_LINE
3712 return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
3715 *specific_scan = list;
3717 WIFI_LOG(WIFI_INFO, "New specific scan handle[%p]", *specific_scan);
3718 return WIFI_MANAGER_ERROR_NONE;
3721 int _wifi_specific_scan_set_ssid(wifi_manager_specific_scan_h specific_scan,
3724 GSList *list = (GSList *)specific_scan;
3725 wifi_manager_multi_scan_ap_s *ap = (wifi_manager_multi_scan_ap_s*)g_try_malloc0(sizeof(wifi_manager_multi_scan_ap_s));
3728 WIFI_LOG(WIFI_ERROR, "Failed to allocate memory"); //LCOV_EXCL_LINE
3729 return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
3731 g_strlcpy(ap->str, essid, NET_WLAN_ESSID_LEN + 1);
3734 list = g_slist_append(list, ap);
3735 multi_scan_type[WIFI_MULTI_SCAN_SSID] = true;
3737 specific_scan = (wifi_manager_specific_scan_h)list;
3738 return WIFI_MANAGER_ERROR_NONE;
3741 int _wifi_specific_scan_set_freq(wifi_manager_specific_scan_h specific_scan,
3744 GSList *list = (GSList *)specific_scan;
3746 snprintf(str, 5, "%d", freq);
3748 wifi_manager_multi_scan_ap_s *ap = (wifi_manager_multi_scan_ap_s*)g_try_malloc0(sizeof(wifi_manager_multi_scan_ap_s));
3751 WIFI_LOG(WIFI_ERROR, "Failed to allocate memory"); //LCOV_EXCL_LINE
3752 return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
3754 g_strlcpy(ap->str, str, NET_WLAN_FREQ_LEN);
3757 list = g_slist_append(list, ap);
3758 multi_scan_type[WIFI_MULTI_SCAN_FREQ] = true;
3760 specific_scan = (wifi_manager_specific_scan_h)list;
3761 return WIFI_MANAGER_ERROR_NONE;
3764 int _wifi_start_multi_scan(wifi_manager_h wifi,
3765 wifi_manager_specific_scan_h specific_scan,
3766 wifi_manager_scan_finished_cb callback, void *user_data)
3769 wifi_manager_handle_s *wifi_handle = wifi;
3770 GSList *multi_scan_list = (GSList *)specific_scan;
3772 rv = net_multi_scan_wifi(wifi_handle->network_info, multi_scan_list->next, multi_scan_type);
3773 if (rv == NET_ERR_ACCESS_DENIED) {
3774 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3775 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3776 } else if (rv == NET_ERR_INVALID_OPERATION) {
3777 return WIFI_MANAGER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
3778 } else if (rv == NET_ERR_OUT_OF_MEMORY) {
3779 return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
3780 } else if (rv == NET_ERR_NONE) {
3781 __set_multi_scan_cb(wifi_handle, callback, user_data);
3782 return WIFI_MANAGER_ERROR_NONE;
3785 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3788 int _wifi_get_connection_mode(wifi_manager_h wifi, wifi_manager_connection_mode_e *mode)
3792 wifi_manager_handle_s *wifi_handle = wifi;
3793 net_profile_info_s *prof_info = NULL;
3795 rv = __update_profile_iterator(wifi_handle);
3796 if (rv == NET_ERR_ACCESS_DENIED) {
3797 WIFI_LOG(WIFI_ERROR, "Access denied");
3798 return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
3801 for (list = wifi_handle->profile_iterator; list; list = list->next) {
3802 prof_info = (net_profile_info_s *)list->data;
3803 if (prof_info->ProfileState == NET_STATE_TYPE_ONLINE ||
3804 prof_info->ProfileState == NET_STATE_TYPE_READY)
3808 if (prof_info == NULL) {
3809 WIFI_LOG(WIFI_ERROR, "There is no connected AP");
3810 return WIFI_MANAGER_ERROR_NO_CONNECTION;
3813 *mode = (wifi_manager_connection_mode_e)prof_info->connection_mode;
3815 return WIFI_MANAGER_ERROR_NONE;
3818 int _wifi_get_service_state(wifi_manager_handle_s *wifi_handle)
3820 wifi_service_state_e ret = WIFI_SERVICE_STATE_UNKNOWN;
3821 net_state_type_e service_state = net_get_service_state(wifi_handle->network_info);
3823 switch (service_state) {
3824 case NET_STATE_TYPE_UNKNOWN:
3825 ret = WIFI_SERVICE_STATE_UNKNOWN;
3827 case NET_STATE_TYPE_FAILURE:
3828 ret = WIFI_SERVICE_STATE_FAILURE;
3830 case NET_STATE_TYPE_ASSOCIATION:
3831 ret = WIFI_SERVICE_STATE_ASSOCIATION;
3833 case NET_STATE_TYPE_CONFIGURATION:
3834 ret = WIFI_SERVICE_STATE_CONFIGURATION;
3836 case NET_STATE_TYPE_READY:
3837 case NET_STATE_TYPE_ONLINE:
3838 ret = WIFI_SERVICE_STATE_CONNECTED;
3840 case NET_STATE_TYPE_IDLE:
3841 case NET_STATE_TYPE_DISCONNECT:
3842 ret = WIFI_SERVICE_STATE_IDLE;
3851 int _wifi_get_max_scan_ssids(wifi_manager_h wifi, int *max_scan_ssids)
3854 wifi_manager_handle_s *wifi_handle = wifi;
3856 rv = net_wifi_get_max_scan_ssids(wifi_handle->network_info, max_scan_ssids);
3857 if (rv == NET_ERR_ACCESS_DENIED) {
3858 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
3859 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
3860 } else if (rv != NET_ERR_NONE) {
3861 WIFI_LOG(WIFI_ERROR, "Failed to get driver_max_scan_ssids"); //LCOV_EXCL_LINE
3862 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3865 return WIFI_MANAGER_ERROR_NONE;
3869 bool _wifi_check_dpp_validity(wifi_manager_dpp_h dpp_h)
3871 GSList *list = NULL;
3876 for (list = dpp_handle_list; list; list = list->next)
3877 if (dpp_h == list->data) return true;
3882 void _wifi_add_to_dpp_list(wifi_manager_dpp_h dpp_h)
3884 dpp_handle_list = g_slist_prepend(dpp_handle_list, dpp_h);
3887 void _wifi_remove_from_dpp_list(wifi_manager_dpp_h dpp_h)
3889 if (dpp_h == g_p_dpp_current)
3890 g_p_dpp_current = NULL;
3891 dpp_handle_list = g_slist_remove(dpp_handle_list, dpp_h);
3895 static gboolean __is_new_initiator(wifi_dpp_s *p_dpp)
3897 return (p_dpp->is_initiator) && (p_dpp->state == WIFI_MANAGER_DPP_STATE_NONE);
3900 static gboolean __is_response_pending_initiator(wifi_dpp_s *p_dpp)
3902 return (p_dpp->is_initiator) && (p_dpp->state == WIFI_MANAGER_DPP_STATE_URI_REQUESTED);
3905 static gboolean __is_new_responder(wifi_dpp_s *p_dpp)
3907 return (!p_dpp->is_initiator) && (p_dpp->state == WIFI_MANAGER_DPP_STATE_NONE);
3910 static gboolean __is_peer_scan_requested_responder(wifi_dpp_s *p_dpp)
3912 return (!p_dpp->is_initiator) && (p_dpp->state == WIFI_MANAGER_DPP_STATE_URI_REQUESTED);
3915 static wifi_manager_error_e __convert_net_err_to_wifi_dpp_error(net_err_e err_type)
3919 return WIFI_MANAGER_ERROR_NONE;
3920 case NET_ERR_IN_PROGRESS:
3921 return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS;
3922 case NET_ERR_ACCESS_DENIED:
3923 return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
3924 case NET_ERR_INVALID_PARAM:
3925 return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
3927 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
3932 int _wifi_dpp_enter_peer_uri(wifi_dpp_s *p_dpp,
3935 int rv = WIFI_MANAGER_ERROR_NONE;
3937 /* Just saving Peer URI for not bootstrapped initiator */
3938 if (__is_new_initiator(p_dpp))
3941 if (!__is_peer_scan_requested_responder(p_dpp))
3942 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
3944 if (g_p_dpp_current != p_dpp)
3945 return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS;
3947 rv = net_dpp_enter_peer_uri(p_dpp->network_info, p_dpp->peer_id, p_dpp->own_id, uri);
3949 if (rv != NET_ERR_NONE)
3950 WIFI_LOG(WIFI_ERROR, "Failed to enter peer URI");
3952 g_p_dpp_current = p_dpp;
3954 return __convert_net_err_to_wifi_dpp_error(rv);
3957 int _wifi_dpp_request_own_uri_gen(wifi_dpp_s *p_dpp, const char *key)
3959 int rv = WIFI_MANAGER_ERROR_NONE;
3961 if (!__is_response_pending_initiator(p_dpp))
3962 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
3964 if (g_p_dpp_current != p_dpp)
3965 return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS;
3967 rv = net_dpp_generate_own_uri(p_dpp->network_info,
3968 p_dpp->peer_id, p_dpp->own_id, p_dpp->is_initiator, key);
3970 if (rv != NET_ERR_NONE)
3971 WIFI_LOG(WIFI_ERROR, "Failed to generate own URI");
3973 return __convert_net_err_to_wifi_dpp_error(rv);
3976 int _wifi_dpp_start(wifi_dpp_s *p_dpp, const char *auth_key,
3977 const char *configurator_key, const char *pass)
3979 int rv = WIFI_MANAGER_ERROR_NONE;
3981 if (!__is_new_initiator(p_dpp) &&
3982 !__is_new_responder(p_dpp))
3983 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
3985 if (g_p_dpp_current)
3986 return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS;
3988 rv = net_dpp_start((void *)p_dpp, auth_key, configurator_key, pass);
3990 if (rv != NET_ERR_NONE)
3991 WIFI_LOG(WIFI_ERROR, "Failed to start");
3993 g_p_dpp_current = p_dpp;
3995 return __convert_net_err_to_wifi_dpp_error(rv);
3998 int _wifi_dpp_stop(wifi_dpp_s *p_dpp)
4000 int rv = WIFI_MANAGER_ERROR_NONE;
4002 if (__is_new_initiator(p_dpp) ||
4003 __is_new_responder(p_dpp))
4004 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
4006 if (!g_p_dpp_current)
4007 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
4009 if (g_p_dpp_current != p_dpp)
4010 return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS;
4012 rv = net_dpp_stop(p_dpp->network_info,
4013 p_dpp->peer_id, p_dpp->own_id, p_dpp->is_initiator);
4015 if (rv != NET_ERR_NONE)
4016 WIFI_LOG(WIFI_ERROR, "Failed to stop");
4018 return __convert_net_err_to_wifi_dpp_error(rv);
4022 void _wifi_lock(void)
4024 pthread_mutex_lock(&g_wifi_thread_mutex);
4027 void _wifi_unlock(void)
4029 pthread_mutex_unlock(&g_wifi_thread_mutex);
4032 int _wifi_set_mac_policy(wifi_manager_h wifi, unsigned int policy)
4035 wifi_manager_handle_s *wifi_handle = wifi;
4037 rv = net_wifi_set_mac_policy(wifi_handle->network_info, policy);
4038 if (rv == NET_ERR_ACCESS_DENIED) {
4039 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
4040 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
4041 } else if (rv != NET_ERR_NONE)
4042 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
4044 wifi_handle->mac_policy = policy;
4046 return WIFI_MANAGER_ERROR_NONE;
4049 int _wifi_get_mac_policy(wifi_manager_h wifi, unsigned int *policy)
4052 wifi_manager_handle_s *wifi_handle = wifi;
4054 rv = net_wifi_get_mac_policy(wifi_handle->network_info, policy);
4055 if (rv == NET_ERR_ACCESS_DENIED) {
4056 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
4057 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
4058 } else if (rv != NET_ERR_NONE)
4059 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
4061 return WIFI_MANAGER_ERROR_NONE;
4064 int _wifi_set_preassoc_mac_policy(wifi_manager_h wifi, unsigned int policy)
4067 wifi_manager_handle_s *wifi_handle = wifi;
4069 rv = net_wifi_set_preassoc_mac_policy(wifi_handle->network_info, policy);
4070 if (rv == NET_ERR_ACCESS_DENIED) {
4071 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
4072 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
4073 } else if (rv != NET_ERR_NONE)
4074 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
4076 wifi_handle->preassoc_mac_policy = policy;
4078 return WIFI_MANAGER_ERROR_NONE;
4081 int _wifi_get_preassoc_mac_policy(wifi_manager_h wifi, unsigned int *policy)
4084 wifi_manager_handle_s *wifi_handle = wifi;
4086 rv = net_wifi_get_preassoc_mac_policy(wifi_handle->network_info, policy);
4087 if (rv == NET_ERR_ACCESS_DENIED) {
4088 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
4089 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
4090 } else if (rv != NET_ERR_NONE)
4091 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
4093 return WIFI_MANAGER_ERROR_NONE;
4096 int _wifi_set_random_mac_lifetime(wifi_manager_h wifi, unsigned int lifetime)
4099 wifi_manager_handle_s *wifi_handle = wifi;
4101 rv = net_wifi_set_random_mac_lifetime(wifi_handle->network_info, lifetime);
4102 if (rv == NET_ERR_ACCESS_DENIED) {
4103 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
4104 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
4105 } else if (rv != NET_ERR_NONE)
4106 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
4108 wifi_handle->random_mac_lifetime = lifetime;
4110 return WIFI_MANAGER_ERROR_NONE;
4113 int _wifi_get_random_mac_lifetime(wifi_manager_h wifi, unsigned int *lifetime)
4116 wifi_manager_handle_s *wifi_handle = wifi;
4118 rv = net_wifi_get_random_mac_lifetime(wifi_handle->network_info, lifetime);
4119 if (rv == NET_ERR_ACCESS_DENIED) {
4120 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
4121 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
4122 } else if (rv != NET_ERR_NONE)
4123 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
4125 return WIFI_MANAGER_ERROR_NONE;
4128 int _wifi_set_country_code(wifi_manager_h wifi, const char *country)
4131 wifi_manager_handle_s *wifi_handle = wifi;
4133 rv = net_wifi_set_country_code(wifi_handle->network_info, country);
4134 if (rv == NET_ERR_ACCESS_DENIED) {
4135 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
4136 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
4137 } else if (rv != NET_ERR_NONE)
4138 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
4140 memset(wifi_handle->country, 0, sizeof(wifi_handle->country));
4141 g_strlcpy(wifi_handle->country, country, sizeof(wifi_handle->country));
4143 return WIFI_MANAGER_ERROR_NONE;
4146 int _wifi_get_country_code(wifi_manager_h wifi, char **country)
4149 wifi_manager_handle_s *wifi_handle = wifi;
4151 rv = net_wifi_get_country_code(wifi_handle->network_info, country);
4152 if (rv == NET_ERR_ACCESS_DENIED) {
4153 WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
4154 return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
4155 } else if (rv != NET_ERR_NONE)
4156 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
4158 return WIFI_MANAGER_ERROR_NONE;