From afa1f268d5275e134566924a84e05ce631396cdb Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 6 Dec 2011 14:55:46 +0000 Subject: [PATCH] adding GNUnet endian operations --- src/include/gnunet_common.h | 39 +++++++++++++++++++ src/transport/gnunet-transport-wlan-helper.c | 41 ++++++-------------- src/transport/gnunet_wlan_sender.c | 2 +- src/transport/plugin_transport_wlan.c | 2 +- 4 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 7eed22fdc..167187c23 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -72,6 +72,45 @@ #define GNUNET_MAX(a,b) (((a) > (b)) ? (a) : (b)) +/** + * Endian operations + */ + +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define GNUNET_htobe16(x) __bswap_16 (x) +# define GNUNET_htole16(x) (x) +# define GNUNET_be16toh(x) __bswap_16 (x) +# define GNUNET_le16toh(x) (x) + +# define GNUNET_htobe32(x) __bswap_32 (x) +# define GNUNET_htole32(x) (x) +# define GNUNET_be32toh(x) __bswap_32 (x) +# define GNUNET_le32toh(x) (x) + +# define GNUNET_htobe64(x) __bswap_64 (x) +# define GNUNET_htole64(x) (x) +# define GNUNET_be64toh(x) __bswap_64 (x) +# define GNUNET_le64toh(x) (x) +# if __BYTE_ORDER == __BIG_ENDIAN +# define GNUNET_htobe16(x) (x) +# define GNUNET_htole16(x) __bswap_16 (x) +# define GNUNET_be16toh(x) (x) +# define GNUNET_le16toh(x) __bswap_16 (x) + +# define GNUNET_htobe32(x) (x) +# define GNUNET_htole32(x) __bswap_32 (x) +# define GNUNET_be32toh(x) (x) +# define GNUNET_le32toh(x) __bswap_32 (x) + +# define GNUNET_htobe64(x) (x) +# define GNUNET_htole64(x) __bswap_64 (x) +# define GNUNET_be64toh(x) (x) +# define GNUNET_le64toh(x) __bswap_64 (x) +# endif +#endif + + + /** * gcc-ism to get packed structs. */ diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index ca4542f1a..f4798c2d9 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c @@ -96,7 +96,6 @@ #include #include #include -#include #include #include @@ -399,24 +398,6 @@ struct Hardware_Infos (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) )) /* *INDENT-ON* */ -#ifndef htole16 -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define htole16(x) (x) -#define le16toh(x) (x) -#define htole32(x) (x) -#define le32toh(x) (x) -#define htole64(x) (x) -#define le64toh(x) (x) -#else -#define htole16(x) ___my_swab16 (x) -#define le16toh(x) ___my_swab16 (x) -#define htole32(x) ___my_swab32 (x) -#define le32toh(x) ___my_swab32 (x) -#define htole64(x) ___my_swab64 (x) -#define le64toh(x) ___my_swab64 (x) -#endif -#endif - /** * struct ieee80211_radiotap_iterator - tracks walk through present radiotap args @@ -494,13 +475,13 @@ ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator, /* sanity check for allowed length and radiotap length field */ - if (max_length < (le16toh (radiotap_header->it_len))) + if (max_length < (GNUNET_le16toh (radiotap_header->it_len))) return (-EINVAL); iterator->rtheader = radiotap_header; - iterator->max_length = le16toh (radiotap_header->it_len); + iterator->max_length = GNUNET_le16toh (radiotap_header->it_len); iterator->arg_index = 0; - iterator->bitmap_shifter = le32toh (radiotap_header->it_present); + iterator->bitmap_shifter = GNUNET_le32toh (radiotap_header->it_present); iterator->arg = ((uint8_t *) radiotap_header) + sizeof (struct ieee80211_radiotap_header); iterator->this_arg = 0; @@ -509,7 +490,7 @@ ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator, if ((iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) { - while (le32toh (*((uint32_t *) iterator->arg)) & + while (GNUNET_le32toh (*((uint32_t *) iterator->arg)) & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK) { iterator->arg += sizeof (uint32_t); @@ -670,7 +651,7 @@ next_entry: { /* b31 was set, there is more */ /* move to next uint32_t bitmap */ - iterator->bitmap_shifter = le32toh (*iterator->next_bitmap); + iterator->bitmap_shifter = GNUNET_le32toh (*iterator->next_bitmap); iterator->next_bitmap++; } else @@ -963,7 +944,7 @@ linux_read (struct Hardware_Infos *dev, unsigned char *buf, size_t buf_size, { case IEEE80211_RADIOTAP_TSFT: - ri->ri_mactime = le64toh (*((uint64_t *) iterator.this_arg)); + ri->ri_mactime = GNUNET_le64toh (*((uint64_t *) iterator.this_arg)); break; case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: @@ -1043,7 +1024,7 @@ linux_read (struct Hardware_Infos *dev, unsigned char *buf, size_t buf_size, break; } } - n = le16toh (rthdr->it_len); + n = GNUNET_le16toh (rthdr->it_len); if (n <= 0 || n >= caplen) return 0; } @@ -1285,12 +1266,12 @@ stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) struct RadioTapheader rtheader; rtheader.header.it_version = 0; - rtheader.header.it_len = htole16 (0x0c); - rtheader.header.it_present = htole32 (0x00008004); + rtheader.header.it_len = GNUNET_htole16 (0x0c); + rtheader.header.it_present = GNUNET_le16toh (0x00008004); rtheader.rate = 0x00; rtheader.pad1 = 0x00; rtheader.txflags = - htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ); + GNUNET_htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ); /* { 0x00, 0x00, <-- radiotap version * 0x0c, 0x00, <- radiotap header length @@ -1321,7 +1302,7 @@ stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) exit (1); } - rtheader.header.it_len = htole16 (sizeof (rtheader)); + rtheader.header.it_len = GNUNET_htole16 (sizeof (rtheader)); rtheader.rate = header->rate; memcpy (write_pout->buf, &rtheader, sizeof (rtheader)); memcpy (write_pout->buf + sizeof (rtheader), &header[1], sendsize); diff --git a/src/transport/gnunet_wlan_sender.c b/src/transport/gnunet_wlan_sender.c index 48151550a..db9d74483 100644 --- a/src/transport/gnunet_wlan_sender.c +++ b/src/transport/gnunet_wlan_sender.c @@ -111,7 +111,7 @@ getWlanHeader (struct ieee80211_frame *Header, const char *to_mac_addr, memcpy (&Header->i_addr1, to_mac_addr, sizeof (mac_bssid)); tmp16 = (uint16_t *) Header->i_dur; - *tmp16 = (uint16_t) htole16 ((size * 1000000) / rate + 290); + *tmp16 = (uint16_t) GNUNET_htole16 ((size * 1000000) / rate + 290); Header->llc[0] = WLAN_LLC_DSAP_FIELD; Header->llc[1] = WLAN_LLC_SSAP_FIELD; diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index bf5411d59..b5961ae38 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -1320,7 +1320,7 @@ getWlanHeader (struct ieee80211_frame *Header, memcpy (&Header->i_addr1, to_mac_addr, sizeof (struct MacAddress)); tmp16 = (uint16_t *) Header->i_dur; - *tmp16 = (uint16_t) htole16 ((size * 1000000) / rate + 290); + *tmp16 = (uint16_t) GNUNET_htole16 ((size * 1000000) / rate + 290); Header->llc[0] = WLAN_LLC_DSAP_FIELD; Header->llc[1] = WLAN_LLC_SSAP_FIELD; -- 2.25.1