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