From 979be3fecf48e36ac6faab90ef7d2512c8999d54 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Wed, 4 Mar 2009 16:23:44 +0200 Subject: [PATCH] Use bit mask/shift and helper functions instead of C bit fields --- hostapd/wme.c | 28 ++++++++++++++++++++++------ hostapd/wme.h | 38 +++++++++++++------------------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/hostapd/wme.c b/hostapd/wme.c index 1be13644d..6ea15ede1 100644 --- a/hostapd/wme.c +++ b/hostapd/wme.c @@ -30,6 +30,24 @@ static u8 wmm_oui[3] = { 0x00, 0x50, 0xf2 }; +static inline u8 wmm_aci_aifsn(int aifsn, int acm, int aci) +{ + u8 ret; + ret = (aifsn << WMM_AC_AIFNS_SHIFT) & WMM_AC_AIFSN_MASK; + if (acm) + ret |= WMM_AC_ACM; + ret |= (aci << WMM_AC_ACI_SHIFT) & WMM_AC_ACI_MASK; + return ret; +} + + +static inline u8 wmm_ecw(int ecwmin, int ecwmax) +{ + return ((ecwmin << WMM_AC_ECWMIN_SHIFT) & WMM_AC_ECWMIN_MASK) | + ((ecwmax << WMM_AC_ECWMAX_SHIFT) & WMM_AC_ECWMAX_MASK); +} + + /* * Add WMM Parameter Element to Beacon, Probe Response, and (Re)Association * Response frames. @@ -58,12 +76,10 @@ u8 * hostapd_eid_wmm(struct hostapd_data *hapd, u8 *eid) struct hostapd_wmm_ac_params *acp = &hapd->iconf->wmm_ac_params[e]; - ac->aifsn = acp->aifs; - ac->acm = acp->admission_control_mandatory; - ac->aci = e; - ac->reserved = 0; - ac->e_cw_min = acp->cwmin; - ac->e_cw_max = acp->cwmax; + ac->aci_aifsn = wmm_aci_aifsn(acp->aifs, + acp->admission_control_mandatory, + e); + ac->cw = wmm_ecw(acp->cwmin, acp->cwmax); ac->txop_limit = host_to_le16(acp->txop_limit); } diff --git a/hostapd/wme.h b/hostapd/wme.h index abfe80be1..3decb4bca 100644 --- a/hostapd/wme.h +++ b/hostapd/wme.h @@ -42,32 +42,20 @@ struct wmm_information_element { } __attribute__ ((packed)); +#define WMM_AC_AIFSN_MASK 0x0f +#define WMM_AC_AIFNS_SHIFT 0 +#define WMM_AC_ACM 0x10 +#define WMM_AC_ACI_MASK 0x60 +#define WMM_AC_ACI_SHIFT 5 + +#define WMM_AC_ECWMIN_MASK 0x0f +#define WMM_AC_ECWMIN_SHIFT 0 +#define WMM_AC_ECWMAX_MASK 0xf0 +#define WMM_AC_ECWMAX_SHIFT 4 + struct wmm_ac_parameter { -#if __BYTE_ORDER == __LITTLE_ENDIAN - /* byte 1: ACI/AIFSN */ - u8 aifsn:4, - acm:1, - aci:2, - reserved:1; - - /* byte 2: ECWmin/ECWmax (CW = 2^ECW - 1) */ - u8 e_cw_min:4, - e_cw_max:4; -#elif __BYTE_ORDER == __BIG_ENDIAN - /* byte 1: ACI/AIFSN */ - u8 reserved:1, - aci:2, - acm:1, - aifsn:4; - - /* byte 2: ECWmin/ECWmax */ - u8 e_cw_max:4, - e_cw_min:4; -#else -#error "Please fix " -#endif - - /* bytes 3 & 4 */ + u8 aci_aifsn; /* AIFSN, ACM, ACI */ + u8 cw; /* ECWmin, ECWmax (CW = 2^ECW - 1) */ le16 txop_limit; } __attribute__ ((packed));