ctrl_iface: Make p2p_ctrl_group_add() more robust

Parse each parameter individually and combine all the function calls.
This will allow further patch to call it with no parameters (currently
this might result in failure).

Signed-off-by: Eliad Peller <eliadx.peller@intel.com>
This commit is contained in:
Eliad Peller 2015-06-17 16:18:15 +03:00 committed by Jouni Malinen
parent e4a80d89bd
commit 29292d53ee

View file

@ -5505,13 +5505,10 @@ static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s, static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
char *cmd, int freq, int ht40, int id, int freq, int ht40, int vht)
int vht)
{ {
int id;
struct wpa_ssid *ssid; struct wpa_ssid *ssid;
id = atoi(cmd);
ssid = wpa_config_get_network(wpa_s->conf, id); ssid = wpa_config_get_network(wpa_s->conf, id);
if (ssid == NULL || ssid->disabled != 2) { if (ssid == NULL || ssid->disabled != 2) {
wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
@ -5527,31 +5524,35 @@ static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd) static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
{ {
int freq = 0, persistent_group = 0, ht40, vht; int freq = 0, persistent = 0, group_id = -1;
char *pos; int vht = wpa_s->conf->p2p_go_vht;
int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
char *token, *context = NULL;
pos = os_strstr(cmd, "freq="); while ((token = str_token(cmd, " ", &context))) {
if (pos) if (sscanf(token, "freq=%d", &freq) == 1 ||
freq = atoi(pos + 5); sscanf(token, "persistent=%d", &group_id) == 1) {
continue;
vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht; } else if (os_strcmp(token, "ht40") == 0) {
ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || ht40 = 1;
vht; } else if (os_strcmp(token, "vht") == 0) {
vht = 1;
if (os_strncmp(cmd, "persistent=", 11) == 0) ht40 = 1;
return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq, } else if (os_strcmp(token, "persistent") == 0) {
ht40, vht); persistent = 1;
if (os_strcmp(cmd, "persistent") == 0 || } else {
os_strncmp(cmd, "persistent ", 11) == 0) wpa_printf(MSG_DEBUG,
persistent_group = 1; "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
token);
if (!persistent_group && !freq && !ht40) { return -1;
wpa_printf(MSG_DEBUG, }
"CTRL: Invalid P2P_GROUP_ADD parameters '%s'", cmd);
return -1;
} }
return wpas_p2p_group_add(wpa_s, persistent_group, freq, ht40, vht); if (group_id >= 0)
return p2p_ctrl_group_add_persistent(wpa_s, group_id,
freq, ht40, vht);
return wpas_p2p_group_add(wpa_s, persistent, freq, ht40, vht);
} }