dbus: Move some of conditional WPS code into separate files

This commit is contained in:
Jouni Malinen 2009-12-20 21:04:40 +02:00
parent a8c481c10a
commit 36da1358bc
8 changed files with 534 additions and 480 deletions

View file

@ -1029,6 +1029,9 @@ endif
ifdef CONFIG_CTRL_IFACE_DBUS ifdef CONFIG_CTRL_IFACE_DBUS
DBUS_CFLAGS += -DCONFIG_CTRL_IFACE_DBUS -DDBUS_API_SUBJECT_TO_CHANGE DBUS_CFLAGS += -DCONFIG_CTRL_IFACE_DBUS -DDBUS_API_SUBJECT_TO_CHANGE
DBUS_OBJS += dbus/ctrl_iface_dbus.o dbus/ctrl_iface_dbus_handlers.o DBUS_OBJS += dbus/ctrl_iface_dbus.o dbus/ctrl_iface_dbus_handlers.o
ifdef CONFIG_WPS
DBUS_OBJS += dbus/dbus_handlers_wps.o
endif
DBUS_OBJS += dbus/dbus_dict_helpers.o DBUS_OBJS += dbus/dbus_dict_helpers.o
ifndef DBUS_LIBS ifndef DBUS_LIBS
DBUS_LIBS := $(shell pkg-config --libs dbus-1) DBUS_LIBS := $(shell pkg-config --libs dbus-1)
@ -1055,6 +1058,9 @@ DBUS_CFLAGS += -DCONFIG_CTRL_IFACE_DBUS_NEW
DBUS_OBJS ?= dbus/dbus_dict_helpers.o DBUS_OBJS ?= dbus/dbus_dict_helpers.o
DBUS_OBJS += dbus/ctrl_iface_dbus_new_helpers.o DBUS_OBJS += dbus/ctrl_iface_dbus_new_helpers.o
DBUS_OBJS += dbus/ctrl_iface_dbus_new.o dbus/ctrl_iface_dbus_new_handlers.o DBUS_OBJS += dbus/ctrl_iface_dbus_new.o dbus/ctrl_iface_dbus_new_handlers.o
ifdef CONFIG_WPS
DBUS_OBJS += dbus/dbus_new_handlers_wps.o
endif
ifndef DBUS_LIBS ifndef DBUS_LIBS
DBUS_LIBS := $(shell pkg-config --libs dbus-1) DBUS_LIBS := $(shell pkg-config --libs dbus-1)
endif endif

View file

@ -30,7 +30,10 @@ endif
@$(E) " CC " $< @$(E) " CC " $<
#CFLAGS += -DCONFIG_WPS ifdef CONFIG_WPS
CFLAGS += -DCONFIG_WPS
endif
CFLAGS += -DCONFIG_CTRL_IFACE_DBUS_NEW CFLAGS += -DCONFIG_CTRL_IFACE_DBUS_NEW
CFLAGS += -DCONFIG_CTRL_IFACE_DBUS CFLAGS += -DCONFIG_CTRL_IFACE_DBUS
@ -68,6 +71,11 @@ LIB_OBJS= \
ctrl_iface_dbus_new_helpers.o \ ctrl_iface_dbus_new_helpers.o \
dbus_dict_helpers.o dbus_dict_helpers.o
ifdef CONFIG_WPS
LIB_OBJS += dbus_handlers_wps.o
LIB_OBJS += dbus_new_handlers_wps.o
endif
libwpadbus.a: $(LIB_OBJS) libwpadbus.a: $(LIB_OBJS)
$(AR) crT $@ $? $(AR) crT $@ $?

View file

