b89255584685e4e3c1aa249bd4f9124cc8b7cde6
[platform/core/connectivity/libnet-client.git] / src / network-profile-intf.c
1 /*
2  * Network Client Library
3  *
4  * Copyright 2012 Samsung Electronics Co., Ltd
5  *
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
9  *
10  * http://www.tizenopensource.org/license
11  *
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.
17  *
18  */
19
20 #include <ctype.h>
21 #include <stdio.h>
22 #include <arpa/inet.h>
23
24 #include "network-info.h"
25 #include "network-internal.h"
26 #include "network-signal-handler.h"
27 #include "network-dbus-request.h"
28
29 #define DBUS_OBJECT_PATH_MAX    150
30
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
34
35 /*****************************************************************************
36  * Local Functions Declaration
37  *****************************************************************************/
38 static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_t *ProfInfo);
39 static int __net_extract_service_info(network_info_t *network_info,
40                 const char *ProfileName, GVariantIter *iter, net_profile_info_t *ProfInfo);
41 static int __net_extract_services(network_info_t *network_info,
42                 GVariantIter *message, net_device_t device_type,
43                 net_profile_info_t **profile_info, int *profile_count);
44 static int __net_extract_ip(const gchar *value, net_addr_t *ipAddr);
45 static int __net_extract_common_info(const char *key, GVariant *variant, net_profile_info_t *ProfInfo);
46 static int __net_extract_mobile_info(network_info_t *network_info, GVariantIter *array, net_profile_info_t *ProfInfo);
47 static int __net_extract_ethernet_info(GVariantIter *array, net_profile_info_t *ProfInfo);
48 static int __net_extract_bluetooth_info(GVariantIter *array, net_profile_info_t *ProfInfo);
49 static int __net_extract_mesh_info(GVariantIter *array, net_profile_info_t *ProfInfo);
50
51 /*****************************************************************************
52  * Extern Variables
53  *****************************************************************************/
54
55 /*****************************************************************************
56  * Local Functions Definition
57  *****************************************************************************/
58 /* LCOV_EXCL_START */
59 static int __net_pm_init_profile_info(net_device_t profile_type, net_profile_info_t *ProfInfo)
60 {
61         int i = 0;
62         net_dev_info_t *net_info = NULL;
63
64         if (ProfInfo == NULL ||
65            (profile_type != NET_DEVICE_WIFI &&
66             profile_type != NET_DEVICE_CELLULAR &&
67             profile_type != NET_DEVICE_ETHERNET &&
68             profile_type != NET_DEVICE_MESH &&
69             profile_type != NET_DEVICE_BLUETOOTH)) {
70                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
71                 return NET_ERR_INVALID_PARAM;
72         }
73
74         memset(ProfInfo, 0, sizeof(net_profile_info_t));
75         ProfInfo->Favourite = (char)FALSE;
76
77         if (profile_type == NET_DEVICE_WIFI) {
78                 ProfInfo->profile_type = NET_DEVICE_WIFI;
79                 ProfInfo->ProfileInfo.Wlan.Strength = 0;
80                 ProfInfo->ProfileInfo.Wlan.frequency = 0;
81                 ProfInfo->ProfileInfo.Wlan.max_rate = 0;
82                 ProfInfo->ProfileInfo.Wlan.wlan_mode = 0;
83                 ProfInfo->ProfileInfo.Wlan.PassphraseRequired = FALSE;
84                 ProfInfo->ProfileInfo.Wlan.security_info.sec_mode = 0;
85                 ProfInfo->ProfileInfo.Wlan.security_info.enc_mode = 0;
86                 ProfInfo->ProfileInfo.Wlan.security_info.wps_support = FALSE;
87
88                 net_info = &(ProfInfo->ProfileInfo.Wlan.net_info);
89         } else if (profile_type == NET_DEVICE_CELLULAR) {
90                 ProfInfo->profile_type = NET_DEVICE_CELLULAR;
91                 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_NONE;
92                 ProfInfo->ProfileInfo.Pdp.ServiceType = NET_SERVICE_UNKNOWN;
93                 ProfInfo->ProfileInfo.Pdp.PdnType = NET_PDN_TYPE_UNKNOWN;
94                 ProfInfo->ProfileInfo.Pdp.RoamPdnType = NET_PDN_TYPE_UNKNOWN;
95                 ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType = NET_PDP_AUTH_NONE;
96                 ProfInfo->ProfileInfo.Pdp.IsStatic = FALSE;
97                 ProfInfo->ProfileInfo.Pdp.Roaming = FALSE;
98                 ProfInfo->ProfileInfo.Pdp.SetupRequired = FALSE;
99                 ProfInfo->ProfileInfo.Pdp.Hidden = FALSE;
100                 ProfInfo->ProfileInfo.Pdp.Editable = TRUE;
101                 ProfInfo->ProfileInfo.Pdp.DefaultConn = FALSE;
102
103                 net_info = &(ProfInfo->ProfileInfo.Pdp.net_info);
104         } else if (profile_type == NET_DEVICE_ETHERNET) {
105                 net_info = &(ProfInfo->ProfileInfo.Ethernet.net_info);
106         } else if (profile_type == NET_DEVICE_BLUETOOTH) {
107                 net_info = &(ProfInfo->ProfileInfo.Bluetooth.net_info);
108         } else if (profile_type == NET_DEVICE_MESH) {
109                 ProfInfo->profile_type = NET_DEVICE_MESH;
110                 ProfInfo->ProfileInfo.Mesh.Strength = 0;
111                 ProfInfo->ProfileInfo.Mesh.frequency = 0;
112                 ProfInfo->ProfileInfo.Mesh.PassphraseRequired = FALSE;
113                 ProfInfo->ProfileInfo.Mesh.security_info.sec_mode = 0;
114
115                 net_info = &(ProfInfo->ProfileInfo.Mesh.net_info);
116         }
117
118         if (net_info != NULL) {
119                 net_info->DnsCount = 0;
120
121                 for (i = 0; i < NET_DNS_ADDR_MAX; i++) {
122                         net_info->DnsAddr[i].Type = NET_ADDR_IPV4;
123                         net_info->DnsAddr[i].Data.Ipv4.s_addr = 0;
124                 }
125
126                 net_info->IpConfigType = 0;
127                 net_info->IpAddr.Type = NET_ADDR_IPV4;
128                 net_info->IpAddr.Data.Ipv4.s_addr = 0;
129                 net_info->BNetmask = FALSE;
130                 net_info->SubnetMask.Type = NET_ADDR_IPV4;
131                 net_info->SubnetMask.Data.Ipv4.s_addr = 0;
132                 net_info->BDefGateway = FALSE;
133                 net_info->GatewayAddr.Type = NET_ADDR_IPV4;
134                 net_info->GatewayAddr.Data.Ipv4.s_addr = 0;
135                 net_info->BServerAddr = FALSE;
136                 net_info->ServerAddr.Type = NET_ADDR_IPV4;
137                 net_info->ServerAddr.Data.Ipv4.s_addr = 0;
138
139                 net_info->IpConfigType6 = 0;
140                 net_info->IpAddr6.Type = NET_ADDR_IPV6;
141                 inet_pton(AF_INET6, "::", &net_info->IpAddr6.Data.Ipv6);
142                 net_info->PrefixLen6 = 0;
143                 net_info->BDefGateway6 = FALSE;
144                 net_info->GatewayAddr6.Type = NET_ADDR_IPV6;
145                 inet_pton(AF_INET6, "::", &net_info->GatewayAddr6.Data.Ipv6);
146
147                 net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
148         }
149
150         return NET_ERR_NONE;
151 }
152
153 static int __net_telephony_init_profile_info(net_telephony_profile_info_t *ProfInfo)
154 {
155         if (ProfInfo == NULL) {
156                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
157
158                 __NETWORK_FUNC_EXIT__;
159                 return NET_ERR_INVALID_PARAM;
160         }
161
162         memset(ProfInfo->ProfileName, '\0', NET_PROFILE_NAME_LEN_MAX+1);
163         ProfInfo->ServiceType = NET_SERVICE_UNKNOWN;
164         ProfInfo->PdnType = NET_PDN_TYPE_UNKNOWN;
165         ProfInfo->RoamPdnType = NET_PDN_TYPE_UNKNOWN;
166         memset(ProfInfo->Apn, '\0', NET_PDP_APN_LEN_MAX+1);
167
168         ProfInfo->AuthInfo.AuthType = NET_PDP_AUTH_NONE;
169         memset(ProfInfo->AuthInfo.UserName, '\0', NET_PDP_AUTH_USERNAME_LEN_MAX+1);
170         memset(ProfInfo->AuthInfo.Password, '\0', NET_PDP_AUTH_PASSWORD_LEN_MAX+1);
171
172         memset(ProfInfo->ProxyAddr, '\0', NET_PROXY_LEN_MAX+1);
173         memset(ProfInfo->HomeURL, '\0', NET_HOME_URL_LEN_MAX+1);
174
175         memset(ProfInfo->Keyword, '\0', NET_PDP_APN_LEN_MAX+1);
176         ProfInfo->Hidden = FALSE;
177         ProfInfo->Editable = TRUE;
178         ProfInfo->DefaultConn = FALSE;
179
180         return NET_ERR_NONE;
181 }
182
183 static void __net_telephony_get_path(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
184 {
185         if (value != NULL)
186                 g_strlcpy(ProfileInfo->ProfileName, value, NET_PROFILE_NAME_LEN_MAX);
187 }
188
189 static void __net_telephony_get_svc_ctg_id(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
190 {
191         net_service_type_t ServiceType = NET_SERVICE_UNKNOWN;
192
193         if (value != NULL)
194                 ServiceType = atoi(value);
195
196         if (ServiceType > NET_SERVICE_UNKNOWN)
197                 ProfileInfo->ServiceType = ServiceType;
198 }
199
200 static void __net_telephony_get_apn(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
201 {
202         if (value != NULL)
203                 g_strlcpy(ProfileInfo->Apn, value, NET_PDP_APN_LEN_MAX);
204 }
205
206 static void __net_telephony_get_pdp_protocol(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
207 {
208         net_pdn_type_e pdnType = NET_PDN_TYPE_UNKNOWN;
209
210         if (value != NULL)
211                 pdnType = atoi(value);
212
213         if (pdnType == NET_PDN_TYPE_IPV4)
214                 ProfileInfo->PdnType = NET_PDN_TYPE_IPV4;
215         else if (pdnType == NET_PDN_TYPE_IPV6)
216                 ProfileInfo->PdnType = NET_PDN_TYPE_IPV6;
217         else if (pdnType == NET_PDN_TYPE_IPV4_IPV6)
218                 ProfileInfo->PdnType = NET_PDN_TYPE_IPV4_IPV6;
219 }
220
221 static void __net_telephony_get_roam_pdp_protocol(const gchar *value,
222                 net_telephony_profile_info_t *ProfileInfo)
223 {
224         net_pdn_type_e roamPdnType = NET_PDN_TYPE_UNKNOWN;
225
226         if (value != NULL)
227                 roamPdnType = atoi(value);
228
229         if (roamPdnType == NET_PDN_TYPE_IPV4)
230                 ProfileInfo->RoamPdnType = NET_PDN_TYPE_IPV4;
231         else if (roamPdnType == NET_PDN_TYPE_IPV6)
232                 ProfileInfo->RoamPdnType = NET_PDN_TYPE_IPV6;
233         else if (roamPdnType == NET_PDN_TYPE_IPV4_IPV6)
234                 ProfileInfo->RoamPdnType = NET_PDN_TYPE_IPV4_IPV6;
235 }
236
237 static void __net_telephony_get_auth_type(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
238 {
239         net_auth_type_t authType = NET_PDP_AUTH_NONE;
240
241         if (value != NULL)
242                 authType = atoi(value);
243
244         if (authType == NET_PDP_AUTH_PAP)
245                 ProfileInfo->AuthInfo.AuthType = NET_PDP_AUTH_PAP;
246         else if (authType == NET_PDP_AUTH_CHAP)
247                 ProfileInfo->AuthInfo.AuthType = NET_PDP_AUTH_CHAP;
248 }
249
250 static void __net_telephony_get_auth_id(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
251 {
252         if (value != NULL)
253                 g_strlcpy(ProfileInfo->AuthInfo.UserName, value, NET_PDP_AUTH_USERNAME_LEN_MAX);
254 }
255
256 static void __net_telephony_get_auth_pwd(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
257 {
258         if (value != NULL)
259                 g_strlcpy(ProfileInfo->AuthInfo.Password, value, NET_PDP_AUTH_PASSWORD_LEN_MAX);
260 }
261
262 static void __net_telephony_get_proxy_addr(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
263 {
264         if (value != NULL)
265                 g_strlcpy(ProfileInfo->ProxyAddr, value, NET_PROXY_LEN_MAX);
266 }
267
268 static void __net_telephony_get_home_uri(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
269 {
270         if (value != NULL)
271                 g_strlcpy(ProfileInfo->HomeURL, value, NET_HOME_URL_LEN_MAX);
272 }
273
274 static void __net_telephony_get_default_internet_conn(const gchar *value,
275                 net_telephony_profile_info_t *ProfileInfo)
276 {
277         if (value == NULL)
278                 return;
279
280         if (g_strcmp0(value, "TRUE") == 0)
281                 ProfileInfo->DefaultConn = TRUE;
282         else
283                 ProfileInfo->DefaultConn = FALSE;
284 }
285
286 static void __net_telephony_get_profile_name(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
287 {
288         if (value != NULL)
289                 g_strlcpy(ProfileInfo->Keyword, value, NET_PDP_APN_LEN_MAX);
290 }
291
292 static void __net_telephony_get_editable(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
293 {
294         if (value == NULL)
295                 return;
296
297         if (g_strcmp0(value, "TRUE") == 0)
298                 ProfileInfo->Editable = TRUE;
299         else
300                 ProfileInfo->Editable = FALSE;
301 }
302
303 static void __net_telephony_get_hidden(const gchar *value, net_telephony_profile_info_t *ProfileInfo)
304 {
305         if (value == NULL)
306                 return;
307
308         if (g_strcmp0(value, "TRUE") == 0)
309                 ProfileInfo->Hidden = TRUE;
310         else
311                 ProfileInfo->Hidden = FALSE;
312 }
313
314 static int __net_telephony_get_profile_info(network_info_t *network_info,
315                         net_profile_name_t *ProfileName, net_telephony_profile_info_t *ProfileInfo)
316 {
317         __NETWORK_FUNC_ENTER__;
318
319         net_err_t Error = NET_ERR_NONE;
320         GVariant *result;
321         GVariantIter *iter;
322         const gchar *key = NULL;
323         const gchar *value = NULL;
324
325         if (ProfileName == NULL || ProfileInfo == NULL) {
326                 NETWORK_LOG(NETWORK_ERROR, "Invalid parameter!");
327                 __NETWORK_FUNC_EXIT__;
328                 return NET_ERR_INVALID_PARAM;
329         }
330
331         result = _net_invoke_dbus_method(network_info, TELEPHONY_SERVICE, ProfileName->ProfileName,
332                         TELEPHONY_PROFILE_INTERFACE, "GetProfile", NULL, &Error);
333         if (result == NULL) {
334                 NETWORK_LOG(NETWORK_ERROR, "_net_invoke_dbus_method failed");
335                 __NETWORK_FUNC_EXIT__;
336                 return Error;
337         }
338
339         Error = __net_telephony_init_profile_info(ProfileInfo);
340
341         if (Error != NET_ERR_NONE) {
342                 g_variant_unref(result);
343                 __NETWORK_FUNC_EXIT__;
344                 return Error;
345         }
346
347         g_variant_get(result, "(a{ss})", &iter);
348         while (g_variant_iter_loop(iter, "{ss}", &key, &value)) {
349                 if (g_strcmp0(key, "path") == 0) {
350                         __net_telephony_get_path(value, ProfileInfo);
351                 } else if (g_strcmp0(key, "svc_ctg_id") == 0) {
352                         __net_telephony_get_svc_ctg_id(value, ProfileInfo);
353                 } else if (g_strcmp0(key, "apn") == 0) {
354                         __net_telephony_get_apn(value, ProfileInfo);
355                 } else if (g_strcmp0(key, "pdp_protocol") == 0) {
356                         __net_telephony_get_pdp_protocol(value, ProfileInfo);
357                 } else if (g_strcmp0(key, "roam_pdp_protocol") == 0) {
358                         __net_telephony_get_roam_pdp_protocol(value, ProfileInfo);
359                 } else if (g_strcmp0(key, "auth_type") == 0) {
360                         __net_telephony_get_auth_type(value, ProfileInfo);
361                 } else if (g_strcmp0(key, "auth_id") == 0) {
362                         __net_telephony_get_auth_id(value, ProfileInfo);
363                 } else if (g_strcmp0(key, "auth_pwd") == 0) {
364                         __net_telephony_get_auth_pwd(value, ProfileInfo);
365                 } else if (g_strcmp0(key, "proxy_addr") == 0) {
366                         __net_telephony_get_proxy_addr(value, ProfileInfo);
367                 } else if (g_strcmp0(key, "home_url") == 0) {
368                         __net_telephony_get_home_uri(value, ProfileInfo);
369                 } else if (g_strcmp0(key, "default_internet_conn") == 0) {
370                         __net_telephony_get_default_internet_conn(value, ProfileInfo);
371                 } else if (g_strcmp0(key, "profile_name") == 0) {
372                         __net_telephony_get_profile_name(value, ProfileInfo);
373                 } else if (g_strcmp0(key, "editable") == 0) {
374                         __net_telephony_get_editable(value, ProfileInfo);
375                 } else if (g_strcmp0(key, "hidden") == 0) {
376                         __net_telephony_get_hidden(value, ProfileInfo);
377                 }
378         }
379
380         g_variant_iter_free(iter);
381         g_variant_unref(result);
382
383         __NETWORK_FUNC_EXIT__;
384         return Error;
385 }
386
387 static int __net_telephony_get_modem_object_path(network_info_t *network_info,
388                         GSList **ModemPathList)
389 {
390         __NETWORK_FUNC_ENTER__;
391
392         net_err_t Error = NET_ERR_NONE;
393         GVariant *result;
394         GVariantIter *iter_modem = NULL;
395         GVariantIter *modem_properties = NULL;
396         const char *modem_path;
397
398         result = _net_invoke_dbus_method(network_info,
399                         TELEPHONY_SERVICE, TELEPHONY_MASTER_PATH,
400                         TELEPHONY_MASTER_INTERFACE, "GetModems", NULL, &Error);
401         if (result == NULL) {
402                 NETWORK_LOG(NETWORK_ERROR, "Failed to get modem path list");
403                 __NETWORK_FUNC_EXIT__;
404                 return Error;
405         }
406
407         g_variant_get(result, "(a{sa{ss}})", &iter_modem);
408         while (g_variant_iter_loop(iter_modem, "{sa{ss}}", &modem_path, &modem_properties)) {
409                 *ModemPathList = g_slist_append(*ModemPathList, g_strdup(modem_path));
410                 NETWORK_LOG(NETWORK_LOW, "modem object path: %s",       modem_path);
411         }
412
413         g_variant_iter_free(iter_modem);
414         g_variant_unref(result);
415
416         __NETWORK_FUNC_EXIT__;
417         return Error;
418 }
419
420 static int __net_telephony_get_profile_list(network_info_t *network_info,
421                         net_profile_name_t **ProfileName, int *ProfileCount)
422 {
423         __NETWORK_FUNC_ENTER__;
424
425         net_err_t Error = NET_ERR_NONE;
426         int count = 0, i = 0;
427         const char *str = NULL;
428         GVariant *result;
429         GVariantIter *iter = NULL;
430         GSList *profiles = NULL, *list = NULL;
431         net_profile_name_t *profileList = NULL;
432
433         GSList *ModemPathList = NULL;
434         const char *path = NULL;
435
436         Error = __net_telephony_get_modem_object_path(network_info, &ModemPathList);
437         if (Error != NET_ERR_NONE) {
438                 NETWORK_LOG(NETWORK_ERROR, "Failed to get modems path list");
439
440                 g_slist_free_full(ModemPathList, g_free);
441                 __NETWORK_FUNC_EXIT__;
442                 return Error;
443         }
444
445         for (list = ModemPathList; list != NULL; list = list->next) {
446                 path = (const char *)list->data;
447
448                 NETWORK_LOG(NETWORK_LOW, "path: %s", path);
449                 result = _net_invoke_dbus_method(network_info,
450                                 TELEPHONY_SERVICE, path, TELEPHONY_MODEM_INTERFACE,
451                                 "GetProfileList", NULL, &Error);
452                 if (result == NULL) {
453                         NETWORK_LOG(NETWORK_LOW, "Failed to get profiles: %s", path);
454                         continue;
455                 }
456
457                 g_variant_get(result, "(as)", &iter);
458                 while (g_variant_iter_loop(iter, "s", &str))
459                         profiles = g_slist_append(profiles, g_strdup(str));
460
461                 g_variant_iter_free(iter);
462                 g_variant_unref(result);
463         }
464
465         g_slist_free_full(ModemPathList, g_free);
466
467         count = g_slist_length(profiles);
468         if (count > 0) {
469                 profileList = (net_profile_name_t*)malloc(sizeof(net_profile_name_t) * count);
470                 Error = NET_ERR_NONE;
471         } else {
472                 *ProfileCount = 0;
473                 goto out;
474         }
475
476         if (profileList == NULL) {
477                 NETWORK_LOG(NETWORK_ERROR, "Failed to allocate memory");
478                 *ProfileCount = 0;
479                 Error = NET_ERR_UNKNOWN;
480                 goto out;
481         }
482
483         for (list = profiles, i = 0; list != NULL; list = list->next, i++)
484                 g_strlcpy(profileList[i].ProfileName,
485                                 (const char *)list->data, NET_PROFILE_NAME_LEN_MAX);
486
487         *ProfileName = profileList;
488         *ProfileCount = count;
489
490 out:
491         g_slist_free_full(profiles, g_free);
492
493         __NETWORK_FUNC_EXIT__;
494         return Error;
495 }
496
497 static int __net_telephony_search_pdp_profile(network_info_t *network_info,
498                         char *ProfileName, net_profile_name_t *PdpProfName)
499 {
500         __NETWORK_FUNC_ENTER__;
501
502         net_err_t Error = NET_ERR_NONE;
503         net_profile_name_t *ProfileList = NULL;
504         char *connmanProfName = NULL;
505         char *telephonyProfName = NULL;
506         char *foundPtr = NULL;
507         int ProfileCount = 0;
508         int i = 0;
509
510         /* Get pdp profile list from telephony service */
511         Error = __net_telephony_get_profile_list(network_info, &ProfileList, &ProfileCount);
512         if (Error != NET_ERR_NONE) {
513                 NETWORK_LOG(NETWORK_ERROR, "Failed to get profile list from telephony service");
514                 NET_MEMFREE(ProfileList);
515                 __NETWORK_FUNC_EXIT__;
516                 return Error;
517         }
518
519         if (ProfileList == NULL || ProfileCount <= 0) {
520                 NETWORK_LOG(NETWORK_ERROR, "There is no PDP profiles");
521                 NET_MEMFREE(ProfileList);
522                 __NETWORK_FUNC_EXIT__;
523                 return NET_ERR_NO_SERVICE;
524         }
525
526         /* Find matching profile */
527         connmanProfName = strrchr(ProfileName, '/') + 1;
528         for (i = 0; i < ProfileCount; i++) {
529                 telephonyProfName = strrchr(ProfileList[i].ProfileName, '/') + 1;
530                 foundPtr = strstr(connmanProfName, telephonyProfName);
531
532                 if (foundPtr != NULL && g_strcmp0(foundPtr, telephonyProfName) == 0) {
533                         g_strlcpy(PdpProfName->ProfileName,
534                                         ProfileList[i].ProfileName, NET_PROFILE_NAME_LEN_MAX);
535
536                         NETWORK_LOG(NETWORK_HIGH,
537                                         "PDP profile name found in cellular profile: %s",
538                                         PdpProfName->ProfileName);
539                         break;
540                 }
541         }
542
543         if (i >= ProfileCount) {
544                 NETWORK_LOG(NETWORK_ERROR, "There is no matching PDP profiles");
545                 NET_MEMFREE(ProfileList);
546                 __NETWORK_FUNC_EXIT__;
547                 return NET_ERR_NO_SERVICE;
548         }
549
550         NET_MEMFREE(ProfileList);
551
552         __NETWORK_FUNC_EXIT__;
553         return Error;
554 }
555 /* LCOV_EXCL_STOP */
556
557 static int __net_extract_all_services(network_info_t *network_info,
558                 GVariantIter *array, net_device_t device_type, const char *service_prefix,
559                 int *prof_count, net_profile_info_t **ProfilePtr)
560 {
561         int count = 0;
562         net_profile_info_t ProfInfo = { 0, };
563         net_err_t Error = NET_ERR_NONE;
564         gchar *obj;
565         GVariantIter *next = NULL;
566
567         __NETWORK_FUNC_ENTER__;
568
569         if (array == NULL || service_prefix == NULL) {
570                 NETWORK_LOG(NETWORK_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
571
572                 __NETWORK_FUNC_EXIT__;
573                 return NET_ERR_INVALID_PARAM;
574         }
575
576         /* LCOV_EXCL_START */
577         while (g_variant_iter_loop(array, "(oa{sv})", &obj, &next)) {
578                 if (obj == NULL)
579                         continue;
580
581                 if (g_str_has_prefix(obj, service_prefix) == TRUE) {
582                         memset(&ProfInfo, 0, sizeof(net_profile_info_t));
583
584                         if ((Error = __net_pm_init_profile_info(device_type, &ProfInfo)) != NET_ERR_NONE) {
585                                 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
586
587                                 NET_MEMFREE(*ProfilePtr);
588                                 *prof_count = 0;
589
590                                 goto error;
591                         }
592
593                         if (device_type == NET_DEVICE_WIFI &&
594                                         g_strrstr(obj + strlen(service_prefix), "hidden") != NULL)
595                                 ProfInfo.ProfileInfo.Wlan.is_hidden = TRUE;
596
597                         ProfInfo.profile_type = device_type;
598                         g_strlcpy(ProfInfo.ProfileName, obj, NET_PROFILE_NAME_LEN_MAX);
599
600                         switch (device_type) {
601                         case NET_DEVICE_WIFI:
602                                 g_strlcpy(ProfInfo.ProfileInfo.Wlan.net_info.ProfileName,
603                                                 obj, NET_PROFILE_NAME_LEN_MAX);
604
605                                 Error = __net_extract_wifi_info(next, &ProfInfo);
606                                 break;
607                         case NET_DEVICE_CELLULAR:
608                                 g_strlcpy(ProfInfo.ProfileInfo.Pdp.net_info.ProfileName,
609                                                 obj, NET_PROFILE_NAME_LEN_MAX);
610
611                                 Error = __net_extract_mobile_info(network_info, next, &ProfInfo);
612                                 break;
613                         case NET_DEVICE_ETHERNET:
614                                 g_strlcpy(ProfInfo.ProfileInfo.Ethernet.net_info.ProfileName,
615                                                 obj, NET_PROFILE_NAME_LEN_MAX);
616
617                                 Error = __net_extract_ethernet_info(next, &ProfInfo);
618                                 break;
619                         case NET_DEVICE_BLUETOOTH:
620                                 g_strlcpy(ProfInfo.ProfileInfo.Bluetooth.net_info.ProfileName,
621                                                 obj, NET_PROFILE_NAME_LEN_MAX);
622
623                                 Error = __net_extract_bluetooth_info(next, &ProfInfo);
624                                 break;
625                         case NET_DEVICE_MESH:
626                                 g_strlcpy(ProfInfo.ProfileInfo.Mesh.net_info.ProfileName,
627                                                 obj, NET_PROFILE_NAME_LEN_MAX);
628
629                                 Error = __net_extract_mesh_info(next, &ProfInfo);
630                                 break;
631                         default:
632                                 NET_MEMFREE(*ProfilePtr);
633                                 *prof_count = 0;
634
635                                 Error = NET_ERR_NOT_SUPPORTED;
636                                 goto error;
637                         }
638
639                         if (Error != NET_ERR_NONE) {
640                                 NETWORK_LOG(NETWORK_ERROR, "Failed to extract service info");
641                                 NET_MEMFREE(*ProfilePtr);
642                                 *prof_count = 0;
643
644                                 goto error;
645                         }
646
647                         *ProfilePtr = (net_profile_info_t *)realloc(*ProfilePtr,
648                                         (count + 1) * sizeof(net_profile_info_t));
649                         if (*ProfilePtr == NULL) {
650                                 NETWORK_LOG(NETWORK_ERROR, "Failed to allocate memory");
651                                 *prof_count = 0;
652
653                                 Error = NET_ERR_UNKNOWN;
654                                 goto error;
655                         }
656
657                         memcpy(*ProfilePtr + count, &ProfInfo, sizeof(net_profile_info_t));
658                         count++;
659                 }
660         }
661         /* LCOV_EXCL_STOP */
662
663         *prof_count = count;
664
665         __NETWORK_FUNC_EXIT__;
666         return NET_ERR_NONE;
667
668 error:
669         /* LCOV_EXCL_START */
670         if (next)
671                 g_variant_iter_free(next);
672         if (obj)
673                 g_free(obj);
674
675         __NETWORK_FUNC_EXIT__;
676         return Error;
677         /* LCOV_EXCL_STOP */
678 }
679
680 static int __net_extract_services(network_info_t *network_info,
681                 GVariantIter *message, net_device_t device_type,
682                 net_profile_info_t **profile_info, int *profile_count)
683 {
684         __NETWORK_FUNC_ENTER__;
685
686         net_err_t Error = NET_ERR_NONE;
687         net_profile_info_t *ProfilePtr = NULL;
688         int prof_cnt = 0;
689         char *service_prefix = NULL;
690
691         *profile_count = 0;
692
693         /* LCOV_EXCL_START */
694         switch (device_type) {
695         case NET_DEVICE_WIFI:
696                 service_prefix = CONNMAN_WIFI_SERVICE_PROFILE_PREFIX;
697                 break;
698         case NET_DEVICE_CELLULAR:
699                 service_prefix = CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX;
700                 break;
701         case NET_DEVICE_ETHERNET:
702                 service_prefix = CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX;
703                 break;
704         case NET_DEVICE_BLUETOOTH:
705                 service_prefix = CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX;
706                 break;
707         case NET_DEVICE_MESH:
708                 service_prefix = CONNMAN_MESH_PROFILE_PREFIX;
709                 break;
710         default:
711                 *profile_count = 0;
712                 *profile_info = NULL;
713                 __NETWORK_FUNC_EXIT__;
714                 return NET_ERR_NOT_SUPPORTED;
715                 break;
716         }
717         /* LCOV_EXCL_STOP */
718
719         Error = __net_extract_all_services(network_info, message,
720                                 device_type, service_prefix, &prof_cnt, &ProfilePtr);
721
722         /* LCOV_EXCL_START */
723         if (Error != NET_ERR_NONE) {
724                 NETWORK_LOG(NETWORK_ERROR, "Failed to extract services from received message");
725                 *profile_count = 0;
726                 *profile_info = NULL;
727                 __NETWORK_FUNC_EXIT__;
728                 return Error;
729         }
730         /* LCOV_EXCL_STOP */
731
732         *profile_count = prof_cnt;
733         *profile_info = ProfilePtr;
734
735         __NETWORK_FUNC_EXIT__;
736         return Error;
737 }
738
739 /* LCOV_EXCL_START */
740 static int __net_extract_ip(const gchar *value, net_addr_t *ipAddr)
741 {
742         __NETWORK_FUNC_ENTER__;
743
744         unsigned char *ipValue = NULL;
745         char *saveptr = NULL;
746         char ipString[NETPM_IPV4_STR_LEN_MAX+1];
747         char *ipToken[4];
748
749         ipValue = (unsigned char *)&(ipAddr->Data.Ipv4.s_addr);
750
751         if (value != NULL) {
752                 g_strlcpy(ipString, value, NETPM_IPV4_STR_LEN_MAX+1);
753
754                 ipToken[0] = strtok_r(ipString, ".", &saveptr);
755
756                 if (ipToken[0] != NULL) {
757                         ipToken[1] = strtok_r(NULL, ".", &saveptr);
758
759                         if (ipToken[1] != NULL) {
760                                 ipToken[2] = strtok_r(NULL, ".", &saveptr);
761
762                                 if (ipToken[2] != NULL) {
763                                         ipToken[3] = strtok_r(NULL, ".", &saveptr);
764
765                                         if (ipToken[3] != NULL) {
766                                                 ipValue[0] = (unsigned char)atoi(ipToken[0]);
767                                                 ipValue[1] = (unsigned char)atoi(ipToken[1]);
768                                                 ipValue[2] = (unsigned char)atoi(ipToken[2]);
769                                                 ipValue[3] = (unsigned char)atoi(ipToken[3]);
770                                         }
771                                 }
772                         }
773                 }
774         }
775
776         __NETWORK_FUNC_EXIT__;
777
778         return NET_ERR_NONE;
779 }
780
781 static int __net_get_prefix_len(const char *netmask)
782 {
783         __NETWORK_FUNC_ENTER__;
784
785         in_addr_t mask = inet_network(netmask);
786         int prefix_len = 0;
787
788         for (; mask; mask <<= 1)
789                 ++prefix_len;
790
791         __NETWORK_FUNC_EXIT__;
792
793         return prefix_len;
794 }
795
796 static gboolean __net_check_address_type(int address_family, const char *address)
797 {
798         unsigned char buf[sizeof(struct in6_addr)] = {0, };
799         int err = 0;
800
801         err = inet_pton(address_family, address, buf);
802         if (err > 0)
803                 return TRUE;
804
805         return FALSE;
806 }
807
808 static void __net_extract_state_value(GVariant *variant, net_profile_info_t *ProfInfo)
809 {
810         const gchar *value = g_variant_get_string(variant, NULL);
811
812         if (g_strcmp0(value, "idle") == 0)
813                 ProfInfo->ProfileState = NET_STATE_TYPE_IDLE;
814         else if (g_strcmp0(value, "failure") == 0)
815                 ProfInfo->ProfileState = NET_STATE_TYPE_FAILURE;
816         else if (g_strcmp0(value, "association") == 0)
817                 ProfInfo->ProfileState = NET_STATE_TYPE_ASSOCIATION;
818         else if (g_strcmp0(value, "configuration") == 0)
819                 ProfInfo->ProfileState = NET_STATE_TYPE_CONFIGURATION;
820         else if (g_strcmp0(value, "ready") == 0)
821                 ProfInfo->ProfileState = NET_STATE_TYPE_READY;
822         else if (g_strcmp0(value, "disconnect") == 0)
823                 ProfInfo->ProfileState = NET_STATE_TYPE_DISCONNECT;
824         else if (g_strcmp0(value, "online") == 0)
825                 ProfInfo->ProfileState = NET_STATE_TYPE_ONLINE;
826         else
827                 ProfInfo->ProfileState = NET_STATE_TYPE_UNKNOWN;
828 }
829
830 static void __net_extract_state6_value(GVariant *variant, net_profile_info_t *ProfInfo)
831 {
832         const gchar *value = g_variant_get_string(variant, NULL);
833
834         if (g_strcmp0(value, "idle") == 0)
835                 ProfInfo->ProfileState6 = NET_STATE_TYPE_IDLE;
836         else if (g_strcmp0(value, "failure") == 0)
837                 ProfInfo->ProfileState6 = NET_STATE_TYPE_FAILURE;
838         else if (g_strcmp0(value, "association") == 0)
839                 ProfInfo->ProfileState6 = NET_STATE_TYPE_ASSOCIATION;
840         else if (g_strcmp0(value, "configuration") == 0)
841                 ProfInfo->ProfileState6 = NET_STATE_TYPE_CONFIGURATION;
842         else if (g_strcmp0(value, "disconnect") == 0)
843                 ProfInfo->ProfileState6 = NET_STATE_TYPE_DISCONNECT;
844         else if (g_strcmp0(value, "ready") == 0)
845                 ProfInfo->ProfileState6 = NET_STATE_TYPE_READY;
846         else if (g_strcmp0(value, "online") == 0)
847                 ProfInfo->ProfileState6 = NET_STATE_TYPE_ONLINE;
848         else
849                 ProfInfo->ProfileState6 = NET_STATE_TYPE_UNKNOWN;
850 }
851
852 static void __net_extract_error(GVariant *variant, net_profile_info_t *ProfInfo)
853 {
854         const gchar *value = g_variant_get_string(variant, NULL);
855
856         if (g_strcmp0(value, "invalid-key") == 0)
857                 ProfInfo->ProfileErrorState = NET_STATE_ERROR_INVALID_KEY;
858         else if (g_strcmp0(value, "connect-failed") == 0)
859                 ProfInfo->ProfileErrorState = NET_STATE_ERROR_CONNECT_FAILED;
860         else if (g_strcmp0(value, "auth-failed") == 0)
861                 ProfInfo->ProfileErrorState = NET_STATE_ERROR_AUTH_FAILED;
862         else if (g_strcmp0(value, "login-failed") == 0)
863                 ProfInfo->ProfileErrorState = NET_STATE_ERROR_LOGIN_FAILED;
864         else if (g_strcmp0(value, "dhcp-failed") == 0)
865                 ProfInfo->ProfileErrorState = NET_STATE_ERROR_DHCP_FAILED;
866         else if (g_strcmp0(value, "out-of-range") == 0)
867                 ProfInfo->ProfileErrorState = NET_STATE_ERROR_OUT_OF_RANGE;
868         else if (g_strcmp0(value, "pin-missing") == 0)
869                 ProfInfo->ProfileErrorState = NET_STATE_ERROR_PIN_MISSING;
870 }
871
872 static void __net_extract_ethernet_value(GVariant *variant, net_dev_info_t *net_info)
873 {
874         const gchar *subKey = NULL;
875         const gchar *value = NULL;
876         GVariant *var = NULL;
877         GVariantIter *iter = NULL;
878         g_variant_get(variant, "a{sv}", &iter);
879         while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
880                 if (g_strcmp0(subKey, "Interface") == 0) {
881                         value = g_variant_get_string(var, NULL);
882
883                         if (value != NULL)
884                                 g_strlcpy(net_info->DevName, value, NET_MAX_DEVICE_NAME_LEN);
885                 } else if (g_strcmp0(subKey, "Address") == 0) {
886                         value = g_variant_get_string(var, NULL);
887
888                         if (value != NULL)
889                                 g_strlcpy(net_info->MacAddr, value, NET_MAX_MAC_ADDR_LEN);
890                 }
891         }
892         g_variant_iter_free(iter);
893 }
894
895 static void __net_extract_ipv4_value(GVariant *variant, net_dev_info_t *net_info)
896 {
897         const gchar *subKey = NULL;
898         const gchar *value = NULL;
899         GVariant *var = NULL;
900         GVariantIter *iter = NULL;
901         g_variant_get(variant, "a{sv}", &iter);
902         while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
903                 if (g_strcmp0(subKey, "Method") == 0) {
904                         value = g_variant_get_string(var, NULL);
905
906                         if (g_strcmp0(value, "dhcp") == 0)
907                                 net_info->IpConfigType = NET_IP_CONFIG_TYPE_DYNAMIC;
908                         else if (g_strcmp0(value, "manual") == 0)
909                                 net_info->IpConfigType = NET_IP_CONFIG_TYPE_STATIC;
910                         else if (g_strcmp0(value, "fixed") == 0)
911                                 net_info->IpConfigType = NET_IP_CONFIG_TYPE_FIXED;
912                         else if (g_strcmp0(value, "off") == 0)
913                                 net_info->IpConfigType = NET_IP_CONFIG_TYPE_OFF;
914
915                         if (net_info->IpConfigType != NET_IP_CONFIG_TYPE_DYNAMIC) {
916                                 net_info->BServerAddr = FALSE;
917                                 net_info->ServerAddr.Type = NET_ADDR_IPV4;
918                                 net_info->ServerAddr.Data.Ipv4.s_addr = 0;
919                         }
920
921                 } else if (g_strcmp0(subKey, "Address") == 0) {
922                         value = g_variant_get_string(var, NULL);
923
924                         __net_extract_ip(value, &net_info->IpAddr);
925                 } else if (g_strcmp0(subKey, "Netmask") == 0) {
926                         value = g_variant_get_string(var, NULL);
927
928                         __net_extract_ip(value, &net_info->SubnetMask);
929                         net_info->PrefixLen = __net_get_prefix_len(value);
930                         net_info->BNetmask = TRUE;
931                 } else if (g_strcmp0(subKey, "Gateway") == 0) {
932                         value = g_variant_get_string(var, NULL);
933
934                         __net_extract_ip(value, &net_info->GatewayAddr);
935                         net_info->BDefGateway = TRUE;
936                 } else if (g_strcmp0(subKey, "DHCPServerIP") == 0) {
937                         value = g_variant_get_string(var, NULL);
938
939                         __net_extract_ip(value, &net_info->ServerAddr);
940                         net_info->BServerAddr = TRUE;
941                 } else if (g_strcmp0(subKey, "DHCPLeaseDuration") == 0) {
942                         net_info->DHCPLeaseDuration = g_variant_get_int32(var);
943                 }
944         }
945         g_variant_iter_free(iter);
946 }
947
948 static void __net_extract_ipv4_configuration_value(GVariant *variant, net_dev_info_t *net_info)
949 {
950         const gchar *subKey = NULL;
951         const gchar *value = NULL;
952         GVariant *var = NULL;
953         GVariantIter *iter = NULL;
954         if (net_info->IpConfigType != NET_IP_CONFIG_TYPE_DYNAMIC &&
955                         net_info->IpConfigType != NET_IP_CONFIG_TYPE_STATIC &&
956                         net_info->IpConfigType != NET_IP_CONFIG_TYPE_FIXED &&
957                         net_info->IpConfigType != NET_IP_CONFIG_TYPE_OFF) {
958
959                 g_variant_get(variant, "a{sv}", &iter);
960                 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
961                         if (g_strcmp0(subKey, "Method") == 0) {
962                                 value = g_variant_get_string(var, NULL);
963
964                                 if (g_strcmp0(value, "dhcp") == 0)
965                                         net_info->IpConfigType = NET_IP_CONFIG_TYPE_DYNAMIC;
966                                 else if (g_strcmp0(value, "manual") == 0)
967                                         net_info->IpConfigType = NET_IP_CONFIG_TYPE_STATIC;
968                                 else if (g_strcmp0(value, "fixed") == 0)
969                                         net_info->IpConfigType = NET_IP_CONFIG_TYPE_FIXED;
970                                 else if (g_strcmp0(value, "off") == 0)
971                                         net_info->IpConfigType = NET_IP_CONFIG_TYPE_OFF;
972
973                         } else if (g_strcmp0(subKey, "Address") == 0 &&
974                                         net_info->IpAddr.Data.Ipv4.s_addr == 0) {
975                                 value = g_variant_get_string(var, NULL);
976
977                                 __net_extract_ip(value, &net_info->IpAddr);
978                         } else if (g_strcmp0(subKey, "Netmask") == 0 &&
979                                         net_info->SubnetMask.Data.Ipv4.s_addr == 0) {
980                                 value = g_variant_get_string(var, NULL);
981
982                                 __net_extract_ip(value, &net_info->SubnetMask);
983                                 net_info->BNetmask = TRUE;
984                         } else if (g_strcmp0(subKey, "Gateway") == 0 &&
985                                         net_info->GatewayAddr.Data.Ipv4.s_addr == 0) {
986                                 value = g_variant_get_string(var, NULL);
987
988                                 __net_extract_ip(value, &net_info->GatewayAddr);
989                                 net_info->BDefGateway = TRUE;
990                         }
991                 }
992                 g_variant_iter_free(iter);
993         }
994 }
995
996 static void __net_extract_ipv6_value(GVariant *variant, net_dev_info_t *net_info)
997 {
998         const gchar *subKey = NULL;
999         const gchar *value = NULL;
1000         GVariant *var = NULL;
1001         GVariantIter *iter = NULL;
1002         g_variant_get(variant, "a{sv}", &iter);
1003         while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
1004                 if (g_strcmp0(subKey, "Method") == 0) {
1005                         value = g_variant_get_string(var, NULL);
1006
1007                         if (g_strcmp0(value, "manual") == 0)
1008                                 net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_STATIC;
1009                         else if (g_strcmp0(value, "off") == 0)
1010                                 net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_OFF;
1011                         else if (g_strcmp0(value, "auto") == 0)
1012                                 net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_AUTO_IP;
1013
1014                 } else if (g_strcmp0(subKey, "Address") == 0) {
1015                         value = g_variant_get_string(var, NULL);
1016
1017                         inet_pton(AF_INET6, value, &net_info->IpAddr6.Data.Ipv6);
1018                 } else if (g_strcmp0(subKey, "PrefixLength") == 0) {
1019                         net_info->PrefixLen6 = g_variant_get_byte(var);
1020                 } else if (g_strcmp0(subKey, "Gateway") == 0) {
1021                         value = g_variant_get_string(var, NULL);
1022
1023                         inet_pton(AF_INET6, value, &net_info->GatewayAddr6.Data.Ipv6);
1024                         net_info->BDefGateway6 = TRUE;
1025                 } else if (g_strcmp0(subKey, "Privacy") == 0) {
1026                         value = g_variant_get_string(var, NULL);
1027
1028                         if (value != NULL)
1029                                 g_strlcpy(net_info->Privacy6, value, NETPM_IPV6_MAX_PRIVACY_LEN);
1030                 }
1031         }
1032         g_variant_iter_free(iter);
1033 }
1034
1035 static void __net_extract_ipv6_configuration_value(GVariant *variant, net_dev_info_t *net_info)
1036 {
1037         const gchar *subKey = NULL;
1038         const gchar *value = NULL;
1039         GVariant *var = NULL;
1040         GVariantIter *iter = NULL;
1041         g_variant_get(variant, "a{sv}", &iter);
1042         while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
1043                 if (g_strcmp0(subKey, "Method") == 0) {
1044                         value = g_variant_get_string(var, NULL);
1045
1046                         if (g_strcmp0(value, "manual") == 0)
1047                                 net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_STATIC;
1048                         else if (g_strcmp0(value, "off") == 0)
1049                                 net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_OFF;
1050                         else if (g_strcmp0(value, "auto") == 0)
1051                                 net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_AUTO_IP;
1052
1053                 } else if (g_strcmp0(subKey, "Address") == 0) {
1054                         value = g_variant_get_string(var, NULL);
1055
1056                         inet_pton(AF_INET6, value, &net_info->IpAddr6.Data.Ipv6);
1057                 } else if (g_strcmp0(subKey, "PrefixLength") == 0) {
1058                         net_info->PrefixLen6 = g_variant_get_byte(var);
1059                 } else if (g_strcmp0(subKey, "Gateway") == 0) {
1060                         value = g_variant_get_string(var, NULL);
1061
1062                         inet_pton(AF_INET6, value, &net_info->GatewayAddr6.Data.Ipv6);
1063                         net_info->BDefGateway6 = TRUE;
1064                 } else if (g_strcmp0(subKey, "Privacy") == 0) {
1065                         value = g_variant_get_string(var, NULL);
1066
1067                         if (value != NULL)
1068                                 g_strlcpy(net_info->Privacy6, value, NETPM_IPV6_MAX_PRIVACY_LEN);
1069                 }
1070         }
1071         g_variant_iter_free(iter);
1072 }
1073
1074 static void __net_extract_nameserver_value(GVariant *variant, net_dev_info_t *net_info)
1075 {
1076         GVariantIter *iter = NULL;
1077         int dnsCount = 0;
1078         int dnsCount6 = 0;
1079         gchar *dns_value = NULL;
1080         gchar *dns_type = NULL;
1081
1082         g_variant_get(variant, "as", &iter);
1083
1084         while (g_variant_iter_loop(iter, "s", &dns_value)) {
1085                 /* Check Type of DNS Address */
1086                 if (__net_check_address_type(AF_INET6, dns_value)) {
1087                         /* IPv6 */
1088                         if (dnsCount6 < NET_DNS_ADDR_MAX) {
1089                                 net_info->DnsAddr6[dnsCount6].Type =
1090                                         NET_ADDR_IPV6;
1091                                 inet_pton(AF_INET6, dns_value,
1092                                                 &net_info->DnsAddr6[dnsCount6]\
1093                                                 .Data.Ipv6);
1094                                 dnsCount6++;
1095                         }
1096                 } else if (__net_check_address_type(AF_INET, dns_value)) {
1097                         /* IPv4 */
1098                         if (dnsCount < NET_DNS_ADDR_MAX) {
1099                                 net_info->DnsAddr[dnsCount].Type =
1100                                         NET_ADDR_IPV4;
1101                                 __net_extract_ip(dns_value,
1102                                                 &net_info->DnsAddr[dnsCount]);
1103                                 dnsCount++;
1104                         }
1105                 } else { /* DNS Type */
1106                         dns_type = g_strdup(dns_value);
1107                         if (g_strcmp0(dns_type, "ipv4.manual") == 0)
1108                                 net_info->DnsConfigType =
1109                                         NET_DNS_CONFIG_TYPE_STATIC;
1110                         else if (g_strcmp0(dns_type, "ipv4.dhcp") == 0)
1111                                 net_info->DnsConfigType =
1112                                         NET_DNS_CONFIG_TYPE_DYNAMIC;
1113                         if (g_strcmp0(dns_type, "ipv6.manual") == 0)
1114                                 net_info->DnsConfigType6 =
1115                                         NET_DNS_CONFIG_TYPE_STATIC;
1116                         else if (g_strcmp0(dns_type, "ipv6.dhcp") == 0)
1117                                 net_info->DnsConfigType6 =
1118                                         NET_DNS_CONFIG_TYPE_DYNAMIC;
1119                         g_free(dns_type);
1120                 }
1121         }
1122         g_variant_iter_free(iter);
1123
1124         net_info->DnsCount = dnsCount;
1125         net_info->DnsCount6 = dnsCount6;
1126 }
1127
1128 static void __net_extract_nameserver_configuration_value(GVariant *variant, net_dev_info_t *net_info)
1129 {
1130         GVariantIter *iter = NULL;
1131         int dnsCount = 0;
1132         int dnsCount6 = 0;
1133         gchar *dns_value = NULL;
1134         gchar *dns_type = NULL;
1135
1136         g_variant_get(variant, "as", &iter);
1137
1138         while (g_variant_iter_loop(iter, "s", &dns_value)) {
1139                 /* Check Type of DNS Address */
1140                 if (__net_check_address_type(AF_INET6, dns_value)) {
1141                         /* IPv6 */
1142                         if (dnsCount6 < NET_DNS_ADDR_MAX) {
1143                                 net_info->DnsAddr6[dnsCount6].Type =
1144                                         NET_ADDR_IPV6;
1145                                 inet_pton(AF_INET6, dns_value,
1146                                                 &net_info->DnsAddr6[dnsCount6]\
1147                                                 .Data.Ipv6);
1148                                 dnsCount6++;
1149                         }
1150                 } else if (__net_check_address_type(AF_INET, dns_value)) {
1151                         /* IPv4 */
1152                         if (dnsCount < NET_DNS_ADDR_MAX) {
1153                                 net_info->DnsAddr[dnsCount].Type =
1154                                         NET_ADDR_IPV4;
1155                                 __net_extract_ip(dns_value,
1156                                                 &net_info->DnsAddr[dnsCount]);
1157                                 dnsCount++;
1158                         }
1159                 } else { /* DNS Type */
1160                         dns_type = g_strdup(dns_value);
1161                         if (g_strcmp0(dns_type, "ipv4.manual") == 0)
1162                                 net_info->DnsConfigType =
1163                                         NET_DNS_CONFIG_TYPE_STATIC;
1164                         else if (g_strcmp0(dns_type, "ipv4.dhcp") == 0)
1165                                 net_info->DnsConfigType =
1166                                         NET_DNS_CONFIG_TYPE_DYNAMIC;
1167                         if (g_strcmp0(dns_type, "ipv6.manual") == 0)
1168                                 net_info->DnsConfigType6 =
1169                                         NET_DNS_CONFIG_TYPE_STATIC;
1170                         else if (g_strcmp0(dns_type, "ipv6.dhcp") == 0)
1171                                 net_info->DnsConfigType6 =
1172                                         NET_DNS_CONFIG_TYPE_DYNAMIC;
1173                         g_free(dns_type);
1174                         }
1175                 }
1176                 g_variant_iter_free(iter);
1177
1178                 net_info->DnsCount = dnsCount;
1179                 net_info->DnsCount6 = dnsCount6;
1180 }
1181
1182 static void __net_extract_proxy_value(GVariant *variant, net_dev_info_t *net_info)
1183 {
1184         const gchar *subKey = NULL;
1185         const gchar *value = NULL;
1186         GVariant *var = NULL;
1187         GVariantIter *iter = NULL;
1188         const gchar *url = NULL;
1189         gchar *servers = NULL;
1190
1191         g_variant_get(variant, "a{sv}", &iter);
1192         while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
1193                 if (g_strcmp0(subKey, "Method") == 0) {
1194                         value = g_variant_get_string(var, NULL);
1195
1196                         if (g_strcmp0(value, "direct") == 0)
1197                                 net_info->ProxyMethod = NET_PROXY_TYPE_DIRECT;
1198                         else if (g_strcmp0(value, "auto") == 0)
1199                                 net_info->ProxyMethod = NET_PROXY_TYPE_AUTO;
1200                         else if (g_strcmp0(value, "manual") == 0)
1201                                 net_info->ProxyMethod = NET_PROXY_TYPE_MANUAL;
1202                         else
1203                                 net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
1204                 } else if (g_strcmp0(subKey, "URL") == 0) {
1205                         url = g_variant_get_string(var, NULL);
1206                 } else if (g_strcmp0(subKey, "Servers") == 0) {
1207                         GVariantIter *iter_sub = NULL;
1208
1209                         g_variant_get(var, "as", &iter_sub);
1210                         if (!g_variant_iter_loop(iter_sub, "s", &servers))
1211                                 NETWORK_LOG(NETWORK_LOW, "There was no value");
1212                         g_variant_iter_free(iter_sub);
1213                 }
1214         }
1215         g_variant_iter_free(iter);
1216
1217         if (net_info->ProxyMethod == NET_PROXY_TYPE_AUTO && url != NULL)
1218                 g_strlcpy(net_info->ProxyAddr, url, NET_PROXY_LEN_MAX);
1219         else if (net_info->ProxyMethod == NET_PROXY_TYPE_MANUAL && servers != NULL)
1220                 g_strlcpy(net_info->ProxyAddr, servers, NET_PROXY_LEN_MAX);
1221
1222         if (servers)
1223                 g_free(servers);
1224 }
1225
1226 static void __net_extract_proxy_configuration_value(GVariant *variant, net_dev_info_t *net_info)
1227 {
1228         const gchar *subKey = NULL;
1229         const gchar *value = NULL;
1230         GVariant *var = NULL;
1231         GVariantIter *iter = NULL;
1232         const gchar *url = NULL;
1233         gchar *servers = NULL;
1234
1235         g_variant_get(variant, "a{sv}", &iter);
1236         while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
1237                 if (g_strcmp0(subKey, "Method") == 0) {
1238                         value = g_variant_get_string(var, NULL);
1239
1240                         if (g_strcmp0(value, "direct") == 0)
1241                                 net_info->ProxyMethod = NET_PROXY_TYPE_DIRECT;
1242                         else if (g_strcmp0(value, "auto") == 0)
1243                                 net_info->ProxyMethod = NET_PROXY_TYPE_AUTO;
1244                         else if (g_strcmp0(value, "manual") == 0)
1245                                 net_info->ProxyMethod = NET_PROXY_TYPE_MANUAL;
1246                         else
1247                                 net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
1248                 } else if (g_strcmp0(subKey, "URL") == 0) {
1249                         url = g_variant_get_string(var, NULL);
1250                 } else if (g_strcmp0(subKey, "Servers") == 0) {
1251                         GVariantIter *iter_sub = NULL;
1252
1253                         g_variant_get(var, "as", &iter_sub);
1254                         if (!g_variant_iter_loop(iter_sub, "s", &servers))
1255                                 NETWORK_LOG(NETWORK_LOW, "There was no value");
1256                         g_variant_iter_free(iter_sub);
1257                 }
1258         }
1259         g_variant_iter_free(iter);
1260
1261         if (net_info->ProxyMethod == NET_PROXY_TYPE_AUTO && url != NULL)
1262                 g_strlcpy(net_info->ProxyAddr, url, NET_PROXY_LEN_MAX);
1263         else if (net_info->ProxyMethod == NET_PROXY_TYPE_MANUAL && servers != NULL)
1264                 g_strlcpy(net_info->ProxyAddr, servers, NET_PROXY_LEN_MAX);
1265
1266         if (servers)
1267                 g_free(servers);
1268 }
1269
1270 static net_ethernet_eap_type_t __net_convert_eap_type_from_string(const char *eap_type)
1271 {
1272         if (g_strcmp0(eap_type, "MD5") == 0)
1273                 return NET_ETHERNET_EAP_TYPE_MD5;
1274         else if (g_strcmp0(eap_type, "PEAP") == 0)
1275                 return NET_ETHERNET_EAP_TYPE_PEAP;
1276         else if (g_strcmp0(eap_type, "TLS") == 0)
1277                 return NET_ETHERNET_EAP_TYPE_TLS;
1278         else if (g_strcmp0(eap_type, "TTLS") == 0)
1279                 return NET_ETHERNET_EAP_TYPE_TTLS;
1280         else if (g_strcmp0(eap_type, "FAST") == 0)
1281                 return NET_ETHERNET_EAP_TYPE_FAST;
1282         else
1283                 return -1;
1284 }
1285
1286 static net_ethernet_eap_auth_type_t __net_convert_eap_auth_from_string(const char *eap_auth)
1287 {
1288         if (g_strcmp0(eap_auth, "PAP") == 0)
1289                 return NET_ETHERNET_EAP_AUTH_TYPE_PAP;
1290         else if (g_strcmp0(eap_auth, "MSCHAP") == 0)
1291                 return NET_ETHERNET_EAP_AUTH_TYPE_MSCHAP;
1292         else if (g_strcmp0(eap_auth, "MSCHAPV2") == 0)
1293                 return NET_ETHERNET_EAP_AUTH_TYPE_MSCHAPV2;
1294         else if (g_strcmp0(eap_auth, "GTC") == 0)
1295                 return NET_ETHERNET_EAP_AUTH_TYPE_GTC;
1296         else if (g_strcmp0(eap_auth, "MD5") == 0)
1297                 return NET_ETHERNET_EAP_AUTH_TYPE_MD5;
1298         else
1299                 return NET_ETHERNET_EAP_AUTH_TYPE_NONE;
1300 }
1301
1302 static void __net_extract_eapol_value(GVariant *variant, net_dev_info_t *net_info)
1303 {
1304         const gchar *subKey = NULL;
1305         const gchar *value = NULL;
1306         GVariant *var = NULL;
1307         GVariantIter *iter = NULL;
1308
1309         g_variant_get(variant, "a{sv}", &iter);
1310         while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
1311                 if (g_strcmp0(subKey, "UseEapol") == 0) {
1312                         net_info->use_eapol = g_variant_get_boolean(var);
1313
1314                 } else if (g_strcmp0(subKey, "EAP") == 0) {
1315                         value = g_variant_get_string(var, NULL);
1316
1317                         if (value != NULL)
1318                                 net_info->eap.eap_type = __net_convert_eap_type_from_string(value);
1319                 } else if (g_strcmp0(subKey, "Identity") == 0) {
1320                         value = g_variant_get_string(var, NULL);
1321
1322                         if (value != NULL)
1323                                 g_strlcpy(net_info->eap.username, value, NET_USERNAME_LEN+1);
1324                 } else if (g_strcmp0(subKey, "AnonymousIdentity") == 0) {
1325                         value = g_variant_get_string(var, NULL);
1326
1327                         if (value != NULL)
1328                                 g_strlcpy(net_info->eap.anonymous_identity, value, NET_USERNAME_LEN+1);
1329                 } else if (g_strcmp0(subKey, "CACertFile") == 0) {
1330                         value = g_variant_get_string(var, NULL);
1331
1332                         if (value != NULL)
1333                                 g_strlcpy(net_info->eap.ca_cert_filename, value, NET_CA_CERT_FILENAME_LEN+1);
1334                 } else if (g_strcmp0(subKey, "ClientCertFile") == 0) {
1335                         value = g_variant_get_string(var, NULL);
1336
1337                         if (value != NULL)
1338                                 g_strlcpy(net_info->eap.client_cert_filename, value, NET_CLIENT_CERT_FILENAME_LEN+1);
1339                 } else if (g_strcmp0(subKey, "PrivateKeyFile") == 0) {
1340                         value = g_variant_get_string(var, NULL);
1341
1342                         if (value != NULL)
1343                                 g_strlcpy(net_info->eap.private_key_filename, value, NET_PRIVATE_KEY_FILENAME_LEN+1);
1344                 } else if (g_strcmp0(subKey, "Phase2") == 0) {
1345                         value = g_variant_get_string(var, NULL);
1346
1347                         if (value != NULL)
1348                                 net_info->eap.eap_auth = __net_convert_eap_auth_from_string(value);
1349                 } else if (g_strcmp0(subKey, "Phase1") == 0) {
1350                         value = g_variant_get_string(var, NULL);
1351
1352                         if (value != NULL) {
1353                                 if (g_strcmp0(value, "1") == 0)
1354                                         net_info->eap.peap_version = 1;
1355                                 else
1356                                         net_info->eap.peap_version = 0;
1357                         }
1358                 } else if (g_strcmp0(subKey, "PacFile") == 0) {
1359                         value = g_variant_get_string(var, NULL);
1360
1361                         if (value != NULL)
1362                                 g_strlcpy(net_info->eap.pac_filename, value, NET_PAC_FILENAME_LEN+1);
1363                 }
1364         }
1365         g_variant_iter_free(iter);
1366 }
1367
1368 static int __net_extract_common_info(const char *key, GVariant *variant, net_profile_info_t *ProfInfo)
1369 {
1370         __NETWORK_FUNC_ENTER__;
1371
1372         net_err_t Error = NET_ERR_NONE;
1373         net_dev_info_t *net_info = NULL;
1374
1375         if (ProfInfo->profile_type == NET_DEVICE_CELLULAR) {
1376                 net_info = &(ProfInfo->ProfileInfo.Pdp.net_info);
1377         } else if (ProfInfo->profile_type == NET_DEVICE_WIFI) {
1378                 net_info = &(ProfInfo->ProfileInfo.Wlan.net_info);
1379         } else if (ProfInfo->profile_type == NET_DEVICE_ETHERNET) {
1380                 net_info = &(ProfInfo->ProfileInfo.Ethernet.net_info);
1381         } else if (ProfInfo->profile_type == NET_DEVICE_BLUETOOTH) {
1382                 net_info = &(ProfInfo->ProfileInfo.Bluetooth.net_info);
1383         } else if (ProfInfo->profile_type == NET_DEVICE_MESH) {
1384                 net_info = &(ProfInfo->ProfileInfo.Mesh.net_info);
1385         } else {
1386                 NETWORK_LOG(NETWORK_ERROR,
1387                                 "Invalid Profile type. [%d]", ProfInfo->profile_type);
1388                 return NET_ERR_INVALID_PARAM;
1389         }
1390
1391         if (g_strcmp0(key, "State") == 0) {
1392                 __net_extract_state_value(variant, ProfInfo);
1393         } else if (g_strcmp0(key, "StateIPv6") == 0) {
1394                 __net_extract_state6_value(variant, ProfInfo);
1395         } else if (g_strcmp0(key, "Error") == 0) {
1396                 __net_extract_error(variant, ProfInfo);
1397         } else if (g_strcmp0(key, "Favorite") == 0) {
1398                 ProfInfo->Favourite = (char)g_variant_get_boolean(variant);
1399         } else if (g_strcmp0(key, "Ethernet") == 0) {
1400                 __net_extract_ethernet_value(variant, net_info);
1401         } else if (g_strcmp0(key, "IPv4") == 0) {
1402                 __net_extract_ipv4_value(variant, net_info);
1403         } else if (g_strcmp0(key, "IPv4.Configuration") == 0) {
1404                 __net_extract_ipv4_configuration_value(variant, net_info);
1405         } else if (g_strcmp0(key, "IPv6") == 0) {
1406                 __net_extract_ipv6_value(variant, net_info);
1407         } else if (g_strcmp0(key, "IPv6.Configuration") == 0) {
1408                 __net_extract_ipv6_configuration_value(variant, net_info);
1409         } else if (g_strcmp0(key, "Nameservers") == 0) {
1410                 __net_extract_nameserver_value(variant, net_info);
1411         } else if (g_strcmp0(key, "Nameservers.Configuration") == 0 && net_info->DnsCount == 0) {
1412                 __net_extract_nameserver_configuration_value(variant, net_info);
1413         } else if (g_strcmp0(key, "Domains") == 0) {
1414         } else if (g_strcmp0(key, "Domains.Configuration") == 0) {
1415         } else if (g_strcmp0(key, "Proxy") == 0) {
1416                 __net_extract_proxy_value(variant, net_info);
1417         } else if (g_strcmp0(key, "Proxy.Configuration") == 0 &&
1418                         net_info->ProxyMethod != NET_PROXY_TYPE_AUTO &&
1419                         net_info->ProxyMethod != NET_PROXY_TYPE_MANUAL) {
1420                 __net_extract_proxy_configuration_value(variant, net_info);
1421         } else if (g_strcmp0(key, "Provider") == 0) {
1422                 /* Do nothing */
1423         } else if (g_strcmp0(key, "EapOverEthernet") == 0) {
1424                 __net_extract_eapol_value(variant, net_info);
1425         }
1426
1427         __NETWORK_FUNC_EXIT__;
1428         return Error;
1429 }
1430
1431 static wlan_eap_type_t __convert_eap_type_from_string(const char *eap_type)
1432 {
1433         if (eap_type == NULL)
1434                 return WLAN_SEC_EAP_TYPE_PEAP;
1435         else if (g_strcmp0(eap_type, "peap") == 0)
1436                 return WLAN_SEC_EAP_TYPE_PEAP;
1437         else if (g_strcmp0(eap_type, "tls") == 0)
1438                 return WLAN_SEC_EAP_TYPE_TLS;
1439         else if (g_strcmp0(eap_type, "ttls") == 0)
1440                 return WLAN_SEC_EAP_TYPE_TTLS;
1441         else if (g_strcmp0(eap_type, "sim") == 0)
1442                 return WLAN_SEC_EAP_TYPE_SIM;
1443         else if (g_strcmp0(eap_type, "aka") == 0)
1444                 return WLAN_SEC_EAP_TYPE_AKA;
1445         else
1446                 return WLAN_SEC_EAP_TYPE_PEAP;
1447 }
1448
1449 static wlan_eap_auth_type_t __convert_eap_auth_from_string(const char *eap_auth)
1450 {
1451         if (eap_auth == NULL)
1452                 return WLAN_SEC_EAP_AUTH_NONE;
1453         else if (g_strcmp0(eap_auth, "NONE") == 0)
1454                 return WLAN_SEC_EAP_AUTH_NONE;
1455         else if (g_strcmp0(eap_auth, "PAP") == 0)
1456                 return WLAN_SEC_EAP_AUTH_PAP;
1457         else if (g_strcmp0(eap_auth, "MSCHAP") == 0)
1458                 return WLAN_SEC_EAP_AUTH_MSCHAP;
1459         else if (g_strcmp0(eap_auth, "MSCHAPV2") == 0)
1460                 return WLAN_SEC_EAP_AUTH_MSCHAPV2;
1461         else if (g_strcmp0(eap_auth, "GTC") == 0)
1462                 return WLAN_SEC_EAP_AUTH_GTC;
1463         else if (g_strcmp0(eap_auth, "MD5") == 0)
1464                 return WLAN_SEC_EAP_AUTH_MD5;
1465         else
1466                 return WLAN_SEC_EAP_AUTH_NONE;
1467 }
1468
1469 static void __net_set_wifi_mode(GVariant *var, net_wifi_profile_info_t *Wlan)
1470 {
1471         const gchar *value = g_variant_get_string(var, NULL);
1472
1473         if (g_strcmp0(value, "managed") == 0)
1474                 Wlan->wlan_mode = NETPM_WLAN_CONNMODE_INFRA;
1475         else if (g_strcmp0(value, "adhoc") == 0)
1476                 Wlan->wlan_mode = NETPM_WLAN_CONNMODE_ADHOC;
1477         else
1478                 Wlan->wlan_mode = NETPM_WLAN_CONNMODE_AUTO;
1479 }
1480
1481 static void __net_set_wifi_security(GVariant *var, net_wifi_profile_info_t *Wlan)
1482 {
1483         GVariantIter *iter_sub = NULL;
1484         const gchar *value = NULL;
1485
1486         g_variant_get(var, "as", &iter_sub);
1487         while (g_variant_iter_loop(iter_sub, "s", &value)) {
1488                 if (g_strcmp0(value, "none") == 0 &&
1489                                 Wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1490                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1491                 else if (g_strcmp0(value, "wep") == 0 &&
1492                                 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WEP)
1493                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_WEP;
1494                 else if (g_strcmp0(value, "psk") == 0 &&
1495                                 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1496                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
1497                 else if (g_strcmp0(value, "ft_psk") == 0 &&
1498                                 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_FT_PSK)
1499                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_FT_PSK;
1500                 else if (g_strcmp0(value, "ieee8021x") == 0 &&
1501                                 Wlan->security_info.sec_mode < WLAN_SEC_MODE_IEEE8021X)
1502                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_IEEE8021X;
1503                 else if (g_strcmp0(value, "wpa") == 0 &&
1504                                 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1505                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
1506                 else if (g_strcmp0(value, "rsn") == 0 &&
1507                                 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1508                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK;
1509                 else if (g_strcmp0(value, "sae") == 0 &&
1510                                 Wlan->security_info.sec_mode < WLAN_SEC_MODE_SAE)
1511                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_SAE;
1512                 else if (g_strcmp0(value, "wps") == 0)
1513                         Wlan->security_info.wps_support = TRUE;
1514                 else if (Wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1515                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1516         }
1517         g_variant_iter_free(iter_sub);
1518 }
1519
1520 static void __net_set_wifi_encryption_mode(GVariant *var, net_wifi_profile_info_t *Wlan)
1521 {
1522         const gchar *value = g_variant_get_string(var, NULL);
1523
1524         if (g_strcmp0(value, "none") == 0)
1525                 Wlan->security_info.enc_mode = WLAN_ENC_MODE_NONE;
1526         else if (g_strcmp0(value, "wep") == 0)
1527                 Wlan->security_info.enc_mode = WLAN_ENC_MODE_WEP;
1528         else if (g_strcmp0(value, "tkip") == 0)
1529                 Wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP;
1530         else if (g_strcmp0(value, "aes") == 0)
1531                 Wlan->security_info.enc_mode = WLAN_ENC_MODE_AES;
1532         else if (g_strcmp0(value, "mixed") == 0)
1533                 Wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP_AES_MIXED;
1534 }
1535
1536 static void __net_set_wifi_name(GVariant *var, net_wifi_profile_info_t *Wlan)
1537 {
1538         const gchar *value = g_variant_get_string(var, NULL);
1539
1540         if (value != NULL)
1541                 g_strlcpy(Wlan->essid, value, NET_WLAN_ESSID_LEN);
1542 }
1543
1544 static void __net_set_wifi_passphrase(GVariant *var, net_wifi_profile_info_t *Wlan)
1545 {
1546         wlan_security_info_t *security_info = &(Wlan->security_info);
1547         const gchar *value = g_variant_get_string(var, NULL);
1548
1549         if (security_info->sec_mode == WLAN_SEC_MODE_WEP && value != NULL)
1550                 g_strlcpy(security_info->authentication.wep.wepKey,
1551                                 value, NETPM_WLAN_MAX_WEP_KEY_LEN+1);
1552         else if ((security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
1553                                 security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) &&
1554                         value != NULL)
1555                 g_strlcpy(security_info->authentication.psk.pskKey,
1556                                 value, NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN+1);
1557         else if (security_info->sec_mode == WLAN_SEC_MODE_SAE && value != NULL)
1558                 g_strlcpy(security_info->authentication.sae.saeKey,
1559                                 value, NETPM_WLAN_MAX_SAE_KEY_LEN+1);
1560 }
1561
1562 static void __net_set_wifi_bssid(GVariant *var, net_wifi_profile_info_t *Wlan)
1563 {
1564         const gchar *value = g_variant_get_string(var, NULL);
1565
1566         if (value != NULL)
1567                 g_strlcpy(Wlan->bssid, value, NET_MAX_MAC_ADDR_LEN);
1568 }
1569
1570 static void __net_set_wifi_eap(GVariant *var, net_wifi_profile_info_t *Wlan)
1571 {
1572         const gchar *value = g_variant_get_string(var, NULL);
1573
1574         if (value != NULL)
1575                 Wlan->security_info.authentication.eap.eap_type =
1576                         __convert_eap_type_from_string(value);
1577 }
1578
1579 static void __net_set_wifi_phase2(GVariant *var, net_wifi_profile_info_t *Wlan)
1580 {
1581         const gchar *value = g_variant_get_string(var, NULL);
1582
1583         if (value != NULL)
1584                 Wlan->security_info.authentication.eap.eap_auth =
1585                         __convert_eap_auth_from_string(value);
1586 }
1587
1588 static void __net_set_wifi_identity(GVariant *var, net_wifi_profile_info_t *Wlan)
1589 {
1590         const gchar *value = g_variant_get_string(var, NULL);
1591
1592         if (value != NULL)
1593                 g_strlcpy(Wlan->security_info.authentication.eap.username,
1594                                 value, NETPM_WLAN_USERNAME_LEN+1);
1595 }
1596
1597 static void __net_set_wifi_password(GVariant *var, net_wifi_profile_info_t *Wlan)
1598 {
1599         const gchar *value = g_variant_get_string(var, NULL);
1600
1601         if (value != NULL)
1602                 g_strlcpy(Wlan->security_info.authentication.eap.password,
1603                                 value, NETPM_WLAN_PASSWORD_LEN+1);
1604 }
1605
1606 static void __net_set_wifi_ca_cert_file(GVariant *var, net_wifi_profile_info_t *Wlan)
1607 {
1608         const gchar *value = g_variant_get_string(var, NULL);
1609
1610         if (value != NULL)
1611                 g_strlcpy(Wlan->security_info.authentication.eap.ca_cert_filename,
1612                                 value, NETPM_WLAN_CA_CERT_FILENAME_LEN+1);
1613 }
1614
1615 static void __net_set_wifi_client_cert_file(GVariant *var, net_wifi_profile_info_t *Wlan)
1616 {
1617         const gchar *value = g_variant_get_string(var, NULL);
1618
1619         if (value != NULL)
1620                 g_strlcpy(Wlan->security_info.authentication.eap.client_cert_filename,
1621                                 value, NETPM_WLAN_CLIENT_CERT_FILENAME_LEN+1);
1622 }
1623
1624 static void __net_set_wifi_private_key_file(GVariant *var, net_wifi_profile_info_t *Wlan)
1625 {
1626         const gchar *value = g_variant_get_string(var, NULL);
1627
1628         if (value != NULL)
1629                 g_strlcpy(Wlan->security_info.authentication.eap.private_key_filename,
1630                                 value, NETPM_WLAN_PRIVATE_KEY_FILENAME_LEN+1);
1631 }
1632
1633 static void __net_set_wifi_private_key_passphrase(GVariant *var, net_wifi_profile_info_t *Wlan)
1634 {
1635         const gchar *value = g_variant_get_string(var, NULL);
1636
1637         if (value != NULL)
1638                 g_strlcpy(Wlan->security_info.authentication.eap.private_key_passwd,
1639                                 value, NETPM_WLAN_PRIVATE_KEY_PASSWD_LEN+1);
1640 }
1641
1642 static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_t *ProfInfo)
1643 {
1644         net_err_t Error = NET_ERR_NONE;
1645         net_wifi_profile_info_t *Wlan = &(ProfInfo->ProfileInfo.Wlan);
1646         GVariant *var = NULL;
1647         const gchar *key = NULL;
1648
1649         __NETWORK_FUNC_ENTER__;
1650
1651         while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
1652                 if (g_strcmp0(key, "Mode") == 0) {
1653                         __net_set_wifi_mode(var, Wlan);
1654                 } else if (g_strcmp0(key, "Security") == 0) {
1655                         __net_set_wifi_security(var, Wlan);
1656                 } else if (g_strcmp0(key, "EncryptionMode") == 0) {
1657                         __net_set_wifi_encryption_mode(var, Wlan);
1658                 } else if (g_strcmp0(key, "Passpoint") == 0) {
1659                         Wlan->passpoint = g_variant_get_boolean(var);
1660                 } else if (g_strcmp0(key, "Strength") == 0) {
1661                         Wlan->Strength = g_variant_get_byte(var);
1662                 } else if (g_strcmp0(key, "Name") == 0) {
1663                         __net_set_wifi_name(var, Wlan);
1664                 } else if (g_strcmp0(key, "Passphrase") == 0) {
1665                         __net_set_wifi_passphrase(var, Wlan);
1666                 } else if (g_strcmp0(key, "PassphraseRequired") == 0) {
1667                         Wlan->PassphraseRequired = g_variant_get_boolean(var);
1668                 } else if (g_strcmp0(key, "BSSID") == 0) {
1669                         __net_set_wifi_bssid(var, Wlan);
1670                 } else if (g_strcmp0(key, "MaxSpeed") == 0) {
1671                         Wlan->max_rate = g_variant_get_int32(var);
1672                 } else if (g_strcmp0(key, "Frequency") == 0) {
1673                         Wlan->frequency = (unsigned int)g_variant_get_uint16(var);
1674                 } else if (g_strcmp0(key, "EAP") == 0) {
1675                         __net_set_wifi_eap(var, Wlan);
1676                 } else if (g_strcmp0(key, "Phase2") == 0) {
1677                         __net_set_wifi_phase2(var, Wlan);
1678                 } else if (g_strcmp0(key, "Identity") == 0) {
1679                         __net_set_wifi_identity(var, Wlan);
1680                 } else if (g_strcmp0(key, "Password") == 0) {
1681                         __net_set_wifi_password(var, Wlan);
1682                 } else if (g_strcmp0(key, "CACertFile") == 0) {
1683                         __net_set_wifi_ca_cert_file(var, Wlan);
1684                 } else if (g_strcmp0(key, "ClientCertFile") == 0) {
1685                         __net_set_wifi_client_cert_file(var, Wlan);
1686                 } else if (g_strcmp0(key, "PrivateKeyFile") == 0) {
1687                         __net_set_wifi_private_key_file(var, Wlan);
1688                 } else if (g_strcmp0(key, "PrivateKeyPassphrase") == 0) {
1689                         __net_set_wifi_private_key_passphrase(var, Wlan);
1690                 } else if (g_strcmp0(key, "Keymgmt") == 0) {
1691                         Wlan->security_info.keymgmt = (unsigned int)g_variant_get_uint32(var);
1692                 } else
1693                         Error = __net_extract_common_info(key, var, ProfInfo);
1694         }
1695
1696         __NETWORK_FUNC_EXIT__;
1697         return Error;
1698 }
1699
1700 static int __net_extract_mesh_info(GVariantIter *array,
1701                                                                 net_profile_info_t *ProfInfo)
1702 {
1703         net_err_t Error = NET_ERR_NONE;
1704         net_mesh_profile_info_t *Mesh = &(ProfInfo->ProfileInfo.Mesh);
1705         GVariant *var = NULL;
1706         const gchar *key = NULL;
1707
1708         __NETWORK_FUNC_ENTER__;
1709
1710         while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
1711                 const gchar *value = NULL;
1712
1713                 if (g_strcmp0(key, "Security") == 0) {
1714                         value = g_variant_get_string(var, NULL);
1715                         if (g_strcmp0(value, "none") == 0 &&
1716                                 Mesh->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1717                                 Mesh->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1718                         else if (g_strcmp0(value, "sae") == 0 &&
1719                                          Mesh->security_info.sec_mode < WLAN_SEC_MODE_SAE)
1720                                 Mesh->security_info.sec_mode = WLAN_SEC_MODE_SAE;
1721                         else if (Mesh->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1722                                 Mesh->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1723                 } else if (g_strcmp0(key, "Strength") == 0) {
1724                         Mesh->Strength = g_variant_get_byte(var);
1725                 } else if (g_strcmp0(key, "Name") == 0) {
1726                         value = g_variant_get_string(var, NULL);
1727
1728                         if (value != NULL)
1729                                 g_strlcpy(Mesh->essid, value, NET_WLAN_ESSID_LEN);
1730                 } else if (g_strcmp0(key, "Passphrase") == 0) {
1731                         wlan_security_info_t *security_info = &(Mesh->security_info);
1732                         value = g_variant_get_string(var, NULL);
1733
1734                         if (security_info->sec_mode == WLAN_SEC_MODE_SAE && value != NULL)
1735                                 g_strlcpy(security_info->authentication.sae.saeKey,
1736                                                 value, NETPM_WLAN_MAX_SAE_KEY_LEN+1);
1737                 } else if (g_strcmp0(key, "PassphraseRequired") == 0) {
1738                         gboolean val;
1739
1740                         val = g_variant_get_boolean(var);
1741
1742                         if (val)
1743                                 Mesh->PassphraseRequired = TRUE;
1744                         else
1745                                 Mesh->PassphraseRequired = FALSE;
1746                 } else if (g_strcmp0(key, "BSSID") == 0) {
1747                         value = g_variant_get_string(var, NULL);
1748
1749                         if (value != NULL)
1750                                 g_strlcpy(Mesh->bssid, value, NET_MAX_MAC_ADDR_LEN);
1751
1752                 } else if (g_strcmp0(key, "Frequency") == 0) {
1753                         Mesh->frequency = (unsigned int)g_variant_get_uint16(var);
1754
1755                 } else
1756                         Error = __net_extract_common_info(key, var, ProfInfo);
1757         }
1758
1759         __NETWORK_FUNC_EXIT__;
1760         return Error;
1761 }
1762
1763 static int __net_extract_mobile_info(network_info_t *network_info,
1764                         GVariantIter *array, net_profile_info_t *ProfInfo)
1765 {
1766         net_err_t Error = NET_ERR_NONE;
1767         GVariant *var = NULL;
1768         const gchar *key = NULL;
1769
1770         __NETWORK_FUNC_ENTER__;
1771
1772         while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
1773                 const gchar *value = NULL;
1774
1775                 if (g_strcmp0(key, "Mode") == 0) {
1776                         value = g_variant_get_string(var, NULL);
1777
1778                         if (g_strcmp0(value, "gprs") == 0)
1779                                 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_GPRS;
1780                         else if (g_strcmp0(value, "edge") == 0)
1781                                 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_EDGE;
1782                         else if (g_strcmp0(value, "umts") == 0)
1783                                 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_UMTS;
1784                         else
1785                                 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_NONE;
1786                 } else if (g_strcmp0(key, "Roaming") == 0) {
1787                         gboolean val;
1788
1789                         val = g_variant_get_boolean(var);
1790                         if (val)
1791                                 ProfInfo->ProfileInfo.Pdp.Roaming = TRUE;
1792                         else
1793                                 ProfInfo->ProfileInfo.Pdp.Roaming = FALSE;
1794                 } else if (g_strcmp0(key, "SetupRequired") == 0) {
1795                         gboolean val;
1796
1797                         val = g_variant_get_boolean(var);
1798                         if (val)
1799                                 ProfInfo->ProfileInfo.Pdp.SetupRequired = TRUE;
1800                         else
1801                                 ProfInfo->ProfileInfo.Pdp.SetupRequired = FALSE;
1802 #if defined TIZEN_DUALSIM_ENABLE
1803                 } else if (g_strcmp0(key, "Name") == 0) {
1804                         value = g_variant_get_string(var, NULL);
1805                         if (value != NULL) {
1806                                 gchar **list = g_strsplit(value, "/context", 0);
1807
1808                                 if (*list) {
1809                                         g_strlcpy(ProfInfo->ProfileInfo.Pdp.PSModemPath,
1810                                                                 list[0], NET_PROFILE_NAME_LEN_MAX);
1811                                         NETWORK_LOG(NETWORK_LOW, "Modem path: %s",
1812                                                                 ProfInfo->ProfileInfo.Pdp.PSModemPath);
1813                                         g_strfreev(list);
1814                                 } else
1815                                         NETWORK_LOG(NETWORK_ERROR, "Invalid modem path: %s", value);
1816                         } else
1817                                 NETWORK_LOG(NETWORK_ERROR, "Null modem path");
1818 #endif
1819                 } else {
1820                         Error = __net_extract_common_info(key, var, ProfInfo);
1821                         if (Error != NET_ERR_NONE)
1822                                 NETWORK_LOG(NETWORK_ERROR, "fail to extract common info err(%d)", Error);
1823                 }
1824         }
1825
1826         /* Get Specific info from telephony service */
1827         net_telephony_profile_info_t telephony_profinfo;
1828         net_profile_name_t PdpProfName;
1829
1830         PdpProfName.ProfileName[0] = '\0';
1831
1832         __net_telephony_init_profile_info(&telephony_profinfo);
1833
1834         /* Find matching profile in telephony service */
1835         Error = __net_telephony_search_pdp_profile(network_info, ProfInfo->ProfileName, &PdpProfName);
1836
1837         if (Error == NET_ERR_NONE && strlen(PdpProfName.ProfileName) > 0) {
1838                 /* Get profile info from telephony service */
1839                 Error = __net_telephony_get_profile_info(network_info, &PdpProfName, &telephony_profinfo);
1840
1841                 if (Error == NET_ERR_NONE) {
1842                         ProfInfo->ProfileInfo.Pdp.ServiceType = telephony_profinfo.ServiceType;
1843
1844                         if (strlen(telephony_profinfo.Apn) > 0)
1845                                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.Apn,
1846                                                 telephony_profinfo.Apn, NET_PDP_APN_LEN_MAX);
1847
1848                         if (strlen(telephony_profinfo.ProxyAddr) > 0)
1849                                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.net_info.ProxyAddr,
1850                                                 telephony_profinfo.ProxyAddr, NET_PROXY_LEN_MAX);
1851
1852                         if (strlen(telephony_profinfo.HomeURL) > 0)
1853                                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.HomeURL,
1854                                                 telephony_profinfo.HomeURL, NET_HOME_URL_LEN_MAX);
1855
1856                         ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType = telephony_profinfo.AuthInfo.AuthType;
1857                         ProfInfo->ProfileInfo.Pdp.PdnType = telephony_profinfo.PdnType;
1858                         ProfInfo->ProfileInfo.Pdp.RoamPdnType = telephony_profinfo.RoamPdnType;
1859
1860                         if (strlen(telephony_profinfo.AuthInfo.UserName) > 0)
1861                                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.AuthInfo.UserName,
1862                                                 telephony_profinfo.AuthInfo.UserName,
1863                                                 NET_PDP_AUTH_USERNAME_LEN_MAX);
1864
1865                         if (strlen(telephony_profinfo.AuthInfo.Password) > 0)
1866                                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.AuthInfo.Password,
1867                                                 telephony_profinfo.AuthInfo.Password,
1868                                                 NET_PDP_AUTH_PASSWORD_LEN_MAX);
1869
1870                         if (strlen(telephony_profinfo.Keyword) > 0)
1871                                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.Keyword,
1872                                                 telephony_profinfo.Keyword,
1873                                                 NET_PDP_APN_LEN_MAX);
1874
1875                         ProfInfo->ProfileInfo.Pdp.Hidden = telephony_profinfo.Hidden;
1876                         ProfInfo->ProfileInfo.Pdp.Editable = telephony_profinfo.Editable;
1877                         ProfInfo->ProfileInfo.Pdp.DefaultConn = telephony_profinfo.DefaultConn;
1878                 }
1879         }
1880
1881         __NETWORK_FUNC_EXIT__;
1882         return Error;
1883 }
1884
1885 static int __net_extract_ethernet_info(GVariantIter *array, net_profile_info_t *ProfInfo)
1886 {
1887         net_err_t Error = NET_ERR_NONE;
1888         GVariant *var = NULL;
1889         const gchar *key = NULL;
1890
1891         __NETWORK_FUNC_ENTER__;
1892
1893         while (g_variant_iter_loop(array, "{sv}", &key, &var))
1894                 Error = __net_extract_common_info(key, var, ProfInfo);
1895
1896         __NETWORK_FUNC_EXIT__;
1897         return Error;
1898 }
1899
1900 static int __net_extract_bluetooth_info(GVariantIter *array, net_profile_info_t *ProfInfo)
1901 {
1902         net_err_t Error = NET_ERR_NONE;
1903         GVariant *var = NULL;
1904         const gchar *key = NULL;
1905
1906         __NETWORK_FUNC_ENTER__;
1907
1908         while (g_variant_iter_loop(array, "{sv}", &key, &var))
1909                 Error = __net_extract_common_info(key, var, ProfInfo);
1910
1911         __NETWORK_FUNC_EXIT__;
1912         return Error;
1913 }
1914
1915 static int __net_extract_service_info(network_info_t *network_info,
1916                 const char *ProfileName, GVariantIter *iter,
1917                 net_profile_info_t *ProfInfo)
1918 {
1919         __NETWORK_FUNC_ENTER__;
1920
1921         net_err_t Error = NET_ERR_NONE;
1922         net_device_t profileType = NET_DEVICE_UNKNOWN;
1923         gchar *key = NULL;
1924         GVariant *value = NULL;
1925
1926         while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
1927                 const gchar *tech = NULL;
1928
1929                 if (g_strcmp0(key, "Type") == 0) {
1930                         tech = g_variant_get_string(value, NULL);
1931
1932                         if (g_strcmp0(tech, "wifi") == 0)
1933                                 profileType = NET_DEVICE_WIFI;
1934                         else if (g_strcmp0(tech, "cellular") == 0)
1935                                 profileType = NET_DEVICE_CELLULAR;
1936                         else if (g_strcmp0(tech, "ethernet") == 0)
1937                                 profileType = NET_DEVICE_ETHERNET;
1938                         else if (g_strcmp0(tech, "bluetooth") == 0)
1939                                 profileType = NET_DEVICE_BLUETOOTH;
1940                         else if (g_strcmp0(tech, "mesh") == 0)
1941                                 profileType = NET_DEVICE_MESH;
1942
1943                         g_variant_unref(value);
1944                         g_free(key);
1945                         break;
1946                 }
1947         }
1948
1949         if (profileType == NET_DEVICE_WIFI) {
1950                 if ((Error = __net_pm_init_profile_info(NET_DEVICE_WIFI, ProfInfo)) != NET_ERR_NONE) {
1951                         NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
1952                         __NETWORK_FUNC_EXIT__;
1953                         return Error;
1954                 }
1955
1956                 ProfInfo->profile_type = NET_DEVICE_WIFI;
1957                 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1958                 g_strlcpy(ProfInfo->ProfileInfo.Wlan.net_info.ProfileName,
1959                                 ProfileName, NET_PROFILE_NAME_LEN_MAX);
1960
1961                 Error = __net_extract_wifi_info(iter, ProfInfo);
1962         } else if (profileType == NET_DEVICE_CELLULAR) {
1963                 if ((Error = __net_pm_init_profile_info(NET_DEVICE_CELLULAR, ProfInfo)) != NET_ERR_NONE) {
1964                         NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
1965                         __NETWORK_FUNC_EXIT__;
1966                         return Error;
1967                 }
1968
1969                 ProfInfo->profile_type = NET_DEVICE_CELLULAR;
1970                 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1971                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.net_info.ProfileName,
1972                                 ProfileName, NET_PROFILE_NAME_LEN_MAX);
1973
1974                 Error = __net_extract_mobile_info(network_info, iter, ProfInfo);
1975         } else if (profileType == NET_DEVICE_ETHERNET) {
1976                 if ((Error = __net_pm_init_profile_info(NET_DEVICE_ETHERNET, ProfInfo)) != NET_ERR_NONE) {
1977                         NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
1978                         __NETWORK_FUNC_EXIT__;
1979                         return Error;
1980                 }
1981
1982                 ProfInfo->profile_type = NET_DEVICE_ETHERNET;
1983                 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1984                 g_strlcpy(ProfInfo->ProfileInfo.Ethernet.net_info.ProfileName,
1985                                 ProfileName, NET_PROFILE_NAME_LEN_MAX);
1986
1987                 Error = __net_extract_ethernet_info(iter, ProfInfo);
1988         } else if (profileType == NET_DEVICE_BLUETOOTH) {
1989                 if ((Error = __net_pm_init_profile_info(NET_DEVICE_BLUETOOTH, ProfInfo)) != NET_ERR_NONE) {
1990                         NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
1991                         __NETWORK_FUNC_EXIT__;
1992                         return Error;
1993                 }
1994
1995                 ProfInfo->profile_type = NET_DEVICE_BLUETOOTH;
1996                 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1997                 g_strlcpy(ProfInfo->ProfileInfo.Bluetooth.net_info.ProfileName,
1998                                 ProfileName, NET_PROFILE_NAME_LEN_MAX);
1999
2000                 Error = __net_extract_bluetooth_info(iter, ProfInfo);
2001         } else if (profileType == NET_DEVICE_MESH) {
2002                 if ((Error = __net_pm_init_profile_info(NET_DEVICE_MESH, ProfInfo)) !=
2003                                                                 NET_ERR_NONE) {
2004                         NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
2005                         __NETWORK_FUNC_EXIT__;
2006                         return Error;
2007                 }
2008
2009                 ProfInfo->profile_type = NET_DEVICE_MESH;
2010                 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
2011                 g_strlcpy(ProfInfo->ProfileInfo.Mesh.net_info.ProfileName,
2012                                 ProfileName, NET_PROFILE_NAME_LEN_MAX);
2013
2014                 Error = __net_extract_mesh_info(iter, ProfInfo);
2015         } else {
2016                 NETWORK_LOG(NETWORK_ERROR, "Not supported profile type");
2017                 __NETWORK_FUNC_EXIT__;
2018                 return NET_ERR_NOT_SUPPORTED;
2019         }
2020
2021         if (Error != NET_ERR_NONE) {
2022                 NETWORK_LOG(NETWORK_ERROR,
2023                                 "Failed to extract service information from received message");
2024
2025                 __NETWORK_FUNC_EXIT__;
2026                 return Error;
2027         }
2028
2029         __NETWORK_FUNC_EXIT__;
2030         return Error;
2031 }
2032
2033 static int __net_get_profile_info(network_info_t *network_info,
2034                         const char *ProfileName, net_profile_info_t *ProfInfo)
2035 {
2036         __NETWORK_FUNC_ENTER__;
2037
2038         net_err_t Error = NET_ERR_NONE;
2039         GVariant *message = NULL;
2040         GVariantIter *iter = NULL;
2041         GVariantIter *service = NULL;
2042         gchar *path = NULL;
2043         gboolean services_found = FALSE;
2044
2045         message = _net_invoke_dbus_method(network_info,
2046                         CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
2047                         CONNMAN_MANAGER_INTERFACE, "GetServices", NULL,
2048                         &Error);
2049         if (message == NULL) {
2050                 NETWORK_LOG(NETWORK_ERROR, "Failed to get profile");
2051                 goto done;
2052         }
2053
2054         g_variant_get(message, "(a(oa{sv}))", &iter);
2055         while (g_variant_iter_loop(iter, "(oa{sv})", &path, &service)) {
2056                 if (g_strcmp0(ProfileName, path) == 0) {
2057                         Error = __net_extract_service_info(network_info,
2058                                                 ProfileName, service, ProfInfo);
2059                         g_variant_iter_free(service);
2060                         g_free(path);
2061                         services_found = TRUE;
2062                         break;
2063                 }
2064         }
2065         g_variant_iter_free(iter);
2066         g_variant_unref(message);
2067
2068         /* Check if mesh profile exists */
2069         if (!services_found) {
2070                 message = _net_invoke_dbus_method(network_info,
2071                                         CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
2072                                         CONNMAN_MANAGER_INTERFACE, "GetMeshPeers", NULL, &Error);
2073                 if (message == NULL) {
2074                         NETWORK_LOG(NETWORK_ERROR, "Failed to get mesh peers");
2075                         goto done;
2076                 }
2077                 g_variant_get(message, "(a(oa{sv}))", &iter);
2078                 while (g_variant_iter_loop(iter, "(oa{sv})", &path, &service)) {
2079                         if (g_strcmp0(ProfileName, path) == 0) {
2080                                 Error = __net_extract_service_info(network_info,
2081                                                         ProfileName, service, ProfInfo);
2082                                 g_variant_iter_free(service);
2083                                 g_free(path);
2084                                 break;
2085                         }
2086                 }
2087
2088                 g_variant_iter_free(iter);
2089                 g_variant_unref(message);
2090         }
2091
2092 done:
2093         __NETWORK_FUNC_EXIT__;
2094         return Error;
2095 }
2096
2097 static int __net_set_default_cellular_service_profile_sync(network_info_t *network_info,
2098                         const char *ProfileName)
2099 {
2100         __NETWORK_FUNC_ENTER__;
2101
2102         net_err_t Error = NET_ERR_NONE;
2103         GVariant *message = NULL;
2104         net_profile_name_t telephony_profile;
2105         char connman_profile[NET_PROFILE_NAME_LEN_MAX+1] = "";
2106
2107         g_strlcpy(connman_profile, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
2108
2109         Error = __net_telephony_search_pdp_profile(network_info, connman_profile, &telephony_profile);
2110         if (Error != NET_ERR_NONE) {
2111                 NETWORK_LOG(NETWORK_ERROR, "__net_telephony_search_pdp_profile() failed");
2112                 __NETWORK_FUNC_EXIT__;
2113                 return Error;
2114         }
2115
2116         message = _net_invoke_dbus_method(network_info,
2117                         TELEPHONY_SERVICE, telephony_profile.ProfileName,
2118                         TELEPHONY_PROFILE_INTERFACE, "SetDefaultConnection", NULL, &Error);
2119         if (message == NULL) {
2120                 NETWORK_LOG(NETWORK_ERROR, "Failed to set default cellular service(profile)");
2121                 goto done;
2122         }
2123
2124         /** Check Reply */
2125         gboolean result = FALSE;
2126
2127         g_variant_get(message, "(b)", &result);
2128         NETWORK_LOG(NETWORK_HIGH, "Set default cellular profile result: %d", result);
2129
2130         if (result)
2131                 Error = NET_ERR_NONE;
2132         else
2133                 Error = NET_ERR_UNKNOWN;
2134
2135         g_variant_unref(message);
2136
2137 done:
2138         __NETWORK_FUNC_EXIT__;
2139
2140         return Error;
2141 }
2142
2143 static int __net_set_default_cellular_service_profile_async(network_info_t *network_info,
2144                         const char *ProfileName)
2145 {
2146         __NETWORK_FUNC_ENTER__;
2147
2148         net_err_t Error = NET_ERR_NONE;
2149         net_profile_name_t telephony_profile;
2150         char connman_profile[NET_PROFILE_NAME_LEN_MAX+1] = {0,};
2151
2152         g_strlcpy(connman_profile, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
2153
2154         Error = __net_telephony_search_pdp_profile(network_info, connman_profile, &telephony_profile);
2155         if (Error != NET_ERR_NONE) {
2156                 NETWORK_LOG(NETWORK_ERROR, "__net_telephony_search_pdp_profile() failed");
2157                 __NETWORK_FUNC_EXIT__;
2158                 return Error;
2159         }
2160
2161         Error = _net_dbus_set_default(network_info, telephony_profile.ProfileName);
2162
2163         __NETWORK_FUNC_EXIT__;
2164         return Error;
2165 }
2166
2167 static int __compare_and_set_passphrase(network_info_t *network_info,
2168                 wlan_security_info_t *ex_security_info, wlan_security_info_t *security_info,
2169                 const char *ProfileName)
2170 {
2171         net_err_t Error = NET_ERR_NONE;
2172         if (ex_security_info->sec_mode == WLAN_SEC_MODE_WEP) {
2173                 if (g_strcmp0(security_info->authentication.wep.wepKey,
2174                                                 ex_security_info->authentication.wep.wepKey) != 0) {
2175                         /* ConnMan does not support modification of passphrase only,
2176                          * you need to make a connection to update passphrase.
2177                          */
2178                         Error = _net_dbus_set_agent_passphrase_and_connect(network_info,
2179                                         security_info->authentication.wep.wepKey, ProfileName);
2180                 }
2181         } else if (ex_security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
2182                         ex_security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) {
2183                 if (g_strcmp0(security_info->authentication.psk.pskKey,
2184                                 ex_security_info->authentication.psk.pskKey) != 0) {
2185                         /* ConnMan does not support modification of passphrase only,
2186                          * you need to make a connection to update passphrase.
2187                          */
2188                         Error = _net_dbus_set_agent_passphrase_and_connect(network_info,
2189                                         security_info->authentication.psk.pskKey, ProfileName);
2190                 }
2191         } else if (ex_security_info->sec_mode == WLAN_SEC_MODE_SAE) {
2192                 if (g_strcmp0(security_info->authentication.sae.saeKey,
2193                                         ex_security_info->authentication.sae.saeKey) != 0) {
2194                         /* ConnMan does not support modification of passphrase only,
2195                          * you need to make a connection to update passphrase.
2196                          */
2197                         Error = _net_dbus_set_agent_passphrase_and_connect(network_info,
2198                                         security_info->authentication.sae.saeKey, ProfileName);
2199                 }
2200         }
2201
2202         return Error;
2203 }
2204
2205 static int __compare_and_set_proxy(network_info_t *network_info,
2206                 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2207                 net_profile_info_t *ProfInfo, char *profilePath)
2208 {
2209         net_err_t Error = NET_ERR_NONE;
2210         if ((ex_net_info->ProxyMethod != net_info->ProxyMethod) ||
2211             (g_strcmp0(ex_net_info->ProxyAddr, net_info->ProxyAddr) != 0)) {
2212                 Error = _net_dbus_set_proxy(network_info, ProfInfo, profilePath);
2213         }
2214         return Error;
2215 }
2216
2217 static int __compare_and_set_ipv4_addresses(network_info_t *network_info,
2218                 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2219                 net_profile_info_t *ProfInfo, char *profilePath)
2220 {
2221         net_err_t Error = NET_ERR_NONE;
2222         if ((ex_net_info->IpConfigType != net_info->IpConfigType) ||
2223                 (net_info->IpConfigType == NET_IP_CONFIG_TYPE_STATIC &&
2224                 (net_info->IpAddr.Data.Ipv4.s_addr !=
2225                                                                 ex_net_info->IpAddr.Data.Ipv4.s_addr ||
2226                 net_info->SubnetMask.Data.Ipv4.s_addr !=
2227                                                                 ex_net_info->SubnetMask.Data.Ipv4.s_addr ||
2228                 net_info->GatewayAddr.Data.Ipv4.s_addr !=
2229                                                                 ex_net_info->GatewayAddr.Data.Ipv4.s_addr))) {
2230                 Error = _net_dbus_set_profile_ipv4(network_info, ProfInfo, profilePath);
2231         }
2232         return Error;
2233 }
2234
2235 static int __compare_and_set_ipv6_addresses(network_info_t *network_info,
2236                 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2237                 net_profile_info_t *ProfInfo, char *profilePath)
2238 {
2239         net_err_t Error = NET_ERR_NONE;
2240         if ((ex_net_info->IpConfigType6 != net_info->IpConfigType6) ||
2241             (net_info->IpConfigType6 == NET_IP_CONFIG_TYPE_STATIC &&
2242              (net_info->IpAddr6.Data.Ipv6.s6_addr != ex_net_info->IpAddr6.Data.Ipv6.s6_addr ||
2243               net_info->PrefixLen6 != ex_net_info->PrefixLen6 ||
2244               net_info->GatewayAddr6.Data.Ipv6.s6_addr != ex_net_info->GatewayAddr6.Data.Ipv6.s6_addr))) {
2245
2246                 Error = _net_dbus_set_profile_ipv6(network_info, ProfInfo, profilePath);
2247
2248         }
2249         return Error;
2250 }
2251
2252 static int __compare_and_set_dns_addresses(network_info_t *network_info,
2253                 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2254                 net_profile_info_t *ProfInfo, char *profilePath)
2255 {
2256         net_err_t Error = NET_ERR_NONE;
2257         int i = 0;
2258         for (i = 0; i < net_info->DnsCount; i++) {
2259                 if (i >= NET_DNS_ADDR_MAX) {
2260                         net_info->DnsCount = NET_DNS_ADDR_MAX;
2261
2262                         break;
2263                 }
2264
2265                 if (net_info->DnsAddr[i].Data.Ipv4.s_addr !=
2266                         ex_net_info->DnsAddr[i].Data.Ipv4.s_addr)
2267                         break;
2268         }
2269
2270         if (i < net_info->DnsCount || ex_net_info->DnsConfigType != net_info->DnsConfigType)
2271                 Error = _net_dbus_set_profile_dns(network_info, ProfInfo, profilePath);
2272
2273         return Error;
2274 }
2275
2276 static int __compare_and_set_dns6_addresses(network_info_t *network_info,
2277                 net_dev_info_t *ex_net_info, net_dev_info_t *net_info,
2278                 net_profile_info_t *ProfInfo, char *profilePath)
2279 {
2280         net_err_t Error = NET_ERR_NONE;
2281         int i = 0;
2282         for (i = 0; i < net_info->DnsCount6; i++) {
2283                 if (i >= NET_DNS_ADDR_MAX) {
2284                         net_info->DnsCount = NET_DNS_ADDR_MAX;
2285                         break;
2286                 }
2287
2288                 if (net_info->DnsAddr6[i].Type == NET_ADDR_IPV6) {
2289                         if (net_info->DnsAddr6[i].Data.Ipv6.s6_addr !=
2290                                         ex_net_info->DnsAddr6[i].Data.Ipv6.s6_addr)
2291                                 break;
2292                 }
2293         }
2294
2295         if (i < net_info->DnsCount6 || ex_net_info->DnsConfigType6 != net_info->DnsConfigType6)
2296                 Error = _net_dbus_set_profile_dns(network_info, ProfInfo, profilePath);
2297
2298         return Error;
2299 }
2300
2301 static int __net_modify_wlan_profile_info(network_info_t *network_info,
2302                 const char *ProfileName, net_profile_info_t *ProfInfo, net_profile_info_t *exProfInfo)
2303 {
2304         __NETWORK_FUNC_ENTER__;
2305
2306         net_err_t Error = NET_ERR_NONE;
2307         char profilePath[NET_PROFILE_NAME_LEN_MAX+1] = "";
2308
2309         wlan_security_info_t *security_info =
2310                                                                 &(ProfInfo->ProfileInfo.Wlan.security_info);
2311         wlan_security_info_t *ex_security_info =
2312                                                                 &(exProfInfo->ProfileInfo.Wlan.security_info);
2313
2314         net_dev_info_t *net_info = &(ProfInfo->ProfileInfo.Wlan.net_info);
2315         net_dev_info_t *ex_net_info = &(exProfInfo->ProfileInfo.Wlan.net_info);
2316
2317         g_strlcpy(profilePath, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
2318
2319         Error = __compare_and_set_passphrase(network_info, ex_security_info, security_info, ProfileName);
2320         if (Error != NET_ERR_NONE) {
2321                 NETWORK_LOG(NETWORK_ERROR, "Failed to set agent field");
2322                 __NETWORK_FUNC_EXIT__;
2323                 return Error;
2324         }
2325
2326         Error = __compare_and_set_proxy(network_info, ex_net_info, net_info, ProfInfo, profilePath);
2327         if (Error != NET_ERR_NONE) {
2328                 NETWORK_LOG(NETWORK_ERROR, "Failed to set proxy");
2329                 __NETWORK_FUNC_EXIT__;
2330                 return Error;
2331         }
2332
2333         Error = __compare_and_set_ipv4_addresses(network_info, ex_net_info, net_info, ProfInfo, profilePath);
2334         if (Error != NET_ERR_NONE) {
2335                 NETWORK_LOG(NETWORK_ERROR, "Failed to set IPv4");
2336                 __NETWORK_FUNC_EXIT__;
2337                 return Error;
2338         }
2339
2340         Error = __compare_and_set_ipv6_addresses(network_info, ex_net_info, net_info, ProfInfo, profilePath);
2341         if (Error != NET_ERR_NONE) {
2342                 NETWORK_LOG(NETWORK_ERROR,  "Error!!! Can't set IPv6\n");
2343                 __NETWORK_FUNC_EXIT__;
2344                 return Error;
2345         }
2346
2347         Error = __compare_and_set_dns_addresses(network_info, ex_net_info, net_info, ProfInfo, profilePath);
2348         if (Error != NET_ERR_NONE) {
2349                 NETWORK_LOG(NETWORK_ERROR, "Failed to set DNS\n");
2350                 __NETWORK_FUNC_EXIT__;
2351                 return Error;
2352         }
2353
2354         Error = __compare_and_set_dns6_addresses(network_info, ex_net_info, net_info, ProfInfo, profilePath);
2355         if (Error != NET_ERR_NONE) {
2356                 NETWORK_LOG(NETWORK_ERROR, "Failed to set DNS6\n");
2357                 __NETWORK_FUNC_EXIT__;
2358                 return Error;
2359         }
2360
2361         __NETWORK_FUNC_EXIT__;
2362         return NET_ERR_NONE;
2363 }
2364
2365 static int __net_wifi_delete_profile(network_info_t *network_info,
2366                 net_profile_name_t *WifiProfName, wlan_security_mode_type_t sec_mode, gboolean passpoint)
2367 {
2368         __NETWORK_FUNC_ENTER__;
2369
2370         net_err_t Error = NET_ERR_NONE;
2371         GVariant *message = NULL;
2372         char param0[NET_PROFILE_NAME_LEN_MAX + 8] = "";
2373         GVariant *params;
2374
2375         if (passpoint == TRUE && WLAN_SEC_MODE_IEEE8021X == sec_mode) {
2376                 message = _net_invoke_dbus_method(network_info,
2377                                 CONNMAN_SERVICE,
2378                                 WifiProfName->ProfileName,
2379                                 CONNMAN_SERVICE_INTERFACE, "Remove", NULL,
2380                                 &Error);
2381
2382                 if (message == NULL) {
2383                         NETWORK_LOG(NETWORK_ERROR, "Failed to Remove service(profile)");
2384                         g_variant_unref(message);
2385                         goto done;
2386                 }
2387
2388                 g_variant_unref(message);
2389
2390                 g_snprintf(param0, NET_PROFILE_NAME_LEN_MAX + 8, "string:%s",
2391                                 WifiProfName->ProfileName);
2392                 params = g_variant_new("(s)", param0);
2393
2394                 message = _net_invoke_dbus_method(network_info,
2395                                 NETCONFIG_SERVICE,
2396                                 NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE,
2397                                 "DeleteEapConfig", params, &Error);
2398         } else if (passpoint == TRUE || WLAN_SEC_MODE_IEEE8021X != sec_mode) {
2399                 message = _net_invoke_dbus_method(network_info,
2400                                 CONNMAN_SERVICE,
2401                                 WifiProfName->ProfileName,
2402                                 CONNMAN_SERVICE_INTERFACE, "Remove", NULL,
2403                                 &Error);
2404         } else {
2405                 g_snprintf(param0, NET_PROFILE_NAME_LEN_MAX + 8, "string:%s",
2406                                 WifiProfName->ProfileName);
2407                 params = g_variant_new("(s)", param0);
2408
2409                 message = _net_invoke_dbus_method(network_info,
2410                                 NETCONFIG_SERVICE,
2411                                 NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE,
2412                                 "DeleteEapConfig", params, &Error);
2413         }
2414
2415         if (message == NULL) {
2416                 NETWORK_LOG(NETWORK_ERROR, "Failed to Remove service(profile)");
2417                 goto done;
2418         }
2419
2420         g_variant_unref(message);
2421 done:
2422         __NETWORK_FUNC_EXIT__;
2423         return Error;
2424 }
2425
2426 static int __net_modify_mesh_profile(network_info_t *network_info,
2427                 const char *ProfileName, net_profile_info_t *ProfInfo, net_profile_info_t *exProfInfo)
2428 {
2429         __NETWORK_FUNC_ENTER__;
2430
2431         net_err_t Error = NET_ERR_NONE;
2432         char profilePath[NET_PROFILE_NAME_LEN_MAX+1] = "";
2433
2434         wlan_security_info_t *security_info =
2435                                                                 &(ProfInfo->ProfileInfo.Mesh.security_info);
2436         wlan_security_info_t *ex_security_info =
2437                                                                 &(exProfInfo->ProfileInfo.Mesh.security_info);
2438
2439         g_strlcpy(profilePath, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
2440
2441         /* Compare and Set 'Passphrase' */
2442         if (ex_security_info->sec_mode == WLAN_SEC_MODE_SAE) {
2443                 if (g_strcmp0(security_info->authentication.sae.saeKey,
2444                                                 ex_security_info->authentication.sae.saeKey) != 0) {
2445                         /* ConnMan does not support modification of passphrase only,
2446                          * you need to make a connection to update passphrase.
2447                          */
2448                         Error = _net_dbus_set_mesh_property(network_info,
2449                                         profilePath, "Passphrase",
2450                                         security_info->authentication.sae.saeKey);
2451
2452                         if (NET_ERR_NONE != Error) {
2453                                 NETWORK_LOG(NETWORK_ERROR, "Failed to set Mesh property");
2454
2455                                 __NETWORK_FUNC_EXIT__;
2456                                 return Error;
2457                         }
2458                 }
2459         }
2460
2461         __NETWORK_FUNC_EXIT__;
2462         return NET_ERR_NONE;
2463 }
2464
2465 static int __net_mesh_delete_profile(network_info_t *network_info, const char *profile_name)
2466 {
2467         __NETWORK_FUNC_ENTER__;
2468
2469         net_err_t Error = NET_ERR_NONE;
2470         GVariant *message = NULL;
2471
2472         message = _net_invoke_dbus_method(network_info,
2473                         CONNMAN_SERVICE, profile_name,
2474                         CONNMAN_MESH_INTERFACE, "Remove", NULL, &Error);
2475         if (message == NULL) {
2476                 NETWORK_LOG(NETWORK_ERROR, "Failed to Remove mesh(profile)");
2477                 goto done;
2478         }
2479
2480         g_variant_unref(message);
2481
2482 done:
2483         __NETWORK_FUNC_EXIT__;
2484         return Error;
2485 }
2486
2487 static int __net_telephony_add_profile(network_info_t *network_info,
2488                         net_profile_info_t *ProfInfo, net_service_type_t network_type)
2489 {
2490         __NETWORK_FUNC_ENTER__;
2491
2492         net_err_t Error = NET_ERR_NONE;
2493
2494         ProfInfo->ProfileInfo.Pdp.ServiceType = network_type;
2495
2496         Error = _net_dbus_add_pdp_profile(network_info, ProfInfo);
2497         if (Error != NET_ERR_NONE) {
2498                 NETWORK_LOG(NETWORK_ERROR, "_net_dbus_add_pdp_profile() failed");
2499                 __NETWORK_FUNC_EXIT__;
2500                 return Error;
2501         }
2502
2503         __NETWORK_FUNC_EXIT__;
2504         return NET_ERR_NONE;
2505 }
2506
2507 static int __net_telephony_modify_profile(network_info_t *network_info,
2508                 const char *ProfileName, net_profile_info_t *ProfInfo, net_profile_info_t *exProfInfo)
2509 {
2510         __NETWORK_FUNC_ENTER__;
2511
2512         net_err_t Error = NET_ERR_NONE;
2513         net_profile_name_t telephony_profile;
2514         char connman_profile[NET_PROFILE_NAME_LEN_MAX+1] = "";
2515
2516         if (_net_is_valid_service_type(exProfInfo->ProfileInfo.Pdp.ServiceType) == FALSE) {
2517                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
2518                 __NETWORK_FUNC_EXIT__;
2519                 return NET_ERR_INVALID_PARAM;
2520         }
2521
2522         g_strlcpy(connman_profile, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
2523         ProfInfo->ProfileInfo.Pdp.ServiceType = exProfInfo->ProfileInfo.Pdp.ServiceType;
2524
2525         Error = __net_telephony_search_pdp_profile(network_info, connman_profile, &telephony_profile);
2526         if (Error != NET_ERR_NONE) {
2527                 NETWORK_LOG(NETWORK_ERROR, "__net_telephony_search_pdp_profile() failed");
2528                 __NETWORK_FUNC_EXIT__;
2529                 return Error;
2530         }
2531
2532         Error = _net_dbus_modify_pdp_profile(network_info, ProfInfo, telephony_profile.ProfileName);
2533         if (Error != NET_ERR_NONE) {
2534                 NETWORK_LOG(NETWORK_ERROR, "_net_dbus_modify_pdp_profile() failed");
2535                 __NETWORK_FUNC_EXIT__;
2536                 return Error;
2537         }
2538
2539         __NETWORK_FUNC_EXIT__;
2540
2541         return Error;
2542 }
2543
2544 static int __net_modify_ethernet_profile(network_info_t *network_info,
2545                 const char *ProfileName, net_profile_info_t *ProfInfo, net_profile_info_t *exProfInfo)
2546 {
2547         __NETWORK_FUNC_ENTER__;
2548
2549         net_err_t Error = NET_ERR_NONE;
2550         int i = 0;
2551         int j = 0;
2552         char profilePath[NET_PROFILE_NAME_LEN_MAX+1] = "";
2553
2554         net_dev_info_t *net_info = &(ProfInfo->ProfileInfo.Ethernet.net_info);
2555         net_dev_info_t *ex_net_info = &(exProfInfo->ProfileInfo.Ethernet.net_info);
2556
2557         g_strlcpy(profilePath, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
2558
2559         /* Compare and Set 'Proxy' */
2560         NETWORK_LOG(NETWORK_HIGH, "Proxy old:%d %s, new:%d %s\n",
2561                         ex_net_info->ProxyMethod,
2562                         ex_net_info->ProxyAddr,
2563                         net_info->ProxyMethod,
2564                         net_info->ProxyAddr);
2565
2566         if ((ex_net_info->ProxyMethod != net_info->ProxyMethod) ||
2567                 (g_strcmp0(ex_net_info->ProxyAddr, net_info->ProxyAddr) != 0)) {
2568
2569                 Error = _net_dbus_set_proxy(network_info, ProfInfo, profilePath);
2570
2571                 if (Error != NET_ERR_NONE) {
2572                         __NETWORK_FUNC_EXIT__;
2573                         return Error;
2574                 }
2575         }
2576
2577         /* Compare and Set 'IPv4 addresses' */
2578         char ip_buffer[NETPM_IPV4_STR_LEN_MAX+1] = "";
2579         char netmask_buffer[NETPM_IPV4_STR_LEN_MAX+1] = "";
2580         char gateway_buffer[NETPM_IPV4_STR_LEN_MAX+1] = "";
2581         g_strlcpy(ip_buffer,
2582                         inet_ntoa(ex_net_info->IpAddr.Data.Ipv4),
2583                         NETPM_IPV4_STR_LEN_MAX + 1);
2584
2585         g_strlcpy(netmask_buffer,
2586                         inet_ntoa(ex_net_info->SubnetMask.Data.Ipv4),
2587                         NETPM_IPV4_STR_LEN_MAX + 1);
2588
2589         g_strlcpy(gateway_buffer,
2590                         inet_ntoa(ex_net_info->GatewayAddr.Data.Ipv4),
2591                         NETPM_IPV4_STR_LEN_MAX + 1);
2592
2593         NETWORK_LOG(NETWORK_HIGH, "IPv4 info old: type %d, IP: %s, netmask:"
2594                         " %s, gateway: %s\n", ex_net_info->IpConfigType,
2595                         ip_buffer,
2596                         netmask_buffer,
2597                         gateway_buffer);
2598
2599         g_strlcpy(ip_buffer,
2600                         inet_ntoa(net_info->IpAddr.Data.Ipv4),
2601                         NETPM_IPV4_STR_LEN_MAX + 1);
2602
2603         g_strlcpy(netmask_buffer,
2604                         inet_ntoa(net_info->SubnetMask.Data.Ipv4),
2605                         NETPM_IPV4_STR_LEN_MAX + 1);
2606
2607         g_strlcpy(gateway_buffer,
2608                         inet_ntoa(net_info->GatewayAddr.Data.Ipv4),
2609                         NETPM_IPV4_STR_LEN_MAX + 1);
2610
2611         NETWORK_LOG(NETWORK_HIGH, "IPv4 info new: type %d, IP: %s, netmask:"
2612                         " %s, gateway: %s\n", net_info->IpConfigType,
2613                         ip_buffer,
2614                         netmask_buffer,
2615                         gateway_buffer);
2616
2617         if ((ex_net_info->IpConfigType != net_info->IpConfigType) ||
2618                 (net_info->IpConfigType == NET_IP_CONFIG_TYPE_STATIC &&
2619                  (net_info->IpAddr.Data.Ipv4.s_addr
2620                                         != ex_net_info->IpAddr.Data.Ipv4.s_addr ||
2621                   net_info->SubnetMask.Data.Ipv4.s_addr
2622                                         != ex_net_info->SubnetMask.Data.Ipv4.s_addr ||
2623                   net_info->GatewayAddr.Data.Ipv4.s_addr
2624                                         != ex_net_info->GatewayAddr.Data.Ipv4.s_addr))) {
2625                 Error = _net_dbus_set_profile_ipv4(network_info, ProfInfo, profilePath);
2626
2627                 if (Error != NET_ERR_NONE) {
2628                         NETWORK_LOG(NETWORK_ERROR, "Failed to set IPv4");
2629
2630                         __NETWORK_FUNC_EXIT__;
2631                         return Error;
2632                 }
2633         }
2634         /* Compare and Set 'DNS addresses' */
2635         for (i = 0; i < net_info->DnsCount; i++) {
2636                 if (i >= NET_DNS_ADDR_MAX) {
2637                         net_info->DnsCount = NET_DNS_ADDR_MAX;
2638                         break;
2639                 }
2640
2641                 if (net_info->DnsAddr[i].Type == NET_ADDR_IPV4) {
2642                         char old_dns[NETPM_IPV4_STR_LEN_MAX+1] = "";
2643                         char new_dns[NETPM_IPV4_STR_LEN_MAX+1] = "";
2644                         g_strlcpy(old_dns,
2645                                 inet_ntoa(ex_net_info->DnsAddr[i].Data.Ipv4),
2646                                 NETPM_IPV4_STR_LEN_MAX+1);
2647                         g_strlcpy(new_dns,
2648                                 inet_ntoa(net_info->DnsAddr[i].Data.Ipv4),
2649                                 NETPM_IPV4_STR_LEN_MAX+1);
2650
2651                         NETWORK_LOG(NETWORK_HIGH, "IPv4 DNS Addr order: %d, old:"
2652                                 "%s, new: %s", i, old_dns, new_dns);
2653
2654                         if (net_info->DnsAddr[i].Data.Ipv4.s_addr !=
2655                                 ex_net_info->DnsAddr[i].Data.Ipv4.s_addr)
2656                                 break;
2657                 }
2658
2659         }
2660
2661         char ipaddr6_old[INET6_ADDRSTRLEN];
2662         char ipaddr6_new[INET6_ADDRSTRLEN];
2663
2664         for (j = 0; j < net_info->DnsCount6; j++) {
2665                 if (j >= NET_DNS_ADDR_MAX) {
2666                         net_info->DnsCount6 = NET_DNS_ADDR_MAX;
2667
2668                         break;
2669                 }
2670
2671                 if (net_info->DnsAddr6[j].Type == NET_ADDR_IPV6) {
2672                         inet_ntop(AF_INET6, &ex_net_info->DnsAddr6[j].Data.Ipv6,
2673                                         ipaddr6_old, INET6_ADDRSTRLEN);
2674                         inet_ntop(AF_INET6, &net_info->DnsAddr6[j].Data.Ipv6,
2675                                         ipaddr6_new, INET6_ADDRSTRLEN);
2676                         NETWORK_LOG(NETWORK_HIGH, "IPv6 DNS Addr order: %d, "
2677                                         "old: %s, new: %s", j, ipaddr6_old,
2678                                         ipaddr6_new);
2679
2680                         if (net_info->DnsAddr6[j].Data.Ipv6.s6_addr !=
2681                                 ex_net_info->DnsAddr6[j].Data.Ipv6.s6_addr)
2682                                 break;
2683                 }
2684         }
2685
2686         if (i < net_info->DnsCount || j < net_info->DnsCount6 ||
2687                         ex_net_info->DnsConfigType != net_info->DnsConfigType ||
2688                         ex_net_info->DnsConfigType6 != net_info->DnsConfigType6) {
2689                 Error = _net_dbus_set_profile_dns(network_info, ProfInfo, profilePath);
2690
2691                 if (Error != NET_ERR_NONE) {
2692                         NETWORK_LOG(NETWORK_ERROR, "Failed to set DNS");
2693
2694                         __NETWORK_FUNC_EXIT__;
2695                         return Error;
2696                 }
2697         }
2698
2699         __NETWORK_FUNC_EXIT__;
2700         return NET_ERR_NONE;
2701 }
2702
2703 static int __net_telephony_delete_profile(network_info_t *network_info,
2704                         net_profile_name_t *PdpProfName)
2705 {
2706         __NETWORK_FUNC_ENTER__;
2707
2708         net_err_t Error = NET_ERR_NONE;
2709         GVariant *message = NULL;
2710
2711         message = _net_invoke_dbus_method(network_info,
2712                         TELEPHONY_SERVICE, PdpProfName->ProfileName,
2713                         TELEPHONY_PROFILE_INTERFACE, "RemoveProfile", NULL, &Error);
2714         if (message == NULL) {
2715                 NETWORK_LOG(NETWORK_ERROR, "Failed to Remove service(profile)");
2716                 goto done;
2717         }
2718
2719         /** Check Reply */
2720         gboolean remove_result = FALSE;
2721
2722         g_variant_get(message, "(b)", &remove_result);
2723         NETWORK_LOG(NETWORK_HIGH, "Profile remove result: %d", remove_result);
2724
2725         if (remove_result)
2726                 Error = NET_ERR_NONE;
2727         else
2728                 Error = NET_ERR_UNKNOWN;
2729
2730         g_variant_unref(message);
2731
2732 done:
2733         __NETWORK_FUNC_EXIT__;
2734         return Error;
2735 }
2736
2737 static gboolean __net_is_cellular_default_candidate(const char *profile)
2738 {
2739         /* This profile should be cellular type */
2740         const char net_suffix[] = "_1";
2741         const char pre_net_suffix[] = "_3";
2742         const char tethering_suffix[] = "_5";
2743         char *suffix;
2744
2745         suffix = strrchr(profile, '_');
2746
2747         if (g_strcmp0(suffix, net_suffix) == 0 ||
2748                         g_strcmp0(suffix, pre_net_suffix) == 0 ||
2749                         g_strcmp0(suffix, tethering_suffix) == 0)
2750                 return TRUE;
2751
2752         return FALSE;
2753 }
2754
2755 static int __net_extract_default_profile(network_info_t *network_info,
2756                 GVariantIter *array, net_profile_info_t *ProfilePtr)
2757 {
2758         net_err_t Error = NET_ERR_NONE;
2759         net_device_t device_type;
2760         gchar *key = NULL;
2761         GVariantIter *value = NULL;
2762
2763         __NETWORK_FUNC_ENTER__;
2764
2765         if (array == NULL || ProfilePtr == NULL) {
2766                 NETWORK_LOG(NETWORK_ERROR, "Invalid parameter");
2767                 __NETWORK_FUNC_EXIT__;
2768                 return NET_ERR_INVALID_PARAM;
2769         }
2770
2771         while (g_variant_iter_loop(array, "(oa{sv})", &key, &value)) {
2772                 if (g_str_has_prefix(key, CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX) == TRUE)
2773                         device_type = NET_DEVICE_CELLULAR;
2774                 else if (g_str_has_prefix(key, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) == TRUE)
2775                         device_type = NET_DEVICE_WIFI;
2776                 else if (g_str_has_prefix(key, CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX) == TRUE)
2777                         device_type = NET_DEVICE_ETHERNET;
2778                 else if (g_str_has_prefix(key, CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX) == TRUE)
2779                         device_type = NET_DEVICE_BLUETOOTH;
2780                 else if (g_str_has_prefix(key, CONNMAN_MESH_PROFILE_PREFIX) == TRUE)
2781                         device_type = NET_DEVICE_MESH;
2782                 else {
2783                         Error = NET_ERR_NO_SERVICE;
2784                         goto error;
2785                 }
2786
2787                 Error = __net_pm_init_profile_info(device_type, ProfilePtr);
2788                 if (Error != NET_ERR_NONE) {
2789                         NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
2790                         goto error;
2791                 }
2792
2793                 ProfilePtr->profile_type = device_type;
2794                 g_strlcpy(ProfilePtr->ProfileName, key, NET_PROFILE_NAME_LEN_MAX);
2795
2796                 if (device_type == NET_DEVICE_CELLULAR &&
2797                                 __net_is_cellular_default_candidate(key) == TRUE) {
2798                         g_strlcpy(ProfilePtr->ProfileInfo.Pdp.net_info.ProfileName,
2799                                         key, NET_PROFILE_NAME_LEN_MAX);
2800
2801                         Error = __net_extract_mobile_info(network_info, value, ProfilePtr);
2802                         break;
2803                 } else if (device_type == NET_DEVICE_WIFI) {
2804                         g_strlcpy(ProfilePtr->ProfileInfo.Wlan.net_info.ProfileName,
2805                                         key, NET_PROFILE_NAME_LEN_MAX);
2806
2807                         Error = __net_extract_wifi_info(value, ProfilePtr);
2808                         break;
2809                 } else if (device_type == NET_DEVICE_ETHERNET) {
2810                         g_strlcpy(ProfilePtr->ProfileInfo.Ethernet.net_info.ProfileName,
2811                                         key, NET_PROFILE_NAME_LEN_MAX);
2812
2813                         Error = __net_extract_ethernet_info(value, ProfilePtr);
2814                         break;
2815                 } else if (device_type == NET_DEVICE_BLUETOOTH) {
2816                         g_strlcpy(ProfilePtr->ProfileInfo.Bluetooth.net_info.ProfileName,
2817                                         key, NET_PROFILE_NAME_LEN_MAX);
2818
2819                         Error = __net_extract_bluetooth_info(value, ProfilePtr);
2820                         break;
2821                 } else if (device_type == NET_DEVICE_MESH) {
2822                         g_strlcpy(ProfilePtr->ProfileInfo.Mesh.net_info.ProfileName,
2823                                         key, NET_PROFILE_NAME_LEN_MAX);
2824
2825                         Error = __net_extract_mesh_info(value, ProfilePtr);
2826                         if (ProfilePtr->ProfileState == NET_STATE_TYPE_READY)
2827                                 break;
2828                 }
2829         }
2830
2831         if (Error == NET_ERR_NONE &&
2832                         (ProfilePtr->ProfileState == NET_STATE_TYPE_READY ||
2833                                         ProfilePtr->ProfileState == NET_STATE_TYPE_ONLINE))
2834                 goto found;
2835
2836         NETWORK_LOG(NETWORK_ERROR, "Fail to find default service");
2837         Error = NET_ERR_NO_SERVICE;
2838
2839 error:
2840         if (value)
2841                 g_variant_iter_free(value);
2842         if (key)
2843                 g_free(key);
2844
2845         __NETWORK_FUNC_EXIT__;
2846         return Error;
2847
2848 found:
2849         NETWORK_LOG(NETWORK_HIGH, "Default: %s", ProfilePtr->ProfileName);
2850
2851         if (value)
2852                 g_variant_iter_free(value);
2853         if (key)
2854                 g_free(key);
2855
2856         __NETWORK_FUNC_EXIT__;
2857         return Error;
2858 }
2859 /* LCOV_EXCL_STOP */
2860
2861 int _net_check_profile_name(const char *ProfileName)
2862 {
2863         __NETWORK_FUNC_ENTER__;
2864
2865         const char *profileHeader = CONNMAN_PATH"/service/";
2866         const char *meshProfileHeader = CONNMAN_PATH"/mesh/";
2867         int i = 0;
2868         int stringLen = 0;
2869
2870         if (ProfileName == NULL || strlen(ProfileName) <= strlen(profileHeader)) {
2871                 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid");
2872                 __NETWORK_FUNC_EXIT__;
2873                 return NET_ERR_INVALID_PARAM;
2874         }
2875
2876         stringLen = strlen(ProfileName);
2877
2878         if (strncmp(profileHeader, ProfileName, strlen(profileHeader)) == 0) {
2879                 for (i = 0; i < stringLen; i++) {
2880                         /* LCOV_EXCL_START */
2881                         if (isgraph(ProfileName[i]) == 0) {
2882                                 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid");
2883                                 __NETWORK_FUNC_EXIT__;
2884                                 return NET_ERR_INVALID_PARAM;
2885                         }
2886                 }
2887         } else if (strncmp(meshProfileHeader, ProfileName,
2888                                                 strlen(meshProfileHeader)) == 0) {
2889                 for (i = 0; i < stringLen; i++) {
2890                         if (isgraph(ProfileName[i]) == 0) {
2891                                 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid");
2892                                 __NETWORK_FUNC_EXIT__;
2893                                 return NET_ERR_INVALID_PARAM;
2894                         }
2895                 }
2896         } else {
2897                 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid");
2898                 __NETWORK_FUNC_EXIT__;
2899                 return NET_ERR_INVALID_PARAM;
2900         }
2901         /* LCOV_EXCL_STOP */
2902
2903         __NETWORK_FUNC_EXIT__;
2904         return NET_ERR_NONE;
2905 }
2906
2907 int _net_get_profile_list(network_info_t *network_info, net_device_t device_type,
2908                         net_profile_info_t **profile_info, int *profile_count)
2909 {
2910         __NETWORK_FUNC_ENTER__;
2911
2912         net_err_t Error = NET_ERR_NONE;
2913         GVariant *message;
2914         GVariantIter *iter;
2915
2916         if (device_type == NET_DEVICE_MESH) {
2917                 /* LCOV_EXCL_START */
2918                 net_cm_network_status_t status = NET_STATUS_UNKNOWN;
2919
2920                 net_get_network_status(network_info, device_type, &status);
2921                 if (status != NET_STATUS_AVAILABLE)
2922                         return NET_ERR_NONE;
2923
2924                 message = _net_invoke_dbus_method(network_info, CONNMAN_SERVICE,
2925                                                 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
2926                                                 "GetMeshPeers", NULL, &Error);
2927                 if (message == NULL) {
2928                         NETWORK_LOG(NETWORK_ERROR, "Failed to get Mesh Peers list");
2929                         __NETWORK_FUNC_EXIT__;
2930                         return Error;
2931                 }
2932                 /* LCOV_EXCL_STOP */
2933         } else {
2934                 message = _net_invoke_dbus_method(network_info, CONNMAN_SERVICE,
2935                                                 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
2936                                                 "GetServices", NULL, &Error);
2937                 /* LCOV_EXCL_START */
2938                 if (message == NULL) {
2939                         NETWORK_LOG(NETWORK_ERROR, "Failed to get service(profile) list");
2940                         __NETWORK_FUNC_EXIT__;
2941                         return Error;
2942                 }
2943                 /* LCOV_EXCL_STOP */
2944         }
2945
2946         switch (device_type) {
2947         case NET_DEVICE_CELLULAR:
2948         case NET_DEVICE_WIFI:
2949         case NET_DEVICE_ETHERNET:
2950         case NET_DEVICE_BLUETOOTH:
2951         case NET_DEVICE_MESH:
2952                 g_variant_get(message, "(a(oa{sv}))", &iter);
2953                 Error = __net_extract_services(network_info, iter,
2954                                         device_type, profile_info, profile_count);
2955
2956                 if (iter != NULL)
2957                         g_variant_iter_free(iter);
2958                 break;
2959
2960         default:
2961                 /* LCOV_EXCL_START */
2962                 Error = NET_ERR_UNKNOWN;
2963                 break;
2964                 /* LCOV_EXCL_STOP */
2965         }
2966
2967         g_variant_unref(message);
2968
2969         __NETWORK_FUNC_EXIT__;
2970         return Error;
2971 }
2972
2973 int _net_extract_services(network_info_t *network_info, net_device_t device_type,
2974                 net_profile_info_t **profile_info, int *profile_count, GVariant *message)
2975 {
2976         net_err_t Error = NET_ERR_NONE;
2977         GVariantIter *iter;
2978
2979         g_variant_get(message, "(a(oa{sv}))", &iter);
2980
2981         Error = __net_extract_services(network_info, iter,
2982                 device_type, profile_info, profile_count);
2983
2984         if (iter != NULL)
2985                         g_variant_iter_free(iter);
2986
2987         return Error;
2988 }
2989
2990 int _net_get_all_profile_list(network_info_t *network_info,
2991                 net_profile_info_t **profile_info, int *profile_count)
2992 {
2993         __NETWORK_FUNC_ENTER__;
2994
2995         net_err_t Error = NET_ERR_NONE;
2996         GVariant *message = NULL;
2997         GVariant *mesh_message = NULL;
2998         int cellular_cnt = 0;
2999         int wifi_cnt = 0;
3000         int ethernet_cnt = 0;
3001         int bluetooth_cnt = 0;
3002         int mesh_cnt = 0;
3003         net_profile_info_t *cellular_profiles = NULL;
3004         net_profile_info_t *wifi_profiles = NULL;
3005         net_profile_info_t *ethernet_profiles = NULL;
3006         net_profile_info_t *bluetooth_profiles = NULL;
3007         net_profile_info_t *mesh_profiles = NULL;
3008         net_profile_info_t *profiles = NULL;
3009         net_cm_network_status_t status = NET_STATUS_UNKNOWN;
3010
3011         message = _net_invoke_dbus_method(network_info, CONNMAN_SERVICE,
3012                                         CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
3013                                         "GetServices", NULL, &Error);
3014         /* LCOV_EXCL_START */
3015         if (message == NULL) {
3016                 NETWORK_LOG(NETWORK_ERROR, "Failed to get service(profile) list");
3017                 __NETWORK_FUNC_EXIT__;
3018                 return Error;
3019         }
3020         /* LCOV_EXCL_STOP */
3021
3022         *profile_count = 0;
3023
3024         Error = _net_extract_services(network_info, NET_DEVICE_CELLULAR,
3025                         &cellular_profiles, &cellular_cnt, message);
3026         if (Error != NET_ERR_NONE)
3027                 goto done;
3028
3029         NETWORK_LOG(NETWORK_LOW, "Cellular profile count: %d", cellular_cnt);
3030         *profile_count += cellular_cnt;
3031
3032         Error = _net_extract_services(network_info, NET_DEVICE_WIFI,
3033                         &wifi_profiles, &wifi_cnt, message);
3034         if (Error != NET_ERR_NONE)
3035                 goto done;
3036
3037         NETWORK_LOG(NETWORK_LOW, "Wi-Fi profile count: %d", wifi_cnt);
3038         *profile_count += wifi_cnt;
3039
3040         Error = _net_extract_services(network_info, NET_DEVICE_ETHERNET,
3041                         &ethernet_profiles, &ethernet_cnt, message);
3042         if (Error != NET_ERR_NONE)
3043                 goto done;
3044
3045         NETWORK_LOG(NETWORK_LOW, "Ethernet profile count: %d", ethernet_cnt);
3046         *profile_count += ethernet_cnt;
3047
3048         Error = _net_extract_services(network_info, NET_DEVICE_BLUETOOTH,
3049                         &bluetooth_profiles, &bluetooth_cnt, message);
3050         if (Error != NET_ERR_NONE)
3051                 goto done;
3052
3053         NETWORK_LOG(NETWORK_LOW, "Bluetooth profile count: %d", bluetooth_cnt);
3054         *profile_count += bluetooth_cnt;
3055
3056         /* LCOV_EXCL_START */
3057         net_get_network_status(network_info, NET_DEVICE_MESH, &status);
3058         if (status == NET_STATUS_AVAILABLE) {
3059                 mesh_message = _net_invoke_dbus_method(network_info, CONNMAN_SERVICE,
3060                                                 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
3061                                                 "GetMeshPeers", NULL, &Error);
3062                 if (mesh_message == NULL) {
3063                         NETWORK_LOG(NETWORK_ERROR, "Failed to get Mesh Peers list");
3064                         NET_MEMFREE(cellular_profiles);
3065                         NET_MEMFREE(wifi_profiles);
3066                         NET_MEMFREE(ethernet_profiles);
3067                         NET_MEMFREE(bluetooth_profiles);
3068                         __NETWORK_FUNC_EXIT__;
3069                         return Error;
3070                 }
3071
3072                 Error = _net_extract_services(network_info, NET_DEVICE_MESH,
3073                         &mesh_profiles, &mesh_cnt, mesh_message);
3074                 if (Error != NET_ERR_NONE)
3075                         goto done;
3076
3077                 NETWORK_LOG(NETWORK_LOW, "Mesh profile count: %d", mesh_cnt);
3078                 *profile_count += mesh_cnt;
3079         }
3080         /* LCOV_EXCL_STOP */
3081
3082         if (*profile_count > 0) {
3083                 profiles = g_try_new0(net_profile_info_t, *profile_count);
3084                 if (profiles) {
3085                         *profile_info = profiles;
3086                         if (cellular_cnt > 0) {
3087                                 memcpy(profiles, cellular_profiles,
3088                                         sizeof(net_profile_info_t) * cellular_cnt);
3089                                 profiles += cellular_cnt;
3090                         }
3091
3092                         if (wifi_cnt > 0) {
3093                                 memcpy(profiles, wifi_profiles,
3094                                         sizeof(net_profile_info_t) * wifi_cnt);
3095                                 profiles += wifi_cnt;
3096                         }
3097
3098                         if (ethernet_cnt > 0) {
3099                                 memcpy(profiles, ethernet_profiles,
3100                                         sizeof(net_profile_info_t) * ethernet_cnt);
3101                                 profiles += ethernet_cnt;
3102                         }
3103
3104                         if (bluetooth_cnt > 0) {
3105                                 memcpy(profiles, bluetooth_profiles,
3106                                         sizeof(net_profile_info_t) * bluetooth_cnt);
3107                                 profiles += bluetooth_cnt;
3108                         }
3109
3110                         if (mesh_cnt > 0) {
3111                                 memcpy(profiles, mesh_profiles,
3112                                         sizeof(net_profile_info_t) * mesh_cnt);
3113                         }
3114                 }
3115         }
3116
3117 done:
3118         if (message != NULL)
3119                 g_variant_unref(message);
3120
3121         if (mesh_message != NULL)
3122                 g_variant_unref(mesh_message);
3123
3124         NET_MEMFREE(cellular_profiles);
3125         NET_MEMFREE(wifi_profiles);
3126         NET_MEMFREE(ethernet_profiles);
3127         NET_MEMFREE(bluetooth_profiles);
3128         NET_MEMFREE(mesh_profiles);
3129
3130         __NETWORK_FUNC_EXIT__;
3131         return Error;
3132 }
3133
3134 /* LCOV_EXCL_START */
3135 int _net_get_default_profile_info(network_info_t *network_info,
3136                         net_profile_info_t *profile_info)
3137 {
3138         net_err_t Error = NET_ERR_NONE;
3139         GVariant *message = NULL;
3140         GVariantIter *iter = NULL;
3141
3142         __NETWORK_FUNC_ENTER__;
3143
3144         message = _net_invoke_dbus_method(network_info,
3145                         CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
3146                         CONNMAN_MANAGER_INTERFACE, "GetServices", NULL, &Error);
3147         if (message == NULL) {
3148                 NETWORK_LOG(NETWORK_ERROR, "Failed to get profile list");
3149                 __NETWORK_FUNC_EXIT__;
3150                 return Error;
3151         }
3152
3153         g_variant_get(message, "(a(oa{sv}))", &iter);
3154         Error = __net_extract_default_profile(network_info, iter, profile_info);
3155
3156         g_variant_iter_free(iter);
3157         g_variant_unref(message);
3158
3159         if (Error == NET_ERR_NO_SERVICE) {
3160                 message = _net_invoke_dbus_method(network_info,
3161                                         CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
3162                                         CONNMAN_MANAGER_INTERFACE, "GetMeshPeers", NULL, &Error);
3163                 if (message == NULL) {
3164                         NETWORK_LOG(NETWORK_ERROR, "Failed to get mesh peers");
3165                         Error = NET_ERR_NO_SERVICE;
3166                         __NETWORK_FUNC_EXIT__;
3167                         return Error;
3168                 }
3169
3170                 g_variant_get(message, "(a(oa{sv}))", &iter);
3171                 Error = __net_extract_default_profile(network_info, iter, profile_info);
3172
3173                 g_variant_iter_free(iter);
3174                 g_variant_unref(message);
3175         }
3176
3177         __NETWORK_FUNC_EXIT__;
3178         return Error;
3179 }
3180
3181 static int __net_telephony_reset_profile(network_info_t *network_info, int type, int sim_id)
3182 {
3183         __NETWORK_FUNC_ENTER__;
3184
3185         net_err_t Error = NET_ERR_NONE;
3186         char subscriber_id[3];
3187
3188         GSList *ModemPathList = NULL;
3189         const char *path = NULL;
3190         GSList *list = NULL;
3191
3192         Error = __net_telephony_get_modem_object_path(network_info, &ModemPathList);
3193         if (Error != NET_ERR_NONE) {
3194                 NETWORK_LOG(NETWORK_ERROR, "Failed to get modems path list");
3195                 g_slist_free_full(ModemPathList, g_free);
3196                 __NETWORK_FUNC_EXIT__;
3197                 return Error;
3198         }
3199
3200         g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", sim_id);
3201
3202         for (list = ModemPathList; list != NULL; list = list->next) {
3203                 path = (const char *)list->data;
3204
3205                 if (g_str_has_suffix(path, subscriber_id) == TRUE) {
3206                 Error = _net_dbus_reset_pdp_profile(network_info, type, path);
3207                 if (Error != NET_ERR_NONE) {
3208                         NETWORK_LOG(NETWORK_HIGH, "_net_dbus_reset_pdp_profile() failed");
3209                                 break;
3210                         }
3211                 }
3212         }
3213
3214         g_slist_free_full(ModemPathList, g_free);
3215
3216         __NETWORK_FUNC_EXIT__;
3217         return NET_ERR_NONE;
3218 }
3219
3220 static int __net_convert_string_to_ipv6_string(char *str, char **ip_address)
3221 {
3222         int pos = 0;
3223         struct sockaddr_in6 sa;
3224         char conv_str[INET6_ADDRSTRLEN] = {0,};
3225
3226         *ip_address = (char *)malloc(INET6_ADDRSTRLEN);
3227         if (NULL == *ip_address) {
3228                 NETWORK_LOG(NETWORK_ERROR, "Malloc Failed");
3229                 return NET_ERR_INVALID_OPERATION;
3230         }
3231
3232         /* Convert String without : to string with : */
3233         for (int i = 0; i < 8; i++) {
3234                 pos = 4 * i;
3235                 if (pos > 0)
3236                         conv_str[pos + i - 1] = ':';
3237                 memcpy(conv_str + pos + i, str + pos, 4);
3238         }
3239
3240         /*
3241          * Convert "fe80:0000:0000:0000:0a00:27ff:fe7a:65ea to fe80::a00:27ff:fe7a:65ea
3242          */
3243         inet_pton(AF_INET6, conv_str, &(sa.sin6_addr));
3244         inet_ntop(AF_INET6, &(sa.sin6_addr), *ip_address, INET6_ADDRSTRLEN);
3245
3246         return NET_ERR_NONE;
3247 }
3248
3249
3250 EXPORT_API int net_reset_profile(void *handle, int type, int sim_id)
3251 {
3252         net_err_t Error = NET_ERR_NONE;
3253         network_info_t *network_info = (network_info_t *)handle;
3254
3255         __NETWORK_FUNC_ENTER__;
3256
3257         if (network_info->request_table[NETWORK_REQUEST_TYPE_RESET_DEFAULT].flag == TRUE) {
3258                 NETWORK_LOG(NETWORK_ERROR, "Error!! Request already in progress");
3259                 __NETWORK_FUNC_EXIT__;
3260                 return NET_ERR_IN_PROGRESS;
3261         }
3262
3263         network_info->request_table[NETWORK_REQUEST_TYPE_RESET_DEFAULT].flag = TRUE;
3264
3265         Error = __net_telephony_reset_profile(network_info, type, sim_id);
3266         if (Error != NET_ERR_NONE) {
3267                 NETWORK_LOG(NETWORK_ERROR,
3268                         "Failed to reset service(profile). Error [%s]",
3269                         _net_print_error(Error));
3270                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_RESET_DEFAULT]),
3271                                         0, sizeof(network_request_table_t));
3272                 __NETWORK_FUNC_EXIT__;
3273                 return Error;
3274         }
3275
3276         __NETWORK_FUNC_EXIT__;
3277         return Error;
3278 }
3279 /* LCOV_EXCL_STOP */
3280
3281
3282 /*****************************************************************************
3283  * ConnMan Wi-Fi Client Interface Sync API Definition
3284  *****************************************************************************/
3285 EXPORT_API int net_add_profile(void *handle, net_service_type_t network_type, net_profile_info_t *prof_info)
3286 {
3287         net_err_t Error = NET_ERR_NONE;
3288         network_info_t *network_info = (network_info_t *)handle;
3289
3290         __NETWORK_FUNC_ENTER__;
3291
3292         if (prof_info == NULL || _net_is_valid_service_type(network_type) == FALSE) {
3293                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3294                 __NETWORK_FUNC_EXIT__;
3295                 return NET_ERR_INVALID_PARAM;
3296         }
3297
3298         /* LCOV_EXCL_START */
3299         Error = __net_telephony_add_profile(network_info, prof_info, network_type);
3300         if (Error != NET_ERR_NONE) {
3301                 NETWORK_LOG(NETWORK_ERROR, "Failed to add service(profile). Error [%s]",
3302                                 _net_print_error(Error));
3303                 __NETWORK_FUNC_EXIT__;
3304                 return Error;
3305         }
3306         /* LCOV_EXCL_STOP */
3307
3308         __NETWORK_FUNC_EXIT__;
3309         return Error;
3310 }
3311
3312 EXPORT_API int net_delete_profile(void *handle, const char *profile_name)
3313 {
3314         __NETWORK_FUNC_ENTER__;
3315
3316         net_err_t Error = NET_ERR_NONE;
3317         net_profile_name_t pdp_prof_name;
3318         net_profile_name_t wifi_prof_name;
3319         net_profile_info_t prof_info;
3320         network_info_t *network_info = (network_info_t *)handle;
3321
3322         NETWORK_LOG(NETWORK_HIGH, "Delete Profile [%s]", profile_name);
3323
3324         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
3325                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3326                 __NETWORK_FUNC_EXIT__;
3327                 return NET_ERR_INVALID_PARAM;
3328         }
3329
3330         /* LCOV_EXCL_START */
3331         Error = __net_get_profile_info(network_info, profile_name, &prof_info);
3332         if (Error != NET_ERR_NONE) {
3333                 NETWORK_LOG(NETWORK_ERROR,
3334                                 "Failed to get service(profile) information. Error [%s]",
3335                                 _net_print_error(Error));
3336
3337                 __NETWORK_FUNC_EXIT__;
3338                 return Error;
3339         }
3340
3341         g_strlcpy(wifi_prof_name.ProfileName, profile_name, NET_PROFILE_NAME_LEN_MAX + 1);
3342
3343         if (prof_info.profile_type == NET_DEVICE_WIFI) {
3344                 Error = __net_wifi_delete_profile(network_info, &wifi_prof_name,
3345                                 prof_info.ProfileInfo.Wlan.security_info.sec_mode,
3346                                 prof_info.ProfileInfo.Wlan.passpoint);
3347                 if (Error != NET_ERR_NONE) {
3348                         NETWORK_LOG(NETWORK_ERROR,
3349                                         "Failed to delete service(profile). Error [%s]",
3350                                         _net_print_error(Error));
3351
3352                         __NETWORK_FUNC_EXIT__;
3353                         return Error;
3354                 }
3355         } else if (prof_info.profile_type == NET_DEVICE_CELLULAR) {
3356                 Error = __net_telephony_search_pdp_profile(network_info,
3357                                 wifi_prof_name.ProfileName, &pdp_prof_name);
3358                 if (Error != NET_ERR_NONE) {
3359                         NETWORK_LOG(NETWORK_ERROR,
3360                                         "Failed to get service(profile) information. Error [%s]",
3361                                         _net_print_error(Error));
3362
3363                         __NETWORK_FUNC_EXIT__;
3364                         return Error;
3365                 }
3366
3367                 Error = __net_telephony_delete_profile(network_info, &pdp_prof_name);
3368                 if (Error != NET_ERR_NONE) {
3369                         NETWORK_LOG(NETWORK_ERROR,
3370                                         "Failed to delete service(profile). Error [%s]",
3371                                         _net_print_error(Error));
3372
3373                         __NETWORK_FUNC_EXIT__;
3374                         return Error;
3375                 }
3376         } else if (prof_info.profile_type == NET_DEVICE_MESH) {
3377                 Error = __net_mesh_delete_profile(network_info, profile_name);
3378                 if (Error != NET_ERR_NONE) {
3379                         NETWORK_LOG(NETWORK_ERROR,
3380                                         "Failed to delete service(profile). Error [%s]",
3381                                         _net_print_error(Error));
3382
3383                         __NETWORK_FUNC_EXIT__;
3384                         return Error;
3385                 }
3386         } else {
3387                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3388
3389                 __NETWORK_FUNC_EXIT__;
3390                 return NET_ERR_INVALID_PARAM;
3391         }
3392         /* LCOV_EXCL_STOP */
3393
3394         __NETWORK_FUNC_EXIT__;
3395         return NET_ERR_NONE;
3396 }
3397
3398 EXPORT_API int net_get_profile_info(void *handle,
3399                         const char *profile_name, net_profile_info_t *prof_info)
3400 {
3401         __NETWORK_FUNC_ENTER__;
3402
3403         net_err_t Error = NET_ERR_NONE;
3404         network_info_t *network_info = (network_info_t *)handle;
3405
3406         if (prof_info == NULL || _net_check_profile_name(profile_name) != NET_ERR_NONE) {
3407                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3408
3409                 __NETWORK_FUNC_EXIT__;
3410                 return NET_ERR_INVALID_PARAM;
3411         }
3412
3413         Error = __net_get_profile_info(network_info, profile_name, prof_info);
3414         /* LCOV_EXCL_START */
3415         if (Error != NET_ERR_NONE)
3416                 NETWORK_LOG(NETWORK_ERROR,
3417                                 "Failed to get service(profile) information. Error [%s]",
3418                                 _net_print_error(Error));
3419         /* LCOV_EXCL_STOP */
3420
3421         __NETWORK_FUNC_EXIT__;
3422         return Error;
3423 }
3424
3425 EXPORT_API int net_modify_profile(void *handle, const char *profile_name, net_profile_info_t *prof_info)
3426 {
3427         __NETWORK_FUNC_ENTER__;
3428
3429         net_err_t Error = NET_ERR_NONE;
3430         net_profile_info_t exProfInfo;
3431         network_info_t *network_info = (network_info_t *)handle;
3432
3433         Error = net_get_profile_info(network_info, profile_name, &exProfInfo);
3434         if (Error != NET_ERR_NONE) {
3435                 NETWORK_LOG(NETWORK_ERROR,
3436                                 "Failed to get service(profile) information. Error [%s]",
3437                                 _net_print_error(Error));
3438
3439                 __NETWORK_FUNC_EXIT__;
3440                 return Error;
3441         }
3442
3443         /* LCOV_EXCL_START */
3444         if (prof_info == NULL ||
3445             (exProfInfo.profile_type != NET_DEVICE_WIFI &&
3446              exProfInfo.profile_type != NET_DEVICE_CELLULAR &&
3447             exProfInfo.profile_type != NET_DEVICE_MESH &&
3448             exProfInfo.profile_type != NET_DEVICE_ETHERNET)) {
3449                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3450                 __NETWORK_FUNC_EXIT__;
3451                 return NET_ERR_INVALID_PARAM;
3452         }
3453
3454         if (exProfInfo.profile_type == NET_DEVICE_WIFI)
3455                 Error = __net_modify_wlan_profile_info(network_info, profile_name, prof_info, &exProfInfo);
3456         else if (exProfInfo.profile_type == NET_DEVICE_CELLULAR)
3457                 Error = __net_telephony_modify_profile(network_info, profile_name, prof_info, &exProfInfo);
3458         else if (exProfInfo.profile_type == NET_DEVICE_ETHERNET)
3459                 Error = __net_modify_ethernet_profile(network_info, profile_name, prof_info, &exProfInfo);
3460         else if (exProfInfo.profile_type == NET_DEVICE_MESH)
3461                 Error = __net_modify_mesh_profile(network_info, profile_name, prof_info, &exProfInfo);
3462
3463         if (Error != NET_ERR_NONE) {
3464                 NETWORK_LOG(NETWORK_ERROR,
3465                                 "Failed to modify service(profile) information. Error [%s]",
3466                                 _net_print_error(Error));
3467
3468                 __NETWORK_FUNC_EXIT__;
3469                 return Error;
3470         }
3471         /* LCOV_EXCL_STOP */
3472
3473         __NETWORK_FUNC_EXIT__;
3474         return NET_ERR_NONE;
3475 }
3476
3477 EXPORT_API int net_get_profile_list(void *handle, net_device_t device_type,
3478                 net_profile_info_t **profile_list, int *count)
3479 {
3480         __NETWORK_FUNC_ENTER__;
3481
3482         net_err_t Error = NET_ERR_NONE;
3483         int profile_count = 0;
3484         net_profile_info_t *profile_info = NULL;
3485         network_info_t *network_info = (network_info_t *)handle;
3486
3487         if (count == NULL) {
3488                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3489                 __NETWORK_FUNC_EXIT__;
3490                 return NET_ERR_INVALID_PARAM;
3491         }
3492
3493         if (device_type != NET_DEVICE_CELLULAR &&
3494             device_type != NET_DEVICE_WIFI &&
3495             device_type != NET_DEVICE_ETHERNET &&
3496             device_type != NET_DEVICE_MESH && //LCOV_EXCL_LINE
3497             device_type != NET_DEVICE_BLUETOOTH) {
3498                 NETWORK_LOG(NETWORK_ERROR, "Not Supported"); //LCOV_EXCL_LINE
3499                 __NETWORK_FUNC_EXIT__;
3500                 return NET_ERR_NOT_SUPPORTED;
3501         }
3502
3503         Error = _net_get_profile_list(network_info, device_type, &profile_info, &profile_count);
3504
3505         /* LCOV_EXCL_START */
3506         if (Error != NET_ERR_NONE) {
3507                 NETWORK_LOG(NETWORK_ERROR,
3508                                 "Failed to get service(profile) list. Error [%s]",
3509                                 _net_print_error(Error));
3510
3511                 NET_MEMFREE(profile_info);
3512
3513                 __NETWORK_FUNC_EXIT__;
3514                 return Error;
3515                 /* LCOV_EXCL_STOP */
3516         } else {
3517                 *count = profile_count;
3518                 *profile_list = profile_info;
3519         }
3520
3521         __NETWORK_FUNC_EXIT__;
3522         return NET_ERR_NONE;
3523 }
3524
3525 EXPORT_API int net_get_all_profile_list(void *handle,
3526                 net_profile_info_t **profile_list, int *count)
3527 {
3528         __NETWORK_FUNC_ENTER__;
3529
3530         net_err_t Error = NET_ERR_NONE;
3531         int profile_count = 0;
3532         net_profile_info_t *profile_info = NULL;
3533         network_info_t *network_info = (network_info_t *)handle;
3534
3535         if (count == NULL) {
3536                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3537                 __NETWORK_FUNC_EXIT__;
3538                 return NET_ERR_INVALID_PARAM;
3539         }
3540
3541         Error = _net_get_all_profile_list(network_info, &profile_info, &profile_count);
3542
3543         /* LCOV_EXCL_START */
3544         if (Error != NET_ERR_NONE) {
3545                 NETWORK_LOG(NETWORK_ERROR,
3546                                 "Failed to get service(profile) list. Error [%s]",
3547                                 _net_print_error(Error));
3548
3549                 NET_MEMFREE(profile_info);
3550
3551                 __NETWORK_FUNC_EXIT__;
3552                 return Error;
3553                 /* LCOV_EXCL_STOP */
3554         } else {
3555                 *count = profile_count;
3556                 *profile_list = profile_info;
3557         }
3558
3559         __NETWORK_FUNC_EXIT__;
3560         return NET_ERR_NONE;
3561 }
3562
3563 /* LCOV_EXCL_START */
3564 EXPORT_API int net_get_cellular_modem_object_path(char **modem_path, int sim_id)
3565 {
3566         net_err_t Error = NET_ERR_NONE;
3567         const char *path = NULL;
3568         char subscriber_id[3];
3569         GSList *ModemPathList = NULL, *list = NULL;
3570
3571         if (sim_id < 0 || modem_path == NULL)
3572                 return NET_ERR_INVALID_PARAM;
3573
3574         Error = __net_telephony_get_modem_object_path(NULL, &ModemPathList);
3575         if (Error != NET_ERR_NONE)
3576                 goto done;
3577
3578         *modem_path = NULL;
3579         g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", sim_id);
3580         for (list = ModemPathList; list != NULL; list = list->next) {
3581                 path = (const char *)list->data;
3582
3583                 NETWORK_LOG(NETWORK_LOW, "path: %s", path);
3584                 if (g_str_has_suffix(path, subscriber_id) == TRUE) {
3585                         *modem_path = g_strdup(path);
3586                         break;
3587                 }
3588         }
3589
3590         if (*modem_path == NULL)
3591                 Error = NET_ERR_MODEM_INTERFACE_NOT_AVAIALABLE;
3592         else
3593                 NETWORK_LOG(NETWORK_LOW, "Subscriber %d: %s", sim_id, *modem_path);
3594
3595 done:
3596         if (ModemPathList)
3597                 g_slist_free_full(ModemPathList, g_free);
3598
3599         __NETWORK_FUNC_EXIT__;
3600         return Error;
3601 }
3602
3603 EXPORT_API int net_set_default_cellular_service_profile(void *handle, const char *profile_name)
3604 {
3605         net_err_t Error = NET_ERR_NONE;
3606         network_info_t *network_info = (network_info_t *)handle;
3607
3608         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
3609                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
3610                 __NETWORK_FUNC_EXIT__;
3611                 return NET_ERR_INVALID_PARAM;
3612         }
3613
3614         Error = __net_set_default_cellular_service_profile_sync(network_info, profile_name);
3615         if (Error != NET_ERR_NONE) {
3616                 NETWORK_LOG(NETWORK_ERROR,
3617                                 "Failed to set default cellular service(profile). Error [%s]",
3618                                 _net_print_error(Error));
3619                 __NETWORK_FUNC_EXIT__;
3620                 return Error;
3621         }
3622
3623         return NET_ERR_NONE;
3624 }
3625
3626 EXPORT_API int net_set_default_cellular_service_profile_async(void *handle,
3627                         const char *profile_name)
3628 {
3629         net_err_t Error = NET_ERR_NONE;
3630         network_info_t *network_info = (network_info_t *)handle;
3631
3632         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
3633                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Parameter");
3634                 __NETWORK_FUNC_EXIT__;
3635                 return NET_ERR_INVALID_PARAM;
3636         }
3637
3638         if (network_info->request_table[NETWORK_REQUEST_TYPE_SET_DEFAULT].flag == TRUE) {
3639                 NETWORK_LOG(NETWORK_ERROR, "Error!! Request already in progress");
3640                 __NETWORK_FUNC_EXIT__;
3641                 return NET_ERR_IN_PROGRESS;
3642         }
3643
3644         network_info->request_table[NETWORK_REQUEST_TYPE_SET_DEFAULT].flag = TRUE;
3645
3646         Error = __net_set_default_cellular_service_profile_async(network_info, profile_name);
3647         if (Error != NET_ERR_NONE) {
3648                 NETWORK_LOG(NETWORK_ERROR,
3649                         "Error!!! failed to set default cellular service(profile). Error [%s]",
3650                         _net_print_error(Error));
3651                 memset(&(network_info->request_table[NETWORK_REQUEST_TYPE_SET_DEFAULT]),
3652                                         0, sizeof(network_request_table_t));
3653                 __NETWORK_FUNC_EXIT__;
3654                 return Error;
3655         }
3656
3657         return NET_ERR_NONE;
3658 }
3659 /* LCOV_EXCL_STOP */
3660
3661 EXPORT_API int net_foreach_ipv6_address(net_device_t device_type,
3662                 GSList **ipv6_address_list)
3663 {
3664         __NETWORK_FUNC_ENTER__;
3665
3666         if (ipv6_address_list == NULL) {
3667                 __NETWORK_FUNC_EXIT__;
3668                 return NET_ERR_INVALID_PARAM;
3669         }
3670
3671         FILE *fp = NULL;
3672
3673         char *ip_address = NULL;
3674         char *if_name = NULL;
3675
3676         char buf[NET_IPV6_ADDRESS_FILE_LEN] = {0,};
3677         char str[NET_IPV6_ADDRESS_LEN + 1] = {0,};
3678
3679         fp = fopen(NET_IPV6_ADDRESS_FILE, "r");
3680         if (NULL == fp) {
3681                 NETWORK_LOG(NETWORK_ERROR, "File Opening Failed"); //LCOV_EXCL_LINE
3682                 __NETWORK_FUNC_EXIT__;
3683                 return NET_ERR_INVALID_OPERATION;
3684         }
3685
3686         while (fgets(buf, sizeof(buf), fp) != NULL) {
3687                 g_strlcpy(str, buf, NET_IPV6_ADDRESS_LEN + 1);
3688                 /* LCOV_EXCL_START */
3689                 switch (device_type) {
3690                 case NET_DEVICE_WIFI:
3691                         if_name = strstr(buf, "wlan");
3692                         break;
3693                 case NET_DEVICE_CELLULAR:
3694                         if_name = strstr(buf, "seth");
3695                         break;
3696                 case NET_DEVICE_USB:
3697                         if_name = strstr(buf, "usb");
3698                         break;
3699                 case NET_DEVICE_ETHERNET:
3700                         if_name = strstr(buf, "eth");
3701                         break;
3702                 case NET_DEVICE_BLUETOOTH:
3703                         if_name = strstr(buf, "bnep");
3704                         break;
3705                 default:
3706                         if_name = NULL;
3707                         break;
3708                 }
3709                 if (if_name != NULL) {
3710                         if (NET_ERR_NONE == __net_convert_string_to_ipv6_string(
3711                                                 str, &ip_address))
3712                                 *ipv6_address_list = g_slist_append(
3713                                                 *ipv6_address_list, ip_address);
3714                 }
3715                 /* LCOV_EXCL_STOP */
3716         }
3717
3718         fclose(fp);
3719
3720         __NETWORK_FUNC_EXIT__;
3721         return NET_ERR_NONE;
3722 }
3723
3724 /**
3725  * @fn   EXPORT_API int net_get_preferred_ipv6_address(char **address)
3726  *
3727  * This function is to get preferred ipv6 address.
3728  * This is Sync API.
3729  *
3730  * @return       0 - on success, negative values for errors
3731  * @param[in]    const char *profile_name - profile name
3732  * @param[out]   char **address - preferred ipv6 address of specific profile
3733  */
3734 EXPORT_API int net_get_preferred_ipv6_address(const char *profile_name, char **address)
3735 {
3736         __NETWORK_FUNC_ENTER__;
3737         net_err_t Error = NET_ERR_NONE;
3738
3739         Error = _net_dbus_get_preferred_ipv6_address(profile_name, address);
3740
3741         if (Error != NET_ERR_NONE)
3742                 NETWORK_LOG(NETWORK_ERROR, "_net_dbus_get_preferred_ipv6_address failed\n");
3743
3744         __NETWORK_FUNC_EXIT__;
3745         return Error;
3746 }
3747