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