From 8c5f73098335225aa71efdbf414f7c8452658f17 Mon Sep 17 00:00:00 2001 From: Jithu Jance Date: Tue, 6 Dec 2011 21:28:02 +0200 Subject: [PATCH] P2P: Add optional "join" argument for p2p_prov_disc command This can be used to request Provision Discovery Request to be sent for the purpose of joining a running group, e.g., to request the GO to display a PIN that we can then use with p2p_connect join command. Signed-hostap: Jithu Jance --- src/drivers/driver.h | 2 +- wpa_supplicant/README-P2P | 6 +++++- wpa_supplicant/ctrl_iface.c | 5 +++-- wpa_supplicant/dbus/dbus_new_handlers_p2p.c | 2 +- wpa_supplicant/driver_i.h | 4 ++-- wpa_supplicant/p2p_supplicant.c | 18 ++++++++++-------- wpa_supplicant/p2p_supplicant.h | 2 +- wpa_supplicant/wpa_cli.c | 16 ++++++++++------ 8 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/drivers/driver.h b/src/drivers/driver.h index 388b405b8..c8a71fd7c 100644 --- a/src/drivers/driver.h +++ b/src/drivers/driver.h @@ -2194,7 +2194,7 @@ struct wpa_driver_ops { * struct wpa_driver_capa. */ int (*p2p_prov_disc_req)(void *priv, const u8 *peer_addr, - u16 config_methods); + u16 config_methods, int join); /** * p2p_sd_request - Schedule a service discovery query diff --git a/wpa_supplicant/README-P2P b/wpa_supplicant/README-P2P index 4b713984b..db6e4aefa 100644 --- a/wpa_supplicant/README-P2P +++ b/wpa_supplicant/README-P2P @@ -101,7 +101,7 @@ Flush P2P peer table and state. Group Formation -p2p_prov_disc +p2p_prov_disc [join] Send P2P provision discovery request to the specified peer. The parameters for this command are the P2P device address of the peer and @@ -110,6 +110,10 @@ the desired configuration method. For example, "p2p_prov_disc us and "p2p_prov_disc 02:01:02:03:04:05 keypad" would request the peer to enter a PIN that we display. +The optional "join" parameter can be used to indicate that this command +is requesting an already running GO to prepare for a new client. This is +mainly used with "display" to request it to display a PIN. + p2p_connect [display|keypad] [persistent] [join|auth] [go_intent=<0..15>] [freq=] diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 443b693dc..4092fe076 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -2551,7 +2551,7 @@ static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) u8 addr[ETH_ALEN]; char *pos; - /* */ + /* [join] */ if (hwaddr_aton(cmd, addr)) return -1; @@ -2561,7 +2561,8 @@ static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) return -1; pos++; - return wpas_p2p_prov_disc(wpa_s, addr, pos); + return wpas_p2p_prov_disc(wpa_s, addr, pos, + os_strstr(pos, "join") != NULL); } diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c index f2c5a1887..5b62b947e 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c +++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c @@ -692,7 +692,7 @@ DBusMessage * wpas_dbus_handler_p2p_prov_disc_req(DBusMessage *message, os_strcmp(config_method, "pushbutton")) return wpas_dbus_error_invalid_args(message, NULL); - if (wpas_p2p_prov_disc(wpa_s, peer_addr, config_method) < 0) + if (wpas_p2p_prov_disc(wpa_s, peer_addr, config_method, 0) < 0) return wpas_dbus_error_unknown_error(message, "Failed to send provision discovery request"); diff --git a/wpa_supplicant/driver_i.h b/wpa_supplicant/driver_i.h index 8b584db21..d61b3fddb 100644 --- a/wpa_supplicant/driver_i.h +++ b/wpa_supplicant/driver_i.h @@ -569,12 +569,12 @@ static inline int wpa_drv_p2p_set_params(struct wpa_supplicant *wpa_s, static inline int wpa_drv_p2p_prov_disc_req(struct wpa_supplicant *wpa_s, const u8 *peer_addr, - u16 config_methods) + u16 config_methods, int join) { if (!wpa_s->driver->p2p_prov_disc_req) return -1; return wpa_s->driver->p2p_prov_disc_req(wpa_s->drv_priv, peer_addr, - config_methods); + config_methods, join); } static inline u64 wpa_drv_p2p_sd_request(struct wpa_supplicant *wpa_s, diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 450cec87a..564517f7c 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -3281,30 +3281,32 @@ void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s, int wpas_p2p_prov_disc(struct wpa_supplicant *wpa_s, const u8 *peer_addr, - const char *config_method) + const char *config_method, int join) { u16 config_methods; - if (os_strcmp(config_method, "display") == 0) + if (os_strncmp(config_method, "display", 7) == 0) config_methods = WPS_CONFIG_DISPLAY; - else if (os_strcmp(config_method, "keypad") == 0) + else if (os_strncmp(config_method, "keypad", 6) == 0) config_methods = WPS_CONFIG_KEYPAD; - else if (os_strcmp(config_method, "pbc") == 0 || - os_strcmp(config_method, "pushbutton") == 0) + else if (os_strncmp(config_method, "pbc", 3) == 0 || + os_strncmp(config_method, "pushbutton", 10) == 0) config_methods = WPS_CONFIG_PUSHBUTTON; - else + else { + wpa_printf(MSG_DEBUG, "P2P: Unknown config method"); return -1; + } if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) { return wpa_drv_p2p_prov_disc_req(wpa_s, peer_addr, - config_methods); + config_methods, join); } if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) return -1; return p2p_prov_disc_req(wpa_s->global->p2p, peer_addr, - config_methods, 0); + config_methods, join); } diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h index 9a13f9f6c..33b22db17 100644 --- a/wpa_supplicant/p2p_supplicant.h +++ b/wpa_supplicant/p2p_supplicant.h @@ -43,7 +43,7 @@ struct p2p_group * wpas_p2p_group_init(struct wpa_supplicant *wpa_s, void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr, int registrar); int wpas_p2p_prov_disc(struct wpa_supplicant *wpa_s, const u8 *peer_addr, - const char *config_method); + const char *config_method, int join); void wpas_send_action_tx_status(struct wpa_supplicant *wpa_s, const u8 *dst, const u8 *data, size_t data_len, enum p2p_send_action_result result); diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index e35f04152..42c81cd7e 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -2077,15 +2077,19 @@ static int wpa_cli_cmd_p2p_prov_disc(struct wpa_ctrl *ctrl, int argc, char cmd[128]; int res; - if (argc != 2) { - printf("Invalid P2P_PROV_DISC command: needs two arguments " - "(address and config method\n" - "(display, keypad, or pbc)\n"); + if (argc != 2 && argc != 3) { + printf("Invalid P2P_PROV_DISC command: needs at least " + "two arguments, address and config method\n" + "(display, keypad, or pbc) and an optional join\n"); return -1; } - res = os_snprintf(cmd, sizeof(cmd), "P2P_PROV_DISC %s %s", - argv[0], argv[1]); + if (argc == 3) + res = os_snprintf(cmd, sizeof(cmd), "P2P_PROV_DISC %s %s %s", + argv[0], argv[1], argv[2]); + else + res = os_snprintf(cmd, sizeof(cmd), "P2P_PROV_DISC %s %s", + argv[0], argv[1]); if (res < 0 || (size_t) res >= sizeof(cmd)) return -1; cmd[sizeof(cmd) - 1] = '\0';