Coverage Report

Created: 2025-07-23 06:31

/src/bluez/lib/bluetooth.h
Line
Count
Source (jump to first uncovered line)
1
/* SPDX-License-Identifier: GPL-2.0-or-later */
2
/*
3
 *
4
 *  BlueZ - Bluetooth protocol stack for Linux
5
 *
6
 *  Copyright (C) 2000-2001  Qualcomm Incorporated
7
 *  Copyright (C) 2002-2003  Maxim Krasnyansky <maxk@qualcomm.com>
8
 *  Copyright (C) 2002-2010  Marcel Holtmann <marcel@holtmann.org>
9
 *  Copyright 2023 NXP
10
 *
11
 *
12
 */
13
14
#ifndef __BLUETOOTH_H
15
#define __BLUETOOTH_H
16
17
#ifdef __cplusplus
18
extern "C" {
19
#endif
20
21
#include <stdio.h>
22
#include <stdint.h>
23
#include <string.h>
24
#include <endian.h>
25
#include <byteswap.h>
26
#include <netinet/in.h>
27
28
#ifndef AF_BLUETOOTH
29
#define AF_BLUETOOTH  31
30
#define PF_BLUETOOTH  AF_BLUETOOTH
31
#endif
32
33
0
#define BTPROTO_L2CAP 0
34
0
#define BTPROTO_HCI 1
35
#define BTPROTO_SCO 2
36
#define BTPROTO_RFCOMM  3
37
#define BTPROTO_BNEP  4
38
#define BTPROTO_CMTP  5
39
#define BTPROTO_HIDP  6
40
#define BTPROTO_AVDTP 7
41
#define BTPROTO_ISO 8
42
43
0
#define SOL_HCI   0
44
0
#define SOL_L2CAP 6
45
#define SOL_SCO   17
46
#define SOL_RFCOMM  18
47
48
#ifndef SOL_BLUETOOTH
49
#define SOL_BLUETOOTH 274
50
#endif
51
52
#define BT_SECURITY 4
53
struct bt_security {
54
  uint8_t level;
55
  uint8_t key_size;
56
};
57
#define BT_SECURITY_SDP   0
58
#define BT_SECURITY_LOW   1
59
#define BT_SECURITY_MEDIUM  2
60
#define BT_SECURITY_HIGH  3
61
#define BT_SECURITY_FIPS  4
62
63
#define BT_DEFER_SETUP  7
64
65
#define BT_FLUSHABLE  8
66
67
#define BT_FLUSHABLE_OFF  0
68
#define BT_FLUSHABLE_ON   1
69
70
#define BT_POWER    9
71
struct bt_power {
72
  uint8_t force_active;
73
};
74
#define BT_POWER_FORCE_ACTIVE_OFF 0
75
#define BT_POWER_FORCE_ACTIVE_ON  1
76
77
#define BT_CHANNEL_POLICY 10
78
79
/* BR/EDR only (default policy)
80
 *   AMP controllers cannot be used.
81
 *   Channel move requests from the remote device are denied.
82
 *   If the L2CAP channel is currently using AMP, move the channel to BR/EDR.
83
 */
84
#define BT_CHANNEL_POLICY_BREDR_ONLY    0
85
86
/* BR/EDR Preferred
87
 *   Allow use of AMP controllers.
88
 *   If the L2CAP channel is currently on AMP, move it to BR/EDR.
89
 *   Channel move requests from the remote device are allowed.
90
 */
91
#define BT_CHANNEL_POLICY_BREDR_PREFERRED 1
92
93
/* AMP Preferred
94
 *   Allow use of AMP controllers
95
 *   If the L2CAP channel is currently on BR/EDR and AMP controller
96
 *     resources are available, initiate a channel move to AMP.
97
 *   Channel move requests from the remote device are allowed.
98
 *   If the L2CAP socket has not been connected yet, try to create
99
 *     and configure the channel directly on an AMP controller rather
100
 *     than BR/EDR.
101
 */
102
#define BT_CHANNEL_POLICY_AMP_PREFERRED   2
103
104
#define BT_VOICE    11
105
struct bt_voice {
106
  uint16_t setting;
107
};
108
109
#define BT_SNDMTU   12
110
#define BT_RCVMTU   13
111
112
#define BT_VOICE_TRANSPARENT      0x0003
113
#define BT_VOICE_CVSD_16BIT     0x0060
114
#define BT_VOICE_TRANSPARENT_16BIT    0x0063
115
116
#define BT_PHY      14
117
118
#define BT_PHY_BR_1M_1SLOT  0x00000001
119
#define BT_PHY_BR_1M_3SLOT  0x00000002
120
#define BT_PHY_BR_1M_5SLOT  0x00000004
121
#define BT_PHY_EDR_2M_1SLOT 0x00000008
122
#define BT_PHY_EDR_2M_3SLOT 0x00000010
123
#define BT_PHY_EDR_2M_5SLOT 0x00000020
124
#define BT_PHY_EDR_3M_1SLOT 0x00000040
125
#define BT_PHY_EDR_3M_3SLOT 0x00000080
126
#define BT_PHY_EDR_3M_5SLOT 0x00000100
127
#define BT_PHY_LE_1M_TX   0x00000200
128
#define BT_PHY_LE_1M_RX   0x00000400
129
#define BT_PHY_LE_2M_TX   0x00000800
130
#define BT_PHY_LE_2M_RX   0x00001000
131
#define BT_PHY_LE_CODED_TX  0x00002000
132
#define BT_PHY_LE_CODED_RX  0x00004000
133
134
#define BT_MODE     15
135
136
#define BT_MODE_BASIC   0x00
137
#define BT_MODE_ERTM    0x01
138
#define BT_MODE_STREAMING 0x02
139
#define BT_MODE_LE_FLOWCTL  0x03
140
#define BT_MODE_EXT_FLOWCTL 0x04
141
142
#define BT_PKT_STATUS   16
143
144
#define BT_SCM_PKT_STATUS 0x03
145
#define BT_SCM_ERROR    0x04
146
147
#define BT_ISO_QOS    17
148
149
#define BT_ISO_QOS_CIG_UNSET  0xff
150
#define BT_ISO_QOS_CIS_UNSET  0xff
151
152
#define BT_ISO_QOS_BIG_UNSET  0xff
153
#define BT_ISO_QOS_BIS_UNSET  0xff
154
155
#define BT_ISO_SYNC_TIMEOUT 0x07d0 /* 20 secs */
156
157
/* For an ISO Broadcaster, this value is used to compute
158
 * the desired Periodic Advertising Interval as a function
159
 * of SDU interval, based on the formula:
160
 *
161
 * PA_Interval = SDU_Interval * sync_factor
162
 *
163
 * This is useful for adjusting how frequent to send PA
164
 * announcements for Broadcast Sinks to discover, depending
165
 * on scenario.
166
 */
167
#define BT_ISO_SYNC_FACTOR  0x01
168
169
#define BT_ISO_QOS_GROUP_UNSET  0xff
170
#define BT_ISO_QOS_STREAM_UNSET 0xff
171
172
struct bt_iso_io_qos {
173
  uint32_t interval;
174
  uint16_t latency;
175
  uint16_t sdu;
176
  uint8_t  phy;
177
  uint8_t  rtn;
178
};
179
180
struct bt_iso_ucast_qos {
181
  uint8_t  cig;
182
  uint8_t  cis;
183
  uint8_t  sca;
184
  uint8_t  packing;
185
  uint8_t  framing;
186
  struct bt_iso_io_qos in;
187
  struct bt_iso_io_qos out;
188
};
189
190
struct bt_iso_bcast_qos {
191
  uint8_t  big;
192
  uint8_t  bis;
193
  uint8_t  sync_factor;
194
  uint8_t  packing;
195
  uint8_t  framing;
196
  struct bt_iso_io_qos in;
197
  struct bt_iso_io_qos out;
198
  uint8_t  encryption;
199
  uint8_t  bcode[16];
200
  uint8_t  options;
201
  uint16_t skip;
202
  uint16_t sync_timeout;
203
  uint8_t  sync_cte_type;
204
  uint8_t  mse;
205
  uint16_t timeout;
206
};
207
208
/* (HCI_MAX_PER_AD_LENGTH - EIR_SERVICE_DATA_LENGTH) */
209
#define BASE_MAX_LENGTH 248
210
struct bt_iso_base {
211
  uint8_t base_len;
212
  uint8_t base[BASE_MAX_LENGTH];
213
};
214
215
struct bt_iso_qos {
216
  union {
217
    struct bt_iso_ucast_qos ucast;
218
    struct bt_iso_bcast_qos bcast;
219
  };
220
};
221
222
#define BT_CODEC    19
223
struct bt_codec {
224
  uint8_t id;
225
  uint16_t cid;
226
  uint16_t vid;
227
  uint8_t data_path_id;
228
  uint8_t num_caps;
229
  struct codec_caps {
230
    uint8_t len;
231
    uint8_t data[];
232
  } caps[];
233
} __attribute__((packed));
234
235
struct bt_codecs {
236
  uint8_t num_codecs;
237
  struct bt_codec codecs[];
238
} __attribute__((packed));
239
240
241
/* Connection and socket states */
242
enum {
243
  BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
244
  BT_OPEN,
245
  BT_BOUND,
246
  BT_LISTEN,
247
  BT_CONNECT,
248
  BT_CONNECT2,
249
  BT_CONFIG,
250
  BT_DISCONN,
251
  BT_CLOSED
252
};
253
254
#define BT_ISO_BASE   20
255
256
#define BT_PKT_SEQNUM   22
257
258
#define BT_SCM_PKT_SEQNUM 0x05
259
260
/* Byte order conversions */
261
#if __BYTE_ORDER == __LITTLE_ENDIAN
262
0
#define htobs(d)  (d)
263
#define htobl(d)  (d)
264
#define htobll(d) (d)
265
0
#define btohs(d)  (d)
266
#define btohl(d)  (d)
267
#define btohll(d) (d)
268
#elif __BYTE_ORDER == __BIG_ENDIAN
269
#define htobs(d)  bswap_16(d)
270
#define htobl(d)  bswap_32(d)
271
#define htobll(d) bswap_64(d)
272
#define btohs(d)  bswap_16(d)
273
#define btohl(d)  bswap_32(d)
274
#define btohll(d) bswap_64(d)
275
#else
276
#error "Unknown byte order"
277
#endif
278
279
/* Bluetooth unaligned access */
280
3.77k
#define bt_get_unaligned(ptr)     \
281
3.77k
__extension__ ({        \
282
3.77k
  struct __attribute__((packed)) {  \
283
3.77k
    __typeof__(*(ptr)) __v;   \
284
3.77k
  } *__p = (__typeof__(__p)) (ptr); \
285
3.77k
  __p->__v;       \
286
3.77k
})
287
288
0
#define bt_put_unaligned(val, ptr)    \
289
0
do {           \
290
0
  struct __attribute__((packed)) {  \
291
0
    __typeof__(*(ptr)) __v;   \
292
0
  } *__p = (__typeof__(__p)) (ptr); \
293
0
  __p->__v = (val);     \
294
0
} while(0)
295
296
#if __BYTE_ORDER == __LITTLE_ENDIAN
297
static inline uint64_t bt_get_le64(const void *ptr)
298
0
{
299
0
  return bt_get_unaligned((const uint64_t *) ptr);
300
0
}
Unexecuted instantiation: util.c:bt_get_le64
Unexecuted instantiation: fuzz_sdp.c:bt_get_le64
Unexecuted instantiation: sdp.c:bt_get_le64
Unexecuted instantiation: bluetooth.c:bt_get_le64
Unexecuted instantiation: hci.c:bt_get_le64
Unexecuted instantiation: fuzz_xml.c:bt_get_le64
Unexecuted instantiation: fuzz_hci.c:bt_get_le64
301
302
static inline uint64_t bt_get_be64(const void *ptr)
303
1.09k
{
304
1.09k
  return bswap_64(bt_get_unaligned((const uint64_t *) ptr));
305
1.09k
}
Unexecuted instantiation: util.c:bt_get_be64
Unexecuted instantiation: fuzz_sdp.c:bt_get_be64
sdp.c:bt_get_be64
Line
Count
Source
303
1.09k
{
304
1.09k
  return bswap_64(bt_get_unaligned((const uint64_t *) ptr));
305
1.09k
}
Unexecuted instantiation: bluetooth.c:bt_get_be64
Unexecuted instantiation: hci.c:bt_get_be64
Unexecuted instantiation: fuzz_xml.c:bt_get_be64
Unexecuted instantiation: fuzz_hci.c:bt_get_be64
306
307
static inline uint32_t bt_get_le32(const void *ptr)
308
0
{
309
0
  return bt_get_unaligned((const uint32_t *) ptr);
310
0
}
Unexecuted instantiation: util.c:bt_get_le32
Unexecuted instantiation: fuzz_sdp.c:bt_get_le32
Unexecuted instantiation: sdp.c:bt_get_le32
Unexecuted instantiation: bluetooth.c:bt_get_le32
Unexecuted instantiation: hci.c:bt_get_le32
Unexecuted instantiation: fuzz_xml.c:bt_get_le32
Unexecuted instantiation: fuzz_hci.c:bt_get_le32
311
312
static inline uint32_t bt_get_be32(const void *ptr)
313
5.57k
{
314
5.57k
  return bswap_32(bt_get_unaligned((const uint32_t *) ptr));
315
5.57k
}
Unexecuted instantiation: util.c:bt_get_be32
Unexecuted instantiation: fuzz_sdp.c:bt_get_be32
sdp.c:bt_get_be32
Line
Count
Source
313
5.57k
{
314
5.57k
  return bswap_32(bt_get_unaligned((const uint32_t *) ptr));
315
5.57k
}
Unexecuted instantiation: bluetooth.c:bt_get_be32
Unexecuted instantiation: hci.c:bt_get_be32
Unexecuted instantiation: fuzz_xml.c:bt_get_be32
Unexecuted instantiation: fuzz_hci.c:bt_get_be32
316
317
static inline uint16_t bt_get_le16(const void *ptr)
318
0
{
319
0
  return bt_get_unaligned((const uint16_t *) ptr);
320
0
}
Unexecuted instantiation: util.c:bt_get_le16
Unexecuted instantiation: fuzz_sdp.c:bt_get_le16
Unexecuted instantiation: sdp.c:bt_get_le16
Unexecuted instantiation: bluetooth.c:bt_get_le16
Unexecuted instantiation: hci.c:bt_get_le16
Unexecuted instantiation: fuzz_xml.c:bt_get_le16
Unexecuted instantiation: fuzz_hci.c:bt_get_le16
321
322
static inline uint16_t bt_get_be16(const void *ptr)
323
148k
{
324
148k
  return bswap_16(bt_get_unaligned((const uint16_t *) ptr));
325
148k
}
Unexecuted instantiation: util.c:bt_get_be16
Unexecuted instantiation: fuzz_sdp.c:bt_get_be16
sdp.c:bt_get_be16
Line
Count
Source
323
148k
{
324
148k
  return bswap_16(bt_get_unaligned((const uint16_t *) ptr));
325
148k
}
Unexecuted instantiation: bluetooth.c:bt_get_be16
Unexecuted instantiation: hci.c:bt_get_be16
Unexecuted instantiation: fuzz_xml.c:bt_get_be16
Unexecuted instantiation: fuzz_hci.c:bt_get_be16
326
327
static inline void bt_put_le64(uint64_t val, const void *ptr)
328
0
{
329
0
  bt_put_unaligned(val, (uint64_t *) ptr);
330
0
}
Unexecuted instantiation: util.c:bt_put_le64
Unexecuted instantiation: fuzz_sdp.c:bt_put_le64
Unexecuted instantiation: sdp.c:bt_put_le64
Unexecuted instantiation: bluetooth.c:bt_put_le64
Unexecuted instantiation: hci.c:bt_put_le64
Unexecuted instantiation: fuzz_xml.c:bt_put_le64
Unexecuted instantiation: fuzz_hci.c:bt_put_le64
331
332
static inline void bt_put_be64(uint64_t val, const void *ptr)
333
0
{
334
0
  bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
335
0
}
Unexecuted instantiation: util.c:bt_put_be64
Unexecuted instantiation: fuzz_sdp.c:bt_put_be64
Unexecuted instantiation: sdp.c:bt_put_be64
Unexecuted instantiation: bluetooth.c:bt_put_be64
Unexecuted instantiation: hci.c:bt_put_be64
Unexecuted instantiation: fuzz_xml.c:bt_put_be64
Unexecuted instantiation: fuzz_hci.c:bt_put_be64
336
337
static inline void bt_put_le32(uint32_t val, const void *ptr)
338
0
{
339
0
  bt_put_unaligned(val, (uint32_t *) ptr);
340
0
}
Unexecuted instantiation: util.c:bt_put_le32
Unexecuted instantiation: fuzz_sdp.c:bt_put_le32
Unexecuted instantiation: sdp.c:bt_put_le32
Unexecuted instantiation: bluetooth.c:bt_put_le32
Unexecuted instantiation: hci.c:bt_put_le32
Unexecuted instantiation: fuzz_xml.c:bt_put_le32
Unexecuted instantiation: fuzz_hci.c:bt_put_le32
341
342
static inline void bt_put_be32(uint32_t val, const void *ptr)
343
0
{
344
0
  bt_put_unaligned(bswap_32(val), (uint32_t *) ptr);
345
0
}
Unexecuted instantiation: util.c:bt_put_be32
Unexecuted instantiation: fuzz_sdp.c:bt_put_be32
Unexecuted instantiation: sdp.c:bt_put_be32
Unexecuted instantiation: bluetooth.c:bt_put_be32
Unexecuted instantiation: hci.c:bt_put_be32
Unexecuted instantiation: fuzz_xml.c:bt_put_be32
Unexecuted instantiation: fuzz_hci.c:bt_put_be32
346
347
static inline void bt_put_le16(uint16_t val, const void *ptr)
348
0
{
349
0
  bt_put_unaligned(val, (uint16_t *) ptr);
350
0
}
Unexecuted instantiation: util.c:bt_put_le16
Unexecuted instantiation: fuzz_sdp.c:bt_put_le16
Unexecuted instantiation: sdp.c:bt_put_le16
Unexecuted instantiation: bluetooth.c:bt_put_le16
Unexecuted instantiation: hci.c:bt_put_le16
Unexecuted instantiation: fuzz_xml.c:bt_put_le16
Unexecuted instantiation: fuzz_hci.c:bt_put_le16
351
352
static inline void bt_put_be16(uint16_t val, const void *ptr)
353
0
{
354
0
  bt_put_unaligned(bswap_16(val), (uint16_t *) ptr);
355
0
}
Unexecuted instantiation: util.c:bt_put_be16
Unexecuted instantiation: fuzz_sdp.c:bt_put_be16
Unexecuted instantiation: sdp.c:bt_put_be16
Unexecuted instantiation: bluetooth.c:bt_put_be16
Unexecuted instantiation: hci.c:bt_put_be16
Unexecuted instantiation: fuzz_xml.c:bt_put_be16
Unexecuted instantiation: fuzz_hci.c:bt_put_be16
356
357
#elif __BYTE_ORDER == __BIG_ENDIAN
358
static inline uint64_t bt_get_le64(const void *ptr)
359
{
360
  return bswap_64(bt_get_unaligned((const uint64_t *) ptr));
361
}
362
363
static inline uint64_t bt_get_be64(const void *ptr)
364
{
365
  return bt_get_unaligned((const uint64_t *) ptr);
366
}
367
368
static inline uint32_t bt_get_le32(const void *ptr)
369
{
370
  return bswap_32(bt_get_unaligned((const uint32_t *) ptr));
371
}
372
373
static inline uint32_t bt_get_be32(const void *ptr)
374
{
375
  return bt_get_unaligned((const uint32_t *) ptr);
376
}
377
378
static inline uint16_t bt_get_le16(const void *ptr)
379
{
380
  return bswap_16(bt_get_unaligned((const uint16_t *) ptr));
381
}
382
383
static inline uint16_t bt_get_be16(const void *ptr)
384
{
385
  return bt_get_unaligned((const uint16_t *) ptr);
386
}
387
388
static inline void bt_put_le64(uint64_t val, const void *ptr)
389
{
390
  bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
391
}
392
393
static inline void bt_put_be64(uint64_t val, const void *ptr)
394
{
395
  bt_put_unaligned(val, (uint64_t *) ptr);
396
}
397
398
static inline void bt_put_le32(uint32_t val, const void *ptr)
399
{
400
  bt_put_unaligned(bswap_32(val), (uint32_t *) ptr);
401
}
402
403
static inline void bt_put_be32(uint32_t val, const void *ptr)
404
{
405
  bt_put_unaligned(val, (uint32_t *) ptr);
406
}
407
408
static inline void bt_put_le16(uint16_t val, const void *ptr)
409
{
410
  bt_put_unaligned(bswap_16(val), (uint16_t *) ptr);
411
}
412
413
static inline void bt_put_be16(uint16_t val, const void *ptr)
414
{
415
  bt_put_unaligned(val, (uint16_t *) ptr);
416
}
417
#else
418
#error "Unknown byte order"
419
#endif
420
421
/* BD Address */
422
typedef struct {
423
  uint8_t b[6];
424
} __attribute__((packed)) bdaddr_t;
425
426
/* BD Address type */
427
#define BDADDR_BREDR           0x00
428
#define BDADDR_LE_PUBLIC       0x01
429
#define BDADDR_LE_RANDOM       0x02
430
431
0
#define BDADDR_ANY   (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
432
#define BDADDR_ALL   (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
433
0
#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
434
435
/* Copy, swap, convert BD Address */
436
static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
437
0
{
438
0
  return memcmp(ba1, ba2, sizeof(bdaddr_t));
439
0
}
Unexecuted instantiation: util.c:bacmp
Unexecuted instantiation: fuzz_sdp.c:bacmp
Unexecuted instantiation: sdp.c:bacmp
Unexecuted instantiation: bluetooth.c:bacmp
Unexecuted instantiation: hci.c:bacmp
Unexecuted instantiation: fuzz_xml.c:bacmp
Unexecuted instantiation: fuzz_hci.c:bacmp
440
static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src)
441
0
{
442
0
  memcpy(dst, src, sizeof(bdaddr_t));
443
0
}
Unexecuted instantiation: util.c:bacpy
Unexecuted instantiation: fuzz_sdp.c:bacpy
Unexecuted instantiation: sdp.c:bacpy
Unexecuted instantiation: bluetooth.c:bacpy
Unexecuted instantiation: hci.c:bacpy
Unexecuted instantiation: fuzz_xml.c:bacpy
Unexecuted instantiation: fuzz_hci.c:bacpy
444
445
void baswap(bdaddr_t *dst, const bdaddr_t *src);
446
bdaddr_t *strtoba(const char *str);
447
char *batostr(const bdaddr_t *ba);
448
int ba2str(const bdaddr_t *ba, char *str);
449
int ba2strlc(const bdaddr_t *ba, char *str);
450
int str2ba(const char *str, bdaddr_t *ba);
451
int ba2oui(const bdaddr_t *ba, char *oui);
452
int bachk(const char *str);
453
454
int baprintf(const char *format, ...);
455
int bafprintf(FILE *stream, const char *format, ...);
456
int basprintf(char *str, const char *format, ...);
457
int basnprintf(char *str, size_t size, const char *format, ...);
458
459
void *bt_malloc(size_t size);
460
void *bt_malloc0(size_t size);
461
void bt_free(void *ptr);
462
463
int bt_error(uint16_t code);
464
const char *bt_compidtostr(int id);
465
466
typedef struct {
467
  uint8_t data[3];
468
} uint24_t;
469
470
typedef struct {
471
  uint8_t data[16];
472
} uint128_t;
473
474
static inline void bswap_128(const void *src, void *dst)
475
2.61k
{
476
2.61k
  const uint8_t *s = (const uint8_t *) src;
477
2.61k
  uint8_t *d = (uint8_t *) dst;
478
2.61k
  int i;
479
480
44.4k
  for (i = 0; i < 16; i++)
481
41.7k
    d[15 - i] = s[i];
482
2.61k
}
Unexecuted instantiation: util.c:bswap_128
Unexecuted instantiation: fuzz_sdp.c:bswap_128
sdp.c:bswap_128
Line
Count
Source
475
2.61k
{
476
2.61k
  const uint8_t *s = (const uint8_t *) src;
477
2.61k
  uint8_t *d = (uint8_t *) dst;
478
2.61k
  int i;
479
480
44.4k
  for (i = 0; i < 16; i++)
481
41.7k
    d[15 - i] = s[i];
482
2.61k
}
Unexecuted instantiation: bluetooth.c:bswap_128
Unexecuted instantiation: hci.c:bswap_128
Unexecuted instantiation: fuzz_xml.c:bswap_128
Unexecuted instantiation: fuzz_hci.c:bswap_128
483
484
#if __BYTE_ORDER == __BIG_ENDIAN
485
486
#define ntoh64(x) (x)
487
488
static inline void ntoh128(const uint128_t *src, uint128_t *dst)
489
{
490
  memcpy(dst, src, sizeof(uint128_t));
491
}
492
493
static inline void btoh128(const uint128_t *src, uint128_t *dst)
494
{
495
  bswap_128(src, dst);
496
}
497
498
#else
499
500
static inline uint64_t ntoh64(uint64_t n)
501
0
{
502
0
  uint64_t h;
503
0
  uint64_t tmp = ntohl(n & 0x00000000ffffffff);
504
505
0
  h = ntohl(n >> 32);
506
0
  h |= tmp << 32;
507
508
0
  return h;
509
0
}
Unexecuted instantiation: util.c:ntoh64
Unexecuted instantiation: fuzz_sdp.c:ntoh64
Unexecuted instantiation: sdp.c:ntoh64
Unexecuted instantiation: bluetooth.c:ntoh64
Unexecuted instantiation: hci.c:ntoh64
Unexecuted instantiation: fuzz_xml.c:ntoh64
Unexecuted instantiation: fuzz_hci.c:ntoh64
510
511
static inline void ntoh128(const uint128_t *src, uint128_t *dst)
512
2.61k
{
513
2.61k
  bswap_128(src, dst);
514
2.61k
}
Unexecuted instantiation: util.c:ntoh128
Unexecuted instantiation: fuzz_sdp.c:ntoh128
sdp.c:ntoh128
Line
Count
Source
512
2.61k
{
513
2.61k
  bswap_128(src, dst);
514
2.61k
}
Unexecuted instantiation: bluetooth.c:ntoh128
Unexecuted instantiation: hci.c:ntoh128
Unexecuted instantiation: fuzz_xml.c:ntoh128
Unexecuted instantiation: fuzz_hci.c:ntoh128
515
516
static inline void btoh128(const uint128_t *src, uint128_t *dst)
517
0
{
518
0
  memcpy(dst, src, sizeof(uint128_t));
519
0
}
Unexecuted instantiation: util.c:btoh128
Unexecuted instantiation: fuzz_sdp.c:btoh128
Unexecuted instantiation: sdp.c:btoh128
Unexecuted instantiation: bluetooth.c:btoh128
Unexecuted instantiation: hci.c:btoh128
Unexecuted instantiation: fuzz_xml.c:btoh128
Unexecuted instantiation: fuzz_hci.c:btoh128
520
521
#endif
522
523
0
#define hton64(x)     ntoh64(x)
524
0
#define hton128(x, y) ntoh128(x, y)
525
#define htob128(x, y) btoh128(x, y)
526
527
#ifdef __cplusplus
528
}
529
#endif
530
531
#endif /* __BLUETOOTH_H */