Add new WPS start/cancel command.
Add WPS success/fail event handler.
Signed-off-by: n-itaya <Natsuki.Itaya(a)sony.com>
---
client/commands.c | 126 +++++++++++++++++++++++++++++++++++++++++
client/dbus_helpers.c | 2 +-
doc/agent-api.txt | 6 ++
doc/technology-api.txt | 43 ++++++++++++++
4 files changed, 176 insertions(+), 1 deletion(-)
diff --git a/client/commands.c b/client/commands.c
index 05b93162..75a5a1de 100644
--- a/client/commands.c
+++ b/client/commands.c
@@ -639,6 +639,86 @@ static int cmd_tether(char *args[], int num, struct connman_option
*options)
return tether_set(args[1], set_tethering);
}
+static int wps_cb(DBusMessageIter *iter, const char *error,
+ void *user_data)
+{
+ bool sta = GPOINTER_TO_UINT(user_data);
+
+ if (error) {
+ fprintf(stderr, "WPS Error: %s\n", error);
+ return 1;
+ }
+
+ if (sta) {
+ fprintf(stdout, "WPS: Success\n");
+ services_list(iter, NULL, NULL);
+ } else
+ fprintf(stdout, "WPS: Started\n");
+
+ return 0;
+}
+
+static void set_wps_authentication(DBusMessageIter *iter, void *user_data)
+{
+ const char *auth = user_data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &auth);
+}
+
+static int cmd_wps_start(char *args[], int num, struct connman_option *options)
+{
+ char *auth = "";
+ char *method = "Start_STA_WPS";
+ bool sta = true;
+
+ if (num > 3)
+ return -E2BIG;
+
+ if (num < 3)
+ return -EINVAL;
+
+ if (g_strcmp0(args[2], "pbc") != 0)
+ auth = args[2];
+
+ if (g_strcmp0(args[1], "ap") == 0) {
+ method = "Start_AP_WPS";
+ sta = false;
+ } else if (g_strcmp0(args[1], "sta") != 0) {
+ fprintf(stdout,
+ "Incorrect mode %s. Correct options: ap or sta\n",
+ args[1]);
+ return -EINVAL;
+ }
+
+ return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+ "/net/connman/technology/wifi",
+ "net.connman.Technology",
+ method, wps_cb, GUINT_TO_POINTER(sta),
+ set_wps_authentication, auth);
+}
+
+static int wps_cancel_cb(DBusMessageIter *iter, const char *error,
+ void *user_data)
+{
+ if (!error)
+ fprintf(stdout, "Ongoing WPS session cancelled\n");
+ else
+ fprintf(stdout, "WPS Error: %s\n", error);
+
+ return 0;
+}
+
+static int cmd_wps_cancel(char *args[], int num, struct connman_option *options)
+{
+ if (num > 1)
+ return -E2BIG;
+
+ return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+ "/net/connman/technology/wifi",
+ "net.connman.Technology", "Cancel_WPS",
+ wps_cancel_cb, NULL, NULL, NULL);
+}
+
static int scan_return(DBusMessageIter *iter, const char *error,
void *user_data)
{
@@ -2332,6 +2412,46 @@ static char *lookup_tether(const char *text, int state)
return NULL;
}
+static char *lookup_wps_option(const char *text, int state, char **opt)
+{
+ static int idx;
+ static int len;
+ char *str;
+
+ if (!state) {
+ idx = 0;
+ len = strlen(text);
+ }
+
+ while (opt[idx]) {
+ str = opt[idx];
+ idx++;
+
+ if (!strncmp(text, str, len))
+ return strdup(str);
+ }
+
+ return NULL;
+}
+
+static char *lookup_wps(const char *text, int state)
+{
+ int level;
+ const char *action[] = { "ap", "sta", NULL };
+ const char *type[] = { "pbc", NULL };
+
+ level = __connmanctl_input_calc_level();
+
+ if (level == 1)
+ return lookup_wps_option(text, state, action);
+ if (level == 2)
+ return lookup_wps_option(text, state, type);
+
+ __connmanctl_input_lookup_end();
+
+ return NULL;
+}
+
static char *lookup_agent(const char *text, int state)
{
if (__connmanctl_input_calc_level() > 1) {
@@ -2736,6 +2856,12 @@ static const struct {
NULL, cmd_tether,
"Enable, disable tethering, set SSID and passphrase for wifi",
lookup_tether },
+ { "wps", "ap|sta <pbc/PIN>", NULL,
cmd_wps_start,
+ "Start WPS in AP or STA mode with PBC or indicating the PIN to be used",
+ lookup_wps },
+ { "wps_cancel", NULL, NULL, cmd_wps_cancel,
+ "Cancel ongoing WPS Session",
+ lookup_wps },
{ "services", "[<service>]", service_options,
cmd_services,
"Display services", lookup_service_arg },
{ "peers", "[peer]", NULL, cmd_peers,
diff --git a/client/dbus_helpers.c b/client/dbus_helpers.c
index 6ca407d4..1a8eea16 100644
--- a/client/dbus_helpers.c
+++ b/client/dbus_helpers.c
@@ -28,7 +28,7 @@
#include "input.h"
#include "dbus_helpers.h"
-#define TIMEOUT 120000
+#define TIMEOUT 125000
void __connmanctl_dbus_print(DBusMessageIter *iter, const char *pre,
const char *dict, const char *sep)
diff --git a/doc/agent-api.txt b/doc/agent-api.txt
index e3c1dcde..24b7f762 100644
--- a/doc/agent-api.txt
+++ b/doc/agent-api.txt
@@ -141,6 +141,12 @@ Fields string Name
In case of a RequestPeerAuthorization, this field will
be set as mandatory.
+ To use this in order to get connected to a given
+ services is deprecated and should not be used. Methods
+ Technology.Start_STA_WPS and Technology.Start_AP_WPS
+ are provided by ConnMan and user should use those two
+ instead.
+
string Username
Username for WISPr authentication. This field will be
diff --git a/doc/technology-api.txt b/doc/technology-api.txt
index f22e9b29..75c1091d 100644
--- a/doc/technology-api.txt
+++ b/doc/technology-api.txt
@@ -40,6 +40,49 @@ Methods dict GetProperties() [deprecated]
via the PeersChanged signal from the manager
interface.
+ void Start_AP_WPS(string authentication)
+
+ Start a WPS Session when the system is playing AP
+ role (Tethering) in order to allow potential Ex-STAs
+ to get connected by using WPS.
+
+ The argument indicates the WPS authentication method
+ which can be an empty string, if user wants to use
+ push-button method, or a pin code if user wants to
+ use the pin method.
+
+ This method is supported only by WiFi technology.
+
+ Possible Errors: [service].Error.InvalidArguments
+ [service].Error.PermissionDenied
+ [service].Error.NotSupported
+
+ void Start_STA_WPS(string authentication)
+
+ Start a WPS Session in STA role in order to be able
+ to get connected with an Ex-AP with WPS capabilities.
+
+ The argument indicates the WPS authentication method
+ which can be an empty string, if user wants to use
+ push-button method, or a pin code if user wants to
+ use the pin method.
+
+ This method is supported only by WiFi technology.
+
+ Possible Errors: [service].Error.InvalidArguments
+ [service].Error.OperationAborted
+ [service].Error.OperationTimeout
+ [service].Error.NotConnected
+ [service].Error.NotSupported
+
+ void Cancel_WPS()
+
+ Cancel ongoing WPS session.
+
+ This method is supported only by WiFi technology.
+
+ Possible Errors: [service].Error.NotSupported
+
Signals PropertyChanged(string name, variant value)
This signal indicates a changed value of the given
--
2.17.1