Hi Eddie,

How's this?

Alastair

On Mon, Feb 23, 2009 at 6:58 PM, Eddie Kohler <[email protected]> wrote:
> Alastair,
>
> I'd like to include something like this, but le32_to_cpu is not a standard
> function, it is probably only defined on Linux?.  If you could resubmit with
> a version that checks for le32_to_cpu and maybe defines a version if it is
> not there, that would be better.
>
> Eddie
>
>
> Alastair McKinley wrote:
>>
>> Hi Eddie,
>>
>> Please consider this patch for Click 1.7.
>>
>> It is a few simple endianness fixes for RadiotapDecap as it is currently
>> broken on big endian.
>>
>> Best regards,
>>
>> Alastair
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> click mailing list
>> [email protected]
>> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>
From 1f2caec6c253e4e430f79acb6521bfb26fb4b2a1 Mon Sep 17 00:00:00 2001
From: Alastair McKinley <[email protected]>
Date: Thu, 26 Feb 2009 18:23:33 +0000
Subject: [PATCH] Add le16-32_to_cpu defs for non-linux

---
 include/click/glue.hh |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/include/click/glue.hh b/include/click/glue.hh
index 6f02ca5..f90910a 100644
--- a/include/click/glue.hh
+++ b/include/click/glue.hh
@@ -538,6 +538,9 @@ CLICK_ENDDECLS
 # define cpu_to_le16(x) bswap_16((x))
 # define le32_to_cpu(x) bswap_32((x))
 # define cpu_to_le32(x) bswap_32((x))
+#elif CLICK_BYTE_ORDER == CLICK_BIG_ENDIAN
+# define le16_to_cpu(x) ((((x) & 0x00ff) <<  8) | (((x) & 0xff00) >> 8))
+# define le32_to_cpu(x) ((((x) & 0x000000ff) << 24) | (((x) & 0x0000ff00) << 8) | (((x) & 0x00ff0000) >> 8 ) | (((x) & 0xff000000) >> 24))
 #else
 /* leave them undefined */
 #endif
-- 
1.5.4.3

From c2eff9508e8d301c6bf0f74a8fab48479a6be837 Mon Sep 17 00:00:00 2001
From: Alastair McKinley <[email protected]>
Date: Thu, 26 Feb 2009 18:22:21 +0000
Subject: [PATCH] radiocapdecap.cc endianness fixes

---
 elements/wifi/radiotapdecap.cc |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/elements/wifi/radiotapdecap.cc b/elements/wifi/radiotapdecap.cc
index 7fc98af..aef3e8e 100644
--- a/elements/wifi/radiotapdecap.cc
+++ b/elements/wifi/radiotapdecap.cc
@@ -54,7 +54,7 @@ static int rt_el_present(struct ieee80211_radiotap_header *th, u_int32_t element
 {
 	if (element > NUM_RADIOTAP_ELEMENTS)
 		return 0;
-	return th->it_present & (1 << element);
+	return le32_to_cpu(th->it_present) & (1 << element);
 }
 
 static int rt_check_header(struct ieee80211_radiotap_header *th, int len)
@@ -65,7 +65,7 @@ static int rt_check_header(struct ieee80211_radiotap_header *th, int len)
 		return 0;
 	}
 
-	if (th->it_len < sizeof(struct ieee80211_radiotap_header)) {
+	if (le16_to_cpu(th->it_len) < sizeof(struct ieee80211_radiotap_header)) {
 		return 0;
 	}
 
@@ -74,11 +74,11 @@ static int rt_check_header(struct ieee80211_radiotap_header *th, int len)
 		    bytes += radiotap_elem_to_bytes[x];
 	}
 
-	if (th->it_len < sizeof(struct ieee80211_radiotap_header) + bytes) {
+	if (le16_to_cpu(th->it_len) < sizeof(struct ieee80211_radiotap_header) + bytes) {
 		return 0;
 	}
 
-	if (th->it_len > len) {
+	if (le16_to_cpu(th->it_len) > len) {
 		return 0;
 	}
 
@@ -141,13 +141,13 @@ RadiotapDecap::simple_action(Packet *p)
 			ceh->silence = *((u_int8_t *) rt_el_offset(th, IEEE80211_RADIOTAP_DB_ANTNOISE));
 
 		if (rt_el_present(th, IEEE80211_RADIOTAP_RX_FLAGS)) {
-			u_int16_t flags = *((u_int16_t *) rt_el_offset(th, IEEE80211_RADIOTAP_RX_FLAGS));
+			u_int16_t flags = le16_to_cpu(*((u_int16_t *) rt_el_offset(th, IEEE80211_RADIOTAP_RX_FLAGS)));
 			if (flags & IEEE80211_RADIOTAP_F_RX_BADFCS)
 				ceh->flags |= WIFI_EXTRA_RX_ERR;
 		}
 
 		if (rt_el_present(th, IEEE80211_RADIOTAP_TX_FLAGS)) {
-			u_int16_t flags = *((u_int16_t *) rt_el_offset(th, IEEE80211_RADIOTAP_TX_FLAGS));
+			u_int16_t flags = le16_to_cpu(*((u_int16_t *) rt_el_offset(th, IEEE80211_RADIOTAP_TX_FLAGS)));
 			ceh->flags |= WIFI_EXTRA_TX;
 			if (flags & IEEE80211_RADIOTAP_F_TX_FAIL)
 				ceh->flags |= WIFI_EXTRA_TX_FAIL;
-- 
1.5.4.3

_______________________________________________
click mailing list
[email protected]
https://amsterdam.lcs.mit.edu/mailman/listinfo/click

Reply via email to