summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-08-12 14:54:06 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-08-13 17:21:56 +0200
commit05dc94529b1a8f7c65c8aebbf8081d1d1f3aa96a (patch)
treeeba72249447d6e2a3f28ed5b2cbfb351a0bc2053
parent81b3178cede7fad5360755a1186071548d139198 (diff)
Remove libbluetooth system header dependencies from BTLE code base
Change-Id: I44c2ba2308a786b1ed67a9f89701c2d18fe64f6b Reviewed-by: Ulf Hermann <ulf.hermann@digia.com>
-rw-r--r--src/bluetooth/bluez/bluez_data_p.h86
-rw-r--r--src/bluetooth/qlowenergycontroller_bluez.cpp18
2 files changed, 94 insertions, 10 deletions
diff --git a/src/bluetooth/bluez/bluez_data_p.h b/src/bluetooth/bluez/bluez_data_p.h
index 822f53b9..70b80ec3 100644
--- a/src/bluetooth/bluez/bluez_data_p.h
+++ b/src/bluetooth/bluez/bluez_data_p.h
@@ -44,6 +44,7 @@
#include <QtCore/qglobal.h>
#include <sys/socket.h>
+#include <QtBluetooth/QBluetoothUuid>
#define BTPROTO_L2CAP 0
#define BTPROTO_RFCOMM 3
@@ -64,6 +65,27 @@
#define L2CAP_LM_TRUSTED 0x0008
#define L2CAP_LM_SECURE 0x0020
+#define BDADDR_LE_PUBLIC 0x01
+
+/* Byte order conversions */
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define htobs(d) (d)
+#define htobl(d) (d)
+#define htobll(d) (d)
+#define btohs(d) (d)
+#define btohl(d) (d)
+#define btohll(d) (d)
+#elif __BYTE_ORDER == __BIG_ENDIAN
+#define htobs(d) bswap_16(d)
+#define htobl(d) bswap_32(d)
+#define htobll(d) bswap_64(d)
+#define btohs(d) bswap_16(d)
+#define btohl(d) bswap_32(d)
+#define btohll(d) bswap_64(d)
+#else
+#error "Unknown byte order"
+#endif
+
// Bluetooth address
typedef struct {
quint8 b[6];
@@ -75,6 +97,9 @@ struct sockaddr_l2 {
unsigned short l2_psm;
bdaddr_t l2_bdaddr;
unsigned short l2_cid;
+#if !defined(QT_BLUEZ_NO_BTLE)
+ quint8 l2_bdaddr_type;
+#endif
};
// RFCOMM socket
@@ -84,4 +109,65 @@ struct sockaddr_rc {
quint8 rc_channel;
};
+// Bt Low Energy related
+
+#define bt_get_unaligned(ptr) \
+({ \
+ struct __attribute__((packed)) { \
+ __typeof__(*(ptr)) __v; \
+ } *__p = (__typeof__(__p)) (ptr); \
+ __p->__v; \
+})
+
+#define bt_put_unaligned(val, ptr) \
+do { \
+ struct __attribute__((packed)) { \
+ __typeof__(*(ptr)) __v; \
+ } *__p = (__typeof__(__p)) (ptr); \
+ __p->__v = (val); \
+} while (0)
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+
+static inline void btoh128(const quint128 *src, quint128 *dst)
+{
+ memcpy(dst, src, sizeof(quint128));
+}
+
+static inline void ntoh128(const quint128 *src, quint128 *dst)
+{
+ int i;
+
+ for (i = 0; i < 16; i++)
+ dst->data[15 - i] = src->data[i];
+}
+
+static inline uint16_t bt_get_le16(const void *ptr)
+{
+ return bt_get_unaligned((const uint16_t *) ptr);
+}
+#elif __BYTE_ORDER == __BIG_ENDIAN
+static inline uint16_t bt_get_le16(const void *ptr)
+{
+ return bswap_16(bt_get_unaligned((const uint16_t *) ptr));
+}
+
+static inline void btoh128(const quint128 *src, quint128 *dst)
+{
+ int i;
+
+ for (i = 0; i < 16; i++)
+ dst->data[15 - i] = src->data[i];
+}
+
+static inline void ntoh128(const quint128 *src, quint128 *dst)
+{
+ memcpy(dst, src, sizeof(quint128));
+}
+#else
+#error "Unknown byte order"
+#endif
+
+#define hton128(x, y) ntoh128(x, y)
+
#endif // BLUEZ_DATA_P_H
diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp
index fe0ae9f2..dcb99736 100644
--- a/src/bluetooth/qlowenergycontroller_bluez.cpp
+++ b/src/bluetooth/qlowenergycontroller_bluez.cpp
@@ -42,14 +42,12 @@
#include "qlowenergycontroller_p.h"
#include "qbluetoothsocket_p.h"
+#include "bluez/bluez_data_p.h"
#include <QtCore/QLoggingCategory>
#include <QtBluetooth/QBluetoothSocket>
#include <QtBluetooth/QLowEnergyService>
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/l2cap.h>
-
#define ATTRIBUTE_CHANNEL_ID 4
#define ATT_DEFAULT_LE_MTU 23
@@ -115,9 +113,9 @@ QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_BLUEZ)
-static inline QBluetoothUuid convert_uuid128(const uint128_t *p)
+static inline QBluetoothUuid convert_uuid128(const quint128 *p)
{
- uint128_t dst_hostOrder, dst_bigEndian;
+ quint128 dst_hostOrder, dst_bigEndian;
// Bluetooth LE data comes as little endian
// uuids are constructed using high endian
@@ -126,7 +124,7 @@ static inline QBluetoothUuid convert_uuid128(const uint128_t *p)
// convert to Qt's own data type
quint128 qtdst;
- memcpy(&qtdst, &dst_bigEndian, sizeof(uint128_t));
+ memcpy(&qtdst, &dst_bigEndian, sizeof(quint128));
return QBluetoothUuid(qtdst);
}
@@ -379,7 +377,7 @@ QLowEnergyHandle parseReadByTypeCharDiscovery(
if (elementLength == 7) // 16 bit uuid
charData->uuid = QBluetoothUuid(bt_get_le16(&data[5]));
else
- charData->uuid = convert_uuid128((uint128_t *)&data[5]);
+ charData->uuid = convert_uuid128((quint128 *)&data[5]);
qCDebug(QT_BT_BLUEZ) << "Found handle:" << hex << attributeHandle
<< "properties:" << charData->properties
@@ -407,7 +405,7 @@ QLowEnergyHandle parseReadByTypeIncludeDiscovery(
if (elementLength == 8) //16 bit uuid
foundServices->append(QBluetoothUuid(bt_get_le16(&data[6])));
else
- foundServices->append(convert_uuid128((uint128_t *) &data[6]));
+ foundServices->append(convert_uuid128((quint128 *) &data[6]));
qCDebug(QT_BT_BLUEZ) << "Found included service: " << hex
<< attributeHandle << "uuid:" << *foundServices;
@@ -478,7 +476,7 @@ void QLowEnergyControllerPrivate::processReply(
if (elementLength == 6) //16 bit uuid
uuid = QBluetoothUuid(bt_get_le16(&data[offset+4]));
else if (elementLength == 20) //128 bit uuid
- uuid = convert_uuid128((uint128_t *)&data[offset+4]);
+ uuid = convert_uuid128((quint128 *)&data[offset+4]);
//else -> do nothing
offset += elementLength;
@@ -715,7 +713,7 @@ void QLowEnergyControllerPrivate::processReply(
if (format == 0x01)
uuid = QBluetoothUuid(bt_get_le16(&data[offset+2]));
else if (format == 0x02)
- uuid = convert_uuid128((uint128_t *)&data[offset+2]);
+ uuid = convert_uuid128((quint128 *)&data[offset+2]);
offset += elementLength;