Use bit mask/shift and helper functions instead of C bit fields

This commit is contained in:
Jouni Malinen 2009-03-04 16:23:44 +02:00 committed by Jouni Malinen
parent 3ae0800c5f
commit 979be3fecf
2 changed files with 35 additions and 31 deletions

View File

@ -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);
}

View File

@ -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 <endian.h>"
#endif
/* bytes 3 & 4 */
u8 aci_aifsn; /* AIFSN, ACM, ACI */
u8 cw; /* ECWmin, ECWmax (CW = 2^ECW - 1) */
le16 txop_limit;
} __attribute__ ((packed));