forked from dsouzahansenfrancis/STBTLE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbluenrg_gatt_aci.c
1476 lines (1161 loc) · 35.4 KB
/
bluenrg_gatt_aci.c
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
/******************** (C) COPYRIGHT 2014 STMicroelectronics ********************
* File Name : bluenrg_gatt_aci.c
* Author : AMS - AAS
* Version : V1.0.0
* Date : 26-Jun-2014
* Description : File with GATT commands for BlueNRG FW6.3.
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#include "hal_types.h"
#include "osal.h"
#include "ble_status.h"
#include "hal.h"
#include "osal.h"
#include "hci_const.h"
#include "bluenrg_aci_const.h"
#include "bluenrg_gatt_aci.h"
#include "bluenrg_gatt_server.h"
#include "bluenrg_gap.h"
#define MIN(a,b) ((a) < (b) )? (a) : (b)
#define MAX(a,b) ((a) > (b) )? (a) : (b)
tBleStatus aci_gatt_init(void)
{
struct hci_request rq;
uint8_t status;
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_INIT;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_add_serv(uint8_t service_uuid_type, const uint8_t* service_uuid, uint8_t service_type, uint8_t max_attr_records, uint16_t *serviceHandle)
{
struct hci_request rq;
gatt_add_serv_rp resp;
uint8_t buffer[19];
uint8_t uuid_len;
uint8_t indx = 0;
buffer[indx] = service_uuid_type;
indx++;
if(service_uuid_type == UUID_TYPE_16){
uuid_len = 2;
}
else {
uuid_len = 16;
}
Osal_MemCpy(buffer + indx, service_uuid, uuid_len);
indx += uuid_len;
buffer[indx] = service_type;
indx++;
buffer[indx] = max_attr_records;
indx++;
Osal_MemSet(&resp, 0, sizeof(resp));
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_ADD_SERV;
rq.cparam = (void *)buffer;
rq.clen = indx;
rq.rparam = &resp;
rq.rlen = GATT_ADD_SERV_RP_SIZE;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
if (resp.status) {
return resp.status;
}
*serviceHandle = btohs(resp.handle);
return 0;
}
tBleStatus aci_gatt_include_service(uint16_t service_handle, uint16_t included_start_handle,
uint16_t included_end_handle, uint8_t included_uuid_type,
const uint8_t* included_uuid, uint16_t *included_handle)
{
struct hci_request rq;
gatt_include_serv_rp resp;
uint8_t buffer[23];
uint8_t uuid_len;
uint8_t indx = 0;
service_handle = htobs(service_handle);
Osal_MemCpy(buffer, &service_handle, 2);
indx += 2;
included_start_handle = htobs(included_start_handle);
Osal_MemCpy(buffer+indx, &included_start_handle, 2);
indx += 2;
included_end_handle = htobs(included_end_handle);
Osal_MemCpy(buffer+indx, &included_end_handle, 2);
indx += 2;
if(included_uuid_type == UUID_TYPE_16){
uuid_len = 2;
} else {
uuid_len = 16;
}
buffer[indx] = included_uuid_type;
indx++;
Osal_MemCpy(buffer + indx, included_uuid, uuid_len);
indx += uuid_len;
Osal_MemSet(&resp, 0, sizeof(resp));
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_INCLUDE_SERV;
rq.cparam = (void *)buffer;
rq.clen = indx;
rq.rparam = &resp;
rq.rlen = GATT_INCLUDE_SERV_RP_SIZE;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
if (resp.status) {
return resp.status;
}
*included_handle = btohs(resp.handle);
return 0;
}
tBleStatus aci_gatt_add_char(uint16_t serviceHandle,
uint8_t charUuidType,
const uint8_t* charUuid,
uint8_t charValueLen,
uint8_t charProperties,
uint8_t secPermissions,
uint8_t gattEvtMask,
uint8_t encryKeySize,
uint8_t isVariable,
uint16_t* charHandle)
{
struct hci_request rq;
gatt_add_serv_rp resp;
uint8_t buffer[25];
uint8_t uuid_len;
uint8_t indx = 0;
serviceHandle = htobs(serviceHandle);
Osal_MemCpy(buffer + indx, &serviceHandle, 2);
indx += 2;
buffer[indx] = charUuidType;
indx++;
if(charUuidType == UUID_TYPE_16){
uuid_len = 2;
}
else {
uuid_len = 16;
}
Osal_MemCpy(buffer + indx, charUuid, uuid_len);
indx += uuid_len;
buffer[indx] = charValueLen;
indx++;
buffer[indx] = charProperties;
indx++;
buffer[indx] = secPermissions;
indx++;
buffer[indx] = gattEvtMask;
indx++;
buffer[indx] = encryKeySize;
indx++;
buffer[indx] = isVariable;
indx++;
Osal_MemSet(&resp, 0, sizeof(resp));
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_ADD_CHAR;
rq.cparam = (void *)buffer;
rq.clen = indx;
rq.rparam = &resp;
rq.rlen = GATT_ADD_CHAR_RP_SIZE;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
if (resp.status) {
return resp.status;
}
*charHandle = btohs(resp.handle);
return 0;
}
tBleStatus aci_gatt_add_char_desc(uint16_t serviceHandle,
uint16_t charHandle,
uint8_t descUuidType,
const uint8_t* uuid,
uint8_t descValueMaxLen,
uint8_t descValueLen,
const void* descValue,
uint8_t secPermissions,
uint8_t accPermissions,
uint8_t gattEvtMask,
uint8_t encryKeySize,
uint8_t isVariable,
uint16_t* descHandle)
{
struct hci_request rq;
gatt_add_char_desc_rp resp;
uint8_t buffer[HCI_MAX_PAYLOAD_SIZE];
uint8_t uuid_len;
uint8_t indx = 0;
serviceHandle = htobs(serviceHandle);
Osal_MemCpy(buffer + indx, &serviceHandle, 2);
indx += 2;
charHandle = htobs(charHandle);
Osal_MemCpy(buffer + indx, &charHandle, 2);
indx += 2;
buffer[indx] = descUuidType;
indx++;
if(descUuidType == UUID_TYPE_16){
uuid_len = 2;
}
else {
uuid_len = 16;
}
Osal_MemCpy(buffer + indx, uuid, uuid_len);
indx += uuid_len;
buffer[indx] = descValueMaxLen;
indx++;
buffer[indx] = descValueLen;
indx++;
if ((descValueLen+indx+5) > HCI_MAX_PAYLOAD_SIZE)
return BLE_STATUS_INVALID_PARAMS;
Osal_MemCpy(buffer + indx, descValue, descValueLen);
indx += descValueLen;
buffer[indx] = secPermissions;
indx++;
buffer[indx] = accPermissions;
indx++;
buffer[indx] = gattEvtMask;
indx++;
buffer[indx] = encryKeySize;
indx++;
buffer[indx] = isVariable;
indx++;
Osal_MemSet(&resp, 0, sizeof(resp));
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_ADD_CHAR_DESC;
rq.cparam = (void *)buffer;
rq.clen = indx;
rq.rparam = &resp;
rq.rlen = GATT_ADD_CHAR_DESC_RP_SIZE;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
if (resp.status) {
return resp.status;
}
*descHandle = btohs(resp.handle);
return 0;
}
tBleStatus aci_gatt_update_char_value(uint16_t servHandle,
uint16_t charHandle,
uint8_t charValOffset,
uint8_t charValueLen,
const uint8_t *charValue)
{
struct hci_request rq;
uint8_t status;
uint8_t buffer[HCI_MAX_PAYLOAD_SIZE];
uint8_t indx = 0;
if ((charValueLen+6) > HCI_MAX_PAYLOAD_SIZE)
return BLE_STATUS_INVALID_PARAMS;
servHandle = htobs(servHandle);
Osal_MemCpy(buffer + indx, &servHandle, 2);
indx += 2;
charHandle = htobs(charHandle);
Osal_MemCpy(buffer + indx, &charHandle, 2);
indx += 2;
buffer[indx] = charValOffset;
indx++;
buffer[indx] = charValueLen;
indx++;
Osal_MemCpy(buffer + indx, charValue, charValueLen);
indx += charValueLen;
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_UPD_CHAR_VAL;
rq.cparam = (void *)buffer;
rq.clen = indx;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
if (status) {
return status;
}
return 0;
}
tBleStatus aci_gatt_del_char(uint16_t servHandle, uint16_t charHandle)
{
struct hci_request rq;
uint8_t status;
gatt_del_char_cp cp;
cp.service_handle = htobs(servHandle);
cp.char_handle = htobs(charHandle);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_DEL_CHAR;
rq.cparam = &cp;
rq.clen = GATT_DEL_CHAR_CP_SIZE;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_del_service(uint16_t servHandle)
{
struct hci_request rq;
uint8_t status;
gatt_del_serv_cp cp;
cp.service_handle = htobs(servHandle);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_DEL_SERV;
rq.cparam = &cp;
rq.clen = GATT_DEL_SERV_CP_SIZE;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_del_include_service(uint16_t servHandle, uint16_t includeServHandle)
{
struct hci_request rq;
uint8_t status;
gatt_del_inc_serv_cp cp;
cp.service_handle = htobs(servHandle);
cp.inc_serv_handle = htobs(includeServHandle);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_DEL_INC_SERV;
rq.cparam = &cp;
rq.clen = GATT_DEL_INC_SERV_CP_SIZE;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_set_event_mask(uint32_t event_mask)
{
struct hci_request rq;
uint8_t status;
gatt_set_evt_mask_cp cp;
cp.evt_mask = htobs(event_mask);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_SET_EVT_MASK;
rq.cparam = &cp;
rq.clen = GATT_SET_EVT_MASK_CP_SIZE;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_exchange_configuration(uint16_t conn_handle)
{
struct hci_request rq;
uint8_t status;
gatt_exchange_config_cp cp;
cp.conn_handle = htobs(conn_handle);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_EXCHANGE_CONFIG;
rq.cparam = &cp;
rq.clen = GATT_EXCHANGE_CONFIG_CP_SIZE;
rq.event = EVT_CMD_STATUS;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_att_find_information_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle)
{
struct hci_request rq;
uint8_t status;
att_find_info_req_cp cp;
cp.conn_handle = htobs(conn_handle);
cp.start_handle = htobs(start_handle);
cp.end_handle = htobs(end_handle);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_ATT_FIND_INFO_REQ;
rq.cparam = &cp;
rq.clen = ATT_FIND_INFO_REQ_CP_SIZE;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_att_find_by_type_value_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle,
uint8_t* uuid, uint8_t attr_val_len, uint8_t* attr_val)
{
struct hci_request rq;
uint8_t status;
att_find_by_type_value_req_cp cp;
if(attr_val_len > sizeof(cp.attr_val))
return BLE_STATUS_INVALID_PARAMS;
cp.conn_handle = htobs(conn_handle);
cp.start_handle = htobs(start_handle);
cp.end_handle = htobs(end_handle);
Osal_MemCpy(cp.uuid, uuid, 2);
cp.attr_val_len = attr_val_len;
Osal_MemCpy(cp.attr_val, attr_val, attr_val_len);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_ATT_FIND_BY_TYPE_VALUE_REQ;
rq.cparam = &cp;
rq.clen = ATT_FIND_BY_TYPE_VALUE_REQ_CP_SIZE + attr_val_len;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_att_read_by_type_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle,
uint8_t uuid_type, uint8_t* uuid)
{
struct hci_request rq;
uint8_t status;
att_read_by_type_req_cp cp;
uint8_t uuid_len;
if(uuid_type == UUID_TYPE_16){
uuid_len = 2;
}
else{
uuid_len = 16;
}
cp.conn_handle = htobs(conn_handle);
cp.start_handle = htobs(start_handle);
cp.end_handle = htobs(end_handle);
cp.uuid_type = uuid_type;
Osal_MemCpy(cp.uuid, uuid, uuid_len);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_ATT_READ_BY_TYPE_REQ;
rq.cparam = &cp;
rq.clen = ATT_READ_BY_TYPE_REQ_CP_SIZE + uuid_len;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_att_read_by_group_type_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle,
uint8_t uuid_type, uint8_t* uuid)
{
struct hci_request rq;
uint8_t status;
att_read_by_group_type_req_cp cp;
uint8_t uuid_len;
if(uuid_type == UUID_TYPE_16){
uuid_len = 2;
}
else{
uuid_len = 16;
}
cp.conn_handle = htobs(conn_handle);
cp.start_handle = htobs(start_handle);
cp.end_handle = htobs(end_handle);
cp.uuid_type = uuid_type;
Osal_MemCpy(cp.uuid, uuid, uuid_len);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_ATT_READ_BY_GROUP_TYPE_REQ;
rq.cparam = &cp;
rq.clen = ATT_READ_BY_GROUP_TYPE_REQ_CP_SIZE + uuid_len;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_att_prepare_write_req(uint16_t conn_handle, uint16_t attr_handle, uint16_t value_offset,
uint8_t attr_val_len, uint8_t* attr_val)
{
struct hci_request rq;
uint8_t status;
att_prepare_write_req_cp cp;
if(attr_val_len > sizeof(cp.attr_val))
return BLE_STATUS_INVALID_PARAMS;
cp.conn_handle = htobs(conn_handle);
cp.attr_handle = htobs(attr_handle);
cp.value_offset = htobs(value_offset);
cp.attr_val_len = attr_val_len;
Osal_MemCpy(cp.attr_val, attr_val, attr_val_len);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_ATT_PREPARE_WRITE_REQ;
rq.cparam = &cp;
rq.clen = ATT_PREPARE_WRITE_REQ_CP_SIZE + attr_val_len;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_att_execute_write_req(uint16_t conn_handle, uint8_t execute)
{
struct hci_request rq;
uint8_t status;
att_execute_write_req_cp cp;
cp.conn_handle = htobs(conn_handle);
cp.execute = execute;
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_ATT_EXECUTE_WRITE_REQ;
rq.cparam = &cp;
rq.clen = ATT_EXECUTE_WRITE_REQ_CP_SIZE;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_disc_all_prim_services(uint16_t conn_handle)
{
struct hci_request rq;
uint8_t status;
gatt_disc_all_prim_services_cp cp;
cp.conn_handle = htobs(conn_handle);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_DISC_ALL_PRIM_SERVICES;
rq.cparam = &cp;
rq.clen = GATT_DISC_ALL_PRIM_SERVICES_CP_SIZE;
rq.event = EVT_CMD_STATUS;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_disc_prim_service_by_uuid(uint16_t conn_handle, uint8_t uuid_type, uint8_t* uuid)
{
struct hci_request rq;
uint8_t status;
gatt_disc_prim_service_by_uuid_cp cp;
uint8_t uuid_len;
if(uuid_type == UUID_TYPE_16){
uuid_len = 2;
}
else{
uuid_len = 16;
}
cp.conn_handle = htobs(conn_handle);
cp.uuid_type = uuid_type;
Osal_MemCpy(cp.uuid, uuid, uuid_len);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_DISC_PRIM_SERVICE_BY_UUID;
rq.cparam = &cp;
rq.clen = GATT_DISC_PRIM_SERVICE_BY_UUID_CP_SIZE + uuid_len;
rq.event = EVT_CMD_STATUS;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_find_included_services(uint16_t conn_handle, uint16_t start_service_handle,
uint16_t end_service_handle)
{
struct hci_request rq;
uint8_t status;
gatt_find_included_services_cp cp;
cp.conn_handle = htobs(conn_handle);
cp.start_handle = htobs(start_service_handle);
cp.end_handle = htobs(end_service_handle);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_FIND_INCLUDED_SERVICES;
rq.cparam = &cp;
rq.clen = GATT_FIND_INCLUDED_SERVICES_CP_SIZE;
rq.event = EVT_CMD_STATUS;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_disc_all_charac_of_serv(uint16_t conn_handle, uint16_t start_attr_handle,
uint16_t end_attr_handle)
{
struct hci_request rq;
uint8_t status;
gatt_disc_all_charac_of_serv_cp cp;
cp.conn_handle = htobs(conn_handle);
cp.start_attr_handle = htobs(start_attr_handle);
cp.end_attr_handle = htobs(end_attr_handle);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_DISC_ALL_CHARAC_OF_SERV;
rq.cparam = &cp;
rq.clen = GATT_DISC_ALL_CHARAC_OF_SERV_CP_SIZE;
rq.event = EVT_CMD_STATUS;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_disc_charac_by_uuid(uint16_t conn_handle, uint16_t start_handle,
uint16_t end_handle, uint8_t charUuidType,
const uint8_t* charUuid)
{
struct hci_request rq;
uint8_t status;
uint8_t buffer[23];
uint8_t uuid_len;
uint8_t indx = 0;
conn_handle = htobs(conn_handle);
Osal_MemCpy(buffer + indx, &conn_handle, 2);
indx += 2;
start_handle = htobs(start_handle);
Osal_MemCpy(buffer + indx, &start_handle, 2);
indx += 2;
end_handle = htobs(end_handle);
Osal_MemCpy(buffer + indx, &end_handle, 2);
indx += 2;
buffer[indx] = charUuidType;
indx++;
if(charUuidType == 0x01){
uuid_len = 2;
}
else {
uuid_len = 16;
}
Osal_MemCpy(buffer + indx, charUuid, uuid_len);
indx += uuid_len;
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_DISC_CHARAC_BY_UUID;
rq.cparam = (void *)buffer;
rq.clen = indx;
rq.event = EVT_CMD_STATUS;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_disc_all_charac_descriptors(uint16_t conn_handle, uint16_t char_val_handle,
uint16_t char_end_handle)
{
struct hci_request rq;
uint8_t status;
gatt_disc_all_charac_descriptors_cp cp;
cp.conn_handle = htobs(conn_handle);
cp.char_val_handle = htobs(char_val_handle);
cp.char_end_handle = htobs(char_end_handle);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_DISC_ALL_CHARAC_DESCRIPTORS;
rq.cparam = &cp;
rq.clen = GATT_DISC_ALL_CHARAC_DESCRIPTORS_CP_SIZE;
rq.event = EVT_CMD_STATUS;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_read_charac_val(uint16_t conn_handle, uint16_t attr_handle)
{
struct hci_request rq;
uint8_t status;
gatt_read_charac_val_cp cp;
cp.conn_handle = htobs(conn_handle);
cp.attr_handle = htobs(attr_handle);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_READ_CHARAC_VAL;
rq.cparam = &cp;
rq.clen = GATT_READ_CHARAC_VAL_CP_SIZE;
rq.event = EVT_CMD_STATUS;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_read_using_charac_uuid(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle,
uint8_t uuid_type, uint8_t* uuid)
{
struct hci_request rq;
uint8_t status;
gatt_read_using_charac_uuid_cp cp;
uint8_t uuid_len;
if(uuid_type == UUID_TYPE_16){
uuid_len = 2;
}
else{
uuid_len = 16;
}
cp.conn_handle = htobs(conn_handle);
cp.start_handle = htobs(start_handle);
cp.end_handle = htobs(end_handle);
cp.uuid_type = uuid_type;
Osal_MemCpy(cp.uuid, uuid, uuid_len);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_READ_USING_CHARAC_UUID;
rq.cparam = &cp;
rq.clen = GATT_READ_USING_CHARAC_UUID_CP_SIZE + uuid_len;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_read_long_charac_val(uint16_t conn_handle, uint16_t attr_handle,
uint16_t val_offset)
{
struct hci_request rq;
uint8_t status;
gatt_read_long_charac_val_cp cp;
cp.conn_handle = htobs(conn_handle);
cp.attr_handle = htobs(attr_handle);
cp.val_offset = htobs(val_offset);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_READ_LONG_CHARAC_VAL;
rq.cparam = &cp;
rq.clen = GATT_READ_LONG_CHARAC_VAL_CP_SIZE;
rq.event = EVT_CMD_STATUS;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_read_multiple_charac_val(uint16_t conn_handle, uint8_t num_handles,
uint8_t* set_of_handles)
{
struct hci_request rq;
uint8_t status;
gatt_read_multiple_charac_val_cp cp;
if(num_handles*2 > sizeof(cp.set_of_handles))
return BLE_STATUS_INVALID_PARAMS;
cp.conn_handle = htobs(conn_handle);
cp.num_handles = htobs(num_handles);
Osal_MemCpy(cp.set_of_handles, set_of_handles, 2*num_handles);
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_READ_MULTIPLE_CHARAC_VAL;
rq.cparam = &cp;
rq.clen = GATT_READ_MULTIPLE_CHARAC_VAL_CP_SIZE + 2*num_handles;
rq.event = EVT_CMD_STATUS;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_write_charac_value(uint16_t conn_handle, uint16_t attr_handle,
uint8_t value_len, uint8_t *attr_value)
{
struct hci_request rq;
uint8_t status;
uint8_t buffer[HCI_MAX_PAYLOAD_SIZE];
uint8_t indx = 0;
if ((value_len+5) > HCI_MAX_PAYLOAD_SIZE)
return BLE_STATUS_INVALID_PARAMS;
conn_handle = htobs(conn_handle);
Osal_MemCpy(buffer + indx, &conn_handle, 2);
indx += 2;
attr_handle = htobs(attr_handle);
Osal_MemCpy(buffer + indx, &attr_handle, 2);
indx += 2;
buffer[indx] = value_len;
indx++;
Osal_MemCpy(buffer + indx, attr_value, value_len);
indx += value_len;
Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_VENDOR_CMD;
rq.ocf = OCF_GATT_WRITE_CHAR_VALUE;
rq.cparam = (void *)buffer;
rq.clen = indx;
rq.event = EVT_CMD_STATUS;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;
return status;
}
tBleStatus aci_gatt_write_long_charac_val(uint16_t conn_handle, uint16_t attr_handle,
uint16_t val_offset, uint8_t val_len, const uint8_t* attr_val)
{
struct hci_request rq;