@ -26,7 +26,6 @@
#include "common/ieee802_11_defs.h" #include "common/ieee802_11_defs.h"
#include "../wpas_glue.h" #include "../wpas_glue.h"
#include "eapol_supp/eapol_supp_sm.h" #include "eapol_supp/eapol_supp_sm.h"
#include "../wps_supplicant.h"
#include "rsn_supp/wpa.h" #include "rsn_supp/wpa.h"
extern int wpa_debug_level; extern int wpa_debug_level;
@ -40,8 +39,8 @@ extern int wpa_debug_timestamp;
* *
* Convenience function to create and return an invalid options error * Convenience function to create and return an invalid options error
*/ */
static DBusMessage * wpas_dbus_new_invalid_opts_error(DBusMessage *message, DBusMessage * wpas_dbus_new_invalid_opts_error(DBusMessage *message,
const char *arg) const char *arg)
{ {
DBusMessage *reply; DBusMessage *reply;
@ -64,7 +63,7 @@ static DBusMessage * wpas_dbus_new_invalid_opts_error(DBusMessage *message,
* *
* Convenience function to create and return a success reply message * Convenience function to create and return a success reply message
*/ */
static DBusMessage * wpas_dbus_new_success_reply(DBusMessage *message) DBusMessage * wpas_dbus_new_success_reply(DBusMessage *message)
{ {
DBusMessage *reply; DBusMessage *reply;
unsigned int success = 1; unsigned int success = 1;
@ -1468,146 +1467,3 @@ DBusMessage * wpas_dbus_iface_remove_blobs(DBusMessage *message,
return wpas_dbus_new_success_reply(message); return wpas_dbus_new_success_reply(message);
} }
#ifdef CONFIG_WPS
/**
* 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"))
ret = wpas_wps_start_pbc(wpa_s, NULL);
else if (!hwaddr_aton(arg_bssid, bssid))
ret = wpas_wps_start_pbc(wpa_s, bssid);
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 = 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 (!os_strcmp(arg_bssid, "any"))
_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);
else
ret = wpas_wps_start_pin(wpa_s, _bssid, NULL);
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) {
dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,
DBUS_TYPE_INVALID);
} else {
char npin[9];
os_snprintf(npin, sizeof(npin), "%08d", ret);
dbus_message_append_args(reply, DBUS_TYPE_STRING, &npin,
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 (!os_strcmp(arg_bssid, "any"))
ret = wpas_wps_start_reg(wpa_s, NULL, pin, NULL);
else 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_PBC_ERROR,
"Could not request credentials");
}
return wpas_dbus_new_success_reply(message);
}
#endif /* CONFIG_WPS */

View file

@ -15,8 +15,6 @@
#ifndef CTRL_IFACE_DBUS_HANDLERS_H #ifndef CTRL_IFACE_DBUS_HANDLERS_H
#define CTRL_IFACE_DBUS_HANDLERS_H #define CTRL_IFACE_DBUS_HANDLERS_H
#ifdef CONFIG_CTRL_IFACE_DBUS
DBusMessage * wpas_dbus_new_invalid_iface_error(DBusMessage *message); DBusMessage * wpas_dbus_new_invalid_iface_error(DBusMessage *message);
DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message, DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
@ -95,7 +93,9 @@ DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message,
DBusMessage * wpas_dbus_iface_wps_reg(DBusMessage *message, DBusMessage * wpas_dbus_iface_wps_reg(DBusMessage *message,
struct wpa_supplicant *wpa_s); struct wpa_supplicant *wpa_s);
#endif /* CONFIG_CTRL_IFACE_DBUS */ 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 */ #endif /* CTRL_IFACE_DBUS_HANDLERS_H */

View file

@ -28,7 +28,6 @@
#include "common/ieee802_11_defs.h" #include "common/ieee802_11_defs.h"
#include "../wpas_glue.h" #include "../wpas_glue.h"
#include "eapol_supp/eapol_supp_sm.h" #include "eapol_supp/eapol_supp_sm.h"
#include "../wps_supplicant.h"
extern int wpa_debug_level; extern int wpa_debug_level;
extern int wpa_debug_show_keys; extern int wpa_debug_show_keys;
@ -107,8 +106,8 @@ static char * wpas_dbus_new_decompose_object_path(const char *path,
* *
* Convenience function to create and return an UnknownError * Convenience function to create and return an UnknownError
*/ */
static DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message, DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
const char *arg) const char *arg)
{ {
return dbus_message_new_error(message, WPAS_DBUS_ERROR_UNKNOWN_ERROR, return dbus_message_new_error(message, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
arg); arg);
@ -152,8 +151,8 @@ static DBusMessage * wpas_dbus_error_network_unknown(DBusMessage *message)
* *
* Convenience function to create and return an invalid options error * Convenience function to create and return an invalid options error
*/ */
static DBusMessage * wpas_dbus_error_invald_args(DBusMessage *message, DBusMessage * wpas_dbus_error_invald_args(DBusMessage *message,
const char *arg) const char *arg)
{ {
DBusMessage *reply; DBusMessage *reply;
@ -3143,327 +3142,3 @@ DBusMessage * wpas_dbus_setter_network_properties(
return reply; return reply;
} }
#ifdef CONFIG_WPS
/**
* wpas_dbus_handler_wps_start - Start WPS configuration
* @message: Pointer to incoming dbus message
* @wpa_s: %wpa_supplicant data structure
* Returns: DBus message dictionary on success or DBus error on failure
*
* Handler for "Start" method call. DBus dictionary argument contains
* information about role (enrollee or registrar), authorization method
* (pin or push button) and optionally pin and bssid. Returned message
* has a dictionary argument which may contain newly generated pin (optional).
*/
DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
struct wpa_supplicant *wpa_s)
{
DBusMessage * reply = NULL;
DBusMessageIter iter, dict_iter, entry_iter, variant_iter, array_iter;
char *key, *val;
int role = 0; /* 0 - not set, 1 - enrollee, 2 - registrar */
int type = 0; /* 0 - not set, 1 - pin, 2 - pbc */
u8 *bssid = NULL;
char *pin = NULL, npin[9] = { '\0' };
int len, ret;
dbus_message_iter_init(message, &iter);
dbus_message_iter_recurse(&iter, &dict_iter);
while (dbus_message_iter_get_arg_type(&dict_iter) ==
DBUS_TYPE_DICT_ENTRY) {
dbus_message_iter_recurse(&dict_iter, &entry_iter);
dbus_message_iter_get_basic(&entry_iter, &key);
dbus_message_iter_next(&entry_iter);
if (os_strcmp(key, "Role") == 0) {
dbus_message_iter_recurse(&entry_iter, &variant_iter);
if (dbus_message_iter_get_arg_type(&variant_iter) !=
DBUS_TYPE_STRING) {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start"
"[dbus]: "
"wrong Role type. string required");
reply = wpas_dbus_error_invald_args(
message, "Role must be a string");
goto out;
}
dbus_message_iter_get_basic(&variant_iter, &val);
if (os_strcmp(val, "enrollee") == 0)
role = 1;
else if (os_strcmp(val, "registrar") == 0)
role = 2;
else {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"unknown role %s", val);
reply = wpas_dbus_error_invald_args(message, val);
goto out;
}
} else if (strcmp(key, "Type") == 0) {
dbus_message_iter_recurse(&entry_iter, &variant_iter);
if (dbus_message_iter_get_arg_type(&variant_iter) !=
DBUS_TYPE_STRING) {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"wrong Type type. string required");
reply = wpas_dbus_error_invald_args(
message, "Type must be a string");
goto out;
}
dbus_message_iter_get_basic(&variant_iter, &val);
if (os_strcmp(val, "pin") == 0)
type = 1;
else if (os_strcmp(val, "pbc") == 0)
type = 2;
else {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"unknown type %s", val);
reply = wpas_dbus_error_invald_args(message,
val);
goto out;
}
} else if (strcmp(key, "Bssid") == 0) {
dbus_message_iter_recurse(&entry_iter, &variant_iter);
if (dbus_message_iter_get_arg_type(&variant_iter) !=
DBUS_TYPE_ARRAY ||
dbus_message_iter_get_element_type(&variant_iter) !=
DBUS_TYPE_ARRAY) {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"wrong Bssid type. byte array required");
reply = wpas_dbus_error_invald_args(
message, "Bssid must be a byte array");
goto out;
}
dbus_message_iter_recurse(&variant_iter, &array_iter);
dbus_message_iter_get_fixed_array(&array_iter, &bssid,
&len);
if (len != ETH_ALEN) {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"wrong Bssid length %d", len);
reply = wpas_dbus_error_invald_args(
message, "Bssid is wrong length");
goto out;
}
}
else if (os_strcmp(key, "Pin") == 0) {
dbus_message_iter_recurse(&entry_iter, &variant_iter);
if (dbus_message_iter_get_arg_type(&variant_iter) !=
DBUS_TYPE_STRING) {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"wrong Pin type. string required");
reply = wpas_dbus_error_invald_args(
message, "Pin must be a string");
goto out;
}
dbus_message_iter_get_basic(&variant_iter, &pin);
} else {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"unknown key %s", key);
reply = wpas_dbus_error_invald_args(message, key);
goto out;
}
dbus_message_iter_next(&dict_iter);
}
if (role == 0) {
wpa_printf(MSG_DEBUG, "wpas_dbus_handler_wps_start[dbus]: "
"Role not specified");
reply = wpas_dbus_error_invald_args(message,
"Role not specified");
goto out;
}
else if (role == 1 && type == 0) {
wpa_printf(MSG_DEBUG, "wpas_dbus_handler_wps_start[dbus]: "
"Type not specified");
reply = wpas_dbus_error_invald_args(message,
"Type not specified");
goto out;
}
else if (role == 2 && pin == NULL) {
wpa_printf(MSG_DEBUG, "wpas_dbus_handler_wps_start[dbus]: "
"Pin required for registrar role.");
reply = wpas_dbus_error_invald_args(
message, "Pin required for registrar role.");
goto out;
}
if (role == 2)
ret = wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
else if (type == 1) {
ret = wpas_wps_start_pin(wpa_s, bssid, pin);
if (ret > 0)
os_snprintf(npin, sizeof(npin), "%08d", ret);
} else
ret = wpas_wps_start_pbc(wpa_s, bssid);
if (ret < 0) {
wpa_printf(MSG_DEBUG, "wpas_dbus_handler_wps_start[dbus]: "
"wpas_wps_failed in role %s and key %s.",
(role == 1 ? "enrollee" : "registrar"),
(type == 0 ? "" : (type == 1 ? "pin" : "pbc")));
reply = wpas_dbus_error_unknown_error(message,
"wps start failed");
goto out;
}
reply = dbus_message_new_method_return(message);
if (!reply) {
perror("wpas_dbus_handler_wps_start[dbus]: out of memory "
"when creating reply");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
dbus_message_iter_init_append(reply, &iter);
if (!wpa_dbus_dict_open_write(&iter, &dict_iter)) {
perror("wpas_dbus_handler_wps_start[dbus]: out of memory "
"when opening dictionary");
dbus_message_unref(reply);
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
if (os_strlen(npin) > 0) {
if (!wpa_dbus_dict_append_string(&dict_iter, "Pin", npin)) {
perror("wpas_dbus_handler_wps_start[dbus]: "
"out of memory when appending pin");
dbus_message_unref(reply);
reply = dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
}
if (!wpa_dbus_dict_close_write(&iter, &dict_iter)) {
perror("wpas_dbus_handler_wps_start[dbus]: out of memory "
"when closing dictionary");
dbus_message_unref(reply);
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
out:
return reply;
}
/**
* wpas_dbus_getter_process_credentials - Check if credentials are processed
* @message: Pointer to incoming dbus message
* @wpa_s: %wpa_supplicant data structure
* Returns: DBus message with a boolean on success or DBus error on failure
*
* Getter for "ProcessCredentials" property. Returns returned boolean will be
* true if wps_cred_processing configuration field is not equal to 1 or false
* if otherwise.
*/
DBusMessage * wpas_dbus_getter_process_credentials(
DBusMessage *message, struct wpa_supplicant *wpa_s)
{
DBusMessage *reply = NULL;
DBusMessageIter iter, variant_iter;
dbus_bool_t process = (wpa_s->conf->wps_cred_processing != 1);
if (message == NULL)
reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
else
reply = dbus_message_new_method_return(message);
if (reply != NULL) {
dbus_message_iter_init_append(reply, &iter);
if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
"b", &variant_iter) ||
!dbus_message_iter_append_basic(&variant_iter,
DBUS_TYPE_BOOLEAN,
&process) ||
!dbus_message_iter_close_container(&iter, &variant_iter)) {
perror("wpas_dbus_getter_process_credentials[dbus]: "
"out of memory to put value into message.");
dbus_message_unref(reply);
reply = dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
NULL);
}
} else {
perror("wpas_dbus_getter_process_credentials[dbus]: out of "
"memory to create reply message.");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
}
return reply;
}
/**
* wpas_dbus_setter_process_credentials - Set credentials_processed conf param
* @message: Pointer to incoming dbus message
* @wpa_s: %wpa_supplicant data structure
* Returns: NULL on success or DBus error on failure
*
* Setter for "ProcessCredentials" property. Sets credentials_processed on 2
* if boolean argument is true or on 1 if otherwise.
*/
DBusMessage * wpas_dbus_setter_process_credentials(
DBusMessage *message, struct wpa_supplicant *wpa_s)
{
DBusMessage *reply = NULL;
DBusMessageIter iter, variant_iter;
dbus_bool_t process_credentials, old_pc;
if (!dbus_message_iter_init(message, &iter)) {
perror("wpas_dbus_getter_ap_scan[dbus]: out of "
"memory to return scanning state.");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
/* omit first and second argument and get value from third*/
dbus_message_iter_next(&iter);
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &variant_iter);
if (dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_BOOLEAN)
{
reply = wpas_dbus_error_invald_args(message,
"BOOLEAN required");
goto out;
}
dbus_message_iter_get_basic(&variant_iter, &process_credentials);
old_pc = (wpa_s->conf->wps_cred_processing != 1);
wpa_s->conf->wps_cred_processing = (process_credentials ? 2 : 1);
if ((wpa_s->conf->wps_cred_processing != 1) != old_pc)
wpa_dbus_signal_property_changed(
wpa_s->global->dbus_new_ctrl_iface,
(WPADBusPropertyAccessor)
wpas_dbus_getter_process_credentials,
wpa_s, wpas_dbus_get_path(wpa_s),
WPAS_DBUS_NEW_IFACE_WPS,
"ProcessCredentials");
out:
return reply;
}
#endif /* CONFIG_WPS */

