diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2015-03-02 13:31:23 +0200 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2015-03-02 14:27:21 +0200 |
commit | 232015aeefd1c945ccfaf9744e791c5888eafcf7 (patch) | |
tree | 779f4118ca01050143a403e9c1ad89bf67573377 /lib/bluetooth.h | |
parent | db6e9fcc192d1a7fb932522899ccb96a4c37e0b4 (diff) | |
download | bluez-232015aeefd1c945ccfaf9744e791c5888eafcf7.tar.gz |
lib/uuid: Fix bt_uuid_to_le for 128 Bits
The convention is that 128 Bits are always defined in big endian format
therefore the bytes always needs to be swapped.
Diffstat (limited to 'lib/bluetooth.h')
-rw-r--r-- | lib/bluetooth.h | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/bluetooth.h b/lib/bluetooth.h index f214d81e2..6ca64b68d 100644 --- a/lib/bluetooth.h +++ b/lib/bluetooth.h @@ -343,6 +343,16 @@ typedef struct { uint8_t data[16]; } uint128_t; +static inline void bswap_128(const void *src, void *dst) +{ + const uint8_t *s = src; + uint8_t *d = dst; + int i; + + for (i = 0; i < 16; i++) + d[15 - i] = s[i]; +} + #if __BYTE_ORDER == __BIG_ENDIAN #define ntoh64(x) (x) @@ -354,10 +364,7 @@ static inline void ntoh128(const uint128_t *src, uint128_t *dst) static inline void btoh128(const uint128_t *src, uint128_t *dst) { - int i; - - for (i = 0; i < 16; i++) - dst->data[15 - i] = src->data[i]; + bswap_128(src, dst); } #else @@ -375,10 +382,7 @@ static inline uint64_t ntoh64(uint64_t n) static inline void ntoh128(const uint128_t *src, uint128_t *dst) { - int i; - - for (i = 0; i < 16; i++) - dst->data[15 - i] = src->data[i]; + bswap_128(src, dst); } static inline void btoh128(const uint128_t *src, uint128_t *dst) |