1/* 2 * WPA Supplicant / dbus-based control interface 3 * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc. 4 *
| 1/* 2 * WPA Supplicant / dbus-based control interface 3 * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc. 4 *
|
5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License version 2 as 7 * published by the Free Software Foundation. 8 * 9 * Alternatively, this software may be distributed under the terms of BSD 10 * license. 11 * 12 * See README and COPYING for more details.
| 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details.
|
13 */ 14 15#include "includes.h" 16#include <dbus/dbus.h> 17 18#include "common.h" 19#include "eloop.h" 20#include "wps/wps.h" 21#include "../config.h" 22#include "../wpa_supplicant_i.h" 23#include "../bss.h" 24#include "dbus_old.h" 25#include "dbus_old_handlers.h"
| 7 */ 8 9#include "includes.h" 10#include <dbus/dbus.h> 11 12#include "common.h" 13#include "eloop.h" 14#include "wps/wps.h" 15#include "../config.h" 16#include "../wpa_supplicant_i.h" 17#include "../bss.h" 18#include "dbus_old.h" 19#include "dbus_old_handlers.h"
|
26#include "dbus_common.h"
| |
27#include "dbus_common_i.h" 28 29 30/** 31 * wpas_dbus_decompose_object_path - Decompose an interface object path into parts 32 * @path: The dbus object path 33 * @network: (out) the configured network this object path refers to, if any 34 * @bssid: (out) the scanned bssid this object path refers to, if any 35 * Returns: The object path of the network interface this path refers to 36 * 37 * For a given object path, decomposes the object path into object id, network, 38 * and BSSID parts, if those parts exist. 39 */ 40char * wpas_dbus_decompose_object_path(const char *path, char **network, 41 char **bssid) 42{ 43 const unsigned int dev_path_prefix_len = 44 strlen(WPAS_DBUS_PATH_INTERFACES "/"); 45 char *obj_path_only; 46 char *next_sep; 47 48 /* Be a bit paranoid about path */ 49 if (!path || strncmp(path, WPAS_DBUS_PATH_INTERFACES "/", 50 dev_path_prefix_len)) 51 return NULL; 52 53 /* Ensure there's something at the end of the path */ 54 if ((path + dev_path_prefix_len)[0] == '\0') 55 return NULL; 56 57 obj_path_only = os_strdup(path); 58 if (obj_path_only == NULL) 59 return NULL; 60 61 next_sep = strchr(obj_path_only + dev_path_prefix_len, '/'); 62 if (next_sep != NULL) { 63 const char *net_part = strstr(next_sep, 64 WPAS_DBUS_NETWORKS_PART "/"); 65 const char *bssid_part = strstr(next_sep, 66 WPAS_DBUS_BSSIDS_PART "/"); 67 68 if (network && net_part) { 69 /* Deal with a request for a configured network */ 70 const char *net_name = net_part + 71 strlen(WPAS_DBUS_NETWORKS_PART "/"); 72 *network = NULL; 73 if (strlen(net_name)) 74 *network = os_strdup(net_name); 75 } else if (bssid && bssid_part) { 76 /* Deal with a request for a scanned BSSID */ 77 const char *bssid_name = bssid_part + 78 strlen(WPAS_DBUS_BSSIDS_PART "/"); 79 if (strlen(bssid_name)) 80 *bssid = os_strdup(bssid_name); 81 else 82 *bssid = NULL; 83 } 84 85 /* Cut off interface object path before "/" */ 86 *next_sep = '\0'; 87 } 88 89 return obj_path_only; 90} 91 92 93/** 94 * wpas_dbus_new_invalid_iface_error - Return a new invalid interface error message 95 * @message: Pointer to incoming dbus message this error refers to 96 * Returns: A dbus error message 97 * 98 * Convenience function to create and return an invalid interface error 99 */ 100DBusMessage * wpas_dbus_new_invalid_iface_error(DBusMessage *message) 101{ 102 return dbus_message_new_error(message, WPAS_ERROR_INVALID_IFACE, 103 "wpa_supplicant knows nothing about " 104 "this interface."); 105} 106 107 108/** 109 * wpas_dbus_new_invalid_network_error - Return a new invalid network error message 110 * @message: Pointer to incoming dbus message this error refers to 111 * Returns: a dbus error message 112 * 113 * Convenience function to create and return an invalid network error 114 */ 115DBusMessage * wpas_dbus_new_invalid_network_error(DBusMessage *message) 116{ 117 return dbus_message_new_error(message, WPAS_ERROR_INVALID_NETWORK, 118 "The requested network does not exist."); 119} 120 121 122/** 123 * wpas_dbus_new_invalid_bssid_error - Return a new invalid bssid error message 124 * @message: Pointer to incoming dbus message this error refers to 125 * Returns: a dbus error message 126 * 127 * Convenience function to create and return an invalid bssid error 128 */ 129static DBusMessage * wpas_dbus_new_invalid_bssid_error(DBusMessage *message) 130{ 131 return dbus_message_new_error(message, WPAS_ERROR_INVALID_BSSID, 132 "The BSSID requested was invalid."); 133} 134 135 136/** 137 * wpas_dispatch_network_method - dispatch messages for configured networks 138 * @message: the incoming dbus message 139 * @wpa_s: a network interface's data 140 * @network_id: id of the configured network we're interested in 141 * Returns: a reply dbus message, or a dbus error message 142 * 143 * This function dispatches all incoming dbus messages for configured networks. 144 */ 145static DBusMessage * wpas_dispatch_network_method(DBusMessage *message, 146 struct wpa_supplicant *wpa_s, 147 int network_id) 148{ 149 DBusMessage *reply = NULL; 150 const char *method = dbus_message_get_member(message); 151 struct wpa_ssid *ssid; 152 153 ssid = wpa_config_get_network(wpa_s->conf, network_id); 154 if (ssid == NULL) 155 return wpas_dbus_new_invalid_network_error(message); 156 157 if (!strcmp(method, "set")) 158 reply = wpas_dbus_iface_set_network(message, wpa_s, ssid); 159 else if (!strcmp(method, "enable")) 160 reply = wpas_dbus_iface_enable_network(message, wpa_s, ssid); 161 else if (!strcmp(method, "disable")) 162 reply = wpas_dbus_iface_disable_network(message, wpa_s, ssid); 163 164 return reply; 165} 166 167 168/** 169 * wpas_dispatch_bssid_method - dispatch messages for scanned networks 170 * @message: the incoming dbus message 171 * @wpa_s: a network interface's data 172 * @bssid: bssid of the scanned network we're interested in 173 * Returns: a reply dbus message, or a dbus error message 174 * 175 * This function dispatches all incoming dbus messages for scanned networks. 176 */ 177static DBusMessage * wpas_dispatch_bssid_method(DBusMessage *message, 178 struct wpa_supplicant *wpa_s, 179 const char *bssid_txt) 180{ 181 u8 bssid[ETH_ALEN]; 182 struct wpa_bss *bss; 183 184 if (hexstr2bin(bssid_txt, bssid, ETH_ALEN) < 0) 185 return wpas_dbus_new_invalid_bssid_error(message); 186 187 bss = wpa_bss_get_bssid(wpa_s, bssid); 188 if (bss == NULL) 189 return wpas_dbus_new_invalid_bssid_error(message); 190 191 /* Dispatch the method call against the scanned bssid */ 192 if (os_strcmp(dbus_message_get_member(message), "properties") == 0) 193 return wpas_dbus_bssid_properties(message, wpa_s, bss); 194 195 return NULL; 196} 197 198 199/** 200 * wpas_iface_message_handler - Dispatch messages for interfaces or networks 201 * @connection: Connection to the system message bus 202 * @message: An incoming dbus message 203 * @user_data: A pointer to a dbus control interface data structure 204 * Returns: Whether or not the message was handled 205 * 206 * This function dispatches all incoming dbus messages for network interfaces, 207 * or objects owned by them, such as scanned BSSIDs and configured networks. 208 */ 209static DBusHandlerResult wpas_iface_message_handler(DBusConnection *connection, 210 DBusMessage *message, 211 void *user_data) 212{ 213 struct wpa_supplicant *wpa_s = user_data; 214 const char *method = dbus_message_get_member(message); 215 const char *path = dbus_message_get_path(message); 216 const char *msg_interface = dbus_message_get_interface(message); 217 char *iface_obj_path = NULL; 218 char *network = NULL; 219 char *bssid = NULL; 220 DBusMessage *reply = NULL; 221 222 /* Caller must specify a message interface */ 223 if (!msg_interface) 224 goto out; 225 226 iface_obj_path = wpas_dbus_decompose_object_path(path, &network, 227 &bssid); 228 if (iface_obj_path == NULL) { 229 reply = wpas_dbus_new_invalid_iface_error(message); 230 goto out; 231 } 232 233 /* Make sure the message's object path actually refers to the 234 * wpa_supplicant structure it's supposed to (which is wpa_s) 235 */ 236 if (wpa_supplicant_get_iface_by_dbus_path(wpa_s->global, 237 iface_obj_path) != wpa_s) { 238 reply = wpas_dbus_new_invalid_iface_error(message); 239 goto out; 240 } 241 242 if (network && !strcmp(msg_interface, WPAS_DBUS_IFACE_NETWORK)) { 243 /* A method for one of this interface's configured networks */ 244 int nid = strtoul(network, NULL, 10); 245 if (errno != EINVAL) 246 reply = wpas_dispatch_network_method(message, wpa_s, 247 nid); 248 else 249 reply = wpas_dbus_new_invalid_network_error(message); 250 } else if (bssid && !strcmp(msg_interface, WPAS_DBUS_IFACE_BSSID)) { 251 /* A method for one of this interface's scanned BSSIDs */ 252 reply = wpas_dispatch_bssid_method(message, wpa_s, bssid); 253 } else if (!strcmp(msg_interface, WPAS_DBUS_IFACE_INTERFACE)) { 254 /* A method for an interface only. */ 255 if (!strcmp(method, "scan")) 256 reply = wpas_dbus_iface_scan(message, wpa_s); 257 else if (!strcmp(method, "scanResults")) 258 reply = wpas_dbus_iface_scan_results(message, wpa_s); 259 else if (!strcmp(method, "addNetwork")) 260 reply = wpas_dbus_iface_add_network(message, wpa_s); 261 else if (!strcmp(method, "removeNetwork")) 262 reply = wpas_dbus_iface_remove_network(message, wpa_s); 263 else if (!strcmp(method, "selectNetwork")) 264 reply = wpas_dbus_iface_select_network(message, wpa_s); 265 else if (!strcmp(method, "capabilities")) 266 reply = wpas_dbus_iface_capabilities(message, wpa_s); 267 else if (!strcmp(method, "disconnect")) 268 reply = wpas_dbus_iface_disconnect(message, wpa_s); 269 else if (!strcmp(method, "setAPScan")) 270 reply = wpas_dbus_iface_set_ap_scan(message, wpa_s); 271 else if (!strcmp(method, "setSmartcardModules")) 272 reply = wpas_dbus_iface_set_smartcard_modules(message, 273 wpa_s); 274 else if (!strcmp(method, "state")) 275 reply = wpas_dbus_iface_get_state(message, wpa_s); 276 else if (!strcmp(method, "scanning")) 277 reply = wpas_dbus_iface_get_scanning(message, wpa_s); 278 else if (!strcmp(method, "setBlobs")) 279 reply = wpas_dbus_iface_set_blobs(message, wpa_s); 280 else if (!strcmp(method, "removeBlobs")) 281 reply = wpas_dbus_iface_remove_blobs(message, wpa_s); 282#ifdef CONFIG_WPS 283 else if (!os_strcmp(method, "wpsPbc")) 284 reply = wpas_dbus_iface_wps_pbc(message, wpa_s); 285 else if (!os_strcmp(method, "wpsPin")) 286 reply = wpas_dbus_iface_wps_pin(message, wpa_s); 287 else if (!os_strcmp(method, "wpsReg")) 288 reply = wpas_dbus_iface_wps_reg(message, wpa_s); 289#endif /* CONFIG_WPS */
| 20#include "dbus_common_i.h" 21 22 23/** 24 * wpas_dbus_decompose_object_path - Decompose an interface object path into parts 25 * @path: The dbus object path 26 * @network: (out) the configured network this object path refers to, if any 27 * @bssid: (out) the scanned bssid this object path refers to, if any 28 * Returns: The object path of the network interface this path refers to 29 * 30 * For a given object path, decomposes the object path into object id, network, 31 * and BSSID parts, if those parts exist. 32 */ 33char * wpas_dbus_decompose_object_path(const char *path, char **network, 34 char **bssid) 35{ 36 const unsigned int dev_path_prefix_len = 37 strlen(WPAS_DBUS_PATH_INTERFACES "/"); 38 char *obj_path_only; 39 char *next_sep; 40 41 /* Be a bit paranoid about path */ 42 if (!path || strncmp(path, WPAS_DBUS_PATH_INTERFACES "/", 43 dev_path_prefix_len)) 44 return NULL; 45 46 /* Ensure there's something at the end of the path */ 47 if ((path + dev_path_prefix_len)[0] == '\0') 48 return NULL; 49 50 obj_path_only = os_strdup(path); 51 if (obj_path_only == NULL) 52 return NULL; 53 54 next_sep = strchr(obj_path_only + dev_path_prefix_len, '/'); 55 if (next_sep != NULL) { 56 const char *net_part = strstr(next_sep, 57 WPAS_DBUS_NETWORKS_PART "/"); 58 const char *bssid_part = strstr(next_sep, 59 WPAS_DBUS_BSSIDS_PART "/"); 60 61 if (network && net_part) { 62 /* Deal with a request for a configured network */ 63 const char *net_name = net_part + 64 strlen(WPAS_DBUS_NETWORKS_PART "/"); 65 *network = NULL; 66 if (strlen(net_name)) 67 *network = os_strdup(net_name); 68 } else if (bssid && bssid_part) { 69 /* Deal with a request for a scanned BSSID */ 70 const char *bssid_name = bssid_part + 71 strlen(WPAS_DBUS_BSSIDS_PART "/"); 72 if (strlen(bssid_name)) 73 *bssid = os_strdup(bssid_name); 74 else 75 *bssid = NULL; 76 } 77 78 /* Cut off interface object path before "/" */ 79 *next_sep = '\0'; 80 } 81 82 return obj_path_only; 83} 84 85 86/** 87 * wpas_dbus_new_invalid_iface_error - Return a new invalid interface error message 88 * @message: Pointer to incoming dbus message this error refers to 89 * Returns: A dbus error message 90 * 91 * Convenience function to create and return an invalid interface error 92 */ 93DBusMessage * wpas_dbus_new_invalid_iface_error(DBusMessage *message) 94{ 95 return dbus_message_new_error(message, WPAS_ERROR_INVALID_IFACE, 96 "wpa_supplicant knows nothing about " 97 "this interface."); 98} 99 100 101/** 102 * wpas_dbus_new_invalid_network_error - Return a new invalid network error message 103 * @message: Pointer to incoming dbus message this error refers to 104 * Returns: a dbus error message 105 * 106 * Convenience function to create and return an invalid network error 107 */ 108DBusMessage * wpas_dbus_new_invalid_network_error(DBusMessage *message) 109{ 110 return dbus_message_new_error(message, WPAS_ERROR_INVALID_NETWORK, 111 "The requested network does not exist."); 112} 113 114 115/** 116 * wpas_dbus_new_invalid_bssid_error - Return a new invalid bssid error message 117 * @message: Pointer to incoming dbus message this error refers to 118 * Returns: a dbus error message 119 * 120 * Convenience function to create and return an invalid bssid error 121 */ 122static DBusMessage * wpas_dbus_new_invalid_bssid_error(DBusMessage *message) 123{ 124 return dbus_message_new_error(message, WPAS_ERROR_INVALID_BSSID, 125 "The BSSID requested was invalid."); 126} 127 128 129/** 130 * wpas_dispatch_network_method - dispatch messages for configured networks 131 * @message: the incoming dbus message 132 * @wpa_s: a network interface's data 133 * @network_id: id of the configured network we're interested in 134 * Returns: a reply dbus message, or a dbus error message 135 * 136 * This function dispatches all incoming dbus messages for configured networks. 137 */ 138static DBusMessage * wpas_dispatch_network_method(DBusMessage *message, 139 struct wpa_supplicant *wpa_s, 140 int network_id) 141{ 142 DBusMessage *reply = NULL; 143 const char *method = dbus_message_get_member(message); 144 struct wpa_ssid *ssid; 145 146 ssid = wpa_config_get_network(wpa_s->conf, network_id); 147 if (ssid == NULL) 148 return wpas_dbus_new_invalid_network_error(message); 149 150 if (!strcmp(method, "set")) 151 reply = wpas_dbus_iface_set_network(message, wpa_s, ssid); 152 else if (!strcmp(method, "enable")) 153 reply = wpas_dbus_iface_enable_network(message, wpa_s, ssid); 154 else if (!strcmp(method, "disable")) 155 reply = wpas_dbus_iface_disable_network(message, wpa_s, ssid); 156 157 return reply; 158} 159 160 161/** 162 * wpas_dispatch_bssid_method - dispatch messages for scanned networks 163 * @message: the incoming dbus message 164 * @wpa_s: a network interface's data 165 * @bssid: bssid of the scanned network we're interested in 166 * Returns: a reply dbus message, or a dbus error message 167 * 168 * This function dispatches all incoming dbus messages for scanned networks. 169 */ 170static DBusMessage * wpas_dispatch_bssid_method(DBusMessage *message, 171 struct wpa_supplicant *wpa_s, 172 const char *bssid_txt) 173{ 174 u8 bssid[ETH_ALEN]; 175 struct wpa_bss *bss; 176 177 if (hexstr2bin(bssid_txt, bssid, ETH_ALEN) < 0) 178 return wpas_dbus_new_invalid_bssid_error(message); 179 180 bss = wpa_bss_get_bssid(wpa_s, bssid); 181 if (bss == NULL) 182 return wpas_dbus_new_invalid_bssid_error(message); 183 184 /* Dispatch the method call against the scanned bssid */ 185 if (os_strcmp(dbus_message_get_member(message), "properties") == 0) 186 return wpas_dbus_bssid_properties(message, wpa_s, bss); 187 188 return NULL; 189} 190 191 192/** 193 * wpas_iface_message_handler - Dispatch messages for interfaces or networks 194 * @connection: Connection to the system message bus 195 * @message: An incoming dbus message 196 * @user_data: A pointer to a dbus control interface data structure 197 * Returns: Whether or not the message was handled 198 * 199 * This function dispatches all incoming dbus messages for network interfaces, 200 * or objects owned by them, such as scanned BSSIDs and configured networks. 201 */ 202static DBusHandlerResult wpas_iface_message_handler(DBusConnection *connection, 203 DBusMessage *message, 204 void *user_data) 205{ 206 struct wpa_supplicant *wpa_s = user_data; 207 const char *method = dbus_message_get_member(message); 208 const char *path = dbus_message_get_path(message); 209 const char *msg_interface = dbus_message_get_interface(message); 210 char *iface_obj_path = NULL; 211 char *network = NULL; 212 char *bssid = NULL; 213 DBusMessage *reply = NULL; 214 215 /* Caller must specify a message interface */ 216 if (!msg_interface) 217 goto out; 218 219 iface_obj_path = wpas_dbus_decompose_object_path(path, &network, 220 &bssid); 221 if (iface_obj_path == NULL) { 222 reply = wpas_dbus_new_invalid_iface_error(message); 223 goto out; 224 } 225 226 /* Make sure the message's object path actually refers to the 227 * wpa_supplicant structure it's supposed to (which is wpa_s) 228 */ 229 if (wpa_supplicant_get_iface_by_dbus_path(wpa_s->global, 230 iface_obj_path) != wpa_s) { 231 reply = wpas_dbus_new_invalid_iface_error(message); 232 goto out; 233 } 234 235 if (network && !strcmp(msg_interface, WPAS_DBUS_IFACE_NETWORK)) { 236 /* A method for one of this interface's configured networks */ 237 int nid = strtoul(network, NULL, 10); 238 if (errno != EINVAL) 239 reply = wpas_dispatch_network_method(message, wpa_s, 240 nid); 241 else 242 reply = wpas_dbus_new_invalid_network_error(message); 243 } else if (bssid && !strcmp(msg_interface, WPAS_DBUS_IFACE_BSSID)) { 244 /* A method for one of this interface's scanned BSSIDs */ 245 reply = wpas_dispatch_bssid_method(message, wpa_s, bssid); 246 } else if (!strcmp(msg_interface, WPAS_DBUS_IFACE_INTERFACE)) { 247 /* A method for an interface only. */ 248 if (!strcmp(method, "scan")) 249 reply = wpas_dbus_iface_scan(message, wpa_s); 250 else if (!strcmp(method, "scanResults")) 251 reply = wpas_dbus_iface_scan_results(message, wpa_s); 252 else if (!strcmp(method, "addNetwork")) 253 reply = wpas_dbus_iface_add_network(message, wpa_s); 254 else if (!strcmp(method, "removeNetwork")) 255 reply = wpas_dbus_iface_remove_network(message, wpa_s); 256 else if (!strcmp(method, "selectNetwork")) 257 reply = wpas_dbus_iface_select_network(message, wpa_s); 258 else if (!strcmp(method, "capabilities")) 259 reply = wpas_dbus_iface_capabilities(message, wpa_s); 260 else if (!strcmp(method, "disconnect")) 261 reply = wpas_dbus_iface_disconnect(message, wpa_s); 262 else if (!strcmp(method, "setAPScan")) 263 reply = wpas_dbus_iface_set_ap_scan(message, wpa_s); 264 else if (!strcmp(method, "setSmartcardModules")) 265 reply = wpas_dbus_iface_set_smartcard_modules(message, 266 wpa_s); 267 else if (!strcmp(method, "state")) 268 reply = wpas_dbus_iface_get_state(message, wpa_s); 269 else if (!strcmp(method, "scanning")) 270 reply = wpas_dbus_iface_get_scanning(message, wpa_s); 271 else if (!strcmp(method, "setBlobs")) 272 reply = wpas_dbus_iface_set_blobs(message, wpa_s); 273 else if (!strcmp(method, "removeBlobs")) 274 reply = wpas_dbus_iface_remove_blobs(message, wpa_s); 275#ifdef CONFIG_WPS 276 else if (!os_strcmp(method, "wpsPbc")) 277 reply = wpas_dbus_iface_wps_pbc(message, wpa_s); 278 else if (!os_strcmp(method, "wpsPin")) 279 reply = wpas_dbus_iface_wps_pin(message, wpa_s); 280 else if (!os_strcmp(method, "wpsReg")) 281 reply = wpas_dbus_iface_wps_reg(message, wpa_s); 282#endif /* CONFIG_WPS */
|
| 283 else if (!os_strcmp(method, "flush")) 284 reply = wpas_dbus_iface_flush(message, wpa_s);
|
290 } 291 292 /* If the message was handled, send back the reply */ 293 if (reply) { 294 if (!dbus_message_get_no_reply(message)) 295 dbus_connection_send(connection, reply, NULL); 296 dbus_message_unref(reply); 297 } 298 299out: 300 os_free(iface_obj_path); 301 os_free(network); 302 os_free(bssid); 303 return reply ? DBUS_HANDLER_RESULT_HANDLED : 304 DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 305} 306 307 308/** 309 * wpas_message_handler - dispatch incoming dbus messages 310 * @connection: connection to the system message bus 311 * @message: an incoming dbus message 312 * @user_data: a pointer to a dbus control interface data structure 313 * Returns: whether or not the message was handled 314 * 315 * This function dispatches all incoming dbus messages to the correct 316 * handlers, depending on what the message's target object path is, 317 * and what the method call is. 318 */ 319static DBusHandlerResult wpas_message_handler(DBusConnection *connection, 320 DBusMessage *message, void *user_data) 321{ 322 struct wpas_dbus_priv *ctrl_iface = user_data; 323 const char *method; 324 const char *path; 325 const char *msg_interface; 326 DBusMessage *reply = NULL; 327 328 method = dbus_message_get_member(message); 329 path = dbus_message_get_path(message); 330 msg_interface = dbus_message_get_interface(message); 331 if (!method || !path || !ctrl_iface || !msg_interface) 332 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 333 334 /* Validate the method interface */ 335 if (strcmp(msg_interface, WPAS_DBUS_INTERFACE) != 0) 336 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 337 338 if (!strcmp(path, WPAS_DBUS_PATH)) { 339 /* dispatch methods against our global dbus interface here */ 340 if (!strcmp(method, "addInterface")) { 341 reply = wpas_dbus_global_add_interface( 342 message, ctrl_iface->global); 343 } else if (!strcmp(method, "removeInterface")) { 344 reply = wpas_dbus_global_remove_interface( 345 message, ctrl_iface->global); 346 } else if (!strcmp(method, "getInterface")) { 347 reply = wpas_dbus_global_get_interface( 348 message, ctrl_iface->global); 349 } else if (!strcmp(method, "setDebugParams")) { 350 reply = wpas_dbus_global_set_debugparams( 351 message, ctrl_iface->global); 352 } 353 } 354 355 /* If the message was handled, send back the reply */ 356 if (reply) { 357 if (!dbus_message_get_no_reply(message)) 358 dbus_connection_send(connection, reply, NULL); 359 dbus_message_unref(reply); 360 } 361 362 return reply ? DBUS_HANDLER_RESULT_HANDLED : 363 DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 364} 365 366 367/** 368 * wpa_supplicant_dbus_notify_scan_results - Send a scan results signal 369 * @wpa_s: %wpa_supplicant network interface data 370 * Returns: 0 on success, -1 on failure 371 * 372 * Notify listeners that this interface has updated scan results. 373 */ 374void wpa_supplicant_dbus_notify_scan_results(struct wpa_supplicant *wpa_s) 375{ 376 struct wpas_dbus_priv *iface = wpa_s->global->dbus; 377 DBusMessage *_signal; 378 379 /* Do nothing if the control interface is not turned on */ 380 if (iface == NULL) 381 return; 382 383 _signal = dbus_message_new_signal(wpa_s->dbus_path, 384 WPAS_DBUS_IFACE_INTERFACE, 385 "ScanResultsAvailable"); 386 if (_signal == NULL) { 387 wpa_printf(MSG_ERROR, "dbus: Not enough memory to send scan " 388 "results signal"); 389 return; 390 } 391 dbus_connection_send(iface->con, _signal, NULL); 392 dbus_message_unref(_signal); 393} 394 395 396/** 397 * wpa_supplicant_dbus_notify_state_change - Send a state change signal 398 * @wpa_s: %wpa_supplicant network interface data 399 * @new_state: new state wpa_supplicant is entering 400 * @old_state: old state wpa_supplicant is leaving 401 * Returns: 0 on success, -1 on failure 402 * 403 * Notify listeners that wpa_supplicant has changed state 404 */ 405void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s, 406 enum wpa_states new_state, 407 enum wpa_states old_state) 408{ 409 struct wpas_dbus_priv *iface; 410 DBusMessage *_signal = NULL; 411 const char *new_state_str, *old_state_str; 412 413 if (wpa_s->dbus_path == NULL) 414 return; /* Skip signal since D-Bus setup is not yet ready */ 415 416 /* Do nothing if the control interface is not turned on */ 417 if (wpa_s->global == NULL) 418 return; 419 iface = wpa_s->global->dbus; 420 if (iface == NULL) 421 return; 422 423 /* Only send signal if state really changed */ 424 if (new_state == old_state) 425 return; 426 427 _signal = dbus_message_new_signal(wpa_s->dbus_path, 428 WPAS_DBUS_IFACE_INTERFACE, 429 "StateChange"); 430 if (_signal == NULL) { 431 wpa_printf(MSG_ERROR, 432 "dbus: wpa_supplicant_dbus_notify_state_change: " 433 "could not create dbus signal; likely out of " 434 "memory"); 435 return; 436 } 437 438 new_state_str = wpa_supplicant_state_txt(new_state); 439 old_state_str = wpa_supplicant_state_txt(old_state); 440 if (new_state_str == NULL || old_state_str == NULL) { 441 wpa_printf(MSG_ERROR, 442 "dbus: wpa_supplicant_dbus_notify_state_change: " 443 "Could not convert state strings"); 444 goto out; 445 } 446 447 if (!dbus_message_append_args(_signal, 448 DBUS_TYPE_STRING, &new_state_str, 449 DBUS_TYPE_STRING, &old_state_str, 450 DBUS_TYPE_INVALID)) { 451 wpa_printf(MSG_ERROR, 452 "dbus: wpa_supplicant_dbus_notify_state_change: " 453 "Not enough memory to construct state change " 454 "signal"); 455 goto out; 456 } 457 458 dbus_connection_send(iface->con, _signal, NULL); 459 460out: 461 dbus_message_unref(_signal); 462} 463 464 465/** 466 * wpa_supplicant_dbus_notify_scanning - send scanning status 467 * @wpa_s: %wpa_supplicant network interface data 468 * Returns: 0 on success, -1 on failure 469 * 470 * Notify listeners of interface scanning state changes 471 */ 472void wpa_supplicant_dbus_notify_scanning(struct wpa_supplicant *wpa_s) 473{ 474 struct wpas_dbus_priv *iface = wpa_s->global->dbus; 475 DBusMessage *_signal; 476 dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE; 477 478 /* Do nothing if the control interface is not turned on */ 479 if (iface == NULL) 480 return; 481 482 _signal = dbus_message_new_signal(wpa_s->dbus_path, 483 WPAS_DBUS_IFACE_INTERFACE, 484 "Scanning"); 485 if (_signal == NULL) { 486 wpa_printf(MSG_ERROR, "dbus: Not enough memory to send scan " 487 "results signal"); 488 return; 489 } 490 491 if (dbus_message_append_args(_signal, 492 DBUS_TYPE_BOOLEAN, &scanning, 493 DBUS_TYPE_INVALID)) { 494 dbus_connection_send(iface->con, _signal, NULL); 495 } else { 496 wpa_printf(MSG_ERROR, "dbus: Not enough memory to construct " 497 "signal"); 498 } 499 dbus_message_unref(_signal); 500} 501 502 503#ifdef CONFIG_WPS 504void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s, 505 const struct wps_credential *cred) 506{ 507 struct wpas_dbus_priv *iface; 508 DBusMessage *_signal = NULL; 509 510 /* Do nothing if the control interface is not turned on */ 511 if (wpa_s->global == NULL) 512 return; 513 iface = wpa_s->global->dbus; 514 if (iface == NULL) 515 return; 516 517 _signal = dbus_message_new_signal(wpa_s->dbus_path, 518 WPAS_DBUS_IFACE_INTERFACE, 519 "WpsCred"); 520 if (_signal == NULL) { 521 wpa_printf(MSG_ERROR, 522 "dbus: wpa_supplicant_dbus_notify_wps_cred: " 523 "Could not create dbus signal; likely out of " 524 "memory"); 525 return; 526 } 527 528 if (!dbus_message_append_args(_signal, 529 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, 530 &cred->cred_attr, cred->cred_attr_len, 531 DBUS_TYPE_INVALID)) { 532 wpa_printf(MSG_ERROR, 533 "dbus: wpa_supplicant_dbus_notify_wps_cred: " 534 "Not enough memory to construct signal"); 535 goto out; 536 } 537 538 dbus_connection_send(iface->con, _signal, NULL); 539 540out: 541 dbus_message_unref(_signal); 542} 543#else /* CONFIG_WPS */ 544void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s, 545 const struct wps_credential *cred) 546{ 547} 548#endif /* CONFIG_WPS */ 549
| 285 } 286 287 /* If the message was handled, send back the reply */ 288 if (reply) { 289 if (!dbus_message_get_no_reply(message)) 290 dbus_connection_send(connection, reply, NULL); 291 dbus_message_unref(reply); 292 } 293 294out: 295 os_free(iface_obj_path); 296 os_free(network); 297 os_free(bssid); 298 return reply ? DBUS_HANDLER_RESULT_HANDLED : 299 DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 300} 301 302 303/** 304 * wpas_message_handler - dispatch incoming dbus messages 305 * @connection: connection to the system message bus 306 * @message: an incoming dbus message 307 * @user_data: a pointer to a dbus control interface data structure 308 * Returns: whether or not the message was handled 309 * 310 * This function dispatches all incoming dbus messages to the correct 311 * handlers, depending on what the message's target object path is, 312 * and what the method call is. 313 */ 314static DBusHandlerResult wpas_message_handler(DBusConnection *connection, 315 DBusMessage *message, void *user_data) 316{ 317 struct wpas_dbus_priv *ctrl_iface = user_data; 318 const char *method; 319 const char *path; 320 const char *msg_interface; 321 DBusMessage *reply = NULL; 322 323 method = dbus_message_get_member(message); 324 path = dbus_message_get_path(message); 325 msg_interface = dbus_message_get_interface(message); 326 if (!method || !path || !ctrl_iface || !msg_interface) 327 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 328 329 /* Validate the method interface */ 330 if (strcmp(msg_interface, WPAS_DBUS_INTERFACE) != 0) 331 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 332 333 if (!strcmp(path, WPAS_DBUS_PATH)) { 334 /* dispatch methods against our global dbus interface here */ 335 if (!strcmp(method, "addInterface")) { 336 reply = wpas_dbus_global_add_interface( 337 message, ctrl_iface->global); 338 } else if (!strcmp(method, "removeInterface")) { 339 reply = wpas_dbus_global_remove_interface( 340 message, ctrl_iface->global); 341 } else if (!strcmp(method, "getInterface")) { 342 reply = wpas_dbus_global_get_interface( 343 message, ctrl_iface->global); 344 } else if (!strcmp(method, "setDebugParams")) { 345 reply = wpas_dbus_global_set_debugparams( 346 message, ctrl_iface->global); 347 } 348 } 349 350 /* If the message was handled, send back the reply */ 351 if (reply) { 352 if (!dbus_message_get_no_reply(message)) 353 dbus_connection_send(connection, reply, NULL); 354 dbus_message_unref(reply); 355 } 356 357 return reply ? DBUS_HANDLER_RESULT_HANDLED : 358 DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 359} 360 361 362/** 363 * wpa_supplicant_dbus_notify_scan_results - Send a scan results signal 364 * @wpa_s: %wpa_supplicant network interface data 365 * Returns: 0 on success, -1 on failure 366 * 367 * Notify listeners that this interface has updated scan results. 368 */ 369void wpa_supplicant_dbus_notify_scan_results(struct wpa_supplicant *wpa_s) 370{ 371 struct wpas_dbus_priv *iface = wpa_s->global->dbus; 372 DBusMessage *_signal; 373 374 /* Do nothing if the control interface is not turned on */ 375 if (iface == NULL) 376 return; 377 378 _signal = dbus_message_new_signal(wpa_s->dbus_path, 379 WPAS_DBUS_IFACE_INTERFACE, 380 "ScanResultsAvailable"); 381 if (_signal == NULL) { 382 wpa_printf(MSG_ERROR, "dbus: Not enough memory to send scan " 383 "results signal"); 384 return; 385 } 386 dbus_connection_send(iface->con, _signal, NULL); 387 dbus_message_unref(_signal); 388} 389 390 391/** 392 * wpa_supplicant_dbus_notify_state_change - Send a state change signal 393 * @wpa_s: %wpa_supplicant network interface data 394 * @new_state: new state wpa_supplicant is entering 395 * @old_state: old state wpa_supplicant is leaving 396 * Returns: 0 on success, -1 on failure 397 * 398 * Notify listeners that wpa_supplicant has changed state 399 */ 400void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s, 401 enum wpa_states new_state, 402 enum wpa_states old_state) 403{ 404 struct wpas_dbus_priv *iface; 405 DBusMessage *_signal = NULL; 406 const char *new_state_str, *old_state_str; 407 408 if (wpa_s->dbus_path == NULL) 409 return; /* Skip signal since D-Bus setup is not yet ready */ 410 411 /* Do nothing if the control interface is not turned on */ 412 if (wpa_s->global == NULL) 413 return; 414 iface = wpa_s->global->dbus; 415 if (iface == NULL) 416 return; 417 418 /* Only send signal if state really changed */ 419 if (new_state == old_state) 420 return; 421 422 _signal = dbus_message_new_signal(wpa_s->dbus_path, 423 WPAS_DBUS_IFACE_INTERFACE, 424 "StateChange"); 425 if (_signal == NULL) { 426 wpa_printf(MSG_ERROR, 427 "dbus: wpa_supplicant_dbus_notify_state_change: " 428 "could not create dbus signal; likely out of " 429 "memory"); 430 return; 431 } 432 433 new_state_str = wpa_supplicant_state_txt(new_state); 434 old_state_str = wpa_supplicant_state_txt(old_state); 435 if (new_state_str == NULL || old_state_str == NULL) { 436 wpa_printf(MSG_ERROR, 437 "dbus: wpa_supplicant_dbus_notify_state_change: " 438 "Could not convert state strings"); 439 goto out; 440 } 441 442 if (!dbus_message_append_args(_signal, 443 DBUS_TYPE_STRING, &new_state_str, 444 DBUS_TYPE_STRING, &old_state_str, 445 DBUS_TYPE_INVALID)) { 446 wpa_printf(MSG_ERROR, 447 "dbus: wpa_supplicant_dbus_notify_state_change: " 448 "Not enough memory to construct state change " 449 "signal"); 450 goto out; 451 } 452 453 dbus_connection_send(iface->con, _signal, NULL); 454 455out: 456 dbus_message_unref(_signal); 457} 458 459 460/** 461 * wpa_supplicant_dbus_notify_scanning - send scanning status 462 * @wpa_s: %wpa_supplicant network interface data 463 * Returns: 0 on success, -1 on failure 464 * 465 * Notify listeners of interface scanning state changes 466 */ 467void wpa_supplicant_dbus_notify_scanning(struct wpa_supplicant *wpa_s) 468{ 469 struct wpas_dbus_priv *iface = wpa_s->global->dbus; 470 DBusMessage *_signal; 471 dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE; 472 473 /* Do nothing if the control interface is not turned on */ 474 if (iface == NULL) 475 return; 476 477 _signal = dbus_message_new_signal(wpa_s->dbus_path, 478 WPAS_DBUS_IFACE_INTERFACE, 479 "Scanning"); 480 if (_signal == NULL) { 481 wpa_printf(MSG_ERROR, "dbus: Not enough memory to send scan " 482 "results signal"); 483 return; 484 } 485 486 if (dbus_message_append_args(_signal, 487 DBUS_TYPE_BOOLEAN, &scanning, 488 DBUS_TYPE_INVALID)) { 489 dbus_connection_send(iface->con, _signal, NULL); 490 } else { 491 wpa_printf(MSG_ERROR, "dbus: Not enough memory to construct " 492 "signal"); 493 } 494 dbus_message_unref(_signal); 495} 496 497 498#ifdef CONFIG_WPS 499void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s, 500 const struct wps_credential *cred) 501{ 502 struct wpas_dbus_priv *iface; 503 DBusMessage *_signal = NULL; 504 505 /* Do nothing if the control interface is not turned on */ 506 if (wpa_s->global == NULL) 507 return; 508 iface = wpa_s->global->dbus; 509 if (iface == NULL) 510 return; 511 512 _signal = dbus_message_new_signal(wpa_s->dbus_path, 513 WPAS_DBUS_IFACE_INTERFACE, 514 "WpsCred"); 515 if (_signal == NULL) { 516 wpa_printf(MSG_ERROR, 517 "dbus: wpa_supplicant_dbus_notify_wps_cred: " 518 "Could not create dbus signal; likely out of " 519 "memory"); 520 return; 521 } 522 523 if (!dbus_message_append_args(_signal, 524 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, 525 &cred->cred_attr, cred->cred_attr_len, 526 DBUS_TYPE_INVALID)) { 527 wpa_printf(MSG_ERROR, 528 "dbus: wpa_supplicant_dbus_notify_wps_cred: " 529 "Not enough memory to construct signal"); 530 goto out; 531 } 532 533 dbus_connection_send(iface->con, _signal, NULL); 534 535out: 536 dbus_message_unref(_signal); 537} 538#else /* CONFIG_WPS */ 539void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s, 540 const struct wps_credential *cred) 541{ 542} 543#endif /* CONFIG_WPS */ 544
|
| 545void wpa_supplicant_dbus_notify_certification(struct wpa_supplicant *wpa_s, 546 int depth, const char *subject, 547 const char *cert_hash, 548 const struct wpabuf *cert) 549{ 550 struct wpas_dbus_priv *iface; 551 DBusMessage *_signal = NULL; 552 const char *hash; 553 const char *cert_hex; 554 int cert_hex_len;
|
550
| 555
|
| 556 /* Do nothing if the control interface is not turned on */ 557 if (wpa_s->global == NULL) 558 return; 559 iface = wpa_s->global->dbus; 560 if (iface == NULL) 561 return; 562 563 _signal = dbus_message_new_signal(wpa_s->dbus_path, 564 WPAS_DBUS_IFACE_INTERFACE, 565 "Certification"); 566 if (_signal == NULL) { 567 wpa_printf(MSG_ERROR, 568 "dbus: wpa_supplicant_dbus_notify_certification: " 569 "Could not create dbus signal; likely out of " 570 "memory"); 571 return; 572 } 573 574 hash = cert_hash ? cert_hash : ""; 575 cert_hex = cert ? wpabuf_head(cert) : ""; 576 cert_hex_len = cert ? wpabuf_len(cert) : 0; 577 578 if (!dbus_message_append_args(_signal, 579 DBUS_TYPE_INT32,&depth, 580 DBUS_TYPE_STRING, &subject, 581 DBUS_TYPE_STRING, &hash, 582 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, 583 &cert_hex, cert_hex_len, 584 DBUS_TYPE_INVALID)) { 585 wpa_printf(MSG_ERROR, 586 "dbus: wpa_supplicant_dbus_notify_certification: " 587 "Not enough memory to construct signal"); 588 goto out; 589 } 590 591 dbus_connection_send(iface->con, _signal, NULL); 592 593out: 594 dbus_message_unref(_signal); 595 596} 597 598
|
551/** 552 * wpa_supplicant_dbus_ctrl_iface_init - Initialize dbus control interface 553 * @global: Pointer to global data from wpa_supplicant_init() 554 * Returns: 0 on success, -1 on failure 555 * 556 * Initialize the dbus control interface and start receiving commands from 557 * external programs over the bus. 558 */ 559int wpa_supplicant_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface) 560{ 561 DBusError error; 562 int ret = -1; 563 DBusObjectPathVTable wpas_vtable = { 564 NULL, &wpas_message_handler, NULL, NULL, NULL, NULL 565 }; 566 567 /* Register the message handler for the global dbus interface */ 568 if (!dbus_connection_register_object_path(iface->con, 569 WPAS_DBUS_PATH, &wpas_vtable, 570 iface)) { 571 wpa_printf(MSG_ERROR, "dbus: Could not set up message " 572 "handler"); 573 return -1; 574 } 575 576 /* Register our service with the message bus */ 577 dbus_error_init(&error); 578 switch (dbus_bus_request_name(iface->con, WPAS_DBUS_SERVICE, 579 0, &error)) { 580 case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER: 581 ret = 0; 582 break; 583 case DBUS_REQUEST_NAME_REPLY_EXISTS: 584 case DBUS_REQUEST_NAME_REPLY_IN_QUEUE: 585 case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER: 586 wpa_printf(MSG_ERROR, "dbus: Could not request service name: " 587 "already registered"); 588 break; 589 default: 590 wpa_printf(MSG_ERROR, "dbus: Could not request service name: " 591 "%s %s", error.name, error.message); 592 break; 593 } 594 dbus_error_free(&error); 595 596 if (ret != 0) 597 return -1; 598 599 wpa_printf(MSG_DEBUG, "Providing DBus service '" WPAS_DBUS_SERVICE 600 "'."); 601 602 return 0; 603} 604 605 606/** 607 * wpas_dbus_register_new_iface - Register a new interface with dbus 608 * @wpa_s: %wpa_supplicant interface description structure to register 609 * Returns: 0 on success, -1 on error 610 * 611 * Registers a new interface with dbus and assigns it a dbus object path. 612 */ 613int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s) 614{ 615 struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus; 616 DBusConnection * con; 617 u32 next; 618 DBusObjectPathVTable vtable = { 619 NULL, &wpas_iface_message_handler, NULL, NULL, NULL, NULL 620 }; 621 622 /* Do nothing if the control interface is not turned on */ 623 if (ctrl_iface == NULL) 624 return 0; 625 626 con = ctrl_iface->con; 627 next = ctrl_iface->next_objid++; 628 629 /* Create and set the interface's object path */ 630 wpa_s->dbus_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX); 631 if (wpa_s->dbus_path == NULL) 632 return -1; 633 os_snprintf(wpa_s->dbus_path, WPAS_DBUS_OBJECT_PATH_MAX, 634 WPAS_DBUS_PATH_INTERFACES "/%u", 635 next); 636 637 /* Register the message handler for the interface functions */ 638 if (!dbus_connection_register_fallback(con, wpa_s->dbus_path, &vtable, 639 wpa_s)) { 640 wpa_printf(MSG_ERROR, "dbus: Could not set up message " 641 "handler for interface %s", wpa_s->ifname); 642 return -1; 643 } 644 645 return 0; 646} 647 648 649/** 650 * wpas_dbus_unregister_iface - Unregister an interface from dbus 651 * @wpa_s: wpa_supplicant interface structure 652 * Returns: 0 on success, -1 on failure 653 * 654 * Unregisters the interface with dbus 655 */ 656int wpas_dbus_unregister_iface(struct wpa_supplicant *wpa_s) 657{ 658 struct wpas_dbus_priv *ctrl_iface; 659 DBusConnection *con; 660 661 /* Do nothing if the control interface is not turned on */ 662 if (wpa_s == NULL || wpa_s->global == NULL) 663 return 0; 664 ctrl_iface = wpa_s->global->dbus; 665 if (ctrl_iface == NULL) 666 return 0; 667 668 con = ctrl_iface->con; 669 if (!dbus_connection_unregister_object_path(con, wpa_s->dbus_path)) 670 return -1; 671 672 os_free(wpa_s->dbus_path); 673 wpa_s->dbus_path = NULL; 674 675 return 0; 676} 677 678 679/** 680 * wpa_supplicant_get_iface_by_dbus_path - Get a new network interface 681 * @global: Pointer to global data from wpa_supplicant_init() 682 * @path: Pointer to a dbus object path representing an interface 683 * Returns: Pointer to the interface or %NULL if not found 684 */ 685struct wpa_supplicant * wpa_supplicant_get_iface_by_dbus_path( 686 struct wpa_global *global, const char *path) 687{ 688 struct wpa_supplicant *wpa_s; 689 690 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { 691 if (strcmp(wpa_s->dbus_path, path) == 0) 692 return wpa_s; 693 } 694 return NULL; 695}
| 599/** 600 * wpa_supplicant_dbus_ctrl_iface_init - Initialize dbus control interface 601 * @global: Pointer to global data from wpa_supplicant_init() 602 * Returns: 0 on success, -1 on failure 603 * 604 * Initialize the dbus control interface and start receiving commands from 605 * external programs over the bus. 606 */ 607int wpa_supplicant_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface) 608{ 609 DBusError error; 610 int ret = -1; 611 DBusObjectPathVTable wpas_vtable = { 612 NULL, &wpas_message_handler, NULL, NULL, NULL, NULL 613 }; 614 615 /* Register the message handler for the global dbus interface */ 616 if (!dbus_connection_register_object_path(iface->con, 617 WPAS_DBUS_PATH, &wpas_vtable, 618 iface)) { 619 wpa_printf(MSG_ERROR, "dbus: Could not set up message " 620 "handler"); 621 return -1; 622 } 623 624 /* Register our service with the message bus */ 625 dbus_error_init(&error); 626 switch (dbus_bus_request_name(iface->con, WPAS_DBUS_SERVICE, 627 0, &error)) { 628 case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER: 629 ret = 0; 630 break; 631 case DBUS_REQUEST_NAME_REPLY_EXISTS: 632 case DBUS_REQUEST_NAME_REPLY_IN_QUEUE: 633 case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER: 634 wpa_printf(MSG_ERROR, "dbus: Could not request service name: " 635 "already registered"); 636 break; 637 default: 638 wpa_printf(MSG_ERROR, "dbus: Could not request service name: " 639 "%s %s", error.name, error.message); 640 break; 641 } 642 dbus_error_free(&error); 643 644 if (ret != 0) 645 return -1; 646 647 wpa_printf(MSG_DEBUG, "Providing DBus service '" WPAS_DBUS_SERVICE 648 "'."); 649 650 return 0; 651} 652 653 654/** 655 * wpas_dbus_register_new_iface - Register a new interface with dbus 656 * @wpa_s: %wpa_supplicant interface description structure to register 657 * Returns: 0 on success, -1 on error 658 * 659 * Registers a new interface with dbus and assigns it a dbus object path. 660 */ 661int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s) 662{ 663 struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus; 664 DBusConnection * con; 665 u32 next; 666 DBusObjectPathVTable vtable = { 667 NULL, &wpas_iface_message_handler, NULL, NULL, NULL, NULL 668 }; 669 670 /* Do nothing if the control interface is not turned on */ 671 if (ctrl_iface == NULL) 672 return 0; 673 674 con = ctrl_iface->con; 675 next = ctrl_iface->next_objid++; 676 677 /* Create and set the interface's object path */ 678 wpa_s->dbus_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX); 679 if (wpa_s->dbus_path == NULL) 680 return -1; 681 os_snprintf(wpa_s->dbus_path, WPAS_DBUS_OBJECT_PATH_MAX, 682 WPAS_DBUS_PATH_INTERFACES "/%u", 683 next); 684 685 /* Register the message handler for the interface functions */ 686 if (!dbus_connection_register_fallback(con, wpa_s->dbus_path, &vtable, 687 wpa_s)) { 688 wpa_printf(MSG_ERROR, "dbus: Could not set up message " 689 "handler for interface %s", wpa_s->ifname); 690 return -1; 691 } 692 693 return 0; 694} 695 696 697/** 698 * wpas_dbus_unregister_iface - Unregister an interface from dbus 699 * @wpa_s: wpa_supplicant interface structure 700 * Returns: 0 on success, -1 on failure 701 * 702 * Unregisters the interface with dbus 703 */ 704int wpas_dbus_unregister_iface(struct wpa_supplicant *wpa_s) 705{ 706 struct wpas_dbus_priv *ctrl_iface; 707 DBusConnection *con; 708 709 /* Do nothing if the control interface is not turned on */ 710 if (wpa_s == NULL || wpa_s->global == NULL) 711 return 0; 712 ctrl_iface = wpa_s->global->dbus; 713 if (ctrl_iface == NULL) 714 return 0; 715 716 con = ctrl_iface->con; 717 if (!dbus_connection_unregister_object_path(con, wpa_s->dbus_path)) 718 return -1; 719 720 os_free(wpa_s->dbus_path); 721 wpa_s->dbus_path = NULL; 722 723 return 0; 724} 725 726 727/** 728 * wpa_supplicant_get_iface_by_dbus_path - Get a new network interface 729 * @global: Pointer to global data from wpa_supplicant_init() 730 * @path: Pointer to a dbus object path representing an interface 731 * Returns: Pointer to the interface or %NULL if not found 732 */ 733struct wpa_supplicant * wpa_supplicant_get_iface_by_dbus_path( 734 struct wpa_global *global, const char *path) 735{ 736 struct wpa_supplicant *wpa_s; 737 738 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { 739 if (strcmp(wpa_s->dbus_path, path) == 0) 740 return wpa_s; 741 } 742 return NULL; 743}
|