HS20: Extend wifi profile for passpoint AP information
[platform/core/connectivity/libnet-client.git] / src / network-profile-intf.c
1 /*
2  * Network Client Library
3  *
4  * Copyright 2011-2013 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://floralicense.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
22 #include "network-internal.h"
23 #include "network-dbus-request.h"
24
25 /*****************************************************************************
26  *      Local Functions Declaration
27  *****************************************************************************/
28 static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_t* ProfInfo);
29 static int __net_get_profile_info(const char* ProfileName, net_profile_info_t* ProfInfo);
30 static int __net_extract_service_info(const char* ProfileName,
31                 GVariant *message, net_profile_info_t* ProfInfo);
32 static int __net_pm_init_profile_info(net_device_t profile_type, net_profile_info_t* ProfInfo);
33 static int __net_telephony_init_profile_info(net_telephony_profile_info_t* ProfInfo);
34 static int __net_telephony_get_profile_info(net_profile_name_t* ProfileName,
35                 net_telephony_profile_info_t *ProfileInfo);
36 static int __net_telephony_get_profile_list(net_profile_name_t** ProfileName, int* ProfileCount);
37 static int __net_extract_services(GVariantIter *message, net_device_t device_type,
38                 net_profile_info_t** profile_info, int* profile_count);
39 static int __net_extract_ip(const gchar *value, net_addr_t *ipAddr);
40 static int __net_extract_common_info(const char *key, GVariant *variant, net_profile_info_t* ProfInfo);
41 static int __net_extract_mobile_info(GVariantIter *array, net_profile_info_t* ProfInfo);
42 static int __net_extract_ethernet_info(GVariantIter *array, net_profile_info_t* ProfInfo);
43 static int __net_extract_bluetooth_info(GVariantIter *array, net_profile_info_t* ProfInfo);
44 static int __net_telephony_search_pdp_profile(char* ProfileName, net_profile_name_t* PdpProfName);
45 static int __net_telephony_modify_profile(const char* ProfileName,
46                 net_profile_info_t* ProfInfo, net_profile_info_t* exProfInfo);
47 static int __net_modify_wlan_profile_info(const char* ProfileName,
48                 net_profile_info_t* ProfInfo, net_profile_info_t* exProfInfo);
49 static int __net_telephony_delete_profile(net_profile_name_t* PdpProfName);
50 static int __net_wifi_delete_profile(net_profile_name_t* WifiProfName,
51                 wlan_security_mode_type_t sec_mode);
52 static int __net_telephony_add_profile(net_profile_info_t *ProfInfo, net_service_type_t network_type);
53 static int __net_set_default_cellular_service_profile_sync(const char* ProfileName);
54 static int __net_set_default_cellular_service_profile_async(const char* ProfileName);
55
56 /*****************************************************************************
57  * Extern Variables
58  *****************************************************************************/
59 extern __thread network_info_t NetworkInfo;
60 extern __thread network_request_table_t request_table[NETWORK_REQUEST_TYPE_MAX];
61
62 /*****************************************************************************
63  *      Local Functions Definition
64  *****************************************************************************/
65 static int __net_pm_init_profile_info(net_device_t profile_type, net_profile_info_t* ProfInfo)
66 {
67         __NETWORK_FUNC_ENTER__;
68
69         int i = 0;
70         net_dev_info_t* net_info = NULL;
71
72         if (ProfInfo == NULL ||
73            (profile_type != NET_DEVICE_WIFI &&
74             profile_type != NET_DEVICE_CELLULAR &&
75             profile_type != NET_DEVICE_ETHERNET &&
76             profile_type != NET_DEVICE_BLUETOOTH)) {
77                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
78                 return NET_ERR_INVALID_PARAM;
79         }
80
81         memset(ProfInfo, 0, sizeof(net_profile_info_t));
82         ProfInfo->Favourite = FALSE;
83
84         if (profile_type == NET_DEVICE_WIFI) {
85                 ProfInfo->profile_type = NET_DEVICE_WIFI;
86                 ProfInfo->ProfileInfo.Wlan.Strength = 0;
87                 ProfInfo->ProfileInfo.Wlan.frequency = 0;
88                 ProfInfo->ProfileInfo.Wlan.max_rate = 0;
89                 ProfInfo->ProfileInfo.Wlan.wlan_mode = 0;
90                 ProfInfo->ProfileInfo.Wlan.PassphraseRequired = FALSE;
91                 ProfInfo->ProfileInfo.Wlan.security_info.sec_mode = 0;
92                 ProfInfo->ProfileInfo.Wlan.security_info.enc_mode = 0;
93                 ProfInfo->ProfileInfo.Wlan.security_info.wps_support = FALSE;
94
95                 net_info = &(ProfInfo->ProfileInfo.Wlan.net_info);
96         } else if(profile_type == NET_DEVICE_CELLULAR) {
97                 ProfInfo->profile_type = NET_DEVICE_CELLULAR;
98                 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_NONE;
99                 ProfInfo->ProfileInfo.Pdp.ServiceType = NET_SERVICE_UNKNOWN;
100                 ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType = NET_PDP_AUTH_NONE;
101                 ProfInfo->ProfileInfo.Pdp.IsStatic = FALSE;
102                 ProfInfo->ProfileInfo.Pdp.Roaming = FALSE;
103                 ProfInfo->ProfileInfo.Pdp.SetupRequired = FALSE;
104                 ProfInfo->ProfileInfo.Pdp.Hidden = FALSE;
105                 ProfInfo->ProfileInfo.Pdp.Editable = TRUE;
106                 ProfInfo->ProfileInfo.Pdp.DefaultConn = FALSE;
107
108                 net_info = &(ProfInfo->ProfileInfo.Pdp.net_info);
109         } else if(profile_type == NET_DEVICE_ETHERNET) {
110                 net_info = &(ProfInfo->ProfileInfo.Ethernet.net_info);
111         } else if(profile_type == NET_DEVICE_BLUETOOTH) {
112                 net_info = &(ProfInfo->ProfileInfo.Bluetooth.net_info);
113         }
114
115         net_info->DnsCount = 0;
116
117         for (i = 0;i < NET_DNS_ADDR_MAX;i++) {
118                 net_info->DnsAddr[i].Type = NET_ADDR_IPV4;
119                 net_info->DnsAddr[i].Data.Ipv4.s_addr = 0;
120         }
121
122         net_info->IpConfigType = 0;
123         net_info->IpAddr.Type = NET_ADDR_IPV4;
124         net_info->IpAddr.Data.Ipv4.s_addr = 0;
125         net_info->BNetmask = FALSE;
126         net_info->SubnetMask.Type = NET_ADDR_IPV4;
127         net_info->SubnetMask.Data.Ipv4.s_addr = 0;
128         net_info->BDefGateway = FALSE;
129         net_info->GatewayAddr.Type = NET_ADDR_IPV4;
130         net_info->GatewayAddr.Data.Ipv4.s_addr = 0;
131         net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
132
133         __NETWORK_FUNC_EXIT__;
134         return NET_ERR_NONE;
135 }
136
137 static int __net_telephony_init_profile_info(net_telephony_profile_info_t* ProfInfo)
138 {
139         __NETWORK_FUNC_ENTER__;
140
141         if (ProfInfo == NULL) {
142                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
143
144                 __NETWORK_FUNC_EXIT__;
145                 return NET_ERR_INVALID_PARAM;
146         }
147
148         memset(ProfInfo->ProfileName, '\0', NET_PROFILE_NAME_LEN_MAX+1);
149         ProfInfo->ServiceType = NET_SERVICE_UNKNOWN;
150         memset(ProfInfo->Apn, '\0', NET_PDP_APN_LEN_MAX+1);
151
152         ProfInfo->AuthInfo.AuthType = NET_PDP_AUTH_NONE;
153         memset(ProfInfo->AuthInfo.UserName, '\0', NET_PDP_AUTH_USERNAME_LEN_MAX+1);
154         memset(ProfInfo->AuthInfo.Password, '\0', NET_PDP_AUTH_PASSWORD_LEN_MAX+1);
155
156         memset(ProfInfo->ProxyAddr, '\0', NET_PROXY_LEN_MAX+1);
157         memset(ProfInfo->HomeURL, '\0', NET_HOME_URL_LEN_MAX+1);
158
159         memset(ProfInfo->Keyword, '\0', NET_PDP_APN_LEN_MAX+1);
160         ProfInfo->Hidden = FALSE;
161         ProfInfo->Editable = TRUE;
162         ProfInfo->DefaultConn = FALSE;
163
164         __NETWORK_FUNC_EXIT__;
165         return NET_ERR_NONE;
166 }
167
168 static int __net_get_service_type(gchar *obj_path)
169 {
170         if (g_str_has_prefix(obj_path, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) == TRUE)
171                 return NET_DEVICE_WIFI;
172         else if (g_str_has_prefix(obj_path, CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX) == TRUE)
173                 return NET_DEVICE_CELLULAR;
174         else if (g_str_has_prefix(obj_path, CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX) == TRUE)
175                 return NET_DEVICE_ETHERNET;
176         else if (g_str_has_prefix(obj_path, CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX) == TRUE)
177                 return NET_DEVICE_BLUETOOTH;
178         else
179                 return NET_DEVICE_UNKNOWN;
180 }
181
182 static int __net_telephony_get_profile_info(net_profile_name_t* ProfileName, net_telephony_profile_info_t *ProfileInfo)
183 {
184         __NETWORK_FUNC_ENTER__;
185
186         net_err_t Error = NET_ERR_NONE;
187         GVariant *result;
188         GVariantIter *iter;
189         const gchar *key = NULL;
190         const gchar *value = NULL;
191
192         if (ProfileName == NULL || ProfileInfo == NULL) {
193                 NETWORK_LOG(NETWORK_ERROR, "Invalid parameter!\n");
194                 __NETWORK_FUNC_EXIT__;
195                 return NET_ERR_INVALID_PARAM;
196         }
197
198         result = _net_invoke_dbus_method(TELEPHONY_SERVICE, ProfileName->ProfileName,
199                         TELEPHONY_PROFILE_INTERFACE, "GetProfile", NULL, &Error);
200         if (result == NULL) {
201                 NETWORK_LOG(NETWORK_ERROR, "_net_invoke_dbus_method failed\n");
202                 __NETWORK_FUNC_EXIT__;
203                 return Error;
204         }
205
206         Error = __net_telephony_init_profile_info(ProfileInfo);
207
208         if (Error != NET_ERR_NONE) {
209                 g_variant_unref(result);
210                 __NETWORK_FUNC_EXIT__;
211                 return Error;
212         }
213
214         g_variant_get(result, "(a{ss})", &iter);
215         while (g_variant_iter_next(iter, "{ss}", &key, &value)) {
216                 if (g_strcmp0(key, "path") == 0) {
217                         if (value != NULL)
218                                 g_strlcpy(ProfileInfo->ProfileName, value, NET_PROFILE_NAME_LEN_MAX);
219                 } else if (g_strcmp0(key, "svc_ctg_id") == 0) {
220                         net_service_type_t ServiceType = NET_SERVICE_UNKNOWN;
221
222                         if (value != NULL)
223                                 ServiceType = atoi(value);
224
225                         if (ServiceType > NET_SERVICE_UNKNOWN)
226                                 ProfileInfo->ServiceType = ServiceType;
227                 } else if (g_strcmp0(key, "apn") == 0) {
228                         if (value != NULL)
229                                 g_strlcpy(ProfileInfo->Apn, value, NET_PDP_APN_LEN_MAX);
230                 } else if (g_strcmp0(key, "auth_type") == 0) {
231                         net_auth_type_t authType = NET_PDP_AUTH_NONE;
232
233                         if (value != NULL)
234                                 authType = atoi(value);
235
236                         if (authType == NET_PDP_AUTH_PAP)
237                                 ProfileInfo->AuthInfo.AuthType = NET_PDP_AUTH_PAP;
238                         else if (authType == NET_PDP_AUTH_CHAP)
239                                 ProfileInfo->AuthInfo.AuthType = NET_PDP_AUTH_CHAP;
240                 } else if (g_strcmp0(key, "auth_id") == 0) {
241                         if (value != NULL)
242                                 g_strlcpy(ProfileInfo->AuthInfo.UserName, value, NET_PDP_AUTH_USERNAME_LEN_MAX);
243                 } else if (g_strcmp0(key, "auth_pwd") == 0) {
244                         if (value != NULL)
245                                 g_strlcpy(ProfileInfo->AuthInfo.Password, value, NET_PDP_AUTH_PASSWORD_LEN_MAX);
246                 } else if (g_strcmp0(key, "proxy_addr") == 0) {
247                         if (value != NULL)
248                                 g_strlcpy(ProfileInfo->ProxyAddr, value, NET_PROXY_LEN_MAX);
249                 } else if (g_strcmp0(key, "home_url") == 0) {
250                         if (value != NULL)
251                                 g_strlcpy(ProfileInfo->HomeURL, value, NET_HOME_URL_LEN_MAX);
252                 } else if (g_strcmp0(key, "default_internet_conn") == 0) {
253                         if (value == NULL)
254                                 continue;
255
256                         if (g_strcmp0(value, "TRUE") == 0)
257                                 ProfileInfo->DefaultConn = TRUE;
258                         else
259                                 ProfileInfo->DefaultConn = FALSE;
260                 } else if (g_strcmp0(key, "profile_name") == 0) {
261                         if (value != NULL)
262                                 g_strlcpy(ProfileInfo->Keyword, value, NET_PDP_APN_LEN_MAX);
263                 } else if (g_strcmp0(key, "editable") == 0) {
264                         if (value == NULL)
265                                 continue;
266
267                         if (g_strcmp0(value, "TRUE") == 0)
268                                 ProfileInfo->Editable = TRUE;
269                         else
270                                 ProfileInfo->Editable = FALSE;
271                 } else if (g_strcmp0(key, "hidden") == 0) {
272                         if (value == NULL)
273                                 continue;
274
275                         if (g_strcmp0(value, "TRUE") == 0)
276                                 ProfileInfo->Hidden = TRUE;
277                         else
278                                 ProfileInfo->Hidden = FALSE;
279                 }
280         }
281
282         g_variant_iter_free(iter);
283         g_variant_unref(result);
284
285         __NETWORK_FUNC_EXIT__;
286         return Error;
287 }
288
289 static int __net_telephony_get_profile_list(net_profile_name_t** ProfileName, int* ProfileCount)
290 {
291         __NETWORK_FUNC_ENTER__;
292
293         net_err_t Error = NET_ERR_NONE;
294         GVariant *result;
295         GVariantIter *iter;
296         const char *str;
297         int count = 0, i;
298         GSList *profiles = NULL, *list;
299         net_profile_name_t* profileList = NULL;
300
301         result = _net_invoke_dbus_method(TELEPHONY_SERVICE, TELEPHONY_MASTER_PATH,
302                         TELEPHONY_MASTER_INTERFACE, "GetProfileList", NULL, &Error);
303         if (result == NULL) {
304                 NETWORK_LOG(NETWORK_ERROR, "_net_invoke_dbus_method failed\n");
305                 __NETWORK_FUNC_EXIT__;
306                 return Error;
307         }
308
309         g_variant_get(result, "(as)", &iter);
310         while (g_variant_iter_loop(iter, "s", &str))
311                 profiles = g_slist_append(profiles, g_strdup(str));
312
313         count = g_slist_length(profiles);
314         if (count > 0)
315                 profileList =
316                                 (net_profile_name_t*)malloc(sizeof(net_profile_name_t) * count);
317         else {
318                 *ProfileCount = 0;
319                 goto out;
320         }
321
322         if (profileList == NULL) {
323                 NETWORK_LOG(NETWORK_ERROR, "Failed to allocate memory\n");
324                 *ProfileCount = 0;
325                 Error = NET_ERR_UNKNOWN;
326                 goto out;
327         }
328
329         for (list = profiles, i = 0; list != NULL; list = list->next, i++)
330                 g_strlcpy(profileList[i].ProfileName,
331                                 (const char *)list->data, NET_PROFILE_NAME_LEN_MAX);
332
333         *ProfileName = profileList;
334         *ProfileCount = count;
335
336 out:
337         g_slist_free_full(profiles, g_free);
338         g_variant_iter_free(iter);
339         g_variant_unref(result);
340
341         __NETWORK_FUNC_EXIT__;
342         return Error;
343 }
344
345 static int __net_telephony_search_pdp_profile(char* ProfileName, net_profile_name_t* PdpProfName)
346 {
347         __NETWORK_FUNC_ENTER__;
348
349         net_err_t Error = NET_ERR_NONE;
350         net_profile_name_t* ProfileList = NULL;
351         char* connmanProfName = NULL;
352         char* telephonyProfName = NULL;
353         char* foundPtr = NULL;
354         int ProfileCount = 0;
355         int i = 0;
356
357         /* Get pdp profile list from telephony service */
358         Error = __net_telephony_get_profile_list(&ProfileList, &ProfileCount);
359         if (Error != NET_ERR_NONE) {
360                 NETWORK_LOG(NETWORK_ERROR, "Failed to get profile list from telephony service\n");
361                 NET_MEMFREE(ProfileList);
362                 __NETWORK_FUNC_EXIT__;
363                 return Error;
364         }
365
366         if (ProfileList == NULL || ProfileCount <= 0) {
367                 NETWORK_LOG(NETWORK_ERROR, "There is no PDP profiles\n");
368                 NET_MEMFREE(ProfileList);
369                 __NETWORK_FUNC_EXIT__;
370                 return NET_ERR_NO_SERVICE;
371         }
372
373         /* Find matching profile */
374         connmanProfName = strrchr(ProfileName, '/') + 1;
375         for (i = 0; i < ProfileCount; i++) {
376                 telephonyProfName = strrchr(ProfileList[i].ProfileName, '/') + 1;
377                 foundPtr = strstr(connmanProfName, telephonyProfName);
378
379                 if (foundPtr != NULL && g_strcmp0(foundPtr, telephonyProfName) == 0) {
380                         g_strlcpy(PdpProfName->ProfileName,
381                                         ProfileList[i].ProfileName, NET_PROFILE_NAME_LEN_MAX);
382
383                         NETWORK_LOG(NETWORK_HIGH,
384                                         "PDP profile name found in cellular profile: %s\n",
385                                         PdpProfName->ProfileName);
386                         break;
387                 }
388         }
389
390         if (i >= ProfileCount) {
391                 NETWORK_LOG(NETWORK_ERROR, "There is no matching PDP profiles\n");
392                 NET_MEMFREE(ProfileList);
393                 __NETWORK_FUNC_EXIT__;
394                 return NET_ERR_NO_SERVICE;
395         }
396
397         NET_MEMFREE(ProfileList);
398
399         __NETWORK_FUNC_EXIT__;
400         return Error;
401 }
402
403 static int __net_extract_mobile_services(GVariantIter *iter,
404                 network_services_list_t *service_info,
405                 net_service_type_t network_type)
406 {
407         int count = 0, i = 0;
408         const char net_suffix[] = "_1";
409         const char mms_suffix[] = "_2";
410         const char pre_net_suffix[] = "_3";
411         const char pre_mms_suffix[] = "_4";
412         const char tethering_suffix[] = "_5";
413         char *suffix = NULL;
414         gchar *obj = NULL;
415         GVariantIter *value = NULL;
416         gboolean found = FALSE;
417
418         __NETWORK_FUNC_ENTER__;
419
420         if (iter == NULL || service_info == NULL) {
421                 NETWORK_LOG(NETWORK_ERROR, "Invalid parameter\n");
422
423                 __NETWORK_FUNC_EXIT__;
424                 return NET_ERR_INVALID_PARAM;
425         }
426
427         if (NET_SERVICE_INTERNET <= network_type &&
428                         network_type <= NET_SERVICE_TETHERING) {
429                 NETWORK_LOG(NETWORK_ERROR, "Service type %d\n", network_type);
430         } else {
431                 NETWORK_LOG(NETWORK_ERROR, "Invalid service type %d\n", network_type);
432                 __NETWORK_FUNC_EXIT__;
433                 return NET_ERR_INVALID_PARAM;
434         }
435
436         service_info->num_of_services = 0;
437
438         while (g_variant_iter_loop(iter, "(oa{sv})", &obj, &value)) {
439                 if (obj == NULL)
440                         continue;
441
442                 if (g_str_has_prefix(obj,
443                                 CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX) == TRUE) {
444                         found = FALSE;
445
446                         suffix = strrchr(obj, '_');
447
448                         if (network_type == NET_SERVICE_INTERNET &&
449                                         g_strcmp0(suffix, net_suffix) == 0)
450                                 found = TRUE;
451                         else if (network_type == NET_SERVICE_MMS &&
452                                         g_strcmp0(suffix, mms_suffix) == 0)
453                                 found = TRUE;
454                         else if (network_type == NET_SERVICE_PREPAID_INTERNET &&
455                                         g_strcmp0(suffix, pre_net_suffix) == 0)
456                                 found = TRUE;
457                         else if (network_type == NET_SERVICE_PREPAID_MMS &&
458                                         g_strcmp0(suffix, pre_mms_suffix) == 0)
459                                 found = TRUE;
460                         else if (network_type == NET_SERVICE_TETHERING &&
461                                         g_strcmp0(suffix, tethering_suffix) == 0)
462                                 found = TRUE;
463
464                         if (found == TRUE) {
465                                 service_info->ProfileName[count] =
466                                                 (char*)malloc(NET_PROFILE_NAME_LEN_MAX+1);
467                                 if (service_info->ProfileName[count] == NULL) {
468                                         NETWORK_LOG(NETWORK_ERROR, "Failed to allocate memory\n");
469
470                                         for (i = 0; i < count; i++)
471                                                 NET_MEMFREE(service_info->ProfileName[i]);
472
473                                         g_variant_iter_free(value);
474                                         g_free(obj);
475                                         __NETWORK_FUNC_EXIT__;
476                                         return NET_ERR_UNKNOWN;
477                                 }
478
479                                 g_strlcpy(service_info->ProfileName[count], obj,
480                                                 NET_PROFILE_NAME_LEN_MAX+1);
481
482                                 count++;
483                         }
484                 }
485         }
486
487         service_info->num_of_services = count;
488
489         __NETWORK_FUNC_EXIT__;
490         return NET_ERR_NONE;
491 }
492
493 static int __net_extract_all_services(GVariantIter *array,
494                 const char *service_prefix, int *prof_count, net_profile_info_t **ProfilePtr)
495 {
496         int count = 0;
497         net_profile_info_t ProfInfo = {0, };
498         net_err_t Error = NET_ERR_NONE;
499         gchar *obj;
500         GVariantIter *next = NULL;
501
502         __NETWORK_FUNC_ENTER__;
503
504         if (array == NULL || service_prefix == NULL) {
505                 NETWORK_LOG(NETWORK_ERROR, "Invalid parameter \n");
506
507                 __NETWORK_FUNC_EXIT__;
508                 return NET_ERR_INVALID_PARAM;
509         }
510
511         while (g_variant_iter_loop(array, "(oa{sv})", &obj, &next)) {
512                 if (obj == NULL)
513                         continue;
514
515                 if (g_str_has_prefix(obj, service_prefix) == TRUE) {
516                         net_device_t local_device_type = __net_get_service_type(obj);
517
518                         if (local_device_type == NET_DEVICE_UNKNOWN)
519                                 continue;
520
521                         if (local_device_type == NET_DEVICE_WIFI &&
522                                         g_strrstr(obj + strlen(service_prefix), "hidden") != NULL)
523                                 continue;
524
525                         memset(&ProfInfo, 0, sizeof(net_profile_info_t));
526                         if ((Error = __net_pm_init_profile_info(local_device_type, &ProfInfo)) != NET_ERR_NONE) {
527                                 NETWORK_LOG(NETWORK_ERROR, "Failed to init profile\n");
528
529                                 NET_MEMFREE(*ProfilePtr);
530                                 *prof_count = 0;
531
532                                 goto error;
533                         }
534
535                         ProfInfo.profile_type = local_device_type;
536                         g_strlcpy(ProfInfo.ProfileName, obj, NET_PROFILE_NAME_LEN_MAX);
537
538                         switch(local_device_type) {
539                         case NET_DEVICE_WIFI:
540                                 g_strlcpy(ProfInfo.ProfileInfo.Wlan.net_info.ProfileName,
541                                                 obj, NET_PROFILE_NAME_LEN_MAX);
542
543                                 Error = __net_extract_wifi_info(next, &ProfInfo);
544                                 break;
545                         case NET_DEVICE_CELLULAR:
546                                 g_strlcpy(ProfInfo.ProfileInfo.Pdp.net_info.ProfileName,
547                                                 obj, NET_PROFILE_NAME_LEN_MAX);
548
549                                 Error = __net_extract_mobile_info(next, &ProfInfo);
550                                 break;
551                         case NET_DEVICE_ETHERNET:
552                                 g_strlcpy(ProfInfo.ProfileInfo.Ethernet.net_info.ProfileName,
553                                                 obj, NET_PROFILE_NAME_LEN_MAX);
554
555                                 Error = __net_extract_ethernet_info(next, &ProfInfo);
556                                 break;
557                         case NET_DEVICE_BLUETOOTH:
558                                 g_strlcpy(ProfInfo.ProfileInfo.Bluetooth.net_info.ProfileName,
559                                                 obj, NET_PROFILE_NAME_LEN_MAX);
560
561                                 Error = __net_extract_bluetooth_info(next, &ProfInfo);
562                                 break;
563                         default:
564                                 NET_MEMFREE(*ProfilePtr);
565                                 *prof_count = 0;
566
567                                 Error = NET_ERR_NOT_SUPPORTED;
568                                 goto error;
569                         }
570
571                         if (Error != NET_ERR_NONE) {
572                                 NETWORK_LOG(NETWORK_ERROR,
573                                                 "Failed to extract service info\n");
574
575                                 NET_MEMFREE(*ProfilePtr);
576                                 *prof_count = 0;
577
578                                 goto error;
579                         }
580
581                         *ProfilePtr = (net_profile_info_t *)realloc(*ProfilePtr,
582                                         (count + 1) * sizeof(net_profile_info_t));
583                         if (*ProfilePtr == NULL) {
584                                 NETWORK_LOG(NETWORK_ERROR, "Failed to allocate memory\n");
585                                 *prof_count = 0;
586
587                                 Error = NET_ERR_UNKNOWN;
588                                 goto error;
589                         }
590
591                         memcpy(*ProfilePtr + count, &ProfInfo, sizeof(net_profile_info_t));
592                         count++;
593                 }
594         }
595
596         *prof_count = count;
597
598         __NETWORK_FUNC_EXIT__;
599         return NET_ERR_NONE;
600
601 error:
602         if (next)
603                 g_variant_iter_free(next);
604
605         if (obj)
606                 g_free(obj);
607
608         __NETWORK_FUNC_EXIT__;
609         return Error;
610 }
611
612 static int __net_extract_services(GVariantIter *message, net_device_t device_type,
613                 net_profile_info_t** profile_info, int* profile_count)
614 {
615         __NETWORK_FUNC_ENTER__;
616
617         net_err_t Error = NET_ERR_NONE;
618         net_profile_info_t *ProfilePtr = NULL;
619         int prof_cnt = 0;
620         char *service_prefix = NULL;
621
622         *profile_count = 0;
623
624         switch (device_type) {
625         case NET_DEVICE_WIFI :
626                 service_prefix = CONNMAN_WIFI_SERVICE_PROFILE_PREFIX;
627                 break;
628         case NET_DEVICE_CELLULAR :
629                 service_prefix = CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX;
630                 break;
631         case NET_DEVICE_ETHERNET :
632                 service_prefix = CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX;
633                 break;
634         case NET_DEVICE_BLUETOOTH :
635                 service_prefix = CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX;
636                 break;
637         case NET_DEVICE_MAX :
638                 service_prefix = CONNMAN_SERVICE_PROFILE_PREFIX;
639                 break;
640         default :
641                 *profile_count = 0;
642                 *profile_info = NULL;
643                 __NETWORK_FUNC_EXIT__;
644                 return NET_ERR_NOT_SUPPORTED;
645                 break;
646         }
647
648         Error = __net_extract_all_services(message, service_prefix, &prof_cnt, &ProfilePtr);
649         if (Error != NET_ERR_NONE) {
650                 NETWORK_LOG(NETWORK_ERROR, "Failed to extract services from received message\n");
651                 *profile_count = 0;
652                 *profile_info = NULL;
653                 __NETWORK_FUNC_EXIT__;
654                 return Error;
655         }
656
657         NETWORK_LOG(NETWORK_HIGH, "Total Num. of Profiles [%d]\n", prof_cnt);
658
659         *profile_count = prof_cnt;
660         *profile_info = ProfilePtr;
661
662         __NETWORK_FUNC_EXIT__;
663
664         return Error;
665 }
666
667 static int __net_extract_ip(const gchar *value, net_addr_t *ipAddr)
668 {
669         __NETWORK_FUNC_ENTER__;
670
671         unsigned char *ipValue = NULL;
672         char *saveptr = NULL;
673         char ipString[NETPM_IPV4_STR_LEN_MAX+1];
674         char* ipToken[4];
675
676         ipValue = (unsigned char *)&(ipAddr->Data.Ipv4.s_addr);
677
678         if(value != NULL) {
679                 g_strlcpy(ipString, value, NETPM_IPV4_STR_LEN_MAX+1);
680
681                 ipToken[0] = strtok_r(ipString, ".", &saveptr);
682
683                 if(ipToken[0] != NULL) {
684                         ipToken[1] = strtok_r(NULL, ".", &saveptr);
685
686                         if(ipToken[1] != NULL) {
687                                 ipToken[2] = strtok_r(NULL, ".", &saveptr);
688
689                                 if(ipToken[2] != NULL) {
690                                         ipToken[3] = strtok_r(NULL, ".", &saveptr);
691
692                                         if(ipToken[3] != NULL) {
693                                                 ipValue[0] = (unsigned char)atoi(ipToken[0]);
694                                                 ipValue[1] = (unsigned char)atoi(ipToken[1]);
695                                                 ipValue[2] = (unsigned char)atoi(ipToken[2]);
696                                                 ipValue[3] = (unsigned char)atoi(ipToken[3]);
697                                         }
698                                 }
699                         }
700                 }
701         }
702
703         __NETWORK_FUNC_EXIT__;
704
705         return NET_ERR_NONE;
706 }
707
708 static int __net_extract_common_info(const char *key, GVariant *variant, net_profile_info_t* ProfInfo)
709 {
710         __NETWORK_FUNC_ENTER__;
711
712         net_err_t Error = NET_ERR_NONE;
713         const gchar *subKey = NULL;
714         const gchar *value = NULL;
715         net_dev_info_t* net_info = NULL;
716         GVariant *var = NULL;
717         GVariantIter *iter = NULL;
718
719         if (ProfInfo->profile_type == NET_DEVICE_CELLULAR) {
720                 net_info = &(ProfInfo->ProfileInfo.Pdp.net_info);
721         } else if (ProfInfo->profile_type == NET_DEVICE_WIFI) {
722                 net_info = &(ProfInfo->ProfileInfo.Wlan.net_info);
723         } else if (ProfInfo->profile_type == NET_DEVICE_ETHERNET) {
724                 net_info = &(ProfInfo->ProfileInfo.Ethernet.net_info);
725         } else if (ProfInfo->profile_type == NET_DEVICE_BLUETOOTH) {
726                 net_info = &(ProfInfo->ProfileInfo.Bluetooth.net_info);
727         } else {
728                 NETWORK_LOG(NETWORK_ERROR,
729                                 "Invalid Profile type. [%d]\n", ProfInfo->profile_type);
730                 return NET_ERR_INVALID_PARAM;
731         }
732
733         if (g_strcmp0(key, "State") == 0) {
734                 value = g_variant_get_string(variant, NULL);
735
736                 if (g_strcmp0(value, "idle") == 0)
737                         ProfInfo->ProfileState = NET_STATE_TYPE_IDLE;
738                 else if (g_strcmp0(value, "failure") == 0)
739                         ProfInfo->ProfileState = NET_STATE_TYPE_FAILURE;
740                 else if (g_strcmp0(value, "association") == 0)
741                         ProfInfo->ProfileState = NET_STATE_TYPE_ASSOCIATION;
742                 else if (g_strcmp0(value, "configuration") == 0)
743                         ProfInfo->ProfileState = NET_STATE_TYPE_CONFIGURATION;
744                 else if (g_strcmp0(value, "ready") == 0)
745                         ProfInfo->ProfileState = NET_STATE_TYPE_READY;
746                 else if (g_strcmp0(value, "disconnect") == 0)
747                         ProfInfo->ProfileState = NET_STATE_TYPE_DISCONNECT;
748                 else if (g_strcmp0(value, "online") == 0)
749                         ProfInfo->ProfileState = NET_STATE_TYPE_ONLINE;
750                 else
751                         ProfInfo->ProfileState = NET_STATE_TYPE_UNKNOWN;
752         } else if (g_strcmp0(key, "Favorite") == 0) {
753                 gboolean val = g_variant_get_boolean(variant);
754
755                 if(val)
756                         ProfInfo->Favourite = TRUE;
757                 else
758                         ProfInfo->Favourite = FALSE;
759         } else if (g_strcmp0(key, "Ethernet") == 0) {
760                 g_variant_get(variant, "a{sv}", &iter);
761                 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
762                         if (g_strcmp0(subKey, "Interface") == 0) {
763                                 value = g_variant_get_string(var, NULL);
764
765                                 if (value != NULL)
766                                         g_strlcpy(net_info->DevName, value, NET_MAX_DEVICE_NAME_LEN);
767                         } else if (g_strcmp0(subKey, "Address") == 0) {
768                                 value = g_variant_get_string(var, NULL);
769
770                                 if (value != NULL)
771                                         g_strlcpy(net_info->MacAddr, value, NET_MAX_MAC_ADDR_LEN);
772                         }
773                 }
774                 g_variant_iter_free(iter);
775         } else if (g_strcmp0(key, "IPv4") == 0) {
776                 g_variant_get(variant, "a{sv}", &iter);
777                 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
778                         if (g_strcmp0(subKey, "Method") == 0) {
779                                 value = g_variant_get_string(var, NULL);
780
781                                 if (g_strcmp0(value, "dhcp") == 0)
782                                         net_info->IpConfigType = NET_IP_CONFIG_TYPE_DYNAMIC;
783                                 else if (g_strcmp0(value, "manual") == 0)
784                                         net_info->IpConfigType = NET_IP_CONFIG_TYPE_STATIC;
785                                 else if (g_strcmp0(value, "fixed") == 0)
786                                         net_info->IpConfigType = NET_IP_CONFIG_TYPE_FIXED;
787                                 else if (g_strcmp0(value, "off") == 0)
788                                         net_info->IpConfigType = NET_IP_CONFIG_TYPE_OFF;
789
790                         } else if (g_strcmp0(subKey, "Address") == 0) {
791                                 value = g_variant_get_string(var, NULL);
792
793                                 __net_extract_ip(value, &net_info->IpAddr);
794                         } else if (g_strcmp0(subKey, "Netmask") == 0) {
795                                 value = g_variant_get_string(var, NULL);
796
797                                 __net_extract_ip(value, &net_info->SubnetMask);
798                                 net_info->BNetmask = TRUE;
799                         } else if (g_strcmp0(subKey, "Gateway") == 0) {
800                                 value = g_variant_get_string(var, NULL);
801
802                                 __net_extract_ip(value, &net_info->GatewayAddr);
803                                 net_info->BDefGateway = TRUE;
804                         }
805                 }
806                 g_variant_iter_free(iter);
807         } else if (g_strcmp0(key, "IPv4.Configuration") == 0) {
808                 if (net_info->IpConfigType != NET_IP_CONFIG_TYPE_DYNAMIC &&
809                     net_info->IpConfigType != NET_IP_CONFIG_TYPE_STATIC &&
810                     net_info->IpConfigType != NET_IP_CONFIG_TYPE_FIXED &&
811                     net_info->IpConfigType != NET_IP_CONFIG_TYPE_OFF) {
812
813                         g_variant_get(variant, "a{sv}", &iter);
814                         while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
815                                 if (g_strcmp0(subKey, "Method") == 0) {
816                                         value = g_variant_get_string(var, NULL);
817
818                                         if(g_strcmp0(value, "dhcp") == 0)
819                                                 net_info->IpConfigType = NET_IP_CONFIG_TYPE_DYNAMIC;
820                                         else if(g_strcmp0(value, "manual") == 0)
821                                                 net_info->IpConfigType = NET_IP_CONFIG_TYPE_STATIC;
822                                         else if (g_strcmp0(value, "fixed") == 0)
823                                                 net_info->IpConfigType = NET_IP_CONFIG_TYPE_FIXED;
824                                         else if(g_strcmp0(value, "off") == 0)
825                                                 net_info->IpConfigType = NET_IP_CONFIG_TYPE_OFF;
826
827                                 } else if (g_strcmp0(subKey, "Address") == 0 &&
828                                            net_info->IpAddr.Data.Ipv4.s_addr == 0) {
829                                         value = g_variant_get_string(var, NULL);
830
831                                         __net_extract_ip(value, &net_info->IpAddr);
832                                 } else if (g_strcmp0(subKey, "Netmask") == 0 &&
833                                            net_info->SubnetMask.Data.Ipv4.s_addr == 0) {
834                                         value = g_variant_get_string(var, NULL);
835
836                                         __net_extract_ip(value, &net_info->SubnetMask);
837                                         net_info->BNetmask = TRUE;
838                                 } else if (g_strcmp0(subKey, "Gateway") == 0 &&
839                                            net_info->GatewayAddr.Data.Ipv4.s_addr == 0) {
840                                         value = g_variant_get_string(var, NULL);
841
842                                         __net_extract_ip(value, &net_info->GatewayAddr);
843                                         net_info->BDefGateway = TRUE;
844                                 }
845                         }
846                         g_variant_iter_free(iter);
847                 }
848         } else if(g_strcmp0(key, "Nameservers") == 0) {
849                 int dnsCount = 0;
850
851                 g_variant_get(variant, "as", &iter);
852                 while (g_variant_iter_loop(iter, "s", &value)) {
853                         __net_extract_ip(value, &net_info->DnsAddr[dnsCount]);
854
855                         dnsCount++;
856                         if (dnsCount >= NET_DNS_ADDR_MAX) {
857                                 g_free((gchar*)value);
858                                 break;
859                         }
860                 }
861
862                 g_variant_iter_free(iter);
863
864                 net_info->DnsCount = dnsCount;
865         } else if (g_strcmp0(key, "Nameservers.Configuration") == 0 && net_info->DnsCount == 0) {
866                 int dnsCount = 0;
867
868                 g_variant_get(variant, "as", &iter);
869                 while (g_variant_iter_loop(iter, "s", &value)) {
870                         __net_extract_ip(value, &net_info->DnsAddr[dnsCount]);
871
872                         dnsCount++;
873                         if (dnsCount >= NET_DNS_ADDR_MAX) {
874                                 g_free((gchar*)value);
875                                 break;
876                         }
877                 }
878                 g_variant_iter_free(iter);
879
880                 net_info->DnsCount = dnsCount;
881         } else if (g_strcmp0(key, "Domains") == 0) {
882         } else if (g_strcmp0(key, "Domains.Configuration") == 0) {
883         } else if (g_strcmp0(key, "Proxy") == 0) {
884                 const gchar *url = NULL;
885                 gchar *servers = NULL;
886
887                 g_variant_get(variant, "a{sv}", &iter);
888                 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
889                         if (g_strcmp0(subKey, "Method") == 0) {
890                                 value = g_variant_get_string(var, NULL);
891
892                                 if (g_strcmp0(value, "direct") == 0)
893                                         net_info->ProxyMethod = NET_PROXY_TYPE_DIRECT;
894                                 else if (g_strcmp0(value, "auto") == 0)
895                                         net_info->ProxyMethod = NET_PROXY_TYPE_AUTO;
896                                 else if (g_strcmp0(value, "manual") == 0)
897                                         net_info->ProxyMethod = NET_PROXY_TYPE_MANUAL;
898                                 else
899                                         net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
900                         } else if (g_strcmp0(subKey, "URL") == 0) {
901                                 url = g_variant_get_string(var, NULL);
902                         } else if (g_strcmp0(subKey, "Servers") == 0) {
903                                 GVariantIter *iter_sub = NULL;
904
905                                 g_variant_get(var, "as", &iter_sub);
906
907                                 if (g_variant_iter_loop(iter_sub, "s", &servers) == FALSE)
908                                         servers = NULL;
909
910                                 g_variant_iter_free(iter_sub);
911                         }
912                 }
913                 g_variant_iter_free(iter);
914
915                 if (net_info->ProxyMethod == NET_PROXY_TYPE_AUTO && url != NULL)
916                         g_strlcpy(net_info->ProxyAddr, url, NET_PROXY_LEN_MAX);
917                 else if (net_info->ProxyMethod == NET_PROXY_TYPE_MANUAL && servers != NULL)
918                         g_strlcpy(net_info->ProxyAddr, servers, NET_PROXY_LEN_MAX);
919
920                 if (servers)
921                         g_free(servers);
922         } else if (g_strcmp0(key, "Proxy.Configuration") == 0 &&
923                    net_info->ProxyMethod != NET_PROXY_TYPE_AUTO &&
924                    net_info->ProxyMethod != NET_PROXY_TYPE_MANUAL) {
925
926                 const gchar *url = NULL;
927                 gchar *servers = NULL;
928
929                 g_variant_get(variant, "a{sv}", &iter);
930                 while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
931                         if (g_strcmp0(subKey, "Method") == 0) {
932                                 value = g_variant_get_string(var, NULL);
933
934                                 if (g_strcmp0(value, "direct") == 0)
935                                         net_info->ProxyMethod = NET_PROXY_TYPE_DIRECT;
936                                 else if (g_strcmp0(value, "auto") == 0)
937                                         net_info->ProxyMethod = NET_PROXY_TYPE_AUTO;
938                                 else if (g_strcmp0(value, "manual") == 0)
939                                         net_info->ProxyMethod = NET_PROXY_TYPE_MANUAL;
940                                 else
941                                         net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
942                         } else if (g_strcmp0(subKey, "URL") == 0) {
943                                 url = g_variant_get_string(var, NULL);
944                         } else if (g_strcmp0(subKey, "Servers") == 0) {
945                                 GVariantIter *iter_sub = NULL;
946
947                                 g_variant_get(var, "as", &iter_sub);
948
949                                 if (g_variant_iter_loop(iter_sub, "s", &servers) == FALSE)
950                                         servers = NULL;
951
952                                 g_variant_iter_free(iter_sub);
953                         }
954                 }
955                 g_variant_iter_free(iter);
956
957                 if (net_info->ProxyMethod == NET_PROXY_TYPE_AUTO && url != NULL)
958                         g_strlcpy(net_info->ProxyAddr, url, NET_PROXY_LEN_MAX);
959                 else if (net_info->ProxyMethod == NET_PROXY_TYPE_MANUAL && servers != NULL)
960                         g_strlcpy(net_info->ProxyAddr, servers, NET_PROXY_LEN_MAX);
961
962                 if (servers)
963                         g_free(servers);
964         } else if(g_strcmp0(key, "Provider") == 0) {
965         }
966
967         __NETWORK_FUNC_EXIT__;
968         return Error;
969 }
970
971 static wlan_eap_type_t __convert_eap_type_from_string(const char *eap_type)
972 {
973         if (eap_type == NULL)
974                 return WLAN_SEC_EAP_TYPE_PEAP;
975         else if (g_str_equal(eap_type, "peap") == TRUE)
976                 return WLAN_SEC_EAP_TYPE_PEAP;
977         else if (g_str_equal(eap_type, "tls") == TRUE)
978                 return WLAN_SEC_EAP_TYPE_TLS;
979         else if (g_str_equal(eap_type, "ttls") == TRUE)
980                 return WLAN_SEC_EAP_TYPE_TTLS;
981         else if (g_str_equal(eap_type, "sim") == TRUE)
982                 return WLAN_SEC_EAP_TYPE_SIM;
983         else if (g_str_equal(eap_type, "aka") == TRUE)
984                 return WLAN_SEC_EAP_TYPE_AKA;
985         else
986                 return WLAN_SEC_EAP_TYPE_PEAP;
987 }
988
989 static wlan_eap_auth_type_t __convert_eap_auth_from_string(const char *eap_auth)
990 {
991         if (eap_auth == NULL)
992                 return WLAN_SEC_EAP_AUTH_NONE;
993         else if (g_str_equal(eap_auth, "NONE") == TRUE)
994                 return WLAN_SEC_EAP_AUTH_NONE;
995         else if (g_str_equal(eap_auth, "PAP") == TRUE)
996                 return WLAN_SEC_EAP_AUTH_PAP;
997         else if (g_str_equal(eap_auth, "MSCHAP") == TRUE)
998                 return WLAN_SEC_EAP_AUTH_MSCHAP;
999         else if (g_str_equal(eap_auth, "MSCHAPV2") == TRUE)
1000                 return WLAN_SEC_EAP_AUTH_MSCHAPV2;
1001         else if (g_str_equal(eap_auth, "GTC") == TRUE)
1002                 return WLAN_SEC_EAP_AUTH_GTC;
1003         else if (g_str_equal(eap_auth, "MD5") == TRUE)
1004                 return WLAN_SEC_EAP_AUTH_MD5;
1005         else
1006                 return WLAN_SEC_EAP_AUTH_NONE;
1007 }
1008
1009 static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_t* ProfInfo)
1010 {
1011         net_err_t Error = NET_ERR_NONE;
1012         net_wifi_profile_info_t *Wlan = &(ProfInfo->ProfileInfo.Wlan);
1013         GVariant *var = NULL;
1014         const gchar *key = NULL;
1015
1016         __NETWORK_FUNC_ENTER__;
1017
1018         while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
1019                 const gchar *value = NULL;
1020
1021                 if (g_strcmp0(key, "Mode") == 0) {
1022                         value = g_variant_get_string(var, NULL);
1023
1024                         if (g_strcmp0(value, "managed") == 0)
1025                                 Wlan->wlan_mode = NETPM_WLAN_CONNMODE_INFRA;
1026                         else if (g_strcmp0(value, "adhoc") == 0)
1027                                 Wlan->wlan_mode = NETPM_WLAN_CONNMODE_ADHOC;
1028                         else
1029                                 Wlan->wlan_mode = NETPM_WLAN_CONNMODE_AUTO;
1030
1031                 } else if (g_strcmp0(key, "Security") == 0) {
1032                         GVariantIter *iter_sub = NULL;
1033
1034                         g_variant_get(var, "as", &iter_sub);
1035                         while (g_variant_iter_loop(iter_sub, "s", &value)) {
1036                                 if (g_strcmp0(value, "none") == 0 &&
1037                                     Wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1038                                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1039                                 else if (g_strcmp0(value, "wep") == 0 &&
1040                                          Wlan->security_info.sec_mode < WLAN_SEC_MODE_WEP)
1041                                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_WEP;
1042                                 else if (g_strcmp0(value, "psk") == 0 &&
1043                                          Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1044                                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
1045                                 else if (g_strcmp0(value, "ieee8021x") == 0 &&
1046                                          Wlan->security_info.sec_mode < WLAN_SEC_MODE_IEEE8021X)
1047                                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_IEEE8021X;
1048                                 else if (g_strcmp0(value, "wpa") == 0 &&
1049                                          Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1050                                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
1051                                 else if (g_strcmp0(value, "rsn") == 0 &&
1052                                          Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1053                                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK;
1054                                 else if (g_strcmp0(value, "wps") == 0)
1055                                         Wlan->security_info.wps_support = TRUE;
1056                                 else if (Wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1057                                         Wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1058                         }
1059                 } else if (g_strcmp0(key, "EncryptionMode") == 0) {
1060                         value = g_variant_get_string(var, NULL);
1061
1062                         if (g_strcmp0(value, "none") == 0)
1063                                 Wlan->security_info.enc_mode = WLAN_ENC_MODE_NONE;
1064                         else if (g_strcmp0(value, "wep") == 0)
1065                                 Wlan->security_info.enc_mode = WLAN_ENC_MODE_WEP;
1066                         else if (g_strcmp0(value, "tkip") == 0)
1067                                 Wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP;
1068                         else if (g_strcmp0(value, "aes") == 0)
1069                                 Wlan->security_info.enc_mode = WLAN_ENC_MODE_AES;
1070                         else if (g_strcmp0(value, "mixed") == 0)
1071                                 Wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP_AES_MIXED;
1072
1073                 } else if (g_strcmp0(key, "Passpoint") == 0) {
1074                         gboolean passpoint;
1075
1076                         passpoint = g_variant_get_boolean(var);
1077                         if (passpoint)
1078                                 Wlan->passpoint = TRUE;
1079                         else
1080                                 Wlan->passpoint = FALSE;
1081
1082                 } else if (g_strcmp0(key, "Strength") == 0) {
1083                         Wlan->Strength = g_variant_get_byte(var);
1084                 } else if (g_strcmp0(key, "Name") == 0) {
1085                         value = g_variant_get_string(var, NULL);
1086
1087                         if (value != NULL)
1088                                 g_strlcpy(Wlan->essid, value, NET_WLAN_ESSID_LEN);
1089                 } else if (g_strcmp0(key, "Passphrase") == 0) {
1090                         wlan_security_info_t *security_info = &(Wlan->security_info);
1091                         value = g_variant_get_string(var, NULL);
1092
1093                         if (security_info->sec_mode == WLAN_SEC_MODE_WEP && value != NULL)
1094                                 g_strlcpy(security_info->authentication.wep.wepKey,
1095                                                 value, NETPM_WLAN_MAX_WEP_KEY_LEN+1);
1096                         else if ((security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
1097                                     security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) &&
1098                                     value != NULL)
1099                                 g_strlcpy(security_info->authentication.psk.pskKey,
1100                                                 value, NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN+1);
1101
1102                 } else if (g_strcmp0(key, "PassphraseRequired") == 0) {
1103                         gboolean val;
1104
1105                         val = g_variant_get_boolean(var);
1106
1107                         if(val)
1108                                 Wlan->PassphraseRequired = TRUE;
1109                         else
1110                                 Wlan->PassphraseRequired = FALSE;
1111                 } else if (g_strcmp0(key, "BSSID") == 0) {
1112                         value = g_variant_get_string(var, NULL);
1113
1114                         if (value != NULL)
1115                                 g_strlcpy(Wlan->bssid, value, NET_MAX_MAC_ADDR_LEN);
1116
1117                 } else if (g_strcmp0(key, "MaxRate") == 0) {
1118                         Wlan->max_rate = g_variant_get_uint32(var);
1119
1120                 } else if (g_strcmp0(key, "Frequency") == 0) {
1121                         unsigned short frequency;
1122                         frequency = g_variant_get_uint16(var);
1123
1124                         Wlan->frequency = (unsigned int)frequency;
1125
1126                 } else if (g_str_equal(key, "EAP") == TRUE) {
1127                         value = g_variant_get_string(var, NULL);
1128
1129                         if (value != NULL)
1130                                 Wlan->security_info.authentication.eap.eap_type =
1131                                                 __convert_eap_type_from_string(value);
1132
1133                 } else if (g_str_equal(key, "Phase2") == TRUE) {
1134                         value = g_variant_get_string(var, NULL);
1135
1136                         if (value != NULL)
1137                                 Wlan->security_info.authentication.eap.eap_auth =
1138                                                 __convert_eap_auth_from_string(value);
1139
1140                 } else if (g_str_equal(key, "Identity") == TRUE) {
1141                         value = g_variant_get_string(var, NULL);
1142
1143                         if (value != NULL)
1144                                 g_strlcpy(Wlan->security_info.authentication.eap.username,
1145                                                 value, NETPM_WLAN_USERNAME_LEN+1);
1146
1147                 } else if (g_str_equal(key, "Password") == TRUE) {
1148                         value = g_variant_get_string(var, NULL);
1149
1150                         if (value != NULL)
1151                                 g_strlcpy(Wlan->security_info.authentication.eap.password,
1152                                                 value, NETPM_WLAN_PASSWORD_LEN+1);
1153
1154                 } else if (g_str_equal(key, "CACertFile") == TRUE) {
1155                         value = g_variant_get_string(var, NULL);
1156
1157                         if (value != NULL)
1158                                 g_strlcpy(Wlan->security_info.authentication.eap.ca_cert_filename,
1159                                                 value, NETPM_WLAN_CA_CERT_FILENAME_LEN+1);
1160
1161                 } else if (g_str_equal(key, "ClientCertFile") == TRUE) {
1162                         value = g_variant_get_string(var, NULL);
1163
1164                         if (value != NULL)
1165                                 g_strlcpy(Wlan->security_info.authentication.eap.client_cert_filename,
1166                                                 value, NETPM_WLAN_CLIENT_CERT_FILENAME_LEN+1);
1167
1168                 } else if (g_str_equal(key, "PrivateKeyFile") == TRUE) {
1169                         value = g_variant_get_string(var, NULL);
1170
1171                         if (value != NULL)
1172                                 g_strlcpy(Wlan->security_info.authentication.eap.private_key_filename,
1173                                                 value, NETPM_WLAN_PRIVATE_KEY_FILENAME_LEN+1);
1174
1175                 } else if (g_str_equal(key, "PrivateKeyPassphrase") == TRUE) {
1176                         value = g_variant_get_string(var, NULL);
1177
1178                         if (value != NULL)
1179                                 g_strlcpy(Wlan->security_info.authentication.eap.private_key_passwd,
1180                                                 value, NETPM_WLAN_PRIVATE_KEY_PASSWD_LEN+1);
1181                 } else
1182                         Error = __net_extract_common_info(key, var, ProfInfo);
1183         }
1184
1185         __NETWORK_FUNC_EXIT__;
1186         return Error;
1187 }
1188
1189 static int __net_extract_mobile_info(GVariantIter *array, net_profile_info_t *ProfInfo)
1190 {
1191         net_err_t Error = NET_ERR_NONE;
1192         GVariant *var = NULL;
1193         const gchar *key = NULL;
1194
1195         __NETWORK_FUNC_ENTER__;
1196
1197         while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
1198                 const gchar *value = NULL;
1199
1200                 if (g_strcmp0(key, "Mode") == 0) {
1201                         value = g_variant_get_string(var, NULL);
1202
1203                         if (g_strcmp0(value, "gprs") == 0)
1204                                 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_GPRS;
1205                         else if (g_strcmp0(value, "edge") == 0)
1206                                 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_EDGE;
1207                         else if (g_strcmp0(value, "umts") == 0)
1208                                 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_UMTS;
1209                         else
1210                                 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_NONE;
1211                 } else if (g_strcmp0(key, "Roaming") == 0) {
1212                         gboolean val;
1213
1214                         val = g_variant_get_boolean(var);
1215                         if (val)
1216                                 ProfInfo->ProfileInfo.Pdp.Roaming = TRUE;
1217                         else
1218                                 ProfInfo->ProfileInfo.Pdp.Roaming = FALSE;
1219                 } else if (g_strcmp0(key, "SetupRequired") == 0) {
1220                         gboolean val;
1221
1222                         val = g_variant_get_boolean(var);
1223                         if (val)
1224                                 ProfInfo->ProfileInfo.Pdp.SetupRequired = TRUE;
1225                         else
1226                                 ProfInfo->ProfileInfo.Pdp.SetupRequired = FALSE;
1227                 } else
1228                         Error = __net_extract_common_info(key, var, ProfInfo);
1229         }
1230
1231         /* Get Specific info from telephony service */
1232         net_telephony_profile_info_t telephony_profinfo;
1233         net_profile_name_t PdpProfName;
1234
1235         PdpProfName.ProfileName[0] = '\0';
1236
1237         __net_telephony_init_profile_info(&telephony_profinfo);
1238
1239         /* Find matching profile in telephony service */
1240         Error = __net_telephony_search_pdp_profile(ProfInfo->ProfileName, &PdpProfName);
1241
1242         if (Error == NET_ERR_NONE && strlen(PdpProfName.ProfileName) > 0) {
1243                 /* Get profile info from telephony service */
1244                 Error = __net_telephony_get_profile_info(&PdpProfName, &telephony_profinfo);
1245
1246                 if (Error == NET_ERR_NONE) {
1247                         ProfInfo->ProfileInfo.Pdp.ServiceType = telephony_profinfo.ServiceType;
1248
1249                         if (strlen(telephony_profinfo.Apn) > 0)
1250                                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.Apn,
1251                                                 telephony_profinfo.Apn, NET_PDP_APN_LEN_MAX);
1252
1253                         if (strlen(telephony_profinfo.ProxyAddr) > 0)
1254                                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.net_info.ProxyAddr,
1255                                                 telephony_profinfo.ProxyAddr, NET_PROXY_LEN_MAX);
1256
1257                         if (strlen(telephony_profinfo.HomeURL) > 0)
1258                                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.HomeURL,
1259                                                 telephony_profinfo.HomeURL, NET_HOME_URL_LEN_MAX);
1260
1261                         ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType = telephony_profinfo.AuthInfo.AuthType;
1262
1263                         if (strlen(telephony_profinfo.AuthInfo.UserName) > 0)
1264                                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.AuthInfo.UserName,
1265                                                 telephony_profinfo.AuthInfo.UserName,
1266                                                 NET_PDP_AUTH_USERNAME_LEN_MAX);
1267
1268                         if (strlen(telephony_profinfo.AuthInfo.Password) > 0)
1269                                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.AuthInfo.Password,
1270                                                 telephony_profinfo.AuthInfo.Password,
1271                                                 NET_PDP_AUTH_PASSWORD_LEN_MAX);
1272
1273                         if (strlen(telephony_profinfo.Keyword) > 0)
1274                                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.Keyword,
1275                                                 telephony_profinfo.Keyword,
1276                                                 NET_PDP_APN_LEN_MAX);
1277
1278                         ProfInfo->ProfileInfo.Pdp.Hidden = telephony_profinfo.Hidden;
1279                         ProfInfo->ProfileInfo.Pdp.Editable = telephony_profinfo.Editable;
1280                         ProfInfo->ProfileInfo.Pdp.DefaultConn = telephony_profinfo.DefaultConn;
1281                 }
1282         }
1283
1284         __NETWORK_FUNC_EXIT__;
1285         return Error;
1286 }
1287
1288 static int __net_extract_ethernet_info(GVariantIter *array, net_profile_info_t* ProfInfo)
1289 {
1290         net_err_t Error = NET_ERR_NONE;
1291         GVariant *var = NULL;
1292         const gchar *key = NULL;
1293
1294         __NETWORK_FUNC_ENTER__;
1295
1296         while (g_variant_iter_loop(array, "{sv}", &key, &var))
1297                 Error = __net_extract_common_info(key, var, ProfInfo);
1298
1299         __NETWORK_FUNC_EXIT__;
1300         return Error;
1301 }
1302
1303 static int __net_extract_bluetooth_info(GVariantIter *array, net_profile_info_t* ProfInfo)
1304 {
1305         net_err_t Error = NET_ERR_NONE;
1306         GVariant *var = NULL;
1307         const gchar *key = NULL;
1308
1309         __NETWORK_FUNC_ENTER__;
1310
1311         while (g_variant_iter_loop(array, "{sv}", &key, &var))
1312                 Error = __net_extract_common_info(key, var, ProfInfo);
1313
1314         __NETWORK_FUNC_EXIT__;
1315         return Error;
1316 }
1317
1318 static int __net_extract_service_info(
1319                 const char* ProfileName, GVariant *message,
1320                 net_profile_info_t* ProfInfo)
1321 {
1322         __NETWORK_FUNC_ENTER__;
1323
1324         net_err_t Error = NET_ERR_NONE;
1325         net_device_t profileType = NET_DEVICE_UNKNOWN;
1326         gchar *key = NULL;
1327         GVariantIter *iter = NULL;
1328         GVariant *value = NULL;
1329
1330         g_variant_get(message, "(a{sv})", &iter);
1331         while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
1332                 const gchar *tech = NULL;
1333
1334                 if (g_strcmp0(key, "Type") == 0) {
1335                         tech = g_variant_get_string(value, NULL);
1336
1337                         if (g_strcmp0(tech, "wifi") == 0)
1338                                 profileType = NET_DEVICE_WIFI;
1339                         else if (g_strcmp0(tech, "cellular") == 0)
1340                                 profileType = NET_DEVICE_CELLULAR;
1341                         else if (g_strcmp0(tech, "ethernet") == 0)
1342                                 profileType = NET_DEVICE_ETHERNET;
1343                         else if (g_strcmp0(tech, "bluetooth") == 0)
1344                                 profileType = NET_DEVICE_BLUETOOTH;
1345
1346                         g_variant_unref(value);
1347                         g_free(key);
1348                         break;
1349                 }
1350         }
1351         g_variant_iter_free(iter);
1352
1353         g_variant_get(message, "(a{sv})", &iter);
1354
1355         if (profileType == NET_DEVICE_WIFI) {
1356                 if ((Error = __net_pm_init_profile_info(NET_DEVICE_WIFI, ProfInfo)) != NET_ERR_NONE) {
1357                         NETWORK_LOG(NETWORK_ERROR, "Failed to init profile\n");
1358                         __NETWORK_FUNC_EXIT__;
1359                         return Error;
1360                 }
1361
1362                 ProfInfo->profile_type = NET_DEVICE_WIFI;
1363                 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1364                 g_strlcpy(ProfInfo->ProfileInfo.Wlan.net_info.ProfileName,
1365                                 ProfileName, NET_PROFILE_NAME_LEN_MAX);
1366
1367                 Error = __net_extract_wifi_info(iter, ProfInfo);
1368         } else if (profileType == NET_DEVICE_CELLULAR) {
1369                 if ((Error = __net_pm_init_profile_info(NET_DEVICE_CELLULAR, ProfInfo)) != NET_ERR_NONE) {
1370                         NETWORK_LOG(NETWORK_ERROR, "Failed to init profile\n");
1371                         __NETWORK_FUNC_EXIT__;
1372                         return Error;
1373                 }
1374
1375                 ProfInfo->profile_type = NET_DEVICE_CELLULAR;
1376                 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1377                 g_strlcpy(ProfInfo->ProfileInfo.Pdp.net_info.ProfileName,
1378                                 ProfileName, NET_PROFILE_NAME_LEN_MAX);
1379
1380                 Error = __net_extract_mobile_info(iter, ProfInfo);
1381         } else if (profileType == NET_DEVICE_ETHERNET) {
1382                 if ((Error = __net_pm_init_profile_info(NET_DEVICE_ETHERNET, ProfInfo)) != NET_ERR_NONE) {
1383                         NETWORK_LOG(NETWORK_ERROR, "Failed to init profile\n");
1384                         __NETWORK_FUNC_EXIT__;
1385                         return Error;
1386                 }
1387
1388                 ProfInfo->profile_type = NET_DEVICE_ETHERNET;
1389                 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1390                 g_strlcpy(ProfInfo->ProfileInfo.Ethernet.net_info.ProfileName,
1391                                 ProfileName, NET_PROFILE_NAME_LEN_MAX);
1392
1393                 Error = __net_extract_ethernet_info(iter, ProfInfo);
1394         } else if (profileType == NET_DEVICE_BLUETOOTH) {
1395                 if ((Error = __net_pm_init_profile_info(NET_DEVICE_BLUETOOTH, ProfInfo)) != NET_ERR_NONE) {
1396                         NETWORK_LOG(NETWORK_ERROR, "Failed to init profile\n");
1397                         __NETWORK_FUNC_EXIT__;
1398                         return Error;
1399                 }
1400
1401                 ProfInfo->profile_type = NET_DEVICE_BLUETOOTH;
1402                 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1403                 g_strlcpy(ProfInfo->ProfileInfo.Bluetooth.net_info.ProfileName,
1404                                 ProfileName, NET_PROFILE_NAME_LEN_MAX);
1405
1406                 Error = __net_extract_bluetooth_info(iter, ProfInfo);
1407         } else {
1408                 NETWORK_LOG(NETWORK_ERROR, "Not supported profile type\n");
1409                 __NETWORK_FUNC_EXIT__;
1410                 return NET_ERR_NOT_SUPPORTED;
1411         }
1412
1413         if (Error != NET_ERR_NONE) {
1414                 NETWORK_LOG(NETWORK_ERROR,
1415                                 "Failed to extract service information from received message\n");
1416
1417                 __NETWORK_FUNC_EXIT__;
1418                 return Error;
1419         }
1420
1421         g_variant_iter_free(iter);
1422
1423         __NETWORK_FUNC_EXIT__;
1424         return Error;
1425 }
1426
1427 static int __net_get_profile_info(
1428                 const char* ProfileName, net_profile_info_t* ProfInfo)
1429 {
1430         __NETWORK_FUNC_ENTER__;
1431
1432         net_err_t Error = NET_ERR_NONE;
1433         GVariant *message = NULL;
1434
1435         message = _net_invoke_dbus_method(CONNMAN_SERVICE, ProfileName,
1436                         CONNMAN_SERVICE_INTERFACE, "GetProperties", NULL, &Error);
1437         if (message == NULL) {
1438                 NETWORK_LOG(NETWORK_ERROR, "Failed to get profile\n");
1439                 goto done;
1440         }
1441
1442         Error = __net_extract_service_info(ProfileName, message, ProfInfo);
1443         g_variant_unref(message);
1444
1445 done:
1446         __NETWORK_FUNC_EXIT__;
1447         return Error;
1448 }
1449
1450 static int __net_set_default_cellular_service_profile_sync(const char* ProfileName)
1451 {
1452         __NETWORK_FUNC_ENTER__;
1453
1454         net_err_t Error = NET_ERR_NONE;
1455         GVariant *message = NULL;
1456         net_profile_name_t telephony_profile;
1457         char connman_profile[NET_PROFILE_NAME_LEN_MAX+1] = "";
1458
1459         g_strlcpy(connman_profile, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
1460
1461         Error = __net_telephony_search_pdp_profile((char*)connman_profile, &telephony_profile);
1462         if (Error != NET_ERR_NONE) {
1463                 NETWORK_LOG(NETWORK_HIGH, "__net_telephony_search_pdp_profile() failed\n");
1464                 __NETWORK_FUNC_EXIT__;
1465                 return Error;
1466         }
1467
1468         message = _net_invoke_dbus_method(TELEPHONY_SERVICE, telephony_profile.ProfileName,
1469                         TELEPHONY_PROFILE_INTERFACE, "SetDefaultConnection", NULL, &Error);
1470
1471         if (message == NULL) {
1472                 NETWORK_LOG(NETWORK_ERROR, "Failed to set default cellular service(profile)\n");
1473                 goto done;
1474         }
1475
1476         /** Check Reply */
1477         gboolean result = FALSE;
1478
1479         g_variant_get(message, "(b)", &result);
1480         NETWORK_LOG(NETWORK_HIGH, "Set default cellular profile result : %d\n", result);
1481
1482         if (result)
1483                 Error = NET_ERR_NONE;
1484         else
1485                 Error = NET_ERR_UNKNOWN;
1486
1487         g_variant_unref(message);
1488
1489 done:
1490         __NETWORK_FUNC_EXIT__;
1491
1492         return Error;
1493 }
1494
1495 static int __net_set_default_cellular_service_profile_async(const char* ProfileName)
1496 {
1497         __NETWORK_FUNC_ENTER__;
1498
1499         net_err_t Error = NET_ERR_NONE;
1500         net_profile_name_t telephony_profile;
1501         char connman_profile[NET_PROFILE_NAME_LEN_MAX+1] = {0,};
1502
1503         g_strlcpy(connman_profile, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
1504
1505         Error = __net_telephony_search_pdp_profile((char*)connman_profile, &telephony_profile);
1506         if (Error != NET_ERR_NONE) {
1507                 NETWORK_LOG(NETWORK_HIGH, "__net_telephony_search_pdp_profile() failed\n");
1508                 __NETWORK_FUNC_EXIT__;
1509                 return Error;
1510         }
1511
1512         Error = _net_dbus_set_default(telephony_profile.ProfileName);
1513
1514         __NETWORK_FUNC_EXIT__;
1515         return Error;
1516 }
1517
1518 static int __net_modify_wlan_profile_info(const char* ProfileName,
1519                 net_profile_info_t* ProfInfo, net_profile_info_t* exProfInfo)
1520 {
1521         __NETWORK_FUNC_ENTER__;
1522
1523         net_err_t Error = NET_ERR_NONE;
1524         int i = 0;
1525         char profilePath[NET_PROFILE_NAME_LEN_MAX+1] = "";
1526
1527         wlan_security_info_t *security_info = &(ProfInfo->ProfileInfo.Wlan.security_info);
1528         wlan_security_info_t *ex_security_info = &(exProfInfo->ProfileInfo.Wlan.security_info);
1529
1530         net_dev_info_t *net_info = &(ProfInfo->ProfileInfo.Wlan.net_info);
1531         net_dev_info_t *ex_net_info = &(exProfInfo->ProfileInfo.Wlan.net_info);
1532
1533         g_strlcpy(profilePath, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
1534
1535         /* Compare and Set 'Passphrase' */
1536         if (ex_security_info->sec_mode == WLAN_SEC_MODE_WEP) {
1537                 if (g_strcmp0(security_info->authentication.wep.wepKey,
1538                                                 ex_security_info->authentication.wep.wepKey) != 0) {
1539                         Error = _net_dbus_set_agent_passphrase(security_info->authentication.wep.wepKey);
1540
1541                         if (NET_ERR_NONE != Error) {
1542                                 NETWORK_LOG(NETWORK_ERROR, "Failed to set agent field\n");
1543
1544                                 __NETWORK_FUNC_EXIT__;
1545                                 return Error;
1546                         }
1547                 }
1548         } else if (ex_security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
1549                         ex_security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) {
1550                 if (g_strcmp0(security_info->authentication.psk.pskKey,
1551                                                 ex_security_info->authentication.psk.pskKey) != 0) {
1552                         Error = _net_dbus_set_agent_passphrase(security_info->authentication.psk.pskKey);
1553
1554                         if (NET_ERR_NONE != Error) {
1555                                 NETWORK_LOG(NETWORK_ERROR, "Failed to set agent field\n");
1556
1557                                 __NETWORK_FUNC_EXIT__;
1558                                 return Error;
1559                         }
1560                 }
1561         }
1562
1563         /* Compare and Set 'Proxy' */
1564         if ((ex_net_info->ProxyMethod != net_info->ProxyMethod) ||
1565             (g_strcmp0(ex_net_info->ProxyAddr, net_info->ProxyAddr) != 0)) {
1566
1567                 Error = _net_dbus_set_proxy(ProfInfo, profilePath);
1568
1569                 if (Error != NET_ERR_NONE) {
1570                         __NETWORK_FUNC_EXIT__;
1571                         return Error;
1572                 }
1573         }
1574
1575         /* Compare and Set 'IPv4 addresses' */
1576         if ((ex_net_info->IpConfigType != net_info->IpConfigType) ||
1577             (net_info->IpConfigType == NET_IP_CONFIG_TYPE_STATIC &&
1578              (net_info->IpAddr.Data.Ipv4.s_addr !=
1579                                                                 ex_net_info->IpAddr.Data.Ipv4.s_addr ||
1580               net_info->SubnetMask.Data.Ipv4.s_addr !=
1581                                                                 ex_net_info->SubnetMask.Data.Ipv4.s_addr ||
1582               net_info->GatewayAddr.Data.Ipv4.s_addr !=
1583                                                                 ex_net_info->GatewayAddr.Data.Ipv4.s_addr))) {
1584                 Error = _net_dbus_set_profile_ipv4(ProfInfo, profilePath);
1585
1586                 if (Error != NET_ERR_NONE) {
1587                         NETWORK_LOG(NETWORK_ERROR, "Failed to set IPv4\n");
1588
1589                         __NETWORK_FUNC_EXIT__;
1590                         return Error;
1591                 }
1592         }
1593
1594         /* Compare and Set 'DNS addresses' */
1595         for (i = 0; i < net_info->DnsCount; i++) {
1596                 if (i >= NET_DNS_ADDR_MAX) {
1597                         net_info->DnsCount = NET_DNS_ADDR_MAX;
1598
1599                         break;
1600                 }
1601
1602                 if (net_info->DnsAddr[i].Data.Ipv4.s_addr !=
1603                                 ex_net_info->DnsAddr[i].Data.Ipv4.s_addr)
1604                         break;
1605         }
1606
1607         if (i < net_info->DnsCount) {
1608                 Error = _net_dbus_set_profile_dns(ProfInfo, profilePath);
1609
1610                 if (Error != NET_ERR_NONE) {
1611                         NETWORK_LOG(NETWORK_ERROR, "Failed to set DNS\n");
1612
1613                         __NETWORK_FUNC_EXIT__;
1614                         return Error;
1615                 }
1616         }
1617
1618         __NETWORK_FUNC_EXIT__;
1619         return NET_ERR_NONE;
1620 }
1621
1622 static int __net_wifi_delete_profile(net_profile_name_t* WifiProfName,
1623                 wlan_security_mode_type_t sec_mode)
1624 {
1625         __NETWORK_FUNC_ENTER__;
1626
1627         net_err_t Error = NET_ERR_NONE;
1628         GVariant *message = NULL;
1629         char param0[NET_PROFILE_NAME_LEN_MAX + 8] = "";
1630         GVariant *params = NULL;
1631
1632         if (WLAN_SEC_MODE_IEEE8021X != sec_mode) {
1633                 message = _net_invoke_dbus_method(CONNMAN_SERVICE,
1634                                 WifiProfName->ProfileName,
1635                                 CONNMAN_SERVICE_INTERFACE, "Remove", NULL,
1636                                 &Error);
1637         } else {
1638                 g_snprintf(param0, NET_PROFILE_NAME_LEN_MAX + 8, "string:%s",
1639                                 WifiProfName->ProfileName);
1640                 params = g_variant_new("(s)", param0);
1641
1642                 message = _net_invoke_dbus_method(NETCONFIG_SERVICE,
1643                                 NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE,
1644                                 "DeleteConfig", params, &Error);
1645         }
1646
1647         if (message == NULL) {
1648                 NETWORK_LOG(NETWORK_ERROR, "Failed to Remove service(profile)\n");
1649                 goto done;
1650         }
1651
1652         g_variant_unref(message);
1653 done:
1654         __NETWORK_FUNC_EXIT__;
1655         return Error;
1656 }
1657
1658 static int __net_telephony_add_profile(net_profile_info_t *ProfInfo, net_service_type_t network_type)
1659 {
1660         __NETWORK_FUNC_ENTER__;
1661
1662         net_err_t Error = NET_ERR_NONE;
1663
1664         ProfInfo->ProfileInfo.Pdp.ServiceType = network_type;
1665
1666         Error = _net_dbus_add_pdp_profile(ProfInfo);
1667         if (Error != NET_ERR_NONE) {
1668                 NETWORK_LOG(NETWORK_HIGH, "_net_dbus_add_pdp_profile() failed\n");
1669                 __NETWORK_FUNC_EXIT__;
1670                 return Error;
1671         }
1672
1673         __NETWORK_FUNC_EXIT__;
1674         return NET_ERR_NONE;
1675 }
1676
1677 static int __net_telephony_modify_profile(const char *ProfileName,
1678                 net_profile_info_t *ProfInfo, net_profile_info_t* exProfInfo)
1679 {
1680         __NETWORK_FUNC_ENTER__;
1681
1682         net_err_t Error = NET_ERR_NONE;
1683         net_profile_name_t telephony_profile;
1684         char connman_profile[NET_PROFILE_NAME_LEN_MAX+1] = "";
1685
1686         if (_net_is_valid_service_type(exProfInfo->ProfileInfo.Pdp.ServiceType) == FALSE) {
1687                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
1688                 __NETWORK_FUNC_EXIT__;
1689                 return NET_ERR_INVALID_PARAM;
1690         }
1691
1692         g_strlcpy(connman_profile, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
1693         ProfInfo->ProfileInfo.Pdp.ServiceType = exProfInfo->ProfileInfo.Pdp.ServiceType;
1694
1695         Error = __net_telephony_search_pdp_profile((char*)connman_profile, &telephony_profile);
1696         if (Error != NET_ERR_NONE) {
1697                 NETWORK_LOG(NETWORK_HIGH, "__net_telephony_search_pdp_profile() failed\n");
1698                 __NETWORK_FUNC_EXIT__;
1699                 return Error;
1700         }
1701
1702         Error = _net_dbus_modify_pdp_profile(ProfInfo, (char*)telephony_profile.ProfileName);
1703         if (Error != NET_ERR_NONE) {
1704                 NETWORK_LOG(NETWORK_HIGH, "_net_dbus_modify_pdp_profile() failed\n");
1705                 __NETWORK_FUNC_EXIT__;
1706                 return Error;
1707         }
1708
1709         __NETWORK_FUNC_EXIT__;
1710
1711         return Error;
1712 }
1713
1714 static int __net_telephony_delete_profile(net_profile_name_t* PdpProfName)
1715 {
1716         __NETWORK_FUNC_ENTER__;
1717
1718         net_err_t Error = NET_ERR_NONE;
1719         GVariant *message = NULL;
1720
1721         message = _net_invoke_dbus_method(TELEPHONY_SERVICE, PdpProfName->ProfileName,
1722                         TELEPHONY_PROFILE_INTERFACE, "RemoveProfile", NULL, &Error);
1723
1724         if (message == NULL) {
1725                 NETWORK_LOG(NETWORK_ERROR, "Failed to Remove service(profile)\n");
1726                 goto done;
1727         }
1728
1729         /** Check Reply */
1730         gboolean remove_result = FALSE;
1731
1732         g_variant_get(message, "(b)", &remove_result);
1733         NETWORK_LOG(NETWORK_HIGH, "Profile remove result : %d\n", remove_result);
1734
1735         if (remove_result)
1736                 Error = NET_ERR_NONE;
1737         else
1738                 Error = NET_ERR_UNKNOWN;
1739
1740         g_variant_unref(message);
1741
1742 done:
1743         __NETWORK_FUNC_EXIT__;
1744         return Error;
1745 }
1746
1747 static gboolean __net_is_cellular_default_candidate(const char* profile)
1748 {
1749         /* This profile should be cellular type */
1750         const char net_suffix[] = "_1";
1751         const char pre_net_suffix[] = "_3";
1752         const char tethering_suffix[] = "_5";
1753         char *suffix;
1754
1755         suffix = strrchr(profile, '_');
1756
1757         if (g_strcmp0(suffix, net_suffix) == 0 ||
1758                         g_strcmp0(suffix, pre_net_suffix) == 0 ||
1759                         g_strcmp0(suffix, tethering_suffix) == 0)
1760                 return TRUE;
1761
1762         return FALSE;
1763 }
1764
1765 static int __net_extract_default_profile(
1766                 GVariantIter *array, net_profile_info_t *ProfilePtr)
1767 {
1768         net_err_t Error = NET_ERR_NONE;
1769         net_device_t device_type;
1770         gchar *key = NULL;
1771         GVariantIter *value = NULL;
1772
1773         __NETWORK_FUNC_ENTER__;
1774
1775         if (array == NULL || ProfilePtr == NULL) {
1776                 NETWORK_LOG(NETWORK_ERROR, "Invalid parameter\n");
1777                 __NETWORK_FUNC_EXIT__;
1778                 return NET_ERR_INVALID_PARAM;
1779         }
1780
1781         while (g_variant_iter_loop(array, "(oa{sv})", &key, &value)) {
1782                 if (g_str_has_prefix(key, CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX) == TRUE)
1783                         device_type = NET_DEVICE_CELLULAR;
1784                 else if (g_str_has_prefix(key, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) == TRUE)
1785                         device_type = NET_DEVICE_WIFI;
1786                 else if (g_str_has_prefix(key, CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX) == TRUE)
1787                         device_type = NET_DEVICE_ETHERNET;
1788                 else if (g_str_has_prefix(key, CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX) == TRUE)
1789                         device_type = NET_DEVICE_BLUETOOTH;
1790                 else {
1791                         g_variant_iter_free(value);
1792                         g_free(key);
1793                         __NETWORK_FUNC_EXIT__;
1794                         return NET_ERR_NO_SERVICE;
1795                 }
1796
1797                 Error = __net_pm_init_profile_info(device_type, ProfilePtr);
1798                 if (Error != NET_ERR_NONE) {
1799                         NETWORK_LOG(NETWORK_ERROR, "Failed to init profile\n");
1800                         g_variant_iter_free(value);
1801                         g_free(key);
1802                         __NETWORK_FUNC_EXIT__;
1803                         return Error;
1804                 }
1805
1806                 ProfilePtr->profile_type = device_type;
1807                 g_strlcpy(ProfilePtr->ProfileName, key, NET_PROFILE_NAME_LEN_MAX);
1808
1809                 if (device_type == NET_DEVICE_CELLULAR &&
1810                                 __net_is_cellular_default_candidate(key) == TRUE) {
1811                         g_strlcpy(ProfilePtr->ProfileInfo.Pdp.net_info.ProfileName,
1812                                         key, NET_PROFILE_NAME_LEN_MAX);
1813
1814                         Error = __net_extract_mobile_info(value, ProfilePtr);
1815
1816                         break;
1817                 } else if (device_type == NET_DEVICE_WIFI) {
1818                         g_strlcpy(ProfilePtr->ProfileInfo.Wlan.net_info.ProfileName,
1819                                         key, NET_PROFILE_NAME_LEN_MAX);
1820
1821                         Error = __net_extract_wifi_info(value, ProfilePtr);
1822
1823                         break;
1824                 } else if (device_type == NET_DEVICE_ETHERNET) {
1825                         g_strlcpy(ProfilePtr->ProfileInfo.Ethernet.net_info.ProfileName,
1826                                         key, NET_PROFILE_NAME_LEN_MAX);
1827
1828                         Error = __net_extract_ethernet_info(value, ProfilePtr);
1829
1830                         break;
1831                 } else if (device_type == NET_DEVICE_BLUETOOTH) {
1832                         g_strlcpy(ProfilePtr->ProfileInfo.Bluetooth.net_info.ProfileName,
1833                                         key, NET_PROFILE_NAME_LEN_MAX);
1834
1835                         Error = __net_extract_bluetooth_info(value, ProfilePtr);
1836
1837                         break;
1838                 }
1839         }
1840
1841         if (Error == NET_ERR_NONE &&
1842                         (ProfilePtr->ProfileState == NET_STATE_TYPE_READY ||
1843                                         ProfilePtr->ProfileState == NET_STATE_TYPE_ONLINE))
1844                 goto found;
1845
1846         NETWORK_LOG(NETWORK_ERROR, "Fail to find default service\n");
1847         Error = NET_ERR_NO_SERVICE;
1848
1849         if (value)
1850                 g_variant_iter_free(value);
1851         if (key)
1852                 g_free(key);
1853
1854         __NETWORK_FUNC_EXIT__;
1855         return Error;
1856
1857 found:
1858         NETWORK_LOG(NETWORK_HIGH, "Default: %s\n", ProfilePtr->ProfileName);
1859
1860         if (value)
1861                 g_variant_iter_free(value);
1862         if (key)
1863                 g_free(key);
1864
1865         __NETWORK_FUNC_EXIT__;
1866         return Error;
1867 }
1868
1869 int _net_check_profile_name(const char* ProfileName)
1870 {
1871         __NETWORK_FUNC_ENTER__;
1872
1873         const char *profileHeader = CONNMAN_PATH"/service/";
1874         int i = 0;
1875         int stringLen = 0;
1876
1877         if (ProfileName == NULL || strlen(ProfileName) <= strlen(profileHeader)) {
1878                 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid\n");
1879                 __NETWORK_FUNC_EXIT__;
1880                 return NET_ERR_INVALID_PARAM;
1881         }
1882
1883         stringLen = strlen(ProfileName);
1884
1885         if (strncmp(profileHeader, ProfileName, strlen(profileHeader)) == 0) {
1886                 for (i = 0;i < stringLen;i++) {
1887                         if (isgraph(ProfileName[i]) == 0) {
1888                                 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid\n");
1889                                 __NETWORK_FUNC_EXIT__;
1890                                 return NET_ERR_INVALID_PARAM;
1891                         }
1892                 }
1893         } else {
1894                 NETWORK_LOG(NETWORK_ERROR, "Profile name is invalid\n");
1895                 __NETWORK_FUNC_EXIT__;
1896                 return NET_ERR_INVALID_PARAM;
1897         }
1898
1899         __NETWORK_FUNC_EXIT__;
1900         return NET_ERR_NONE;
1901 }
1902
1903 int _net_get_profile_list(net_device_t device_type,
1904                 net_profile_info_t** profile_info, int* profile_count)
1905 {
1906         __NETWORK_FUNC_ENTER__;
1907
1908         net_err_t Error = NET_ERR_NONE;
1909         GVariant *message = NULL;
1910         GVariantIter *iter = NULL;
1911
1912         message = _net_invoke_dbus_method(CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
1913                         CONNMAN_MANAGER_INTERFACE, "GetServices", NULL, &Error);
1914         if (message == NULL) {
1915                 NETWORK_LOG(NETWORK_ERROR, "Failed to get service(profile) list\n");
1916                 __NETWORK_FUNC_EXIT__;
1917                 return Error;
1918         }
1919
1920         switch (device_type) {
1921         case NET_DEVICE_CELLULAR:
1922         case NET_DEVICE_WIFI:
1923         case NET_DEVICE_ETHERNET:
1924         case NET_DEVICE_BLUETOOTH:
1925         case NET_DEVICE_MAX:
1926                 g_variant_get(message, "(a(oa{sv}))", &iter);
1927                 Error = __net_extract_services(iter, device_type, profile_info, profile_count);
1928
1929                 if (iter != NULL)
1930                         g_variant_iter_free(iter);
1931                 break;
1932
1933         default :
1934                 Error = NET_ERR_UNKNOWN;
1935                 break;
1936         }
1937
1938         NETWORK_LOG(NETWORK_HIGH, "Error = %d\n", Error);
1939         g_variant_unref(message);
1940
1941         __NETWORK_FUNC_EXIT__;
1942         return Error;
1943 }
1944
1945 int _net_get_service_profile(net_service_type_t service_type, net_profile_name_t *profile_name)
1946 {
1947         __NETWORK_FUNC_ENTER__;
1948
1949         net_err_t Error = NET_ERR_NONE;
1950         GVariant *message = NULL;
1951         GVariantIter *iter = NULL;
1952         network_services_list_t service_info = {0,};
1953         int i = 0;
1954
1955         message = _net_invoke_dbus_method(CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
1956                         CONNMAN_MANAGER_INTERFACE, "GetServices", NULL, &Error);
1957         if (message == NULL) {
1958                 NETWORK_LOG(NETWORK_ERROR, "Failed to get profile list\n");
1959
1960                 __NETWORK_FUNC_EXIT__;
1961                 return Error;
1962         }
1963
1964         g_variant_get(message, "(a(oa{sv}))", &iter);
1965         Error = __net_extract_mobile_services(iter, &service_info, service_type);
1966
1967         g_variant_iter_free(iter);
1968
1969         if (Error != NET_ERR_NONE)
1970                 goto done;
1971
1972         if (service_info.num_of_services > 0) {
1973                 memcpy(profile_name->ProfileName, service_info.ProfileName[0], NET_PROFILE_NAME_LEN_MAX);
1974                 (profile_name->ProfileName)[NET_PROFILE_NAME_LEN_MAX] = '\0';
1975         } else
1976                 Error = NET_ERR_NO_SERVICE;
1977
1978         for (i = 0; i < service_info.num_of_services; i++)
1979                 NET_MEMFREE(service_info.ProfileName[i]);
1980
1981 done:
1982         g_variant_unref(message);
1983
1984         __NETWORK_FUNC_EXIT__;
1985         return Error;
1986 }
1987
1988 int _net_get_default_profile_info(net_profile_info_t *profile_info)
1989 {
1990         net_err_t Error = NET_ERR_NONE;
1991         GVariant *message = NULL;
1992         GVariantIter *iter = NULL;
1993
1994         __NETWORK_FUNC_ENTER__;
1995
1996         message = _net_invoke_dbus_method(CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
1997                         CONNMAN_MANAGER_INTERFACE, "GetServices", NULL, &Error);
1998         if (message == NULL) {
1999                 NETWORK_LOG(NETWORK_ERROR, "Failed to get profile list\n");
2000                 __NETWORK_FUNC_EXIT__;
2001                 return NET_ERR_NO_SERVICE;
2002         }
2003
2004         g_variant_get(message, "(a(oa{sv}))", &iter);
2005         Error = __net_extract_default_profile(iter, profile_info);
2006
2007         g_variant_iter_free (iter);
2008         g_variant_unref(message);
2009
2010         __NETWORK_FUNC_EXIT__;
2011         return Error;
2012 }
2013
2014 /*****************************************************************************
2015  *      ConnMan Wi-Fi Client Interface Sync API Definition
2016  *****************************************************************************/
2017 EXPORT_API int net_add_profile(net_service_type_t network_type, net_profile_info_t *prof_info)
2018 {
2019         net_err_t Error = NET_ERR_NONE;
2020
2021         __NETWORK_FUNC_ENTER__;
2022
2023         if (NetworkInfo.ref_count < 1) {
2024                 NETWORK_LOG(NETWORK_ERROR, "Application is not registered\n");
2025                 __NETWORK_FUNC_EXIT__;
2026                 return NET_ERR_APP_NOT_REGISTERED;
2027         }
2028
2029         if (prof_info == NULL || _net_is_valid_service_type(network_type) == FALSE) {
2030                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
2031                 __NETWORK_FUNC_EXIT__;
2032                 return NET_ERR_INVALID_PARAM;
2033         }
2034
2035         Error = __net_telephony_add_profile(prof_info, network_type);
2036
2037         if (Error != NET_ERR_NONE) {
2038                 NETWORK_LOG(NETWORK_ERROR, "Failed to add service(profile). Error [%s]\n",
2039                                 _net_print_error(Error));
2040                 __NETWORK_FUNC_EXIT__;
2041                 return Error;
2042         }
2043
2044         __NETWORK_FUNC_EXIT__;
2045         return Error;
2046 }
2047
2048 EXPORT_API int net_delete_profile(const char* profile_name)
2049 {
2050         __NETWORK_FUNC_ENTER__;
2051
2052         net_err_t Error = NET_ERR_NONE;
2053         net_profile_name_t pdp_prof_name;
2054         net_profile_name_t wifi_prof_name;
2055         net_profile_info_t prof_info;
2056
2057         if (NetworkInfo.ref_count < 1) {
2058                 NETWORK_LOG(NETWORK_ERROR, "Application is not registered\n");
2059                 __NETWORK_FUNC_EXIT__;
2060                 return NET_ERR_APP_NOT_REGISTERED;
2061         }
2062
2063         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
2064                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
2065                 __NETWORK_FUNC_EXIT__;
2066                 return NET_ERR_INVALID_PARAM;
2067         }
2068
2069         Error = __net_get_profile_info(profile_name, &prof_info);
2070         if (Error != NET_ERR_NONE) {
2071                 NETWORK_LOG(NETWORK_ERROR,
2072                                 "Failed to get service(profile) information. Error [%s]\n",
2073                                 _net_print_error(Error));
2074
2075                 __NETWORK_FUNC_EXIT__;
2076                 return Error;
2077         }
2078
2079         g_strlcpy(wifi_prof_name.ProfileName, profile_name, NET_PROFILE_NAME_LEN_MAX + 1);
2080
2081         if (prof_info.profile_type == NET_DEVICE_WIFI) {
2082                 Error = __net_wifi_delete_profile(&wifi_prof_name,
2083                                 prof_info.ProfileInfo.Wlan.security_info.sec_mode);
2084                 if (Error != NET_ERR_NONE) {
2085                         NETWORK_LOG(NETWORK_ERROR,
2086                                         "Failed to delete service(profile). Error [%s]\n",
2087                                         _net_print_error(Error));
2088
2089                         __NETWORK_FUNC_EXIT__;
2090                         return Error;
2091                 }
2092         } else if (prof_info.profile_type == NET_DEVICE_CELLULAR) {
2093                 Error = __net_telephony_search_pdp_profile(wifi_prof_name.ProfileName, &pdp_prof_name);
2094                 if (Error != NET_ERR_NONE) {
2095                         NETWORK_LOG(NETWORK_ERROR,
2096                                         "Failed to get service(profile) information. Error [%s]\n",
2097                                         _net_print_error(Error));
2098
2099                         __NETWORK_FUNC_EXIT__;
2100                         return Error;
2101                 }
2102
2103                 Error = __net_telephony_delete_profile(&pdp_prof_name);
2104                 if (Error != NET_ERR_NONE) {
2105                         NETWORK_LOG(NETWORK_ERROR,
2106                                         "Failed to delete service(profile). Error [%s]\n",
2107                                         _net_print_error(Error));
2108
2109                         __NETWORK_FUNC_EXIT__;
2110                         return Error;
2111                 }
2112         } else {
2113                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
2114
2115                 __NETWORK_FUNC_EXIT__;
2116                 return NET_ERR_INVALID_PARAM;
2117         }
2118
2119         __NETWORK_FUNC_EXIT__;
2120         return NET_ERR_NONE;
2121 }
2122
2123 EXPORT_API int net_get_profile_info(const char *profile_name, net_profile_info_t *prof_info)
2124 {
2125         __NETWORK_FUNC_ENTER__;
2126
2127         net_err_t Error = NET_ERR_NONE;
2128
2129         if (NetworkInfo.ref_count < 1) {
2130                 NETWORK_LOG(NETWORK_ERROR, "Application is not registered\n");
2131                 __NETWORK_FUNC_EXIT__;
2132                 return NET_ERR_APP_NOT_REGISTERED;
2133         }
2134
2135         if (prof_info == NULL ||
2136                         _net_check_profile_name(profile_name) != NET_ERR_NONE) {
2137                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
2138
2139                 __NETWORK_FUNC_EXIT__;
2140                 return NET_ERR_INVALID_PARAM;
2141         }
2142
2143         Error = __net_get_profile_info(profile_name, prof_info);
2144         if (Error != NET_ERR_NONE)
2145                 NETWORK_LOG(NETWORK_ERROR,
2146                                 "Failed to get service(profile) information. Error [%s]\n",
2147                                 _net_print_error(Error));
2148
2149         __NETWORK_FUNC_EXIT__;
2150         return Error;
2151 }
2152
2153 EXPORT_API int net_modify_profile(const char* profile_name, net_profile_info_t* prof_info)
2154 {
2155         __NETWORK_FUNC_ENTER__;
2156
2157         net_err_t Error = NET_ERR_NONE;
2158         net_profile_info_t exProfInfo;
2159
2160         if (NetworkInfo.ref_count < 1) {
2161                 NETWORK_LOG(NETWORK_ERROR, "Application is not registered\n");
2162                 __NETWORK_FUNC_EXIT__;
2163                 return NET_ERR_APP_NOT_REGISTERED;
2164         }
2165
2166         Error = net_get_profile_info(profile_name, &exProfInfo);
2167         if (Error != NET_ERR_NONE) {
2168                 NETWORK_LOG(NETWORK_ERROR,
2169                                 "Failed to get service(profile) information. Error [%s]\n",
2170                                 _net_print_error(Error));
2171
2172                 __NETWORK_FUNC_EXIT__;
2173                 return Error;
2174         }
2175
2176         if (prof_info == NULL ||
2177             (exProfInfo.profile_type != NET_DEVICE_WIFI &&
2178              exProfInfo.profile_type != NET_DEVICE_CELLULAR)) {
2179                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
2180                 __NETWORK_FUNC_EXIT__;
2181                 return NET_ERR_INVALID_PARAM;
2182         }
2183
2184         if (exProfInfo.profile_type == NET_DEVICE_WIFI)
2185                 Error = __net_modify_wlan_profile_info(profile_name, prof_info, &exProfInfo);
2186         else if (exProfInfo.profile_type == NET_DEVICE_CELLULAR)
2187                 Error = __net_telephony_modify_profile(profile_name, prof_info, &exProfInfo);
2188
2189         if (Error != NET_ERR_NONE) {
2190                 NETWORK_LOG(NETWORK_ERROR,
2191                                 "Failed to modify service(profile) information. Error [%s]\n",
2192                                 _net_print_error(Error));
2193
2194                 __NETWORK_FUNC_EXIT__;
2195                 return Error;
2196         }
2197
2198         __NETWORK_FUNC_EXIT__;
2199         return NET_ERR_NONE;
2200 }
2201
2202 EXPORT_API int net_get_profile_list(net_device_t device_type, net_profile_info_t **profile_list, int *count)
2203 {
2204         __NETWORK_FUNC_ENTER__;
2205
2206         net_err_t Error = NET_ERR_NONE;
2207         int profile_count = 0;
2208         net_profile_info_t* profile_info = NULL;
2209
2210         if (count == NULL) {
2211                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
2212                 __NETWORK_FUNC_EXIT__;
2213                 return NET_ERR_INVALID_PARAM;
2214         }
2215
2216         if (NetworkInfo.ref_count < 1) {
2217                 NETWORK_LOG(NETWORK_ERROR, "Application is not registered\n");
2218                 __NETWORK_FUNC_EXIT__;
2219                 return NET_ERR_APP_NOT_REGISTERED;
2220         }
2221
2222         if (device_type != NET_DEVICE_CELLULAR &&
2223             device_type != NET_DEVICE_WIFI &&
2224             device_type != NET_DEVICE_ETHERNET &&
2225             device_type != NET_DEVICE_BLUETOOTH &&
2226             device_type != NET_DEVICE_MAX) {
2227                 NETWORK_LOG(NETWORK_ERROR, "Not Supported\n");
2228                 __NETWORK_FUNC_EXIT__;
2229                 return NET_ERR_NOT_SUPPORTED;
2230         }
2231
2232         Error = _net_get_profile_list(device_type, &profile_info, &profile_count);
2233
2234         if (Error != NET_ERR_NONE) {
2235                 NETWORK_LOG(NETWORK_ERROR,
2236                                 "Failed to get service(profile) list. Error [%s]\n",
2237                                 _net_print_error(Error));
2238
2239                 NET_MEMFREE(profile_info);
2240
2241                 __NETWORK_FUNC_EXIT__;
2242                 return Error;
2243         } else {
2244                 *count = profile_count;
2245                 *profile_list = profile_info;
2246         }
2247
2248         __NETWORK_FUNC_EXIT__;
2249         return NET_ERR_NONE;
2250 }
2251
2252 EXPORT_API int net_set_default_cellular_service_profile(const char *profile_name)
2253 {
2254         net_err_t Error = NET_ERR_NONE;
2255
2256         if (NetworkInfo.ref_count < 1) {
2257                 NETWORK_LOG(NETWORK_ERROR, "Application is not registered\n");
2258                 __NETWORK_FUNC_EXIT__;
2259                 return NET_ERR_APP_NOT_REGISTERED;
2260         }
2261
2262         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
2263                 NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
2264                 __NETWORK_FUNC_EXIT__;
2265                 return NET_ERR_INVALID_PARAM;
2266         }
2267
2268         Error = __net_set_default_cellular_service_profile_sync(profile_name);
2269         if (Error != NET_ERR_NONE) {
2270                 NETWORK_LOG(NETWORK_ERROR,
2271                                 "Failed to set default cellular service(profile). Error [%s]\n",
2272                                 _net_print_error(Error));
2273                 __NETWORK_FUNC_EXIT__;
2274                 return Error;
2275         }
2276
2277         return NET_ERR_NONE;
2278 }
2279
2280 EXPORT_API int net_set_default_cellular_service_profile_async(const char *profile_name)
2281 {
2282         net_err_t Error = NET_ERR_NONE;
2283
2284         if (NetworkInfo.ref_count < 1) {
2285                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application is not registered\n");
2286                 __NETWORK_FUNC_EXIT__;
2287                 return NET_ERR_APP_NOT_REGISTERED;
2288         }
2289
2290         if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
2291                 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Parameter\n");
2292                 __NETWORK_FUNC_EXIT__;
2293                 return NET_ERR_INVALID_PARAM;
2294         }
2295
2296         if (request_table[NETWORK_REQUEST_TYPE_SET_DEFAULT].flag == TRUE) {
2297                 NETWORK_LOG(NETWORK_ERROR, "Error!! Request already in progress\n");
2298                 __NETWORK_FUNC_EXIT__;
2299                 return NET_ERR_IN_PROGRESS;
2300         }
2301
2302         if (_net_dbus_is_pending_call_used() == TRUE) {
2303                 NETWORK_LOG(NETWORK_ERROR, "Error!! pending call already in progress\n");
2304                 __NETWORK_FUNC_EXIT__;
2305                 return NET_ERR_IN_PROGRESS;
2306         }
2307
2308         request_table[NETWORK_REQUEST_TYPE_SET_DEFAULT].flag = TRUE;
2309
2310         Error = __net_set_default_cellular_service_profile_async(profile_name);
2311         if (Error != NET_ERR_NONE) {
2312                 NETWORK_LOG(NETWORK_ERROR,
2313                         "Error!!! failed to set default cellular service(profile). Error [%s]\n",
2314                         _net_print_error(Error));
2315                 memset(&request_table[NETWORK_REQUEST_TYPE_SET_DEFAULT],
2316                                         0, sizeof(network_request_table_t));
2317                 __NETWORK_FUNC_EXIT__;
2318                 return Error;
2319         }
2320
2321         return NET_ERR_NONE;
2322 }