forked from paulh002/sdrberry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gattlib.h
694 lines (623 loc) · 26.7 KB
/
gattlib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
/*
*
* GattLib - GATT Library
*
* Copyright (C) 2016-2020 Olivier Martin <[email protected]>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __GATTLIB_H__
#define __GATTLIB_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>
#ifndef BDADDR_BREDR
/* GattLib note: BD Address have only been introduced into Bluez v4.100. */
/* Prior to this version, only BDADDR_BREDR can be supported */
/* BD Address type */
#define BDADDR_BREDR 0x00
#define BDADDR_LE_PUBLIC 0x01
#define BDADDR_LE_RANDOM 0x02
#endif
#if BLUEZ_VERSION_MAJOR == 5
#define ATT_MAX_MTU ATT_MAX_VALUE_LEN
#endif
/**
* @name Gattlib errors
*/
//@{
#define GATTLIB_SUCCESS 0
#define GATTLIB_INVALID_PARAMETER 1
#define GATTLIB_NOT_FOUND 2
#define GATTLIB_OUT_OF_MEMORY 3
#define GATTLIB_NOT_SUPPORTED 4
#define GATTLIB_DEVICE_ERROR 5
#define GATTLIB_ERROR_DBUS 6
#define GATTLIB_ERROR_BLUEZ 7
#define GATTLIB_ERROR_INTERNAL 8
//@}
/**
* @name GATT Characteristic Properties Bitfield values
*/
//@{
#define GATTLIB_CHARACTERISTIC_BROADCAST 0x01
#define GATTLIB_CHARACTERISTIC_READ 0x02
#define GATTLIB_CHARACTERISTIC_WRITE_WITHOUT_RESP 0x04
#define GATTLIB_CHARACTERISTIC_WRITE 0x08
#define GATTLIB_CHARACTERISTIC_NOTIFY 0x10
#define GATTLIB_CHARACTERISTIC_INDICATE 0x20
//@}
/**
* Helper function to create UUID16 from a 16bit integer
*/
#define CREATE_UUID16(value16) { .type=SDP_UUID16, .value.uuid16=(value16) }
/**
* @name Options for gattlib_connect()
*
* @note Options with the prefix `GATTLIB_CONNECTION_OPTIONS_LEGACY_`
* is for Bluez prior to v5.42 (before Bluez) support
*/
//@{
#define GATTLIB_CONNECTION_OPTIONS_LEGACY_BDADDR_LE_PUBLIC (1 << 0)
#define GATTLIB_CONNECTION_OPTIONS_LEGACY_BDADDR_LE_RANDOM (1 << 1)
#define GATTLIB_CONNECTION_OPTIONS_LEGACY_BT_SEC_LOW (1 << 2)
#define GATTLIB_CONNECTION_OPTIONS_LEGACY_BT_SEC_MEDIUM (1 << 3)
#define GATTLIB_CONNECTION_OPTIONS_LEGACY_BT_SEC_HIGH (1 << 4)
#define GATTLIB_CONNECTION_OPTIONS_LEGACY_PSM(value) (((value) & 0x3FF) << 11) //< We encode PSM on 10 bits (up to 1023)
#define GATTLIB_CONNECTION_OPTIONS_LEGACY_MTU(value) (((value) & 0x3FF) << 21) //< We encode MTU on 10 bits (up to 1023)
#define GATTLIB_CONNECTION_OPTIONS_LEGACY_GET_PSM(options) (((options) >> 11) && 0x3FF)
#define GATTLIB_CONNECTION_OPTIONS_LEGACY_GET_MTU(options) (((options) >> 21) && 0x3FF)
#define GATTLIB_CONNECTION_OPTIONS_LEGACY_DEFAULT \
GATTLIB_CONNECTION_OPTIONS_LEGACY_BDADDR_LE_PUBLIC | \
GATTLIB_CONNECTION_OPTIONS_LEGACY_BDADDR_LE_RANDOM | \
GATTLIB_CONNECTION_OPTIONS_LEGACY_BT_SEC_LOW
//@}
/**
* @name Discover filter
*/
//@{
#define GATTLIB_DISCOVER_FILTER_USE_NONE 0
#define GATTLIB_DISCOVER_FILTER_USE_UUID (1 << 0)
#define GATTLIB_DISCOVER_FILTER_USE_RSSI (1 << 1)
#define GATTLIB_DISCOVER_FILTER_NOTIFY_CHANGE (1 << 2)
//@}
/**
* @name Gattlib Eddystone types
*/
//@{
#define GATTLIB_EDDYSTONE_TYPE_UID (1 << 0)
#define GATTLIB_EDDYSTONE_TYPE_URL (1 << 1)
#define GATTLIB_EDDYSTONE_TYPE_TLM (1 << 2)
#define GATTLIB_EDDYSTONE_TYPE_EID (1 << 3)
#define GATTLIB_EDDYSTONE_LIMIT_RSSI (1 << 4)
//@}
/**
* @name Eddystone ID types defined by its specification: https://github.com/google/eddystone
*/
//@{
#define EDDYSTONE_TYPE_UID 0x00
#define EDDYSTONE_TYPE_URL 0x10
#define EDDYSTONE_TYPE_TLM 0x20
#define EDDYSTONE_TYPE_EID 0x30
//@}
typedef struct _gatt_connection_t gatt_connection_t;
typedef struct _gatt_stream_t gatt_stream_t;
/**
* Structure to represent a GATT Service and its data in the BLE advertisement packet
*/
typedef struct {
uuid_t uuid; /**< UUID of the GATT Service */
uint8_t* data; /**< Data attached to the GATT Service */
size_t data_length; /**< Length of data attached to the GATT Service */
} gattlib_advertisement_data_t;
typedef void (*gattlib_event_handler_t)(const uuid_t* uuid, const uint8_t* data, size_t data_length, void* user_data);
/**
* @brief Handler called on disconnection
*
* @param connection Connection that is disconnecting
* @param user_data Data defined when calling `gattlib_register_on_disconnect()`
*/
typedef void (*gattlib_disconnection_handler_t)(void* user_data);
/**
* @brief Handler called on new discovered BLE device
*
* @param adapter is the adapter that has found the BLE device
* @param addr is the MAC address of the BLE device
* @param name is the name of BLE device if advertised
* @param user_data Data defined when calling `gattlib_register_on_disconnect()`
*/
typedef void (*gattlib_discovered_device_t)(void *adapter, const char* addr, const char* name, void *user_data);
/**
* @brief Handler called on new discovered BLE device
*
* @param adapter is the adapter that has found the BLE device
* @param addr is the MAC address of the BLE device
* @param name is the name of BLE device if advertised
* @param advertisement_data is an array of Service UUID and their respective data
* @param advertisement_data_count is the number of elements in the advertisement_data array
* @param manufacturer_id is the ID of the Manufacturer ID
* @param manufacturer_data is the data following Manufacturer ID
* @param manufacturer_data_size is the size of manufacturer_data
* @param user_data Data defined when calling `gattlib_register_on_disconnect()`
*/
typedef void (*gattlib_discovered_device_with_data_t)(void *adapter, const char* addr, const char* name,
gattlib_advertisement_data_t *advertisement_data, size_t advertisement_data_count,
uint16_t manufacturer_id, uint8_t *manufacturer_data, size_t manufacturer_data_size,
void *user_data);
/**
* @brief Handler called on asynchronous connection when connection is ready
*
* @param connection Connection that is disconnecting
* @param user_data Data defined when calling `gattlib_register_on_disconnect()`
*/
typedef void (*gatt_connect_cb_t)(gatt_connection_t* connection, void* user_data);
/**
* @brief Callback called when GATT characteristic read value has been received
*
* @param buffer contains the value to read.
* @param buffer_len Length of the read data
*
*/
typedef void* (*gatt_read_cb_t)(const void *buffer, size_t buffer_len);
/**
* @brief Constant defining Eddystone common data UID in Advertisement data
*/
extern const uuid_t gattlib_eddystone_common_data_uuid;
/**
* @brief List of prefix for Eddystone URL Scheme
*/
extern const char *gattlib_eddystone_url_scheme_prefix[];
/**
* @brief Open Bluetooth adapter
*
* @param adapter_name With value NULL, the default adapter will be selected.
* @param adapter is the context of the newly opened adapter
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_adapter_open(const char* adapter_name, void** adapter);
/**
* @brief Enable Bluetooth scanning on a given adapter
*
* @param adapter is the context of the newly opened adapter
* @param discovered_device_cb is the function callback called for each new Bluetooth device discovered
* @param timeout defines the duration of the Bluetooth scanning. When timeout=0, we scan indefinitely.
* @param user_data is the data passed to the callback `discovered_device_cb()`
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_adapter_scan_enable(void* adapter, gattlib_discovered_device_t discovered_device_cb, size_t timeout, void *user_data);
/**
* @brief Enable Bluetooth scanning on a given adapter
*
* @param adapter is the context of the newly opened adapter
* @param uuid_list is a NULL-terminated list of UUIDs to filter. The rule only applies to advertised UUID.
* Returned devices would match any of the UUIDs of the list.
* @param rssi_threshold is the imposed RSSI threshold for the returned devices.
* @param enabled_filters defines the parameters to use for filtering. There are selected by using the macros
* GATTLIB_DISCOVER_FILTER_USE_UUID and GATTLIB_DISCOVER_FILTER_USE_RSSI.
* @param discovered_device_cb is the function callback called for each new Bluetooth device discovered
* @param timeout defines the duration of the Bluetooth scanning. When timeout=0, we scan indefinitely.
* @param user_data is the data passed to the callback `discovered_device_cb()`
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid_list, int16_t rssi_threshold, uint32_t enabled_filters,
gattlib_discovered_device_t discovered_device_cb, size_t timeout, void *user_data);
/**
* @brief Enable Eddystone Bluetooth Device scanning on a given adapter
*
* @param adapter is the context of the newly opened adapter
* @param rssi_threshold is the imposed RSSI threshold for the returned devices.
* @param eddystone_types defines the type(s) of Eddystone advertisement data type to select.
* The types are defined by the macros `GATTLIB_EDDYSTONE_TYPE_*`. The macro `GATTLIB_EDDYSTONE_LIMIT_RSSI`
* can also be used to limit RSSI with rssi_threshold.
* @param discovered_device_cb is the function callback called for each new Bluetooth device discovered
* @param timeout defines the duration of the Bluetooth scanning. When timeout=0, we scan indefinitely.
* @param user_data is the data passed to the callback `discovered_device_cb()`
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_adapter_scan_eddystone(void *adapter, int16_t rssi_threshold, uint32_t eddystone_types,
gattlib_discovered_device_with_data_t discovered_device_cb, size_t timeout, void *user_data);
/**
* @brief Disable Bluetooth scanning on a given adapter
*
* @param adapter is the context of the newly opened adapter
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_adapter_scan_disable(void* adapter);
/**
* @brief Close Bluetooth adapter context
*
* @param adapter is the context of the newly opened adapter
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_adapter_close(void* adapter);
/**
* @brief Function to connect to a BLE device
*
* @param adapter Local Adaptater interface. When passing NULL, we use default adapter.
* @param dst Remote Bluetooth address
* @param options Options to connect to BLE device. See `GATTLIB_CONNECTION_OPTIONS_*`
*/
gatt_connection_t *gattlib_connect(void *adapter, const char *dst, unsigned long options);
/**
* @brief Function to asynchronously connect to a BLE device
*
* @note This function is mainly used before Bluez v5.42 (prior to D-BUS support)
*
* @param adapter Local Adaptater interface. When passing NULL, we use default adapter.
* @param dst Remote Bluetooth address
* @param options Options to connect to BLE device. See `GATTLIB_CONNECTION_OPTIONS_*`
* @param connect_cb is the callback to call when the connection is established
* @param user_data is the user specific data to pass to the callback
*/
gatt_connection_t *gattlib_connect_async(void *adapter, const char *dst,
unsigned long options,
gatt_connect_cb_t connect_cb, void* user_data);
/**
* @brief Function to disconnect the GATT connection
*
* @param connection Active GATT connection
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_disconnect(gatt_connection_t* connection);
/**
* @brief Function to register a callback on GATT disconnection
*
* @param connection Active GATT connection
* @param handler is the callaback to invoke on disconnection
* @param user_data is user specific data to pass to the callaback
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
void gattlib_register_on_disconnect(gatt_connection_t *connection, gattlib_disconnection_handler_t handler, void* user_data);
/**
* Structure to represent GATT Primary Service
*/
typedef struct {
uint16_t attr_handle_start; /**< First attribute handle of the GATT Primary Service */
uint16_t attr_handle_end; /**< Last attibute handle of the GATT Primary Service */
uuid_t uuid; /**< UUID of the Primary Service */
} gattlib_primary_service_t;
/**
* Structure to represent GATT Characteristic
*/
typedef struct {
uint16_t handle; /**< Handle of the GATT characteristic */
uint8_t properties; /**< Property of the GATT characteristic */
uint16_t value_handle; /**< Handle for the value of the GATT characteristic */
uuid_t uuid; /**< UUID of the GATT characteristic */
} gattlib_characteristic_t;
/**
* Structure to represent GATT Descriptor
*/
typedef struct {
uint16_t handle; /**< Handle of the GATT Descriptor */
uint16_t uuid16; /**< UUID16 of the GATT Descriptor */
uuid_t uuid; /**< UUID of the GATT Descriptor */
} gattlib_descriptor_t;
/**
* @brief Function to discover GATT Services
*
* @note This function can be used to force GATT services/characteristic discovery
*
* @param connection Active GATT connection
* @param services array of GATT services allocated by the function. Can be NULL.
* @param services_count Number of GATT services discovered. Can be NULL
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_discover_primary(gatt_connection_t* connection, gattlib_primary_service_t** services, int* services_count);
/**
* @brief Function to discover GATT Characteristic
*
* @note This function can be used to force GATT services/characteristic discovery
*
* @param connection Active GATT connection
* @param start is the index of the first handle of the range
* @param end is the index of the last handle of the range
* @param characteristics array of GATT characteristics allocated by the function. Can be NULL.
* @param characteristics_count Number of GATT characteristics discovered. Can be NULL
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_discover_char_range(gatt_connection_t* connection, int start, int end, gattlib_characteristic_t** characteristics, int* characteristics_count);
/**
* @brief Function to discover GATT Characteristic
*
* @note This function can be used to force GATT services/characteristic discovery
*
* @param connection Active GATT connection
* @param characteristics array of GATT characteristics allocated by the function. Can be NULL.
* @param characteristics_count Number of GATT characteristics discovered. Can be NULL
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_discover_char(gatt_connection_t* connection, gattlib_characteristic_t** characteristics, int* characteristics_count);
/**
* @brief Function to discover GATT Descriptors in a range of handles
*
* @param connection Active GATT connection
* @param start is the index of the first handle of the range
* @param end is the index of the last handle of the range
* @param descriptors array of GATT descriptors allocated by the function. Can be NULL.
* @param descriptors_count Number of GATT descriptors discovered. Can be NULL
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_discover_desc_range(gatt_connection_t* connection, int start, int end, gattlib_descriptor_t** descriptors, int* descriptors_count);
/**
* @brief Function to discover GATT Descriptor
*
* @param connection Active GATT connection
* @param descriptors array of GATT descriptors allocated by the function. Can be NULL.
* @param descriptors_count Number of GATT descriptors discovered. Can be NULL
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_discover_desc(gatt_connection_t* connection, gattlib_descriptor_t** descriptors, int* descriptors_count);
/**
* @brief Function to read GATT characteristic
*
* @note buffer is allocated by the function. It is the responsibility of the caller to free the buffer.
*
* @param connection Active GATT connection
* @param uuid UUID of the GATT characteristic to read
* @param buffer contains the value to read. It is allocated by the function.
* @param buffer_len Length of the read data
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_read_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid, void** buffer, size_t* buffer_len);
/**
* @brief Function to asynchronously read GATT characteristic
*
* @param connection Active GATT connection
* @param uuid UUID of the GATT characteristic to read
* @param gatt_read_cb is the callback to read when the GATT characteristic is available
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_read_char_by_uuid_async(gatt_connection_t* connection, uuid_t* uuid, gatt_read_cb_t gatt_read_cb);
/**
* @brief Function to write to the GATT characteristic UUID
*
* @param connection Active GATT connection
* @param uuid UUID of the GATT characteristic to read
* @param buffer contains the values to write to the GATT characteristic
* @param buffer_len is the length of the buffer to write
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_write_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid, const void* buffer, size_t buffer_len);
/**
* @brief Function to write to the GATT characteristic handle
*
* @param connection Active GATT connection
* @param handle is the handle of the GATT characteristic
* @param buffer contains the values to write to the GATT characteristic
* @param buffer_len is the length of the buffer to write
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_write_char_by_handle(gatt_connection_t* connection, uint16_t handle, const void* buffer, size_t buffer_len);
/**
* @brief Function to write without response to the GATT characteristic UUID
*
* @param connection Active GATT connection
* @param uuid UUID of the GATT characteristic to read
* @param buffer contains the values to write to the GATT characteristic
* @param buffer_len is the length of the buffer to write
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_write_without_response_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid, const void* buffer, size_t buffer_len);
/**
* @brief Create a stream to a GATT characteristic to write data in continue
*
* @note: The GATT characteristic must support 'Write-Without-Response'
*
* @param connection Active GATT connection
* @param uuid UUID of the GATT characteristic to write
* @param stream is the object that is attached to the GATT characteristic that is used to write data to
* @param mtu is the MTU of the GATT connection to optimise the stream writting
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_write_char_by_uuid_stream_open(gatt_connection_t* connection, uuid_t* uuid, gatt_stream_t **stream, uint16_t *mtu);
/**
* @brief Write data to the stream previously created with `gattlib_write_char_by_uuid_stream_open()`
*
* @param stream is the object that is attached to the GATT characteristic that is used to write data to
* @param buffer is the data to write to the stream
* @param buffer_len is the length of the buffer to write
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_write_char_stream_write(gatt_stream_t *stream, const void *buffer, size_t buffer_len);
/**
* @brief Close the stream previously created with `gattlib_write_char_by_uuid_stream_open()`
*
* @param stream is the object that is attached to the GATT characteristic that is used to write data to
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_write_char_stream_close(gatt_stream_t *stream);
/**
* @brief Function to write without response to the GATT characteristic handle
*
* @param connection Active GATT connection
* @param handle is the handle of the GATT characteristic
* @param buffer contains the values to write to the GATT characteristic
* @param buffer_len is the length of the buffer to write
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_write_without_response_char_by_handle(gatt_connection_t* connection, uint16_t handle, const void* buffer, size_t buffer_len);
/*
* @brief Enable notification on GATT characteristic represented by its UUID
*
* @param connection Active GATT connection
* @param uuid UUID of the characteristic that will trigger the notification
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_notification_start(gatt_connection_t* connection, const uuid_t* uuid);
/*
* @brief Disable notification on GATT characteristic represented by its UUID
*
* @param connection Active GATT connection
* @param uuid UUID of the characteristic that will trigger the notification
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_notification_stop(gatt_connection_t* connection, const uuid_t* uuid);
/*
* @brief Enable indication on GATT characteristic represented by its UUID
*
* @param connection Active GATT connection
* @param uuid UUID of the characteristic that will trigger the indication
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_indication_start(gatt_connection_t* connection, const uuid_t* uuid);
/*
* @brief Disable indication on GATT characteristic represented by its UUID
*
* @param connection Active GATT connection
* @param uuid UUID of the characteristic that will trigger the indication
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_indication_stop(gatt_connection_t* connection, const uuid_t* uuid);
/*
* @brief Register a handle for the GATT notifications
*
* @param connection Active GATT connection
* @param notification_handler is the handler to call on notification
* @param user_data if the user specific data to pass to the handler
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
void gattlib_register_notification(gatt_connection_t* connection, gattlib_event_handler_t notification_handler, void* user_data);
/*
* @brief Register a handle for the GATT indications
*
* @param connection Active GATT connection
* @param notification_handler is the handler to call on indications
* @param user_data if the user specific data to pass to the handler
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
void gattlib_register_indication(gatt_connection_t* connection, gattlib_event_handler_t indication_handler, void* user_data);
#if 0 // Disable until https://github.com/labapart/gattlib/issues/75 is resolved
/**
* @brief Function to retrieve RSSI from a GATT connection
*
* @param connection Active GATT connection
* @param rssi is the Received Signal Strength Indicator of the remote device
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_get_rssi(gatt_connection_t *connection, int16_t *rssi);
#endif
/**
* @brief Function to retrieve RSSI from a MAC Address
*
* @note: This function is mainly used before a connection is established. Once the connection
* established, the function `gattlib_get_rssi()` should be preferred.
*
* @param adapter is the adapter the new device has been seen
* @param mac_address is the MAC address of the device to get the RSSI
* @param rssi is the Received Signal Strength Indicator of the remote device
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_get_rssi_from_mac(void *adapter, const char *mac_address, int16_t *rssi);
/**
* @brief Function to retrieve Advertisement Data from a MAC Address
*
* @param connection Active GATT connection
* @param advertisement_data is an array of Service UUID and their respective data
* @param advertisement_data_count is the number of elements in the advertisement_data array
* @param manufacturer_id is the ID of the Manufacturer ID
* @param manufacturer_data is the data following Manufacturer ID
* @param manufacturer_data_size is the size of manufacturer_data
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_get_advertisement_data(gatt_connection_t *connection,
gattlib_advertisement_data_t **advertisement_data, size_t *advertisement_data_count,
uint16_t *manufacturer_id, uint8_t **manufacturer_data, size_t *manufacturer_data_size);
/**
* @brief Function to retrieve Advertisement Data from a MAC Address
*
* @param adapter is the adapter the new device has been seen
* @param mac_address is the MAC address of the device to get the RSSI
* @param advertisement_data is an array of Service UUID and their respective data
* @param advertisement_data_count is the number of elements in the advertisement_data array
* @param manufacturer_id is the ID of the Manufacturer ID
* @param manufacturer_data is the data following Manufacturer ID
* @param manufacturer_data_size is the size of manufacturer_data
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_get_advertisement_data_from_mac(void *adapter, const char *mac_address,
gattlib_advertisement_data_t **advertisement_data, size_t *advertisement_data_count,
uint16_t *manufacturer_id, uint8_t **manufacturer_data, size_t *manufacturer_data_size);
/**
* @brief Convert a UUID into a string
*
* @param uuid is the UUID to convert
* @param str is the buffer that will contain the string
* @param size is the size of the buffer
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_uuid_to_string(const uuid_t *uuid, char *str, size_t size);
/**
* @brief Convert a string representing a UUID into a UUID structure
*
* @param str is the buffer containing the string
* @param size is the size of the buffer
* @param uuid is the UUID structure that would receive the UUID
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_string_to_uuid(const char *str, size_t size, uuid_t *uuid);
/**
* @brief Compare two UUIDs
*
* @param uuid1 is the one of the UUID to compare with
* @param uuid2 is the other UUID to compare with
*
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/
int gattlib_uuid_cmp(const uuid_t *uuid1, const uuid_t *uuid2);
#ifdef __cplusplus
}
#endif
#endif