#include "netdbus.h"
#include "netsupplicant.h"
-#define NETCONFIG_DBUS_REPLY_TIMEOUT (10 * 1000)
+#define DBUS_OBJECT_PATH_MAX 150
+#define NETCONFIG_DBUS_REPLY_TIMEOUT (10 * 1000)
static void setup_dbus_args(gpointer data, gpointer user_data)
{
- struct dbus_input_arguments *args;
DBusMessageIter *iter;
+ struct dbus_input_arguments *args;
- if (data != NULL && user_data != NULL) {
- args = (struct dbus_input_arguments *)data;
- iter = (DBusMessageIter *) user_data;
-
- dbus_message_iter_append_basic(iter, args->type,
- &(args->data));
+ if (data == NULL || user_data == NULL)
+ return;
+
+ iter = (DBusMessageIter *) user_data;
+ args = (struct dbus_input_arguments *)data;
+
+ if (args->data == NULL)
+ return;
+
+ switch (args->type) {
+ case DBUS_TYPE_STRING:
+ case DBUS_TYPE_OBJECT_PATH:
+ DBG("parameter [%s]", args->data);
+ dbus_message_iter_append_basic(iter, args->type, &(args->data));
+ break;
+ case DBUS_TYPE_BOOLEAN:
+ case DBUS_TYPE_UINT32:
+ case DBUS_TYPE_INT32:
+ DBG("parameter [%d]", args->data);
+ dbus_message_iter_append_basic(iter, args->type, args->data);
+ break;
+ case DBUS_TYPE_INVALID:
+ default:
+ return;
}
}
-static GList *setup_input_args(GList *list,
+GList *setup_input_args(GList *list,
struct dbus_input_arguments *items)
{
struct dbus_input_arguments *iter = items;
return NULL;
while (iter->data) {
- list = g_list_append(list, iter);
+ list = g_list_append(list, iter); //Adds a new element on to the end of the list
iter++;
}
return FALSE;
}
+const char *netconfig_wifi_get_supplicant_interface_(void)
+{
+ GList *input_args = NULL;
+ DBusMessage *message = NULL;
+ struct dbus_input_arguments args[] = {
+ {DBUS_TYPE_STRING, WIFI_IFNAME},
+ {DBUS_TYPE_INVALID, NULL}
+ };
+ const char *path;
+ static char obj_path[DBUS_OBJECT_PATH_MAX] = { '\0', };
+
+ if (obj_path[0] != '\0')
+ return (const char *)obj_path;
+
+ input_args = setup_input_args(input_args, args);
+
+ message = netconfig_supplicant_invoke_dbus_method_(
+ SUPPLICANT_SERVICE, SUPPLICANT_PATH,
+ SUPPLICANT_INTERFACE, "GetInterface", input_args);
+
+ g_list_free(input_args);
+
+ if (message == NULL)
+ return NULL;
+
+ if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) {
+ const char *err_msg = dbus_message_get_error_name(message);
+ ERR("Error!!! Error message received %s", err_msg);
+ goto error;
+ }
+
+ dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
+
+ g_strlcpy(obj_path, path, DBUS_OBJECT_PATH_MAX);
+
+ dbus_message_unref(message);
+
+ return (const char *)obj_path;
+
+error:
+ if (message != NULL)
+ dbus_message_unref(message);
+
+ return NULL;
+}
+
+
DBusMessage *netconfig_supplicant_invoke_dbus_method(const char *dest,
DBusConnection *connection,
const char *path, const char *interface_name,
return reply;
}
+
+DBusMessage *netconfig_supplicant_invoke_dbus_method_(const char *dest,
+ const char *path, const char *interface_name,
+ const char *method, GList *args)
+{
+ DBusError error;
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ DBusMessage *message = NULL;
+ DBusConnection *connection = NULL;
+
+// DBG("[DBUS Sync] %s %s %s", interface_name, method, path);
+
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (connection == NULL) {
+ ERR("Failed to get system bus");
+ return NULL;
+ }
+
+ message = dbus_message_new_method_call(dest, path, interface_name, method);
+ if (message == NULL) {
+ ERR("Failed DBus method call");
+ dbus_connection_unref(connection);
+ return NULL;
+ }
+
+ dbus_message_iter_init_append(message, &iter);
+
+ if (args != NULL)
+ g_list_foreach(args, setup_dbus_args, (gpointer)&iter);
+
+ dbus_error_init(&error);
+
+ reply = dbus_connection_send_with_reply_and_block(connection, message,
+ NETCONFIG_DBUS_REPLY_TIMEOUT, &error);
+
+ if (reply == NULL) {
+ if (dbus_error_is_set(&error) == TRUE) {
+ ERR("dbus_connection_send_with_reply_and_block() failed. "
+ "DBus error [%s: %s]", error.name, error.message);
+
+ dbus_error_free(&error);
+ } else
+ ERR("Failed to get properties");
+
+ dbus_message_unref(message);
+ dbus_connection_unref(connection);
+
+ return NULL;
+ }
+
+ dbus_message_unref(message);
+ dbus_connection_unref(connection);
+
+ return reply;
+}
+
+DBusMessage *netconfig_supplicant_invoke_dbus_interface_property_get(const char *interface,
+ const char *key)
+{
+ DBusError error;
+ DBusMessage *reply = NULL;
+ DBusMessage *message = NULL;
+ DBusConnection *connection = NULL;
+ const char *path;
+
+ ERR("[DBUS] property_get : %s", key);
+
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (connection == NULL) {
+ ERR("Failed to get system bus");
+ return NULL;
+ }
+
+ path = netconfig_wifi_get_supplicant_interface_();
+ if (path == NULL) {
+ DBG("Failed to get wpa_supplicant DBus path");
+ dbus_connection_unref(connection);
+ return NULL;
+ }
+
+ message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
+ DBUS_INTERFACE_PROPERTIES, "Get");
+ if (message == NULL) {
+ ERR("Failed DBus method call");
+ dbus_connection_unref(connection);
+ return NULL;
+ }
+
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &interface,
+ DBUS_TYPE_STRING, &key, NULL);
+
+ dbus_error_init(&error);
+
+ reply = dbus_connection_send_with_reply_and_block(connection, message,
+ NETCONFIG_DBUS_REPLY_TIMEOUT, &error);
+ if (reply == NULL) {
+ if (dbus_error_is_set(&error) == TRUE) {
+ ERR("dbus_connection_send_with_reply_and_block() failed. "
+ "DBus error [%s: %s]", error.name, error.message);
+
+ dbus_error_free(&error);
+ } else
+ ERR("Failed to get properties");
+
+ dbus_message_unref(message);
+ dbus_connection_unref(connection);
+
+ return NULL;
+ }
+
+ dbus_message_unref(message);
+ dbus_connection_unref(connection);
+
+ return reply;
+}
+
+dbus_bool_t netconfig_supplicant_invoke_dbus_interface_property_set(const char *interface,
+ const char *key, const char *type, GList *args,
+ DBusPendingCallNotifyFunction notify_func)
+{
+ dbus_bool_t result = FALSE;
+ DBusPendingCall *call;
+ DBusMessage *message = NULL;
+ DBusConnection *connection = NULL;
+ DBusMessageIter iter, value;
+ const char *path;
+
+ DBG("[DBUS] property_set : %s", key);
+
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (connection == NULL) {
+ ERR("Failed to get system bus");
+ return result;
+ }
+
+ path = netconfig_wifi_get_supplicant_interface_();
+ if (path == NULL) {
+ ERR("Failed to get wpa_supplicant DBus path");
+ dbus_connection_unref(connection);
+ return result;
+ }
+
+ message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
+ DBUS_INTERFACE_PROPERTIES, "Set");
+ if (message == NULL) {
+ ERR("Failed DBus method call");
+ dbus_connection_unref(connection);
+ return result;
+ }
+
+ dbus_message_iter_init_append(message, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &interface);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+ type, &value);
+
+ if (args != NULL)
+ g_list_foreach(args, setup_dbus_args, (gpointer)&value);
+
+ dbus_message_iter_close_container(&iter, &value);
+
+ result = dbus_connection_send_with_reply(connection, message, &call,
+ NETCONFIG_DBUS_REPLY_TIMEOUT);
+ if (result == FALSE || call == NULL) {
+ ERR("dbus_connection_send_with_reply() failed");
+
+ dbus_message_unref(message);
+ dbus_connection_unref(connection);
+
+ return result;
+ }
+
+ if (notify_func == NULL)
+ dbus_pending_call_cancel(call);
+ else
+ dbus_pending_call_set_notify(call, notify_func, NULL, NULL);
+
+ dbus_message_unref(message);
+ dbus_connection_unref(connection);
+
+ return result;
+}
+
--- /dev/null
+/*\r
+ * Network Configuration Module\r
+ *\r
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ */\r
+\r
+#include <errno.h>\r
+\r
+#include "log.h"\r
+#include "util.h"\r
+#include "neterror.h"\r
+#include "netdbus.h"\r
+#include "netsupplicant.h"\r
+#include "wifi-passpoint.h"\r
+\r
+\r
+static gboolean netconfig_wifi_get_passpoint(gint32 *enabled)\r
+{\r
+ DBusMessage *reply;\r
+ DBusMessageIter iter, variant;\r
+ dbus_bool_t value;\r
+ gboolean result = FALSE;\r
+\r
+ reply = netconfig_supplicant_invoke_dbus_interface_property_get(SUPPLICANT_IFACE_INTERFACE,\r
+ "Passpoint");\r
+ if (reply == NULL) {\r
+ ERR("Error!!! Failed to get passpoint property");\r
+ return result;\r
+ }\r
+\r
+ if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {\r
+ const char *err_msg = dbus_message_get_error_name(reply);\r
+ ERR("Error!!! Error message received [%s]", err_msg);\r
+ return result;\r
+ }\r
+\r
+ dbus_message_iter_init(reply, &iter);\r
+\r
+ if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_VARIANT) {\r
+ dbus_message_iter_recurse(&iter, &variant);\r
+ if (dbus_message_iter_get_arg_type(&variant) == DBUS_TYPE_INT32) {\r
+ dbus_message_iter_get_basic(&variant, &value);\r
+ if (value == TRUE)\r
+ *enabled = 1;\r
+ else\r
+ *enabled = 0;\r
+\r
+ result = TRUE;\r
+ }\r
+ }\r
+\r
+ dbus_message_unref(reply);\r
+\r
+ return result;\r
+}\r
+\r
+static gboolean netconfig_wifi_set_passpoint(gint32 enable)\r
+{\r
+ gint32 value = enable;\r
+ gboolean result = FALSE;\r
+ GList *input_args = NULL;\r
+\r
+ struct dbus_input_arguments args_enable[2] = {\r
+ {DBUS_TYPE_INT32, &value},\r
+ {DBUS_TYPE_INVALID, NULL}\r
+ };\r
+\r
+ input_args = setup_input_args(input_args, args_enable);\r
+\r
+ result = netconfig_supplicant_invoke_dbus_interface_property_set(SUPPLICANT_IFACE_INTERFACE,\r
+ "Passpoint", DBUS_TYPE_INT32_AS_STRING, input_args, NULL);\r
+ if (result == FALSE)\r
+ ERR("Fail to set passpoint enable [%d]", enable);\r
+\r
+ g_list_free(input_args);\r
+\r
+ return result;\r
+}\r
+\r
+gboolean netconfig_iface_wifi_get_passpoint(NetconfigWifi *wifi,\r
+ gint32 *result, GError **error)\r
+{\r
+ g_return_val_if_fail(wifi != NULL, FALSE);\r
+\r
+ if (netconfig_wifi_get_passpoint(result))\r
+ return TRUE;\r
+\r
+ return FALSE;\r
+}\r
+\r
+gboolean netconfig_iface_wifi_set_passpoint(NetconfigWifi *wifi,\r
+ gint32 enable, GError **error)\r
+{\r
+ g_return_val_if_fail(wifi != NULL, FALSE);//Verifies that the expression expr , usually representing a precondition, evaluates to TRUE. If the function does not return a value, use g_return_if_fail() instead\r
+\r
+ return netconfig_wifi_set_passpoint(enable);\r
+}\r
+\r