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