View file

@ -136,4 +136,9 @@ DBusMessage * wpas_dbus_setter_process_credentials(
DBusMessage * wpas_dbus_getter_credentials(DBusMessage *message, DBusMessage * wpas_dbus_getter_credentials(DBusMessage *message,
struct wpa_supplicant *wpa_s); struct wpa_supplicant *wpa_s);
DBusMessage * wpas_dbus_error_invald_args(DBusMessage *message,
const char *arg);
DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
const char *arg);
#endif /* CTRL_IFACE_DBUS_HANDLERS_NEW_H */ #endif /* CTRL_IFACE_DBUS_HANDLERS_NEW_H */

View file

@ -0,0 +1,160 @@
/*
* WPA Supplicant / dbus-based control interface (WPS)
* Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* See README and COPYING for more details.
*/
#include "includes.h"
#include "common.h"
#include "../config.h"
#include "../wpa_supplicant_i.h"
#include "../wps_supplicant.h"
#include "ctrl_iface_dbus.h"
#include "ctrl_iface_dbus_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"))
ret = wpas_wps_start_pbc(wpa_s, NULL);
else if (!hwaddr_aton(arg_bssid, bssid))
ret = wpas_wps_start_pbc(wpa_s, bssid);
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 = 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 (!os_strcmp(arg_bssid, "any"))
_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);
else
ret = wpas_wps_start_pin(wpa_s, _bssid, NULL);
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) {
dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,
DBUS_TYPE_INVALID);
} else {
char npin[9];
os_snprintf(npin, sizeof(npin), "%08d", ret);
dbus_message_append_args(reply, DBUS_TYPE_STRING, &npin,
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 (!os_strcmp(arg_bssid, "any"))
ret = wpas_wps_start_reg(wpa_s, NULL, pin, NULL);
else 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_PBC_ERROR,
"Could not request credentials");
}
return wpas_dbus_new_success_reply(message);
}

