]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
EDMG: Helper functions for parameter encoding/checking
authorAlexei Avshalom Lazar <ailizaro@codeaurora.org>
Wed, 11 Sep 2019 09:03:07 +0000 (12:03 +0300)
committerJouni Malinen <j@w1.fi>
Mon, 7 Oct 2019 13:59:21 +0000 (16:59 +0300)
Signed-off-by: Alexei Avshalom Lazar <ailizaro@codeaurora.org>
src/common/ieee802_11_common.c
src/common/ieee802_11_common.h

index f833ae8e04903d73b57e1b6824d474975ac33423..6461223e9c896524b4ec5e8f1826e864beaef36c 100644 (file)
@@ -2012,3 +2012,75 @@ int ieee802_11_ext_capab(const u8 *ie, unsigned int capab)
                return 0;
        return !!(ie[2 + capab / 8] & BIT(capab % 8));
 }
+
+
+void hostapd_encode_edmg_chan(int edmg_enable, u8 edmg_channel,
+                             int primary_channel,
+                             struct ieee80211_edmg_config *edmg)
+{
+       if (!edmg_enable) {
+               edmg->channels = 0;
+               edmg->bw_config = 0;
+               return;
+       }
+
+       /* Only EDMG CB1 and EDMG CB2 contiguous channels supported for now */
+       switch (edmg_channel) {
+       case EDMG_CHANNEL_9:
+               edmg->channels = EDMG_CHANNEL_9_SUBCHANNELS;
+               edmg->bw_config = EDMG_BW_CONFIG_5;
+               return;
+       case EDMG_CHANNEL_10:
+               edmg->channels = EDMG_CHANNEL_10_SUBCHANNELS;
+               edmg->bw_config = EDMG_BW_CONFIG_5;
+               return;
+       case EDMG_CHANNEL_11:
+               edmg->channels = EDMG_CHANNEL_11_SUBCHANNELS;
+               edmg->bw_config = EDMG_BW_CONFIG_5;
+               return;
+       case EDMG_CHANNEL_12:
+               edmg->channels = EDMG_CHANNEL_12_SUBCHANNELS;
+               edmg->bw_config = EDMG_BW_CONFIG_5;
+               return;
+       case EDMG_CHANNEL_13:
+               edmg->channels = EDMG_CHANNEL_13_SUBCHANNELS;
+               edmg->bw_config = EDMG_BW_CONFIG_5;
+               return;
+       default:
+               if (primary_channel > 0 && primary_channel < 7) {
+                       edmg->channels = BIT(primary_channel - 1);
+                       edmg->bw_config = EDMG_BW_CONFIG_4;
+               } else {
+                       edmg->channels = 0;
+                       edmg->bw_config = 0;
+               }
+               break;
+       }
+}
+
+
+/* Check if the requested EDMG configuration is a subset of the allowed
+ * EDMG configuration. */
+int ieee802_edmg_is_allowed(struct ieee80211_edmg_config allowed,
+                           struct ieee80211_edmg_config requested)
+{
+       /*
+        * The validation check if the requested EDMG configuration
+        * is a subset of the allowed EDMG configuration:
+        * 1. Check that the requested channels are part (set) of the allowed
+        * channels.
+        * 2. P802.11ay defines the values of bw_config between 4 and 15.
+        * (bw config % 4) will give us 4 groups inside bw_config definition,
+        * inside each group we can check the subset just by comparing the
+        * bw_config value.
+        * Between this 4 groups, there is no subset relation - as a result of
+        * the P802.11ay definition.
+        * bw_config defined by IEEE P802.11ay/D4.0, 9.4.2.251, Table 13.
+        */
+       if (((requested.channels & allowed.channels) != requested.channels) ||
+           ((requested.bw_config % 4) > (allowed.bw_config % 4)) ||
+           requested.bw_config > allowed.bw_config)
+               return 0;
+
+       return 1;
+}
index 9b045b41a38661c2c0a11824949dddec1781dfc5..2452b82b96c7238bb27325e81b7c6f0ca01e53db 100644 (file)
@@ -273,4 +273,13 @@ static inline int for_each_element_completed(const struct element *element,
        return (const u8 *) element == (const u8 *) data + datalen;
 }
 
+struct ieee80211_edmg_config;
+
+void hostapd_encode_edmg_chan(int edmg_enable, u8 edmg_channel,
+                             int primary_channel,
+                             struct ieee80211_edmg_config *edmg);
+
+int ieee802_edmg_is_allowed(struct ieee80211_edmg_config allowed,
+                           struct ieee80211_edmg_config requested);
+
 #endif /* IEEE802_11_COMMON_H */