2 * Network Configuration Module
4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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.
22 #include "netsupplicant.h"
24 #define DBUS_OBJECT_PATH_MAX 150
26 const char *netconfig_wifi_get_supplicant_interface(void)
28 GVariant *message = NULL;
29 GVariant *params = NULL;
31 static char obj_path[DBUS_OBJECT_PATH_MAX] = { '\0', };
33 if (obj_path[0] != '\0')
34 return (const char *)obj_path;
36 params = g_variant_new("(s)", WIFI_IFNAME);
38 message = netconfig_supplicant_invoke_dbus_method(
39 SUPPLICANT_SERVICE, SUPPLICANT_PATH,
40 SUPPLICANT_INTERFACE, "GetInterface", params);
42 if (message == NULL) {
43 ERR("Failed to get object path");
47 g_variant_get(message, "(o)", &path);
49 g_strlcpy(obj_path, path, DBUS_OBJECT_PATH_MAX);
53 g_variant_unref(message);
55 return (const char *)obj_path;
58 GVariant *netconfig_supplicant_invoke_dbus_method(const char *dest, const char *path,
59 const char *interface_name, const char *method, GVariant *params)
62 GVariant *reply = NULL;
63 GDBusConnection *connection = NULL;
65 INFO("[DBUS Sync] %s %s %s", interface_name, method, path);
67 connection = netdbus_get_connection();
68 if (connection == NULL) {
69 ERR("Failed to get GDBus Connection");
73 reply = g_dbus_connection_call_sync(
81 G_DBUS_CALL_FLAGS_NONE,
82 NETCONFIG_DBUS_REPLY_TIMEOUT,
83 netdbus_get_cancellable(),
88 ERR("g_dbus_connection_call_sync() failed"
89 "error [%d: %s]", error->code, error->message);
92 ERR("g_dbus_connection_call_sync() failed");
101 gboolean netconfig_supplicant_invoke_dbus_method_nonblock(const char *dest,
102 const char *path, const char *interface_name,
103 const char *method, GVariant *params,
104 GAsyncReadyCallback notify_func)
106 GDBusConnection *connection = NULL;
108 INFO("[DBUS Async] %s %s %s", interface_name, method, path);
110 connection = netdbus_get_connection();
111 if (connection == NULL) {
112 DBG("Failed to get GDBusconnection");
116 g_dbus_connection_call(connection,
123 G_DBUS_CALL_FLAGS_NONE,
124 NETCONFIG_DBUS_REPLY_TIMEOUT,
125 netdbus_get_cancellable(),
126 (GAsyncReadyCallback) notify_func,
132 GVariant *netconfig_supplicant_invoke_dbus_interface_property_get(const char *interface,
135 GVariant *params = NULL;
136 GVariant *reply = NULL;
139 ERR("[GDBUS] property_get : %s", key);
141 path = netconfig_wifi_get_supplicant_interface();
143 DBG("Failed to get wpa_supplicant DBus path");
147 params = g_variant_new("(ss)", interface, key);
149 reply = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
151 DBUS_INTERFACE_PROPERTIES,
156 ERR("netconfig_supplicant_invoke_dbus_method() failed.");
163 gboolean netconfig_supplicant_invoke_dbus_interface_property_set(const char *interface,
164 const char *key, GVariant *var,
165 GAsyncReadyCallback notify_func)
167 gboolean result = FALSE;
168 GVariant *message = NULL;
171 DBG("[DBUS] property_set : %s", key);
173 path = netconfig_wifi_get_supplicant_interface();
175 ERR("Failed to get wpa_supplicant DBus path");
179 message = g_variant_new("(ssv)", interface, key, var);
180 result = netconfig_invoke_dbus_method_nonblock(SUPPLICANT_SERVICE,
182 DBUS_INTERFACE_PROPERTIES,
187 if (result == FALSE) {
188 ERR("dbus_connection_send_with_reply() failed");