P2P: Set FORCE_FREQ flag as part of p2p_prepare_channel()

Both p2p_connect and p2p_authorize use the same functionality to select
the channel preferences for GO Negotiation. The part of setting this
device flag was copied to each function, but it can also be handled by
the shared function after some reordering of code.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2012-12-27 07:58:04 +02:00
parent b1129f657c
commit 92ac756c84

View file

@ -1117,8 +1117,8 @@ void p2p_stop_find(struct p2p_data *p2p)
}
static int p2p_prepare_channel(struct p2p_data *p2p, unsigned int force_freq,
unsigned int pref_freq)
static int p2p_prepare_channel(struct p2p_data *p2p, struct p2p_device *dev,
unsigned int force_freq, unsigned int pref_freq)
{
if (force_freq || pref_freq) {
u8 op_reg_class, op_channel;
@ -1200,6 +1200,11 @@ static int p2p_prepare_channel(struct p2p_data *p2p, unsigned int force_freq,
p2p->op_reg_class, p2p->op_channel,
force_freq ? " (forced)" : "");
if (force_freq)
dev->flags |= P2P_DEV_FORCE_FREQ;
else
dev->flags &= ~P2P_DEV_FORCE_FREQ;
return 0;
}
@ -1240,9 +1245,6 @@ int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr,
MAC2STR(peer_addr), go_intent, MAC2STR(own_interface_addr),
wps_method, persistent_group, pd_before_go_neg);
if (p2p_prepare_channel(p2p, force_freq, pref_freq) < 0)
return -1;
dev = p2p_get_device(p2p, peer_addr);
if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) {
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
@ -1251,6 +1253,9 @@ int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr,
return -1;
}
if (p2p_prepare_channel(p2p, dev, force_freq, pref_freq) < 0)
return -1;
if (dev->flags & P2P_DEV_GROUP_CLIENT_ONLY) {
if (!(dev->info.dev_capab &
P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY)) {
@ -1318,11 +1323,6 @@ int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr,
dev->wps_method = wps_method;
dev->status = P2P_SC_SUCCESS;
if (force_freq)
dev->flags |= P2P_DEV_FORCE_FREQ;
else
dev->flags &= ~P2P_DEV_FORCE_FREQ;
if (p2p->p2p_scan_running) {
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
"P2P: p2p_scan running - delay connect send");
@ -1352,9 +1352,6 @@ int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr,
MAC2STR(peer_addr), go_intent, MAC2STR(own_interface_addr),
wps_method, persistent_group);
if (p2p_prepare_channel(p2p, force_freq, pref_freq) < 0)
return -1;
dev = p2p_get_device(p2p, peer_addr);
if (dev == NULL) {
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
@ -1363,6 +1360,9 @@ int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr,
return -1;
}
if (p2p_prepare_channel(p2p, dev, force_freq, pref_freq) < 0)
return -1;
p2p->ssid_set = 0;
if (force_ssid) {
wpa_hexdump_ascii(MSG_DEBUG, "P2P: Forced SSID",
@ -1383,11 +1383,6 @@ int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr,
dev->wps_method = wps_method;
dev->status = P2P_SC_SUCCESS;
if (force_freq)
dev->flags |= P2P_DEV_FORCE_FREQ;
else
dev->flags &= ~P2P_DEV_FORCE_FREQ;
return 0;
}