From fe468b071434098b74baffb361bf9e9375609dd8 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 12 Feb 2019 01:16:13 +0200 Subject: [PATCH] HE: Fix set_he_cap() parsing of config options for MU EDCA Params When I replaced the POS() function with ffs() when applying relevant parts from the original patch, this ended up breaking the frame construction since the POS() function was supposed to count the bit offset for the mask with 0 being the LSB instead of 1 returned by ffs(). Furthermore, ffs() is not available in all C libraries (e.g., not directly exposed by strings.h on Android), so better not depend on that or compiler builtins for this since there is no need for this to be as fast as possible in configuration parsing. Fix this with a simple function to determine the number of bits the value needs to be shifted left to align with the mask. Fixes: 11ce7a1bc3e2 ("HE: Add MU EDCA Parameter Set element (AP)") Signed-off-by: Jouni Malinen --- hostapd/config_file.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/hostapd/config_file.c b/hostapd/config_file.c index aeec1d9e2..c8ff7a06a 100644 --- a/hostapd/config_file.c +++ b/hostapd/config_file.c @@ -1380,10 +1380,26 @@ static int hostapd_config_vht_capab(struct hostapd_config *conf, #ifdef CONFIG_IEEE80211AX + +static u8 find_bit_offset(u8 val) +{ + u8 res = 0; + + for (; val; val >>= 1) { + if (val & 1) + break; + res++; + } + + return res; +} + + static u8 set_he_cap(int val, u8 mask) { - return (u8) (mask & (val << ffs(mask))); + return (u8) (mask & (val << find_bit_offset(mask))); } + #endif /* CONFIG_IEEE80211AX */