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