summaryrefslogtreecommitdiff
path: root/lib/bluetooth.h
diff options
context:
space:
mode:
authorAndrei Emeltchenko <andrei.emeltchenko@intel.com>2011-10-24 12:20:04 +0300
committerJohan Hedberg <johan.hedberg@intel.com>2011-10-25 10:07:58 +0200
commit41ccb16f6c95c73468fd0d526b06388643754df4 (patch)
tree849f53da5f48b72023b38102130197fc5ffa3c99 /lib/bluetooth.h
parent7bcf9638e863effd002741d7bf0f72c18fd565a4 (diff)
downloadbluez-41ccb16f6c95c73468fd0d526b06388643754df4.tar.gz
Add get_le/get_be helpers
Helpers to access LE / BE values. In different Bluetooth protocols/profiles there is a mixture of LE / BE byte order.
Diffstat (limited to 'lib/bluetooth.h')
-rw-r--r--lib/bluetooth.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index b0680e28f..5bd4f03df 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -125,6 +125,70 @@ do { \
__p->__v = (val); \
} while(0)
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+static inline uint64_t bt_get_le64(void *ptr)
+{
+ return bt_get_unaligned((uint64_t *) ptr);
+}
+
+static inline uint64_t bt_get_be64(void *ptr)
+{
+ return bswap_64(bt_get_unaligned((uint64_t *) ptr));
+}
+
+static inline uint32_t bt_get_le32(void *ptr)
+{
+ return bt_get_unaligned((uint32_t *) ptr);
+}
+
+static inline uint32_t bt_get_be32(void *ptr)
+{
+ return bswap_32(bt_get_unaligned((uint32_t *) ptr));
+}
+
+static inline uint16_t bt_get_le16(void *ptr)
+{
+ return bt_get_unaligned((uint16_t *) ptr);
+}
+
+static inline uint16_t bt_get_be16(void *ptr)
+{
+ return bswap_16(bt_get_unaligned((uint16_t *) ptr));
+}
+#elif __BYTE_ORDER == __BIG_ENDIAN
+static inline uint64_t bt_get_le64(void *ptr)
+{
+ return bswap_64(bt_get_unaligned((uint64_t *) ptr));
+}
+
+static inline uint64_t bt_get_be64(void *ptr)
+{
+ return bt_get_unaligned((uint64_t *) ptr);
+}
+
+static inline uint32_t bt_get_le32(void *ptr)
+{
+ return bswap_32(bt_get_unaligned((uint32_t *) ptr));
+}
+
+static inline uint32_t bt_get_be32(void *ptr)
+{
+ return bt_get_unaligned((uint32_t *) ptr);
+}
+
+static inline uint16_t bt_get_le16(void *ptr)
+{
+ return bswap_16(bt_get_unaligned((uint16_t *) ptr));
+}
+
+static inline uint16_t bt_get_be16(void *ptr)
+{
+ return bt_get_unaligned((uint16_t *) ptr);
+}
+#else
+#error "Unknown byte order"
+#endif
+
/* BD Address */
typedef struct {
uint8_t b[6];