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