View file

@ -0,0 +1,344 @@
/*
* WPA Supplicant / dbus-based control interface (WPS)
* Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
* Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* See README and COPYING for more details.
*/
#include "includes.h"
#include "common.h"
#include "../config.h"
#include "../wpa_supplicant_i.h"
#include "../wps_supplicant.h"
#include "ctrl_iface_dbus_new_helpers.h"
#include "ctrl_iface_dbus_new.h"
#include "ctrl_iface_dbus_new_handlers.h"
#include "dbus_dict_helpers.h"
/**
* wpas_dbus_handler_wps_start - Start WPS configuration
* @message: Pointer to incoming dbus message
* @wpa_s: %wpa_supplicant data structure
* Returns: DBus message dictionary on success or DBus error on failure
*
* Handler for "Start" method call. DBus dictionary argument contains
* information about role (enrollee or registrar), authorization method
* (pin or push button) and optionally pin and bssid. Returned message
* has a dictionary argument which may contain newly generated pin (optional).
*/
DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
struct wpa_supplicant *wpa_s)
{
DBusMessage * reply = NULL;
DBusMessageIter iter, dict_iter, entry_iter, variant_iter, array_iter;
char *key, *val;
int role = 0; /* 0 - not set, 1 - enrollee, 2 - registrar */
int type = 0; /* 0 - not set, 1 - pin, 2 - pbc */
u8 *bssid = NULL;
char *pin = NULL, npin[9] = { '\0' };
int len, ret;
dbus_message_iter_init(message, &iter);
dbus_message_iter_recurse(&iter, &dict_iter);
while (dbus_message_iter_get_arg_type(&dict_iter) ==
DBUS_TYPE_DICT_ENTRY) {
dbus_message_iter_recurse(&dict_iter, &entry_iter);
dbus_message_iter_get_basic(&entry_iter, &key);
dbus_message_iter_next(&entry_iter);
if (os_strcmp(key, "Role") == 0) {
dbus_message_iter_recurse(&entry_iter, &variant_iter);
if (dbus_message_iter_get_arg_type(&variant_iter) !=
DBUS_TYPE_STRING) {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start"
"[dbus]: "
"wrong Role type. string required");
reply = wpas_dbus_error_invald_args(
message, "Role must be a string");
goto out;
}
dbus_message_iter_get_basic(&variant_iter, &val);
if (os_strcmp(val, "enrollee") == 0)
role = 1;
else if (os_strcmp(val, "registrar") == 0)
role = 2;
else {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"unknown role %s", val);
reply = wpas_dbus_error_invald_args(message, val);
goto out;
}
} else if (strcmp(key, "Type") == 0) {
dbus_message_iter_recurse(&entry_iter, &variant_iter);
if (dbus_message_iter_get_arg_type(&variant_iter) !=
DBUS_TYPE_STRING) {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"wrong Type type. string required");
reply = wpas_dbus_error_invald_args(
message, "Type must be a string");
goto out;
}
dbus_message_iter_get_basic(&variant_iter, &val);
if (os_strcmp(val, "pin") == 0)
type = 1;
else if (os_strcmp(val, "pbc") == 0)
type = 2;
else {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"unknown type %s", val);
reply = wpas_dbus_error_invald_args(message,
val);
goto out;
}
} else if (strcmp(key, "Bssid") == 0) {
dbus_message_iter_recurse(&entry_iter, &variant_iter);
if (dbus_message_iter_get_arg_type(&variant_iter) !=
DBUS_TYPE_ARRAY ||
dbus_message_iter_get_element_type(&variant_iter) !=
DBUS_TYPE_ARRAY) {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"wrong Bssid type. byte array required");
reply = wpas_dbus_error_invald_args(
message, "Bssid must be a byte array");
goto out;
}
dbus_message_iter_recurse(&variant_iter, &array_iter);
dbus_message_iter_get_fixed_array(&array_iter, &bssid,
&len);
if (len != ETH_ALEN) {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"wrong Bssid length %d", len);
reply = wpas_dbus_error_invald_args(
message, "Bssid is wrong length");
goto out;
}
}
else if (os_strcmp(key, "Pin") == 0) {
dbus_message_iter_recurse(&entry_iter, &variant_iter);
if (dbus_message_iter_get_arg_type(&variant_iter) !=
DBUS_TYPE_STRING) {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"wrong Pin type. string required");
reply = wpas_dbus_error_invald_args(
message, "Pin must be a string");
goto out;
}
dbus_message_iter_get_basic(&variant_iter, &pin);
} else {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"unknown key %s", key);
reply = wpas_dbus_error_invald_args(message, key);
goto out;
}
dbus_message_iter_next(&dict_iter);
}
if (role == 0) {
wpa_printf(MSG_DEBUG, "wpas_dbus_handler_wps_start[dbus]: "
"Role not specified");
reply = wpas_dbus_error_invald_args(message,
"Role not specified");
goto out;
}
else if (role == 1 && type == 0) {
wpa_printf(MSG_DEBUG, "wpas_dbus_handler_wps_start[dbus]: "
"Type not specified");
reply = wpas_dbus_error_invald_args(message,
"Type not specified");
goto out;
}
else if (role == 2 && pin == NULL) {
wpa_printf(MSG_DEBUG, "wpas_dbus_handler_wps_start[dbus]: "
"Pin required for registrar role.");
reply = wpas_dbus_error_invald_args(
message, "Pin required for registrar role.");
goto out;
}
if (role == 2)
ret = wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
else if (type == 1) {
ret = wpas_wps_start_pin(wpa_s, bssid, pin);
if (ret > 0)
os_snprintf(npin, sizeof(npin), "%08d", ret);
} else
ret = wpas_wps_start_pbc(wpa_s, bssid);
if (ret < 0) {
wpa_printf(MSG_DEBUG, "wpas_dbus_handler_wps_start[dbus]: "
"wpas_wps_failed in role %s and key %s.",
(role == 1 ? "enrollee" : "registrar"),
(type == 0 ? "" : (type == 1 ? "pin" : "pbc")));
reply = wpas_dbus_error_unknown_error(message,
"wps start failed");
goto out;
}
reply = dbus_message_new_method_return(message);
if (!reply) {
perror("wpas_dbus_handler_wps_start[dbus]: out of memory "
"when creating reply");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
dbus_message_iter_init_append(reply, &iter);
if (!wpa_dbus_dict_open_write(&iter, &dict_iter)) {
perror("wpas_dbus_handler_wps_start[dbus]: out of memory "
"when opening dictionary");
dbus_message_unref(reply);
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
if (os_strlen(npin) > 0) {
if (!wpa_dbus_dict_append_string(&dict_iter, "Pin", npin)) {
perror("wpas_dbus_handler_wps_start[dbus]: "
"out of memory when appending pin");
dbus_message_unref(reply);
reply = dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
}
if (!wpa_dbus_dict_close_write(&iter, &dict_iter)) {
perror("wpas_dbus_handler_wps_start[dbus]: out of memory "
"when closing dictionary");
dbus_message_unref(reply);
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
out:
return reply;
}
/**
* wpas_dbus_getter_process_credentials - Check if credentials are processed
* @message: Pointer to incoming dbus message
* @wpa_s: %wpa_supplicant data structure
* Returns: DBus message with a boolean on success or DBus error on failure
*
* Getter for "ProcessCredentials" property. Returns returned boolean will be
* true if wps_cred_processing configuration field is not equal to 1 or false
* if otherwise.
*/
DBusMessage * wpas_dbus_getter_process_credentials(
DBusMessage *message, struct wpa_supplicant *wpa_s)
{
DBusMessage *reply = NULL;
DBusMessageIter iter, variant_iter;
dbus_bool_t process = (wpa_s->conf->wps_cred_processing != 1);
if (message == NULL)
reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
else
reply = dbus_message_new_method_return(message);
if (reply != NULL) {
dbus_message_iter_init_append(reply, &iter);
if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
"b", &variant_iter) ||
!dbus_message_iter_append_basic(&variant_iter,
DBUS_TYPE_BOOLEAN,
&process) ||
!dbus_message_iter_close_container(&iter, &variant_iter)) {
perror("wpas_dbus_getter_process_credentials[dbus]: "
"out of memory to put value into message.");
dbus_message_unref(reply);
reply = dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
NULL);
}
} else {
perror("wpas_dbus_getter_process_credentials[dbus]: out of "
"memory to create reply message.");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
}
return reply;
}
/**
* wpas_dbus_setter_process_credentials - Set credentials_processed conf param
* @message: Pointer to incoming dbus message
* @wpa_s: %wpa_supplicant data structure
* Returns: NULL on success or DBus error on failure
*
* Setter for "ProcessCredentials" property. Sets credentials_processed on 2
* if boolean argument is true or on 1 if otherwise.
*/
DBusMessage * wpas_dbus_setter_process_credentials(
DBusMessage *message, struct wpa_supplicant *wpa_s)
{
DBusMessage *reply = NULL;
DBusMessageIter iter, variant_iter;
dbus_bool_t process_credentials, old_pc;
if (!dbus_message_iter_init(message, &iter)) {
perror("wpas_dbus_getter_ap_scan[dbus]: out of "
"memory to return scanning state.");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
/* omit first and second argument and get value from third*/
dbus_message_iter_next(&iter);
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &variant_iter);
if (dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_BOOLEAN)
{
reply = wpas_dbus_error_invald_args(message,
"BOOLEAN required");
goto out;
}
dbus_message_iter_get_basic(&variant_iter, &process_credentials);
old_pc = (wpa_s->conf->wps_cred_processing != 1);
wpa_s->conf->wps_cred_processing = (process_credentials ? 2 : 1);
if ((wpa_s->conf->wps_cred_processing != 1) != old_pc)
wpa_dbus_signal_property_changed(
wpa_s->global->dbus_new_ctrl_iface,
(WPADBusPropertyAccessor)
wpas_dbus_getter_process_credentials,
wpa_s, wpas_dbus_get_path(wpa_s),
WPAS_DBUS_NEW_IFACE_WPS,
"ProcessCredentials");
out:
return reply;
}