2 * Network Client Library
4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.tizenopensource.org/license
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.
24 #endif /* __cplusplus */
27 /*****************************************************************************
29 *****************************************************************************/
35 #include <dbus/dbus-glib.h>
36 #include <dbus/dbus.h>
37 #include <sys/types.h>
41 /*****************************************************************************
43 *****************************************************************************/
45 #include "network-internal.h"
46 #include "network-dbus-request.h"
48 /*****************************************************************************
50 *****************************************************************************/
52 #define DBUS_REPLY_TIMEOUT (120 * 1000)
54 /*****************************************************************************
55 * Local Functions Declaration
56 *****************************************************************************/
58 static int __net_error_string_to_enum(const char* error);
59 static int __net_netconfig_error_string_to_enum(const char* error);
60 static int _net_get_error_from_message(DBusMessage *message);
61 static int _net_get_error_from_netconfig_message(DBusMessage *message);
62 static void __net_open_connection_reply(DBusPendingCall *call, void *user_data);
63 static void __net_close_connection_reply(DBusPendingCall *call, void *user_data);
64 static void __net_wifi_power_reply(DBusPendingCall *call, void *user_data);
66 /*****************************************************************************
68 *****************************************************************************/
71 /*****************************************************************************
73 *****************************************************************************/
75 struct dbus_pending_call_data {
76 DBusPendingCall *pcall;
80 static struct dbus_pending_call_data network_dbus_pending_call_data = {
85 /*****************************************************************************
87 *****************************************************************************/
89 extern network_info_t NetworkInfo;
90 extern network_request_table_t request_table[NETWORK_REQUEST_TYPE_MAX];
93 /*****************************************************************************
95 *****************************************************************************/
97 /*****************************************************************************
98 * Local Functions Definition
99 *****************************************************************************/
101 static int __net_error_string_to_enum(const char* error)
103 NETWORK_LOG(NETWORK_HIGH, "Passed error value [%s]\n", error);
105 if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".NoReply"))
106 return NET_ERR_TIME_OUT;
107 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".Failed"))
108 return NET_ERR_UNKNOWN;
109 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".UnknownMethod"))
110 return NET_ERR_UNKNOWN_METHOD;
111 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".InvalidArguments"))
112 return NET_ERR_INVALID_PARAM;
113 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".PermissionDenied"))
114 return NET_ERR_ACCESS_DENIED;
115 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".PassphraseRequired"))
116 return NET_ERR_INVALID_OPERATION;
117 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".NotRegistered"))
118 return NET_ERR_INVALID_OPERATION;
119 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".NotUnique"))
120 return NET_ERR_INVALID_OPERATION;
121 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".NotSupported"))
122 return NET_ERR_NOT_SUPPORTED;
123 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".NotImplemented"))
124 return NET_ERR_NOT_SUPPORTED;
125 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".NotFound"))
126 return NET_ERR_NOT_SUPPORTED;
127 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".NoCarrier"))
128 return NET_ERR_NOT_SUPPORTED;
129 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".InProgress"))
130 return NET_ERR_IN_PROGRESS;
131 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".AlreadyExists"))
132 return NET_ERR_INVALID_OPERATION;
133 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".AlreadyEnabled"))
134 return NET_ERR_INVALID_OPERATION;
135 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".AlreadyDisabled"))
136 return NET_ERR_INVALID_OPERATION;
137 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".AlreadyConnected"))
138 return NET_ERR_ACTIVE_CONNECTION_EXISTS;
139 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".NotConnected"))
140 return NET_ERR_NO_ACTIVE_CONNECTIONS;
141 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".OperationAborted"))
142 return NET_ERR_OPERATION_ABORTED;
143 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".OperationTimeout"))
144 return NET_ERR_TIME_OUT;
145 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".InvalidService"))
146 return NET_ERR_NO_SERVICE;
147 else if (NULL != strstr(error, CONNMAN_ERROR_INTERFACE ".InvalidProperty"))
148 return NET_ERR_INVALID_OPERATION;
149 return NET_ERR_UNKNOWN;
152 static int __net_netconfig_error_string_to_enum(const char* error)
154 NETWORK_LOG(NETWORK_HIGH, "Passed error value [%s]\n", error);
157 return NET_ERR_UNKNOWN;
159 if (NULL != strstr(error, ".WifiDriverFailed"))
160 return NET_ERR_WIFI_DRIVER_FAILURE;
161 else if (NULL != strstr(error, ".SecurityRestricted"))
162 return NET_ERR_SECURITY_RESTRICTED;
163 return NET_ERR_UNKNOWN;
166 static int _net_get_error_from_message(DBusMessage *message)
168 __NETWORK_FUNC_ENTER__;
172 MessageType = dbus_message_get_type(message);
174 if (MessageType == DBUS_MESSAGE_TYPE_ERROR) {
175 const char* ptr = dbus_message_get_error_name(message);
176 NETWORK_LOG(NETWORK_ERROR, "Error!!! Error message received [%s]\n", ptr);
177 __NETWORK_FUNC_EXIT__;
178 return __net_error_string_to_enum(ptr);
181 __NETWORK_FUNC_EXIT__;
185 static int _net_get_error_from_netconfig_message(DBusMessage *message)
187 __NETWORK_FUNC_ENTER__;
191 MessageType = dbus_message_get_type(message);
193 if (MessageType == DBUS_MESSAGE_TYPE_ERROR) {
194 const char* ptr = dbus_message_get_error_name(message);
195 const char* err_msg = _net_get_string(message);
196 NETWORK_LOG(NETWORK_ERROR,
197 "Error!!! Error message received [%s] [%s]\n", ptr, err_msg);
198 __NETWORK_FUNC_EXIT__;
199 return __net_netconfig_error_string_to_enum(err_msg);
202 __NETWORK_FUNC_EXIT__;
206 static void __net_open_connection_reply(DBusPendingCall *call, void *user_data)
208 __NETWORK_FUNC_ENTER__;
210 NETWORK_LOG(NETWORK_LOW, "__net_open_connection_reply() called\n");
212 net_event_info_t event_data = {0,};
213 net_profile_info_t prof_info;
214 network_request_table_t *open_info = &request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION];
215 network_request_table_t *wps_info = &request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS];
217 DBusMessage *reply = dbus_pending_call_steal_reply(call);
218 net_err_t Error = _net_get_error_from_message(reply);
220 if (Error == NET_ERR_NONE)
223 NETWORK_LOG(NETWORK_ERROR,
224 "Error!!! Connection open failed. Error code : [%d]\n", Error);
226 if (open_info->flag == TRUE) {
227 net_device_t device_type = _net_get_tech_type_from_path(open_info->ProfileName);
229 if (Error == NET_ERR_IN_PROGRESS &&
230 device_type == NET_DEVICE_CELLULAR)
233 snprintf(event_data.ProfileName,
234 NET_PROFILE_NAME_LEN_MAX + 1, "%s",
235 open_info->ProfileName);
237 memset(open_info, 0, sizeof(network_request_table_t));
239 event_data.Error = Error;
241 if (Error == NET_ERR_ACTIVE_CONNECTION_EXISTS) {
242 Error = net_get_profile_info(event_data.ProfileName, &prof_info);
244 if (device_type == NET_DEVICE_CELLULAR)
245 event_data.Error = NET_ERR_NONE;
247 if (Error != NET_ERR_NONE) {
248 NETWORK_LOG(NETWORK_ERROR,
249 "Error!!! net_get_profile_info() failed [%s]\n",
250 _net_print_error(Error));
251 event_data.Datalength = 0;
252 event_data.Data = NULL;
254 event_data.Datalength = sizeof(net_profile_info_t);
255 event_data.Data = &prof_info;
259 event_data.Event = NET_EVENT_OPEN_RSP;
260 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_OPEN_RSP Error = %s\n",
261 _net_print_error(event_data.Error));
262 _net_client_callback(&event_data);
263 } else if (wps_info->flag == TRUE) {
265 snprintf(event_data.ProfileName,
266 NET_PROFILE_NAME_LEN_MAX + 1, "%s",
267 wps_info->ProfileName);
269 memset(wps_info, 0, sizeof(network_request_table_t));
271 event_data.Error = Error;
273 if (Error == NET_ERR_ACTIVE_CONNECTION_EXISTS) {
274 Error = net_get_profile_info(event_data.ProfileName, &prof_info);
275 if (Error != NET_ERR_NONE) {
276 NETWORK_LOG(NETWORK_ERROR,
277 "Error!!! net_get_profile_info() failed [%s]\n",
278 _net_print_error(Error));
279 event_data.Datalength = 0;
280 event_data.Data = NULL;
282 event_data.Datalength = sizeof(net_profile_info_t);
283 event_data.Data = &prof_info;
287 event_data.Event = NET_EVENT_WIFI_WPS_RSP;
289 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_WIFI_WPS_RSP Error = %s\n",
290 _net_print_error(event_data.Error));
291 _net_client_callback(&event_data);
295 dbus_message_unref(reply);
296 dbus_pending_call_unref(call);
298 network_dbus_pending_call_data.is_used = FALSE;
299 network_dbus_pending_call_data.pcall = NULL;
301 __NETWORK_FUNC_EXIT__;
304 static void __net_close_connection_reply(DBusPendingCall *call, void *user_data)
306 __NETWORK_FUNC_ENTER__;
308 NETWORK_LOG(NETWORK_LOW, "__net_close_connection_reply() called\n");
310 net_event_info_t event_data = {0,};
311 network_request_table_t *close_info = &request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION];
313 DBusMessage *reply = dbus_pending_call_steal_reply(call);
314 net_err_t Error = _net_get_error_from_message(reply);
316 if (Error == NET_ERR_NONE)
319 NETWORK_LOG(NETWORK_ERROR,
320 "Error!!! Connection close failed. Error code : [%d]\n", Error);
322 if (close_info->flag == TRUE) {
323 net_device_t device_type = _net_get_tech_type_from_path(close_info->ProfileName);
325 if (Error == NET_ERR_ACTIVE_CONNECTION_EXISTS &&
326 device_type == NET_DEVICE_CELLULAR)
327 Error = NET_ERR_NONE;
329 snprintf(event_data.ProfileName,
330 NET_PROFILE_NAME_LEN_MAX + 1, "%s",
331 close_info->ProfileName);
333 memset(close_info, 0, sizeof(network_request_table_t));
335 event_data.Error = Error;
336 event_data.Datalength = 0;
337 event_data.Data = NULL;
338 event_data.Event = NET_EVENT_CLOSE_RSP;
339 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_CLOSE_RSP Error = %s\n",
340 _net_print_error(event_data.Error));
341 _net_client_callback(&event_data);
345 dbus_message_unref(reply);
346 dbus_pending_call_unref(call);
348 network_dbus_pending_call_data.is_used = FALSE;
349 network_dbus_pending_call_data.pcall = NULL;
351 __NETWORK_FUNC_EXIT__;
354 static void __net_wifi_power_reply(DBusPendingCall *call, void *user_data)
356 __NETWORK_FUNC_ENTER__;
358 NETWORK_LOG(NETWORK_LOW, "__net_wifi_power_reply() called\n");
360 DBusMessage *reply = dbus_pending_call_steal_reply(call);
361 net_err_t Error = _net_get_error_from_netconfig_message(reply);
362 net_event_info_t event_data = {0,};
364 if (Error != NET_ERR_NONE)
365 NETWORK_LOG(NETWORK_ERROR, "Error!!! Wifi Power on/off failed. Error code : [%d]\n", Error);
367 if (request_table[NETWORK_REQUEST_TYPE_WIFI_POWER].flag == TRUE) {
368 memset(&request_table[NETWORK_REQUEST_TYPE_WIFI_POWER],
369 0, sizeof(network_request_table_t));
371 event_data.Event = NET_EVENT_WIFI_POWER_RSP;
372 NETWORK_LOG(NETWORK_LOW,
373 "Sending NET_EVENT_WIFI_POWER_RSP wifi state : %d Error = %d\n",
374 NetworkInfo.wifi_state, Error);
376 event_data.Datalength = sizeof(net_wifi_state_t);
377 event_data.Data = &(NetworkInfo.wifi_state);
378 event_data.Error = Error;
379 _net_client_callback(&event_data);
382 dbus_message_unref(reply);
383 dbus_pending_call_unref(call);
385 network_dbus_pending_call_data.is_used = FALSE;
386 network_dbus_pending_call_data.pcall = NULL;
388 __NETWORK_FUNC_EXIT__;
391 static void __net_specific_scan_wifi_reply(DBusPendingCall *call, void *user_data)
393 __NETWORK_FUNC_ENTER__;
395 DBusMessage *reply = dbus_pending_call_steal_reply(call);
396 net_err_t Error = _net_get_error_from_netconfig_message(reply);
398 if (Error != NET_ERR_NONE)
399 NETWORK_LOG(NETWORK_ERROR, "Error!!! Find hidden AP failed. Error code : [%d]\n", Error);
401 NETWORK_LOG(NETWORK_LOW, "Hidden AP response received for AP.\n");
403 if (request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].flag == TRUE) {
404 net_event_info_t event_data = {0,};
405 if (NET_ERR_NONE != Error) {
406 /* An error occured. So lets reset specific scan request entry in the request table */
407 memset(&request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN],
408 0, sizeof(network_request_table_t));
410 event_data.Event = NET_EVENT_SPECIFIC_SCAN_RSP;
411 NETWORK_LOG(NETWORK_LOW,
412 "Sending NET_EVENT_SPECIFIC_SCAN_RSP wifi state : %d Error = %d\n",
413 NetworkInfo.wifi_state, Error);
415 event_data.Datalength = sizeof(net_wifi_state_t);
416 event_data.Data = &(NetworkInfo.wifi_state);
417 event_data.Error = Error;
418 _net_client_callback(&event_data);
421 dbus_message_unref(reply);
422 dbus_pending_call_unref(call);
424 network_dbus_pending_call_data.is_used = FALSE;
425 network_dbus_pending_call_data.pcall = NULL;
427 __NETWORK_FUNC_EXIT__;
430 static char *__net_make_group_name(const char *ssid, const char *net_mode, const char *sec)
434 char buf_tmp[32] = {0,};
438 if (ssid == NULL || net_mode == NULL || sec == NULL)
441 ssid_len = strlen(ssid);
445 if (g_strcmp0(net_mode, "managed") != 0)
448 if (!g_strcmp0(sec, "wpa") || !g_strcmp0(sec, "rsn"))
453 buf = g_try_malloc0((ssid_len * 2) + strlen(net_mode) + strlen(sec) + 3);
457 for (i = 0; i < ssid_len; i++) {
458 snprintf(buf_tmp, 3, "%02x", ssid[i]);
459 strcat(buf, buf_tmp);
462 snprintf(buf_tmp, 32, "_%s_%s", net_mode, g_sec);
463 strcat(buf, buf_tmp);
465 NETWORK_LOG(NETWORK_HIGH, "Group name : %s\n", buf);
470 static int __net_append_param(DBusMessage *message, char *param_array[])
473 dbus_uint32_t uint32 = 0;
474 DBusMessageIter iter;
475 DBusMessageIter container_iter;
479 if (param_array == NULL)
482 dbus_message_iter_init_append(message, &iter);
484 while (param_array[count] != NULL) {
485 args = param_array[count];
486 NETWORK_LOG(NETWORK_HIGH, "parameter %d - [%s]", count, param_array[count]);
488 ch = strchr(args, ':');
490 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid parameter[\"%s\"]\n", args);
491 return NET_ERR_INVALID_PARAM;
495 if (strcmp(args, CONNMAN_CLIENT_DBUS_TYPE_STRING) == 0) {
496 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &ch);
497 } else if (strcmp(args, CONNMAN_CLIENT_DBUS_TYPE_UINT32) == 0) {
498 uint32 = strtoul(ch, NULL, 0);
499 dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &uint32);
500 } else if (strcmp(args, CONNMAN_CLIENT_DBUS_TYPE_VARIANT) == 0) {
502 ch = strchr(args, ':');
504 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid data format[\"%s\"]\n", args);
505 return NET_ERR_INVALID_PARAM;
509 if (strcmp(args, CONNMAN_CLIENT_DBUS_TYPE_STRING) == 0) {
510 dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
511 DBUS_TYPE_STRING_AS_STRING, &container_iter);
512 dbus_message_iter_append_basic(&container_iter, DBUS_TYPE_STRING, &ch);
513 dbus_message_iter_close_container(&iter, &container_iter);
515 NETWORK_LOG(NETWORK_ERROR, "Error!!! Not supported data format[\"%s\"]\n", args);
516 return NET_ERR_INVALID_PARAM;
519 NETWORK_LOG(NETWORK_ERROR, "Error!!! Not supported data format[\"%s\"]\n", args);
520 return NET_ERR_INVALID_PARAM;
528 /*****************************************************************************
529 * Global Functions Definition
530 *****************************************************************************/
532 DBusMessage *_net_invoke_dbus_method(const char* dest, const char* path,
533 char* interface_name, char* method, char *param_array[], int *dbus_error)
535 __NETWORK_FUNC_ENTER__;
538 DBusConnection* conn = NULL;
539 DBusMessage *reply = NULL;
540 DBusMessage *message = NULL;
542 *dbus_error = NET_ERR_NONE;
544 NETWORK_LOG(NETWORK_HIGH, "[DBUS Sync] %s.%s, %s\n", interface_name, method, path);
546 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
548 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't get on system bus\n");
549 *dbus_error = NET_ERR_UNKNOWN;
550 __NETWORK_FUNC_EXIT__;
554 message = dbus_message_new_method_call(dest, path, interface_name, method);
555 if (message == NULL) {
556 NETWORK_LOG(NETWORK_ERROR, "Error!!! dbus_message_new_method_call() failed\n");
557 dbus_connection_unref(conn);
558 *dbus_error = NET_ERR_UNKNOWN;
559 __NETWORK_FUNC_EXIT__;
563 if (__net_append_param(message, param_array) != NET_ERR_NONE) {
564 NETWORK_LOG(NETWORK_ERROR, "Error!!! __net_append_param() failed\n");
565 dbus_message_unref(message);
566 dbus_connection_unref(conn);
567 *dbus_error = NET_ERR_INVALID_PARAM;
568 __NETWORK_FUNC_EXIT__;
572 dbus_error_init(&error);
574 reply = dbus_connection_send_with_reply_and_block(conn, message, DBUS_REPLY_TIMEOUT, &error);
576 if (dbus_error_is_set(&error) == TRUE) {
577 NETWORK_LOG(NETWORK_ERROR,
578 "Error!!! dbus_connection_send_with_reply_and_block() failed. dbus error [%s: %s]\n",
579 error.name, error.message);
580 *dbus_error = __net_error_string_to_enum(error.name);
581 dbus_error_free(&error);
583 NETWORK_LOG(NETWORK_ERROR, "Error!!! dbus_connection_send_with_reply_and_block() failed\n");
584 *dbus_error = NET_ERR_UNKNOWN;
587 dbus_message_unref(message);
588 dbus_connection_unref(conn);
589 __NETWORK_FUNC_EXIT__;
593 dbus_message_unref(message);
594 dbus_connection_unref(conn);
596 __NETWORK_FUNC_EXIT__;
600 int _net_invoke_dbus_method_nonblock(const char* dest, const char* path,
601 char* interface_name, char* method, DBusPendingCallNotifyFunction notify_func)
603 __NETWORK_FUNC_ENTER__;
605 DBusConnection* conn = NULL;
606 DBusMessage *message = NULL;
607 DBusPendingCall *call;
610 NETWORK_LOG(NETWORK_HIGH, "[DBUS Async] %s.%s, %s\n", interface_name, method, path);
612 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
614 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't get on system bus\n");
615 __NETWORK_FUNC_EXIT__;
616 return NET_ERR_UNKNOWN;
619 message = dbus_message_new_method_call(dest, path, interface_name, method);
620 if (message == NULL) {
621 NETWORK_LOG(NETWORK_ERROR, "Error!!! dbus_message_new_method_call() Failed\n");
622 dbus_connection_unref(conn);
623 __NETWORK_FUNC_EXIT__;
624 return NET_ERR_UNKNOWN;
627 result = dbus_connection_send_with_reply(conn, message, &call, DBUS_REPLY_TIMEOUT);
629 if (result == FALSE || call == NULL) {
630 NETWORK_LOG(NETWORK_ERROR, "Error!!! dbus_connection_send_with_reply() Failed\n");
631 dbus_message_unref(message);
632 dbus_connection_unref(conn);
633 return NET_ERR_UNKNOWN;
636 dbus_pending_call_set_notify(call, notify_func, NULL, NULL);
637 network_dbus_pending_call_data.pcall = call;
638 network_dbus_pending_call_data.is_used = TRUE;
640 dbus_message_unref(message);
641 dbus_connection_unref(conn);
643 __NETWORK_FUNC_EXIT__;
647 int _net_dbus_open_connection(const char* profile_name)
649 __NETWORK_FUNC_ENTER__;
651 net_err_t Error = NET_ERR_NONE;
653 Error = _net_invoke_dbus_method_nonblock(CONNMAN_SERVICE, profile_name,
654 CONNMAN_SERVICE_INTERFACE, "Connect", __net_open_connection_reply);
656 __NETWORK_FUNC_EXIT__;
660 int _net_dbus_close_connection(const char* profile_name)
662 __NETWORK_FUNC_ENTER__;
664 net_err_t Error = NET_ERR_NONE;
666 Error = _net_invoke_dbus_method_nonblock(CONNMAN_SERVICE, profile_name,
667 CONNMAN_SERVICE_INTERFACE, "Disconnect", __net_close_connection_reply);
669 __NETWORK_FUNC_EXIT__;
673 int _net_dbus_scan_request(void)
675 __NETWORK_FUNC_ENTER__;
677 net_err_t Error = NET_ERR_NONE;
678 DBusMessage *message = NULL;
680 char param1[] = "string:wifi";
681 char path[CONNMAN_MAX_BUFLEN] = "/";
682 char* param_array[] = {NULL, NULL};
684 param_array[0] = param1;
686 message = _net_invoke_dbus_method(CONNMAN_SERVICE, path,
687 CONNMAN_MANAGER_INTERFACE, "RequestScan", param_array, &Error);
689 if (Error == NET_ERR_IN_PROGRESS)
690 Error = NET_ERR_NONE;
692 if (Error != NET_ERR_NONE)
693 NETWORK_LOG(NETWORK_ERROR, "Error!!! _net_invoke_dbus_method failed\n");
696 dbus_message_unref(message);
698 __NETWORK_FUNC_EXIT__;
702 int _net_dbus_set_bgscan_mode(net_wifi_background_scan_mode_t mode)
704 __NETWORK_FUNC_ENTER__;
706 net_err_t Error = NET_ERR_NONE;
707 DBusMessage *message = NULL;
709 char param1[64] = "";
710 char path[CONNMAN_MAX_BUFLEN] = NETCONFIG_WIFI_PATH;
711 char* param_array[] = {NULL, NULL};
713 snprintf(param1, 64, "uint32:%d", mode);
714 param_array[0] = param1;
716 message = _net_invoke_dbus_method(NETCONFIG_SERVICE, path,
717 NETCONFIG_WIFI_INTERFACE, "SetBgscan", param_array, &Error);
719 if (Error != NET_ERR_NONE)
720 NETWORK_LOG(NETWORK_ERROR, "Error!!! _net_invoke_dbus_method failed\n");
723 dbus_message_unref(message);
725 __NETWORK_FUNC_EXIT__;
729 int _net_dbus_get_technology_state(network_get_tech_state_info_t* tech_state)
731 __NETWORK_FUNC_ENTER__;
733 net_err_t Error = NET_ERR_NONE;
734 DBusMessage *message = NULL;
736 if ((tech_state == NULL) || (strlen(tech_state->technology) == 0)) {
737 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Invalid parameter\n");
738 __NETWORK_FUNC_EXIT__;
739 return NET_ERR_INVALID_PARAM;
742 if (strcmp(tech_state->technology, "wifi") == 0) {
743 int hotspot_state = 0;
744 vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &hotspot_state);
746 if (hotspot_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
750 message = _net_invoke_dbus_method(CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
751 CONNMAN_MANAGER_INTERFACE, "GetProperties", NULL, &Error);
753 if (message == NULL) {
754 NETWORK_LOG(NETWORK_ERROR, "Error!!! Failed to get technology info\n");
758 Error = _net_get_tech_state(message, tech_state);
760 NETWORK_LOG(NETWORK_HIGH,
762 "AvailableTechnology [%d]\n"
763 "EnabledTechnology [%d]\n"
764 "ConnectedTechnology [%d]\n"
765 "DefaultTechnology [%d]\n",
766 tech_state->technology,
767 tech_state->AvailableTechnology,
768 tech_state->EnabledTechnology,
769 tech_state->ConnectedTechnology,
770 tech_state->DefaultTechnology);
772 dbus_message_unref(message);
775 __NETWORK_FUNC_EXIT__;
779 int _net_dbus_get_network_status(net_device_t device_type, net_cm_network_status_t* network_status)
781 __NETWORK_FUNC_ENTER__;
783 net_err_t Error = NET_ERR_NONE;
784 network_get_tech_state_info_t tech_state = {{0,},};
786 if (device_type == NET_DEVICE_WIFI)
787 snprintf(tech_state.technology, NET_TECH_LENGTH_MAX, "%s", "wifi");
788 else if (device_type == NET_DEVICE_CELLULAR)
789 snprintf(tech_state.technology, NET_TECH_LENGTH_MAX, "%s", "cellular");
791 Error = NET_ERR_INVALID_PARAM;
795 Error = _net_dbus_get_technology_state(&tech_state);
796 if (Error != NET_ERR_NONE) {
797 NETWORK_LOG(NETWORK_ERROR,
798 "Error!!! _net_dbus_get_technology_state() failed. Error [%s]\n",
799 _net_print_error(Error));
803 if (tech_state.ConnectedTechnology == TRUE)
804 *network_status = NET_STATUS_AVAILABLE;
806 *network_status = NET_STATUS_UNAVAILABLE;
809 __NETWORK_FUNC_EXIT__;
813 int _net_dbus_get_statistics(net_device_t device_type, net_statistics_type_e statistics_type, unsigned long long *size)
815 net_err_t Error = NET_ERR_NONE;
816 DBusMessage *message = NULL;
819 if (device_type == NET_DEVICE_WIFI) {
820 switch (statistics_type) {
821 case NET_STATISTICS_TYPE_LAST_RECEIVED_DATA:
822 method = "GetWifiLastRxBytes";
824 case NET_STATISTICS_TYPE_LAST_SENT_DATA:
825 method = "GetWifiLastTxBytes";
827 case NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
828 method = "GetWifiTotalRxBytes";
830 case NET_STATISTICS_TYPE_TOTAL_SENT_DATA:
831 method = "GetWifiTotalTxBytes";
834 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid ProfileName passed\n");
835 return NET_ERR_INVALID_PARAM;
838 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid ProfileName passed\n");
839 return NET_ERR_INVALID_PARAM;
842 message = _net_invoke_dbus_method(
843 NETCONFIG_SERVICE, NETCONFIG_STATISTICS_PATH,
844 NETCONFIG_STATISTICS_INTERFACE, method, NULL, &Error);
845 if (message == NULL) {
846 NETWORK_LOG(NETWORK_ERROR, "Error!!! Failed to get service properties\n");
850 *size = _net_get_uint64(message);
852 NETWORK_LOG(NETWORK_HIGH, "success [%s] statistics size : [%llu]\n", method, *size);
853 dbus_message_unref(message);
858 int _net_dbus_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type)
860 net_err_t Error = NET_ERR_NONE;
861 DBusMessage *message = NULL;
864 if (device_type == NET_DEVICE_CELLULAR) {
865 switch (statistics_type) {
866 case NET_STATISTICS_TYPE_LAST_RECEIVED_DATA:
867 method = "ResetCellularLastRxBytes";
869 case NET_STATISTICS_TYPE_LAST_SENT_DATA:
870 method = "ResetCellularLastTxBytes";
872 case NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
873 method = "ResetCellularTotalRxBytes";
875 case NET_STATISTICS_TYPE_TOTAL_SENT_DATA:
876 method = "ResetCellularTotalTxBytes";
879 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid ProfileName passed\n");
880 return NET_ERR_INVALID_PARAM;
882 } else if (device_type == NET_DEVICE_WIFI) {
883 switch (statistics_type) {
884 case NET_STATISTICS_TYPE_LAST_RECEIVED_DATA:
885 method = "ResetWifiLastRxBytes";
887 case NET_STATISTICS_TYPE_LAST_SENT_DATA:
888 method = "ResetWifiLastTxBytes";
890 case NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
891 method = "ResetWifiTotalRxBytes";
893 case NET_STATISTICS_TYPE_TOTAL_SENT_DATA:
894 method = "ResetWifiTotalTxBytes";
897 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid ProfileName passed\n");
898 return NET_ERR_INVALID_PARAM;
901 NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid ProfileName passed\n");
902 return NET_ERR_INVALID_PARAM;
905 message = _net_invoke_dbus_method(
906 NETCONFIG_SERVICE, NETCONFIG_STATISTICS_PATH,
907 NETCONFIG_STATISTICS_INTERFACE, method, NULL, &Error);
908 if (message == NULL) {
909 NETWORK_LOG(NETWORK_ERROR, "Error!!! Failed to get service properties\n");
913 NETWORK_LOG(NETWORK_HIGH, "reset [%s] statistics success\n", method);
914 dbus_message_unref(message);
919 int _net_dbus_get_state(char* state)
921 __NETWORK_FUNC_ENTER__;
923 net_err_t Error = NET_ERR_NONE;
924 DBusMessage *message = NULL;
925 char *net_state = NULL;
927 message = _net_invoke_dbus_method(
928 CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
929 CONNMAN_MANAGER_INTERFACE, "GetState", NULL, &Error);
930 if (message == NULL) {
931 NETWORK_LOG(NETWORK_ERROR, "Error!!! Failed to get service properties\n");
932 __NETWORK_FUNC_EXIT__;
936 net_state = _net_get_string(message);
937 snprintf(state, strlen(net_state)+1, "%s", net_state);
939 NETWORK_LOG( NETWORK_HIGH, "State : [%s]\n", state);
941 dbus_message_unref(message);
943 __NETWORK_FUNC_EXIT__;
947 int _net_dbus_connect_service(const net_wifi_connect_service_info_t *wifi_connection_info)
949 __NETWORK_FUNC_ENTER__;
951 net_err_t Error = NET_ERR_NONE;
953 const char *prop_type = "Type";
954 const char *prop_mode = "Mode";
955 const char *prop_ssid = "SSID";
956 const char *prop_security = "Security";
957 const char *prop_passphrase = "Passphrase";
958 const char *prop_eap_type = "EAPType";
959 const char *prop_eap_auth = "EAPAuth";
960 const char *prop_identity = "Identity";
961 const char *prop_password = "Password";
962 const char *prop_ca_cert_file = "CACert";
963 const char *prop_client_cert_file = "ClientCert";
964 const char *prop_private_key_file = "PrivateKeyFile";
965 const char *prop_private_key_password = "PrivateKeyPassword";
967 DBusMessage* message = NULL;
968 DBusMessageIter dict, entry, array, value;
969 DBusConnection* conn = NULL;
970 DBusPendingCall *call;
972 char *group_name = NULL;
974 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
976 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't get on system bus\n");
977 __NETWORK_FUNC_EXIT__;
978 return NET_ERR_UNKNOWN;
981 message = dbus_message_new_method_call(CONNMAN_SERVICE, CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, "ConnectService");
983 if (message == NULL) {
984 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! dbus_message_new_method_call() failed\n");
985 __NETWORK_FUNC_EXIT__;
986 return NET_ERR_UNKNOWN;
989 dbus_message_iter_init_append(message, &array);
990 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY, "{sv}", &dict);
992 if (wifi_connection_info->type != NULL) {
993 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
994 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_type);
995 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
996 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &wifi_connection_info->type);
997 dbus_message_iter_close_container(&entry, &value);
998 dbus_message_iter_close_container(&dict, &entry);
1001 if (wifi_connection_info->mode != NULL) {
1002 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
1003 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_mode);
1004 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
1005 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &wifi_connection_info->mode);
1006 dbus_message_iter_close_container(&entry, &value);
1007 dbus_message_iter_close_container(&dict, &entry);
1010 if (wifi_connection_info->ssid != NULL) {
1011 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
1012 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_ssid);
1013 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
1014 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &wifi_connection_info->ssid);
1015 dbus_message_iter_close_container(&entry, &value);
1016 dbus_message_iter_close_container(&dict, &entry);
1019 if (wifi_connection_info->security != NULL) {
1020 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
1021 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_security);
1022 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
1023 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &wifi_connection_info->security);
1024 dbus_message_iter_close_container(&entry, &value);
1025 dbus_message_iter_close_container(&dict, &entry);
1028 if (g_str_equal(wifi_connection_info->security, "ieee8021x") == TRUE) {
1030 if (wifi_connection_info->eap_type != NULL) {
1031 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
1032 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_eap_type);
1033 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
1034 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &wifi_connection_info->eap_type);
1035 dbus_message_iter_close_container(&entry, &value);
1036 dbus_message_iter_close_container(&dict, &entry);
1039 if (wifi_connection_info->eap_auth != NULL) {
1040 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
1041 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_eap_auth);
1042 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
1043 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &wifi_connection_info->eap_auth);
1044 dbus_message_iter_close_container(&entry, &value);
1045 dbus_message_iter_close_container(&dict, &entry);
1048 if (wifi_connection_info->identity != NULL) {
1049 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
1050 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_identity);
1051 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
1052 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &wifi_connection_info->identity);
1053 dbus_message_iter_close_container(&entry, &value);
1054 dbus_message_iter_close_container(&dict, &entry);
1057 if (wifi_connection_info->password != NULL) {
1058 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
1059 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_password);
1060 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
1061 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &wifi_connection_info->password);
1062 dbus_message_iter_close_container(&entry, &value);
1063 dbus_message_iter_close_container(&dict, &entry);
1066 if (wifi_connection_info->ca_cert_file != NULL) {
1067 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
1068 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_ca_cert_file);
1069 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
1070 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &wifi_connection_info->ca_cert_file);
1071 dbus_message_iter_close_container(&entry, &value);
1072 dbus_message_iter_close_container(&dict, &entry);
1075 if (wifi_connection_info->client_cert_file != NULL) {
1076 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
1077 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_client_cert_file);
1078 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
1079 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &wifi_connection_info->client_cert_file);
1080 dbus_message_iter_close_container(&entry, &value);
1081 dbus_message_iter_close_container(&dict, &entry);
1084 if (wifi_connection_info->private_key_file != NULL) {
1085 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
1086 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_private_key_file);
1087 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
1088 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &wifi_connection_info->private_key_file);
1089 dbus_message_iter_close_container(&entry, &value);
1090 dbus_message_iter_close_container(&dict, &entry);
1093 if (wifi_connection_info->private_key_password != NULL) {
1094 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
1095 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_private_key_password);
1096 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
1097 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &wifi_connection_info->private_key_password);
1098 dbus_message_iter_close_container(&entry, &value);
1099 dbus_message_iter_close_container(&dict, &entry);
1102 /** none, wep, psk, rsn */
1103 if (wifi_connection_info->passphrase != NULL) {
1104 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
1105 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_passphrase);
1106 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
1107 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &wifi_connection_info->passphrase);
1108 dbus_message_iter_close_container(&entry, &value);
1109 dbus_message_iter_close_container(&dict, &entry);
1113 dbus_message_iter_close_container(&array, &dict);
1115 group_name = __net_make_group_name(wifi_connection_info->ssid,
1116 wifi_connection_info->mode, wifi_connection_info->security);
1117 if (group_name == NULL) {
1118 NETWORK_LOG(NETWORK_ERROR, "Error!!! can't make a group name\n");
1119 dbus_message_unref(message);
1120 __NETWORK_FUNC_EXIT__;
1121 return NET_ERR_UNKNOWN;
1124 snprintf(request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].ProfileName,
1125 NET_PROFILE_NAME_LEN_MAX+1, "%s", group_name);
1127 result = dbus_connection_send_with_reply(conn, message, &call, 6 * DBUS_REPLY_TIMEOUT);
1129 if (result == FALSE || call == NULL) {
1130 NETWORK_LOG(NETWORK_ERROR, "Error!!! dbus_connection_send_with_reply() Failed\n");
1131 dbus_message_unref(message);
1132 __NETWORK_FUNC_EXIT__;
1133 return NET_ERR_UNKNOWN;
1136 dbus_pending_call_set_notify(call, __net_open_connection_reply, NULL, NULL);
1137 network_dbus_pending_call_data.pcall = call;
1138 network_dbus_pending_call_data.is_used = TRUE;
1140 dbus_message_unref(message);
1142 NETWORK_LOG(NETWORK_HIGH, "Successfully configured\n");
1144 dbus_connection_unref(conn);
1145 __NETWORK_FUNC_EXIT__;
1149 int _net_dbus_set_profile_ipv4(net_profile_info_t* prof_info, char* profile_name)
1151 __NETWORK_FUNC_ENTER__;
1153 net_err_t Error = NET_ERR_NONE;
1155 const char *manual_method = "manual";
1156 const char *dhcp_method = "dhcp";
1157 const char *off_method = "off";
1159 const char *prop_ipv4_configuration = "IPv4.Configuration";
1160 const char *prop_method = "Method";
1161 const char *prop_address = "Address";
1162 const char *prop_gateway = "Gateway";
1163 const char *prop_netmask = "Netmask";
1165 char ip_buffer[NETPM_IPV4_STR_LEN_MAX+1] = "";
1166 char netmask_buffer[NETPM_IPV4_STR_LEN_MAX+1] = "";
1167 char gateway_buffer[NETPM_IPV4_STR_LEN_MAX+1] = "";
1169 char *ipaddress = ip_buffer;
1170 char *netmask = netmask_buffer;
1171 char *gateway = gateway_buffer;
1173 DBusMessage *message = NULL;
1174 DBusMessage *reply = NULL;
1175 DBusMessageIter itr, variant, dict, entry;
1176 DBusConnection* conn = NULL;
1178 if ((prof_info == NULL) || (profile_name == NULL) || (strlen(profile_name) == 0)) {
1179 NETWORK_LOG(NETWORK_ASSERT, "Error!!! Invalid argument\n");
1180 __NETWORK_FUNC_EXIT__;
1181 return NET_ERR_INVALID_PARAM;
1184 snprintf(ip_buffer, NETPM_IPV4_STR_LEN_MAX + 1, "%s",
1185 inet_ntoa(prof_info->ProfileInfo.Wlan.net_info.IpAddr.Data.Ipv4));
1186 snprintf(netmask_buffer, NETPM_IPV4_STR_LEN_MAX + 1, "%s",
1187 inet_ntoa(prof_info->ProfileInfo.Wlan.net_info.SubnetMask.Data.Ipv4));
1188 snprintf(gateway_buffer, NETPM_IPV4_STR_LEN_MAX + 1, "%s",
1189 inet_ntoa(prof_info->ProfileInfo.Wlan.net_info.GatewayAddr.Data.Ipv4));
1191 NETWORK_LOG(NETWORK_ASSERT, "ipaddress : %s, netmask : %s, gateway : %s\n",
1192 ipaddress, netmask, gateway);
1194 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1196 NETWORK_LOG(NETWORK_ERROR, "Error!!! Can't get on system bus\n");
1197 __NETWORK_FUNC_EXIT__;
1198 return NET_ERR_UNKNOWN;
1201 /** Send ipaddress, netmask, gateway configuration */
1202 message = dbus_message_new_method_call(CONNMAN_SERVICE,
1203 profile_name, CONNMAN_SERVICE_INTERFACE, "SetProperty");
1204 if (message == NULL) {
1205 NETWORK_LOG( NETWORK_ERROR, "Error!!! dbus_message_new_method_call() failed\n");
1206 dbus_connection_unref(conn);
1207 __NETWORK_FUNC_EXIT__;
1208 return NET_ERR_UNKNOWN;
1210 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 1/2 : %s %s %s %s\n", CONNMAN_SERVICE,
1211 profile_name, CONNMAN_SERVICE_INTERFACE, "SetProperty");
1213 dbus_message_iter_init_append(message, &itr);
1214 dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &prop_ipv4_configuration);
1216 dbus_message_iter_open_container
1217 (&itr, DBUS_TYPE_VARIANT,
1218 (DBUS_TYPE_ARRAY_AS_STRING
1219 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
1220 DBUS_TYPE_STRING_AS_STRING
1221 DBUS_TYPE_STRING_AS_STRING
1222 DBUS_DICT_ENTRY_END_CHAR_AS_STRING),
1224 dbus_message_iter_open_container
1225 (&variant, DBUS_TYPE_ARRAY,
1226 (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
1227 DBUS_TYPE_STRING_AS_STRING
1228 DBUS_TYPE_STRING_AS_STRING
1229 DBUS_DICT_ENTRY_END_CHAR_AS_STRING),
1232 if (prof_info->ProfileInfo.Wlan.net_info.IpConfigType == NET_IP_CONFIG_TYPE_DYNAMIC ||
1233 prof_info->ProfileInfo.Wlan.net_info.IpConfigType == NET_IP_CONFIG_TYPE_AUTO_IP) {
1234 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1235 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_method);
1236 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &dhcp_method);
1237 dbus_message_iter_close_container(&dict, &entry);
1238 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s %s\n", prop_method, dhcp_method);
1239 } else if (prof_info->ProfileInfo.Wlan.net_info.IpConfigType == NET_IP_CONFIG_TYPE_OFF) {
1240 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1241 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_method);
1242 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &off_method);
1243 dbus_message_iter_close_container(&dict, &entry);
1244 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s %s\n", prop_method, off_method);
1245 } else if (prof_info->ProfileInfo.Wlan.net_info.IpConfigType == NET_IP_CONFIG_TYPE_STATIC) {
1246 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1247 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_method);
1248 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &manual_method);
1249 dbus_message_iter_close_container(&dict, &entry);
1251 if (strlen(ipaddress) >= NETPM_IPV4_STR_LEN_MIN) {
1252 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1253 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_address);
1254 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &ipaddress);
1255 dbus_message_iter_close_container(&dict, &entry);
1258 if (strlen(netmask) >= NETPM_IPV4_STR_LEN_MIN) {
1259 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1260 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_netmask);
1261 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &netmask);
1262 dbus_message_iter_close_container(&dict, &entry);
1265 if (strlen(gateway) >= NETPM_IPV4_STR_LEN_MIN) {
1266 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1267 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_gateway);
1268 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &gateway);
1269 dbus_message_iter_close_container(&dict, &entry);
1271 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s %s %s %s %s %s %s %s\n",
1272 prop_method, manual_method, prop_address, ipaddress,
1273 prop_netmask, netmask, prop_gateway, gateway);
1275 NETWORK_LOG(NETWORK_ASSERT, "Error!!! Invalid argument\n");
1276 __NETWORK_FUNC_EXIT__;
1277 return NET_ERR_INVALID_PARAM;
1280 dbus_message_iter_close_container(&variant, &dict);
1281 dbus_message_iter_close_container(&itr, &variant);
1283 dbus_error_init(&error);
1285 reply = dbus_connection_send_with_reply_and_block(conn,
1286 message, DBUS_REPLY_TIMEOUT,
1289 if (reply == NULL) {
1290 if (dbus_error_is_set (&error) == TRUE) {
1291 NETWORK_LOG(NETWORK_ERROR,
1292 "Error!!! dbus_connection_send_with_reply_and_block() failed, Error[%s: %s]\n",
1295 Error = __net_error_string_to_enum(error.name);
1296 dbus_error_free(&error);
1297 dbus_message_unref(message);
1298 __NETWORK_FUNC_EXIT__;
1302 dbus_message_unref(message);
1303 __NETWORK_FUNC_EXIT__;
1304 return NET_ERR_UNKNOWN;
1307 dbus_message_unref(reply);
1308 dbus_message_unref(message);
1310 NETWORK_LOG(NETWORK_HIGH, "Successfully configured IPv4.Configuration\n");
1312 dbus_connection_unref(conn);
1314 __NETWORK_FUNC_EXIT__;
1315 return NET_ERR_NONE;
1318 int _net_dbus_set_profile_dns(net_profile_info_t* prof_info, char* profile_name)
1320 __NETWORK_FUNC_ENTER__;
1322 net_err_t Error = NET_ERR_NONE;
1325 const char *prop_nameserver_configuration = "Nameservers.Configuration";
1326 char dns_buffer[NET_DNS_ADDR_MAX][NETPM_IPV4_STR_LEN_MAX+1];
1327 char *dns_address[NET_DNS_ADDR_MAX];
1329 DBusMessage *message = NULL;
1330 DBusMessage *reply = NULL;
1331 DBusMessageIter itr;
1332 DBusConnection* conn = NULL;
1335 if ((prof_info == NULL) || (profile_name == NULL) || (strlen(profile_name) == 0) ||
1336 (prof_info->ProfileInfo.Wlan.net_info.DnsCount > NET_DNS_ADDR_MAX)) {
1337 NETWORK_LOG(NETWORK_ASSERT, "Error!!! Invalid parameter\n");
1338 __NETWORK_FUNC_EXIT__;
1339 return NET_ERR_INVALID_PARAM;
1342 for (i = 0;i < prof_info->ProfileInfo.Wlan.net_info.DnsCount;i++) {
1343 dns_buffer[i][0] = '\0';
1344 dns_address[i] = NULL;
1346 snprintf(dns_buffer[i], NETPM_IPV4_STR_LEN_MAX + 1, "%s",
1347 inet_ntoa(prof_info->ProfileInfo.Wlan.net_info.DnsAddr[i].Data.Ipv4));
1348 if (strlen(dns_buffer[i]) >= NETPM_IPV4_STR_LEN_MIN)
1349 dns_address[i] = dns_buffer[i];
1352 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1354 NETWORK_LOG(NETWORK_ERROR, "Error!!! Can't get on system bus\n");
1355 __NETWORK_FUNC_EXIT__;
1356 return NET_ERR_UNKNOWN;
1359 if (prof_info->ProfileInfo.Wlan.net_info.IpConfigType == NET_IP_CONFIG_TYPE_STATIC) {
1360 message = dbus_message_new_method_call(CONNMAN_SERVICE,
1361 profile_name, CONNMAN_SERVICE_INTERFACE, "SetProperty");
1363 if (message == NULL) {
1364 NETWORK_LOG(NETWORK_ERROR,
1365 "Error!!! dbus_message_new_method_call() failed\n");
1366 __NETWORK_FUNC_EXIT__;
1367 return NET_ERR_UNKNOWN;
1370 dbus_message_iter_init_append(message, &itr);
1371 dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &prop_nameserver_configuration);
1373 DBusMessageIter value, array;
1374 dbus_message_iter_open_container(&itr, DBUS_TYPE_VARIANT,
1375 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING, &value);
1377 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
1378 DBUS_TYPE_STRING_AS_STRING, &array);
1380 for (i = 0;i < prof_info->ProfileInfo.Wlan.net_info.DnsCount;i++) {
1381 dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING, &(dns_address[i]));
1384 dbus_message_iter_close_container(&value, &array);
1385 dbus_message_iter_close_container(&itr, &value);
1387 dbus_error_init(&error);
1389 reply = dbus_connection_send_with_reply_and_block(conn,
1390 message, DBUS_REPLY_TIMEOUT,
1393 if (reply == NULL) {
1394 if (dbus_error_is_set (&error) == TRUE) {
1395 NETWORK_LOG(NETWORK_ERROR,
1396 "Error!!! dbus_connection_send_with_reply_and_block() failed, Error[%s: %s]\n",
1399 Error = __net_error_string_to_enum(error.name);
1400 dbus_error_free(&error);
1401 dbus_message_unref(message);
1402 __NETWORK_FUNC_EXIT__;
1405 dbus_message_unref(message);
1406 __NETWORK_FUNC_EXIT__;
1407 return NET_ERR_UNKNOWN;
1409 dbus_message_unref(reply);
1410 dbus_message_unref(message);
1411 NETWORK_LOG(NETWORK_HIGH, "Successfully configured Nameservers.Configuration\n");
1414 __NETWORK_FUNC_EXIT__;
1415 return NET_ERR_NONE;
1418 int _net_dbus_set_proxy(net_profile_info_t* prof_info, char* profile_name)
1420 __NETWORK_FUNC_ENTER__;
1422 net_err_t Error = NET_ERR_NONE;
1425 const char *direct_method = "direct"; /* not method[] as gcc screws it with dbus */
1426 const char *auto_method = "auto"; /* not method[] as gcc screws it with dbus */
1427 const char *manual_method = "manual"; /* not method[] as gcc screws it with dbus */
1429 const char *prop_proxy_configuration = "Proxy.Configuration";
1430 const char *prop_method = "Method";
1431 const char *prop_url = "URL";
1432 const char *prop_servers = "Servers";
1434 char proxy_buffer[NET_PROXY_LEN_MAX+1] = "";
1435 char *proxy_address = proxy_buffer;
1437 DBusMessage *message = NULL;
1438 DBusMessage *reply = NULL;
1439 DBusMessageIter itr, variant, dict, entry, sub_variant, str_array;
1440 DBusConnection* conn = NULL;
1442 snprintf(proxy_buffer, NET_PROXY_LEN_MAX + 1, "%s", prof_info->ProfileInfo.Wlan.net_info.ProxyAddr);
1444 NETWORK_LOG(NETWORK_ASSERT, "Method : %d, proxy address : %s\n",
1445 prof_info->ProfileInfo.Wlan.net_info.ProxyMethod, proxy_address);
1447 if ((prof_info == NULL) || (profile_name == NULL) || (strlen(profile_name) == 0)) {
1448 NETWORK_LOG(NETWORK_ASSERT, "Error!!! Invalid argument\n");
1449 __NETWORK_FUNC_EXIT__;
1450 return NET_ERR_INVALID_PARAM;
1453 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1455 NETWORK_LOG(NETWORK_ERROR, "Error!!! Can't get on system bus\n");
1456 __NETWORK_FUNC_EXIT__;
1457 return NET_ERR_UNKNOWN;
1460 /** Send proxy method, url, servers configuration */
1461 message = dbus_message_new_method_call(CONNMAN_SERVICE, profile_name,
1462 CONNMAN_SERVICE_INTERFACE, "SetProperty");
1463 if (message == NULL) {
1464 NETWORK_LOG(NETWORK_ERROR, "Error!!! dbus_message_new_method_call() failed\n");
1465 __NETWORK_FUNC_EXIT__;
1466 return NET_ERR_UNKNOWN;
1469 dbus_message_iter_init_append(message, &itr);
1470 dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &prop_proxy_configuration);
1472 dbus_message_iter_open_container
1473 (&itr, DBUS_TYPE_VARIANT,
1474 (DBUS_TYPE_ARRAY_AS_STRING
1475 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
1476 DBUS_TYPE_STRING_AS_STRING
1477 DBUS_TYPE_VARIANT_AS_STRING
1478 DBUS_DICT_ENTRY_END_CHAR_AS_STRING),
1480 dbus_message_iter_open_container
1481 (&variant, DBUS_TYPE_ARRAY,
1482 (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
1483 DBUS_TYPE_STRING_AS_STRING
1484 DBUS_TYPE_VARIANT_AS_STRING
1485 DBUS_DICT_ENTRY_END_CHAR_AS_STRING),
1488 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1489 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_method);
1491 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
1492 DBUS_TYPE_STRING_AS_STRING, &sub_variant);
1494 switch (prof_info->ProfileInfo.Wlan.net_info.ProxyMethod) {
1495 case NET_PROXY_TYPE_AUTO:
1496 dbus_message_iter_append_basic(&sub_variant, DBUS_TYPE_STRING, &auto_method);
1498 case NET_PROXY_TYPE_MANUAL:
1499 dbus_message_iter_append_basic(&sub_variant, DBUS_TYPE_STRING, &manual_method);
1502 dbus_message_iter_append_basic(&sub_variant, DBUS_TYPE_STRING, &direct_method);
1506 dbus_message_iter_close_container(&entry, &sub_variant);
1507 dbus_message_iter_close_container(&dict, &entry);
1509 if (prof_info->ProfileInfo.Wlan.net_info.ProxyMethod == NET_PROXY_TYPE_AUTO) {
1510 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1511 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_url);
1513 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
1514 DBUS_TYPE_STRING_AS_STRING, &sub_variant);
1515 dbus_message_iter_append_basic(&sub_variant, DBUS_TYPE_STRING, &proxy_address);
1517 dbus_message_iter_close_container(&entry, &sub_variant);
1518 dbus_message_iter_close_container(&dict, &entry);
1521 if (prof_info->ProfileInfo.Wlan.net_info.ProxyMethod == NET_PROXY_TYPE_MANUAL) {
1522 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1523 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_servers);
1525 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
1526 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING, &sub_variant);
1528 dbus_message_iter_open_container(&sub_variant, DBUS_TYPE_ARRAY,
1529 DBUS_TYPE_STRING_AS_STRING, &str_array);
1530 dbus_message_iter_append_basic(&str_array, DBUS_TYPE_STRING, &proxy_address);
1532 dbus_message_iter_close_container(&sub_variant, &str_array);
1533 dbus_message_iter_close_container(&entry, &sub_variant);
1534 dbus_message_iter_close_container(&dict, &entry);
1537 dbus_message_iter_close_container(&variant, &dict);
1538 dbus_message_iter_close_container(&itr, &variant);
1540 dbus_error_init(&error);
1542 reply = dbus_connection_send_with_reply_and_block(conn,
1543 message, DBUS_REPLY_TIMEOUT,
1546 if (reply == NULL) {
1547 if (dbus_error_is_set(&error) == TRUE) {
1548 NETWORK_LOG( NETWORK_ERROR,
1549 "Error!!! dbus_connection_send_with_reply_and_block() failed, Error[%s: %s]\n",
1552 Error = __net_error_string_to_enum(error.name);
1553 dbus_error_free(&error);
1554 dbus_message_unref(message);
1555 __NETWORK_FUNC_EXIT__;
1559 dbus_message_unref(message);
1560 __NETWORK_FUNC_EXIT__;
1561 return NET_ERR_UNKNOWN;
1564 dbus_message_unref(reply);
1565 dbus_message_unref(message);
1567 NETWORK_LOG( NETWORK_HIGH, "Successfully configured Proxy.Configuration\n");
1569 dbus_connection_unref(conn);
1571 __NETWORK_FUNC_EXIT__;
1572 return NET_ERR_NONE;
1576 int _net_dbus_add_pdp_profile(net_profile_info_t *prof_info)
1578 __NETWORK_FUNC_ENTER__;
1580 net_err_t Error = NET_ERR_NONE;
1582 const char *service_type = "svc_ctg_id";
1583 const char *home_url = "home_url";
1584 const char *proxy_addr = "proxy_addr";
1585 const char *auth_pwd = "auth_pwd";
1586 const char *auth_type = "auth_type";
1587 const char *auth_id = "auth_id";
1588 const char *apn = "apn";
1590 char buff_svc_type[10] = "";
1591 char buff_auth_type[10] = "";
1592 char *temp_ptr = NULL;
1594 DBusMessage *message = NULL;
1595 DBusMessage *reply = NULL;
1596 DBusMessageIter iter, dict, entry;
1597 DBusConnection* conn = NULL;
1599 if (prof_info == NULL) {
1600 NETWORK_LOG(NETWORK_ASSERT, "Error!!! Invalid argument\n");
1601 __NETWORK_FUNC_EXIT__;
1602 return NET_ERR_INVALID_PARAM;
1605 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1607 NETWORK_LOG(NETWORK_ERROR, "Error!!! Can't get on system bus\n");
1608 __NETWORK_FUNC_EXIT__;
1609 return NET_ERR_UNKNOWN;
1612 /** Create message */
1613 message = dbus_message_new_method_call(TELEPHONY_SERVCE,
1614 TELEPHONY_MASTER_PATH, TELEPHONY_MASTER_INTERFACE, "AddProfile");
1615 if (message == NULL) {
1616 NETWORK_LOG(NETWORK_ERROR, "Error!!! dbus_message_new_method_call() failed\n");
1617 dbus_connection_unref(conn);
1618 __NETWORK_FUNC_EXIT__;
1619 return NET_ERR_UNKNOWN;
1622 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 1/2 : %s %s %s %s\n", TELEPHONY_SERVCE,
1623 TELEPHONY_MASTER_PATH, TELEPHONY_MASTER_INTERFACE, ".AddProfile");
1625 dbus_message_iter_init_append(message, &iter);
1627 dbus_message_iter_open_container
1628 (&iter, DBUS_TYPE_ARRAY,
1629 (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
1630 DBUS_TYPE_STRING_AS_STRING
1631 DBUS_TYPE_STRING_AS_STRING
1632 DBUS_DICT_ENTRY_END_CHAR_AS_STRING),
1635 if (prof_info->ProfileInfo.Pdp.ServiceType > NET_SERVICE_UNKNOWN &&
1636 prof_info->ProfileInfo.Pdp.ServiceType <= NET_SERVICE_PREPAID_MMS) {
1637 snprintf(buff_svc_type, 10, "%d", prof_info->ProfileInfo.Pdp.ServiceType);
1638 temp_ptr = buff_svc_type;
1640 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1641 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &service_type);
1642 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1643 dbus_message_iter_close_container(&dict, &entry);
1645 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1646 service_type, temp_ptr);
1649 if (strlen(prof_info->ProfileInfo.Pdp.HomeURL) > 0) {
1650 temp_ptr = prof_info->ProfileInfo.Pdp.HomeURL;
1652 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1653 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &home_url);
1654 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1655 dbus_message_iter_close_container(&dict, &entry);
1657 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1658 home_url, temp_ptr);
1661 if (strlen(prof_info->ProfileInfo.Pdp.net_info.ProxyAddr) > 0) {
1662 temp_ptr = prof_info->ProfileInfo.Pdp.net_info.ProxyAddr;
1664 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1665 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &proxy_addr);
1666 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1667 dbus_message_iter_close_container(&dict, &entry);
1669 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1670 proxy_addr, temp_ptr);
1673 if (strlen(prof_info->ProfileInfo.Pdp.AuthInfo.Password) > 0) {
1674 temp_ptr = prof_info->ProfileInfo.Pdp.AuthInfo.Password;
1676 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1677 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &auth_pwd);
1678 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1679 dbus_message_iter_close_container(&dict, &entry);
1681 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1682 auth_pwd, temp_ptr);
1685 if (strlen(prof_info->ProfileInfo.Pdp.AuthInfo.UserName) > 0) {
1686 temp_ptr = prof_info->ProfileInfo.Pdp.AuthInfo.UserName;
1688 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1689 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &auth_id);
1690 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1691 dbus_message_iter_close_container(&dict, &entry);
1693 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1697 if (prof_info->ProfileInfo.Pdp.AuthInfo.AuthType >= NET_PDP_AUTH_NONE &&
1698 prof_info->ProfileInfo.Pdp.AuthInfo.AuthType <= NET_PDP_AUTH_CHAP) {
1699 snprintf(buff_auth_type, 10, "%d", prof_info->ProfileInfo.Pdp.AuthInfo.AuthType);
1700 temp_ptr = buff_auth_type;
1702 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1703 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &auth_type);
1704 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1705 dbus_message_iter_close_container(&dict, &entry);
1707 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1708 auth_type, temp_ptr);
1711 if (strlen(prof_info->ProfileInfo.Pdp.Apn) > 0) {
1712 temp_ptr = prof_info->ProfileInfo.Pdp.Apn;
1714 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1715 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &apn);
1716 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1717 dbus_message_iter_close_container(&dict, &entry);
1719 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1723 dbus_message_iter_close_container(&iter, &dict);
1724 dbus_error_init(&error);
1727 reply = dbus_connection_send_with_reply_and_block(conn,
1728 message, DBUS_REPLY_TIMEOUT,
1732 if (reply == NULL) {
1733 if (dbus_error_is_set (&error) == TRUE) {
1734 NETWORK_LOG(NETWORK_ERROR,
1735 "Error!!! dbus_connection_send_with_reply_and_block() failed, Error[%s: %s]\n",
1738 Error = __net_error_string_to_enum(error.name);
1739 dbus_error_free(&error);
1740 dbus_message_unref(message);
1741 __NETWORK_FUNC_EXIT__;
1745 dbus_message_unref(message);
1746 dbus_connection_unref(conn);
1747 __NETWORK_FUNC_EXIT__;
1748 return NET_ERR_UNKNOWN;
1750 NETWORK_LOG(NETWORK_HIGH, "Successfully requested : Add PDP profile\n");
1753 DBusMessageIter iter2;
1756 dbus_message_iter_init(reply, &iter2);
1757 if (dbus_message_iter_get_arg_type(&iter2) == DBUS_TYPE_BOOLEAN) {
1758 dbus_message_iter_get_basic(&iter2, &add_result);
1759 NETWORK_LOG(NETWORK_HIGH, "Profile add result : %d\n", add_result);
1763 Error = NET_ERR_NONE;
1765 Error = NET_ERR_UNKNOWN;
1767 dbus_message_unref(reply);
1768 dbus_message_unref(message);
1769 dbus_connection_unref(conn);
1771 __NETWORK_FUNC_EXIT__;
1776 int _net_dbus_modify_pdp_profile(net_profile_info_t *prof_info, const char *profile_name)
1778 __NETWORK_FUNC_ENTER__;
1780 net_err_t Error = NET_ERR_NONE;
1783 const char *service_type = "svc_ctg_id";
1784 const char *home_url = "home_url";
1785 const char *proxy_addr = "proxy_addr";
1786 const char *auth_pwd = "auth_pwd";
1787 const char *auth_type = "auth_type";
1788 const char *auth_id = "auth_id";
1789 const char *apn = "apn";
1791 char buff_svc_type[10] = "";
1792 char buff_auth_type[10] = "";
1793 char *temp_ptr = NULL;
1795 DBusMessage *message = NULL;
1796 DBusMessage *reply = NULL;
1797 DBusMessageIter iter, dict, entry;
1798 DBusConnection* conn = NULL;
1800 if ((prof_info == NULL) || (profile_name == NULL)) {
1801 NETWORK_LOG(NETWORK_ASSERT, "Error!!! Invalid argument\n");
1802 __NETWORK_FUNC_EXIT__;
1803 return NET_ERR_INVALID_PARAM;
1806 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1808 NETWORK_LOG(NETWORK_ERROR, "Error!!! Can't get on system bus\n");
1809 __NETWORK_FUNC_EXIT__;
1810 return NET_ERR_UNKNOWN;
1813 /** Create message */
1814 message = dbus_message_new_method_call(TELEPHONY_SERVCE,
1815 profile_name, TELEPHONY_PROFILE_INTERFACE, "ModifyProfile");
1816 if (message == NULL) {
1817 NETWORK_LOG(NETWORK_ERROR, "Error!!! dbus_message_new_method_call() failed\n");
1818 dbus_connection_unref(conn);
1819 __NETWORK_FUNC_EXIT__;
1820 return NET_ERR_UNKNOWN;
1823 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 1/2 : %s %s %s %s\n", TELEPHONY_SERVCE,
1824 profile_name, TELEPHONY_PROFILE_INTERFACE, ".ModifyProfile");
1826 dbus_message_iter_init_append(message, &iter);
1828 dbus_message_iter_open_container
1829 (&iter, DBUS_TYPE_ARRAY,
1830 (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
1831 DBUS_TYPE_STRING_AS_STRING
1832 DBUS_TYPE_STRING_AS_STRING
1833 DBUS_DICT_ENTRY_END_CHAR_AS_STRING),
1836 if (prof_info->ProfileInfo.Pdp.ServiceType > NET_SERVICE_UNKNOWN &&
1837 prof_info->ProfileInfo.Pdp.ServiceType <= NET_SERVICE_PREPAID_MMS) {
1838 snprintf(buff_svc_type, 10, "%d", prof_info->ProfileInfo.Pdp.ServiceType);
1839 temp_ptr = buff_svc_type;
1841 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1842 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &service_type);
1843 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1844 dbus_message_iter_close_container(&dict, &entry);
1846 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1847 service_type, temp_ptr);
1850 if (strlen(prof_info->ProfileInfo.Pdp.HomeURL) > 0) {
1851 temp_ptr = prof_info->ProfileInfo.Pdp.HomeURL;
1853 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1854 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &home_url);
1855 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1856 dbus_message_iter_close_container(&dict, &entry);
1858 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1859 home_url, temp_ptr);
1862 if (strlen(prof_info->ProfileInfo.Pdp.net_info.ProxyAddr) > 0) {
1863 temp_ptr = prof_info->ProfileInfo.Pdp.net_info.ProxyAddr;
1865 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1866 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &proxy_addr);
1867 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1868 dbus_message_iter_close_container(&dict, &entry);
1870 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1871 proxy_addr, temp_ptr);
1874 if (strlen(prof_info->ProfileInfo.Pdp.AuthInfo.Password) > 0) {
1875 temp_ptr = prof_info->ProfileInfo.Pdp.AuthInfo.Password;
1877 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1878 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &auth_pwd);
1879 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1880 dbus_message_iter_close_container(&dict, &entry);
1882 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1883 auth_pwd, temp_ptr);
1886 if (strlen(prof_info->ProfileInfo.Pdp.AuthInfo.UserName) > 0) {
1887 temp_ptr = prof_info->ProfileInfo.Pdp.AuthInfo.UserName;
1889 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1890 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &auth_id);
1891 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1892 dbus_message_iter_close_container(&dict, &entry);
1894 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1898 if (prof_info->ProfileInfo.Pdp.AuthInfo.AuthType >= NET_PDP_AUTH_NONE &&
1899 prof_info->ProfileInfo.Pdp.AuthInfo.AuthType <= NET_PDP_AUTH_CHAP) {
1900 snprintf(buff_auth_type, 10, "%d", prof_info->ProfileInfo.Pdp.AuthInfo.AuthType);
1901 temp_ptr = buff_auth_type;
1903 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1904 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &auth_type);
1905 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1906 dbus_message_iter_close_container(&dict, &entry);
1908 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1909 auth_type, temp_ptr);
1912 if (strlen(prof_info->ProfileInfo.Pdp.Apn) > 0) {
1913 temp_ptr = prof_info->ProfileInfo.Pdp.Apn;
1915 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
1916 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &apn);
1917 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &temp_ptr);
1918 dbus_message_iter_close_container(&dict, &entry);
1920 NETWORK_LOG(NETWORK_ASSERT, "DBus Message 2/2 : %s : %s\n",
1924 dbus_message_iter_close_container(&iter, &dict);
1925 dbus_error_init(&error);
1928 reply = dbus_connection_send_with_reply_and_block(conn,
1929 message, DBUS_REPLY_TIMEOUT,
1933 if (reply == NULL) {
1934 if (dbus_error_is_set (&error) == TRUE) {
1935 NETWORK_LOG(NETWORK_ERROR,
1936 "Error!!! dbus_connection_send_with_reply_and_block() failed, Error[%s: %s]\n",
1939 Error = __net_error_string_to_enum(error.name);
1940 dbus_error_free(&error);
1941 dbus_message_unref(message);
1942 __NETWORK_FUNC_EXIT__;
1946 dbus_message_unref(message);
1947 dbus_connection_unref(conn);
1948 __NETWORK_FUNC_EXIT__;
1949 return NET_ERR_UNKNOWN;
1951 NETWORK_LOG(NETWORK_HIGH, "Successfully requested : Modify PDP profile\n");
1954 DBusMessageIter iter2;
1957 dbus_message_iter_init(reply, &iter2);
1958 if (dbus_message_iter_get_arg_type(&iter2) == DBUS_TYPE_BOOLEAN) {
1959 dbus_message_iter_get_basic(&iter2, &add_result);
1960 NETWORK_LOG(NETWORK_HIGH, "Profile modify result : %d\n", add_result);
1964 Error = NET_ERR_NONE;
1966 Error = NET_ERR_UNKNOWN;
1968 dbus_message_unref(reply);
1969 dbus_message_unref(message);
1970 dbus_connection_unref(conn);
1972 __NETWORK_FUNC_EXIT__;
1977 int _net_dbus_load_wifi_driver(void)
1979 __NETWORK_FUNC_ENTER__;
1981 net_err_t Error = NET_ERR_NONE;
1983 Error = _net_invoke_dbus_method_nonblock(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
1984 NETCONFIG_WIFI_INTERFACE, "LoadDriver", __net_wifi_power_reply);
1986 __NETWORK_FUNC_EXIT__;
1990 int _net_dbus_remove_wifi_driver(void)
1992 __NETWORK_FUNC_ENTER__;
1994 net_err_t Error = NET_ERR_NONE;
1996 Error = _net_invoke_dbus_method_nonblock(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
1997 NETCONFIG_WIFI_INTERFACE, "RemoveDriver", __net_wifi_power_reply);
1999 __NETWORK_FUNC_EXIT__;
2003 dbus_bool_t _net_dbus_is_pending_call_used(void)
2005 return network_dbus_pending_call_data.is_used;
2008 void _net_dbus_set_pending_call_used(dbus_bool_t used)
2010 network_dbus_pending_call_data.is_used = used;
2013 DBusPendingCall *_net_dbus_get_pending_call(void)
2015 return network_dbus_pending_call_data.pcall;
2018 void _net_dbus_set_pending_call(DBusPendingCall *call)
2020 network_dbus_pending_call_data.pcall = call;
2023 void _net_dbus_clear_pending_call(void)
2025 if (_net_dbus_is_pending_call_used()) {
2026 dbus_pending_call_cancel(_net_dbus_get_pending_call());
2027 _net_dbus_set_pending_call(NULL);
2028 _net_dbus_set_pending_call_used(FALSE);
2032 int _net_dbus_specific_scan_request(const char *ssid)
2034 __NETWORK_FUNC_ENTER__;
2036 DBusMessage* message = NULL;
2037 DBusConnection* conn = NULL;
2038 DBusPendingCall *call = NULL;
2039 dbus_bool_t result = FALSE;
2041 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
2043 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Can't get on system bus\n");
2044 __NETWORK_FUNC_EXIT__;
2045 return NET_ERR_UNKNOWN;
2048 message = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, "RequestSpecificScan");
2049 if (message == NULL) {
2050 NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! dbus_message_new_method_call() failed\n");
2051 dbus_connection_unref(conn);
2052 __NETWORK_FUNC_EXIT__;
2053 return NET_ERR_UNKNOWN;
2056 dbus_message_append_args(message, DBUS_TYPE_STRING, &ssid, NULL);
2058 result = dbus_connection_send_with_reply(conn, message, &call, 6 * DBUS_REPLY_TIMEOUT);
2059 if (result == FALSE || call == NULL) {
2060 NETWORK_LOG(NETWORK_ERROR, "Error!!! dbus_connection_send_with_reply() Failed\n");
2061 dbus_message_unref(message);
2062 dbus_connection_unref(conn);
2063 __NETWORK_FUNC_EXIT__;
2064 return NET_ERR_UNKNOWN;
2067 NETWORK_LOG(NETWORK_HIGH, "Successfully configured\n");
2069 dbus_pending_call_set_notify(call, __net_specific_scan_wifi_reply, NULL, NULL);
2070 network_dbus_pending_call_data.pcall = call;
2071 network_dbus_pending_call_data.is_used = TRUE;
2073 dbus_message_unref(message);
2074 dbus_connection_unref(conn);
2076 __NETWORK_FUNC_EXIT__;
2077 return NET_ERR_NONE;
2082 #endif /* __cplusplus */