P2P: Clean up channel--frequency conversion functions
All P2P use cases are required to use the global operating table and there is no need to need to try to maintain some backwards compatibility with country code -specific values. Clean up the implementation by removing the unnecessary country parameter. Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
e864c0aefe
commit
9ccd916504
7 changed files with 50 additions and 108 deletions
|
@ -226,8 +226,7 @@ static void p2p_listen_in_find(struct p2p_data *p2p, int dev_disc)
|
|||
"P2P: Starting short listen state (state=%s)",
|
||||
p2p_state_txt(p2p->state));
|
||||
|
||||
freq = p2p_channel_to_freq(p2p->cfg->country, p2p->cfg->reg_class,
|
||||
p2p->cfg->channel);
|
||||
freq = p2p_channel_to_freq(p2p->cfg->reg_class, p2p->cfg->channel);
|
||||
if (freq < 0) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
|
||||
"P2P: Unknown regulatory class/channel");
|
||||
|
@ -277,8 +276,7 @@ int p2p_listen(struct p2p_data *p2p, unsigned int timeout)
|
|||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
|
||||
"P2P: Going to listen(only) state");
|
||||
|
||||
freq = p2p_channel_to_freq(p2p->cfg->country, p2p->cfg->reg_class,
|
||||
p2p->cfg->channel);
|
||||
freq = p2p_channel_to_freq(p2p->cfg->reg_class, p2p->cfg->channel);
|
||||
if (freq < 0) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
|
||||
"P2P: Unknown regulatory class/channel");
|
||||
|
@ -867,7 +865,7 @@ static int p2p_get_next_prog_freq(struct p2p_data *p2p)
|
|||
channel = c->reg_class[cl].channel[ch];
|
||||
}
|
||||
|
||||
freq = p2p_channel_to_freq(p2p->cfg->country, reg_class, channel);
|
||||
freq = p2p_channel_to_freq(reg_class, channel);
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Next progressive search "
|
||||
"channel: reg_class %u channel %u -> %d MHz",
|
||||
reg_class, channel, freq);
|
||||
|
@ -1176,8 +1174,7 @@ static int p2p_prepare_channel_pref(struct p2p_data *p2p,
|
|||
u8 op_class, op_channel;
|
||||
unsigned int freq = force_freq ? force_freq : pref_freq;
|
||||
|
||||
if (p2p_freq_to_channel(p2p->cfg->country, freq,
|
||||
&op_class, &op_channel) < 0) {
|
||||
if (p2p_freq_to_channel(freq, &op_class, &op_channel) < 0) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
|
||||
"P2P: Unsupported frequency %u MHz", freq);
|
||||
return -1;
|
||||
|
@ -1213,24 +1210,24 @@ static void p2p_prepare_channel_best(struct p2p_data *p2p)
|
|||
|
||||
if (!p2p->cfg->cfg_op_channel && p2p->best_freq_overall > 0 &&
|
||||
p2p_supported_freq(p2p, p2p->best_freq_overall) &&
|
||||
p2p_freq_to_channel(p2p->cfg->country, p2p->best_freq_overall,
|
||||
&op_class, &op_channel) == 0) {
|
||||
p2p_freq_to_channel(p2p->best_freq_overall, &op_class, &op_channel)
|
||||
== 0) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Select best "
|
||||
"overall channel as operating channel preference");
|
||||
p2p->op_reg_class = op_class;
|
||||
p2p->op_channel = op_channel;
|
||||
} else if (!p2p->cfg->cfg_op_channel && p2p->best_freq_5 > 0 &&
|
||||
p2p_supported_freq(p2p, p2p->best_freq_5) &&
|
||||
p2p_freq_to_channel(p2p->cfg->country, p2p->best_freq_5,
|
||||
&op_class, &op_channel) == 0) {
|
||||
p2p_freq_to_channel(p2p->best_freq_5, &op_class, &op_channel)
|
||||
== 0) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Select best 5 GHz "
|
||||
"channel as operating channel preference");
|
||||
p2p->op_reg_class = op_class;
|
||||
p2p->op_channel = op_channel;
|
||||
} else if (!p2p->cfg->cfg_op_channel && p2p->best_freq_24 > 0 &&
|
||||
p2p_supported_freq(p2p, p2p->best_freq_24) &&
|
||||
p2p_freq_to_channel(p2p->cfg->country, p2p->best_freq_24,
|
||||
&op_class, &op_channel) == 0) {
|
||||
p2p_freq_to_channel(p2p->best_freq_24, &op_class,
|
||||
&op_channel) == 0) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Select best 2.4 "
|
||||
"GHz channel as operating channel preference");
|
||||
p2p->op_reg_class = op_class;
|
||||
|
@ -1479,8 +1476,7 @@ void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr,
|
|||
|
||||
if (msg->listen_channel) {
|
||||
int freq;
|
||||
freq = p2p_channel_to_freq((char *) msg->listen_channel,
|
||||
msg->listen_channel[3],
|
||||
freq = p2p_channel_to_freq(msg->listen_channel[3],
|
||||
msg->listen_channel[4]);
|
||||
if (freq < 0) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
|
||||
|
@ -1579,8 +1575,7 @@ void p2p_go_complete(struct p2p_data *p2p, struct p2p_device *peer)
|
|||
|
||||
if (go) {
|
||||
/* Setup AP mode for WPS provisioning */
|
||||
res.freq = p2p_channel_to_freq(p2p->cfg->country,
|
||||
p2p->op_reg_class,
|
||||
res.freq = p2p_channel_to_freq(p2p->op_reg_class,
|
||||
p2p->op_channel);
|
||||
os_memcpy(res.ssid, p2p->ssid, p2p->ssid_len);
|
||||
res.ssid_len = p2p->ssid_len;
|
||||
|
@ -1604,8 +1599,7 @@ void p2p_go_complete(struct p2p_data *p2p, struct p2p_device *peer)
|
|||
int freq;
|
||||
if (freqs + 1 == P2P_MAX_CHANNELS)
|
||||
break;
|
||||
freq = p2p_channel_to_freq(peer->country, c->reg_class,
|
||||
c->channel[j]);
|
||||
freq = p2p_channel_to_freq(c->reg_class, c->channel[j]);
|
||||
if (freq < 0)
|
||||
continue;
|
||||
res.freq_list[freqs++] = freq;
|
||||
|
@ -1835,8 +1829,7 @@ static void p2p_add_dev_from_probe_req(struct p2p_data *p2p, const u8 *addr,
|
|||
|
||||
if (msg.listen_channel) {
|
||||
os_memcpy(dev->country, msg.listen_channel, 3);
|
||||
dev->listen_freq = p2p_channel_to_freq(dev->country,
|
||||
msg.listen_channel[3],
|
||||
dev->listen_freq = p2p_channel_to_freq(msg.listen_channel[3],
|
||||
msg.listen_channel[4]);
|
||||
}
|
||||
|
||||
|
@ -4045,7 +4038,7 @@ void p2p_set_managed_oper(struct p2p_data *p2p, int enabled)
|
|||
|
||||
int p2p_set_listen_channel(struct p2p_data *p2p, u8 reg_class, u8 channel)
|
||||
{
|
||||
if (p2p_channel_to_freq(p2p->cfg->country, reg_class, channel) < 0)
|
||||
if (p2p_channel_to_freq(reg_class, channel) < 0)
|
||||
return -1;
|
||||
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Set Listen channel: "
|
||||
|
@ -4075,8 +4068,7 @@ int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len)
|
|||
int p2p_set_oper_channel(struct p2p_data *p2p, u8 op_reg_class, u8 op_channel,
|
||||
int cfg_op_channel)
|
||||
{
|
||||
if (p2p_channel_to_freq(p2p->cfg->country, op_reg_class, op_channel)
|
||||
< 0)
|
||||
if (p2p_channel_to_freq(op_reg_class, op_channel) < 0)
|
||||
return -1;
|
||||
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_INFO, "P2P: Set Operating channel: "
|
||||
|
|
|
@ -351,7 +351,7 @@ void p2p_reselect_channel(struct p2p_data *p2p,
|
|||
unsigned int i;
|
||||
|
||||
if (p2p->own_freq_preference > 0 &&
|
||||
p2p_freq_to_channel(p2p->cfg->country, p2p->own_freq_preference,
|
||||
p2p_freq_to_channel(p2p->own_freq_preference,
|
||||
&op_reg_class, &op_channel) == 0 &&
|
||||
p2p_channels_includes(intersection, op_reg_class, op_channel)) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick own channel "
|
||||
|
@ -363,7 +363,7 @@ void p2p_reselect_channel(struct p2p_data *p2p,
|
|||
}
|
||||
|
||||
if (p2p->best_freq_overall > 0 &&
|
||||
p2p_freq_to_channel(p2p->cfg->country, p2p->best_freq_overall,
|
||||
p2p_freq_to_channel(p2p->best_freq_overall,
|
||||
&op_reg_class, &op_channel) == 0 &&
|
||||
p2p_channels_includes(intersection, op_reg_class, op_channel)) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick best overall "
|
||||
|
@ -375,12 +375,11 @@ void p2p_reselect_channel(struct p2p_data *p2p,
|
|||
}
|
||||
|
||||
/* First, try to pick the best channel from another band */
|
||||
freq = p2p_channel_to_freq(p2p->cfg->country, p2p->op_reg_class,
|
||||
p2p->op_channel);
|
||||
freq = p2p_channel_to_freq(p2p->op_reg_class, p2p->op_channel);
|
||||
if (freq >= 2400 && freq < 2500 && p2p->best_freq_5 > 0 &&
|
||||
!p2p_channels_includes(intersection, p2p->op_reg_class,
|
||||
p2p->op_channel) &&
|
||||
p2p_freq_to_channel(p2p->cfg->country, p2p->best_freq_5,
|
||||
p2p_freq_to_channel(p2p->best_freq_5,
|
||||
&op_reg_class, &op_channel) == 0 &&
|
||||
p2p_channels_includes(intersection, op_reg_class, op_channel)) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick best 5 GHz "
|
||||
|
@ -394,7 +393,7 @@ void p2p_reselect_channel(struct p2p_data *p2p,
|
|||
if (freq >= 4900 && freq < 6000 && p2p->best_freq_24 > 0 &&
|
||||
!p2p_channels_includes(intersection, p2p->op_reg_class,
|
||||
p2p->op_channel) &&
|
||||
p2p_freq_to_channel(p2p->cfg->country, p2p->best_freq_24,
|
||||
p2p_freq_to_channel(p2p->best_freq_24,
|
||||
&op_reg_class, &op_channel) == 0 &&
|
||||
p2p_channels_includes(intersection, op_reg_class, op_channel)) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick best 2.4 GHz "
|
||||
|
@ -734,9 +733,7 @@ void p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
|
|||
goto fail;
|
||||
|
||||
dev->go_state = go ? LOCAL_GO : REMOTE_GO;
|
||||
dev->oper_freq = p2p_channel_to_freq((const char *)
|
||||
msg.operating_channel,
|
||||
msg.operating_channel[3],
|
||||
dev->oper_freq = p2p_channel_to_freq(msg.operating_channel[3],
|
||||
msg.operating_channel[4]);
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer operating "
|
||||
"channel preference: %d MHz", dev->oper_freq);
|
||||
|
@ -771,8 +768,7 @@ fail:
|
|||
if (rx_freq > 0)
|
||||
freq = rx_freq;
|
||||
else
|
||||
freq = p2p_channel_to_freq(p2p->cfg->country,
|
||||
p2p->cfg->reg_class,
|
||||
freq = p2p_channel_to_freq(p2p->cfg->reg_class,
|
||||
p2p->cfg->channel);
|
||||
if (freq < 0) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
|
||||
|
@ -1048,9 +1044,7 @@ void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
|
|||
}
|
||||
|
||||
if (msg.operating_channel) {
|
||||
dev->oper_freq = p2p_channel_to_freq((const char *)
|
||||
msg.operating_channel,
|
||||
msg.operating_channel[3],
|
||||
dev->oper_freq = p2p_channel_to_freq(msg.operating_channel[3],
|
||||
msg.operating_channel[4]);
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer operating "
|
||||
"channel preference: %d MHz", dev->oper_freq);
|
||||
|
|
|
@ -557,9 +557,8 @@ struct p2p_group_info {
|
|||
|
||||
/* p2p_utils.c */
|
||||
int p2p_random(char *buf, size_t len);
|
||||
int p2p_channel_to_freq(const char *country, int reg_class, int channel);
|
||||
int p2p_freq_to_channel(const char *country, unsigned int freq, u8 *reg_class,
|
||||
u8 *channel);
|
||||
int p2p_channel_to_freq(int op_class, int channel);
|
||||
int p2p_freq_to_channel(unsigned int freq, u8 *op_class, u8 *channel);
|
||||
void p2p_channels_intersect(const struct p2p_channels *a,
|
||||
const struct p2p_channels *b,
|
||||
struct p2p_channels *res);
|
||||
|
|
|
@ -238,8 +238,7 @@ void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
|
|||
if (op_freq) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Invitation "
|
||||
"processing forced frequency %d MHz", op_freq);
|
||||
if (p2p_freq_to_channel(p2p->cfg->country, op_freq,
|
||||
®_class, &channel) < 0) {
|
||||
if (p2p_freq_to_channel(op_freq, ®_class, &channel) < 0) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
|
||||
"P2P: Unknown forced freq %d MHz from "
|
||||
"invitation_process()", op_freq);
|
||||
|
@ -278,7 +277,6 @@ void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
|
|||
if (msg.operating_channel) {
|
||||
int req_freq;
|
||||
req_freq = p2p_channel_to_freq(
|
||||
(const char *) msg.operating_channel,
|
||||
msg.operating_channel[3],
|
||||
msg.operating_channel[4]);
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer "
|
||||
|
@ -326,8 +324,7 @@ void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
|
|||
}
|
||||
}
|
||||
|
||||
op_freq = p2p_channel_to_freq(p2p->cfg->country,
|
||||
p2p->op_reg_class,
|
||||
op_freq = p2p_channel_to_freq(p2p->op_reg_class,
|
||||
p2p->op_channel);
|
||||
if (op_freq < 0) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
|
||||
|
@ -362,8 +359,7 @@ fail:
|
|||
if (rx_freq > 0)
|
||||
freq = rx_freq;
|
||||
else
|
||||
freq = p2p_channel_to_freq(p2p->cfg->country,
|
||||
p2p->cfg->reg_class,
|
||||
freq = p2p_channel_to_freq(p2p->cfg->reg_class,
|
||||
p2p->cfg->channel);
|
||||
if (freq < 0) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
|
||||
|
|
|
@ -217,8 +217,7 @@ out:
|
|||
if (rx_freq > 0)
|
||||
freq = rx_freq;
|
||||
else
|
||||
freq = p2p_channel_to_freq(p2p->cfg->country,
|
||||
p2p->cfg->reg_class,
|
||||
freq = p2p_channel_to_freq(p2p->cfg->reg_class,
|
||||
p2p->cfg->channel);
|
||||
if (freq < 0) {
|
||||
wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
|
||||
|
|
|
@ -290,8 +290,7 @@ void p2p_rx_gas_initial_req(struct p2p_data *p2p, const u8 *sa,
|
|||
if (rx_freq > 0)
|
||||
freq = rx_freq;
|
||||
else
|
||||
freq = p2p_channel_to_freq(p2p->cfg->country,
|
||||
p2p->cfg->reg_class,
|
||||
freq = p2p_channel_to_freq(p2p->cfg->reg_class,
|
||||
p2p->cfg->channel);
|
||||
if (freq < 0)
|
||||
return;
|
||||
|
|
|
@ -46,11 +46,17 @@ int p2p_random(char *buf, size_t len)
|
|||
}
|
||||
|
||||
|
||||
static int p2p_channel_to_freq_j4(int reg_class, int channel)
|
||||
/**
|
||||
* p2p_channel_to_freq - Convert channel info to frequency
|
||||
* @op_class: Operating class
|
||||
* @channel: Channel number
|
||||
* Returns: Frequency in MHz or -1 if the specified channel is unknown
|
||||
*/
|
||||
int p2p_channel_to_freq(int op_class, int channel)
|
||||
{
|
||||
/* Table J-4 in P802.11REVmb/D4.0 - Global operating classes */
|
||||
/* TODO: more regulatory classes */
|
||||
switch (reg_class) {
|
||||
/* Table E-4 in IEEE Std 802.11-2012 - Global operating classes */
|
||||
/* TODO: more operating classes */
|
||||
switch (op_class) {
|
||||
case 81:
|
||||
/* channels 1..13 */
|
||||
if (channel < 1 || channel > 13)
|
||||
|
@ -93,76 +99,35 @@ static int p2p_channel_to_freq_j4(int reg_class, int channel)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* p2p_channel_to_freq - Convert channel info to frequency
|
||||
* @country: Country code
|
||||
* @reg_class: Regulatory class
|
||||
* @channel: Channel number
|
||||
* Returns: Frequency in MHz or -1 if the specified channel is unknown
|
||||
*/
|
||||
int p2p_channel_to_freq(const char *country, int reg_class, int channel)
|
||||
{
|
||||
if (country[2] == 0x04)
|
||||
return p2p_channel_to_freq_j4(reg_class, channel);
|
||||
|
||||
/* These are mainly for backwards compatibility; to be removed */
|
||||
switch (reg_class) {
|
||||
case 1: /* US/1, EU/1, JP/1 = 5 GHz, channels 36,40,44,48 */
|
||||
if (channel < 36 || channel > 48)
|
||||
return -1;
|
||||
return 5000 + 5 * channel;
|
||||
case 3: /* US/3 = 5 GHz, channels 149,153,157,161 */
|
||||
case 5: /* US/5 = 5 GHz, channels 149,153,157,161 */
|
||||
if (channel < 149 || channel > 161)
|
||||
return -1;
|
||||
return 5000 + 5 * channel;
|
||||
case 4: /* EU/4 = 2.407 GHz, channels 1..13 */
|
||||
case 12: /* US/12 = 2.407 GHz, channels 1..11 */
|
||||
case 30: /* JP/30 = 2.407 GHz, channels 1..13 */
|
||||
if (channel < 1 || channel > 13)
|
||||
return -1;
|
||||
return 2407 + 5 * channel;
|
||||
case 31: /* JP/31 = 2.414 GHz, channel 14 */
|
||||
if (channel != 14)
|
||||
return -1;
|
||||
return 2414 + 5 * channel;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* p2p_freq_to_channel - Convert frequency into channel info
|
||||
* @country: Country code
|
||||
* @reg_class: Buffer for returning regulatory class
|
||||
* @op_class: Buffer for returning operating class
|
||||
* @channel: Buffer for returning channel number
|
||||
* Returns: 0 on success, -1 if the specified frequency is unknown
|
||||
*/
|
||||
int p2p_freq_to_channel(const char *country, unsigned int freq, u8 *reg_class,
|
||||
u8 *channel)
|
||||
int p2p_freq_to_channel(unsigned int freq, u8 *op_class, u8 *channel)
|
||||
{
|
||||
/* TODO: more operating classes */
|
||||
if (freq >= 2412 && freq <= 2472) {
|
||||
*reg_class = 81; /* 2.407 GHz, channels 1..13 */
|
||||
*op_class = 81; /* 2.407 GHz, channels 1..13 */
|
||||
*channel = (freq - 2407) / 5;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (freq == 2484) {
|
||||
*reg_class = 82; /* channel 14 */
|
||||
*op_class = 82; /* channel 14 */
|
||||
*channel = 14;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (freq >= 5180 && freq <= 5240) {
|
||||
*reg_class = 115; /* 5 GHz, channels 36..48 */
|
||||
*op_class = 115; /* 5 GHz, channels 36..48 */
|
||||
*channel = (freq - 5000) / 5;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (freq >= 5745 && freq <= 5805) {
|
||||
*reg_class = 124; /* 5 GHz, channels 149..161 */
|
||||
*op_class = 124; /* 5 GHz, channels 149..161 */
|
||||
*channel = (freq - 5000) / 5;
|
||||
return 0;
|
||||
}
|
||||
|
@ -261,9 +226,8 @@ int p2p_channels_includes_freq(const struct p2p_channels *channels,
|
|||
for (i = 0; i < channels->reg_classes; i++) {
|
||||
const struct p2p_reg_class *reg = &channels->reg_class[i];
|
||||
for (j = 0; j < reg->channels; j++) {
|
||||
if (p2p_channel_to_freq_j4(reg->reg_class,
|
||||
reg->channel[j]) ==
|
||||
(int) freq)
|
||||
if (p2p_channel_to_freq(reg->reg_class,
|
||||
reg->channel[j]) == (int) freq)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -274,8 +238,7 @@ int p2p_channels_includes_freq(const struct p2p_channels *channels,
|
|||
int p2p_supported_freq(struct p2p_data *p2p, unsigned int freq)
|
||||
{
|
||||
u8 op_reg_class, op_channel;
|
||||
if (p2p_freq_to_channel(p2p->cfg->country, freq,
|
||||
&op_reg_class, &op_channel) < 0)
|
||||
if (p2p_freq_to_channel(freq, &op_reg_class, &op_channel) < 0)
|
||||
return 0;
|
||||
return p2p_channels_includes(&p2p->cfg->channels, op_reg_class,
|
||||
op_channel);
|
||||
|
|
Loading…
Reference in a new issue