Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
bluez_data_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef BLUEZ_DATA_P_H
5#define BLUEZ_DATA_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qglobal_p.h>
19#include <QtCore/qendian.h>
20#include <sys/socket.h>
21#include <QtBluetooth/QBluetoothUuid>
22#include <QtCore/qtmetamacros.h>
23
25
26#define ATTRIBUTE_CHANNEL_ID 4
27#define SIGNALING_CHANNEL_ID 5
28#define SECURITY_CHANNEL_ID 6
29
30#define BTPROTO_L2CAP 0
31#define BTPROTO_HCI 1
32#define BTPROTO_RFCOMM 3
33
34#define SOL_HCI 0
35#define SOL_L2CAP 6
36#define SOL_RFCOMM 18
37#ifndef SOL_BLUETOOTH
38#define SOL_BLUETOOTH 274
39#endif
40
41#define RFCOMM_LM 0x03
42
43#define RFCOMM_LM_AUTH 0x0002
44#define RFCOMM_LM_ENCRYPT 0x0004
45#define RFCOMM_LM_TRUSTED 0x0008
46#define RFCOMM_LM_SECURE 0x0020
47
48#define L2CAP_LM 0x03
49#define L2CAP_LM_AUTH 0x0002
50#define L2CAP_LM_ENCRYPT 0x0004
51#define L2CAP_LM_TRUSTED 0x0008
52#define L2CAP_LM_SECURE 0x0020
53
54#define BT_SECURITY 4
59#define BT_SECURITY_SDP 0
60#define BT_SECURITY_LOW 1
61#define BT_SECURITY_MEDIUM 2
62#define BT_SECURITY_HIGH 3
63
64#define BDADDR_LE_PUBLIC 0x01
65#define BDADDR_LE_RANDOM 0x02
66
67#define SCO_LINK 0x00
68#define ACL_LINK 0x01
69#define ESCO_LINK 0x02
70#define LE_LINK 0x80 // based on hcitool.c -> no fixed constant available
71
72/* Byte order conversions */
73#if __BYTE_ORDER == __LITTLE_ENDIAN
74#define htobs(d) (d)
75#define htobl(d) (d)
76#define htobll(d) (d)
77#define btohs(d) (d)
78#define btohl(d) (d)
79#define btohll(d) (d)
80#elif __BYTE_ORDER == __BIG_ENDIAN
81#define htobs(d) qbswap((quint16)(d))
82#define htobl(d) qbswap((quint32)(d))
83#define htobll(d) qbswap((quint64)(d))
84#define btohs(d) qbswap((quint16)(d))
85#define btohl(d) qbswap((quint32)(d))
86#define btohll(d) qbswap((quint64)(d))
87#else
88#error "Unknown byte order"
89#endif
90
91#define HCIGETCONNLIST _IOR('H', 212, int)
92#define HCIGETDEVINFO _IOR('H', 211, int)
93#define HCIGETDEVLIST _IOR('H', 210, int)
94
95// Generic 128 bits of data
97
98// Bluetooth address
99typedef struct {
101} __attribute__((packed)) bdaddr_t;
102
103// L2CP socket
105 sa_family_t l2_family;
106 unsigned short l2_psm;
107 bdaddr_t l2_bdaddr;
108 unsigned short l2_cid;
109#if !defined(QT_BLUEZ_NO_BTLE)
111#endif
112};
113
114// RFCOMM socket
116 sa_family_t rc_family;
117 bdaddr_t rc_bdaddr;
119};
120
121// Bt Low Energy related
122
123template<typename T> inline T getBtData(const void *ptr)
124{
125 return qFromLittleEndian<T>(reinterpret_cast<const uchar *>(ptr));
126}
127
128static inline quint16 bt_get_le16(const void *ptr)
129{
130 return getBtData<quint16>(ptr);
131}
132
133template<typename T> inline void putBtData(T src, void *dst)
134{
135 qToLittleEndian(src, reinterpret_cast<uchar *>(dst));
136}
137
138// HCI related
139
140#define HCI_MAX_DEV 16
141#define HCI_DEV_NONE 0xffff
142
143#define HCI_CHANNEL_CONTROL 0x3
144
145#define HCI_MAX_EVENT_SIZE 260
146
147// HCI sockopts
148#define HCI_FILTER 2
149
150// HCI packet types
151#define HCI_COMMAND_PKT 0x01
152#define HCI_ACL_PKT 0x02
153#define HCI_EVENT_PKT 0x04
154#define HCI_VENDOR_PKT 0xff
155
156#define HCI_FLT_TYPE_BITS 31
157#define HCI_FLT_EVENT_BITS 63
158
159
161 sa_family_t hci_family;
162 unsigned short hci_dev;
163 unsigned short hci_channel;
164};
165
170
175
188
211
220
226
232
233static inline void hci_set_bit(int nr, void *addr)
234{
235 *((quint32 *) addr + (nr >> 5)) |= (1 << (nr & 31));
236}
237static inline void hci_clear_bit(int nr, void *addr)
238{
239 *((quint32 *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
240}
241static inline void hci_filter_clear(struct hci_filter *f)
242{
243 memset(f, 0, sizeof(*f));
244}
245static inline void hci_filter_set_ptype(int t, struct hci_filter *f)
246{
247 hci_set_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
248}
249static inline void hci_filter_clear_ptype(int t, struct hci_filter *f)
250{
251 hci_clear_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
252}
253static inline void hci_filter_set_event(int e, struct hci_filter *f)
254{
255 hci_set_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
256}
257static inline void hci_filter_clear_event(int e, struct hci_filter *f)
258{
259 hci_clear_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
260}
261static inline void hci_filter_all_ptypes(struct hci_filter *f)
262{
263 memset((void *) &f->type_mask, 0xff, sizeof(f->type_mask));
264}
265static inline void hci_filter_all_events(struct hci_filter *f)
266{
267 memset((void *) f->event_mask, 0xff, sizeof(f->event_mask));
268}
269
270typedef struct {
273} __attribute__ ((packed)) hci_event_hdr;
274#define HCI_EVENT_HDR_SIZE 2
275
276typedef struct {
280} __attribute__ ((packed)) evt_encrypt_change;
281#define EVT_ENCRYPT_CHANGE_SIZE 4
282
287
294
299
304
305namespace QBluezConst {
311
323
324 enum class AttCommand : quint8 {
326 ATT_OP_EXCHANGE_MTU_REQUEST = 0x02, //send own mtu
327 ATT_OP_EXCHANGE_MTU_RESPONSE = 0x03, //receive server MTU
328 ATT_OP_FIND_INFORMATION_REQUEST = 0x04, //discover individual attribute info
332 ATT_OP_READ_BY_TYPE_REQUEST = 0x08, //discover characteristics
334 ATT_OP_READ_REQUEST = 0x0A, //read characteristic & descriptor values
336 ATT_OP_READ_BLOB_REQUEST = 0x0C, //read values longer than MTU-1
340 ATT_OP_READ_BY_GROUP_REQUEST = 0x10, //discover services
342 ATT_OP_WRITE_REQUEST = 0x12, //write characteristic with response
344 ATT_OP_PREPARE_WRITE_REQUEST = 0x16, //write values longer than MTU-3 -> queueing
346 ATT_OP_EXECUTE_WRITE_REQUEST = 0x18, //write values longer than MTU-3 -> execute queue
348 ATT_OP_HANDLE_VAL_NOTIFICATION = 0x1b, //informs about value change
349 ATT_OP_HANDLE_VAL_INDICATION = 0x1d, //informs about value change -> requires reply
350 ATT_OP_HANDLE_VAL_CONFIRMATION = 0x1e, //answer for ATT_OP_HANDLE_VAL_INDICATION
351 ATT_OP_WRITE_COMMAND = 0x52, //write characteristic without response
353 };
355
356 enum class AttError : quint8 {
357 ATT_ERROR_NO_ERROR = 0x00,
371 ATT_ERROR_UNLIKELY = 0x0E,
376 //------------------------------------------
377 // The error codes in this block are
378 // implementation specific errors
379
381
382 //------------------------------------------
384 };
386}
387/* Command opcode pack/unpack */
388#define opCodePack(ogf, ocf) (quint16(((ocf) & 0x03ff)|((ogf) << 10)))
389#define ogfFromOpCode(op) ((op) >> 10)
390#define ocfFromOpCode(op) ((op) & 0x03ff)
391
393
394#endif // BLUEZ_DATA_P_H
static void hci_filter_all_ptypes(struct hci_filter *f)
static void hci_filter_all_events(struct hci_filter *f)
#define HCI_FLT_EVENT_BITS
#define HCI_FLT_TYPE_BITS
T getBtData(const void *ptr)
static void hci_filter_set_ptype(int t, struct hci_filter *f)
QUuid::Id128Bytes BluezUint128
static quint16 bt_get_le16(const void *ptr)
static void hci_clear_bit(int nr, void *addr)
static void hci_filter_clear(struct hci_filter *f)
static void hci_filter_clear_ptype(int t, struct hci_filter *f)
#define HCI_VENDOR_PKT
static void hci_set_bit(int nr, void *addr)
void putBtData(T src, void *dst)
static void hci_filter_clear_event(int e, struct hci_filter *f)
struct AclData __attribute__
static void hci_filter_set_event(int e, struct hci_filter *f)
@ OcfLeSetScanResponseData
Combined button and popup list for selecting options.
constexpr T qToLittleEndian(T source)
Definition qendian.h:176
static ControlElement< T > * ptr(QWidget *widget)
GLboolean GLboolean GLboolean b
GLfloat GLfloat f
GLenum src
GLenum GLenum dst
GLuint name
GLenum const void * addr
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint GLenum GLsizei GLsizei GLint GLint GLboolean packed
#define Q_ENUM_NS(x)
#define Q_NAMESPACE
unsigned int quint32
Definition qtypes.h:50
unsigned char uchar
Definition qtypes.h:32
unsigned short quint16
Definition qtypes.h:48
unsigned char quint8
Definition qtypes.h:46
quint16 dataLen
quint16 pbFlag
quint16 handle
quint16 bcFlag
quint16 length
quint16 channelId
quint8 key_size
quint32 link_mode
bdaddr_t bdaddr
struct hci_conn_info conn_info[0]
quint16 acl_pkts
bdaddr_t bdaddr
struct hci_dev_stats stat
quint8 features[8]
quint32 link_mode
quint16 sco_mtu
quint16 sco_pkts
quint16 acl_mtu
quint32 link_policy
quint32 pkt_type
struct hci_dev_req dev_req[0]
quint16 dev_id
quint32 dev_opt
quint32 type_mask
quint16 opcode
quint32 event_mask[2]
sa_family_t hci_family
unsigned short hci_dev
unsigned short hci_channel
unsigned short l2_cid
sa_family_t l2_family
quint8 l2_bdaddr_type
bdaddr_t l2_bdaddr
unsigned short l2_psm
sa_family_t rc_family
quint8 rc_channel
bdaddr_t rc_bdaddr
\inmodule QtCore
Definition quuid.h:58