1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
24
25
26
27
28
29
30
35
38
39
43
44
45
46
47
48
49
50
51
52
53
54
55
56
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
92
93
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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
166
169
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
318
319
320
321
322
323
324
325
326
327
328
329
330
331
335
336
337
338
339
340
341
342
343
344
345
346
347
348
352
353
354
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
454
455
456
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
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
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
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
687
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
720
721
722
723
724
725
726
727
728
729
730
731
737
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
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
814
815
816
817
818
819
820
821
822
823
824
825
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
921
922
923
932
933
934
935
936
937
938
939
940
941
942
943
944
945
949
950
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
977
978
979
984
985
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1021
1022
1025
1026
1027
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1081
1082
1083
1084
1085
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1190
1191
1203
1204
1205
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1229
1230
1231
1232
1233
/* ... */
/* ... */
#include "common/bt_target.h"
#include "osi/allocator.h"
#if defined(GATTC_INCLUDED) && (GATTC_INCLUDED == TRUE)
#include <string.h>
#include "bta/bta_sys.h"
#include "bta/bta_gatt_api.h"
#include "bta_gattc_int.h"
#include "stack/l2c_api.h"5 includes
/* ... */
static const tBTA_SYS_REG bta_gattc_reg = {
bta_gattc_hdl_event,
BTA_GATTC_Disable
}{...};
/* ... */
void BTA_GATTC_Disable(void)
{
BT_HDR *p_buf;
if (bta_sys_is_register(BTA_ID_GATTC) == FALSE) {
APPL_TRACE_WARNING("GATTC Module not enabled/already disabled\n");
return;
}{...}
if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
p_buf->event = BTA_GATTC_API_DISABLE_EVT;
bta_sys_sendmsg(p_buf);
}{...}
bta_sys_deregister(BTA_ID_GATTC);
}{ ... }
/* ... */
void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb)
{
tBTA_GATTC_API_REG *p_buf;
if (bta_sys_is_register(BTA_ID_GATTC) == FALSE) {
bta_sys_register(BTA_ID_GATTC, &bta_gattc_reg);
}{...}
if ((p_buf = (tBTA_GATTC_API_REG *) osi_malloc(sizeof(tBTA_GATTC_API_REG))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_REG_EVT;
if (p_app_uuid != NULL) {
memcpy(&p_buf->app_uuid, p_app_uuid, sizeof(tBT_UUID));
}{...}
p_buf->p_cback = p_client_cb;
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if)
{
tBTA_GATTC_API_DEREG *p_buf;
if ((p_buf = (tBTA_GATTC_API_DEREG *) osi_malloc(sizeof(tBTA_GATTC_API_DEREG))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_DEREG_EVT;
p_buf->client_if = client_if;
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_Enh_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux, tBTA_ADDR_TYPE own_addr_type,
UINT8 phy_mask, tBTA_BLE_CONN_PARAMS *phy_1m_conn_params, tBTA_BLE_CONN_PARAMS *phy_2m_conn_params,
tBTA_BLE_CONN_PARAMS *phy_coded_conn_params)
{
tBTA_GATTC_API_OPEN *p_buf;
if ((p_buf = (tBTA_GATTC_API_OPEN *) osi_malloc(sizeof(tBTA_GATTC_API_OPEN))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_OPEN_EVT;
p_buf->client_if = client_if;
p_buf->is_direct = is_direct;
p_buf->transport = transport;
p_buf->is_aux = is_aux;
p_buf->remote_addr_type = remote_addr_type;
p_buf->own_addr_type = own_addr_type;
p_buf->phy_mask = phy_mask;
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
if ((phy_mask & BTA_BLE_PHY_1M_MASK) && phy_1m_conn_params) {
memcpy(&p_buf->phy_1m_conn_params, phy_1m_conn_params, sizeof(tBTA_BLE_CONN_PARAMS));
}{...}
if ((phy_mask & BTA_BLE_PHY_2M_MASK) && phy_2m_conn_params) {
memcpy(&p_buf->phy_2m_conn_params, phy_2m_conn_params, sizeof(tBTA_BLE_CONN_PARAMS));
}{...}
if ((phy_mask & BTA_BLE_PHY_CODED_MASK) && phy_coded_conn_params) {
memcpy(&p_buf->phy_coded_conn_params, phy_coded_conn_params, sizeof(tBTA_BLE_CONN_PARAMS));
}{...}
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct)
{
if(bta_sys_is_register(BTA_ID_GATTC) == FALSE) {
return;
}{...}
tBTA_GATTC_API_CANCEL_OPEN *p_buf;
if ((p_buf = (tBTA_GATTC_API_CANCEL_OPEN *) osi_malloc(sizeof(tBTA_GATTC_API_CANCEL_OPEN))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_CANCEL_OPEN_EVT;
p_buf->client_if = client_if;
p_buf->is_direct = is_direct;
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_Close(UINT16 conn_id)
{
BT_HDR *p_buf;
if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
p_buf->event = BTA_GATTC_API_CLOSE_EVT;
p_buf->layer_specific = conn_id;
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_ConfigureMTU (UINT16 conn_id)
{
tBTA_GATTC_API_CFG_MTU *p_buf;
if ((p_buf = (tBTA_GATTC_API_CFG_MTU *) osi_malloc(sizeof(tBTA_GATTC_API_CFG_MTU))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_CFG_MTU_EVT;
p_buf->hdr.layer_specific = conn_id;
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_ServiceSearchRequest (UINT16 conn_id, tBT_UUID *p_srvc_uuid)
{
tBTA_GATTC_API_SEARCH *p_buf;
UINT16 len = sizeof(tBTA_GATTC_API_SEARCH) + sizeof(tBT_UUID);
if ((p_buf = (tBTA_GATTC_API_SEARCH *) osi_malloc(len)) != NULL) {
memset(p_buf, 0, len);
p_buf->hdr.event = BTA_GATTC_API_SEARCH_EVT;
p_buf->hdr.layer_specific = conn_id;
if (p_srvc_uuid) {
p_buf->p_srvc_uuid = (tBT_UUID *)(p_buf + 1);
memcpy(p_buf->p_srvc_uuid, p_srvc_uuid, sizeof(tBT_UUID));
}{...} else {
p_buf->p_srvc_uuid = NULL;
}{...}
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
const list_t* BTA_GATTC_GetServices(UINT16 conn_id)
{
return bta_gattc_get_services(conn_id);
}{ ... }
/* ... */
const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(UINT16 conn_id, UINT16 handle)
{
return bta_gattc_get_characteristic(conn_id, handle);
}{ ... }
/* ... */
const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(UINT16 conn_id, UINT16 handle)
{
return bta_gattc_get_descriptor(conn_id, handle);
}{ ... }
void BTA_GATTC_GetServiceWithUUID(UINT16 conn_id, tBT_UUID *svc_uuid,
btgatt_db_element_t **db, UINT16 *count)
{
bta_gattc_get_service_with_uuid(conn_id, svc_uuid, db, count);
}{ ... }
void BTA_GATTC_GetAllChar(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle,
btgatt_db_element_t **db, UINT16 *count)
{
bta_gattc_get_db_with_opration(conn_id,
GATT_OP_GET_ALL_CHAR,
0,
NULL,
NULL,
NULL,
start_handle,
end_handle,
db,
count);
}{ ... }
void BTA_GATTC_GetAllDescriptor(UINT16 conn_id, UINT16 char_handle,
btgatt_db_element_t **db, UINT16 *count)
{
bta_gattc_get_db_with_opration(conn_id,
GATT_OP_GET_ALL_DESCRI,
char_handle,
NULL,
NULL,
NULL,
0,
0xFFFF,
db,
count);
}{ ... }
void BTA_GATTC_GetCharByUUID(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, tBT_UUID char_uuid,
btgatt_db_element_t **db, UINT16 *count)
{
bta_gattc_get_db_with_opration(conn_id,
GATT_OP_GET_CHAR_BY_UUID,
0,
NULL,
&char_uuid,
NULL,
start_handle,
end_handle,
db,
count);
}{ ... }
void BTA_GATTC_GetDescrByUUID(UINT16 conn_id, uint16_t start_handle, uint16_t end_handle,
tBT_UUID char_uuid, tBT_UUID descr_uuid,
btgatt_db_element_t **db, UINT16 *count)
{
bta_gattc_get_db_with_opration(conn_id,
GATT_OP_GET_DESCRI_BY_UUID,
0,
NULL,
&char_uuid,
&descr_uuid,
start_handle,
end_handle,
db,
count);
}{ ... }
void BTA_GATTC_GetDescrByCharHandle(UINT16 conn_id, UINT16 char_handle, tBT_UUID descr_uuid,
btgatt_db_element_t **db, UINT16 *count)
{
bta_gattc_get_db_with_opration(conn_id,
GATT_OP_GET_DESCRI_BY_HANDLE,
char_handle,
NULL,
NULL,
&descr_uuid,
0,
0xFFFF,
db,
count);
}{ ... }
void BTA_GATTC_GetIncludeService(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle,
tBT_UUID *incl_uuid, btgatt_db_element_t **db, UINT16 *count)
{
bta_gattc_get_db_with_opration(conn_id,
GATT_OP_GET_INCLUDE_SVC,
0,
incl_uuid,
NULL,
NULL,
start_handle,
end_handle,
db,
count);
}{ ... }
void BTA_GATTC_GetDBSize(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, UINT16 *count)
{
bta_gattc_get_db_size_handle(conn_id, start_handle, end_handle, count);
}{ ... }
void BTA_GATTC_GetDBSizeByType(UINT16 conn_id, bt_gatt_db_attribute_type_t type,
UINT16 start_handle, UINT16 end_handle, UINT16 char_handle, UINT16 *count)
{
bta_gattc_get_db_size_with_type_handle(conn_id, type, start_handle, end_handle, char_handle, count);
}{ ... }
/* ... */
void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle,
btgatt_db_element_t **db, UINT16 *count)
{
bta_gattc_get_gatt_db(conn_id, start_handle, end_handle, db, count);
}{ ... }
/* ... */
void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req)
{
tBTA_GATTC_API_READ *p_buf;
if ((p_buf = (tBTA_GATTC_API_READ *) osi_malloc(sizeof(tBTA_GATTC_API_READ))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTC_API_READ));
p_buf->hdr.event = BTA_GATTC_API_READ_EVT;
p_buf->hdr.layer_specific = conn_id;
p_buf->auth_req = auth_req;
p_buf->handle = handle;
p_buf->cmpl_evt = BTA_GATTC_READ_CHAR_EVT;
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_ReadCharDescr (UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req)
{
tBTA_GATTC_API_READ *p_buf;
UINT16 len = (UINT16)(sizeof(tBTA_GATT_ID) + sizeof(tBTA_GATTC_API_READ));
if ((p_buf = (tBTA_GATTC_API_READ *) osi_malloc(len)) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTC_API_READ));
p_buf->hdr.event = BTA_GATTC_API_READ_EVT;
p_buf->hdr.layer_specific = conn_id;
p_buf->auth_req = auth_req;
p_buf->handle = handle;
p_buf->cmpl_evt = BTA_GATTC_READ_DESCR_EVT;
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_ReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi,
tBTA_GATT_AUTH_REQ auth_req)
{
tBTA_GATTC_API_READ_MULTI *p_buf;
UINT16 len = (UINT16)(sizeof(tBTA_GATTC_API_READ_MULTI));
if ((p_buf = (tBTA_GATTC_API_READ_MULTI *) osi_malloc(len)) != NULL) {
memset(p_buf, 0, len);
p_buf->hdr.event = BTA_GATTC_API_READ_MULTI_EVT;
p_buf->hdr.layer_specific = conn_id;
p_buf->auth_req = auth_req;
p_buf->num_attr = p_read_multi->num_attr;
p_buf->cmpl_evt = BTA_GATTC_READ_MULTIPLE_EVT;
if (p_buf->num_attr > 0) {
memcpy(p_buf->handles, p_read_multi->handles, sizeof(UINT16) * p_read_multi->num_attr);
}{...}
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_ReadMultipleVariable(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi,
tBTA_GATT_AUTH_REQ auth_req)
{
tBTA_GATTC_API_READ_MULTI *p_buf;
UINT16 len = (UINT16)(sizeof(tBTA_GATTC_API_READ_MULTI));
if ((p_buf = (tBTA_GATTC_API_READ_MULTI *) osi_malloc(len)) != NULL) {
memset(p_buf, 0, len);
p_buf->hdr.event = BTA_GATTC_API_READ_MULTI_VAR_EVT;
p_buf->hdr.layer_specific = conn_id;
p_buf->auth_req = auth_req;
p_buf->num_attr = p_read_multi->num_attr;
p_buf->cmpl_evt = BTA_GATTC_READ_MULTI_VAR_EVT;
if (p_buf->num_attr > 0) {
memcpy(p_buf->handles, p_read_multi->handles, sizeof(UINT16) * p_read_multi->num_attr);
}{...}
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_Read_by_type(UINT16 conn_id, UINT16 s_handle,UINT16 e_handle, tBT_UUID *uuid, tBTA_GATT_AUTH_REQ auth_req)
{
tBTA_GATTC_API_READ *p_buf;
if ((p_buf = (tBTA_GATTC_API_READ *) osi_malloc(sizeof(tBTA_GATTC_API_READ))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTC_API_READ));
p_buf->hdr.event = BTA_GATTC_API_READ_BY_TYPE_EVT;
p_buf->hdr.layer_specific = conn_id;
p_buf->auth_req = auth_req;
p_buf->s_handle = s_handle;
p_buf->e_handle = e_handle;
memcpy(&(p_buf->uuid), uuid, sizeof(tBT_UUID));
p_buf->cmpl_evt = BTA_GATTC_READ_CHAR_EVT;
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
UINT16 handle,
tBTA_GATTC_WRITE_TYPE write_type,
UINT16 len,
UINT8 *p_value,
tBTA_GATT_AUTH_REQ auth_req)
{
tBTA_GATTC_API_WRITE *p_buf;
if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_WRITE) + len))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTC_API_WRITE) + len);
p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
p_buf->hdr.layer_specific = conn_id;
p_buf->auth_req = auth_req;
p_buf->handle = handle;
p_buf->cmpl_evt = BTA_GATTC_WRITE_CHAR_EVT;
p_buf->write_type = write_type;
p_buf->len = len;
if (p_value && len > 0) {
p_buf->p_value = (UINT8 *)(p_buf + 1);
memcpy(p_buf->p_value, p_value, len);
}{...}
if(write_type == BTA_GATTC_TYPE_WRITE_NO_RSP){
l2ble_update_att_acl_pkt_num(L2CA_DECREASE_BTC_NUM, NULL);
l2ble_update_att_acl_pkt_num(L2CA_ADD_BTU_NUM, NULL);
}{...}
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
UINT16 handle,
tBTA_GATTC_WRITE_TYPE write_type,
tBTA_GATT_UNFMT *p_data,
tBTA_GATT_AUTH_REQ auth_req)
{
size_t len = sizeof(tBTA_GATTC_API_WRITE);
tBTA_GATTC_API_WRITE *p_buf;
if (p_data != NULL) {
len += p_data->len;
}{...}
if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc(len)) != NULL) {
memset(p_buf, 0, len);
p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
p_buf->hdr.layer_specific = conn_id;
p_buf->auth_req = auth_req;
p_buf->handle = handle;
p_buf->cmpl_evt = BTA_GATTC_WRITE_DESCR_EVT;
p_buf->write_type = write_type;
if (p_data && p_data->len != 0) {
p_buf->p_value = (UINT8 *)(p_buf + 1);
p_buf->len = p_data->len;
memcpy(p_buf->p_value, p_data->p_value, p_data->len);
}{...}
if(write_type == BTA_GATTC_TYPE_WRITE_NO_RSP){
l2ble_update_att_acl_pkt_num(L2CA_DECREASE_BTC_NUM, NULL);
l2ble_update_att_acl_pkt_num(L2CA_ADD_BTU_NUM, NULL);
}{...}
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_PrepareWrite (UINT16 conn_id, UINT16 handle,
UINT16 offset, UINT16 len, UINT8 *p_value,
tBTA_GATT_AUTH_REQ auth_req)
{
tBTA_GATTC_API_WRITE *p_buf;
if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_WRITE) + len))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTC_API_WRITE) + len);
p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
p_buf->hdr.layer_specific = conn_id;
p_buf->auth_req = auth_req;
p_buf->handle = handle;
p_buf->write_type = BTA_GATTC_WRITE_PREPARE;
p_buf->offset = offset;
p_buf->len = len;
if (p_value && len > 0) {
p_buf->p_value = (UINT8 *)(p_buf + 1);
memcpy(p_buf->p_value, p_value, len);
}{...}
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_PrepareWriteCharDescr (UINT16 conn_id, UINT16 handle,
UINT16 offset,tBTA_GATT_UNFMT *p_data,
tBTA_GATT_AUTH_REQ auth_req)
{
tBTA_GATTC_API_WRITE *p_buf;
UINT16 len = sizeof(tBTA_GATTC_API_WRITE);
if (p_data != NULL) {
len += p_data->len;
}{...}
if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc(len)) != NULL) {
memset(p_buf, 0, len);
p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
p_buf->hdr.layer_specific = conn_id;
p_buf->auth_req = auth_req;
p_buf->handle = handle;
p_buf->write_type = BTA_GATTC_WRITE_PREPARE;
p_buf->offset = offset;
if (p_data && p_data->len != 0) {
p_buf->len = p_data->len;
p_buf->p_value = (UINT8 *)(p_buf + 1);
memcpy(p_buf->p_value, p_data->p_value, p_data->len);
}{...}
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_ExecuteWrite (UINT16 conn_id, BOOLEAN is_execute)
{
tBTA_GATTC_API_EXEC *p_buf;
if ((p_buf = (tBTA_GATTC_API_EXEC *) osi_malloc((UINT16)sizeof(tBTA_GATTC_API_EXEC))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTC_API_EXEC));
p_buf->hdr.event = BTA_GATTC_API_EXEC_EVT;
p_buf->hdr.layer_specific = conn_id;
p_buf->is_execute = is_execute;
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_SendIndConfirm (UINT16 conn_id, UINT16 handle)
{
tBTA_GATTC_API_CONFIRM *p_buf;
APPL_TRACE_API("BTA_GATTC_SendIndConfirm conn_id=%d handle =0x%x",
conn_id, handle);
if ((p_buf = (tBTA_GATTC_API_CONFIRM *) osi_malloc(sizeof(tBTA_GATTC_API_CONFIRM))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTC_API_CONFIRM));
p_buf->hdr.event = BTA_GATTC_API_CONFIRM_EVT;
p_buf->hdr.layer_specific = conn_id;
p_buf->handle = handle;
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if,
BD_ADDR bda, UINT16 handle)
{
tBTA_GATTC_RCB *p_clreg;
tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER;
UINT8 i;
if (!handle)
{
APPL_TRACE_ERROR("deregistration failed, handle is 0");
return status;
}{...}
if ((p_clreg = bta_gattc_cl_get_regcb(client_if)) != NULL) {
for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) {
if ( p_clreg->notif_reg[i].in_use &&
!memcmp(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN) &&
p_clreg->notif_reg[i].handle == handle) {
APPL_TRACE_DEBUG("notification already registered");
status = BTA_GATT_OK;
break;
}{...}
}{...}
if (status != BTA_GATT_OK) {
for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) {
if (!p_clreg->notif_reg[i].in_use) {
memset((void *)&p_clreg->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG));
p_clreg->notif_reg[i].in_use = TRUE;
memcpy(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN);
p_clreg->notif_reg[i].handle = handle;
status = BTA_GATT_OK;
break;
}{...}
}{...}
if (i == BTA_GATTC_NOTIF_REG_MAX) {
status = BTA_GATT_NO_RESOURCES;
APPL_TRACE_ERROR("Max Notification Reached, registration failed,see CONFIG_BT_GATTC_NOTIF_REG_MAX in menuconfig");
}{...}
}{...}
}{...} else {
APPL_TRACE_ERROR("Client_if: %d Not Registered", client_if);
}{...}
return status;
}{ ... }
/* ... */
tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF client_if,
BD_ADDR bda, UINT16 handle)
{
if (!handle) {
APPL_TRACE_ERROR("%s: deregistration failed, handle is 0", __func__);
return BTA_GATT_ILLEGAL_PARAMETER;
}{...}
tBTA_GATTC_RCB *p_clreg = bta_gattc_cl_get_regcb(client_if);
if (p_clreg == NULL) {
APPL_TRACE_ERROR("%s client_if: %d not registered bd_addr:%02x:%02x:%02x:%02x:%02x:%02x",
__func__, client_if, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
return BTA_GATT_ILLEGAL_PARAMETER;
}{...}
for (int i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) {
if (p_clreg->notif_reg[i].in_use &&
!memcmp(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN) &&
p_clreg->notif_reg[i].handle == handle) {
APPL_TRACE_DEBUG("%s deregistered bd_addr:%02x:%02x:%02x:%02x:%02x:%02x",
__func__, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
memset(&p_clreg->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG));
return BTA_GATT_OK;
}{...}
}{...}
APPL_TRACE_ERROR("%s registration not found bd_addr:%02x:%02x:%02x:%02x:%02x:%02x",
__func__, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
return BTA_GATT_ERROR;
}{ ... }
/* ... */
void BTA_GATTC_Refresh(BD_ADDR remote_bda, bool erase_flash)
{
#if(GATTC_CACHE_NVS == TRUE)
if(erase_flash) {
bta_gattc_cache_reset(remote_bda);
}{...}
#endif/* ... */
if(bta_sys_is_register(BTA_ID_GATTC) == FALSE) {
return;
}{...}
tBTA_GATTC_API_CACHE_REFRESH *p_buf;
if ((p_buf = (tBTA_GATTC_API_CACHE_REFRESH *) osi_malloc(sizeof(tBTA_GATTC_API_CACHE_REFRESH))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_REFRESH_EVT;
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
void BTA_GATTC_CacheAssoc(tBTA_GATTC_IF client_if, BD_ADDR src_addr, BD_ADDR assoc_addr, BOOLEAN is_assoc)
{
tBTA_GATTC_API_CACHE_ASSOC *p_buf;
if ((p_buf = (tBTA_GATTC_API_CACHE_ASSOC *)osi_malloc(sizeof(tBTA_GATTC_API_CACHE_ASSOC))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_CACHE_ASSOC_EVT;
p_buf->is_assoc = is_assoc;
p_buf->client_if = client_if;
memcpy(p_buf->src_addr, src_addr, sizeof(BD_ADDR));
memcpy(p_buf->assoc_addr, assoc_addr, sizeof(BD_ADDR));
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
void BTA_GATTC_CacheGetAddrList(tBTA_GATTC_IF client_if)
{
tBTA_GATTC_API_GET_ADDR *p_buf;
if ((p_buf = (tBTA_GATTC_API_GET_ADDR *)osi_malloc(sizeof(tBTA_GATTC_API_GET_ADDR))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_CACHE_GET_ADDR_LIST_EVT;
p_buf->client_if = client_if;
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_Clean(BD_ADDR remote_bda)
{
#if(GATTC_CACHE_NVS == TRUE)
bta_gattc_cache_reset(remote_bda);/* ... */
#endif
tBTA_GATTC_API_CACHE_CLEAN *p_buf;
if ((p_buf = (tBTA_GATTC_API_CACHE_CLEAN *) osi_malloc(sizeof(tBTA_GATTC_API_CACHE_CLEAN))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_CACHE_CLEAN_EVT;
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target_bda)
{
tBTA_GATTC_API_LISTEN *p_buf;
if ((p_buf = (tBTA_GATTC_API_LISTEN *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_LISTEN_EVT;
p_buf->client_if = client_if;
p_buf->start = start;
if (target_bda) {
p_buf->remote_bda = (UINT8 *)(p_buf + 1);
memcpy(p_buf->remote_bda, target_bda, BD_ADDR_LEN);
}{...} else {
p_buf->remote_bda = NULL;
}{...}
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
/* ... */
void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, BOOLEAN start)
{
tBTA_GATTC_API_LISTEN *p_buf;
if ((p_buf = (tBTA_GATTC_API_LISTEN *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_BROADCAST_EVT;
p_buf->client_if = client_if;
p_buf->start = start;
bta_sys_sendmsg(p_buf);
}{...}
return;
}{ ... }
uint8_t BTA_GATTC_AutoDiscoverEnable(uint8_t enable)
{
APPL_TRACE_DEBUG("%s enable %d", __func__, enable);
bta_gattc_cb.auto_disc = ((enable > 0) ? true : false);
GATTC_AutoDiscoverEnable(enable);
return 0;
}{ ... }
typedef struct {
UINT16 len;
union {
UINT16 uuid16;
UINT32 uuid32;
UINT8 uuid128[LEN_UUID_128];
}{ ... } uuid;
}{ ... } __attribute__((packed)) tAPP_UUID;
uint8_t BTA_GATTC_Discover(uint8_t gatt_if, uint16_t conn_id, void *uuid, uint8_t disc_type, uint16_t s_handle, uint16_t e_handle)
{
tGATT_STATUS status;
tGATT_DISC_PARAM param;
tAPP_UUID *app_uuid = (tAPP_UUID *)uuid;
conn_id = (UINT16)((((UINT8)conn_id) << 8) | gatt_if);
memset(¶m, 0, sizeof(tGATT_DISC_PARAM));
if (disc_type == GATT_DISC_SRVC_ALL || disc_type == GATT_DISC_SRVC_BY_UUID) {
param.s_handle = 1;
param.e_handle = 0xFFFF;
}{...} else {
param.s_handle = s_handle;
param.e_handle = e_handle;
}{...}
if (app_uuid) {
param.service.len = app_uuid->len;
if (app_uuid->len == LEN_UUID_16) {
param.service.uu.uuid16 = app_uuid->uuid.uuid16;
}{...} else if (app_uuid->len == LEN_UUID_32) {
param.service.uu.uuid32 = app_uuid->uuid.uuid32;
}{...} else if (app_uuid->len == LEN_UUID_128) {
memcpy(param.service.uu.uuid128, app_uuid->uuid.uuid128, LEN_UUID_128);
}{...} else {
APPL_TRACE_ERROR("%s invalid uuid len %u", __func__, app_uuid->len);
}{...}
}{...}
status = GATTC_Discover (conn_id, disc_type, ¶m);
if (status != GATT_SUCCESS) {
APPL_TRACE_ERROR("%s status %x", __func__, status);
return -1;
}{...}
return 0;
}{ ... }
uint8_t BTA_GATTC_ReadLongChar(uint8_t gatt_if, uint16_t conn_id, uint16_t handle, uint16_t offset, uint8_t auth_req)
{
tGATT_STATUS status;
tGATT_READ_PARAM read_param;
conn_id = (UINT16)((((UINT8)conn_id) << 8) | gatt_if);
memset (&read_param, 0, sizeof(tGATT_READ_PARAM));
read_param.partial.handle = handle;
read_param.partial.offset = offset;
read_param.partial.auth_req = auth_req;
status = GATTC_Read(conn_id, GATT_READ_PARTIAL, &read_param);
if (status != GATT_SUCCESS) {
APPL_TRACE_ERROR("%s status %x", __func__, status);
return -1;
}{...}
return 0;
}{ ... }
/* ... */
#endif