]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add utility function to derive operating class and channel
authorMathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
Mon, 6 Aug 2018 19:46:22 +0000 (15:46 -0400)
committerJouni Malinen <j@w1.fi>
Sun, 16 Dec 2018 16:35:30 +0000 (18:35 +0200)
This function can be used to easily convert the parameters returned
by the channel_info driver API, into their corresponding operating
class and channel number.

Signed-off-by: Mathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
src/common/ieee802_11_common.c
src/common/ieee802_11_common.h

index e1ef27795b99a0eb0d75c75e9ee234b0a7105fcc..d1cc101b029e726f72d2f472789e647bf3a1acfb 100644 (file)
@@ -896,6 +896,41 @@ enum hostapd_hw_mode ieee80211_freq_to_channel_ext(unsigned int freq,
 }
 
 
+int ieee80211_chaninfo_to_channel(unsigned int freq, enum chan_width chanwidth,
+                                 int sec_channel, u8 *op_class, u8 *channel)
+{
+       int vht = CHAN_WIDTH_UNKNOWN;
+
+       switch (chanwidth) {
+       case CHAN_WIDTH_UNKNOWN:
+       case CHAN_WIDTH_20_NOHT:
+       case CHAN_WIDTH_20:
+       case CHAN_WIDTH_40:
+               vht = VHT_CHANWIDTH_USE_HT;
+               break;
+       case CHAN_WIDTH_80:
+               vht = VHT_CHANWIDTH_80MHZ;
+               break;
+       case CHAN_WIDTH_80P80:
+               vht = VHT_CHANWIDTH_80P80MHZ;
+               break;
+       case CHAN_WIDTH_160:
+               vht = VHT_CHANWIDTH_160MHZ;
+               break;
+       }
+
+       if (ieee80211_freq_to_channel_ext(freq, sec_channel, vht, op_class,
+                                         channel) == NUM_HOSTAPD_MODES) {
+               wpa_printf(MSG_WARNING,
+                          "Cannot determine operating class and channel (freq=%u chanwidth=%d sec_channel=%d)",
+                          freq, chanwidth, sec_channel);
+               return -1;
+       }
+
+       return 0;
+}
+
+
 static const char *const us_op_class_cc[] = {
        "US", "CA", NULL
 };
index ff7e51de3dc9bebbf6a8e9b1694b87466080749e..e801caf45615dd0ba3d4d7c15e92cae6f4775d80 100644 (file)
@@ -12,6 +12,7 @@
 #include "defs.h"
 
 struct hostapd_hw_modes;
+enum chan_width;
 
 #define MAX_NOF_MB_IES_SUPPORTED 5
 
@@ -160,6 +161,8 @@ int ieee80211_chan_to_freq(const char *country, u8 op_class, u8 chan);
 enum hostapd_hw_mode ieee80211_freq_to_channel_ext(unsigned int freq,
                                                   int sec_channel, int vht,
                                                   u8 *op_class, u8 *channel);
+int ieee80211_chaninfo_to_channel(unsigned int freq, enum chan_width chanwidth,
+                                 int sec_channel, u8 *op_class, u8 *channel);
 int ieee80211_is_dfs(int freq, const struct hostapd_hw_modes *modes,
                     u16 num_modes);
 enum phy_type ieee80211_get_phy_type(int freq, int ht, int vht);