enum hostapd_hw_mode ieee80211_freq_to_chan(int freq, u8 *channel)
{
- enum hostapd_hw_mode mode = NUM_HOSTAPD_MODES;
+ u8 op_class;
+
+ return ieee80211_freq_to_channel_ext(freq, 0, 0, &op_class, channel);
+}
+
+
+/**
+ * ieee80211_freq_to_channel_ext - Convert frequency into channel info
+ * for HT40 and VHT. DFS channels are not covered.
+ * @freq: Frequency (MHz) to convert
+ * @sec_channel: 0 = non-HT40, 1 = sec. channel above, -1 = sec. channel below
+ * @vht: 0 - non-VHT, 1 - 80 MHz
+ * @op_class: Buffer for returning operating class
+ * @channel: Buffer for returning channel number
+ * Returns: hw_mode on success, NUM_HOSTAPD_MODES on failure
+ */
+enum hostapd_hw_mode ieee80211_freq_to_channel_ext(unsigned int freq,
+ int sec_channel, int vht,
+ u8 *op_class, u8 *channel)
+{
+ /* TODO: more operating classes */
+
+ if (sec_channel > 1 || sec_channel < -1)
+ return NUM_HOSTAPD_MODES;
if (freq >= 2412 && freq <= 2472) {
- mode = HOSTAPD_MODE_IEEE80211G;
+ if ((freq - 2407) % 5)
+ return NUM_HOSTAPD_MODES;
+
+ if (vht)
+ return NUM_HOSTAPD_MODES;
+
+ /* 2.407 GHz, channels 1..13 */
+ if (sec_channel == 1)
+ *op_class = 83;
+ else if (sec_channel == -1)
+ *op_class = 84;
+ else
+ *op_class = 81;
+
*channel = (freq - 2407) / 5;
- } else if (freq == 2484) {
- mode = HOSTAPD_MODE_IEEE80211B;
+
+ return HOSTAPD_MODE_IEEE80211G;
+ }
+
+ if (freq == 2484) {
+ if (sec_channel || vht)
+ return NUM_HOSTAPD_MODES;
+
+ *op_class = 82; /* channel 14 */
*channel = 14;
- } else if (freq >= 4900 && freq < 5000) {
- mode = HOSTAPD_MODE_IEEE80211A;
+
+ return HOSTAPD_MODE_IEEE80211B;
+ }
+
+ if (freq >= 4900 && freq < 5000) {
+ if ((freq - 4000) % 5)
+ return NUM_HOSTAPD_MODES;
*channel = (freq - 4000) / 5;
- } else if (freq >= 5000 && freq < 5900) {
- mode = HOSTAPD_MODE_IEEE80211A;
+ *op_class = 0; /* TODO */
+ return HOSTAPD_MODE_IEEE80211A;
+ }
+
+ /* 5 GHz, channels 36..48 */
+ if (freq >= 5180 && freq <= 5240) {
+ if ((freq - 5000) % 5)
+ return NUM_HOSTAPD_MODES;
+
+ if (sec_channel == 1)
+ *op_class = 116;
+ else if (sec_channel == -1)
+ *op_class = 117;
+ else if (vht)
+ *op_class = 128;
+ else
+ *op_class = 115;
+
*channel = (freq - 5000) / 5;
- } else if (freq >= 56160 + 2160 * 1 && freq <= 56160 + 2160 * 4) {
- mode = HOSTAPD_MODE_IEEE80211AD;
+
+ return HOSTAPD_MODE_IEEE80211A;
+ }
+
+ /* 5 GHz, channels 149..161 */
+ if (freq >= 5745 && freq <= 5805) {
+ if ((freq - 5000) % 5)
+ return NUM_HOSTAPD_MODES;
+
+ if (sec_channel == 1)
+ *op_class = 126;
+ else if (sec_channel == -1)
+ *op_class = 127;
+ else if (vht)
+ *op_class = 128;
+ else
+ *op_class = 124;
+
+ *channel = (freq - 5000) / 5;
+
+ return HOSTAPD_MODE_IEEE80211A;
+ }
+
+ /* 5 GHz, channels 149..169 */
+ if (freq >= 5745 && freq <= 5845) {
+ if ((freq - 5000) % 5)
+ return NUM_HOSTAPD_MODES;
+
+ *op_class = 125;
+
+ *channel = (freq - 5000) / 5;
+
+ return HOSTAPD_MODE_IEEE80211A;
+ }
+
+ if (freq >= 5000 && freq < 5900) {
+ if ((freq - 5000) % 5)
+ return NUM_HOSTAPD_MODES;
+ *channel = (freq - 5000) / 5;
+ *op_class = 0; /* TODO */
+ return HOSTAPD_MODE_IEEE80211A;
+ }
+
+ /* 56.16 GHz, channel 1..4 */
+ if (freq >= 56160 + 2160 * 1 && freq <= 56160 + 2160 * 4) {
+ if (sec_channel || vht)
+ return NUM_HOSTAPD_MODES;
+
*channel = (freq - 56160) / 2160;
+ *op_class = 180;
+
+ return HOSTAPD_MODE_IEEE80211AD;
}
- return mode;
+ return NUM_HOSTAPD_MODES;
}
#include "includes.h"
#include "common.h"
+#include "common/defs.h"
#include "common/ieee802_11_common.h"
#include "p2p_i.h"
*/
int p2p_freq_to_channel(unsigned int freq, u8 *op_class, u8 *channel)
{
- /* TODO: more operating classes */
- if (freq >= 2412 && freq <= 2472) {
- if ((freq - 2407) % 5)
- return -1;
-
- *op_class = 81; /* 2.407 GHz, channels 1..13 */
- *channel = (freq - 2407) / 5;
- return 0;
- }
-
- if (freq == 2484) {
- *op_class = 82; /* channel 14 */
- *channel = 14;
- return 0;
- }
-
- if (freq >= 5180 && freq <= 5240) {
- if ((freq - 5000) % 5)
- return -1;
-
- *op_class = 115; /* 5 GHz, channels 36..48 */
- *channel = (freq - 5000) / 5;
- return 0;
- }
-
- if (freq >= 5745 && freq <= 5805) {
- if ((freq - 5000) % 5)
- return -1;
-
- *op_class = 124; /* 5 GHz, channels 149..161 */
- *channel = (freq - 5000) / 5;
- return 0;
- }
-
- if (freq >= 5745 && freq <= 5845) {
- if ((freq - 5000) % 5)
- return -1;
-
- *op_class = 125; /* 5 GHz, channels 149..169 */
- *channel = (freq - 5000) / 5;
- return 0;
- }
-
- if (freq >= 58320 && freq <= 64800) {
- if ((freq - 58320) % 2160)
- return -1;
-
- *op_class = 180; /* 60 GHz, channels 1..4 */
- *channel = (freq - 56160) / 2160;
- return 0;
- }
+ if (ieee80211_freq_to_channel_ext(freq, 0, 0, op_class, channel) ==
+ NUM_HOSTAPD_MODES)
+ return -1;
- return -1;
+ return 0;
}