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 *prof_info);
39 static int __net_extract_services(network_info_t *network_info,
40 GVariantIter *message, net_device_t device_type,
41 net_profile_info_t **profile_info, int *profile_count);
42 static int __net_extract_ip(const gchar *value, net_addr_t *ipAddr);
43 static int __net_extract_common_info(const char *key, GVariant *variant, net_profile_info_t *prof_info);
44 static int __net_extract_mobile_info(network_info_t *network_info, GVariantIter *array, net_profile_info_t *prof_info);
45 static int __net_extract_ethernet_info(GVariantIter *array, net_profile_info_t *prof_info);
46 static int __net_extract_bluetooth_info(GVariantIter *array, net_profile_info_t *prof_info);
47 static int __net_extract_mesh_info(GVariantIter *array, net_profile_info_t *prof_info);
49 /*****************************************************************************
51 *****************************************************************************/
53 /*****************************************************************************
54 * Local Functions Definition
55 *****************************************************************************/
57 static int __net_pm_init_profile_info(net_device_t profile_type, net_profile_info_t *prof_info)
60 net_dev_info_t *net_info = NULL;
62 if (prof_info == NULL ||
63 (profile_type != NET_DEVICE_WIFI &&
64 profile_type != NET_DEVICE_CELLULAR &&
65 profile_type != NET_DEVICE_ETHERNET &&
66 profile_type != NET_DEVICE_MESH &&
67 profile_type != NET_DEVICE_BLUETOOTH)) {
68 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
69 return NET_ERR_INVALID_PARAM;
72 memset(prof_info, 0, sizeof(net_profile_info_t));
73 prof_info->favourite = (char)FALSE;
75 if (profile_type == NET_DEVICE_WIFI) {
76 prof_info->profile_type = NET_DEVICE_WIFI;
77 prof_info->profile_info.wlan.strength = 0;
78 prof_info->profile_info.wlan.frequency = 0;
79 prof_info->profile_info.wlan.max_rate = 0;
80 prof_info->profile_info.wlan.wlan_mode = 0;
81 prof_info->profile_info.wlan.passphrase_required = FALSE;
82 prof_info->profile_info.wlan.security_info.sec_mode = 0;
83 prof_info->profile_info.wlan.security_info.enc_mode = 0;
84 prof_info->profile_info.wlan.security_info.wps_support = FALSE;
86 net_info = &(prof_info->profile_info.wlan.net_info);
87 } else if (profile_type == NET_DEVICE_CELLULAR) {
88 prof_info->profile_type = NET_DEVICE_CELLULAR;
89 prof_info->profile_info.pdp.protocol_type = NET_PDP_TYPE_NONE;
90 prof_info->profile_info.pdp.service_type = NET_SERVICE_UNKNOWN;
91 prof_info->profile_info.pdp.pdn_type = NET_PDN_TYPE_UNKNOWN;
92 prof_info->profile_info.pdp.roam_pdn_type = NET_PDN_TYPE_UNKNOWN;
93 prof_info->profile_info.pdp.auth_info.auth_type = NET_PDP_AUTH_NONE;
94 prof_info->profile_info.pdp.is_static = FALSE;
95 prof_info->profile_info.pdp.roaming = FALSE;
96 prof_info->profile_info.pdp.setup_required = FALSE;
97 prof_info->profile_info.pdp.hidden = FALSE;
98 prof_info->profile_info.pdp.editable = TRUE;
99 prof_info->profile_info.pdp.default_conn = FALSE;
101 net_info = &(prof_info->profile_info.pdp.net_info);
102 } else if (profile_type == NET_DEVICE_ETHERNET) {
103 net_info = &(prof_info->profile_info.ethernet.net_info);
104 } else if (profile_type == NET_DEVICE_BLUETOOTH) {
105 net_info = &(prof_info->profile_info.bluetooth.net_info);
106 } else if (profile_type == NET_DEVICE_MESH) {
107 prof_info->profile_type = NET_DEVICE_MESH;
108 prof_info->profile_info.mesh.strength = 0;
109 prof_info->profile_info.mesh.frequency = 0;
110 prof_info->profile_info.mesh.passphrase_required = FALSE;
111 prof_info->profile_info.mesh.security_info.sec_mode = 0;
113 net_info = &(prof_info->profile_info.mesh.net_info);
116 if (net_info != NULL) {
117 net_info->dns_count = 0;
119 for (i = 0; i < NET_DNS_ADDR_MAX; i++) {
120 net_info->dns_addr[i].Type = NET_ADDR_IPV4;
121 net_info->dns_addr[i].data.Ipv4.s_addr = 0;
124 net_info->ip_config_type = 0;
125 net_info->ip_addr.Type = NET_ADDR_IPV4;
126 net_info->ip_addr.data.Ipv4.s_addr = 0;
127 net_info->b_netmask = FALSE;
128 net_info->subnet_mask.Type = NET_ADDR_IPV4;
129 net_info->subnet_mask.data.Ipv4.s_addr = 0;
130 net_info->b_def_gateway = FALSE;
131 net_info->gateway_addr.Type = NET_ADDR_IPV4;
132 net_info->gateway_addr.data.Ipv4.s_addr = 0;
133 net_info->b_server_addr = FALSE;
134 net_info->server_addr.Type = NET_ADDR_IPV4;
135 net_info->server_addr.data.Ipv4.s_addr = 0;
137 net_info->ip_config_type6 = 0;
138 net_info->ip_addr6.Type = NET_ADDR_IPV6;
139 inet_pton(AF_INET6, "::", &net_info->ip_addr6.data.Ipv6);
140 net_info->prefix_len6 = 0;
141 net_info->b_def_gateway6 = FALSE;
142 net_info->gateway_addr6.Type = NET_ADDR_IPV6;
143 inet_pton(AF_INET6, "::", &net_info->gateway_addr6.data.Ipv6);
145 net_info->proxy_method = NET_PROXY_TYPE_UNKNOWN;
151 static int __net_telephony_init_profile_info(net_telephony_profile_info_t *prof_info)
153 if (prof_info == NULL) {
154 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
156 __NETWORK_FUNC_EXIT__;
157 return NET_ERR_INVALID_PARAM;
160 memset(prof_info->profile_name, '\0', NET_PROFILE_NAME_LEN_MAX+1);
161 prof_info->service_type = NET_SERVICE_UNKNOWN;
162 prof_info->pdn_type = NET_PDN_TYPE_UNKNOWN;
163 prof_info->roam_pdn_type = NET_PDN_TYPE_UNKNOWN;
164 memset(prof_info->apn, '\0', NET_PDP_APN_LEN_MAX+1);
166 prof_info->auth_info.auth_type = NET_PDP_AUTH_NONE;
167 memset(prof_info->auth_info.user_name, '\0', NET_PDP_AUTH_USERNAME_LEN_MAX+1);
168 memset(prof_info->auth_info.password, '\0', NET_PDP_AUTH_PASSWORD_LEN_MAX+1);
170 memset(prof_info->proxy_addr, '\0', NET_PROXY_LEN_MAX+1);
171 memset(prof_info->home_url, '\0', NET_HOME_URL_LEN_MAX+1);
173 memset(prof_info->keyword, '\0', NET_PDP_APN_LEN_MAX+1);
174 prof_info->hidden = FALSE;
175 prof_info->editable = TRUE;
176 prof_info->default_conn = FALSE;
181 static void __net_telephony_get_path(const gchar *value, net_telephony_profile_info_t *profile_info)
184 g_strlcpy(profile_info->profile_name, value, NET_PROFILE_NAME_LEN_MAX);
187 static void __net_telephony_get_svc_ctg_id(const gchar *value, net_telephony_profile_info_t *profile_info)
189 net_service_type_t service_type = NET_SERVICE_UNKNOWN;
192 service_type = atoi(value);
194 if (service_type > NET_SERVICE_UNKNOWN)
195 profile_info->service_type = service_type;
198 static void __net_telephony_get_apn(const gchar *value, net_telephony_profile_info_t *profile_info)
201 g_strlcpy(profile_info->apn, value, NET_PDP_APN_LEN_MAX);
204 static void __net_telephony_get_pdp_protocol(const gchar *value, net_telephony_profile_info_t *profile_info)
206 net_pdn_type_e pdnType = NET_PDN_TYPE_UNKNOWN;
209 pdnType = atoi(value);
211 if (pdnType == NET_PDN_TYPE_IPV4)
212 profile_info->pdn_type = NET_PDN_TYPE_IPV4;
213 else if (pdnType == NET_PDN_TYPE_IPV6)
214 profile_info->pdn_type = NET_PDN_TYPE_IPV6;
215 else if (pdnType == NET_PDN_TYPE_IPV4_IPV6)
216 profile_info->pdn_type = NET_PDN_TYPE_IPV4_IPV6;
219 static void __net_telephony_get_roam_pdp_protocol(const gchar *value,
220 net_telephony_profile_info_t *profile_info)
222 net_pdn_type_e roampdn_type = NET_PDN_TYPE_UNKNOWN;
225 roampdn_type = atoi(value);
227 if (roampdn_type == NET_PDN_TYPE_IPV4)
228 profile_info->roam_pdn_type = NET_PDN_TYPE_IPV4;
229 else if (roampdn_type == NET_PDN_TYPE_IPV6)
230 profile_info->roam_pdn_type = NET_PDN_TYPE_IPV6;
231 else if (roampdn_type == NET_PDN_TYPE_IPV4_IPV6)
232 profile_info->roam_pdn_type = NET_PDN_TYPE_IPV4_IPV6;
235 static void __net_telephony_get_auth_type(const gchar *value, net_telephony_profile_info_t *profile_info)
237 net_auth_type_t authType = NET_PDP_AUTH_NONE;
240 authType = atoi(value);
242 if (authType == NET_PDP_AUTH_PAP)
243 profile_info->auth_info.auth_type = NET_PDP_AUTH_PAP;
244 else if (authType == NET_PDP_AUTH_CHAP)
245 profile_info->auth_info.auth_type = NET_PDP_AUTH_CHAP;
248 static void __net_telephony_get_auth_id(const gchar *value, net_telephony_profile_info_t *profile_info)
251 g_strlcpy(profile_info->auth_info.user_name, value, NET_PDP_AUTH_USERNAME_LEN_MAX);
254 static void __net_telephony_get_auth_pwd(const gchar *value, net_telephony_profile_info_t *profile_info)
257 g_strlcpy(profile_info->auth_info.password, value, NET_PDP_AUTH_PASSWORD_LEN_MAX);
260 static void __net_telephony_get_proxy_addr(const gchar *value, net_telephony_profile_info_t *profile_info)
263 g_strlcpy(profile_info->proxy_addr, value, NET_PROXY_LEN_MAX);
266 static void __net_telephony_get_home_uri(const gchar *value, net_telephony_profile_info_t *profile_info)
269 g_strlcpy(profile_info->home_url, value, NET_HOME_URL_LEN_MAX);
272 static void __net_telephony_get_default_internet_conn(const gchar *value,
273 net_telephony_profile_info_t *profile_info)
278 if (g_strcmp0(value, "TRUE") == 0)
279 profile_info->default_conn = TRUE;
281 profile_info->default_conn = FALSE;
284 static void __net_telephony_get_profile_name(const gchar *value, net_telephony_profile_info_t *profile_info)
287 g_strlcpy(profile_info->keyword, value, NET_PDP_APN_LEN_MAX);
290 static void __net_telephony_get_editable(const gchar *value, net_telephony_profile_info_t *profile_info)
295 if (g_strcmp0(value, "TRUE") == 0)
296 profile_info->editable = TRUE;
298 profile_info->editable = FALSE;
301 static void __net_telephony_get_hidden(const gchar *value, net_telephony_profile_info_t *profile_info)
306 if (g_strcmp0(value, "TRUE") == 0)
307 profile_info->hidden = TRUE;
309 profile_info->hidden = FALSE;
312 static int __net_telephony_get_profile_info(network_info_t *network_info,
313 net_profile_name_t *profile_name, net_telephony_profile_info_t *profile_info)
315 __NETWORK_FUNC_ENTER__;
317 net_err_t Error = NET_ERR_NONE;
320 const gchar *key = NULL;
321 const gchar *value = NULL;
323 if (profile_name == NULL || profile_info == NULL) {
324 NETWORK_LOG(NETWORK_ERROR, "Invalid parameter!");
325 __NETWORK_FUNC_EXIT__;
326 return NET_ERR_INVALID_PARAM;
329 result = _net_invoke_dbus_method(network_info, TELEPHONY_SERVICE, profile_name->profile_name,
330 TELEPHONY_PROFILE_INTERFACE, "GetProfile", NULL, &Error);
331 if (result == NULL) {
332 NETWORK_LOG(NETWORK_ERROR, "_net_invoke_dbus_method failed");
333 __NETWORK_FUNC_EXIT__;
337 Error = __net_telephony_init_profile_info(profile_info);
339 if (Error != NET_ERR_NONE) {
340 g_variant_unref(result);
341 __NETWORK_FUNC_EXIT__;
345 g_variant_get(result, "(a{ss})", &iter);
346 while (g_variant_iter_loop(iter, "{ss}", &key, &value)) {
347 if (g_strcmp0(key, "path") == 0)
348 __net_telephony_get_path(value, profile_info);
349 else if (g_strcmp0(key, "svc_ctg_id") == 0)
350 __net_telephony_get_svc_ctg_id(value, profile_info);
351 else if (g_strcmp0(key, "apn") == 0)
352 __net_telephony_get_apn(value, profile_info);
353 else if (g_strcmp0(key, "pdp_protocol") == 0)
354 __net_telephony_get_pdp_protocol(value, profile_info);
355 else if (g_strcmp0(key, "roam_pdp_protocol") == 0)
356 __net_telephony_get_roam_pdp_protocol(value, profile_info);
357 else if (g_strcmp0(key, "auth_type") == 0)
358 __net_telephony_get_auth_type(value, profile_info);
359 else if (g_strcmp0(key, "auth_id") == 0)
360 __net_telephony_get_auth_id(value, profile_info);
361 else if (g_strcmp0(key, "auth_pwd") == 0)
362 __net_telephony_get_auth_pwd(value, profile_info);
363 else if (g_strcmp0(key, "proxy_addr") == 0)
364 __net_telephony_get_proxy_addr(value, profile_info);
365 else if (g_strcmp0(key, "home_url") == 0)
366 __net_telephony_get_home_uri(value, profile_info);
367 else if (g_strcmp0(key, "default_internet_conn") == 0)
368 __net_telephony_get_default_internet_conn(value, profile_info);
369 else if (g_strcmp0(key, "profile_name") == 0)
370 __net_telephony_get_profile_name(value, profile_info);
371 else if (g_strcmp0(key, "editable") == 0)
372 __net_telephony_get_editable(value, profile_info);
373 else if (g_strcmp0(key, "hidden") == 0)
374 __net_telephony_get_hidden(value, profile_info);
377 g_variant_iter_free(iter);
378 g_variant_unref(result);
380 __NETWORK_FUNC_EXIT__;
384 static int __net_telephony_get_modem_object_path(network_info_t *network_info,
385 GSList **ModemPathList)
387 __NETWORK_FUNC_ENTER__;
389 net_err_t Error = NET_ERR_NONE;
391 GVariantIter *iter_modem = NULL;
392 GVariantIter *modem_properties = NULL;
393 const char *modem_path;
395 result = _net_invoke_dbus_method(network_info,
396 TELEPHONY_SERVICE, TELEPHONY_MASTER_PATH,
397 TELEPHONY_MASTER_INTERFACE, "GetModems", NULL, &Error);
398 if (result == NULL) {
399 NETWORK_LOG(NETWORK_ERROR, "Failed to get modem path list");
400 __NETWORK_FUNC_EXIT__;
404 g_variant_get(result, "(a{sa{ss}})", &iter_modem);
405 while (g_variant_iter_loop(iter_modem, "{sa{ss}}", &modem_path, &modem_properties)) {
406 *ModemPathList = g_slist_append(*ModemPathList, g_strdup(modem_path));
407 NETWORK_LOG(NETWORK_LOW, "modem object path: %s", modem_path);
410 g_variant_iter_free(iter_modem);
411 g_variant_unref(result);
413 __NETWORK_FUNC_EXIT__;
417 static int __net_telephony_get_profile_list(network_info_t *network_info,
418 net_profile_name_t **profile_name, int *profile_count)
420 __NETWORK_FUNC_ENTER__;
422 net_err_t Error = NET_ERR_NONE;
423 int count = 0, i = 0;
424 const char *str = NULL;
426 GVariantIter *iter = NULL;
427 GSList *profiles = NULL, *list = NULL;
428 net_profile_name_t *profileList = NULL;
430 GSList *ModemPathList = NULL;
431 const char *path = NULL;
433 Error = __net_telephony_get_modem_object_path(network_info, &ModemPathList);
434 if (Error != NET_ERR_NONE) {
435 NETWORK_LOG(NETWORK_ERROR, "Failed to get modems path list");
437 g_slist_free_full(ModemPathList, g_free);
438 __NETWORK_FUNC_EXIT__;
442 for (list = ModemPathList; list != NULL; list = list->next) {
443 path = (const char *)list->data;
445 NETWORK_LOG(NETWORK_LOW, "path: %s", path);
446 result = _net_invoke_dbus_method(network_info,
447 TELEPHONY_SERVICE, path, TELEPHONY_MODEM_INTERFACE,
448 "GetProfileList", NULL, &Error);
449 if (result == NULL) {
450 NETWORK_LOG(NETWORK_LOW, "Failed to get profiles: %s", path);
454 g_variant_get(result, "(as)", &iter);
455 while (g_variant_iter_loop(iter, "s", &str))
456 profiles = g_slist_append(profiles, g_strdup(str));
458 g_variant_iter_free(iter);
459 g_variant_unref(result);
462 g_slist_free_full(ModemPathList, g_free);
464 count = g_slist_length(profiles);
466 profileList = (net_profile_name_t*)malloc(sizeof(net_profile_name_t) * count);
467 Error = NET_ERR_NONE;
473 if (profileList == NULL) {
474 NETWORK_LOG(NETWORK_ERROR, "Failed to allocate memory");
476 Error = NET_ERR_UNKNOWN;
480 for (list = profiles, i = 0; list != NULL; list = list->next, i++)
481 g_strlcpy(profileList[i].profile_name,
482 (const char *)list->data, NET_PROFILE_NAME_LEN_MAX);
484 *profile_name = profileList;
485 *profile_count = count;
488 g_slist_free_full(profiles, g_free);
490 __NETWORK_FUNC_EXIT__;
494 static int __net_telephony_search_pdp_profile(network_info_t *network_info,
495 char *profile_name, net_profile_name_t *PdpProfName)
497 __NETWORK_FUNC_ENTER__;
499 net_err_t Error = NET_ERR_NONE;
500 net_profile_name_t *ProfileList = NULL;
501 char *connmanProfName = NULL;
502 char *telephonyProfName = NULL;
503 char *foundPtr = NULL;
504 int profile_count = 0;
507 /* Get pdp profile list from telephony service */
508 Error = __net_telephony_get_profile_list(network_info, &ProfileList, &profile_count);
509 if (Error != NET_ERR_NONE) {
510 NETWORK_LOG(NETWORK_ERROR, "Failed to get profile list from telephony service");
511 NET_MEMFREE(ProfileList);
512 __NETWORK_FUNC_EXIT__;
516 if (ProfileList == NULL || profile_count <= 0) {
517 NETWORK_LOG(NETWORK_ERROR, "There is no PDP profiles");
518 NET_MEMFREE(ProfileList);
519 __NETWORK_FUNC_EXIT__;
520 return NET_ERR_NO_SERVICE;
523 /* Find matching profile */
524 connmanProfName = strrchr(profile_name, '/') + 1;
525 for (i = 0; i < profile_count; i++) {
526 telephonyProfName = strrchr(ProfileList[i].profile_name, '/') + 1;
527 foundPtr = strstr(connmanProfName, telephonyProfName);
529 if (foundPtr != NULL && g_strcmp0(foundPtr, telephonyProfName) == 0) {
530 g_strlcpy(PdpProfName->profile_name,
531 ProfileList[i].profile_name, NET_PROFILE_NAME_LEN_MAX);
533 NETWORK_LOG(NETWORK_HIGH,
534 "PDP profile name found in cellular profile: %s",
535 PdpProfName->profile_name);
540 if (i >= profile_count) {
541 NETWORK_LOG(NETWORK_ERROR, "There is no matching PDP profiles");
542 NET_MEMFREE(ProfileList);
543 __NETWORK_FUNC_EXIT__;
544 return NET_ERR_NO_SERVICE;
547 NET_MEMFREE(ProfileList);
549 __NETWORK_FUNC_EXIT__;
554 static int __net_extract_all_services(network_info_t *network_info,
555 GVariantIter *array, net_device_t device_type, const char *service_prefix,
556 int *prof_count, net_profile_info_t **ProfilePtr)
559 net_profile_info_t prof_info = { 0, };
560 net_err_t Error = NET_ERR_NONE;
562 gchar *service_name = NULL;
563 GHashTable *service_hash = NULL;
564 GVariantIter *next = NULL;
566 __NETWORK_FUNC_ENTER__;
568 if (array == NULL || service_prefix == NULL) {
569 NETWORK_LOG(NETWORK_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
571 __NETWORK_FUNC_EXIT__;
572 return NET_ERR_INVALID_PARAM;
575 service_hash = g_hash_table_new(g_str_hash, g_str_equal);
577 /* LCOV_EXCL_START */
578 while (g_variant_iter_loop(array, "(oa{sv})", &obj, &next)) {
582 if (g_str_has_prefix(obj, service_prefix) == TRUE) {
583 memset(&prof_info, 0, sizeof(net_profile_info_t));
585 if ((Error = __net_pm_init_profile_info(device_type, &prof_info)) != NET_ERR_NONE) {
586 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
588 NET_MEMFREE(*ProfilePtr);
594 if (device_type == NET_DEVICE_WIFI) {
595 service_name = &obj[strlen(service_prefix) + 13];
596 if (g_hash_table_lookup(service_hash, service_name))
599 g_hash_table_insert(service_hash, service_name, service_name);
601 if (g_strrstr(obj + strlen(service_prefix), "hidden") != NULL)
602 prof_info.profile_info.wlan.is_hidden = TRUE;
605 prof_info.profile_type = device_type;
606 g_strlcpy(prof_info.profile_name, obj, NET_PROFILE_NAME_LEN_MAX);
608 switch (device_type) {
609 case NET_DEVICE_WIFI:
610 g_strlcpy(prof_info.profile_info.wlan.net_info.profile_name,
611 obj, NET_PROFILE_NAME_LEN_MAX);
613 Error = __net_extract_wifi_info(next, &prof_info);
615 case NET_DEVICE_CELLULAR:
616 g_strlcpy(prof_info.profile_info.pdp.net_info.profile_name,
617 obj, NET_PROFILE_NAME_LEN_MAX);
619 Error = __net_extract_mobile_info(network_info, next, &prof_info);
621 case NET_DEVICE_ETHERNET:
622 g_strlcpy(prof_info.profile_info.ethernet.net_info.profile_name,
623 obj, NET_PROFILE_NAME_LEN_MAX);
625 Error = __net_extract_ethernet_info(next, &prof_info);
627 case NET_DEVICE_BLUETOOTH:
628 g_strlcpy(prof_info.profile_info.bluetooth.net_info.profile_name,
629 obj, NET_PROFILE_NAME_LEN_MAX);
631 Error = __net_extract_bluetooth_info(next, &prof_info);
633 case NET_DEVICE_MESH:
634 g_strlcpy(prof_info.profile_info.mesh.net_info.profile_name,
635 obj, NET_PROFILE_NAME_LEN_MAX);
637 Error = __net_extract_mesh_info(next, &prof_info);
640 NET_MEMFREE(*ProfilePtr);
643 Error = NET_ERR_NOT_SUPPORTED;
647 if (Error != NET_ERR_NONE) {
648 NETWORK_LOG(NETWORK_ERROR, "Failed to extract service info");
649 NET_MEMFREE(*ProfilePtr);
655 *ProfilePtr = (net_profile_info_t *)realloc(*ProfilePtr,
656 (count + 1) * sizeof(net_profile_info_t));
657 if (*ProfilePtr == NULL) {
658 NETWORK_LOG(NETWORK_ERROR, "Failed to allocate memory");
661 Error = NET_ERR_UNKNOWN;
665 memcpy(*ProfilePtr + count, &prof_info, sizeof(net_profile_info_t));
673 g_hash_table_destroy(service_hash);
675 __NETWORK_FUNC_EXIT__;
679 /* LCOV_EXCL_START */
680 g_hash_table_destroy(service_hash);
683 g_variant_iter_free(next);
687 __NETWORK_FUNC_EXIT__;
692 static int __net_extract_services(network_info_t *network_info,
693 GVariantIter *message, net_device_t device_type,
694 net_profile_info_t **profile_info, int *profile_count)
696 __NETWORK_FUNC_ENTER__;
698 net_err_t Error = NET_ERR_NONE;
699 net_profile_info_t *ProfilePtr = NULL;
701 char *service_prefix = NULL;
705 /* LCOV_EXCL_START */
706 switch (device_type) {
707 case NET_DEVICE_WIFI:
708 service_prefix = CONNMAN_WIFI_SERVICE_PROFILE_PREFIX;
710 case NET_DEVICE_CELLULAR:
711 service_prefix = CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX;
713 case NET_DEVICE_ETHERNET:
714 service_prefix = CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX;
716 case NET_DEVICE_BLUETOOTH:
717 service_prefix = CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX;
719 case NET_DEVICE_MESH:
720 service_prefix = CONNMAN_MESH_PROFILE_PREFIX;
724 *profile_info = NULL;
725 __NETWORK_FUNC_EXIT__;
726 return NET_ERR_NOT_SUPPORTED;
731 Error = __net_extract_all_services(network_info, message,
732 device_type, service_prefix, &prof_cnt, &ProfilePtr);
734 /* LCOV_EXCL_START */
735 if (Error != NET_ERR_NONE) {
736 NETWORK_LOG(NETWORK_ERROR, "Failed to extract services from received message");
738 *profile_info = NULL;
739 __NETWORK_FUNC_EXIT__;
744 *profile_count = prof_cnt;
745 *profile_info = ProfilePtr;
747 __NETWORK_FUNC_EXIT__;
751 /* LCOV_EXCL_START */
752 static int __net_extract_ip(const gchar *value, net_addr_t *ipAddr)
754 __NETWORK_FUNC_ENTER__;
756 unsigned char *ipValue = NULL;
757 char *saveptr = NULL;
758 char ipString[NETPM_IPV4_STR_LEN_MAX+1];
761 ipValue = (unsigned char *)&(ipAddr->data.Ipv4.s_addr);
764 g_strlcpy(ipString, value, NETPM_IPV4_STR_LEN_MAX+1);
766 ipToken[0] = strtok_r(ipString, ".", &saveptr);
768 if (ipToken[0] != NULL) {
769 ipToken[1] = strtok_r(NULL, ".", &saveptr);
771 if (ipToken[1] != NULL) {
772 ipToken[2] = strtok_r(NULL, ".", &saveptr);
774 if (ipToken[2] != NULL) {
775 ipToken[3] = strtok_r(NULL, ".", &saveptr);
777 if (ipToken[3] != NULL) {
778 ipValue[0] = (unsigned char)atoi(ipToken[0]);
779 ipValue[1] = (unsigned char)atoi(ipToken[1]);
780 ipValue[2] = (unsigned char)atoi(ipToken[2]);
781 ipValue[3] = (unsigned char)atoi(ipToken[3]);
788 __NETWORK_FUNC_EXIT__;
793 static int __net_get_prefix_len(const char *netmask)
795 __NETWORK_FUNC_ENTER__;
797 in_addr_t mask = inet_network(netmask);
800 for (; mask; mask <<= 1)
803 __NETWORK_FUNC_EXIT__;
808 static gboolean __net_check_address_type(int address_family, const char *address)
810 unsigned char buf[sizeof(struct in6_addr)] = {0, };
813 err = inet_pton(address_family, address, buf);
820 static void __net_extract_state_value(GVariant *variant, net_profile_info_t *prof_info)
822 const gchar *value = g_variant_get_string(variant, NULL);
824 if (g_strcmp0(value, "idle") == 0)
825 prof_info->profile_state = NET_STATE_TYPE_IDLE;
826 else if (g_strcmp0(value, "failure") == 0)
827 prof_info->profile_state = NET_STATE_TYPE_FAILURE;
828 else if (g_strcmp0(value, "association") == 0)
829 prof_info->profile_state = NET_STATE_TYPE_ASSOCIATION;
830 else if (g_strcmp0(value, "configuration") == 0)
831 prof_info->profile_state = NET_STATE_TYPE_CONFIGURATION;
832 else if (g_strcmp0(value, "ready") == 0)
833 prof_info->profile_state = NET_STATE_TYPE_READY;
834 else if (g_strcmp0(value, "disconnect") == 0)
835 prof_info->profile_state = NET_STATE_TYPE_DISCONNECT;
836 else if (g_strcmp0(value, "online") == 0)
837 prof_info->profile_state = NET_STATE_TYPE_ONLINE;
839 prof_info->profile_state = NET_STATE_TYPE_UNKNOWN;
842 static void __net_extract_state6_value(GVariant *variant, net_profile_info_t *prof_info)
844 const gchar *value = g_variant_get_string(variant, NULL);
846 if (g_strcmp0(value, "idle") == 0)
847 prof_info->profile_state6 = NET_STATE_TYPE_IDLE;
848 else if (g_strcmp0(value, "failure") == 0)
849 prof_info->profile_state6 = NET_STATE_TYPE_FAILURE;
850 else if (g_strcmp0(value, "association") == 0)
851 prof_info->profile_state6 = NET_STATE_TYPE_ASSOCIATION;
852 else if (g_strcmp0(value, "configuration") == 0)
853 prof_info->profile_state6 = NET_STATE_TYPE_CONFIGURATION;
854 else if (g_strcmp0(value, "disconnect") == 0)
855 prof_info->profile_state6 = NET_STATE_TYPE_DISCONNECT;
856 else if (g_strcmp0(value, "ready") == 0)
857 prof_info->profile_state6 = NET_STATE_TYPE_READY;
858 else if (g_strcmp0(value, "online") == 0)
859 prof_info->profile_state6 = NET_STATE_TYPE_ONLINE;
861 prof_info->profile_state6 = NET_STATE_TYPE_UNKNOWN;
864 static void __net_extract_error(GVariant *variant, net_profile_info_t *prof_info)
866 const gchar *value = g_variant_get_string(variant, NULL);
868 if (g_strcmp0(value, "invalid-key") == 0)
869 prof_info->profile_error_state = NET_STATE_ERROR_INVALID_KEY;
870 else if (g_strcmp0(value, "connect-failed") == 0)
871 prof_info->profile_error_state = NET_STATE_ERROR_CONNECT_FAILED;
872 else if (g_strcmp0(value, "auth-failed") == 0)
873 prof_info->profile_error_state = NET_STATE_ERROR_AUTH_FAILED;
874 else if (g_strcmp0(value, "assoc-failed") == 0)
875 prof_info->profile_error_state = NET_STATE_ERROR_ASSOC_FAILED;
876 else if (g_strcmp0(value, "login-failed") == 0)
877 prof_info->profile_error_state = NET_STATE_ERROR_LOGIN_FAILED;
878 else if (g_strcmp0(value, "dhcp-failed") == 0)
879 prof_info->profile_error_state = NET_STATE_ERROR_DHCP_FAILED;
880 else if (g_strcmp0(value, "out-of-range") == 0)
881 prof_info->profile_error_state = NET_STATE_ERROR_OUT_OF_RANGE;
882 else if (g_strcmp0(value, "pin-missing") == 0)
883 prof_info->profile_error_state = NET_STATE_ERROR_PIN_MISSING;
886 static void __net_extract_ethernet_value(GVariant *variant, net_dev_info_t *net_info)
888 const gchar *subKey = NULL;
889 const gchar *value = NULL;
890 GVariant *var = NULL;
891 GVariantIter *iter = NULL;
892 g_variant_get(variant, "a{sv}", &iter);
893 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
894 if (g_strcmp0(subKey, "Interface") == 0) {
895 value = g_variant_get_string(var, NULL);
898 g_strlcpy(net_info->dev_name, value, NET_MAX_DEVICE_NAME_LEN);
899 } else if (g_strcmp0(subKey, "Address") == 0) {
900 value = g_variant_get_string(var, NULL);
903 g_strlcpy(net_info->mac_addr, value, NET_MAX_MAC_ADDR_LEN);
906 g_variant_iter_free(iter);
909 static void __net_get_ipv4_method(const gchar *value, net_dev_info_t *net_info)
911 if (g_strcmp0(value, "dhcp") == 0)
912 net_info->ip_config_type = NET_IP_CONFIG_TYPE_DYNAMIC;
913 else if (g_strcmp0(value, "auto") == 0)
914 net_info->ip_config_type = NET_IP_CONFIG_TYPE_AUTO_IP;
915 else if (g_strcmp0(value, "manual") == 0)
916 net_info->ip_config_type = NET_IP_CONFIG_TYPE_STATIC;
917 else if (g_strcmp0(value, "fixed") == 0)
918 net_info->ip_config_type = NET_IP_CONFIG_TYPE_FIXED;
919 else if (g_strcmp0(value, "off") == 0)
920 net_info->ip_config_type = NET_IP_CONFIG_TYPE_OFF;
923 static void __net_extract_ipv4_value(GVariant *variant, net_dev_info_t *net_info)
925 const gchar *subKey = NULL;
926 const gchar *value = NULL;
927 GVariant *var = NULL;
928 GVariantIter *iter = NULL;
929 g_variant_get(variant, "a{sv}", &iter);
930 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
931 if (g_strcmp0(subKey, "Method") == 0) {
932 value = g_variant_get_string(var, NULL);
934 __net_get_ipv4_method(value, net_info);
936 if (net_info->ip_config_type != NET_IP_CONFIG_TYPE_DYNAMIC) {
937 net_info->b_server_addr = FALSE;
938 net_info->server_addr.Type = NET_ADDR_IPV4;
939 net_info->server_addr.data.Ipv4.s_addr = 0;
942 } else if (g_strcmp0(subKey, "Address") == 0) {
943 value = g_variant_get_string(var, NULL);
945 __net_extract_ip(value, &net_info->ip_addr);
946 } else if (g_strcmp0(subKey, "Netmask") == 0) {
947 value = g_variant_get_string(var, NULL);
949 __net_extract_ip(value, &net_info->subnet_mask);
950 net_info->prefix_len = __net_get_prefix_len(value);
951 net_info->b_netmask = TRUE;
952 } else if (g_strcmp0(subKey, "Gateway") == 0) {
953 value = g_variant_get_string(var, NULL);
955 __net_extract_ip(value, &net_info->gateway_addr);
956 net_info->b_def_gateway = TRUE;
957 } else if (g_strcmp0(subKey, "DHCPServerIP") == 0) {
958 value = g_variant_get_string(var, NULL);
960 __net_extract_ip(value, &net_info->server_addr);
961 net_info->b_server_addr = TRUE;
962 } else if (g_strcmp0(subKey, "DHCPLeaseDuration") == 0) {
963 net_info->dhcp_lease_duration = g_variant_get_int32(var);
966 g_variant_iter_free(iter);
969 static void __net_extract_ipv4_configuration_value(GVariant *variant, net_dev_info_t *net_info)
971 const gchar *subKey = NULL;
972 const gchar *value = NULL;
973 GVariant *var = NULL;
974 GVariantIter *iter = NULL;
975 if (net_info->ip_config_type != NET_IP_CONFIG_TYPE_DYNAMIC &&
976 net_info->ip_config_type != NET_IP_CONFIG_TYPE_STATIC &&
977 net_info->ip_config_type != NET_IP_CONFIG_TYPE_FIXED &&
978 net_info->ip_config_type != NET_IP_CONFIG_TYPE_OFF) {
980 g_variant_get(variant, "a{sv}", &iter);
981 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
982 if (g_strcmp0(subKey, "Method") == 0) {
983 value = g_variant_get_string(var, NULL);
985 __net_get_ipv4_method(value, net_info);
987 } else if (g_strcmp0(subKey, "Address") == 0 &&
988 net_info->ip_addr.data.Ipv4.s_addr == 0) {
989 value = g_variant_get_string(var, NULL);
991 __net_extract_ip(value, &net_info->ip_addr);
992 } else if (g_strcmp0(subKey, "Netmask") == 0 &&
993 net_info->subnet_mask.data.Ipv4.s_addr == 0) {
994 value = g_variant_get_string(var, NULL);
996 __net_extract_ip(value, &net_info->subnet_mask);
997 net_info->b_netmask = TRUE;
998 } else if (g_strcmp0(subKey, "Gateway") == 0 &&
999 net_info->gateway_addr.data.Ipv4.s_addr == 0) {
1000 value = g_variant_get_string(var, NULL);
1002 __net_extract_ip(value, &net_info->gateway_addr);
1003 net_info->b_def_gateway = TRUE;
1006 g_variant_iter_free(iter);
1010 static void __net_extract_ipv6_value(GVariant *variant, net_dev_info_t *net_info)
1012 const gchar *subKey = NULL;
1013 const gchar *value = NULL;
1014 GVariant *var = NULL;
1015 GVariantIter *iter = NULL;
1016 g_variant_get(variant, "a{sv}", &iter);
1017 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
1018 if (g_strcmp0(subKey, "Method") == 0) {
1019 value = g_variant_get_string(var, NULL);
1021 if (g_strcmp0(value, "manual") == 0)
1022 net_info->ip_config_type6 = NET_IP_CONFIG_TYPE_STATIC;
1023 else if (g_strcmp0(value, "off") == 0)
1024 net_info->ip_config_type6 = NET_IP_CONFIG_TYPE_OFF;
1025 else if (g_strcmp0(value, "auto") == 0 ||
1026 g_strcmp0(value, "6to4") == 0)
1027 net_info->ip_config_type6 = NET_IP_CONFIG_TYPE_AUTO_IP;
1029 } else if (g_strcmp0(subKey, "Address") == 0) {
1030 value = g_variant_get_string(var, NULL);
1032 inet_pton(AF_INET6, value, &net_info->ip_addr6.data.Ipv6);
1033 } else if (g_strcmp0(subKey, "PrefixLength") == 0) {
1034 net_info->prefix_len6 = g_variant_get_byte(var);
1035 } else if (g_strcmp0(subKey, "Gateway") == 0) {
1036 value = g_variant_get_string(var, NULL);
1038 inet_pton(AF_INET6, value, &net_info->gateway_addr6.data.Ipv6);
1039 net_info->b_def_gateway6 = TRUE;
1040 } else if (g_strcmp0(subKey, "Privacy") == 0) {
1041 value = g_variant_get_string(var, NULL);
1044 g_strlcpy(net_info->privacy6, value, NETPM_IPV6_MAX_PRIVACY_LEN);
1047 g_variant_iter_free(iter);
1050 static void __net_extract_nameserver_value(GVariant *variant, net_dev_info_t *net_info)
1052 GVariantIter *iter = NULL;
1055 gchar *dns_value = NULL;
1056 gchar *dns_type = NULL;
1058 g_variant_get(variant, "as", &iter);
1060 while (g_variant_iter_loop(iter, "s", &dns_value)) {
1061 /* Check Type of DNS Address */
1062 if (__net_check_address_type(AF_INET6, dns_value)) {
1064 if (dnsCount6 < NET_DNS_ADDR_MAX) {
1065 net_info->dns_addr6[dnsCount6].Type =
1067 inet_pton(AF_INET6, dns_value,
1068 &net_info->dns_addr6[dnsCount6]\
1072 } else if (__net_check_address_type(AF_INET, dns_value)) {
1074 if (dnsCount < NET_DNS_ADDR_MAX) {
1075 net_info->dns_addr[dnsCount].Type =
1077 __net_extract_ip(dns_value,
1078 &net_info->dns_addr[dnsCount]);
1081 } else { /* DNS Type */
1082 dns_type = g_strdup(dns_value);
1083 if (g_strcmp0(dns_type, "ipv4.manual") == 0)
1084 net_info->dns_config_type =
1085 NET_DNS_CONFIG_TYPE_STATIC;
1086 else if (g_strcmp0(dns_type, "ipv4.dhcp") == 0)
1087 net_info->dns_config_type =
1088 NET_DNS_CONFIG_TYPE_DYNAMIC;
1089 if (g_strcmp0(dns_type, "ipv6.manual") == 0)
1090 net_info->dns_config_type6 =
1091 NET_DNS_CONFIG_TYPE_STATIC;
1092 else if (g_strcmp0(dns_type, "ipv6.dhcp") == 0)
1093 net_info->dns_config_type6 =
1094 NET_DNS_CONFIG_TYPE_DYNAMIC;
1098 g_variant_iter_free(iter);
1100 net_info->dns_count = dnsCount;
1101 net_info->dns_count6 = dnsCount6;
1104 static void __net_extract_proxy_value(GVariant *variant, net_dev_info_t *net_info)
1106 const gchar *subKey = NULL;
1107 const gchar *value = NULL;
1108 GVariant *var = NULL;
1109 GVariantIter *iter = NULL;
1110 const gchar *url = NULL;
1111 gchar *servers = NULL;
1113 g_variant_get(variant, "a{sv}", &iter);
1114 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
1115 if (g_strcmp0(subKey, "Method") == 0) {
1116 value = g_variant_get_string(var, NULL);
1118 if (g_strcmp0(value, "direct") == 0)
1119 net_info->proxy_method = NET_PROXY_TYPE_DIRECT;
1120 else if (g_strcmp0(value, "auto") == 0)
1121 net_info->proxy_method = NET_PROXY_TYPE_AUTO;
1122 else if (g_strcmp0(value, "manual") == 0)
1123 net_info->proxy_method = NET_PROXY_TYPE_MANUAL;
1125 net_info->proxy_method = NET_PROXY_TYPE_UNKNOWN;
1126 } else if (g_strcmp0(subKey, "URL") == 0) {
1127 url = g_variant_get_string(var, NULL);
1128 } else if (g_strcmp0(subKey, "Servers") == 0) {
1129 GVariantIter *iter_sub = NULL;
1131 g_variant_get(var, "as", &iter_sub);
1132 if (!g_variant_iter_loop(iter_sub, "s", &servers))
1133 NETWORK_LOG(NETWORK_LOW, "There was no value");
1134 g_variant_iter_free(iter_sub);
1137 g_variant_iter_free(iter);
1139 if (net_info->proxy_method == NET_PROXY_TYPE_AUTO && url != NULL)
1140 g_strlcpy(net_info->proxy_addr, url, NET_PROXY_LEN_MAX);
1141 else if (net_info->proxy_method == NET_PROXY_TYPE_MANUAL && servers != NULL)
1142 g_strlcpy(net_info->proxy_addr, servers, NET_PROXY_LEN_MAX);
1148 static net_ethernet_eap_type_t __net_convert_eap_type_from_string(const char *eap_type)
1150 if (g_strcmp0(eap_type, "MD5") == 0)
1151 return NET_ETHERNET_EAP_TYPE_MD5;
1152 else if (g_strcmp0(eap_type, "PEAP") == 0)
1153 return NET_ETHERNET_EAP_TYPE_PEAP;
1154 else if (g_strcmp0(eap_type, "TLS") == 0)
1155 return NET_ETHERNET_EAP_TYPE_TLS;
1156 else if (g_strcmp0(eap_type, "TTLS") == 0)
1157 return NET_ETHERNET_EAP_TYPE_TTLS;
1158 else if (g_strcmp0(eap_type, "FAST") == 0)
1159 return NET_ETHERNET_EAP_TYPE_FAST;
1164 static net_ethernet_eap_auth_type_t __net_convert_eap_auth_from_string(const char *eap_auth)
1166 if (g_strcmp0(eap_auth, "PAP") == 0)
1167 return NET_ETHERNET_EAP_AUTH_TYPE_PAP;
1168 else if (g_strcmp0(eap_auth, "MSCHAP") == 0)
1169 return NET_ETHERNET_EAP_AUTH_TYPE_MSCHAP;
1170 else if (g_strcmp0(eap_auth, "MSCHAPV2") == 0)
1171 return NET_ETHERNET_EAP_AUTH_TYPE_MSCHAPV2;
1172 else if (g_strcmp0(eap_auth, "GTC") == 0)
1173 return NET_ETHERNET_EAP_AUTH_TYPE_GTC;
1174 else if (g_strcmp0(eap_auth, "MD5") == 0)
1175 return NET_ETHERNET_EAP_AUTH_TYPE_MD5;
1177 return NET_ETHERNET_EAP_AUTH_TYPE_NONE;
1180 static void __net_extract_eapol_value(GVariant *variant, net_dev_info_t *net_info)
1182 const gchar *subKey = NULL;
1183 const gchar *value = NULL;
1184 GVariant *var = NULL;
1185 GVariantIter *iter = NULL;
1187 g_variant_get(variant, "a{sv}", &iter);
1188 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
1189 if (g_strcmp0(subKey, "UseEapol") == 0) {
1190 net_info->use_eapol = g_variant_get_boolean(var);
1192 } else if (g_strcmp0(subKey, "EAP") == 0) {
1193 value = g_variant_get_string(var, NULL);
1196 net_info->eap.eap_type = __net_convert_eap_type_from_string(value);
1197 } else if (g_strcmp0(subKey, "Identity") == 0) {
1198 value = g_variant_get_string(var, NULL);
1201 g_strlcpy(net_info->eap.username, value, NET_USERNAME_LEN+1);
1202 } else if (g_strcmp0(subKey, "AnonymousIdentity") == 0) {
1203 value = g_variant_get_string(var, NULL);
1206 g_strlcpy(net_info->eap.anonymous_identity, value, NET_USERNAME_LEN+1);
1207 } else if (g_strcmp0(subKey, "CACertFile") == 0) {
1208 value = g_variant_get_string(var, NULL);
1211 g_strlcpy(net_info->eap.ca_cert_filename, value, NET_CA_CERT_FILENAME_LEN+1);
1212 } else if (g_strcmp0(subKey, "ClientCertFile") == 0) {
1213 value = g_variant_get_string(var, NULL);
1216 g_strlcpy(net_info->eap.client_cert_filename, value, NET_CLIENT_CERT_FILENAME_LEN+1);
1217 } else if (g_strcmp0(subKey, "PrivateKeyFile") == 0) {
1218 value = g_variant_get_string(var, NULL);
1221 g_strlcpy(net_info->eap.private_key_filename, value, NET_PRIVATE_KEY_FILENAME_LEN+1);
1222 } else if (g_strcmp0(subKey, "Phase2") == 0) {
1223 value = g_variant_get_string(var, NULL);
1226 net_info->eap.eap_auth = __net_convert_eap_auth_from_string(value);
1227 } else if (g_strcmp0(subKey, "Phase1") == 0) {
1228 value = g_variant_get_string(var, NULL);
1230 if (value != NULL) {
1231 if (g_strcmp0(value, "1") == 0)
1232 net_info->eap.peap_version = 1;
1234 net_info->eap.peap_version = 0;
1236 } else if (g_strcmp0(subKey, "PacFile") == 0) {
1237 value = g_variant_get_string(var, NULL);
1240 g_strlcpy(net_info->eap.pac_filename, value, NET_PAC_FILENAME_LEN+1);
1243 g_variant_iter_free(iter);
1246 static int __net_extract_common_info(const char *key, GVariant *variant, net_profile_info_t *prof_info)
1248 __NETWORK_FUNC_ENTER__;
1250 net_err_t Error = NET_ERR_NONE;
1251 net_dev_info_t *net_info = NULL;
1253 if (prof_info->profile_type == NET_DEVICE_CELLULAR) {
1254 net_info = &(prof_info->profile_info.pdp.net_info);
1255 } else if (prof_info->profile_type == NET_DEVICE_WIFI) {
1256 net_info = &(prof_info->profile_info.wlan.net_info);
1257 } else if (prof_info->profile_type == NET_DEVICE_ETHERNET) {
1258 net_info = &(prof_info->profile_info.ethernet.net_info);
1259 } else if (prof_info->profile_type == NET_DEVICE_BLUETOOTH) {
1260 net_info = &(prof_info->profile_info.bluetooth.net_info);
1261 } else if (prof_info->profile_type == NET_DEVICE_MESH) {
1262 net_info = &(prof_info->profile_info.mesh.net_info);
1264 NETWORK_LOG(NETWORK_ERROR,
1265 "Invalid Profile type. [%d]", prof_info->profile_type);
1266 return NET_ERR_INVALID_PARAM;
1269 if (g_strcmp0(key, "State") == 0) {
1270 __net_extract_state_value(variant, prof_info);
1271 } else if (g_strcmp0(key, "StateIPv6") == 0) {
1272 __net_extract_state6_value(variant, prof_info);
1273 } else if (g_strcmp0(key, "Error") == 0) {
1274 __net_extract_error(variant, prof_info);
1275 } else if (g_strcmp0(key, "Favorite") == 0) {
1276 prof_info->favourite = (char)g_variant_get_boolean(variant);
1277 } else if (g_strcmp0(key, "Ethernet") == 0) {
1278 __net_extract_ethernet_value(variant, net_info);
1279 } else if (g_strcmp0(key, "IPv4") == 0) {
1280 __net_extract_ipv4_value(variant, net_info);
1281 } else if (g_strcmp0(key, "IPv4.Configuration") == 0) {
1282 __net_extract_ipv4_configuration_value(variant, net_info);
1283 } else if (g_strcmp0(key, "IPv6") == 0) {
1284 __net_extract_ipv6_value(variant, net_info);
1285 } else if (g_strcmp0(key, "IPv6.Configuration") == 0) {
1286 __net_extract_ipv6_value(variant, net_info);
1287 } else if (g_strcmp0(key, "Nameservers") == 0) {
1288 __net_extract_nameserver_value(variant, net_info);
1289 } else if (g_strcmp0(key, "Nameservers.Configuration") == 0 && net_info->dns_count == 0) {
1290 __net_extract_nameserver_value(variant, net_info);
1291 } else if (g_strcmp0(key, "Domains") == 0) {
1292 } else if (g_strcmp0(key, "Domains.Configuration") == 0) {
1293 } else if (g_strcmp0(key, "Proxy") == 0) {
1294 __net_extract_proxy_value(variant, net_info);
1295 } else if (g_strcmp0(key, "Proxy.Configuration") == 0 &&
1296 net_info->proxy_method != NET_PROXY_TYPE_AUTO &&
1297 net_info->proxy_method != NET_PROXY_TYPE_MANUAL) {
1298 __net_extract_proxy_value(variant, net_info);
1299 } else if (g_strcmp0(key, "Provider") == 0) {
1301 } else if (g_strcmp0(key, "EapOverEthernet") == 0) {
1302 __net_extract_eapol_value(variant, net_info);
1305 __NETWORK_FUNC_EXIT__;
1309 static wlan_eap_type_t __convert_eap_type_from_string(const char *eap_type)
1311 if (eap_type == NULL)
1312 return WLAN_SEC_EAP_TYPE_PEAP;
1313 else if (g_strcmp0(eap_type, "peap") == 0)
1314 return WLAN_SEC_EAP_TYPE_PEAP;
1315 else if (g_strcmp0(eap_type, "tls") == 0)
1316 return WLAN_SEC_EAP_TYPE_TLS;
1317 else if (g_strcmp0(eap_type, "ttls") == 0)
1318 return WLAN_SEC_EAP_TYPE_TTLS;
1319 else if (g_strcmp0(eap_type, "sim") == 0)
1320 return WLAN_SEC_EAP_TYPE_SIM;
1321 else if (g_strcmp0(eap_type, "aka") == 0)
1322 return WLAN_SEC_EAP_TYPE_AKA;
1324 return WLAN_SEC_EAP_TYPE_PEAP;
1327 static wlan_eap_auth_type_t __convert_eap_auth_from_string(const char *eap_auth)
1329 if (eap_auth == NULL)
1330 return WLAN_SEC_EAP_AUTH_NONE;
1331 else if (g_strcmp0(eap_auth, "NONE") == 0)
1332 return WLAN_SEC_EAP_AUTH_NONE;
1333 else if (g_strcmp0(eap_auth, "PAP") == 0)
1334 return WLAN_SEC_EAP_AUTH_PAP;
1335 else if (g_strcmp0(eap_auth, "MSCHAP") == 0)
1336 return WLAN_SEC_EAP_AUTH_MSCHAP;
1337 else if (g_strcmp0(eap_auth, "MSCHAPV2") == 0)
1338 return WLAN_SEC_EAP_AUTH_MSCHAPV2;
1339 else if (g_strcmp0(eap_auth, "GTC") == 0)
1340 return WLAN_SEC_EAP_AUTH_GTC;
1341 else if (g_strcmp0(eap_auth, "MD5") == 0)
1342 return WLAN_SEC_EAP_AUTH_MD5;
1344 return WLAN_SEC_EAP_AUTH_NONE;
1347 static void __net_set_wifi_mode(GVariant *var, net_wifi_profile_info_t *wlan)
1349 const gchar *value = g_variant_get_string(var, NULL);
1351 if (g_strcmp0(value, "managed") == 0)
1352 wlan->wlan_mode = NETPM_WLAN_CONNMODE_INFRA;
1353 else if (g_strcmp0(value, "adhoc") == 0)
1354 wlan->wlan_mode = NETPM_WLAN_CONNMODE_ADHOC;
1356 wlan->wlan_mode = NETPM_WLAN_CONNMODE_AUTO;
1359 static void __net_set_wifi_security(GVariant *var, net_wifi_profile_info_t *wlan)
1361 GVariantIter *iter_sub = NULL;
1362 const gchar *value = NULL;
1364 g_variant_get(var, "as", &iter_sub);
1365 while (g_variant_iter_loop(iter_sub, "s", &value)) {
1366 if (g_strcmp0(value, "none") == 0 &&
1367 wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1368 wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1369 else if (g_strcmp0(value, "wep") == 0 &&
1370 wlan->security_info.sec_mode < WLAN_SEC_MODE_WEP)
1371 wlan->security_info.sec_mode = WLAN_SEC_MODE_WEP;
1372 else if (g_strcmp0(value, "psk") == 0 &&
1373 wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1374 wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
1375 else if (g_strcmp0(value, "ft_psk") == 0 &&
1376 wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_FT_PSK)
1377 wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_FT_PSK;
1378 else if (g_strcmp0(value, "ieee8021x") == 0 &&
1379 wlan->security_info.sec_mode < WLAN_SEC_MODE_IEEE8021X)
1380 wlan->security_info.sec_mode = WLAN_SEC_MODE_IEEE8021X;
1381 else if (g_strcmp0(value, "wpa") == 0 &&
1382 wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1383 wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
1384 else if (g_strcmp0(value, "rsn") == 0 &&
1385 wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1386 wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK;
1387 else if (g_strcmp0(value, "sae") == 0 &&
1388 wlan->security_info.sec_mode < WLAN_SEC_MODE_SAE)
1389 wlan->security_info.sec_mode = WLAN_SEC_MODE_SAE;
1390 else if (g_strcmp0(value, "wps") == 0)
1391 wlan->security_info.wps_support = TRUE;
1392 else if (wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1393 wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1395 g_variant_iter_free(iter_sub);
1398 static void __net_set_wifi_encryption_mode(GVariant *var, net_wifi_profile_info_t *wlan)
1400 const gchar *value = g_variant_get_string(var, NULL);
1402 if (g_strcmp0(value, "none") == 0)
1403 wlan->security_info.enc_mode = WLAN_ENC_MODE_NONE;
1404 else if (g_strcmp0(value, "wep") == 0)
1405 wlan->security_info.enc_mode = WLAN_ENC_MODE_WEP;
1406 else if (g_strcmp0(value, "tkip") == 0)
1407 wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP;
1408 else if (g_strcmp0(value, "aes") == 0)
1409 wlan->security_info.enc_mode = WLAN_ENC_MODE_AES;
1410 else if (g_strcmp0(value, "mixed") == 0)
1411 wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP_AES_MIXED;
1414 static void __net_set_wifi_name(GVariant *var, net_wifi_profile_info_t *wlan)
1416 const gchar *value = g_variant_get_string(var, NULL);
1419 g_strlcpy(wlan->essid, value, NET_WLAN_ESSID_LEN);
1422 static void __net_set_wifi_passphrase(GVariant *var, net_wifi_profile_info_t *wlan)
1424 wlan_security_info_t *security_info = &(wlan->security_info);
1425 const gchar *value = g_variant_get_string(var, NULL);
1427 if (security_info->sec_mode == WLAN_SEC_MODE_WEP && value != NULL)
1428 g_strlcpy(security_info->authentication.wep.wep_key,
1429 value, NETPM_WLAN_MAX_WEP_KEY_LEN+1);
1430 else if ((security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
1431 security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) &&
1433 g_strlcpy(security_info->authentication.psk.psk_key,
1434 value, NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN+1);
1435 else if (security_info->sec_mode == WLAN_SEC_MODE_SAE && value != NULL)
1436 g_strlcpy(security_info->authentication.sae.sae_key,
1437 value, NETPM_WLAN_MAX_SAE_KEY_LEN+1);
1440 static void __net_set_wifi_bssid(GVariant *var, net_wifi_profile_info_t *wlan)
1442 const gchar *value = g_variant_get_string(var, NULL);
1445 g_strlcpy(wlan->bssid, value, NET_MAX_MAC_ADDR_LEN);
1448 static void __net_set_wifi_eap(GVariant *var, net_wifi_profile_info_t *wlan)
1450 const gchar *value = g_variant_get_string(var, NULL);
1453 wlan->security_info.authentication.eap.eap_type =
1454 __convert_eap_type_from_string(value);
1457 static void __net_set_wifi_phase2(GVariant *var, net_wifi_profile_info_t *wlan)
1459 const gchar *value = g_variant_get_string(var, NULL);
1462 wlan->security_info.authentication.eap.eap_auth =
1463 __convert_eap_auth_from_string(value);
1466 static void __net_set_wifi_identity(GVariant *var, net_wifi_profile_info_t *wlan)
1468 const gchar *value = g_variant_get_string(var, NULL);
1471 g_strlcpy(wlan->security_info.authentication.eap.username,
1472 value, NETPM_WLAN_USERNAME_LEN+1);
1475 static void __net_set_wifi_password(GVariant *var, net_wifi_profile_info_t *wlan)
1477 const gchar *value = g_variant_get_string(var, NULL);
1480 g_strlcpy(wlan->security_info.authentication.eap.password,
1481 value, NETPM_WLAN_PASSWORD_LEN+1);
1484 static void __net_set_wifi_ca_cert_file(GVariant *var, net_wifi_profile_info_t *wlan)
1486 const gchar *value = g_variant_get_string(var, NULL);
1489 g_strlcpy(wlan->security_info.authentication.eap.ca_cert_filename,
1490 value, NETPM_WLAN_CA_CERT_FILENAME_LEN+1);
1493 static void __net_set_wifi_client_cert_file(GVariant *var, net_wifi_profile_info_t *wlan)
1495 const gchar *value = g_variant_get_string(var, NULL);
1498 g_strlcpy(wlan->security_info.authentication.eap.client_cert_filename,
1499 value, NETPM_WLAN_CLIENT_CERT_FILENAME_LEN+1);
1502 static void __net_set_wifi_private_key_file(GVariant *var, net_wifi_profile_info_t *wlan)
1504 const gchar *value = g_variant_get_string(var, NULL);
1507 g_strlcpy(wlan->security_info.authentication.eap.private_key_filename,
1508 value, NETPM_WLAN_PRIVATE_KEY_FILENAME_LEN+1);
1511 static void __net_set_wifi_private_key_passphrase(GVariant *var, net_wifi_profile_info_t *wlan)
1513 const gchar *value = g_variant_get_string(var, NULL);
1516 g_strlcpy(wlan->security_info.authentication.eap.private_key_passwd,
1517 value, NETPM_WLAN_PRIVATE_KEY_PASSWD_LEN+1);
1520 static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_t *prof_info)
1522 net_err_t Error = NET_ERR_NONE;
1523 net_wifi_profile_info_t *wlan = &(prof_info->profile_info.wlan);
1524 GVariant *var = NULL;
1525 const gchar *key = NULL;
1527 __NETWORK_FUNC_ENTER__;
1529 while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
1530 if (g_strcmp0(key, "Mode") == 0)
1531 __net_set_wifi_mode(var, wlan);
1532 else if (g_strcmp0(key, "Security") == 0)
1533 __net_set_wifi_security(var, wlan);
1534 else if (g_strcmp0(key, "EncryptionMode") == 0)
1535 __net_set_wifi_encryption_mode(var, wlan);
1536 else if (g_strcmp0(key, "Passpoint") == 0)
1537 wlan->passpoint = g_variant_get_boolean(var);
1538 else if (g_strcmp0(key, "Strength") == 0)
1539 wlan->strength = g_variant_get_byte(var);
1540 else if (g_strcmp0(key, "Name") == 0)
1541 __net_set_wifi_name(var, wlan);
1542 else if (g_strcmp0(key, "Passphrase") == 0)
1543 __net_set_wifi_passphrase(var, wlan);
1544 else if (g_strcmp0(key, "PassphraseRequired") == 0)
1545 wlan->passphrase_required = g_variant_get_boolean(var);
1546 else if (g_strcmp0(key, "BSSID") == 0)
1547 __net_set_wifi_bssid(var, wlan);
1548 else if (g_strcmp0(key, "MaxSpeed") == 0)
1549 wlan->max_rate = g_variant_get_int32(var);
1550 else if (g_strcmp0(key, "Frequency") == 0)
1551 wlan->frequency = (unsigned int)g_variant_get_uint16(var);
1552 else if (g_strcmp0(key, "EAP") == 0)
1553 __net_set_wifi_eap(var, wlan);
1554 else if (g_strcmp0(key, "Phase2") == 0)
1555 __net_set_wifi_phase2(var, wlan);
1556 else if (g_strcmp0(key, "Identity") == 0)
1557 __net_set_wifi_identity(var, wlan);
1558 else if (g_strcmp0(key, "Password") == 0)
1559 __net_set_wifi_password(var, wlan);
1560 else if (g_strcmp0(key, "CACertFile") == 0)
1561 __net_set_wifi_ca_cert_file(var, wlan);
1562 else if (g_strcmp0(key, "ClientCertFile") == 0)
1563 __net_set_wifi_client_cert_file(var, wlan);
1564 else if (g_strcmp0(key, "PrivateKeyFile") == 0)
1565 __net_set_wifi_private_key_file(var, wlan);
1566 else if (g_strcmp0(key, "PrivateKeyPassphrase") == 0)
1567 __net_set_wifi_private_key_passphrase(var, wlan);
1568 else if (g_strcmp0(key, "Keymgmt") == 0)
1569 wlan->security_info.keymgmt = (unsigned int)g_variant_get_uint32(var);
1571 Error = __net_extract_common_info(key, var, prof_info);
1574 __NETWORK_FUNC_EXIT__;
1578 static int __net_extract_mesh_info(GVariantIter *array,
1579 net_profile_info_t *prof_info)
1581 net_err_t Error = NET_ERR_NONE;
1582 net_mesh_profile_info_t *mesh = &(prof_info->profile_info.mesh);
1583 GVariant *var = NULL;
1584 const gchar *key = NULL;
1586 __NETWORK_FUNC_ENTER__;
1588 while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
1589 const gchar *value = NULL;
1591 if (g_strcmp0(key, "Security") == 0) {
1592 value = g_variant_get_string(var, NULL);
1593 if (g_strcmp0(value, "none") == 0 &&
1594 mesh->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1595 mesh->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1596 else if (g_strcmp0(value, "sae") == 0 &&
1597 mesh->security_info.sec_mode < WLAN_SEC_MODE_SAE)
1598 mesh->security_info.sec_mode = WLAN_SEC_MODE_SAE;
1599 else if (mesh->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1600 mesh->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1601 } else if (g_strcmp0(key, "Strength") == 0) {
1602 mesh->strength = g_variant_get_byte(var);
1603 } else if (g_strcmp0(key, "Name") == 0) {
1604 value = g_variant_get_string(var, NULL);
1607 g_strlcpy(mesh->essid, value, NET_WLAN_ESSID_LEN);
1608 } else if (g_strcmp0(key, "Passphrase") == 0) {
1609 wlan_security_info_t *security_info = &(mesh->security_info);
1610 value = g_variant_get_string(var, NULL);
1612 if (security_info->sec_mode == WLAN_SEC_MODE_SAE && value != NULL)
1613 g_strlcpy(security_info->authentication.sae.sae_key,
1614 value, NETPM_WLAN_MAX_SAE_KEY_LEN+1);
1615 } else if (g_strcmp0(key, "PassphraseRequired") == 0) {
1618 val = g_variant_get_boolean(var);
1621 mesh->passphrase_required = TRUE;
1623 mesh->passphrase_required = FALSE;
1624 } else if (g_strcmp0(key, "BSSID") == 0) {
1625 value = g_variant_get_string(var, NULL);
1628 g_strlcpy(mesh->bssid, value, NET_MAX_MAC_ADDR_LEN);
1630 } else if (g_strcmp0(key, "Frequency") == 0) {
1631 mesh->frequency = (unsigned int)g_variant_get_uint16(var);
1634 Error = __net_extract_common_info(key, var, prof_info);
1637 __NETWORK_FUNC_EXIT__;
1641 static int __net_extract_mobile_info(network_info_t *network_info,
1642 GVariantIter *array, net_profile_info_t *prof_info)
1644 net_err_t Error = NET_ERR_NONE;
1645 GVariant *var = NULL;
1646 const gchar *key = NULL;
1648 __NETWORK_FUNC_ENTER__;
1650 while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
1651 const gchar *value = NULL;
1653 if (g_strcmp0(key, "Mode") == 0) {
1654 value = g_variant_get_string(var, NULL);
1656 if (g_strcmp0(value, "gprs") == 0)
1657 prof_info->profile_info.pdp.protocol_type = NET_PDP_TYPE_GPRS;
1658 else if (g_strcmp0(value, "edge") == 0)
1659 prof_info->profile_info.pdp.protocol_type = NET_PDP_TYPE_EDGE;
1660 else if (g_strcmp0(value, "umts") == 0)
1661 prof_info->profile_info.pdp.protocol_type = NET_PDP_TYPE_UMTS;
1663 prof_info->profile_info.pdp.protocol_type = NET_PDP_TYPE_NONE;
1664 } else if (g_strcmp0(key, "Roaming") == 0) {
1667 val = g_variant_get_boolean(var);
1669 prof_info->profile_info.pdp.roaming = TRUE;
1671 prof_info->profile_info.pdp.roaming = FALSE;
1672 } else if (g_strcmp0(key, "setup_required") == 0) {
1675 val = g_variant_get_boolean(var);
1677 prof_info->profile_info.pdp.setup_required = TRUE;
1679 prof_info->profile_info.pdp.setup_required = FALSE;
1680 #if defined TIZEN_DUALSIM_ENABLE
1681 } else if (g_strcmp0(key, "Name") == 0) {
1682 value = g_variant_get_string(var, NULL);
1683 if (value != NULL) {
1684 gchar **list = g_strsplit(value, "/context", 0);
1687 g_strlcpy(prof_info->profile_info.pdp.ps_modem_path,
1688 list[0], NET_PROFILE_NAME_LEN_MAX);
1689 NETWORK_LOG(NETWORK_LOW, "Modem path: %s",
1690 prof_info->profile_info.pdp.ps_modem_path);
1693 NETWORK_LOG(NETWORK_ERROR, "Invalid modem path: %s", value);
1695 NETWORK_LOG(NETWORK_ERROR, "Null modem path");
1698 Error = __net_extract_common_info(key, var, prof_info);
1699 if (Error != NET_ERR_NONE)
1700 NETWORK_LOG(NETWORK_ERROR, "fail to extract common info err(%d)", Error);
1704 /* Get Specific info from telephony service */
1705 net_telephony_profile_info_t telephony_profinfo;
1706 net_profile_name_t PdpProfName;
1708 PdpProfName.profile_name[0] = '\0';
1710 __net_telephony_init_profile_info(&telephony_profinfo);
1712 /* Find matching profile in telephony service */
1713 Error = __net_telephony_search_pdp_profile(network_info, prof_info->profile_name, &PdpProfName);
1715 if (Error == NET_ERR_NONE && strlen(PdpProfName.profile_name) > 0) {
1716 /* Get profile info from telephony service */
1717 Error = __net_telephony_get_profile_info(network_info, &PdpProfName, &telephony_profinfo);
1719 if (Error == NET_ERR_NONE) {
1720 prof_info->profile_info.pdp.service_type = telephony_profinfo.service_type;
1722 if (strlen(telephony_profinfo.apn) > 0)
1723 g_strlcpy(prof_info->profile_info.pdp.apn,
1724 telephony_profinfo.apn, NET_PDP_APN_LEN_MAX);
1726 if (strlen(telephony_profinfo.proxy_addr) > 0)
1727 g_strlcpy(prof_info->profile_info.pdp.net_info.proxy_addr,
1728 telephony_profinfo.proxy_addr, NET_PROXY_LEN_MAX);
1730 if (strlen(telephony_profinfo.home_url) > 0)
1731 g_strlcpy(prof_info->profile_info.pdp.home_url,
1732 telephony_profinfo.home_url, NET_HOME_URL_LEN_MAX);
1734 prof_info->profile_info.pdp.auth_info.auth_type = telephony_profinfo.auth_info.auth_type;
1735 prof_info->profile_info.pdp.pdn_type = telephony_profinfo.pdn_type;
1736 prof_info->profile_info.pdp.roam_pdn_type = telephony_profinfo.roam_pdn_type;
1738 if (strlen(telephony_profinfo.auth_info.user_name) > 0)
1739 g_strlcpy(prof_info->profile_info.pdp.auth_info.user_name,
1740 telephony_profinfo.auth_info.user_name,
1741 NET_PDP_AUTH_USERNAME_LEN_MAX);
1743 if (strlen(telephony_profinfo.auth_info.password) > 0)
1744 g_strlcpy(prof_info->profile_info.pdp.auth_info.password,
1745 telephony_profinfo.auth_info.password,
1746 NET_PDP_AUTH_PASSWORD_LEN_MAX);
1748 if (strlen(telephony_profinfo.keyword) > 0)
1749 g_strlcpy(prof_info->profile_info.pdp.keyword,
1750 telephony_profinfo.keyword,
1751 NET_PDP_APN_LEN_MAX);
1753 prof_info->profile_info.pdp.hidden = telephony_profinfo.hidden;
1754 prof_info->profile_info.pdp.editable = telephony_profinfo.editable;
1755 prof_info->profile_info.pdp.default_conn = telephony_profinfo.default_conn;
1759 __NETWORK_FUNC_EXIT__;
1763 static int __net_extract_ethernet_info(GVariantIter *array, net_profile_info_t *prof_info)
1765 net_err_t Error = NET_ERR_NONE;
1766 GVariant *var = NULL;
1767 const gchar *key = NULL;
1769 __NETWORK_FUNC_ENTER__;
1771 while (g_variant_iter_loop(array, "{sv}", &key, &var))
1772 Error = __net_extract_common_info(key, var, prof_info);
1774 __NETWORK_FUNC_EXIT__;
1778 static int __net_extract_bluetooth_info(GVariantIter *array, net_profile_info_t *prof_info)
1780 net_err_t Error = NET_ERR_NONE;
1781 GVariant *var = NULL;
1782 const gchar *key = NULL;
1784 __NETWORK_FUNC_ENTER__;
1786 while (g_variant_iter_loop(array, "{sv}", &key, &var))
1787 Error = __net_extract_common_info(key, var, prof_info);
1789 __NETWORK_FUNC_EXIT__;
1793 int _net_extract_service_info(network_info_t *network_info,
1794 const char *profile_name, GVariantIter *iter,
1795 net_profile_info_t *prof_info)
1797 __NETWORK_FUNC_ENTER__;
1799 net_err_t Error = NET_ERR_NONE;
1800 net_device_t profileType = NET_DEVICE_UNKNOWN;
1802 GVariant *value = NULL;
1804 while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
1805 const gchar *tech = NULL;
1807 if (g_strcmp0(key, "Type") == 0) {
1808 tech = g_variant_get_string(value, NULL);
1810 if (g_strcmp0(tech, "wifi") == 0)
1811 profileType = NET_DEVICE_WIFI;
1812 else if (g_strcmp0(tech, "cellular") == 0)
1813 profileType = NET_DEVICE_CELLULAR;
1814 else if (g_strcmp0(tech, "ethernet") == 0)
1815 profileType = NET_DEVICE_ETHERNET;
1816 else if (g_strcmp0(tech, "bluetooth") == 0)
1817 profileType = NET_DEVICE_BLUETOOTH;
1818 else if (g_strcmp0(tech, "mesh") == 0)
1819 profileType = NET_DEVICE_MESH;
1821 g_variant_unref(value);
1827 if (profileType == NET_DEVICE_WIFI) {
1828 if ((Error = __net_pm_init_profile_info(NET_DEVICE_WIFI, prof_info)) != NET_ERR_NONE) {
1829 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
1830 __NETWORK_FUNC_EXIT__;
1834 prof_info->profile_type = NET_DEVICE_WIFI;
1835 g_strlcpy(prof_info->profile_name, profile_name, NET_PROFILE_NAME_LEN_MAX);
1836 g_strlcpy(prof_info->profile_info.wlan.net_info.profile_name,
1837 profile_name, NET_PROFILE_NAME_LEN_MAX);
1839 Error = __net_extract_wifi_info(iter, prof_info);
1840 } else if (profileType == NET_DEVICE_CELLULAR) {
1841 if ((Error = __net_pm_init_profile_info(NET_DEVICE_CELLULAR, prof_info)) != NET_ERR_NONE) {
1842 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
1843 __NETWORK_FUNC_EXIT__;
1847 prof_info->profile_type = NET_DEVICE_CELLULAR;
1848 g_strlcpy(prof_info->profile_name, profile_name, NET_PROFILE_NAME_LEN_MAX);
1849 g_strlcpy(prof_info->profile_info.pdp.net_info.profile_name,
1850 profile_name, NET_PROFILE_NAME_LEN_MAX);
1852 Error = __net_extract_mobile_info(network_info, iter, prof_info);
1853 } else if (profileType == NET_DEVICE_ETHERNET) {
1854 if ((Error = __net_pm_init_profile_info(NET_DEVICE_ETHERNET, prof_info)) != NET_ERR_NONE) {
1855 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
1856 __NETWORK_FUNC_EXIT__;
1860 prof_info->profile_type = NET_DEVICE_ETHERNET;
1861 g_strlcpy(prof_info->profile_name, profile_name, NET_PROFILE_NAME_LEN_MAX);
1862 g_strlcpy(prof_info->profile_info.ethernet.net_info.profile_name,
1863 profile_name, NET_PROFILE_NAME_LEN_MAX);
1865 Error = __net_extract_ethernet_info(iter, prof_info);
1866 } else if (profileType == NET_DEVICE_BLUETOOTH) {
1867 if ((Error = __net_pm_init_profile_info(NET_DEVICE_BLUETOOTH, prof_info)) != NET_ERR_NONE) {
1868 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
1869 __NETWORK_FUNC_EXIT__;
1873 prof_info->profile_type = NET_DEVICE_BLUETOOTH;
1874 g_strlcpy(prof_info->profile_name, profile_name, NET_PROFILE_NAME_LEN_MAX);
1875 g_strlcpy(prof_info->profile_info.bluetooth.net_info.profile_name,
1876 profile_name, NET_PROFILE_NAME_LEN_MAX);
1878 Error = __net_extract_bluetooth_info(iter, prof_info);
1879 } else if (profileType == NET_DEVICE_MESH) {
1880 if ((Error = __net_pm_init_profile_info(NET_DEVICE_MESH, prof_info)) !=
1882 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
1883 __NETWORK_FUNC_EXIT__;
1887 prof_info->profile_type = NET_DEVICE_MESH;
1888 g_strlcpy(prof_info->profile_name, profile_name, NET_PROFILE_NAME_LEN_MAX);
1889 g_strlcpy(prof_info->profile_info.mesh.net_info.profile_name,
1890 profile_name, NET_PROFILE_NAME_LEN_MAX);
1892 Error = __net_extract_mesh_info(iter, prof_info);
1894 NETWORK_LOG(NETWORK_ERROR, "Not supported profile type");
1895 __NETWORK_FUNC_EXIT__;
1896 return NET_ERR_NOT_SUPPORTED;
1899 if (Error != NET_ERR_NONE) {
1900 NETWORK_LOG(NETWORK_ERROR,
1901 "Failed to extract service information from received message");
1903 __NETWORK_FUNC_EXIT__;
1907 __NETWORK_FUNC_EXIT__;
1911 void _net_extract_clock_updated(GVariantIter *iter, bool *state)
1913 __NETWORK_FUNC_ENTER__;
1916 GVariant *value = NULL;
1920 while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
1922 if (g_strcmp0(key, "TimeUpdated") == 0) {
1923 updated = g_variant_get_boolean(value);
1928 g_variant_unref(value);
1934 __NETWORK_FUNC_EXIT__;
1937 void _net_extract_ntp_server(GVariantIter *iter, char **ntp_server)
1939 __NETWORK_FUNC_ENTER__;
1942 GVariant *value = NULL;
1943 gchar *server = NULL;
1945 while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
1947 if (g_strcmp0(key, "Timeservers") == 0) {
1948 GVariantIter *iter_sub = NULL;
1950 g_variant_get(value, "as", &iter_sub);
1951 if (!g_variant_iter_loop(iter_sub, "s", &server))
1952 NETWORK_LOG(NETWORK_ERROR, "No NTP Server");
1954 g_variant_iter_free(iter_sub);
1957 *ntp_server = g_strdup(server);
1961 g_variant_unref(value);
1967 __NETWORK_FUNC_EXIT__;
1970 static int __net_get_mesh_peers(network_info_t *network_info,
1971 const char *profile_name, net_profile_info_t *prof_info)
1973 __NETWORK_FUNC_ENTER__;
1975 net_err_t Error = NET_ERR_NO_SERVICE;
1976 GVariant *message = NULL;
1977 GVariantIter *iter = NULL;
1978 GVariantIter *service = NULL;
1981 /* Check if mesh profile exists */
1982 message = _net_invoke_dbus_method(network_info,
1983 CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
1984 CONNMAN_MANAGER_INTERFACE, "GetmeshPeers", NULL, &Error);
1985 if (message == NULL) {
1986 NETWORK_LOG(NETWORK_ERROR, "Failed to get mesh peers");
1989 g_variant_get(message, "(a(oa{sv}))", &iter);
1990 while (g_variant_iter_loop(iter, "(oa{sv})", &path, &service)) {
1991 if (g_strcmp0(profile_name, path) == 0) {
1992 Error = _net_extract_service_info(network_info,
1993 profile_name, service, prof_info);
1994 g_variant_iter_free(service);
2000 g_variant_iter_free(iter);
2001 g_variant_unref(message);
2003 __NETWORK_FUNC_EXIT__;
2007 static int __net_get_profile_info(network_info_t *network_info,
2008 const char *profile_name, net_profile_info_t *prof_info)
2010 __NETWORK_FUNC_ENTER__;
2012 net_err_t Error = NET_ERR_NONE;
2013 GVariant *message = NULL;
2014 GVariantIter *service = NULL;
2016 message = _net_invoke_dbus_method(network_info,
2017 CONNMAN_SERVICE, profile_name,
2018 CONNMAN_SERVICE_INTERFACE, "GetProperties", NULL,
2020 if (message == NULL) {
2021 NETWORK_LOG(NETWORK_LOW, "Failed to get profile, check for mesh peers");
2022 __NETWORK_FUNC_EXIT__;
2023 return __net_get_mesh_peers(network_info, profile_name, prof_info);
2026 g_variant_get(message, "(a{sv})", &service);
2027 Error = _net_extract_service_info(network_info, profile_name,
2028 service, prof_info);
2029 g_variant_iter_free(service);
2030 g_variant_unref(message);
2032 __NETWORK_FUNC_EXIT__;
2036 static int __net_set_default_cellular_service_profile_sync(network_info_t *network_info,
2037 const char *profile_name)
2039 __NETWORK_FUNC_ENTER__;
2041 net_err_t Error = NET_ERR_NONE;
2042 GVariant *message = NULL;
2043 net_profile_name_t telephony_profile;
2044 char connman_profile[NET_PROFILE_NAME_LEN_MAX+1] = "";
2046 g_strlcpy(connman_profile, profile_name, NET_PROFILE_NAME_LEN_MAX+1);
2048 Error = __net_telephony_search_pdp_profile(network_info, connman_profile, &telephony_profile);
2049 if (Error != NET_ERR_NONE) {
2050 NETWORK_LOG(NETWORK_ERROR, "__net_telephony_search_pdp_profile() failed");
2051 __NETWORK_FUNC_EXIT__;
2055 message = _net_invoke_dbus_method(network_info,
2056 TELEPHONY_SERVICE, telephony_profile.profile_name,
2057 TELEPHONY_PROFILE_INTERFACE, "SetDefaultConnection", NULL, &Error);
2058 if (message == NULL) {
2059 NETWORK_LOG(NETWORK_ERROR, "Failed to set default cellular service(profile)");
2064 gboolean result = FALSE;
2066 g_variant_get(message, "(b)", &result);
2067 NETWORK_LOG(NETWORK_HIGH, "Set default cellular profile result: %d", result);
2070 Error = NET_ERR_NONE;
2072 Error = NET_ERR_UNKNOWN;
2074 g_variant_unref(message);
2077 __NETWORK_FUNC_EXIT__;
2082 static int __net_set_default_cellular_service_profile_async(network_info_t *network_info,
2083 const char *profile_name)
2085 __NETWORK_FUNC_ENTER__;
2087 net_err_t Error = NET_ERR_NONE;
2088 net_profile_name_t telephony_profile;
2089 char connman_profile[NET_PROFILE_NAME_LEN_MAX+1] = {0,};
2091 g_strlcpy(connman_profile, profile_name, NET_PROFILE_NAME_LEN_MAX+1);
2093 Error = __net_telephony_search_pdp_profile(network_info, connman_profile, &telephony_profile);
2094 if (Error != NET_ERR_NONE) {
2095 NETWORK_LOG(NETWORK_ERROR, "__net_telephony_search_pdp_profile() failed");
2096 __NETWORK_FUNC_EXIT__;
2100 Error = _net_dbus_set_default(network_info, telephony_profile.profile_name);
2102 __NETWORK_FUNC_EXIT__;
2106 static int __compare_and_set_passphrase(network_info_t *network_info,
2107 wlan_security_info_t *ex_security_info, wlan_security_info_t *security_info,
2108 const char *profile_name)
2110 net_err_t Error = NET_ERR_NONE;
2111 if (ex_security_info->sec_mode == WLAN_SEC_MODE_WEP) {
2112 if (g_strcmp0(security_info->authentication.wep.wep_key,
2113 ex_security_info->authentication.wep.wep_key) != 0) {
2114 /* ConnMan does not support modification of passphrase only,
2115 * you need to make a connection to update passphrase.
2117 Error = _net_dbus_set_agent_passphrase_and_connect(network_info,
2118 security_info->authentication.wep.wep_key, profile_name);
2120 } else if (ex_security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
2121 ex_security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) {
2122 if (g_strcmp0(security_info->authentication.psk.psk_key,
2123 ex_security_info->authentication.psk.psk_key) != 0) {
2124 /* ConnMan does not support modification of passphrase only,
2125 * you need to make a connection to update passphrase.
2127 Error = _net_dbus_set_agent_passphrase_and_connect(network_info,
2128 security_info->authentication.psk.psk_key, profile_name);
2130 } else if (ex_security_info->sec_mode == WLAN_SEC_MODE_SAE) {
2131 if (g_strcmp0(security_info->authentication.sae.sae_key,
2132 ex_security_info->authentication.sae.sae_key) != 0) {
2133 /* ConnMan does not support modification of passphrase only,
2134 * you need to make a connection to update passphrase.
2136 Error = _net_dbus_set_agent_passphrase_and_connect(network_info,
2137 security_info->authentication.sae.sae_key, profile_name);
2144 static int __compare_and_set_proxy(network_info_t *network_info,
2145 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2146 net_profile_info_t *prof_info, char *profilePath)
2148 net_err_t Error = NET_ERR_NONE;
2149 if ((ex_net_info->proxy_method != net_info->proxy_method) ||
2150 (g_strcmp0(ex_net_info->proxy_addr, net_info->proxy_addr) != 0)) {
2151 Error = _net_dbus_set_proxy(network_info, prof_info, profilePath);
2156 static int __compare_and_set_ipv4_addresses(network_info_t *network_info,
2157 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2158 net_profile_info_t *prof_info, char *profilePath)
2160 net_err_t Error = NET_ERR_NONE;
2161 if ((ex_net_info->ip_config_type != net_info->ip_config_type) ||
2162 (net_info->ip_config_type == NET_IP_CONFIG_TYPE_STATIC &&
2163 (net_info->ip_addr.data.Ipv4.s_addr !=
2164 ex_net_info->ip_addr.data.Ipv4.s_addr ||
2165 net_info->subnet_mask.data.Ipv4.s_addr !=
2166 ex_net_info->subnet_mask.data.Ipv4.s_addr ||
2167 net_info->gateway_addr.data.Ipv4.s_addr !=
2168 ex_net_info->gateway_addr.data.Ipv4.s_addr))) {
2169 Error = _net_dbus_set_profile_ipv4(network_info, prof_info, profilePath);
2174 static int __compare_and_set_ipv6_addresses(network_info_t *network_info,
2175 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2176 net_profile_info_t *prof_info, char *profilePath)
2178 net_err_t Error = NET_ERR_NONE;
2179 if ((ex_net_info->ip_config_type6 != net_info->ip_config_type6) ||
2180 (net_info->ip_config_type6 == NET_IP_CONFIG_TYPE_STATIC &&
2181 (net_info->ip_addr6.data.Ipv6.s6_addr != ex_net_info->ip_addr6.data.Ipv6.s6_addr ||
2182 net_info->prefix_len6 != ex_net_info->prefix_len6 ||
2183 net_info->gateway_addr6.data.Ipv6.s6_addr != ex_net_info->gateway_addr6.data.Ipv6.s6_addr))) {
2185 Error = _net_dbus_set_profile_ipv6(network_info, prof_info, profilePath);
2191 static int __compare_and_set_dns_addresses(network_info_t *network_info,
2192 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2193 net_profile_info_t *prof_info, char *profilePath)
2195 net_err_t Error = NET_ERR_NONE;
2197 for (i = 0; i < net_info->dns_count; i++) {
2198 if (i >= NET_DNS_ADDR_MAX) {
2199 net_info->dns_count = NET_DNS_ADDR_MAX;
2204 if (net_info->dns_addr[i].data.Ipv4.s_addr !=
2205 ex_net_info->dns_addr[i].data.Ipv4.s_addr)
2209 if (i < net_info->dns_count || ex_net_info->dns_config_type != net_info->dns_config_type)
2210 Error = _net_dbus_set_profile_dns(network_info, prof_info, profilePath);
2215 static int __compare_and_set_dns6_addresses(network_info_t *network_info,
2216 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2217 net_profile_info_t *prof_info, char *profilePath)
2219 net_err_t Error = NET_ERR_NONE;
2221 for (i = 0; i < net_info->dns_count6; i++) {
2222 if (i >= NET_DNS_ADDR_MAX) {
2223 net_info->dns_count = NET_DNS_ADDR_MAX;
2227 if (net_info->dns_addr6[i].Type == NET_ADDR_IPV6) {
2228 if (net_info->dns_addr6[i].data.Ipv6.s6_addr !=
2229 ex_net_info->dns_addr6[i].data.Ipv6.s6_addr)
2234 if (i < net_info->dns_count6 || ex_net_info->dns_config_type6 != net_info->dns_config_type6)
2235 Error = _net_dbus_set_profile_dns(network_info, prof_info, profilePath);
2240 static int __net_modify_wlan_profile_info(network_info_t *network_info,
2241 const char *profile_name, net_profile_info_t *prof_info, net_profile_info_t *exprof_info)
2243 __NETWORK_FUNC_ENTER__;
2245 net_err_t Error = NET_ERR_NONE;
2246 char profilePath[NET_PROFILE_NAME_LEN_MAX+1] = "";
2248 wlan_security_info_t *security_info =
2249 &(prof_info->profile_info.wlan.security_info);
2250 wlan_security_info_t *ex_security_info =
2251 &(exprof_info->profile_info.wlan.security_info);
2253 net_dev_info_t *net_info = &(prof_info->profile_info.wlan.net_info);
2254 net_dev_info_t *ex_net_info = &(exprof_info->profile_info.wlan.net_info);
2256 g_strlcpy(profilePath, profile_name, NET_PROFILE_NAME_LEN_MAX+1);
2258 Error = __compare_and_set_passphrase(network_info, ex_security_info, security_info, profile_name);
2259 if (Error != NET_ERR_NONE) {
2260 NETWORK_LOG(NETWORK_ERROR, "Failed to set agent field");
2261 __NETWORK_FUNC_EXIT__;
2265 Error = __compare_and_set_proxy(network_info, ex_net_info, net_info, prof_info, profilePath);
2266 if (Error != NET_ERR_NONE) {
2267 NETWORK_LOG(NETWORK_ERROR, "Failed to set proxy");
2268 __NETWORK_FUNC_EXIT__;
2272 Error = __compare_and_set_ipv4_addresses(network_info, ex_net_info, net_info, prof_info, profilePath);
2273 if (Error != NET_ERR_NONE) {
2274 NETWORK_LOG(NETWORK_ERROR, "Failed to set IPv4");
2275 __NETWORK_FUNC_EXIT__;
2279 Error = __compare_and_set_ipv6_addresses(network_info, ex_net_info, net_info, prof_info, profilePath);
2280 if (Error != NET_ERR_NONE) {
2281 NETWORK_LOG(NETWORK_ERROR, "Error!!! Can't set IPv6\n");
2282 __NETWORK_FUNC_EXIT__;
2286 Error = __compare_and_set_dns_addresses(network_info, ex_net_info, net_info, prof_info, profilePath);
2287 if (Error != NET_ERR_NONE) {
2288 NETWORK_LOG(NETWORK_ERROR, "Failed to set DNS\n");
2289 __NETWORK_FUNC_EXIT__;
2293 Error = __compare_and_set_dns6_addresses(network_info, ex_net_info, net_info, prof_info, profilePath);
2294 if (Error != NET_ERR_NONE) {
2295 NETWORK_LOG(NETWORK_ERROR, "Failed to set DNS6\n");
2296 __NETWORK_FUNC_EXIT__;
2300 __NETWORK_FUNC_EXIT__;
2301 return NET_ERR_NONE;
2304 static int __net_wifi_delete_profile(network_info_t *network_info,
2305 net_profile_name_t *WifiProfName, wlan_security_mode_type_t sec_mode, gboolean passpoint)
2307 __NETWORK_FUNC_ENTER__;
2309 net_err_t Error = NET_ERR_NONE;
2310 GVariant *message = NULL;
2311 char param0[NET_PROFILE_NAME_LEN_MAX + 8] = "";
2314 if (passpoint == TRUE && WLAN_SEC_MODE_IEEE8021X == sec_mode) {
2315 message = _net_invoke_dbus_method(network_info,
2317 WifiProfName->profile_name,
2318 CONNMAN_SERVICE_INTERFACE, "Remove", NULL,
2321 if (message == NULL) {
2322 NETWORK_LOG(NETWORK_ERROR, "Failed to Remove service(profile)");
2323 g_variant_unref(message);
2327 g_variant_unref(message);
2329 g_snprintf(param0, NET_PROFILE_NAME_LEN_MAX + 8, "string:%s",
2330 WifiProfName->profile_name);
2331 params = g_variant_new("(s)", param0);
2333 message = _net_invoke_dbus_method(network_info,
2335 NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE,
2336 "DeleteEapConfig", params, &Error);
2337 } else if (passpoint == TRUE || WLAN_SEC_MODE_IEEE8021X != sec_mode) {
2338 message = _net_invoke_dbus_method(network_info,
2340 WifiProfName->profile_name,
2341 CONNMAN_SERVICE_INTERFACE, "Remove", NULL,
2344 g_snprintf(param0, NET_PROFILE_NAME_LEN_MAX + 8, "string:%s",
2345 WifiProfName->profile_name);
2346 params = g_variant_new("(s)", param0);
2348 message = _net_invoke_dbus_method(network_info,
2350 NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE,
2351 "DeleteEapConfig", params, &Error);
2354 if (message == NULL) {
2355 NETWORK_LOG(NETWORK_ERROR, "Failed to Remove service(profile)");
2359 g_variant_unref(message);
2361 __NETWORK_FUNC_EXIT__;
2365 static int __net_modify_mesh_profile(network_info_t *network_info,
2366 const char *profile_name, net_profile_info_t *prof_info, net_profile_info_t *exprof_info)
2368 __NETWORK_FUNC_ENTER__;
2370 net_err_t Error = NET_ERR_NONE;
2371 char profilePath[NET_PROFILE_NAME_LEN_MAX+1] = "";
2373 wlan_security_info_t *security_info =
2374 &(prof_info->profile_info.mesh.security_info);
2375 wlan_security_info_t *ex_security_info =
2376 &(exprof_info->profile_info.mesh.security_info);
2378 g_strlcpy(profilePath, profile_name, NET_PROFILE_NAME_LEN_MAX+1);
2380 /* Compare and Set 'Passphrase' */
2381 if (ex_security_info->sec_mode == WLAN_SEC_MODE_SAE) {
2382 if (g_strcmp0(security_info->authentication.sae.sae_key,
2383 ex_security_info->authentication.sae.sae_key) != 0) {
2384 /* ConnMan does not support modification of passphrase only,
2385 * you need to make a connection to update passphrase.
2387 Error = _net_dbus_set_mesh_property(network_info,
2388 profilePath, "Passphrase",
2389 security_info->authentication.sae.sae_key);
2391 if (NET_ERR_NONE != Error) {
2392 NETWORK_LOG(NETWORK_ERROR, "Failed to set Mesh property");
2394 __NETWORK_FUNC_EXIT__;
2400 __NETWORK_FUNC_EXIT__;
2401 return NET_ERR_NONE;
2404 static int __net_mesh_delete_profile(network_info_t *network_info, const char *profile_name)
2406 __NETWORK_FUNC_ENTER__;
2408 net_err_t Error = NET_ERR_NONE;
2409 GVariant *message = NULL;
2411 message = _net_invoke_dbus_method(network_info,
2412 CONNMAN_SERVICE, profile_name,
2413 CONNMAN_MESH_INTERFACE, "Remove", NULL, &Error);
2414 if (message == NULL) {
2415 NETWORK_LOG(NETWORK_ERROR, "Failed to Remove mesh(profile)");
2419 g_variant_unref(message);
2422 __NETWORK_FUNC_EXIT__;
2426 static int __net_telephony_add_profile(network_info_t *network_info,
2427 net_profile_info_t *prof_info, net_service_type_t network_type)
2429 __NETWORK_FUNC_ENTER__;
2431 net_err_t Error = NET_ERR_NONE;
2433 prof_info->profile_info.pdp.service_type = network_type;
2435 Error = _net_dbus_add_pdp_profile(network_info, prof_info);
2436 if (Error != NET_ERR_NONE) {
2437 NETWORK_LOG(NETWORK_ERROR, "_net_dbus_add_pdp_profile() failed");
2438 __NETWORK_FUNC_EXIT__;
2442 __NETWORK_FUNC_EXIT__;
2443 return NET_ERR_NONE;
2446 static int __net_telephony_modify_profile(network_info_t *network_info,
2447 const char *profile_name, net_profile_info_t *prof_info, net_profile_info_t *exprof_info)
2449 __NETWORK_FUNC_ENTER__;
2451 net_err_t Error = NET_ERR_NONE;
2452 net_profile_name_t telephony_profile;
2453 char connman_profile[NET_PROFILE_NAME_LEN_MAX+1] = "";
2455 if (_net_is_valid_service_type(exprof_info->profile_info.pdp.service_type) == FALSE) {
2456 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
2457 __NETWORK_FUNC_EXIT__;
2458 return NET_ERR_INVALID_PARAM;
2461 g_strlcpy(connman_profile, profile_name, NET_PROFILE_NAME_LEN_MAX+1);
2462 prof_info->profile_info.pdp.service_type = exprof_info->profile_info.pdp.service_type;
2464 Error = __net_telephony_search_pdp_profile(network_info, connman_profile, &telephony_profile);
2465 if (Error != NET_ERR_NONE) {
2466 NETWORK_LOG(NETWORK_ERROR, "__net_telephony_search_pdp_profile() failed");
2467 __NETWORK_FUNC_EXIT__;
2471 Error = _net_dbus_modify_pdp_profile(network_info, prof_info, telephony_profile.profile_name);
2472 if (Error != NET_ERR_NONE) {
2473 NETWORK_LOG(NETWORK_ERROR, "_net_dbus_modify_pdp_profile() failed");
2474 __NETWORK_FUNC_EXIT__;
2478 __NETWORK_FUNC_EXIT__;
2483 static int __net_modify_ethernet_profile(network_info_t *network_info,
2484 const char *profile_name, net_profile_info_t *prof_info, net_profile_info_t *exprof_info)
2486 __NETWORK_FUNC_ENTER__;
2488 net_err_t Error = NET_ERR_NONE;
2491 char profilePath[NET_PROFILE_NAME_LEN_MAX+1] = "";
2493 net_dev_info_t *net_info = &(prof_info->profile_info.ethernet.net_info);
2494 net_dev_info_t *ex_net_info = &(exprof_info->profile_info.ethernet.net_info);
2496 g_strlcpy(profilePath, profile_name, NET_PROFILE_NAME_LEN_MAX+1);
2498 /* Compare and Set 'Proxy' */
2499 NETWORK_LOG(NETWORK_HIGH, "Proxy old:%d %s, new:%d %s\n",
2500 ex_net_info->proxy_method,
2501 ex_net_info->proxy_addr,
2502 net_info->proxy_method,
2503 net_info->proxy_addr);
2505 if ((ex_net_info->proxy_method != net_info->proxy_method) ||
2506 (g_strcmp0(ex_net_info->proxy_addr, net_info->proxy_addr) != 0)) {
2508 Error = _net_dbus_set_proxy(network_info, prof_info, profilePath);
2510 if (Error != NET_ERR_NONE) {
2511 __NETWORK_FUNC_EXIT__;
2516 /* Compare and Set 'IPv4 addresses' */
2517 char ip_buffer[NETPM_IPV4_STR_LEN_MAX+1] = "";
2518 char netmask_buffer[NETPM_IPV4_STR_LEN_MAX+1] = "";
2519 char gateway_buffer[NETPM_IPV4_STR_LEN_MAX+1] = "";
2520 g_strlcpy(ip_buffer,
2521 inet_ntoa(ex_net_info->ip_addr.data.Ipv4),
2522 NETPM_IPV4_STR_LEN_MAX + 1);
2524 g_strlcpy(netmask_buffer,
2525 inet_ntoa(ex_net_info->subnet_mask.data.Ipv4),
2526 NETPM_IPV4_STR_LEN_MAX + 1);
2528 g_strlcpy(gateway_buffer,
2529 inet_ntoa(ex_net_info->gateway_addr.data.Ipv4),
2530 NETPM_IPV4_STR_LEN_MAX + 1);
2532 NETWORK_LOG(NETWORK_HIGH, "IPv4 info old: type %d, IP: %s, netmask:"
2533 " %s, gateway: %s\n", ex_net_info->ip_config_type,
2538 g_strlcpy(ip_buffer,
2539 inet_ntoa(net_info->ip_addr.data.Ipv4),
2540 NETPM_IPV4_STR_LEN_MAX + 1);
2542 g_strlcpy(netmask_buffer,
2543 inet_ntoa(net_info->subnet_mask.data.Ipv4),
2544 NETPM_IPV4_STR_LEN_MAX + 1);
2546 g_strlcpy(gateway_buffer,
2547 inet_ntoa(net_info->gateway_addr.data.Ipv4),
2548 NETPM_IPV4_STR_LEN_MAX + 1);
2550 NETWORK_LOG(NETWORK_HIGH, "IPv4 info new: type %d, IP: %s, netmask:"
2551 " %s, gateway: %s\n", net_info->ip_config_type,
2556 if ((ex_net_info->ip_config_type != net_info->ip_config_type) ||
2557 (net_info->ip_config_type == NET_IP_CONFIG_TYPE_STATIC &&
2558 (net_info->ip_addr.data.Ipv4.s_addr
2559 != ex_net_info->ip_addr.data.Ipv4.s_addr ||
2560 net_info->subnet_mask.data.Ipv4.s_addr
2561 != ex_net_info->subnet_mask.data.Ipv4.s_addr ||
2562 net_info->gateway_addr.data.Ipv4.s_addr
2563 != ex_net_info->gateway_addr.data.Ipv4.s_addr))) {
2564 Error = _net_dbus_set_profile_ipv4(network_info, prof_info, profilePath);
2566 if (Error != NET_ERR_NONE) {
2567 NETWORK_LOG(NETWORK_ERROR, "Failed to set IPv4");
2569 __NETWORK_FUNC_EXIT__;
2573 /* Compare and Set 'DNS addresses' */
2574 for (i = 0; i < net_info->dns_count; i++) {
2575 if (i >= NET_DNS_ADDR_MAX) {
2576 net_info->dns_count = NET_DNS_ADDR_MAX;
2580 if (net_info->dns_addr[i].Type == NET_ADDR_IPV4) {
2581 char old_dns[NETPM_IPV4_STR_LEN_MAX+1] = "";
2582 char new_dns[NETPM_IPV4_STR_LEN_MAX+1] = "";
2584 inet_ntoa(ex_net_info->dns_addr[i].data.Ipv4),
2585 NETPM_IPV4_STR_LEN_MAX+1);
2587 inet_ntoa(net_info->dns_addr[i].data.Ipv4),
2588 NETPM_IPV4_STR_LEN_MAX+1);
2590 NETWORK_LOG(NETWORK_HIGH, "IPv4 DNS Addr order: %d, old:"
2591 "%s, new: %s", i, old_dns, new_dns);
2593 if (net_info->dns_addr[i].data.Ipv4.s_addr !=
2594 ex_net_info->dns_addr[i].data.Ipv4.s_addr)
2600 char ipaddr6_old[INET6_ADDRSTRLEN];
2601 char ipaddr6_new[INET6_ADDRSTRLEN];
2603 for (j = 0; j < net_info->dns_count6; j++) {
2604 if (j >= NET_DNS_ADDR_MAX) {
2605 net_info->dns_count6 = NET_DNS_ADDR_MAX;
2610 if (net_info->dns_addr6[j].Type == NET_ADDR_IPV6) {
2611 inet_ntop(AF_INET6, &ex_net_info->dns_addr6[j].data.Ipv6,
2612 ipaddr6_old, INET6_ADDRSTRLEN);
2613 inet_ntop(AF_INET6, &net_info->dns_addr6[j].data.Ipv6,
2614 ipaddr6_new, INET6_ADDRSTRLEN);
2615 NETWORK_LOG(NETWORK_HIGH, "IPv6 DNS Addr order: %d, "
2616 "old: %s, new: %s", j, ipaddr6_old,
2619 if (net_info->dns_addr6[j].data.Ipv6.s6_addr !=
2620 ex_net_info->dns_addr6[j].data.Ipv6.s6_addr)
2625 if (i < net_info->dns_count || j < net_info->dns_count6 ||
2626 ex_net_info->dns_config_type != net_info->dns_config_type ||
2627 ex_net_info->dns_config_type6 != net_info->dns_config_type6) {
2628 Error = _net_dbus_set_profile_dns(network_info, prof_info, profilePath);
2630 if (Error != NET_ERR_NONE) {
2631 NETWORK_LOG(NETWORK_ERROR, "Failed to set DNS");
2633 __NETWORK_FUNC_EXIT__;
2638 __NETWORK_FUNC_EXIT__;
2639 return NET_ERR_NONE;
2642 static int __net_telephony_delete_profile(network_info_t *network_info,
2643 net_profile_name_t *PdpProfName)
2645 __NETWORK_FUNC_ENTER__;
2647 net_err_t Error = NET_ERR_NONE;
2648 GVariant *message = NULL;
2650 message = _net_invoke_dbus_method(network_info,
2651 TELEPHONY_SERVICE, PdpProfName->profile_name,
2652 TELEPHONY_PROFILE_INTERFACE, "RemoveProfile", NULL, &Error);
2653 if (message == NULL) {
2654 NETWORK_LOG(NETWORK_ERROR, "Failed to Remove service(profile)");
2659 gboolean remove_result = FALSE;
2661 g_variant_get(message, "(b)", &remove_result);
2662 NETWORK_LOG(NETWORK_HIGH, "Profile remove result: %d", remove_result);
2665 Error = NET_ERR_NONE;
2667 Error = NET_ERR_UNKNOWN;
2669 g_variant_unref(message);
2672 __NETWORK_FUNC_EXIT__;
2676 static gboolean __net_is_cellular_default_candidate(const char *profile)
2678 /* This profile should be cellular type */
2679 const char net_suffix[] = "_1";
2680 const char pre_net_suffix[] = "_3";
2681 const char tethering_suffix[] = "_5";
2684 suffix = strrchr(profile, '_');
2686 if (g_strcmp0(suffix, net_suffix) == 0 ||
2687 g_strcmp0(suffix, pre_net_suffix) == 0 ||
2688 g_strcmp0(suffix, tethering_suffix) == 0)
2694 static int __net_extract_default_profile(network_info_t *network_info,
2695 GVariant *message, net_profile_info_t *ProfilePtr)
2697 net_err_t Error = NET_ERR_NONE;
2698 net_device_t device_type;
2699 gchar *obj_path = NULL;
2700 GVariantIter *iter = NULL;
2702 __NETWORK_FUNC_ENTER__;
2704 if (message == NULL || ProfilePtr == NULL) {
2705 NETWORK_LOG(NETWORK_ERROR, "Invalid parameter");
2706 __NETWORK_FUNC_EXIT__;
2707 return NET_ERR_INVALID_PARAM;
2710 if (!g_variant_is_of_type(message, G_VARIANT_TYPE("(oa{sv})"))) {
2711 NETWORK_LOG(NETWORK_ERROR, "There is no default service");
2712 __NETWORK_FUNC_EXIT__;
2713 return NET_ERR_NO_SERVICE;
2716 g_variant_get(message, "(oa{sv})", &obj_path, &iter);
2718 if (g_str_has_prefix(obj_path, CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX) == TRUE)
2719 device_type = NET_DEVICE_CELLULAR;
2720 else if (g_str_has_prefix(obj_path, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) == TRUE)
2721 device_type = NET_DEVICE_WIFI;
2722 else if (g_str_has_prefix(obj_path, CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX) == TRUE)
2723 device_type = NET_DEVICE_ETHERNET;
2724 else if (g_str_has_prefix(obj_path, CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX) == TRUE)
2725 device_type = NET_DEVICE_BLUETOOTH;
2726 else if (g_str_has_prefix(obj_path, CONNMAN_MESH_PROFILE_PREFIX) == TRUE)
2727 device_type = NET_DEVICE_MESH;
2729 Error = NET_ERR_NO_SERVICE;
2730 g_variant_iter_free(iter);
2731 __NETWORK_FUNC_EXIT__;
2735 Error = __net_pm_init_profile_info(device_type, ProfilePtr);
2736 if (Error != NET_ERR_NONE) {
2737 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
2738 g_variant_iter_free(iter);
2739 __NETWORK_FUNC_EXIT__;
2743 ProfilePtr->profile_type = device_type;
2744 g_strlcpy(ProfilePtr->profile_name, obj_path, NET_PROFILE_NAME_LEN_MAX);
2746 if (device_type == NET_DEVICE_CELLULAR &&
2747 __net_is_cellular_default_candidate(obj_path) == TRUE) {
2748 g_strlcpy(ProfilePtr->profile_info.pdp.net_info.profile_name,
2749 obj_path, NET_PROFILE_NAME_LEN_MAX);
2751 Error = __net_extract_mobile_info(network_info, iter, ProfilePtr);
2752 } else if (device_type == NET_DEVICE_WIFI) {
2753 g_strlcpy(ProfilePtr->profile_info.wlan.net_info.profile_name,
2754 obj_path, NET_PROFILE_NAME_LEN_MAX);
2756 Error = __net_extract_wifi_info(iter, ProfilePtr);
2757 } else if (device_type == NET_DEVICE_ETHERNET) {
2758 g_strlcpy(ProfilePtr->profile_info.ethernet.net_info.profile_name,
2759 obj_path, NET_PROFILE_NAME_LEN_MAX);
2761 Error = __net_extract_ethernet_info(iter, ProfilePtr);
2762 } else if (device_type == NET_DEVICE_BLUETOOTH) {
2763 g_strlcpy(ProfilePtr->profile_info.bluetooth.net_info.profile_name,
2764 obj_path, NET_PROFILE_NAME_LEN_MAX);
2766 Error = __net_extract_bluetooth_info(iter, ProfilePtr);
2767 } else if (device_type == NET_DEVICE_MESH) {
2768 g_strlcpy(ProfilePtr->profile_info.mesh.net_info.profile_name,
2769 obj_path, NET_PROFILE_NAME_LEN_MAX);
2771 Error = __net_extract_mesh_info(iter, ProfilePtr);
2774 if (Error != NET_ERR_NONE) {
2775 g_variant_iter_free(iter);
2776 __NETWORK_FUNC_EXIT__;
2780 NETWORK_LOG(NETWORK_HIGH, "Default: %s", ProfilePtr->profile_name);
2782 g_variant_iter_free(iter);
2785 __NETWORK_FUNC_EXIT__;
2788 /* LCOV_EXCL_STOP */
2790 int _net_check_profile_name(const char *profile_name)
2792 __NETWORK_FUNC_ENTER__;
2794 const char *profileHeader = CONNMAN_PATH"/service/";
2795 const char *meshProfileHeader = CONNMAN_PATH"/mesh/";
2799 if (profile_name == NULL || strlen(profile_name) <= strlen(profileHeader)) {
2800 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid");
2801 __NETWORK_FUNC_EXIT__;
2802 return NET_ERR_INVALID_PARAM;
2805 stringLen = strlen(profile_name);
2807 if (strncmp(profileHeader, profile_name, strlen(profileHeader)) == 0) {
2808 for (i = 0; i < stringLen; i++) {
2809 /* LCOV_EXCL_START */
2810 if (isgraph(profile_name[i]) == 0) {
2811 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid");
2812 __NETWORK_FUNC_EXIT__;
2813 return NET_ERR_INVALID_PARAM;
2816 } else if (strncmp(meshProfileHeader, profile_name,
2817 strlen(meshProfileHeader)) == 0) {
2818 for (i = 0; i < stringLen; i++) {
2819 if (isgraph(profile_name[i]) == 0) {
2820 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid");
2821 __NETWORK_FUNC_EXIT__;
2822 return NET_ERR_INVALID_PARAM;
2826 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid");
2827 __NETWORK_FUNC_EXIT__;
2828 return NET_ERR_INVALID_PARAM;
2830 /* LCOV_EXCL_STOP */
2832 __NETWORK_FUNC_EXIT__;
2833 return NET_ERR_NONE;
2836 int _net_get_profile_list(network_info_t *network_info, net_device_t device_type,
2837 net_profile_info_t **profile_info, int *profile_count)
2839 __NETWORK_FUNC_ENTER__;
2841 net_err_t Error = NET_ERR_NONE;
2845 if (device_type == NET_DEVICE_MESH) {
2846 /* LCOV_EXCL_START */
2847 net_cm_network_status_t status = NET_STATUS_UNKNOWN;
2849 net_get_network_status(network_info, device_type, &status);
2850 if (status != NET_STATUS_AVAILABLE)
2851 return NET_ERR_NONE;
2853 message = _net_invoke_dbus_method(network_info, CONNMAN_SERVICE,
2854 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
2855 "GetMeshPeers", NULL, &Error);
2856 if (message == NULL) {
2857 NETWORK_LOG(NETWORK_ERROR, "Failed to get Mesh Peers list");
2858 __NETWORK_FUNC_EXIT__;
2861 /* LCOV_EXCL_STOP */
2863 message = _net_invoke_dbus_method(network_info, CONNMAN_SERVICE,
2864 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
2865 "GetServices", NULL, &Error);
2866 /* LCOV_EXCL_START */
2867 if (message == NULL) {
2868 NETWORK_LOG(NETWORK_ERROR, "Failed to get service(profile) list");
2869 __NETWORK_FUNC_EXIT__;
2872 /* LCOV_EXCL_STOP */
2875 switch (device_type) {
2876 case NET_DEVICE_CELLULAR:
2877 case NET_DEVICE_WIFI:
2878 case NET_DEVICE_ETHERNET:
2879 case NET_DEVICE_BLUETOOTH:
2880 case NET_DEVICE_MESH:
2881 g_variant_get(message, "(a(oa{sv}))", &iter);
2882 Error = __net_extract_services(network_info, iter,
2883 device_type, profile_info, profile_count);
2886 g_variant_iter_free(iter);
2890 /* LCOV_EXCL_START */
2891 Error = NET_ERR_UNKNOWN;
2893 /* LCOV_EXCL_STOP */
2896 g_variant_unref(message);
2898 __NETWORK_FUNC_EXIT__;
2902 int _net_extract_services(network_info_t *network_info, net_device_t device_type,
2903 net_profile_info_t **profile_info, int *profile_count, GVariant *message)
2905 net_err_t Error = NET_ERR_NONE;
2908 g_variant_get(message, "(a(oa{sv}))", &iter);
2910 Error = __net_extract_services(network_info, iter,
2911 device_type, profile_info, profile_count);
2914 g_variant_iter_free(iter);
2919 int _net_get_all_profile_list(network_info_t *network_info,
2920 net_profile_info_t **profile_info, int *profile_count)
2922 __NETWORK_FUNC_ENTER__;
2924 net_err_t Error = NET_ERR_NONE;
2925 GVariant *message = NULL;
2926 GVariant *mesh_message = NULL;
2927 int cellular_cnt = 0;
2929 int ethernet_cnt = 0;
2930 int bluetooth_cnt = 0;
2932 net_profile_info_t *cellular_profiles = NULL;
2933 net_profile_info_t *wifi_profiles = NULL;
2934 net_profile_info_t *ethernet_profiles = NULL;
2935 net_profile_info_t *bluetooth_profiles = NULL;
2936 net_profile_info_t *mesh_profiles = NULL;
2937 net_profile_info_t *profiles = NULL;
2938 net_cm_network_status_t status = NET_STATUS_UNKNOWN;
2940 message = _net_invoke_dbus_method(network_info, CONNMAN_SERVICE,
2941 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
2942 "GetServices", NULL, &Error);
2943 /* LCOV_EXCL_START */
2944 if (message == NULL) {
2945 NETWORK_LOG(NETWORK_ERROR, "Failed to get service(profile) list");
2946 __NETWORK_FUNC_EXIT__;
2949 /* LCOV_EXCL_STOP */
2953 Error = _net_extract_services(network_info, NET_DEVICE_CELLULAR,
2954 &cellular_profiles, &cellular_cnt, message);
2955 if (Error != NET_ERR_NONE)
2958 NETWORK_LOG(NETWORK_LOW, "Cellular profile count: %d", cellular_cnt);
2959 *profile_count += cellular_cnt;
2961 Error = _net_extract_services(network_info, NET_DEVICE_WIFI,
2962 &wifi_profiles, &wifi_cnt, message);
2963 if (Error != NET_ERR_NONE)
2966 NETWORK_LOG(NETWORK_LOW, "Wi-Fi profile count: %d", wifi_cnt);
2967 *profile_count += wifi_cnt;
2969 Error = _net_extract_services(network_info, NET_DEVICE_ETHERNET,
2970 ðernet_profiles, ðernet_cnt, message);
2971 if (Error != NET_ERR_NONE)
2974 NETWORK_LOG(NETWORK_LOW, "Ethernet profile count: %d", ethernet_cnt);
2975 *profile_count += ethernet_cnt;
2977 Error = _net_extract_services(network_info, NET_DEVICE_BLUETOOTH,
2978 &bluetooth_profiles, &bluetooth_cnt, message);
2979 if (Error != NET_ERR_NONE)
2982 NETWORK_LOG(NETWORK_LOW, "Bluetooth profile count: %d", bluetooth_cnt);
2983 *profile_count += bluetooth_cnt;
2985 /* LCOV_EXCL_START */
2986 net_get_network_status(network_info, NET_DEVICE_MESH, &status);
2987 if (status == NET_STATUS_AVAILABLE) {
2988 mesh_message = _net_invoke_dbus_method(network_info, CONNMAN_SERVICE,
2989 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
2990 "GetMeshPeers", NULL, &Error);
2991 if (mesh_message == NULL) {
2992 NETWORK_LOG(NETWORK_ERROR, "Failed to get Mesh Peers list");
2993 NET_MEMFREE(cellular_profiles);
2994 NET_MEMFREE(wifi_profiles);
2995 NET_MEMFREE(ethernet_profiles);
2996 NET_MEMFREE(bluetooth_profiles);
2997 __NETWORK_FUNC_EXIT__;
3001 Error = _net_extract_services(network_info, NET_DEVICE_MESH,
3002 &mesh_profiles, &mesh_cnt, mesh_message);
3003 if (Error != NET_ERR_NONE)
3006 NETWORK_LOG(NETWORK_LOW, "Mesh profile count: %d", mesh_cnt);
3007 *profile_count += mesh_cnt;
3009 /* LCOV_EXCL_STOP */
3011 if (*profile_count > 0) {
3012 profiles = g_try_new0(net_profile_info_t, *profile_count);
3014 *profile_info = profiles;
3015 if (cellular_cnt > 0) {
3016 memcpy(profiles, cellular_profiles,
3017 sizeof(net_profile_info_t) * cellular_cnt);
3018 profiles += cellular_cnt;
3022 memcpy(profiles, wifi_profiles,
3023 sizeof(net_profile_info_t) * wifi_cnt);
3024 profiles += wifi_cnt;
3027 if (ethernet_cnt > 0) {
3028 memcpy(profiles, ethernet_profiles,
3029 sizeof(net_profile_info_t) * ethernet_cnt);
3030 profiles += ethernet_cnt;
3033 if (bluetooth_cnt > 0) {
3034 memcpy(profiles, bluetooth_profiles,
3035 sizeof(net_profile_info_t) * bluetooth_cnt);
3036 profiles += bluetooth_cnt;
3040 memcpy(profiles, mesh_profiles,
3041 sizeof(net_profile_info_t) * mesh_cnt);
3047 if (message != NULL)
3048 g_variant_unref(message);
3050 if (mesh_message != NULL)
3051 g_variant_unref(mesh_message);
3053 NET_MEMFREE(cellular_profiles);
3054 NET_MEMFREE(wifi_profiles);
3055 NET_MEMFREE(ethernet_profiles);
3056 NET_MEMFREE(bluetooth_profiles);
3057 NET_MEMFREE(mesh_profiles);
3059 __NETWORK_FUNC_EXIT__;
3063 /* LCOV_EXCL_START */
3064 int _net_get_default_profile_info(network_info_t *network_info,
3065 net_profile_info_t *profile_info)
3067 net_err_t Error = NET_ERR_NONE;
3068 GVariant *message = NULL;
3070 __NETWORK_FUNC_ENTER__;
3072 message = _net_invoke_dbus_method(network_info,
3073 CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
3074 CONNMAN_MANAGER_INTERFACE, "GetDefaultService", NULL, &Error);
3075 if (message == NULL) {
3076 NETWORK_LOG(NETWORK_ERROR, "Failed to get profile list");
3077 __NETWORK_FUNC_EXIT__;
3081 Error = __net_extract_default_profile(network_info, message, profile_info);
3083 g_variant_unref(message);
3085 __NETWORK_FUNC_EXIT__;
3089 static int __net_telephony_reset_profile(network_info_t *network_info, int type, int sim_id)
3091 __NETWORK_FUNC_ENTER__;
3093 net_err_t Error = NET_ERR_NONE;
3094 char subscriber_id[3];
3096 GSList *ModemPathList = NULL;
3097 const char *path = NULL;
3098 GSList *list = NULL;
3100 Error = __net_telephony_get_modem_object_path(network_info, &ModemPathList);
3101 if (Error != NET_ERR_NONE) {
3102 NETWORK_LOG(NETWORK_ERROR, "Failed to get modems path list");
3103 g_slist_free_full(ModemPathList, g_free);
3104 __NETWORK_FUNC_EXIT__;
3108 g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", sim_id);
3110 for (list = ModemPathList; list != NULL; list = list->next) {
3111 path = (const char *)list->data;
3113 if (g_str_has_suffix(path, subscriber_id) == TRUE) {
3114 Error = _net_dbus_reset_pdp_profile(network_info, type, path);
3115 if (Error != NET_ERR_NONE) {
3116 NETWORK_LOG(NETWORK_HIGH, "_net_dbus_reset_pdp_profile() failed");
3122 g_slist_free_full(ModemPathList, g_free);
3124 __NETWORK_FUNC_EXIT__;
3125 return NET_ERR_NONE;
3128 static int __net_convert_string_to_ipv6_string(char *str, char **ip_address)
3131 struct sockaddr_in6 sa;
3132 char conv_str[INET6_ADDRSTRLEN] = {0,};
3134 *ip_address = (char *)malloc(INET6_ADDRSTRLEN);
3135 if (NULL == *ip_address) {
3136 NETWORK_LOG(NETWORK_ERROR, "Malloc Failed");
3137 return NET_ERR_INVALID_OPERATION;
3140 /* Convert String without : to string with : */
3141 for (int i = 0; i < 8; i++) {
3144 conv_str[pos + i - 1] = ':';
3145 memcpy(conv_str + pos + i, str + pos, 4);
3149 * Convert "fe80:0000:0000:0000:0a00:27ff:fe7a:65ea to fe80::a00:27ff:fe7a:65ea
3151 inet_pton(AF_INET6, conv_str, &(sa.sin6_addr));
3152 inet_ntop(AF_INET6, &(sa.sin6_addr), *ip_address, INET6_ADDRSTRLEN);
3154 return NET_ERR_NONE;
3158 EXPORT_API int net_reset_profile(void *handle, int type, int sim_id)
3160 net_err_t Error = NET_ERR_NONE;
3161 network_info_t *network_info = (network_info_t *)handle;
3163 __NETWORK_FUNC_ENTER__;
3165 if (network_info->request_table[NETWORK_REQUEST_TYPE_RESET_DEFAULT].flag == TRUE) {
3166 NETWORK_LOG(NETWORK_ERROR, "Error!! Request already in progress");
3167 __NETWORK_FUNC_EXIT__;
3168 return NET_ERR_IN_PROGRESS;
3171 network_info->request_table[NETWORK_REQUEST_TYPE_RESET_DEFAULT].flag = TRUE;
3173 Error = __net_telephony_reset_profile(network_info, type, sim_id);
3174 if (Error != NET_ERR_NONE) {
3175 NETWORK_LOG(NETWORK_ERROR,
3176 "Failed to reset service(profile). Error [%s]",
3177 _net_print_error(Error));
3178 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_RESET_DEFAULT]),
3179 0, sizeof(network_request_table_t));
3180 __NETWORK_FUNC_EXIT__;
3184 __NETWORK_FUNC_EXIT__;
3187 /* LCOV_EXCL_STOP */
3190 /*****************************************************************************
3191 * ConnMan Wi-Fi Client Interface Sync API Definition
3192 *****************************************************************************/
3193 EXPORT_API int net_add_profile(void *handle, net_service_type_t network_type, net_profile_info_t *prof_info)
3195 net_err_t Error = NET_ERR_NONE;
3196 network_info_t *network_info = (network_info_t *)handle;
3198 __NETWORK_FUNC_ENTER__;
3200 if (prof_info == NULL || _net_is_valid_service_type(network_type) == FALSE) {
3201 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3202 __NETWORK_FUNC_EXIT__;
3203 return NET_ERR_INVALID_PARAM;
3206 /* LCOV_EXCL_START */
3207 Error = __net_telephony_add_profile(network_info, prof_info, network_type);
3208 if (Error != NET_ERR_NONE) {
3209 NETWORK_LOG(NETWORK_ERROR, "Failed to add service(profile). Error [%s]",
3210 _net_print_error(Error));
3211 __NETWORK_FUNC_EXIT__;
3214 /* LCOV_EXCL_STOP */
3216 __NETWORK_FUNC_EXIT__;
3220 EXPORT_API int net_delete_profile(void *handle, const char *profile_name)
3222 __NETWORK_FUNC_ENTER__;
3224 net_err_t Error = NET_ERR_NONE;
3225 net_profile_name_t pdp_prof_name;
3226 net_profile_name_t wifi_prof_name;
3227 net_profile_info_t prof_info;
3228 network_info_t *network_info = (network_info_t *)handle;
3230 NETWORK_LOG(NETWORK_HIGH, "Delete Profile [%s]", profile_name);
3232 if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
3233 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3234 __NETWORK_FUNC_EXIT__;
3235 return NET_ERR_INVALID_PARAM;
3238 /* LCOV_EXCL_START */
3239 Error = __net_get_profile_info(network_info, profile_name, &prof_info);
3240 if (Error != NET_ERR_NONE) {
3241 NETWORK_LOG(NETWORK_ERROR,
3242 "Failed to get service(profile) information. Error [%s]",
3243 _net_print_error(Error));
3245 __NETWORK_FUNC_EXIT__;
3249 g_strlcpy(wifi_prof_name.profile_name, profile_name, NET_PROFILE_NAME_LEN_MAX + 1);
3251 if (prof_info.profile_type == NET_DEVICE_WIFI) {
3252 Error = __net_wifi_delete_profile(network_info, &wifi_prof_name,
3253 prof_info.profile_info.wlan.security_info.sec_mode,
3254 prof_info.profile_info.wlan.passpoint);
3255 if (Error != NET_ERR_NONE) {
3256 NETWORK_LOG(NETWORK_ERROR,
3257 "Failed to delete service(profile). Error [%s]",
3258 _net_print_error(Error));
3260 __NETWORK_FUNC_EXIT__;
3263 } else if (prof_info.profile_type == NET_DEVICE_CELLULAR) {
3264 Error = __net_telephony_search_pdp_profile(network_info,
3265 wifi_prof_name.profile_name, &pdp_prof_name);
3266 if (Error != NET_ERR_NONE) {
3267 NETWORK_LOG(NETWORK_ERROR,
3268 "Failed to get service(profile) information. Error [%s]",
3269 _net_print_error(Error));
3271 __NETWORK_FUNC_EXIT__;
3275 Error = __net_telephony_delete_profile(network_info, &pdp_prof_name);
3276 if (Error != NET_ERR_NONE) {
3277 NETWORK_LOG(NETWORK_ERROR,
3278 "Failed to delete service(profile). Error [%s]",
3279 _net_print_error(Error));
3281 __NETWORK_FUNC_EXIT__;
3284 } else if (prof_info.profile_type == NET_DEVICE_MESH) {
3285 Error = __net_mesh_delete_profile(network_info, profile_name);
3286 if (Error != NET_ERR_NONE) {
3287 NETWORK_LOG(NETWORK_ERROR,
3288 "Failed to delete service(profile). Error [%s]",
3289 _net_print_error(Error));
3291 __NETWORK_FUNC_EXIT__;
3295 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3297 __NETWORK_FUNC_EXIT__;
3298 return NET_ERR_INVALID_PARAM;
3300 /* LCOV_EXCL_STOP */
3302 __NETWORK_FUNC_EXIT__;
3303 return NET_ERR_NONE;
3306 EXPORT_API int net_get_profile_info(void *handle,
3307 const char *profile_name, net_profile_info_t *prof_info)
3309 __NETWORK_FUNC_ENTER__;
3311 net_err_t Error = NET_ERR_NONE;
3312 network_info_t *network_info = (network_info_t *)handle;
3314 if (prof_info == NULL || _net_check_profile_name(profile_name) != NET_ERR_NONE) {
3315 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3317 __NETWORK_FUNC_EXIT__;
3318 return NET_ERR_INVALID_PARAM;
3321 Error = __net_get_profile_info(network_info, profile_name, prof_info);
3322 /* LCOV_EXCL_START */
3323 if (Error != NET_ERR_NONE)
3324 NETWORK_LOG(NETWORK_ERROR,
3325 "Failed to get service(profile) information. Error [%s]",
3326 _net_print_error(Error));
3327 /* LCOV_EXCL_STOP */
3329 __NETWORK_FUNC_EXIT__;
3333 EXPORT_API int net_modify_profile(void *handle, const char *profile_name, net_profile_info_t *prof_info)
3335 __NETWORK_FUNC_ENTER__;
3337 net_err_t Error = NET_ERR_NONE;
3338 net_profile_info_t exprof_info;
3339 network_info_t *network_info = (network_info_t *)handle;
3341 Error = net_get_profile_info(network_info, profile_name, &exprof_info);
3342 if (Error != NET_ERR_NONE) {
3343 NETWORK_LOG(NETWORK_ERROR,
3344 "Failed to get service(profile) information. Error [%s]",
3345 _net_print_error(Error));
3347 __NETWORK_FUNC_EXIT__;
3351 /* LCOV_EXCL_START */
3352 if (prof_info == NULL ||
3353 (exprof_info.profile_type != NET_DEVICE_WIFI &&
3354 exprof_info.profile_type != NET_DEVICE_CELLULAR &&
3355 exprof_info.profile_type != NET_DEVICE_MESH &&
3356 exprof_info.profile_type != NET_DEVICE_ETHERNET)) {
3357 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3358 __NETWORK_FUNC_EXIT__;
3359 return NET_ERR_INVALID_PARAM;
3362 if (exprof_info.profile_type == NET_DEVICE_WIFI)
3363 Error = __net_modify_wlan_profile_info(network_info, profile_name, prof_info, &exprof_info);
3364 else if (exprof_info.profile_type == NET_DEVICE_CELLULAR)
3365 Error = __net_telephony_modify_profile(network_info, profile_name, prof_info, &exprof_info);
3366 else if (exprof_info.profile_type == NET_DEVICE_ETHERNET)
3367 Error = __net_modify_ethernet_profile(network_info, profile_name, prof_info, &exprof_info);
3368 else if (exprof_info.profile_type == NET_DEVICE_MESH)
3369 Error = __net_modify_mesh_profile(network_info, profile_name, prof_info, &exprof_info);
3371 if (Error != NET_ERR_NONE) {
3372 NETWORK_LOG(NETWORK_ERROR,
3373 "Failed to modify service(profile) information. Error [%s]",
3374 _net_print_error(Error));
3376 __NETWORK_FUNC_EXIT__;
3379 /* LCOV_EXCL_STOP */
3381 __NETWORK_FUNC_EXIT__;
3382 return NET_ERR_NONE;
3385 EXPORT_API int net_get_profile_list(void *handle, net_device_t device_type,
3386 net_profile_info_t **profile_list, int *count)
3388 __NETWORK_FUNC_ENTER__;
3390 net_err_t Error = NET_ERR_NONE;
3391 int profile_count = 0;
3392 net_profile_info_t *profile_info = NULL;
3393 network_info_t *network_info = (network_info_t *)handle;
3395 if (count == NULL) {
3396 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3397 __NETWORK_FUNC_EXIT__;
3398 return NET_ERR_INVALID_PARAM;
3401 if (device_type != NET_DEVICE_CELLULAR &&
3402 device_type != NET_DEVICE_WIFI &&
3403 device_type != NET_DEVICE_ETHERNET &&
3404 device_type != NET_DEVICE_MESH && //LCOV_EXCL_LINE
3405 device_type != NET_DEVICE_BLUETOOTH) {
3406 NETWORK_LOG(NETWORK_ERROR, "Not Supported"); //LCOV_EXCL_LINE
3407 __NETWORK_FUNC_EXIT__;
3408 return NET_ERR_NOT_SUPPORTED;
3411 Error = _net_get_profile_list(network_info, device_type, &profile_info, &profile_count);
3413 /* LCOV_EXCL_START */
3414 if (Error != NET_ERR_NONE) {
3415 NETWORK_LOG(NETWORK_ERROR,
3416 "Failed to get service(profile) list. Error [%s]",
3417 _net_print_error(Error));
3419 NET_MEMFREE(profile_info);
3421 __NETWORK_FUNC_EXIT__;
3423 /* LCOV_EXCL_STOP */
3425 *count = profile_count;
3426 *profile_list = profile_info;
3429 __NETWORK_FUNC_EXIT__;
3430 return NET_ERR_NONE;
3433 EXPORT_API int net_get_all_profile_list(void *handle,
3434 net_profile_info_t **profile_list, int *count)
3436 __NETWORK_FUNC_ENTER__;
3438 net_err_t Error = NET_ERR_NONE;
3439 int profile_count = 0;
3440 net_profile_info_t *profile_info = NULL;
3441 network_info_t *network_info = (network_info_t *)handle;
3443 if (count == NULL) {
3444 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3445 __NETWORK_FUNC_EXIT__;
3446 return NET_ERR_INVALID_PARAM;
3449 Error = _net_get_all_profile_list(network_info, &profile_info, &profile_count);
3451 /* LCOV_EXCL_START */
3452 if (Error != NET_ERR_NONE) {
3453 NETWORK_LOG(NETWORK_ERROR,
3454 "Failed to get service(profile) list. Error [%s]",
3455 _net_print_error(Error));
3457 NET_MEMFREE(profile_info);
3459 __NETWORK_FUNC_EXIT__;
3461 /* LCOV_EXCL_STOP */
3463 *count = profile_count;
3464 *profile_list = profile_info;
3467 __NETWORK_FUNC_EXIT__;
3468 return NET_ERR_NONE;
3471 /* LCOV_EXCL_START */
3472 EXPORT_API int net_get_cellular_modem_object_path(char **modem_path, int sim_id)
3474 net_err_t Error = NET_ERR_NONE;
3475 const char *path = NULL;
3476 char subscriber_id[3];
3477 GSList *ModemPathList = NULL, *list = NULL;
3479 if (sim_id < 0 || modem_path == NULL)
3480 return NET_ERR_INVALID_PARAM;
3482 Error = __net_telephony_get_modem_object_path(NULL, &ModemPathList);
3483 if (Error != NET_ERR_NONE)
3487 g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", sim_id);
3488 for (list = ModemPathList; list != NULL; list = list->next) {
3489 path = (const char *)list->data;
3491 NETWORK_LOG(NETWORK_LOW, "path: %s", path);
3492 if (g_str_has_suffix(path, subscriber_id) == TRUE) {
3493 *modem_path = g_strdup(path);
3498 if (*modem_path == NULL)
3499 Error = NET_ERR_MODEM_INTERFACE_NOT_AVAIALABLE;
3501 NETWORK_LOG(NETWORK_LOW, "Subscriber %d: %s", sim_id, *modem_path);
3505 g_slist_free_full(ModemPathList, g_free);
3507 __NETWORK_FUNC_EXIT__;
3511 EXPORT_API int net_set_default_cellular_service_profile(void *handle, const char *profile_name)
3513 net_err_t Error = NET_ERR_NONE;
3514 network_info_t *network_info = (network_info_t *)handle;
3516 if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
3517 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3518 __NETWORK_FUNC_EXIT__;
3519 return NET_ERR_INVALID_PARAM;
3522 Error = __net_set_default_cellular_service_profile_sync(network_info, profile_name);
3523 if (Error != NET_ERR_NONE) {
3524 NETWORK_LOG(NETWORK_ERROR,
3525 "Failed to set default cellular service(profile). Error [%s]",
3526 _net_print_error(Error));
3527 __NETWORK_FUNC_EXIT__;
3531 return NET_ERR_NONE;
3534 EXPORT_API int net_set_default_cellular_service_profile_async(void *handle,
3535 const char *profile_name)
3537 net_err_t Error = NET_ERR_NONE;
3538 network_info_t *network_info = (network_info_t *)handle;
3540 if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
3541 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Parameter");
3542 __NETWORK_FUNC_EXIT__;
3543 return NET_ERR_INVALID_PARAM;
3546 if (network_info->request_table[NETWORK_REQUEST_TYPE_SET_DEFAULT].flag == TRUE) {
3547 NETWORK_LOG(NETWORK_ERROR, "Error!! Request already in progress");
3548 __NETWORK_FUNC_EXIT__;
3549 return NET_ERR_IN_PROGRESS;
3552 network_info->request_table[NETWORK_REQUEST_TYPE_SET_DEFAULT].flag = TRUE;
3554 Error = __net_set_default_cellular_service_profile_async(network_info, profile_name);
3555 if (Error != NET_ERR_NONE) {
3556 NETWORK_LOG(NETWORK_ERROR,
3557 "Error!!! failed to set default cellular service(profile). Error [%s]",
3558 _net_print_error(Error));
3559 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_SET_DEFAULT]),
3560 0, sizeof(network_request_table_t));
3561 __NETWORK_FUNC_EXIT__;
3565 return NET_ERR_NONE;
3567 /* LCOV_EXCL_STOP */
3569 EXPORT_API int net_foreach_ipv6_address(net_device_t device_type,
3570 GSList **ipv6_address_list)
3572 __NETWORK_FUNC_ENTER__;
3574 if (ipv6_address_list == NULL) {
3575 __NETWORK_FUNC_EXIT__;
3576 return NET_ERR_INVALID_PARAM;
3581 char *ip_address = NULL;
3582 char *if_name = NULL;
3584 char buf[NET_IPV6_ADDRESS_FILE_LEN] = {0,};
3585 char str[NET_IPV6_ADDRESS_LEN + 1] = {0,};
3587 fp = fopen(NET_IPV6_ADDRESS_FILE, "r");
3589 NETWORK_LOG(NETWORK_ERROR, "File Opening Failed"); //LCOV_EXCL_LINE
3590 __NETWORK_FUNC_EXIT__;
3591 return NET_ERR_INVALID_OPERATION;
3594 while (fgets(buf, sizeof(buf), fp) != NULL) {
3595 g_strlcpy(str, buf, NET_IPV6_ADDRESS_LEN + 1);
3596 /* LCOV_EXCL_START */
3597 switch (device_type) {
3598 case NET_DEVICE_WIFI:
3599 if_name = strstr(buf, "wlan");
3601 case NET_DEVICE_CELLULAR:
3602 if_name = strstr(buf, "seth");
3604 case NET_DEVICE_USB:
3605 if_name = strstr(buf, "usb");
3607 case NET_DEVICE_ETHERNET:
3608 if_name = strstr(buf, "eth");
3610 case NET_DEVICE_BLUETOOTH:
3611 if_name = strstr(buf, "bnep");
3617 if (if_name != NULL) {
3618 if (NET_ERR_NONE == __net_convert_string_to_ipv6_string(
3620 *ipv6_address_list = g_slist_append(
3621 *ipv6_address_list, ip_address);
3623 /* LCOV_EXCL_STOP */
3628 __NETWORK_FUNC_EXIT__;
3629 return NET_ERR_NONE;
3633 * @fn EXPORT_API int net_get_preferred_ipv6_address(char **address)
3635 * This function is to get preferred ipv6 address.
3638 * @return 0 - on success, negative values for errors
3639 * @param[in] const char *profile_name - profile name
3640 * @param[out] char **address - preferred ipv6 address of specific profile
3642 EXPORT_API int net_get_preferred_ipv6_address(const char *profile_name, char **address)
3644 __NETWORK_FUNC_ENTER__;
3645 net_err_t Error = NET_ERR_NONE;
3647 Error = _net_dbus_get_preferred_ipv6_address(profile_name, address);
3649 if (Error != NET_ERR_NONE)
3650 NETWORK_LOG(NETWORK_ERROR, "_net_dbus_get_preferred_ipv6_address failed\n");
3652 __NETWORK_FUNC_EXIT__;