-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcy_ble_cps.c
2457 lines (2176 loc) · 111 KB
/
cy_ble_cps.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
/***************************************************************************//**
* \file cy_ble_cps.c
* \version 3.60
*
* \brief
* Contains the source code for Cycling Power service.
*
********************************************************************************
* \copyright
* Copyright 2017-2021, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
*******************************************************************************/
#include "cy_ble_event_handler.h"
#if defined(CY_IP_MXBLESS)
#if CY_BLE_LIB_HOST_CORE
/*******************************************************************************
* Internal Defines / Macro Functions
*******************************************************************************/
#define Cy_BLE_CPSC_CheckCharHandle(handle) \
do { \
if((handle).valueHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE) \
{ \
(handle).valueHandle = discCharInfo->valueHandle; \
(handle).properties = discCharInfo->properties; \
} \
else \
{ \
Cy_BLE_ApplCallback((uint32_t)CY_BLE_EVT_GATTC_CHAR_DUPLICATION, \
&(discCharInfo)); \
} \
} while(0)
#define Cy_BLE_CPSS_ConnectEventHandler Cy_BLE_CPSS_Init
#define Cy_BLE_CPSS_DisconnectEventHandler Cy_BLE_CPSS_StopBroadcast
#define Cy_BLE_CPSC_DisconnectEventHandler Cy_BLE_CPSC_StopObserve
/*******************************************************************************
* Private Function Prototypes
*******************************************************************************/
static cy_en_ble_gatt_err_code_t Cy_BLE_CPS_EventHandler(uint32_t eventCode, void *eventParam);
static cy_en_ble_gatt_err_code_t Cy_BLE_CPSS_EventHandler(uint32_t eventCode, void *eventParam);
static cy_en_ble_gatt_err_code_t Cy_BLE_CPSC_EventHandler(uint32_t eventCode, void *eventParam);
static cy_en_ble_gatt_err_code_t Cy_BLE_CPSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam);
static void Cy_BLE_CPSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam);
static void Cy_BLE_CPSS_ConnParamUpdateRspEventHandler(const cy_stc_ble_l2cap_conn_update_rsp_param_t *eventParam);
static void Cy_BLE_CPSS_ConnUpdateCompleteEventHandler(const cy_stc_ble_gap_conn_param_updated_in_controller_t *eventParam);
static void Cy_BLE_CPSS_AdvertisementStartStopEventHandler(void);
static void Cy_BLE_CPSC_DiscoverCharacteristicsEventHandler(cy_stc_ble_disc_char_info_t *discCharInfo);
static void Cy_BLE_CPSC_DiscoverCharDescriptorsEventHandler(cy_stc_ble_disc_descr_info_t *discDescrInfo);
static void Cy_BLE_CPSC_GetCharRange(cy_stc_ble_disc_range_info_t *charRangeInfo);
static void Cy_BLE_CPSC_NotificationEventHandler(cy_stc_ble_gattc_handle_value_ntf_param_t *eventParam);
static void Cy_BLE_CPSC_IndicationEventHandler(cy_stc_ble_gattc_handle_value_ind_param_t *eventParam);
static void Cy_BLE_CPSC_ReadResponseEventHandler(cy_stc_ble_gattc_read_rsp_param_t *eventParam);
static void Cy_BLE_CPSC_WriteResponseEventHandler(const cy_stc_ble_conn_handle_t *eventParam);
static void Cy_BLE_CPSC_ErrorResponseEventHandler(const cy_stc_ble_gatt_err_param_t *eventParam);
static void Cy_BLE_CPSC_ScanStartStopEventHandler(void);
static void Cy_BLE_CPSC_ScanProcessEventHandler(cy_stc_ble_gapc_adv_report_param_t *eventParam);
static void Cy_BLE_CPSC_TimeOutEventHandler(const cy_stc_ble_timeout_param_t *eventParam);
/*******************************************************************************
* Global Variables
*******************************************************************************/
/* The pointers to the callback functions */
static cy_ble_callback_t Cy_BLE_CPS_ApplCallback = NULL;
static cy_ble_event_handler_cb_t Cy_BLE_CPSC_EventHandlerCallback = NULL;
static cy_ble_event_handler_cb_t Cy_BLE_CPSS_EventHandlerCallback = NULL;
/* The internal storage for the last request handle to check response for server */
static cy_ble_gatt_db_attr_handle_t cy_ble_cpssReqHandle;
/* The internal storage for the last request handle to check response */
static cy_ble_gatt_db_attr_handle_t cy_ble_cpscReqHandle[CY_BLE_MAX_CONNECTION_INSTANCES];
/* The pointer to a global BLE CPS server config structure */
const cy_stc_ble_cpss_config_t *cy_ble_cpssConfigPtr = NULL;
/* The pointer to a global BLE CPS client config structure */
const cy_stc_ble_cpsc_config_t *cy_ble_cpscConfigPtr = NULL;
cy_stc_ble_cps_cp_adjustment_t cy_ble_cpssAdjustment;
static uint8_t cy_ble_cpssFlag;
static cy_stc_ble_gap_conn_param_updated_in_controller_t cy_ble_cpssConnParam;
static uint8_t cy_ble_cpscFlag[CY_BLE_MAX_CONNECTION_INSTANCES];
static cy_stc_ble_timer_info_t cy_ble_cpscCpTimeout[CY_BLE_MAX_CONNECTION_INSTANCES];
static uint8_t cy_ble_cpscObserverFlag;
cy_stc_ble_gapp_disc_param_t cy_ble_cpssBroadcastParam;
cy_stc_ble_gapp_disc_data_t cy_ble_cpssBroadcastData =
{
{ /* Length, FLAGS, BR/EDR NOT Supported */
CY_BLE_GAP_ADV_FLAGS_PACKET_LENGTH, (uint8_t)CY_BLE_GAP_ADV_FLAGS, CY_BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED,
/* Advertising Interval data type contains the advInterval value */
CY_BLE_GAP_ADV_ADVERT_INTERVAL_PACKET_LENGTH, (uint8_t)CY_BLE_GAP_ADV_ADVERT_INTERVAL,
CY_LO8(CY_BLE_GAP_ADV_ADVERT_INTERVAL_NONCON_MIN), CY_HI8(CY_BLE_GAP_ADV_ADVERT_INTERVAL_NONCON_MIN),
/* The service data type consists of a CPS service UUID with the Cycling Power Measurement
* characteristic value */
CY_BLE_CPSS_BROADCAST_DATA_LEN_MIN, /* Packet length */
(uint8_t)CY_BLE_GAP_ADV_SRVC_DATA_16UUID, /* service data */
CY_LO8(CY_BLE_UUID_CPS_SERVICE), CY_HI8(CY_BLE_UUID_CPS_SERVICE), /* CPS service UUID */
0x00u, 0x00u, /* Flags */
0x11u, 0x11u, /* Instantaneous Power */
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u
},
/* Advertising data length */
CY_BLE_CPSS_BROADCAST_DATA_LEN_MIN + CY_BLE_CPSS_BROADCAST_HEADER_LEN,
};
cy_stc_ble_gapp_disc_mode_info_t cy_ble_cpssBroadcastModeInfo =
{
CY_BLE_GAPP_NONE_DISC_BROADCAST_MODE, /* discMode */
&cy_ble_cpssBroadcastParam,
&cy_ble_cpssBroadcastData,
NULL,
0u, /* advTo */
};
/******************************************************************************
* Function Name: Cy_BLE_CPSS_Init
***************************************************************************//**
*
* This function initializes server of the Cycling Power service.
*
* \param config: Configuration structure for the CPS.
*
* \return
* \ref cy_en_ble_api_result_t : Return value indicates whether the function succeeded or
* failed. The following are possible error codes.
*
* Error Codes | Description
* ------------ | -----------
* CY_BLE_SUCCESS | The function completed successfully.
* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter.
* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback.
*
******************************************************************************/
cy_en_ble_api_result_t Cy_BLE_CPSS_Init(const cy_stc_ble_cpss_config_t *config)
{
cy_en_ble_api_result_t apiResult;
if(config == NULL)
{
apiResult = CY_BLE_ERROR_INVALID_PARAMETER;
}
else
{
/* Registers a pointer to config structure */
cy_ble_cpssConfigPtr = config;
/* Registers event handler for the CPS */
apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_CPS_EventHandler);
/* Registers a pointer to server event handler function */
Cy_BLE_CPSS_EventHandlerCallback = &Cy_BLE_CPSS_EventHandler;
cy_ble_cpssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE;
cy_ble_cpssFlag = 0u;
cy_ble_cpssAdjustment.samplingRate = CY_BLE_CPS_SAMLING_RATE_DEFAULT;
}
return(apiResult);
}
/******************************************************************************
* Function Name: Cy_BLE_CPSC_Init
***************************************************************************//**
*
* This function initializes client of the Cycling Power service.
*
* \param config: Configuration structure for the CPS.
*
* \return
* \ref cy_en_ble_api_result_t : Return value indicates whether the function succeeded or
* failed. The following are possible error codes.
*
* Error Codes | Description
* ------------ | -----------
* CY_BLE_SUCCESS | The function completed successfully.
* CY_BLE_ERROR_INVALID_PARAMETER | On specifying NULL as input parameter.
* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Buffer overflow in the registration callback.
*
******************************************************************************/
cy_en_ble_api_result_t Cy_BLE_CPSC_Init(const cy_stc_ble_cpsc_config_t *config)
{
cy_en_ble_api_result_t apiResult;
if((config == NULL) || ((cy_ble_configPtr->params->gattRole & CY_BLE_GATT_CLIENT) == 0u))
{
apiResult = CY_BLE_ERROR_INVALID_PARAMETER;
}
else
{
uint32_t idx;
/* Registers a pointer to config structure */
cy_ble_cpscConfigPtr = config;
/* Registers event handler for the CPS */
apiResult = Cy_BLE_RegisterServiceEventHandler(&Cy_BLE_CPS_EventHandler);
/* Registers a pointer to client event handler function */
Cy_BLE_CPSC_EventHandlerCallback = &Cy_BLE_CPSC_EventHandler;
for(idx = 0u; idx < cy_ble_configPtr->params->maxClientCount; idx++)
{
uint32 servCnt = cy_ble_configPtr->context->discServiCount;
uint32 cpsServIdx = cy_ble_cpscConfigPtr->serviceDiscIdx;
if(cy_ble_configPtr->context->serverInfo[(idx * servCnt) + cpsServIdx].range.startHandle ==
CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)
{
/* Get pointer to CPS client structure */
cy_stc_ble_cpsc_t *cpscPtr = (cy_stc_ble_cpsc_t *)&cy_ble_cpscConfigPtr->attrInfo[idx];
/* Clean client structure */
(void)memset(cpscPtr, 0, sizeof(cy_stc_ble_cpsc_t));
/* Initialize uuid */
cy_ble_configPtr->context->serverInfo[(idx * servCnt) + cpsServIdx].uuid =
CY_BLE_UUID_CPS_SERVICE;
}
cy_ble_cpscFlag[idx] = 0u;
cy_ble_cpscCpTimeout[idx].timeout = CY_BLE_CPS_CP_PROCEDURE_TIMEOUT;
cy_ble_cpscReqHandle[idx] = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE;
}
}
return(apiResult);
}
/******************************************************************************
* Function Name: Cy_BLE_CPS_RegisterAttrCallback
***************************************************************************//**
*
* Registers a callback function for service-specific attribute operations.
* Service-specific Write Requests from the peer device will not be handled with
* an unregistered callback function.
*
* \param callbackFunc: An application layer event callback function to receive
* events from the PSoC 6 BLE Middleware. The definition of \ref cy_ble_callback_t
* for CPS service is:<br>
* typedef void (* cy_ble_callback_t) (uint32_t eventCode, void *eventParam),
* where:
* * eventCode: Indicates the event that triggered this callback
* (e.g. #CY_BLE_EVT_CPSS_NOTIFICATION_ENABLED).
* * eventParam: Contains the parameters corresponding to the
* current event; (e.g. pointer to \ref cy_stc_ble_cps_char_value_t
* structure that contains details of the characteristic
* for which the notification enabled event was triggered).
*
******************************************************************************/
void Cy_BLE_CPS_RegisterAttrCallback(cy_ble_callback_t callbackFunc)
{
Cy_BLE_CPS_ApplCallback = callbackFunc;
}
/******************************************************************************
* Function Name: Cy_BLE_CPSS_SetCharacteristicValue
***************************************************************************//**
*
* Sets a characteristic value of Cycling Power service, which is a value
* identified by charIndex, to the local database.
*
* \param charIndex: The index of the service characteristic of type
* \ref cy_en_ble_cps_char_index_t. The valid values are,
* * \ref CY_BLE_CPS_POWER_MEASURE
* * \ref CY_BLE_CPS_POWER_FEATURE
* * \ref CY_BLE_CPS_SENSOR_LOCATION
* * \ref CY_BLE_CPS_POWER_VECTOR
* * \ref CY_BLE_CPS_POWER_CP
* \param attrSize: The size of the characteristic value attribute.
* \param attrValue: The pointer to the characteristic value data that should be
* stored to the GATT database.
*
* \return
* A return value of type \ref cy_en_ble_api_result_t.
*
* Error Codes | Description
* ------------ | -----------
* CY_BLE_SUCCESS | The request was handled successfully.
* CY_BLE_ERROR_INVALID_PARAMETER | Validation of the input parameter failed.
* CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE| An optional characteristic is absent.
*
******************************************************************************/
cy_en_ble_api_result_t Cy_BLE_CPSS_SetCharacteristicValue(cy_en_ble_cps_char_index_t charIndex,
uint8_t attrSize,
uint8_t *attrValue)
{
cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS;
if(charIndex >= CY_BLE_CPS_CHAR_COUNT)
{
apiResult = CY_BLE_ERROR_INVALID_PARAMETER;
}
else
{
/* Store data in database */
cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo;
dbAttrValInfo.connHandle.bdHandle = 0u;
dbAttrValInfo.connHandle.attId = 0u;
dbAttrValInfo.handleValuePair.attrHandle = cy_ble_cpssConfigPtr->attrInfo->charInfo[charIndex].charHandle;
dbAttrValInfo.handleValuePair.value.len = attrSize;
dbAttrValInfo.handleValuePair.value.val = attrValue;
dbAttrValInfo.offset = 0u;
dbAttrValInfo.flags = CY_BLE_GATT_DB_LOCALLY_INITIATED;
if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE)
{
apiResult = CY_BLE_ERROR_INVALID_PARAMETER;
}
}
return(apiResult);
}
/******************************************************************************
* Function Name: Cy_BLE_CPSS_GetCharacteristicValue
***************************************************************************//**
*
* Gets a characteristic value of Cycling Power service. The value is
* identified by charIndex.
*
* \param charIndex: The index of the service characteristic of type
* \ref cy_en_ble_cps_char_index_t. The valid values are,
* * \ref CY_BLE_CPS_POWER_MEASURE
* * \ref CY_BLE_CPS_POWER_FEATURE
* * \ref CY_BLE_CPS_SENSOR_LOCATION
* * \ref CY_BLE_CPS_POWER_VECTOR
* * \ref CY_BLE_CPS_POWER_CP
* \param attrSize: The size of the characteristic value attribute.
* \param attrValue: The pointer to the location where characteristic value data
* should be stored.
*
* \return
* A return value of type \ref cy_en_ble_api_result_t.
*
* Error Codes | Description
* ------------ | -----------
* CY_BLE_SUCCESS | The characteristic value was read successfully.
* CY_BLE_ERROR_INVALID_PARAMETER | Validation of the input parameter failed.
*
******************************************************************************/
cy_en_ble_api_result_t Cy_BLE_CPSS_GetCharacteristicValue(cy_en_ble_cps_char_index_t charIndex,
uint8_t attrSize,
uint8_t *attrValue)
{
cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS;
if(charIndex >= CY_BLE_CPS_CHAR_COUNT)
{
apiResult = CY_BLE_ERROR_INVALID_PARAMETER;
}
else
{
cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo;
dbAttrValInfo.connHandle.bdHandle = 0u;
dbAttrValInfo.connHandle.attId = 0u;
dbAttrValInfo.handleValuePair.attrHandle = cy_ble_cpssConfigPtr->attrInfo->charInfo[charIndex].charHandle;
dbAttrValInfo.handleValuePair.value.len = attrSize;
dbAttrValInfo.handleValuePair.value.val = attrValue;
dbAttrValInfo.offset = 0u;
dbAttrValInfo.flags = CY_BLE_GATT_DB_LOCALLY_INITIATED;
if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE)
{
apiResult = CY_BLE_ERROR_INVALID_PARAMETER;
}
}
return(apiResult);
}
/******************************************************************************
* Function Name: Cy_BLE_CPSS_SetCharacteristicDescriptor
***************************************************************************//**
*
* Sets a characteristic descriptor of the specified characteristic of Cycling
* Power service.
*
* \param connHandle: The connection handle.
* \param charIndex: The index of the service characteristic of type
* \ref cy_en_ble_cps_char_index_t. The valid values are,
* * \ref CY_BLE_CPS_POWER_MEASURE
* * \ref CY_BLE_CPS_POWER_FEATURE
* * \ref CY_BLE_CPS_SENSOR_LOCATION
* * \ref CY_BLE_CPS_POWER_VECTOR
* * \ref CY_BLE_CPS_POWER_CP
* \param descrIndex: The index of the service characteristic descriptor of type
* \ref cy_en_ble_cps_descr_index_t. The valid values are,
* * \ref CY_BLE_CPS_CCCD
* * \ref CY_BLE_CPS_SCCD
* \param attrSize: The size of the characteristic descriptor attribute.
* \param attrValue: The pointer to the descriptor value data that should
* be stored to the GATT database.
*
* \return
* A return value of type \ref cy_en_ble_api_result_t.
*
* Error Codes | Description
* ------------ | -----------
* CY_BLE_SUCCESS | The characteristic descriptor value was read successfully.
* CY_BLE_ERROR_INVALID_PARAMETER | Validation of the input parameter failed.
*
******************************************************************************/
cy_en_ble_api_result_t Cy_BLE_CPSS_SetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle,
cy_en_ble_cps_char_index_t charIndex,
cy_en_ble_cps_descr_index_t descrIndex,
uint8_t attrSize,
uint8_t *attrValue)
{
cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS;
if((charIndex >= CY_BLE_CPS_CHAR_COUNT) || (descrIndex >= CY_BLE_CPS_DESCR_COUNT))
{
apiResult = CY_BLE_ERROR_INVALID_PARAMETER;
}
else
{
cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo;
dbAttrValInfo.handleValuePair.attrHandle = cy_ble_cpssConfigPtr->attrInfo->charInfo[charIndex].descrHandle[descrIndex];
dbAttrValInfo.handleValuePair.value.len = attrSize;
dbAttrValInfo.handleValuePair.value.val = attrValue;
dbAttrValInfo.connHandle = connHandle;
dbAttrValInfo.offset = 0u;
dbAttrValInfo.flags = CY_BLE_GATT_DB_LOCALLY_INITIATED;
if(Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE)
{
apiResult = CY_BLE_ERROR_INVALID_PARAMETER;
}
}
return(apiResult);
}
/******************************************************************************
* Function Name: Cy_BLE_CPSS_GetCharacteristicDescriptor
***************************************************************************//**
*
* Gets a characteristic descriptor of the specified characteristic of Cycling
* Power service.
*
* \param connHandle: The connection handle.
* \param charIndex: The index of the service characteristic of type
* \ref cy_en_ble_cps_char_index_t. The valid values are,
* * \ref CY_BLE_CPS_POWER_MEASURE
* * \ref CY_BLE_CPS_POWER_FEATURE
* * \ref CY_BLE_CPS_SENSOR_LOCATION
* * \ref CY_BLE_CPS_POWER_VECTOR
* * \ref CY_BLE_CPS_POWER_CP
* \param descrIndex: The index of the service characteristic descriptor of type
* \ref cy_en_ble_cps_descr_index_t. The valid values are,
* * \ref CY_BLE_CPS_CCCD
* * \ref CY_BLE_CPS_SCCD
* \param attrSize: The size of the characteristic descriptor attribute.
* \param attrValue: The pointer to the location where characteristic descriptor
* value data should be stored.
*
* \return
* A return value of type \ref cy_en_ble_api_result_t.
*
* Error Codes | Description
* ------------ | -----------
* CY_BLE_SUCCESS | The characteristic descriptor value was read successfully.
* CY_BLE_ERROR_INVALID_PARAMETER | Validation of the input parameter failed.
*
******************************************************************************/
cy_en_ble_api_result_t Cy_BLE_CPSS_GetCharacteristicDescriptor(cy_stc_ble_conn_handle_t connHandle,
cy_en_ble_cps_char_index_t charIndex,
cy_en_ble_cps_descr_index_t descrIndex,
uint8_t attrSize,
uint8_t *attrValue)
{
cy_en_ble_api_result_t apiResult = CY_BLE_SUCCESS;
if((charIndex >= CY_BLE_CPS_CHAR_COUNT) || (descrIndex >= CY_BLE_CPS_DESCR_COUNT))
{
apiResult = CY_BLE_ERROR_INVALID_PARAMETER;
}
else
{
cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo;
dbAttrValInfo.handleValuePair.attrHandle = cy_ble_cpssConfigPtr->attrInfo->charInfo[charIndex].descrHandle[descrIndex];
dbAttrValInfo.handleValuePair.value.len = attrSize;
dbAttrValInfo.handleValuePair.value.val = attrValue;
dbAttrValInfo.connHandle = connHandle;
dbAttrValInfo.offset = 0u;
dbAttrValInfo.flags = CY_BLE_GATT_DB_LOCALLY_INITIATED;
if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfo) != CY_BLE_GATT_ERR_NONE)
{
apiResult = CY_BLE_ERROR_INVALID_PARAMETER;
}
}
return(apiResult);
}
/******************************************************************************
* Function Name: Cy_BLE_CPSS_WriteEventHandler
***************************************************************************//**
*
* Handles Write Request event for CPS service.
*
* \param eventParam: The pointer to the data structure specified by the event.
*
* \return
* A return value of type cy_en_ble_gatt_err_code_t.
* * CY_BLE_GATT_ERR_NONE - write is successful
* * CY_BLE_GATT_ERR_PROCEDURE_ALREADY_IN_PROGRESS
* * CY_BLE_GATT_ERR_CCCD_IMPROPERLY_CONFIGURED
*
******************************************************************************/
static cy_en_ble_gatt_err_code_t Cy_BLE_CPSS_WriteEventHandler(cy_stc_ble_gatts_write_cmd_req_param_t *eventParam)
{
cy_en_ble_cps_char_index_t locCharIndex;
cy_stc_ble_cps_char_value_t locCharValue = { .connHandle = eventParam->connHandle };
cy_en_ble_gatt_err_code_t gattErr = CY_BLE_GATT_ERR_NONE;
uint8_t locReqHandle = 0u;
if(Cy_BLE_CPS_ApplCallback != NULL)
{
/* Error conditions for CP Characteristic value Write Request */
if((eventParam->handleValPair.attrHandle == cy_ble_cpssConfigPtr->attrInfo->charInfo[CY_BLE_CPS_POWER_CP].charHandle) &&
(!CY_BLE_IS_INDICATION_ENABLED(eventParam->connHandle.attId,
cy_ble_cpssConfigPtr->attrInfo->charInfo[CY_BLE_CPS_POWER_CP].
descrHandle[CY_BLE_CPS_CCCD])))
{
gattErr = CY_BLE_GATT_ERR_CCCD_IMPROPERLY_CONFIGURED;
cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK;
}
else if((eventParam->handleValPair.attrHandle ==
cy_ble_cpssConfigPtr->attrInfo->charInfo[CY_BLE_CPS_POWER_CP].charHandle) &&
((cy_ble_cpssFlag & CY_BLE_CPSS_FLAG_CP_PROCEDURE_IN_PROGRESS) != 0u))
{
gattErr = CY_BLE_GATT_ERR_PROCEDURE_ALREADY_IN_PROGRESS;
cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK;
}
else
{
for(locCharIndex = CY_BLE_CPS_POWER_MEASURE; (locCharIndex < CY_BLE_CPS_CHAR_COUNT) && (locReqHandle == 0u);
locCharIndex++)
{
if((eventParam->handleValPair.attrHandle == cy_ble_cpssConfigPtr->attrInfo->charInfo[locCharIndex].
descrHandle[CY_BLE_CPS_CCCD]) ||
(eventParam->handleValPair.attrHandle == cy_ble_cpssConfigPtr->attrInfo->charInfo[locCharIndex].
descrHandle[CY_BLE_CPS_SCCD]) ||
(eventParam->handleValPair.attrHandle == cy_ble_cpssConfigPtr->attrInfo->charInfo[locCharIndex].charHandle))
{
/* Store value to database */
cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfo;
dbAttrValInfo.handleValuePair = eventParam->handleValPair;
dbAttrValInfo.connHandle = eventParam->connHandle;
dbAttrValInfo.offset = 0u;
dbAttrValInfo.flags = CY_BLE_GATT_DB_PEER_INITIATED;
/* Clear event handled flag to send Write Response */
cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK;
locReqHandle = 1u;
locCharValue.charIndex = locCharIndex;
locCharValue.value = &eventParam->handleValPair.value;
gattErr = Cy_BLE_GATTS_WriteAttributeValueCCCD(&dbAttrValInfo);
if(gattErr == CY_BLE_GATT_ERR_NONE)
{
/* Characteristic value Write Request */
if(eventParam->handleValPair.attrHandle ==
cy_ble_cpssConfigPtr->attrInfo->charInfo[locCharIndex].charHandle)
{
Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_WRITE_CHAR, &locCharValue);
/* In the context of the Cycling Power Control Point characteristic, a procedure is started
* when a write to the Cycling Power Control Point characteristic is successfully completed
*/
if(locCharIndex == CY_BLE_CPS_POWER_CP)
{
cy_ble_cpssFlag |= CY_BLE_CPSS_FLAG_CP_PROCEDURE_IN_PROGRESS;
}
}
/* Client Characteristic Configuration descriptor Write Request */
else if(eventParam->handleValPair.attrHandle ==
cy_ble_cpssConfigPtr->attrInfo->charInfo[locCharIndex].descrHandle[CY_BLE_CPS_CCCD])
{
/* Check characteristic properties for Notification */
if(CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_cpssConfigPtr->attrInfo->charInfo[locCharIndex].
charHandle))
{
if(CY_BLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val))
{
uint16_t requiredConnIntv;
uint8_t prefConnParamCharValue[CY_BLE_PPCPC_LEN];
requiredConnIntv = CY_BLE_CPS_SAMLING_RATE_TO_CONN_INTV /
cy_ble_cpssAdjustment.samplingRate;
/* Cycling Power Vector characteristic has special behavior
* described in CPS specification, section 3.5.1 */
if((locCharIndex == CY_BLE_CPS_POWER_VECTOR) &&
(cy_ble_cpssConnParam.connIntv > requiredConnIntv))
{
/* Read characteristic value from database */
cy_stc_ble_gatts_db_attr_val_info_t dbAttrValInfoCCCD;
dbAttrValInfoCCCD.connHandle.bdHandle = 0u;
dbAttrValInfoCCCD.connHandle.attId = 0u;
dbAttrValInfoCCCD.handleValuePair.attrHandle = cy_ble_gapsConfigPtr->attrInfo->prefConnParamCharHandle;
dbAttrValInfoCCCD.handleValuePair.value.len = sizeof(prefConnParamCharValue);
dbAttrValInfoCCCD.handleValuePair.value.val = prefConnParamCharValue;
dbAttrValInfoCCCD.flags = CY_BLE_GATT_DB_LOCALLY_INITIATED;
if(Cy_BLE_GATTS_ReadAttributeValueCCCD(&dbAttrValInfoCCCD) ==
CY_BLE_GATT_ERR_NONE)
{
/* If the current connection parameters do not allow sending of
* notification, request new connection parameters by using the GAP
* Connection Parameter Update procedure.
*/
cy_stc_ble_gap_conn_update_param_info_t connUpdateParam;
/* Send Connection Parameter Update Request to Client */
connUpdateParam.connIntvMin = requiredConnIntv;
connUpdateParam.connIntvMax = requiredConnIntv;
connUpdateParam.connLatency = Cy_BLE_Get16ByPtr(prefConnParamCharValue +
CY_BLE_PPCPC_SLAVE_LATENCY_OFFSET);
connUpdateParam.supervisionTO = Cy_BLE_Get16ByPtr(prefConnParamCharValue +
CY_BLE_PPCPC_SUP_TIMEOUT_OFFSET);
connUpdateParam.bdHandle = eventParam->connHandle.bdHandle;
if(Cy_BLE_L2CAP_LeConnectionParamUpdateRequest(&connUpdateParam)
== CY_BLE_SUCCESS)
{
cy_ble_cpssFlag |= CY_BLE_CPSS_FLAG_PV_PROCEDURE_IN_PROGRESS;
/* Set event handled flag to not send Write Response. Response will be
* sent when Central accept the request for connection parameter update
* in Cy_BLE_CPSS_ConnParamUpdateRspEventHandler function.
*/
cy_ble_eventHandlerFlag |= CY_BLE_CALLBACK;
}
}
}
else
{
Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_NOTIFICATION_ENABLED,
&locCharValue);
}
}
else
{
Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_NOTIFICATION_DISABLED,
&locCharValue);
}
}
/* Check characteristic properties for Indication */
if(CY_BLE_IS_INDICATION_SUPPORTED(cy_ble_cpssConfigPtr->attrInfo->charInfo[locCharIndex].charHandle))
{
if(CY_BLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val))
{
Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_INDICATION_ENABLED, &locCharValue);
}
else
{
Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_INDICATION_DISABLED, &locCharValue);
}
}
}
/* Server Characteristic Configuration descriptor Write Request */
else
{
/* Check characteristic properties for Broadcast */
if(CY_BLE_IS_BROADCAST_SUPPORTED(cy_ble_cpssConfigPtr->attrInfo->charInfo[locCharIndex].
charHandle))
{
if(CY_BLE_IS_BROADCAST_ENABLED_IN_PTR(eventParam->handleValPair.value.val))
{
Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_BROADCAST_ENABLED, &locCharValue);
}
else
{
Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_BROADCAST_DISABLED, &locCharValue);
}
}
}
}
}
}
}
}
return(gattErr);
}
/******************************************************************************
* Function Name: Cy_BLE_CPSS_SendNotification
***************************************************************************//**
*
* Sends notification with a characteristic value of the CPS, which is a value
* specified by charIndex, to the client device.
*
* On enabling notification successfully for a service characteristic it sends out a
* 'Handle Value Notification' which results in \ref CY_BLE_EVT_CPSC_NOTIFICATION event
* at the GATT Client's end.
*
* \param connHandle: The connection handle
* \param charIndex: The index of the service characteristic of type
* \ref cy_en_ble_cps_char_index_t. The valid values are,
* * \ref CY_BLE_CPS_POWER_MEASURE
* * \ref CY_BLE_CPS_POWER_FEATURE
* * \ref CY_BLE_CPS_SENSOR_LOCATION
* * \ref CY_BLE_CPS_POWER_VECTOR
* * \ref CY_BLE_CPS_POWER_CP
* \param attrSize: The size of the characteristic value attribute.
* \param attrValue: The pointer to the characteristic value data that should be
* sent to the client device.
* \return
* A return value of type \ref cy_en_ble_api_result_t.
*
* Error Codes | Description
* ------------ | -----------
* CY_BLE_SUCCESS | The request was handled successfully.
* CY_BLE_ERROR_INVALID_PARAMETER | Validation of the input parameter failed.
* CY_BLE_ERROR_INVALID_OPERATION | Operation is invalid for this characteristic.
* CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE | An optional characteristic is absent.
* CY_BLE_ERROR_INVALID_STATE | Connection with the client is not established.
* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed.
* CY_BLE_ERROR_NTF_DISABLED | Notification is not enabled by the client.
*
******************************************************************************/
cy_en_ble_api_result_t Cy_BLE_CPSS_SendNotification(cy_stc_ble_conn_handle_t connHandle,
cy_en_ble_cps_char_index_t charIndex,
uint8_t attrSize,
uint8_t *attrValue)
{
cy_en_ble_api_result_t apiResult;
/* Send Notification if it is enabled and connected */
if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED)
{
apiResult = CY_BLE_ERROR_INVALID_STATE;
}
else if(charIndex >= CY_BLE_CPS_CHAR_COUNT)
{
apiResult = CY_BLE_ERROR_INVALID_PARAMETER;
}
else if(cy_ble_cpssConfigPtr->attrInfo->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)
{
apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE;
}
else if((!CY_BLE_IS_NOTIFICATION_SUPPORTED(cy_ble_cpssConfigPtr->attrInfo->charInfo[charIndex].charHandle)) ||
(!CY_BLE_IS_NOTIFICATION_ENABLED(connHandle.attId, cy_ble_cpssConfigPtr->attrInfo->charInfo[charIndex].
descrHandle[CY_BLE_CPS_CCCD])))
{
apiResult = CY_BLE_ERROR_NTF_DISABLED;
}
else
{
cy_stc_ble_gatts_handle_value_ntf_t ntfReqParam;
/* Fill all fields of Write Request structure ... */
ntfReqParam.handleValPair.attrHandle = cy_ble_cpssConfigPtr->attrInfo->charInfo[charIndex].charHandle;
ntfReqParam.handleValPair.value.val = attrValue;
ntfReqParam.handleValPair.value.len = attrSize;
ntfReqParam.connHandle = connHandle;
/* Send notification to the client using previously filled structure */
apiResult = Cy_BLE_GATTS_Notification(&ntfReqParam);
}
return(apiResult);
}
/******************************************************************************
* Function Name: Cy_BLE_CPSS_SendIndication
***************************************************************************//**
*
* Sends indication with a characteristic value of the CPS, which is a value
* specified by charIndex, to the client device.
*
* On enabling indication successfully it sends out a 'Handle Value Indication' which
* results in \ref CY_BLE_EVT_CPSC_INDICATION or \ref CY_BLE_EVT_GATTC_HANDLE_VALUE_IND (if
* service-specific callback function is not registered) event at the GATT Client's end.
*
* \param connHandle: The connection handle
* \param charIndex: The index of the service characteristic of type
* \ref cy_en_ble_cps_char_index_t. The valid values are,
* * \ref CY_BLE_CPS_POWER_MEASURE
* * \ref CY_BLE_CPS_POWER_FEATURE
* * \ref CY_BLE_CPS_SENSOR_LOCATION
* * \ref CY_BLE_CPS_POWER_VECTOR
* * \ref CY_BLE_CPS_POWER_CP
* \param attrSize: The size of the characteristic value attribute.
* \param attrValue: The pointer to the characteristic value data that should be
* sent to the client device.
* \return
* A return value of type \ref cy_en_ble_api_result_t.
*
* Error Codes | Description
* ------------ | -----------
* CY_BLE_SUCCESS | The request was handled successfully.
* CY_BLE_ERROR_INVALID_PARAMETER | Validation of the input parameter failed.
* CY_BLE_ERROR_INVALID_OPERATION | Operation is invalid for this characteristic.
* CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE | An optional characteristic is absent.
* CY_BLE_ERROR_INVALID_STATE | Connection with the client is not established.
* CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed.
* CY_BLE_ERROR_NTF_DISABLED | Notification is not enabled by the client.
*
* \events
* In case of successful execution (return value = \ref CY_BLE_SUCCESS)
* the following events can appear: \n
* If the CPS service-specific callback is registered
* with \ref Cy_BLE_CPS_RegisterAttrCallback():
* * \ref CY_BLE_EVT_CPSS_INDICATION_CONFIRMED - In case if the indication is
* successfully delivered to the peer device.
* .
* Otherwise, if the CPS service-specific callback is not registered:
* * \ref CY_BLE_EVT_GATTS_HANDLE_VALUE_CNF - In case if the indication is
* successfully delivered to the peer device.
*
******************************************************************************/
cy_en_ble_api_result_t Cy_BLE_CPSS_SendIndication(cy_stc_ble_conn_handle_t connHandle,
cy_en_ble_cps_char_index_t charIndex,
uint8_t attrSize,
uint8_t *attrValue)
{
cy_en_ble_api_result_t apiResult;
/* Send Notification if it is enabled and connected */
if(Cy_BLE_GetConnectionState(connHandle) < CY_BLE_CONN_STATE_CONNECTED)
{
apiResult = CY_BLE_ERROR_INVALID_STATE;
}
else if(charIndex >= CY_BLE_CPS_CHAR_COUNT)
{
apiResult = CY_BLE_ERROR_INVALID_PARAMETER;
}
else if(cy_ble_cpssConfigPtr->attrInfo->charInfo[charIndex].charHandle == CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE)
{
apiResult = CY_BLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE;
}
else if((!CY_BLE_IS_INDICATION_SUPPORTED(cy_ble_cpssConfigPtr->attrInfo->charInfo[charIndex].charHandle)) ||
(!CY_BLE_IS_INDICATION_ENABLED(connHandle.attId, cy_ble_cpssConfigPtr->attrInfo->charInfo[charIndex].
descrHandle[CY_BLE_CPS_CCCD])))
{
apiResult = CY_BLE_ERROR_IND_DISABLED;
}
else
{
cy_stc_ble_gatts_handle_value_ind_t indReqParam;
/* Fill all fields of Write Request structure ... */
indReqParam.handleValPair.attrHandle = cy_ble_cpssConfigPtr->attrInfo->charInfo[charIndex].charHandle;
indReqParam.handleValPair.value.val = attrValue;
indReqParam.handleValPair.value.len = attrSize;
indReqParam.connHandle = connHandle;
/* Send indication to client using previously filled structure */
apiResult = Cy_BLE_GATTS_Indication(&indReqParam);
/* Save handle to support service-specific value confirmation response from Client */
if(apiResult == CY_BLE_SUCCESS)
{
cy_ble_cpssReqHandle = indReqParam.handleValPair.attrHandle;
}
}
return(apiResult);
}
/******************************************************************************
* Function Name: Cy_BLE_CPSS_ConfirmationEventHandler
***************************************************************************//**
*
* Handles a Value Confirmation request event from the BLE Stack.
*
* *eventParam - Pointer to a structure of type 'cy_stc_ble_conn_handle_t'.
*
******************************************************************************/
static void Cy_BLE_CPSS_ConfirmationEventHandler(const cy_stc_ble_conn_handle_t *eventParam)
{
cy_en_ble_cps_char_index_t locCharIndex;
cy_stc_ble_cps_char_value_t locCharValue = { .connHandle = *eventParam };
uint8_t locReqHandle = 0u;
if((Cy_BLE_CPS_ApplCallback != NULL) && (CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE != cy_ble_cpssReqHandle))
{
for(locCharIndex = CY_BLE_CPS_POWER_MEASURE; (locCharIndex < CY_BLE_CPS_CHAR_COUNT) && (locReqHandle == 0u);
locCharIndex++)
{
if(cy_ble_cpssReqHandle == cy_ble_cpssConfigPtr->attrInfo->charInfo[locCharIndex].charHandle)
{
locCharValue.charIndex = locCharIndex;
locCharValue.value = NULL;
cy_ble_eventHandlerFlag &= (uint8_t) ~CY_BLE_CALLBACK;
cy_ble_cpssReqHandle = CY_BLE_GATT_INVALID_ATTR_HANDLE_VALUE;
/* The Cycling Power Control Point procedure is complete when the server indicated with the Op Code
* set to Response Code.
*/
if(locCharIndex == CY_BLE_CPS_POWER_CP)
{
cy_ble_cpssFlag &= (uint8_t) ~CY_BLE_CPSS_FLAG_CP_PROCEDURE_IN_PROGRESS;
}
Cy_BLE_CPS_ApplCallback((uint32_t)CY_BLE_EVT_CPSS_INDICATION_CONFIRMED, &locCharValue);
locReqHandle = 1u;
}
}
}
}
/******************************************************************************
* Function Name: Cy_BLE_CPSS_ConnParamUpdateRspEventHandler
***************************************************************************//**
*
* Handles the L2CAP connection parameter response event from
* the BLE Stack.
*
* \param eventParam: The pointer to the data structure specified by the event.
*
******************************************************************************/
static void Cy_BLE_CPSS_ConnParamUpdateRspEventHandler(const cy_stc_ble_l2cap_conn_update_rsp_param_t *eventParam)
{
if((Cy_BLE_CPS_ApplCallback != NULL) && ((cy_ble_cpssFlag & CY_BLE_CPSS_FLAG_PV_PROCEDURE_IN_PROGRESS) != 0u))
{
cy_stc_ble_conn_handle_t locConnHandle =
{
.bdHandle = eventParam->bdHandle
};
cy_ble_cpssFlag &= (uint8_t) ~CY_BLE_CPSS_FLAG_PV_PROCEDURE_IN_PROGRESS;
if(eventParam->result != 0u)
{
/* If the client does not change the connection parameters Server shall return an ATT Error Response
* to the Write Request with an Error Code set to the application Error Code 0x80
* (Inappropriate Connection Parameters). */
cy_stc_ble_gatt_err_param_t err_param;
err_param.errInfo.opCode = (cy_en_ble_gatt_pdu_t)CY_BLE_GATT_WRITE_REQ;
err_param.errInfo.attrHandle = cy_ble_cpssConfigPtr->attrInfo->charInfo[CY_BLE_CPS_POWER_VECTOR].
descrHandle[CY_BLE_CPS_CCCD];
err_param.errInfo.errorCode = CY_BLE_GATT_ERR_CPS_INAPPROPRIATE_CONNECTION_PARAMETERS;
/* get connHandle form cy_ble_connHandle, to have actual value of connHandle.attId */
err_param.connHandle = cy_ble_connHandle[Cy_BLE_GetConnHandleIdx(locConnHandle)];
/* Send Error Response */
(void)Cy_BLE_GATTS_ErrorRsp(&err_param);
}
else
{
cy_stc_ble_cps_char_value_t locCharValue;
locCharValue.connHandle = cy_ble_connHandle[Cy_BLE_GetConnHandleIdx(locConnHandle)];
locCharValue.charIndex = CY_BLE_CPS_POWER_VECTOR;
cy_stc_ble_gatt_value_t locValue;
uint8_t cccdVal[2u];
Cy_BLE_Set16ByPtr(cccdVal, CY_BLE_CCCD_NOTIFICATION);
/* Otherwise, the server shall respond with a Write Response and start sending notifications
* of the Cycling Power Vector characteristic. */