Add a new wifi error type for association failure
[platform/core/api/wifi-manager.git] / src / wifi_internal.c
1 /*
2  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #define _GNU_SOURCE
18 #include <pthread.h>
19 #include <glib.h>
20 #include <ctype.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <system_info.h>
25
26 #include "wifi_internal.h"
27
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"
36
37 #define WIFI_MAC_ADDR_PATH_LEN      32
38 #define WIFI_MAC_ADDR_PATH          "/sys/class/net/%s/address"
39
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
43  */
44 static wifi_dpp_s *g_p_dpp_current = NULL;
45
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;
50
51 static gboolean multi_scan_type[WIFI_MULTI_SCAN_MAX] = {0, };
52
53 static bool wifi_is_feature_checked[WIFI_SUPPORTED_FEATURE_MAX] = {0, };
54 static bool wifi_feature_supported[WIFI_SUPPORTED_FEATURE_MAX] = {0, };
55
56 static pthread_mutex_t g_wifi_thread_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
57
58 //LCOV_EXCL_START
59 static wifi_manager_error_e __convert_to_ap_error_type(net_err_e err_type)
60 {
61         switch (err_type) {
62         case NET_ERR_NONE:
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;
104         default:
105                 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
106         }
107 }
108
109 static const char *__convert_ap_error_type_to_string(wifi_manager_error_e err_type)
110 {
111         switch (err_type) {
112         case WIFI_MANAGER_ERROR_NONE:
113                 return "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:
149                 return "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";
164
165         default:
166                 return "UNKNOWN";
167         }
168 }
169
170 static const char *__convert_ap_state_to_string(wifi_manager_connection_state_e state)
171 {
172         switch (state) {
173         case WIFI_MANAGER_CONNECTION_STATE_FAILURE:
174                 return "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:
182                 return "CONNECTED";
183         default:
184                 return "UNKNOWN";
185         }
186 }
187 //LCOV_EXCL_STOP
188
189 static gchar *__wifi_change_name_to_hexadecimal(const gchar *name)
190 {
191         GString *string;
192         gint i = 0;
193         gint length = 0;
194         gchar *hex = NULL;
195
196         if (name == NULL)
197                 return NULL;
198
199         length = strlen(name);
200
201         string = g_string_sized_new((gsize)(length * 2));
202         if (string == NULL)
203                 return NULL;
204
205         for (i = 0; i < length; i++)
206                 g_string_append_printf(string, "%02x", name[i]);
207
208         hex = g_strdup_printf("%s", string->str);
209         g_string_free(string, TRUE);
210
211         return hex;
212 }
213
214 //LCOV_EXCL_START
215 static gchar *__wifi_security_type_to_string(wifi_manager_security_type_e security_type)
216 {
217         switch (security_type) {
218         case WIFI_MANAGER_SECURITY_TYPE_NONE:
219                 return WIFI_SECURITY_NONE;
220
221         case WIFI_MANAGER_SECURITY_TYPE_WEP:
222                 return WIFI_SECURITY_WEP;
223
224         case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK:
225         case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK:
226                 return WIFI_SECURITY_WPA_PSK;
227
228         case WIFI_MANAGER_SECURITY_TYPE_SAE:
229                 return WIFI_SECURITY_SAE;
230
231         case WIFI_MANAGER_SECURITY_TYPE_OWE:
232                 return WIFI_SECURITY_OWE;
233
234         case WIFI_MANAGER_SECURITY_TYPE_DPP:
235                 return WIFI_SECURITY_DPP;
236
237         case WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK:
238                 return WIFI_SECURITY_WPA_FT_PSK;
239
240         case WIFI_MANAGER_SECURITY_TYPE_EAP:
241                 return WIFI_SECURITY_EAP;
242
243         default:
244                 return NULL;
245         }
246 }
247
248 gchar *_wifi_eap_type_to_string(wifi_manager_eap_type_e eap_type)
249 {
250         gchar *type = NULL;
251
252         switch (eap_type) {
253         case WIFI_MANAGER_EAP_TYPE_PEAP:
254                 type = g_strdup("PEAP");
255                 break;
256         case WIFI_MANAGER_EAP_TYPE_TLS:
257                 type = g_strdup("TLS");
258                 break;
259         case WIFI_MANAGER_EAP_TYPE_TTLS:
260                 type = g_strdup("TTLS");
261                 break;
262         case WIFI_MANAGER_EAP_TYPE_SIM:
263                 type = g_strdup("SIM");
264                 break;
265         case WIFI_MANAGER_EAP_TYPE_AKA:
266                 type = g_strdup("AKA");
267                 break;
268         case WIFI_MANAGER_EAP_TYPE_AKA_PRIME:
269                 type = g_strdup("AKA'");
270                 break;
271         case WIFI_MANAGER_EAP_TYPE_FAST:
272                 type = g_strdup("FAST");
273                 break;
274         case WIFI_MANAGER_EAP_TYPE_PWD:
275                 type = g_strdup("PWD");
276                 break;
277         }
278         return type;
279 }
280
281 gchar *_wifi_eap_auth_type_to_string(wifi_manager_eap_auth_type_e eap_auth_type)
282 {
283         gchar *type = NULL;
284
285         switch (eap_auth_type) {
286         case WIFI_MANAGER_EAP_AUTH_TYPE_PAP:
287                 type = g_strdup("PAP");
288                 break;
289         case WIFI_MANAGER_EAP_AUTH_TYPE_MSCHAP:
290                 type = g_strdup("MSCHAP");
291                 break;
292         case WIFI_MANAGER_EAP_AUTH_TYPE_MSCHAPV2:
293                 type = g_strdup("MSCHAPV2");
294                 break;
295         case WIFI_MANAGER_EAP_AUTH_TYPE_GTC:
296                 type = g_strdup("GTC");
297                 break;
298         case WIFI_MANAGER_EAP_AUTH_TYPE_MD5:
299                 type = g_strdup("MD5");
300                 break;
301         default:
302         case WIFI_MANAGER_EAP_AUTH_TYPE_NONE:
303                 type = NULL;
304                 break;
305         }
306         return type;
307 }
308
309 static void __clear_profile_internal_list(GSList *iterator)
310 {
311         GSList *list;
312
313         for (list = iterator; list; list = list->next) {
314                 net_profile_info_s *prof_info = (net_profile_info_s *)list->data;
315
316                 if (prof_info->vsie_list) {
317                         g_slist_free_full(prof_info->vsie_list, g_free);
318                         prof_info->vsie_list = NULL;
319                 }
320
321                 if (prof_info->bssid_list) {
322                         g_slist_free_full(prof_info->bssid_list, g_free);
323                         prof_info->bssid_list = NULL;
324                 }
325         }
326 }
327
328 void __clear_interface_list(GSList **iterator)
329 {
330         if (*iterator) {
331                 *iterator = g_slist_nth(*iterator, 0);
332                 g_slist_free_full(*iterator, g_free);
333                 *iterator = NULL;
334         }
335 }
336 //LCOV_EXCL_STOP
337
338 void __clear_profile_list(GSList **iterator)
339 {
340         if (*iterator) {
341                 *iterator = g_slist_nth(*iterator, 0);
342                 __clear_profile_internal_list(*iterator);
343                 g_slist_free_full(*iterator, g_free);
344                 *iterator = NULL;
345         }
346 }
347
348 gpointer _wifi_copy_vsie_list(gconstpointer data, gpointer user_data)
349 {
350         unsigned char *str = (unsigned char *)data;
351         unsigned char *vsie;
352         vsie = g_try_malloc0(str[1]+2);
353
354         if (vsie)
355                 memcpy(vsie, str, str[1]+2);
356         else
357                 WIFI_LOG(WIFI_ERROR, "Failed to allocate memory.");  //LCOV_EXCL_LINE
358
359         return vsie;
360 }
361
362 gpointer _wifi_copy_bssid_list(gconstpointer data, gpointer user_data)
363 {
364         net_profile_bssid_list_s *org_data, *dst_data;
365
366         org_data = (net_profile_bssid_list_s *)data;
367         dst_data = g_try_malloc0(sizeof(net_profile_bssid_list_s));
368         if (dst_data) {
369                 g_strlcpy(dst_data->bssid, org_data->bssid, 18);
370                 dst_data->strength = org_data->strength;
371                 dst_data->frequency = org_data->frequency;
372         }
373
374         return dst_data;
375 }
376
377 static int __update_profile_iterator(wifi_manager_handle_s *wifi_handle)
378 {
379         int rv;
380
381         __clear_profile_list(&(wifi_handle->profile_iterator));
382
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
388         }
389
390         return WIFI_MANAGER_ERROR_NONE;
391 }
392
393 //LCOV_EXCL_START
394 static int __update_interface_iterator(wifi_manager_handle_s *wifi_handle)
395 {
396         int rv;
397
398         __clear_interface_list(&(wifi_handle->interface_iterator));
399
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
405         }
406
407         return WIFI_MANAGER_ERROR_NONE;
408 }
409 //LCOV_EXCL_STOP
410
411 static void __update_specific_iterator(wifi_manager_handle_s *wifi_handle, GSList *bss_list)
412 {
413         int i, count = 0;
414         GSList *list = bss_list;
415         net_profile_info_s *prof_info = NULL;
416
417         count = (int)g_slist_length(list);
418         if (count == 0) {
419                 WIFI_LOG(WIFI_INFO, "No hidden AP found"); //LCOV_EXCL_LINE
420                 return; //LCOV_EXCL_LINE
421         }
422
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
429                 }
430
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
435                 }
436
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;
442
443                 wifi_handle->specific_profile_iterator =
444                         g_slist_append(wifi_handle->specific_profile_iterator,
445                                 (net_profile_info_s *)prof_info);
446         }
447 }
448
449 static void __update_bss_profile_iterator(wifi_manager_handle_s *wifi_handle,
450                 GSList *bss_list)
451 {
452         int count = 0;
453         GSList *list = bss_list;
454
455         count = (int)g_slist_length(list);
456         if (count == 0) {
457                 WIFI_LOG(WIFI_INFO, "No AP found !!"); //LCOV_EXCL_LINE
458                 return; //LCOV_EXCL_LINE
459         }
460
461         for (list = bss_list; list; list = list->next) {
462
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
468                 }
469
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
474                 }
475
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);
478
479                 profile->wlan_mode = ap->mode;
480
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;
485
486                 wifi_handle->bss_profile_iterator =
487                         g_slist_append(wifi_handle->bss_profile_iterator,
488                                 (net_profile_info_s *)profile);
489         }
490 }
491
492 //LCOV_EXCL_START
493 static void __update_netlink_scan_profile_iterator(wifi_manager_handle_s *wifi_handle,
494                 GSList *bss_list)
495 {
496         int count = 0;
497         GSList *list = bss_list;
498
499         count = (int)g_slist_length(list);
500         if (count == 0) {
501                 WIFI_LOG(WIFI_INFO, "No AP found !!");
502                 return;
503         }
504
505         for (list = bss_list; list; list = list->next) {
506
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");
511                         return;
512                 }
513
514                 if (net_init_profile_info(wifi_handle->network_info, profile) != NET_ERR_NONE) {
515                         WIFI_LOG(WIFI_ERROR, "Failed to init profile");
516                         g_free(profile);
517                         return;
518                 }
519
520                 g_strlcpy(profile->essid, ap->ssid, NET_WLAN_ESSID_LEN + 1);
521                 g_strlcpy(profile->bssid, ap->bssid, WIFI_MAC_ADDR_LEN + 1);
522
523                 if (ap->vsie_list) {
524                         GSList *l_list;
525
526                         for (l_list = ap->vsie_list; l_list; l_list = l_list->next) {
527                                 unsigned char *str = (unsigned char *)l_list->data;
528                                 unsigned char *vsie;
529                                 vsie = g_try_malloc0(str[1]+2);
530
531                                 if (vsie) {
532                                         memcpy(vsie, str, str[1]+2);
533                                         profile->vsie_list = g_slist_append(profile->vsie_list, vsie);
534                                 } else
535                                         WIFI_LOG(WIFI_ERROR, "Failed to allocate memory.");
536                         }
537
538                         g_slist_free_full(ap->vsie_list, g_free);
539                         ap->vsie_list = NULL;
540                 }
541
542                 profile->frequency = (unsigned int)ap->freq;
543                 profile->Strength = 120 + ap->rssi;
544
545                 switch (ap->security_type) {
546                 case 0:
547                         profile->security_info.sec_mode = WLAN_SEC_MODE_NONE;
548                         break;
549                 case 1:
550                         profile->security_info.sec_mode = WLAN_SEC_MODE_WEP;
551                         break;
552                 case 2:
553                         profile->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
554                         break;
555                 case 3:
556                         profile->security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK;
557                         break;
558                 case 4:
559                         profile->security_info.sec_mode = WLAN_SEC_MODE_SAE;
560                         break;
561                 case 5:
562                         profile->security_info.sec_mode = WLAN_SEC_MODE_IEEE8021X;
563                         break;
564                 default:
565                         profile->security_info.sec_mode = WLAN_SEC_MODE_NONE;
566                         break;
567                 }
568
569                 switch (ap->encryption_type) {
570                 case 0:
571                         profile->security_info.enc_mode = WLAN_ENC_MODE_NONE;
572                         break;
573                 case 1:
574                         profile->security_info.enc_mode = WLAN_ENC_MODE_WEP;
575                         break;
576                 case 2:
577                         profile->security_info.enc_mode = WLAN_ENC_MODE_TKIP;
578                         break;
579                 case 3:
580                         profile->security_info.enc_mode = WLAN_ENC_MODE_AES;
581                         break;
582                 case 4:
583                         profile->security_info.enc_mode = WLAN_ENC_MODE_TKIP_AES_MIXED;
584                         break;
585                 default:
586                         profile->security_info.enc_mode = WLAN_ENC_MODE_NONE;
587                         break;
588                 }
589
590                 wifi_handle->bss_profile_iterator = g_slist_append(wifi_handle->bss_profile_iterator,
591                                         (net_profile_info_s *)profile);
592         }
593 }
594 //LCOV_EXCL_STOP
595
596 static void __convert_profile_info_to_wifi_info(net_wifi_connection_info_s *wifi_info,
597                                                                 net_profile_info_s *ap_info)
598 {
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;
605 }
606
607 static int __connect_with_wifi_info(wifi_manager_handle_s *wifi_handle,
608                 net_profile_info_s *ap_info)
609 {
610         net_wifi_connection_info_s wifi_info;
611
612         memset(&wifi_info, 0, sizeof(net_wifi_connection_info_s));
613
614         __convert_profile_info_to_wifi_info(&wifi_info, ap_info);
615
616         return net_open_connection_with_wifi_info(wifi_handle->network_info, &wifi_info);
617 }
618
619 static int __load_configurations(wifi_manager_handle_s *wifi_handle,
620                 const gchar *config_id, wifi_config_s *config)
621 {
622         int rv;
623
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
636
637         return WIFI_MANAGER_ERROR_NONE;
638 }
639
640 static int __load_eap_configurations(wifi_manager_handle_s *wifi_handle,
641                 const gchar *config_id, wifi_config_s *config)
642 {
643         int rv;
644
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
657
658         return WIFI_MANAGER_ERROR_NONE;
659 }
660
661 //LCOV_EXCL_START
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)
664 {
665         net_profile_info_s *ap_info = NULL;
666
667         if (profile_name == NULL)
668                 return;
669
670         WIFI_LOG(WIFI_INFO, "%s state changed : %s", profile_name, __convert_ap_state_to_string(state));
671
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");
676                         return;
677                 }
678
679                 if (profile_info) {
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,
683                                         NULL);
684
685                         ap_info->bssid_list = g_slist_copy_deep(profile_info->bssid_list,
686                                         _wifi_copy_bssid_list,
687                                         NULL);
688                 } else {
689                         ap_info->network_info = wifi_handle->network_info;
690                 }
691
692                 WIFI_LOG(WIFI_INFO, "[Ap info] profile name(%s) essid(%s) bssid(%s)",
693                                 ap_info->ProfileName, ap_info->essid, ap_info->bssid);
694
695                 _wifi_add_to_ap_list(ap_info);
696
697                 wifi_handle->connection_state_cb(state, ap_info,
698                         wifi_handle->connection_state_user_data);
699
700                 _wifi_remove_from_ap_list(ap_info);
701
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);
706
707                 g_free(ap_info);
708         }
709 }
710
711 static void __set_activated_cb(wifi_manager_handle_s *wifi_handle,
712                 wifi_manager_activated_cb user_cb, void *user_data)
713 {
714         wifi_handle->activated_cb = user_cb;
715         wifi_handle->activated_user_data = user_data;
716 }
717
718 static void __set_deactivated_cb(wifi_manager_handle_s *wifi_handle,
719                 wifi_manager_deactivated_cb user_cb, void *user_data)
720 {
721         wifi_handle->deactivated_cb = user_cb;
722         wifi_handle->deactivated_user_data = user_data;
723 }
724
725 static void __power_on_off_cb(wifi_manager_handle_s *wifi_handle,
726                 net_event_info_s *event_cb, bool is_requested)
727 {
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;
731
732         if (wifi_handle->activated_cb == NULL &&
733                 wifi_handle->deactivated_cb == NULL &&
734                 wifi_handle->device_state_cb == NULL)
735                 return;
736
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));
748                 } else {
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;
752                 }
753         } else {
754                 WIFI_LOG(WIFI_ERROR, "Wi-Fi power request failed(%d)", event_cb->Error);
755
756                 if (event_cb->Error == NET_ERR_SECURITY_RESTRICTED)
757                         error_code = WIFI_MANAGER_ERROR_SECURITY_RESTRICTED;
758                 else
759                         error_code = WIFI_MANAGER_ERROR_OPERATION_FAILED;
760
761                 state = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED;
762         }
763
764         if (wifi_handle->activated_cb)
765                 wifi_handle->activated_cb(error_code, wifi_handle->activated_user_data);
766
767         wifi_handle->activated_cb = NULL;
768         wifi_handle->activated_user_data = NULL;
769
770         if (wifi_handle->deactivated_cb)
771                 wifi_handle->deactivated_cb(error_code, wifi_handle->deactivated_user_data);
772
773         wifi_handle->deactivated_cb = NULL;
774         wifi_handle->deactivated_user_data = NULL;
775
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);
779         }
780 }
781
782 static void __set_scan_cb(wifi_manager_handle_s *wifi_handle,
783                 wifi_manager_scan_finished_cb user_cb, void *user_data)
784 {
785         wifi_handle->scan_request_cb = user_cb;
786         wifi_handle->scan_request_user_data = user_data;
787 }
788
789 static void __set_specific_scan_cb(wifi_manager_handle_s *wifi_handle,
790                 wifi_manager_scan_finished_cb user_cb, void *user_data)
791 {
792         wifi_handle->specific_scan_cb = user_cb;
793         wifi_handle->specific_scan_user_data = user_data;
794 }
795
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)
798 {
799         wifi_handle->bssid_scan_cb = user_cb;
800         wifi_handle->bssid_scan_user_data = user_data;
801 }
802
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)
805 {
806         wifi_handle->netlink_scan_cb = user_cb;
807         wifi_handle->netlink_scan_user_data = user_data;
808 }
809
810 static void __set_multi_scan_cb(wifi_manager_handle_s *wifi_handle,
811                 wifi_manager_scan_finished_cb user_cb, void *user_data)
812 {
813         wifi_handle->multi_scan_cb = user_cb;
814         wifi_handle->multi_scan_user_data = user_data;
815 }
816
817 static void __scan_cb(wifi_manager_handle_s *wifi_handle,
818                 net_event_info_s *event_cb, bool is_requested)
819 {
820         wifi_manager_error_e error_code = WIFI_MANAGER_ERROR_NONE;
821
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;
825         }
826
827         if (wifi_handle->scan_request_cb) {
828                 wifi_handle->scan_request_cb(error_code, wifi_handle->scan_request_user_data);
829
830                 wifi_handle->scan_request_cb = NULL;
831                 wifi_handle->scan_request_user_data = NULL;
832
833                 return;
834         }
835
836         if (wifi_handle->bg_scan_cb)
837                 wifi_handle->bg_scan_cb(error_code, wifi_handle->bg_scan_user_data);
838 }
839
840 static void __scan_changed_cb(wifi_manager_handle_s *wifi_handle, wifi_manager_scan_state_e scan_state)
841 {
842         if (scan_state == 1)
843                 WIFI_LOG(WIFI_INFO, "scan state: Scan is in progress");
844         else
845                 WIFI_LOG(WIFI_INFO, "scan state: Scan is not running");
846
847         if (wifi_handle->scan_changed_cb)
848                 wifi_handle->scan_changed_cb(scan_state, wifi_handle->scan_changed_user_data);
849 }
850
851 static void __specific_scan_cb(wifi_manager_handle_s *wifi_handle, net_event_info_s *event_cb)
852 {
853         wifi_manager_error_e error_code = WIFI_MANAGER_ERROR_NONE;
854
855         __clear_profile_list(&(wifi_handle->specific_profile_iterator));
856
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));
864         }
865
866         if (wifi_handle->specific_scan_cb)
867                 wifi_handle->specific_scan_cb(error_code, wifi_handle->specific_scan_user_data);
868
869         wifi_handle->specific_scan_cb = NULL;
870         wifi_handle->specific_scan_user_data = NULL;
871 }
872
873 static void __bssid_scan_cb(wifi_manager_handle_s *wifi_handle, net_event_info_s *event_cb)
874 {
875         wifi_manager_error_e error_code = WIFI_MANAGER_ERROR_NONE;
876
877         __clear_profile_list(&(wifi_handle->bss_profile_iterator));
878
879         if (event_cb->Error != NET_ERR_NONE) {
880                 WIFI_LOG(WIFI_ERROR, "BSSID scan failed!, Error [%d]",
881                                  event_cb->Error);
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));
887         }
888
889         if (wifi_handle->bssid_scan_cb)
890                 wifi_handle->bssid_scan_cb(error_code, wifi_handle->bssid_scan_user_data);
891
892         wifi_handle->bssid_scan_cb = NULL;
893         wifi_handle->bssid_scan_user_data = NULL;
894 }
895
896 static void __ip_conflict_cb(wifi_manager_handle_s *wifi_handle, net_event_info_s *event_cb)
897 {
898         char *mac = NULL;
899         char *state = NULL;
900         net_ip_conflict_info_s *conflict_info = NULL;
901         wifi_manager_ip_conflict_state_e conflict_state = WIFI_MANAGER_IP_CONFLICT_STATE_UNKNOWN;
902
903         __clear_profile_list(&(wifi_handle->bss_profile_iterator));
904
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;
915                 }
916         }
917
918         if (wifi_handle->ip_conflict_cb)
919                 wifi_handle->ip_conflict_cb(mac, conflict_state, wifi_handle->ip_conflict_user_data);
920 }
921
922 static void __netlink_scan_cb(wifi_manager_handle_s *wifi_handle, net_event_info_s *event_cb)
923 {
924         wifi_manager_error_e error_code = WIFI_MANAGER_ERROR_NONE;
925
926         __clear_profile_list(&(wifi_handle->bss_profile_iterator));
927
928         if (event_cb->Error != NET_ERR_NONE) {
929                 WIFI_LOG(WIFI_ERROR, "NETLINK scan failed!, Error [%d]",
930                                  event_cb->Error);
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));
936         }
937
938         if (wifi_handle->netlink_scan_cb)
939                 wifi_handle->netlink_scan_cb(error_code, wifi_handle->netlink_scan_user_data);
940
941         wifi_handle->netlink_scan_cb = NULL;
942         wifi_handle->netlink_scan_user_data = NULL;
943 }
944
945 static void __multi_scan_cb(wifi_manager_handle_s *wifi_handle, net_event_info_s *event_cb)
946 {
947         wifi_manager_error_e error_code = WIFI_MANAGER_ERROR_NONE;
948
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;
952         }
953
954         if (wifi_handle->multi_scan_cb)
955                 wifi_handle->multi_scan_cb(error_code, wifi_handle->multi_scan_user_data);
956
957         wifi_handle->multi_scan_cb = NULL;
958         wifi_handle->multi_scan_user_data = NULL;
959 }
960
961 static void __set_connected_cb(wifi_manager_handle_s *wifi_handle,
962                 wifi_manager_connected_cb user_cb, void *user_data)
963 {
964         wifi_handle->connected_cb = user_cb;
965         wifi_handle->connected_user_data = user_data;
966 }
967
968 static void __connected_cb(wifi_manager_handle_s *wifi_handle, wifi_manager_error_e result)
969 {
970         if (wifi_handle->connected_cb)
971                 wifi_handle->connected_cb(result, wifi_handle->connected_user_data);
972
973         wifi_handle->connected_cb = NULL;
974         wifi_handle->connected_user_data = NULL;
975 }
976
977 static void __set_disconnected_cb(wifi_manager_handle_s *wifi_handle,
978                 wifi_manager_disconnected_cb user_cb, void *user_data)
979 {
980         wifi_handle->disconnected_cb = user_cb;
981         wifi_handle->disconnected_user_data = user_data;
982 }
983
984 static void __disconnected_cb(wifi_manager_handle_s *wifi_handle,
985                 wifi_manager_error_e result)
986 {
987         if (wifi_handle->disconnected_cb)
988                 wifi_handle->disconnected_cb(result, wifi_handle->disconnected_user_data);
989
990         wifi_handle->disconnected_cb = NULL;
991         wifi_handle->disconnected_user_data = NULL;
992 }
993
994 static void __tdls_discovered_cb(wifi_manager_handle_s *wifi_handle,
995                 net_event_info_s *event_cb)
996 {
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;
1001
1002         if (discover_info == NULL) {
1003                 WIFI_LOG(WIFI_INFO, "Discover Data is NULL !!!");
1004                 return;
1005         }
1006
1007         peer_mac_add = discover_info->mac_add;
1008
1009         WIFI_LOG(WIFI_INFO, "Peer Mac Add %s , Type[%d] ", peer_mac_add, discover_info->type);
1010
1011         if (discover_info->type == 0) //TDLS Discovery : Unicast
1012                 state = WIFI_MANAGER_TDLS_DISCOVERY_STATE_FINISHED;
1013
1014         else if (discover_info->type == 1 &&
1015                                 (NULL != strstr("00:00:00:00:00:00", peer_mac_add))) {
1016
1017                 WIFI_LOG(WIFI_INFO, "TDLS: Broadcast Discovery Timeout Event");
1018                 state = WIFI_MANAGER_TDLS_DISCOVERY_STATE_FINISHED;
1019         } else
1020                 state = WIFI_MANAGER_TDLS_DISCOVERY_STATE_ONGOING;
1021
1022         if (wifi_handle->tdls_discovered_cb)
1023                 wifi_handle->tdls_discovered_cb(state, peer_mac_add,
1024                         wifi_handle->tdls_discovered_user_data);
1025 }
1026
1027
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)
1030 {
1031         char *peer_mac_add = NULL;
1032         peer_mac_add = (char*)event_cb->Data;
1033
1034         WIFI_LOG(WIFI_INFO, "Peer Mac Add %s ", peer_mac_add);
1035
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);
1039 }
1040 //LCOV_EXCL_STOP
1041
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)
1044 {
1045         wifi_handle->forget_ap_cb = user_cb;
1046         wifi_handle->forget_ap_user_data = user_data;
1047 }
1048
1049 static void __forget_ap_cb(wifi_manager_handle_s *wifi_handle, wifi_manager_error_e result)
1050 {
1051         if (wifi_handle->forget_ap_cb)
1052                 wifi_handle->forget_ap_cb(result, wifi_handle->forget_ap_user_data);
1053
1054         wifi_handle->forget_ap_cb = NULL;
1055         wifi_handle->forget_ap_user_data = NULL;
1056 }
1057
1058 static void __rssi_level_changed_cb(wifi_manager_handle_s *wifi_handle,
1059                 net_rssi_info_s *rssi_info)
1060 {
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);
1065         }
1066 }
1067
1068 //LCOV_EXCL_START
1069 static void __module_state_changed_cb(wifi_manager_handle_s *wifi_handle,
1070                 net_module_info_s *module_info)
1071 {
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);
1076         }
1077 }
1078
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)
1081 {
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);
1085 }
1086
1087 static void __dpp_uri_generated_cb(wifi_manager_handle_s *wifi_handle,
1088                 net_dpp_event_info_s *dpp_event_info)
1089 {
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;
1093         }
1094
1095         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_URI_GENERATED,
1096                         WIFI_MANAGER_DPP_STATE_NONE);
1097 }
1098
1099 static void __dpp_bootstrapped_cb(wifi_manager_handle_s *wifi_handle,
1100                 net_dpp_event_info_s *dpp_event_info)
1101 {
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;
1105         }
1106
1107         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1108                         WIFI_MANAGER_DPP_STATE_BOOTSTRAPPED);
1109 }
1110
1111 static void __dpp_awaiting_cb(wifi_manager_handle_s *wifi_handle,
1112                 net_dpp_event_info_s *dpp_event_info)
1113 {
1114         if (g_p_dpp_current)
1115                 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_AWAITING;
1116
1117         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1118                         WIFI_MANAGER_DPP_STATE_AWAITING);
1119 }
1120
1121 static void __dpp_authenticating_cb(wifi_manager_handle_s *wifi_handle,
1122                 net_dpp_event_info_s *dpp_event_info)
1123 {
1124         if (g_p_dpp_current)
1125                 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_AUTHENTICATING;
1126
1127         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1128                         WIFI_MANAGER_DPP_STATE_AUTHENTICATING);
1129 }
1130
1131 static void __dpp_auth_success_cb(wifi_manager_handle_s *wifi_handle,
1132                 net_dpp_event_info_s *dpp_event_info)
1133 {
1134         if (g_p_dpp_current)
1135                 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_AUTHENTICATED;
1136
1137         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1138                         WIFI_MANAGER_DPP_STATE_AUTHENTICATED);
1139 }
1140
1141 static void __dpp_auth_failed_cb(wifi_manager_handle_s *wifi_handle,
1142                 net_dpp_event_info_s *dpp_event_info)
1143 {
1144         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_AUTH_FAILED,
1145                         WIFI_MANAGER_DPP_STATE_NONE);
1146 }
1147
1148 static void __dpp_not_compatible_cb(wifi_manager_handle_s *wifi_handle,
1149                 net_dpp_event_info_s *dpp_event_info)
1150 {
1151         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_NOT_COMPATIBLE,
1152                         WIFI_MANAGER_DPP_STATE_NONE);
1153 }
1154
1155 static void __dpp_conf_failed_cb(wifi_manager_handle_s *wifi_handle,
1156                 net_dpp_event_info_s *dpp_event_info)
1157 {
1158         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_CONF_FAILED,
1159                         WIFI_MANAGER_DPP_STATE_NONE);
1160 }
1161
1162 static void __dpp_scan_peer_qr_cb(wifi_manager_handle_s *wifi_handle,
1163                 net_dpp_event_info_s *dpp_event_info)
1164 {
1165         if (g_p_dpp_current)
1166                 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_URI_REQUESTED;
1167
1168         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1169                         WIFI_MANAGER_DPP_STATE_URI_REQUESTED);
1170 }
1171
1172 static void __dpp_network_id_cb(wifi_manager_handle_s *wifi_handle,
1173                 net_dpp_event_info_s *dpp_event_info)
1174 {
1175         if (g_p_dpp_current)
1176                 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_CONFIGURED;
1177
1178         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1179                         WIFI_MANAGER_DPP_STATE_CONFIGURED);
1180 }
1181
1182 static void __dpp_conf_sent_cb(wifi_manager_handle_s *wifi_handle,
1183                 net_dpp_event_info_s *dpp_event_info)
1184 {
1185         if (g_p_dpp_current)
1186                 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_CONFIGURING;
1187
1188         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1189                         WIFI_MANAGER_DPP_STATE_CONFIGURING);
1190 }
1191
1192 static void __dpp_conf_received_cb(wifi_manager_handle_s *wifi_handle,
1193                 net_dpp_event_info_s *dpp_event_info)
1194 {
1195         if (g_p_dpp_current)
1196                 g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_CONFIGURED;
1197
1198         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1199                         WIFI_MANAGER_DPP_STATE_CONFIGURED);
1200 }
1201
1202 static void __dpp_failed_cb(wifi_manager_handle_s *wifi_handle,
1203                 net_dpp_event_info_s *dpp_event_info)
1204 {
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;
1211         }
1212
1213         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_REQUEST_FAILED,
1214                         WIFI_MANAGER_DPP_STATE_NONE);
1215
1216         g_p_dpp_current = NULL;
1217 }
1218
1219 static void __dpp_removed_cb(wifi_manager_handle_s *wifi_handle,
1220                 net_dpp_event_info_s *dpp_event_info)
1221 {
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;
1228         }
1229
1230         __raise_dpp_event_callback(wifi_handle, WIFI_MANAGER_DPP_EVENT_STATE_CHANGED,
1231                         WIFI_MANAGER_DPP_STATE_NONE);
1232
1233         g_p_dpp_current = NULL;
1234 }
1235
1236 static void __roaming_state_changed_cb(wifi_manager_handle_s *wifi_handle,
1237                 net_roam_event_info_s *roam_event_info)
1238 {
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;
1243
1244         if (state) {
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;
1260                 }
1261         }
1262
1263         WIFI_LOG(WIFI_INFO, "Roaming state: %s, cur_bssid %s, dst_bssid %s",
1264                                                                                 state, cur_bssid, dst_bssid);
1265
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);
1269 }
1270 //LCOV_EXCL_STOP
1271
1272 static void _wifi_evt_cb(net_event_info_s *event_cb, void *user_data)
1273 {
1274         WIFI_LOCK;
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;
1279
1280         if (!__wifi_check_handle_validity(wifi_handle)) {
1281                 WIFI_LOG(WIFI_ERROR, "Wifi handle is not initialized");
1282                 WIFI_UNLOCK;
1283                 return;
1284         }
1285
1286         switch (event_cb->Event) {
1287         case NET_EVENT_OPEN_RSP:
1288         case NET_EVENT_WIFI_WPS_RSP:
1289                 is_requested = true;
1290                 /* fall through */
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) &&
1295                                 (event_cb->Error !=
1296                                  NET_ERR_CONNECTION_WPS_TIMEOUT) &&
1297                                 (event_cb->Error !=
1298                                  NET_ERR_CONNECTION_WPS_OVERLAP) &&
1299                                 (event_cb->Error !=
1300                                  NET_ERR_CONNECTION_WPS_WEP_PROHIBITED)) {
1301                         WIFI_UNLOCK;
1302                         return;
1303                 }
1304
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));
1308
1309                 if (is_requested)
1310                         __connected_cb(wifi_handle, result);
1311
1312                 switch (event_cb->Error) {
1313                 case NET_ERR_NONE:
1314                         if (event_cb->Datalength == sizeof(net_profile_info_s))
1315                                 prof_info_p = (net_profile_info_s *)event_cb->Data;
1316
1317                         __state_changed_cb(wifi_handle, event_cb->ProfileName, prof_info_p,
1318                                                         WIFI_MANAGER_CONNECTION_STATE_CONNECTED);
1319                         WIFI_UNLOCK;
1320                         return;
1321                 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
1322                         WIFI_UNLOCK;
1323                         return;
1324                 default:
1325                         if (event_cb->Datalength == sizeof(net_profile_info_s))
1326                                 prof_info_p = (net_profile_info_s *)event_cb->Data;
1327
1328                         __state_changed_cb(wifi_handle, event_cb->ProfileName, prof_info_p,
1329                                                         WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED);
1330
1331                         break;
1332                 }
1333
1334                 break;
1335         case NET_EVENT_CLOSE_RSP:
1336                 is_requested = true;
1337                 /* fall through */
1338         case NET_EVENT_CLOSE_IND:
1339                 if (_wifi_check_profile_name_validity(event_cb->ProfileName) != true) {
1340                         WIFI_UNLOCK;
1341                         return;
1342                 }
1343
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));
1347
1348                 if (is_requested)
1349                         __disconnected_cb(wifi_handle, result);
1350
1351                 switch (event_cb->Error) {
1352                 case NET_ERR_NONE:
1353                         if (event_cb->Datalength == sizeof(net_profile_info_s))
1354                                 prof_info_p = (net_profile_info_s *)event_cb->Data;
1355
1356                         __state_changed_cb(wifi_handle, event_cb->ProfileName, prof_info_p,
1357                                                         WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED);
1358
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;
1369                         }
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;
1381                         }
1382
1383                         WIFI_UNLOCK;
1384                         return;
1385                 default:
1386                         break;
1387                 }
1388
1389                 break;
1390         case NET_EVENT_NET_STATE_IND:
1391                 if (_wifi_check_profile_name_validity(event_cb->ProfileName) != true) {
1392                         WIFI_UNLOCK;
1393                         return;
1394                 }
1395
1396                 if (event_cb->Datalength != sizeof(net_profile_info_s)) {
1397                         WIFI_UNLOCK;
1398                         return;
1399                 }
1400
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);
1404
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);
1407
1408                 if (ap_state == WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED) {
1409                         net_profile_info_s *profile = NULL;
1410                         bool is_profile_exists = false;
1411
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;
1416                                         break;
1417                                 }
1418                         }
1419
1420                         if (is_profile_exists == false)
1421                                 prof_info_p = NULL;
1422                 }
1423
1424                 __state_changed_cb(wifi_handle, event_cb->ProfileName, prof_info_p, ap_state);
1425                 break;
1426         case NET_EVENT_WIFI_SCAN_RSP:
1427         case NET_EVENT_WIFI_SCAN_IND:
1428                 __scan_cb(wifi_handle, event_cb, is_requested);
1429                 break;
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);
1433                 break;
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);
1437                 break;
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);
1441                 break;
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
1445                 break;
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
1449                 break;
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);
1454                 break;
1455         case NET_EVENT_WIFI_POWER_RSP:
1456                 is_requested = true;
1457                 /* fall through */
1458         case NET_EVENT_WIFI_POWER_IND:
1459                 __power_on_off_cb(wifi_handle, event_cb, is_requested);
1460                 break;
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
1464                 break;
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
1468                 break;
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
1472                 break;
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
1476                 break;
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
1480                 break;
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
1484                 break;
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);
1488                 break;
1489         //LCOV_EXCL_START
1490         case NET_EVENT_WIFI_MODULE_STATE_CHANGED:
1491                 __module_state_changed_cb(wifi_handle, (net_module_info_s *)event_cb->Data);
1492                 break;
1493         case NET_EVENT_WIFI_DPP_URI_GENERATED:
1494                 __dpp_uri_generated_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1495                 break;
1496         case NET_EVENT_WIFI_DPP_BOOTSTRAPPED:
1497                 __dpp_bootstrapped_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1498                 break;
1499         case NET_EVENT_WIFI_DPP_AWAITING:
1500                 __dpp_awaiting_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1501                 break;
1502         case NET_EVENT_WIFI_DPP_AUTHENTICATING:
1503                 __dpp_authenticating_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1504                 break;
1505         case NET_EVENT_WIFI_DPP_AUTH_SUCCESS:
1506                 __dpp_auth_success_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1507                 break;
1508         case NET_EVENT_WIFI_DPP_AUTH_FAILED:
1509                 __dpp_auth_failed_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1510                 break;
1511         case NET_EVENT_WIFI_DPP_NOT_COMPATIBLE:
1512                 __dpp_not_compatible_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1513                 break;
1514         case NET_EVENT_WIFI_DPP_CONF_FAILED:
1515                 __dpp_conf_failed_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1516                 break;
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);
1519                 break;
1520         case NET_EVENT_WIFI_DPP_NETWORK_ID:
1521                 __dpp_network_id_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1522                 break;
1523         case NET_EVENT_WIFI_DPP_CONF_SENT:
1524                 __dpp_conf_sent_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1525                 break;
1526         case NET_EVENT_WIFI_DPP_CONF_RECEIVED:
1527                 __dpp_conf_received_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1528                 break;
1529         case NET_EVENT_WIFI_DPP_FAILED:
1530                 __dpp_failed_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1531                 break;
1532         case NET_EVENT_WIFI_DPP_REMOVED:
1533                 __dpp_removed_cb(wifi_handle, (net_dpp_event_info_s *)event_cb->Data);
1534                 break;
1535         case NET_EVENT_WIFI_ROAM_STATE_IND:
1536                 __roaming_state_changed_cb(wifi_handle, (net_roam_event_info_s *)event_cb->Data);
1537                 break;
1538         //LCOV_EXCL_STOP
1539         default:
1540                 break;
1541         }
1542
1543         WIFI_UNLOCK;
1544 }
1545
1546 int _wifi_init(wifi_manager_h wifi, const char *ifname)
1547 {
1548         int rv;
1549         wifi_manager_handle_s *wifi_handle = wifi;
1550
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
1556         }
1557
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;
1561
1562         return WIFI_MANAGER_ERROR_NONE;
1563 }
1564
1565 int _wifi_create_handle(wifi_manager_h *wifi)
1566 {
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
1571         }
1572
1573         pthread_mutex_init(&(wifi_handle->mutex_ap_handle_list), NULL);
1574         wifi_handle->random_mac_lifetime = 60; /* default value */
1575
1576         *wifi = wifi_handle;
1577
1578         WIFI_LOG(WIFI_INFO, "New handle create[%p]", *wifi);
1579
1580         return WIFI_MANAGER_ERROR_NONE;
1581 }
1582
1583 void _wifi_destroy_handle(wifi_manager_h wifi)
1584 {
1585         if (!wifi)
1586                 return;
1587
1588         wifi_manager_handle_s *wifi_handle = (wifi_manager_handle_s *)wifi;
1589         pthread_mutex_destroy(&(wifi_handle->mutex_ap_handle_list));
1590         g_free(wifi);
1591 }
1592
1593 void _wifi_add_to_handle_list(wifi_manager_h *wifi)
1594 {
1595         wifi_manager_handle_list = g_slist_append(wifi_manager_handle_list, *wifi);
1596 }
1597
1598 void _wifi_remove_from_handle_list(wifi_manager_h wifi)
1599 {
1600         wifi_manager_handle_list = g_slist_remove(wifi_manager_handle_list, wifi);
1601 }
1602
1603 int _wifi_length_from_handle_list(void)
1604 {
1605         return g_slist_length(wifi_manager_handle_list);
1606 }
1607
1608 bool _wifi_find_from_handle_list(wifi_manager_h wifi)
1609 {
1610         if (g_slist_find(wifi_manager_handle_list, wifi) != NULL)
1611                 return true;
1612         else
1613                 return false;
1614 }
1615
1616 bool _wifi_find_network_info_from_handle_list(network_info_s *network_info)
1617 {
1618         GSList *list = NULL;
1619
1620         for (list = wifi_manager_handle_list; list; list = list->next) {
1621                 wifi_manager_handle_s *wifi_handle = list->data;
1622
1623                 if (wifi_handle->network_info == network_info)
1624                         return true;
1625         }
1626
1627         return false;
1628 }
1629
1630 void config_free(gpointer data)
1631 {
1632         wifi_config_s *h = (wifi_config_s *)data;
1633         g_free(h->name);
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);
1645         }
1646         if (h->ip_info) {
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]);
1652         }
1653         g_free(h);
1654 }
1655
1656 void __clear_config_list(GSList **iterator)
1657 {
1658         if (*iterator) {
1659                 g_slist_free_full(*iterator, config_free);
1660                 *iterator = NULL;
1661         }
1662 }
1663
1664 //LCOV_EXCL_START
1665 static void __free_dpp(gpointer data)
1666 {
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);
1672         g_free(p_dpp);
1673 }
1674 //LCOV_EXCL_STOP
1675
1676 static void _wifi_ap_handle_list_lock(wifi_manager_handle_s *wifi)
1677 {
1678         if (!wifi)
1679                 return;
1680
1681         int ret = pthread_mutex_lock(&(wifi->mutex_ap_handle_list));
1682         if (ret < 0)
1683                 WIFI_LOG(WIFI_ERROR, "Failed to lock the ap_handle_list[%d]", ret);
1684 }
1685
1686 static void _wifi_ap_handle_list_unlock(wifi_manager_handle_s *wifi)
1687 {
1688         if (!wifi)
1689                 return;
1690
1691         int ret = pthread_mutex_unlock(&(wifi->mutex_ap_handle_list));
1692         if (ret < 0)
1693                 WIFI_LOG(WIFI_ERROR, "Failed to unlock the ap_handle_list[%d]", ret);
1694 }
1695
1696 void _wifi_deinit(wifi_manager_h wifi)
1697 {
1698         wifi_manager_handle_s *wifi_handle = wifi;
1699
1700         net_deregister_client_ext(wifi_handle->network_info);
1701
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);
1705
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));
1709
1710         __clear_config_list(&(wifi_handle->config_handle_list));
1711         __clear_config_list(&(wifi_handle->config_iterator));
1712 }
1713
1714 void _wifi_clear_profile_list(void)
1715 {
1716         g_slist_free_full(dpp_handle_list, __free_dpp);
1717         g_p_dpp_current = NULL;
1718 }
1719
1720 //LCOV_EXCL_START
1721 void _wifi_set_cs_tid(wifi_manager_h wifi, int tid)
1722 {
1723         wifi_manager_handle_s *wifi_handle = wifi;
1724
1725         net_set_cs_tid(wifi_handle->network_info, tid);
1726 }
1727
1728 void _wifi_unset_cs_tid(int tid)
1729 {
1730         net_unset_cs_tid(tid);
1731 }
1732 //LCOV_EXCL_STOP
1733
1734 int _wifi_activate(wifi_manager_h wifi, wifi_manager_activated_cb callback,
1735                 gboolean wifi_picker_test, void *user_data)
1736 {
1737         int rv = NET_ERR_NONE;
1738         wifi_manager_handle_s *wifi_handle = wifi;
1739
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);
1744
1745         return rv;
1746 }
1747
1748 int _wifi_deactivate(wifi_manager_h wifi, wifi_manager_deactivated_cb callback, void *user_data)
1749 {
1750         int rv = NET_ERR_NONE;
1751         wifi_manager_handle_s *wifi_handle = wifi;
1752
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);
1757
1758         return rv;
1759 }
1760
1761 int _wifi_get_mac_address(wifi_manager_h wifi, char **mac_address)
1762 {
1763         FILE *fp = NULL;
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;
1767
1768         g_snprintf(mac_path, WIFI_MAC_ADDR_PATH_LEN, WIFI_MAC_ADDR_PATH, wifi_handle->interface_name);
1769
1770         if (access(mac_path, F_OK) == 0)
1771                 fp = fopen(mac_path, "r");
1772
1773         if (fp) {
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
1778                 }
1779
1780                 WIFI_LOG(WIFI_INFO, "%s : %s", mac_path, buf);
1781
1782                 *mac_address = g_strdup(buf);
1783                 fclose(fp);
1784         } else {
1785                 *mac_address = _net_vconf_get_str(wifi_handle->network_info, VCONFKEY_WIFI_BSSID_ADDRESS);
1786
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
1792                 }
1793
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
1801                 }
1802         }
1803
1804         return WIFI_MANAGER_ERROR_NONE;
1805 }
1806
1807 int _wifi_ip_conflict_detect_enable_set(wifi_manager_h wifi, bool detect)
1808 {
1809         int rv = NET_ERR_NONE;
1810         wifi_manager_handle_s *wifi_handle = wifi;
1811
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;
1820         }
1821
1822         return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1823 }
1824
1825 bool _wifi_check_ap_validity(net_profile_info_s *ap_info)
1826 {
1827         if (ap_info == NULL)
1828                 return false;
1829
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)
1834                         return false;
1835
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);
1839                         return true;
1840                 }
1841                 _wifi_ap_handle_list_unlock(wifi_handle);
1842
1843                 if (g_slist_find(wifi_handle->profile_iterator, ap_info) != NULL)
1844                         return true;
1845
1846                 if (g_slist_find(wifi_handle->specific_profile_iterator, ap_info) != NULL)
1847                         return true;
1848
1849                 if (g_slist_find(wifi_handle->bss_profile_iterator, ap_info) != NULL)
1850                         return true;
1851         }
1852
1853         return false;
1854 }
1855
1856 void _wifi_add_to_ap_list(net_profile_info_s *ap_info)
1857 {
1858         network_info_s *network_info;
1859         wifi_manager_handle_s *wifi_handle;
1860
1861         network_info = ap_info->network_info;
1862         if (network_info == NULL)
1863                 return;
1864
1865         wifi_handle = network_info->wifi_handle;
1866         if (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);
1871         }
1872 }
1873
1874 void _wifi_remove_from_ap_list(net_profile_info_s *ap_info)
1875 {
1876         network_info_s *network_info;
1877         wifi_manager_handle_s *wifi_handle;
1878
1879         network_info = ap_info->network_info;
1880         if (network_info == NULL)
1881                 return;
1882
1883         wifi_handle = network_info->wifi_handle;
1884         if (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);
1889         }
1890 }
1891
1892 bool _wifi_check_profile_name_validity(const char *profile_name)
1893 {
1894         const char *profile_prefix = "/net/connman/service/wifi_";
1895         int i = 0;
1896
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");
1900                 return false;
1901         }
1902
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
1907                 }
1908                 i++;
1909         }
1910
1911         return true;
1912 }
1913
1914 bool _wifi_check_essid_validity(const char *essid)
1915 {
1916         int essid_len = 0;
1917
1918         if (essid == NULL)
1919                 return false;
1920
1921         essid_len = strlen(essid);
1922
1923         if (essid_len < 1 || essid_len > 32)
1924                 return false;
1925
1926         if (!g_utf8_validate(essid, -1, NULL))
1927                 return false;
1928
1929         return true;
1930 }
1931
1932 int _wifi_get_wifi_device_state(wifi_manager_h wifi, wifi_manager_device_state_e *device_state)
1933 {
1934         net_tech_info_s tech_info;
1935         wifi_manager_handle_s *wifi_handle = wifi;
1936
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
1945         }
1946
1947         if (tech_info.powered)
1948                 *device_state = WIFI_MANAGER_DEVICE_STATE_ACTIVATED;
1949         else
1950                 *device_state = WIFI_MANAGER_DEVICE_STATE_DEACTIVATED;
1951
1952         return WIFI_MANAGER_ERROR_NONE;
1953 }
1954
1955 int _wifi_get_wifi_state(wifi_manager_h wifi, wifi_manager_connection_state_e *connection_state)
1956 {
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;
1960
1961         tech_state = net_get_technology_state(wifi_handle->network_info);
1962         service_state = _wifi_get_service_state(wifi_handle);
1963
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;
1972         else {
1973                 switch (service_state) {
1974                 case WIFI_SERVICE_STATE_ASSOCIATION:
1975                         *connection_state = WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION;
1976                         break;
1977                 case WIFI_SERVICE_STATE_CONFIGURATION:
1978                         *connection_state = WIFI_MANAGER_CONNECTION_STATE_CONFIGURATION;
1979                         break;
1980                 case WIFI_SERVICE_STATE_CONNECTED:
1981                         *connection_state = WIFI_MANAGER_CONNECTION_STATE_CONNECTED;
1982                         break;
1983                 case WIFI_SERVICE_STATE_UNKNOWN:
1984                 case WIFI_SERVICE_STATE_FAILURE:
1985                 case WIFI_SERVICE_STATE_IDLE:
1986                 default:
1987                         *connection_state = WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED;
1988                 }
1989         }
1990         /* LCOV_EXCL_STOP */
1991
1992         return WIFI_MANAGER_ERROR_NONE;
1993 }
1994
1995 void _wifi_get_intf_name(wifi_manager_h wifi, char **name)
1996 {
1997         wifi_manager_handle_s *wifi_handle = wifi;
1998
1999         *name = g_strdup(wifi_handle->interface_name);
2000 }
2001
2002 int _wifi_ip_conflict_detect_is_enabled(wifi_manager_h wifi, bool *state)
2003 {
2004         int rv;
2005         gboolean is_enabled = FALSE;
2006         wifi_manager_handle_s *wifi_handle = wifi;
2007
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;
2015         }
2016
2017         return WIFI_MANAGER_ERROR_NONE;
2018 }
2019
2020 int _wifi_scan_request(wifi_manager_h wifi,
2021                 wifi_manager_scan_finished_cb callback, void *user_data)
2022 {
2023         int rv;
2024         wifi_manager_handle_s *wifi_handle = wifi;
2025
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;
2035         }
2036
2037         return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2038 }
2039
2040 int _wifi_get_scan_state(wifi_manager_h wifi, wifi_manager_scan_state_e *scan_state)
2041 {
2042         int rv;
2043         int state = 0;
2044         wifi_manager_handle_s *wifi_handle = wifi;
2045
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;
2055         }
2056
2057         return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2058 }
2059
2060 int _wifi_scan_specific_ap(wifi_manager_h wifi, const char *essid,
2061                                                         wifi_manager_scan_finished_cb callback, void *user_data)
2062 {
2063         int rv;
2064         wifi_manager_handle_s *wifi_handle = wifi;
2065
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;
2076         }
2077
2078         return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2079 }
2080
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)
2084 {
2085         int rv;
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;
2090         GSList *list;
2091
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
2096         }
2097
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
2101         }
2102
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;
2106
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;
2112                         break;
2113                 case WLAN_SEC_MODE_WEP:
2114                         type = WIFI_MANAGER_SECURITY_TYPE_WEP;
2115                         break;
2116                 case WLAN_SEC_MODE_IEEE8021X:
2117                         type = WIFI_MANAGER_SECURITY_TYPE_EAP;
2118                         break;
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;
2123                         break;
2124                 case WLAN_SEC_MODE_SAE:
2125                         type = WIFI_MANAGER_SECURITY_TYPE_SAE;
2126                         break;
2127                 case WLAN_SEC_MODE_OWE:
2128                         type = WIFI_MANAGER_SECURITY_TYPE_OWE;
2129                         break;
2130                 case WLAN_SEC_MODE_DPP:
2131                         type = WIFI_MANAGER_SECURITY_TYPE_DPP;
2132                         break;
2133                 }
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;
2140                         }
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,
2144                                                                    passphrase);
2145                         if (rv != WIFI_MANAGER_ERROR_NONE)
2146                                 return rv;
2147                         return _wifi_open_profile(wifi, (wifi_manager_ap_h)prof_info,
2148                                                           callback, user_data);
2149                 }
2150         }
2151
2152         if (is_available == false) {
2153                 WIFI_LOG(WIFI_INFO, "No hidden profiles found");
2154                 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
2155         }
2156
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);
2161                 break;
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);
2166                 break;
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);
2170                 break;
2171         case WLAN_SEC_MODE_NONE:
2172         case WLAN_SEC_MODE_OWE:
2173                 break;
2174         case WLAN_SEC_MODE_IEEE8021X:
2175         default:
2176                 WIFI_LOG(WIFI_INFO, "Invalid security type"); //LCOV_EXCL_LINE
2177                 return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2178         }
2179
2180         g_strlcpy(profile_info->essid, essid, NET_WLAN_ESSID_LEN+1);
2181
2182         return _wifi_open_profile(wifi, profile_info, callback, user_data);
2183 }
2184
2185 int _wifi_bssid_scan_request(wifi_manager_h wifi,
2186                 wifi_manager_bssid_scan_finished_cb callback, void *user_data)
2187 {
2188         int rv;
2189         wifi_manager_device_state_e device_state;
2190         wifi_manager_handle_s *wifi_handle = wifi;
2191         int activated = -1;
2192         int flight_mode = -1;
2193
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
2197         }
2198
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)
2202                         activated = 0;
2203                 else
2204                         activated = 1;
2205         }
2206
2207         WIFI_LOG(WIFI_INFO, "Activated: %d, flight mode: %d", activated, flight_mode);
2208
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
2212         }
2213
2214         rv = net_bssid_scan_wifi(wifi_handle->network_info, activated);
2215
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;
2224         }
2225
2226         WIFI_LOG(WIFI_ERROR, "Operation Failed"); //LCOV_EXCL_LINE
2227         return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2228 }
2229
2230 //LCOV_EXCL_START
2231 bool _wifi_check_netlink_scan_validity(wifi_manager_netlink_scan_h netlink_scan)
2232 {
2233         GSList *list = NULL;
2234
2235         if (netlink_scan == NULL)
2236                 return false;
2237
2238         for (list = netlink_scan_handle_list; list; list = list->next)
2239                 if (netlink_scan == list->data) return true;
2240
2241         return false;
2242 }
2243
2244 void _wifi_add_to_netlink_scan_list(wifi_manager_netlink_scan_h *netlink_scan)
2245 {
2246         netlink_scan_handle_list = g_slist_append(netlink_scan_handle_list, *netlink_scan);
2247 }
2248
2249 int _wifi_netlink_scan_create(wifi_manager_netlink_scan_h *netlink_scan)
2250 {
2251         *netlink_scan = g_try_malloc0(sizeof(wifi_netlink_scan_s));
2252
2253         if (*netlink_scan == NULL) {
2254                 WIFI_LOG(WIFI_ERROR, "Failed to create netlink scan handle");
2255                 return WIFI_MANAGER_ERROR_OUT_OF_MEMORY;
2256         }
2257
2258         WIFI_LOG(WIFI_INFO, "New netlink scan handle[%p]", *netlink_scan);
2259         return WIFI_MANAGER_ERROR_NONE;
2260 }
2261
2262 void _wifi_remove_from_netlink_scan_list(wifi_manager_netlink_scan_h netlink_scan)
2263 {
2264         wifi_netlink_scan_s *list = (wifi_netlink_scan_s *)netlink_scan;
2265         if (list->ssids)
2266                 g_slist_free_full(list->ssids, g_free);
2267
2268         netlink_scan_handle_list = g_slist_remove(netlink_scan_handle_list, netlink_scan);
2269         g_free(netlink_scan);
2270 }
2271
2272 void _wifi_netlink_scan_set_ssid(wifi_manager_netlink_scan_h netlink_scan,
2273                 const char *essid)
2274 {
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));
2277
2278         netlink_scan = (wifi_manager_netlink_scan_h)nl_scan;
2279 }
2280
2281 void _wifi_netlink_scan_set_vsie(wifi_manager_netlink_scan_h netlink_scan,
2282                 const char *vsie)
2283 {
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);
2286
2287         netlink_scan = (wifi_manager_netlink_scan_h)nl_scan;
2288 }
2289
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)
2292 {
2293         int rv;
2294         bool enable;
2295         int is_on = 0;
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;
2299
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;
2306         }
2307
2308         enable = (is_on & vconf_type) ? true : false;
2309
2310         if (enable == false) {
2311                 WIFI_LOG(WIFI_ERROR, "SoftAP is not enabled");
2312                 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
2313         }
2314
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;
2324         }
2325
2326         WIFI_LOG(WIFI_ERROR, "Operation Failed");
2327         return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2328 }
2329
2330 int _wifi_add_vsie(wifi_manager_h wifi, wifi_manager_vsie_frames_e frame_id, const char *vsie_str)
2331 {
2332         int rv;
2333         net_vsie_frames_e f_id;
2334         wifi_manager_handle_s *wifi_handle = wifi;
2335
2336         switch (frame_id) {
2337         case WIFI_MANAGER_VSIE_FRAME_ASSOC_REQ:
2338                 f_id = NET_VSIE_FRAME_ASSOC_REQ;
2339                 break;
2340         case WIFI_MANAGER_VSIE_FRAME_PROBE_REQ:
2341                 f_id = NET_VSIE_FRAME_PROBE_REQ;
2342                 break;
2343         case WIFI_MANAGER_VSIE_FRAME_REASSOC:
2344                 f_id = NET_VSIE_FRAME_REASSOC;
2345                 break;
2346         case WIFI_MANAGER_VSIE_FRAME_AUTH_REQ:
2347                 f_id = NET_VSIE_FRAME_AUTH_REQ;
2348                 break;
2349         case WIFI_MANAGER_VSIE_FRAME_ACTION:
2350                 f_id = NET_VSIE_FRAME_ACTION;
2351                 break;
2352         default:
2353                 WIFI_LOG(WIFI_ERROR, "Frame ID: [%d] not supported.", frame_id);
2354                 return WIFI_MANAGER_ERROR_NOT_SUPPORTED;
2355         }
2356
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;
2365         }
2366
2367         WIFI_LOG(WIFI_ERROR, "Operation Failed");
2368         return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2369 }
2370
2371 int _wifi_get_vsie(wifi_manager_h wifi, wifi_manager_vsie_frames_e frame_id, char **vsie_str)
2372 {
2373         int rv;
2374         net_vsie_frames_e f_id;
2375         wifi_manager_handle_s *wifi_handle = wifi;
2376
2377         switch (frame_id) {
2378         case WIFI_MANAGER_VSIE_FRAME_ASSOC_REQ:
2379                 f_id = NET_VSIE_FRAME_ASSOC_REQ;
2380                 break;
2381         case WIFI_MANAGER_VSIE_FRAME_PROBE_REQ:
2382                 f_id = NET_VSIE_FRAME_PROBE_REQ;
2383                 break;
2384         case WIFI_MANAGER_VSIE_FRAME_REASSOC:
2385                 f_id = NET_VSIE_FRAME_REASSOC;
2386                 break;
2387         case WIFI_MANAGER_VSIE_FRAME_AUTH_REQ:
2388                 f_id = NET_VSIE_FRAME_AUTH_REQ;
2389                 break;
2390         case WIFI_MANAGER_VSIE_FRAME_ACTION:
2391                 f_id = NET_VSIE_FRAME_ACTION;
2392                 break;
2393         default:
2394                 WIFI_LOG(WIFI_ERROR, "Frame ID: [%d] not supported.", frame_id);
2395                 return WIFI_MANAGER_ERROR_NOT_SUPPORTED;
2396         }
2397
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;
2406         }
2407
2408         WIFI_LOG(WIFI_ERROR, "Operation Failed");
2409         return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2410 }
2411
2412 int _wifi_remove_vsie(wifi_manager_h wifi, wifi_manager_vsie_frames_e frame_id, const char *vsie_str)
2413 {
2414         int rv;
2415         net_vsie_frames_e f_id;
2416         wifi_manager_handle_s *wifi_handle = wifi;
2417
2418         switch (frame_id) {
2419         case WIFI_MANAGER_VSIE_FRAME_ASSOC_REQ:
2420                 f_id = NET_VSIE_FRAME_ASSOC_REQ;
2421                 break;
2422         case WIFI_MANAGER_VSIE_FRAME_PROBE_REQ:
2423                 f_id = NET_VSIE_FRAME_PROBE_REQ;
2424                 break;
2425         case WIFI_MANAGER_VSIE_FRAME_REASSOC:
2426                 f_id = NET_VSIE_FRAME_REASSOC;
2427                 break;
2428         case WIFI_MANAGER_VSIE_FRAME_AUTH_REQ:
2429                 f_id = NET_VSIE_FRAME_AUTH_REQ;
2430                 break;
2431         case WIFI_MANAGER_VSIE_FRAME_ACTION:
2432                 f_id = NET_VSIE_FRAME_ACTION;
2433                 break;
2434         default:
2435                 WIFI_LOG(WIFI_ERROR, "Frame ID: [%d] not supported.", frame_id);
2436                 return WIFI_MANAGER_ERROR_NOT_SUPPORTED;
2437         }
2438
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;
2447         }
2448
2449         WIFI_LOG(WIFI_ERROR, "Operation Failed");
2450         return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2451 }
2452
2453 int _wifi_flush_bss(wifi_manager_h wifi)
2454 {
2455         int rv;
2456         wifi_manager_handle_s *wifi_handle = wifi;
2457
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;
2462         }
2463
2464         return WIFI_MANAGER_ERROR_NONE;
2465 }
2466
2467 int _wifi_set_bssid(wifi_manager_h wifi, char *bssid)
2468 {
2469         int rv;
2470         wifi_manager_handle_s *wifi_handle = wifi;
2471
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;
2476         }
2477
2478         return WIFI_MANAGER_ERROR_NONE;
2479 }
2480
2481 int _wifi_set_auto_connect(wifi_manager_h wifi, int connect_mode)
2482 {
2483         int rv;
2484         wifi_manager_handle_s *wifi_handle = wifi;
2485
2486         rv = net_wifi_set_auto_connect_mode(wifi_handle->network_info, connect_mode);
2487
2488         if (rv != NET_ERR_NONE)
2489                 WIFI_LOG(WIFI_ERROR, "Failed to set auto connection mode");
2490
2491         return rv;
2492 }
2493
2494 int _wifi_get_auto_connect(wifi_manager_h wifi, int *connect_mode)
2495 {
2496         int rv;
2497         wifi_manager_handle_s *wifi_handle = wifi;
2498
2499         rv = net_wifi_get_auto_connect_mode(wifi_handle->network_info, connect_mode);
2500
2501         if (rv != NET_ERR_NONE)
2502                 WIFI_LOG(WIFI_ERROR, "Failed to get auto connection mode");
2503
2504         return rv;
2505 }
2506
2507 int _wifi_get_5ghz_support(wifi_manager_h wifi, bool *supported)
2508 {
2509         int rv;
2510         wifi_manager_handle_s *wifi_handle = wifi;
2511         gboolean is_supported = FALSE;
2512
2513         rv = net_wifi_get_5ghz_support(wifi_handle->network_info, &is_supported);
2514
2515         if (rv != NET_ERR_NONE)
2516                 WIFI_LOG(WIFI_ERROR, "Failed to get 5 Ghz supported");
2517
2518         *supported = is_supported;
2519         return rv;
2520 }
2521
2522
2523 int _wifi_set_ap_auto_connect(wifi_manager_ap_h ap, bool autoconnect)
2524 {
2525         int rv = 0;
2526         net_profile_info_s *ap_info = ap;
2527
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;
2536         }
2537
2538         return WIFI_MANAGER_ERROR_NONE;
2539 }
2540
2541 int _wifi_get_ap_auto_connect(wifi_manager_ap_h ap, bool *autoconnect)
2542 {
2543         int rv = 0;
2544         gboolean auto_connect = FALSE;
2545         net_profile_info_s *ap_info = ap;
2546
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;
2555         }
2556
2557         *autoconnect = auto_connect;
2558         return WIFI_MANAGER_ERROR_NONE;
2559 }
2560 //LCOV_EXCL_STOP
2561
2562 int _wifi_get_connected_profile(wifi_manager_h wifi, wifi_manager_ap_h *ap)
2563 {
2564         int rv;
2565         wifi_manager_handle_s *wifi_handle = wifi;
2566         net_profile_info_s *ap_info = NULL;
2567         const char *ifname = wifi_handle->interface_name;
2568
2569         ap_info = g_try_malloc0(sizeof(net_profile_info_s));
2570         if (ap_info == NULL)
2571                 return WIFI_MANAGER_ERROR_OUT_OF_MEMORY;
2572
2573         rv = net_get_connected_profile(wifi_handle->network_info, ifname, ap_info);
2574         if (rv != NET_ERR_NONE) {
2575                 g_free(ap_info);
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
2583                 else
2584                         return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
2585         }
2586
2587         _wifi_add_to_ap_list(ap_info);
2588         *ap = (wifi_manager_ap_h)ap_info;
2589
2590         return WIFI_MANAGER_ERROR_NONE;
2591 }
2592
2593 //LCOV_EXCL_START
2594 int _wifi_foreach_available_interface(wifi_manager_h wifi,
2595                 wifi_manager_interface_cb callback, void *user_data)
2596 {
2597         int rv;
2598         GSList *list;
2599         wifi_manager_handle_s *wifi_handle = wifi;
2600
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
2605         }
2606
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
2610         }
2611
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;
2616         }
2617
2618         return WIFI_MANAGER_ERROR_NONE;
2619 }
2620 //LCOV_EXCL_STOP
2621
2622 int _wifi_foreach_found_ap(wifi_manager_h wifi,
2623                 wifi_manager_found_ap_cb callback, void *user_data)
2624 {
2625         int rv;
2626         GSList *list;
2627         wifi_manager_handle_s *wifi_handle = wifi;
2628
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
2633         }
2634
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
2638         }
2639
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)
2644                                 continue;
2645
2646                         rv = callback((wifi_manager_ap_h)prof_info, user_data);
2647                         if (rv == false) break;
2648                 }
2649         }
2650
2651         return WIFI_MANAGER_ERROR_NONE;
2652 }
2653
2654 //LCOV_EXCL_START
2655 int _wifi_foreach_found_ap_in_all_interfaces(wifi_manager_h wifi,
2656                 wifi_manager_found_ap_cb callback, void *user_data)
2657 {
2658         int rv;
2659         GSList *list;
2660         wifi_manager_handle_s *wifi_handle = wifi;
2661
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
2666         }
2667
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
2671         }
2672
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)
2676                         continue;
2677
2678                 rv = callback((wifi_manager_ap_h)prof_info, user_data);
2679                 if (rv == false) break;
2680         }
2681
2682         return WIFI_MANAGER_ERROR_NONE;
2683 }
2684 //LCOV_EXCL_STOP
2685
2686 int _wifi_foreach_found_specific_ap(wifi_manager_h wifi,
2687                 wifi_manager_found_ap_cb callback, void *user_data)
2688 {
2689         int rv;
2690         GSList *list;
2691         wifi_manager_handle_s *wifi_handle = wifi;
2692
2693         if ((int)g_slist_length(wifi_handle->specific_profile_iterator) == 0) {
2694                 WIFI_LOG(WIFI_WARN, "There is no specific APs");
2695
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
2700                 }
2701
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
2705                 }
2706
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;
2712                         }
2713                 }
2714
2715                 return WIFI_MANAGER_ERROR_NONE;
2716         }
2717
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;
2722         }
2723
2724         return WIFI_MANAGER_ERROR_NONE;
2725 }
2726
2727 int _wifi_foreach_found_bssid_ap(wifi_manager_h wifi,
2728                 wifi_manager_found_ap_cb callback, void *user_data)
2729 {
2730         int rv;
2731         GSList *list;
2732         wifi_manager_handle_s *wifi_handle = wifi;
2733
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;
2738         }
2739
2740         return WIFI_MANAGER_ERROR_NONE;
2741 }
2742
2743 //LCOV_EXCL_START
2744 int _wifi_foreach_found_netlink_scan_ap(wifi_manager_h wifi,
2745                 wifi_manager_found_ap_cb callback, void *user_data)
2746 {
2747         int rv;
2748         GSList *list;
2749         wifi_manager_handle_s *wifi_handle = wifi;
2750
2751         if (wifi_handle->bss_profile_iterator == NULL) {
2752                 WIFI_LOG(WIFI_ERROR, "Failed to search APs");
2753                 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
2754         }
2755
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;
2760         }
2761
2762         __clear_profile_list(&(wifi_handle->bss_profile_iterator));
2763
2764         return WIFI_MANAGER_ERROR_NONE;
2765 }
2766 //LCOV_EXCL_STOP
2767
2768 int _wifi_open_profile(wifi_manager_h wifi, wifi_manager_ap_h ap_h,
2769                 wifi_manager_connected_cb callback, void *user_data)
2770 {
2771         int rv;
2772         bool valid_profile;
2773         net_profile_info_s *ap_info = ap_h;
2774         wifi_manager_handle_s *wifi_handle = wifi;
2775
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);
2783         else
2784                 rv = __connect_with_wifi_info(wifi_handle, ap_info);
2785
2786         rv = __convert_to_ap_error_type(rv);
2787         if (rv == WIFI_MANAGER_ERROR_NONE)
2788                 __set_connected_cb(wifi_handle, callback, user_data);
2789
2790         return rv;
2791 }
2792
2793 int _wifi_close_profile(wifi_manager_h wifi, wifi_manager_ap_h ap_h,
2794                 wifi_manager_disconnected_cb callback, void *user_data)
2795 {
2796         int rv;
2797         net_profile_info_s *ap_info = ap_h;
2798         wifi_manager_handle_s *wifi_handle = wifi;
2799
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
2806         }
2807
2808         __set_disconnected_cb(wifi_handle, callback, user_data);
2809
2810         return WIFI_MANAGER_ERROR_NONE;
2811 }
2812
2813 //LCOV_EXCL_START
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)
2816 {
2817         int rv;
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));
2822
2823         wps_info.type = WIFI_WPS_PBC;
2824
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);
2828
2829         __set_connected_cb(wifi_handle, callback, user_data);
2830
2831         return WIFI_MANAGER_ERROR_NONE;
2832 }
2833
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)
2836 {
2837         int rv;
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;
2841
2842         if (ap_info == NULL) {
2843                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
2844                 return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
2845         }
2846
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);
2850
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);
2854
2855         __set_connected_cb(wifi_handle, callback, user_data);
2856
2857         return WIFI_MANAGER_ERROR_NONE;
2858 }
2859 //LCOV_EXCL_STOP
2860
2861 int _wifi_forget_ap(wifi_manager_h wifi, wifi_manager_ap_h ap)
2862 {
2863         int rv = 0;
2864         wifi_manager_handle_s *wifi_handle = wifi;
2865         net_profile_info_s *ap_info = ap;
2866
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
2870         }
2871
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
2878         }
2879
2880         ap_info->Favourite = (char)FALSE;
2881
2882         return WIFI_MANAGER_ERROR_NONE;
2883 }
2884
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)
2887 {
2888         int rv = 0;
2889         wifi_manager_handle_s *wifi_handle = wifi;
2890         net_profile_info_s *ap_info = ap;
2891
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
2895         }
2896
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
2903         }
2904
2905         ap_info->Favourite = (char)FALSE;
2906         __set_forget_ap_cb(wifi_handle, callback, user_data);
2907
2908         return WIFI_MANAGER_ERROR_NONE;
2909 }
2910
2911 //LCOV_EXCL_START
2912 int _wifi_update_ap_info(wifi_manager_h wifi, net_profile_info_s *ap_info)
2913 {
2914         int rv = NET_ERR_NONE;
2915         wifi_manager_handle_s *wifi_handle = wifi;
2916
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
2926         }
2927
2928         return WIFI_MANAGER_ERROR_NONE;
2929 }
2930
2931 int _wifi_connect_with_wps_pbc_without_ssid(wifi_manager_h wifi,
2932                 wifi_manager_connected_cb callback, void *user_data)
2933 {
2934         int rv;
2935         wifi_manager_handle_s *wifi_handle = wifi;
2936         net_wifi_wps_info_s wps_info;
2937         net_profile_info_s *profile = NULL;
2938         GSList *list;
2939
2940         memset(&wps_info, 0, sizeof(net_wifi_wps_info_s));
2941
2942         wps_info.type = WIFI_WPS_PBC;
2943
2944         WIFI_LOG(WIFI_INFO, "start");
2945
2946         /* Disconnect if already connected to an AP */
2947         __update_profile_iterator(wifi_handle);
2948
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);
2958
2959                         wifi_handle->is_disconnect_wps_pbc = true;
2960                 }
2961         }
2962
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);
2967         }
2968
2969         __set_connected_cb(wifi_handle, callback, user_data);
2970
2971         return WIFI_MANAGER_ERROR_NONE;
2972 }
2973
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)
2976 {
2977         int rv;
2978         wifi_manager_handle_s *wifi_handle = wifi;
2979         net_wifi_wps_info_s wps_info;
2980         net_profile_info_s *profile = NULL;
2981         GSList *list;
2982
2983         memset(&wps_info, 0, sizeof(net_wifi_wps_info_s));
2984
2985         wps_info.type = WIFI_WPS_PIN;
2986         g_strlcpy(wps_info.pin, pin, NET_WLAN_MAX_WPSPIN_LEN + 1);
2987
2988         WIFI_LOG(WIFI_INFO, "pin: %s", pin);
2989
2990         /* Disconnect if already connected to an AP */
2991         __update_profile_iterator(wifi_handle);
2992
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;
3004                 }
3005         }
3006
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);
3011         }
3012
3013         __set_connected_cb(wifi_handle, callback, user_data);
3014
3015         return WIFI_MANAGER_ERROR_NONE;
3016 }
3017
3018 int _wifi_cancel_wps(wifi_manager_h wifi)
3019 {
3020         int rv;
3021         wifi_manager_handle_s *wifi_handle = wifi;
3022
3023         rv = net_wifi_cancel_wps(wifi_handle->network_info);
3024         if (rv != NET_ERR_NONE)
3025                 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
3026
3027         __connected_cb(wifi_handle, WIFI_MANAGER_ERROR_OPERATION_ABORTED);
3028
3029         return WIFI_MANAGER_ERROR_NONE;
3030 }
3031 //LCOV_EXCL_STOP
3032
3033 bool _wifi_check_config_validity(wifi_config_s *config)
3034 {
3035         wifi_manager_handle_s *wifi_handle;
3036
3037         if (config == NULL)
3038                 return false;
3039
3040         wifi_handle = config->wifi_handle;
3041         if (wifi_handle == NULL)
3042                 return false;
3043
3044         if (_wifi_find_from_handle_list(wifi_handle) == false)
3045                 return false;
3046
3047         if (g_slist_find(wifi_handle->config_handle_list, config) != NULL)
3048                 return true;
3049
3050         if (g_slist_find(wifi_handle->config_iterator, config) != NULL)
3051                 return true;
3052
3053         return false;
3054 }
3055
3056 void _wifi_add_to_config_list(wifi_config_s *config)
3057 {
3058         wifi_manager_handle_s *wifi_handle = config->wifi_handle;
3059
3060         if (wifi_handle) {
3061                 wifi_handle->config_handle_list =
3062                         g_slist_append(wifi_handle->config_handle_list, config);
3063         }
3064 }
3065
3066 void _wifi_remove_from_config_list(wifi_config_s *config)
3067 {
3068         wifi_manager_handle_s *wifi_handle = config->wifi_handle;
3069
3070         if (wifi_handle) {
3071                 wifi_handle->config_handle_list =
3072                         g_slist_remove(wifi_handle->config_handle_list, config);
3073         }
3074 }
3075
3076 gchar *_wifi_config_get_config_id(const gchar *name, wifi_manager_security_type_e security_type)
3077 {
3078         gchar *config_id = NULL;
3079         gchar *ssid = NULL;
3080         gchar *type = NULL;
3081
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);
3085
3086         g_free(ssid);
3087         g_free(type);
3088
3089         return config_id;
3090 }
3091
3092 int _wifi_config_get_config_id_list(wifi_manager_h wifi, GSList **list)
3093 {
3094         int rv;
3095         wifi_manager_handle_s *wifi_handle = wifi;
3096
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
3106         }
3107
3108         return WIFI_MANAGER_ERROR_NONE;
3109 }
3110
3111 void destroy_wifi_config(wifi_config_s *h)
3112 {
3113         //LCOV_EXCL_START
3114         int i;
3115
3116         g_free(h->name);
3117         g_free(h->passphrase);
3118         g_free(h->proxy_address);
3119
3120         if (h->ip_info) {
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]);
3126                 g_free(h->ip_info);
3127         }
3128
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);
3138         }
3139
3140         g_free(h);
3141         //LCOV_EXCL_STOP
3142 }
3143
3144 int _wifi_save_configuration(wifi_manager_h wifi, wifi_config_s *config)
3145 {
3146         int rv;
3147         wifi_manager_handle_s *wifi_handle = wifi;
3148         gchar *config_id = NULL;
3149         gchar *ssid = NULL;
3150
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
3157                 } else {
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
3162                         }
3163                 }
3164         }
3165
3166         config_id = _wifi_config_get_config_id(config->name, config->security_type);
3167         ssid = __wifi_change_name_to_hexadecimal(config->name);
3168
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
3178         }
3179
3180         return WIFI_MANAGER_ERROR_NONE;
3181 }
3182
3183 int _wifi_load_configurations(wifi_manager_h wifi)
3184 {
3185         int rv;
3186         wifi_manager_handle_s *wifi_handle = wifi;
3187         GSList *config_ids = NULL;
3188         GSList *head_config_ids = NULL;
3189
3190         __clear_config_list(&(wifi_handle->config_iterator));
3191
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
3196         }
3197
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
3201         }
3202
3203         head_config_ids = config_ids;
3204         while (config_ids) {
3205                 wifi_config_s *h;
3206                 gchar *id = config_ids->data;
3207
3208                 h = g_new0(wifi_config_s, 1);
3209                 if (h == NULL)
3210                         break;
3211
3212                 h->wifi_handle = wifi_handle;
3213
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
3219                         }
3220                         rv = __load_eap_configurations(wifi_handle, id, h);
3221                 } else {
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
3226                         }
3227                         rv = __load_configurations(wifi_handle, id, h);
3228                 }
3229
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
3233                 } else {
3234                         h->address_family = WIFI_MANAGER_ADDRESS_FAMILY_IPV4;
3235                         h->is_saved = TRUE;
3236
3237                         wifi_handle->config_iterator = g_slist_append(wifi_handle->config_iterator,
3238                                         (wifi_manager_config_h)h);
3239                 }
3240
3241                 config_ids = config_ids->next;
3242         }
3243
3244         g_slist_free_full(head_config_ids, g_free);
3245
3246         return WIFI_MANAGER_ERROR_NONE;
3247 }
3248
3249 int _wifi_foreach_configuration(wifi_manager_h wifi,
3250                 wifi_manager_config_list_cb callback, void *user_data)
3251 {
3252         int rv;
3253         GSList *list;
3254         wifi_manager_handle_s *wifi_handle = wifi;
3255
3256         for (list = wifi_handle->config_iterator; list; list = list->next) {
3257                 rv = callback((wifi_manager_config_h)list->data, user_data);
3258                 if (rv == false)
3259                         break;
3260         }
3261
3262         return WIFI_MANAGER_ERROR_NONE;
3263 }
3264
3265 int _wifi_remove_configuration(wifi_manager_h wifi, const gchar *config_id)
3266 {
3267         int rv;
3268         GSList *list;
3269         wifi_manager_handle_s *wifi_handle = wifi;
3270
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
3277
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
3282         }
3283
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
3287         }
3288
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) {
3292
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
3299                         }
3300
3301                         prof_info->Favourite = (char)FALSE; //LCOV_EXCL_LINE
3302                         break;
3303                 }
3304         }
3305
3306         return WIFI_MANAGER_ERROR_NONE;
3307 }
3308
3309 //LCOV_EXCL_START
3310 int _wifi_save_eap_configurations(wifi_manager_h wifi, wifi_config_s *config)
3311 {
3312         int rv;
3313         wifi_manager_handle_s *wifi_handle = wifi;
3314         gchar *config_id = NULL;
3315         gchar *ssid = NULL;
3316
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;
3321         }
3322
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;
3327         } else {
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;
3331                 }
3332         }
3333
3334         config_id = _wifi_config_get_config_id(config->name, config->security_type);
3335         ssid = __wifi_change_name_to_hexadecimal(config->name);
3336
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
3346
3347         return WIFI_MANAGER_ERROR_NONE;
3348 }
3349
3350 int _wifi_configuration_set_field(wifi_manager_h wifi,
3351                 const gchar *config_id, const gchar *key, const gchar *value)
3352 {
3353         int rv;
3354         wifi_manager_handle_s *wifi_handle = wifi;
3355
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
3362
3363         return WIFI_MANAGER_ERROR_NONE;
3364 }
3365
3366 int _wifi_configuration_get_passphrase(wifi_manager_h wifi,
3367                 const gchar *config_id, gchar **passphrase)
3368 {
3369         int rv;
3370         wifi_manager_handle_s *wifi_handle = wifi;
3371
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
3378
3379         return WIFI_MANAGER_ERROR_NONE;
3380 }
3381
3382 int _wifi_check_get_privilege(wifi_manager_h wifi)
3383 {
3384         int rv;
3385         wifi_manager_handle_s *wifi_handle = wifi;
3386
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
3393
3394         return WIFI_MANAGER_ERROR_NONE;
3395 }
3396
3397 int _wifi_check_profile_privilege(wifi_manager_h wifi)
3398 {
3399         int rv;
3400         wifi_manager_handle_s *wifi_handle = wifi;
3401
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
3408
3409         return WIFI_MANAGER_ERROR_NONE;
3410 }
3411 //LCOV_EXCL_STOP
3412
3413 bool __check_feature_supported(const char *key, wifi_supported_feature_e feature)
3414 {
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
3420                 }
3421                 wifi_is_feature_checked[feature] = true;
3422         }
3423         return wifi_feature_supported[feature];
3424 }
3425
3426 int _wifi_check_feature_supported(const char *feature_name, ...)
3427 {
3428         va_list list;
3429         const char *key;
3430         bool value = false;
3431         bool feature_supported = false;
3432
3433         va_start(list, feature_name);
3434         key = feature_name;
3435         while (1) {
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);
3442
3443                 feature_supported |= value;
3444                 key = va_arg(list, const char *);
3445                 if (!key) break;
3446         }
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
3452                 else
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
3455                 va_end(list);
3456                 return WIFI_MANAGER_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
3457         }
3458
3459         va_end(list);
3460         set_last_result(WIFI_MANAGER_ERROR_NONE);
3461         return WIFI_MANAGER_ERROR_NONE;
3462 }
3463
3464 //LCOV_EXCL_START
3465 tizen_profile_t _get_tizen_profile()
3466 {
3467         static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
3468         if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
3469                 return profile;
3470
3471         char *profileName;
3472         system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
3473         switch (*profileName) {
3474         case 'm':
3475         case 'M':
3476                 profile = TIZEN_PROFILE_MOBILE;
3477                 break;
3478         case 'w':
3479         case 'W':
3480                 profile = TIZEN_PROFILE_WEARABLE; //LCOV_EXCL_LINE
3481                 break; //LCOV_EXCL_LINE
3482         case 't':
3483         case 'T':
3484                 profile = TIZEN_PROFILE_TV; //LCOV_EXCL_LINE
3485                 break; //LCOV_EXCL_LINE
3486         case 'i':
3487         case 'I':
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
3492         }
3493         free(profileName);
3494
3495         return profile;
3496 }
3497
3498 int _wifi_set_autoscan(wifi_manager_h wifi, bool autoscan)
3499 {
3500         int rv = 0;
3501         wifi_manager_handle_s *wifi_handle = wifi;
3502
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;
3509
3510         return WIFI_MANAGER_ERROR_NONE;
3511 }
3512
3513 int _wifi_set_background_scan_mode(wifi_manager_h wifi,
3514                 wifi_manager_autoscan_mode_e mode)
3515 {
3516         int rv = 0;
3517         wifi_manager_handle_s *wifi_handle = wifi;
3518
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;
3525
3526         return WIFI_MANAGER_ERROR_NONE;
3527 }
3528
3529 int _wifi_set_ip_conflict_period(wifi_manager_h wifi, unsigned int initial_time)
3530 {
3531         int rv = 0;
3532         wifi_manager_handle_s *wifi_handle = wifi;
3533
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;
3540
3541         return WIFI_MANAGER_ERROR_NONE;
3542 }
3543
3544 int _wifi_get_autoscan(wifi_manager_h wifi, bool *autoscan)
3545 {
3546         int rv;
3547         gboolean auto_scan = 0;
3548         wifi_manager_handle_s *wifi_handle = wifi;
3549
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
3557         }
3558
3559         *autoscan =  auto_scan;
3560         return WIFI_MANAGER_ERROR_NONE;
3561 }
3562
3563 int _wifi_get_autoscanmode(wifi_manager_h wifi, wifi_manager_autoscan_mode_e *autoscanmode)
3564 {
3565         int rv;
3566         wifi_manager_handle_s *wifi_handle = wifi;
3567
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
3575         }
3576
3577         return WIFI_MANAGER_ERROR_NONE;
3578 }
3579
3580 int _wifi_set_passpoint(wifi_manager_h wifi, int passpoint)
3581 {
3582         int rv;
3583         wifi_manager_handle_s *wifi_handle = wifi;
3584
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");
3588
3589         return rv;
3590 }
3591
3592 int _wifi_get_passpoint(wifi_manager_h wifi, int *passpoint)
3593 {
3594         int rv;
3595         wifi_manager_handle_s *wifi_handle = wifi;
3596
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");
3600
3601         return rv;
3602 }
3603
3604 int _wifi_get_ip_conflict_period(wifi_manager_h wifi, unsigned int* initial_time)
3605 {
3606         int rv;
3607         wifi_manager_handle_s *wifi_handle = wifi;
3608
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
3616         }
3617
3618         return WIFI_MANAGER_ERROR_NONE;
3619 }
3620
3621 int _wifi_get_ip_conflict_state(wifi_manager_h wifi, wifi_manager_ip_conflict_state_e *state)
3622 {
3623         int rv;
3624         wifi_manager_handle_s *wifi_handle = wifi;
3625
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
3633         }
3634
3635         return WIFI_MANAGER_ERROR_NONE;
3636 }
3637
3638 int _wifi_get_wps_generated_pin(wifi_manager_h wifi, char **wps_pin)
3639 {
3640         int rv;
3641         wifi_manager_handle_s *wifi_handle = wifi;
3642
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");
3646
3647         return rv;
3648 }
3649
3650 int _wifi_get_module_state(wifi_manager_h wifi, wifi_manager_module_state_e *state)
3651 {
3652         int rv = 0;
3653         int wifi_device_status = 0;
3654         wifi_manager_handle_s *wifi_handle = wifi;
3655
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
3663         }
3664
3665         if (wifi_device_status == 0) {
3666                 WIFI_LOG(WIFI_INFO, "Wi-Fi Module is detached");
3667                 *state = WIFI_MANAGER_MODULE_STATE_DETACHED;
3668         } else {
3669                 WIFI_LOG(WIFI_INFO, "Wi-Fi Module is attached");
3670                 *state = WIFI_MANAGER_MODULE_STATE_ATTACHED;
3671         }
3672
3673         return WIFI_MANAGER_ERROR_NONE;
3674 }
3675 //LCOV_EXCL_STOP
3676
3677 bool _wifi_check_multi_scan_validity(wifi_manager_specific_scan_h specific_scan)
3678 {
3679         GSList *list = NULL;
3680
3681         if (specific_scan == NULL)
3682                 return false;
3683
3684         for (list = multi_scan_handle_list; list; list = list->next)
3685                 if (specific_scan == list->data) return true;
3686
3687         return false;
3688 }
3689
3690 void _wifi_add_to_multi_scan_list(wifi_manager_specific_scan_h *specific_scan)
3691 {
3692         multi_scan_handle_list = g_slist_append(multi_scan_handle_list, *specific_scan);
3693 }
3694
3695 void _wifi_remove_from_multi_scan_list(wifi_manager_specific_scan_h specific_scan)
3696 {
3697         GSList *multi_scan_list = (GSList *)specific_scan;
3698
3699         g_slist_free_full(multi_scan_list, g_free);
3700
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;
3704 }
3705
3706 int _wifi_specific_scan_create(wifi_manager_specific_scan_h *specific_scan)
3707 {
3708         GSList *list = g_slist_alloc();
3709
3710         if (list == NULL) {
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
3713         }
3714
3715         *specific_scan = list;
3716
3717         WIFI_LOG(WIFI_INFO, "New specific scan handle[%p]", *specific_scan);
3718         return WIFI_MANAGER_ERROR_NONE;
3719 }
3720
3721 int _wifi_specific_scan_set_ssid(wifi_manager_specific_scan_h specific_scan,
3722                 const char *essid)
3723 {
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));
3726
3727         if (!ap) {
3728                 WIFI_LOG(WIFI_ERROR, "Failed to allocate memory"); //LCOV_EXCL_LINE
3729                 return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
3730         }
3731         g_strlcpy(ap->str, essid, NET_WLAN_ESSID_LEN + 1);
3732         ap->flag = true;
3733
3734         list = g_slist_append(list, ap);
3735         multi_scan_type[WIFI_MULTI_SCAN_SSID] = true;
3736
3737         specific_scan = (wifi_manager_specific_scan_h)list;
3738         return WIFI_MANAGER_ERROR_NONE;
3739 }
3740
3741 int _wifi_specific_scan_set_freq(wifi_manager_specific_scan_h specific_scan,
3742                 int freq)
3743 {
3744         GSList *list = (GSList *)specific_scan;
3745         char str[5];
3746         snprintf(str, 5, "%d", freq);
3747
3748         wifi_manager_multi_scan_ap_s *ap = (wifi_manager_multi_scan_ap_s*)g_try_malloc0(sizeof(wifi_manager_multi_scan_ap_s));
3749
3750         if (!ap) {
3751                 WIFI_LOG(WIFI_ERROR, "Failed to allocate memory"); //LCOV_EXCL_LINE
3752                 return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
3753         }
3754         g_strlcpy(ap->str, str, NET_WLAN_FREQ_LEN);
3755         ap->flag = false;
3756
3757         list = g_slist_append(list, ap);
3758         multi_scan_type[WIFI_MULTI_SCAN_FREQ] = true;
3759
3760         specific_scan = (wifi_manager_specific_scan_h)list;
3761         return WIFI_MANAGER_ERROR_NONE;
3762 }
3763
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)
3767 {
3768         int rv = -1;
3769         wifi_manager_handle_s *wifi_handle = wifi;
3770         GSList *multi_scan_list = (GSList *)specific_scan;
3771
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;
3783         }
3784
3785         return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
3786 }
3787
3788 int _wifi_get_connection_mode(wifi_manager_h wifi, wifi_manager_connection_mode_e *mode)
3789 {
3790         int rv;
3791         GSList *list;
3792         wifi_manager_handle_s *wifi_handle = wifi;
3793         net_profile_info_s *prof_info = NULL;
3794
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;
3799         }
3800
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)
3805                         break;
3806         }
3807
3808         if (prof_info == NULL) {
3809                 WIFI_LOG(WIFI_ERROR, "There is no connected AP");
3810                 return WIFI_MANAGER_ERROR_NO_CONNECTION;
3811         }
3812
3813         *mode = (wifi_manager_connection_mode_e)prof_info->connection_mode;
3814
3815         return WIFI_MANAGER_ERROR_NONE;
3816 }
3817
3818 int _wifi_get_service_state(wifi_manager_handle_s *wifi_handle)
3819 {
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);
3822
3823         switch (service_state) {
3824         case NET_STATE_TYPE_UNKNOWN:
3825                 ret = WIFI_SERVICE_STATE_UNKNOWN;
3826                 break;
3827         case NET_STATE_TYPE_FAILURE:
3828                 ret = WIFI_SERVICE_STATE_FAILURE;
3829                 break;
3830         case NET_STATE_TYPE_ASSOCIATION:
3831                 ret = WIFI_SERVICE_STATE_ASSOCIATION;
3832                 break;
3833         case NET_STATE_TYPE_CONFIGURATION:
3834                 ret = WIFI_SERVICE_STATE_CONFIGURATION;
3835                 break;
3836         case NET_STATE_TYPE_READY:
3837         case NET_STATE_TYPE_ONLINE:
3838                 ret = WIFI_SERVICE_STATE_CONNECTED;
3839                 break;
3840         case NET_STATE_TYPE_IDLE:
3841         case NET_STATE_TYPE_DISCONNECT:
3842                 ret = WIFI_SERVICE_STATE_IDLE;
3843                 break;
3844         default:
3845                 break;
3846         }
3847
3848         return ret;
3849 }
3850
3851 int _wifi_get_max_scan_ssids(wifi_manager_h wifi, int *max_scan_ssids)
3852 {
3853         int rv;
3854         wifi_manager_handle_s *wifi_handle = wifi;
3855
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
3863         }
3864
3865         return WIFI_MANAGER_ERROR_NONE;
3866 }
3867
3868 //LCOV_EXCL_START
3869 bool _wifi_check_dpp_validity(wifi_manager_dpp_h dpp_h)
3870 {
3871         GSList *list = NULL;
3872
3873         if (dpp_h == NULL)
3874                 return false;
3875
3876         for (list = dpp_handle_list; list; list = list->next)
3877                 if (dpp_h == list->data) return true;
3878
3879         return false;
3880 }
3881
3882 void _wifi_add_to_dpp_list(wifi_manager_dpp_h dpp_h)
3883 {
3884         dpp_handle_list = g_slist_prepend(dpp_handle_list, dpp_h);
3885 }
3886
3887 void _wifi_remove_from_dpp_list(wifi_manager_dpp_h dpp_h)
3888 {
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);
3892         g_free(dpp_h);
3893 }
3894
3895 static gboolean __is_new_initiator(wifi_dpp_s *p_dpp)
3896 {
3897         return (p_dpp->is_initiator) && (p_dpp->state == WIFI_MANAGER_DPP_STATE_NONE);
3898 }
3899
3900 static gboolean __is_response_pending_initiator(wifi_dpp_s *p_dpp)
3901 {
3902         return (p_dpp->is_initiator) && (p_dpp->state == WIFI_MANAGER_DPP_STATE_URI_REQUESTED);
3903 }
3904
3905 static gboolean __is_new_responder(wifi_dpp_s *p_dpp)
3906 {
3907         return (!p_dpp->is_initiator) && (p_dpp->state == WIFI_MANAGER_DPP_STATE_NONE);
3908 }
3909
3910 static gboolean __is_peer_scan_requested_responder(wifi_dpp_s *p_dpp)
3911 {
3912         return (!p_dpp->is_initiator) && (p_dpp->state == WIFI_MANAGER_DPP_STATE_URI_REQUESTED);
3913 }
3914
3915 static wifi_manager_error_e __convert_net_err_to_wifi_dpp_error(net_err_e err_type)
3916 {
3917         switch (err_type) {
3918         case NET_ERR_NONE:
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;
3926         default:
3927                 return WIFI_MANAGER_ERROR_OPERATION_FAILED;
3928         }
3929 }
3930
3931
3932 int _wifi_dpp_enter_peer_uri(wifi_dpp_s *p_dpp,
3933                 const char *uri)
3934 {
3935         int rv = WIFI_MANAGER_ERROR_NONE;
3936
3937         /* Just saving Peer URI for not bootstrapped initiator */
3938         if (__is_new_initiator(p_dpp))
3939                 return rv;
3940
3941         if (!__is_peer_scan_requested_responder(p_dpp))
3942                 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
3943
3944         if (g_p_dpp_current != p_dpp)
3945                 return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS;
3946
3947         rv = net_dpp_enter_peer_uri(p_dpp->network_info, p_dpp->peer_id, p_dpp->own_id, uri);
3948
3949         if (rv != NET_ERR_NONE)
3950                 WIFI_LOG(WIFI_ERROR, "Failed to enter peer URI");
3951         else
3952                 g_p_dpp_current = p_dpp;
3953
3954         return __convert_net_err_to_wifi_dpp_error(rv);
3955 }
3956
3957 int _wifi_dpp_request_own_uri_gen(wifi_dpp_s *p_dpp, const char *key)
3958 {
3959         int rv = WIFI_MANAGER_ERROR_NONE;
3960
3961         if (!__is_response_pending_initiator(p_dpp))
3962                 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
3963
3964         if (g_p_dpp_current != p_dpp)
3965                 return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS;
3966
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);
3969
3970         if (rv != NET_ERR_NONE)
3971                 WIFI_LOG(WIFI_ERROR, "Failed to generate own URI");
3972
3973         return __convert_net_err_to_wifi_dpp_error(rv);
3974 }
3975
3976 int _wifi_dpp_start(wifi_dpp_s *p_dpp, const char *auth_key,
3977                 const char *configurator_key, const char *pass)
3978 {
3979         int rv = WIFI_MANAGER_ERROR_NONE;
3980
3981         if (!__is_new_initiator(p_dpp) &&
3982                         !__is_new_responder(p_dpp))
3983                 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
3984
3985         if (g_p_dpp_current)
3986                 return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS;
3987
3988         rv = net_dpp_start((void *)p_dpp, auth_key, configurator_key, pass);
3989
3990         if (rv != NET_ERR_NONE)
3991                 WIFI_LOG(WIFI_ERROR, "Failed to start");
3992         else
3993                 g_p_dpp_current = p_dpp;
3994
3995         return __convert_net_err_to_wifi_dpp_error(rv);
3996 }
3997
3998 int _wifi_dpp_stop(wifi_dpp_s *p_dpp)
3999 {
4000         int rv = WIFI_MANAGER_ERROR_NONE;
4001
4002         if (__is_new_initiator(p_dpp) ||
4003                         __is_new_responder(p_dpp))
4004                 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
4005
4006         if (!g_p_dpp_current)
4007                 return WIFI_MANAGER_ERROR_INVALID_OPERATION;
4008
4009         if (g_p_dpp_current != p_dpp)
4010                 return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS;
4011
4012         rv = net_dpp_stop(p_dpp->network_info,
4013                 p_dpp->peer_id, p_dpp->own_id, p_dpp->is_initiator);
4014
4015         if (rv != NET_ERR_NONE)
4016                 WIFI_LOG(WIFI_ERROR, "Failed to stop");
4017
4018         return __convert_net_err_to_wifi_dpp_error(rv);
4019 }
4020 //LCOV_EXCL_STOP
4021
4022 void _wifi_lock(void)
4023 {
4024         pthread_mutex_lock(&g_wifi_thread_mutex);
4025 }
4026
4027 void _wifi_unlock(void)
4028 {
4029         pthread_mutex_unlock(&g_wifi_thread_mutex);
4030 }
4031
4032 int _wifi_set_mac_policy(wifi_manager_h wifi, unsigned int policy)
4033 {
4034         int rv;
4035         wifi_manager_handle_s *wifi_handle = wifi;
4036
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
4043
4044         wifi_handle->mac_policy = policy;
4045
4046         return WIFI_MANAGER_ERROR_NONE;
4047 }
4048
4049 int _wifi_get_mac_policy(wifi_manager_h wifi, unsigned int *policy)
4050 {
4051         int rv;
4052         wifi_manager_handle_s *wifi_handle = wifi;
4053
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
4060
4061         return WIFI_MANAGER_ERROR_NONE;
4062 }
4063
4064 int _wifi_set_preassoc_mac_policy(wifi_manager_h wifi, unsigned int policy)
4065 {
4066         int rv;
4067         wifi_manager_handle_s *wifi_handle = wifi;
4068
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
4075
4076         wifi_handle->preassoc_mac_policy = policy;
4077
4078         return WIFI_MANAGER_ERROR_NONE;
4079 }
4080
4081 int _wifi_get_preassoc_mac_policy(wifi_manager_h wifi, unsigned int *policy)
4082 {
4083         int rv;
4084         wifi_manager_handle_s *wifi_handle = wifi;
4085
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
4092
4093         return WIFI_MANAGER_ERROR_NONE;
4094 }
4095
4096 int _wifi_set_random_mac_lifetime(wifi_manager_h wifi, unsigned int lifetime)
4097 {
4098         int rv;
4099         wifi_manager_handle_s *wifi_handle = wifi;
4100
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
4107
4108         wifi_handle->random_mac_lifetime = lifetime;
4109
4110         return WIFI_MANAGER_ERROR_NONE;
4111 }
4112
4113 int _wifi_get_random_mac_lifetime(wifi_manager_h wifi, unsigned int *lifetime)
4114 {
4115         int rv;
4116         wifi_manager_handle_s *wifi_handle = wifi;
4117
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
4124
4125         return WIFI_MANAGER_ERROR_NONE;
4126 }
4127
4128 int _wifi_set_country_code(wifi_manager_h wifi, const char *country)
4129 {
4130         int rv;
4131         wifi_manager_handle_s *wifi_handle = wifi;
4132
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
4139
4140         memset(wifi_handle->country, 0, sizeof(wifi_handle->country));
4141         g_strlcpy(wifi_handle->country, country, sizeof(wifi_handle->country));
4142
4143         return WIFI_MANAGER_ERROR_NONE;
4144 }
4145
4146 int _wifi_get_country_code(wifi_manager_h wifi, char **country)
4147 {
4148         int rv;
4149         wifi_manager_handle_s *wifi_handle = wifi;
4150
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
4157
4158         return WIFI_MANAGER_ERROR_NONE;
4159 }