P2P: Simplify code in wpas_p2p_connect()

There's some duplicated code there that can be simplified
with just a single new variable.

Signed-hostap: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2011-11-18 23:32:03 +02:00 committed by Jouni Malinen
parent 98ac6763ff
commit 6cad95db72

View file

@ -2670,6 +2670,7 @@ int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
u8 bssid[ETH_ALEN]; u8 bssid[ETH_ALEN];
int ret = 0; int ret = 0;
enum wpa_driver_if_type iftype; enum wpa_driver_if_type iftype;
const u8 *if_addr;
if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
return -1; return -1;
@ -2765,44 +2766,34 @@ int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s);
if (!wpa_s->create_p2p_iface) { if (wpa_s->create_p2p_iface) {
if (auth) { /* Prepare to add a new interface for the group */
if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method, iftype = WPA_IF_P2P_GROUP;
go_intent, wpa_s->own_addr, if (go_intent == 15)
force_freq, persistent_group) iftype = WPA_IF_P2P_GO;
< 0) if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) {
return -1; wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
return ret; "interface for the group");
}
if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method,
go_intent, wpa_s->own_addr,
force_freq, persistent_group) < 0)
return -1; return -1;
return ret; }
}
/* Prepare to add a new interface for the group */ if_addr = wpa_s->pending_interface_addr;
iftype = WPA_IF_P2P_GROUP; } else
if (go_intent == 15) if_addr = wpa_s->own_addr;
iftype = WPA_IF_P2P_GO;
if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) {
wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
"interface for the group");
return -1;
}
if (auth) { if (auth) {
if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method, if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method,
go_intent, go_intent, if_addr,
wpa_s->pending_interface_addr,
force_freq, persistent_group) < 0) force_freq, persistent_group) < 0)
return -1; return -1;
return ret; return ret;
} }
if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method, go_intent,
wpa_s->pending_interface_addr, if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method,
force_freq, persistent_group) < 0) { go_intent, if_addr, force_freq,
wpas_p2p_remove_pending_group_interface(wpa_s); persistent_group) < 0) {
if (wpa_s->create_p2p_iface)
wpas_p2p_remove_pending_group_interface(wpa_s);
return -1; return -1;
} }
return ret; return ret;