428e7b8f14010197e7e8c3f190252046064fb9f7
[platform/core/api/wifi-manager.git] / src / network_interface.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 #include <ctype.h>
18 #include <vconf.h>
19 #include <vconf-keys.h>
20 #include <stdio.h>
21 #include <arpa/inet.h>
22
23 #include "wifi_internal.h"
24 #include "network_interface.h"
25 #include "network_internal.h"
26 #include "network_dbus.h"
27 #include "network_signal.h"
28
29 #define DBUS_OBJECT_PATH_MAX    150
30
31 //LCOV_EXCL_START
32 static int __net_check_get_privilege(network_info_s *network_info)
33 {
34         __NETWORK_FUNC_ENTER__;
35
36         net_err_e Error = NET_ERR_NONE;
37         GVariant *message = NULL;
38
39         message = _net_invoke_dbus_method(network_info,
40                         NETCONFIG_SERVICE, NETCONFIG_NETWORK_PATH,
41                         NETCONFIG_NETWORK_INTERFACE, "CheckGetPrivilege",
42                         NULL, &Error);
43         if (message == NULL) {
44                 WIFI_LOG(WIFI_ERROR, "Failed to check get privilege"); //LCOV_EXCL_LINE
45                 return Error; //LCOV_EXCL_LINE
46         }
47
48         g_variant_unref(message);
49
50         __NETWORK_FUNC_EXIT__;
51         return Error;
52 }
53
54 static int __net_set_ip_conflict_detect_mode(network_info_s *network_info, bool detect)
55 {
56         __NETWORK_FUNC_ENTER__;
57
58         net_err_e Error = NET_ERR_NONE;
59         GVariant *message = NULL;
60         GVariant *params;
61         params = g_variant_new("(sb)", network_info->interface_name, detect);
62
63         message = _net_invoke_dbus_method(network_info,
64                         NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
65                         NETCONFIG_WIFI_INTERFACE, "IpConflictSetEnable",
66                         params, &Error);
67         if (message == NULL) {
68                 WIFI_LOG(WIFI_ERROR, "Failed to set conflict detect enable mode"); //LCOV_EXCL_LINE
69                 __NETWORK_FUNC_EXIT__;
70                 return Error; //LCOV_EXCL_LINE
71         }
72
73         g_variant_unref(message);
74
75         __NETWORK_FUNC_EXIT__;
76         return Error;
77 }
78
79 static int __net_ip_conflict_detect_is_enabled(network_info_s *network_info,
80                 gboolean *state)
81 {
82         __NETWORK_FUNC_ENTER__;
83
84         net_err_e Error = NET_ERR_NONE;
85         GVariant *params = NULL;
86         GVariant *message = NULL;
87
88         params = g_variant_new("(s)", network_info->interface_name);
89
90         message = _net_invoke_dbus_method(network_info,
91                         NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
92                         NETCONFIG_WIFI_INTERFACE, "IsIpConflictDetectEnabled",
93                         params, &Error);
94         if (message == NULL) {
95                 WIFI_LOG(WIFI_ERROR, "Failed to get conflict detect enable mode"); //LCOV_EXCL_LINE
96                 __NETWORK_FUNC_EXIT__;
97                 return Error; //LCOV_EXCL_LINE
98         }
99
100         g_variant_get(message, "(b)", state);
101         g_variant_unref(message);
102
103         __NETWORK_FUNC_EXIT__;
104         return Error;
105 }
106
107
108 static int __net_check_profile_privilege(network_info_s *network_info)
109 {
110         __NETWORK_FUNC_ENTER__;
111
112         net_err_e Error = NET_ERR_NONE;
113         GVariant *message = NULL;
114
115         message = _net_invoke_dbus_method(network_info,
116                         NETCONFIG_SERVICE, NETCONFIG_NETWORK_PATH,
117                         NETCONFIG_NETWORK_INTERFACE, "CheckProfilePrivilege",
118                         NULL, &Error);
119         if (message == NULL) {
120                 WIFI_LOG(WIFI_ERROR, "Failed to check profile privilege"); //LCOV_EXCL_LINE
121                 return Error; //LCOV_EXCL_LINE
122         }
123
124         g_variant_unref(message);
125
126         __NETWORK_FUNC_EXIT__;
127         return Error;
128 }
129 //LCOV_EXCL_STOP
130
131 static int __net_get_prefix_len(const char *netmask)
132 {
133         __NETWORK_FUNC_ENTER__;
134
135         in_addr_t mask = inet_network(netmask);
136         int prefix_len = 0;
137
138         for (; mask; mask <<= 1)
139                 ++prefix_len;
140
141         __NETWORK_FUNC_EXIT__;
142
143         return prefix_len;
144 }
145
146 //LCOV_EXCL_START
147 static int __net_extract_ip(const gchar *value, net_addr_s *ipAddr)
148 {
149         __NETWORK_FUNC_ENTER__;
150
151         unsigned char *ipValue = NULL;
152         char *saveptr = NULL;
153         char ipString[NET_IPV4_STR_LEN_MAX+1];
154         char* ipToken[4];
155
156         ipValue = (unsigned char *)&(ipAddr->Data.Ipv4.s_addr);
157
158         if (value != NULL) {
159                 g_strlcpy(ipString, value, NET_IPV4_STR_LEN_MAX+1);
160
161                 ipToken[0] = strtok_r(ipString, ".", &saveptr);
162
163                 if (ipToken[0] != NULL) {
164                         ipToken[1] = strtok_r(NULL, ".", &saveptr);
165
166                         if (ipToken[1] != NULL) {
167                                 ipToken[2] = strtok_r(NULL, ".", &saveptr);
168
169                                 if (ipToken[2] != NULL) {
170                                         ipToken[3] = strtok_r(NULL, ".", &saveptr);
171
172                                         if (ipToken[3] != NULL) {
173                                                 ipValue[0] = (unsigned char)atoi(ipToken[0]);
174                                                 ipValue[1] = (unsigned char)atoi(ipToken[1]);
175                                                 ipValue[2] = (unsigned char)atoi(ipToken[2]);
176                                                 ipValue[3] = (unsigned char)atoi(ipToken[3]);
177                                         }
178                                 }
179                         }
180                 }
181         }
182
183         __NETWORK_FUNC_EXIT__;
184
185         return NET_ERR_NONE;
186 }
187
188 static gboolean __net_check_address_type(int address_family, const char *address)
189 {
190         unsigned char buf[sizeof(struct in6_addr)] = {0, };
191         int err = 0;
192
193         err = inet_pton(address_family, address, buf);
194         if (err > 0)
195                 return TRUE;
196
197         return FALSE;
198 }
199
200 static int __net_extract_common_info(const char *key, GVariant *variant, net_profile_info_s* ProfInfo)
201 {
202         __NETWORK_FUNC_ENTER__;
203
204         net_err_e Error = NET_ERR_NONE;
205         const gchar *subKey = NULL;
206         const gchar *value = NULL;
207         net_dev_info_s* net_info = NULL;
208         GVariant *var = NULL;
209         GVariantIter *iter = NULL;
210
211         net_info = &(ProfInfo->net_info);
212
213         if (g_strcmp0(key, "State") == 0) {
214                 value = g_variant_get_string(variant, NULL);
215
216                 if (g_strcmp0(value, "idle") == 0)
217                         ProfInfo->ProfileState = NET_STATE_TYPE_IDLE;
218                 else if (g_strcmp0(value, "failure") == 0)
219                         ProfInfo->ProfileState = NET_STATE_TYPE_FAILURE;
220                 else if (g_strcmp0(value, "association") == 0)
221                         ProfInfo->ProfileState = NET_STATE_TYPE_ASSOCIATION;
222                 else if (g_strcmp0(value, "configuration") == 0)
223                         ProfInfo->ProfileState = NET_STATE_TYPE_CONFIGURATION;
224                 else if (g_strcmp0(value, "ready") == 0)
225                         ProfInfo->ProfileState = NET_STATE_TYPE_READY;
226                 else if (g_strcmp0(value, "disconnect") == 0)
227                         ProfInfo->ProfileState = NET_STATE_TYPE_DISCONNECT;
228                 else if (g_strcmp0(value, "online") == 0)
229                         ProfInfo->ProfileState = NET_STATE_TYPE_ONLINE;
230                 else
231                         ProfInfo->ProfileState = NET_STATE_TYPE_UNKNOWN;
232         } else if (g_strcmp0(key, "Error") == 0) {
233                 value = g_variant_get_string(variant, NULL);
234
235                 if (g_strcmp0(value, "invalid-key") == 0)
236                         ProfInfo->ProfileErrorState = NET_STATE_ERROR_INVALID_KEY;
237                 else if (g_strcmp0(value, "connect-failed") == 0)
238                         ProfInfo->ProfileErrorState = NET_STATE_ERROR_CONNECT_FAILED;
239                 else if (g_strcmp0(value, "auth-failed") == 0)
240                         ProfInfo->ProfileErrorState = NET_STATE_ERROR_AUTH_FAILED;
241                 else if (g_strcmp0(value, "login-failed") == 0)
242                         ProfInfo->ProfileErrorState = NET_STATE_ERROR_LOGIN_FAILED;
243                 else if (g_strcmp0(value, "dhcp-failed") == 0)
244                         ProfInfo->ProfileErrorState = NET_STATE_ERROR_DHCP_FAILED;
245                 else if (g_strcmp0(value, "out-of-range") == 0)
246                         ProfInfo->ProfileErrorState = NET_STATE_ERROR_OUT_OF_RANGE;
247                 else if (g_strcmp0(value, "pin-missing") == 0)
248                         ProfInfo->ProfileErrorState = NET_STATE_ERROR_PIN_MISSING;
249         } else if (g_strcmp0(key, "Favorite") == 0) {
250                 gboolean val = g_variant_get_boolean(variant);
251
252                 if (val)
253                         ProfInfo->Favourite = (char)TRUE;
254                 else
255                         ProfInfo->Favourite = (char)FALSE;
256         } else if (g_strcmp0(key, "Ethernet") == 0) {
257                 g_variant_get(variant, "a{sv}", &iter);
258                 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
259                         if (g_strcmp0(subKey, "Interface") == 0) {
260                                 value = g_variant_get_string(var, NULL);
261
262                                 if (value != NULL)
263                                         g_strlcpy(net_info->DevName, value, NET_MAX_DEVICE_NAME_LEN);
264                         } else if (g_strcmp0(subKey, "Address") == 0) {
265                                 value = g_variant_get_string(var, NULL);
266
267                                 if (value != NULL)
268                                         g_strlcpy(net_info->MacAddr, value, WIFI_MAC_ADDR_LEN + 1);
269                         }
270                 }
271                 g_variant_iter_free(iter);
272         } else if (g_strcmp0(key, "IPv4") == 0) {
273                 g_variant_get(variant, "a{sv}", &iter);
274                 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
275                         if (g_strcmp0(subKey, "Method") == 0) {
276                                 value = g_variant_get_string(var, NULL);
277
278                                 if (g_strcmp0(value, "dhcp") == 0)
279                                         net_info->IpConfigType = NET_IP_CONFIG_TYPE_DYNAMIC;
280                                 else if (g_strcmp0(value, "manual") == 0)
281                                         net_info->IpConfigType = NET_IP_CONFIG_TYPE_STATIC;
282                                 else if (g_strcmp0(value, "fixed") == 0)
283                                         net_info->IpConfigType = NET_IP_CONFIG_TYPE_FIXED;
284                                 else if (g_strcmp0(value, "off") == 0)
285                                         net_info->IpConfigType = NET_IP_CONFIG_TYPE_OFF;
286
287                                 if (net_info->IpConfigType != NET_IP_CONFIG_TYPE_DYNAMIC) {
288                                         net_info->BServerAddr = FALSE;
289                                         net_info->ServerAddr.Type = NET_ADDR_IPV4;
290                                         net_info->ServerAddr.Data.Ipv4.s_addr = 0;
291                                 }
292
293                         } else if (g_strcmp0(subKey, "Address") == 0) {
294                                 value = g_variant_get_string(var, NULL);
295
296                                 __net_extract_ip(value, &net_info->IpAddr);
297                         } else if (g_strcmp0(subKey, "Netmask") == 0) {
298                                 value = g_variant_get_string(var, NULL);
299
300                                 __net_extract_ip(value, &net_info->SubnetMask);
301                                 net_info->PrefixLen = __net_get_prefix_len(value);
302                                 net_info->BNetmask = TRUE;
303                         } else if (g_strcmp0(subKey, "Gateway") == 0) {
304                                 value = g_variant_get_string(var, NULL);
305
306                                 __net_extract_ip(value, &net_info->GatewayAddr);
307                                 net_info->BDefGateway = TRUE;
308                         } else if (g_strcmp0(subKey, "DHCPServerIP") == 0) {
309                                 value = g_variant_get_string(var, NULL);
310
311                                 __net_extract_ip(value, &net_info->ServerAddr);
312                                 net_info->BServerAddr = TRUE;
313                         } else if (g_strcmp0(subKey, "DHCPLeaseDuration") == 0) {
314                                 net_info->DHCPLeaseDuration = g_variant_get_int32(var);
315                         }
316                 }
317                 g_variant_iter_free(iter);
318         } else if (g_strcmp0(key, "IPv4.Configuration") == 0) {
319                 if (net_info->IpConfigType != NET_IP_CONFIG_TYPE_DYNAMIC &&
320                     net_info->IpConfigType != NET_IP_CONFIG_TYPE_STATIC &&
321                     net_info->IpConfigType != NET_IP_CONFIG_TYPE_FIXED &&
322                     net_info->IpConfigType != NET_IP_CONFIG_TYPE_OFF) {
323
324                         g_variant_get(variant, "a{sv}", &iter);
325                         while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
326                                 if (g_strcmp0(subKey, "Method") == 0) {
327                                         value = g_variant_get_string(var, NULL);
328
329                                         if (g_strcmp0(value, "dhcp") == 0)
330                                                 net_info->IpConfigType = NET_IP_CONFIG_TYPE_DYNAMIC;
331                                         else if (g_strcmp0(value, "manual") == 0)
332                                                 net_info->IpConfigType = NET_IP_CONFIG_TYPE_STATIC;
333                                         else if (g_strcmp0(value, "fixed") == 0)
334                                                 net_info->IpConfigType = NET_IP_CONFIG_TYPE_FIXED;
335                                         else if (g_strcmp0(value, "off") == 0)
336                                                 net_info->IpConfigType = NET_IP_CONFIG_TYPE_OFF;
337
338                                 } else if (g_strcmp0(subKey, "Address") == 0 &&
339                                                         net_info->IpAddr.Data.Ipv4.s_addr == 0) {
340                                         value = g_variant_get_string(var, NULL);
341
342                                         __net_extract_ip(value, &net_info->IpAddr);
343                                 } else if (g_strcmp0(subKey, "Netmask") == 0 &&
344                                                         net_info->SubnetMask.Data.Ipv4.s_addr == 0) {
345                                         value = g_variant_get_string(var, NULL);
346
347                                         __net_extract_ip(value, &net_info->SubnetMask);
348                                         net_info->PrefixLen = __net_get_prefix_len(value);
349                                         net_info->BNetmask = TRUE;
350                                 } else if (g_strcmp0(subKey, "Gateway") == 0 &&
351                                                         net_info->GatewayAddr.Data.Ipv4.s_addr == 0) {
352                                         value = g_variant_get_string(var, NULL);
353
354                                         __net_extract_ip(value, &net_info->GatewayAddr);
355                                         net_info->BDefGateway = TRUE;
356                                 }
357                         }
358                         g_variant_iter_free(iter);
359                 }
360         } else if (g_strcmp0(key, "IPv6") == 0) {
361                 g_variant_get(variant, "a{sv}", &iter);
362                 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
363                         if (g_strcmp0(subKey, "Method") == 0) {
364                                 value = g_variant_get_string(var, NULL);
365
366                                 if (g_strcmp0(value, "manual") == 0)
367                                         net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_STATIC;
368                                 else if (g_strcmp0(value, "off") == 0)
369                                         net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_OFF;
370                                 else if (g_strcmp0(value, "auto") == 0)
371                                         net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_AUTO_IP;
372
373                         } else if (g_strcmp0(subKey, "Address") == 0) {
374                                 value = g_variant_get_string(var, NULL);
375
376                                 inet_pton(AF_INET6, value, &net_info->IpAddr6.Data.Ipv6);
377                         } else if (g_strcmp0(subKey, "PrefixLength") == 0) {
378                                 net_info->PrefixLen6 = g_variant_get_byte(var);
379                         } else if (g_strcmp0(subKey, "Gateway") == 0) {
380                                 value = g_variant_get_string(var, NULL);
381
382                                 inet_pton(AF_INET6, value, &net_info->GatewayAddr6.Data.Ipv6);
383                                 net_info->BDefGateway6 = TRUE;
384                         } else if (g_strcmp0(subKey, "Privacy") == 0) {
385                                 value = g_variant_get_string(var, NULL);
386
387                                 if (value != NULL)
388                                         g_strlcpy(net_info->Privacy6, value, NET_IPV6_MAX_PRIVACY_LEN);
389                         }
390                 }
391                 g_variant_iter_free(iter);
392         } else if (g_strcmp0(key, "IPv6.Configuration") == 0) {
393                 g_variant_get(variant, "a{sv}", &iter);
394                 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
395                         if (g_strcmp0(subKey, "Method") == 0) {
396                                 value = g_variant_get_string(var, NULL);
397
398                                 if (g_strcmp0(value, "manual") == 0)
399                                         net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_STATIC;
400                                 else if (g_strcmp0(value, "off") == 0)
401                                         net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_OFF;
402                                 else if (g_strcmp0(value, "auto") == 0)
403                                         net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_AUTO_IP;
404
405                         } else if (g_strcmp0(subKey, "Address") == 0) {
406                                 value = g_variant_get_string(var, NULL);
407
408                                 inet_pton(AF_INET6, value, &net_info->IpAddr6.Data.Ipv6);
409                         } else if (g_strcmp0(subKey, "PrefixLength") == 0) {
410                                 net_info->PrefixLen6 = g_variant_get_byte(var);
411                         } else if (g_strcmp0(subKey, "Gateway") == 0) {
412                                 value = g_variant_get_string(var, NULL);
413
414                                 inet_pton(AF_INET6, value, &net_info->GatewayAddr6.Data.Ipv6);
415                                 net_info->BDefGateway6 = TRUE;
416                         } else if (g_strcmp0(subKey, "Privacy") == 0) {
417                                 value = g_variant_get_string(var, NULL);
418
419                                 if (value != NULL)
420                                         g_strlcpy(net_info->Privacy6, value, NET_IPV6_MAX_PRIVACY_LEN);
421                         }
422                 }
423                 g_variant_iter_free(iter);
424         } else if (g_strcmp0(key, "Nameservers") == 0) {
425                 int dnsCount = 0;
426                 int dnsCount6 = 0;
427                 gchar *dns_value = NULL;
428                 gchar *dns_type = NULL;
429
430                 g_variant_get(variant, "as", &iter);
431
432                 while (g_variant_iter_loop(iter, "s", &dns_value)) {
433                         if (__net_check_address_type(AF_INET6, dns_value)) {
434                                 if (dnsCount6 < NET_DNS_ADDR_MAX) {
435                                         net_info->DnsAddr6[dnsCount6].Type =
436                                                 NET_ADDR_IPV6;
437                                         inet_pton(AF_INET6, dns_value,
438                                                         &net_info->DnsAddr6[dnsCount6]\
439                                                         .Data.Ipv6);
440                                         dnsCount6++;
441                                 }
442                         } else if (__net_check_address_type(AF_INET, dns_value)) {
443                                 if (dnsCount < NET_DNS_ADDR_MAX) {
444                                         net_info->DnsAddr[dnsCount].Type =
445                                                 NET_ADDR_IPV4;
446                                         __net_extract_ip(dns_value,
447                                                         &net_info->DnsAddr[dnsCount]);
448                                         dnsCount++;
449                                 }
450                         } else { /* DNS Type */
451                                 dns_type = g_strdup(dns_value);
452                                 if (g_strcmp0(dns_type, "ipv4.manual") == 0)
453                                         net_info->DnsConfigType =
454                                                 NET_DNS_CONFIG_TYPE_STATIC;
455                                 else if (g_strcmp0(dns_type, "ipv4.dhcp") == 0)
456                                         net_info->DnsConfigType =
457                                                 NET_DNS_CONFIG_TYPE_DYNAMIC;
458                                 if (g_strcmp0(dns_type, "ipv6.manual") == 0)
459                                         net_info->DnsConfigType6 =
460                                                 NET_DNS_CONFIG_TYPE_STATIC;
461                                 else if (g_strcmp0(dns_type, "ipv6.dhcp") == 0)
462                                         net_info->DnsConfigType6 =
463                                                 NET_DNS_CONFIG_TYPE_DYNAMIC;
464                                 g_free(dns_type);
465                         }
466                 }
467                 g_variant_iter_free(iter);
468
469                 net_info->DnsCount = dnsCount;
470                 net_info->DnsCount6 = dnsCount6;
471         } else if (g_strcmp0(key, "Nameservers.Configuration") == 0 && net_info->DnsCount == 0) {
472                 int dnsCount = 0;
473                 int dnsCount6 = 0;
474                 gchar *dns_value = NULL;
475                 gchar *dns_type = NULL;
476
477                 g_variant_get(variant, "as", &iter);
478
479                 while (g_variant_iter_loop(iter, "s", &dns_value)) {
480                         if (__net_check_address_type(AF_INET6, dns_value)) {
481                                 if (dnsCount6 < NET_DNS_ADDR_MAX) {
482                                         net_info->DnsAddr6[dnsCount6].Type =
483                                                 NET_ADDR_IPV6;
484                                         inet_pton(AF_INET6, dns_value,
485                                                         &net_info->DnsAddr6[dnsCount6]\
486                                                         .Data.Ipv6);
487                                         dnsCount6++;
488                                 }
489                         } else if (__net_check_address_type(AF_INET, dns_value)) {
490                                 if (dnsCount < NET_DNS_ADDR_MAX) {
491                                         net_info->DnsAddr[dnsCount].Type =
492                                                 NET_ADDR_IPV4;
493                                         __net_extract_ip(dns_value,
494                                                         &net_info->DnsAddr[dnsCount]);
495                                         dnsCount++;
496                                 }
497                         } else { /* DNS Type */
498                                 dns_type = g_strdup(dns_value);
499                                 if (g_strcmp0(dns_type, "ipv4.manual") == 0)
500                                         net_info->DnsConfigType =
501                                                 NET_DNS_CONFIG_TYPE_STATIC;
502                                 else if (g_strcmp0(dns_type, "ipv4.dhcp") == 0)
503                                         net_info->DnsConfigType =
504                                                 NET_DNS_CONFIG_TYPE_DYNAMIC;
505                                 if (g_strcmp0(dns_type, "ipv6.manual") == 0)
506                                         net_info->DnsConfigType6 =
507                                                 NET_DNS_CONFIG_TYPE_STATIC;
508                                 else if (g_strcmp0(dns_type, "ipv6.dhcp") == 0)
509                                         net_info->DnsConfigType6 =
510                                                 NET_DNS_CONFIG_TYPE_DYNAMIC;
511                                 g_free(dns_type);
512                         }
513                 }
514                 g_variant_iter_free(iter);
515
516                 net_info->DnsCount = dnsCount;
517                 net_info->DnsCount6 = dnsCount6;
518         } else if (g_strcmp0(key, "Domains") == 0) {
519         } else if (g_strcmp0(key, "Domains.Configuration") == 0) {
520         } else if (g_strcmp0(key, "Proxy") == 0) {
521                 const gchar *url = NULL;
522                 gchar *servers = NULL;
523
524                 g_variant_get(variant, "a{sv}", &iter);
525                 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
526                         if (g_strcmp0(subKey, "Method") == 0) {
527                                 value = g_variant_get_string(var, NULL);
528
529                                 if (g_strcmp0(value, "direct") == 0)
530                                         net_info->ProxyMethod = NET_PROXY_TYPE_DIRECT;
531                                 else if (g_strcmp0(value, "auto") == 0)
532                                         net_info->ProxyMethod = NET_PROXY_TYPE_AUTO;
533                                 else if (g_strcmp0(value, "manual") == 0)
534                                         net_info->ProxyMethod = NET_PROXY_TYPE_MANUAL;
535                                 else
536                                         net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
537                         } else if (g_strcmp0(subKey, "URL") == 0) {
538                                 url = g_variant_get_string(var, NULL);
539                         } else if (g_strcmp0(subKey, "Servers") == 0) {
540                                 GVariantIter *iter_sub = NULL;
541
542                                 g_variant_get(var, "as", &iter_sub);
543                                 if (!g_variant_iter_loop(iter_sub, "s", &servers))
544                                         WIFI_LOG(WIFI_ERROR, "There was no value");
545                                 g_variant_iter_free(iter_sub);
546                         }
547                 }
548                 g_variant_iter_free(iter);
549
550                 if (net_info->ProxyMethod == NET_PROXY_TYPE_AUTO && url != NULL)
551                         g_strlcpy(net_info->ProxyAddr, url, NET_PROXY_LEN_MAX);
552                 else if (net_info->ProxyMethod == NET_PROXY_TYPE_MANUAL && servers != NULL)
553                         g_strlcpy(net_info->ProxyAddr, servers, NET_PROXY_LEN_MAX);
554
555                 if (servers)
556                         g_free(servers);
557         } else if (g_strcmp0(key, "Proxy.Configuration") == 0 &&
558                         net_info->ProxyMethod != NET_PROXY_TYPE_AUTO &&
559                         net_info->ProxyMethod != NET_PROXY_TYPE_MANUAL) {
560
561                 const gchar *url = NULL;
562                 gchar *servers = NULL;
563
564                 g_variant_get(variant, "a{sv}", &iter);
565                 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
566                         if (g_strcmp0(subKey, "Method") == 0) {
567                                 value = g_variant_get_string(var, NULL);
568
569                                 if (g_strcmp0(value, "direct") == 0)
570                                         net_info->ProxyMethod = NET_PROXY_TYPE_DIRECT;
571                                 else if (g_strcmp0(value, "auto") == 0)
572                                         net_info->ProxyMethod = NET_PROXY_TYPE_AUTO;
573                                 else if (g_strcmp0(value, "manual") == 0)
574                                         net_info->ProxyMethod = NET_PROXY_TYPE_MANUAL;
575                                 else
576                                         net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
577                         } else if (g_strcmp0(subKey, "URL") == 0) {
578                                 url = g_variant_get_string(var, NULL);
579                         } else if (g_strcmp0(subKey, "Servers") == 0) {
580                                 GVariantIter *iter_sub = NULL;
581
582                                 g_variant_get(var, "as", &iter_sub);
583                                 if (!g_variant_iter_loop(iter_sub, "s", &servers))
584                                         WIFI_LOG(WIFI_ERROR, "There was no value");
585
586                                 g_variant_iter_free(iter_sub);
587                         }
588                 }
589                 g_variant_iter_free(iter);
590
591                 if (net_info->ProxyMethod == NET_PROXY_TYPE_AUTO && url != NULL)
592                         g_strlcpy(net_info->ProxyAddr, url, NET_PROXY_LEN_MAX);
593                 else if (net_info->ProxyMethod == NET_PROXY_TYPE_MANUAL && servers != NULL)
594                         g_strlcpy(net_info->ProxyAddr, servers, NET_PROXY_LEN_MAX);
595
596                 if (servers)
597                         g_free(servers);
598         } else if (g_strcmp0(key, "Provider") == 0) {
599                 /* Do noting */
600         }
601
602         __NETWORK_FUNC_EXIT__;
603         return Error;
604 }
605
606 static wlan_eap_type_e __convert_eap_type_from_string(const char *eap_type)
607 {
608         if (eap_type == NULL)
609                 return WLAN_SEC_EAP_TYPE_PEAP;
610         else if (g_strcmp0(eap_type, "peap") == 0)
611                 return WLAN_SEC_EAP_TYPE_PEAP;
612         else if (g_strcmp0(eap_type, "tls") == 0)
613                 return WLAN_SEC_EAP_TYPE_TLS;
614         else if (g_strcmp0(eap_type, "ttls") == 0)
615                 return WLAN_SEC_EAP_TYPE_TTLS;
616         else if (g_strcmp0(eap_type, "sim") == 0)
617                 return WLAN_SEC_EAP_TYPE_SIM;
618         else if (g_strcmp0(eap_type, "aka") == 0)
619                 return WLAN_SEC_EAP_TYPE_AKA;
620         else
621                 return WLAN_SEC_EAP_TYPE_PEAP;
622 }
623
624 static wlan_eap_auth_type_e __convert_eap_auth_from_string(const char *eap_auth)
625 {
626         if (eap_auth == NULL)
627                 return WLAN_SEC_EAP_AUTH_NONE;
628         else if (g_strcmp0(eap_auth, "NONE") == 0)
629                 return WLAN_SEC_EAP_AUTH_NONE;
630         else if (g_strcmp0(eap_auth, "PAP") == 0)
631                 return WLAN_SEC_EAP_AUTH_PAP;
632         else if (g_strcmp0(eap_auth, "MSCHAP") == 0)
633                 return WLAN_SEC_EAP_AUTH_MSCHAP;
634         else if (g_strcmp0(eap_auth, "MSCHAPV2") == 0)
635                 return WLAN_SEC_EAP_AUTH_MSCHAPV2;
636         else if (g_strcmp0(eap_auth, "GTC") == 0)
637                 return WLAN_SEC_EAP_AUTH_GTC;
638         else if (g_strcmp0(eap_auth, "MD5") == 0)
639                 return WLAN_SEC_EAP_AUTH_MD5;
640         else
641                 return WLAN_SEC_EAP_AUTH_NONE;
642 }
643
644 static int __net_wifi_modify_profile(network_info_s *network_info,
645                 const char* ProfileName, net_profile_info_s* ProfInfo,
646                 net_profile_info_s* exProfInfo)
647 {
648         __NETWORK_FUNC_ENTER__;
649
650         net_err_e Error = NET_ERR_NONE;
651         int i = 0;
652         char profilePath[NET_PROFILE_NAME_LEN_MAX+1] = "";
653
654         wlan_security_info_s *security_info = &(ProfInfo->security_info);
655         wlan_security_info_s *ex_security_info = &(exProfInfo->security_info);
656         net_dev_info_s *net_info = &(ProfInfo->net_info);
657         net_dev_info_s *ex_net_info = &(exProfInfo->net_info);
658
659         g_strlcpy(profilePath, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
660
661         /* Compare and Set 'Passphrase' */
662         if (ex_security_info->sec_mode == WLAN_SEC_MODE_WEP) {
663                 if (g_strcmp0(security_info->authentication.wep.wepKey,
664                                                 ex_security_info->authentication.wep.wepKey) != 0) {
665                         Error = _net_dbus_set_agent_passphrase_and_connect(network_info,
666                                         security_info->authentication.wep.wepKey, ProfileName);
667
668                         if (NET_ERR_NONE != Error) {
669                                 WIFI_LOG(WIFI_ERROR, "Failed to set agent field");
670
671                                 __NETWORK_FUNC_EXIT__;
672                                 return Error;
673                         }
674                 }
675         } else if (ex_security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
676                         ex_security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) {
677                 if (g_strcmp0(security_info->authentication.psk.pskKey,
678                                 ex_security_info->authentication.psk.pskKey) != 0) {
679                         Error = _net_dbus_set_agent_passphrase_and_connect(network_info,
680                                         security_info->authentication.psk.pskKey, ProfileName);
681
682                         if (NET_ERR_NONE != Error) {
683                                 WIFI_LOG(WIFI_ERROR, "Failed to set agent field");
684
685                                 __NETWORK_FUNC_EXIT__;
686                                 return Error;
687                         }
688                 }
689         }
690
691         /* Compare and Set 'Proxy' */
692         if ((ex_net_info->ProxyMethod != net_info->ProxyMethod) ||
693             (g_strcmp0(ex_net_info->ProxyAddr, net_info->ProxyAddr) != 0)) {
694
695                 Error = _net_dbus_set_proxy(network_info, ProfInfo, profilePath);
696                 if (Error != NET_ERR_NONE) {
697                         __NETWORK_FUNC_EXIT__;
698                         return Error;
699                 }
700         }
701
702         /* Compare and Set 'IPv4 addresses' */
703         if ((ex_net_info->IpConfigType != net_info->IpConfigType) ||
704                 (net_info->IpConfigType == NET_IP_CONFIG_TYPE_STATIC &&
705                 (net_info->IpAddr.Data.Ipv4.s_addr != ex_net_info->IpAddr.Data.Ipv4.s_addr ||
706                 net_info->SubnetMask.Data.Ipv4.s_addr != ex_net_info->SubnetMask.Data.Ipv4.s_addr ||
707                 net_info->GatewayAddr.Data.Ipv4.s_addr != ex_net_info->GatewayAddr.Data.Ipv4.s_addr))) {
708
709                 Error = _net_dbus_set_profile_ipv4(network_info, ProfInfo, profilePath);
710
711                 if (Error != NET_ERR_NONE) {
712                         WIFI_LOG(WIFI_ERROR, "Failed to set IPv4");
713
714                         __NETWORK_FUNC_EXIT__;
715                         return Error;
716                 }
717         }
718
719         /* Compare and Set 'IPv6 addresses' */
720         if ((ex_net_info->IpConfigType6 != net_info->IpConfigType6) ||
721             (net_info->IpConfigType6 == NET_IP_CONFIG_TYPE_STATIC &&
722              (net_info->IpAddr6.Data.Ipv6.s6_addr != ex_net_info->IpAddr6.Data.Ipv6.s6_addr ||
723               net_info->PrefixLen6 != ex_net_info->PrefixLen6 ||
724               net_info->GatewayAddr6.Data.Ipv6.s6_addr != ex_net_info->GatewayAddr6.Data.Ipv6.s6_addr))) {
725
726                 Error = _net_dbus_set_profile_ipv6(network_info, ProfInfo, profilePath);
727
728                 if (Error != NET_ERR_NONE) {
729                         WIFI_LOG(WIFI_ERROR,  "Error!!! Can't set IPv6");
730
731                         __NETWORK_FUNC_EXIT__;
732                         return Error;
733                 }
734         }
735
736         /* Compare and Set 'DNS addresses' */
737         for (i = 0; i < net_info->DnsCount; i++) {
738                 if (i >= NET_DNS_ADDR_MAX) {
739                         net_info->DnsCount = NET_DNS_ADDR_MAX;
740
741                         break;
742                 }
743
744                 if (net_info->DnsAddr[i].Data.Ipv4.s_addr !=
745                         ex_net_info->DnsAddr[i].Data.Ipv4.s_addr)
746                         break;
747         }
748
749         if (i < net_info->DnsCount ||
750                         ex_net_info->DnsConfigType != net_info->DnsConfigType ||
751                         ex_net_info->DnsConfigType6 != net_info->DnsConfigType6) {
752
753                 Error = _net_dbus_set_profile_dns(network_info, ProfInfo, profilePath);
754
755                 if (Error != NET_ERR_NONE) {
756                         WIFI_LOG(WIFI_ERROR, "Failed to set DNS");
757
758                         __NETWORK_FUNC_EXIT__;
759                         return Error;
760                 }
761         }
762
763         __NETWORK_FUNC_EXIT__;
764         return NET_ERR_NONE;
765 }
766
767 static int __net_wifi_delete_profile(network_info_s *network_info,
768                 net_profile_name_s* WifiProfName, wlan_security_mode_type_e sec_mode,
769                 gboolean passpoint)
770 {
771         __NETWORK_FUNC_ENTER__;
772
773         net_err_e Error = NET_ERR_NONE;
774         GVariant *message = NULL;
775         char param0[NET_PROFILE_NAME_LEN_MAX + 8] = "";
776         GVariant *params;
777
778         if (passpoint == TRUE && WLAN_SEC_MODE_IEEE8021X == sec_mode) {
779                 message = _net_invoke_dbus_method(network_info,
780                                 CONNMAN_SERVICE, WifiProfName->ProfileName,
781                                 CONNMAN_SERVICE_INTERFACE, "Remove",
782                                 NULL, &Error);
783
784                 if (message == NULL) {
785                         WIFI_LOG(WIFI_ERROR, "Failed to Remove service(profile)");
786                         g_variant_unref(message);
787                         goto done;
788                 }
789
790                 g_variant_unref(message);
791
792                 g_snprintf(param0, NET_PROFILE_NAME_LEN_MAX + 8, "string:%s",
793                                 WifiProfName->ProfileName);
794                 params = g_variant_new("(s)", param0);
795
796                 message = _net_invoke_dbus_method(network_info,
797                                 NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
798                                 NETCONFIG_WIFI_INTERFACE, "DeleteEapConfig",
799                                 params, &Error);
800         } else if (passpoint == TRUE || WLAN_SEC_MODE_IEEE8021X != sec_mode) {
801                 message = _net_invoke_dbus_method(network_info,
802                                 CONNMAN_SERVICE, WifiProfName->ProfileName,
803                                 CONNMAN_SERVICE_INTERFACE, "Remove",
804                                 NULL, &Error);
805         } else {
806                 g_snprintf(param0, NET_PROFILE_NAME_LEN_MAX + 8, "string:%s",
807                                 WifiProfName->ProfileName);
808                 params = g_variant_new("(s)", param0);
809
810                 message = _net_invoke_dbus_method(network_info,
811                                 NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
812                                 NETCONFIG_WIFI_INTERFACE, "DeleteEapConfig",
813                                 params, &Error);
814         }
815
816         if (message == NULL) {
817                 WIFI_LOG(WIFI_ERROR, "Failed to Remove service(profile)");
818                 goto done;
819         }
820
821         g_variant_unref(message);
822 done:
823         __NETWORK_FUNC_EXIT__;
824         return Error;
825 }
826
827 static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* ProfInfo)
828 {
829         net_err_e Error = NET_ERR_NONE;
830         GVariant *var = NULL;
831         const gchar *key = NULL;
832
833         __NETWORK_FUNC_ENTER__;
834
835         while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
836                 const gchar *value = NULL;
837
838                 if (g_strcmp0(key, "Mode") == 0) {
839                         value = g_variant_get_string(var, NULL);
840
841                         if (g_strcmp0(value, "managed") == 0)
842                                 ProfInfo->wlan_mode = NET_WLAN_CONNMODE_INFRA;
843                         else if (g_strcmp0(value, "adhoc") == 0)
844                                 ProfInfo->wlan_mode = NET_WLAN_CONNMODE_ADHOC;
845                         else
846                                 ProfInfo->wlan_mode = NET_WLAN_CONNMODE_AUTO;
847
848                 } else if (g_strcmp0(key, "Security") == 0) {
849                         GVariantIter *iter_sub = NULL;
850
851                         g_variant_get(var, "as", &iter_sub);
852                         while (g_variant_iter_loop(iter_sub, "s", &value)) {
853                                 if (g_strcmp0(value, "none") == 0 &&
854                                         ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_NONE)
855                                         ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_NONE;
856                                 else if (g_strcmp0(value, "wep") == 0 &&
857                                                  ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_WEP)
858                                         ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_WEP;
859                                 else if (g_strcmp0(value, "psk") == 0 &&
860                                                  ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
861                                         ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
862                                 else if (g_strcmp0(value, "ft_psk") == 0 &&
863                                         ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_WPA_FT_PSK)
864                                         ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_WPA_FT_PSK;
865                                 else if (g_strcmp0(value, "ieee8021x") == 0 &&
866                                                  ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_IEEE8021X)
867                                         ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_IEEE8021X;
868                                 else if (g_strcmp0(value, "wpa") == 0 &&
869                                                  ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
870                                         ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
871                                 else if (g_strcmp0(value, "rsn") == 0 &&
872                                                  ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
873                                         ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK;
874                                 else if (g_strcmp0(value, "sae") == 0 &&
875                                                  ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_SAE)
876                                         ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_SAE;
877                                 else if (g_strcmp0(value, "owe") == 0 &&
878                                                  ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_SAE)
879                                         ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_OWE;
880                                 else if (g_strcmp0(value, "dpp") == 0 &&
881                                                  ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_SAE)
882                                         ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_DPP;
883                                 else if (g_strcmp0(value, "wps") == 0)
884                                         ProfInfo->security_info.wps_support = TRUE;
885                                 else if (ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_NONE)
886                                         ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_NONE;
887                         }
888                         g_variant_iter_free(iter_sub);
889                 } else if (g_strcmp0(key, "EncryptionMode") == 0) {
890                         value = g_variant_get_string(var, NULL);
891
892                         if (g_strcmp0(value, "none") == 0)
893                                 ProfInfo->security_info.enc_mode = WLAN_ENC_MODE_NONE;
894                         else if (g_strcmp0(value, "wep") == 0)
895                                 ProfInfo->security_info.enc_mode = WLAN_ENC_MODE_WEP;
896                         else if (g_strcmp0(value, "tkip") == 0)
897                                 ProfInfo->security_info.enc_mode = WLAN_ENC_MODE_TKIP;
898                         else if (g_strcmp0(value, "aes") == 0)
899                                 ProfInfo->security_info.enc_mode = WLAN_ENC_MODE_AES;
900                         else if (g_strcmp0(value, "mixed") == 0)
901                                 ProfInfo->security_info.enc_mode = WLAN_ENC_MODE_TKIP_AES_MIXED;
902
903                 } else if (g_strcmp0(key, "Passpoint") == 0) {
904                         gboolean passpoint;
905
906                         passpoint = g_variant_get_boolean(var);
907                         if (passpoint)
908                                 ProfInfo->passpoint = TRUE;
909                         else
910                                 ProfInfo->passpoint = FALSE;
911
912                 } else if (g_strcmp0(key, "Strength") == 0) {
913                         ProfInfo->Strength = g_variant_get_byte(var);
914                 } else if (g_strcmp0(key, "Name") == 0) {
915                         value = g_variant_get_string(var, NULL);
916
917                         if (value != NULL)
918                                 g_strlcpy(ProfInfo->essid, value, NET_WLAN_ESSID_LEN + 1);
919                 } else if (g_strcmp0(key, "Passphrase") == 0) {
920                         wlan_security_info_s *security_info = &(ProfInfo->security_info);
921                         value = g_variant_get_string(var, NULL);
922
923                         if (security_info->sec_mode == WLAN_SEC_MODE_WEP && value != NULL)
924                                 g_strlcpy(security_info->authentication.wep.wepKey,
925                                                 value, NET_WLAN_MAX_WEP_KEY_LEN+1);
926                         else if ((security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
927                                                 security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) &&
928                                                 value != NULL)
929                                 g_strlcpy(security_info->authentication.psk.pskKey,
930                                                 value, NET_WLAN_MAX_PSK_PASSPHRASE_LEN+1);
931                 } else if (g_strcmp0(key, "PassphraseRequired") == 0) {
932                         gboolean val;
933
934                         val = g_variant_get_boolean(var);
935
936                         if (val)
937                                 ProfInfo->PassphraseRequired = TRUE;
938                         else
939                                 ProfInfo->PassphraseRequired = FALSE;
940                 } else if (g_strcmp0(key, "SSID") == 0) {
941                         const gchar *ssid = NULL;
942                         gsize ssid_len;
943                         ssid = g_variant_get_fixed_array(var, &ssid_len, sizeof(guchar));
944                         memcpy(ProfInfo->raw_ssid, ssid, ssid_len);
945                         ProfInfo->raw_ssid_len = ssid_len;
946                 } else if (g_strcmp0(key, "BSSID") == 0) {
947                         value = g_variant_get_string(var, NULL);
948
949                         if (value != NULL)
950                                 g_strlcpy(ProfInfo->bssid, value, WIFI_MAC_ADDR_LEN + 1);
951
952                 } else if (g_strcmp0(key, "MaxSpeed") == 0) {
953                         ProfInfo->max_rate = g_variant_get_int32(var);
954
955                 } else if (g_strcmp0(key, "Frequency") == 0) {
956                         ProfInfo->frequency = (unsigned int)g_variant_get_uint16(var);
957                 } else if (g_strcmp0(key, "Protocol") == 0) {
958                         value = g_variant_get_string(var, NULL);
959                         if (value != NULL)
960                                 g_strlcpy(ProfInfo->operation_mode, value, NET_MAX_PROTOCOL_LEN+1);
961                 } else if (g_strcmp0(key, "ConnMode") == 0) {
962                         ProfInfo->connection_mode = (unsigned int)g_variant_get_uint16(var);
963
964                 } else if (g_strcmp0(key, "Vsie") == 0) {
965                         const unsigned char *vsie_bytes = NULL;
966                         unsigned char *vsie = NULL;
967                         gsize size;
968
969                         vsie_bytes = g_variant_get_fixed_array(var, &size, sizeof(guchar));
970
971                         if (vsie_bytes) {
972                                 vsie = (unsigned char *)g_try_malloc0(size);
973                                 if (vsie) {
974                                         memcpy(vsie, vsie_bytes, size);
975                                         ProfInfo->vsie_list = g_slist_append(ProfInfo->vsie_list, vsie);
976                                 } else
977                                         WIFI_LOG(WIFI_ERROR, "Failed to allocate memory.");
978                         }
979                 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
980                         ProfInfo->disconnect_reason = g_variant_get_int32(var);
981
982                 } else if (g_strcmp0(key, "AssocStatusCode") == 0) {
983                         ProfInfo->assoc_status_code = g_variant_get_int32(var);
984
985                 } else if (g_strcmp0(key, "EAP") == 0) {
986                         value = g_variant_get_string(var, NULL);
987
988                         if (value != NULL)
989                                 ProfInfo->security_info.authentication.eap.eap_type =
990                                                 __convert_eap_type_from_string(value);
991
992                 } else if (g_strcmp0(key, "Phase2") == 0) {
993                         value = g_variant_get_string(var, NULL);
994
995                         if (value != NULL)
996                                 ProfInfo->security_info.authentication.eap.eap_auth =
997                                                 __convert_eap_auth_from_string(value);
998
999                 } else if (g_strcmp0(key, "Identity") == 0) {
1000                         value = g_variant_get_string(var, NULL);
1001
1002                         if (value != NULL)
1003                                 g_strlcpy(ProfInfo->security_info.authentication.eap.username,
1004                                                 value, NET_WLAN_USERNAME_LEN+1);
1005
1006                 } else if (g_strcmp0(key, "Password") == 0) {
1007                         value = g_variant_get_string(var, NULL);
1008
1009                         if (value != NULL)
1010                                 g_strlcpy(ProfInfo->security_info.authentication.eap.password,
1011                                                 value, NET_WLAN_PASSWORD_LEN+1);
1012
1013                 } else if (g_strcmp0(key, "CACertFile") == 0) {
1014                         value = g_variant_get_string(var, NULL);
1015
1016                         if (value != NULL)
1017                                 g_strlcpy(ProfInfo->security_info.authentication.eap.ca_cert_filename,
1018                                                 value, NET_WLAN_CA_CERT_FILENAME_LEN+1);
1019
1020                 } else if (g_strcmp0(key, "ClientCertFile") == 0) {
1021                         value = g_variant_get_string(var, NULL);
1022
1023                         if (value != NULL)
1024                                 g_strlcpy(ProfInfo->security_info.authentication.eap.client_cert_filename,
1025                                                 value, NET_WLAN_CLIENT_CERT_FILENAME_LEN+1);
1026
1027                 } else if (g_strcmp0(key, "PrivateKeyFile") == 0) {
1028                         value = g_variant_get_string(var, NULL);
1029
1030                         if (value != NULL)
1031                                 g_strlcpy(ProfInfo->security_info.authentication.eap.private_key_filename,
1032                                                 value, NET_WLAN_PRIVATE_KEY_FILENAME_LEN+1);
1033
1034                 } else if (g_strcmp0(key, "PrivateKeyPassphrase") == 0) {
1035                         value = g_variant_get_string(var, NULL);
1036
1037                         if (value != NULL)
1038                                 g_strlcpy(ProfInfo->security_info.authentication.eap.private_key_passwd,
1039                                                 value, NET_WLAN_PRIVATE_KEY_PASSWD_LEN+1);
1040
1041                 } else if (g_strcmp0(key, "Keymgmt") == 0) {
1042                         ProfInfo->security_info.keymgmt = (unsigned int)g_variant_get_uint32(var);
1043                 } else if (g_strcmp0(key, "Country") == 0) {
1044                         value = g_variant_get_string(var, NULL);
1045
1046                         if (value != NULL)
1047                                 g_strlcpy(ProfInfo->country_code, value, NET_WLAN_COUNTRY_CODE_LEN);
1048                 } else if (g_strcmp0(key, "BSSID.List") == 0) {
1049                         GVariantIter *iter_sub = NULL;
1050                         net_profile_bssid_list_s *bssid_list = NULL;
1051                         gchar *bssid_key = NULL;
1052                         GVariant *bssid_var = NULL;
1053                         g_variant_get(var, "a{sv}", &iter_sub);
1054
1055                         while (g_variant_iter_loop(iter_sub, "{sv}", &bssid_key,
1056                                                                            &bssid_var)) {
1057                                 if (g_strcmp0(bssid_key, "BSSID") == 0) {
1058                                         bssid_list = (net_profile_bssid_list_s *)g_try_malloc0(sizeof(net_profile_bssid_list_s));
1059
1060                                         if (bssid_list) {
1061                                                 value = g_variant_get_string(bssid_var, NULL);
1062
1063                                                 if (value != NULL)
1064                                                         g_strlcpy(bssid_list->bssid, value, 18);
1065                                                 else
1066                                                         WIFI_LOG(WIFI_ERROR, "Value is empty");
1067                                         } else {
1068                                                 WIFI_LOG(WIFI_ERROR, "Failed to allocate memory.");
1069                                                 g_variant_unref(bssid_var);
1070                                                 g_free(bssid_key);
1071                                                 break;
1072                                         }
1073                                 } else if (bssid_list && g_strcmp0(bssid_key, "Strength") == 0) {
1074                                         bssid_list->strength = (int)g_variant_get_uint16(bssid_var);
1075                                 } else if (bssid_list && g_strcmp0(bssid_key, "Frequency") == 0) {
1076                                         bssid_list->frequency = (int)g_variant_get_uint16(bssid_var);
1077                                         ProfInfo->bssid_list = g_slist_append(ProfInfo->bssid_list,
1078                                                                                                                   bssid_list);
1079                                 }
1080                         }
1081                         g_variant_iter_free(iter_sub);
1082                 } else if (g_strcmp0(key, "Hidden") == 0) {
1083                         ProfInfo->ap_hidden_status = g_variant_get_boolean(var);
1084                 } else
1085                         Error = __net_extract_common_info(key, var, ProfInfo);
1086         }
1087
1088         __NETWORK_FUNC_EXIT__;
1089         return Error;
1090 }
1091
1092 static int __net_extract_service_info(network_info_s *network_info,
1093                 const char* ProfileName, GVariantIter *iter,
1094                 net_profile_info_s* ProfInfo)
1095 {
1096         __NETWORK_FUNC_ENTER__;
1097
1098         net_err_e Error = NET_ERR_NONE;
1099         gchar *key = NULL;
1100         GVariant *value = NULL;
1101         gboolean isProf = FALSE;
1102
1103         while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
1104                 const gchar *tech = NULL;
1105
1106                 if (g_strcmp0(key, "Type") == 0) {
1107                         tech = g_variant_get_string(value, NULL);
1108
1109                         if (g_strcmp0(tech, "wifi") == 0)
1110                                 isProf = TRUE;
1111
1112                         g_variant_unref(value);
1113                         g_free(key);
1114                         break;
1115                 }
1116         }
1117
1118         if (isProf) {
1119                 if ((Error = net_init_profile_info(network_info, ProfInfo)) != NET_ERR_NONE) {
1120                         WIFI_LOG(WIFI_ERROR, "Failed to init profile");
1121                         __NETWORK_FUNC_EXIT__;
1122                         return Error;
1123                 }
1124
1125                 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX + 1);
1126                 g_strlcpy(ProfInfo->net_info.ProfileName,
1127                                 ProfileName, NET_PROFILE_NAME_LEN_MAX + 1);
1128
1129                 Error = __net_extract_wifi_info(iter, ProfInfo);
1130         }
1131
1132         __NETWORK_FUNC_EXIT__;
1133         return Error;
1134 }
1135
1136 static int __net_extract_all_services(network_info_s *network_info,
1137                 GVariantIter *array, const char *service_prefix, GSList **profile_list)
1138 {
1139         net_profile_info_s *ProfInfo = NULL;
1140         net_err_e Error = NET_ERR_NONE;
1141         gchar *obj;
1142         GVariantIter *next = NULL;
1143
1144         __NETWORK_FUNC_ENTER__;
1145
1146         if (array == NULL || service_prefix == NULL) {
1147                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
1148
1149                 __NETWORK_FUNC_EXIT__;
1150                 return NET_ERR_INVALID_PARAM;
1151         }
1152
1153         while (g_variant_iter_loop(array, "(oa{sv})", &obj, &next)) {
1154                 if (obj == NULL)
1155                         continue;
1156
1157                 if (_net_check_service_mac_addr(network_info, obj) != TRUE)
1158                         continue;
1159
1160                 if (g_str_has_prefix(obj, service_prefix) == TRUE) {
1161                         ProfInfo = g_try_malloc0(sizeof(net_profile_info_s));
1162                         if (ProfInfo == NULL)
1163                                 goto error;
1164
1165                         if ((Error = net_init_profile_info(network_info, ProfInfo)) != NET_ERR_NONE) {
1166                                 WIFI_LOG(WIFI_ERROR, "Failed to init profile");
1167                                 goto error;
1168                         }
1169
1170                         if (g_strrstr(obj + strlen(service_prefix), "hidden") != NULL)
1171                                 ProfInfo->is_hidden = TRUE;
1172
1173                         g_strlcpy(ProfInfo->ProfileName, obj, NET_PROFILE_NAME_LEN_MAX + 1);
1174
1175                         g_strlcpy(ProfInfo->net_info.ProfileName,
1176                                         obj, NET_PROFILE_NAME_LEN_MAX + 1);
1177
1178                         Error = __net_extract_wifi_info(next, ProfInfo);
1179
1180                         if (Error != NET_ERR_NONE) {
1181                                 WIFI_LOG(WIFI_ERROR, "Failed to extract service info");
1182                                 goto error;
1183                         }
1184
1185                         *profile_list = g_slist_append(*profile_list, (net_profile_info_s *)ProfInfo);
1186                 }
1187         }
1188
1189         __NETWORK_FUNC_EXIT__;
1190         return NET_ERR_NONE;
1191
1192 error:
1193         if (next)
1194                 g_variant_iter_free(next);
1195         if (obj)
1196                 g_free(obj);
1197         if (ProfInfo)
1198                 g_free(ProfInfo);
1199         __NETWORK_FUNC_EXIT__;
1200         return Error;
1201 }
1202
1203 static int __net_extract_services(network_info_s *network_info,
1204                 GVariantIter *message, GSList **profile_list)
1205 {
1206         __NETWORK_FUNC_ENTER__;
1207
1208         net_err_e Error = NET_ERR_NONE;
1209         char *service_prefix = NULL;
1210
1211         service_prefix = CONNMAN_WIFI_SERVICE_PROFILE_PREFIX;
1212
1213         Error = __net_extract_all_services(network_info,
1214                 message, service_prefix, profile_list);
1215         if (Error != NET_ERR_NONE) {
1216                 WIFI_LOG(WIFI_ERROR, "Failed to extract services from received message");
1217                 __NETWORK_FUNC_EXIT__;
1218                 return Error;
1219         }
1220
1221         __NETWORK_FUNC_EXIT__;
1222         return Error;
1223 }
1224
1225 static int __net_get_profile_info(network_info_s *network_info,
1226                 const char *ProfileName, net_profile_info_s *ProfInfo)
1227 {
1228         __NETWORK_FUNC_ENTER__;
1229
1230         net_err_e Error = NET_ERR_NONE;
1231         GVariant *message = NULL;
1232         GVariantIter *iter = NULL;
1233         GVariantIter *service = NULL;
1234         gchar *path = NULL;
1235
1236         message = _net_invoke_dbus_method(network_info,
1237                         CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
1238                         CONNMAN_MANAGER_INTERFACE, "GetServices",
1239                         NULL, &Error);
1240         if (message == NULL) {
1241                 WIFI_LOG(WIFI_ERROR, "Failed to get profile");
1242                 goto done;
1243         }
1244
1245         Error = NET_ERR_NO_PROFILE;
1246         g_variant_get(message, "(a(oa{sv}))", &iter);
1247         while (g_variant_iter_loop(iter, "(oa{sv})", &path, &service)) {
1248                 if (g_strcmp0(ProfileName, path) == 0) {
1249                         Error = __net_extract_service_info(network_info,
1250                                 ProfileName, service, ProfInfo);
1251                         g_variant_iter_free(service);
1252                         g_free(path);
1253                         break;
1254                 }
1255         }
1256
1257         g_variant_iter_free(iter);
1258         g_variant_unref(message);
1259
1260 done:
1261         __NETWORK_FUNC_EXIT__;
1262         return Error;
1263 }
1264
1265 static net_err_e __net_get_wifi_state(network_info_s *network_info)
1266 {
1267         net_err_e err = NET_ERR_NONE;
1268
1269         if (network_info->wifi_state == WIFI_UNKNOWN ||
1270                 network_info->wifi_state == WIFI_OFF) {
1271                 err = _net_get_wifi_state(network_info);
1272         }
1273
1274         return err;
1275 }
1276
1277 void net_forget_ap_finished(network_info_s *network_info, net_err_e Error)
1278 {
1279         __NETWORK_FUNC_ENTER__;
1280
1281         net_event_info_s *event_data = NULL;
1282         char event_string[64];
1283
1284         if (network_info->request_table[NETWORK_REQUEST_TYPE_FORGET_AP].flag == FALSE) {
1285                 __NETWORK_FUNC_EXIT__;
1286                 return;
1287         }
1288
1289         memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_FORGET_AP]), 0,
1290                sizeof(network_request_table_s));
1291
1292         event_data = g_try_malloc0(sizeof(net_event_info_s));
1293         if (event_data == NULL) {
1294                 __NETWORK_FUNC_EXIT__;
1295                 return;
1296         }
1297
1298         event_data->Event = NET_EVENT_WIFI_FORGET_AP_IND;
1299         g_strlcpy(event_string, "Sending NET_EVENT_WIFI_FORGET_AP_IND", 64);
1300
1301         event_data->Error = Error;
1302         event_data->Datalength = 0;
1303         event_data->Data = NULL;
1304
1305         WIFI_LOG(WIFI_INFO, "%s, Error: %d", event_string, event_data->Error);
1306
1307         if (network_info->event_callback)
1308                 network_info->event_callback(event_data, network_info->user_data);
1309
1310         g_free(event_data);
1311
1312         __NETWORK_FUNC_EXIT__;
1313 }
1314 //LCOV_EXCL_STOP
1315
1316 int _net_check_profile_name(const char* ProfileName)
1317 {
1318         __NETWORK_FUNC_ENTER__;
1319
1320         const char *profileHeader = CONNMAN_PATH"/service/";
1321         int i = 0;
1322         int stringLen = 0;
1323
1324         if (ProfileName == NULL || strlen(ProfileName) <= strlen(profileHeader)) {
1325                 WIFI_LOG(WIFI_ERROR, "Profile name is invalid"); //LCOV_EXCL_LINE
1326                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1327                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
1328         }
1329
1330         stringLen = strlen(ProfileName);
1331
1332         if (strncmp(profileHeader, ProfileName, strlen(profileHeader)) == 0) {
1333                 for (i = 0; i < stringLen; i++) {
1334                         if (isgraph(ProfileName[i]) == 0) {
1335                                 WIFI_LOG(WIFI_ERROR, "Profile name is invalid"); //LCOV_EXCL_LINE
1336                                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1337                                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
1338                         }
1339                 }
1340         } else {
1341                 WIFI_LOG(WIFI_ERROR, "Profile name is invalid"); //LCOV_EXCL_LINE
1342                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1343                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
1344         }
1345
1346         __NETWORK_FUNC_EXIT__;
1347         return NET_ERR_NONE;
1348 }
1349
1350 gboolean _net_check_service_mac_addr(network_info_s *network_info, const char* service)
1351 {
1352         __NETWORK_FUNC_ENTER__;
1353         const char *service_header = CONNMAN_WIFI_SERVICE_PROFILE_PREFIX;
1354         const char *org = NULL;
1355         const char *dst = NULL;
1356         int service_index = 0;
1357         int mac_index = 0;
1358         int i = 0;
1359
1360         service_index = strlen(service_header);
1361         for (i = 0; i < 6; i++) {
1362                 org = &service[service_index];
1363                 dst = &network_info->mac_address[mac_index];
1364
1365                 if (g_ascii_strncasecmp(org, dst, 2) != 0)
1366                         return FALSE;
1367
1368                 service_index += 2;
1369                 mac_index += 3;
1370         }
1371
1372         __NETWORK_FUNC_EXIT__;
1373         return TRUE;
1374 }
1375
1376 int _net_get_interface_list(network_info_s *network_info, GSList **interface_list)
1377 {
1378         __NETWORK_FUNC_ENTER__;
1379
1380         net_err_e Error = NET_ERR_NONE;
1381         GVariant *message;
1382         GVariantIter *iter;
1383         gchar *interface_name = NULL;
1384
1385         message = _net_invoke_dbus_method(network_info,
1386                         CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PATH,
1387                         CONNMAN_TECHNOLOGY_INTERFACE, "GetInterfaces",
1388                         NULL, &Error);
1389         if (message == NULL) {
1390                 WIFI_LOG(WIFI_ERROR, "Failed to get interface list"); //LCOV_EXCL_LINE
1391                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1392                 return Error; //LCOV_EXCL_LINE
1393         }
1394
1395         g_variant_get(message, "(as)", &iter);
1396         while (g_variant_iter_loop(iter, "s", &interface_name)) {
1397                 WIFI_LOG(WIFI_INFO, "Ifname [%s]", interface_name);
1398                 *interface_list = g_slist_append(*interface_list, g_strdup(interface_name));
1399         }
1400
1401         g_variant_iter_free(iter);
1402         g_variant_unref(message);
1403
1404         __NETWORK_FUNC_EXIT__;
1405         return Error;
1406 }
1407
1408 int _net_get_profile_list(network_info_s *network_info, GSList **profile_list)
1409 {
1410         __NETWORK_FUNC_ENTER__;
1411
1412         net_err_e Error = NET_ERR_NONE;
1413         GVariant *message;
1414         GVariantIter *iter;
1415
1416         message = _net_invoke_dbus_method(network_info,
1417                         CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
1418                         CONNMAN_MANAGER_INTERFACE, "GetServices",
1419                         NULL, &Error);
1420         if (message == NULL) {
1421                 WIFI_LOG(WIFI_ERROR, "Failed to get service(profile) list"); //LCOV_EXCL_LINE
1422                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1423                 return Error; //LCOV_EXCL_LINE
1424         }
1425
1426         g_variant_get(message, "(a(oa{sv}))", &iter);
1427         Error = __net_extract_services(network_info, iter, profile_list);
1428
1429         if (iter != NULL)
1430                 g_variant_iter_free(iter);
1431
1432         g_variant_unref(message);
1433
1434         __NETWORK_FUNC_EXIT__;
1435         return Error;
1436 }
1437
1438 int net_init_profile_info(network_info_s *network_info, net_profile_info_s *ProfInfo)
1439 {
1440         int i = 0;
1441         net_dev_info_s *net_info = NULL;
1442
1443         if (ProfInfo == NULL) {
1444                 WIFI_LOG(WIFI_ERROR, "Invalid Parameter"); //LCOV_EXCL_LINE
1445                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
1446         }
1447
1448         memset(ProfInfo, 0, sizeof(net_profile_info_s));
1449         ProfInfo->Favourite = (char)FALSE;
1450
1451         ProfInfo->Strength = 0;
1452         ProfInfo->frequency = 0;
1453         ProfInfo->max_rate = 0;
1454         ProfInfo->wlan_mode = 0;
1455         ProfInfo->PassphraseRequired = FALSE;
1456         ProfInfo->security_info.sec_mode = 0;
1457         ProfInfo->security_info.enc_mode = 0;
1458         ProfInfo->security_info.wps_support = FALSE;
1459         ProfInfo->disconnect_reason = WIFI_REASON_UNSPECIFIED;
1460         ProfInfo->assoc_status_code = 0;
1461
1462         ProfInfo->network_info = network_info;
1463
1464         net_info = &(ProfInfo->net_info);
1465
1466         net_info->DnsCount = 0;
1467
1468         for (i = 0; i < NET_DNS_ADDR_MAX; i++) {
1469                 net_info->DnsAddr[i].Type = NET_ADDR_IPV4;
1470                 net_info->DnsAddr[i].Data.Ipv4.s_addr = 0;
1471         }
1472
1473         net_info->IpConfigType = 0;
1474         net_info->IpAddr.Type = NET_ADDR_IPV4;
1475         net_info->IpAddr.Data.Ipv4.s_addr = 0;
1476         net_info->BNetmask = FALSE;
1477         net_info->SubnetMask.Type = NET_ADDR_IPV4;
1478         net_info->SubnetMask.Data.Ipv4.s_addr = 0;
1479         net_info->BDefGateway = FALSE;
1480         net_info->GatewayAddr.Type = NET_ADDR_IPV4;
1481         net_info->GatewayAddr.Data.Ipv4.s_addr = 0;
1482         net_info->BServerAddr = FALSE;
1483         net_info->ServerAddr.Type = NET_ADDR_IPV4;
1484         net_info->ServerAddr.Data.Ipv4.s_addr = 0;
1485
1486         net_info->IpConfigType6 = 0;
1487         net_info->IpAddr6.Type = NET_ADDR_IPV6;
1488         inet_pton(AF_INET6, "::", &net_info->IpAddr6.Data.Ipv6);
1489         net_info->PrefixLen6 = 0;
1490         net_info->BDefGateway6 = FALSE;
1491         net_info->GatewayAddr6.Type = NET_ADDR_IPV6;
1492         inet_pton(AF_INET6, "::", &net_info->GatewayAddr6.Data.Ipv6);
1493
1494         net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
1495
1496         return NET_ERR_NONE;
1497 }
1498
1499 int net_specific_scan_wifi(network_info_s *network_info, const char *ssid)
1500 {
1501         __NETWORK_FUNC_ENTER__;
1502
1503         net_err_e Error = NET_ERR_NONE;
1504
1505         if (ssid == NULL) {
1506                 WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1507                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1508                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
1509         }
1510
1511         Error = __net_get_wifi_state(network_info);
1512         if (Error != NET_ERR_NONE) {
1513                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
1514                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1515                 return Error; //LCOV_EXCL_LINE
1516         }
1517
1518         if (network_info->wifi_state == WIFI_OFF) {
1519                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
1520                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1521                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
1522         }
1523
1524         if (network_info->request_table[NETWORK_REQUEST_TYPE_SCAN].flag == TRUE ||
1525                 network_info->request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag == TRUE ||
1526                 network_info->request_table[NETWORK_REQUEST_TYPE_NETLINK_SCAN].flag == TRUE ||
1527                 network_info->request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].flag == TRUE) {
1528                 WIFI_LOG(WIFI_ERROR, "pending call in progress"); //LCOV_EXCL_LINE
1529                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1530                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
1531         }
1532
1533         if (network_info->request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].flag == TRUE) {
1534                 WIFI_LOG(WIFI_ERROR, "Specific scan request in progress"); //LCOV_EXCL_LINE
1535                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1536                 return NET_ERR_IN_PROGRESS; //LCOV_EXCL_LINE
1537         }
1538
1539         network_info->request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].flag = TRUE;
1540         g_strlcpy(network_info->request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].ssid,
1541                                 ssid, NET_WLAN_ESSID_LEN + 1);
1542
1543         Error = _net_dbus_specific_scan_request(network_info, ssid);
1544         if (Error != NET_ERR_NONE) {
1545                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
1546                                 "_net_dbus_specific_scan_request() failed. Error [%s]",
1547                                 _net_print_error(Error));
1548
1549                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN]), 0, //LCOV_EXCL_LINE
1550                                 sizeof(network_request_table_s));
1551         }
1552
1553         __NETWORK_FUNC_EXIT__;
1554         return Error;
1555 }
1556
1557 //LCOV_EXCL_START
1558 int net_bssid_scan_wifi(network_info_s *network_info, int activated)
1559 {
1560         __NETWORK_FUNC_ENTER__;
1561
1562         net_err_e Error = NET_ERR_NONE;
1563
1564         if (network_info->request_table[NETWORK_REQUEST_TYPE_SCAN].flag == TRUE ||
1565                 network_info->request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].flag == TRUE ||
1566                 network_info->request_table[NETWORK_REQUEST_TYPE_NETLINK_SCAN].flag == TRUE ||
1567                 network_info->request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].flag == TRUE) {
1568                 WIFI_LOG(WIFI_ERROR, "pending call in progress"); //LCOV_EXCL_LINE
1569                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1570                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
1571         }
1572
1573         if (network_info->request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag == TRUE) {
1574                 WIFI_LOG(WIFI_ERROR, "BSSID scan request in progress");
1575                 __NETWORK_FUNC_EXIT__;
1576                 return NET_ERR_IN_PROGRESS;
1577         }
1578
1579         network_info->request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag = TRUE;
1580
1581         if (activated == 0)
1582                 Error = _net_dbus_bssid_scan_request(network_info);
1583         else
1584                 Error = _net_dbus_scan_request(network_info);
1585
1586         if (Error != NET_ERR_NONE) {
1587                 WIFI_LOG(WIFI_ERROR,
1588                                 "_net_dbus_bssid_scan_request() failed. Error [%s]",
1589                                 _net_print_error(Error));
1590
1591                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN]), 0,
1592                                 sizeof(network_request_table_s));
1593         }
1594
1595         __NETWORK_FUNC_EXIT__;
1596         return Error;
1597 }
1598
1599 int net_netlink_scan_wifi(network_info_s *network_info, GSList *nl_scan_list, const char *vsie)
1600 {
1601         __NETWORK_FUNC_ENTER__;
1602
1603         net_err_e Error = NET_ERR_NONE;
1604
1605         if (network_info->request_table[NETWORK_REQUEST_TYPE_SCAN].flag == TRUE ||
1606                 network_info->request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag == TRUE ||
1607                 network_info->request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].flag == TRUE ||
1608                 network_info->request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].flag == TRUE) {
1609                 WIFI_LOG(WIFI_ERROR, "pending call in progress"); //LCOV_EXCL_LINE
1610                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1611                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
1612         }
1613
1614         if (network_info->request_table[NETWORK_REQUEST_TYPE_NETLINK_SCAN].flag == TRUE) {
1615                 WIFI_LOG(WIFI_ERROR, "Netlink scan request in progress");
1616                 __NETWORK_FUNC_EXIT__;
1617                 return NET_ERR_IN_PROGRESS;
1618         }
1619
1620         network_info->request_table[NETWORK_REQUEST_TYPE_NETLINK_SCAN].flag = TRUE;
1621         Error = _net_dbus_netlink_scan_request(network_info, nl_scan_list, vsie);
1622
1623         if (Error != NET_ERR_NONE) {
1624                 WIFI_LOG(WIFI_ERROR,
1625                                 "netlink dbus request failed. Error [%s]",
1626                                 _net_print_error(Error));
1627                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_NETLINK_SCAN]), 0,
1628                                 sizeof(network_request_table_s));
1629         }
1630
1631         __NETWORK_FUNC_EXIT__;
1632         return Error;
1633 }
1634
1635 int net_multi_scan_wifi(network_info_s *network_info,
1636                 GSList *multi_scan_list, gboolean multi_scan_type[])
1637 {
1638         __NETWORK_FUNC_ENTER__;
1639
1640         net_err_e Error = NET_ERR_NONE;
1641
1642         if (multi_scan_list == NULL) {
1643                 WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1644                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1645                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
1646         }
1647
1648         Error = __net_get_wifi_state(network_info);
1649         if (Error != NET_ERR_NONE) {
1650                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
1651                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1652                 return Error; //LCOV_EXCL_LINE
1653         }
1654
1655         if (network_info->wifi_state == WIFI_OFF) {
1656                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
1657                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1658                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
1659         }
1660
1661         if (network_info->request_table[NETWORK_REQUEST_TYPE_SCAN].flag == TRUE ||
1662                 network_info->request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag == TRUE ||
1663                 network_info->request_table[NETWORK_REQUEST_TYPE_NETLINK_SCAN].flag == TRUE ||
1664                 network_info->request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].flag == TRUE) {
1665                 WIFI_LOG(WIFI_ERROR, "pending call in progress"); //LCOV_EXCL_LINE
1666                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1667                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
1668         }
1669
1670         if (network_info->request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].flag == TRUE) {
1671                 WIFI_LOG(WIFI_ERROR, "Multi Scan request in progress"); //LCOV_EXCL_LINE
1672                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1673                 return NET_ERR_IN_PROGRESS; //LCOV_EXCL_LINE
1674         }
1675
1676         network_info->request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].flag = TRUE;
1677         if (multi_scan_type[WIFI_MULTI_SCAN_SSID] == true &&
1678                         multi_scan_type[WIFI_MULTI_SCAN_FREQ] == true)
1679                 network_info->request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].multi_scan_type = WIFI_MULTI_SCAN_SSID_FREQ;
1680         else if (multi_scan_type[WIFI_MULTI_SCAN_SSID] == true)
1681                 network_info->request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].multi_scan_type = WIFI_MULTI_SCAN_SSID;
1682         else if (multi_scan_type[WIFI_MULTI_SCAN_FREQ] == true)
1683                 network_info->request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].multi_scan_type = WIFI_MULTI_SCAN_FREQ;
1684
1685         wifi_manager_multi_scan_ap_s *temp = NULL;
1686         for (GSList *list = multi_scan_list; list; list = list->next) {
1687                 temp = (wifi_manager_multi_scan_ap_s*)g_try_malloc0(sizeof(wifi_manager_multi_scan_ap_s));
1688                 if (!temp) {
1689                         WIFI_LOG(WIFI_ERROR, "Failed to allocate memory"); //LCOV_EXCL_LINE
1690                         return NET_ERR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
1691                 }
1692                 g_strlcpy(temp->str, ((wifi_manager_multi_scan_ap_s *)list->data)->str, NET_WLAN_ESSID_LEN + 1);
1693                 temp->flag = ((wifi_manager_multi_scan_ap_s *)list->data)->flag;
1694
1695                 network_info->request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].multi_scan_list = g_slist_append(
1696                                         network_info->request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].multi_scan_list, temp);
1697         }
1698
1699         Error = _net_dbus_multi_scan_request(network_info, multi_scan_list);
1700         if (Error != NET_ERR_NONE) {
1701                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
1702                                 "_net_dbus_multi_scan_request() failed. Error [%s]",
1703                                 _net_print_error(Error));
1704
1705                 g_slist_free_full(network_info->request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].multi_scan_list, g_free);
1706                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN]), 0, //LCOV_EXCL_LINE
1707                                 sizeof(network_request_table_s));
1708         }
1709
1710         __NETWORK_FUNC_EXIT__;
1711         return Error;
1712 }
1713
1714 int net_get_wps_generated_pin(network_info_s *network_info, char **wps_pin)
1715 {
1716         net_err_e error = NET_ERR_NONE;
1717         error = _net_dbus_get_wps_generated_pin(network_info, wps_pin);
1718
1719         if (error != NET_ERR_NONE)
1720                 WIFI_LOG(WIFI_ERROR, "Failed to get wps pin : %d", error);
1721
1722         return error;
1723 }
1724
1725 int net_wifi_get_passpoint(network_info_s *network_info, int *enabled)
1726 {
1727         __NETWORK_FUNC_ENTER__;
1728
1729         net_err_e Error = NET_ERR_NONE;
1730
1731         Error = __net_get_wifi_state(network_info);
1732         if (Error != NET_ERR_NONE) {
1733                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
1734                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1735                 return Error; //LCOV_EXCL_LINE
1736         }
1737
1738         if (network_info->wifi_state == WIFI_OFF) {
1739                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
1740                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1741                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
1742         }
1743
1744         Error = _net_dbus_get_passpoint(network_info, enabled);
1745         if (Error != NET_ERR_NONE) {
1746                 WIFI_LOG(WIFI_ERROR,
1747                                 "_net_dbus_get_passpoint() failed. Error [%s]",
1748                                 _net_print_error(Error));
1749         }
1750
1751         __NETWORK_FUNC_EXIT__;
1752         return Error;
1753 }
1754
1755 int net_wifi_set_passpoint(network_info_s *network_info, int enable)
1756 {
1757         __NETWORK_FUNC_ENTER__;
1758
1759         net_err_e Error = NET_ERR_NONE;
1760
1761         Error = __net_get_wifi_state(network_info);
1762         if (Error != NET_ERR_NONE) {
1763                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
1764                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1765                 return Error; //LCOV_EXCL_LINE
1766         }
1767
1768         if (network_info->wifi_state == WIFI_OFF) {
1769                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
1770                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1771                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
1772         }
1773
1774         Error = _net_dbus_set_passpoint(network_info, enable);
1775         if (Error != NET_ERR_NONE) {
1776                 WIFI_LOG(WIFI_ERROR,
1777                                 "_net_dbus_set_passpoint() failed. Error [%s]",
1778                                 _net_print_error(Error));
1779         }
1780
1781         __NETWORK_FUNC_EXIT__;
1782         return Error;
1783 }
1784
1785 int net_wifi_add_vsie(network_info_s *network_info, unsigned int frame_id, const char *vsie_str)
1786 {
1787         __NETWORK_FUNC_ENTER__;
1788
1789         net_err_e Error = NET_ERR_NONE;
1790
1791         Error = __net_get_wifi_state(network_info);
1792         if (Error != NET_ERR_NONE) {
1793                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
1794                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1795                 return Error; //LCOV_EXCL_LINE
1796         }
1797
1798         if (network_info->wifi_state == WIFI_OFF) {
1799                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
1800                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1801                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
1802         }
1803
1804         Error = _net_dbus_add_vsie(network_info, frame_id, vsie_str);
1805         if (Error != NET_ERR_NONE) {
1806                 WIFI_LOG(WIFI_ERROR,
1807                                 "_net_dbus_add_vsie() failed. Error [%s]",
1808                                 _net_print_error(Error));
1809         }
1810
1811         __NETWORK_FUNC_EXIT__;
1812         return Error;
1813 }
1814
1815 int net_wifi_get_vsie(network_info_s *network_info, unsigned int frame_id, char **vsie_str)
1816 {
1817         __NETWORK_FUNC_ENTER__;
1818
1819         net_err_e Error = NET_ERR_NONE;
1820
1821         Error = __net_get_wifi_state(network_info);
1822         if (Error != NET_ERR_NONE) {
1823                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
1824                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1825                 return Error; //LCOV_EXCL_LINE
1826         }
1827
1828         if (network_info->wifi_state == WIFI_OFF) {
1829                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
1830                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1831                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
1832         }
1833
1834         Error = _net_dbus_get_vsie(network_info, frame_id, vsie_str);
1835         if (Error != NET_ERR_NONE) {
1836                 WIFI_LOG(WIFI_ERROR,
1837                                 "_net_dbus_get_vsie() failed. Error [%s]",
1838                                 _net_print_error(Error));
1839         }
1840
1841         __NETWORK_FUNC_EXIT__;
1842         return Error;
1843 }
1844
1845 int net_wifi_remove_vsie(network_info_s *network_info, unsigned int frame_id, const char *vsie_str)
1846 {
1847         __NETWORK_FUNC_ENTER__;
1848
1849         net_err_e Error = NET_ERR_NONE;
1850
1851         Error = __net_get_wifi_state(network_info);
1852         if (Error != NET_ERR_NONE) {
1853                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
1854                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1855                 return Error; //LCOV_EXCL_LINE
1856         }
1857
1858         if (network_info->wifi_state == WIFI_OFF) {
1859                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
1860                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
1861                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
1862         }
1863
1864         Error = _net_dbus_remove_vsie(network_info, frame_id, vsie_str);
1865         if (Error != NET_ERR_NONE) {
1866                 WIFI_LOG(WIFI_ERROR,
1867                                 "_net_dbus_remove_vsie() failed. Error [%s]",
1868                                 _net_print_error(Error));
1869         }
1870
1871         __NETWORK_FUNC_EXIT__;
1872         return Error;
1873 }
1874
1875 EXPORT_API int net_wifi_flush_bss(network_info_s *network_info)
1876 {
1877         __NETWORK_CAPI_FUNC_ENTER__;
1878
1879         net_err_e Error = NET_ERR_NONE;
1880
1881         Error = _net_dbus_flush_bss(network_info);
1882         if (Error != NET_ERR_NONE) {
1883                 WIFI_LOG(WIFI_ERROR, "Failed to flush bss. Error [%s]",
1884                                 _net_print_error(Error));
1885                 __NETWORK_CAPI_FUNC_EXIT__;
1886                 return Error;
1887         }
1888
1889         __NETWORK_CAPI_FUNC_EXIT__;
1890         return NET_ERR_NONE;
1891 }
1892
1893 int net_wifi_set_bssid(network_info_s *network_info, char *bssid)
1894 {
1895         __NETWORK_CAPI_FUNC_ENTER__;
1896
1897         net_err_e Error = NET_ERR_NONE;
1898
1899         Error = _net_dbus_set_bssid(network_info, bssid);
1900         if (Error != NET_ERR_NONE) {
1901                 WIFI_LOG(WIFI_ERROR, "Failed to set bssid. Error [%s]",
1902                                 _net_print_error(Error));
1903                 __NETWORK_CAPI_FUNC_EXIT__;
1904                 return Error;
1905         }
1906
1907         __NETWORK_CAPI_FUNC_EXIT__;
1908         return NET_ERR_NONE;
1909 }
1910
1911 EXPORT_API int net_wifi_set_auto_connect_mode(network_info_s *network_info,
1912                 int connect_mode)
1913 {
1914         __NETWORK_CAPI_FUNC_ENTER__;
1915
1916         net_err_e Error = NET_ERR_NONE;
1917
1918         if ((Error = _net_dbus_set_auto_connect_mode(network_info, connect_mode)) != NET_ERR_NONE) {
1919                 WIFI_LOG(WIFI_ERROR,
1920                                 "Failed to set auto connect mode. Error [%s]",
1921                                 _net_print_error(Error));
1922
1923                 __NETWORK_CAPI_FUNC_EXIT__;
1924                 return Error;
1925         }
1926
1927         __NETWORK_CAPI_FUNC_EXIT__;
1928         return NET_ERR_NONE;
1929 }
1930
1931 EXPORT_API int net_wifi_get_5ghz_support(network_info_s *network_info, gboolean *supported)
1932 {
1933         __NETWORK_CAPI_FUNC_ENTER__;
1934
1935         net_err_e Error = NET_ERR_NONE;
1936
1937         if ((Error = _net_dbus_get_5ghz_support(network_info, supported)) != NET_ERR_NONE) {
1938                 WIFI_LOG(WIFI_ERROR,
1939                                 "Failed to get 5 Ghz supported. Error [%s]",
1940                                 _net_print_error(Error));
1941
1942                 __NETWORK_CAPI_FUNC_EXIT__;
1943                 return Error;
1944         }
1945
1946         __NETWORK_CAPI_FUNC_EXIT__;
1947         return NET_ERR_NONE;
1948 }
1949
1950 EXPORT_API int net_wifi_get_auto_connect_mode(network_info_s *network_info,
1951                 int *connect_mode)
1952 {
1953         __NETWORK_CAPI_FUNC_ENTER__;
1954
1955         net_err_e Error = NET_ERR_NONE;
1956
1957         if ((Error = _net_dbus_get_auto_connect_mode(network_info, connect_mode)) != NET_ERR_NONE) {
1958                 WIFI_LOG(WIFI_ERROR,
1959                                 "Failed to set auto connect mode. Error [%s]",
1960                                 _net_print_error(Error));
1961
1962                 __NETWORK_CAPI_FUNC_EXIT__;
1963                 return Error;
1964         }
1965
1966         __NETWORK_CAPI_FUNC_EXIT__;
1967         return NET_ERR_NONE;
1968 }
1969
1970 EXPORT_API int net_wifi_set_ap_auto_connect(network_info_s *network_info,
1971                 const char *profile_name, gboolean autoconnect)
1972 {
1973         __NETWORK_FUNC_ENTER__;
1974
1975         net_err_e Error = NET_ERR_NONE;
1976
1977         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
1978                 WIFI_LOG(WIFI_ERROR, "Invalid profile name");
1979                 __NETWORK_FUNC_EXIT__;
1980                 return NET_ERR_INVALID_PARAM;
1981         }
1982
1983         Error = _net_dbus_wifi_set_autoconnect(network_info, profile_name, autoconnect);
1984         if (Error != NET_ERR_NONE)
1985                 WIFI_LOG(WIFI_ERROR, "Failed to set autoconnect(%d), Error[%s]",
1986                                 autoconnect, _net_print_error(Error));
1987
1988         __NETWORK_FUNC_EXIT__;
1989         return Error;
1990 }
1991
1992 EXPORT_API int net_wifi_get_ap_auto_connect(network_info_s *network_info,
1993                 const char *profile_name, gboolean *autoconnect)
1994 {
1995         __NETWORK_FUNC_ENTER__;
1996
1997         net_err_e Error = NET_ERR_NONE;
1998
1999         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
2000                 WIFI_LOG(WIFI_ERROR, "Invalid profile name");
2001                 __NETWORK_FUNC_EXIT__;
2002                 return NET_ERR_INVALID_PARAM;
2003         }
2004
2005         Error = _net_dbus_wifi_get_autoconnect(network_info, profile_name, autoconnect);
2006         if (Error != NET_ERR_NONE)
2007                 WIFI_LOG(WIFI_ERROR, "Failed to get autoconnect, Error[%s]",
2008                                 _net_print_error(Error));
2009
2010         __NETWORK_FUNC_EXIT__;
2011         return Error;
2012 }
2013 //LCOV_EXCL_STOP
2014
2015 int net_open_connection_with_wifi_info(network_info_s *network_info,
2016                 const net_wifi_connection_info_s *wifi_info)
2017 {
2018         __NETWORK_FUNC_ENTER__;
2019
2020         net_err_e Error = NET_ERR_NONE;
2021
2022         if (wifi_info == NULL) {
2023                 WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
2024                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2025                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
2026         }
2027
2028         Error = __net_get_wifi_state(network_info);
2029         if (Error != NET_ERR_NONE) {
2030                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
2031                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2032                 return Error; //LCOV_EXCL_LINE
2033         }
2034
2035         if (network_info->wifi_state == WIFI_OFF) {
2036                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
2037                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2038                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2039         }
2040
2041         if (network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER].flag == TRUE ||
2042                 network_info->request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE ||
2043                 network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag == TRUE ||
2044                 network_info->request_table[NETWORK_REQUEST_TYPE_FORGET_AP].flag == TRUE) {
2045                 WIFI_LOG(WIFI_ERROR, "pending call in progress"); //LCOV_EXCL_LINE
2046                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2047                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2048         }
2049
2050         if (network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE) {
2051                 WIFI_LOG(WIFI_ERROR, "Connection open request in progress"); //LCOV_EXCL_LINE
2052                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2053                 return NET_ERR_IN_PROGRESS; //LCOV_EXCL_LINE
2054         }
2055
2056         network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag = TRUE;
2057
2058         Error = _net_open_connection_with_wifi_info(network_info, wifi_info);
2059         if (Error != NET_ERR_NONE) {
2060                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
2061                                 "net_open_connection_with_wifi_info() failed. Error [%s]",
2062                                 _net_print_error(Error));
2063
2064                 if (network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag != 0)
2065                         memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION]), 0, //LCOV_EXCL_LINE
2066                                         sizeof(network_request_table_s));
2067
2068                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2069                 return Error; //LCOV_EXCL_LINE
2070         }
2071
2072         __NETWORK_FUNC_EXIT__;
2073         return NET_ERR_NONE;
2074 }
2075
2076 int net_wifi_power_on(network_info_s *network_info, gboolean wifi_picker_test)
2077 {
2078         __NETWORK_FUNC_ENTER__;
2079
2080         net_err_e Error = NET_ERR_NONE;
2081         int hotspot_state = 0;
2082
2083         if (!net_get_device_policy_wifi(network_info)) {
2084                 WIFI_LOG(WIFI_ERROR, "Wifi profile device policy restricts"); //LCOV_EXCL_LINE
2085                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2086                 return NET_ERR_SECURITY_RESTRICTED; //LCOV_EXCL_LINE
2087         }
2088
2089         /* TODO */
2090         if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &hotspot_state) != 0) {
2091                 WIFI_LOG(WIFI_ERROR, "Failed to get vconf key of hotspot mode"); //LCOV_EXCL_LINE
2092                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2093                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2094         }
2095
2096         if (hotspot_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) {
2097                 WIFI_LOG(WIFI_ERROR, "Wi-Fi hotspot is enabled!"); //LCOV_EXCL_LINE
2098                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2099                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2100         }
2101
2102         Error = __net_get_wifi_state(network_info);
2103         if (Error != NET_ERR_NONE) {
2104                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
2105                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2106                 return Error; //LCOV_EXCL_LINE
2107         }
2108
2109         if (network_info->wifi_state == WIFI_ON) {
2110                 WIFI_LOG(WIFI_ERROR, "Wi-Fi is powered on already!"); //LCOV_EXCL_LINE
2111                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2112                 return NET_ERR_ALREADY_EXISTS; //LCOV_EXCL_LINE
2113         }
2114
2115         if (network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER].flag == TRUE) {
2116                 WIFI_LOG(WIFI_ERROR, "Request in progress"); //LCOV_EXCL_LINE
2117                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2118                 return NET_ERR_IN_PROGRESS; //LCOV_EXCL_LINE
2119         }
2120
2121         memset(network_info->request_table, 0, sizeof(network_info->request_table));
2122
2123         network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER].flag = TRUE;
2124
2125         Error = _net_dbus_load_wifi_driver(network_info, wifi_picker_test);
2126         if (Error != NET_ERR_NONE) {
2127                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
2128                                 "Failed to request Wi-Fi power on/off. Error [%s]",
2129                                 _net_print_error(Error));
2130
2131                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER]), 0, //LCOV_EXCL_LINE
2132                                 sizeof(network_request_table_s));
2133
2134                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2135                 return Error; //LCOV_EXCL_LINE
2136         }
2137
2138         __NETWORK_FUNC_EXIT__;
2139         return NET_ERR_NONE;
2140 }
2141
2142 int net_wifi_power_off(network_info_s *network_info)
2143 {
2144         __NETWORK_FUNC_ENTER__;
2145
2146         net_err_e Error = NET_ERR_NONE;
2147
2148         Error = __net_get_wifi_state(network_info);
2149         if (Error != NET_ERR_NONE) {
2150                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
2151                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2152                 return Error; //LCOV_EXCL_LINE
2153         }
2154
2155         if (network_info->wifi_state == WIFI_OFF) {
2156                 WIFI_LOG(WIFI_ERROR, "Wi-Fi is powered off already!"); //LCOV_EXCL_LINE
2157                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2158                 return NET_ERR_ALREADY_EXISTS; //LCOV_EXCL_LINE
2159         }
2160
2161         if (network_info->request_table[NETWORK_REQUEST_TYPE_NETLINK_SCAN].flag == TRUE) {
2162                 WIFI_LOG(WIFI_ERROR, "pending call in progress"); //LCOV_EXCL_LINE
2163                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2164                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2165         }
2166
2167         if (network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER].flag == TRUE) {
2168                 WIFI_LOG(WIFI_ERROR, "Request in progress"); //LCOV_EXCL_LINE
2169                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2170                 return NET_ERR_IN_PROGRESS; //LCOV_EXCL_LINE
2171         }
2172
2173         if (network_info->request_table[NETWORK_REQUEST_TYPE_SCAN].flag == TRUE)
2174                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_SCAN]),
2175                                 0, sizeof(network_request_table_s));
2176
2177         if (network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE)
2178                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION]),
2179                                 0, sizeof(network_request_table_s));
2180
2181         if (network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag == TRUE)
2182                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS]),
2183                                 0, sizeof(network_request_table_s));
2184
2185         if (network_info->request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE)
2186                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION]),
2187                                 0, sizeof(network_request_table_s));
2188
2189         if (network_info->request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].flag == TRUE)
2190                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN]),
2191                                 0, sizeof(network_request_table_s));
2192
2193         if (network_info->request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag == TRUE)
2194                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN]),
2195                                 0, sizeof(network_request_table_s));
2196
2197         network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER].flag = TRUE;
2198
2199         Error = _net_dbus_remove_wifi_driver(network_info);
2200         if (Error != NET_ERR_NONE) {
2201                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
2202                                 "Failed to request Wi-Fi power on/off. Error [%s]",
2203                                 _net_print_error(Error));
2204
2205                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER]), //LCOV_EXCL_LINE
2206                                 0, sizeof(network_request_table_s));
2207
2208                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2209                 return Error; //LCOV_EXCL_LINE
2210         }
2211
2212         __NETWORK_FUNC_EXIT__;
2213         return NET_ERR_NONE;
2214 }
2215
2216 int net_scan_wifi(network_info_s *network_info)
2217 {
2218         __NETWORK_FUNC_ENTER__;
2219
2220         net_err_e Error = NET_ERR_NONE;
2221
2222         Error = __net_get_wifi_state(network_info);
2223         if (Error != NET_ERR_NONE) {
2224                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
2225                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2226                 return Error; //LCOV_EXCL_LINE
2227         }
2228
2229         if (network_info->wifi_state == WIFI_OFF) {
2230                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
2231                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2232                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2233         }
2234
2235         if (network_info->request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].flag == TRUE ||
2236                 network_info->request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag == TRUE ||
2237                 network_info->request_table[NETWORK_REQUEST_TYPE_NETLINK_SCAN].flag == TRUE ||
2238                 network_info->request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].flag == TRUE) {
2239                 WIFI_LOG(WIFI_ERROR, "pending call in progress"); //LCOV_EXCL_LINE
2240                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2241                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2242         }
2243
2244         if (network_info->request_table[NETWORK_REQUEST_TYPE_SCAN].flag == TRUE) {
2245                 WIFI_LOG(WIFI_ERROR, "Scan request in progress"); //LCOV_EXCL_LINE
2246                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2247                 return NET_ERR_IN_PROGRESS; //LCOV_EXCL_LINE
2248         }
2249
2250         network_info->request_table[NETWORK_REQUEST_TYPE_SCAN].flag = TRUE;
2251
2252         Error = _net_dbus_scan_request(network_info);
2253         if (Error != NET_ERR_NONE) {
2254                 WIFI_LOG(WIFI_ERROR, "Failed to request scan. Error [%s]", //LCOV_EXCL_LINE
2255                                 _net_print_error(Error));
2256
2257                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_SCAN]), 0, //LCOV_EXCL_LINE
2258                                 sizeof(network_request_table_s));
2259
2260                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2261                 return Error; //LCOV_EXCL_LINE
2262         }
2263
2264         __NETWORK_FUNC_EXIT__;
2265         return NET_ERR_NONE;
2266 }
2267
2268 int net_wifi_get_scan_state(network_info_s *network_info, int *scanstate)
2269 {
2270         __NETWORK_FUNC_ENTER__;
2271
2272         net_err_e Error = NET_ERR_NONE;
2273
2274         Error = __net_get_wifi_state(network_info);
2275         if (Error != NET_ERR_NONE) {
2276                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
2277                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2278                 return Error; //LCOV_EXCL_LINE
2279         }
2280
2281         if (network_info->wifi_state == WIFI_OFF) {
2282                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
2283                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2284                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2285         }
2286
2287         if (network_info->request_table[NETWORK_REQUEST_TYPE_SCAN].flag == TRUE) {
2288                 WIFI_LOG(WIFI_ERROR, "Scan request in progress"); //LCOV_EXCL_LINE
2289                 *scanstate = 1; //LCOV_EXCL_LINE
2290                 __NETWORK_FUNC_EXIT__;
2291                 return NET_ERR_NONE; //LCOV_EXCL_LINE
2292         }
2293
2294         Error = _net_dbus_get_scan_state(network_info, scanstate);
2295         if (Error != NET_ERR_NONE) {
2296                 WIFI_LOG(WIFI_ERROR, "Failed to get scan state. Error [%s]", //LCOV_EXCL_LINE
2297                                 _net_print_error(Error));
2298
2299                 __NETWORK_FUNC_EXIT__;
2300                 return Error; //LCOV_EXCL_LINE
2301         }
2302
2303         __NETWORK_FUNC_EXIT__;
2304         return NET_ERR_NONE;
2305 }
2306
2307 //LCOV_EXCL_START
2308 int net_wifi_enroll_wps(network_info_s *network_info,
2309                 const char *profile_name, net_wifi_wps_info_s *wps_info)
2310 {
2311         __NETWORK_FUNC_ENTER__;
2312
2313         net_err_e Error = NET_ERR_NONE;
2314
2315         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
2316                 WIFI_LOG(WIFI_ERROR, "Invalid profile name");
2317                 __NETWORK_FUNC_EXIT__;
2318                 return NET_ERR_INVALID_PARAM;
2319         }
2320
2321         Error = __net_get_wifi_state(network_info);
2322         if (Error != NET_ERR_NONE) {
2323                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state");
2324                 __NETWORK_FUNC_EXIT__;
2325                 return Error;
2326         }
2327
2328         if (network_info->wifi_state == WIFI_OFF) {
2329                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!");
2330                 __NETWORK_FUNC_EXIT__;
2331                 return NET_ERR_INVALID_OPERATION;
2332         }
2333
2334         if (network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER].flag == TRUE ||
2335                 network_info->request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE ||
2336                 network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE ||
2337                 network_info->request_table[NETWORK_REQUEST_TYPE_FORGET_AP].flag == TRUE) {
2338                 WIFI_LOG(WIFI_ERROR, "pending call in progress"); //LCOV_EXCL_LINE
2339                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2340                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2341         }
2342
2343         if (network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag == TRUE) {
2344                 WIFI_LOG(WIFI_ERROR, "Request in progress");
2345                 __NETWORK_FUNC_EXIT__;
2346                 return NET_ERR_IN_PROGRESS;
2347         }
2348
2349         network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag = TRUE;
2350         g_strlcpy(network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].ProfileName,
2351                         profile_name, NET_PROFILE_NAME_LEN_MAX+1);
2352
2353         if (wps_info->type == WIFI_WPS_PBC)
2354                 Error = _net_dbus_set_agent_wps_pbc_and_connect(network_info, profile_name);
2355         else if (wps_info->type == WIFI_WPS_PIN)
2356                 Error = _net_dbus_set_agent_wps_pin_and_connect(network_info, wps_info->pin, profile_name);
2357         else
2358                 Error = NET_ERR_INVALID_PARAM;
2359
2360         if (NET_ERR_NONE != Error) {
2361                 WIFI_LOG(WIFI_ERROR, "WPS configuration failed(%s)", _net_print_error(Error));
2362
2363                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS]), 0,
2364                                 sizeof(network_request_table_s));
2365         }
2366
2367         __NETWORK_FUNC_EXIT__;
2368         return Error;
2369 }
2370
2371 int net_wifi_cancel_wps(network_info_s *network_info)
2372 {
2373         __NETWORK_FUNC_ENTER__;
2374
2375         net_err_e Error = NET_ERR_NONE;
2376
2377         WIFI_LOG(WIFI_INFO, "net_wifi_wps_cancel called");
2378
2379         Error = __net_get_wifi_state(network_info);
2380         if (Error != NET_ERR_NONE) {
2381                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
2382                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2383                 return Error; //LCOV_EXCL_LINE
2384         }
2385
2386         if (network_info->wifi_state != WIFI_ON) {
2387                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
2388                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2389                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2390         }
2391
2392         if (network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag == FALSE) {
2393                 WIFI_LOG(WIFI_ERROR, "No pending call in progress");
2394                 __NETWORK_FUNC_EXIT__;
2395                 return NET_ERR_INVALID_OPERATION;
2396         }
2397
2398         if (network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].ProfileName[0] != '\0')
2399                 net_delete_profile(network_info, network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].ProfileName);
2400
2401         Error = _net_dbus_cancel_wps(network_info);
2402         if (Error != NET_ERR_NONE) {
2403                 WIFI_LOG(WIFI_ERROR,
2404                         "Failed to request cancel WPS, Error [%s]",
2405                         _net_print_error(Error));
2406         }
2407
2408         memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS]), 0,
2409                         sizeof(network_request_table_s));
2410
2411         __NETWORK_FUNC_EXIT__;
2412         return Error;
2413 }
2414
2415 wifi_tech_state_e net_get_technology_state(network_info_s *network_info)
2416 {
2417         GVariant *message = NULL, *variant;
2418         GVariantIter *iter, *next;
2419         wifi_tech_state_e tech_state = WIFI_TECH_OFF;
2420         gboolean wifi_tech_powered = FALSE;
2421         gboolean wifi_tech_connected = FALSE;
2422         const char *path;
2423         gchar *key;
2424         net_err_e Error = NET_ERR_NONE;
2425
2426         message = _net_invoke_dbus_method(network_info,
2427                         CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
2428                         CONNMAN_MANAGER_INTERFACE, "GetTechnologies",
2429                         NULL, &Error);
2430
2431         if (message == NULL) {
2432                 WIFI_LOG(WIFI_ERROR, "Failed to get_technology_state");
2433                 return WIFI_TECH_UNKNOWN;
2434         }
2435
2436         g_variant_get(message, "(a(oa{sv}))", &iter);
2437         while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) {
2438                 if (path == NULL || g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) != 0)
2439                         continue;
2440
2441                 while (g_variant_iter_loop(next, "{sv}", &key, &variant)) {
2442                         if (g_strcmp0(key, "Device.List") == 0) {
2443                                 GVariantIter *list_iter = NULL;
2444                                 gchar *dev_key = NULL;
2445                                 GVariant *dev_var = NULL;
2446                                 const gchar *sdata = NULL;
2447                                 gboolean bdata = FALSE;
2448                                 gboolean find = FALSE;
2449
2450                                 g_variant_get(variant, "a{sv}", &list_iter);
2451                                 while(g_variant_iter_loop(list_iter, "{sv}", &dev_key, &dev_var)) {
2452                                         if (g_variant_is_of_type(dev_var, G_VARIANT_TYPE_STRING)) {
2453                                                 sdata = g_variant_get_string(dev_var, NULL);
2454                                                 WIFI_LOG(WIFI_INFO, "%s [%s]", dev_key, sdata);
2455
2456                                                 if (g_strcmp0(dev_key, "Ifname") == 0) {
2457                                                         find = g_strcmp0(sdata, network_info->interface_name) == 0 ? TRUE : FALSE;
2458                                                 }
2459                                         } else if (g_variant_is_of_type(dev_var, G_VARIANT_TYPE_BOOLEAN)) {
2460                                                 bdata = g_variant_get_boolean(dev_var);
2461                                                 WIFI_LOG(WIFI_INFO, "%s [%s]", dev_key, bdata ? "True" : "False");
2462
2463                                                 if (find && g_strcmp0(dev_key, "Powered") == 0) {
2464                                                         wifi_tech_powered = bdata;
2465                                                 } else if (find && g_strcmp0(dev_key, "Connected") == 0) {
2466                                                         wifi_tech_connected = bdata;
2467                                                 }
2468                                         }
2469                                 }
2470                                 g_variant_iter_free(list_iter);
2471                         }
2472                 }
2473         }
2474
2475         g_variant_unref(message);
2476
2477         g_variant_iter_free(iter);
2478
2479         if (wifi_tech_powered == TRUE)
2480                 tech_state = WIFI_TECH_POWERED;
2481
2482         if (wifi_tech_connected == TRUE)
2483                 tech_state = WIFI_TECH_CONNECTED;
2484
2485         return tech_state;
2486 }
2487
2488 int net_check_get_privilege(network_info_s *network_info)
2489 {
2490         net_err_e Error = NET_ERR_NONE;
2491
2492         Error = __net_check_get_privilege(network_info);
2493         if (Error != NET_ERR_NONE) {
2494                 WIFI_LOG(WIFI_ERROR, "Failed to check get privilege. Error [%s]", //LCOV_EXCL_LINE
2495                 _net_print_error(Error)); //LCOV_EXCL_LINE
2496         }
2497
2498         return Error;
2499 }
2500
2501 int net_set_ip_conflict_detect_mode(network_info_s *network_info, gboolean detect)
2502 {
2503         __NETWORK_FUNC_ENTER__;
2504
2505         net_err_e Error = NET_ERR_NONE;
2506
2507         Error = __net_set_ip_conflict_detect_mode(network_info, detect);
2508         if (Error != NET_ERR_NONE) {
2509                 WIFI_LOG(WIFI_ERROR, "Failed to set ip conflict detection enable, Error [%s]", //LCOV_EXCL_LINE
2510                 _net_print_error(Error));
2511                 __NETWORK_FUNC_EXIT__;
2512                 return Error; //LCOV_EXCL_LINE
2513         }
2514
2515         __NETWORK_FUNC_EXIT__;
2516         return Error;
2517 }
2518
2519 int net_ip_conflict_detect_is_enabled(network_info_s *network_info, gboolean *state)
2520 {
2521         __NETWORK_FUNC_ENTER__;
2522
2523         net_err_e Error = NET_ERR_NONE;
2524
2525         Error = __net_ip_conflict_detect_is_enabled(network_info, state);
2526         if (Error != NET_ERR_NONE) {
2527                 WIFI_LOG(WIFI_ERROR, "Failed to get ip conflict detection mode, Error [%s]", //LCOV_EXCL_LINE
2528                 _net_print_error(Error));
2529                 __NETWORK_FUNC_EXIT__;
2530                 return Error; //LCOV_EXCL_LINE
2531         }
2532
2533         __NETWORK_FUNC_EXIT__;
2534         return Error;
2535 }
2536
2537 int net_check_profile_privilege(network_info_s *network_info)
2538 {
2539         net_err_e Error = NET_ERR_NONE;
2540
2541         Error = __net_check_profile_privilege(network_info);
2542         if (Error != NET_ERR_NONE) {
2543                 WIFI_LOG(WIFI_ERROR, "Failed to check profile privilege. Error [%s]", //LCOV_EXCL_LINE
2544                 _net_print_error(Error)); //LCOV_EXCL_LINE
2545         }
2546
2547         return Error;
2548 }
2549
2550 int net_wifi_enroll_wps_without_ssid(network_info_s *network_info,
2551                 net_wifi_wps_info_s *wps_info)
2552 {
2553         __NETWORK_FUNC_ENTER__;
2554
2555         net_err_e Error = NET_ERR_NONE;
2556
2557         Error = __net_get_wifi_state(network_info);
2558         if (Error != NET_ERR_NONE) {
2559                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
2560                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2561                 return Error; //LCOV_EXCL_LINE
2562         }
2563
2564         if (network_info->wifi_state != WIFI_ON) {
2565                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
2566                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2567                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2568         }
2569
2570         if (network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER].flag == TRUE ||
2571                 network_info->request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE ||
2572                 network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE ||
2573                 network_info->request_table[NETWORK_REQUEST_TYPE_FORGET_AP].flag == TRUE) {
2574                 WIFI_LOG(WIFI_ERROR, "pending call in progress"); //LCOV_EXCL_LINE
2575                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2576                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2577         }
2578
2579         if (network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag == TRUE) {
2580                 WIFI_LOG(WIFI_ERROR, "Request in progress");
2581                 __NETWORK_FUNC_EXIT__;
2582                 return NET_ERR_IN_PROGRESS;
2583         }
2584
2585         memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS]), 0,
2586                                                 sizeof(network_request_table_s));
2587         network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag = TRUE;
2588
2589         if (wps_info->type == WIFI_WPS_PBC) {
2590                 Error = _net_dbus_open_connection_without_ssid(network_info);
2591         } else if (wps_info->type == WIFI_WPS_PIN) {
2592                 Error = _net_dbus_open_pin_connection_without_ssid(network_info, wps_info->pin);
2593         } else{
2594                 __NETWORK_FUNC_EXIT__;
2595                 return NET_ERR_INVALID_PARAM;
2596         }
2597
2598         if (Error != NET_ERR_NONE) {
2599                 WIFI_LOG(WIFI_ERROR,
2600                                 "Failed to request open connection, Error [%s]",
2601                                 _net_print_error(Error));
2602
2603                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS]), 0,
2604                                 sizeof(network_request_table_s));
2605         }
2606
2607         __NETWORK_FUNC_EXIT__;
2608         return Error;
2609 }
2610
2611 int net_wifi_tdls_disconnect(network_info_s *network_info, const char* peer_mac_addr)
2612 {
2613         __NETWORK_FUNC_ENTER__;
2614
2615         net_err_e Error = NET_ERR_NONE;
2616
2617         if (peer_mac_addr == NULL) {
2618                 WIFI_LOG(WIFI_ERROR, "invalid parameter");
2619                 __NETWORK_FUNC_EXIT__;
2620                 return NET_ERR_INVALID_PARAM;
2621         }
2622
2623         Error = _net_dbus_tdls_disconnect(network_info, peer_mac_addr);
2624
2625         if (Error != NET_ERR_NONE)
2626                 WIFI_LOG(WIFI_ERROR, "_net_dbus_tdls_set_device_type failed");
2627
2628
2629         __NETWORK_FUNC_EXIT__;
2630         return Error;
2631
2632 }
2633
2634 int net_wifi_tdls_connected_peer(network_info_s *network_info, char** peer_mac_addr)
2635 {
2636         __NETWORK_FUNC_ENTER__;
2637
2638         net_err_e Error = NET_ERR_NONE;
2639
2640         if (peer_mac_addr == NULL) {
2641                 WIFI_LOG(WIFI_ERROR, "invalid parameter");
2642                 __NETWORK_FUNC_EXIT__;
2643                 return NET_ERR_INVALID_PARAM;
2644         }
2645
2646         Error = _net_dbus_tdls_connected_peer(network_info, peer_mac_addr);
2647
2648         if (Error != NET_ERR_NONE)
2649                 WIFI_LOG(WIFI_ERROR, "net_wifi_tdls_connected_peer failed");
2650
2651
2652         __NETWORK_FUNC_EXIT__;
2653         return Error;
2654
2655 }
2656
2657 int net_wifi_tdls_enable_channel_switch(network_info_s *network_info,
2658                 const char* peer_mac_addr, int freq)
2659 {
2660         __NETWORK_FUNC_ENTER__;
2661
2662         net_err_e Error = NET_ERR_NONE;
2663
2664         if (peer_mac_addr == NULL || freq < 0) {
2665                 WIFI_LOG(WIFI_ERROR, "invalid parameter");
2666                 __NETWORK_FUNC_EXIT__;
2667                 return NET_ERR_INVALID_PARAM;
2668         }
2669
2670         Error = _net_dbus_tdls_enable_channel_switch(network_info, peer_mac_addr, freq);
2671         if (Error != NET_ERR_NONE)
2672                 WIFI_LOG(WIFI_ERROR, "net_wifi_tdls_enable_channel_switch failed");
2673
2674         __NETWORK_FUNC_EXIT__;
2675         return Error;
2676
2677 }
2678
2679 int net_wifi_tdls_disbale_channel_switch(network_info_s *network_info,
2680                 const char* peer_mac_addr)
2681 {
2682         __NETWORK_FUNC_ENTER__;
2683
2684         net_err_e Error = NET_ERR_NONE;
2685
2686         if (peer_mac_addr == NULL) {
2687                 WIFI_LOG(WIFI_ERROR, "invalid parameter");
2688                 __NETWORK_FUNC_EXIT__;
2689                 return NET_ERR_INVALID_PARAM;
2690         }
2691
2692         Error = _net_dbus_tdls_disable_channel_switch(network_info, peer_mac_addr);
2693         if (Error != NET_ERR_NONE)
2694                 WIFI_LOG(WIFI_ERROR, "net_wifi_tdls_disbale_channel_switch failed");
2695
2696
2697         __NETWORK_FUNC_EXIT__;
2698         return Error;
2699
2700 }
2701
2702
2703 int net_wifi_tdls_connect(network_info_s *network_info, const char* peer_mac_addr)
2704 {
2705         __NETWORK_FUNC_ENTER__;
2706
2707         net_err_e Error = NET_ERR_NONE;
2708
2709         if (peer_mac_addr == NULL) {
2710                 WIFI_LOG(WIFI_ERROR, "invalid parameter");
2711                 __NETWORK_FUNC_EXIT__;
2712                 return NET_ERR_INVALID_PARAM;
2713         }
2714
2715         Error = _net_dbus_tdls_connect(network_info, peer_mac_addr);
2716         if (Error != NET_ERR_NONE)
2717                 WIFI_LOG(WIFI_ERROR, "_net_dbus_tdls_connect failed");
2718
2719
2720         __NETWORK_FUNC_EXIT__;
2721         return Error;
2722
2723 }
2724
2725 int net_wifi_tdls_discover(network_info_s *network_info, const char* peer_mac_addr)
2726 {
2727         __NETWORK_FUNC_ENTER__;
2728
2729         net_err_e Error = NET_ERR_NONE;
2730
2731         if (peer_mac_addr == NULL) {
2732                 WIFI_LOG(WIFI_ERROR, "invalid parameter");
2733                 __NETWORK_FUNC_EXIT__;
2734                 return NET_ERR_INVALID_PARAM;
2735         }
2736
2737         if (network_info->request_table[NETWORK_REQUEST_TYPE_TDLS_DISCOVERY].flag == TRUE) {
2738                 WIFI_LOG(WIFI_ERROR, "TDLS Discovery Request in progress"); //LCOV_EXCL_LINE
2739                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2740                 return NET_ERR_IN_PROGRESS; //LCOV_EXCL_LINE
2741         }
2742
2743         network_info->request_table[NETWORK_REQUEST_TYPE_TDLS_DISCOVERY].flag = TRUE;
2744
2745         Error = _net_dbus_tdls_discover(network_info, peer_mac_addr);
2746         if (Error != NET_ERR_NONE) {
2747                 WIFI_LOG(WIFI_ERROR, "_net_dbus_tdls_discover failed");
2748
2749                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_TDLS_DISCOVERY]), 0, //LCOV_EXCL_LINE
2750                                 sizeof(network_request_table_s));
2751
2752                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2753                 return Error; //LCOV_EXCL_LINE
2754         }
2755
2756         __NETWORK_FUNC_EXIT__;
2757         return Error;
2758 }
2759 int net_get_device_policy_wifi(network_info_s *network_info)
2760 {
2761         __NETWORK_FUNC_ENTER__;
2762
2763         int state = -1;
2764         net_err_e Error = _net_dbus_device_policy_get_wifi(network_info, &state);
2765
2766         if (Error != NET_ERR_NONE) {
2767                 WIFI_LOG(WIFI_ERROR, "_net_dbus_device_policy_get_wifi failed");
2768                 state = TRUE;
2769         }
2770
2771         WIFI_LOG(WIFI_INFO, "Wifi device policy state [%d]", state);
2772
2773         __NETWORK_FUNC_EXIT__;
2774         return state;
2775 }
2776
2777 int net_get_device_policy_wifi_profile(network_info_s *network_info)
2778 {
2779         __NETWORK_FUNC_ENTER__;
2780
2781         int state = -1;
2782         net_err_e Error = _net_dbus_device_policy_get_wifi_profile(network_info, &state);
2783
2784         if (Error != NET_ERR_NONE) {
2785                 WIFI_LOG(WIFI_ERROR, "_net_dbus_device_policy_get_wifi_profile failed");
2786                 state = TRUE;
2787         }
2788
2789         WIFI_LOG(WIFI_INFO, "Wifi profile policy state [%d]", state);
2790
2791         __NETWORK_FUNC_EXIT__;
2792         return state;
2793 }
2794 //LCOV_EXCL_STOP
2795
2796 int net_register_client_ext(network_info_s **network_info,
2797                 const char *interface_name, net_event_cb event_cb, void *user_data)
2798 {
2799         __NETWORK_FUNC_ENTER__;
2800
2801         net_err_e Error = NET_ERR_NONE;
2802         network_info_s *net_info = NULL;
2803         GSList *list = NULL;
2804         GSList *interface_list = NULL;
2805
2806         if (event_cb == NULL) {
2807                 WIFI_LOG(WIFI_ERROR, "Invalid EventCb parameter"); //LCOV_EXCL_LINE
2808                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2809                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
2810         }
2811
2812         net_info = g_try_malloc0(sizeof(network_info_s));
2813         if (net_info == NULL) {
2814                 WIFI_LOG(WIFI_ERROR, "Failed to allocate memory"); //LCOV_EXCL_LINE
2815                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2816                 return NET_ERR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
2817         }
2818
2819         Error = _net_dbus_create_gdbus_call(net_info);
2820         if (Error != NET_ERR_NONE) {
2821                 g_free(net_info); //LCOV_EXCL_LINE
2822                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2823                 return Error; //LCOV_EXCL_LINE
2824         }
2825
2826         Error = _net_get_interface_list(net_info, &interface_list);
2827         if (Error != NET_ERR_NONE) {
2828                 WIFI_LOG(WIFI_ERROR, "Failed to get interface list. Error [%s]", //LCOV_EXCL_LINE
2829                                 _net_print_error(Error));
2830                 _net_dbus_close_gdbus_call(net_info); //LCOV_EXCL_LINE
2831                 g_free(net_info); //LCOV_EXCL_LINE
2832                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2833                 return Error; //LCOV_EXCL_LINE
2834         }
2835
2836         for (list = interface_list; list; list = list->next) {
2837                 const char *ifname = list->data;
2838                 if (interface_name == NULL || !g_strcmp0(interface_name, ifname)) {
2839                         g_strlcpy(net_info->interface_name, ifname, NET_WLAN_IF_NAME_LEN + 1);
2840                         WIFI_LOG(WIFI_INFO, "Set interface name [%s]", ifname);
2841                         break;
2842                 }
2843         }
2844
2845         if (list == NULL) {
2846                 WIFI_LOG(WIFI_ERROR, "Failed to find interface [%s]", interface_name);  //LCOV_EXCL_LINE
2847                 _net_dbus_close_gdbus_call(net_info); //LCOV_EXCL_LINE
2848                 g_free(net_info); //LCOV_EXCL_LINE
2849                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2850                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2851         }
2852
2853         Error = _net_register_signal(net_info);
2854         if (Error != NET_ERR_NONE) {
2855                 WIFI_LOG(WIFI_ERROR, "Failed to register DBus signal [%s]", //LCOV_EXCL_LINE
2856                                 _net_print_error(Error));
2857                 _net_dbus_close_gdbus_call(net_info); //LCOV_EXCL_LINE
2858                 g_free(net_info); //LCOV_EXCL_LINE
2859                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2860                 return Error; //LCOV_EXCL_LINE
2861         }
2862
2863         Error = _net_init_service_state(net_info);
2864         if (Error != NET_ERR_NONE) {
2865                 WIFI_LOG(WIFI_ERROR, "Failed to init service state [%s]", //LCOV_EXCL_LINE
2866                                 _net_print_error(Error));
2867                 _net_deregister_signal(net_info); //LCOV_EXCL_LINE
2868                 _net_dbus_close_gdbus_call(net_info); //LCOV_EXCL_LINE
2869                 g_free(net_info); //LCOV_EXCL_LINE
2870                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2871                 return Error; //LCOV_EXCL_LINE
2872         }
2873
2874         net_info->event_callback = event_cb;
2875         net_info->user_data = user_data;
2876
2877         *network_info = net_info;
2878
2879         __NETWORK_FUNC_EXIT__;
2880         return NET_ERR_NONE;
2881 }
2882
2883 void net_deregister_client_ext(network_info_s *network_info)
2884 {
2885         __NETWORK_FUNC_ENTER__;
2886
2887         if (network_info) {
2888                 network_info->event_callback = NULL;
2889                 network_info->user_data = NULL;
2890
2891                 _net_deregister_signal(network_info);
2892                 _net_dbus_close_gdbus_call(network_info);
2893                 _net_clear_request_table(network_info);
2894
2895                 g_free(network_info);
2896         }
2897
2898         __NETWORK_FUNC_EXIT__;
2899 }
2900
2901 //LCOV_EXCL_START
2902 void net_set_cs_tid(network_info_s *network_info, int tid)
2903 {
2904         _net_set_cs_tid(network_info, tid);
2905 }
2906
2907 void net_unset_cs_tid(int tid)
2908 {
2909         _net_unset_cs_tid(tid);
2910 }
2911 //LCOV_EXCL_STOP
2912
2913 int net_open_connection(network_info_s *network_info, const char *profile_name)
2914 {
2915         __NETWORK_FUNC_ENTER__;
2916
2917         net_err_e Error = NET_ERR_NONE;
2918
2919         WIFI_LOG(WIFI_INFO, "Open: %s", profile_name);
2920
2921         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
2922                 WIFI_LOG(WIFI_ERROR, "Invalid profile name"); //LCOV_EXCL_LINE
2923                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2924                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
2925         }
2926
2927         if (network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER].flag == TRUE ||
2928                 network_info->request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE ||
2929                 network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag == TRUE ||
2930                 network_info->request_table[NETWORK_REQUEST_TYPE_FORGET_AP].flag == TRUE) {
2931                 WIFI_LOG(WIFI_ERROR, "pending call in progress"); //LCOV_EXCL_LINE
2932                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2933                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
2934         }
2935
2936         if (network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE) {
2937                 WIFI_LOG(WIFI_ERROR, "Request in progress"); //LCOV_EXCL_LINE
2938                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2939                 return NET_ERR_IN_PROGRESS; //LCOV_EXCL_LINE
2940         }
2941
2942         network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag = TRUE;
2943         g_strlcpy(network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].ProfileName,
2944                         profile_name, NET_PROFILE_NAME_LEN_MAX+1);
2945
2946         Error = _net_dbus_open_connection(network_info, profile_name);
2947         if (Error != NET_ERR_NONE) {
2948                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
2949                                 "Failed to request open connection, Error [%s]",
2950                                 _net_print_error(Error));
2951
2952                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION]), //LCOV_EXCL_LINE
2953                                 0, sizeof(network_request_table_s));
2954
2955                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2956                 return Error; //LCOV_EXCL_LINE
2957         }
2958
2959         __NETWORK_FUNC_EXIT__;
2960         return NET_ERR_NONE;
2961 }
2962
2963 int net_close_connection(network_info_s *network_info, const char *profile_name)
2964 {
2965         __NETWORK_FUNC_ENTER__;
2966
2967         net_err_e Error = NET_ERR_NONE;
2968
2969         WIFI_LOG(WIFI_INFO, "ProfileName [%s] passed", profile_name);
2970
2971         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
2972                 WIFI_LOG(WIFI_ERROR, "Invalid profile name"); //LCOV_EXCL_LINE
2973                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2974                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
2975         }
2976
2977         if (network_info->request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE) {
2978                 WIFI_LOG(WIFI_ERROR, "Request in progress"); //LCOV_EXCL_LINE
2979                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2980                 return NET_ERR_IN_PROGRESS; //LCOV_EXCL_LINE
2981         }
2982
2983         network_info->request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag = TRUE;
2984         g_strlcpy(network_info->request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].ProfileName,
2985                         profile_name, NET_PROFILE_NAME_LEN_MAX+1);
2986
2987         Error = _net_dbus_close_connection(network_info, profile_name);
2988         if (Error != NET_ERR_NONE) {
2989                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
2990                                 "Failed to request close connection, Error [%s]",
2991                                 _net_print_error(Error));
2992
2993                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION]), //LCOV_EXCL_LINE
2994                                 0, sizeof(network_request_table_s));
2995
2996                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2997                 return Error; //LCOV_EXCL_LINE
2998         }
2999
3000         __NETWORK_FUNC_EXIT__;
3001         return NET_ERR_NONE;
3002 }
3003
3004 int net_delete_profile(network_info_s *network_info, const char* profile_name)
3005 {
3006         __NETWORK_FUNC_ENTER__;
3007
3008         net_err_e Error = NET_ERR_NONE;
3009         net_profile_name_s wifi_prof_name;
3010         net_profile_info_s prof_info;
3011
3012         WIFI_LOG(WIFI_INFO, "Delete Profile [%s]", profile_name);
3013
3014         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
3015                 WIFI_LOG(WIFI_ERROR, "Invalid Parameter"); //LCOV_EXCL_LINE
3016                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3017                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
3018         }
3019
3020         Error = __net_get_profile_info(network_info, profile_name, &prof_info);
3021         if (Error != NET_ERR_NONE) {
3022                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3023                                 "Failed to get service(profile) information. Error [%s]",
3024                                 _net_print_error(Error));
3025
3026                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3027                 return Error; //LCOV_EXCL_LINE
3028         }
3029
3030         g_strlcpy(wifi_prof_name.ProfileName, profile_name, NET_PROFILE_NAME_LEN_MAX + 1);
3031
3032         Error = __net_wifi_delete_profile(network_info,
3033                         &wifi_prof_name,
3034                         prof_info.security_info.sec_mode,
3035                         prof_info.passpoint);
3036         if (Error != NET_ERR_NONE) {
3037                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3038                                 "Failed to delete service(profile). Error [%s]",
3039                                 _net_print_error(Error));
3040
3041                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3042                 return Error; //LCOV_EXCL_LINE
3043         }
3044
3045         __NETWORK_FUNC_EXIT__;
3046         return NET_ERR_NONE;
3047 }
3048
3049 static void _net_delete_profile_async_reply(GObject *source_object,
3050                         GAsyncResult *res, gpointer user_data)
3051 {
3052         __NETWORK_FUNC_ENTER__;
3053
3054         GDBusConnection *conn = NULL;
3055         GError *error = NULL;
3056         net_err_e Error = NET_ERR_NONE;
3057         GVariant *message = NULL;
3058         GVariantIter *iter = NULL;
3059         GVariantIter *service = NULL;
3060         gchar *path = NULL;
3061         net_profile_name_s wifi_prof_name;
3062         net_profile_info_s prof_info;
3063         network_info_s *network_info = (network_info_s *)user_data;
3064         network_request_table_s *request_table = network_info->request_table;
3065
3066         conn = G_DBUS_CONNECTION(source_object);
3067         message = g_dbus_connection_call_finish(conn, res, &error);
3068         if (message == NULL && error != NULL) {
3069                 WIFI_LOG(WIFI_ERROR, "Delete profile, error [%s]", error->message);
3070                 Error = NET_ERR_UNKNOWN;
3071                 g_error_free(error);
3072                 goto error;
3073         }
3074
3075         Error = NET_ERR_NO_PROFILE;
3076         g_variant_get(message, "(a(oa{sv}))", &iter);
3077         if (iter == NULL) {
3078                 g_variant_unref(message);
3079                 goto error;
3080         }
3081
3082         while (g_variant_iter_loop(iter, "(oa{sv})", &path, &service)) {
3083                 if (g_strcmp0(request_table[NETWORK_REQUEST_TYPE_FORGET_AP].ProfileName, path) == 0) {
3084                         Error = __net_extract_service_info(network_info,
3085                                                 path, service, &prof_info);
3086                         g_variant_iter_free(service);
3087                         g_free(path);
3088                         break;
3089                 }
3090         }
3091
3092         g_variant_iter_free(iter);
3093         g_variant_unref(message);
3094
3095         if (Error != NET_ERR_NONE)
3096                 goto error;
3097
3098         g_strlcpy(wifi_prof_name.ProfileName,
3099                   request_table[NETWORK_REQUEST_TYPE_FORGET_AP].ProfileName,
3100                   NET_PROFILE_NAME_LEN_MAX + 1);
3101
3102         Error = __net_wifi_delete_profile(network_info, &wifi_prof_name,
3103                         prof_info.security_info.sec_mode, prof_info.passpoint);
3104         if (Error != NET_ERR_NONE) {
3105                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3106                                 "Failed to delete service(profile). Error [%s]",
3107                                 _net_print_error(Error));
3108                 goto error;
3109         }
3110
3111         if (prof_info.ProfileState != NET_STATE_TYPE_ONLINE &&
3112             prof_info.ProfileState != NET_STATE_TYPE_READY &&
3113             prof_info.ProfileState != NET_STATE_TYPE_ASSOCIATION &&
3114             prof_info.ProfileState != NET_STATE_TYPE_CONFIGURATION)
3115                 net_forget_ap_finished(network_info, Error);
3116
3117         __NETWORK_FUNC_EXIT__;
3118         return;
3119
3120 error:
3121         net_forget_ap_finished(network_info, Error);
3122         __NETWORK_FUNC_EXIT__;
3123 }
3124
3125 int net_delete_profile_async(network_info_s *network_info, const char* profile_name)
3126 {
3127         __NETWORK_FUNC_ENTER__;
3128
3129         net_err_e Error = NET_ERR_NONE;
3130
3131         WIFI_LOG(WIFI_INFO, "Delete Profile [%s]", profile_name);
3132
3133         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
3134                 WIFI_LOG(WIFI_ERROR, "Invalid Parameter"); //LCOV_EXCL_LINE
3135                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3136                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
3137         }
3138
3139         /* Get service details */
3140         network_info->request_table[NETWORK_REQUEST_TYPE_FORGET_AP].flag = TRUE;
3141         g_strlcpy(network_info->request_table[NETWORK_REQUEST_TYPE_FORGET_AP].ProfileName,
3142                   profile_name, NET_PROFILE_NAME_LEN_MAX+1);
3143
3144         Error = _net_invoke_dbus_method_nonblock(network_info,
3145                                 CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
3146                                 CONNMAN_MANAGER_INTERFACE, "GetServices",
3147                                 NULL, DBUS_REPLY_TIMEOUT,
3148                                 _net_delete_profile_async_reply);
3149         if (Error != NET_ERR_NONE) {
3150                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3151                                 "Failed to get service(profile) information. Error [%s]",
3152                                 _net_print_error(Error));
3153
3154                 network_info->request_table[NETWORK_REQUEST_TYPE_FORGET_AP].flag = FALSE;
3155                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3156                 return Error; //LCOV_EXCL_LINE
3157         }
3158
3159         __NETWORK_FUNC_EXIT__;
3160         return NET_ERR_NONE;
3161 }
3162
3163 int net_modify_profile(network_info_s *network_info,
3164                 const char* profile_name, net_profile_info_s* prof_info)
3165 {
3166         __NETWORK_FUNC_ENTER__;
3167
3168         net_err_e Error = NET_ERR_NONE;
3169         net_profile_info_s exProfInfo;
3170
3171         if (!net_get_device_policy_wifi(network_info)) {
3172                 WIFI_LOG(WIFI_ERROR, "Wifi device policy restricts"); //LCOV_EXCL_LINE
3173                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3174                 return NET_ERR_SECURITY_RESTRICTED; //LCOV_EXCL_LINE
3175         }
3176
3177         if (!net_get_device_policy_wifi_profile(network_info)) {
3178                 WIFI_LOG(WIFI_ERROR, "Wifi profile device policy restricts"); //LCOV_EXCL_LINE
3179                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3180                 return NET_ERR_SECURITY_RESTRICTED; //LCOV_EXCL_LINE
3181         }
3182
3183         Error = net_get_profile_info(network_info, profile_name, &exProfInfo);
3184         if (Error != NET_ERR_NONE) {
3185                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3186                                 "Failed to get service(profile) information. Error [%s]",
3187                                 _net_print_error(Error));
3188
3189                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3190                 return Error; //LCOV_EXCL_LINE
3191         }
3192
3193         if (prof_info == NULL) {
3194                 WIFI_LOG(WIFI_ERROR, "Invalid Parameter"); //LCOV_EXCL_LINE
3195                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3196                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
3197         }
3198
3199
3200         Error = __net_wifi_modify_profile(network_info, profile_name, prof_info, &exProfInfo);
3201
3202         if (Error != NET_ERR_NONE) {
3203                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3204                                 "Failed to modify service(profile) information. Error [%s]",
3205                                 _net_print_error(Error));
3206
3207                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3208                 return Error; //LCOV_EXCL_LINE
3209         }
3210
3211         __NETWORK_FUNC_EXIT__;
3212         return NET_ERR_NONE;
3213 }
3214
3215 int net_get_profile_info(network_info_s *network_info,
3216                 const char *profile_name, net_profile_info_s *prof_info)
3217 {
3218         __NETWORK_FUNC_ENTER__;
3219
3220         net_err_e Error = NET_ERR_NONE;
3221
3222         if (prof_info == NULL ||
3223                         _net_check_profile_name(profile_name) != NET_ERR_NONE) {
3224                 WIFI_LOG(WIFI_ERROR, "Invalid Parameter"); //LCOV_EXCL_LINE
3225
3226                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3227                 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
3228         }
3229
3230         Error = __net_get_profile_info(network_info, profile_name, prof_info);
3231         if (Error != NET_ERR_NONE)
3232                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3233                                 "Failed to get service(profile) information. Error [%s]",
3234                                 _net_print_error(Error));
3235
3236         __NETWORK_FUNC_EXIT__;
3237         return Error;
3238 }
3239
3240 int net_get_interface_list(network_info_s *network_info, GSList **interface_list)
3241 {
3242         __NETWORK_FUNC_ENTER__;
3243
3244         net_err_e Error = NET_ERR_NONE;
3245
3246         Error = _net_get_interface_list(network_info, interface_list);
3247         if (Error != NET_ERR_NONE) {
3248                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3249                                 "Failed to get interface list. Error [%s]",
3250                                 _net_print_error(Error));
3251         }
3252
3253         __NETWORK_FUNC_EXIT__;
3254         return Error;
3255 }
3256
3257 int net_get_profile_list(network_info_s *network_info, GSList **profile_list)
3258 {
3259         __NETWORK_FUNC_ENTER__;
3260
3261         net_err_e Error = NET_ERR_NONE;
3262
3263         Error = _net_get_profile_list(network_info, profile_list);
3264         if (Error != NET_ERR_NONE) {
3265                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3266                                 "Failed to get service(profile) list. Error [%s]",
3267                                 _net_print_error(Error));
3268         }
3269
3270         __NETWORK_FUNC_EXIT__;
3271         return Error;
3272 }
3273
3274 int net_get_technology_properties(network_info_s *network_info, net_tech_info_s *tech_info)
3275 {
3276         __NETWORK_FUNC_ENTER__;
3277
3278         net_err_e Error = NET_ERR_NONE;
3279
3280         if ((Error = _net_dbus_get_tech_status(network_info, tech_info)) != NET_ERR_NONE) {
3281                 WIFI_LOG(WIFI_ERROR, "Failed to get technology status. Error [%s]", //LCOV_EXCL_LINE
3282                                 _net_print_error(Error));
3283                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3284                 return Error; //LCOV_EXCL_LINE
3285         }
3286
3287         __NETWORK_FUNC_EXIT__;
3288         return NET_ERR_NONE;
3289 }
3290
3291 int net_config_get_id_list(network_info_s *network_info, GSList **list)
3292 {
3293         __NETWORK_FUNC_ENTER__;
3294
3295         net_err_e Error = NET_ERR_NONE;
3296
3297         Error = _net_dbus_config_get_id_list(network_info, list);
3298         if (Error != NET_ERR_NONE)
3299                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3300                                 "Failed to get config id list. Error [%s]",
3301                                 _net_print_error(Error));
3302
3303         __NETWORK_FUNC_EXIT__;
3304         return Error;
3305 }
3306
3307 int net_config_set_field(network_info_s *network_info,
3308                 const gchar *config_id, const gchar *key, const gchar *value)
3309 {
3310         __NETWORK_FUNC_ENTER__;
3311
3312         net_err_e Error = NET_ERR_NONE;
3313
3314         Error = _net_dbus_config_set_field(network_info, config_id, key, value);
3315         if (Error != NET_ERR_NONE)
3316                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3317                                 "Failed to set field. Error [%s]",
3318                                 _net_print_error(Error));
3319
3320         __NETWORK_FUNC_EXIT__;
3321         return Error;
3322 }
3323
3324 int net_config_get_passphrase(network_info_s *network_info,
3325                 const gchar *config_id, gchar **passphrase)
3326 {
3327         __NETWORK_FUNC_ENTER__;
3328
3329         net_err_e Error = NET_ERR_NONE;
3330
3331         Error = _net_dbus_config_get_passphrase(network_info, config_id, passphrase);
3332         if (Error != NET_ERR_NONE)
3333                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3334                                 "Failed to get config id list. Error [%s]",
3335                                 _net_print_error(Error));
3336
3337         __NETWORK_FUNC_EXIT__;
3338         return Error;
3339 }
3340
3341 int net_config_save_configurations(network_info_s *network_info,
3342                 const gchar *config_id, const gchar *name, const gchar *ssid, const gchar *passphrase,
3343                 const gchar *proxy_address, net_ip_info_config_s *ip_info,
3344                 gboolean is_hidden, gboolean is_created)
3345 {
3346         __NETWORK_FUNC_ENTER__;
3347
3348         net_err_e Error = NET_ERR_NONE;
3349
3350         Error = _net_dbus_config_save_configurations(network_info,
3351                         config_id, name, ssid, passphrase, proxy_address,
3352                         ip_info, is_hidden, is_created);
3353         if (Error != NET_ERR_NONE)
3354                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3355                                 "Failed to save configurations. Error [%s]",
3356                                 _net_print_error(Error));
3357
3358         __NETWORK_FUNC_EXIT__;
3359         return Error;
3360 }
3361
3362 //LCOV_EXCL_START
3363 int net_config_save_eap_configurations(network_info_s *network_info,
3364                 const gchar *config_id, const gchar *name, const gchar *ssid, const gchar *passphrase,
3365                 const gchar *proxy_address, void *eap_config, gboolean is_hidden, gboolean is_created)
3366 {
3367         __NETWORK_FUNC_ENTER__;
3368
3369         net_err_e Error = NET_ERR_NONE;
3370         net_eap_config_s *net_eap_config = (net_eap_config_s *)eap_config;
3371
3372         Error = _net_dbus_config_save_eap_configurations(network_info,
3373                                 config_id, name, ssid, passphrase,
3374                                 proxy_address, net_eap_config, is_hidden, is_created);
3375         if (Error != NET_ERR_NONE)
3376                 WIFI_LOG(WIFI_ERROR,
3377                                 "Failed to save configurations. Error [%s]",
3378                                 _net_print_error(Error));
3379
3380         __NETWORK_FUNC_EXIT__;
3381         return Error;
3382 }
3383 //LCOV_EXCL_STOP
3384
3385 int net_config_remove_configurations(network_info_s *network_info,
3386                 const gchar *config_id)
3387 {
3388         __NETWORK_FUNC_ENTER__;
3389
3390         net_err_e Error = NET_ERR_NONE;
3391
3392         Error = _net_dbus_config_remove_configurations(network_info, config_id);
3393         if (Error != NET_ERR_NONE)
3394                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3395                                 "Failed to remove configurations. Error [%s]",
3396                                 _net_print_error(Error));
3397
3398         __NETWORK_FUNC_EXIT__;
3399         return Error;
3400 }
3401
3402 int net_config_load_configurations(network_info_s *network_info,
3403                 const gchar *config_id, gchar **name,
3404                 gchar **passphrase, void *security_type, gchar **proxy_address, gboolean *is_hidden,
3405                 net_ip_info_config_s **ip_info, void *last_error)
3406 {
3407         __NETWORK_FUNC_ENTER__;
3408
3409         net_err_e Error = NET_ERR_NONE;
3410         net_wifi_security_type_e *sec_type = (net_wifi_security_type_e *)security_type;
3411
3412         Error = _net_dbus_config_load_configurations(network_info,
3413                                 config_id, name, passphrase, sec_type, proxy_address,
3414                                 is_hidden, ip_info, last_error);
3415         if (Error != NET_ERR_NONE)
3416                 WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
3417                                 "Failed to load configurations. Error [%s]",
3418                                 _net_print_error(Error));
3419
3420         __NETWORK_FUNC_EXIT__;
3421         return Error;
3422 }
3423
3424 //LCOV_EXCL_START
3425 int net_config_load_eap_configurations(network_info_s *network_info,
3426                 const gchar *config_id, gchar **name, void *security_type, gchar **proxy_address,
3427                 gboolean *is_hidden, void **eap_config, void *last_error)
3428 {
3429         __NETWORK_FUNC_ENTER__;
3430
3431         net_err_e Error = NET_ERR_NONE;
3432         net_eap_config_s **net_eap_config = (net_eap_config_s **)eap_config;
3433         net_wifi_security_type_e *sec_type = (net_wifi_security_type_e *)security_type;
3434
3435         Error = _net_dbus_config_load_eap_configurations(network_info,
3436                                 config_id, name, sec_type, proxy_address, is_hidden,
3437                                 net_eap_config, last_error);
3438         if (Error != NET_ERR_NONE)
3439                 WIFI_LOG(WIFI_ERROR,
3440                                 "Failed to load eap configurations. Error [%s]",
3441                                 _net_print_error(Error));
3442
3443         __NETWORK_FUNC_EXIT__;
3444         return Error;
3445 }
3446
3447 int net_wifi_set_autoscan(network_info_s *network_info, gboolean autoscan)
3448 {
3449         __NETWORK_FUNC_ENTER__;
3450
3451         net_err_e Error = NET_ERR_NONE;
3452
3453         WIFI_LOG(WIFI_INFO, "[%s] auto scan", autoscan ? "enable" : "disable");
3454
3455         if (autoscan)
3456                 Error = _net_dbus_resume_bgscan(network_info);
3457         else
3458                 Error = _net_dbus_pause_bgscan(network_info);
3459
3460         if (Error != NET_ERR_NONE) {
3461                 WIFI_LOG(WIFI_ERROR,
3462                                 "Failed to enable/disable auto scan Error [%s]",
3463                                 _net_print_error(Error));
3464
3465                 __NETWORK_FUNC_EXIT__;
3466                 return Error;
3467         }
3468
3469         __NETWORK_FUNC_EXIT__;
3470         return NET_ERR_NONE;
3471 }
3472
3473 int net_wifi_set_background_scan_mode(network_info_s *network_info,
3474                 net_wifi_background_scan_mode_e scan_mode)
3475 {
3476         __NETWORK_FUNC_ENTER__;
3477
3478         net_err_e Error = NET_ERR_NONE;
3479
3480         Error = __net_get_wifi_state(network_info);
3481         if (Error != NET_ERR_NONE) {
3482                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
3483                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3484                 return Error; //LCOV_EXCL_LINE
3485         }
3486
3487         if (network_info->wifi_state == WIFI_OFF) {
3488                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
3489                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3490                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
3491         }
3492
3493         if ((Error = _net_dbus_set_bgscan_mode(network_info, scan_mode)) != NET_ERR_NONE) {
3494                 WIFI_LOG(WIFI_ERROR,
3495                                 "Failed to set bgscan mode. Error [%s]",
3496                                 _net_print_error(Error));
3497
3498                 __NETWORK_FUNC_EXIT__;
3499                 return Error;
3500         }
3501
3502         __NETWORK_FUNC_EXIT__;
3503         return NET_ERR_NONE;
3504 }
3505
3506 int net_wifi_set_ip_conflict_period(network_info_s *network_info,
3507                 unsigned int initial_time)
3508 {
3509         __NETWORK_FUNC_ENTER__;
3510
3511         net_err_e Error = NET_ERR_NONE;
3512
3513         if ((Error = _net_dbus_set_ip_conflict_period(network_info, initial_time)) != NET_ERR_NONE) {
3514                 WIFI_LOG(WIFI_ERROR,
3515                                 "Failed to set ip conflict detect period. Error [%s]",
3516                                 _net_print_error(Error));
3517
3518                 __NETWORK_FUNC_EXIT__;
3519                 return Error;
3520         }
3521
3522         __NETWORK_FUNC_EXIT__;
3523         return NET_ERR_NONE;
3524 }
3525
3526 int net_wifi_get_ip_conflict_period(network_info_s *network_info,
3527                 unsigned int* initial_time)
3528 {
3529         __NETWORK_FUNC_ENTER__;
3530
3531         net_err_e Error = NET_ERR_NONE;
3532         GVariant *params = NULL;
3533         GVariant *message = NULL;
3534
3535         params = g_variant_new("(s)", network_info->interface_name);
3536
3537         message = _net_invoke_dbus_method(network_info,
3538                         NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
3539                         NETCONFIG_WIFI_INTERFACE, "GetIpConflictPeriod",
3540                         params, &Error);
3541         if (message == NULL) {
3542                 WIFI_LOG(WIFI_ERROR, "Failed to get IP conflict detection period"); //LCOV_EXCL_LINE
3543                 __NETWORK_FUNC_EXIT__;
3544                 return Error; //LCOV_EXCL_LINE
3545         }
3546
3547         g_variant_get(message, "(u)", initial_time);
3548         g_variant_unref(message);
3549
3550         __NETWORK_FUNC_EXIT__;
3551         return Error;
3552 }
3553
3554 int net_wifi_get_ip_conflict_state(network_info_s *network_info, unsigned int *state)
3555 {
3556         __NETWORK_FUNC_ENTER__;
3557
3558         net_err_e Error = NET_ERR_NONE;
3559         GVariant *params = NULL;
3560         GVariant *message = NULL;
3561
3562         params = g_variant_new("(s)", network_info->interface_name);
3563
3564         message = _net_invoke_dbus_method(network_info,
3565                         NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
3566                         NETCONFIG_WIFI_INTERFACE, "GetIpConflictState",
3567                         params, &Error);
3568         if (message == NULL) {
3569                 WIFI_LOG(WIFI_ERROR, "Failed to get IP conflict state"); //LCOV_EXCL_LINE
3570                 __NETWORK_FUNC_EXIT__;
3571                 return Error; //LCOV_EXCL_LINE
3572         }
3573
3574         g_variant_get(message, "(u)", state);
3575         g_variant_unref(message);
3576
3577         __NETWORK_FUNC_EXIT__;
3578         return Error;
3579 }
3580
3581 int net_wifi_get_autoscan(network_info_s *network_info, gboolean *autoscan)
3582 {
3583         __NETWORK_FUNC_ENTER__;
3584
3585         net_err_e Error = NET_ERR_NONE;
3586
3587         Error = _net_dbus_get_autoscan(network_info, autoscan);
3588         if (Error != NET_ERR_NONE) {
3589                 WIFI_LOG(WIFI_ERROR,
3590                                 "_net_dbus_get_autoscan() failed. Error [%s]",
3591                                 _net_print_error(Error));
3592         }
3593
3594         __NETWORK_FUNC_EXIT__;
3595         return Error;
3596 }
3597
3598 int net_wifi_get_autoscanmode(network_info_s *network_info, unsigned int *autoscanmode)
3599 {
3600         __NETWORK_FUNC_ENTER__;
3601
3602         net_err_e Error = NET_ERR_NONE;
3603
3604         Error = _net_dbus_get_autoscanmode(network_info, autoscanmode);
3605         if (Error != NET_ERR_NONE) {
3606                 WIFI_LOG(WIFI_ERROR,
3607                                 "_net_dbus_get_autoscanmode() failed. Error [%s]",
3608                                 _net_print_error(Error));
3609         }
3610
3611         __NETWORK_FUNC_EXIT__;
3612         return Error;
3613 }
3614
3615 int net_wifi_get_module_state(network_info_s *network_info, int *module_state)
3616 {
3617         GVariant *message = NULL, *variant;
3618         GVariantIter *iter, *next;
3619         const char *path;
3620         gchar *key;
3621         net_err_e Error = NET_ERR_NONE;
3622
3623         message = _net_invoke_dbus_method(network_info,
3624                         CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
3625                         CONNMAN_MANAGER_INTERFACE, "GetTechnologies",
3626                         NULL, &Error);
3627
3628         if (message == NULL) {
3629                 WIFI_LOG(WIFI_ERROR, "Failed to get_technology_state");
3630                 return Error;
3631         }
3632
3633         *module_state = 0;
3634
3635         g_variant_get(message, "(a(oa{sv}))", &iter);
3636         while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) {
3637                 if (path == NULL || g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) != 0)
3638                         continue;
3639
3640                 while (g_variant_iter_loop(next, "{sv}", &key, &variant)) {
3641                         if (g_strcmp0(key, "Device.List") == 0) {
3642                                 GVariantIter *list_iter = NULL;
3643                                 gchar *dev_key = NULL;
3644                                 GVariant *dev_var = NULL;
3645                                 const gchar *sdata = NULL;
3646
3647                                 g_variant_get(variant, "a{sv}", &list_iter);
3648                                 while(g_variant_iter_loop(list_iter, "{sv}", &dev_key, &dev_var)) {
3649                                         if (g_variant_is_of_type(dev_var, G_VARIANT_TYPE_STRING)) {
3650                                                 sdata = g_variant_get_string(dev_var, NULL);
3651                                                 WIFI_LOG(WIFI_INFO, "%s [%s]", dev_key, sdata);
3652
3653                                                 if (g_strcmp0(dev_key, "Ifname") == 0) {
3654                                                         if (g_strcmp0(sdata, network_info->interface_name) == 0)
3655                                                                 *module_state = 1;
3656                                                 }
3657                                         }
3658                                 }
3659                                 g_variant_iter_free(list_iter);
3660                         }
3661                 }
3662         }
3663
3664         g_variant_unref(message);
3665         g_variant_iter_free(iter);
3666
3667         return NET_ERR_NONE;
3668 }
3669
3670 static int __net_convert_string_to_ipv6_string(char *str, char **ip_address)
3671 {
3672         int i = 1;
3673         int pos = 0;
3674         struct sockaddr_in6 sa;
3675
3676         *ip_address = (char *)malloc(INET6_ADDRSTRLEN);
3677         if (NULL == *ip_address) {
3678                 WIFI_LOG(WIFI_ERROR, "Malloc Failed");
3679                 return NET_ERR_INVALID_OPERATION;
3680         }
3681
3682         /* Convert String without : to string with : */
3683         for (i = 1; i < 8; i++) {
3684                 pos = 4 * i + i;
3685                 memmove(str + pos, str + pos - 1,
3686                                 strlen(str) - pos + 2 * i);
3687                 str[pos - 1] = ':';
3688         }
3689
3690         /*
3691          * Convert "fe80:0000:0000:0000:0a00:27ff:fe7a:65ea" to fe80::a00:27ff:fe7a:65ea
3692          */
3693         inet_pton(AF_INET6, str, &(sa.sin6_addr));
3694         inet_ntop(AF_INET6, &(sa.sin6_addr), *ip_address, INET6_ADDRSTRLEN);
3695
3696         return NET_ERR_NONE;
3697 }
3698
3699 int net_foreach_ipv6_address(GSList **ipv6_address_list)
3700 {
3701         __NETWORK_FUNC_ENTER__;
3702
3703         FILE *fp = NULL;
3704         char *ip_address = NULL;
3705         char *if_name = NULL;
3706
3707         char buf[NET_IPV6_ADDRESS_FILE_LEN] = {0, };
3708         char str[NET_IPV6_ADDRESS_FILE_LEN] = {0, };
3709
3710         net_err_e Error = NET_ERR_NONE;
3711
3712         fp = fopen(NET_IPV6_ADDRESS_FILE, "r");
3713         if (fp == NULL) {
3714                 WIFI_LOG(WIFI_ERROR, "Failed to open file");
3715                 __NETWORK_FUNC_EXIT__;
3716                 return NET_ERR_INVALID_OPERATION;
3717         }
3718
3719         while (fgets(buf, sizeof(buf), fp) != NULL) {
3720                 sscanf(buf, "%64s", str);
3721                 if_name = strstr(buf, "wlan");
3722                 if (if_name != NULL) {
3723                         Error = __net_convert_string_to_ipv6_string(str, &ip_address);
3724                         if (Error == NET_ERR_NONE)
3725                                 *ipv6_address_list = g_slist_append(*ipv6_address_list, ip_address);
3726                 }
3727         }
3728
3729         fclose(fp);
3730
3731         __NETWORK_FUNC_EXIT__;
3732         return Error;
3733 }
3734
3735 int net_get_preferred_ipv6_address(network_info_s *network_info,
3736                 const char *profilename, char **address)
3737 {
3738         __NETWORK_FUNC_ENTER__;
3739         net_err_e Error = NET_ERR_NONE;
3740
3741         Error = _net_dbus_get_preferred_ipv6_address(network_info, profilename, address);
3742         if (Error != NET_ERR_NONE)
3743                 WIFI_LOG(WIFI_ERROR, "_net_dbus_get_preferred_ipv6_address failed");
3744
3745         __NETWORK_FUNC_EXIT__;
3746         return Error;
3747 }
3748
3749 int net_get_service_state(network_info_s *network_info)
3750 {
3751         return network_info->service_state;
3752 }
3753
3754 int net_wifi_get_max_scan_ssids(network_info_s *network_info, int *max_scan_ssids)
3755 {
3756         __NETWORK_CAPI_FUNC_ENTER__;
3757
3758         net_err_e Error = NET_ERR_NONE;
3759
3760         Error = _net_dbus_get_max_scan_ssids(network_info, max_scan_ssids);
3761         if (Error != NET_ERR_NONE) {
3762                 WIFI_LOG(WIFI_ERROR,
3763                                 "Failed to get Max scan SSIDs. Error [%s]",
3764                                 _net_print_error(Error));
3765
3766                 __NETWORK_CAPI_FUNC_EXIT__;
3767                 return Error;
3768         }
3769
3770         __NETWORK_CAPI_FUNC_EXIT__;
3771         return NET_ERR_NONE;
3772 }
3773
3774 static net_err_e __check_preconditions(network_info_s *network_info)
3775 {
3776         net_err_e Error = NET_ERR_NONE;
3777
3778         Error = __net_get_wifi_state(network_info);
3779         if (Error != NET_ERR_NONE) {
3780                 WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE
3781                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3782                 return Error; //LCOV_EXCL_LINE
3783         }
3784
3785         if (network_info->wifi_state == WIFI_OFF) {
3786                 WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE
3787                 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3788                 return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
3789         }
3790
3791         return Error;
3792 }
3793
3794 int net_dpp_enter_peer_uri(network_info_s *network_info,
3795                 guint32 peer_id, guint32 own_id, const char *uri)
3796 {
3797         net_err_e Error = NET_ERR_NONE;
3798
3799         Error = __check_preconditions(network_info);
3800         if (Error != NET_ERR_NONE)
3801                 WIFI_LOG(WIFI_ERROR, "Failed to enter peer uri : %d", Error);
3802         /* TODO generate args, set request table value, handle return values*/
3803
3804         Error = _net_dbus_dpp_enter_peer_uri(network_info, peer_id, own_id, uri);
3805
3806         if (Error != NET_ERR_NONE) {
3807                 WIFI_LOG(WIFI_ERROR,
3808                                 "Set Peer Uri dbus request failed. Error [%s]",
3809                                 _net_print_error(Error));
3810         }
3811
3812         return Error;
3813 }
3814
3815 int net_dpp_generate_own_uri(network_info_s *network_info,
3816                 guint32 peer_id, guint32 own_id, gboolean is_initiator, const char *key)
3817 {
3818         net_err_e Error = NET_ERR_NONE;
3819
3820         Error = __check_preconditions(network_info);
3821         if (Error != NET_ERR_NONE)
3822                 WIFI_LOG(WIFI_ERROR, "Failed to generate uri : %d", Error);
3823         /* TODO generate args, set request table value, handle return values*/
3824
3825         Error = _net_dbus_dpp_generate_uri(network_info, peer_id, own_id, is_initiator, key);
3826
3827         if (Error != NET_ERR_NONE) {
3828                 WIFI_LOG(WIFI_ERROR,
3829                                 "Generate URI dbus request failed. Error [%s]",
3830                                 _net_print_error(Error));
3831         }
3832
3833         return Error;
3834 }
3835
3836 static gchar *__dpp_network_role_to_string(wifi_manager_dpp_network_role_e role)
3837 {
3838         if (role == WIFI_MANAGER_DPP_NETWORK_ROLE_AP)
3839                 return "ap";
3840         else if (role == WIFI_MANAGER_DPP_NETWORK_ROLE_STA)
3841                 return "sta";
3842         else
3843                 return NULL;
3844 }
3845
3846 static gchar *__dpp_akm_to_string(wifi_manager_dpp_akm_e akm)
3847 {
3848         if (akm == WIFI_MANAGER_DPP_AKM_PSK)
3849                 return "psk";
3850         else if (akm == WIFI_MANAGER_DPP_AKM_SAE)
3851                 return "sae";
3852         else if (akm == WIFI_MANAGER_DPP_AKM_DPP)
3853                 return "dpp";
3854         else
3855                 return NULL;
3856 }
3857
3858 static net_err_e __net_dpp_start_each(wifi_dpp_s *p_dpp, const char *auth_key,
3859                 const char *configurator_key, const char *pass)
3860 {
3861         int rv;
3862         gboolean is_configurator = (p_dpp->role == WIFI_MANAGER_DPP_ROLE_CONFIGURATOR);
3863
3864         if (p_dpp->is_initiator && is_configurator)
3865                 rv = _net_dbus_dpp_start_configurator_initiator(p_dpp->network_info,
3866                                 p_dpp->group_id, p_dpp->ssid,
3867                                 p_dpp->peer_uri, p_dpp->peer_id,
3868                                 __dpp_network_role_to_string(p_dpp->net_role),
3869                                 __dpp_akm_to_string(p_dpp->akm),
3870                                 configurator_key, pass);
3871         else if (p_dpp->is_initiator && !is_configurator)
3872                 rv = _net_dbus_dpp_start_enrollee_initiator(p_dpp->network_info,
3873                                 p_dpp->peer_uri, p_dpp->peer_id);
3874         else if (!p_dpp->is_initiator && is_configurator)
3875                 rv = _net_dbus_dpp_start_configurator_responder(p_dpp->network_info,
3876                                 p_dpp->group_id, p_dpp->ssid,
3877                                 __dpp_network_role_to_string(p_dpp->net_role),
3878                                 __dpp_akm_to_string(p_dpp->akm),
3879                                 auth_key, configurator_key, pass);
3880         else
3881                 rv = _net_dbus_dpp_start_enrollee_responder(p_dpp->network_info, auth_key);
3882
3883         return rv;
3884 }
3885
3886 int net_dpp_start(void *dpp_handle, const char *auth_key,
3887                 const char *configurator_key, const char *pass)
3888 {
3889         net_err_e Error = NET_ERR_NONE;
3890         wifi_dpp_s *dpp_data = (wifi_dpp_s *)dpp_handle;
3891
3892         Error = __check_preconditions(dpp_data->network_info);
3893         if (Error != NET_ERR_NONE)
3894                 WIFI_LOG(WIFI_ERROR, "Failed to start dpp uri : %d", Error);
3895         /* TODO generate args, set request table value, handle return values*/
3896
3897         Error = __net_dpp_start_each(dpp_data, auth_key, configurator_key, pass);
3898
3899         if (Error != NET_ERR_NONE) {
3900                 WIFI_LOG(WIFI_ERROR,
3901                                 "DppStart dbus request failed. Error [%s]",
3902                                 _net_print_error(Error));
3903         }
3904
3905         return Error;
3906 }
3907
3908 int net_dpp_stop(network_info_s *network_info,
3909                 guint32 peer_id, guint32 own_id, gboolean is_initiator)
3910 {
3911         net_err_e Error = NET_ERR_NONE;
3912
3913         Error = __check_preconditions(network_info);
3914         if (Error != NET_ERR_NONE)
3915                 WIFI_LOG(WIFI_ERROR, "Failed to stop dpp : %d", Error);
3916         /* TODO generate args, set request table value, handle return values*/
3917
3918         Error = _net_dbus_dpp_stop(network_info, peer_id, own_id, is_initiator);
3919
3920         if (Error != NET_ERR_NONE) {
3921                 WIFI_LOG(WIFI_ERROR,
3922                                 "DppStop dbus request failed. Error [%s]",
3923                                 _net_print_error(Error));
3924         }
3925
3926         return Error;
3927 }
3928 //LCOV_EXCL_STOP