mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-26 10:39:23 +01:00
client: wsc: Get rid of bind/unbind_interface
This commit is contained in:
parent
d90eb32cb0
commit
5aa5e2fef6
@ -890,20 +890,6 @@ static const struct command device_commands[] = {
|
|||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct proxy_interface *device_wsc_get(const char *device_name)
|
|
||||||
{
|
|
||||||
const struct device *device;
|
|
||||||
const struct proxy_interface *proxy =
|
|
||||||
get_device_proxy_by_name(device_name);
|
|
||||||
|
|
||||||
if (!proxy)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
device = proxy_interface_get_data(proxy);
|
|
||||||
|
|
||||||
return device->wsc;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *device_wsc_family_arg_completion(const char *text, int state)
|
char *device_wsc_family_arg_completion(const char *text, int state)
|
||||||
{
|
{
|
||||||
return proxy_property_str_completion(&device_interface_type,
|
return proxy_property_str_completion(&device_interface_type,
|
||||||
@ -911,7 +897,6 @@ char *device_wsc_family_arg_completion(const char *text, int state)
|
|||||||
"Name", text, state);
|
"Name", text, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *device_ap_family_arg_completion(const char *text, int state)
|
char *device_ap_family_arg_completion(const char *text, int state)
|
||||||
{
|
{
|
||||||
return proxy_property_str_completion(&device_interface_type,
|
return proxy_property_str_completion(&device_interface_type,
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
struct proxy_interface;
|
struct proxy_interface;
|
||||||
const struct proxy_interface *device_wsc_get(const char *device_name);
|
|
||||||
|
|
||||||
char *device_wsc_family_arg_completion(const char *text, int state);
|
char *device_wsc_family_arg_completion(const char *text, int state);
|
||||||
|
|
||||||
|
114
client/wsc.c
114
client/wsc.c
@ -32,8 +32,6 @@
|
|||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
struct wsc {
|
struct wsc {
|
||||||
const struct proxy_interface *device;
|
|
||||||
|
|
||||||
/* TODO: Add status */
|
/* TODO: Add status */
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -46,48 +44,12 @@ static void wsc_destroy(void *data)
|
|||||||
{
|
{
|
||||||
struct wsc *wsc = data;
|
struct wsc *wsc = data;
|
||||||
|
|
||||||
wsc->device = NULL;
|
|
||||||
|
|
||||||
l_free(wsc);
|
l_free(wsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool wsc_bind_interface(const struct proxy_interface *proxy,
|
|
||||||
const struct proxy_interface *dependency)
|
|
||||||
{
|
|
||||||
const char *interface = proxy_interface_get_interface(dependency);
|
|
||||||
|
|
||||||
if (!strcmp(interface, IWD_DEVICE_INTERFACE)) {
|
|
||||||
struct wsc *wsc = proxy_interface_get_data(proxy);
|
|
||||||
|
|
||||||
wsc->device = dependency;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool wsc_unbind_interface(const struct proxy_interface *proxy,
|
|
||||||
const struct proxy_interface *dependency)
|
|
||||||
{
|
|
||||||
const char *interface = proxy_interface_get_interface(dependency);
|
|
||||||
|
|
||||||
if (!strcmp(interface, IWD_DEVICE_INTERFACE)) {
|
|
||||||
struct wsc *wsc = proxy_interface_get_data(proxy);
|
|
||||||
|
|
||||||
wsc->device = NULL;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct proxy_interface_type_ops wsc_ops = {
|
static const struct proxy_interface_type_ops wsc_ops = {
|
||||||
.create = wsc_create,
|
.create = wsc_create,
|
||||||
.destroy = wsc_destroy,
|
.destroy = wsc_destroy,
|
||||||
.bind_interface = wsc_bind_interface,
|
|
||||||
.unbind_interface = wsc_unbind_interface,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct proxy_interface_type wsc_interface_type = {
|
static struct proxy_interface_type wsc_interface_type = {
|
||||||
@ -123,28 +85,29 @@ static void generate_pin_callback(struct l_dbus_message *message,
|
|||||||
check_errors_method_callback, pin);
|
check_errors_method_callback, pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool match_by_device(const void *a, const void *b)
|
|
||||||
{
|
|
||||||
const struct wsc *wsc = a;
|
|
||||||
|
|
||||||
return wsc->device ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void display_wsc_inline(const char *margin, const void *data)
|
static void display_wsc_inline(const char *margin, const void *data)
|
||||||
{
|
{
|
||||||
const struct wsc *wsc = data;
|
const struct proxy_interface *wsc_i = data;
|
||||||
|
struct proxy_interface *device_i =
|
||||||
|
proxy_interface_find(IWD_DEVICE_INTERFACE,
|
||||||
|
proxy_interface_get_path(wsc_i));
|
||||||
|
const char *identity;
|
||||||
|
|
||||||
if (wsc->device && proxy_interface_get_identity_str(wsc->device))
|
if (!device_i)
|
||||||
display("%s%-*s\n", margin,
|
return;
|
||||||
20, proxy_interface_get_identity_str(wsc->device));
|
|
||||||
|
identity = proxy_interface_get_identity_str(device_i);
|
||||||
|
if (!identity)
|
||||||
|
return;
|
||||||
|
|
||||||
|
display("%s%-*s\n", margin, 20, identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_status cmd_list(const char *device_name, char **argv, int argc)
|
static enum cmd_status cmd_list(const char *device_name, char **argv, int argc)
|
||||||
{
|
{
|
||||||
const struct l_queue_entry *entry;
|
const struct l_queue_entry *entry;
|
||||||
struct l_queue *match =
|
struct l_queue *match =
|
||||||
proxy_interface_find_all(IWD_WSC_INTERFACE,
|
proxy_interface_find_all(IWD_WSC_INTERFACE, NULL, NULL);
|
||||||
match_by_device, NULL);
|
|
||||||
|
|
||||||
display_table_header("WSC-capable Devices", MARGIN "%-*s", 20, "Name");
|
display_table_header("WSC-capable Devices", MARGIN "%-*s", 20, "Name");
|
||||||
|
|
||||||
@ -156,8 +119,7 @@ static enum cmd_status cmd_list(const char *device_name, char **argv, int argc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (entry = l_queue_get_entries(match); entry; entry = entry->next) {
|
for (entry = l_queue_get_entries(match); entry; entry = entry->next) {
|
||||||
const struct wsc *wsc = proxy_interface_get_data(entry->data);
|
const struct proxy_interface *wsc = entry->data;
|
||||||
|
|
||||||
display_wsc_inline(MARGIN, wsc);
|
display_wsc_inline(MARGIN, wsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,15 +133,15 @@ static enum cmd_status cmd_list(const char *device_name, char **argv, int argc)
|
|||||||
static enum cmd_status cmd_push_button(const char *device_name,
|
static enum cmd_status cmd_push_button(const char *device_name,
|
||||||
char **argv, int argc)
|
char **argv, int argc)
|
||||||
{
|
{
|
||||||
const struct proxy_interface *proxy = device_wsc_get(device_name);
|
const struct proxy_interface *wsc_i =
|
||||||
|
device_proxy_find(device_name, IWD_WSC_INTERFACE);
|
||||||
if (!proxy) {
|
|
||||||
display("Invalid device name '%s'\n", device_name);
|
|
||||||
|
|
||||||
|
if (!wsc_i) {
|
||||||
|
display("No wsc on device: '%s'\n", device_name);
|
||||||
return CMD_STATUS_INVALID_VALUE;
|
return CMD_STATUS_INVALID_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy_interface_method_call(proxy, "PushButton", "",
|
proxy_interface_method_call(wsc_i, "PushButton", "",
|
||||||
check_errors_method_callback);
|
check_errors_method_callback);
|
||||||
|
|
||||||
return CMD_STATUS_TRIGGERED;
|
return CMD_STATUS_TRIGGERED;
|
||||||
@ -188,18 +150,18 @@ static enum cmd_status cmd_push_button(const char *device_name,
|
|||||||
static enum cmd_status cmd_start_user_pin(const char *device_name,
|
static enum cmd_status cmd_start_user_pin(const char *device_name,
|
||||||
char **argv, int argc)
|
char **argv, int argc)
|
||||||
{
|
{
|
||||||
const struct proxy_interface *proxy = device_wsc_get(device_name);
|
const struct proxy_interface *wsc_i;
|
||||||
|
|
||||||
if (!proxy) {
|
|
||||||
display("Invalid device name '%s'\n", device_name);
|
|
||||||
|
|
||||||
return CMD_STATUS_INVALID_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
return CMD_STATUS_INVALID_ARGS;
|
return CMD_STATUS_INVALID_ARGS;
|
||||||
|
|
||||||
proxy_interface_method_call(proxy, "StartPin", "s",
|
wsc_i = device_proxy_find(device_name, IWD_WSC_INTERFACE);
|
||||||
|
if (!wsc_i) {
|
||||||
|
display("No wsc on device: '%s'\n", device_name);
|
||||||
|
return CMD_STATUS_INVALID_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy_interface_method_call(wsc_i, "StartPin", "s",
|
||||||
check_errors_method_callback, argv[0]);
|
check_errors_method_callback, argv[0]);
|
||||||
|
|
||||||
return CMD_STATUS_TRIGGERED;
|
return CMD_STATUS_TRIGGERED;
|
||||||
@ -208,15 +170,15 @@ static enum cmd_status cmd_start_user_pin(const char *device_name,
|
|||||||
static enum cmd_status cmd_start_pin(const char *device_name,
|
static enum cmd_status cmd_start_pin(const char *device_name,
|
||||||
char **argv, int argc)
|
char **argv, int argc)
|
||||||
{
|
{
|
||||||
const struct proxy_interface *proxy = device_wsc_get(device_name);
|
const struct proxy_interface *wsc_i =
|
||||||
|
device_proxy_find(device_name, IWD_WSC_INTERFACE);
|
||||||
if (!proxy) {
|
|
||||||
display("Invalid device name '%s'\n", device_name);
|
|
||||||
|
|
||||||
|
if (!wsc_i) {
|
||||||
|
display("No wsc on device: '%s'\n", device_name);
|
||||||
return CMD_STATUS_INVALID_VALUE;
|
return CMD_STATUS_INVALID_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy_interface_method_call(proxy, "GeneratePin", "",
|
proxy_interface_method_call(wsc_i, "GeneratePin", "",
|
||||||
generate_pin_callback);
|
generate_pin_callback);
|
||||||
|
|
||||||
return CMD_STATUS_TRIGGERED;
|
return CMD_STATUS_TRIGGERED;
|
||||||
@ -225,15 +187,15 @@ static enum cmd_status cmd_start_pin(const char *device_name,
|
|||||||
static enum cmd_status cmd_cancel(const char *device_name,
|
static enum cmd_status cmd_cancel(const char *device_name,
|
||||||
char **argv, int argc)
|
char **argv, int argc)
|
||||||
{
|
{
|
||||||
const struct proxy_interface *proxy = device_wsc_get(device_name);
|
const struct proxy_interface *wsc_i =
|
||||||
|
device_proxy_find(device_name, IWD_WSC_INTERFACE);
|
||||||
if (!proxy) {
|
|
||||||
display("Invalid device name '%s'\n", device_name);
|
|
||||||
|
|
||||||
|
if (!wsc_i) {
|
||||||
|
display("No wsc on device: '%s'\n", device_name);
|
||||||
return CMD_STATUS_INVALID_VALUE;
|
return CMD_STATUS_INVALID_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy_interface_method_call(proxy, "Cancel", "",
|
proxy_interface_method_call(wsc_i, "Cancel", "",
|
||||||
check_errors_method_callback);
|
check_errors_method_callback);
|
||||||
|
|
||||||
return CMD_STATUS_TRIGGERED;
|
return CMD_STATUS_TRIGGERED;
|
||||||
|
Loading…
Reference in New Issue
Block a user