wpa_supplicant: Drop the old D-Bus interface support
This drops support for the fi.epitest.hostap.WPASupplicant D-Bus name along with the associated CONFIG_CTRL_IFACE_DBUS option. Nothing should really be using this since 2010. This is a just a straightforward removal. Perhaps the dbus_common.c and dbus_new.c can be merged now. Also, the "_NEW" suffix of the config option seems to make even less sense than it used to. Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>master
parent
192d061add
commit
6a8dee76d4
@ -1,745 +0,0 @@
|
|||||||
/*
|
|
||||||
* WPA Supplicant / dbus-based control interface
|
|
||||||
* Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
|
|
||||||
*
|
|
||||||
* This software may be distributed under the terms of the BSD license.
|
|
||||||
* See README for more details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "includes.h"
|
|
||||||
#include <dbus/dbus.h>
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "eloop.h"
|
|
||||||
#include "wps/wps.h"
|
|
||||||
#include "../config.h"
|
|
||||||
#include "../wpa_supplicant_i.h"
|
|
||||||
#include "../bss.h"
|
|
||||||
#include "dbus_old.h"
|
|
||||||
#include "dbus_old_handlers.h"
|
|
||||||
#include "dbus_common_i.h"
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_dbus_decompose_object_path - Decompose an interface object path into parts
|
|
||||||
* @path: The dbus object path
|
|
||||||
* @network: (out) the configured network this object path refers to, if any
|
|
||||||
* @bssid: (out) the scanned bssid this object path refers to, if any
|
|
||||||
* Returns: The object path of the network interface this path refers to
|
|
||||||
*
|
|
||||||
* For a given object path, decomposes the object path into object id, network,
|
|
||||||
* and BSSID parts, if those parts exist.
|
|
||||||
*/
|
|
||||||
char * wpas_dbus_decompose_object_path(const char *path, char **network,
|
|
||||||
char **bssid)
|
|
||||||
{
|
|
||||||
const unsigned int dev_path_prefix_len =
|
|
||||||
strlen(WPAS_DBUS_PATH_INTERFACES "/");
|
|
||||||
char *obj_path_only;
|
|
||||||
char *next_sep;
|
|
||||||
|
|
||||||
/* Be a bit paranoid about path */
|
|
||||||
if (!path || strncmp(path, WPAS_DBUS_PATH_INTERFACES "/",
|
|
||||||
dev_path_prefix_len))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
/* Ensure there's something at the end of the path */
|
|
||||||
if ((path + dev_path_prefix_len)[0] == '\0')
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
obj_path_only = os_strdup(path);
|
|
||||||
if (obj_path_only == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
next_sep = strchr(obj_path_only + dev_path_prefix_len, '/');
|
|
||||||
if (next_sep != NULL) {
|
|
||||||
const char *net_part = strstr(next_sep,
|
|
||||||
WPAS_DBUS_NETWORKS_PART "/");
|
|
||||||
const char *bssid_part = strstr(next_sep,
|
|
||||||
WPAS_DBUS_BSSIDS_PART "/");
|
|
||||||
|
|
||||||
if (network && net_part) {
|
|
||||||
/* Deal with a request for a configured network */
|
|
||||||
const char *net_name = net_part +
|
|
||||||
strlen(WPAS_DBUS_NETWORKS_PART "/");
|
|
||||||
*network = NULL;
|
|
||||||
if (strlen(net_name))
|
|
||||||
*network = os_strdup(net_name);
|
|
||||||
} else if (bssid && bssid_part) {
|
|
||||||
/* Deal with a request for a scanned BSSID */
|
|
||||||
const char *bssid_name = bssid_part +
|
|
||||||
strlen(WPAS_DBUS_BSSIDS_PART "/");
|
|
||||||
if (strlen(bssid_name))
|
|
||||||
*bssid = os_strdup(bssid_name);
|
|
||||||
else
|
|
||||||
*bssid = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Cut off interface object path before "/" */
|
|
||||||
*next_sep = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj_path_only;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_dbus_new_invalid_iface_error - Return a new invalid interface error message
|
|
||||||
* @message: Pointer to incoming dbus message this error refers to
|
|
||||||
* Returns: A dbus error message
|
|
||||||
*
|
|
||||||
* Convenience function to create and return an invalid interface error
|
|
||||||
*/
|
|
||||||
DBusMessage * wpas_dbus_new_invalid_iface_error(DBusMessage *message)
|
|
||||||
{
|
|
||||||
return dbus_message_new_error(
|
|
||||||
message, WPAS_ERROR_INVALID_IFACE,
|
|
||||||
"wpa_supplicant knows nothing about this interface.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_dbus_new_invalid_network_error - Return a new invalid network error message
|
|
||||||
* @message: Pointer to incoming dbus message this error refers to
|
|
||||||
* Returns: a dbus error message
|
|
||||||
*
|
|
||||||
* Convenience function to create and return an invalid network error
|
|
||||||
*/
|
|
||||||
DBusMessage * wpas_dbus_new_invalid_network_error(DBusMessage *message)
|
|
||||||
{
|
|
||||||
return dbus_message_new_error(message, WPAS_ERROR_INVALID_NETWORK,
|
|
||||||
"The requested network does not exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_dbus_new_invalid_bssid_error - Return a new invalid bssid error message
|
|
||||||
* @message: Pointer to incoming dbus message this error refers to
|
|
||||||
* Returns: a dbus error message
|
|
||||||
*
|
|
||||||
* Convenience function to create and return an invalid bssid error
|
|
||||||
*/
|
|
||||||
static DBusMessage * wpas_dbus_new_invalid_bssid_error(DBusMessage *message)
|
|
||||||
{
|
|
||||||
return dbus_message_new_error(message, WPAS_ERROR_INVALID_BSSID,
|
|
||||||
"The BSSID requested was invalid.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_dispatch_network_method - dispatch messages for configured networks
|
|
||||||
* @message: the incoming dbus message
|
|
||||||
* @wpa_s: a network interface's data
|
|
||||||
* @network_id: id of the configured network we're interested in
|
|
||||||
* Returns: a reply dbus message, or a dbus error message
|
|
||||||
*
|
|
||||||
* This function dispatches all incoming dbus messages for configured networks.
|
|
||||||
*/
|
|
||||||
static DBusMessage * wpas_dispatch_network_method(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s,
|
|
||||||
int network_id)
|
|
||||||
{
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
const char *method = dbus_message_get_member(message);
|
|
||||||
struct wpa_ssid *ssid;
|
|
||||||
|
|
||||||
ssid = wpa_config_get_network(wpa_s->conf, network_id);
|
|
||||||
if (ssid == NULL)
|
|
||||||
return wpas_dbus_new_invalid_network_error(message);
|
|
||||||
|
|
||||||
if (!strcmp(method, "set"))
|
|
||||||
reply = wpas_dbus_iface_set_network(message, wpa_s, ssid);
|
|
||||||
else if (!strcmp(method, "enable"))
|
|
||||||
reply = wpas_dbus_iface_enable_network(message, wpa_s, ssid);
|
|
||||||
else if (!strcmp(method, "disable"))
|
|
||||||
reply = wpas_dbus_iface_disable_network(message, wpa_s, ssid);
|
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_dispatch_bssid_method - dispatch messages for scanned networks
|
|
||||||
* @message: the incoming dbus message
|
|
||||||
* @wpa_s: a network interface's data
|
|
||||||
* @bssid: bssid of the scanned network we're interested in
|
|
||||||
* Returns: a reply dbus message, or a dbus error message
|
|
||||||
*
|
|
||||||
* This function dispatches all incoming dbus messages for scanned networks.
|
|
||||||
*/
|
|
||||||
static DBusMessage * wpas_dispatch_bssid_method(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s,
|
|
||||||
const char *bssid_txt)
|
|
||||||
{
|
|
||||||
u8 bssid[ETH_ALEN];
|
|
||||||
struct wpa_bss *bss;
|
|
||||||
|
|
||||||
if (hexstr2bin(bssid_txt, bssid, ETH_ALEN) < 0)
|
|
||||||
return wpas_dbus_new_invalid_bssid_error(message);
|
|
||||||
|
|
||||||
bss = wpa_bss_get_bssid(wpa_s, bssid);
|
|
||||||
if (bss == NULL)
|
|
||||||
return wpas_dbus_new_invalid_bssid_error(message);
|
|
||||||
|
|
||||||
/* Dispatch the method call against the scanned bssid */
|
|
||||||
if (os_strcmp(dbus_message_get_member(message), "properties") == 0)
|
|
||||||
return wpas_dbus_bssid_properties(message, wpa_s, bss);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_iface_message_handler - Dispatch messages for interfaces or networks
|
|
||||||
* @connection: Connection to the system message bus
|
|
||||||
* @message: An incoming dbus message
|
|
||||||
* @user_data: A pointer to a dbus control interface data structure
|
|
||||||
* Returns: Whether or not the message was handled
|
|
||||||
*
|
|
||||||
* This function dispatches all incoming dbus messages for network interfaces,
|
|
||||||
* or objects owned by them, such as scanned BSSIDs and configured networks.
|
|
||||||
*/
|
|
||||||
static DBusHandlerResult wpas_iface_message_handler(DBusConnection *connection,
|
|
||||||
DBusMessage *message,
|
|
||||||
void *user_data)
|
|
||||||
{
|
|
||||||
struct wpa_supplicant *wpa_s = user_data;
|
|
||||||
const char *method = dbus_message_get_member(message);
|
|
||||||
const char *path = dbus_message_get_path(message);
|
|
||||||
const char *msg_interface = dbus_message_get_interface(message);
|
|
||||||
char *iface_obj_path = NULL;
|
|
||||||
char *network = NULL;
|
|
||||||
char *bssid = NULL;
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
|
|
||||||
/* Caller must specify a message interface */
|
|
||||||
if (!msg_interface)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
wpa_printf(MSG_MSGDUMP, "dbus[old/iface]: %s.%s (%s) [%s]",
|
|
||||||
msg_interface, method, path,
|
|
||||||
dbus_message_get_signature(message));
|
|
||||||
|
|
||||||
iface_obj_path = wpas_dbus_decompose_object_path(path, &network,
|
|
||||||
&bssid);
|
|
||||||
if (iface_obj_path == NULL) {
|
|
||||||
reply = wpas_dbus_new_invalid_iface_error(message);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make sure the message's object path actually refers to the
|
|
||||||
* wpa_supplicant structure it's supposed to (which is wpa_s)
|
|
||||||
*/
|
|
||||||
if (wpa_supplicant_get_iface_by_dbus_path(wpa_s->global,
|
|
||||||
iface_obj_path) != wpa_s) {
|
|
||||||
reply = wpas_dbus_new_invalid_iface_error(message);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (network && !strcmp(msg_interface, WPAS_DBUS_IFACE_NETWORK)) {
|
|
||||||
/* A method for one of this interface's configured networks */
|
|
||||||
int nid = strtoul(network, NULL, 10);
|
|
||||||
|
|
||||||
if (errno != EINVAL)
|
|
||||||
reply = wpas_dispatch_network_method(message, wpa_s,
|
|
||||||
nid);
|
|
||||||
else
|
|
||||||
reply = wpas_dbus_new_invalid_network_error(message);
|
|
||||||
} else if (bssid && !strcmp(msg_interface, WPAS_DBUS_IFACE_BSSID)) {
|
|
||||||
/* A method for one of this interface's scanned BSSIDs */
|
|
||||||
reply = wpas_dispatch_bssid_method(message, wpa_s, bssid);
|
|
||||||
} else if (!strcmp(msg_interface, WPAS_DBUS_IFACE_INTERFACE)) {
|
|
||||||
/* A method for an interface only. */
|
|
||||||
if (!strcmp(method, "scan"))
|
|
||||||
reply = wpas_dbus_iface_scan(message, wpa_s);
|
|
||||||
else if (!strcmp(method, "scanResults"))
|
|
||||||
reply = wpas_dbus_iface_scan_results(message, wpa_s);
|
|
||||||
else if (!strcmp(method, "addNetwork"))
|
|
||||||
reply = wpas_dbus_iface_add_network(message, wpa_s);
|
|
||||||
else if (!strcmp(method, "removeNetwork"))
|
|
||||||
reply = wpas_dbus_iface_remove_network(message, wpa_s);
|
|
||||||
else if (!strcmp(method, "selectNetwork"))
|
|
||||||
reply = wpas_dbus_iface_select_network(message, wpa_s);
|
|
||||||
else if (!strcmp(method, "capabilities"))
|
|
||||||
reply = wpas_dbus_iface_capabilities(message, wpa_s);
|
|
||||||
else if (!strcmp(method, "disconnect"))
|
|
||||||
reply = wpas_dbus_iface_disconnect(message, wpa_s);
|
|
||||||
else if (!strcmp(method, "setAPScan"))
|
|
||||||
reply = wpas_dbus_iface_set_ap_scan(message, wpa_s);
|
|
||||||
else if (!strcmp(method, "setSmartcardModules"))
|
|
||||||
reply = wpas_dbus_iface_set_smartcard_modules(message,
|
|
||||||
wpa_s);
|
|
||||||
else if (!strcmp(method, "state"))
|
|
||||||
reply = wpas_dbus_iface_get_state(message, wpa_s);
|
|
||||||
else if (!strcmp(method, "scanning"))
|
|
||||||
reply = wpas_dbus_iface_get_scanning(message, wpa_s);
|
|
||||||
#ifndef CONFIG_NO_CONFIG_BLOBS
|
|
||||||
else if (!strcmp(method, "setBlobs"))
|
|
||||||
reply = wpas_dbus_iface_set_blobs(message, wpa_s);
|
|
||||||
else if (!strcmp(method, "removeBlobs"))
|
|
||||||
reply = wpas_dbus_iface_remove_blobs(message, wpa_s);
|
|
||||||
#endif /* CONFIG_NO_CONFIG_BLOBS */
|
|
||||||
#ifdef CONFIG_WPS
|
|
||||||
else if (os_strcmp(method, "wpsPbc") == 0)
|
|
||||||
reply = wpas_dbus_iface_wps_pbc(message, wpa_s);
|
|
||||||
else if (os_strcmp(method, "wpsPin") == 0)
|
|
||||||
reply = wpas_dbus_iface_wps_pin(message, wpa_s);
|
|
||||||
else if (os_strcmp(method, "wpsReg") == 0)
|
|
||||||
reply = wpas_dbus_iface_wps_reg(message, wpa_s);
|
|
||||||
#endif /* CONFIG_WPS */
|
|
||||||
else if (os_strcmp(method, "flush") == 0)
|
|
||||||
reply = wpas_dbus_iface_flush(message, wpa_s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the message was handled, send back the reply */
|
|
||||||
out:
|
|
||||||
if (reply) {
|
|
||||||
if (!dbus_message_get_no_reply(message))
|
|
||||||
dbus_connection_send(connection, reply, NULL);
|
|
||||||
dbus_message_unref(reply);
|
|
||||||
}
|
|
||||||
|
|
||||||
os_free(iface_obj_path);
|
|
||||||
os_free(network);
|
|
||||||
os_free(bssid);
|
|
||||||
return reply ? DBUS_HANDLER_RESULT_HANDLED :
|
|
||||||
DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_message_handler - dispatch incoming dbus messages
|
|
||||||
* @connection: connection to the system message bus
|
|
||||||
* @message: an incoming dbus message
|
|
||||||
* @user_data: a pointer to a dbus control interface data structure
|
|
||||||
* Returns: whether or not the message was handled
|
|
||||||
*
|
|
||||||
* This function dispatches all incoming dbus messages to the correct
|
|
||||||
* handlers, depending on what the message's target object path is,
|
|
||||||
* and what the method call is.
|
|
||||||
*/
|
|
||||||
static DBusHandlerResult wpas_message_handler(DBusConnection *connection,
|
|
||||||
DBusMessage *message, void *user_data)
|
|
||||||
{
|
|
||||||
struct wpas_dbus_priv *ctrl_iface = user_data;
|
|
||||||
const char *method;
|
|
||||||
const char *path;
|
|
||||||
const char *msg_interface;
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
|
|
||||||
method = dbus_message_get_member(message);
|
|
||||||
path = dbus_message_get_path(message);
|
|
||||||
msg_interface = dbus_message_get_interface(message);
|
|
||||||
if (!method || !path || !ctrl_iface || !msg_interface)
|
|
||||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
|
||||||
|
|
||||||
wpa_printf(MSG_MSGDUMP, "dbus[old]: %s.%s (%s) [%s]",
|
|
||||||
msg_interface, method, path,
|
|
||||||
dbus_message_get_signature(message));
|
|
||||||
|
|
||||||
/* Validate the method interface */
|
|
||||||
if (strcmp(msg_interface, WPAS_DBUS_INTERFACE) != 0)
|
|
||||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
|
||||||
|
|
||||||
if (!strcmp(path, WPAS_DBUS_PATH)) {
|
|
||||||
/* dispatch methods against our global dbus interface here */
|
|
||||||
if (!strcmp(method, "addInterface")) {
|
|
||||||
reply = wpas_dbus_global_add_interface(
|
|
||||||
message, ctrl_iface->global);
|
|
||||||
} else if (!strcmp(method, "removeInterface")) {
|
|
||||||
reply = wpas_dbus_global_remove_interface(
|
|
||||||
message, ctrl_iface->global);
|
|
||||||
} else if (!strcmp(method, "getInterface")) {
|
|
||||||
reply = wpas_dbus_global_get_interface(
|
|
||||||
message, ctrl_iface->global);
|
|
||||||
} else if (!strcmp(method, "setDebugParams")) {
|
|
||||||
reply = wpas_dbus_global_set_debugparams(
|
|
||||||
message, ctrl_iface->global);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the message was handled, send back the reply */
|
|
||||||
if (reply) {
|
|
||||||
if (!dbus_message_get_no_reply(message))
|
|
||||||
dbus_connection_send(connection, reply, NULL);
|
|
||||||
dbus_message_unref(reply);
|
|
||||||
}
|
|
||||||
|
|
||||||
return reply ? DBUS_HANDLER_RESULT_HANDLED :
|
|
||||||
DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpa_supplicant_dbus_notify_scan_results - Send a scan results signal
|
|
||||||
* @wpa_s: %wpa_supplicant network interface data
|
|
||||||
* Returns: 0 on success, -1 on failure
|
|
||||||
*
|
|
||||||
* Notify listeners that this interface has updated scan results.
|
|
||||||
*/
|
|
||||||
void wpa_supplicant_dbus_notify_scan_results(struct wpa_supplicant *wpa_s)
|
|
||||||
{
|
|
||||||
struct wpas_dbus_priv *iface = wpa_s->global->dbus;
|
|
||||||
DBusMessage *_signal;
|
|
||||||
|
|
||||||
/* Do nothing if the control interface is not turned on */
|
|
||||||
if (iface == NULL || !wpa_s->dbus_path)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_signal = dbus_message_new_signal(wpa_s->dbus_path,
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE,
|
|
||||||
"ScanResultsAvailable");
|
|
||||||
if (_signal == NULL) {
|
|
||||||
wpa_printf(MSG_ERROR,
|
|
||||||
"dbus: Not enough memory to send scan results signal");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dbus_connection_send(iface->con, _signal, NULL);
|
|
||||||
dbus_message_unref(_signal);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpa_supplicant_dbus_notify_state_change - Send a state change signal
|
|
||||||
* @wpa_s: %wpa_supplicant network interface data
|
|
||||||
* @new_state: new state wpa_supplicant is entering
|
|
||||||
* @old_state: old state wpa_supplicant is leaving
|
|
||||||
* Returns: 0 on success, -1 on failure
|
|
||||||
*
|
|
||||||
* Notify listeners that wpa_supplicant has changed state
|
|
||||||
*/
|
|
||||||
void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s,
|
|
||||||
enum wpa_states new_state,
|
|
||||||
enum wpa_states old_state)
|
|
||||||
{
|
|
||||||
struct wpas_dbus_priv *iface;
|
|
||||||
DBusMessage *_signal = NULL;
|
|
||||||
const char *new_state_str, *old_state_str;
|
|
||||||
|
|
||||||
if (wpa_s->dbus_path == NULL)
|
|
||||||
return; /* Skip signal since D-Bus setup is not yet ready */
|
|
||||||
|
|
||||||
/* Do nothing if the control interface is not turned on */
|
|
||||||
if (wpa_s->global == NULL)
|
|
||||||
return;
|
|
||||||
iface = wpa_s->global->dbus;
|
|
||||||
if (iface == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Only send signal if state really changed */
|
|
||||||
if (new_state == old_state)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_signal = dbus_message_new_signal(wpa_s->dbus_path,
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE,
|
|
||||||
"StateChange");
|
|
||||||
if (_signal == NULL) {
|
|
||||||
wpa_printf(MSG_ERROR,
|
|
||||||
"dbus: %s: could not create dbus signal; likely out of memory",
|
|
||||||
__func__);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
new_state_str = wpa_supplicant_state_txt(new_state);
|
|
||||||
old_state_str = wpa_supplicant_state_txt(old_state);
|
|
||||||
|
|
||||||
if (!dbus_message_append_args(_signal,
|
|
||||||
DBUS_TYPE_STRING, &new_state_str,
|
|
||||||
DBUS_TYPE_STRING, &old_state_str,
|
|
||||||
DBUS_TYPE_INVALID)) {
|
|
||||||
wpa_printf(MSG_ERROR,
|
|
||||||
"dbus: %s: Not enough memory to construct state change signal",
|
|
||||||
__func__);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_connection_send(iface->con, _signal, NULL);
|
|
||||||
|
|
||||||
out:
|
|
||||||
dbus_message_unref(_signal);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpa_supplicant_dbus_notify_scanning - send scanning status
|
|
||||||
* @wpa_s: %wpa_supplicant network interface data
|
|
||||||
* Returns: 0 on success, -1 on failure
|
|
||||||
*
|
|
||||||
* Notify listeners of interface scanning state changes
|
|
||||||
*/
|
|
||||||
void wpa_supplicant_dbus_notify_scanning(struct wpa_supplicant *wpa_s)
|
|
||||||
{
|
|
||||||
struct wpas_dbus_priv *iface = wpa_s->global->dbus;
|
|
||||||
DBusMessage *_signal;
|
|
||||||
dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
|
|
||||||
|
|
||||||
/* Do nothing if the control interface is not turned on */
|
|
||||||
if (iface == NULL || !wpa_s->dbus_path)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_signal = dbus_message_new_signal(wpa_s->dbus_path,
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE,
|
|
||||||
"Scanning");
|
|
||||||
if (_signal == NULL) {
|
|
||||||
wpa_printf(MSG_ERROR,
|
|
||||||
"dbus: Not enough memory to send scan results signal");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dbus_message_append_args(_signal,
|
|
||||||
DBUS_TYPE_BOOLEAN, &scanning,
|
|
||||||
DBUS_TYPE_INVALID)) {
|
|
||||||
dbus_connection_send(iface->con, _signal, NULL);
|
|
||||||
} else {
|
|
||||||
wpa_printf(MSG_ERROR,
|
|
||||||
"dbus: Not enough memory to construct signal");
|
|
||||||
}
|
|
||||||
dbus_message_unref(_signal);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef CONFIG_WPS
|
|
||||||
void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s,
|
|
||||||
const struct wps_credential *cred)
|
|
||||||
{
|
|
||||||
struct wpas_dbus_priv *iface;
|
|
||||||
DBusMessage *_signal = NULL;
|
|
||||||
|
|
||||||
/* Do nothing if the control interface is not turned on */
|
|
||||||
if (wpa_s->global == NULL)
|
|
||||||
return;
|
|
||||||
iface = wpa_s->global->dbus;
|
|
||||||
if (iface == NULL || !wpa_s->dbus_path)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_signal = dbus_message_new_signal(wpa_s->dbus_path,
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE,
|
|
||||||
"WpsCred");
|
|
||||||
if (_signal == NULL) {
|
|
||||||
wpa_printf(MSG_ERROR,
|
|
||||||
"dbus: %s: Could not create dbus signal; likely out of memory",
|
|
||||||
__func__);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dbus_message_append_args(_signal,
|
|
||||||
DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
|
|
||||||
&cred->cred_attr, cred->cred_attr_len,
|
|
||||||
DBUS_TYPE_INVALID)) {
|
|
||||||
wpa_printf(MSG_ERROR,
|
|
||||||
"dbus: %s: Not enough memory to construct signal",
|
|
||||||
__func__);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_connection_send(iface->con, _signal, NULL);
|
|
||||||
|
|
||||||
out:
|
|
||||||
dbus_message_unref(_signal);
|
|
||||||
}
|
|
||||||
#else /* CONFIG_WPS */
|
|
||||||
void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s,
|
|
||||||
const struct wps_credential *cred)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif /* CONFIG_WPS */
|
|
||||||
|
|
||||||
void wpa_supplicant_dbus_notify_certification(struct wpa_supplicant *wpa_s,
|
|
||||||
int depth, const char *subject,
|
|
||||||
const char *cert_hash,
|
|
||||||
const struct wpabuf *cert)
|
|
||||||
{
|
|
||||||
struct wpas_dbus_priv *iface;
|
|
||||||
DBusMessage *_signal = NULL;
|
|
||||||
const char *hash;
|
|
||||||
const char *cert_hex;
|
|
||||||
int cert_hex_len;
|
|
||||||
|
|
||||||
/* Do nothing if the control interface is not turned on */
|
|
||||||
if (wpa_s->global == NULL)
|
|
||||||
return;
|
|
||||||
iface = wpa_s->global->dbus;
|
|
||||||
if (iface == NULL || !wpa_s->dbus_path)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_signal = dbus_message_new_signal(wpa_s->dbus_path,
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE,
|
|
||||||
"Certification");
|
|
||||||
if (_signal == NULL) {
|
|
||||||
wpa_printf(MSG_ERROR,
|
|
||||||
"dbus: %s: Could not create dbus signal; likely out of memory",
|
|
||||||
__func__);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
hash = cert_hash ? cert_hash : "";
|
|
||||||
cert_hex = cert ? wpabuf_head(cert) : "";
|
|
||||||
cert_hex_len = cert ? wpabuf_len(cert) : 0;
|
|
||||||
|
|
||||||
if (!dbus_message_append_args(_signal,
|
|
||||||
DBUS_TYPE_INT32, &depth,
|
|
||||||
DBUS_TYPE_STRING, &subject,
|
|
||||||
DBUS_TYPE_STRING, &hash,
|
|
||||||
DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
|
|
||||||
&cert_hex, cert_hex_len,
|
|
||||||
DBUS_TYPE_INVALID)) {
|
|
||||||
wpa_printf(MSG_ERROR,
|
|
||||||
"dbus: %s: Not enough memory to construct signal",
|
|
||||||
__func__);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_connection_send(iface->con, _signal, NULL);
|
|
||||||
|
|
||||||
out:
|
|
||||||
dbus_message_unref(_signal);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpa_supplicant_dbus_ctrl_iface_init - Initialize dbus control interface
|
|
||||||
* @global: Pointer to global data from wpa_supplicant_init()
|
|
||||||
* Returns: 0 on success, -1 on failure
|
|
||||||
*
|
|
||||||
* Initialize the dbus control interface and start receiving commands from
|
|
||||||
* external programs over the bus.
|
|
||||||
*/
|
|
||||||
int wpa_supplicant_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface)
|
|
||||||
{
|
|
||||||
DBusError error;
|
|
||||||
int ret = -1;
|
|
||||||
DBusObjectPathVTable wpas_vtable = {
|
|
||||||
NULL, &wpas_message_handler, NULL, NULL, NULL, NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Register the message handler for the global dbus interface */
|
|
||||||
if (!dbus_connection_register_object_path(iface->con,
|
|
||||||
WPAS_DBUS_PATH, &wpas_vtable,
|
|
||||||
iface)) {
|
|
||||||
wpa_printf(MSG_ERROR, "dbus: Could not set up message handler");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Register our service with the message bus */
|
|
||||||
dbus_error_init(&error);
|
|
||||||
switch (dbus_bus_request_name(iface->con, WPAS_DBUS_SERVICE,
|
|
||||||
0, &error)) {
|
|
||||||
case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
|
|
||||||
ret = 0;
|
|
||||||
break;
|
|
||||||
case DBUS_REQUEST_NAME_REPLY_EXISTS:
|
|
||||||
case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
|
|
||||||
case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
|
|
||||||
wpa_printf(MSG_ERROR,
|
|
||||||
"dbus: Could not request service name: already registered");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
wpa_printf(MSG_ERROR,
|
|
||||||
"dbus: Could not request service name: %s %s",
|
|
||||||
error.name, error.message);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
dbus_error_free(&error);
|
|
||||||
|
|
||||||
if (ret != 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "Providing DBus service '" WPAS_DBUS_SERVICE
|
|
||||||
"'.");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_dbus_register_new_iface - Register a new interface with dbus
|
|
||||||
* @wpa_s: %wpa_supplicant interface description structure to register
|
|
||||||
* Returns: 0 on success, -1 on error
|
|
||||||
*
|
|
||||||
* Registers a new interface with dbus and assigns it a dbus object path.
|
|
||||||
*/
|
|
||||||
int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s)
|
|
||||||
{
|
|
||||||
struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
|
|
||||||
DBusConnection * con;
|
|
||||||
u32 next;
|
|
||||||
DBusObjectPathVTable vtable = {
|
|
||||||
NULL, &wpas_iface_message_handler, NULL, NULL, NULL, NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Do nothing if the control interface is not turned on */
|
|
||||||
if (ctrl_iface == NULL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
con = ctrl_iface->con;
|
|
||||||
next = ctrl_iface->next_objid++;
|
|
||||||
|
|
||||||
/* Create and set the interface's object path */
|
|
||||||
wpa_s->dbus_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
|
|
||||||
if (wpa_s->dbus_path == NULL)
|
|
||||||
return -1;
|
|
||||||
os_snprintf(wpa_s->dbus_path, WPAS_DBUS_OBJECT_PATH_MAX,
|
|
||||||
WPAS_DBUS_PATH_INTERFACES "/%u",
|
|
||||||
next);
|
|
||||||
|
|
||||||
/* Register the message handler for the interface functions */
|
|
||||||
if (!dbus_connection_register_fallback(con, wpa_s->dbus_path, &vtable,
|
|
||||||
wpa_s)) {
|
|
||||||
wpa_printf(MSG_ERROR,
|
|
||||||
"dbus: Could not set up message handler for interface %s",
|
|
||||||
wpa_s->ifname);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_dbus_unregister_iface - Unregister an interface from dbus
|
|
||||||
* @wpa_s: wpa_supplicant interface structure
|
|
||||||
* Returns: 0 on success, -1 on failure
|
|
||||||
*
|
|
||||||
* Unregisters the interface with dbus
|
|
||||||
*/
|
|
||||||
int wpas_dbus_unregister_iface(struct wpa_supplicant *wpa_s)
|
|
||||||
{
|
|
||||||
struct wpas_dbus_priv *ctrl_iface;
|
|
||||||
DBusConnection *con;
|
|
||||||
|
|
||||||
/* Do nothing if the control interface is not turned on */
|
|
||||||
if (wpa_s == NULL || wpa_s->global == NULL)
|
|
||||||
return 0;
|
|
||||||
ctrl_iface = wpa_s->global->dbus;
|
|
||||||
if (ctrl_iface == NULL || wpa_s->dbus_path == NULL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
con = ctrl_iface->con;
|
|
||||||
if (!dbus_connection_unregister_object_path(con, wpa_s->dbus_path))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
os_free(wpa_s->dbus_path);
|
|
||||||
wpa_s->dbus_path = NULL;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpa_supplicant_get_iface_by_dbus_path - Get a new network interface
|
|
||||||
* @global: Pointer to global data from wpa_supplicant_init()
|
|
||||||
* @path: Pointer to a dbus object path representing an interface
|
|
||||||
* Returns: Pointer to the interface or %NULL if not found
|
|
||||||
*/
|
|
||||||
struct wpa_supplicant * wpa_supplicant_get_iface_by_dbus_path(
|
|
||||||
struct wpa_global *global, const char *path)
|
|
||||||
{
|
|
||||||
struct wpa_supplicant *wpa_s;
|
|
||||||
|
|
||||||
for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
|
|
||||||
if (wpa_s->dbus_path && strcmp(wpa_s->dbus_path, path) == 0)
|
|
||||||
return wpa_s;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
@ -1,142 +0,0 @@
|
|||||||
/*
|
|
||||||
* WPA Supplicant / dbus-based control interface
|
|
||||||
* Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
|
|
||||||
*
|
|
||||||
* This software may be distributed under the terms of the BSD license.
|
|
||||||
* See README for more details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CTRL_IFACE_DBUS_H
|
|
||||||
#define CTRL_IFACE_DBUS_H
|
|
||||||
|
|
||||||
struct wps_credential;
|
|
||||||
|
|
||||||
#ifdef CONFIG_CTRL_IFACE_DBUS
|
|
||||||
|
|
||||||
#define WPAS_DBUS_OBJECT_PATH_MAX 150
|
|
||||||
|
|
||||||
#define WPAS_DBUS_SERVICE "fi.epitest.hostap.WPASupplicant"
|
|
||||||
#define WPAS_DBUS_PATH "/fi/epitest/hostap/WPASupplicant"
|
|
||||||
#define WPAS_DBUS_INTERFACE "fi.epitest.hostap.WPASupplicant"
|
|
||||||
|
|
||||||
#define WPAS_DBUS_PATH_INTERFACES WPAS_DBUS_PATH "/Interfaces"
|
|
||||||
#define WPAS_DBUS_IFACE_INTERFACE WPAS_DBUS_INTERFACE ".Interface"
|
|
||||||
|
|
||||||
#define WPAS_DBUS_NETWORKS_PART "Networks"
|
|
||||||
#define WPAS_DBUS_IFACE_NETWORK WPAS_DBUS_INTERFACE ".Network"
|
|
||||||
|
|
||||||
#define WPAS_DBUS_BSSIDS_PART "BSSIDs"
|
|
||||||
#define WPAS_DBUS_IFACE_BSSID WPAS_DBUS_INTERFACE ".BSSID"
|
|
||||||
|
|
||||||
|
|
||||||
/* Errors */
|
|
||||||
#define WPAS_ERROR_INVALID_NETWORK \
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE ".InvalidNetwork"
|
|
||||||
#define WPAS_ERROR_INVALID_BSSID \
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE ".InvalidBSSID"
|
|
||||||
|
|
||||||
#define WPAS_ERROR_INVALID_OPTS \
|
|
||||||
WPAS_DBUS_INTERFACE ".InvalidOptions"
|
|
||||||
#define WPAS_ERROR_INVALID_IFACE \
|
|
||||||
WPAS_DBUS_INTERFACE ".InvalidInterface"
|
|
||||||
|
|
||||||
#define WPAS_ERROR_ADD_ERROR \
|
|
||||||
WPAS_DBUS_INTERFACE ".AddError"
|
|
||||||
#define WPAS_ERROR_EXISTS_ERROR \
|
|
||||||
WPAS_DBUS_INTERFACE ".ExistsError"
|
|
||||||
#define WPAS_ERROR_REMOVE_ERROR \
|
|
||||||
WPAS_DBUS_INTERFACE ".RemoveError"
|
|
||||||
|
|
||||||
#define WPAS_ERROR_SCAN_ERROR \
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE ".ScanError"
|
|
||||||
#define WPAS_ERROR_ADD_NETWORK_ERROR \
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE ".AddNetworkError"
|
|
||||||
#define WPAS_ERROR_INTERNAL_ERROR \
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE ".InternalError"
|
|
||||||
#define WPAS_ERROR_REMOVE_NETWORK_ERROR \
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE ".RemoveNetworkError"
|
|
||||||
|
|
||||||
#define WPAS_ERROR_WPS_PBC_ERROR \
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE ".WpsPbcError"
|
|
||||||
#define WPAS_ERROR_WPS_PIN_ERROR \
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE ".WpsPinError"
|
|
||||||
#define WPAS_ERROR_WPS_REG_ERROR \
|
|
||||||
WPAS_DBUS_IFACE_INTERFACE ".WpsRegError"
|
|
||||||
|
|
||||||
#define WPAS_DBUS_BSSID_FORMAT "%02x%02x%02x%02x%02x%02x"
|
|
||||||
|
|
||||||
struct wpa_global;
|
|
||||||
struct wpa_supplicant;
|
|
||||||
|
|
||||||
int wpa_supplicant_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface);
|
|
||||||
void wpa_supplicant_dbus_notify_scan_results(struct wpa_supplicant *wpa_s);
|
|
||||||
void wpa_supplicant_dbus_notify_scanning(struct wpa_supplicant *wpa_s);
|
|
||||||
void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s,
|
|
||||||
enum wpa_states new_state,
|
|
||||||
enum wpa_states old_state);
|
|
||||||
void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s,
|
|
||||||
const struct wps_credential *cred);
|
|
||||||
void wpa_supplicant_dbus_notify_certification(struct wpa_supplicant *wpa_s,
|
|
||||||
int depth, const char *subject,
|
|
||||||
const char *cert_hash,
|
|
||||||
const struct wpabuf *cert);
|
|
||||||
|
|
||||||
char * wpas_dbus_decompose_object_path(const char *path, char **network,
|
|
||||||
char **bssid);
|
|
||||||
|
|
||||||
int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s);
|
|
||||||
int wpas_dbus_unregister_iface(struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
|
|
||||||
/* Methods internal to the dbus control interface */
|
|
||||||
struct wpa_supplicant * wpa_supplicant_get_iface_by_dbus_path(
|
|
||||||
struct wpa_global *global, const char *path);
|
|
||||||
|
|
||||||
#else /* CONFIG_CTRL_IFACE_DBUS */
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
wpa_supplicant_dbus_notify_scan_results(struct wpa_supplicant *wpa_s)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
wpa_supplicant_dbus_notify_scanning(struct wpa_supplicant *wpa_s)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s,
|
|
||||||
enum wpa_states new_state,
|
|
||||||
enum wpa_states old_state)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s,
|
|
||||||
const struct wps_credential *cred)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
wpa_supplicant_dbus_notify_certification(struct wpa_supplicant *wpa_s,
|
|
||||||
int depth, const char *subject,
|
|
||||||
const char *cert_hash,
|
|
||||||
const struct wpabuf *cert)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
|
||||||
wpas_dbus_register_iface(struct wpa_supplicant *wpa_s)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
|
||||||
wpas_dbus_unregister_iface(struct wpa_supplicant *wpa_s)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* CONFIG_CTRL_IFACE_DBUS */
|
|
||||||
|
|
||||||
#endif /* CTRL_IFACE_DBUS_H */
|
|
File diff suppressed because it is too large
Load Diff
@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* WPA Supplicant / dbus-based control interface
|
|
||||||
* Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
|
|
||||||
*
|
|
||||||
* This software may be distributed under the terms of the BSD license.
|
|
||||||
* See README for more details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CTRL_IFACE_DBUS_HANDLERS_H
|
|
||||||
#define CTRL_IFACE_DBUS_HANDLERS_H
|
|
||||||
|
|
||||||
struct wpa_bss;
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_new_invalid_iface_error(DBusMessage *message);
|
|
||||||
DBusMessage * wpas_dbus_new_invalid_network_error(DBusMessage *message);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
|
|
||||||
struct wpa_global *global);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_global_remove_interface(DBusMessage *message,
|
|
||||||
struct wpa_global *global);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_global_get_interface(DBusMessage *message,
|
|
||||||
struct wpa_global *global);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_global_set_debugparams(DBusMessage *message,
|
|
||||||
struct wpa_global *global);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_scan(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s,
|
|
||||||
struct wpa_bss *bss);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_capabilities(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_add_network(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_remove_network(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_set_network(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s,
|
|
||||||
struct wpa_ssid *ssid);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_enable_network(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s,
|
|
||||||
struct wpa_ssid *ssid);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_disable_network(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s,
|
|
||||||
struct wpa_ssid *ssid);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_select_network(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_disconnect(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_set_ap_scan(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_set_smartcard_modules(
|
|
||||||
DBusMessage *message, struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_get_state(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_get_scanning(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_set_blobs(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_remove_blobs(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_wps_pbc(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_wps_reg(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_iface_flush(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s);
|
|
||||||
|
|
||||||
DBusMessage * wpas_dbus_new_success_reply(DBusMessage *message);
|
|
||||||
DBusMessage * wpas_dbus_new_invalid_opts_error(DBusMessage *message,
|
|
||||||
const char *arg);
|
|
||||||
|
|
||||||
#endif /* CTRL_IFACE_DBUS_HANDLERS_H */
|
|
||||||
|
|
@ -1,156 +0,0 @@
|
|||||||
/*
|
|
||||||
* WPA Supplicant / dbus-based control interface (WPS)
|
|
||||||
* Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
|
|
||||||
*
|
|
||||||
* This software may be distributed under the terms of the BSD license.
|
|
||||||
* See README for more details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "includes.h"
|
|
||||||
#include <dbus/dbus.h>
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "../config.h"
|
|
||||||
#include "../wpa_supplicant_i.h"
|
|
||||||
#include "../wps_supplicant.h"
|
|
||||||
#include "dbus_old.h"
|
|
||||||
#include "dbus_old_handlers.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_dbus_iface_wps_pbc - Request credentials using WPS PBC method
|
|
||||||
* @message: Pointer to incoming dbus message
|
|
||||||
* @wpa_s: %wpa_supplicant data structure
|
|
||||||
* Returns: A dbus message containing a UINT32 indicating success (1) or
|
|
||||||
* failure (0)
|
|
||||||
*
|
|
||||||
* Handler function for "wpsPbc" method call
|
|
||||||
*/
|
|
||||||
DBusMessage * wpas_dbus_iface_wps_pbc(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s)
|
|
||||||
{
|
|
||||||
char *arg_bssid = NULL;
|
|
||||||
u8 bssid[ETH_ALEN];
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
|
|
||||||
DBUS_TYPE_INVALID))
|
|
||||||
return wpas_dbus_new_invalid_opts_error(message, NULL);
|
|
||||||
|
|
||||||
if (os_strcmp(arg_bssid, "any") == 0)
|
|
||||||
ret = wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
|
|
||||||
else if (!hwaddr_aton(arg_bssid, bssid))
|
|
||||||
ret = wpas_wps_start_pbc(wpa_s, bssid, 0, 0);
|
|
||||||
else {
|
|
||||||
return wpas_dbus_new_invalid_opts_error(message,
|
|
||||||
"Invalid BSSID");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
return dbus_message_new_error(
|
|
||||||
message, WPAS_ERROR_WPS_PBC_ERROR,
|
|
||||||
"Could not start PBC negotiation");
|
|
||||||
}
|
|
||||||
|
|
||||||
return wpas_dbus_new_success_reply(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_dbus_iface_wps_pin - Establish the PIN number of the enrollee
|
|
||||||
* @message: Pointer to incoming dbus message
|
|
||||||
* @wpa_s: %wpa_supplicant data structure
|
|
||||||
* Returns: A dbus message containing a UINT32 indicating success (1) or
|
|
||||||
* failure (0)
|
|
||||||
*
|
|
||||||
* Handler function for "wpsPin" method call
|
|
||||||
*/
|
|
||||||
DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s)
|
|
||||||
{
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
char *arg_bssid;
|
|
||||||
char *pin = NULL;
|
|
||||||
u8 bssid[ETH_ALEN], *_bssid = NULL;
|
|
||||||
int ret;
|
|
||||||
char npin[9];
|
|
||||||
|
|
||||||
if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
|
|
||||||
DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
|
|
||||||
return wpas_dbus_new_invalid_opts_error(message, NULL);
|
|
||||||
|
|
||||||
if (os_strcmp(arg_bssid, "any") == 0)
|
|
||||||
_bssid = NULL;
|
|
||||||
else if (!hwaddr_aton(arg_bssid, bssid))
|
|
||||||
_bssid = bssid;
|
|
||||||
else {
|
|
||||||
return wpas_dbus_new_invalid_opts_error(message,
|
|
||||||
"Invalid BSSID");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (os_strlen(pin) > 0)
|
|
||||||
ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
|
|
||||||
DEV_PW_DEFAULT);
|
|
||||||
else
|
|
||||||
ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0,
|
|
||||||
DEV_PW_DEFAULT);
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
return dbus_message_new_error(message,
|
|
||||||
WPAS_ERROR_WPS_PIN_ERROR,
|
|
||||||
"Could not init PIN");
|
|
||||||
}
|
|
||||||
|
|
||||||
reply = dbus_message_new_method_return(message);
|
|
||||||
if (reply == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (ret > 0) {
|
|
||||||
ret = os_snprintf(npin, sizeof(npin), "%08d", ret);
|
|
||||||
if (os_snprintf_error(sizeof(npin), ret))
|
|
||||||
return wpas_dbus_new_invalid_opts_error(message,
|
|
||||||
"invalid PIN");
|
|
||||||
|
|
||||||
pin = npin;
|
|
||||||
}
|
|
||||||
dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,
|
|
||||||
DBUS_TYPE_INVALID);
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_dbus_iface_wps_reg - Request credentials using the PIN of the AP
|
|
||||||
* @message: Pointer to incoming dbus message
|
|
||||||
* @wpa_s: %wpa_supplicant data structure
|
|
||||||
* Returns: A dbus message containing a UINT32 indicating success (1) or
|
|
||||||
* failure (0)
|
|
||||||
*
|
|
||||||
* Handler function for "wpsReg" method call
|
|
||||||
*/
|
|
||||||
DBusMessage * wpas_dbus_iface_wps_reg(DBusMessage *message,
|
|
||||||
struct wpa_supplicant *wpa_s)
|
|
||||||
{
|
|
||||||
char *arg_bssid;
|
|
||||||
char *pin = NULL;
|
|
||||||
u8 bssid[ETH_ALEN];
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
|
|
||||||
DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
|
|
||||||
return wpas_dbus_new_invalid_opts_error(message, NULL);
|
|
||||||
|
|
||||||
if (!hwaddr_aton(arg_bssid, bssid))
|
|
||||||
ret = wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
|
|
||||||
else {
|
|
||||||
return wpas_dbus_new_invalid_opts_error(message,
|
|
||||||
"Invalid BSSID");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
return dbus_message_new_error(message,
|
|
||||||
WPAS_ERROR_WPS_REG_ERROR,
|
|
||||||
"Could not request credentials");
|
|
||||||
}
|
|
||||||
|
|
||||||
return wpas_dbus_new_success_reply(message);
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
[D-BUS Service]
|
|
||||||
Name=fi.epitest.hostap.WPASupplicant
|
|
||||||
Exec=@BINDIR@/wpa_supplicant -u
|
|
||||||
User=root
|
|
||||||
SystemdService=wpa_supplicant.service
|
|
@ -1,91 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
|
|
||||||
import dbus
|
|
||||||
import sys, os
|
|
||||||
import time
|
|
||||||
|
|
||||||
WPAS_DBUS_SERVICE = "fi.epitest.hostap.WPASupplicant"
|
|
||||||
WPAS_DBUS_INTERFACE = "fi.epitest.hostap.WPASupplicant"
|
|
||||||
WPAS_DBUS_OPATH = "/fi/epitest/hostap/WPASupplicant"
|
|
||||||
|
|
||||||
WPAS_DBUS_INTERFACES_INTERFACE = "fi.epitest.hostap.WPASupplicant.Interface"
|
|
||||||
WPAS_DBUS_INTERFACES_OPATH = "/fi/epitest/hostap/WPASupplicant/Interfaces"
|
|
||||||
WPAS_DBUS_BSSID_INTERFACE = "fi.epitest.hostap.WPASupplicant.BSSID"
|
|
||||||
|
|
||||||
def byte_array_to_string(s):
|
|
||||||
import urllib
|
|
||||||
r = ""
|
|
||||||
for c in s:
|
|
||||||
if c >= 32 and c < 127:
|
|
||||||
r += "%c" % c
|
|
||||||
else:
|
|
||||||
r += urllib.quote(chr(c))
|
|
||||||
return r
|
|
||||||
|
|
||||||
def main():
|
|
||||||
if len(sys.argv) != 2:
|
|
||||||
print("Usage: wpas-test.py <interface>")
|
|
||||||
os._exit(1)
|
|
||||||
|
|
||||||
ifname = sys.argv[1]
|
|
||||||
|
|
||||||
bus = dbus.SystemBus()
|
|
||||||
wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
|
|
||||||
wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
|
|
||||||
|
|
||||||
# See if wpa_supplicant already knows about this interface
|
|
||||||
path = None
|
|
||||||
try:
|
|
||||||
path = wpas.getInterface(ifname)
|
|
||||||
except dbus.dbus_bindings.DBusException as exc:
|
|
||||||
if str(exc) != "wpa_supplicant knows nothing about this interface.":
|
|
||||||
raise exc
|
|
||||||
try:
|
|
||||||
path = wpas.addInterface(ifname, {'driver': dbus.Variant('wext')})
|
|
||||||
except dbus.dbus_bindings.DBusException as exc:
|
|
||||||
if str(exc) != "wpa_supplicant already controls this interface.":
|
|
||||||
raise exc
|
|
||||||
|
|
||||||
if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
|
|
||||||
iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE)
|
|
||||||
iface.scan()
|
|
||||||
# Should really wait for the "scanResults" signal instead of sleeping
|
|
||||||
time.sleep(5)
|
|
||||||
res = iface.scanResults()
|
|
||||||
|
|
||||||
print("Scanned wireless networks:")
|
|
||||||
for opath in res:
|
|
||||||
net_obj = bus.get_object(WPAS_DBUS_SERVICE, opath)
|
|
||||||
net = dbus.Interface(net_obj, WPAS_DBUS_BSSID_INTERFACE)
|
|
||||||
props = net.properties()
|
|
||||||
|
|
||||||
# Convert the byte-array for SSID and BSSID to printable strings
|
|
||||||
bssid = ""
|
|
||||||
for item in props["bssid"]:
|
|
||||||
bssid = bssid + ":%02x" % item
|
|
||||||
bssid = bssid[1:]
|
|
||||||
ssid = byte_array_to_string(props["ssid"])
|
|
||||||
wpa = "no"
|
|
||||||
if props.has_key("wpaie"):
|
|
||||||
wpa = "yes"
|
|
||||||
wpa2 = "no"
|
|
||||||
if props.has_key("rsnie"):
|
|
||||||
wpa2 = "yes"
|
|
||||||
freq = 0
|
|
||||||
if props.has_key("frequency"):
|
|
||||||
freq = props["frequency"]
|
|
||||||
caps = props["capabilities"]
|
|
||||||
qual = props["quality"]
|
|
||||||
level = props["level"]
|
|
||||||
noise = props["noise"]
|
|
||||||
maxrate = props["maxrate"] / 1000000
|
|
||||||
|
|
||||||
print(" %s :: ssid='%s' wpa=%s wpa2=%s quality=%d%% rate=%d freq=%d" % (bssid, ssid, wpa, wpa2, qual, maxrate, freq))
|
|
||||||
|
|
||||||
wpas.removeInterface(dbus.ObjectPath(path))
|
|
||||||
# Should fail here with unknown interface error
|
|
||||||
iface.scan()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|
Loading…
Reference in New Issue