Add generic operating class and channel to frequency function
ieee80211_chan_to_freq() is a generic function that replaces and extends the previous P2P-specific p2p_channel_to_freq(). The new function supports both the global operating class table as well as the additional US, EU, JP, and CN operating class tables. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
73360424d9
commit
533630625d
3 changed files with 283 additions and 50 deletions
|
@ -537,6 +537,286 @@ enum hostapd_hw_mode ieee80211_freq_to_chan(int freq, u8 *channel)
|
|||
}
|
||||
|
||||
|
||||
static const char *us_op_class_cc[] = {
|
||||
"US", "CA", NULL
|
||||
};
|
||||
|
||||
static const char *eu_op_class_cc[] = {
|
||||
"AL", "AM", "AT", "AZ", "BA", "BE", "BG", "BY", "CH", "CY", "CZ", "DE",
|
||||
"DK", "EE", "EL", "ES", "FI", "FR", "GE", "HR", "HU", "IE", "IS", "IT",
|
||||
"LI", "LT", "LU", "LV", "MD", "ME", "MK", "MT", "NL", "NO", "PL", "PT",
|
||||
"RO", "RS", "RU", "SE", "SI", "SK", "TR", "UA", "UK", NULL
|
||||
};
|
||||
|
||||
static const char *jp_op_class_cc[] = {
|
||||
"JP", NULL
|
||||
};
|
||||
|
||||
static const char *cn_op_class_cc[] = {
|
||||
"CN", "CA", NULL
|
||||
};
|
||||
|
||||
|
||||
static int country_match(const char *cc[], const char *country)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (country == NULL)
|
||||
return 0;
|
||||
for (i = 0; cc[i]; i++) {
|
||||
if (cc[i][0] == country[0] && cc[i][1] == country[1])
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int ieee80211_chan_to_freq_us(u8 op_class, u8 chan)
|
||||
{
|
||||
switch (op_class) {
|
||||
case 12: /* channels 1..11 */
|
||||
case 32: /* channels 1..7; 40 MHz */
|
||||
case 33: /* channels 5..11; 40 MHz */
|
||||
if (chan < 1 || chan > 11)
|
||||
return -1;
|
||||
return 2407 + 5 * chan;
|
||||
case 1: /* channels 36,40,44,48 */
|
||||
case 2: /* channels 52,56,60,64; dfs */
|
||||
case 22: /* channels 36,44; 40 MHz */
|
||||
case 23: /* channels 52,60; 40 MHz */
|
||||
case 27: /* channels 40,48; 40 MHz */
|
||||
case 28: /* channels 56,64; 40 MHz */
|
||||
if (chan < 36 || chan > 64)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 4: /* channels 100-144 */
|
||||
case 24: /* channels 100-140; 40 MHz */
|
||||
if (chan < 100 || chan > 144)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 3: /* channels 149,153,157,161 */
|
||||
case 25: /* channels 149,157; 40 MHz */
|
||||
case 26: /* channels 149,157; 40 MHz */
|
||||
case 30: /* channels 153,161; 40 MHz */
|
||||
case 31: /* channels 153,161; 40 MHz */
|
||||
if (chan < 149 || chan > 161)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 34: /* 60 GHz band, channels 1..3 */
|
||||
if (chan < 1 || chan > 3)
|
||||
return -1;
|
||||
return 56160 + 2160 * chan;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int ieee80211_chan_to_freq_eu(u8 op_class, u8 chan)
|
||||
{
|
||||
switch (op_class) {
|
||||
case 4: /* channels 1..13 */
|
||||
case 11: /* channels 1..9; 40 MHz */
|
||||
case 12: /* channels 5..13; 40 MHz */
|
||||
if (chan < 1 || chan > 13)
|
||||
return -1;
|
||||
return 2407 + 5 * chan;
|
||||
case 1: /* channels 36,40,44,48 */
|
||||
case 2: /* channels 52,56,60,64; dfs */
|
||||
case 5: /* channels 36,44; 40 MHz */
|
||||
case 6: /* channels 52,60; 40 MHz */
|
||||
case 8: /* channels 40,48; 40 MHz */
|
||||
case 9: /* channels 56,64; 40 MHz */
|
||||
if (chan < 36 || chan > 64)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 3: /* channels 100-140 */
|
||||
case 7: /* channels 100-132; 40 MHz */
|
||||
case 10: /* channels 104-136; 40 MHz */
|
||||
case 16: /* channels 100-140 */
|
||||
if (chan < 100 || chan > 140)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 17: /* channels 149,153,157,161,165,169 */
|
||||
if (chan < 149 || chan > 169)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 18: /* 60 GHz band, channels 1..4 */
|
||||
if (chan < 1 || chan > 4)
|
||||
return -1;
|
||||
return 56160 + 2160 * chan;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int ieee80211_chan_to_freq_jp(u8 op_class, u8 chan)
|
||||
{
|
||||
switch (op_class) {
|
||||
case 30: /* channels 1..13 */
|
||||
case 56: /* channels 1..9; 40 MHz */
|
||||
case 57: /* channels 5..13; 40 MHz */
|
||||
if (chan < 1 || chan > 13)
|
||||
return -1;
|
||||
return 2407 + 5 * chan;
|
||||
case 31: /* channel 14 */
|
||||
if (chan != 14)
|
||||
return -1;
|
||||
return 2414 + 5 * chan;
|
||||
case 1: /* channels 34,38,42,46(old) or 36,40,44,48 */
|
||||
case 32: /* channels 52,56,60,64 */
|
||||
case 33: /* channels 52,56,60,64 */
|
||||
case 36: /* channels 36,44; 40 MHz */
|
||||
case 37: /* channels 52,60; 40 MHz */
|
||||
case 38: /* channels 52,60; 40 MHz */
|
||||
case 41: /* channels 40,48; 40 MHz */
|
||||
case 42: /* channels 56,64; 40 MHz */
|
||||
case 43: /* channels 56,64; 40 MHz */
|
||||
if (chan < 34 || chan > 64)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 34: /* channels 100-140 */
|
||||
case 35: /* channels 100-140 */
|
||||
case 39: /* channels 100-132; 40 MHz */
|
||||
case 40: /* channels 100-132; 40 MHz */
|
||||
case 44: /* channels 104-136; 40 MHz */
|
||||
case 45: /* channels 104-136; 40 MHz */
|
||||
case 58: /* channels 100-140 */
|
||||
if (chan < 100 || chan > 140)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 59: /* 60 GHz band, channels 1..4 */
|
||||
if (chan < 1 || chan > 3)
|
||||
return -1;
|
||||
return 56160 + 2160 * chan;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int ieee80211_chan_to_freq_cn(u8 op_class, u8 chan)
|
||||
{
|
||||
switch (op_class) {
|
||||
case 7: /* channels 1..13 */
|
||||
case 8: /* channels 1..9; 40 MHz */
|
||||
case 9: /* channels 5..13; 40 MHz */
|
||||
if (chan < 1 || chan > 13)
|
||||
return -1;
|
||||
return 2407 + 5 * chan;
|
||||
case 1: /* channels 36,40,44,48 */
|
||||
case 2: /* channels 52,56,60,64; dfs */
|
||||
case 4: /* channels 36,44; 40 MHz */
|
||||
case 5: /* channels 52,60; 40 MHz */
|
||||
if (chan < 36 || chan > 64)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 3: /* channels 149,153,157,161,165 */
|
||||
case 6: /* channels 149,157; 40 MHz */
|
||||
if (chan < 149 || chan > 165)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int ieee80211_chan_to_freq_global(u8 op_class, u8 chan)
|
||||
{
|
||||
/* Table E-4 in IEEE Std 802.11-2012 - Global operating classes */
|
||||
switch (op_class) {
|
||||
case 81:
|
||||
/* channels 1..13 */
|
||||
if (chan < 1 || chan > 13)
|
||||
return -1;
|
||||
return 2407 + 5 * chan;
|
||||
case 82:
|
||||
/* channel 14 */
|
||||
if (chan != 14)
|
||||
return -1;
|
||||
return 2414 + 5 * chan;
|
||||
case 83: /* channels 1..9; 40 MHz */
|
||||
case 84: /* channels 5..13; 40 MHz */
|
||||
if (chan < 1 || chan > 13)
|
||||
return -1;
|
||||
return 2407 + 5 * chan;
|
||||
case 115: /* channels 36,40,44,48; indoor only */
|
||||
case 116: /* channels 36,44; 40 MHz; indoor only */
|
||||
case 117: /* channels 40,48; 40 MHz; indoor only */
|
||||
case 118: /* channels 52,56,60,64; dfs */
|
||||
case 119: /* channels 52,60; 40 MHz; dfs */
|
||||
case 120: /* channels 56,64; 40 MHz; dfs */
|
||||
if (chan < 36 || chan > 64)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 121: /* channels 100-140 */
|
||||
case 122: /* channels 100-142; 40 MHz */
|
||||
case 123: /* channels 104-136; 40 MHz */
|
||||
if (chan < 100 || chan > 140)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 124: /* channels 149,153,157,161 */
|
||||
case 125: /* channels 149,153,157,161,165,169 */
|
||||
case 126: /* channels 149,157; 40 MHz */
|
||||
case 127: /* channels 153,161; 40 MHz */
|
||||
if (chan < 149 || chan > 161)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 128: /* center freqs 42, 58, 106, 122, 138, 155; 80 MHz */
|
||||
case 130: /* center freqs 42, 58, 106, 122, 138, 155; 80 MHz */
|
||||
if (chan < 36 || chan > 161)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 129: /* center freqs 50, 114; 160 MHz */
|
||||
if (chan < 50 || chan > 114)
|
||||
return -1;
|
||||
return 5000 + 5 * chan;
|
||||
case 180: /* 60 GHz band, channels 1..4 */
|
||||
if (chan < 1 || chan > 4)
|
||||
return -1;
|
||||
return 56160 + 2160 * chan;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* ieee80211_chan_to_freq - Convert channel info to frequency
|
||||
* @country: Country code, if known; otherwise, global operating class is used
|
||||
* @op_class: Operating class
|
||||
* @chan: Channel number
|
||||
* Returns: Frequency in MHz or -1 if the specified channel is unknown
|
||||
*/
|
||||
int ieee80211_chan_to_freq(const char *country, u8 op_class, u8 chan)
|
||||
{
|
||||
int freq;
|
||||
|
||||
if (country_match(us_op_class_cc, country)) {
|
||||
freq = ieee80211_chan_to_freq_us(op_class, chan);
|
||||
if (freq > 0)
|
||||
return freq;
|
||||
}
|
||||
|
||||
if (country_match(eu_op_class_cc, country)) {
|
||||
freq = ieee80211_chan_to_freq_eu(op_class, chan);
|
||||
if (freq > 0)
|
||||
return freq;
|
||||
}
|
||||
|
||||
if (country_match(jp_op_class_cc, country)) {
|
||||
freq = ieee80211_chan_to_freq_jp(op_class, chan);
|
||||
if (freq > 0)
|
||||
return freq;
|
||||
}
|
||||
|
||||
if (country_match(cn_op_class_cc, country)) {
|
||||
freq = ieee80211_chan_to_freq_cn(op_class, chan);
|
||||
if (freq > 0)
|
||||
return freq;
|
||||
}
|
||||
|
||||
return ieee80211_chan_to_freq_global(op_class, chan);
|
||||
}
|
||||
|
||||
|
||||
static int is_11b(u8 rate)
|
||||
{
|
||||
return rate == 0x02 || rate == 0x04 || rate == 0x0b || rate == 0x16;
|
||||
|
|
|
@ -105,6 +105,7 @@ struct hostapd_wmm_ac_params {
|
|||
int hostapd_config_wmm_ac(struct hostapd_wmm_ac_params wmm_ac_params[],
|
||||
const char *name, const char *val);
|
||||
enum hostapd_hw_mode ieee80211_freq_to_chan(int freq, u8 *channel);
|
||||
int ieee80211_chan_to_freq(const char *country, u8 op_class, u8 chan);
|
||||
|
||||
int supp_rates_11b_only(struct ieee802_11_elems *elems);
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "includes.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "common/ieee802_11_common.h"
|
||||
#include "p2p_i.h"
|
||||
|
||||
|
||||
|
@ -54,56 +55,7 @@ int p2p_random(char *buf, size_t len)
|
|||
*/
|
||||
int p2p_channel_to_freq(int op_class, int channel)
|
||||
{
|
||||
/* 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)
|
||||
return -1;
|
||||
return 2407 + 5 * channel;
|
||||
case 82:
|
||||
/* channel 14 */
|
||||
if (channel != 14)
|
||||
return -1;
|
||||
return 2414 + 5 * channel;
|
||||
case 83: /* channels 1..9; 40 MHz */
|
||||
case 84: /* channels 5..13; 40 MHz */
|
||||
if (channel < 1 || channel > 13)
|
||||
return -1;
|
||||
return 2407 + 5 * channel;
|
||||
case 115: /* channels 36,40,44,48; indoor only */
|
||||
case 118: /* channels 52,56,60,64; dfs */
|
||||
if (channel < 36 || channel > 64)
|
||||
return -1;
|
||||
return 5000 + 5 * channel;
|
||||
case 124: /* channels 149,153,157,161 */
|
||||
case 125: /* channels 149,153,157,161,165,169 */
|
||||
if (channel < 149 || channel > 161)
|
||||
return -1;
|
||||
return 5000 + 5 * channel;
|
||||
case 116: /* channels 36,44; 40 MHz; indoor only */
|
||||
case 117: /* channels 40,48; 40 MHz; indoor only */
|
||||
case 119: /* channels 52,60; 40 MHz; dfs */
|
||||
case 120: /* channels 56,64; 40 MHz; dfs */
|
||||
if (channel < 36 || channel > 64)
|
||||
return -1;
|
||||
return 5000 + 5 * channel;
|
||||
case 126: /* channels 149,157; 40 MHz */
|
||||
case 127: /* channels 153,161; 40 MHz */
|
||||
if (channel < 149 || channel > 161)
|
||||
return -1;
|
||||
return 5000 + 5 * channel;
|
||||
case 128: /* center freqs 42, 58, 106, 122, 138, 155; 80 MHz */
|
||||
if (channel < 36 || channel > 161)
|
||||
return -1;
|
||||
return 5000 + 5 * channel;
|
||||
case 180: /* 60 GHz band, channels 1..4 */
|
||||
if (channel < 1 || channel > 4)
|
||||
return -1;
|
||||
return 56160 + 2160 * channel;
|
||||
}
|
||||
return -1;
|
||||
return ieee80211_chan_to_freq(NULL, op_class, channel);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue