2 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <vconf-keys.h>
21 #include <arpa/inet.h>
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"
29 #define DBUS_OBJECT_PATH_MAX 150
32 static int __net_check_get_privilege(network_info_s *network_info)
34 __NETWORK_FUNC_ENTER__;
36 net_err_e Error = NET_ERR_NONE;
37 GVariant *message = NULL;
39 message = _net_invoke_dbus_method(network_info,
40 NETCONFIG_SERVICE, NETCONFIG_NETWORK_PATH,
41 NETCONFIG_NETWORK_INTERFACE, "CheckGetPrivilege",
43 if (message == NULL) {
44 WIFI_LOG(WIFI_ERROR, "Failed to check get privilege"); //LCOV_EXCL_LINE
45 return Error; //LCOV_EXCL_LINE
48 g_variant_unref(message);
50 __NETWORK_FUNC_EXIT__;
54 static int __net_set_ip_conflict_detect_mode(network_info_s *network_info, bool detect)
56 __NETWORK_FUNC_ENTER__;
58 net_err_e Error = NET_ERR_NONE;
59 GVariant *message = NULL;
61 params = g_variant_new("(sb)", network_info->interface_name, detect);
63 message = _net_invoke_dbus_method(network_info,
64 NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
65 NETCONFIG_WIFI_INTERFACE, "IpConflictSetEnable",
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
73 g_variant_unref(message);
75 __NETWORK_FUNC_EXIT__;
79 static int __net_ip_conflict_detect_is_enabled(network_info_s *network_info,
82 __NETWORK_FUNC_ENTER__;
84 net_err_e Error = NET_ERR_NONE;
85 GVariant *params = NULL;
86 GVariant *message = NULL;
88 params = g_variant_new("(s)", network_info->interface_name);
90 message = _net_invoke_dbus_method(network_info,
91 NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
92 NETCONFIG_WIFI_INTERFACE, "IsIpConflictDetectEnabled",
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
100 g_variant_get(message, "(b)", state);
101 g_variant_unref(message);
103 __NETWORK_FUNC_EXIT__;
108 static int __net_check_profile_privilege(network_info_s *network_info)
110 __NETWORK_FUNC_ENTER__;
112 net_err_e Error = NET_ERR_NONE;
113 GVariant *message = NULL;
115 message = _net_invoke_dbus_method(network_info,
116 NETCONFIG_SERVICE, NETCONFIG_NETWORK_PATH,
117 NETCONFIG_NETWORK_INTERFACE, "CheckProfilePrivilege",
119 if (message == NULL) {
120 WIFI_LOG(WIFI_ERROR, "Failed to check profile privilege"); //LCOV_EXCL_LINE
121 return Error; //LCOV_EXCL_LINE
124 g_variant_unref(message);
126 __NETWORK_FUNC_EXIT__;
131 static int __net_get_prefix_len(const char *netmask)
133 __NETWORK_FUNC_ENTER__;
135 in_addr_t mask = inet_network(netmask);
138 for (; mask; mask <<= 1)
141 __NETWORK_FUNC_EXIT__;
147 static int __net_extract_ip(const gchar *value, net_addr_s *ipAddr)
149 __NETWORK_FUNC_ENTER__;
151 unsigned char *ipValue = NULL;
152 char *saveptr = NULL;
153 char ipString[NET_IPV4_STR_LEN_MAX+1];
156 ipValue = (unsigned char *)&(ipAddr->Data.Ipv4.s_addr);
159 g_strlcpy(ipString, value, NET_IPV4_STR_LEN_MAX+1);
161 ipToken[0] = strtok_r(ipString, ".", &saveptr);
163 if (ipToken[0] != NULL) {
164 ipToken[1] = strtok_r(NULL, ".", &saveptr);
166 if (ipToken[1] != NULL) {
167 ipToken[2] = strtok_r(NULL, ".", &saveptr);
169 if (ipToken[2] != NULL) {
170 ipToken[3] = strtok_r(NULL, ".", &saveptr);
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]);
183 __NETWORK_FUNC_EXIT__;
188 static gboolean __net_check_address_type(int address_family, const char *address)
190 unsigned char buf[sizeof(struct in6_addr)] = {0, };
193 err = inet_pton(address_family, address, buf);
200 static int __net_extract_common_info(const char *key, GVariant *variant, net_profile_info_s* ProfInfo)
202 __NETWORK_FUNC_ENTER__;
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;
211 net_info = &(ProfInfo->net_info);
213 if (g_strcmp0(key, "State") == 0) {
214 value = g_variant_get_string(variant, NULL);
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;
231 ProfInfo->ProfileState = NET_STATE_TYPE_UNKNOWN;
232 } else if (g_strcmp0(key, "Error") == 0) {
233 value = g_variant_get_string(variant, NULL);
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);
253 ProfInfo->Favourite = (char)TRUE;
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);
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);
268 g_strlcpy(net_info->MacAddr, value, WIFI_MAC_ADDR_LEN + 1);
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);
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;
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;
293 } else if (g_strcmp0(subKey, "Address") == 0) {
294 value = g_variant_get_string(var, NULL);
296 __net_extract_ip(value, &net_info->IpAddr);
297 } else if (g_strcmp0(subKey, "Netmask") == 0) {
298 value = g_variant_get_string(var, NULL);
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);
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);
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);
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) {
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);
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;
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);
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);
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);
354 __net_extract_ip(value, &net_info->GatewayAddr);
355 net_info->BDefGateway = TRUE;
358 g_variant_iter_free(iter);
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);
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;
373 } else if (g_strcmp0(subKey, "Address") == 0) {
374 value = g_variant_get_string(var, NULL);
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);
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);
388 g_strlcpy(net_info->Privacy6, value, NET_IPV6_MAX_PRIVACY_LEN);
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);
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;
405 } else if (g_strcmp0(subKey, "Address") == 0) {
406 value = g_variant_get_string(var, NULL);
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);
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);
420 g_strlcpy(net_info->Privacy6, value, NET_IPV6_MAX_PRIVACY_LEN);
423 g_variant_iter_free(iter);
424 } else if (g_strcmp0(key, "Nameservers") == 0) {
427 gchar *dns_value = NULL;
428 gchar *dns_type = NULL;
430 g_variant_get(variant, "as", &iter);
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 =
437 inet_pton(AF_INET6, dns_value,
438 &net_info->DnsAddr6[dnsCount6]\
442 } else if (__net_check_address_type(AF_INET, dns_value)) {
443 if (dnsCount < NET_DNS_ADDR_MAX) {
444 net_info->DnsAddr[dnsCount].Type =
446 __net_extract_ip(dns_value,
447 &net_info->DnsAddr[dnsCount]);
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;
467 g_variant_iter_free(iter);
469 net_info->DnsCount = dnsCount;
470 net_info->DnsCount6 = dnsCount6;
471 } else if (g_strcmp0(key, "Nameservers.Configuration") == 0 && net_info->DnsCount == 0) {
474 gchar *dns_value = NULL;
475 gchar *dns_type = NULL;
477 g_variant_get(variant, "as", &iter);
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 =
484 inet_pton(AF_INET6, dns_value,
485 &net_info->DnsAddr6[dnsCount6]\
489 } else if (__net_check_address_type(AF_INET, dns_value)) {
490 if (dnsCount < NET_DNS_ADDR_MAX) {
491 net_info->DnsAddr[dnsCount].Type =
493 __net_extract_ip(dns_value,
494 &net_info->DnsAddr[dnsCount]);
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;
514 g_variant_iter_free(iter);
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;
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);
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;
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;
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);
548 g_variant_iter_free(iter);
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);
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) {
561 const gchar *url = NULL;
562 gchar *servers = NULL;
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);
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;
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;
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");
586 g_variant_iter_free(iter_sub);
589 g_variant_iter_free(iter);
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);
598 } else if (g_strcmp0(key, "Provider") == 0) {
602 __NETWORK_FUNC_EXIT__;
606 static wlan_eap_type_e __convert_eap_type_from_string(const char *eap_type)
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;
621 return WLAN_SEC_EAP_TYPE_PEAP;
624 static wlan_eap_auth_type_e __convert_eap_auth_from_string(const char *eap_auth)
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;
641 return WLAN_SEC_EAP_AUTH_NONE;
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)
648 __NETWORK_FUNC_ENTER__;
650 net_err_e Error = NET_ERR_NONE;
652 char profilePath[NET_PROFILE_NAME_LEN_MAX+1] = "";
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);
659 g_strlcpy(profilePath, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
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);
668 if (NET_ERR_NONE != Error) {
669 WIFI_LOG(WIFI_ERROR, "Failed to set agent field");
671 __NETWORK_FUNC_EXIT__;
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);
682 if (NET_ERR_NONE != Error) {
683 WIFI_LOG(WIFI_ERROR, "Failed to set agent field");
685 __NETWORK_FUNC_EXIT__;
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)) {
695 Error = _net_dbus_set_proxy(network_info, ProfInfo, profilePath);
696 if (Error != NET_ERR_NONE) {
697 __NETWORK_FUNC_EXIT__;
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))) {
709 Error = _net_dbus_set_profile_ipv4(network_info, ProfInfo, profilePath);
711 if (Error != NET_ERR_NONE) {
712 WIFI_LOG(WIFI_ERROR, "Failed to set IPv4");
714 __NETWORK_FUNC_EXIT__;
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))) {
726 Error = _net_dbus_set_profile_ipv6(network_info, ProfInfo, profilePath);
728 if (Error != NET_ERR_NONE) {
729 WIFI_LOG(WIFI_ERROR, "Error!!! Can't set IPv6");
731 __NETWORK_FUNC_EXIT__;
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;
744 if (net_info->DnsAddr[i].Data.Ipv4.s_addr !=
745 ex_net_info->DnsAddr[i].Data.Ipv4.s_addr)
749 if (i < net_info->DnsCount ||
750 ex_net_info->DnsConfigType != net_info->DnsConfigType ||
751 ex_net_info->DnsConfigType6 != net_info->DnsConfigType6) {
753 Error = _net_dbus_set_profile_dns(network_info, ProfInfo, profilePath);
755 if (Error != NET_ERR_NONE) {
756 WIFI_LOG(WIFI_ERROR, "Failed to set DNS");
758 __NETWORK_FUNC_EXIT__;
763 __NETWORK_FUNC_EXIT__;
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,
771 __NETWORK_FUNC_ENTER__;
773 net_err_e Error = NET_ERR_NONE;
774 GVariant *message = NULL;
775 char param0[NET_PROFILE_NAME_LEN_MAX + 8] = "";
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",
784 if (message == NULL) {
785 WIFI_LOG(WIFI_ERROR, "Failed to Remove service(profile)");
786 g_variant_unref(message);
790 g_variant_unref(message);
792 g_snprintf(param0, NET_PROFILE_NAME_LEN_MAX + 8, "string:%s",
793 WifiProfName->ProfileName);
794 params = g_variant_new("(s)", param0);
796 message = _net_invoke_dbus_method(network_info,
797 NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
798 NETCONFIG_WIFI_INTERFACE, "DeleteEapConfig",
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",
806 g_snprintf(param0, NET_PROFILE_NAME_LEN_MAX + 8, "string:%s",
807 WifiProfName->ProfileName);
808 params = g_variant_new("(s)", param0);
810 message = _net_invoke_dbus_method(network_info,
811 NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
812 NETCONFIG_WIFI_INTERFACE, "DeleteEapConfig",
816 if (message == NULL) {
817 WIFI_LOG(WIFI_ERROR, "Failed to Remove service(profile)");
821 g_variant_unref(message);
823 __NETWORK_FUNC_EXIT__;
827 static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* ProfInfo)
829 net_err_e Error = NET_ERR_NONE;
830 GVariant *var = NULL;
831 const gchar *key = NULL;
833 __NETWORK_FUNC_ENTER__;
835 while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
836 const gchar *value = NULL;
838 if (g_strcmp0(key, "Mode") == 0) {
839 value = g_variant_get_string(var, NULL);
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;
846 ProfInfo->wlan_mode = NET_WLAN_CONNMODE_AUTO;
848 } else if (g_strcmp0(key, "Security") == 0) {
849 GVariantIter *iter_sub = NULL;
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;
888 g_variant_iter_free(iter_sub);
889 } else if (g_strcmp0(key, "EncryptionMode") == 0) {
890 value = g_variant_get_string(var, NULL);
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;
903 } else if (g_strcmp0(key, "Passpoint") == 0) {
906 passpoint = g_variant_get_boolean(var);
908 ProfInfo->passpoint = TRUE;
910 ProfInfo->passpoint = FALSE;
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);
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);
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) &&
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) {
934 val = g_variant_get_boolean(var);
937 ProfInfo->PassphraseRequired = TRUE;
939 ProfInfo->PassphraseRequired = FALSE;
940 } else if (g_strcmp0(key, "SSID") == 0) {
941 const gchar *ssid = NULL;
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);
950 g_strlcpy(ProfInfo->bssid, value, WIFI_MAC_ADDR_LEN + 1);
952 } else if (g_strcmp0(key, "MaxSpeed") == 0) {
953 ProfInfo->max_rate = g_variant_get_int32(var);
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);
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);
964 } else if (g_strcmp0(key, "Vsie") == 0) {
965 const unsigned char *vsie_bytes = NULL;
966 unsigned char *vsie = NULL;
969 vsie_bytes = g_variant_get_fixed_array(var, &size, sizeof(guchar));
972 vsie = (unsigned char *)g_try_malloc0(size);
974 memcpy(vsie, vsie_bytes, size);
975 ProfInfo->vsie_list = g_slist_append(ProfInfo->vsie_list, vsie);
977 WIFI_LOG(WIFI_ERROR, "Failed to allocate memory.");
979 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
980 ProfInfo->disconnect_reason = g_variant_get_int32(var);
982 } else if (g_strcmp0(key, "AssocStatusCode") == 0) {
983 ProfInfo->assoc_status_code = g_variant_get_int32(var);
985 } else if (g_strcmp0(key, "EAP") == 0) {
986 value = g_variant_get_string(var, NULL);
989 ProfInfo->security_info.authentication.eap.eap_type =
990 __convert_eap_type_from_string(value);
992 } else if (g_strcmp0(key, "Phase2") == 0) {
993 value = g_variant_get_string(var, NULL);
996 ProfInfo->security_info.authentication.eap.eap_auth =
997 __convert_eap_auth_from_string(value);
999 } else if (g_strcmp0(key, "Identity") == 0) {
1000 value = g_variant_get_string(var, NULL);
1003 g_strlcpy(ProfInfo->security_info.authentication.eap.username,
1004 value, NET_WLAN_USERNAME_LEN+1);
1006 } else if (g_strcmp0(key, "Password") == 0) {
1007 value = g_variant_get_string(var, NULL);
1010 g_strlcpy(ProfInfo->security_info.authentication.eap.password,
1011 value, NET_WLAN_PASSWORD_LEN+1);
1013 } else if (g_strcmp0(key, "CACertFile") == 0) {
1014 value = g_variant_get_string(var, NULL);
1017 g_strlcpy(ProfInfo->security_info.authentication.eap.ca_cert_filename,
1018 value, NET_WLAN_CA_CERT_FILENAME_LEN+1);
1020 } else if (g_strcmp0(key, "ClientCertFile") == 0) {
1021 value = g_variant_get_string(var, NULL);
1024 g_strlcpy(ProfInfo->security_info.authentication.eap.client_cert_filename,
1025 value, NET_WLAN_CLIENT_CERT_FILENAME_LEN+1);
1027 } else if (g_strcmp0(key, "PrivateKeyFile") == 0) {
1028 value = g_variant_get_string(var, NULL);
1031 g_strlcpy(ProfInfo->security_info.authentication.eap.private_key_filename,
1032 value, NET_WLAN_PRIVATE_KEY_FILENAME_LEN+1);
1034 } else if (g_strcmp0(key, "PrivateKeyPassphrase") == 0) {
1035 value = g_variant_get_string(var, NULL);
1038 g_strlcpy(ProfInfo->security_info.authentication.eap.private_key_passwd,
1039 value, NET_WLAN_PRIVATE_KEY_PASSWD_LEN+1);
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);
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);
1055 while (g_variant_iter_loop(iter_sub, "{sv}", &bssid_key,
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));
1061 value = g_variant_get_string(bssid_var, NULL);
1064 g_strlcpy(bssid_list->bssid, value, 18);
1066 WIFI_LOG(WIFI_ERROR, "Value is empty");
1068 WIFI_LOG(WIFI_ERROR, "Failed to allocate memory.");
1069 g_variant_unref(bssid_var);
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,
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);
1085 Error = __net_extract_common_info(key, var, ProfInfo);
1088 __NETWORK_FUNC_EXIT__;
1092 static int __net_extract_service_info(network_info_s *network_info,
1093 const char* ProfileName, GVariantIter *iter,
1094 net_profile_info_s* ProfInfo)
1096 __NETWORK_FUNC_ENTER__;
1098 net_err_e Error = NET_ERR_NONE;
1100 GVariant *value = NULL;
1101 gboolean isProf = FALSE;
1103 while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
1104 const gchar *tech = NULL;
1106 if (g_strcmp0(key, "Type") == 0) {
1107 tech = g_variant_get_string(value, NULL);
1109 if (g_strcmp0(tech, "wifi") == 0)
1112 g_variant_unref(value);
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__;
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);
1129 Error = __net_extract_wifi_info(iter, ProfInfo);
1132 __NETWORK_FUNC_EXIT__;
1136 static int __net_extract_all_services(network_info_s *network_info,
1137 GVariantIter *array, const char *service_prefix, GSList **profile_list)
1139 net_profile_info_s *ProfInfo = NULL;
1140 net_err_e Error = NET_ERR_NONE;
1142 GVariantIter *next = NULL;
1144 __NETWORK_FUNC_ENTER__;
1146 if (array == NULL || service_prefix == NULL) {
1147 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
1149 __NETWORK_FUNC_EXIT__;
1150 return NET_ERR_INVALID_PARAM;
1153 while (g_variant_iter_loop(array, "(oa{sv})", &obj, &next)) {
1157 if (_net_check_service_mac_addr(network_info, obj) != TRUE)
1160 if (g_str_has_prefix(obj, service_prefix) == TRUE) {
1161 ProfInfo = g_try_malloc0(sizeof(net_profile_info_s));
1162 if (ProfInfo == NULL)
1165 if ((Error = net_init_profile_info(network_info, ProfInfo)) != NET_ERR_NONE) {
1166 WIFI_LOG(WIFI_ERROR, "Failed to init profile");
1170 if (g_strrstr(obj + strlen(service_prefix), "hidden") != NULL)
1171 ProfInfo->is_hidden = TRUE;
1173 g_strlcpy(ProfInfo->ProfileName, obj, NET_PROFILE_NAME_LEN_MAX + 1);
1175 g_strlcpy(ProfInfo->net_info.ProfileName,
1176 obj, NET_PROFILE_NAME_LEN_MAX + 1);
1178 Error = __net_extract_wifi_info(next, ProfInfo);
1180 if (Error != NET_ERR_NONE) {
1181 WIFI_LOG(WIFI_ERROR, "Failed to extract service info");
1185 *profile_list = g_slist_append(*profile_list, (net_profile_info_s *)ProfInfo);
1189 __NETWORK_FUNC_EXIT__;
1190 return NET_ERR_NONE;
1194 g_variant_iter_free(next);
1199 __NETWORK_FUNC_EXIT__;
1203 static int __net_extract_services(network_info_s *network_info,
1204 GVariantIter *message, GSList **profile_list)
1206 __NETWORK_FUNC_ENTER__;
1208 net_err_e Error = NET_ERR_NONE;
1209 char *service_prefix = NULL;
1211 service_prefix = CONNMAN_WIFI_SERVICE_PROFILE_PREFIX;
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__;
1221 __NETWORK_FUNC_EXIT__;
1225 static int __net_get_profile_info(network_info_s *network_info,
1226 const char *ProfileName, net_profile_info_s *ProfInfo)
1228 __NETWORK_FUNC_ENTER__;
1230 net_err_e Error = NET_ERR_NONE;
1231 GVariant *message = NULL;
1232 GVariantIter *iter = NULL;
1233 GVariantIter *service = NULL;
1236 message = _net_invoke_dbus_method(network_info,
1237 CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
1238 CONNMAN_MANAGER_INTERFACE, "GetServices",
1240 if (message == NULL) {
1241 WIFI_LOG(WIFI_ERROR, "Failed to get profile");
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);
1257 g_variant_iter_free(iter);
1258 g_variant_unref(message);
1261 __NETWORK_FUNC_EXIT__;
1265 static net_err_e __net_get_wifi_state(network_info_s *network_info)
1267 net_err_e err = NET_ERR_NONE;
1269 if (network_info->wifi_state == WIFI_UNKNOWN ||
1270 network_info->wifi_state == WIFI_OFF) {
1271 err = _net_get_wifi_state(network_info);
1277 void net_forget_ap_finished(network_info_s *network_info, net_err_e Error)
1279 __NETWORK_FUNC_ENTER__;
1281 net_event_info_s *event_data = NULL;
1282 char event_string[64];
1284 if (network_info->request_table[NETWORK_REQUEST_TYPE_FORGET_AP].flag == FALSE) {
1285 __NETWORK_FUNC_EXIT__;
1289 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_FORGET_AP]), 0,
1290 sizeof(network_request_table_s));
1292 event_data = g_try_malloc0(sizeof(net_event_info_s));
1293 if (event_data == NULL) {
1294 __NETWORK_FUNC_EXIT__;
1298 event_data->Event = NET_EVENT_WIFI_FORGET_AP_IND;
1299 g_strlcpy(event_string, "Sending NET_EVENT_WIFI_FORGET_AP_IND", 64);
1301 event_data->Error = Error;
1302 event_data->Datalength = 0;
1303 event_data->Data = NULL;
1305 WIFI_LOG(WIFI_INFO, "%s, Error: %d", event_string, event_data->Error);
1307 if (network_info->event_callback)
1308 network_info->event_callback(event_data, network_info->user_data);
1312 __NETWORK_FUNC_EXIT__;
1316 int _net_check_profile_name(const char* ProfileName)
1318 __NETWORK_FUNC_ENTER__;
1320 const char *profileHeader = CONNMAN_PATH"/service/";
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
1330 stringLen = strlen(ProfileName);
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
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
1346 __NETWORK_FUNC_EXIT__;
1347 return NET_ERR_NONE;
1350 gboolean _net_check_service_mac_addr(network_info_s *network_info, const char* service)
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;
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];
1365 if (g_ascii_strncasecmp(org, dst, 2) != 0)
1372 __NETWORK_FUNC_EXIT__;
1376 int _net_get_interface_list(network_info_s *network_info, GSList **interface_list)
1378 __NETWORK_FUNC_ENTER__;
1380 net_err_e Error = NET_ERR_NONE;
1383 gchar *interface_name = NULL;
1385 message = _net_invoke_dbus_method(network_info,
1386 CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PATH,
1387 CONNMAN_TECHNOLOGY_INTERFACE, "GetInterfaces",
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
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));
1401 g_variant_iter_free(iter);
1402 g_variant_unref(message);
1404 __NETWORK_FUNC_EXIT__;
1408 int _net_get_profile_list(network_info_s *network_info, GSList **profile_list)
1410 __NETWORK_FUNC_ENTER__;
1412 net_err_e Error = NET_ERR_NONE;
1416 message = _net_invoke_dbus_method(network_info,
1417 CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
1418 CONNMAN_MANAGER_INTERFACE, "GetServices",
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
1426 g_variant_get(message, "(a(oa{sv}))", &iter);
1427 Error = __net_extract_services(network_info, iter, profile_list);
1430 g_variant_iter_free(iter);
1432 g_variant_unref(message);
1434 __NETWORK_FUNC_EXIT__;
1438 int net_init_profile_info(network_info_s *network_info, net_profile_info_s *ProfInfo)
1441 net_dev_info_s *net_info = NULL;
1443 if (ProfInfo == NULL) {
1444 WIFI_LOG(WIFI_ERROR, "Invalid Parameter"); //LCOV_EXCL_LINE
1445 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
1448 memset(ProfInfo, 0, sizeof(net_profile_info_s));
1449 ProfInfo->Favourite = (char)FALSE;
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;
1462 ProfInfo->network_info = network_info;
1464 net_info = &(ProfInfo->net_info);
1466 net_info->DnsCount = 0;
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;
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;
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);
1494 net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
1496 return NET_ERR_NONE;
1499 int net_specific_scan_wifi(network_info_s *network_info, const char *ssid)
1501 __NETWORK_FUNC_ENTER__;
1503 net_err_e Error = NET_ERR_NONE;
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
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
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
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
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
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);
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));
1549 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN]), 0, //LCOV_EXCL_LINE
1550 sizeof(network_request_table_s));
1553 __NETWORK_FUNC_EXIT__;
1558 int net_bssid_scan_wifi(network_info_s *network_info, int activated)
1560 __NETWORK_FUNC_ENTER__;
1562 net_err_e Error = NET_ERR_NONE;
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
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;
1579 network_info->request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN].flag = TRUE;
1582 Error = _net_dbus_bssid_scan_request(network_info);
1584 Error = _net_dbus_scan_request(network_info);
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));
1591 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_BSSID_SCAN]), 0,
1592 sizeof(network_request_table_s));
1595 __NETWORK_FUNC_EXIT__;
1599 int net_netlink_scan_wifi(network_info_s *network_info, GSList *nl_scan_list, const char *vsie)
1601 __NETWORK_FUNC_ENTER__;
1603 net_err_e Error = NET_ERR_NONE;
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
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;
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);
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));
1631 __NETWORK_FUNC_EXIT__;
1635 int net_multi_scan_wifi(network_info_s *network_info,
1636 GSList *multi_scan_list, gboolean multi_scan_type[])
1638 __NETWORK_FUNC_ENTER__;
1640 net_err_e Error = NET_ERR_NONE;
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
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
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
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
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
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;
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));
1689 WIFI_LOG(WIFI_ERROR, "Failed to allocate memory"); //LCOV_EXCL_LINE
1690 return NET_ERR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
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;
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);
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));
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));
1710 __NETWORK_FUNC_EXIT__;
1714 int net_get_wps_generated_pin(network_info_s *network_info, char **wps_pin)
1716 net_err_e error = NET_ERR_NONE;
1717 error = _net_dbus_get_wps_generated_pin(network_info, wps_pin);
1719 if (error != NET_ERR_NONE)
1720 WIFI_LOG(WIFI_ERROR, "Failed to get wps pin : %d", error);
1725 int net_wifi_get_passpoint(network_info_s *network_info, int *enabled)
1727 __NETWORK_FUNC_ENTER__;
1729 net_err_e Error = NET_ERR_NONE;
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
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
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));
1751 __NETWORK_FUNC_EXIT__;
1755 int net_wifi_set_passpoint(network_info_s *network_info, int enable)
1757 __NETWORK_FUNC_ENTER__;
1759 net_err_e Error = NET_ERR_NONE;
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
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
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));
1781 __NETWORK_FUNC_EXIT__;
1785 int net_wifi_add_vsie(network_info_s *network_info, unsigned int frame_id, const char *vsie_str)
1787 __NETWORK_FUNC_ENTER__;
1789 net_err_e Error = NET_ERR_NONE;
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
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
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));
1811 __NETWORK_FUNC_EXIT__;
1815 int net_wifi_get_vsie(network_info_s *network_info, unsigned int frame_id, char **vsie_str)
1817 __NETWORK_FUNC_ENTER__;
1819 net_err_e Error = NET_ERR_NONE;
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
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
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));
1841 __NETWORK_FUNC_EXIT__;
1845 int net_wifi_remove_vsie(network_info_s *network_info, unsigned int frame_id, const char *vsie_str)
1847 __NETWORK_FUNC_ENTER__;
1849 net_err_e Error = NET_ERR_NONE;
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
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
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));
1871 __NETWORK_FUNC_EXIT__;
1875 EXPORT_API int net_wifi_flush_bss(network_info_s *network_info)
1877 __NETWORK_CAPI_FUNC_ENTER__;
1879 net_err_e Error = NET_ERR_NONE;
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__;
1889 __NETWORK_CAPI_FUNC_EXIT__;
1890 return NET_ERR_NONE;
1893 int net_wifi_set_bssid(network_info_s *network_info, char *bssid)
1895 __NETWORK_CAPI_FUNC_ENTER__;
1897 net_err_e Error = NET_ERR_NONE;
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__;
1907 __NETWORK_CAPI_FUNC_EXIT__;
1908 return NET_ERR_NONE;
1911 EXPORT_API int net_wifi_set_auto_connect_mode(network_info_s *network_info,
1914 __NETWORK_CAPI_FUNC_ENTER__;
1916 net_err_e Error = NET_ERR_NONE;
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));
1923 __NETWORK_CAPI_FUNC_EXIT__;
1927 __NETWORK_CAPI_FUNC_EXIT__;
1928 return NET_ERR_NONE;
1931 EXPORT_API int net_wifi_get_5ghz_support(network_info_s *network_info, gboolean *supported)
1933 __NETWORK_CAPI_FUNC_ENTER__;
1935 net_err_e Error = NET_ERR_NONE;
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));
1942 __NETWORK_CAPI_FUNC_EXIT__;
1946 __NETWORK_CAPI_FUNC_EXIT__;
1947 return NET_ERR_NONE;
1950 EXPORT_API int net_wifi_get_auto_connect_mode(network_info_s *network_info,
1953 __NETWORK_CAPI_FUNC_ENTER__;
1955 net_err_e Error = NET_ERR_NONE;
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));
1962 __NETWORK_CAPI_FUNC_EXIT__;
1966 __NETWORK_CAPI_FUNC_EXIT__;
1967 return NET_ERR_NONE;
1970 EXPORT_API int net_wifi_set_ap_auto_connect(network_info_s *network_info,
1971 const char *profile_name, gboolean autoconnect)
1973 __NETWORK_FUNC_ENTER__;
1975 net_err_e Error = NET_ERR_NONE;
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;
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));
1988 __NETWORK_FUNC_EXIT__;
1992 EXPORT_API int net_wifi_get_ap_auto_connect(network_info_s *network_info,
1993 const char *profile_name, gboolean *autoconnect)
1995 __NETWORK_FUNC_ENTER__;
1997 net_err_e Error = NET_ERR_NONE;
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;
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));
2010 __NETWORK_FUNC_EXIT__;
2015 int net_open_connection_with_wifi_info(network_info_s *network_info,
2016 const net_wifi_connection_info_s *wifi_info)
2018 __NETWORK_FUNC_ENTER__;
2020 net_err_e Error = NET_ERR_NONE;
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
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
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
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
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
2056 network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag = TRUE;
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));
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));
2068 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2069 return Error; //LCOV_EXCL_LINE
2072 __NETWORK_FUNC_EXIT__;
2073 return NET_ERR_NONE;
2076 int net_wifi_power_on(network_info_s *network_info, gboolean wifi_picker_test)
2078 __NETWORK_FUNC_ENTER__;
2080 net_err_e Error = NET_ERR_NONE;
2081 int hotspot_state = 0;
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
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
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
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
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
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
2121 memset(network_info->request_table, 0, sizeof(network_info->request_table));
2123 network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER].flag = TRUE;
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));
2131 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER]), 0, //LCOV_EXCL_LINE
2132 sizeof(network_request_table_s));
2134 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2135 return Error; //LCOV_EXCL_LINE
2138 __NETWORK_FUNC_EXIT__;
2139 return NET_ERR_NONE;
2142 int net_wifi_power_off(network_info_s *network_info)
2144 __NETWORK_FUNC_ENTER__;
2146 net_err_e Error = NET_ERR_NONE;
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
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
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
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
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));
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));
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));
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));
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));
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));
2197 network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER].flag = TRUE;
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));
2205 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_WIFI_POWER]), //LCOV_EXCL_LINE
2206 0, sizeof(network_request_table_s));
2208 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2209 return Error; //LCOV_EXCL_LINE
2212 __NETWORK_FUNC_EXIT__;
2213 return NET_ERR_NONE;
2216 int net_scan_wifi(network_info_s *network_info)
2218 __NETWORK_FUNC_ENTER__;
2220 net_err_e Error = NET_ERR_NONE;
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
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
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
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
2250 network_info->request_table[NETWORK_REQUEST_TYPE_SCAN].flag = TRUE;
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));
2257 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_SCAN]), 0, //LCOV_EXCL_LINE
2258 sizeof(network_request_table_s));
2260 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2261 return Error; //LCOV_EXCL_LINE
2264 __NETWORK_FUNC_EXIT__;
2265 return NET_ERR_NONE;
2268 int net_wifi_get_scan_state(network_info_s *network_info, int *scanstate)
2270 __NETWORK_FUNC_ENTER__;
2272 net_err_e Error = NET_ERR_NONE;
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
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
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
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));
2299 __NETWORK_FUNC_EXIT__;
2300 return Error; //LCOV_EXCL_LINE
2303 __NETWORK_FUNC_EXIT__;
2304 return NET_ERR_NONE;
2308 int net_wifi_enroll_wps(network_info_s *network_info,
2309 const char *profile_name, net_wifi_wps_info_s *wps_info)
2311 __NETWORK_FUNC_ENTER__;
2313 net_err_e Error = NET_ERR_NONE;
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;
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__;
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;
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
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;
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);
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);
2358 Error = NET_ERR_INVALID_PARAM;
2360 if (NET_ERR_NONE != Error) {
2361 WIFI_LOG(WIFI_ERROR, "WPS configuration failed(%s)", _net_print_error(Error));
2363 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS]), 0,
2364 sizeof(network_request_table_s));
2367 __NETWORK_FUNC_EXIT__;
2371 int net_wifi_cancel_wps(network_info_s *network_info)
2373 __NETWORK_FUNC_ENTER__;
2375 net_err_e Error = NET_ERR_NONE;
2377 WIFI_LOG(WIFI_INFO, "net_wifi_wps_cancel called");
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
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
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;
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);
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));
2408 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS]), 0,
2409 sizeof(network_request_table_s));
2411 __NETWORK_FUNC_EXIT__;
2415 wifi_tech_state_e net_get_technology_state(network_info_s *network_info)
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;
2424 net_err_e Error = NET_ERR_NONE;
2426 message = _net_invoke_dbus_method(network_info,
2427 CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
2428 CONNMAN_MANAGER_INTERFACE, "GetTechnologies",
2431 if (message == NULL) {
2432 WIFI_LOG(WIFI_ERROR, "Failed to get_technology_state");
2433 return WIFI_TECH_UNKNOWN;
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)
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;
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);
2456 if (g_strcmp0(dev_key, "Ifname") == 0) {
2457 find = g_strcmp0(sdata, network_info->interface_name) == 0 ? TRUE : FALSE;
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");
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;
2470 g_variant_iter_free(list_iter);
2475 g_variant_unref(message);
2477 g_variant_iter_free(iter);
2479 if (wifi_tech_powered == TRUE)
2480 tech_state = WIFI_TECH_POWERED;
2482 if (wifi_tech_connected == TRUE)
2483 tech_state = WIFI_TECH_CONNECTED;
2488 int net_check_get_privilege(network_info_s *network_info)
2490 net_err_e Error = NET_ERR_NONE;
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
2501 int net_set_ip_conflict_detect_mode(network_info_s *network_info, gboolean detect)
2503 __NETWORK_FUNC_ENTER__;
2505 net_err_e Error = NET_ERR_NONE;
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
2515 __NETWORK_FUNC_EXIT__;
2519 int net_ip_conflict_detect_is_enabled(network_info_s *network_info, gboolean *state)
2521 __NETWORK_FUNC_ENTER__;
2523 net_err_e Error = NET_ERR_NONE;
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
2533 __NETWORK_FUNC_EXIT__;
2537 int net_check_profile_privilege(network_info_s *network_info)
2539 net_err_e Error = NET_ERR_NONE;
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
2550 int net_wifi_enroll_wps_without_ssid(network_info_s *network_info,
2551 net_wifi_wps_info_s *wps_info)
2553 __NETWORK_FUNC_ENTER__;
2555 net_err_e Error = NET_ERR_NONE;
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
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
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
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;
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;
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);
2594 __NETWORK_FUNC_EXIT__;
2595 return NET_ERR_INVALID_PARAM;
2598 if (Error != NET_ERR_NONE) {
2599 WIFI_LOG(WIFI_ERROR,
2600 "Failed to request open connection, Error [%s]",
2601 _net_print_error(Error));
2603 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS]), 0,
2604 sizeof(network_request_table_s));
2607 __NETWORK_FUNC_EXIT__;
2611 int net_wifi_tdls_disconnect(network_info_s *network_info, const char* peer_mac_addr)
2613 __NETWORK_FUNC_ENTER__;
2615 net_err_e Error = NET_ERR_NONE;
2617 if (peer_mac_addr == NULL) {
2618 WIFI_LOG(WIFI_ERROR, "invalid parameter");
2619 __NETWORK_FUNC_EXIT__;
2620 return NET_ERR_INVALID_PARAM;
2623 Error = _net_dbus_tdls_disconnect(network_info, peer_mac_addr);
2625 if (Error != NET_ERR_NONE)
2626 WIFI_LOG(WIFI_ERROR, "_net_dbus_tdls_set_device_type failed");
2629 __NETWORK_FUNC_EXIT__;
2634 int net_wifi_tdls_connected_peer(network_info_s *network_info, char** peer_mac_addr)
2636 __NETWORK_FUNC_ENTER__;
2638 net_err_e Error = NET_ERR_NONE;
2640 if (peer_mac_addr == NULL) {
2641 WIFI_LOG(WIFI_ERROR, "invalid parameter");
2642 __NETWORK_FUNC_EXIT__;
2643 return NET_ERR_INVALID_PARAM;
2646 Error = _net_dbus_tdls_connected_peer(network_info, peer_mac_addr);
2648 if (Error != NET_ERR_NONE)
2649 WIFI_LOG(WIFI_ERROR, "net_wifi_tdls_connected_peer failed");
2652 __NETWORK_FUNC_EXIT__;
2657 int net_wifi_tdls_enable_channel_switch(network_info_s *network_info,
2658 const char* peer_mac_addr, int freq)
2660 __NETWORK_FUNC_ENTER__;
2662 net_err_e Error = NET_ERR_NONE;
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;
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");
2674 __NETWORK_FUNC_EXIT__;
2679 int net_wifi_tdls_disbale_channel_switch(network_info_s *network_info,
2680 const char* peer_mac_addr)
2682 __NETWORK_FUNC_ENTER__;
2684 net_err_e Error = NET_ERR_NONE;
2686 if (peer_mac_addr == NULL) {
2687 WIFI_LOG(WIFI_ERROR, "invalid parameter");
2688 __NETWORK_FUNC_EXIT__;
2689 return NET_ERR_INVALID_PARAM;
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");
2697 __NETWORK_FUNC_EXIT__;
2703 int net_wifi_tdls_connect(network_info_s *network_info, const char* peer_mac_addr)
2705 __NETWORK_FUNC_ENTER__;
2707 net_err_e Error = NET_ERR_NONE;
2709 if (peer_mac_addr == NULL) {
2710 WIFI_LOG(WIFI_ERROR, "invalid parameter");
2711 __NETWORK_FUNC_EXIT__;
2712 return NET_ERR_INVALID_PARAM;
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");
2720 __NETWORK_FUNC_EXIT__;
2725 int net_wifi_tdls_discover(network_info_s *network_info, const char* peer_mac_addr)
2727 __NETWORK_FUNC_ENTER__;
2729 net_err_e Error = NET_ERR_NONE;
2731 if (peer_mac_addr == NULL) {
2732 WIFI_LOG(WIFI_ERROR, "invalid parameter");
2733 __NETWORK_FUNC_EXIT__;
2734 return NET_ERR_INVALID_PARAM;
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
2743 network_info->request_table[NETWORK_REQUEST_TYPE_TDLS_DISCOVERY].flag = TRUE;
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");
2749 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_TDLS_DISCOVERY]), 0, //LCOV_EXCL_LINE
2750 sizeof(network_request_table_s));
2752 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2753 return Error; //LCOV_EXCL_LINE
2756 __NETWORK_FUNC_EXIT__;
2759 int net_get_device_policy_wifi(network_info_s *network_info)
2761 __NETWORK_FUNC_ENTER__;
2764 net_err_e Error = _net_dbus_device_policy_get_wifi(network_info, &state);
2766 if (Error != NET_ERR_NONE) {
2767 WIFI_LOG(WIFI_ERROR, "_net_dbus_device_policy_get_wifi failed");
2771 WIFI_LOG(WIFI_INFO, "Wifi device policy state [%d]", state);
2773 __NETWORK_FUNC_EXIT__;
2777 int net_get_device_policy_wifi_profile(network_info_s *network_info)
2779 __NETWORK_FUNC_ENTER__;
2782 net_err_e Error = _net_dbus_device_policy_get_wifi_profile(network_info, &state);
2784 if (Error != NET_ERR_NONE) {
2785 WIFI_LOG(WIFI_ERROR, "_net_dbus_device_policy_get_wifi_profile failed");
2789 WIFI_LOG(WIFI_INFO, "Wifi profile policy state [%d]", state);
2791 __NETWORK_FUNC_EXIT__;
2796 int net_register_client_ext(network_info_s **network_info,
2797 const char *interface_name, net_event_cb event_cb, void *user_data)
2799 __NETWORK_FUNC_ENTER__;
2801 net_err_e Error = NET_ERR_NONE;
2802 network_info_s *net_info = NULL;
2803 GSList *list = NULL;
2804 GSList *interface_list = NULL;
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
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
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
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
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);
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
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
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
2874 net_info->event_callback = event_cb;
2875 net_info->user_data = user_data;
2877 *network_info = net_info;
2879 __NETWORK_FUNC_EXIT__;
2880 return NET_ERR_NONE;
2883 void net_deregister_client_ext(network_info_s *network_info)
2885 __NETWORK_FUNC_ENTER__;
2888 network_info->event_callback = NULL;
2889 network_info->user_data = NULL;
2891 _net_deregister_signal(network_info);
2892 _net_dbus_close_gdbus_call(network_info);
2893 _net_clear_request_table(network_info);
2895 g_free(network_info);
2898 __NETWORK_FUNC_EXIT__;
2902 void net_set_cs_tid(network_info_s *network_info, int tid)
2904 _net_set_cs_tid(network_info, tid);
2907 void net_unset_cs_tid(int tid)
2909 _net_unset_cs_tid(tid);
2913 int net_open_connection(network_info_s *network_info, const char *profile_name)
2915 __NETWORK_FUNC_ENTER__;
2917 net_err_e Error = NET_ERR_NONE;
2919 WIFI_LOG(WIFI_INFO, "Open: %s", profile_name);
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
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
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
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);
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));
2952 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION]), //LCOV_EXCL_LINE
2953 0, sizeof(network_request_table_s));
2955 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2956 return Error; //LCOV_EXCL_LINE
2959 __NETWORK_FUNC_EXIT__;
2960 return NET_ERR_NONE;
2963 int net_close_connection(network_info_s *network_info, const char *profile_name)
2965 __NETWORK_FUNC_ENTER__;
2967 net_err_e Error = NET_ERR_NONE;
2969 WIFI_LOG(WIFI_INFO, "ProfileName [%s] passed", profile_name);
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
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
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);
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));
2993 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION]), //LCOV_EXCL_LINE
2994 0, sizeof(network_request_table_s));
2996 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
2997 return Error; //LCOV_EXCL_LINE
3000 __NETWORK_FUNC_EXIT__;
3001 return NET_ERR_NONE;
3004 int net_delete_profile(network_info_s *network_info, const char* profile_name)
3006 __NETWORK_FUNC_ENTER__;
3008 net_err_e Error = NET_ERR_NONE;
3009 net_profile_name_s wifi_prof_name;
3010 net_profile_info_s prof_info;
3012 WIFI_LOG(WIFI_INFO, "Delete Profile [%s]", profile_name);
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
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));
3026 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3027 return Error; //LCOV_EXCL_LINE
3030 g_strlcpy(wifi_prof_name.ProfileName, profile_name, NET_PROFILE_NAME_LEN_MAX + 1);
3032 Error = __net_wifi_delete_profile(network_info,
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));
3041 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3042 return Error; //LCOV_EXCL_LINE
3045 __NETWORK_FUNC_EXIT__;
3046 return NET_ERR_NONE;
3049 static void _net_delete_profile_async_reply(GObject *source_object,
3050 GAsyncResult *res, gpointer user_data)
3052 __NETWORK_FUNC_ENTER__;
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;
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;
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);
3075 Error = NET_ERR_NO_PROFILE;
3076 g_variant_get(message, "(a(oa{sv}))", &iter);
3078 g_variant_unref(message);
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);
3092 g_variant_iter_free(iter);
3093 g_variant_unref(message);
3095 if (Error != NET_ERR_NONE)
3098 g_strlcpy(wifi_prof_name.ProfileName,
3099 request_table[NETWORK_REQUEST_TYPE_FORGET_AP].ProfileName,
3100 NET_PROFILE_NAME_LEN_MAX + 1);
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));
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);
3117 __NETWORK_FUNC_EXIT__;
3121 net_forget_ap_finished(network_info, Error);
3122 __NETWORK_FUNC_EXIT__;
3125 int net_delete_profile_async(network_info_s *network_info, const char* profile_name)
3127 __NETWORK_FUNC_ENTER__;
3129 net_err_e Error = NET_ERR_NONE;
3131 WIFI_LOG(WIFI_INFO, "Delete Profile [%s]", profile_name);
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
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);
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));
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
3159 __NETWORK_FUNC_EXIT__;
3160 return NET_ERR_NONE;
3163 int net_modify_profile(network_info_s *network_info,
3164 const char* profile_name, net_profile_info_s* prof_info)
3166 __NETWORK_FUNC_ENTER__;
3168 net_err_e Error = NET_ERR_NONE;
3169 net_profile_info_s exProfInfo;
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
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
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));
3189 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3190 return Error; //LCOV_EXCL_LINE
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
3200 Error = __net_wifi_modify_profile(network_info, profile_name, prof_info, &exProfInfo);
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));
3207 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3208 return Error; //LCOV_EXCL_LINE
3211 __NETWORK_FUNC_EXIT__;
3212 return NET_ERR_NONE;
3215 int net_get_profile_info(network_info_s *network_info,
3216 const char *profile_name, net_profile_info_s *prof_info)
3218 __NETWORK_FUNC_ENTER__;
3220 net_err_e Error = NET_ERR_NONE;
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
3226 __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
3227 return NET_ERR_INVALID_PARAM; //LCOV_EXCL_LINE
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));
3236 __NETWORK_FUNC_EXIT__;
3240 int net_get_interface_list(network_info_s *network_info, GSList **interface_list)
3242 __NETWORK_FUNC_ENTER__;
3244 net_err_e Error = NET_ERR_NONE;
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));
3253 __NETWORK_FUNC_EXIT__;
3257 int net_get_profile_list(network_info_s *network_info, GSList **profile_list)
3259 __NETWORK_FUNC_ENTER__;
3261 net_err_e Error = NET_ERR_NONE;
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));
3270 __NETWORK_FUNC_EXIT__;
3274 int net_get_technology_properties(network_info_s *network_info, net_tech_info_s *tech_info)
3276 __NETWORK_FUNC_ENTER__;
3278 net_err_e Error = NET_ERR_NONE;
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
3287 __NETWORK_FUNC_EXIT__;
3288 return NET_ERR_NONE;
3291 int net_config_get_id_list(network_info_s *network_info, GSList **list)
3293 __NETWORK_FUNC_ENTER__;
3295 net_err_e Error = NET_ERR_NONE;
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));
3303 __NETWORK_FUNC_EXIT__;
3307 int net_config_set_field(network_info_s *network_info,
3308 const gchar *config_id, const gchar *key, const gchar *value)
3310 __NETWORK_FUNC_ENTER__;
3312 net_err_e Error = NET_ERR_NONE;
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));
3320 __NETWORK_FUNC_EXIT__;
3324 int net_config_get_passphrase(network_info_s *network_info,
3325 const gchar *config_id, gchar **passphrase)
3327 __NETWORK_FUNC_ENTER__;
3329 net_err_e Error = NET_ERR_NONE;
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));
3337 __NETWORK_FUNC_EXIT__;
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)
3346 __NETWORK_FUNC_ENTER__;
3348 net_err_e Error = NET_ERR_NONE;
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));
3358 __NETWORK_FUNC_EXIT__;
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)
3367 __NETWORK_FUNC_ENTER__;
3369 net_err_e Error = NET_ERR_NONE;
3370 net_eap_config_s *net_eap_config = (net_eap_config_s *)eap_config;
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));
3380 __NETWORK_FUNC_EXIT__;
3385 int net_config_remove_configurations(network_info_s *network_info,
3386 const gchar *config_id)
3388 __NETWORK_FUNC_ENTER__;
3390 net_err_e Error = NET_ERR_NONE;
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));
3398 __NETWORK_FUNC_EXIT__;
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)
3407 __NETWORK_FUNC_ENTER__;
3409 net_err_e Error = NET_ERR_NONE;
3410 net_wifi_security_type_e *sec_type = (net_wifi_security_type_e *)security_type;
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));
3420 __NETWORK_FUNC_EXIT__;
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)
3429 __NETWORK_FUNC_ENTER__;
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;
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));
3443 __NETWORK_FUNC_EXIT__;
3447 int net_wifi_set_autoscan(network_info_s *network_info, gboolean autoscan)
3449 __NETWORK_FUNC_ENTER__;
3451 net_err_e Error = NET_ERR_NONE;
3453 WIFI_LOG(WIFI_INFO, "[%s] auto scan", autoscan ? "enable" : "disable");
3456 Error = _net_dbus_resume_bgscan(network_info);
3458 Error = _net_dbus_pause_bgscan(network_info);
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));
3465 __NETWORK_FUNC_EXIT__;
3469 __NETWORK_FUNC_EXIT__;
3470 return NET_ERR_NONE;
3473 int net_wifi_set_background_scan_mode(network_info_s *network_info,
3474 net_wifi_background_scan_mode_e scan_mode)
3476 __NETWORK_FUNC_ENTER__;
3478 net_err_e Error = NET_ERR_NONE;
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
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
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));
3498 __NETWORK_FUNC_EXIT__;
3502 __NETWORK_FUNC_EXIT__;
3503 return NET_ERR_NONE;
3506 int net_wifi_set_ip_conflict_period(network_info_s *network_info,
3507 unsigned int initial_time)
3509 __NETWORK_FUNC_ENTER__;
3511 net_err_e Error = NET_ERR_NONE;
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));
3518 __NETWORK_FUNC_EXIT__;
3522 __NETWORK_FUNC_EXIT__;
3523 return NET_ERR_NONE;
3526 int net_wifi_get_ip_conflict_period(network_info_s *network_info,
3527 unsigned int* initial_time)
3529 __NETWORK_FUNC_ENTER__;
3531 net_err_e Error = NET_ERR_NONE;
3532 GVariant *params = NULL;
3533 GVariant *message = NULL;
3535 params = g_variant_new("(s)", network_info->interface_name);
3537 message = _net_invoke_dbus_method(network_info,
3538 NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
3539 NETCONFIG_WIFI_INTERFACE, "GetIpConflictPeriod",
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
3547 g_variant_get(message, "(u)", initial_time);
3548 g_variant_unref(message);
3550 __NETWORK_FUNC_EXIT__;
3554 int net_wifi_get_ip_conflict_state(network_info_s *network_info, unsigned int *state)
3556 __NETWORK_FUNC_ENTER__;
3558 net_err_e Error = NET_ERR_NONE;
3559 GVariant *params = NULL;
3560 GVariant *message = NULL;
3562 params = g_variant_new("(s)", network_info->interface_name);
3564 message = _net_invoke_dbus_method(network_info,
3565 NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
3566 NETCONFIG_WIFI_INTERFACE, "GetIpConflictState",
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
3574 g_variant_get(message, "(u)", state);
3575 g_variant_unref(message);
3577 __NETWORK_FUNC_EXIT__;
3581 int net_wifi_get_autoscan(network_info_s *network_info, gboolean *autoscan)
3583 __NETWORK_FUNC_ENTER__;
3585 net_err_e Error = NET_ERR_NONE;
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));
3594 __NETWORK_FUNC_EXIT__;
3598 int net_wifi_get_autoscanmode(network_info_s *network_info, unsigned int *autoscanmode)
3600 __NETWORK_FUNC_ENTER__;
3602 net_err_e Error = NET_ERR_NONE;
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));
3611 __NETWORK_FUNC_EXIT__;
3615 int net_wifi_get_module_state(network_info_s *network_info, int *module_state)
3617 GVariant *message = NULL, *variant;
3618 GVariantIter *iter, *next;
3621 net_err_e Error = NET_ERR_NONE;
3623 message = _net_invoke_dbus_method(network_info,
3624 CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
3625 CONNMAN_MANAGER_INTERFACE, "GetTechnologies",
3628 if (message == NULL) {
3629 WIFI_LOG(WIFI_ERROR, "Failed to get_technology_state");
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)
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;
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);
3653 if (g_strcmp0(dev_key, "Ifname") == 0) {
3654 if (g_strcmp0(sdata, network_info->interface_name) == 0)
3659 g_variant_iter_free(list_iter);
3664 g_variant_unref(message);
3665 g_variant_iter_free(iter);
3667 return NET_ERR_NONE;
3670 static int __net_convert_string_to_ipv6_string(char *str, char **ip_address)
3674 struct sockaddr_in6 sa;
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;
3682 /* Convert String without : to string with : */
3683 for (i = 1; i < 8; i++) {
3685 memmove(str + pos, str + pos - 1,
3686 strlen(str) - pos + 2 * i);
3691 * Convert "fe80:0000:0000:0000:0a00:27ff:fe7a:65ea" to fe80::a00:27ff:fe7a:65ea
3693 inet_pton(AF_INET6, str, &(sa.sin6_addr));
3694 inet_ntop(AF_INET6, &(sa.sin6_addr), *ip_address, INET6_ADDRSTRLEN);
3696 return NET_ERR_NONE;
3699 int net_foreach_ipv6_address(GSList **ipv6_address_list)
3701 __NETWORK_FUNC_ENTER__;
3704 char *ip_address = NULL;
3705 char *if_name = NULL;
3707 char buf[NET_IPV6_ADDRESS_FILE_LEN] = {0, };
3708 char str[NET_IPV6_ADDRESS_FILE_LEN] = {0, };
3710 net_err_e Error = NET_ERR_NONE;
3712 fp = fopen(NET_IPV6_ADDRESS_FILE, "r");
3714 WIFI_LOG(WIFI_ERROR, "Failed to open file");
3715 __NETWORK_FUNC_EXIT__;
3716 return NET_ERR_INVALID_OPERATION;
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);
3731 __NETWORK_FUNC_EXIT__;
3735 int net_get_preferred_ipv6_address(network_info_s *network_info,
3736 const char *profilename, char **address)
3738 __NETWORK_FUNC_ENTER__;
3739 net_err_e Error = NET_ERR_NONE;
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");
3745 __NETWORK_FUNC_EXIT__;
3749 int net_get_service_state(network_info_s *network_info)
3751 return network_info->service_state;
3754 int net_wifi_get_max_scan_ssids(network_info_s *network_info, int *max_scan_ssids)
3756 __NETWORK_CAPI_FUNC_ENTER__;
3758 net_err_e Error = NET_ERR_NONE;
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));
3766 __NETWORK_CAPI_FUNC_EXIT__;
3770 __NETWORK_CAPI_FUNC_EXIT__;
3771 return NET_ERR_NONE;
3774 static net_err_e __check_preconditions(network_info_s *network_info)
3776 net_err_e Error = NET_ERR_NONE;
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
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
3794 int net_dpp_enter_peer_uri(network_info_s *network_info,
3795 guint32 peer_id, guint32 own_id, const char *uri)
3797 net_err_e Error = NET_ERR_NONE;
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*/
3804 Error = _net_dbus_dpp_enter_peer_uri(network_info, peer_id, own_id, uri);
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));
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)
3818 net_err_e Error = NET_ERR_NONE;
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*/
3825 Error = _net_dbus_dpp_generate_uri(network_info, peer_id, own_id, is_initiator, key);
3827 if (Error != NET_ERR_NONE) {
3828 WIFI_LOG(WIFI_ERROR,
3829 "Generate URI dbus request failed. Error [%s]",
3830 _net_print_error(Error));
3836 static gchar *__dpp_network_role_to_string(wifi_manager_dpp_network_role_e role)
3838 if (role == WIFI_MANAGER_DPP_NETWORK_ROLE_AP)
3840 else if (role == WIFI_MANAGER_DPP_NETWORK_ROLE_STA)
3846 static gchar *__dpp_akm_to_string(wifi_manager_dpp_akm_e akm)
3848 if (akm == WIFI_MANAGER_DPP_AKM_PSK)
3850 else if (akm == WIFI_MANAGER_DPP_AKM_SAE)
3852 else if (akm == WIFI_MANAGER_DPP_AKM_DPP)
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)
3862 gboolean is_configurator = (p_dpp->role == WIFI_MANAGER_DPP_ROLE_CONFIGURATOR);
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);
3881 rv = _net_dbus_dpp_start_enrollee_responder(p_dpp->network_info, auth_key);
3886 int net_dpp_start(void *dpp_handle, const char *auth_key,
3887 const char *configurator_key, const char *pass)
3889 net_err_e Error = NET_ERR_NONE;
3890 wifi_dpp_s *dpp_data = (wifi_dpp_s *)dpp_handle;
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*/
3897 Error = __net_dpp_start_each(dpp_data, auth_key, configurator_key, pass);
3899 if (Error != NET_ERR_NONE) {
3900 WIFI_LOG(WIFI_ERROR,
3901 "DppStart dbus request failed. Error [%s]",
3902 _net_print_error(Error));
3908 int net_dpp_stop(network_info_s *network_info,
3909 guint32 peer_id, guint32 own_id, gboolean is_initiator)
3911 net_err_e Error = NET_ERR_NONE;
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*/
3918 Error = _net_dbus_dpp_stop(network_info, peer_id, own_id, is_initiator);
3920 if (Error != NET_ERR_NONE) {
3921 WIFI_LOG(WIFI_ERROR,
3922 "DppStop dbus request failed. Error [%s]",
3923 _net_print_error(Error));