aboutsummaryrefslogtreecommitdiffstats
path: root/hostapd
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2007-02-10 17:59:29 (GMT)
committerJouni Malinen <j@w1.fi>2007-02-10 17:59:29 (GMT)
commitcd8ab0450bed8475cb260ac36a97136465d7aa3a (patch)
tree8c802ca7e1a2af57c7822501bca096605e5584cf /hostapd
parent14ed4199edcc81ef9de41da089da223d132d5e1d (diff)
downloadhostap-history-cd8ab0450bed8475cb260ac36a97136465d7aa3a.zip
hostap-history-cd8ab0450bed8475cb260ac36a97136465d7aa3a.tar.gz
hostap-history-cd8ab0450bed8475cb260ac36a97136465d7aa3a.tar.bz2
Added endianness annotation for sparse and resolved most of the
warnings from this.
Diffstat (limited to 'hostapd')
-rw-r--r--hostapd/common.c13
-rw-r--r--hostapd/common.h72
-rw-r--r--hostapd/eap.c10
-rw-r--r--hostapd/eap_aka.c4
-rw-r--r--hostapd/eap_pax.c10
-rw-r--r--hostapd/eap_peap.c8
-rw-r--r--hostapd/eap_psk.c10
-rw-r--r--hostapd/eap_sake.c8
-rw-r--r--hostapd/eap_sim.c4
-rw-r--r--hostapd/eap_tls.c6
-rw-r--r--hostapd/eap_tls_common.c6
-rw-r--r--hostapd/eap_tlv.c2
-rw-r--r--hostapd/eap_ttls.c8
-rw-r--r--hostapd/eap_vendor_test.c6
-rw-r--r--hostapd/eapol_sm.c4
-rw-r--r--hostapd/hostapd.h8
-rw-r--r--hostapd/iapp.c8
-rw-r--r--hostapd/ieee802_11_defs.h40
-rw-r--r--hostapd/ieee802_1x.c19
-rw-r--r--hostapd/radius_server.c6
-rw-r--r--hostapd/wme.h2
-rw-r--r--hostapd/wpa.c2
-rw-r--r--hostapd/wpa_common.h6
23 files changed, 143 insertions, 119 deletions
diff --git a/hostapd/common.c b/hostapd/common.c
index 88d89f0..49dc0bf 100644
--- a/hostapd/common.c
+++ b/hostapd/common.c
@@ -1,6 +1,6 @@
/*
* wpa_supplicant/hostapd / common helper functions, etc.
- * Copyright (c) 2002-2006, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2002-2007, Jouni Malinen <jkmaline@cc.hut.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -130,15 +130,18 @@ void wpa_get_ntp_timestamp(u8 *buf)
{
struct os_time now;
u32 sec, usec;
+ be32 tmp;
/* 64-bit NTP timestamp (time from 1900-01-01 00:00:00) */
os_get_time(&now);
- sec = host_to_be32(now.sec + 2208988800U); /* Epoch to 1900 */
+ sec = now.sec + 2208988800U; /* Epoch to 1900 */
/* Estimate 2^32/10^6 = 4295 - 1/32 - 1/512 */
usec = now.usec;
- usec = host_to_be32(4295 * usec - (usec >> 5) - (usec >> 9));
- os_memcpy(buf, (u8 *) &sec, 4);
- os_memcpy(buf + 4, (u8 *) &usec, 4);
+ usec = 4295 * usec - (usec >> 5) - (usec >> 9);
+ tmp = host_to_be32(sec);
+ os_memcpy(buf, (u8 *) &tmp, 4);
+ tmp = host_to_be32(usec);
+ os_memcpy(buf + 4, (u8 *) &tmp, 4);
}
diff --git a/hostapd/common.h b/hostapd/common.h
index 0f20c8d..bf92887 100644
--- a/hostapd/common.h
+++ b/hostapd/common.h
@@ -1,6 +1,6 @@
/*
* wpa_supplicant/hostapd / common helper functions, etc.
- * Copyright (c) 2002-2006, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2002-2007, Jouni Malinen <jkmaline@cc.hut.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -101,17 +101,18 @@ static inline unsigned int wpa_swap_32(unsigned int v)
#endif /* __BYTE_ORDER */
#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define le_to_host16(n) (n)
-#define host_to_le16(n) (n)
-#define be_to_host16(n) bswap_16(n)
-#define host_to_be16(n) bswap_16(n)
-#define le_to_host32(n) (n)
-#define be_to_host32(n) bswap_32(n)
-#define host_to_be32(n) bswap_32(n)
-#define le_to_host64(n) (n)
-#define host_to_le64(n) (n)
-#define be_to_host64(n) bswap_64(n)
-#define host_to_be64(n) bswap_64(n)
+#define le_to_host16(n) ((__force u16) (le16) (n))
+#define host_to_le16(n) ((__force le16) (u16) (n))
+#define be_to_host16(n) bswap_16((__force u16) (be16) (n))
+#define host_to_be16(n) ((__force be16) bswap_16((n)))
+#define le_to_host32(n) ((__force u32) (le32) (n))
+#define host_to_le32(n) ((__force le32) (u32) (n))
+#define be_to_host32(n) bswap_32((__force u32) (be32) (n))
+#define host_to_be32(n) ((__force be32) bswap_32((n)))
+#define le_to_host64(n) ((__force u64) (le64) (n))
+#define host_to_le64(n) ((__force le64) (u64) (n))
+#define be_to_host64(n) bswap_64((__force u64) (be64) (n))
+#define host_to_be64(n) ((__force be64) bswap_64((n)))
#elif __BYTE_ORDER == __BIG_ENDIAN
#define le_to_host16(n) bswap_16(n)
#define host_to_le16(n) bswap_16(n)
@@ -150,21 +151,21 @@ static inline unsigned int wpa_swap_32(unsigned int v)
#define WPA_GET_BE24(a) ((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
((u32) (a)[2]))
-#define WPA_PUT_BE24(a, val) \
- do { \
- (a)[0] = (u8) (((u32) (val)) >> 16); \
- (a)[1] = (u8) (((u32) (val)) >> 8); \
- (a)[2] = (u8) (((u32) (val)) & 0xff); \
+#define WPA_PUT_BE24(a, val) \
+ do { \
+ (a)[0] = (u8) ((((u32) (val)) >> 16) & 0xff); \
+ (a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \
+ (a)[2] = (u8) (((u32) (val)) & 0xff); \
} while (0)
#define WPA_GET_BE32(a) ((((u32) (a)[0]) << 24) | (((u32) (a)[1]) << 16) | \
(((u32) (a)[2]) << 8) | ((u32) (a)[3]))
-#define WPA_PUT_BE32(a, val) \
- do { \
- (a)[0] = (u8) (((u32) (val)) >> 24); \
- (a)[1] = (u8) (((u32) (val)) >> 16); \
- (a)[2] = (u8) (((u32) (val)) >> 8); \
- (a)[3] = (u8) (((u32) (val)) & 0xff); \
+#define WPA_PUT_BE32(a, val) \
+ do { \
+ (a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff); \
+ (a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff); \
+ (a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff); \
+ (a)[3] = (u8) (((u32) (val)) & 0xff); \
} while (0)
#define WPA_GET_BE64(a) ((((u64) (a)[0]) << 56) | (((u64) (a)[1]) << 48) | \
@@ -555,8 +556,27 @@ const char * wpa_ssid_txt(u8 *ssid, size_t ssid_len);
#define BIT(x) (1 << (x))
#endif
-typedef u16 __be16;
-typedef u32 __be32;
-typedef u64 __be64;
+/*
+ * Definitions for sparse validation
+ * (http://kernel.org/pub/linux/kernel/people/josh/sparse/)
+ */
+#ifdef __CHECKER__
+#define __force __attribute__((force))
+#define __bitwise __attribute__((bitwise))
+#else
+#define __force
+#define __bitwise
+#endif
+
+typedef u16 __bitwise be16;
+typedef u16 __bitwise le16;
+typedef u32 __bitwise be32;
+typedef u32 __bitwise le32;
+typedef u64 __bitwise be64;
+typedef u64 __bitwise le64;
+
+typedef u16 __bitwise __be16;
+typedef u32 __bitwise __be32;
+typedef u64 __bitwise __be64;
#endif /* COMMON_H */
diff --git a/hostapd/eap.c b/hostapd/eap.c
index b11ceb1..37b6dcc 100644
--- a/hostapd/eap.c
+++ b/hostapd/eap.c
@@ -1,6 +1,6 @@
/*
* hostapd / EAP Standalone Authenticator state machine (RFC 4137)
- * Copyright (c) 2004-2006, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2004-2007, Jouni Malinen <jkmaline@cc.hut.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -356,7 +356,7 @@ SM_STATE(EAP, NAK)
nak = (struct eap_hdr *) sm->eapRespData;
if (nak && sm->eapRespDataLen > sizeof(*nak)) {
- len = ntohs(nak->length);
+ len = be_to_host16(nak->length);
if (len > sm->eapRespDataLen)
len = sm->eapRespDataLen;
pos = (u8 *) (nak + 1);
@@ -615,7 +615,7 @@ static void eap_sm_parseEapResp(struct eap_sm *sm, u8 *resp, size_t len)
return;
hdr = (struct eap_hdr *) resp;
- plen = ntohs(hdr->length);
+ plen = be_to_host16(hdr->length);
if (plen > len) {
wpa_printf(MSG_DEBUG, "EAP: Ignored truncated EAP-Packet "
"(len=%lu plen=%lu)", (unsigned long) len,
@@ -662,7 +662,7 @@ static u8 * eap_sm_buildSuccess(struct eap_sm *sm, int id, size_t *len)
return NULL;
resp->code = EAP_CODE_SUCCESS;
resp->identifier = id;
- resp->length = htons(*len);
+ resp->length = host_to_be16(*len);
return (u8 *) resp;
}
@@ -679,7 +679,7 @@ static u8 * eap_sm_buildFailure(struct eap_sm *sm, int id, size_t *len)
return NULL;
resp->code = EAP_CODE_FAILURE;
resp->identifier = id;
- resp->length = htons(*len);
+ resp->length = host_to_be16(*len);
return (u8 *) resp;
}
diff --git a/hostapd/eap_aka.c b/hostapd/eap_aka.c
index 379f61c..b5994d0 100644
--- a/hostapd/eap_aka.c
+++ b/hostapd/eap_aka.c
@@ -275,7 +275,7 @@ static Boolean eap_aka_check(struct eap_sm *sm, void *priv,
resp = (struct eap_hdr *) respData;
pos = (u8 *) (resp + 1);
if (respDataLen < sizeof(*resp) + 4 || *pos != EAP_TYPE_AKA ||
- (ntohs(resp->length)) > respDataLen) {
+ (be_to_host16(resp->length)) > respDataLen) {
wpa_printf(MSG_INFO, "EAP-AKA: Invalid frame");
return TRUE;
}
@@ -641,7 +641,7 @@ static void eap_aka_process(struct eap_sm *sm, void *priv,
resp = (struct eap_hdr *) respData;
pos = (u8 *) (resp + 1);
subtype = pos[1];
- len = ntohs(resp->length);
+ len = be_to_host16(resp->length);
pos += 4;
if (eap_sim_parse_attr(pos, respData + len, &attr, 1, 0)) {
diff --git a/hostapd/eap_pax.c b/hostapd/eap_pax.c
index aaf5777..b158a7c 100644
--- a/hostapd/eap_pax.c
+++ b/hostapd/eap_pax.c
@@ -1,6 +1,6 @@
/*
* hostapd / EAP-PAX (RFC 4746) server
- * Copyright (c) 2005-2006, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2005-2007, Jouni Malinen <jkmaline@cc.hut.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -99,7 +99,7 @@ static u8 * eap_pax_build_std_1(struct eap_sm *sm,
req->code = EAP_CODE_REQUEST;
req->identifier = id;
- req->length = htons(*reqDataLen);
+ req->length = host_to_be16(*reqDataLen);
req->type = EAP_TYPE_PAX;
req->op_code = EAP_PAX_OP_STD_1;
req->flags = 0;
@@ -144,7 +144,7 @@ static u8 * eap_pax_build_std_3(struct eap_sm *sm,
req->code = EAP_CODE_REQUEST;
req->identifier = id;
- req->length = htons(*reqDataLen);
+ req->length = host_to_be16(*reqDataLen);
req->type = EAP_TYPE_PAX;
req->op_code = EAP_PAX_OP_STD_3;
req->flags = 0;
@@ -202,7 +202,7 @@ static Boolean eap_pax_check(struct eap_sm *sm, void *priv,
resp = (struct eap_pax_hdr *) respData;
if (respDataLen < sizeof(*resp) || resp->type != EAP_TYPE_PAX ||
- (len = ntohs(resp->length)) > respDataLen ||
+ (len = be_to_host16(resp->length)) > respDataLen ||
len < sizeof(*resp) + EAP_PAX_ICV_LEN) {
wpa_printf(MSG_INFO, "EAP-PAX: Invalid frame");
return TRUE;
@@ -304,7 +304,7 @@ static void eap_pax_process_std_2(struct eap_sm *sm,
wpa_printf(MSG_DEBUG, "EAP-PAX: Received PAX_STD-2");
resp = (struct eap_pax_hdr *) respData;
- len = ntohs(resp->length);
+ len = be_to_host16(resp->length);
pos = (u8 *) (resp + 1);
left = len - sizeof(*resp);
diff --git a/hostapd/eap_peap.c b/hostapd/eap_peap.c
index 24f9917..1a57c16 100644
--- a/hostapd/eap_peap.c
+++ b/hostapd/eap_peap.c
@@ -180,7 +180,7 @@ static u8 * eap_peap_build_start(struct eap_sm *sm, struct eap_peap_data *data,
req->code = EAP_CODE_REQUEST;
req->identifier = id;
- req->length = htons(*reqDataLen);
+ req->length = host_to_be16(*reqDataLen);
pos = (u8 *) (req + 1);
*pos++ = EAP_TYPE_PEAP;
*pos = EAP_TLS_FLAGS_START | data->peap_version;
@@ -294,7 +294,7 @@ static u8 * eap_peap_build_phase2_term(struct eap_sm *sm,
hdr->code = success ? EAP_CODE_SUCCESS : EAP_CODE_FAILURE;
hdr->identifier = id;
- hdr->length = htons(req_len);
+ hdr->length = host_to_be16(req_len);
wpa_hexdump_key(MSG_DEBUG, "EAP-PEAP: Encrypting Phase 2 data",
(u8 *) hdr, req_len);
@@ -342,7 +342,7 @@ static Boolean eap_peap_check(struct eap_sm *sm, void *priv,
resp = (struct eap_hdr *) respData;
pos = (u8 *) (resp + 1);
if (respDataLen < sizeof(*resp) + 2 || *pos != EAP_TYPE_PEAP ||
- (ntohs(resp->length)) > respDataLen) {
+ (be_to_host16(resp->length)) > respDataLen) {
wpa_printf(MSG_INFO, "EAP-PEAP: Invalid frame");
return TRUE;
}
@@ -591,7 +591,7 @@ static void eap_peap_process(struct eap_sm *sm, void *priv,
pos = (u8 *) (resp + 1);
pos++;
flags = *pos++;
- left = htons(resp->length) - sizeof(struct eap_hdr) - 2;
+ left = be_to_host16(resp->length) - sizeof(struct eap_hdr) - 2;
wpa_printf(MSG_DEBUG, "EAP-PEAP: Received packet(len=%lu) - "
"Flags 0x%02x", (unsigned long) respDataLen, flags);
peer_version = flags & EAP_PEAP_VERSION_MASK;
diff --git a/hostapd/eap_psk.c b/hostapd/eap_psk.c
index 83de87e..e2c1123 100644
--- a/hostapd/eap_psk.c
+++ b/hostapd/eap_psk.c
@@ -1,6 +1,6 @@
/*
* hostapd / EAP-PSK (draft-bersani-eap-psk-11.txt) server
- * Copyright (c) 2005-2006, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2005-2007, Jouni Malinen <jkmaline@cc.hut.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -84,7 +84,7 @@ static u8 * eap_psk_build_1(struct eap_sm *sm, struct eap_psk_data *data,
req->code = EAP_CODE_REQUEST;
req->identifier = id;
- req->length = htons(*reqDataLen);
+ req->length = host_to_be16(*reqDataLen);
req->type = EAP_TYPE_PSK;
req->flags = EAP_PSK_FLAGS_SET_T(0); /* T=0 */
memcpy(req->rand_s, data->rand_s, EAP_PSK_RAND_LEN);
@@ -114,7 +114,7 @@ static u8 * eap_psk_build_3(struct eap_sm *sm, struct eap_psk_data *data,
req->code = EAP_CODE_REQUEST;
req->identifier = id;
- req->length = htons(*reqDataLen);
+ req->length = host_to_be16(*reqDataLen);
req->type = EAP_TYPE_PSK;
req->flags = EAP_PSK_FLAGS_SET_T(2); /* T=2 */
memcpy(req->rand_s, data->rand_s, EAP_PSK_RAND_LEN);
@@ -229,7 +229,7 @@ static void eap_psk_process_2(struct eap_sm *sm,
wpa_printf(MSG_DEBUG, "EAP-PSK: Received PSK-2");
resp = (struct eap_psk_hdr_2 *) respData;
- len = ntohs(resp->length);
+ len = be_to_host16(resp->length);
pos = (u8 *) (resp + 1);
left = len - sizeof(*resp);
@@ -332,7 +332,7 @@ static void eap_psk_process_4(struct eap_sm *sm,
resp = (struct eap_psk_hdr_4 *) respData;
pos = (u8 *) (resp + 1);
- left = ntohs(resp->length) - sizeof(*resp);
+ left = be_to_host16(resp->length) - sizeof(*resp);
wpa_hexdump(MSG_MSGDUMP, "EAP-PSK: Encrypted PCHANNEL", pos, left);
diff --git a/hostapd/eap_sake.c b/hostapd/eap_sake.c
index 41ff67e..3fc1245 100644
--- a/hostapd/eap_sake.c
+++ b/hostapd/eap_sake.c
@@ -1,6 +1,6 @@
/*
* hostapd / EAP-SAKE (RFC 4763) server
- * Copyright (c) 2006, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2006-2007, Jouni Malinen <jkmaline@cc.hut.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -118,7 +118,7 @@ static u8 * eap_sake_build_msg(struct eap_sake_data *data, u8 **payload,
req = (struct eap_sake_hdr *) msg;
req->code = EAP_CODE_REQUEST;
req->identifier = id;
- req->length = htons((u16) *length);
+ req->length = host_to_be16((u16) *length);
req->type = EAP_TYPE_SAKE;
req->version = EAP_SAKE_VERSION;
req->session_id = data->session_id;
@@ -272,7 +272,7 @@ static Boolean eap_sake_check(struct eap_sm *sm, void *priv,
resp = (struct eap_sake_hdr *) respData;
if (respDataLen < sizeof(*resp) ||
resp->type != EAP_TYPE_SAKE ||
- (len = ntohs(resp->length)) > respDataLen ||
+ (len = be_to_host16(resp->length)) > respDataLen ||
len < sizeof(*resp)) {
wpa_printf(MSG_INFO, "EAP-SAKE: Invalid frame");
return TRUE;
@@ -443,7 +443,7 @@ static void eap_sake_process(struct eap_sm *sm, void *priv,
resp = (struct eap_sake_hdr *) respData;
subtype = resp->subtype;
pos = (u8 *) (resp + 1);
- end = respData + ntohs(resp->length);
+ end = respData + be_to_host16(resp->length);
wpa_hexdump(MSG_DEBUG, "EAP-SAKE: Received attributes",
pos, end - pos);
diff --git a/hostapd/eap_sim.c b/hostapd/eap_sim.c
index 175c8e5..e3e15a5 100644
--- a/hostapd/eap_sim.c
+++ b/hostapd/eap_sim.c
@@ -271,7 +271,7 @@ static Boolean eap_sim_check(struct eap_sm *sm, void *priv,
resp = (struct eap_hdr *) respData;
pos = (u8 *) (resp + 1);
if (respDataLen < sizeof(*resp) + 4 || *pos != EAP_TYPE_SIM ||
- (ntohs(resp->length)) > respDataLen) {
+ (be_to_host16(resp->length)) > respDataLen) {
wpa_printf(MSG_INFO, "EAP-SIM: Invalid frame");
return TRUE;
}
@@ -585,7 +585,7 @@ static void eap_sim_process(struct eap_sm *sm, void *priv,
resp = (struct eap_hdr *) respData;
pos = (u8 *) (resp + 1);
subtype = pos[1];
- len = ntohs(resp->length);
+ len = be_to_host16(resp->length);
pos += 4;
if (eap_sim_parse_attr(pos, respData + len, &attr, 0, 0)) {
diff --git a/hostapd/eap_tls.c b/hostapd/eap_tls.c
index 2dbffaf..903342a 100644
--- a/hostapd/eap_tls.c
+++ b/hostapd/eap_tls.c
@@ -75,7 +75,7 @@ static u8 * eap_tls_build_start(struct eap_sm *sm, struct eap_tls_data *data,
req->code = EAP_CODE_REQUEST;
req->identifier = id;
- req->length = htons(*reqDataLen);
+ req->length = host_to_be16(*reqDataLen);
pos = (u8 *) (req + 1);
*pos++ = EAP_TYPE_TLS;
*pos = EAP_TLS_FLAGS_START;
@@ -134,7 +134,7 @@ static Boolean eap_tls_check(struct eap_sm *sm, void *priv,
resp = (struct eap_hdr *) respData;
pos = (u8 *) (resp + 1);
if (respDataLen < sizeof(*resp) + 2 || *pos != EAP_TYPE_TLS ||
- (ntohs(resp->length)) > respDataLen) {
+ (be_to_host16(resp->length)) > respDataLen) {
wpa_printf(MSG_INFO, "EAP-TLS: Invalid frame");
return TRUE;
}
@@ -156,7 +156,7 @@ static void eap_tls_process(struct eap_sm *sm, void *priv,
pos = (u8 *) (resp + 1);
pos++;
flags = *pos++;
- left = htons(resp->length) - sizeof(struct eap_hdr) - 2;
+ left = be_to_host16(resp->length) - sizeof(struct eap_hdr) - 2;
wpa_printf(MSG_DEBUG, "EAP-TLS: Received packet(len=%lu) - "
"Flags 0x%02x", (unsigned long) respDataLen, flags);
if (flags & EAP_TLS_FLAGS_LENGTH_INCLUDED) {
diff --git a/hostapd/eap_tls_common.c b/hostapd/eap_tls_common.c
index 3e7be82..8236c95 100644
--- a/hostapd/eap_tls_common.c
+++ b/hostapd/eap_tls_common.c
@@ -1,6 +1,6 @@
/*
* hostapd / EAP-TLS/PEAP/TTLS common functions
- * Copyright (c) 2004-2006, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2004-2007, Jouni Malinen <jkmaline@cc.hut.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -261,7 +261,7 @@ int eap_server_tls_buildReq_helper(struct eap_sm *sm,
memcpy(pos, &data->tls_out[data->tls_out_pos], len);
data->tls_out_pos += len;
*out_len = (pos - (u8 *) req) + len;
- req->length = htons(*out_len);
+ req->length = host_to_be16(*out_len);
*out_data = (u8 *) req;
if (!(*flags & EAP_TLS_FLAGS_MORE_FRAGMENTS)) {
@@ -288,7 +288,7 @@ u8 * eap_server_tls_build_ack(size_t *reqDataLen, u8 id, int eap_type,
wpa_printf(MSG_DEBUG, "SSL: Building ACK");
req->code = EAP_CODE_REQUEST;
req->identifier = id;
- req->length = htons(*reqDataLen);
+ req->length = host_to_be16(*reqDataLen);
pos = (u8 *) (req + 1);
*pos++ = eap_type; /* Type */
*pos = peap_version; /* Flags */
diff --git a/hostapd/eap_tlv.c b/hostapd/eap_tlv.c
index 5672c11..63e5fb9 100644
--- a/hostapd/eap_tlv.c
+++ b/hostapd/eap_tlv.c
@@ -101,7 +101,7 @@ static Boolean eap_tlv_check(struct eap_sm *sm, void *priv,
resp = (struct eap_hdr *) respData;
pos = (u8 *) (resp + 1);
if (respDataLen < sizeof(*resp) + 1 || *pos != EAP_TYPE_TLV ||
- (ntohs(resp->length)) > respDataLen) {
+ (be_to_host16(resp->length)) > respDataLen) {
wpa_printf(MSG_INFO, "EAP-TLV: Invalid frame");
return TRUE;
}
diff --git a/hostapd/eap_ttls.c b/hostapd/eap_ttls.c
index cdd6283..098b948 100644
--- a/hostapd/eap_ttls.c
+++ b/hostapd/eap_ttls.c
@@ -203,7 +203,7 @@ static int eap_ttls_avp_parse(u8 *buf, size_t len, struct eap_ttls_avp *parse)
"underflow");
goto fail;
}
- vendor_id = be_to_host32(* (u32 *) dpos);
+ vendor_id = be_to_host32(* (be32 *) dpos);
wpa_printf(MSG_DEBUG, "EAP-TTLS: AVP vendor_id %d",
(int) vendor_id);
dpos += 4;
@@ -438,7 +438,7 @@ static u8 * eap_ttls_build_start(struct eap_sm *sm, struct eap_ttls_data *data,
req->code = EAP_CODE_REQUEST;
req->identifier = id;
- req->length = htons(*reqDataLen);
+ req->length = host_to_be16(*reqDataLen);
pos = (u8 *) (req + 1);
*pos++ = EAP_TYPE_TTLS;
*pos = EAP_TLS_FLAGS_START | data->ttls_version;
@@ -656,7 +656,7 @@ static Boolean eap_ttls_check(struct eap_sm *sm, void *priv,
resp = (struct eap_hdr *) respData;
pos = (u8 *) (resp + 1);
if (respDataLen < sizeof(*resp) + 2 || *pos != EAP_TYPE_TTLS ||
- (ntohs(resp->length)) > respDataLen) {
+ (be_to_host16(resp->length)) > respDataLen) {
wpa_printf(MSG_INFO, "EAP-TTLS: Invalid frame");
return TRUE;
}
@@ -1301,7 +1301,7 @@ static void eap_ttls_process(struct eap_sm *sm, void *priv,
pos = (u8 *) (resp + 1);
pos++;
flags = *pos++;
- left = htons(resp->length) - sizeof(struct eap_hdr) - 2;
+ left = be_to_host16(resp->length) - sizeof(struct eap_hdr) - 2;
wpa_printf(MSG_DEBUG, "EAP-TTLS: Received packet(len=%lu) - "
"Flags 0x%02x", (unsigned long) respDataLen, flags);
peer_version = flags & EAP_PEAP_VERSION_MASK;
diff --git a/hostapd/eap_vendor_test.c b/hostapd/eap_vendor_test.c
index db8e06e..8f6e628 100644
--- a/hostapd/eap_vendor_test.c
+++ b/hostapd/eap_vendor_test.c
@@ -1,6 +1,6 @@
/*
* hostapd / Test method for vendor specific (expanded) EAP type
- * Copyright (c) 2005, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2005-2007, Jouni Malinen <jkmaline@cc.hut.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -91,7 +91,7 @@ static u8 * eap_vendor_test_buildReq(struct eap_sm *sm, void *priv, int id,
req->code = EAP_CODE_REQUEST;
req->identifier = id;
- req->length = htons(*reqDataLen);
+ req->length = host_to_be16(*reqDataLen);
pos = (u8 *) (req + 1);
*pos++ = EAP_TYPE_EXPANDED;
WPA_PUT_BE24(pos, EAP_VENDOR_ID);
@@ -117,7 +117,7 @@ static Boolean eap_vendor_test_check(struct eap_sm *sm, void *priv,
pos = (u8 *) (resp + 1);
if (respDataLen < sizeof(*resp))
return TRUE;
- len = ntohs(resp->length);
+ len = be_to_host16(resp->length);
if (len > respDataLen)
return TRUE;
diff --git a/hostapd/eapol_sm.c b/hostapd/eapol_sm.c
index 2f31203..b0259da 100644
--- a/hostapd/eapol_sm.c
+++ b/hostapd/eapol_sm.c
@@ -1,6 +1,6 @@
/*
* hostapd / IEEE 802.1X Authenticator - EAPOL state machine
- * Copyright (c) 2002-2006, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2002-2007, Jouni Malinen <jkmaline@cc.hut.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -64,7 +64,7 @@ static void eapol_auth_tx_canned_eap(struct eapol_state_machine *sm,
struct eap_hdr *hdr = (struct eap_hdr *) sm->last_eap_radius;
eap.identifier = hdr->identifier + 1;
}
- eap.length = htons(sizeof(eap));
+ eap.length = host_to_be16(sizeof(eap));
hostapd_logger(sm->hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
HOSTAPD_LEVEL_DEBUG, "Sending canned EAP packet %s "
diff --git a/hostapd/hostapd.h b/hostapd/hostapd.h
index 14caee3..90dc0ec 100644
--- a/hostapd/hostapd.h
+++ b/hostapd/hostapd.h
@@ -1,7 +1,7 @@
/*
* hostapd / Initialization and configuration
* Host AP kernel driver
- * Copyright (c) 2002-2006, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2002-2007, Jouni Malinen <jkmaline@cc.hut.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -51,12 +51,12 @@ struct ieee8023_hdr {
struct ieee80211_hdr {
- u16 frame_control;
- u16 duration_id;
+ le16 frame_control;
+ le16 duration_id;
u8 addr1[6];
u8 addr2[6];
u8 addr3[6];
- u16 seq_ctrl;
+ le16 seq_ctrl;
/* followed by 'u8 addr4[6];' if ToDS and FromDS is set in data frame
*/
} STRUCT_PACKED;
diff --git a/hostapd/iapp.c b/hostapd/iapp.c
index 417f019..a7c8f39 100644
--- a/hostapd/iapp.c
+++ b/hostapd/iapp.c
@@ -60,8 +60,8 @@
struct iapp_hdr {
u8 version;
u8 command;
- u16 identifier;
- u16 length;
+ be16 identifier;
+ be16 length;
/* followed by length-6 octets of data */
} __attribute__ ((packed));
@@ -83,7 +83,7 @@ struct iapp_add_notify {
u8 addr_len; /* ETH_ALEN */
u8 reserved;
u8 mac_addr[ETH_ALEN];
- u16 seq_num;
+ be16 seq_num;
} __attribute__ ((packed));
@@ -91,7 +91,7 @@ struct iapp_add_notify {
struct iapp_layer2_update {
u8 da[ETH_ALEN]; /* broadcast */
u8 sa[ETH_ALEN]; /* STA addr */
- u16 len; /* 6 */
+ be16 len; /* 6 */
u8 dsap; /* null DSAP address */
u8 ssap; /* null SSAP address, CR=Response */
u8 control;
diff --git a/hostapd/ieee802_11_defs.h b/hostapd/ieee802_11_defs.h
index 6474a16..e9025aa 100644
--- a/hostapd/ieee802_11_defs.h
+++ b/hostapd/ieee802_11_defs.h
@@ -1,6 +1,6 @@
/*
* IEEE 802.11 Frame type definitions
- * Copyright (c) 2002-2006, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2002-2007, Jouni Malinen <jkmaline@cc.hut.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -195,50 +195,50 @@
#endif /* _MSC_VER */
struct ieee80211_mgmt {
- u16 frame_control;
- u16 duration;
+ le16 frame_control;
+ le16 duration;
u8 da[6];
u8 sa[6];
u8 bssid[6];
- u16 seq_ctrl;
+ le16 seq_ctrl;
union {
struct {
- u16 auth_alg;
- u16 auth_transaction;
- u16 status_code;
+ le16 auth_alg;
+ le16 auth_transaction;
+ le16 status_code;
/* possibly followed by Challenge text */
u8 variable[0];
} STRUCT_PACKED auth;
struct {
- u16 reason_code;
+ le16 reason_code;
} STRUCT_PACKED deauth;
struct {
- u16 capab_info;
- u16 listen_interval;
+ le16 capab_info;
+ le16 listen_interval;
/* followed by SSID and Supported rates */
u8 variable[0];
} STRUCT_PACKED assoc_req;
struct {
- u16 capab_info;
- u16 status_code;
- u16 aid;
+ le16 capab_info;
+ le16 status_code;
+ le16 aid;
/* followed by Supported rates */
u8 variable[0];
} STRUCT_PACKED assoc_resp, reassoc_resp;
struct {
- u16 capab_info;
- u16 listen_interval;
+ le16 capab_info;
+ le16 listen_interval;
u8 current_ap[6];
/* followed by SSID and Supported rates */
u8 variable[0];
} STRUCT_PACKED reassoc_req;
struct {
- u16 reason_code;
+ le16 reason_code;
} STRUCT_PACKED disassoc;
struct {
u8 timestamp[8];
- u16 beacon_int;
- u16 capab_info;
+ le16 beacon_int;
+ le16 capab_info;
/* followed by some of SSID, Supported rates,
* FH Params, DS Params, CF Params, IBSS Params, TIM */
u8 variable[0];
@@ -249,8 +249,8 @@ struct ieee80211_mgmt {
} STRUCT_PACKED probe_req;
struct {
u8 timestamp[8];
- u16 beacon_int;
- u16 capab_info;
+ le16 beacon_int;
+ le16 capab_info;
/* followed by some of SSID, Supported rates,
* FH Params, DS Params, CF Params, IBSS Params */
u8 variable[0];
diff --git a/hostapd/ieee802_1x.c b/hostapd/ieee802_1x.c
index f091e0e..ab19b0a 100644
--- a/hostapd/ieee802_1x.c
+++ b/hostapd/ieee802_1x.c
@@ -1,6 +1,6 @@
/*
* hostapd / IEEE 802.1X Authenticator
- * Copyright (c) 2002-2006, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2002-2007, Jouni Malinen <jkmaline@cc.hut.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -67,7 +67,7 @@ static void ieee802_1x_send(struct hostapd_data *hapd, struct sta_info *sta,
xhdr = (struct ieee802_1x_hdr *) buf;
xhdr->version = hapd->conf->eapol_version;
xhdr->type = type;
- xhdr->length = htons(datalen);
+ xhdr->length = host_to_be16(datalen);
if (datalen > 0 && data != NULL)
memcpy(xhdr + 1, data, datalen);
@@ -161,7 +161,7 @@ void ieee802_1x_request_identity(struct hostapd_data *hapd,
eap = (struct eap_hdr *) buf;
eap->code = EAP_CODE_REQUEST;
eap->identifier = ++sm->currentId;
- eap->length = htons(tlen);
+ eap->length = host_to_be16(tlen);
pos = (u8 *) (eap + 1);
*pos++ = EAP_TYPE_IDENTITY;
if (hapd->conf->eap_req_id_text) {
@@ -247,7 +247,7 @@ static void ieee802_1x_tx_key_one(struct hostapd_data *hapd,
* in ieee802_1x_send() */
hdr->version = hapd->conf->eapol_version;
hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
- hdr->length = htons(len);
+ hdr->length = host_to_be16(len);
hmac_md5(sm->eapol_key_sign, sm->eapol_key_sign_len,
buf, sizeof(*hdr) + len,
key->key_signature);
@@ -654,7 +654,7 @@ static void handle_eap_response(struct hostapd_data *hapd,
hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
"id=%d len=%d) from STA: EAP Response-%s (%d)",
- eap->code, eap->identifier, ntohs(eap->length),
+ eap->code, eap->identifier, be_to_host16(eap->length),
eap_type_text(type), type);
if (type == EAP_TYPE_IDENTITY) {
@@ -711,7 +711,7 @@ static void handle_eap(struct hostapd_data *hapd, struct sta_info *sta,
eap = (struct eap_hdr *) buf;
- eap_len = ntohs(eap->length);
+ eap_len = be_to_host16(eap->length);
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
" EAP: code=%d identifier=%d length=%d",
eap->code, eap->identifier, eap_len);
@@ -777,7 +777,7 @@ void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
}
hdr = (struct ieee802_1x_hdr *) buf;
- datalen = ntohs(hdr->length);
+ datalen = be_to_host16(hdr->length);
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
" IEEE 802.1X: version=%d type=%d length=%d\n",
hdr->version, hdr->type, datalen);
@@ -1091,7 +1091,8 @@ static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
HOSTAPD_LEVEL_DEBUG, "decapsulated EAP packet (code=%d "
"id=%d len=%d) from RADIUS server: %s",
- hdr->code, hdr->identifier, ntohs(hdr->length), buf);
+ hdr->code, hdr->identifier, be_to_host16(hdr->length),
+ buf);
sm->eapReq = TRUE;
free(sm->last_eap_radius);
@@ -1707,7 +1708,7 @@ int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "IEEE 802.1X: " MACSTR
" TX status - version=%d type=%d length=%d - ack=%d\n",
MAC2STR(sta->addr), xhdr->version, xhdr->type,
- ntohs(xhdr->length), ack);
+ be_to_host16(xhdr->length), ack);
/* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant
* or Authenticator state machines, but EAPOL-Key packets are not
diff --git a/hostapd/radius_server.c b/hostapd/radius_server.c
index e591ce3..a23c837 100644
--- a/hostapd/radius_server.c
+++ b/hostapd/radius_server.c
@@ -1,6 +1,6 @@
/*
* hostapd / RADIUS authentication server
- * Copyright (c) 2005-2006, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2005-2007, Jouni Malinen <jkmaline@cc.hut.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -387,7 +387,7 @@ static int radius_server_reject(struct radius_server_data *data,
memset(&eapfail, 0, sizeof(eapfail));
eapfail.code = EAP_CODE_FAILURE;
eapfail.identifier = 0;
- eapfail.length = htons(sizeof(eapfail));
+ eapfail.length = host_to_be16(sizeof(eapfail));
if (!radius_msg_add_eap(msg, (u8 *) &eapfail, sizeof(eapfail))) {
RADIUS_DEBUG("Failed to add EAP-Message attribute");
@@ -511,7 +511,7 @@ static int radius_server_request(struct radius_server_data *data,
hdr = wpa_zalloc(sizeof(*hdr));
if (hdr) {
hdr->identifier = resp_id;
- hdr->length = htons(sizeof(*hdr));
+ hdr->length = host_to_be16(sizeof(*hdr));
sess->eapReqData = (u8 *) hdr;
sess->eapReqDataLen = sizeof(*hdr);
}
diff --git a/hostapd/wme.h b/hostapd/wme.h
index 367bb80..d233b10 100644
--- a/hostapd/wme.h
+++ b/hostapd/wme.h
@@ -88,7 +88,7 @@ struct wme_ac_parameter {
#endif
/* bytes 3 & 4 */
- u16 txopLimit;
+ le16 txopLimit;
} __attribute__ ((packed));
struct wme_parameter_element {
diff --git a/hostapd/wpa.c b/hostapd/wpa.c
index c2987ca..ae18a0d 100644
--- a/hostapd/wpa.c
+++ b/hostapd/wpa.c
@@ -926,7 +926,7 @@ void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
return;
hdr->version = wpa_auth->conf.eapol_version;
hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
- hdr->length = htons(len - sizeof(*hdr));
+ hdr->length = host_to_be16(len - sizeof(*hdr));
key = (struct wpa_eapol_key *) (hdr + 1);
key->type = sm->wpa == WPA_VERSION_WPA2 ?
diff --git a/hostapd/wpa_common.h b/hostapd/wpa_common.h
index 9bdbf73..f35db75 100644
--- a/hostapd/wpa_common.h
+++ b/hostapd/wpa_common.h
@@ -39,7 +39,7 @@
struct ieee802_1x_hdr {
u8 version;
u8 type;
- u16 length;
+ be16 length;
/* followed by length octets of data */
} STRUCT_PACKED;
@@ -202,8 +202,8 @@ enum {
#endif /* CONFIG_PEERKEY */
struct rsn_error_kde {
- u16 mui;
- u16 error_type;
+ be16 mui;
+ be16 error_type;
} STRUCT_PACKED;
#ifdef CONFIG_IEEE80211W