P2P: Move group removal reason to a function parameter

wpa_s->removal_reason was set only when calling wpas_p2p_group_delete()
and while couple of call places did not set this, it should really be
set in each case. As such, it works better as a function parameter than
a variable in struct wpa_supplicant.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2012-08-11 12:41:31 +03:00
parent 30ee769235
commit 8dba4aef11
2 changed files with 28 additions and 28 deletions

View File

@ -57,6 +57,16 @@
#define P2P_MAX_INITIAL_CONN_WAIT 10
#endif /* P2P_MAX_INITIAL_CONN_WAIT */
enum p2p_group_removal_reason {
P2P_GROUP_REMOVAL_UNKNOWN,
P2P_GROUP_REMOVAL_SILENT,
P2P_GROUP_REMOVAL_FORMATION_FAILED,
P2P_GROUP_REMOVAL_REQUESTED,
P2P_GROUP_REMOVAL_IDLE_TIMEOUT,
P2P_GROUP_REMOVAL_UNAVAILABLE,
P2P_GROUP_REMOVAL_GO_ENDING_SESSION
};
static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx);
static struct wpa_supplicant *
@ -214,7 +224,8 @@ static struct wpa_supplicant * wpas_get_p2p_group(struct wpa_supplicant *wpa_s,
}
static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s, int silent)
static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s,
enum p2p_group_removal_reason removal_reason)
{
struct wpa_ssid *ssid;
char *gtype;
@ -235,11 +246,6 @@ static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s, int silent)
ssid = ssid->next;
}
if (ssid == NULL) {
/*
* Reset wpa_s->removal_reason to the default unknown
* state.
*/
wpa_s->removal_reason = P2P_GROUP_REMOVAL_UNKNOWN;
wpa_printf(MSG_ERROR, "P2P: P2P group interface "
"not found");
return -1;
@ -262,10 +268,13 @@ static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s, int silent)
P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
wpa_s->ifname, wpa_s->cross_connect_uplink);
}
switch (wpa_s->removal_reason) {
switch (removal_reason) {
case P2P_GROUP_REMOVAL_REQUESTED:
reason = " reason=REQUESTED";
break;
case P2P_GROUP_REMOVAL_FORMATION_FAILED:
reason = " reason=FORMATION_FAILED";
break;
case P2P_GROUP_REMOVAL_IDLE_TIMEOUT:
reason = " reason=IDLE";
break;
@ -279,7 +288,7 @@ static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s, int silent)
reason = "";
break;
}
if (!silent) {
if (removal_reason != P2P_GROUP_REMOVAL_SILENT) {
wpa_msg(wpa_s->parent, MSG_INFO,
P2P_EVENT_GROUP_REMOVED "%s %s%s",
wpa_s->ifname, gtype, reason);
@ -288,7 +297,7 @@ static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s, int silent)
if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0)
wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout");
if (!silent && ssid)
if (removal_reason != P2P_GROUP_REMOVAL_SILENT && ssid)
wpas_notify_p2p_group_removed(wpa_s, ssid, gtype);
if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
@ -560,7 +569,8 @@ static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s,
if (!success) {
wpa_msg(wpa_s->parent, MSG_INFO,
P2P_EVENT_GROUP_FORMATION_FAILURE);
wpas_p2p_group_delete(wpa_s, 0);
wpas_p2p_group_delete(wpa_s,
P2P_GROUP_REMOVAL_FORMATION_FAILED);
return;
}
@ -4290,8 +4300,7 @@ static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx)
wpa_printf(MSG_DEBUG, "P2P: Group idle timeout reached - terminate "
"group");
wpa_s->removal_reason = P2P_GROUP_REMOVAL_IDLE_TIMEOUT;
wpas_p2p_group_delete(wpa_s, 0);
wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_IDLE_TIMEOUT);
}
@ -4370,8 +4379,8 @@ void wpas_p2p_deauth_notif(struct wpa_supplicant *wpa_s, const u8 *bssid,
wpa_s->current_ssid->mode == WPAS_MODE_INFRA) {
wpa_printf(MSG_DEBUG, "P2P: GO indicated that the P2P Group "
"session is ending");
wpa_s->removal_reason = P2P_GROUP_REMOVAL_GO_ENDING_SESSION;
wpas_p2p_group_delete(wpa_s, 0);
wpas_p2p_group_delete(wpa_s,
P2P_GROUP_REMOVAL_GO_ENDING_SESSION);
}
}
@ -4739,7 +4748,8 @@ int wpas_p2p_cancel(struct wpa_supplicant *wpa_s)
found = 1;
eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
wpa_s->parent, NULL);
wpas_p2p_group_delete(wpa_s, 0);
wpas_p2p_group_delete(wpa_s,
P2P_GROUP_REMOVAL_REQUESTED);
break;
}
}
@ -4760,8 +4770,7 @@ void wpas_p2p_interface_unavailable(struct wpa_supplicant *wpa_s)
wpa_printf(MSG_DEBUG, "P2P: Remove group due to driver resource not "
"being available anymore");
wpa_s->removal_reason = P2P_GROUP_REMOVAL_UNAVAILABLE;
wpas_p2p_group_delete(wpa_s, 0);
wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_UNAVAILABLE);
}
@ -4807,8 +4816,7 @@ int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s)
if (wpa_s == NULL)
return -1;
wpa_s->removal_reason = P2P_GROUP_REMOVAL_REQUESTED;
return wpas_p2p_group_delete(wpa_s, 0);
return wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_REQUESTED);
}
@ -4892,7 +4900,7 @@ static void wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s,
wpa_s = wpa_s->parent;
offchannel_send_action_done(wpa_s);
if (group_added)
wpas_p2p_group_delete(group, 1);
wpas_p2p_group_delete(group, P2P_GROUP_REMOVAL_SILENT);
wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Fall back to GO Negotiation");
wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, wpa_s->p2p_pin,
wpa_s->p2p_wps_method, wpa_s->p2p_persistent_group, 0,

View File

@ -514,14 +514,6 @@ struct wpa_supplicant {
*/
char cross_connect_uplink[100];
enum {
P2P_GROUP_REMOVAL_UNKNOWN,
P2P_GROUP_REMOVAL_REQUESTED,
P2P_GROUP_REMOVAL_IDLE_TIMEOUT,
P2P_GROUP_REMOVAL_UNAVAILABLE,
P2P_GROUP_REMOVAL_GO_ENDING_SESSION
} removal_reason;
unsigned int p2p_cb_on_scan_complete:1;
unsigned int p2p_auto_join:1;
unsigned int p2p_auto_pd:1;