2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #endif /* __cplusplus */
24 /*****************************************************************************
26 *****************************************************************************/
35 /*****************************************************************************
37 *****************************************************************************/
39 #include "network-internal.h"
40 #include "network-dbus-request.h"
42 /*****************************************************************************
44 *****************************************************************************/
46 /*****************************************************************************
47 * Local Functions Declaration
48 *****************************************************************************/
49 static int __net_extract_wifi_info(DBusMessageIter *array, net_profile_info_t* ProfInfo);
50 static int __net_get_profile_info(const char* ProfileName, net_profile_info_t* ProfInfo);
51 static int __net_extract_service_info(const char* ProfileName,
52 DBusMessage *message, net_profile_info_t* ProfInfo);
53 static int __net_pm_init_profile_info(net_device_t profile_type, net_profile_info_t* ProfInfo);
54 static int __net_telephony_init_profile_info(net_telephony_profile_info_t* ProfInfo);
55 static int __net_telephony_get_profile_info(net_profile_name_t* ProfileName,
56 net_telephony_profile_info_t* ProfileInfo);
57 static int __net_telephony_get_profile_list(net_profile_name_t** ProfileName, int* ProfileCount);
58 static int __net_extract_wifi_services(DBusMessage* message,
59 DBusMessageIter* dict, network_services_list_t* service_info);
60 static int __net_extract_mobile_services(DBusMessage* message, DBusMessageIter* dict,
61 network_services_list_t* service_info, net_service_type_t network_type);
62 static int __net_extract_services(DBusMessage *message, net_device_t device_type,
63 net_profile_info_t** profile_info, int* profile_count);
64 static int __net_extract_ip(DBusMessageIter *iter, net_addr_t *ipAddr);
65 static int __net_extract_common_info(const char *key, DBusMessageIter *variant, net_profile_info_t* ProfInfo);
66 static int __net_extract_mobile_info(DBusMessageIter *array, net_profile_info_t* ProfInfo);
67 static int __net_telephony_search_pdp_profile(char* ProfileName, net_profile_name_t* PdpProfName);
68 static int __net_telephony_modify_profile(const char* ProfileName,
69 net_profile_info_t* ProfInfo, net_profile_info_t* exProfInfo);
70 static int __net_modify_wlan_profile_info(const char* ProfileName,
71 net_profile_info_t* ProfInfo, net_profile_info_t* exProfInfo);
72 static int __net_telephony_delete_profile(net_profile_name_t* PdpProfName);
73 static int __net_wifi_delete_profile(net_profile_name_t* WifiProfName);
74 static int __net_telephony_add_profile(net_profile_info_t *ProfInfo, net_service_type_t network_type);
75 static int __net_extract_defult_profile(DBusMessageIter* iter, net_profile_name_t *profile_name);
76 static int __net_set_profile_property(char* path, char* key, char* value);
78 /*****************************************************************************
80 *****************************************************************************/
82 /*****************************************************************************
84 *****************************************************************************/
86 extern network_info_t NetworkInfo;
88 /*****************************************************************************
90 *****************************************************************************/
92 /*****************************************************************************
93 * Local Functions Definition
94 *****************************************************************************/
96 static int __net_pm_init_profile_info(net_device_t profile_type, net_profile_info_t* ProfInfo)
98 __NETWORK_FUNC_ENTER__;
101 net_dev_info_t* net_info = NULL;
103 if (ProfInfo == NULL ||
104 (profile_type != NET_DEVICE_WIFI && profile_type != NET_DEVICE_CELLULAR)) {
105 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Parameter\n");
106 return NET_ERR_INVALID_PARAM;
109 memset(ProfInfo->ProfileName, '\0', NET_PROFILE_NAME_LEN_MAX+1);
110 ProfInfo->Favourite = FALSE;
112 if (profile_type == NET_DEVICE_WIFI) {
113 ProfInfo->profile_type = NET_DEVICE_WIFI;
114 memset(ProfInfo->ProfileInfo.Wlan.essid, '\0', NET_WLAN_ESSID_LEN+1);
115 memset(ProfInfo->ProfileInfo.Wlan.bssid, '\0', NET_MAX_MAC_ADDR_LEN+1);
116 ProfInfo->ProfileInfo.Wlan.Strength = 0;
117 ProfInfo->ProfileInfo.Wlan.frequency = 0;
118 ProfInfo->ProfileInfo.Wlan.max_rate = 0;
119 ProfInfo->ProfileInfo.Wlan.wlan_mode = 0;
120 ProfInfo->ProfileInfo.Wlan.PassphraseRequired = FALSE;
122 ProfInfo->ProfileInfo.Wlan.security_info.sec_mode = 0;
123 ProfInfo->ProfileInfo.Wlan.security_info.enc_mode = 0;
125 if (NETPM_WLAN_MAX_WEP_KEY_LEN >= NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN)
126 memset(ProfInfo->ProfileInfo.Wlan.security_info.authentication.wep.wepKey,
127 '\0', NETPM_WLAN_MAX_WEP_KEY_LEN+1);
129 memset(ProfInfo->ProfileInfo.Wlan.security_info.authentication.psk.pskKey,
130 '\0', NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN+1);
132 ProfInfo->ProfileInfo.Wlan.security_info.wps_support = FALSE;
134 net_info = &(ProfInfo->ProfileInfo.Wlan.net_info);
135 } else if(profile_type == NET_DEVICE_CELLULAR) {
136 ProfInfo->profile_type = NET_DEVICE_CELLULAR;
137 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_NONE;
138 ProfInfo->ProfileInfo.Pdp.ServiceType = NET_SERVICE_UNKNOWN;
139 ProfInfo->ProfileInfo.Pdp.Apn[0] = '\0';
140 ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType = NET_PDP_AUTH_NONE;
141 ProfInfo->ProfileInfo.Pdp.AuthInfo.UserName[0] = '\0';
142 ProfInfo->ProfileInfo.Pdp.AuthInfo.Password[0] = '\0';
143 ProfInfo->ProfileInfo.Pdp.HomeURL[0] = '\0';
144 ProfInfo->ProfileInfo.Pdp.Mcc[0] = '\0';
145 ProfInfo->ProfileInfo.Pdp.Mnc[0] = '\0';
146 ProfInfo->ProfileInfo.Pdp.IsStatic = FALSE;
147 ProfInfo->ProfileInfo.Pdp.Roaming = FALSE;
148 ProfInfo->ProfileInfo.Pdp.SetupRequired = FALSE;
150 net_info = &(ProfInfo->ProfileInfo.Pdp.net_info);
153 memset(net_info->ProfileName, '\0', NET_PROFILE_NAME_LEN_MAX+1);
154 memset(net_info->DevName, '\0', NET_MAX_DEVICE_NAME_LEN+1);
155 net_info->DnsCount = 0;
157 for (i = 0;i < NET_DNS_ADDR_MAX;i++) {
158 net_info->DnsAddr[i].Type = NET_ADDR_IPV4;
159 net_info->DnsAddr[i].Data.Ipv4.s_addr = 0;
162 net_info->IpConfigType = 0;
163 net_info->IpAddr.Type = NET_ADDR_IPV4;
164 net_info->IpAddr.Data.Ipv4.s_addr = 0;
165 net_info->BNetmask = FALSE;
166 net_info->SubnetMask.Type = NET_ADDR_IPV4;
167 net_info->SubnetMask.Data.Ipv4.s_addr = 0;
168 net_info->BDefGateway = FALSE;
169 net_info->GatewayAddr.Type = NET_ADDR_IPV4;
170 net_info->GatewayAddr.Data.Ipv4.s_addr = 0;
171 net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
172 memset(net_info->ProxyAddr, '\0', NET_PROXY_LEN_MAX+1);
173 memset(net_info->MacAddr, '\0', NET_MAX_MAC_ADDR_LEN+1);
175 __NETWORK_FUNC_EXIT__;
180 static int __net_telephony_init_profile_info(net_telephony_profile_info_t* ProfInfo)
182 __NETWORK_FUNC_ENTER__;
184 if (ProfInfo == NULL) {
185 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Parameter\n");
186 __NETWORK_FUNC_EXIT__;
187 return NET_ERR_INVALID_PARAM;
190 memset(ProfInfo->ProfileName, '\0', NET_PROFILE_NAME_LEN_MAX+1);
191 ProfInfo->ServiceType = NET_SERVICE_UNKNOWN;
192 memset(ProfInfo->Apn, '\0', NET_PDP_APN_LEN_MAX+1);
194 ProfInfo->AuthInfo.AuthType = NET_PDP_AUTH_NONE;
195 memset(ProfInfo->AuthInfo.UserName, '\0', NET_PDP_AUTH_USERNAME_LEN_MAX+1);
196 memset(ProfInfo->AuthInfo.Password, '\0', NET_PDP_AUTH_PASSWORD_LEN_MAX+1);
198 memset(ProfInfo->ProxyAddr, '\0', NET_PROXY_LEN_MAX+1);
199 memset(ProfInfo->HomeURL, '\0', NET_HOME_URL_LEN_MAX+1);
201 __NETWORK_FUNC_EXIT__;
206 static int __net_telephony_get_profile_info(net_profile_name_t* ProfileName, net_telephony_profile_info_t* ProfileInfo)
208 __NETWORK_FUNC_ENTER__;
210 net_err_t Error = NET_ERR_NONE;
211 DBusMessage* result = NULL;
212 DBusMessageIter iter, array;
214 if (ProfileName == NULL || ProfileInfo == NULL) {
215 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid parameter!\n");
216 __NETWORK_FUNC_EXIT__;
217 return NET_ERR_INVALID_PARAM;
220 char request[] = TELEPHONY_PROFILE_INTERFACE ".GetProfile";
221 char* param_array[] = {NULL, NULL, NULL};
223 param_array[0] = ProfileName->ProfileName;
224 param_array[1] = request;
226 NETWORK_LOG(NETWORK_HIGH, "Requesting [%s %s]\n",
230 if ((Error = _net_send_dbus_request(TELEPHONY_SERVCE, param_array, &result)) != NET_ERR_NONE) {
231 NETWORK_LOG(NETWORK_ERROR, "Error!!! _net_send_dbus_request failed\n");
232 __NETWORK_FUNC_EXIT__;
236 /* Parsing profile info */
237 dbus_message_iter_init(result, &iter);
238 dbus_message_iter_recurse(&iter, &array);
240 Error = __net_telephony_init_profile_info(ProfileInfo);
242 if (Error != NET_ERR_NONE) {
243 dbus_message_unref(result);
244 __NETWORK_FUNC_EXIT__;
249 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
250 DBusMessageIter entry;
251 const char *key = NULL;
252 const char *value = NULL;
254 dbus_message_iter_recurse(&array, &entry);
255 dbus_message_iter_get_basic(&entry, &key);
257 dbus_message_iter_next(&entry);
259 if (strcmp(key, "path") == 0) {
260 dbus_message_iter_get_basic(&entry, &value);
263 g_strlcpy(ProfileInfo->ProfileName, value, NET_PROFILE_NAME_LEN_MAX);
265 } else if (strcmp(key, "svc_ctg_id") == 0) {
266 net_service_type_t ServiceType = NET_SERVICE_UNKNOWN;
267 dbus_message_iter_get_basic(&entry, &value);
270 ServiceType = atoi(value);
272 if (ServiceType > NET_SERVICE_UNKNOWN)
273 ProfileInfo->ServiceType = ServiceType;
275 } else if (strcmp(key, "apn") == 0) {
276 dbus_message_iter_get_basic(&entry, &value);
279 g_strlcpy(ProfileInfo->Apn, value, NET_PDP_APN_LEN_MAX);
281 } else if (strcmp(key, "auth_type") == 0) {
282 net_auth_type_t authType = NET_PDP_AUTH_NONE;
283 dbus_message_iter_get_basic(&entry, &value);
286 authType = atoi(value);
288 if (authType == NET_PDP_AUTH_PAP)
289 ProfileInfo->AuthInfo.AuthType = NET_PDP_AUTH_PAP;
290 else if (authType == NET_PDP_AUTH_CHAP)
291 ProfileInfo->AuthInfo.AuthType = NET_PDP_AUTH_CHAP;
293 } else if (strcmp(key, "auth_id") == 0) {
294 dbus_message_iter_get_basic(&entry, &value);
297 g_strlcpy(ProfileInfo->AuthInfo.UserName, value, NET_PDP_AUTH_USERNAME_LEN_MAX);
299 } else if (strcmp(key, "auth_pwd") == 0) {
300 dbus_message_iter_get_basic(&entry, &value);
303 g_strlcpy(ProfileInfo->AuthInfo.Password, value, NET_PDP_AUTH_PASSWORD_LEN_MAX);
305 } else if (strcmp(key, "proxy_addr") == 0) {
306 dbus_message_iter_get_basic(&entry, &value);
309 g_strlcpy(ProfileInfo->ProxyAddr, value, NET_PROXY_LEN_MAX);
311 } else if (strcmp(key, "home_url") == 0) {
312 dbus_message_iter_get_basic(&entry, &value);
315 g_strlcpy(ProfileInfo->HomeURL, value, NET_HOME_URL_LEN_MAX);
317 dbus_message_iter_next(&array);
320 dbus_message_unref(result);
322 __NETWORK_FUNC_EXIT__;
326 static int __net_telephony_get_profile_list(net_profile_name_t** ProfileName, int* ProfileCount)
328 __NETWORK_FUNC_ENTER__;
330 net_err_t Error = NET_ERR_NONE;
331 DBusMessage* result = NULL;
332 net_profile_name_t* profileList = NULL;
333 DBusMessageIter iter, array;
336 char request[] = TELEPHONY_MASTER_INTERFACE ".GetProfileList";
337 char path[] = TELEPHONY_MASTER_PATH;
338 char* param_array[] = {NULL, NULL, NULL};
340 param_array[0] = path;
341 param_array[1] = request;
343 NETWORK_LOG(NETWORK_HIGH, "Requesting [%s %s]\n",
347 Error = _net_send_dbus_request(TELEPHONY_SERVCE, param_array, &result);
349 if (Error != NET_ERR_NONE) {
350 NETWORK_LOG(NETWORK_ERROR, "Error!!! _net_send_dbus_request failed\n");
351 __NETWORK_FUNC_EXIT__;
355 dbus_message_iter_init(result, &iter);
356 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
357 NETWORK_LOG(NETWORK_HIGH, "There is no profiles\n");
359 dbus_message_unref(result);
360 __NETWORK_FUNC_EXIT__;
364 dbus_message_iter_recurse(&iter, &array);
366 /* Get count of profile name from reply message */
367 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
369 dbus_message_iter_next(&array);
373 profileList = (net_profile_name_t*)malloc(sizeof(net_profile_name_t) * count);
376 dbus_message_unref(result);
377 __NETWORK_FUNC_EXIT__;
381 if (profileList == NULL) {
382 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Failed to allocate memory\n");
384 dbus_message_unref(result);
385 __NETWORK_FUNC_EXIT__;
386 return NET_ERR_UNKNOWN;
391 /* Parsing to get profile name from reply message */
392 dbus_message_iter_init(result, &iter);
393 dbus_message_iter_recurse(&iter, &array);
394 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
395 const char *key = NULL;
397 dbus_message_iter_get_basic(&array, &key);
400 g_strlcpy(profileList[count].ProfileName, key, NET_PROFILE_NAME_LEN_MAX);
403 dbus_message_iter_next(&array);
406 *ProfileName = profileList;
407 *ProfileCount = count;
409 dbus_message_unref(result);
411 __NETWORK_FUNC_EXIT__;
415 static int __net_telephony_search_pdp_profile(char* ProfileName, net_profile_name_t* PdpProfName)
417 __NETWORK_FUNC_ENTER__;
419 net_err_t Error = NET_ERR_NONE;
420 net_profile_name_t* ProfileList = NULL;
421 char* connmanProfName = NULL;
422 char* telephonyProfName = NULL;
423 char* foundPtr = NULL;
424 int ProfileCount = 0;
427 /* Get pdp profile list from telephony service */
428 Error = __net_telephony_get_profile_list(&ProfileList, &ProfileCount);
429 if (Error != NET_ERR_NONE) {
430 NETWORK_LOG(NETWORK_ERROR, "Error!!! failed to get profile list from telephony service\n");
431 NET_MEMFREE(ProfileList);
432 __NETWORK_FUNC_EXIT__;
436 if (ProfileList == NULL || ProfileCount <= 0) {
437 NETWORK_LOG(NETWORK_ERROR, "Error!!! There is no PDP profiles\n");
438 NET_MEMFREE(ProfileList);
439 __NETWORK_FUNC_EXIT__;
440 return NET_ERR_NO_SERVICE;
443 /* Find matching profile */
444 connmanProfName = strrchr(ProfileName, '/') + 1;
445 for (i = 0;i < ProfileCount;i++) {
446 telephonyProfName = strrchr(ProfileList[i].ProfileName, '/') + 1;
447 foundPtr = strstr(connmanProfName, telephonyProfName);
449 if (foundPtr != NULL && strcmp(foundPtr, telephonyProfName) == 0) {
450 g_strlcpy(PdpProfName->ProfileName,
451 ProfileList[i].ProfileName, NET_PROFILE_NAME_LEN_MAX);
452 NETWORK_LOG(NETWORK_HIGH,
453 "PDP profile name found in cellular profile: %s\n",
454 PdpProfName->ProfileName);
459 if (i >= ProfileCount) {
460 NETWORK_LOG(NETWORK_ERROR, "Error!!! There is no matching PDP profiles\n");
461 NET_MEMFREE(ProfileList);
462 __NETWORK_FUNC_EXIT__;
463 return NET_ERR_NO_SERVICE;
466 NET_MEMFREE(ProfileList);
467 __NETWORK_FUNC_EXIT__;
472 static int __net_extract_wifi_services(DBusMessage* message,
473 DBusMessageIter* dict, network_services_list_t* service_info)
478 __NETWORK_FUNC_ENTER__;
480 if(message == NULL || dict == NULL || service_info == NULL)
482 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid prarameter \n");
483 __NETWORK_FUNC_EXIT__;
484 return NET_ERR_INVALID_PARAM;
487 while(dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY)
489 DBusMessageIter keyValue, array, value;
490 const char *key = NULL;
491 const char *objPath = NULL;
493 dbus_message_iter_recurse(dict, &keyValue);
494 dbus_message_iter_get_basic(&keyValue, &key);
496 if(strcmp(key, "Services") == 0)
498 dbus_message_iter_next(&keyValue);
499 dbus_message_iter_recurse(&keyValue, &array);
500 if(dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
502 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't get service list\n");
503 __NETWORK_FUNC_EXIT__;
504 return NET_ERR_NO_SERVICE;
507 dbus_message_iter_recurse(&array, &value);
508 if(dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_OBJECT_PATH)
510 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't get service list\n");
511 __NETWORK_FUNC_EXIT__;
512 return NET_ERR_NO_SERVICE;
515 while(dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_OBJECT_PATH)
517 dbus_message_iter_get_basic(&value, &objPath);
519 if(strstr(objPath, "wifi_") != NULL)
521 service_info->ProfileName[count] = (char*)malloc(NET_PROFILE_NAME_LEN_MAX+1);
522 if(service_info->ProfileName[count] == NULL)
524 NETWORK_LOG(NETWORK_EXCEPTION,
525 "Error!!! Failed to allocate memory\n");
527 for(i = 0;i < count;i++)
528 NET_MEMFREE(service_info->ProfileName[i]);
530 __NETWORK_FUNC_EXIT__;
531 return NET_ERR_UNKNOWN;
534 g_strlcpy(service_info->ProfileName[count], objPath, NET_PROFILE_NAME_LEN_MAX);
539 dbus_message_iter_next(&value);
542 service_info->num_of_services = count;
546 dbus_message_iter_next(dict);
549 __NETWORK_FUNC_EXIT__;
554 static int __net_extract_mobile_services(DBusMessage* message, DBusMessageIter* dict,
555 network_services_list_t* service_info, net_service_type_t network_type)
559 const char net_suffix[] = "_1";
560 const char mms_suffix[] = "_2";
561 const char wap_suffix[] = "_3";
564 __NETWORK_FUNC_ENTER__;
566 if (message == NULL || dict == NULL || service_info == NULL) {
567 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid prarameter \n");
568 __NETWORK_FUNC_EXIT__;
569 return NET_ERR_INVALID_PARAM;
572 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
573 DBusMessageIter keyValue, array, value;
574 const char *key = NULL;
575 const char *objPath = NULL;
578 dbus_message_iter_recurse(dict, &keyValue);
579 dbus_message_iter_get_basic(&keyValue, &key);
581 if (strcmp(key, "Services") == 0) {
582 dbus_message_iter_next(&keyValue);
583 dbus_message_iter_recurse(&keyValue, &array);
585 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY) {
586 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't get service list\n");
587 __NETWORK_FUNC_EXIT__;
588 return NET_ERR_NO_SERVICE;
591 dbus_message_iter_recurse(&array, &value);
593 if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_OBJECT_PATH) {
594 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't get service list\n");
595 __NETWORK_FUNC_EXIT__;
596 return NET_ERR_NO_SERVICE;
599 while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_OBJECT_PATH) {
600 dbus_message_iter_get_basic(&value, &objPath);
602 if (strstr(objPath, "cellular_") != NULL) {
605 suffix = strrchr(objPath, '_');
607 if (network_type == NET_SERVICE_UNKNOWN)
609 else if (network_type == NET_SERVICE_MMS && strcmp(suffix, mms_suffix) == 0)
611 else if (network_type == NET_SERVICE_WAP && strcmp(suffix, wap_suffix) == 0)
613 else if (network_type == NET_SERVICE_INTERNET && strcmp(suffix, net_suffix) == 0)
617 service_info->ProfileName[count] = (char*)malloc(NET_PROFILE_NAME_LEN_MAX+1);
618 if (service_info->ProfileName[count] == NULL) {
619 NETWORK_LOG(NETWORK_EXCEPTION,
620 "Error!!! Failed to allocate memory\n");
622 for (i = 0;i < count;i++)
623 NET_MEMFREE(service_info->ProfileName[i]);
625 __NETWORK_FUNC_EXIT__;
626 return NET_ERR_UNKNOWN;
629 g_strlcpy(service_info->ProfileName[count], objPath, NET_PROFILE_NAME_LEN_MAX+1);
631 NETWORK_LOG(NETWORK_HIGH, "index [%d] ProfileName [%s]\n",
632 count, service_info->ProfileName[count]);
638 dbus_message_iter_next(&value);
640 service_info->num_of_services = count;
643 dbus_message_iter_next(dict);
646 __NETWORK_FUNC_EXIT__;
651 static int __net_extract_services(DBusMessage *message, net_device_t device_type,
652 net_profile_info_t** profile_info, int* profile_count)
654 __NETWORK_FUNC_ENTER__;
656 net_err_t Error = NET_ERR_NONE;
657 DBusMessageIter iter, dict;
658 network_services_list_t service_info = {0,};
659 net_profile_info_t ProfileInfo = {0, };
660 net_profile_info_t* ProfilePtr = NULL;
665 dbus_message_iter_init(message, &iter);
666 dbus_message_iter_recurse(&iter, &dict);
670 switch (device_type) {
671 case NET_DEVICE_WIFI :
672 Error = __net_extract_wifi_services(message, &dict, &service_info);
674 case NET_DEVICE_CELLULAR :
675 Error = __net_extract_mobile_services(message, &dict, &service_info, NET_SERVICE_UNKNOWN);
678 __NETWORK_FUNC_EXIT__;
679 return NET_ERR_NOT_SUPPORTED;
683 if (Error != NET_ERR_NONE) {
684 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't extract services from received message\n");
686 __NETWORK_FUNC_EXIT__;
690 NETWORK_LOG(NETWORK_HIGH, "Num. of Profiles from Manager : [%d]\n", service_info.num_of_services);
693 for (i = 0; i < service_info.num_of_services; i++) {
694 memset(&ProfileInfo, 0, sizeof(net_profile_info_t));
696 Error = __net_get_profile_info(service_info.ProfileName[i], &ProfileInfo);
697 if (Error != NET_ERR_NONE) {
698 NETWORK_LOG(NETWORK_ERROR, "Error!!! failed to get service(profile) information. Error [%s]\n",
699 _net_print_error(Error));
700 NETWORK_LOG(NETWORK_HIGH, "Continuing with next profile\n");
706 ProfilePtr = (net_profile_info_t*)realloc(ProfilePtr, (j + 1) * sizeof(net_profile_info_t));
707 if (ProfilePtr == NULL) {
708 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Failed to allocate memory\n");
710 for (i = 0;i < service_info.num_of_services;i++)
711 NET_MEMFREE(service_info.ProfileName[i]);
713 __NETWORK_FUNC_EXIT__;
714 return NET_ERR_UNKNOWN;
717 memcpy(ProfilePtr + j, &ProfileInfo, sizeof(net_profile_info_t));
721 for(i = 0;i < service_info.num_of_services;i++)
722 NET_MEMFREE(service_info.ProfileName[i]);
724 NETWORK_LOG(NETWORK_HIGH, "Total Num. of Profiles [%d]\n", profiles);
726 *profile_count = profiles;
727 *profile_info = ProfilePtr;
729 __NETWORK_FUNC_EXIT__;
735 static int __net_extract_ip(DBusMessageIter *iter, net_addr_t *ipAddr)
737 __NETWORK_FUNC_ENTER__;
739 unsigned char *ipValue = NULL;
740 const char *value = NULL;
741 char *saveptr = NULL;
742 char ipString[NETPM_IPV4_STR_LEN_MAX+1];
745 dbus_message_iter_get_basic(iter, &value);
747 ipValue = (unsigned char *)&(ipAddr->Data.Ipv4.s_addr);
750 g_strlcpy(ipString, value, NETPM_IPV4_STR_LEN_MAX+1);
752 ipToken[0] = strtok_r(ipString, ".", &saveptr);
754 if(ipToken[0] != NULL) {
755 ipToken[1] = strtok_r(NULL, ".", &saveptr);
757 if(ipToken[1] != NULL) {
758 ipToken[2] = strtok_r(NULL, ".", &saveptr);
760 if(ipToken[2] != NULL) {
761 ipToken[3] = strtok_r(NULL, ".", &saveptr);
763 if(ipToken[3] != NULL) {
764 ipValue[0] = (unsigned char)atoi(ipToken[0]);
765 ipValue[1] = (unsigned char)atoi(ipToken[1]);
766 ipValue[2] = (unsigned char)atoi(ipToken[2]);
767 ipValue[3] = (unsigned char)atoi(ipToken[3]);
774 __NETWORK_FUNC_EXIT__;
779 static int __net_extract_common_info(const char *key, DBusMessageIter *variant, net_profile_info_t* ProfInfo)
781 __NETWORK_FUNC_ENTER__;
783 net_err_t Error = NET_ERR_NONE;
784 DBusMessageIter subIter1, subIter2, subIter3, subIter4;
785 const char *subKey = NULL;
786 const char *value = NULL;
787 net_dev_info_t* net_info = NULL;
789 if (ProfInfo->profile_type == NET_DEVICE_CELLULAR) {
790 net_info = &(ProfInfo->ProfileInfo.Pdp.net_info);
791 } else if (ProfInfo->profile_type == NET_DEVICE_WIFI) {
792 net_info = &(ProfInfo->ProfileInfo.Wlan.net_info);
794 NETWORK_LOG(NETWORK_ERROR,
795 "Error!!! Invalid Profile type. [%d]\n", ProfInfo->profile_type);
796 return NET_ERR_INVALID_PARAM;
799 if (strcmp(key, "State") == 0) {
800 dbus_message_iter_get_basic(variant, &value);
802 if (strcmp(value, "idle") == 0)
803 ProfInfo->ProfileState = NET_STATE_TYPE_IDLE;
804 else if (strcmp(value, "failure") == 0)
805 ProfInfo->ProfileState = NET_STATE_TYPE_FAILURE;
806 else if (strcmp(value, "association") == 0)
807 ProfInfo->ProfileState = NET_STATE_TYPE_ASSOCIATION;
808 else if (strcmp(value, "configuration") == 0)
809 ProfInfo->ProfileState = NET_STATE_TYPE_CONFIGURATION;
810 else if (strcmp(value, "ready") == 0)
811 ProfInfo->ProfileState = NET_STATE_TYPE_READY;
812 else if (strcmp(value, "disconnect") == 0)
813 ProfInfo->ProfileState = NET_STATE_TYPE_DISCONNECT;
814 else if (strcmp(value, "online") == 0)
815 ProfInfo->ProfileState = NET_STATE_TYPE_ONLINE;
817 ProfInfo->ProfileState = NET_STATE_TYPE_UNKNOWN;
818 } else if (strcmp(key, "Favorite") == 0) {
821 dbus_message_iter_get_basic(variant, &val);
824 ProfInfo->Favourite = TRUE;
826 ProfInfo->Favourite = FALSE;
827 } else if (strcmp(key, "Ethernet") == 0) {
828 dbus_message_iter_recurse(variant, &subIter1);
830 while (dbus_message_iter_get_arg_type(&subIter1) == DBUS_TYPE_DICT_ENTRY) {
831 dbus_message_iter_recurse(&subIter1, &subIter2);
832 dbus_message_iter_get_basic(&subIter2, &subKey);
834 if (strcmp(subKey, "Interface") == 0) {
835 dbus_message_iter_next(&subIter2);
836 dbus_message_iter_recurse(&subIter2, &subIter3);
837 dbus_message_iter_get_basic(&subIter3, &value);
840 g_strlcpy(net_info->DevName, value, NET_MAX_DEVICE_NAME_LEN);
842 } else if (strcmp(subKey, "Address") == 0) {
843 dbus_message_iter_next(&subIter2);
844 dbus_message_iter_recurse(&subIter2, &subIter3);
845 dbus_message_iter_get_basic(&subIter3, &value);
848 g_strlcpy(net_info->MacAddr, value, NET_MAX_MAC_ADDR_LEN);
851 dbus_message_iter_next(&subIter1);
853 } else if (strcmp(key, "IPv4") == 0) {
854 dbus_message_iter_recurse(variant, &subIter1);
856 while (dbus_message_iter_get_arg_type(&subIter1) == DBUS_TYPE_DICT_ENTRY) {
857 dbus_message_iter_recurse(&subIter1, &subIter2);
858 dbus_message_iter_get_basic(&subIter2, &subKey);
860 if (strcmp(subKey, "Method") == 0) {
861 dbus_message_iter_next(&subIter2);
862 dbus_message_iter_recurse(&subIter2, &subIter3);
863 dbus_message_iter_get_basic(&subIter3, &value);
865 if (strcmp(value, "dhcp") == 0)
866 net_info->IpConfigType = NET_IP_CONFIG_TYPE_DYNAMIC;
867 else if (strcmp(value, "manual") == 0)
868 net_info->IpConfigType = NET_IP_CONFIG_TYPE_STATIC;
869 else if (strcmp(value, "fixed") == 0)
870 net_info->IpConfigType = NET_IP_CONFIG_TYPE_FIXED;
871 else if (strcmp(value, "off") == 0)
872 net_info->IpConfigType = NET_IP_CONFIG_TYPE_OFF;
874 } else if (strcmp(subKey, "Address") == 0) {
875 dbus_message_iter_next(&subIter2);
876 dbus_message_iter_recurse(&subIter2, &subIter3);
877 __net_extract_ip(&subIter3, &net_info->IpAddr);
878 } else if (strcmp(subKey, "Netmask") == 0) {
879 dbus_message_iter_next(&subIter2);
880 dbus_message_iter_recurse(&subIter2, &subIter3);
881 __net_extract_ip(&subIter3, &net_info->SubnetMask);
882 net_info->BNetmask = TRUE;
883 } else if (strcmp(subKey, "Gateway") == 0) {
884 dbus_message_iter_next(&subIter2);
885 dbus_message_iter_recurse(&subIter2, &subIter3);
886 __net_extract_ip(&subIter3, &net_info->GatewayAddr);
887 net_info->BDefGateway = TRUE;
890 dbus_message_iter_next(&subIter1);
892 } else if (strcmp(key, "IPv4.Configuration") == 0) {
894 if (net_info->IpConfigType != NET_IP_CONFIG_TYPE_DYNAMIC &&
895 net_info->IpConfigType != NET_IP_CONFIG_TYPE_STATIC &&
896 net_info->IpConfigType != NET_IP_CONFIG_TYPE_OFF) {
898 dbus_message_iter_recurse(variant, &subIter1);
900 while (dbus_message_iter_get_arg_type(&subIter1) == DBUS_TYPE_DICT_ENTRY) {
901 dbus_message_iter_recurse(&subIter1, &subIter2);
902 dbus_message_iter_get_basic(&subIter2, &subKey);
904 if (strcmp(subKey, "Method") == 0) {
905 dbus_message_iter_next(&subIter2);
906 dbus_message_iter_recurse(&subIter2, &subIter3);
907 dbus_message_iter_get_basic(&subIter3, &value);
909 if(strcmp(value, "dhcp") == 0)
910 net_info->IpConfigType = NET_IP_CONFIG_TYPE_DYNAMIC;
911 else if(strcmp(value, "manual") == 0)
912 net_info->IpConfigType = NET_IP_CONFIG_TYPE_STATIC;
913 else if(strcmp(value, "off") == 0)
914 net_info->IpConfigType = NET_IP_CONFIG_TYPE_OFF;
916 } else if (strcmp(subKey, "Address") == 0 &&
917 net_info->IpAddr.Data.Ipv4.s_addr == 0) {
918 dbus_message_iter_next(&subIter2);
919 dbus_message_iter_recurse(&subIter2, &subIter3);
920 __net_extract_ip(&subIter3, &net_info->IpAddr);
921 } else if (strcmp(subKey, "Netmask") == 0 &&
922 net_info->SubnetMask.Data.Ipv4.s_addr == 0) {
923 dbus_message_iter_next(&subIter2);
924 dbus_message_iter_recurse(&subIter2, &subIter3);
925 __net_extract_ip(&subIter3, &net_info->SubnetMask);
926 net_info->BNetmask = TRUE;
927 } else if (strcmp(subKey, "Gateway") == 0 &&
928 net_info->GatewayAddr.Data.Ipv4.s_addr == 0) {
929 dbus_message_iter_next(&subIter2);
930 dbus_message_iter_recurse(&subIter2, &subIter3);
931 __net_extract_ip(&subIter3, &net_info->GatewayAddr);
932 net_info->BDefGateway = TRUE;
935 dbus_message_iter_next(&subIter1);
938 } else if(strcmp(key, "Nameservers") == 0) {
940 dbus_message_iter_recurse(variant, &subIter1);
942 while (dbus_message_iter_get_arg_type(&subIter1) == DBUS_TYPE_STRING) {
943 __net_extract_ip(&subIter1, &net_info->DnsAddr[dnsCount]);
945 if (dnsCount >= NET_DNS_ADDR_MAX)
948 dbus_message_iter_next(&subIter1);
951 net_info->DnsCount = dnsCount;
952 } else if (strcmp(key, "Nameservers.Configuration") == 0 && net_info->DnsCount == 0) {
954 dbus_message_iter_recurse(variant, &subIter1);
956 while (dbus_message_iter_get_arg_type(&subIter1) == DBUS_TYPE_STRING) {
957 __net_extract_ip(&subIter1, &net_info->DnsAddr[dnsCount]);
959 if(dnsCount >= NET_DNS_ADDR_MAX)
962 dbus_message_iter_next(&subIter1);
965 net_info->DnsCount = dnsCount;
966 } else if (strcmp(key, "Domains") == 0) {
967 } else if (strcmp(key, "Domains.Configuration") == 0) {
968 } else if (strcmp(key, "Proxy") == 0) {
969 dbus_message_iter_recurse(variant, &subIter1);
971 while (dbus_message_iter_get_arg_type(&subIter1) == DBUS_TYPE_DICT_ENTRY) {
972 dbus_message_iter_recurse(&subIter1, &subIter2);
973 dbus_message_iter_get_basic(&subIter2, &subKey);
975 if (strcmp(subKey, "Method") == 0) {
976 dbus_message_iter_next(&subIter2);
977 dbus_message_iter_recurse(&subIter2, &subIter3);
978 dbus_message_iter_get_basic(&subIter3, &value);
980 if (strcmp(value, "direct") == 0)
981 net_info->ProxyMethod = NET_PROXY_TYPE_DIRECT;
982 else if (strcmp(value, "auto") == 0)
983 net_info->ProxyMethod = NET_PROXY_TYPE_AUTO;
984 else if (strcmp(value, "manual") == 0)
985 net_info->ProxyMethod = NET_PROXY_TYPE_MANUAL;
987 net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
988 } else if (strcmp(subKey, "URL") == 0) {
989 dbus_message_iter_next(&subIter2);
990 dbus_message_iter_recurse(&subIter2, &subIter3);
991 dbus_message_iter_get_basic(&subIter3, &value);
994 g_strlcpy(net_info->ProxyAddr, value, NET_PROXY_LEN_MAX);
996 } else if (strcmp(subKey, "Servers") == 0) {
997 dbus_message_iter_next(&subIter2);
998 dbus_message_iter_recurse(&subIter2, &subIter3);
1000 if (dbus_message_iter_get_arg_type(&subIter3) == DBUS_TYPE_ARRAY) {
1001 dbus_message_iter_recurse(&subIter3, &subIter4);
1003 if (dbus_message_iter_get_arg_type(&subIter4) == DBUS_TYPE_STRING) {
1004 dbus_message_iter_get_basic(&subIter4, &value);
1007 g_strlcpy(net_info->ProxyAddr, value, NET_PROXY_LEN_MAX);
1012 dbus_message_iter_next(&subIter1);
1014 } else if (strcmp(key, "Proxy.Configuration") == 0 &&
1015 (net_info->ProxyMethod == NET_PROXY_TYPE_UNKNOWN ||
1016 strlen(net_info->ProxyAddr) == 0)) {
1018 dbus_message_iter_recurse(variant, &subIter1);
1020 while (dbus_message_iter_get_arg_type(&subIter1) == DBUS_TYPE_DICT_ENTRY) {
1021 dbus_message_iter_recurse(&subIter1, &subIter2);
1022 dbus_message_iter_get_basic(&subIter2, &subKey);
1024 if (strcmp(subKey, "Method") == 0 &&
1025 net_info->ProxyMethod == NET_PROXY_TYPE_UNKNOWN) {
1026 dbus_message_iter_next(&subIter2);
1027 dbus_message_iter_recurse(&subIter2, &subIter3);
1028 dbus_message_iter_get_basic(&subIter3, &value);
1030 if (strcmp(value, "direct") == 0)
1031 net_info->ProxyMethod = NET_PROXY_TYPE_DIRECT;
1032 else if (strcmp(value, "auto") == 0)
1033 net_info->ProxyMethod = NET_PROXY_TYPE_AUTO;
1034 else if (strcmp(value, "manual") == 0)
1035 net_info->ProxyMethod = NET_PROXY_TYPE_MANUAL;
1037 net_info->ProxyMethod = NET_PROXY_TYPE_UNKNOWN;
1038 } else if (strcmp(subKey, "URL") == 0 && strlen(net_info->ProxyAddr) == 0) {
1039 dbus_message_iter_next(&subIter2);
1040 dbus_message_iter_recurse(&subIter2, &subIter3);
1041 dbus_message_iter_get_basic(&subIter3, &value);
1044 g_strlcpy(net_info->ProxyAddr, value, NET_PROXY_LEN_MAX+1);
1046 } else if (strcmp(subKey, "Servers") == 0 && strlen(net_info->ProxyAddr) == 0) {
1047 dbus_message_iter_next(&subIter2);
1048 dbus_message_iter_recurse(&subIter2, &subIter3);
1050 if (dbus_message_iter_get_arg_type(&subIter3) == DBUS_TYPE_ARRAY) {
1051 dbus_message_iter_recurse(&subIter3, &subIter4);
1053 if (dbus_message_iter_get_arg_type(&subIter4) == DBUS_TYPE_STRING) {
1054 dbus_message_iter_get_basic(&subIter4, &value);
1057 g_strlcpy(net_info->ProxyAddr, value, NET_PROXY_LEN_MAX+1);
1062 dbus_message_iter_next(&subIter1);
1064 } else if(strcmp(key, "Provider") == 0) {
1067 __NETWORK_FUNC_EXIT__;
1072 static int __net_extract_wifi_info(DBusMessageIter *array, net_profile_info_t* ProfInfo)
1074 __NETWORK_FUNC_ENTER__;
1076 net_err_t Error = NET_ERR_NONE;
1077 net_wifi_profile_info_t *Wlan = &(ProfInfo->ProfileInfo.Wlan);
1079 while (dbus_message_iter_get_arg_type(array) == DBUS_TYPE_DICT_ENTRY) {
1080 DBusMessageIter entry, variant, sub_array;
1081 const char *key = NULL;
1082 const char *value = NULL;
1084 dbus_message_iter_recurse(array, &entry);
1085 dbus_message_iter_get_basic(&entry, &key);
1087 dbus_message_iter_next(&entry);
1088 dbus_message_iter_recurse(&entry, &variant);
1090 if (strcmp(key, "Mode") == 0) {
1091 dbus_message_iter_get_basic(&variant, &value);
1093 if (strcmp(value, "managed") == 0)
1094 Wlan->wlan_mode = NETPM_WLAN_CONNMODE_INFRA;
1095 else if (strcmp(value, "adhoc") == 0)
1096 Wlan->wlan_mode = NETPM_WLAN_CONNMODE_ADHOC;
1098 Wlan->wlan_mode = NETPM_WLAN_CONNMODE_AUTO;
1099 } else if (strcmp(key, "Security") == 0) {
1100 dbus_message_iter_recurse(&variant, &sub_array);
1102 while (dbus_message_iter_get_arg_type(&sub_array) == DBUS_TYPE_STRING) {
1103 dbus_message_iter_get_basic(&sub_array, &value);
1104 if (strcmp(value, "none") == 0 &&
1105 Wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1106 Wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1107 else if (strcmp(value, "wep") == 0 &&
1108 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WEP)
1109 Wlan->security_info.sec_mode = WLAN_SEC_MODE_WEP;
1110 else if (strcmp(value, "psk") == 0 &&
1111 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1112 Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
1113 else if (strcmp(value, "ieee8021x") == 0 &&
1114 Wlan->security_info.sec_mode < WLAN_SEC_MODE_IEEE8021X)
1115 Wlan->security_info.sec_mode = WLAN_SEC_MODE_IEEE8021X;
1116 else if (strcmp(value, "wpa") == 0 &&
1117 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1118 Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
1119 else if (strcmp(value, "rsn") == 0 &&
1120 Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
1121 Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK;
1122 else if (strcmp(value, "wps") == 0)
1123 Wlan->security_info.wps_support = TRUE;
1124 else if (Wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
1125 Wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
1127 dbus_message_iter_next(&sub_array);
1129 } else if (strcmp(key, "EncryptionMode") == 0) {
1130 dbus_message_iter_get_basic(&variant, &value);
1132 if (strcmp(value, "none") == 0)
1133 Wlan->security_info.enc_mode = WLAN_ENC_MODE_NONE;
1134 else if (strcmp(value, "wep") == 0)
1135 Wlan->security_info.enc_mode = WLAN_ENC_MODE_WEP;
1136 else if (strcmp(value, "tkip") == 0)
1137 Wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP;
1138 else if (strcmp(value, "aes") == 0)
1139 Wlan->security_info.enc_mode = WLAN_ENC_MODE_AES;
1140 else if (strcmp(value, "mixed") == 0)
1141 Wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP_AES_MIXED;
1143 dbus_message_iter_next(&sub_array);
1145 } else if (strcmp(key, "Strength") == 0) {
1146 dbus_message_iter_get_basic(&variant, &(Wlan->Strength));
1147 } else if (strcmp(key, "Name") == 0) {
1148 dbus_message_iter_get_basic(&variant, &value);
1151 g_strlcpy(Wlan->essid, value, NET_WLAN_ESSID_LEN);
1153 } else if (strcmp(key, "Passphrase") == 0) {
1154 wlan_security_info_t *security_info = &(Wlan->security_info);
1155 dbus_message_iter_get_basic(&variant, &value);
1157 if (security_info->sec_mode == WLAN_SEC_MODE_WEP && value != NULL)
1158 g_strlcpy(security_info->authentication.wep.wepKey,
1159 value, NETPM_WLAN_MAX_WEP_KEY_LEN+1);
1160 else if ((security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
1161 security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) &&
1163 g_strlcpy(security_info->authentication.psk.pskKey,
1164 value, NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN+1);
1166 } else if (strcmp(key, "PassphraseRequired") == 0) {
1169 dbus_message_iter_get_basic(&variant, &val);
1172 Wlan->PassphraseRequired = TRUE;
1174 Wlan->PassphraseRequired = FALSE;
1175 } else if (strcmp(key, "BSSID") == 0) {
1176 dbus_message_iter_get_basic(&variant, &value);
1179 g_strlcpy(Wlan->bssid, value, NET_MAX_MAC_ADDR_LEN);
1181 } else if (strcmp(key, "MaxRate") == 0) {
1182 unsigned int maxrate;
1183 dbus_message_iter_get_basic(&variant, &maxrate);
1185 Wlan->max_rate = maxrate;
1187 } else if (strcmp(key, "Frequency") == 0) {
1188 unsigned short frequency;
1189 dbus_message_iter_get_basic(&variant, &frequency);
1191 Wlan->frequency = (unsigned int)frequency;
1194 __net_extract_common_info(key, &variant, ProfInfo);
1197 dbus_message_iter_next(array);
1200 __NETWORK_FUNC_EXIT__;
1205 static int __net_extract_mobile_info(DBusMessageIter *array, net_profile_info_t* ProfInfo)
1207 net_err_t Error = NET_ERR_NONE;
1209 __NETWORK_FUNC_ENTER__;
1211 while (dbus_message_iter_get_arg_type(array) == DBUS_TYPE_DICT_ENTRY) {
1212 DBusMessageIter entry, variant;
1213 const char *key = NULL;
1214 const char *value = NULL;
1216 dbus_message_iter_recurse(array, &entry);
1217 dbus_message_iter_get_basic(&entry, &key);
1219 dbus_message_iter_next(&entry);
1220 dbus_message_iter_recurse(&entry, &variant);
1222 if (strcmp(key, "Mode") == 0) {
1223 dbus_message_iter_get_basic(&variant, &value);
1225 if (strcmp(value, "gprs") == 0)
1226 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_GPRS;
1227 else if (strcmp(value, "edge") == 0)
1228 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_EDGE;
1229 else if (strcmp(value, "umts") == 0)
1230 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_UMTS;
1232 ProfInfo->ProfileInfo.Pdp.ProtocolType = NET_PDP_TYPE_NONE;
1233 } else if (strcmp(key, "Roaming") == 0) {
1236 dbus_message_iter_get_basic(&variant, &val);
1239 ProfInfo->ProfileInfo.Pdp.Roaming = TRUE;
1241 ProfInfo->ProfileInfo.Pdp.Roaming = FALSE;
1242 } else if (strcmp(key, "SetupRequired") == 0) {
1245 dbus_message_iter_get_basic(&variant, &val);
1248 ProfInfo->ProfileInfo.Pdp.SetupRequired = TRUE;
1250 ProfInfo->ProfileInfo.Pdp.SetupRequired = FALSE;
1252 __net_extract_common_info(key, &variant, ProfInfo);
1254 dbus_message_iter_next(array);
1257 /* Get Specific info from telephony service */
1258 net_telephony_profile_info_t telephony_profinfo;
1259 net_profile_name_t PdpProfName;
1261 PdpProfName.ProfileName[0] = '\0';
1263 __net_telephony_init_profile_info(&telephony_profinfo);
1265 /* Find matching profile in telephony service */
1266 Error = __net_telephony_search_pdp_profile(ProfInfo->ProfileName, &PdpProfName);
1268 if (Error == NET_ERR_NONE && strlen(PdpProfName.ProfileName) > 0) {
1269 /* Get profile info from telephony service */
1270 Error = __net_telephony_get_profile_info(&PdpProfName, &telephony_profinfo);
1272 if (Error == NET_ERR_NONE) {
1273 ProfInfo->ProfileInfo.Pdp.ServiceType = telephony_profinfo.ServiceType;
1275 if (strlen(telephony_profinfo.Apn) > 0)
1276 g_strlcpy(ProfInfo->ProfileInfo.Pdp.Apn,
1277 telephony_profinfo.Apn, NET_PDP_APN_LEN_MAX);
1279 if (strlen(telephony_profinfo.ProxyAddr) > 0)
1280 g_strlcpy(ProfInfo->ProfileInfo.Pdp.net_info.ProxyAddr,
1281 telephony_profinfo.ProxyAddr, NET_PROXY_LEN_MAX);
1283 if (strlen(telephony_profinfo.HomeURL) > 0)
1284 g_strlcpy(ProfInfo->ProfileInfo.Pdp.HomeURL,
1285 telephony_profinfo.HomeURL, NET_HOME_URL_LEN_MAX);
1287 ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType = telephony_profinfo.AuthInfo.AuthType;
1289 if (strlen(telephony_profinfo.AuthInfo.UserName) > 0)
1290 g_strlcpy(ProfInfo->ProfileInfo.Pdp.AuthInfo.UserName,
1291 telephony_profinfo.AuthInfo.UserName,
1292 NET_PDP_AUTH_USERNAME_LEN_MAX);
1294 if (strlen(telephony_profinfo.AuthInfo.Password) > 0)
1295 g_strlcpy(ProfInfo->ProfileInfo.Pdp.AuthInfo.Password,
1296 telephony_profinfo.AuthInfo.Password,
1297 NET_PDP_AUTH_PASSWORD_LEN_MAX);
1301 __NETWORK_FUNC_EXIT__;
1306 static int __net_extract_service_info(const char* ProfileName, DBusMessage *message, net_profile_info_t* ProfInfo)
1308 __NETWORK_FUNC_ENTER__;
1310 net_err_t Error = NET_ERR_NONE;
1311 DBusMessageIter iter, array;
1312 net_device_t profileType = NET_DEVICE_UNKNOWN;
1314 dbus_message_iter_init(message, &iter);
1315 dbus_message_iter_recurse(&iter, &array);
1317 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
1318 DBusMessageIter entry, dict;
1319 const char *key = NULL;
1320 const char *temp = NULL;
1322 dbus_message_iter_recurse(&array, &entry);
1323 dbus_message_iter_get_basic(&entry, &key);
1325 if (strcmp(key, "Type") == 0) {
1326 dbus_message_iter_next(&entry);
1327 dbus_message_iter_recurse(&entry, &dict);
1328 dbus_message_iter_get_basic(&dict, &temp);
1329 if (strcmp(temp, "wifi") == 0)
1330 profileType = NET_DEVICE_WIFI;
1331 else if (strcmp(temp, "cellular") == 0)
1332 profileType = NET_DEVICE_CELLULAR;
1337 dbus_message_iter_next(&array);
1340 dbus_message_iter_init(message, &iter);
1341 dbus_message_iter_recurse(&iter, &array);
1343 if (profileType == NET_DEVICE_WIFI) {
1344 if ((Error = __net_pm_init_profile_info(NET_DEVICE_WIFI, ProfInfo)) != NET_ERR_NONE) {
1345 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't init profile\n");
1346 __NETWORK_FUNC_EXIT__;
1350 ProfInfo->profile_type = NET_DEVICE_WIFI;
1351 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1352 g_strlcpy(ProfInfo->ProfileInfo.Wlan.net_info.ProfileName,
1353 ProfileName, NET_PROFILE_NAME_LEN_MAX);
1355 Error = __net_extract_wifi_info(&array, ProfInfo);
1357 } else if (profileType == NET_DEVICE_CELLULAR) {
1358 if ((Error = __net_pm_init_profile_info(NET_DEVICE_CELLULAR, ProfInfo)) != NET_ERR_NONE) {
1359 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't init profile\n");
1360 __NETWORK_FUNC_EXIT__;
1364 ProfInfo->profile_type = NET_DEVICE_CELLULAR;
1365 g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX);
1366 g_strlcpy(ProfInfo->ProfileInfo.Pdp.net_info.ProfileName,
1367 ProfileName, NET_PROFILE_NAME_LEN_MAX);
1369 Error = __net_extract_mobile_info(&array, ProfInfo);
1371 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Not supported profile type\n");
1372 __NETWORK_FUNC_EXIT__;
1373 return NET_ERR_NOT_SUPPORTED;
1376 if (Error != NET_ERR_NONE) {
1377 NETWORK_LOG(NETWORK_EXCEPTION,
1378 "Error!!! Can't extract service information from received message\n");
1379 __NETWORK_FUNC_EXIT__;
1383 __NETWORK_FUNC_EXIT__;
1388 static int __net_get_profile_info(const char* ProfileName, net_profile_info_t* ProfInfo)
1390 __NETWORK_FUNC_ENTER__;
1392 net_err_t Error = NET_ERR_NONE;
1393 DBusConnection* conn = NULL;
1394 DBusMessage *message = NULL;
1396 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1399 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't get on system bus\n");
1400 __NETWORK_FUNC_EXIT__;
1401 return NET_ERR_UNKNOWN;
1404 message = _net_invoke_dbus_method(CONNMAN_SERVICE, conn, ProfileName,
1405 CONNMAN_SERVICE_INTERFACE, "GetProperties", &Error);
1407 if (message == NULL) {
1408 NETWORK_LOG(NETWORK_ERROR,
1409 "Error!!! Failed to get service(profile) information\n");
1413 Error = __net_extract_service_info(ProfileName, message, ProfInfo);
1415 dbus_message_unref(message);
1417 dbus_connection_unref(conn);
1419 __NETWORK_FUNC_EXIT__;
1425 static int __net_set_profile_property(char* path, char* key, char* value)
1427 __NETWORK_FUNC_ENTER__;
1429 net_err_t Error = NET_ERR_NONE;
1431 char request[] = CONNMAN_SERVICE_INTERFACE ".SetProperty";
1432 char* param_array[] = {NULL, NULL, NULL, NULL, NULL};
1434 param_array[0] = path;
1435 param_array[1] = request;
1436 param_array[2] = key;
1437 param_array[3] = value;
1439 NETWORK_LOG(NETWORK_HIGH, "Requesting [%s %s %s %s]\n",
1445 Error = _net_send_dbus_request(CONNMAN_SERVICE, param_array, NULL);
1446 if (Error != NET_ERR_NONE) {
1447 NETWORK_LOG(NETWORK_ERROR, "Error!!! _net_send_dbus_request failed\n");
1448 __NETWORK_FUNC_EXIT__;
1452 __NETWORK_FUNC_EXIT__;
1453 return NET_ERR_NONE;
1456 static int __net_modify_wlan_profile_info(const char* ProfileName,
1457 net_profile_info_t* ProfInfo, net_profile_info_t* exProfInfo)
1459 __NETWORK_FUNC_ENTER__;
1461 net_err_t Error = NET_ERR_NONE;
1463 char profilePath[NET_PROFILE_NAME_LEN_MAX+1] = "";
1464 char propertyInfo[128] = "";
1465 char keyString[64] = "";
1467 wlan_security_info_t *security_info = &(ProfInfo->ProfileInfo.Wlan.security_info);
1468 wlan_security_info_t *ex_security_info = &(exProfInfo->ProfileInfo.Wlan.security_info);
1470 net_dev_info_t *net_info = &(ProfInfo->ProfileInfo.Wlan.net_info);
1471 net_dev_info_t *ex_net_info = &(exProfInfo->ProfileInfo.Wlan.net_info);
1473 snprintf(profilePath, NET_PROFILE_NAME_LEN_MAX+1, "%s", ProfileName);
1475 /* Compare and Set 'Passphrase' */
1476 if (ex_security_info->sec_mode == WLAN_SEC_MODE_WEP) {
1477 if (strcmp(security_info->authentication.wep.wepKey
1478 , ex_security_info->authentication.wep.wepKey) != 0) {
1480 snprintf(keyString, 64, "string:Passphrase");
1481 snprintf(propertyInfo, 128, "variant:string:%s",
1482 security_info->authentication.wep.wepKey);
1483 Error = __net_set_profile_property(profilePath, keyString, propertyInfo);
1484 if (Error != NET_ERR_NONE) {
1485 NETWORK_LOG(NETWORK_ERROR,
1486 "Error!!! __net_set_profile_property() failed\n");
1487 __NETWORK_FUNC_EXIT__;
1491 } else if (ex_security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
1492 ex_security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) {
1494 if (strcmp(security_info->authentication.psk.pskKey,
1495 ex_security_info->authentication.psk.pskKey) != 0) {
1497 snprintf(keyString, 64, "string:Passphrase");
1498 snprintf(propertyInfo, 128, "variant:string:%s",
1499 security_info->authentication.psk.pskKey);
1500 Error = __net_set_profile_property(profilePath, keyString, propertyInfo);
1502 if (Error != NET_ERR_NONE) {
1503 __NETWORK_FUNC_EXIT__;
1509 /* Compare and Set 'Proxy' */
1510 if ((ex_net_info->ProxyMethod != net_info->ProxyMethod) ||
1511 (strcmp(ex_net_info->ProxyAddr, net_info->ProxyAddr) != 0)) {
1513 Error = _net_dbus_set_proxy(ProfInfo, profilePath);
1515 if (Error != NET_ERR_NONE) {
1516 __NETWORK_FUNC_EXIT__;
1521 /* Compare and Set 'IPv4 addresses' */
1522 if ((ex_net_info->IpConfigType != net_info->IpConfigType) ||
1523 (net_info->IpConfigType == NET_IP_CONFIG_TYPE_STATIC &&
1524 (net_info->IpAddr.Data.Ipv4.s_addr != ex_net_info->IpAddr.Data.Ipv4.s_addr ||
1525 net_info->SubnetMask.Data.Ipv4.s_addr != ex_net_info->SubnetMask.Data.Ipv4.s_addr ||
1526 net_info->GatewayAddr.Data.Ipv4.s_addr != ex_net_info->GatewayAddr.Data.Ipv4.s_addr))) {
1528 Error = _net_dbus_set_profile_ipv4(ProfInfo, profilePath);
1530 if (Error != NET_ERR_NONE) {
1531 NETWORK_LOG(NETWORK_ERROR, "Error!!! Can't set IPv4\n");
1532 __NETWORK_FUNC_EXIT__;
1537 /* Compare and Set 'DNS addresses' */
1538 if (net_info->IpConfigType == NET_IP_CONFIG_TYPE_STATIC) {
1539 for (i = 0;i < net_info->DnsCount;i++) {
1540 if(i >= NET_DNS_ADDR_MAX) {
1541 net_info->DnsCount = NET_DNS_ADDR_MAX;
1545 if (net_info->DnsAddr[i].Data.Ipv4.s_addr !=
1546 ex_net_info->DnsAddr[i].Data.Ipv4.s_addr) break;
1549 if (i < net_info->DnsCount) {
1550 Error = _net_dbus_set_profile_dns(ProfInfo, profilePath);
1552 if (Error != NET_ERR_NONE) {
1553 NETWORK_LOG(NETWORK_ERROR, "Error!!! Can't set dns\n");
1554 __NETWORK_FUNC_EXIT__;
1560 __NETWORK_FUNC_EXIT__;
1561 return NET_ERR_NONE;
1564 static int __net_wifi_delete_profile(net_profile_name_t* WifiProfName)
1566 __NETWORK_FUNC_ENTER__;
1568 net_err_t Error = NET_ERR_NONE;
1569 DBusConnection* conn = NULL;
1570 DBusMessage *message = NULL;
1572 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1575 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't get on system bus\n");
1576 __NETWORK_FUNC_EXIT__;
1577 return NET_ERR_UNKNOWN;
1580 message = _net_invoke_dbus_method(CONNMAN_SERVICE, conn, WifiProfName->ProfileName,
1581 CONNMAN_SERVICE_INTERFACE, "Remove", &Error);
1583 if (message == NULL) {
1584 NETWORK_LOG(NETWORK_ERROR,
1585 "Error!!! Failed to Remove service(profile)\n");
1589 dbus_message_unref(message);
1591 dbus_connection_unref(conn);
1593 __NETWORK_FUNC_EXIT__;
1598 static int __net_telephony_add_profile(net_profile_info_t *ProfInfo, net_service_type_t network_type)
1600 __NETWORK_FUNC_ENTER__;
1602 net_err_t Error = NET_ERR_NONE;
1604 ProfInfo->ProfileInfo.Pdp.ServiceType = network_type;
1606 Error = _net_dbus_add_pdp_profile(ProfInfo);
1607 if (Error != NET_ERR_NONE) {
1608 NETWORK_LOG(NETWORK_HIGH, "_net_dbus_add_pdp_profile() failed\n");
1609 __NETWORK_FUNC_EXIT__;
1613 __NETWORK_FUNC_EXIT__;
1614 return NET_ERR_NONE;
1617 static int __net_telephony_modify_profile(const char *ProfileName,
1618 net_profile_info_t *ProfInfo, net_profile_info_t* exProfInfo)
1620 __NETWORK_FUNC_ENTER__;
1622 net_err_t Error = NET_ERR_NONE;
1623 net_profile_name_t telephony_profile;
1624 char connman_profile[NET_PROFILE_NAME_LEN_MAX+1] = "";
1626 g_strlcpy(connman_profile, ProfileName, NET_PROFILE_NAME_LEN_MAX+1);
1627 ProfInfo->ProfileInfo.Pdp.ServiceType = exProfInfo->ProfileInfo.Pdp.ServiceType;
1629 Error = __net_telephony_search_pdp_profile((char*)connman_profile, &telephony_profile);
1630 if (Error != NET_ERR_NONE) {
1631 NETWORK_LOG(NETWORK_HIGH, "__net_telephony_search_pdp_profile() failed\n");
1632 __NETWORK_FUNC_EXIT__;
1636 Error = _net_dbus_modify_pdp_profile(ProfInfo, (char*)telephony_profile.ProfileName);
1637 if (Error != NET_ERR_NONE) {
1638 NETWORK_LOG(NETWORK_HIGH, "_net_dbus_modify_pdp_profile() failed\n");
1639 __NETWORK_FUNC_EXIT__;
1643 __NETWORK_FUNC_EXIT__;
1648 static int __net_telephony_delete_profile(net_profile_name_t* PdpProfName)
1650 __NETWORK_FUNC_ENTER__;
1652 net_err_t Error = NET_ERR_NONE;
1653 DBusConnection* conn = NULL;
1654 DBusMessage *message = NULL;
1656 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1659 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't get on system bus\n");
1660 __NETWORK_FUNC_EXIT__;
1661 return NET_ERR_UNKNOWN;
1664 message = _net_invoke_dbus_method(TELEPHONY_SERVCE, conn, PdpProfName->ProfileName,
1665 TELEPHONY_PROFILE_INTERFACE, "RemoveProfile", &Error);
1667 if (message == NULL) {
1668 NETWORK_LOG(NETWORK_ERROR,
1669 "Error!!! Failed to Remove service(profile)\n");
1674 DBusMessageIter iter;
1675 int remove_result = 0;
1677 dbus_message_iter_init(message, &iter);
1678 if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_BOOLEAN) {
1679 dbus_message_iter_get_basic(&iter, &remove_result);
1680 NETWORK_LOG(NETWORK_HIGH, "Profile remove result : %d\n", remove_result);
1684 Error = NET_ERR_NONE;
1686 Error = NET_ERR_UNKNOWN;
1688 dbus_message_unref(message);
1691 dbus_connection_unref(conn);
1693 __NETWORK_FUNC_EXIT__;
1697 static int __net_extract_defult_device(DBusMessageIter* dict, net_device_t *device_type)
1699 __NETWORK_FUNC_ENTER__;
1701 net_err_t Error = NET_ERR_NONE;
1703 if (dict == NULL || device_type == NULL) {
1704 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid prarameter \n");
1705 __NETWORK_FUNC_EXIT__;
1706 return NET_ERR_INVALID_PARAM;
1709 *device_type = NET_DEVICE_UNKNOWN;
1711 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1712 DBusMessageIter keyValue, value;
1713 const char *key = NULL;
1714 const char *objPath = NULL;
1716 dbus_message_iter_recurse(dict, &keyValue);
1717 dbus_message_iter_get_basic(&keyValue, &key);
1719 if (strcmp(key, "DefaultTechnology") == 0) {
1720 dbus_message_iter_next(&keyValue);
1721 dbus_message_iter_recurse(&keyValue, &value);
1723 if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_STRING)
1726 dbus_message_iter_get_basic(&value, &objPath);
1727 if (objPath == NULL || strlen(objPath) == 0)
1730 if (strcmp(objPath, "wifi") == 0)
1731 *device_type = NET_DEVICE_WIFI;
1732 else if (strcmp(objPath, "cellular") == 0)
1733 *device_type = NET_DEVICE_CELLULAR;
1737 dbus_message_iter_next(dict);
1740 if (*device_type == NET_DEVICE_UNKNOWN)
1741 Error = NET_ERR_NO_SERVICE;
1743 __NETWORK_FUNC_EXIT__;
1747 static int __net_extract_defult_profile(DBusMessageIter* iter, net_profile_name_t *profile_name)
1749 __NETWORK_FUNC_ENTER__;
1751 net_err_t Error = NET_ERR_NONE;
1752 net_device_t device_type = NET_DEVICE_UNKNOWN;
1753 DBusMessageIter dict;
1754 const char net_suffix[] = "_1";
1755 char *suffix = NULL;
1756 const char *objPath = NULL;
1758 if (iter == NULL || profile_name == NULL) {
1759 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid prarameter \n");
1760 __NETWORK_FUNC_EXIT__;
1761 return NET_ERR_INVALID_PARAM;
1764 memset(profile_name, 0, sizeof(net_profile_name_t));
1766 dbus_message_iter_recurse(iter, &dict);
1767 Error = __net_extract_defult_device(&dict, &device_type);
1769 if (Error != NET_ERR_NONE) {
1770 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! There is no Default Technology\n");
1771 __NETWORK_FUNC_EXIT__;
1775 dbus_message_iter_recurse(iter, &dict);
1776 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1777 DBusMessageIter keyValue, array, value;
1778 const char *key = NULL;
1780 dbus_message_iter_recurse(&dict, &keyValue);
1781 dbus_message_iter_get_basic(&keyValue, &key);
1783 if (strcmp(key, "Services") == 0) {
1784 dbus_message_iter_next(&keyValue);
1785 dbus_message_iter_recurse(&keyValue, &array);
1787 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY) {
1788 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't get service list\n");
1789 __NETWORK_FUNC_EXIT__;
1790 return NET_ERR_NO_SERVICE;
1793 dbus_message_iter_recurse(&array, &value);
1795 while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_OBJECT_PATH) {
1796 dbus_message_iter_get_basic(&value, &objPath);
1798 if (device_type == NET_DEVICE_CELLULAR &&
1799 strstr(objPath, "/cellular_") != NULL) {
1801 suffix = strrchr(objPath, '_');
1803 if (strcmp(suffix, net_suffix) == 0) {
1807 } else if (device_type == NET_DEVICE_WIFI &&
1808 strstr(objPath, "/wifi_") != NULL)
1813 dbus_message_iter_next(&value);
1815 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't find default service\n");
1816 __NETWORK_FUNC_EXIT__;
1817 return NET_ERR_NO_SERVICE;
1819 dbus_message_iter_next(&dict);
1822 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't find default service\n");
1823 Error = NET_ERR_NO_SERVICE;
1826 if (Error == NET_ERR_NONE && objPath != NULL) {
1827 g_strlcpy(profile_name->ProfileName, objPath, NET_PROFILE_NAME_LEN_MAX);
1828 NETWORK_LOG(NETWORK_HIGH, "Default profile found : %s\n", profile_name->ProfileName);
1831 __NETWORK_FUNC_EXIT__;
1836 int _net_check_profile_name(const char* ProfileName)
1838 __NETWORK_FUNC_ENTER__;
1840 const char *profileHeader = "/profile/";
1844 if (ProfileName == NULL || strlen(ProfileName) <= strlen(profileHeader)) {
1845 NETWORK_LOG(NETWORK_ERROR, "Error!!! Profile name is invalid\n");
1846 __NETWORK_FUNC_EXIT__;
1847 return NET_ERR_INVALID_PARAM;
1850 stringLen = strlen(ProfileName);
1852 if (strncmp(profileHeader, ProfileName, strlen(profileHeader)) == 0) {
1853 for (i = 0;i < stringLen;i++) {
1854 if (isgraph(ProfileName[i]) == 0) {
1855 NETWORK_LOG(NETWORK_ERROR, "Error!!! Profile name is invalid\n");
1856 __NETWORK_FUNC_EXIT__;
1857 return NET_ERR_INVALID_PARAM;
1861 NETWORK_LOG(NETWORK_ERROR, "Error!!! Profile name is invalid\n");
1862 __NETWORK_FUNC_EXIT__;
1863 return NET_ERR_INVALID_PARAM;
1866 __NETWORK_FUNC_EXIT__;
1867 return NET_ERR_NONE;
1870 int _net_get_profile_list(net_device_t device_type, net_profile_info_t** profile_info, int* profile_count)
1872 __NETWORK_FUNC_ENTER__;
1874 net_err_t Error = NET_ERR_NONE;
1875 DBusConnection* conn = NULL;
1876 DBusMessage *message = NULL;
1878 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1880 NETWORK_LOG(NETWORK_EXCEPTION,
1881 "Error!!! Can't get on system bus\n");
1882 __NETWORK_FUNC_EXIT__;
1883 return NET_ERR_UNKNOWN;
1886 message = _net_invoke_dbus_method(CONNMAN_SERVICE, conn, CONNMAN_MANAGER_PATH,
1887 CONNMAN_MANAGER_INTERFACE, "GetProperties", &Error);
1888 if (message == NULL) {
1889 NETWORK_LOG(NETWORK_ERROR,
1890 "Error!!! Failed to get service(profile) list\n");
1891 dbus_connection_unref(conn);
1892 __NETWORK_FUNC_EXIT__;
1896 switch (device_type) {
1897 case NET_DEVICE_CELLULAR:
1898 case NET_DEVICE_WIFI:
1899 Error = __net_extract_services(message, device_type, profile_info, profile_count);
1902 Error = NET_ERR_UNKNOWN;
1906 NETWORK_LOG(NETWORK_HIGH, "Error = %d\n", Error);
1908 dbus_message_unref(message);
1909 dbus_connection_unref(conn);
1911 __NETWORK_FUNC_EXIT__;
1915 int _net_get_service_profile(net_service_type_t service_type, net_profile_name_t *profile_name)
1917 __NETWORK_FUNC_ENTER__;
1919 net_err_t Error = NET_ERR_NONE;
1920 DBusConnection* conn = NULL;
1921 DBusMessage *message = NULL;
1922 DBusMessageIter iter, dict;
1923 network_services_list_t service_info = {0,};
1926 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1928 NETWORK_LOG(NETWORK_EXCEPTION,
1929 "Error!!! Can't get on system bus\n");
1930 __NETWORK_FUNC_EXIT__;
1931 return NET_ERR_UNKNOWN;
1934 message = _net_invoke_dbus_method(CONNMAN_SERVICE, conn, CONNMAN_MANAGER_PATH,
1935 CONNMAN_MANAGER_INTERFACE, "GetProperties", &Error);
1936 if (message == NULL) {
1937 NETWORK_LOG(NETWORK_ERROR,
1938 "Error!!! Failed to get service(profile) list\n");
1939 dbus_connection_unref(conn);
1940 __NETWORK_FUNC_EXIT__;
1944 dbus_message_iter_init(message, &iter);
1945 dbus_message_iter_recurse(&iter, &dict);
1947 Error = __net_extract_mobile_services(message, &dict, &service_info, service_type);
1949 if (Error != NET_ERR_NONE)
1952 if (service_info.num_of_services > 0) {
1953 memcpy(profile_name->ProfileName, service_info.ProfileName[0], NET_PROFILE_NAME_LEN_MAX);
1954 (profile_name->ProfileName)[NET_PROFILE_NAME_LEN_MAX] = '\0';
1956 Error = NET_ERR_NO_SERVICE;
1958 for (i = 0;i < service_info.num_of_services;i++)
1959 NET_MEMFREE(service_info.ProfileName[i]);
1962 dbus_message_unref(message);
1963 dbus_connection_unref(conn);
1965 __NETWORK_FUNC_EXIT__;
1969 int _net_get_default_profile_info(net_profile_info_t *profile_info)
1971 __NETWORK_FUNC_ENTER__;
1973 net_err_t Error = NET_ERR_NONE;
1974 DBusConnection* conn = NULL;
1975 DBusMessage *message = NULL;
1976 DBusMessageIter iter;
1977 net_profile_name_t profile_name;
1978 const char *prof_name = NULL;
1980 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1982 NETWORK_LOG(NETWORK_EXCEPTION,
1983 "Error!!! Can't get on system bus\n");
1984 __NETWORK_FUNC_EXIT__;
1985 return NET_ERR_UNKNOWN;
1988 message = _net_invoke_dbus_method(CONNMAN_SERVICE, conn, CONNMAN_MANAGER_PATH,
1989 CONNMAN_MANAGER_INTERFACE, "GetProperties", &Error);
1990 if (message == NULL) {
1991 NETWORK_LOG(NETWORK_ERROR,
1992 "Error!!! Failed to get service(profile) list\n");
1993 dbus_connection_unref(conn);
1994 __NETWORK_FUNC_EXIT__;
1998 dbus_message_iter_init(message, &iter);
1999 Error = __net_extract_defult_profile(&iter, &profile_name);
2001 if (Error != NET_ERR_NONE)
2004 prof_name = (const char*)profile_name.ProfileName;
2005 Error = __net_get_profile_info(prof_name, profile_info);
2008 dbus_message_unref(message);
2009 dbus_connection_unref(conn);
2011 __NETWORK_FUNC_EXIT__;
2015 /*****************************************************************************
2016 * ConnMan Wi-Fi Client Interface Sync API Definition
2017 *****************************************************************************/
2020 EXPORT_API int net_add_profile(net_service_type_t network_type, net_profile_info_t *prof_info)
2022 net_err_t Error = NET_ERR_NONE;
2024 __NETWORK_FUNC_ENTER__;
2026 if (NetworkInfo.ClientEventCb == NULL) {
2027 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
2028 __NETWORK_FUNC_EXIT__;
2029 return NET_ERR_APP_NOT_REGISTERED;
2032 if (prof_info == NULL ||
2033 (network_type != NET_SERVICE_INTERNET &&
2034 network_type != NET_SERVICE_MMS &&
2035 network_type != NET_SERVICE_WAP)) {
2036 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Parameter\n");
2037 __NETWORK_FUNC_EXIT__;
2038 return NET_ERR_INVALID_PARAM;
2041 Error = __net_telephony_add_profile(prof_info, network_type);
2043 if (Error != NET_ERR_NONE) {
2044 NETWORK_LOG(NETWORK_ERROR, "Error!!! failed to add service(profile). Error [%s]\n",
2045 _net_print_error(Error));
2046 __NETWORK_FUNC_EXIT__;
2050 __NETWORK_FUNC_EXIT__;
2055 EXPORT_API int net_delete_profile(const char* profile_name)
2057 __NETWORK_FUNC_ENTER__;
2059 net_err_t Error = NET_ERR_NONE;
2060 net_profile_name_t pdp_prof_name;
2061 net_profile_name_t wifi_prof_name;
2062 net_profile_info_t prof_info;
2064 if (NetworkInfo.ClientEventCb == NULL) {
2065 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
2066 __NETWORK_FUNC_EXIT__;
2067 return NET_ERR_APP_NOT_REGISTERED;
2070 if (_net_check_profile_name(profile_name) != NET_ERR_NONE) {
2071 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Parameter\n");
2072 __NETWORK_FUNC_EXIT__;
2073 return NET_ERR_INVALID_PARAM;
2076 Error = __net_get_profile_info(profile_name, &prof_info);
2077 if (Error != NET_ERR_NONE) {
2078 NETWORK_LOG(NETWORK_ERROR,
2079 "Error!!! failed to get service(profile) information. Error [%s]\n",
2080 _net_print_error(Error));
2081 __NETWORK_FUNC_EXIT__;
2085 g_strlcpy(wifi_prof_name.ProfileName, profile_name, NET_PROFILE_NAME_LEN_MAX + 1);
2087 if (prof_info.profile_type == NET_DEVICE_WIFI) {
2088 Error = __net_wifi_delete_profile(&wifi_prof_name);
2089 if (Error != NET_ERR_NONE) {
2090 NETWORK_LOG(NETWORK_ERROR,
2091 "Error!!! failed to delete service(profile). Error [%s]\n",
2092 _net_print_error(Error));
2093 __NETWORK_FUNC_EXIT__;
2096 } else if (prof_info.profile_type == NET_DEVICE_CELLULAR) {
2097 Error = __net_telephony_search_pdp_profile(wifi_prof_name.ProfileName, &pdp_prof_name);
2098 if (Error != NET_ERR_NONE) {
2099 NETWORK_LOG(NETWORK_ERROR,
2100 "Error!!! failed to get service(profile) information. Error [%s]\n",
2101 _net_print_error(Error));
2102 __NETWORK_FUNC_EXIT__;
2106 Error = __net_telephony_delete_profile(&pdp_prof_name);
2107 if (Error != NET_ERR_NONE) {
2108 NETWORK_LOG(NETWORK_ERROR,
2109 "Error!!! failed to delete service(profile). Error [%s]\n",
2110 _net_print_error(Error));
2111 __NETWORK_FUNC_EXIT__;
2115 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Parameter\n");
2116 __NETWORK_FUNC_EXIT__;
2117 return NET_ERR_INVALID_PARAM;
2120 __NETWORK_FUNC_EXIT__;
2121 return NET_ERR_NONE;
2125 EXPORT_API int net_get_profile_info(const char *profile_name, net_profile_info_t *prof_info)
2127 __NETWORK_FUNC_ENTER__;
2129 net_err_t Error = NET_ERR_NONE;
2131 if (NetworkInfo.ClientEventCb == NULL) {
2132 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
2133 __NETWORK_FUNC_EXIT__;
2134 return NET_ERR_APP_NOT_REGISTERED;
2137 if (_net_check_profile_name(profile_name) != NET_ERR_NONE || prof_info == NULL) {
2138 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Parameter\n");
2139 __NETWORK_FUNC_EXIT__;
2140 return NET_ERR_INVALID_PARAM;
2143 Error = __net_get_profile_info(profile_name, prof_info);
2144 if (Error != NET_ERR_NONE)
2145 NETWORK_LOG(NETWORK_ERROR,
2146 "Error!!! failed to get service(profile) information. Error [%s]\n",
2147 _net_print_error(Error));
2149 __NETWORK_FUNC_EXIT__;
2154 EXPORT_API int net_modify_profile(const char* profile_name, net_profile_info_t* prof_info)
2156 __NETWORK_FUNC_ENTER__;
2158 net_err_t Error = NET_ERR_NONE;
2159 net_profile_info_t exProfInfo;
2161 if (NetworkInfo.ClientEventCb == NULL) {
2162 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
2163 __NETWORK_FUNC_EXIT__;
2164 return NET_ERR_APP_NOT_REGISTERED;
2167 Error = net_get_profile_info(profile_name, &exProfInfo);
2168 if (Error != NET_ERR_NONE) {
2169 NETWORK_LOG(NETWORK_ERROR,
2170 "Error!!! failed to get service(profile) information. Error [%s]\n",
2171 _net_print_error(Error));
2172 __NETWORK_FUNC_EXIT__;
2176 if (prof_info == NULL ||
2177 (exProfInfo.profile_type != NET_DEVICE_WIFI &&
2178 exProfInfo.profile_type != NET_DEVICE_CELLULAR)) {
2179 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Parameter\n");
2180 __NETWORK_FUNC_EXIT__;
2181 return NET_ERR_INVALID_PARAM;
2184 if (exProfInfo.profile_type == NET_DEVICE_WIFI)
2185 Error = __net_modify_wlan_profile_info(profile_name, prof_info, &exProfInfo);
2186 else if (exProfInfo.profile_type == NET_DEVICE_CELLULAR)
2187 Error = __net_telephony_modify_profile(profile_name, prof_info, &exProfInfo);
2189 if (Error != NET_ERR_NONE) {
2190 NETWORK_LOG(NETWORK_ERROR,
2191 "Error!!! failed to modify service(profile) information. Error [%s]\n",
2192 _net_print_error(Error));
2193 __NETWORK_FUNC_EXIT__;
2197 __NETWORK_FUNC_EXIT__;
2199 return NET_ERR_NONE;
2203 EXPORT_API int net_get_profile_list(net_device_t device_type, net_profile_info_t **profile_list, int *count)
2205 __NETWORK_FUNC_ENTER__;
2207 net_err_t Error = NET_ERR_NONE;
2208 int profile_count = 0;
2209 net_profile_info_t* profile_info = NULL;
2211 if (count == NULL) {
2212 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid Parameter\n");
2213 __NETWORK_FUNC_EXIT__;
2214 return NET_ERR_INVALID_PARAM;
2217 if (NetworkInfo.ClientEventCb == NULL) {
2218 NETWORK_LOG(NETWORK_ERROR, "Error!!! Application was not registered\n");
2219 __NETWORK_FUNC_EXIT__;
2220 return NET_ERR_APP_NOT_REGISTERED;
2223 if (device_type != NET_DEVICE_CELLULAR && device_type != NET_DEVICE_WIFI) {
2224 NETWORK_LOG(NETWORK_ERROR, "Error!!! Not Supported\n");
2225 __NETWORK_FUNC_EXIT__;
2226 return NET_ERR_NOT_SUPPORTED;
2229 Error = _net_get_profile_list(device_type, &profile_info, &profile_count);
2231 if (Error != NET_ERR_NONE) {
2232 NETWORK_LOG(NETWORK_ERROR,
2233 "Error!!! failed to get service(profile) list. Error [%s]\n",
2234 _net_print_error(Error));
2236 NET_MEMFREE(profile_info);
2238 __NETWORK_FUNC_EXIT__;
2241 *count = profile_count;
2242 *profile_list = profile_info;
2245 __NETWORK_FUNC_EXIT__;
2246 return NET_ERR_NONE;
2250 /*****************************************************************************
2251 * ConnMan Wi-Fi Client Interface Async Function Definition
2252 *****************************************************************************/
2256 #endif /* __cplusplus */