2017-05-01 19:23:44 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Wireless daemon for Linux
|
|
|
|
*
|
2019-10-25 00:43:08 +02:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation. All rights reserved.
|
2017-05-01 19:23:44 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <ell/ell.h>
|
|
|
|
|
2019-12-13 09:02:42 +01:00
|
|
|
#include "client/command.h"
|
|
|
|
#include "client/dbus-proxy.h"
|
|
|
|
#include "client/device.h"
|
|
|
|
#include "client/display.h"
|
2017-05-01 19:23:44 +02:00
|
|
|
|
|
|
|
static struct proxy_interface_type wsc_interface_type = {
|
|
|
|
.interface = IWD_WSC_INTERFACE,
|
|
|
|
};
|
|
|
|
|
2017-05-01 19:23:48 +02:00
|
|
|
static void check_errors_method_callback(struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
dbus_message_has_error(message);
|
|
|
|
}
|
|
|
|
|
2017-05-01 19:23:51 +02:00
|
|
|
static void generate_pin_callback(struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
const struct proxy_interface *proxy = user_data;
|
|
|
|
const char *pin;
|
|
|
|
|
|
|
|
if (dbus_message_has_error(message))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!l_dbus_message_get_arguments(message, "s", &pin)) {
|
|
|
|
l_error("Failed to parse 'generate pin' callback message");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pin)
|
|
|
|
return;
|
|
|
|
|
|
|
|
proxy_interface_method_call(proxy, "StartPin", "s",
|
|
|
|
check_errors_method_callback, pin);
|
|
|
|
}
|
|
|
|
|
2018-09-14 10:01:55 +02:00
|
|
|
static void display_wsc_inline(const char *margin, const void *data)
|
2017-05-12 23:36:51 +02:00
|
|
|
{
|
2018-09-14 10:01:55 +02:00
|
|
|
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;
|
2017-05-12 23:36:51 +02:00
|
|
|
|
2018-09-14 10:01:55 +02:00
|
|
|
if (!device_i)
|
|
|
|
return;
|
2017-05-12 23:36:51 +02:00
|
|
|
|
2018-09-14 10:01:55 +02:00
|
|
|
identity = proxy_interface_get_identity_str(device_i);
|
|
|
|
if (!identity)
|
|
|
|
return;
|
2017-05-12 23:36:51 +02:00
|
|
|
|
2018-09-14 10:01:55 +02:00
|
|
|
display("%s%-*s\n", margin, 20, identity);
|
2017-05-12 23:36:51 +02:00
|
|
|
}
|
|
|
|
|
2018-07-27 21:41:30 +02:00
|
|
|
static enum cmd_status cmd_list(const char *device_name, char **argv, int argc)
|
2017-05-12 23:36:51 +02:00
|
|
|
{
|
|
|
|
const struct l_queue_entry *entry;
|
|
|
|
struct l_queue *match =
|
2018-09-14 10:01:55 +02:00
|
|
|
proxy_interface_find_all(IWD_WSC_INTERFACE, NULL, NULL);
|
2017-05-12 23:36:51 +02:00
|
|
|
|
2017-05-20 00:13:42 +02:00
|
|
|
display_table_header("WSC-capable Devices", MARGIN "%-*s", 20, "Name");
|
|
|
|
|
|
|
|
if (!match) {
|
2017-05-12 23:36:51 +02:00
|
|
|
display("No WSC-capable devices available\n");
|
2017-05-20 00:13:42 +02:00
|
|
|
display_table_footer();
|
2017-05-12 23:36:51 +02:00
|
|
|
|
2018-08-03 23:35:37 +02:00
|
|
|
return CMD_STATUS_DONE;
|
2017-05-12 23:36:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (entry = l_queue_get_entries(match); entry; entry = entry->next) {
|
2018-09-14 10:01:55 +02:00
|
|
|
const struct proxy_interface *wsc = entry->data;
|
2017-05-12 23:36:51 +02:00
|
|
|
display_wsc_inline(MARGIN, wsc);
|
|
|
|
}
|
|
|
|
|
|
|
|
display_table_footer();
|
|
|
|
|
|
|
|
l_queue_destroy(match, NULL);
|
|
|
|
|
2018-08-03 23:35:37 +02:00
|
|
|
return CMD_STATUS_DONE;
|
2017-05-12 23:36:51 +02:00
|
|
|
}
|
|
|
|
|
2018-07-27 21:41:30 +02:00
|
|
|
static enum cmd_status cmd_push_button(const char *device_name,
|
|
|
|
char **argv, int argc)
|
2017-05-01 19:23:45 +02:00
|
|
|
{
|
2018-09-14 10:01:55 +02:00
|
|
|
const struct proxy_interface *wsc_i =
|
|
|
|
device_proxy_find(device_name, IWD_WSC_INTERFACE);
|
2017-05-01 19:23:49 +02:00
|
|
|
|
2018-09-14 10:01:55 +02:00
|
|
|
if (!wsc_i) {
|
|
|
|
display("No wsc on device: '%s'\n", device_name);
|
2017-05-01 19:23:49 +02:00
|
|
|
return CMD_STATUS_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
|
2018-09-14 10:01:55 +02:00
|
|
|
proxy_interface_method_call(wsc_i, "PushButton", "",
|
2017-05-01 19:23:49 +02:00
|
|
|
check_errors_method_callback);
|
|
|
|
|
2018-08-03 23:35:37 +02:00
|
|
|
return CMD_STATUS_TRIGGERED;
|
2017-05-01 19:23:45 +02:00
|
|
|
}
|
|
|
|
|
2018-07-27 21:41:30 +02:00
|
|
|
static enum cmd_status cmd_start_user_pin(const char *device_name,
|
|
|
|
char **argv, int argc)
|
2017-05-01 19:23:45 +02:00
|
|
|
{
|
2018-09-14 10:01:55 +02:00
|
|
|
const struct proxy_interface *wsc_i;
|
2017-05-01 19:23:50 +02:00
|
|
|
|
2018-09-14 10:01:55 +02:00
|
|
|
if (argc != 1)
|
|
|
|
return CMD_STATUS_INVALID_ARGS;
|
2017-05-01 19:23:50 +02:00
|
|
|
|
2018-09-14 10:01:55 +02:00
|
|
|
wsc_i = device_proxy_find(device_name, IWD_WSC_INTERFACE);
|
|
|
|
if (!wsc_i) {
|
|
|
|
display("No wsc on device: '%s'\n", device_name);
|
2017-05-01 19:23:50 +02:00
|
|
|
return CMD_STATUS_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
|
2018-09-14 10:01:55 +02:00
|
|
|
proxy_interface_method_call(wsc_i, "StartPin", "s",
|
2018-07-27 21:41:30 +02:00
|
|
|
check_errors_method_callback, argv[0]);
|
2017-05-01 19:23:50 +02:00
|
|
|
|
2018-08-03 23:35:37 +02:00
|
|
|
return CMD_STATUS_TRIGGERED;
|
2017-05-01 19:23:45 +02:00
|
|
|
}
|
|
|
|
|
2018-07-27 21:41:30 +02:00
|
|
|
static enum cmd_status cmd_start_pin(const char *device_name,
|
|
|
|
char **argv, int argc)
|
2017-05-01 19:23:45 +02:00
|
|
|
{
|
2018-09-14 10:01:55 +02:00
|
|
|
const struct proxy_interface *wsc_i =
|
|
|
|
device_proxy_find(device_name, IWD_WSC_INTERFACE);
|
2017-05-01 19:23:51 +02:00
|
|
|
|
2018-09-14 10:01:55 +02:00
|
|
|
if (!wsc_i) {
|
|
|
|
display("No wsc on device: '%s'\n", device_name);
|
2017-05-01 19:23:51 +02:00
|
|
|
return CMD_STATUS_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
|
2018-09-14 10:01:55 +02:00
|
|
|
proxy_interface_method_call(wsc_i, "GeneratePin", "",
|
2017-05-01 19:23:51 +02:00
|
|
|
generate_pin_callback);
|
|
|
|
|
2018-08-03 23:35:37 +02:00
|
|
|
return CMD_STATUS_TRIGGERED;
|
2017-05-01 19:23:45 +02:00
|
|
|
}
|
|
|
|
|
2018-07-27 21:41:30 +02:00
|
|
|
static enum cmd_status cmd_cancel(const char *device_name,
|
|
|
|
char **argv, int argc)
|
2017-05-01 19:23:45 +02:00
|
|
|
{
|
2018-09-14 10:01:55 +02:00
|
|
|
const struct proxy_interface *wsc_i =
|
|
|
|
device_proxy_find(device_name, IWD_WSC_INTERFACE);
|
2017-05-01 19:23:48 +02:00
|
|
|
|
2018-09-14 10:01:55 +02:00
|
|
|
if (!wsc_i) {
|
|
|
|
display("No wsc on device: '%s'\n", device_name);
|
2017-05-01 19:23:48 +02:00
|
|
|
return CMD_STATUS_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
|
2018-09-14 10:01:55 +02:00
|
|
|
proxy_interface_method_call(wsc_i, "Cancel", "",
|
2017-05-01 19:23:48 +02:00
|
|
|
check_errors_method_callback);
|
|
|
|
|
2018-08-03 23:35:37 +02:00
|
|
|
return CMD_STATUS_TRIGGERED;
|
2017-05-01 19:23:45 +02:00
|
|
|
}
|
|
|
|
|
2017-05-01 19:23:44 +02:00
|
|
|
static const struct command wsc_commands[] = {
|
2017-05-12 23:36:51 +02:00
|
|
|
{ NULL, "list", NULL, cmd_list, "List WSC-capable devices", true },
|
2017-05-01 19:23:45 +02:00
|
|
|
{ "<wlan>", "push-button", NULL, cmd_push_button, "PushButton mode" },
|
2022-07-07 19:54:59 +02:00
|
|
|
{ "<wlan>", "start-user-pin", "<PIN>", cmd_start_user_pin,
|
2017-05-01 19:23:45 +02:00
|
|
|
"PIN mode" },
|
|
|
|
{ "<wlan>", "start-pin", NULL, cmd_start_pin,
|
2022-07-07 19:54:59 +02:00
|
|
|
"PIN mode with generated 8 digit PIN" },
|
2017-05-01 19:23:45 +02:00
|
|
|
{ "<wlan>", "cancel", NULL, cmd_cancel, "Aborts WSC operations" },
|
2017-05-01 19:23:44 +02:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2017-05-01 19:23:46 +02:00
|
|
|
static char *family_arg_completion(const char *text, int state)
|
|
|
|
{
|
2018-09-15 05:58:10 +02:00
|
|
|
return device_arg_completion(text, state, wsc_commands,
|
|
|
|
IWD_WSC_INTERFACE);
|
2017-05-01 19:23:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *entity_arg_completion(const char *text, int state)
|
|
|
|
{
|
|
|
|
return command_entity_arg_completion(text, state, wsc_commands);
|
|
|
|
}
|
|
|
|
|
2017-05-01 19:23:44 +02:00
|
|
|
static struct command_family wsc_command_family = {
|
|
|
|
.caption = "WiFi Simple Configuration",
|
|
|
|
.name = "wsc",
|
|
|
|
.command_list = wsc_commands,
|
2017-05-01 19:23:46 +02:00
|
|
|
.family_arg_completion = family_arg_completion,
|
|
|
|
.entity_arg_completion = entity_arg_completion,
|
2017-05-01 19:23:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static int wsc_command_family_init(void)
|
|
|
|
{
|
|
|
|
command_family_register(&wsc_command_family);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wsc_command_family_exit(void)
|
|
|
|
{
|
|
|
|
command_family_unregister(&wsc_command_family);
|
|
|
|
}
|
|
|
|
|
|
|
|
COMMAND_FAMILY(wsc_command_family, wsc_command_family_init,
|
|
|
|
wsc_command_family_exit)
|
|
|
|
|
|
|
|
static int wsc_interface_init(void)
|
|
|
|
{
|
|
|
|
proxy_interface_type_register(&wsc_interface_type);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wsc_interface_exit(void)
|
|
|
|
{
|
2017-05-02 22:20:46 +02:00
|
|
|
proxy_interface_type_unregister(&wsc_interface_type);
|
2017-05-01 19:23:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
INTERFACE_TYPE(wsc_interface_type, wsc_interface_init, wsc_interface_exit)
|