2 * Network Client Library
4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.1 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.tizenopensource.org/license
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include <arpa/inet.h>
24 #include "network-info.h"
25 #include "network-internal.h"
26 #include "network-signal-handler.h"
27 #include "network-dbus-request.h"
29 #define DBUS_OBJECT_PATH_MAX 150
31 #define NET_IPV6_ADDRESS_FILE "/proc/net/if_inet6"
32 #define NET_IPV6_ADDRESS_FILE_LEN 100
33 #define NET_IPV6_ADDRESS_LEN 32
35 /*****************************************************************************
36 * Local Functions Declaration
37 *****************************************************************************/
38 static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_t *ProfInfo);
39 static int __net_extract_service_info(network_info_t *network_info,
40 const char *ProfileName, GVariantIter *iter, net_profile_info_t *ProfInfo);
41 static int __net_extract_services(network_info_t *network_info,
42 GVariantIter *message, net_device_t device_type,
43 net_profile_info_t **profile_info, int *profile_count);
44 static int __net_extract_ip(const gchar *value, net_addr_t *ipAddr);
45 static int __net_extract_common_info(const char *key, GVariant *variant, net_profile_info_t *ProfInfo);
46 static int __net_extract_mobile_info(network_info_t *network_info, GVariantIter *array, net_profile_info_t *ProfInfo);
47 static int __net_extract_ethernet_info(GVariantIter *array, net_profile_info_t *ProfInfo);
48 static int __net_extract_bluetooth_info(GVariantIter *array, net_profile_info_t *ProfInfo);
49 static int __net_extract_mesh_info(GVariantIter *array, net_profile_info_t *ProfInfo);
51 /*****************************************************************************
53 *****************************************************************************/
55 /*****************************************************************************
56 * Local Functions Definition
57 *****************************************************************************/
59 static int __net_pm_init_profile_info(net_device_t profile_type, net_profile_info_t *ProfInfo)
62 net_dev_info_t *net_info = NULL;
64 if (ProfInfo == NULL ||
65 (profile_type != NET_DEVICE_WIFI &&
66 profile_type != NET_DEVICE_CELLULAR &&
67 profile_type != NET_DEVICE_ETHERNET &&
68 profile_type != NET_DEVICE_MESH &&
69 profile_type != NET_DEVICE_BLUETOOTH)) {
70 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
71 return NET_ERR_INVALID_PARAM;
74 memset(ProfInfo, 0, sizeof(net_profile_info_t));
75 ProfInfo->Favourite = (char)FALSE;
77 if (profile_type == NET_DEVICE_WIFI) {
78 ProfInfo->profile_type = NET_DEVICE_WIFI;
79 ProfInfo->ProfileInfo.Wlan.Strength = 0;
80 ProfInfo->ProfileInfo.Wlan.frequency = 0;
81 ProfInfo->ProfileInfo.Wlan.max_rate = 0;
82 ProfInfo->ProfileInfo.Wlan.wlan_mode = 0;
83 ProfInfo->ProfileInfo.Wlan.PassphraseRequired = FALSE;
84 ProfInfo->ProfileInfo.Wlan.security_info.sec_mode = 0;
85 ProfInfo->ProfileInfo.Wlan.security_info.enc_mode = 0;
86 ProfInfo->ProfileInfo.Wlan.security_info.wps_support = FALSE;
88 net_info = &(ProfInfo->ProfileInfo.Wlan.net_info);
89 } else if (profile_type == NET_DEVICE_CELLULAR) {
90 ProfInfo->profile_type = NET_DEVICE_CELLULAR;
91 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_NONE;
92 ProfInfo->ProfileInfo.Pdp.ServiceType = NET_SERVICE_UNKNOWN;
93 ProfInfo->ProfileInfo.Pdp.PdnType = NET_PDN_TYPE_UNKNOWN;
94 ProfInfo->ProfileInfo.Pdp.RoamPdnType = NET_PDN_TYPE_UNKNOWN;
95 ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType = NET_PDP_AUTH_NONE;
96 ProfInfo->ProfileInfo.Pdp.IsStatic = FALSE;
97 ProfInfo->ProfileInfo.Pdp.Roaming = FALSE;
98 ProfInfo->ProfileInfo.Pdp.SetupRequired = FALSE;
99 ProfInfo->ProfileInfo.Pdp.Hidden = FALSE;
100 ProfInfo->ProfileInfo.Pdp.Editable = TRUE;
101 ProfInfo->ProfileInfo.Pdp.DefaultConn = FALSE;
103 net_info = &(ProfInfo->ProfileInfo.Pdp.net_info);
104 } else if (profile_type == NET_DEVICE_ETHERNET) {
105 net_info = &(ProfInfo->ProfileInfo.Ethernet.net_info);
106 } else if (profile_type == NET_DEVICE_BLUETOOTH) {
107 net_info = &(ProfInfo->ProfileInfo.Bluetooth.net_info);
108 } else if (profile_type == NET_DEVICE_MESH) {
109 ProfInfo->profile_type = NET_DEVICE_MESH;
110 ProfInfo->ProfileInfo.Mesh.Strength = 0;
111 ProfInfo->ProfileInfo.Mesh.frequency = 0;
112 ProfInfo->ProfileInfo.Mesh.PassphraseRequired = FALSE;
113 ProfInfo->ProfileInfo.Mesh.security_info.sec_mode = 0;
115 net_info = &(ProfInfo->ProfileInfo.Mesh.net_info);
118 if (net_info != NULL) {
119 net_info->DnsCount = 0;
121 for (i = 0; i < NET_DNS_ADDR_MAX; i++) {
122 net_info->DnsAddr[i].Type = NET_ADDR_IPV4;
123 net_info->DnsAddr[i].Data.Ipv4.s_addr = 0;
126 net_info->IpConfigType = 0;
127 net_info->IpAddr.Type = NET_ADDR_IPV4;
128 net_info->IpAddr.Data.Ipv4.s_addr = 0;
129 net_info->BNetmask = FALSE;
130 net_info->SubnetMask.Type = NET_ADDR_IPV4;
131 net_info->SubnetMask.Data.Ipv4.s_addr = 0;
132 net_info->BDefGateway = FALSE;
133 net_info->GatewayAddr.Type = NET_ADDR_IPV4;
134 net_info->GatewayAddr.Data.Ipv4.s_addr = 0;
135 net_info->BServerAddr = FALSE;
136 net_info->ServerAddr.Type = NET_ADDR_IPV4;
137 net_info->ServerAddr.Data.Ipv4.s_addr = 0;
139 net_info->IpConfigType6 = 0;
140 net_info->IpAddr6.Type = NET_ADDR_IPV6;
141 inet_pton(AF_INET6, "::", &net_info->IpAddr6.Data.Ipv6);
142 net_info->PrefixLen6 = 0;
143 net_info->BDefGateway6 = FALSE;
144 net_info->GatewayAddr6.Type = NET_ADDR_IPV6;
145 inet_pton(AF_INET6, "::", &net_info->GatewayAddr6.Data.Ipv6);
147 net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
153 static int __net_telephony_init_profile_info(net_telephony_profile_info_t *ProfInfo)
155 if (ProfInfo == NULL) {
156 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
158 __NETWORK_FUNC_EXIT__;
159 return NET_ERR_INVALID_PARAM;
162 memset(ProfInfo->ProfileName, '\0', NET_PROFILE_NAME_LEN_MAX+1);
163 ProfInfo->ServiceType = NET_SERVICE_UNKNOWN;
164 ProfInfo->PdnType = NET_PDN_TYPE_UNKNOWN;
165 ProfInfo->RoamPdnType = NET_PDN_TYPE_UNKNOWN;
166 memset(ProfInfo->Apn, '\0', NET_PDP_APN_LEN_MAX+1);
168 ProfInfo->AuthInfo.AuthType = NET_PDP_AUTH_NONE;
169 memset(ProfInfo->AuthInfo.UserName, '\0', NET_PDP_AUTH_USERNAME_LEN_MAX+1);
170 memset(ProfInfo->AuthInfo.Password, '\0', NET_PDP_AUTH_PASSWORD_LEN_MAX+1);
172 memset(ProfInfo->ProxyAddr, '\0', NET_PROXY_LEN_MAX+1);
173 memset(ProfInfo->HomeURL, '\0', NET_HOME_URL_LEN_MAX+1);
175 memset(ProfInfo->Keyword, '\0', NET_PDP_APN_LEN_MAX+1);
176 ProfInfo->Hidden = FALSE;
177 ProfInfo->Editable = TRUE;
178 ProfInfo->DefaultConn = FALSE;
183 static void __net_telephony_get_path(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
186 g_strlcpy(ProfileInfo->ProfileName, value, NET_PROFILE_NAME_LEN_MAX);
189 static void __net_telephony_get_svc_ctg_id(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
191 net_service_type_t ServiceType = NET_SERVICE_UNKNOWN;
194 ServiceType = atoi(value);
196 if (ServiceType > NET_SERVICE_UNKNOWN)
197 ProfileInfo->ServiceType = ServiceType;
200 static void __net_telephony_get_apn(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
203 g_strlcpy(ProfileInfo->Apn, value, NET_PDP_APN_LEN_MAX);
206 static void __net_telephony_get_pdp_protocol(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
208 net_pdn_type_e pdnType = NET_PDN_TYPE_UNKNOWN;
211 pdnType = atoi(value);
213 if (pdnType == NET_PDN_TYPE_IPV4)
214 ProfileInfo->PdnType = NET_PDN_TYPE_IPV4;
215 else if (pdnType == NET_PDN_TYPE_IPV6)
216 ProfileInfo->PdnType = NET_PDN_TYPE_IPV6;
217 else if (pdnType == NET_PDN_TYPE_IPV4_IPV6)
218 ProfileInfo->PdnType = NET_PDN_TYPE_IPV4_IPV6;
221 static void __net_telephony_get_roam_pdp_protocol(const gchar *value,
222 net_telephony_profile_info_t *ProfileInfo)
224 net_pdn_type_e roamPdnType = NET_PDN_TYPE_UNKNOWN;
227 roamPdnType = atoi(value);
229 if (roamPdnType == NET_PDN_TYPE_IPV4)
230 ProfileInfo->RoamPdnType = NET_PDN_TYPE_IPV4;
231 else if (roamPdnType == NET_PDN_TYPE_IPV6)
232 ProfileInfo->RoamPdnType = NET_PDN_TYPE_IPV6;
233 else if (roamPdnType == NET_PDN_TYPE_IPV4_IPV6)
234 ProfileInfo->RoamPdnType = NET_PDN_TYPE_IPV4_IPV6;
237 static void __net_telephony_get_auth_type(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
239 net_auth_type_t authType = NET_PDP_AUTH_NONE;
242 authType = atoi(value);
244 if (authType == NET_PDP_AUTH_PAP)
245 ProfileInfo->AuthInfo.AuthType = NET_PDP_AUTH_PAP;
246 else if (authType == NET_PDP_AUTH_CHAP)
247 ProfileInfo->AuthInfo.AuthType = NET_PDP_AUTH_CHAP;
250 static void __net_telephony_get_auth_id(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
253 g_strlcpy(ProfileInfo->AuthInfo.UserName, value, NET_PDP_AUTH_USERNAME_LEN_MAX);
256 static void __net_telephony_get_auth_pwd(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
259 g_strlcpy(ProfileInfo->AuthInfo.Password, value, NET_PDP_AUTH_PASSWORD_LEN_MAX);
262 static void __net_telephony_get_proxy_addr(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
265 g_strlcpy(ProfileInfo->ProxyAddr, value, NET_PROXY_LEN_MAX);
268 static void __net_telephony_get_home_uri(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
271 g_strlcpy(ProfileInfo->HomeURL, value, NET_HOME_URL_LEN_MAX);
274 static void __net_telephony_get_default_internet_conn(const gchar *value,
275 net_telephony_profile_info_t *ProfileInfo)
280 if (g_strcmp0(value, "TRUE") == 0)
281 ProfileInfo->DefaultConn = TRUE;
283 ProfileInfo->DefaultConn = FALSE;
286 static void __net_telephony_get_profile_name(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
289 g_strlcpy(ProfileInfo->Keyword, value, NET_PDP_APN_LEN_MAX);
292 static void __net_telephony_get_editable(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
297 if (g_strcmp0(value, "TRUE") == 0)
298 ProfileInfo->Editable = TRUE;
300 ProfileInfo->Editable = FALSE;
303 static void __net_telephony_get_hidden(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
308 if (g_strcmp0(value, "TRUE") == 0)
309 ProfileInfo->Hidden = TRUE;
311 ProfileInfo->Hidden = FALSE;
314 static int __net_telephony_get_profile_info(network_info_t *network_info,
315 net_profile_name_t *ProfileName, net_telephony_profile_info_t *ProfileInfo)
317 __NETWORK_FUNC_ENTER__;
319 net_err_t Error = NET_ERR_NONE;
322 const gchar *key = NULL;
323 const gchar *value = NULL;
325 if (ProfileName == NULL || ProfileInfo == NULL) {
326 NETWORK_LOG(NETWORK_ERROR, "Invalid parameter!");
327 __NETWORK_FUNC_EXIT__;
328 return NET_ERR_INVALID_PARAM;
331 result = _net_invoke_dbus_method(network_info, TELEPHONY_SERVICE, ProfileName->ProfileName,
332 TELEPHONY_PROFILE_INTERFACE, "GetProfile", NULL, &Error);
333 if (result == NULL) {
334 NETWORK_LOG(NETWORK_ERROR, "_net_invoke_dbus_method failed");
335 __NETWORK_FUNC_EXIT__;
339 Error = __net_telephony_init_profile_info(ProfileInfo);
341 if (Error != NET_ERR_NONE) {
342 g_variant_unref(result);
343 __NETWORK_FUNC_EXIT__;
347 g_variant_get(result, "(a{ss})", &iter);
348 while (g_variant_iter_loop(iter, "{ss}", &key, &value)) {
349 if (g_strcmp0(key, "path") == 0) {
350 __net_telephony_get_path(value, ProfileInfo);
351 } else if (g_strcmp0(key, "svc_ctg_id") == 0) {
352 __net_telephony_get_svc_ctg_id(value, ProfileInfo);
353 } else if (g_strcmp0(key, "apn") == 0) {
354 __net_telephony_get_apn(value, ProfileInfo);
355 } else if (g_strcmp0(key, "pdp_protocol") == 0) {
356 __net_telephony_get_pdp_protocol(value, ProfileInfo);
357 } else if (g_strcmp0(key, "roam_pdp_protocol") == 0) {
358 __net_telephony_get_roam_pdp_protocol(value, ProfileInfo);
359 } else if (g_strcmp0(key, "auth_type") == 0) {
360 __net_telephony_get_auth_type(value, ProfileInfo);
361 } else if (g_strcmp0(key, "auth_id") == 0) {
362 __net_telephony_get_auth_id(value, ProfileInfo);
363 } else if (g_strcmp0(key, "auth_pwd") == 0) {
364 __net_telephony_get_auth_pwd(value, ProfileInfo);
365 } else if (g_strcmp0(key, "proxy_addr") == 0) {
366 __net_telephony_get_proxy_addr(value, ProfileInfo);
367 } else if (g_strcmp0(key, "home_url") == 0) {
368 __net_telephony_get_home_uri(value, ProfileInfo);
369 } else if (g_strcmp0(key, "default_internet_conn") == 0) {
370 __net_telephony_get_default_internet_conn(value, ProfileInfo);
371 } else if (g_strcmp0(key, "profile_name") == 0) {
372 __net_telephony_get_profile_name(value, ProfileInfo);
373 } else if (g_strcmp0(key, "editable") == 0) {
374 __net_telephony_get_editable(value, ProfileInfo);
375 } else if (g_strcmp0(key, "hidden") == 0) {
376 __net_telephony_get_hidden(value, ProfileInfo);
380 g_variant_iter_free(iter);
381 g_variant_unref(result);
383 __NETWORK_FUNC_EXIT__;
387 static int __net_telephony_get_modem_object_path(network_info_t *network_info,
388 GSList **ModemPathList)
390 __NETWORK_FUNC_ENTER__;
392 net_err_t Error = NET_ERR_NONE;
394 GVariantIter *iter_modem = NULL;
395 GVariantIter *modem_properties = NULL;
396 const char *modem_path;
398 result = _net_invoke_dbus_method(network_info,
399 TELEPHONY_SERVICE, TELEPHONY_MASTER_PATH,
400 TELEPHONY_MASTER_INTERFACE, "GetModems", NULL, &Error);
401 if (result == NULL) {
402 NETWORK_LOG(NETWORK_ERROR, "Failed to get modem path list");
403 __NETWORK_FUNC_EXIT__;
407 g_variant_get(result, "(a{sa{ss}})", &iter_modem);
408 while (g_variant_iter_loop(iter_modem, "{sa{ss}}", &modem_path, &modem_properties)) {
409 *ModemPathList = g_slist_append(*ModemPathList, g_strdup(modem_path));
410 NETWORK_LOG(NETWORK_LOW, "modem object path: %s", modem_path);
413 g_variant_iter_free(iter_modem);
414 g_variant_unref(result);
416 __NETWORK_FUNC_EXIT__;
420 static int __net_telephony_get_profile_list(network_info_t *network_info,
421 net_profile_name_t **ProfileName, int *ProfileCount)
423 __NETWORK_FUNC_ENTER__;
425 net_err_t Error = NET_ERR_NONE;
426 int count = 0, i = 0;
427 const char *str = NULL;
429 GVariantIter *iter = NULL;
430 GSList *profiles = NULL, *list = NULL;
431 net_profile_name_t *profileList = NULL;
433 GSList *ModemPathList = NULL;
434 const char *path = NULL;
436 Error = __net_telephony_get_modem_object_path(network_info, &ModemPathList);
437 if (Error != NET_ERR_NONE) {
438 NETWORK_LOG(NETWORK_ERROR, "Failed to get modems path list");
440 g_slist_free_full(ModemPathList, g_free);
441 __NETWORK_FUNC_EXIT__;
445 for (list = ModemPathList; list != NULL; list = list->next) {
446 path = (const char *)list->data;
448 NETWORK_LOG(NETWORK_LOW, "path: %s", path);
449 result = _net_invoke_dbus_method(network_info,
450 TELEPHONY_SERVICE, path, TELEPHONY_MODEM_INTERFACE,
451 "GetProfileList", NULL, &Error);
452 if (result == NULL) {
453 NETWORK_LOG(NETWORK_LOW, "Failed to get profiles: %s", path);
457 g_variant_get(result, "(as)", &iter);
458 while (g_variant_iter_loop(iter, "s", &str))
459 profiles = g_slist_append(profiles, g_strdup(str));
461 g_variant_iter_free(iter);
462 g_variant_unref(result);
465 g_slist_free_full(ModemPathList, g_free);
467 count = g_slist_length(profiles);
469 profileList = (net_profile_name_t*)malloc(sizeof(net_profile_name_t) * count);
470 Error = NET_ERR_NONE;
476 if (profileList == NULL) {
477 NETWORK_LOG(NETWORK_ERROR, "Failed to allocate memory");
479 Error = NET_ERR_UNKNOWN;
483 for (list = profiles, i = 0; list != NULL; list = list->next, i++)
484 g_strlcpy(profileList[i].ProfileName,
485 (const char *)list->data, NET_PROFILE_NAME_LEN_MAX);
487 *ProfileName = profileList;
488 *ProfileCount = count;
491 g_slist_free_full(profiles, g_free);
493 __NETWORK_FUNC_EXIT__;
497 static int __net_telephony_search_pdp_profile(network_info_t *network_info,
498 char *ProfileName, net_profile_name_t *PdpProfName)
500 __NETWORK_FUNC_ENTER__;
502 net_err_t Error = NET_ERR_NONE;
503 net_profile_name_t *ProfileList = NULL;
504 char *connmanProfName = NULL;
505 char *telephonyProfName = NULL;
506 char *foundPtr = NULL;
507 int ProfileCount = 0;
510 /* Get pdp profile list from telephony service */
511 Error = __net_telephony_get_profile_list(network_info, &ProfileList, &ProfileCount);
512 if (Error != NET_ERR_NONE) {
513 NETWORK_LOG(NETWORK_ERROR, "Failed to get profile list from telephony service");
514 NET_MEMFREE(ProfileList);
515 __NETWORK_FUNC_EXIT__;
519 if (ProfileList == NULL || ProfileCount <= 0) {
520 NETWORK_LOG(NETWORK_ERROR, "There is no PDP profiles");
521 NET_MEMFREE(ProfileList);
522 __NETWORK_FUNC_EXIT__;
523 return NET_ERR_NO_SERVICE;
526 /* Find matching profile */
527 connmanProfName = strrchr(ProfileName, '/') + 1;
528 for (i = 0; i < ProfileCount; i++) {
529 telephonyProfName = strrchr(ProfileList[i].ProfileName, '/') + 1;
530 foundPtr = strstr(connmanProfName, telephonyProfName);
532 if (foundPtr != NULL && g_strcmp0(foundPtr, telephonyProfName) == 0) {
533 g_strlcpy(PdpProfName->ProfileName,
534 ProfileList[i].ProfileName, NET_PROFILE_NAME_LEN_MAX);
536 NETWORK_LOG(NETWORK_HIGH,
537 "PDP profile name found in cellular profile: %s",
538 PdpProfName->ProfileName);
543 if (i >= ProfileCount) {
544 NETWORK_LOG(NETWORK_ERROR, "There is no matching PDP profiles");
545 NET_MEMFREE(ProfileList);
546 __NETWORK_FUNC_EXIT__;
547 return NET_ERR_NO_SERVICE;
550 NET_MEMFREE(ProfileList);
552 __NETWORK_FUNC_EXIT__;
557 static int __net_extract_all_services(network_info_t *network_info,
558 GVariantIter *array, net_device_t device_type, const char *service_prefix,
559 int *prof_count, net_profile_info_t **ProfilePtr)
562 net_profile_info_t ProfInfo = { 0, };
563 net_err_t Error = NET_ERR_NONE;
565 GVariantIter *next = NULL;
567 __NETWORK_FUNC_ENTER__;
569 if (array == NULL || service_prefix == NULL) {
570 NETWORK_LOG(NETWORK_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
572 __NETWORK_FUNC_EXIT__;
573 return NET_ERR_INVALID_PARAM;
576 /* LCOV_EXCL_START */
577 while (g_variant_iter_loop(array, "(oa{sv})", &obj, &next)) {
581 if (g_str_has_prefix(obj, service_prefix) == TRUE) {
582 memset(&ProfInfo, 0, sizeof(net_profile_info_t));
584 if ((Error = __net_pm_init_profile_info(device_type, &ProfInfo)) != NET_ERR_NONE) {
585 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
587 NET_MEMFREE(*ProfilePtr);
593 if (device_type == NET_DEVICE_WIFI &&
594 g_strrstr(obj + strlen(service_prefix), "hidden") != NULL)
595 ProfInfo.ProfileInfo.Wlan.is_hidden = TRUE;
597 ProfInfo.profile_type = device_type;
598 g_strlcpy(ProfInfo.ProfileName, obj, NET_PROFILE_NAME_LEN_MAX);
600 switch (device_type) {
601 case NET_DEVICE_WIFI:
602 g_strlcpy(ProfInfo.ProfileInfo.Wlan.net_info.ProfileName,
603 obj, NET_PROFILE_NAME_LEN_MAX);
605 Error = __net_extract_wifi_info(next, &ProfInfo);
607 case NET_DEVICE_CELLULAR:
608 g_strlcpy(ProfInfo.ProfileInfo.Pdp.net_info.ProfileName,
609 obj, NET_PROFILE_NAME_LEN_MAX);
611 Error = __net_extract_mobile_info(network_info, next, &ProfInfo);
613 case NET_DEVICE_ETHERNET:
614 g_strlcpy(ProfInfo.ProfileInfo.Ethernet.net_info.ProfileName,
615 obj, NET_PROFILE_NAME_LEN_MAX);
617 Error = __net_extract_ethernet_info(next, &ProfInfo);
619 case NET_DEVICE_BLUETOOTH:
620 g_strlcpy(ProfInfo.ProfileInfo.Bluetooth.net_info.ProfileName,
621 obj, NET_PROFILE_NAME_LEN_MAX);
623 Error = __net_extract_bluetooth_info(next, &ProfInfo);
625 case NET_DEVICE_MESH:
626 g_strlcpy(ProfInfo.ProfileInfo.Mesh.net_info.ProfileName,
627 obj, NET_PROFILE_NAME_LEN_MAX);
629 Error = __net_extract_mesh_info(next, &ProfInfo);
632 NET_MEMFREE(*ProfilePtr);
635 Error = NET_ERR_NOT_SUPPORTED;
639 if (Error != NET_ERR_NONE) {
640 NETWORK_LOG(NETWORK_ERROR, "Failed to extract service info");
641 NET_MEMFREE(*ProfilePtr);
647 *ProfilePtr = (net_profile_info_t *)realloc(*ProfilePtr,
648 (count + 1) * sizeof(net_profile_info_t));
649 if (*ProfilePtr == NULL) {
650 NETWORK_LOG(NETWORK_ERROR, "Failed to allocate memory");
653 Error = NET_ERR_UNKNOWN;
657 memcpy(*ProfilePtr + count, &ProfInfo, sizeof(net_profile_info_t));
665 __NETWORK_FUNC_EXIT__;
669 /* LCOV_EXCL_START */
671 g_variant_iter_free(next);
675 __NETWORK_FUNC_EXIT__;
680 static int __net_extract_services(network_info_t *network_info,
681 GVariantIter *message, net_device_t device_type,
682 net_profile_info_t **profile_info, int *profile_count)
684 __NETWORK_FUNC_ENTER__;
686 net_err_t Error = NET_ERR_NONE;
687 net_profile_info_t *ProfilePtr = NULL;
689 char *service_prefix = NULL;
693 /* LCOV_EXCL_START */
694 switch (device_type) {
695 case NET_DEVICE_WIFI:
696 service_prefix = CONNMAN_WIFI_SERVICE_PROFILE_PREFIX;
698 case NET_DEVICE_CELLULAR:
699 service_prefix = CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX;
701 case NET_DEVICE_ETHERNET:
702 service_prefix = CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX;
704 case NET_DEVICE_BLUETOOTH:
705 service_prefix = CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX;
707 case NET_DEVICE_MESH:
708 service_prefix = CONNMAN_MESH_PROFILE_PREFIX;
712 *profile_info = NULL;
713 __NETWORK_FUNC_EXIT__;
714 return NET_ERR_NOT_SUPPORTED;
719 Error = __net_extract_all_services(network_info, message,
720 device_type, service_prefix, &prof_cnt, &ProfilePtr);
722 /* LCOV_EXCL_START */
723 if (Error != NET_ERR_NONE) {
724 NETWORK_LOG(NETWORK_ERROR, "Failed to extract services from received message");
726 *profile_info = NULL;
727 __NETWORK_FUNC_EXIT__;
732 *profile_count = prof_cnt;
733 *profile_info = ProfilePtr;
735 __NETWORK_FUNC_EXIT__;
739 /* LCOV_EXCL_START */
740 static int __net_extract_ip(const gchar *value, net_addr_t *ipAddr)
742 __NETWORK_FUNC_ENTER__;
744 unsigned char *ipValue = NULL;
745 char *saveptr = NULL;
746 char ipString[NETPM_IPV4_STR_LEN_MAX+1];
749 ipValue = (unsigned char *)&(ipAddr->Data.Ipv4.s_addr);
752 g_strlcpy(ipString, value, NETPM_IPV4_STR_LEN_MAX+1);
754 ipToken[0] = strtok_r(ipString, ".", &saveptr);
756 if (ipToken[0] != NULL) {
757 ipToken[1] = strtok_r(NULL, ".", &saveptr);
759 if (ipToken[1] != NULL) {
760 ipToken[2] = strtok_r(NULL, ".", &saveptr);
762 if (ipToken[2] != NULL) {
763 ipToken[3] = strtok_r(NULL, ".", &saveptr);
765 if (ipToken[3] != NULL) {
766 ipValue[0] = (unsigned char)atoi(ipToken[0]);
767 ipValue[1] = (unsigned char)atoi(ipToken[1]);
768 ipValue[2] = (unsigned char)atoi(ipToken[2]);
769 ipValue[3] = (unsigned char)atoi(ipToken[3]);
776 __NETWORK_FUNC_EXIT__;
781 static int __net_get_prefix_len(const char *netmask)
783 __NETWORK_FUNC_ENTER__;
785 in_addr_t mask = inet_network(netmask);
788 for (; mask; mask <<= 1)
791 __NETWORK_FUNC_EXIT__;
796 static gboolean __net_check_address_type(int address_family, const char *address)
798 unsigned char buf[sizeof(struct in6_addr)] = {0, };
801 err = inet_pton(address_family, address, buf);
808 static void __net_extract_state_value(GVariant *variant, net_profile_info_t *ProfInfo)
810 const gchar *value = g_variant_get_string(variant, NULL);
812 if (g_strcmp0(value, "idle") == 0)
813 ProfInfo->ProfileState = NET_STATE_TYPE_IDLE;
814 else if (g_strcmp0(value, "failure") == 0)
815 ProfInfo->ProfileState = NET_STATE_TYPE_FAILURE;
816 else if (g_strcmp0(value, "association") == 0)
817 ProfInfo->ProfileState = NET_STATE_TYPE_ASSOCIATION;
818 else if (g_strcmp0(value, "configuration") == 0)
819 ProfInfo->ProfileState = NET_STATE_TYPE_CONFIGURATION;
820 else if (g_strcmp0(value, "ready") == 0)
821 ProfInfo->ProfileState = NET_STATE_TYPE_READY;
822 else if (g_strcmp0(value, "disconnect") == 0)
823 ProfInfo->ProfileState = NET_STATE_TYPE_DISCONNECT;
824 else if (g_strcmp0(value, "online") == 0)
825 ProfInfo->ProfileState = NET_STATE_TYPE_ONLINE;
827 ProfInfo->ProfileState = NET_STATE_TYPE_UNKNOWN;
830 static void __net_extract_state6_value(GVariant *variant, net_profile_info_t *ProfInfo)
832 const gchar *value = g_variant_get_string(variant, NULL);
834 if (g_strcmp0(value, "idle") == 0)
835 ProfInfo->ProfileState6 = NET_STATE_TYPE_IDLE;
836 else if (g_strcmp0(value, "failure") == 0)
837 ProfInfo->ProfileState6 = NET_STATE_TYPE_FAILURE;
838 else if (g_strcmp0(value, "association") == 0)
839 ProfInfo->ProfileState6 = NET_STATE_TYPE_ASSOCIATION;
840 else if (g_strcmp0(value, "configuration") == 0)
841 ProfInfo->ProfileState6 = NET_STATE_TYPE_CONFIGURATION;
842 else if (g_strcmp0(value, "disconnect") == 0)
843 ProfInfo->ProfileState6 = NET_STATE_TYPE_DISCONNECT;
844 else if (g_strcmp0(value, "ready") == 0)
845 ProfInfo->ProfileState6 = NET_STATE_TYPE_READY;
846 else if (g_strcmp0(value, "online") == 0)
847 ProfInfo->ProfileState6 = NET_STATE_TYPE_ONLINE;
849 ProfInfo->ProfileState6 = NET_STATE_TYPE_UNKNOWN;
852 static void __net_extract_error(GVariant *variant, net_profile_info_t *ProfInfo)
854 const gchar *value = g_variant_get_string(variant, NULL);
856 if (g_strcmp0(value, "invalid-key") == 0)
857 ProfInfo->ProfileErrorState = NET_STATE_ERROR_INVALID_KEY;
858 else if (g_strcmp0(value, "connect-failed") == 0)
859 ProfInfo->ProfileErrorState = NET_STATE_ERROR_CONNECT_FAILED;
860 else if (g_strcmp0(value, "auth-failed") == 0)
861 ProfInfo->ProfileErrorState = NET_STATE_ERROR_AUTH_FAILED;
862 else if (g_strcmp0(value, "login-failed") == 0)
863 ProfInfo->ProfileErrorState = NET_STATE_ERROR_LOGIN_FAILED;
864 else if (g_strcmp0(value, "dhcp-failed") == 0)
865 ProfInfo->ProfileErrorState = NET_STATE_ERROR_DHCP_FAILED;
866 else if (g_strcmp0(value, "out-of-range") == 0)
867 ProfInfo->ProfileErrorState = NET_STATE_ERROR_OUT_OF_RANGE;
868 else if (g_strcmp0(value, "pin-missing") == 0)
869 ProfInfo->ProfileErrorState = NET_STATE_ERROR_PIN_MISSING;
872 static void __net_extract_ethernet_value(GVariant *variant, net_dev_info_t *net_info)
874 const gchar *subKey = NULL;
875 const gchar *value = NULL;
876 GVariant *var = NULL;
877 GVariantIter *iter = NULL;
878 g_variant_get(variant, "a{sv}", &iter);
879 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
880 if (g_strcmp0(subKey, "Interface") == 0) {
881 value = g_variant_get_string(var, NULL);
884 g_strlcpy(net_info->DevName, value, NET_MAX_DEVICE_NAME_LEN);
885 } else if (g_strcmp0(subKey, "Address") == 0) {
886 value = g_variant_get_string(var, NULL);
889 g_strlcpy(net_info->MacAddr, value, NET_MAX_MAC_ADDR_LEN);
892 g_variant_iter_free(iter);
895 static void __net_extract_ipv4_value(GVariant *variant, net_dev_info_t *net_info)
897 const gchar *subKey = NULL;
898 const gchar *value = NULL;
899 GVariant *var = NULL;
900 GVariantIter *iter = NULL;
901 g_variant_get(variant, "a{sv}", &iter);
902 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
903 if (g_strcmp0(subKey, "Method") == 0) {
904 value = g_variant_get_string(var, NULL);
906 if (g_strcmp0(value, "dhcp") == 0)
907 net_info->IpConfigType = NET_IP_CONFIG_TYPE_DYNAMIC;
908 else if (g_strcmp0(value, "manual") == 0)
909 net_info->IpConfigType = NET_IP_CONFIG_TYPE_STATIC;
910 else if (g_strcmp0(value, "fixed") == 0)
911 net_info->IpConfigType = NET_IP_CONFIG_TYPE_FIXED;
912 else if (g_strcmp0(value, "off") == 0)
913 net_info->IpConfigType = NET_IP_CONFIG_TYPE_OFF;
915 if (net_info->IpConfigType != NET_IP_CONFIG_TYPE_DYNAMIC) {
916 net_info->BServerAddr = FALSE;
917 net_info->ServerAddr.Type = NET_ADDR_IPV4;
918 net_info->ServerAddr.Data.Ipv4.s_addr = 0;
921 } else if (g_strcmp0(subKey, "Address") == 0) {
922 value = g_variant_get_string(var, NULL);
924 __net_extract_ip(value, &net_info->IpAddr);
925 } else if (g_strcmp0(subKey, "Netmask") == 0) {
926 value = g_variant_get_string(var, NULL);
928 __net_extract_ip(value, &net_info->SubnetMask);
929 net_info->PrefixLen = __net_get_prefix_len(value);
930 net_info->BNetmask = TRUE;
931 } else if (g_strcmp0(subKey, "Gateway") == 0) {
932 value = g_variant_get_string(var, NULL);
934 __net_extract_ip(value, &net_info->GatewayAddr);
935 net_info->BDefGateway = TRUE;
936 } else if (g_strcmp0(subKey, "DHCPServerIP") == 0) {
937 value = g_variant_get_string(var, NULL);
939 __net_extract_ip(value, &net_info->ServerAddr);
940 net_info->BServerAddr = TRUE;
941 } else if (g_strcmp0(subKey, "DHCPLeaseDuration") == 0) {
942 net_info->DHCPLeaseDuration = g_variant_get_int32(var);
945 g_variant_iter_free(iter);
948 static void __net_extract_ipv4_configuration_value(GVariant *variant, net_dev_info_t *net_info)
950 const gchar *subKey = NULL;
951 const gchar *value = NULL;
952 GVariant *var = NULL;
953 GVariantIter *iter = NULL;
954 if (net_info->IpConfigType != NET_IP_CONFIG_TYPE_DYNAMIC &&
955 net_info->IpConfigType != NET_IP_CONFIG_TYPE_STATIC &&
956 net_info->IpConfigType != NET_IP_CONFIG_TYPE_FIXED &&
957 net_info->IpConfigType != NET_IP_CONFIG_TYPE_OFF) {
959 g_variant_get(variant, "a{sv}", &iter);
960 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
961 if (g_strcmp0(subKey, "Method") == 0) {
962 value = g_variant_get_string(var, NULL);
964 if (g_strcmp0(value, "dhcp") == 0)
965 net_info->IpConfigType = NET_IP_CONFIG_TYPE_DYNAMIC;
966 else if (g_strcmp0(value, "manual") == 0)
967 net_info->IpConfigType = NET_IP_CONFIG_TYPE_STATIC;
968 else if (g_strcmp0(value, "fixed") == 0)
969 net_info->IpConfigType = NET_IP_CONFIG_TYPE_FIXED;
970 else if (g_strcmp0(value, "off") == 0)
971 net_info->IpConfigType = NET_IP_CONFIG_TYPE_OFF;
973 } else if (g_strcmp0(subKey, "Address") == 0 &&
974 net_info->IpAddr.Data.Ipv4.s_addr == 0) {
975 value = g_variant_get_string(var, NULL);
977 __net_extract_ip(value, &net_info->IpAddr);
978 } else if (g_strcmp0(subKey, "Netmask") == 0 &&
979 net_info->SubnetMask.Data.Ipv4.s_addr == 0) {
980 value = g_variant_get_string(var, NULL);
982 __net_extract_ip(value, &net_info->SubnetMask);
983 net_info->BNetmask = TRUE;
984 } else if (g_strcmp0(subKey, "Gateway") == 0 &&
985 net_info->GatewayAddr.Data.Ipv4.s_addr == 0) {
986 value = g_variant_get_string(var, NULL);
988 __net_extract_ip(value, &net_info->GatewayAddr);
989 net_info->BDefGateway = TRUE;
992 g_variant_iter_free(iter);
996 static void __net_extract_ipv6_value(GVariant *variant, net_dev_info_t *net_info)
998 const gchar *subKey = NULL;
999 const gchar *value = NULL;
1000 GVariant *var = NULL;
1001 GVariantIter *iter = NULL;
1002 g_variant_get(variant, "a{sv}", &iter);
1003 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
1004 if (g_strcmp0(subKey, "Method") == 0) {
1005 value = g_variant_get_string(var, NULL);
1007 if (g_strcmp0(value, "manual") == 0)
1008 net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_STATIC;
1009 else if (g_strcmp0(value, "off") == 0)
1010 net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_OFF;
1011 else if (g_strcmp0(value, "auto") == 0)
1012 net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_AUTO_IP;
1014 } else if (g_strcmp0(subKey, "Address") == 0) {
1015 value = g_variant_get_string(var, NULL);
1017 inet_pton(AF_INET6, value, &net_info->IpAddr6.Data.Ipv6);
1018 } else if (g_strcmp0(subKey, "PrefixLength") == 0) {
1019 net_info->PrefixLen6 = g_variant_get_byte(var);
1020 } else if (g_strcmp0(subKey, "Gateway") == 0) {
1021 value = g_variant_get_string(var, NULL);
1023 inet_pton(AF_INET6, value, &net_info->GatewayAddr6.Data.Ipv6);
1024 net_info->BDefGateway6 = TRUE;
1025 } else if (g_strcmp0(subKey, "Privacy") == 0) {
1026 value = g_variant_get_string(var, NULL);
1029 g_strlcpy(net_info->Privacy6, value, NETPM_IPV6_MAX_PRIVACY_LEN);
1032 g_variant_iter_free(iter);
1035 static void __net_extract_ipv6_configuration_value(GVariant *variant, net_dev_info_t *net_info)
1037 const gchar *subKey = NULL;
1038 const gchar *value = NULL;
1039 GVariant *var = NULL;
1040 GVariantIter *iter = NULL;
1041 g_variant_get(variant, "a{sv}", &iter);
1042 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
1043 if (g_strcmp0(subKey, "Method") == 0) {
1044 value = g_variant_get_string(var, NULL);
1046 if (g_strcmp0(value, "manual") == 0)
1047 net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_STATIC;
1048 else if (g_strcmp0(value, "off") == 0)
1049 net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_OFF;
1050 else if (g_strcmp0(value, "auto") == 0)
1051 net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_AUTO_IP;
1053 } else if (g_strcmp0(subKey, "Address") == 0) {
1054 value = g_variant_get_string(var, NULL);
1056 inet_pton(AF_INET6, value, &net_info->IpAddr6.Data.Ipv6);
1057 } else if (g_strcmp0(subKey, "PrefixLength") == 0) {
1058 net_info->PrefixLen6 = g_variant_get_byte(var);
1059 } else if (g_strcmp0(subKey, "Gateway") == 0) {
1060 value = g_variant_get_string(var, NULL);
1062 inet_pton(AF_INET6, value, &net_info->GatewayAddr6.Data.Ipv6);
1063 net_info->BDefGateway6 = TRUE;
1064 } else if (g_strcmp0(subKey, "Privacy") == 0) {
1065 value = g_variant_get_string(var, NULL);
1068 g_strlcpy(net_info->Privacy6, value, NETPM_IPV6_MAX_PRIVACY_LEN);
1071 g_variant_iter_free(iter);
1074 static void __net_extract_nameserver_value(GVariant *variant, net_dev_info_t *net_info)
1076 GVariantIter *iter = NULL;
1079 gchar *dns_value = NULL;
1080 gchar *dns_type = NULL;
1082 g_variant_get(variant, "as", &iter);
1084 while (g_variant_iter_loop(iter, "s", &dns_value)) {
1085 /* Check Type of DNS Address */
1086 if (__net_check_address_type(AF_INET6, dns_value)) {
1088 if (dnsCount6 < NET_DNS_ADDR_MAX) {
1089 net_info->DnsAddr6[dnsCount6].Type =
1091 inet_pton(AF_INET6, dns_value,
1092 &net_info->DnsAddr6[dnsCount6]\
1096 } else if (__net_check_address_type(AF_INET, dns_value)) {
1098 if (dnsCount < NET_DNS_ADDR_MAX) {
1099 net_info->DnsAddr[dnsCount].Type =
1101 __net_extract_ip(dns_value,
1102 &net_info->DnsAddr[dnsCount]);
1105 } else { /* DNS Type */
1106 dns_type = g_strdup(dns_value);
1107 if (g_strcmp0(dns_type, "ipv4.manual") == 0)
1108 net_info->DnsConfigType =
1109 NET_DNS_CONFIG_TYPE_STATIC;
1110 else if (g_strcmp0(dns_type, "ipv4.dhcp") == 0)
1111 net_info->DnsConfigType =
1112 NET_DNS_CONFIG_TYPE_DYNAMIC;
1113 if (g_strcmp0(dns_type, "ipv6.manual") == 0)
1114 net_info->DnsConfigType6 =
1115 NET_DNS_CONFIG_TYPE_STATIC;
1116 else if (g_strcmp0(dns_type, "ipv6.dhcp") == 0)
1117 net_info->DnsConfigType6 =
1118 NET_DNS_CONFIG_TYPE_DYNAMIC;
1122 g_variant_iter_free(iter);
1124 net_info->DnsCount = dnsCount;
1125 net_info->DnsCount6 = dnsCount6;
1128 static void __net_extract_nameserver_configuration_value(GVariant *variant, net_dev_info_t *net_info)
1130 GVariantIter *iter = NULL;
1133 gchar *dns_value = NULL;
1134 gchar *dns_type = NULL;
1136 g_variant_get(variant, "as", &iter);
1138 while (g_variant_iter_loop(iter, "s", &dns_value)) {
1139 /* Check Type of DNS Address */
1140 if (__net_check_address_type(AF_INET6, dns_value)) {
1142 if (dnsCount6 < NET_DNS_ADDR_MAX) {
1143 net_info->DnsAddr6[dnsCount6].Type =
1145 inet_pton(AF_INET6, dns_value,
1146 &net_info->DnsAddr6[dnsCount6]\
1150 } else if (__net_check_address_type(AF_INET, dns_value)) {
1152 if (dnsCount < NET_DNS_ADDR_MAX) {
1153 net_info->DnsAddr[dnsCount].Type =
1155 __net_extract_ip(dns_value,
1156 &net_info->DnsAddr[dnsCount]);
1159 } else { /* DNS Type */
1160 dns_type = g_strdup(dns_value);
1161 if (g_strcmp0(dns_type, "ipv4.manual") == 0)
1162 net_info->DnsConfigType =
1163 NET_DNS_CONFIG_TYPE_STATIC;
1164 else if (g_strcmp0(dns_type, "ipv4.dhcp") == 0)
1165 net_info->DnsConfigType =
1166 NET_DNS_CONFIG_TYPE_DYNAMIC;
1167 if (g_strcmp0(dns_type, "ipv6.manual") == 0)
1168 net_info->DnsConfigType6 =
1169 NET_DNS_CONFIG_TYPE_STATIC;
1170 else if (g_strcmp0(dns_type, "ipv6.dhcp") == 0)
1171 net_info->DnsConfigType6 =
1172 NET_DNS_CONFIG_TYPE_DYNAMIC;
1176 g_variant_iter_free(iter);
1178 net_info->DnsCount = dnsCount;
1179 net_info->DnsCount6 = dnsCount6;
1182 static void __net_extract_proxy_value(GVariant *variant, net_dev_info_t *net_info)
1184 const gchar *subKey = NULL;
1185 const gchar *value = NULL;
1186 GVariant *var = NULL;
1187 GVariantIter *iter = NULL;
1188 const gchar *url = NULL;
1189 gchar *servers = NULL;
1191 g_variant_get(variant, "a{sv}", &iter);
1192 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
1193 if (g_strcmp0(subKey, "Method") == 0) {
1194 value = g_variant_get_string(var, NULL);
1196 if (g_strcmp0(value, "direct") == 0)
1197 net_info->ProxyMethod = NET_PROXY_TYPE_DIRECT;
1198 else if (g_strcmp0(value, "auto") == 0)
1199 net_info->ProxyMethod = NET_PROXY_TYPE_AUTO;
1200 else if (g_strcmp0(value, "manual") == 0)
1201 net_info->ProxyMethod = NET_PROXY_TYPE_MANUAL;
1203 net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
1204 } else if (g_strcmp0(subKey, "URL") == 0) {
1205 url = g_variant_get_string(var, NULL);
1206 } else if (g_strcmp0(subKey, "Servers") == 0) {
1207 GVariantIter *iter_sub = NULL;
1209 g_variant_get(var, "as", &iter_sub);
1210 if (!g_variant_iter_loop(iter_sub, "s", &servers))
1211 NETWORK_LOG(NETWORK_LOW, "There was no value");
1212 g_variant_iter_free(iter_sub);
1215 g_variant_iter_free(iter);
1217 if (net_info->ProxyMethod == NET_PROXY_TYPE_AUTO && url != NULL)
1218 g_strlcpy(net_info->ProxyAddr, url, NET_PROXY_LEN_MAX);
1219 else if (net_info->ProxyMethod == NET_PROXY_TYPE_MANUAL && servers != NULL)
1220 g_strlcpy(net_info->ProxyAddr, servers, NET_PROXY_LEN_MAX);
1226 static void __net_extract_proxy_configuration_value(GVariant *variant, net_dev_info_t *net_info)
1228 const gchar *subKey = NULL;
1229 const gchar *value = NULL;
1230 GVariant *var = NULL;
1231 GVariantIter *iter = NULL;
1232 const gchar *url = NULL;
1233 gchar *servers = NULL;
1235 g_variant_get(variant, "a{sv}", &iter);
1236 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
1237 if (g_strcmp0(subKey, "Method") == 0) {
1238 value = g_variant_get_string(var, NULL);
1240 if (g_strcmp0(value, "direct") == 0)
1241 net_info->ProxyMethod = NET_PROXY_TYPE_DIRECT;
1242 else if (g_strcmp0(value, "auto") == 0)
1243 net_info->ProxyMethod = NET_PROXY_TYPE_AUTO;
1244 else if (g_strcmp0(value, "manual") == 0)
1245 net_info->ProxyMethod = NET_PROXY_TYPE_MANUAL;
1247 net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
1248 } else if (g_strcmp0(subKey, "URL") == 0) {
1249 url = g_variant_get_string(var, NULL);
1250 } else if (g_strcmp0(subKey, "Servers") == 0) {
1251 GVariantIter *iter_sub = NULL;
1253 g_variant_get(var, "as", &iter_sub);
1254 if (!g_variant_iter_loop(iter_sub, "s", &servers))
1255 NETWORK_LOG(NETWORK_LOW, "There was no value");
1256 g_variant_iter_free(iter_sub);
1259 g_variant_iter_free(iter);
1261 if (net_info->ProxyMethod == NET_PROXY_TYPE_AUTO && url != NULL)
1262 g_strlcpy(net_info->ProxyAddr, url, NET_PROXY_LEN_MAX);
1263 else if (net_info->ProxyMethod == NET_PROXY_TYPE_MANUAL && servers != NULL)
1264 g_strlcpy(net_info->ProxyAddr, servers, NET_PROXY_LEN_MAX);
1270 static net_ethernet_eap_type_t __net_convert_eap_type_from_string(const char *eap_type)
1272 if (g_strcmp0(eap_type, "MD5") == 0)
1273 return NET_ETHERNET_EAP_TYPE_MD5;
1274 else if (g_strcmp0(eap_type, "PEAP") == 0)
1275 return NET_ETHERNET_EAP_TYPE_PEAP;
1276 else if (g_strcmp0(eap_type, "TLS") == 0)
1277 return NET_ETHERNET_EAP_TYPE_TLS;
1278 else if (g_strcmp0(eap_type, "TTLS") == 0)
1279 return NET_ETHERNET_EAP_TYPE_TTLS;
1280 else if (g_strcmp0(eap_type, "FAST") == 0)
1281 return NET_ETHERNET_EAP_TYPE_FAST;
1286 static net_ethernet_eap_auth_type_t __net_convert_eap_auth_from_string(const char *eap_auth)
1288 if (g_strcmp0(eap_auth, "PAP") == 0)
1289 return NET_ETHERNET_EAP_AUTH_TYPE_PAP;
1290 else if (g_strcmp0(eap_auth, "MSCHAP") == 0)
1291 return NET_ETHERNET_EAP_AUTH_TYPE_MSCHAP;
1292 else if (g_strcmp0(eap_auth, "MSCHAPV2") == 0)
1293 return NET_ETHERNET_EAP_AUTH_TYPE_MSCHAPV2;
1294 else if (g_strcmp0(eap_auth, "GTC") == 0)
1295 return NET_ETHERNET_EAP_AUTH_TYPE_GTC;
1296 else if (g_strcmp0(eap_auth, "MD5") == 0)
1297 return NET_ETHERNET_EAP_AUTH_TYPE_MD5;
1299 return NET_ETHERNET_EAP_AUTH_TYPE_NONE;
1302 static void __net_extract_eapol_value(GVariant *variant, net_dev_info_t *net_info)
1304 const gchar *subKey = NULL;
1305 const gchar *value = NULL;
1306 GVariant *var = NULL;
1307 GVariantIter *iter = NULL;
1309 g_variant_get(variant, "a{sv}", &iter);
1310 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
1311 if (g_strcmp0(subKey, "UseEapol") == 0) {
1312 net_info->use_eapol = g_variant_get_boolean(var);
1314 } else if (g_strcmp0(subKey, "EAP") == 0) {
1315 value = g_variant_get_string(var, NULL);
1318 net_info->eap.eap_type = __net_convert_eap_type_from_string(value);
1319 } else if (g_strcmp0(subKey, "Identity") == 0) {
1320 value = g_variant_get_string(var, NULL);
1323 g_strlcpy(net_info->eap.username, value, NET_USERNAME_LEN+1);
1324 } else if (g_strcmp0(subKey, "AnonymousIdentity") == 0) {
1325 value = g_variant_get_string(var, NULL);
1328 g_strlcpy(net_info->eap.anonymous_identity, value, NET_USERNAME_LEN+1);
1329 } else if (g_strcmp0(subKey, "CACertFile") == 0) {
1330 value = g_variant_get_string(var, NULL);
1333 g_strlcpy(net_info->eap.ca_cert_filename, value, NET_CA_CERT_FILENAME_LEN+1);
1334 } else if (g_strcmp0(subKey, "ClientCertFile") == 0) {
1335 value = g_variant_get_string(var, NULL);
1338 g_strlcpy(net_info->eap.client_cert_filename, value, NET_CLIENT_CERT_FILENAME_LEN+1);
1339 } else if (g_strcmp0(subKey, "PrivateKeyFile") == 0) {
1340 value = g_variant_get_string(var, NULL);
1343 g_strlcpy(net_info->eap.private_key_filename, value, NET_PRIVATE_KEY_FILENAME_LEN+1);
1344 } else if (g_strcmp0(subKey, "Phase2") == 0) {
1345 value = g_variant_get_string(var, NULL);
1348 net_info->eap.eap_auth = __net_convert_eap_auth_from_string(value);
1349 } else if (g_strcmp0(subKey, "Phase1") == 0) {
1350 value = g_variant_get_string(var, NULL);
1352 if (value != NULL) {
1353 if (g_strcmp0(value, "1") == 0)
1354 net_info->eap.peap_version = 1;
1356 net_info->eap.peap_version = 0;
1358 } else if (g_strcmp0(subKey, "PacFile") == 0) {
1359 value = g_variant_get_string(var, NULL);
1362 g_strlcpy(net_info->eap.pac_filename, value, NET_PAC_FILENAME_LEN+1);
1365 g_variant_iter_free(iter);
1368 static int __net_extract_common_info(const char *key, GVariant *variant, net_profile_info_t *ProfInfo)
1370 __NETWORK_FUNC_ENTER__;
1372 net_err_t Error = NET_ERR_NONE;
1373 net_dev_info_t *net_info = NULL;
1375 if (ProfInfo->profile_type == NET_DEVICE_CELLULAR) {
1376 net_info = &(ProfInfo->ProfileInfo.Pdp.net_info);
1377 } else if (ProfInfo->profile_type == NET_DEVICE_WIFI) {
1378 net_info = &(ProfInfo->ProfileInfo.Wlan.net_info);
1379 } else if (ProfInfo->profile_type == NET_DEVICE_ETHERNET) {
1380 net_info = &(ProfInfo->ProfileInfo.Ethernet.net_info);
1381 } else if (ProfInfo->profile_type == NET_DEVICE_BLUETOOTH) {
1382 net_info = &(ProfInfo->ProfileInfo.Bluetooth.net_info);
1383 } else if (ProfInfo->profile_type == NET_DEVICE_MESH) {
1384 net_info = &(ProfInfo->ProfileInfo.Mesh.net_info);
1386 NETWORK_LOG(NETWORK_ERROR,
1387 "Invalid Profile type. [%d]", ProfInfo->profile_type);
1388 return NET_ERR_INVALID_PARAM;
1391 if (g_strcmp0(key, "State") == 0) {
1392 __net_extract_state_value(variant, ProfInfo);
1393 } else if (g_strcmp0(key, "StateIPv6") == 0) {
1394 __net_extract_state6_value(variant, ProfInfo);
1395 } else if (g_strcmp0(key, "Error") == 0) {
1396 __net_extract_error(variant, ProfInfo);
1397 } else if (g_strcmp0(key, "Favorite") == 0) {
1398 ProfInfo->Favourite = (char)g_variant_get_boolean(variant);
1399 } else if (g_strcmp0(key, "Ethernet") == 0) {
1400 __net_extract_ethernet_value(variant, net_info);
1401 } else if (g_strcmp0(key, "IPv4") == 0) {
1402 __net_extract_ipv4_value(variant, net_info);
1403 } else if (g_strcmp0(key, "IPv4.Configuration") == 0) {
1404 __net_extract_ipv4_configuration_value(variant, net_info);
1405 } else if (g_strcmp0(key, "IPv6") == 0) {
1406 __net_extract_ipv6_value(variant, net_info);
1407 } else if (g_strcmp0(key, "IPv6.Configuration") == 0) {
1408 __net_extract_ipv6_configuration_value(variant, net_info);
1409 } else if (g_strcmp0(key, "Nameservers") == 0) {
1410 __net_extract_nameserver_value(variant, net_info);
1411 } else if (g_strcmp0(key, "Nameservers.Configuration") == 0 && net_info->DnsCount == 0) {
1412 __net_extract_nameserver_configuration_value(variant, net_info);
1413 } else if (g_strcmp0(key, "Domains") == 0) {
1414 } else if (g_strcmp0(key, "Domains.Configuration") == 0) {
1415 } else if (g_strcmp0(key, "Proxy") == 0) {
1416 __net_extract_proxy_value(variant, net_info);
1417 } else if (g_strcmp0(key, "Proxy.Configuration") == 0 &&
1418 net_info->ProxyMethod != NET_PROXY_TYPE_AUTO &&
1419 net_info->ProxyMethod != NET_PROXY_TYPE_MANUAL) {
1420 __net_extract_proxy_configuration_value(variant, net_info);
1421 } else if (g_strcmp0(key, "Provider") == 0) {
1423 } else if (g_strcmp0(key, "EapOverEthernet") == 0) {
1424 __net_extract_eapol_value(variant, net_info);
1427 __NETWORK_FUNC_EXIT__;
1431 static wlan_eap_type_t __convert_eap_type_from_string(const char *eap_type)
1433 if (eap_type == NULL)
1434 return WLAN_SEC_EAP_TYPE_PEAP;
1435 else if (g_strcmp0(eap_type, "peap") == 0)
1436 return WLAN_SEC_EAP_TYPE_PEAP;
1437 else if (g_strcmp0(eap_type, "tls") == 0)
1438 return WLAN_SEC_EAP_TYPE_TLS;
1439 else if (g_strcmp0(eap_type, "ttls") == 0)
1440 return WLAN_SEC_EAP_TYPE_TTLS;
1441 else if (g_strcmp0(eap_type, "sim") == 0)
1442 return WLAN_SEC_EAP_TYPE_SIM;
1443 else if (g_strcmp0(eap_type, "aka") == 0)
1444 return WLAN_SEC_EAP_TYPE_AKA;
1446 return WLAN_SEC_EAP_TYPE_PEAP;
1449 static wlan_eap_auth_type_t __convert_eap_auth_from_string(const char *eap_auth)
1451 if (eap_auth == NULL)
1452 return WLAN_SEC_EAP_AUTH_NONE;
1453 else if (g_strcmp0(eap_auth, "NONE") == 0)
1454 return WLAN_SEC_EAP_AUTH_NONE;
1455 else if (g_strcmp0(eap_auth, "PAP") == 0)
1456 return WLAN_SEC_EAP_AUTH_PAP;
1457 else if (g_strcmp0(eap_auth, "MSCHAP") == 0)
1458 return WLAN_SEC_EAP_AUTH_MSCHAP;
1459 else if (g_strcmp0(eap_auth, "MSCHAPV2") == 0)
1460 return WLAN_SEC_EAP_AUTH_MSCHAPV2;
1461 else if (g_strcmp0(eap_auth, "GTC") == 0)
1462 return WLAN_SEC_EAP_AUTH_GTC;
1463 else if (g_strcmp0(eap_auth, "MD5") == 0)
1464 return WLAN_SEC_EAP_AUTH_MD5;
1466 return WLAN_SEC_EAP_AUTH_NONE;
1469 static void __net_set_wifi_mode(GVariant *var, net_wifi_profile_info_t *Wlan)
1471 const gchar *value = g_variant_get_string(var, NULL);
1473 if (g_strcmp0(value, "managed") == 0)
1474 Wlan->wlan_mode = NETPM_WLAN_CONNMODE_INFRA;
1475 else if (g_strcmp0(value, "adhoc") == 0)
1476 Wlan->wlan_mode = NETPM_WLAN_CONNMODE_ADHOC;
1478 Wlan->wlan_mode = NETPM_WLAN_CONNMODE_AUTO;
1481 static void __net_set_wifi_security(GVariant *var, net_wifi_profile_info_t *Wlan)
1483 GVariantIter *iter_sub = NULL;
1484 const gchar *value = NULL;
1486 g_variant_get(var, "as", &iter_sub);
1487 while (g_variant_iter_loop(iter_sub, "s", &value)) {
1488 if (g_strcmp0(value, "none") == 0 &&
1489 Wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1490 Wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1491 else if (g_strcmp0(value, "wep") == 0 &&
1492 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WEP)
1493 Wlan->security_info.sec_mode = WLAN_SEC_MODE_WEP;
1494 else if (g_strcmp0(value, "psk") == 0 &&
1495 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1496 Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
1497 else if (g_strcmp0(value, "ft_psk") == 0 &&
1498 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_FT_PSK)
1499 Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_FT_PSK;
1500 else if (g_strcmp0(value, "ieee8021x") == 0 &&
1501 Wlan->security_info.sec_mode < WLAN_SEC_MODE_IEEE8021X)
1502 Wlan->security_info.sec_mode = WLAN_SEC_MODE_IEEE8021X;
1503 else if (g_strcmp0(value, "wpa") == 0 &&
1504 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1505 Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
1506 else if (g_strcmp0(value, "rsn") == 0 &&
1507 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1508 Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK;
1509 else if (g_strcmp0(value, "sae") == 0 &&
1510 Wlan->security_info.sec_mode < WLAN_SEC_MODE_SAE)
1511 Wlan->security_info.sec_mode = WLAN_SEC_MODE_SAE;
1512 else if (g_strcmp0(value, "wps") == 0)
1513 Wlan->security_info.wps_support = TRUE;
1514 else if (Wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1515 Wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1517 g_variant_iter_free(iter_sub);
1520 static void __net_set_wifi_encryption_mode(GVariant *var, net_wifi_profile_info_t *Wlan)
1522 const gchar *value = g_variant_get_string(var, NULL);
1524 if (g_strcmp0(value, "none") == 0)
1525 Wlan->security_info.enc_mode = WLAN_ENC_MODE_NONE;
1526 else if (g_strcmp0(value, "wep") == 0)
1527 Wlan->security_info.enc_mode = WLAN_ENC_MODE_WEP;
1528 else if (g_strcmp0(value, "tkip") == 0)
1529 Wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP;
1530 else if (g_strcmp0(value, "aes") == 0)
1531 Wlan->security_info.enc_mode = WLAN_ENC_MODE_AES;
1532 else if (g_strcmp0(value, "mixed") == 0)
1533 Wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP_AES_MIXED;
1536 static void __net_set_wifi_name(GVariant *var, net_wifi_profile_info_t *Wlan)
1538 const gchar *value = g_variant_get_string(var, NULL);
1541 g_strlcpy(Wlan->essid, value, NET_WLAN_ESSID_LEN);
1544 static void __net_set_wifi_passphrase(GVariant *var, net_wifi_profile_info_t *Wlan)
1546 wlan_security_info_t *security_info = &(Wlan->security_info);
1547 const gchar *value = g_variant_get_string(var, NULL);
1549 if (security_info->sec_mode == WLAN_SEC_MODE_WEP && value != NULL)
1550 g_strlcpy(security_info->authentication.wep.wepKey,
1551 value, NETPM_WLAN_MAX_WEP_KEY_LEN+1);
1552 else if ((security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
1553 security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) &&
1555 g_strlcpy(security_info->authentication.psk.pskKey,
1556 value, NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN+1);
1557 else if (security_info->sec_mode == WLAN_SEC_MODE_SAE && value != NULL)
1558 g_strlcpy(security_info->authentication.sae.saeKey,
1559 value, NETPM_WLAN_MAX_SAE_KEY_LEN+1);
1562 static void __net_set_wifi_bssid(GVariant *var, net_wifi_profile_info_t *Wlan)
1564 const gchar *value = g_variant_get_string(var, NULL);
1567 g_strlcpy(Wlan->bssid, value, NET_MAX_MAC_ADDR_LEN);
1570 static void __net_set_wifi_eap(GVariant *var, net_wifi_profile_info_t *Wlan)
1572 const gchar *value = g_variant_get_string(var, NULL);
1575 Wlan->security_info.authentication.eap.eap_type =
1576 __convert_eap_type_from_string(value);
1579 static void __net_set_wifi_phase2(GVariant *var, net_wifi_profile_info_t *Wlan)
1581 const gchar *value = g_variant_get_string(var, NULL);
1584 Wlan->security_info.authentication.eap.eap_auth =
1585 __convert_eap_auth_from_string(value);
1588 static void __net_set_wifi_identity(GVariant *var, net_wifi_profile_info_t *Wlan)
1590 const gchar *value = g_variant_get_string(var, NULL);
1593 g_strlcpy(Wlan->security_info.authentication.eap.username,
1594 value, NETPM_WLAN_USERNAME_LEN+1);
1597 static void __net_set_wifi_password(GVariant *var, net_wifi_profile_info_t *Wlan)
1599 const gchar *value = g_variant_get_string(var, NULL);
1602 g_strlcpy(Wlan->security_info.authentication.eap.password,
1603 value, NETPM_WLAN_PASSWORD_LEN+1);
1606 static void __net_set_wifi_ca_cert_file(GVariant *var, net_wifi_profile_info_t *Wlan)
1608 const gchar *value = g_variant_get_string(var, NULL);
1611 g_strlcpy(Wlan->security_info.authentication.eap.ca_cert_filename,
1612 value, NETPM_WLAN_CA_CERT_FILENAME_LEN+1);
1615 static void __net_set_wifi_client_cert_file(GVariant *var, net_wifi_profile_info_t *Wlan)
1617 const gchar *value = g_variant_get_string(var, NULL);
1620 g_strlcpy(Wlan->security_info.authentication.eap.client_cert_filename,
1621 value, NETPM_WLAN_CLIENT_CERT_FILENAME_LEN+1);
1624 static void __net_set_wifi_private_key_file(GVariant *var, net_wifi_profile_info_t *Wlan)
1626 const gchar *value = g_variant_get_string(var, NULL);
1629 g_strlcpy(Wlan->security_info.authentication.eap.private_key_filename,
1630 value, NETPM_WLAN_PRIVATE_KEY_FILENAME_LEN+1);
1633 static void __net_set_wifi_private_key_passphrase(GVariant *var, net_wifi_profile_info_t *Wlan)
1635 const gchar *value = g_variant_get_string(var, NULL);
1638 g_strlcpy(Wlan->security_info.authentication.eap.private_key_passwd,
1639 value, NETPM_WLAN_PRIVATE_KEY_PASSWD_LEN+1);
1642 static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_t *ProfInfo)
1644 net_err_t Error = NET_ERR_NONE;
1645 net_wifi_profile_info_t *Wlan = &(ProfInfo->ProfileInfo.Wlan);
1646 GVariant *var = NULL;
1647 const gchar *key = NULL;
1649 __NETWORK_FUNC_ENTER__;
1651 while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
1652 if (g_strcmp0(key, "Mode") == 0) {
1653 __net_set_wifi_mode(var, Wlan);
1654 } else if (g_strcmp0(key, "Security") == 0) {
1655 __net_set_wifi_security(var, Wlan);
1656 } else if (g_strcmp0(key, "EncryptionMode") == 0) {
1657 __net_set_wifi_encryption_mode(var, Wlan);
1658 } else if (g_strcmp0(key, "Passpoint") == 0) {
1659 Wlan->passpoint = g_variant_get_boolean(var);
1660 } else if (g_strcmp0(key, "Strength") == 0) {
1661 Wlan->Strength = g_variant_get_byte(var);
1662 } else if (g_strcmp0(key, "Name") == 0) {
1663 __net_set_wifi_name(var, Wlan);
1664 } else if (g_strcmp0(key, "Passphrase") == 0) {
1665 __net_set_wifi_passphrase(var, Wlan);
1666 } else if (g_strcmp0(key, "PassphraseRequired") == 0) {
1667 Wlan->PassphraseRequired = g_variant_get_boolean(var);
1668 } else if (g_strcmp0(key, "BSSID") == 0) {
1669 __net_set_wifi_bssid(var, Wlan);
1670 } else if (g_strcmp0(key, "MaxSpeed") == 0) {
1671 Wlan->max_rate = g_variant_get_int32(var);
1672 } else if (g_strcmp0(key, "Frequency") == 0) {
1673 Wlan->frequency = (unsigned int)g_variant_get_uint16(var);
1674 } else if (g_strcmp0(key, "EAP") == 0) {
1675 __net_set_wifi_eap(var, Wlan);
1676 } else if (g_strcmp0(key, "Phase2") == 0) {
1677 __net_set_wifi_phase2(var, Wlan);
1678 } else if (g_strcmp0(key, "Identity") == 0) {
1679 __net_set_wifi_identity(var, Wlan);
1680 } else if (g_strcmp0(key, "Password") == 0) {
1681 __net_set_wifi_password(var, Wlan);
1682 } else if (g_strcmp0(key, "CACertFile") == 0) {
1683 __net_set_wifi_ca_cert_file(var, Wlan);
1684 } else if (g_strcmp0(key, "ClientCertFile") == 0) {
1685 __net_set_wifi_client_cert_file(var, Wlan);
1686 } else if (g_strcmp0(key, "PrivateKeyFile") == 0) {
1687 __net_set_wifi_private_key_file(var, Wlan);
1688 } else if (g_strcmp0(key, "PrivateKeyPassphrase") == 0) {
1689 __net_set_wifi_private_key_passphrase(var, Wlan);
1690 } else if (g_strcmp0(key, "Keymgmt") == 0) {
1691 Wlan->security_info.keymgmt = (unsigned int)g_variant_get_uint32(var);
1693 Error = __net_extract_common_info(key, var, ProfInfo);
1696 __NETWORK_FUNC_EXIT__;
1700 static int __net_extract_mesh_info(GVariantIter *array,
1701 net_profile_info_t *ProfInfo)
1703 net_err_t Error = NET_ERR_NONE;
1704 net_mesh_profile_info_t *Mesh = &(ProfInfo->ProfileInfo.Mesh);
1705 GVariant *var = NULL;
1706 const gchar *key = NULL;
1708 __NETWORK_FUNC_ENTER__;
1710 while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
1711 const gchar *value = NULL;
1713 if (g_strcmp0(key, "Security") == 0) {
1714 value = g_variant_get_string(var, NULL);
1715 if (g_strcmp0(value, "none") == 0 &&
1716 Mesh->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1717 Mesh->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1718 else if (g_strcmp0(value, "sae") == 0 &&
1719 Mesh->security_info.sec_mode < WLAN_SEC_MODE_SAE)
1720 Mesh->security_info.sec_mode = WLAN_SEC_MODE_SAE;
1721 else if (Mesh->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1722 Mesh->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1723 } else if (g_strcmp0(key, "Strength") == 0) {
1724 Mesh->Strength = g_variant_get_byte(var);
1725 } else if (g_strcmp0(key, "Name") == 0) {
1726 value = g_variant_get_string(var, NULL);
1729 g_strlcpy(Mesh->essid, value, NET_WLAN_ESSID_LEN);
1730 } else if (g_strcmp0(key, "Passphrase") == 0) {
1731 wlan_security_info_t *security_info = &(Mesh->security_info);
1732 value = g_variant_get_string(var, NULL);
1734 if (security_info->sec_mode == WLAN_SEC_MODE_SAE && value != NULL)
1735 g_strlcpy(security_info->authentication.sae.saeKey,
1736 value, NETPM_WLAN_MAX_SAE_KEY_LEN+1);
1737 } else if (g_strcmp0(key, "PassphraseRequired") == 0) {
1740 val = g_variant_get_boolean(var);
1743 Mesh->PassphraseRequired = TRUE;
1745 Mesh->PassphraseRequired = FALSE;
1746 } else if (g_strcmp0(key, "BSSID") == 0) {
1747 value = g_variant_get_string(var, NULL);
1750 g_strlcpy(Mesh->bssid, value, NET_MAX_MAC_ADDR_LEN);
1752 } else if (g_strcmp0(key, "Frequency") == 0) {
1753 Mesh->frequency = (unsigned int)g_variant_get_uint16(var);
1756 Error = __net_extract_common_info(key, var, ProfInfo);
1759 __NETWORK_FUNC_EXIT__;
1763 static int __net_extract_mobile_info(network_info_t *network_info,
1764 GVariantIter *array, net_profile_info_t *ProfInfo)
1766 net_err_t Error = NET_ERR_NONE;
1767 GVariant *var = NULL;
1768 const gchar *key = NULL;
1770 __NETWORK_FUNC_ENTER__;
1772 while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
1773 const gchar *value = NULL;
1775 if (g_strcmp0(key, "Mode") == 0) {
1776 value = g_variant_get_string(var, NULL);
1778 if (g_strcmp0(value, "gprs") == 0)
1779 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_GPRS;
1780 else if (g_strcmp0(value, "edge") == 0)
1781 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_EDGE;
1782 else if (g_strcmp0(value, "umts") == 0)
1783 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_UMTS;
1785 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_NONE;
1786 } else if (g_strcmp0(key, "Roaming") == 0) {
1789 val = g_variant_get_boolean(var);
1791 ProfInfo->ProfileInfo.Pdp.Roaming = TRUE;
1793 ProfInfo->ProfileInfo.Pdp.Roaming = FALSE;
1794 } else if (g_strcmp0(key, "SetupRequired") == 0) {
1797 val = g_variant_get_boolean(var);
1799 ProfInfo->ProfileInfo.Pdp.SetupRequired = TRUE;
1801 ProfInfo->ProfileInfo.Pdp.SetupRequired = FALSE;
1802 #if defined TIZEN_DUALSIM_ENABLE
1803 } else if (g_strcmp0(key, "Name") == 0) {
1804 value = g_variant_get_string(var, NULL);
1805 if (value != NULL) {
1806 gchar **list = g_strsplit(value, "/context", 0);
1809 g_strlcpy(ProfInfo->ProfileInfo.Pdp.PSModemPath,
1810 list[0], NET_PROFILE_NAME_LEN_MAX);
1811 NETWORK_LOG(NETWORK_LOW, "Modem path: %s",
1812 ProfInfo->ProfileInfo.Pdp.PSModemPath);
1815 NETWORK_LOG(NETWORK_ERROR, "Invalid modem path: %s", value);
1817 NETWORK_LOG(NETWORK_ERROR, "Null modem path");
1820 Error = __net_extract_common_info(key, var, ProfInfo);
1821 if (Error != NET_ERR_NONE)
1822 NETWORK_LOG(NETWORK_ERROR, "fail to extract common info err(%d)", Error);
1826 /* Get Specific info from telephony service */
1827 net_telephony_profile_info_t telephony_profinfo;
1828 net_profile_name_t PdpProfName;
1830 PdpProfName.ProfileName[0] = '\0';
1832 __net_telephony_init_profile_info(&telephony_profinfo);
1834 /* Find matching profile in telephony service */
1835 Error = __net_telephony_search_pdp_profile(network_info, ProfInfo->ProfileName, &PdpProfName);
1837 if (Error == NET_ERR_NONE && strlen(PdpProfName.ProfileName) > 0) {
1838 /* Get profile info from telephony service */
1839 Error = __net_telephony_get_profile_info(network_info, &PdpProfName, &telephony_profinfo);
1841 if (Error == NET_ERR_NONE) {
1842 ProfInfo->ProfileInfo.Pdp.ServiceType = telephony_profinfo.ServiceType;
1844 if (strlen(telephony_profinfo.Apn) > 0)
1845 g_strlcpy(ProfInfo->ProfileInfo.Pdp.Apn,
1846 telephony_profinfo.Apn, NET_PDP_APN_LEN_MAX);
1848 if (strlen(telephony_profinfo.ProxyAddr) > 0)
1849 g_strlcpy(ProfInfo->ProfileInfo.Pdp.net_info.ProxyAddr,
1850 telephony_profinfo.ProxyAddr, NET_PROXY_LEN_MAX);
1852 if (strlen(telephony_profinfo.HomeURL) > 0)
1853 g_strlcpy(ProfInfo->ProfileInfo.Pdp.HomeURL,
1854 telephony_profinfo.HomeURL, NET_HOME_URL_LEN_MAX);
1856 ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType = telephony_profinfo.AuthInfo.AuthType;
1857 ProfInfo->ProfileInfo.Pdp.PdnType = telephony_profinfo.PdnType;
1858 ProfInfo->ProfileInfo.Pdp.RoamPdnType = telephony_profinfo.RoamPdnType;
1860 if (strlen(telephony_profinfo.AuthInfo.UserName) > 0)
1861 g_strlcpy(ProfInfo->ProfileInfo.Pdp.AuthInfo.UserName,
1862 telephony_profinfo.AuthInfo.UserName,
1863 NET_PDP_AUTH_USERNAME_LEN_MAX);
1865 if (strlen(telephony_profinfo.AuthInfo.Password) > 0)
1866 g_strlcpy(ProfInfo->ProfileInfo.Pdp.AuthInfo.Password,
1867 telephony_profinfo.AuthInfo.Password,
1868 NET_PDP_AUTH_PASSWORD_LEN_MAX);
1870 if (strlen(telephony_profinfo.Keyword) > 0)
1871 g_strlcpy(ProfInfo->ProfileInfo.Pdp.Keyword,
1872 telephony_profinfo.Keyword,
1873 NET_PDP_APN_LEN_MAX);
1875 ProfInfo->ProfileInfo.Pdp.Hidden = telephony_profinfo.Hidden;
1876 ProfInfo->ProfileInfo.Pdp.Editable = telephony_profinfo.Editable;
1877 ProfInfo->ProfileInfo.Pdp.DefaultConn = telephony_profinfo.DefaultConn;
1881 __NETWORK_FUNC_EXIT__;
1885 static int __net_extract_ethernet_info(GVariantIter *array, net_profile_info_t *ProfInfo)
1887 net_err_t Error = NET_ERR_NONE;
1888 GVariant *var = NULL;
1889 const gchar *key = NULL;
1891 __NETWORK_FUNC_ENTER__;
1893 while (g_variant_iter_loop(array, "{sv}", &key, &var))
1894 Error = __net_extract_common_info(key, var, ProfInfo);
1896 __NETWORK_FUNC_EXIT__;
1900 static int __net_extract_bluetooth_info(GVariantIter *array, net_profile_info_t *ProfInfo)
1902 net_err_t Error = NET_ERR_NONE;
1903 GVariant *var = NULL;
1904 const gchar *key = NULL;
1906 __NETWORK_FUNC_ENTER__;
1908 while (g_variant_iter_loop(array, "{sv}", &key, &var))
1909 Error = __net_extract_common_info(key, var, ProfInfo);
1911 __NETWORK_FUNC_EXIT__;
1915 static int __net_extract_service_info(network_info_t *network_info,
1916 const char *ProfileName, GVariantIter *iter,
1917 net_profile_info_t *ProfInfo)
1919 __NETWORK_FUNC_ENTER__;
1921 net_err_t Error = NET_ERR_NONE;
1922 net_device_t profileType = NET_DEVICE_UNKNOWN;
1924 GVariant *value = NULL;
1926 while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
1927 const gchar *tech = NULL;
1929 if (g_strcmp0(key, "Type") == 0) {
1930 tech = g_variant_get_string(value, NULL);
1932 if (g_strcmp0(tech, "wifi") == 0)
1933 profileType = NET_DEVICE_WIFI;
1934 else if (g_strcmp0(tech, "cellular") == 0)
1935 profileType = NET_DEVICE_CELLULAR;
1936 else if (g_strcmp0(tech, "ethernet") == 0)
1937 profileType = NET_DEVICE_ETHERNET;
1938 else if (g_strcmp0(tech, "bluetooth") == 0)
1939 profileType = NET_DEVICE_BLUETOOTH;
1940 else if (g_strcmp0(tech, "mesh") == 0)
1941 profileType = NET_DEVICE_MESH;
1943 g_variant_unref(value);
1949 if (profileType == NET_DEVICE_WIFI) {
1950 if ((Error = __net_pm_init_profile_info(NET_DEVICE_WIFI, ProfInfo)) != NET_ERR_NONE) {
1951 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
1952 __NETWORK_FUNC_EXIT__;
1956 ProfInfo->profile_type = NET_DEVICE_WIFI;
1957 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1958 g_strlcpy(ProfInfo->ProfileInfo.Wlan.net_info.ProfileName,
1959 ProfileName, NET_PROFILE_NAME_LEN_MAX);
1961 Error = __net_extract_wifi_info(iter, ProfInfo);
1962 } else if (profileType == NET_DEVICE_CELLULAR) {
1963 if ((Error = __net_pm_init_profile_info(NET_DEVICE_CELLULAR, ProfInfo)) != NET_ERR_NONE) {
1964 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
1965 __NETWORK_FUNC_EXIT__;
1969 ProfInfo->profile_type = NET_DEVICE_CELLULAR;
1970 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1971 g_strlcpy(ProfInfo->ProfileInfo.Pdp.net_info.ProfileName,
1972 ProfileName, NET_PROFILE_NAME_LEN_MAX);
1974 Error = __net_extract_mobile_info(network_info, iter, ProfInfo);
1975 } else if (profileType == NET_DEVICE_ETHERNET) {
1976 if ((Error = __net_pm_init_profile_info(NET_DEVICE_ETHERNET, ProfInfo)) != NET_ERR_NONE) {
1977 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
1978 __NETWORK_FUNC_EXIT__;
1982 ProfInfo->profile_type = NET_DEVICE_ETHERNET;
1983 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1984 g_strlcpy(ProfInfo->ProfileInfo.Ethernet.net_info.ProfileName,
1985 ProfileName, NET_PROFILE_NAME_LEN_MAX);
1987 Error = __net_extract_ethernet_info(iter, ProfInfo);
1988 } else if (profileType == NET_DEVICE_BLUETOOTH) {
1989 if ((Error = __net_pm_init_profile_info(NET_DEVICE_BLUETOOTH, ProfInfo)) != NET_ERR_NONE) {
1990 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
1991 __NETWORK_FUNC_EXIT__;
1995 ProfInfo->profile_type = NET_DEVICE_BLUETOOTH;
1996 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1997 g_strlcpy(ProfInfo->ProfileInfo.Bluetooth.net_info.ProfileName,
1998 ProfileName, NET_PROFILE_NAME_LEN_MAX);
2000 Error = __net_extract_bluetooth_info(iter, ProfInfo);
2001 } else if (profileType == NET_DEVICE_MESH) {
2002 if ((Error = __net_pm_init_profile_info(NET_DEVICE_MESH, ProfInfo)) !=
2004 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
2005 __NETWORK_FUNC_EXIT__;
2009 ProfInfo->profile_type = NET_DEVICE_MESH;
2010 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
2011 g_strlcpy(ProfInfo->ProfileInfo.Mesh.net_info.ProfileName,
2012 ProfileName, NET_PROFILE_NAME_LEN_MAX);
2014 Error = __net_extract_mesh_info(iter, ProfInfo);
2016 NETWORK_LOG(NETWORK_ERROR, "Not supported profile type");
2017 __NETWORK_FUNC_EXIT__;
2018 return NET_ERR_NOT_SUPPORTED;
2021 if (Error != NET_ERR_NONE) {
2022 NETWORK_LOG(NETWORK_ERROR,
2023 "Failed to extract service information from received message");
2025 __NETWORK_FUNC_EXIT__;
2029 __NETWORK_FUNC_EXIT__;
2033 static int __net_get_profile_info(network_info_t *network_info,
2034 const char *ProfileName, net_profile_info_t *ProfInfo)
2036 __NETWORK_FUNC_ENTER__;
2038 net_err_t Error = NET_ERR_NONE;
2039 GVariant *message = NULL;
2040 GVariantIter *iter = NULL;
2041 GVariantIter *service = NULL;
2043 gboolean services_found = FALSE;
2045 message = _net_invoke_dbus_method(network_info,
2046 CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
2047 CONNMAN_MANAGER_INTERFACE, "GetServices", NULL,
2049 if (message == NULL) {
2050 NETWORK_LOG(NETWORK_ERROR, "Failed to get profile");
2054 g_variant_get(message, "(a(oa{sv}))", &iter);
2055 while (g_variant_iter_loop(iter, "(oa{sv})", &path, &service)) {
2056 if (g_strcmp0(ProfileName, path) == 0) {
2057 Error = __net_extract_service_info(network_info,
2058 ProfileName, service, ProfInfo);
2059 g_variant_iter_free(service);
2061 services_found = TRUE;
2065 g_variant_iter_free(iter);
2066 g_variant_unref(message);
2068 /* Check if mesh profile exists */
2069 if (!services_found) {
2070 message = _net_invoke_dbus_method(network_info,
2071 CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
2072 CONNMAN_MANAGER_INTERFACE, "GetMeshPeers", NULL, &Error);
2073 if (message == NULL) {
2074 NETWORK_LOG(NETWORK_ERROR, "Failed to get mesh peers");
2077 g_variant_get(message, "(a(oa{sv}))", &iter);
2078 while (g_variant_iter_loop(iter, "(oa{sv})", &path, &service)) {
2079 if (g_strcmp0(ProfileName, path) == 0) {
2080 Error = __net_extract_service_info(network_info,
2081 ProfileName, service, ProfInfo);
2082 g_variant_iter_free(service);
2088 g_variant_iter_free(iter);
2089 g_variant_unref(message);
2093 __NETWORK_FUNC_EXIT__;
2097 static int __net_set_default_cellular_service_profile_sync(network_info_t *network_info,
2098 const char *ProfileName)
2100 __NETWORK_FUNC_ENTER__;
2102 net_err_t Error = NET_ERR_NONE;
2103 GVariant *message = NULL;
2104 net_profile_name_t telephony_profile;
2105 char connman_profile[NET_PROFILE_NAME_LEN_MAX+1] = "";
2107 g_strlcpy(connman_profile, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
2109 Error = __net_telephony_search_pdp_profile(network_info, connman_profile, &telephony_profile);
2110 if (Error != NET_ERR_NONE) {
2111 NETWORK_LOG(NETWORK_ERROR, "__net_telephony_search_pdp_profile() failed");
2112 __NETWORK_FUNC_EXIT__;
2116 message = _net_invoke_dbus_method(network_info,
2117 TELEPHONY_SERVICE, telephony_profile.ProfileName,
2118 TELEPHONY_PROFILE_INTERFACE, "SetDefaultConnection", NULL, &Error);
2119 if (message == NULL) {
2120 NETWORK_LOG(NETWORK_ERROR, "Failed to set default cellular service(profile)");
2125 gboolean result = FALSE;
2127 g_variant_get(message, "(b)", &result);
2128 NETWORK_LOG(NETWORK_HIGH, "Set default cellular profile result: %d", result);
2131 Error = NET_ERR_NONE;
2133 Error = NET_ERR_UNKNOWN;
2135 g_variant_unref(message);
2138 __NETWORK_FUNC_EXIT__;
2143 static int __net_set_default_cellular_service_profile_async(network_info_t *network_info,
2144 const char *ProfileName)
2146 __NETWORK_FUNC_ENTER__;
2148 net_err_t Error = NET_ERR_NONE;
2149 net_profile_name_t telephony_profile;
2150 char connman_profile[NET_PROFILE_NAME_LEN_MAX+1] = {0,};
2152 g_strlcpy(connman_profile, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
2154 Error = __net_telephony_search_pdp_profile(network_info, connman_profile, &telephony_profile);
2155 if (Error != NET_ERR_NONE) {
2156 NETWORK_LOG(NETWORK_ERROR, "__net_telephony_search_pdp_profile() failed");
2157 __NETWORK_FUNC_EXIT__;
2161 Error = _net_dbus_set_default(network_info, telephony_profile.ProfileName);
2163 __NETWORK_FUNC_EXIT__;
2167 static int __compare_and_set_passphrase(network_info_t *network_info,
2168 wlan_security_info_t *ex_security_info, wlan_security_info_t *security_info,
2169 const char *ProfileName)
2171 net_err_t Error = NET_ERR_NONE;
2172 if (ex_security_info->sec_mode == WLAN_SEC_MODE_WEP) {
2173 if (g_strcmp0(security_info->authentication.wep.wepKey,
2174 ex_security_info->authentication.wep.wepKey) != 0) {
2175 /* ConnMan does not support modification of passphrase only,
2176 * you need to make a connection to update passphrase.
2178 Error = _net_dbus_set_agent_passphrase_and_connect(network_info,
2179 security_info->authentication.wep.wepKey, ProfileName);
2181 } else if (ex_security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
2182 ex_security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) {
2183 if (g_strcmp0(security_info->authentication.psk.pskKey,
2184 ex_security_info->authentication.psk.pskKey) != 0) {
2185 /* ConnMan does not support modification of passphrase only,
2186 * you need to make a connection to update passphrase.
2188 Error = _net_dbus_set_agent_passphrase_and_connect(network_info,
2189 security_info->authentication.psk.pskKey, ProfileName);
2191 } else if (ex_security_info->sec_mode == WLAN_SEC_MODE_SAE) {
2192 if (g_strcmp0(security_info->authentication.sae.saeKey,
2193 ex_security_info->authentication.sae.saeKey) != 0) {
2194 /* ConnMan does not support modification of passphrase only,
2195 * you need to make a connection to update passphrase.
2197 Error = _net_dbus_set_agent_passphrase_and_connect(network_info,
2198 security_info->authentication.sae.saeKey, ProfileName);
2205 static int __compare_and_set_proxy(network_info_t *network_info,
2206 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2207 net_profile_info_t *ProfInfo, char *profilePath)
2209 net_err_t Error = NET_ERR_NONE;
2210 if ((ex_net_info->ProxyMethod != net_info->ProxyMethod) ||
2211 (g_strcmp0(ex_net_info->ProxyAddr, net_info->ProxyAddr) != 0)) {
2212 Error = _net_dbus_set_proxy(network_info, ProfInfo, profilePath);
2217 static int __compare_and_set_ipv4_addresses(network_info_t *network_info,
2218 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2219 net_profile_info_t *ProfInfo, char *profilePath)
2221 net_err_t Error = NET_ERR_NONE;
2222 if ((ex_net_info->IpConfigType != net_info->IpConfigType) ||
2223 (net_info->IpConfigType == NET_IP_CONFIG_TYPE_STATIC &&
2224 (net_info->IpAddr.Data.Ipv4.s_addr !=
2225 ex_net_info->IpAddr.Data.Ipv4.s_addr ||
2226 net_info->SubnetMask.Data.Ipv4.s_addr !=
2227 ex_net_info->SubnetMask.Data.Ipv4.s_addr ||
2228 net_info->GatewayAddr.Data.Ipv4.s_addr !=
2229 ex_net_info->GatewayAddr.Data.Ipv4.s_addr))) {
2230 Error = _net_dbus_set_profile_ipv4(network_info, ProfInfo, profilePath);
2235 static int __compare_and_set_ipv6_addresses(network_info_t *network_info,
2236 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2237 net_profile_info_t *ProfInfo, char *profilePath)
2239 net_err_t Error = NET_ERR_NONE;
2240 if ((ex_net_info->IpConfigType6 != net_info->IpConfigType6) ||
2241 (net_info->IpConfigType6 == NET_IP_CONFIG_TYPE_STATIC &&
2242 (net_info->IpAddr6.Data.Ipv6.s6_addr != ex_net_info->IpAddr6.Data.Ipv6.s6_addr ||
2243 net_info->PrefixLen6 != ex_net_info->PrefixLen6 ||
2244 net_info->GatewayAddr6.Data.Ipv6.s6_addr != ex_net_info->GatewayAddr6.Data.Ipv6.s6_addr))) {
2246 Error = _net_dbus_set_profile_ipv6(network_info, ProfInfo, profilePath);
2252 static int __compare_and_set_dns_addresses(network_info_t *network_info,
2253 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2254 net_profile_info_t *ProfInfo, char *profilePath)
2256 net_err_t Error = NET_ERR_NONE;
2258 for (i = 0; i < net_info->DnsCount; i++) {
2259 if (i >= NET_DNS_ADDR_MAX) {
2260 net_info->DnsCount = NET_DNS_ADDR_MAX;
2265 if (net_info->DnsAddr[i].Data.Ipv4.s_addr !=
2266 ex_net_info->DnsAddr[i].Data.Ipv4.s_addr)
2270 if (i < net_info->DnsCount || ex_net_info->DnsConfigType != net_info->DnsConfigType)
2271 Error = _net_dbus_set_profile_dns(network_info, ProfInfo, profilePath);
2276 static int __compare_and_set_dns6_addresses(network_info_t *network_info,
2277 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2278 net_profile_info_t *ProfInfo, char *profilePath)
2280 net_err_t Error = NET_ERR_NONE;
2282 for (i = 0; i < net_info->DnsCount6; i++) {
2283 if (i >= NET_DNS_ADDR_MAX) {
2284 net_info->DnsCount = NET_DNS_ADDR_MAX;
2288 if (net_info->DnsAddr6[i].Type == NET_ADDR_IPV6) {
2289 if (net_info->DnsAddr6[i].Data.Ipv6.s6_addr !=
2290 ex_net_info->DnsAddr6[i].Data.Ipv6.s6_addr)
2295 if (i < net_info->DnsCount6 || ex_net_info->DnsConfigType6 != net_info->DnsConfigType6)
2296 Error = _net_dbus_set_profile_dns(network_info, ProfInfo, profilePath);
2301 static int __net_modify_wlan_profile_info(network_info_t *network_info,
2302 const char *ProfileName, net_profile_info_t *ProfInfo, net_profile_info_t *exProfInfo)
2304 __NETWORK_FUNC_ENTER__;
2306 net_err_t Error = NET_ERR_NONE;
2307 char profilePath[NET_PROFILE_NAME_LEN_MAX+1] = "";
2309 wlan_security_info_t *security_info =
2310 &(ProfInfo->ProfileInfo.Wlan.security_info);
2311 wlan_security_info_t *ex_security_info =
2312 &(exProfInfo->ProfileInfo.Wlan.security_info);
2314 net_dev_info_t *net_info = &(ProfInfo->ProfileInfo.Wlan.net_info);
2315 net_dev_info_t *ex_net_info = &(exProfInfo->ProfileInfo.Wlan.net_info);
2317 g_strlcpy(profilePath, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
2319 Error = __compare_and_set_passphrase(network_info, ex_security_info, security_info, ProfileName);
2320 if (Error != NET_ERR_NONE) {
2321 NETWORK_LOG(NETWORK_ERROR, "Failed to set agent field");
2322 __NETWORK_FUNC_EXIT__;
2326 Error = __compare_and_set_proxy(network_info, ex_net_info, net_info, ProfInfo, profilePath);
2327 if (Error != NET_ERR_NONE) {
2328 NETWORK_LOG(NETWORK_ERROR, "Failed to set proxy");
2329 __NETWORK_FUNC_EXIT__;
2333 Error = __compare_and_set_ipv4_addresses(network_info, ex_net_info, net_info, ProfInfo, profilePath);
2334 if (Error != NET_ERR_NONE) {
2335 NETWORK_LOG(NETWORK_ERROR, "Failed to set IPv4");
2336 __NETWORK_FUNC_EXIT__;
2340 Error = __compare_and_set_ipv6_addresses(network_info, ex_net_info, net_info, ProfInfo, profilePath);
2341 if (Error != NET_ERR_NONE) {
2342 NETWORK_LOG(NETWORK_ERROR, "Error!!! Can't set IPv6\n");
2343 __NETWORK_FUNC_EXIT__;
2347 Error = __compare_and_set_dns_addresses(network_info, ex_net_info, net_info, ProfInfo, profilePath);
2348 if (Error != NET_ERR_NONE) {
2349 NETWORK_LOG(NETWORK_ERROR, "Failed to set DNS\n");
2350 __NETWORK_FUNC_EXIT__;
2354 Error = __compare_and_set_dns6_addresses(network_info, ex_net_info, net_info, ProfInfo, profilePath);
2355 if (Error != NET_ERR_NONE) {
2356 NETWORK_LOG(NETWORK_ERROR, "Failed to set DNS6\n");
2357 __NETWORK_FUNC_EXIT__;
2361 __NETWORK_FUNC_EXIT__;
2362 return NET_ERR_NONE;
2365 static int __net_wifi_delete_profile(network_info_t *network_info,
2366 net_profile_name_t *WifiProfName, wlan_security_mode_type_t sec_mode, gboolean passpoint)
2368 __NETWORK_FUNC_ENTER__;
2370 net_err_t Error = NET_ERR_NONE;
2371 GVariant *message = NULL;
2372 char param0[NET_PROFILE_NAME_LEN_MAX + 8] = "";
2375 if (passpoint == TRUE && WLAN_SEC_MODE_IEEE8021X == sec_mode) {
2376 message = _net_invoke_dbus_method(network_info,
2378 WifiProfName->ProfileName,
2379 CONNMAN_SERVICE_INTERFACE, "Remove", NULL,
2382 if (message == NULL) {
2383 NETWORK_LOG(NETWORK_ERROR, "Failed to Remove service(profile)");
2384 g_variant_unref(message);
2388 g_variant_unref(message);
2390 g_snprintf(param0, NET_PROFILE_NAME_LEN_MAX + 8, "string:%s",
2391 WifiProfName->ProfileName);
2392 params = g_variant_new("(s)", param0);
2394 message = _net_invoke_dbus_method(network_info,
2396 NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE,
2397 "DeleteEapConfig", params, &Error);
2398 } else if (passpoint == TRUE || WLAN_SEC_MODE_IEEE8021X != sec_mode) {
2399 message = _net_invoke_dbus_method(network_info,
2401 WifiProfName->ProfileName,
2402 CONNMAN_SERVICE_INTERFACE, "Remove", NULL,
2405 g_snprintf(param0, NET_PROFILE_NAME_LEN_MAX + 8, "string:%s",
2406 WifiProfName->ProfileName);
2407 params = g_variant_new("(s)", param0);
2409 message = _net_invoke_dbus_method(network_info,
2411 NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE,
2412 "DeleteEapConfig", params, &Error);
2415 if (message == NULL) {
2416 NETWORK_LOG(NETWORK_ERROR, "Failed to Remove service(profile)");
2420 g_variant_unref(message);
2422 __NETWORK_FUNC_EXIT__;
2426 static int __net_modify_mesh_profile(network_info_t *network_info,
2427 const char *ProfileName, net_profile_info_t *ProfInfo, net_profile_info_t *exProfInfo)
2429 __NETWORK_FUNC_ENTER__;
2431 net_err_t Error = NET_ERR_NONE;
2432 char profilePath[NET_PROFILE_NAME_LEN_MAX+1] = "";
2434 wlan_security_info_t *security_info =
2435 &(ProfInfo->ProfileInfo.Mesh.security_info);
2436 wlan_security_info_t *ex_security_info =
2437 &(exProfInfo->ProfileInfo.Mesh.security_info);
2439 g_strlcpy(profilePath, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
2441 /* Compare and Set 'Passphrase' */
2442 if (ex_security_info->sec_mode == WLAN_SEC_MODE_SAE) {
2443 if (g_strcmp0(security_info->authentication.sae.saeKey,
2444 ex_security_info->authentication.sae.saeKey) != 0) {
2445 /* ConnMan does not support modification of passphrase only,
2446 * you need to make a connection to update passphrase.
2448 Error = _net_dbus_set_mesh_property(network_info,
2449 profilePath, "Passphrase",
2450 security_info->authentication.sae.saeKey);
2452 if (NET_ERR_NONE != Error) {
2453 NETWORK_LOG(NETWORK_ERROR, "Failed to set Mesh property");
2455 __NETWORK_FUNC_EXIT__;
2461 __NETWORK_FUNC_EXIT__;
2462 return NET_ERR_NONE;
2465 static int __net_mesh_delete_profile(network_info_t *network_info, const char *profile_name)
2467 __NETWORK_FUNC_ENTER__;
2469 net_err_t Error = NET_ERR_NONE;
2470 GVariant *message = NULL;
2472 message = _net_invoke_dbus_method(network_info,
2473 CONNMAN_SERVICE, profile_name,
2474 CONNMAN_MESH_INTERFACE, "Remove", NULL, &Error);
2475 if (message == NULL) {
2476 NETWORK_LOG(NETWORK_ERROR, "Failed to Remove mesh(profile)");
2480 g_variant_unref(message);
2483 __NETWORK_FUNC_EXIT__;
2487 static int __net_telephony_add_profile(network_info_t *network_info,
2488 net_profile_info_t *ProfInfo, net_service_type_t network_type)
2490 __NETWORK_FUNC_ENTER__;
2492 net_err_t Error = NET_ERR_NONE;
2494 ProfInfo->ProfileInfo.Pdp.ServiceType = network_type;
2496 Error = _net_dbus_add_pdp_profile(network_info, ProfInfo);
2497 if (Error != NET_ERR_NONE) {
2498 NETWORK_LOG(NETWORK_ERROR, "_net_dbus_add_pdp_profile() failed");
2499 __NETWORK_FUNC_EXIT__;
2503 __NETWORK_FUNC_EXIT__;
2504 return NET_ERR_NONE;
2507 static int __net_telephony_modify_profile(network_info_t *network_info,
2508 const char *ProfileName, net_profile_info_t *ProfInfo, net_profile_info_t *exProfInfo)
2510 __NETWORK_FUNC_ENTER__;
2512 net_err_t Error = NET_ERR_NONE;
2513 net_profile_name_t telephony_profile;
2514 char connman_profile[NET_PROFILE_NAME_LEN_MAX+1] = "";
2516 if (_net_is_valid_service_type(exProfInfo->ProfileInfo.Pdp.ServiceType) == FALSE) {
2517 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
2518 __NETWORK_FUNC_EXIT__;
2519 return NET_ERR_INVALID_PARAM;
2522 g_strlcpy(connman_profile, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
2523 ProfInfo->ProfileInfo.Pdp.ServiceType = exProfInfo->ProfileInfo.Pdp.ServiceType;
2525 Error = __net_telephony_search_pdp_profile(network_info, connman_profile, &telephony_profile);
2526 if (Error != NET_ERR_NONE) {
2527 NETWORK_LOG(NETWORK_ERROR, "__net_telephony_search_pdp_profile() failed");
2528 __NETWORK_FUNC_EXIT__;
2532 Error = _net_dbus_modify_pdp_profile(network_info, ProfInfo, telephony_profile.ProfileName);
2533 if (Error != NET_ERR_NONE) {
2534 NETWORK_LOG(NETWORK_ERROR, "_net_dbus_modify_pdp_profile() failed");
2535 __NETWORK_FUNC_EXIT__;
2539 __NETWORK_FUNC_EXIT__;
2544 static int __net_modify_ethernet_profile(network_info_t *network_info,
2545 const char *ProfileName, net_profile_info_t *ProfInfo, net_profile_info_t *exProfInfo)
2547 __NETWORK_FUNC_ENTER__;
2549 net_err_t Error = NET_ERR_NONE;
2552 char profilePath[NET_PROFILE_NAME_LEN_MAX+1] = "";
2554 net_dev_info_t *net_info = &(ProfInfo->ProfileInfo.Ethernet.net_info);
2555 net_dev_info_t *ex_net_info = &(exProfInfo->ProfileInfo.Ethernet.net_info);
2557 g_strlcpy(profilePath, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
2559 /* Compare and Set 'Proxy' */
2560 NETWORK_LOG(NETWORK_HIGH, "Proxy old:%d %s, new:%d %s\n",
2561 ex_net_info->ProxyMethod,
2562 ex_net_info->ProxyAddr,
2563 net_info->ProxyMethod,
2564 net_info->ProxyAddr);
2566 if ((ex_net_info->ProxyMethod != net_info->ProxyMethod) ||
2567 (g_strcmp0(ex_net_info->ProxyAddr, net_info->ProxyAddr) != 0)) {
2569 Error = _net_dbus_set_proxy(network_info, ProfInfo, profilePath);
2571 if (Error != NET_ERR_NONE) {
2572 __NETWORK_FUNC_EXIT__;
2577 /* Compare and Set 'IPv4 addresses' */
2578 char ip_buffer[NETPM_IPV4_STR_LEN_MAX+1] = "";
2579 char netmask_buffer[NETPM_IPV4_STR_LEN_MAX+1] = "";
2580 char gateway_buffer[NETPM_IPV4_STR_LEN_MAX+1] = "";
2581 g_strlcpy(ip_buffer,
2582 inet_ntoa(ex_net_info->IpAddr.Data.Ipv4),
2583 NETPM_IPV4_STR_LEN_MAX + 1);
2585 g_strlcpy(netmask_buffer,
2586 inet_ntoa(ex_net_info->SubnetMask.Data.Ipv4),
2587 NETPM_IPV4_STR_LEN_MAX + 1);
2589 g_strlcpy(gateway_buffer,
2590 inet_ntoa(ex_net_info->GatewayAddr.Data.Ipv4),
2591 NETPM_IPV4_STR_LEN_MAX + 1);
2593 NETWORK_LOG(NETWORK_HIGH, "IPv4 info old: type %d, IP: %s, netmask:"
2594 " %s, gateway: %s\n", ex_net_info->IpConfigType,
2599 g_strlcpy(ip_buffer,
2600 inet_ntoa(net_info->IpAddr.Data.Ipv4),
2601 NETPM_IPV4_STR_LEN_MAX + 1);
2603 g_strlcpy(netmask_buffer,
2604 inet_ntoa(net_info->SubnetMask.Data.Ipv4),
2605 NETPM_IPV4_STR_LEN_MAX + 1);
2607 g_strlcpy(gateway_buffer,
2608 inet_ntoa(net_info->GatewayAddr.Data.Ipv4),
2609 NETPM_IPV4_STR_LEN_MAX + 1);
2611 NETWORK_LOG(NETWORK_HIGH, "IPv4 info new: type %d, IP: %s, netmask:"
2612 " %s, gateway: %s\n", net_info->IpConfigType,
2617 if ((ex_net_info->IpConfigType != net_info->IpConfigType) ||
2618 (net_info->IpConfigType == NET_IP_CONFIG_TYPE_STATIC &&
2619 (net_info->IpAddr.Data.Ipv4.s_addr
2620 != ex_net_info->IpAddr.Data.Ipv4.s_addr ||
2621 net_info->SubnetMask.Data.Ipv4.s_addr
2622 != ex_net_info->SubnetMask.Data.Ipv4.s_addr ||
2623 net_info->GatewayAddr.Data.Ipv4.s_addr
2624 != ex_net_info->GatewayAddr.Data.Ipv4.s_addr))) {
2625 Error = _net_dbus_set_profile_ipv4(network_info, ProfInfo, profilePath);
2627 if (Error != NET_ERR_NONE) {
2628 NETWORK_LOG(NETWORK_ERROR, "Failed to set IPv4");
2630 __NETWORK_FUNC_EXIT__;
2634 /* Compare and Set 'DNS addresses' */
2635 for (i = 0; i < net_info->DnsCount; i++) {
2636 if (i >= NET_DNS_ADDR_MAX) {
2637 net_info->DnsCount = NET_DNS_ADDR_MAX;
2641 if (net_info->DnsAddr[i].Type == NET_ADDR_IPV4) {
2642 char old_dns[NETPM_IPV4_STR_LEN_MAX+1] = "";
2643 char new_dns[NETPM_IPV4_STR_LEN_MAX+1] = "";
2645 inet_ntoa(ex_net_info->DnsAddr[i].Data.Ipv4),
2646 NETPM_IPV4_STR_LEN_MAX+1);
2648 inet_ntoa(net_info->DnsAddr[i].Data.Ipv4),
2649 NETPM_IPV4_STR_LEN_MAX+1);
2651 NETWORK_LOG(NETWORK_HIGH, "IPv4 DNS Addr order: %d, old:"
2652 "%s, new: %s", i, old_dns, new_dns);
2654 if (net_info->DnsAddr[i].Data.Ipv4.s_addr !=
2655 ex_net_info->DnsAddr[i].Data.Ipv4.s_addr)
2661 char ipaddr6_old[INET6_ADDRSTRLEN];
2662 char ipaddr6_new[INET6_ADDRSTRLEN];
2664 for (j = 0; j < net_info->DnsCount6; j++) {
2665 if (j >= NET_DNS_ADDR_MAX) {
2666 net_info->DnsCount6 = NET_DNS_ADDR_MAX;
2671 if (net_info->DnsAddr6[j].Type == NET_ADDR_IPV6) {
2672 inet_ntop(AF_INET6, &ex_net_info->DnsAddr6[j].Data.Ipv6,
2673 ipaddr6_old, INET6_ADDRSTRLEN);
2674 inet_ntop(AF_INET6, &net_info->DnsAddr6[j].Data.Ipv6,
2675 ipaddr6_new, INET6_ADDRSTRLEN);
2676 NETWORK_LOG(NETWORK_HIGH, "IPv6 DNS Addr order: %d, "
2677 "old: %s, new: %s", j, ipaddr6_old,
2680 if (net_info->DnsAddr6[j].Data.Ipv6.s6_addr !=
2681 ex_net_info->DnsAddr6[j].Data.Ipv6.s6_addr)
2686 if (i < net_info->DnsCount || j < net_info->DnsCount6 ||
2687 ex_net_info->DnsConfigType != net_info->DnsConfigType ||
2688 ex_net_info->DnsConfigType6 != net_info->DnsConfigType6) {
2689 Error = _net_dbus_set_profile_dns(network_info, ProfInfo, profilePath);
2691 if (Error != NET_ERR_NONE) {
2692 NETWORK_LOG(NETWORK_ERROR, "Failed to set DNS");
2694 __NETWORK_FUNC_EXIT__;
2699 __NETWORK_FUNC_EXIT__;
2700 return NET_ERR_NONE;
2703 static int __net_telephony_delete_profile(network_info_t *network_info,
2704 net_profile_name_t *PdpProfName)
2706 __NETWORK_FUNC_ENTER__;
2708 net_err_t Error = NET_ERR_NONE;
2709 GVariant *message = NULL;
2711 message = _net_invoke_dbus_method(network_info,
2712 TELEPHONY_SERVICE, PdpProfName->ProfileName,
2713 TELEPHONY_PROFILE_INTERFACE, "RemoveProfile", NULL, &Error);
2714 if (message == NULL) {
2715 NETWORK_LOG(NETWORK_ERROR, "Failed to Remove service(profile)");
2720 gboolean remove_result = FALSE;
2722 g_variant_get(message, "(b)", &remove_result);
2723 NETWORK_LOG(NETWORK_HIGH, "Profile remove result: %d", remove_result);
2726 Error = NET_ERR_NONE;
2728 Error = NET_ERR_UNKNOWN;
2730 g_variant_unref(message);
2733 __NETWORK_FUNC_EXIT__;
2737 static gboolean __net_is_cellular_default_candidate(const char *profile)
2739 /* This profile should be cellular type */
2740 const char net_suffix[] = "_1";
2741 const char pre_net_suffix[] = "_3";
2742 const char tethering_suffix[] = "_5";
2745 suffix = strrchr(profile, '_');
2747 if (g_strcmp0(suffix, net_suffix) == 0 ||
2748 g_strcmp0(suffix, pre_net_suffix) == 0 ||
2749 g_strcmp0(suffix, tethering_suffix) == 0)
2755 static int __net_extract_default_profile(network_info_t *network_info,
2756 GVariantIter *array, net_profile_info_t *ProfilePtr)
2758 net_err_t Error = NET_ERR_NONE;
2759 net_device_t device_type;
2761 GVariantIter *value = NULL;
2763 __NETWORK_FUNC_ENTER__;
2765 if (array == NULL || ProfilePtr == NULL) {
2766 NETWORK_LOG(NETWORK_ERROR, "Invalid parameter");
2767 __NETWORK_FUNC_EXIT__;
2768 return NET_ERR_INVALID_PARAM;
2771 while (g_variant_iter_loop(array, "(oa{sv})", &key, &value)) {
2772 if (g_str_has_prefix(key, CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX) == TRUE)
2773 device_type = NET_DEVICE_CELLULAR;
2774 else if (g_str_has_prefix(key, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) == TRUE)
2775 device_type = NET_DEVICE_WIFI;
2776 else if (g_str_has_prefix(key, CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX) == TRUE)
2777 device_type = NET_DEVICE_ETHERNET;
2778 else if (g_str_has_prefix(key, CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX) == TRUE)
2779 device_type = NET_DEVICE_BLUETOOTH;
2780 else if (g_str_has_prefix(key, CONNMAN_MESH_PROFILE_PREFIX) == TRUE)
2781 device_type = NET_DEVICE_MESH;
2783 Error = NET_ERR_NO_SERVICE;
2787 Error = __net_pm_init_profile_info(device_type, ProfilePtr);
2788 if (Error != NET_ERR_NONE) {
2789 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
2793 ProfilePtr->profile_type = device_type;
2794 g_strlcpy(ProfilePtr->ProfileName, key, NET_PROFILE_NAME_LEN_MAX);
2796 if (device_type == NET_DEVICE_CELLULAR &&
2797 __net_is_cellular_default_candidate(key) == TRUE) {
2798 g_strlcpy(ProfilePtr->ProfileInfo.Pdp.net_info.ProfileName,
2799 key, NET_PROFILE_NAME_LEN_MAX);
2801 Error = __net_extract_mobile_info(network_info, value, ProfilePtr);
2803 } else if (device_type == NET_DEVICE_WIFI) {
2804 g_strlcpy(ProfilePtr->ProfileInfo.Wlan.net_info.ProfileName,
2805 key, NET_PROFILE_NAME_LEN_MAX);
2807 Error = __net_extract_wifi_info(value, ProfilePtr);
2809 } else if (device_type == NET_DEVICE_ETHERNET) {
2810 g_strlcpy(ProfilePtr->ProfileInfo.Ethernet.net_info.ProfileName,
2811 key, NET_PROFILE_NAME_LEN_MAX);
2813 Error = __net_extract_ethernet_info(value, ProfilePtr);
2815 } else if (device_type == NET_DEVICE_BLUETOOTH) {
2816 g_strlcpy(ProfilePtr->ProfileInfo.Bluetooth.net_info.ProfileName,
2817 key, NET_PROFILE_NAME_LEN_MAX);
2819 Error = __net_extract_bluetooth_info(value, ProfilePtr);
2821 } else if (device_type == NET_DEVICE_MESH) {
2822 g_strlcpy(ProfilePtr->ProfileInfo.Mesh.net_info.ProfileName,
2823 key, NET_PROFILE_NAME_LEN_MAX);
2825 Error = __net_extract_mesh_info(value, ProfilePtr);
2826 if (ProfilePtr->ProfileState == NET_STATE_TYPE_READY)
2831 if (Error == NET_ERR_NONE &&
2832 (ProfilePtr->ProfileState == NET_STATE_TYPE_READY ||
2833 ProfilePtr->ProfileState == NET_STATE_TYPE_ONLINE))
2836 NETWORK_LOG(NETWORK_ERROR, "Fail to find default service");
2837 Error = NET_ERR_NO_SERVICE;
2841 g_variant_iter_free(value);
2845 __NETWORK_FUNC_EXIT__;
2849 NETWORK_LOG(NETWORK_HIGH, "Default: %s", ProfilePtr->ProfileName);
2852 g_variant_iter_free(value);
2856 __NETWORK_FUNC_EXIT__;
2859 /* LCOV_EXCL_STOP */
2861 int _net_check_profile_name(const char *ProfileName)
2863 __NETWORK_FUNC_ENTER__;
2865 const char *profileHeader = CONNMAN_PATH"/service/";
2866 const char *meshProfileHeader = CONNMAN_PATH"/mesh/";
2870 if (ProfileName == NULL || strlen(ProfileName) <= strlen(profileHeader)) {
2871 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid");
2872 __NETWORK_FUNC_EXIT__;
2873 return NET_ERR_INVALID_PARAM;
2876 stringLen = strlen(ProfileName);
2878 if (strncmp(profileHeader, ProfileName, strlen(profileHeader)) == 0) {
2879 for (i = 0; i < stringLen; i++) {
2880 /* LCOV_EXCL_START */
2881 if (isgraph(ProfileName[i]) == 0) {
2882 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid");
2883 __NETWORK_FUNC_EXIT__;
2884 return NET_ERR_INVALID_PARAM;
2887 } else if (strncmp(meshProfileHeader, ProfileName,
2888 strlen(meshProfileHeader)) == 0) {
2889 for (i = 0; i < stringLen; i++) {
2890 if (isgraph(ProfileName[i]) == 0) {
2891 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid");
2892 __NETWORK_FUNC_EXIT__;
2893 return NET_ERR_INVALID_PARAM;
2897 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid");
2898 __NETWORK_FUNC_EXIT__;
2899 return NET_ERR_INVALID_PARAM;
2901 /* LCOV_EXCL_STOP */
2903 __NETWORK_FUNC_EXIT__;
2904 return NET_ERR_NONE;
2907 int _net_get_profile_list(network_info_t *network_info, net_device_t device_type,
2908 net_profile_info_t **profile_info, int *profile_count)
2910 __NETWORK_FUNC_ENTER__;
2912 net_err_t Error = NET_ERR_NONE;
2916 if (device_type == NET_DEVICE_MESH) {
2917 /* LCOV_EXCL_START */
2918 net_cm_network_status_t status = NET_STATUS_UNKNOWN;
2920 net_get_network_status(network_info, device_type, &status);
2921 if (status != NET_STATUS_AVAILABLE)
2922 return NET_ERR_NONE;
2924 message = _net_invoke_dbus_method(network_info, CONNMAN_SERVICE,
2925 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
2926 "GetMeshPeers", NULL, &Error);
2927 if (message == NULL) {
2928 NETWORK_LOG(NETWORK_ERROR, "Failed to get Mesh Peers list");
2929 __NETWORK_FUNC_EXIT__;
2932 /* LCOV_EXCL_STOP */
2934 message = _net_invoke_dbus_method(network_info, CONNMAN_SERVICE,
2935 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
2936 "GetServices", NULL, &Error);
2937 /* LCOV_EXCL_START */
2938 if (message == NULL) {
2939 NETWORK_LOG(NETWORK_ERROR, "Failed to get service(profile) list");
2940 __NETWORK_FUNC_EXIT__;
2943 /* LCOV_EXCL_STOP */
2946 switch (device_type) {
2947 case NET_DEVICE_CELLULAR:
2948 case NET_DEVICE_WIFI:
2949 case NET_DEVICE_ETHERNET:
2950 case NET_DEVICE_BLUETOOTH:
2951 case NET_DEVICE_MESH:
2952 g_variant_get(message, "(a(oa{sv}))", &iter);
2953 Error = __net_extract_services(network_info, iter,
2954 device_type, profile_info, profile_count);
2957 g_variant_iter_free(iter);
2961 /* LCOV_EXCL_START */
2962 Error = NET_ERR_UNKNOWN;
2964 /* LCOV_EXCL_STOP */
2967 g_variant_unref(message);
2969 __NETWORK_FUNC_EXIT__;
2973 int _net_extract_services(network_info_t *network_info, net_device_t device_type,
2974 net_profile_info_t **profile_info, int *profile_count, GVariant *message)
2976 net_err_t Error = NET_ERR_NONE;
2979 g_variant_get(message, "(a(oa{sv}))", &iter);
2981 Error = __net_extract_services(network_info, iter,
2982 device_type, profile_info, profile_count);
2985 g_variant_iter_free(iter);
2990 int _net_get_all_profile_list(network_info_t *network_info,
2991 net_profile_info_t **profile_info, int *profile_count)
2993 __NETWORK_FUNC_ENTER__;
2995 net_err_t Error = NET_ERR_NONE;
2996 GVariant *message = NULL;
2997 GVariant *mesh_message = NULL;
2998 int cellular_cnt = 0;
3000 int ethernet_cnt = 0;
3001 int bluetooth_cnt = 0;
3003 net_profile_info_t *cellular_profiles = NULL;
3004 net_profile_info_t *wifi_profiles = NULL;
3005 net_profile_info_t *ethernet_profiles = NULL;
3006 net_profile_info_t *bluetooth_profiles = NULL;
3007 net_profile_info_t *mesh_profiles = NULL;
3008 net_profile_info_t *profiles = NULL;
3009 net_cm_network_status_t status = NET_STATUS_UNKNOWN;
3011 message = _net_invoke_dbus_method(network_info, CONNMAN_SERVICE,
3012 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
3013 "GetServices", NULL, &Error);
3014 /* LCOV_EXCL_START */
3015 if (message == NULL) {
3016 NETWORK_LOG(NETWORK_ERROR, "Failed to get service(profile) list");
3017 __NETWORK_FUNC_EXIT__;
3020 /* LCOV_EXCL_STOP */
3024 Error = _net_extract_services(network_info, NET_DEVICE_CELLULAR,
3025 &cellular_profiles, &cellular_cnt, message);
3026 if (Error != NET_ERR_NONE)
3029 NETWORK_LOG(NETWORK_LOW, "Cellular profile count: %d", cellular_cnt);
3030 *profile_count += cellular_cnt;
3032 Error = _net_extract_services(network_info, NET_DEVICE_WIFI,
3033 &wifi_profiles, &wifi_cnt, message);
3034 if (Error != NET_ERR_NONE)
3037 NETWORK_LOG(NETWORK_LOW, "Wi-Fi profile count: %d", wifi_cnt);
3038 *profile_count += wifi_cnt;
3040 Error = _net_extract_services(network_info, NET_DEVICE_ETHERNET,
3041 ðernet_profiles, ðernet_cnt, message);
3042 if (Error != NET_ERR_NONE)
3045 NETWORK_LOG(NETWORK_LOW, "Ethernet profile count: %d", ethernet_cnt);
3046 *profile_count += ethernet_cnt;
3048 Error = _net_extract_services(network_info, NET_DEVICE_BLUETOOTH,
3049 &bluetooth_profiles, &bluetooth_cnt, message);
3050 if (Error != NET_ERR_NONE)
3053 NETWORK_LOG(NETWORK_LOW, "Bluetooth profile count: %d", bluetooth_cnt);
3054 *profile_count += bluetooth_cnt;
3056 /* LCOV_EXCL_START */
3057 net_get_network_status(network_info, NET_DEVICE_MESH, &status);
3058 if (status == NET_STATUS_AVAILABLE) {
3059 mesh_message = _net_invoke_dbus_method(network_info, CONNMAN_SERVICE,
3060 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
3061 "GetMeshPeers", NULL, &Error);
3062 if (mesh_message == NULL) {
3063 NETWORK_LOG(NETWORK_ERROR, "Failed to get Mesh Peers list");
3064 NET_MEMFREE(cellular_profiles);
3065 NET_MEMFREE(wifi_profiles);
3066 NET_MEMFREE(ethernet_profiles);
3067 NET_MEMFREE(bluetooth_profiles);
3068 __NETWORK_FUNC_EXIT__;
3072 Error = _net_extract_services(network_info, NET_DEVICE_MESH,
3073 &mesh_profiles, &mesh_cnt, mesh_message);
3074 if (Error != NET_ERR_NONE)
3077 NETWORK_LOG(NETWORK_LOW, "Mesh profile count: %d", mesh_cnt);
3078 *profile_count += mesh_cnt;
3080 /* LCOV_EXCL_STOP */
3082 if (*profile_count > 0) {
3083 profiles = g_try_new0(net_profile_info_t, *profile_count);
3085 *profile_info = profiles;
3086 if (cellular_cnt > 0) {
3087 memcpy(profiles, cellular_profiles,
3088 sizeof(net_profile_info_t) * cellular_cnt);
3089 profiles += cellular_cnt;
3093 memcpy(profiles, wifi_profiles,
3094 sizeof(net_profile_info_t) * wifi_cnt);
3095 profiles += wifi_cnt;
3098 if (ethernet_cnt > 0) {
3099 memcpy(profiles, ethernet_profiles,
3100 sizeof(net_profile_info_t) * ethernet_cnt);
3101 profiles += ethernet_cnt;
3104 if (bluetooth_cnt > 0) {
3105 memcpy(profiles, bluetooth_profiles,
3106 sizeof(net_profile_info_t) * bluetooth_cnt);
3107 profiles += bluetooth_cnt;
3111 memcpy(profiles, mesh_profiles,
3112 sizeof(net_profile_info_t) * mesh_cnt);
3118 if (message != NULL)
3119 g_variant_unref(message);
3121 if (mesh_message != NULL)
3122 g_variant_unref(mesh_message);
3124 NET_MEMFREE(cellular_profiles);
3125 NET_MEMFREE(wifi_profiles);
3126 NET_MEMFREE(ethernet_profiles);
3127 NET_MEMFREE(bluetooth_profiles);
3128 NET_MEMFREE(mesh_profiles);
3130 __NETWORK_FUNC_EXIT__;
3134 /* LCOV_EXCL_START */
3135 int _net_get_default_profile_info(network_info_t *network_info,
3136 net_profile_info_t *profile_info)
3138 net_err_t Error = NET_ERR_NONE;
3139 GVariant *message = NULL;
3140 GVariantIter *iter = NULL;
3142 __NETWORK_FUNC_ENTER__;
3144 message = _net_invoke_dbus_method(network_info,
3145 CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
3146 CONNMAN_MANAGER_INTERFACE, "GetServices", NULL, &Error);
3147 if (message == NULL) {
3148 NETWORK_LOG(NETWORK_ERROR, "Failed to get profile list");
3149 __NETWORK_FUNC_EXIT__;
3153 g_variant_get(message, "(a(oa{sv}))", &iter);
3154 Error = __net_extract_default_profile(network_info, iter, profile_info);
3156 g_variant_iter_free(iter);
3157 g_variant_unref(message);
3159 if (Error == NET_ERR_NO_SERVICE) {
3160 message = _net_invoke_dbus_method(network_info,
3161 CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
3162 CONNMAN_MANAGER_INTERFACE, "GetMeshPeers", NULL, &Error);
3163 if (message == NULL) {
3164 NETWORK_LOG(NETWORK_ERROR, "Failed to get mesh peers");
3165 Error = NET_ERR_NO_SERVICE;
3166 __NETWORK_FUNC_EXIT__;
3170 g_variant_get(message, "(a(oa{sv}))", &iter);
3171 Error = __net_extract_default_profile(network_info, iter, profile_info);
3173 g_variant_iter_free(iter);
3174 g_variant_unref(message);
3177 __NETWORK_FUNC_EXIT__;
3181 static int __net_telephony_reset_profile(network_info_t *network_info, int type, int sim_id)
3183 __NETWORK_FUNC_ENTER__;
3185 net_err_t Error = NET_ERR_NONE;
3186 char subscriber_id[3];
3188 GSList *ModemPathList = NULL;
3189 const char *path = NULL;
3190 GSList *list = NULL;
3192 Error = __net_telephony_get_modem_object_path(network_info, &ModemPathList);
3193 if (Error != NET_ERR_NONE) {
3194 NETWORK_LOG(NETWORK_ERROR, "Failed to get modems path list");
3195 g_slist_free_full(ModemPathList, g_free);
3196 __NETWORK_FUNC_EXIT__;
3200 g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", sim_id);
3202 for (list = ModemPathList; list != NULL; list = list->next) {
3203 path = (const char *)list->data;
3205 if (g_str_has_suffix(path, subscriber_id) == TRUE) {
3206 Error = _net_dbus_reset_pdp_profile(network_info, type, path);
3207 if (Error != NET_ERR_NONE) {
3208 NETWORK_LOG(NETWORK_HIGH, "_net_dbus_reset_pdp_profile() failed");
3214 g_slist_free_full(ModemPathList, g_free);
3216 __NETWORK_FUNC_EXIT__;
3217 return NET_ERR_NONE;
3220 static int __net_convert_string_to_ipv6_string(char *str, char **ip_address)
3223 struct sockaddr_in6 sa;
3224 char conv_str[INET6_ADDRSTRLEN] = {0,};
3226 *ip_address = (char *)malloc(INET6_ADDRSTRLEN);
3227 if (NULL == *ip_address) {
3228 NETWORK_LOG(NETWORK_ERROR, "Malloc Failed");
3229 return NET_ERR_INVALID_OPERATION;
3232 /* Convert String without : to string with : */
3233 for (int i = 0; i < 8; i++) {
3236 conv_str[pos + i - 1] = ':';
3237 memcpy(conv_str + pos + i, str + pos, 4);
3241 * Convert "fe80:0000:0000:0000:0a00:27ff:fe7a:65ea to fe80::a00:27ff:fe7a:65ea
3243 inet_pton(AF_INET6, conv_str, &(sa.sin6_addr));
3244 inet_ntop(AF_INET6, &(sa.sin6_addr), *ip_address, INET6_ADDRSTRLEN);
3246 return NET_ERR_NONE;
3250 EXPORT_API int net_reset_profile(void *handle, int type, int sim_id)
3252 net_err_t Error = NET_ERR_NONE;
3253 network_info_t *network_info = (network_info_t *)handle;
3255 __NETWORK_FUNC_ENTER__;
3257 if (network_info->request_table[NETWORK_REQUEST_TYPE_RESET_DEFAULT].flag == TRUE) {
3258 NETWORK_LOG(NETWORK_ERROR, "Error!! Request already in progress");
3259 __NETWORK_FUNC_EXIT__;
3260 return NET_ERR_IN_PROGRESS;
3263 network_info->request_table[NETWORK_REQUEST_TYPE_RESET_DEFAULT].flag = TRUE;
3265 Error = __net_telephony_reset_profile(network_info, type, sim_id);
3266 if (Error != NET_ERR_NONE) {
3267 NETWORK_LOG(NETWORK_ERROR,
3268 "Failed to reset service(profile). Error [%s]",
3269 _net_print_error(Error));
3270 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_RESET_DEFAULT]),
3271 0, sizeof(network_request_table_t));
3272 __NETWORK_FUNC_EXIT__;
3276 __NETWORK_FUNC_EXIT__;
3279 /* LCOV_EXCL_STOP */
3282 /*****************************************************************************
3283 * ConnMan Wi-Fi Client Interface Sync API Definition
3284 *****************************************************************************/
3285 EXPORT_API int net_add_profile(void *handle, net_service_type_t network_type, net_profile_info_t *prof_info)
3287 net_err_t Error = NET_ERR_NONE;
3288 network_info_t *network_info = (network_info_t *)handle;
3290 __NETWORK_FUNC_ENTER__;
3292 if (prof_info == NULL || _net_is_valid_service_type(network_type) == FALSE) {
3293 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3294 __NETWORK_FUNC_EXIT__;
3295 return NET_ERR_INVALID_PARAM;
3298 /* LCOV_EXCL_START */
3299 Error = __net_telephony_add_profile(network_info, prof_info, network_type);
3300 if (Error != NET_ERR_NONE) {
3301 NETWORK_LOG(NETWORK_ERROR, "Failed to add service(profile). Error [%s]",
3302 _net_print_error(Error));
3303 __NETWORK_FUNC_EXIT__;
3306 /* LCOV_EXCL_STOP */
3308 __NETWORK_FUNC_EXIT__;
3312 EXPORT_API int net_delete_profile(void *handle, const char *profile_name)
3314 __NETWORK_FUNC_ENTER__;
3316 net_err_t Error = NET_ERR_NONE;
3317 net_profile_name_t pdp_prof_name;
3318 net_profile_name_t wifi_prof_name;
3319 net_profile_info_t prof_info;
3320 network_info_t *network_info = (network_info_t *)handle;
3322 NETWORK_LOG(NETWORK_HIGH, "Delete Profile [%s]", profile_name);
3324 if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
3325 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3326 __NETWORK_FUNC_EXIT__;
3327 return NET_ERR_INVALID_PARAM;
3330 /* LCOV_EXCL_START */
3331 Error = __net_get_profile_info(network_info, profile_name, &prof_info);
3332 if (Error != NET_ERR_NONE) {
3333 NETWORK_LOG(NETWORK_ERROR,
3334 "Failed to get service(profile) information. Error [%s]",
3335 _net_print_error(Error));
3337 __NETWORK_FUNC_EXIT__;
3341 g_strlcpy(wifi_prof_name.ProfileName, profile_name, NET_PROFILE_NAME_LEN_MAX + 1);
3343 if (prof_info.profile_type == NET_DEVICE_WIFI) {
3344 Error = __net_wifi_delete_profile(network_info, &wifi_prof_name,
3345 prof_info.ProfileInfo.Wlan.security_info.sec_mode,
3346 prof_info.ProfileInfo.Wlan.passpoint);
3347 if (Error != NET_ERR_NONE) {
3348 NETWORK_LOG(NETWORK_ERROR,
3349 "Failed to delete service(profile). Error [%s]",
3350 _net_print_error(Error));
3352 __NETWORK_FUNC_EXIT__;
3355 } else if (prof_info.profile_type == NET_DEVICE_CELLULAR) {
3356 Error = __net_telephony_search_pdp_profile(network_info,
3357 wifi_prof_name.ProfileName, &pdp_prof_name);
3358 if (Error != NET_ERR_NONE) {
3359 NETWORK_LOG(NETWORK_ERROR,
3360 "Failed to get service(profile) information. Error [%s]",
3361 _net_print_error(Error));
3363 __NETWORK_FUNC_EXIT__;
3367 Error = __net_telephony_delete_profile(network_info, &pdp_prof_name);
3368 if (Error != NET_ERR_NONE) {
3369 NETWORK_LOG(NETWORK_ERROR,
3370 "Failed to delete service(profile). Error [%s]",
3371 _net_print_error(Error));
3373 __NETWORK_FUNC_EXIT__;
3376 } else if (prof_info.profile_type == NET_DEVICE_MESH) {
3377 Error = __net_mesh_delete_profile(network_info, profile_name);
3378 if (Error != NET_ERR_NONE) {
3379 NETWORK_LOG(NETWORK_ERROR,
3380 "Failed to delete service(profile). Error [%s]",
3381 _net_print_error(Error));
3383 __NETWORK_FUNC_EXIT__;
3387 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3389 __NETWORK_FUNC_EXIT__;
3390 return NET_ERR_INVALID_PARAM;
3392 /* LCOV_EXCL_STOP */
3394 __NETWORK_FUNC_EXIT__;
3395 return NET_ERR_NONE;
3398 EXPORT_API int net_get_profile_info(void *handle,
3399 const char *profile_name, net_profile_info_t *prof_info)
3401 __NETWORK_FUNC_ENTER__;
3403 net_err_t Error = NET_ERR_NONE;
3404 network_info_t *network_info = (network_info_t *)handle;
3406 if (prof_info == NULL || _net_check_profile_name(profile_name) != NET_ERR_NONE) {
3407 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3409 __NETWORK_FUNC_EXIT__;
3410 return NET_ERR_INVALID_PARAM;
3413 Error = __net_get_profile_info(network_info, profile_name, prof_info);
3414 /* LCOV_EXCL_START */
3415 if (Error != NET_ERR_NONE)
3416 NETWORK_LOG(NETWORK_ERROR,
3417 "Failed to get service(profile) information. Error [%s]",
3418 _net_print_error(Error));
3419 /* LCOV_EXCL_STOP */
3421 __NETWORK_FUNC_EXIT__;
3425 EXPORT_API int net_modify_profile(void *handle, const char *profile_name, net_profile_info_t *prof_info)
3427 __NETWORK_FUNC_ENTER__;
3429 net_err_t Error = NET_ERR_NONE;
3430 net_profile_info_t exProfInfo;
3431 network_info_t *network_info = (network_info_t *)handle;
3433 Error = net_get_profile_info(network_info, profile_name, &exProfInfo);
3434 if (Error != NET_ERR_NONE) {
3435 NETWORK_LOG(NETWORK_ERROR,
3436 "Failed to get service(profile) information. Error [%s]",
3437 _net_print_error(Error));
3439 __NETWORK_FUNC_EXIT__;
3443 /* LCOV_EXCL_START */
3444 if (prof_info == NULL ||
3445 (exProfInfo.profile_type != NET_DEVICE_WIFI &&
3446 exProfInfo.profile_type != NET_DEVICE_CELLULAR &&
3447 exProfInfo.profile_type != NET_DEVICE_MESH &&
3448 exProfInfo.profile_type != NET_DEVICE_ETHERNET)) {
3449 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3450 __NETWORK_FUNC_EXIT__;
3451 return NET_ERR_INVALID_PARAM;
3454 if (exProfInfo.profile_type == NET_DEVICE_WIFI)
3455 Error = __net_modify_wlan_profile_info(network_info, profile_name, prof_info, &exProfInfo);
3456 else if (exProfInfo.profile_type == NET_DEVICE_CELLULAR)
3457 Error = __net_telephony_modify_profile(network_info, profile_name, prof_info, &exProfInfo);
3458 else if (exProfInfo.profile_type == NET_DEVICE_ETHERNET)
3459 Error = __net_modify_ethernet_profile(network_info, profile_name, prof_info, &exProfInfo);
3460 else if (exProfInfo.profile_type == NET_DEVICE_MESH)
3461 Error = __net_modify_mesh_profile(network_info, profile_name, prof_info, &exProfInfo);
3463 if (Error != NET_ERR_NONE) {
3464 NETWORK_LOG(NETWORK_ERROR,
3465 "Failed to modify service(profile) information. Error [%s]",
3466 _net_print_error(Error));
3468 __NETWORK_FUNC_EXIT__;
3471 /* LCOV_EXCL_STOP */
3473 __NETWORK_FUNC_EXIT__;
3474 return NET_ERR_NONE;
3477 EXPORT_API int net_get_profile_list(void *handle, net_device_t device_type,
3478 net_profile_info_t **profile_list, int *count)
3480 __NETWORK_FUNC_ENTER__;
3482 net_err_t Error = NET_ERR_NONE;
3483 int profile_count = 0;
3484 net_profile_info_t *profile_info = NULL;
3485 network_info_t *network_info = (network_info_t *)handle;
3487 if (count == NULL) {
3488 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3489 __NETWORK_FUNC_EXIT__;
3490 return NET_ERR_INVALID_PARAM;
3493 if (device_type != NET_DEVICE_CELLULAR &&
3494 device_type != NET_DEVICE_WIFI &&
3495 device_type != NET_DEVICE_ETHERNET &&
3496 device_type != NET_DEVICE_MESH && //LCOV_EXCL_LINE
3497 device_type != NET_DEVICE_BLUETOOTH) {
3498 NETWORK_LOG(NETWORK_ERROR, "Not Supported"); //LCOV_EXCL_LINE
3499 __NETWORK_FUNC_EXIT__;
3500 return NET_ERR_NOT_SUPPORTED;
3503 Error = _net_get_profile_list(network_info, device_type, &profile_info, &profile_count);
3505 /* LCOV_EXCL_START */
3506 if (Error != NET_ERR_NONE) {
3507 NETWORK_LOG(NETWORK_ERROR,
3508 "Failed to get service(profile) list. Error [%s]",
3509 _net_print_error(Error));
3511 NET_MEMFREE(profile_info);
3513 __NETWORK_FUNC_EXIT__;
3515 /* LCOV_EXCL_STOP */
3517 *count = profile_count;
3518 *profile_list = profile_info;
3521 __NETWORK_FUNC_EXIT__;
3522 return NET_ERR_NONE;
3525 EXPORT_API int net_get_all_profile_list(void *handle,
3526 net_profile_info_t **profile_list, int *count)
3528 __NETWORK_FUNC_ENTER__;
3530 net_err_t Error = NET_ERR_NONE;
3531 int profile_count = 0;
3532 net_profile_info_t *profile_info = NULL;
3533 network_info_t *network_info = (network_info_t *)handle;
3535 if (count == NULL) {
3536 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3537 __NETWORK_FUNC_EXIT__;
3538 return NET_ERR_INVALID_PARAM;
3541 Error = _net_get_all_profile_list(network_info, &profile_info, &profile_count);
3543 /* LCOV_EXCL_START */
3544 if (Error != NET_ERR_NONE) {
3545 NETWORK_LOG(NETWORK_ERROR,
3546 "Failed to get service(profile) list. Error [%s]",
3547 _net_print_error(Error));
3549 NET_MEMFREE(profile_info);
3551 __NETWORK_FUNC_EXIT__;
3553 /* LCOV_EXCL_STOP */
3555 *count = profile_count;
3556 *profile_list = profile_info;
3559 __NETWORK_FUNC_EXIT__;
3560 return NET_ERR_NONE;
3563 /* LCOV_EXCL_START */
3564 EXPORT_API int net_get_cellular_modem_object_path(char **modem_path, int sim_id)
3566 net_err_t Error = NET_ERR_NONE;
3567 const char *path = NULL;
3568 char subscriber_id[3];
3569 GSList *ModemPathList = NULL, *list = NULL;
3571 if (sim_id < 0 || modem_path == NULL)
3572 return NET_ERR_INVALID_PARAM;
3574 Error = __net_telephony_get_modem_object_path(NULL, &ModemPathList);
3575 if (Error != NET_ERR_NONE)
3579 g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", sim_id);
3580 for (list = ModemPathList; list != NULL; list = list->next) {
3581 path = (const char *)list->data;
3583 NETWORK_LOG(NETWORK_LOW, "path: %s", path);
3584 if (g_str_has_suffix(path, subscriber_id) == TRUE) {
3585 *modem_path = g_strdup(path);
3590 if (*modem_path == NULL)
3591 Error = NET_ERR_MODEM_INTERFACE_NOT_AVAIALABLE;
3593 NETWORK_LOG(NETWORK_LOW, "Subscriber %d: %s", sim_id, *modem_path);
3597 g_slist_free_full(ModemPathList, g_free);
3599 __NETWORK_FUNC_EXIT__;
3603 EXPORT_API int net_set_default_cellular_service_profile(void *handle, const char *profile_name)
3605 net_err_t Error = NET_ERR_NONE;
3606 network_info_t *network_info = (network_info_t *)handle;
3608 if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
3609 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3610 __NETWORK_FUNC_EXIT__;
3611 return NET_ERR_INVALID_PARAM;
3614 Error = __net_set_default_cellular_service_profile_sync(network_info, profile_name);
3615 if (Error != NET_ERR_NONE) {
3616 NETWORK_LOG(NETWORK_ERROR,
3617 "Failed to set default cellular service(profile). Error [%s]",
3618 _net_print_error(Error));
3619 __NETWORK_FUNC_EXIT__;
3623 return NET_ERR_NONE;
3626 EXPORT_API int net_set_default_cellular_service_profile_async(void *handle,
3627 const char *profile_name)
3629 net_err_t Error = NET_ERR_NONE;
3630 network_info_t *network_info = (network_info_t *)handle;
3632 if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
3633 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Parameter");
3634 __NETWORK_FUNC_EXIT__;
3635 return NET_ERR_INVALID_PARAM;
3638 if (network_info->request_table[NETWORK_REQUEST_TYPE_SET_DEFAULT].flag == TRUE) {
3639 NETWORK_LOG(NETWORK_ERROR, "Error!! Request already in progress");
3640 __NETWORK_FUNC_EXIT__;
3641 return NET_ERR_IN_PROGRESS;
3644 network_info->request_table[NETWORK_REQUEST_TYPE_SET_DEFAULT].flag = TRUE;
3646 Error = __net_set_default_cellular_service_profile_async(network_info, profile_name);
3647 if (Error != NET_ERR_NONE) {
3648 NETWORK_LOG(NETWORK_ERROR,
3649 "Error!!! failed to set default cellular service(profile). Error [%s]",
3650 _net_print_error(Error));
3651 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_SET_DEFAULT]),
3652 0, sizeof(network_request_table_t));
3653 __NETWORK_FUNC_EXIT__;
3657 return NET_ERR_NONE;
3659 /* LCOV_EXCL_STOP */
3661 EXPORT_API int net_foreach_ipv6_address(net_device_t device_type,
3662 GSList **ipv6_address_list)
3664 __NETWORK_FUNC_ENTER__;
3666 if (ipv6_address_list == NULL) {
3667 __NETWORK_FUNC_EXIT__;
3668 return NET_ERR_INVALID_PARAM;
3673 char *ip_address = NULL;
3674 char *if_name = NULL;
3676 char buf[NET_IPV6_ADDRESS_FILE_LEN] = {0,};
3677 char str[NET_IPV6_ADDRESS_LEN + 1] = {0,};
3679 fp = fopen(NET_IPV6_ADDRESS_FILE, "r");
3681 NETWORK_LOG(NETWORK_ERROR, "File Opening Failed"); //LCOV_EXCL_LINE
3682 __NETWORK_FUNC_EXIT__;
3683 return NET_ERR_INVALID_OPERATION;
3686 while (fgets(buf, sizeof(buf), fp) != NULL) {
3687 g_strlcpy(str, buf, NET_IPV6_ADDRESS_LEN + 1);
3688 /* LCOV_EXCL_START */
3689 switch (device_type) {
3690 case NET_DEVICE_WIFI:
3691 if_name = strstr(buf, "wlan");
3693 case NET_DEVICE_CELLULAR:
3694 if_name = strstr(buf, "seth");
3696 case NET_DEVICE_USB:
3697 if_name = strstr(buf, "usb");
3699 case NET_DEVICE_ETHERNET:
3700 if_name = strstr(buf, "eth");
3702 case NET_DEVICE_BLUETOOTH:
3703 if_name = strstr(buf, "bnep");
3709 if (if_name != NULL) {
3710 if (NET_ERR_NONE == __net_convert_string_to_ipv6_string(
3712 *ipv6_address_list = g_slist_append(
3713 *ipv6_address_list, ip_address);
3715 /* LCOV_EXCL_STOP */
3720 __NETWORK_FUNC_EXIT__;
3721 return NET_ERR_NONE;
3725 * @fn EXPORT_API int net_get_preferred_ipv6_address(char **address)
3727 * This function is to get preferred ipv6 address.
3730 * @return 0 - on success, negative values for errors
3731 * @param[in] const char *profile_name - profile name
3732 * @param[out] char **address - preferred ipv6 address of specific profile
3734 EXPORT_API int net_get_preferred_ipv6_address(const char *profile_name, char **address)
3736 __NETWORK_FUNC_ENTER__;
3737 net_err_t Error = NET_ERR_NONE;
3739 Error = _net_dbus_get_preferred_ipv6_address(profile_name, address);
3741 if (Error != NET_ERR_NONE)
3742 NETWORK_LOG(NETWORK_ERROR, "_net_dbus_get_preferred_ipv6_address failed\n");
3744 __NETWORK_FUNC_EXIT__;