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 char *netconfig_get_supplicant_interface(const char *ifname)
26 GVariant *message = NULL;
27 GVariant *params = NULL;
33 params = g_variant_new("(s)", ifname);
35 message = netconfig_supplicant_invoke_dbus_method(
36 SUPPLICANT_SERVICE, SUPPLICANT_PATH,
37 SUPPLICANT_INTERFACE, "GetInterface", params);
39 if (message == NULL) {
40 ERR("Failed to get interface");
44 g_variant_get(message, "(o)", &path);
46 g_variant_unref(message);
51 char *netconfig_wifi_get_supplicant_interface_path(const char *interface_name)
53 const char *ifname = interface_name ? interface_name : WIFI_IFNAME;
54 return netconfig_get_supplicant_interface(ifname);
57 char *netconfig_wifi_get_supplicant_p2p_interface(void)
59 GVariant *message = NULL;
62 message = netconfig_supplicant_invoke_dbus_method(
63 SUPPLICANT_SERVICE, SUPPLICANT_PATH,
64 SUPPLICANT_INTERFACE, "GetP2PInterface", NULL);
66 if (message == NULL) {
67 ERR("Failed to get object path");
71 g_variant_get(message, "(o)", &path);
73 g_variant_unref(message);
78 GVariant *netconfig_supplicant_invoke_dbus_method(const char *dest, const char *path,
79 const char *interface_name, const char *method, GVariant *params)
82 GVariant *reply = NULL;
83 GDBusConnection *connection = NULL;
85 if (g_strcmp0(method, "GetInterface") != 0)
86 INFO("[DBUS Sync] %s %s %s", interface_name, method, path);
88 connection = netdbus_get_connection();
89 if (connection == NULL) {
90 ERR("Failed to get GDBus Connection");
94 reply = g_dbus_connection_call_sync(
102 G_DBUS_CALL_FLAGS_NONE,
103 NETCONFIG_DBUS_REPLY_TIMEOUT,
104 netdbus_get_cancellable(),
109 ERR("g_dbus_connection_call_sync() failed"
110 "error [%d: %s]", error->code, error->message);
113 ERR("g_dbus_connection_call_sync() failed");
122 gboolean netconfig_supplicant_invoke_dbus_method_nonblock(const char *dest,
123 const char *path, const char *interface_name,
124 const char *method, GVariant *params,
125 GAsyncReadyCallback notify_func, void *user_data)
127 GDBusConnection *connection = NULL;
129 INFO("[DBUS Async] %s %s %s", interface_name, method, path);
131 connection = netdbus_get_connection();
132 if (connection == NULL) {
133 DBG("Failed to get GDBusconnection");
137 g_dbus_connection_call(connection,
144 G_DBUS_CALL_FLAGS_NONE,
145 NETCONFIG_DBUS_REPLY_TIMEOUT,
146 netdbus_get_cancellable(),
147 (GAsyncReadyCallback) notify_func,
151 netconfig_gdbus_pending_call_ref();
156 GVariant *netconfig_supplicant_invoke_dbus_interface_property_get(const char *interface_name,
159 GVariant *params = NULL;
160 GVariant *reply = NULL;
163 ERR("[GDBUS] property_get : %s", key);
165 path = netconfig_wifi_get_supplicant_interface_path(interface_name);
167 DBG("Failed to get wpa_supplicant DBus path");
171 params = g_variant_new("(ss)", SUPPLICANT_IFACE_INTERFACE, key);
173 reply = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE,
175 DBUS_INTERFACE_PROPERTIES,
181 ERR("netconfig_supplicant_invoke_dbus_method() failed.");
188 gboolean netconfig_supplicant_invoke_dbus_interface_property_set(const char *interface_name,
189 const char *key, GVariant *var,
190 GAsyncReadyCallback notify_func)
192 gboolean result = FALSE;
193 GVariant *message = NULL;
196 DBG("[DBUS] property_set : %s", key);
198 path = netconfig_wifi_get_supplicant_interface_path(interface_name);
200 ERR("Failed to get wpa_supplicant DBus path");
204 message = g_variant_new("(ssv)", SUPPLICANT_IFACE_INTERFACE, key, var);
205 result = netconfig_invoke_dbus_method_nonblock(SUPPLICANT_SERVICE,
207 DBUS_INTERFACE_PROPERTIES,
214 if (result == FALSE) {
215 ERR("dbus_connection_send_with_reply() failed");