Select one of the symbols to view example projects that use it.
 
Outline
#define btstack_gatt_client_h
#include "hci.h"
#define GATT_CLIENT_COLLISION_BACKOFF_MS
gatt_client_state_t
gatt_client_mtu_t
gatt_client
gatt_client_notification
gatt_client_service_t
gatt_client_characteristic_t
gatt_client_characteristic_descriptor_t
gatt_client_init();
gatt_client_set_required_security_level(gap_security_level_t);
gatt_client_classic_connect(btstack_packet_handler_t, uint8_t *);
gatt_client_classic_disconnect(btstack_packet_handler_t, hci_con_handle_t);
gatt_client_le_enhanced_connect(btstack_packet_handler_t, hci_con_handle_t, uint8_t, uint8_t *, uint16_t);
gatt_client_get_mtu(hci_con_handle_t, uint16_t *);
gatt_client_mtu_enable_auto_negotiation(uint8_t);
gatt_client_send_mtu_negotiation(btstack_packet_handler_t, hci_con_handle_t);
gatt_client_is_ready(hci_con_handle_t);
gatt_client_discover_primary_services(btstack_packet_handler_t, hci_con_handle_t);
gatt_client_discover_secondary_services(btstack_packet_handler_t, hci_con_handle_t);
gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t, hci_con_handle_t, uint16_t);
gatt_client_discover_primary_services_by_uuid128(btstack_packet_handler_t, hci_con_handle_t, const uint8_t *);
gatt_client_find_included_services_for_service(btstack_packet_handler_t, hci_con_handle_t, gatt_client_service_t *);
gatt_client_discover_characteristics_for_service(btstack_packet_handler_t, hci_con_handle_t, gatt_client_service_t *);
gatt_client_discover_characteristics_for_handle_range_by_uuid16(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t, uint16_t);
gatt_client_discover_characteristics_for_handle_range_by_uuid128(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t, const uint8_t *);
gatt_client_discover_characteristics_for_service_by_uuid16(btstack_packet_handler_t, hci_con_handle_t, gatt_client_service_t *, uint16_t);
gatt_client_discover_characteristics_for_service_by_uuid128(btstack_packet_handler_t, hci_con_handle_t, gatt_client_service_t *, const uint8_t *);
gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t, hci_con_handle_t, gatt_client_characteristic_t *);
gatt_client_read_value_of_characteristic(btstack_packet_handler_t, hci_con_handle_t, gatt_client_characteristic_t *);
gatt_client_read_value_of_characteristic_using_value_handle(btstack_packet_handler_t, hci_con_handle_t, uint16_t);
gatt_client_read_value_of_characteristics_by_uuid16(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t, uint16_t);
gatt_client_read_value_of_characteristics_by_uuid128(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t, const uint8_t *);
gatt_client_read_long_value_of_characteristic(btstack_packet_handler_t, hci_con_handle_t, gatt_client_characteristic_t *);
gatt_client_read_long_value_of_characteristic_using_value_handle(btstack_packet_handler_t, hci_con_handle_t, uint16_t);
gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t);
gatt_client_read_multiple_characteristic_values(btstack_packet_handler_t, hci_con_handle_t, int, uint16_t *);
gatt_client_read_multiple_variable_characteristic_values(btstack_packet_handler_t, hci_con_handle_t, int, uint16_t *);
gatt_client_write_value_of_characteristic_without_response(hci_con_handle_t, uint16_t, uint16_t, uint8_t *);
gatt_client_signed_write_without_response(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t, uint8_t *);
gatt_client_write_value_of_characteristic(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t, uint8_t *);
gatt_client_write_long_value_of_characteristic(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t, uint8_t *);
gatt_client_write_long_value_of_characteristic_with_offset(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t, uint16_t, uint8_t *);
gatt_client_reliable_write_long_value_of_characteristic(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t, uint8_t *);
gatt_client_read_characteristic_descriptor(btstack_packet_handler_t, hci_con_handle_t, gatt_client_characteristic_descriptor_t *);
gatt_client_read_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t, hci_con_handle_t, uint16_t);
gatt_client_read_long_characteristic_descriptor(btstack_packet_handler_t, hci_con_handle_t, gatt_client_characteristic_descriptor_t *);
gatt_client_read_long_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t, hci_con_handle_t, uint16_t);
gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t);
gatt_client_write_characteristic_descriptor(btstack_packet_handler_t, hci_con_handle_t, gatt_client_characteristic_descriptor_t *, uint16_t, uint8_t *);
gatt_client_write_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t, uint8_t *);
gatt_client_write_long_characteristic_descriptor(btstack_packet_handler_t, hci_con_handle_t, gatt_client_characteristic_descriptor_t *, uint16_t, uint8_t *);
gatt_client_write_long_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t, uint8_t *);
gatt_client_write_long_characteristic_descriptor_using_descriptor_handle_with_offset(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t, uint16_t, uint8_t *);
gatt_client_write_client_characteristic_configuration(btstack_packet_handler_t, hci_con_handle_t, gatt_client_characteristic_t *, uint16_t);
gatt_client_listen_for_characteristic_value_updates(gatt_client_notification_t *, btstack_packet_handler_t, hci_con_handle_t, gatt_client_characteristic_t *);
gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t *);
gatt_client_prepare_write(btstack_packet_handler_t, hci_con_handle_t, uint16_t, uint16_t, uint16_t, uint8_t *);
gatt_client_execute_write(btstack_packet_handler_t, hci_con_handle_t);
gatt_client_cancel_write(btstack_packet_handler_t, hci_con_handle_t);
gatt_client_request_to_send_gatt_query(btstack_context_callback_registration_t *, hci_con_handle_t);
gatt_client_request_to_write_without_response(btstack_context_callback_registration_t *, hci_con_handle_t);
gatt_client_request_can_write_without_response_event(btstack_packet_handler_t, hci_con_handle_t);
gatt_client_deserialize_service(const uint8_t *, int, gatt_client_service_t *);
gatt_client_deserialize_characteristic(const uint8_t *, int, gatt_client_characteristic_t *);
gatt_client_deserialize_characteristic_descriptor(const uint8_t *, int, gatt_client_characteristic_descriptor_t *);
Files
loading...
SourceVuRaspberry Pi Pico SDK and ExamplesBluetooth LE Stacksrc/ble/gatt_client.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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * Copyright (C) 2014 BlueKitchen GmbH * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the copyright holders nor the names of * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * 4. Any redistribution, use, or modification is done solely for * personal benefit and not for any commercial purpose or for * monetary gain. * * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * Please inquire about commercial licensing options at * contact@bluekitchen-gmbh.com * *//* ... */ /** * @title GATT Client * *//* ... */ #ifndef btstack_gatt_client_h #define btstack_gatt_client_h #include "hci.h" // spec defines 100 ms, PTS might indicate an error if we sent after 100 ms #define GATT_CLIENT_COLLISION_BACKOFF_MS 150 #if defined __cplusplus extern "C" { #endif typedef enum { P_READY, P_W2_EMIT_QUERY_COMPLETE_EVENT, P_W2_SEND_SERVICE_QUERY, P_W4_SERVICE_QUERY_RESULT, P_W2_SEND_SERVICE_WITH_UUID_QUERY, P_W4_SERVICE_WITH_UUID_RESULT, P_W2_SEND_ALL_CHARACTERISTICS_OF_SERVICE_QUERY, P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT, P_W2_SEND_CHARACTERISTIC_WITH_UUID_QUERY, P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT, P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY, P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT, P_W2_SEND_INCLUDED_SERVICE_QUERY, P_W4_INCLUDED_SERVICE_QUERY_RESULT, P_W2_SEND_INCLUDED_SERVICE_WITH_UUID_QUERY, P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT, P_W2_SEND_READ_CHARACTERISTIC_VALUE_QUERY, P_W4_READ_CHARACTERISTIC_VALUE_RESULT, P_W2_SEND_READ_BLOB_QUERY, P_W4_READ_BLOB_RESULT, P_W2_SEND_READ_BY_TYPE_REQUEST, P_W4_READ_BY_TYPE_RESPONSE, P_W2_SEND_READ_MULTIPLE_REQUEST, P_W4_READ_MULTIPLE_RESPONSE, P_W2_SEND_READ_MULTIPLE_VARIABLE_REQUEST, P_W4_READ_MULTIPLE_VARIABLE_RESPONSE, P_W2_SEND_WRITE_CHARACTERISTIC_VALUE, P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT, P_W2_PREPARE_WRITE, P_W4_PREPARE_WRITE_RESULT, P_W2_PREPARE_RELIABLE_WRITE, P_W4_PREPARE_RELIABLE_WRITE_RESULT, P_W2_EXECUTE_PREPARED_WRITE, P_W4_EXECUTE_PREPARED_WRITE_RESULT, P_W2_CANCEL_PREPARED_WRITE, P_W4_CANCEL_PREPARED_WRITE_RESULT, P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH, P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT, #ifdef ENABLE_GATT_FIND_INFORMATION_FOR_CCC_DISCOVERY P_W2_SEND_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY, P_W4_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT,/* ... */ #else P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY, P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT,/* ... */ #endif P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION, P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT, P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY, P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT, P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY, P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT, P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR, P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, // all long writes use this P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR, P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR, P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, // gatt reliable write API use this (manual version of the above) P_W2_PREPARE_WRITE_SINGLE, P_W4_PREPARE_WRITE_SINGLE_RESULT, P_W4_IDENTITY_RESOLVING, P_W4_CMAC_READY, P_W4_CMAC_RESULT, P_W2_SEND_SIGNED_WRITE, P_W4_SEND_SIGNED_WRITE_DONE, P_W2_SDP_QUERY, P_W4_SDP_QUERY, P_W2_L2CAP_CONNECT, P_W4_L2CAP_CONNECTION, P_W2_EMIT_CONNECTED, P_L2CAP_CLOSED, ...} gatt_client_state_t; typedef enum{ SEND_MTU_EXCHANGE, SENT_MTU_EXCHANGE, MTU_EXCHANGED, MTU_AUTO_EXCHANGE_DISABLED ...} gatt_client_mtu_t; #ifdef ENABLE_GATT_OVER_EATT typedef enum { GATT_CLIENT_EATT_IDLE, GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W2_SEND, GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W4_DONE, GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W2_SEND, GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W4_DONE, GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W2_SEND, GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W4_DONE, GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W2_SEND, GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W4_DONE, GATT_CLIENT_EATT_L2CAP_SETUP, GATT_CLIENT_EATT_READY, ...} gatt_client_eatt_state_t;/* ... */ #endif typedef struct gatt_client{ btstack_linked_item_t item; gatt_client_state_t state; // user callback btstack_packet_handler_t callback; // can write without response callback btstack_packet_handler_t write_without_response_callback; // can write without response requests btstack_linked_list_t write_without_response_requests; // regular gatt query requests btstack_linked_list_t query_requests; hci_con_handle_t con_handle; att_bearer_type_t bearer_type; #ifdef ENABLE_GATT_OVER_CLASSIC bd_addr_t addr; uint16_t l2cap_psm; uint16_t l2cap_cid; btstack_context_callback_registration_t callback_request;/* ... */ #endif #ifdef ENABLE_GATT_OVER_EATT gatt_client_eatt_state_t eatt_state; btstack_linked_list_t eatt_clients; uint8_t * eatt_storage_buffer; uint16_t eatt_storage_size; uint8_t eatt_num_clients; uint8_t gatt_server_supported_features; uint16_t gatt_service_start_group_handle; uint16_t gatt_service_end_group_handle; uint16_t gatt_client_supported_features_handle;/* ... */ #endif uint16_t mtu; gatt_client_mtu_t mtu_state; uint16_t uuid16; uint8_t uuid128[16]; uint16_t start_group_handle; uint16_t end_group_handle; uint16_t query_start_handle; uint16_t query_end_handle; uint8_t characteristic_properties; uint16_t characteristic_start_handle; uint16_t attribute_handle; uint16_t attribute_offset; uint16_t attribute_length; uint8_t* attribute_value; // read multiple characteristic values uint16_t read_multiple_handle_count; uint16_t * read_multiple_handles; uint16_t client_characteristic_configuration_handle; uint8_t client_characteristic_configuration_value[2]; bool filter_with_uuid; bool send_confirmation; int le_device_index; uint8_t cmac[8]; btstack_timer_source_t gc_timeout; uint8_t security_counter; bool wait_for_authentication_complete; uint8_t pending_error_code; bool reencryption_active; uint8_t reencryption_result; gap_security_level_t security_level; ...} gatt_client_t; typedef struct gatt_client_notification { btstack_linked_item_t item; btstack_packet_handler_t callback; hci_con_handle_t con_handle; uint16_t attribute_handle; ...} gatt_client_notification_t; /* API_START */ typedef struct { uint16_t start_group_handle; uint16_t end_group_handle; uint16_t uuid16; uint8_t uuid128[16]; ...} gatt_client_service_t; typedef struct { uint16_t start_handle; uint16_t value_handle; uint16_t end_handle; uint16_t properties; uint16_t uuid16; uint8_t uuid128[16]; ...} gatt_client_characteristic_t; typedef struct { uint16_t handle; uint16_t uuid16; uint8_t uuid128[16]; ...} gatt_client_characteristic_descriptor_t; /** * @brief Set up GATT client. *//* ... */ void gatt_client_init(void); /** * @brief Set minimum required security level for GATT Client * @note The Bluetooth specification makes the GATT Server responsible to check for security. * This allows an attacker to spoof an existing device with a GATT Servers, but skip the authentication part. * If your application is exchanging sensitive data with a remote device, you would need to manually check * the security level before sending/receive such data. * With level > 0, the GATT Client triggers authentication for all GATT Requests and defers any exchange * until the required security level is established. * gatt_client_request_can_write_without_response_event does not trigger authentication * gatt_client_request_to_write_without_response does not trigger authentication * @pram level, default LEVEL_0 (no encryption required) *//* ... */ void gatt_client_set_required_security_level(gap_security_level_t level); /** * @brief Connect to remote GATT Server over Classic (BR/EDR) Connection * GATT_EVENT_CONNECTED with status and con_handle for other API functions * is emitted on connection complete. * @note requires ENABLE_GATT_OVER_CLASSIC. * @param addr * @return status *//* ... */ uint8_t gatt_client_classic_connect(btstack_packet_handler_t callback, bd_addr_t addr); /** * @brief Disconnect o Classic (BR/EDR) connection to a remote GATT Server * @note requires ENABLE_GATT_OVER_CLASSIC * @param con_handle * @return status *//* ... */ uint8_t gatt_client_classic_disconnect(btstack_packet_handler_t callback, hci_con_handle_t con_handle); /** * @brief Setup Enhanced LE Bearer with up to 5 channels on existing LE connection * @param callback for GATT_EVENT_CONNECTED and GATT_EVENT_DISCONNECTED events * @param con_handle * @param num_channels * @param storage_buffer for L2CAP connection * @param storage_size - each channel requires (2 * ATT MTU) + 10 bytes * @return *//* ... */ uint8_t gatt_client_le_enhanced_connect(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint8_t num_channels, uint8_t * storage_buffer, uint16_t storage_size); /** * @brief MTU is available after the first query has completed. If status is equal to ERROR_CODE_SUCCESS, it returns the real value, * otherwise the default value ATT_DEFAULT_MTU (see bluetooth.h). * @param con_handle * @param mtu * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if MTU is not exchanged and MTU auto-exchange is disabled * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu); /** * @brief Sets whether a MTU Exchange Request shall be automatically send before the * first attribute read request is send. Default is enabled. * @param enabled *//* ... */ void gatt_client_mtu_enable_auto_negotiation(uint8_t enabled); /** * @brief Sends a MTU Exchange Request, this allows for the client to exchange MTU * when gatt_client_mtu_enable_auto_negotiation is disabled. * @param callback * @param con_handle *//* ... */ void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con_handle_t con_handle); /** * @brief Returns 1 if the GATT client is ready to receive a query. It is used with daemon. * @param con_handle * @return is_ready_status 0 - if no GATT client for con_handle is found, or is not ready, otherwise 1 *//* ... */ int gatt_client_is_ready(hci_con_handle_t con_handle); /** * @brief Discovers all primary services. * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. * @param callback * @param con_handle * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); /** * @brief Discovers all secondary services. * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. * @param callback * @param con_handle * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); /** * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. * @param callback * @param con_handle * @param uuid16 * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16); /** * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. * @param callback * @param con_handle * @param uuid128 * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_discover_primary_services_by_uuid128(btstack_packet_handler_t callback, hci_con_handle_t con_handle, const uint8_t * uuid128); /** * @brief Finds included services within the specified service. * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. * Information about included service type (primary/secondary) can be retrieved either by sending * an ATT find information request for the returned start group handle * (returning the handle and the UUID for primary or secondary service) or by comparing the service * to the list of all primary services. * @param callback * @param con_handle * @param service * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_find_included_services_for_service(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service); /** * @brief Discovers all characteristics within the specified service. * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited. * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. * @param callback * @param con_handle * @param service * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_discover_characteristics_for_service(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service); /** * @brief The following four functions are used to discover all characteristics within * the specified service or handle range, and return those that match the given UUID. * * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. * @param callback * @param con_handle * @param start_handle * @param end_handle * @param uuid16 * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16); /** * @brief The following four functions are used to discover all characteristics within the * specified service or handle range, and return those that match the given UUID. * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. * @param callback * @param con_handle * @param start_handle * @param end_handle * @param uuid128 * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid128(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t start_handle, uint16_t end_handle, const uint8_t * uuid128); /** * @brief The following four functions are used to discover all characteristics within the * specified service or handle range, and return those that match the given UUID. * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. * @param callback * @param con_handle * @param service * @param uuid16 * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_discover_characteristics_for_service_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service, uint16_t uuid16); /** * @brief The following four functions are used to discover all characteristics within the * specified service or handle range, and return those that match the given UUID. * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. * @param callback * @param con_handle * @param service * @param uuid128 * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_discover_characteristics_for_service_by_uuid128(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service, const uint8_t * uuid128); /** * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted. * * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. * @param callback * @param con_handle * @param characteristic * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic); /** * @brief Reads the characteristic value using the characteristic's value handle. * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. * @param callback * @param con_handle * @param characteristic * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_read_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic); /** * @brief Reads the characteristic value using the characteristic's value handle. * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. * @param callback * @param con_handle * @param value_handle * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_read_value_of_characteristic_using_value_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle); /** * @brief Reads the characteric value of all characteristics with the uuid. * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. * @param callback * @param con_handle * @param start_handle * @param end_handle * @param uuid16 * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_read_value_of_characteristics_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16); /** * @brief Reads the characteric value of all characteristics with the uuid. * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. * @param callback * @param con_handle * @param start_handle * @param end_handle * @param uuid128 * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_read_value_of_characteristics_by_uuid128(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t start_handle, uint16_t end_handle, const uint8_t * uuid128); /** * @brief Reads the long characteristic value using the characteristic's value handle. * The value will be returned in several blobs. * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. * @param callback * @param con_handle * @param characteristic * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_read_long_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic); /** * @brief Reads the long characteristic value using the characteristic's value handle. * The value will be returned in several blobs. * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. * @param callback * @param con_handle * @param value_handle * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle); /** * @brief Reads the long characteristic value using the characteristic's value handle. * The value will be returned in several blobs. * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. * @param callback * @param con_handle * @param value_handle * @param offset * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t offset); /* * @brief Read multiple characteristic values. * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. * @param callback * @param con_handle * @param num_value_handles * @param value_handles list of handles * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_read_multiple_characteristic_values(btstack_packet_handler_t callback, hci_con_handle_t con_handle, int num_value_handles, uint16_t * value_handles); /* * @brief Read multiple varaible characteristic values. Only supported over LE Enhanced Bearer * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. * @param callback * @param con_handle * @param num_value_handles * @param value_handles list of handles * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_read_multiple_variable_characteristic_values(btstack_packet_handler_t callback, hci_con_handle_t con_handle, int num_value_handles, uint16_t * value_handles); /** * @brief Writes the characteristic value using the characteristic's value handle without * an acknowledgment that the write was successfully performed. * @param con_handle * @param value_handle * @param value_length * @param value is copied on success and does not need to be retained * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready * BTSTACK_ACL_BUFFERS_FULL , if L2CAP cannot send, there are no free ACL slots * ERROR_CODE_SUCCESS , if query is successfully registered *//* ... */ uint8_t gatt_client_write_value_of_characteristic_without_response(hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value); /** * @brief Writes the authenticated characteristic value using the characteristic's value handle * without an acknowledgment that the write was successfully performed. * @note GATT_EVENT_QUERY_COMPLETE is emitted with ATT_ERROR_SUCCESS for success, * or ATT_ERROR_BONDING_INFORMATION_MISSING if there is no bonding information stored. * @param callback * @param con_handle * @param value_handle * @param message_len * @param message is not copied, make sure memory is accessible until write is done * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_signed_write_without_response(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t message_len, uint8_t * message); /** * @brief Writes the characteristic value using the characteristic's value handle. * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. * The write is successfully performed, if the event's att_status field is set to * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). * @param callback * @param con_handle * @param value_handle * @param value_length * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_write_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value); /** * @brief Writes the characteristic value using the characteristic's value handle. * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). * @param callback * @param con_handle * @param value_handle * @param value_length * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_write_long_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value); /** * @brief Writes the characteristic value using the characteristic's value handle. * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). * @param callback * @param con_handle * @param value_handle * @param offset of value * @param value_length * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_write_long_value_of_characteristic_with_offset(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t offset, uint16_t value_length, uint8_t * value); /** * @brief Writes of the long characteristic value using the characteristic's value handle. * It uses server response to validate that the write was correctly received. * The GATT_EVENT_QUERY_COMPLETE EVENT marks the end of write. * The write is successfully performed, if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). * @param callback * @param con_handle * @param value_handle * @param value_length * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_reliable_write_long_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value); /** * @brief Reads the characteristic descriptor using its handle. * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. * @param callback * @param con_handle * @param descriptor * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_read_characteristic_descriptor(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t * descriptor); /** * @brief Reads the characteristic descriptor using its handle. * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. * @param callback * @param con_handle * @param descriptor * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_read_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle); /** * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. * @param callback * @param con_handle * @param descriptor * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_read_long_characteristic_descriptor(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t * descriptor); /** * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. * @param callback * @param con_handle * @param descriptor_handle * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle); /** * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. * @param callback * @param con_handle * @param descriptor_handle * @param offset * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle, uint16_t offset); /** * @brief Writes the characteristic descriptor using its handle. * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). * @param callback * @param con_handle * @param descriptor * @param value_length * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_write_characteristic_descriptor(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t * descriptor, uint16_t value_length, uint8_t * value); /** * @brief Writes the characteristic descriptor using its handle. * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). * @param callback * @param con_handle * @param descriptor_handle * @param value_length * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_write_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle, uint16_t value_length, uint8_t * value); /** * @brief Writes the characteristic descriptor using its handle. * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). * @param callback * @param con_handle * @param descriptor * @param value_length * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_write_long_characteristic_descriptor(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t * descriptor, uint16_t value_length, uint8_t * value); /** * @brief Writes the characteristic descriptor using its handle. * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). * @param callback * @param con_handle * @param descriptor_handle * @param value_length * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle, uint16_t value_length, uint8_t * value); /** * @brief Writes the characteristic descriptor using its handle. * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). * @param callback * @param con_handle * @param descriptor_handle * @param offset of value * @param value_length * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle_with_offset(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle, uint16_t offset, uint16_t value_length, uint8_t * value); /** * @brief Writes the client characteristic configuration of the specified characteristic. * It is used to subscribe for notifications or indications of the characteristic value. * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value. * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). * @param callback * @param con_handle * @param characteristic * @param configuration GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED if configuring notification, but characteristic has no notification property set * GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED if configuring indication, but characteristic has no indication property set * ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE if configuration is invalid * ERROR_CODE_SUCCESS if query is successfully registered *//* ... */ uint8_t gatt_client_write_client_characteristic_configuration(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic, uint16_t configuration); /** * @brief Register for notifications and indications of a characteristic enabled by * the gatt_client_write_client_characteristic_configuration function. * @param notification struct used to store registration * @param callback * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices * @param characteristic or NULL to receive updates for all characteristics *//* ... */ void gatt_client_listen_for_characteristic_value_updates(gatt_client_notification_t * notification, btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic); /** * @brief Stop listening to characteristic value updates registered with * the gatt_client_listen_for_characteristic_value_updates function. * @param notification struct used in gatt_client_listen_for_characteristic_value_updates *//* ... */ void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification); /** * @brief Transactional write. It can be called as many times as it is needed to write the characteristics within the same transaction. * Call the gatt_client_execute_write function to commit the transaction. * @param callback * @param con_handle * @param attribute_handle * @param offset of value * @param value_length * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received *//* ... */ uint8_t gatt_client_prepare_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t offset, uint16_t value_length, uint8_t * value); /** * @brief Commit transactional write. GATT_EVENT_QUERY_COMPLETE is received. * @param callback * @param con_handle * @return status *//* ... */ uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); /** * @brief Abort transactional write. GATT_EVENT_QUERY_COMPLETE is received. * @param callback * @param con_handle * @return status *//* ... */ uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); /** * @brief Request callback when regular gatt query can be sent * @note callback might happen during call to this function * @param callback_registration to point to callback function and context information * @param con_handle * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered *//* ... */ uint8_t gatt_client_request_to_send_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); /** * @brief Request callback when writing characteristic value without response is possible * @note callback might happen during call to this function * @param callback_registration to point to callback function and context information * @param con_handle * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered *//* ... */ uint8_t gatt_client_request_to_write_without_response(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); // the following functions are marked as deprecated and will be removed eventually /** * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees * a single successful gatt_client_write_value_of_characteristic_without_response call. * @deprecated please use gatt_client_request_to_write_without_response instead * @param callback * @param con_handle * @return status *//* ... */ uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle); /* API_END */ // used by generated btstack_event.c void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t * service); void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic); void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor); #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION void gatt_client_att_packet_handler_fuzz(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size); uint8_t gatt_client_get_client(hci_con_handle_t con_handle, gatt_client_t ** gatt_client);/* ... */ #endif #if defined __cplusplus }extern "C" { ... } #endif /* ... */ #endif
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.