1 /***************************************************************************//**
2 * \file cy_ble_common.c
3 * \version 3.60
4 *
5 * \brief
6 *  This file contains the source code for the API of the BLE PSoC 6 BLE Middleware.
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright 2017-2021, Cypress Semiconductor Corporation.  All rights reserved.
11 * You may use this file only in accordance with the license, terms, conditions,
12 * disclaimers, and limitations in the end user license agreement accompanying
13 * the software package with which this file was provided.
14 *******************************************************************************/
15 
16 #if defined(COMPONENT_BLESS_HOST_IPC) || \
17     defined(COMPONENT_BLESS_CONTROLLER) || defined(COMPONENT_BLESS_HOST)
18 #include "cycfg_ble.h"
19 #endif /* defined(COMPONENT_BLESS_CONTROLLER_IPC) || defined(COMPONENT_BLESS_HOST_IPC) ... */
20 
21 #include "cy_ble_cfg_common.h"
22 #include "cy_ble_hal_pvt.h"
23 
24 #if defined(CY_IP_MXBLESS)
25 
26 
27 /******************************************************************************
28 * Function Name: Cy_BLE_Init
29 ***************************************************************************//**
30 *
31 *  Initializes the PSoC 6 BLE Middleware.
32 *
33 *  \param config: The configuration structure for the PSoC 6 BLE Middleware.
34 *
35 *  \return
36 *  \ref cy_en_ble_api_result_t : Return value indicates if the function succeeded or
37 *   failed. The following are possible error codes.
38 *
39 *   Error codes                     | Description
40 *   ------------                    | -----------
41 *   CY_BLE_SUCCESS                  | The function completed successfully.
42 *   CY_BLE_ERROR_INVALID_PARAMETER  | On specifying NULL as the input parameter.
43 *
44 ******************************************************************************/
Cy_BLE_Init(const cy_stc_ble_config_t * config)45 cy_en_ble_api_result_t Cy_BLE_Init(const cy_stc_ble_config_t *config)
46 {
47     cy_en_ble_api_result_t apiResult;
48 
49     #if (CY_BLE_STACK_IPC_CONTR_CORE) || (CY_BLE_MODE_HCI)
50 
51         /* Initializes the controller portion of the BLE (dual CPU mode) */
52         apiResult = Cy_BLE_InitController(config);
53 
54     #else
55 
56         /* Initializes the host portion of the BLE (dual CPU mode) or full
57          * (controller/host) in single CPU */
58         apiResult = Cy_BLE_InitHost(config);
59 
60     #endif /* end stack mode condition */
61 
62 
63     return(apiResult);
64 }
65 
66 
67 /******************************************************************************
68 * Function Name: Cy_BLE_Enable
69 ***************************************************************************//**
70 *
71 *  Initializes and enable the BLE Stack.
72 *
73 *  Calling this function results in generation of a #CY_BLE_EVT_STACK_ON event
74 *  on successful initialization of the BLE Stack.
75 *
76 *  BLE Stack enables the BLE ECO clock automatically with the default
77 *  parameters:
78 *     Parameter            | Value
79 *     -------------------- | -----------
80 *     ECO Frequency        | CY_BLE_DEFAULT_ECO_FREQ
81 *     Divider              | CY_BLE_DEFAULT_ECO_DIV
82 *     Startup time         | CY_BLE_DEFAULT_OSC_STARTUP_DELAY_LF
83 *     Load cap             | CY_BLE_DEFAULT_CAP_TRIM_VALUE
84 *
85 *  If there is a need to start the BLE with non-default ECO parameters,
86 *  call the Cy_BLE_EcoConfigure() function with the custom configuration each
87 *  time before calling the Cy_BLE_Enable() function.
88 *
89 *  This function initializes the BLE Stack which consists of the BLE Stack
90 *  Manager, BLE Controller, and BLE Host modules. It takes care of initializing
91 *  the Profile layer, schedulers, Timer and other platform-related resources
92 *  required for the PSoC 6 BLE Middleware. It also registers the callback function
93 *  for BLE events that will be registered in the BLE stack.
94 *
95 *  Note that this function does not reset the BLE Stack.
96 *
97 *  For the HCI-Mode of operation, this function will not initialize the BLE Host
98 *  module.
99 *
100 *  Calling this function results in generation of a #CY_BLE_EVT_STACK_ON event
101 *  on successful initialization of the BLE Stack.
102 *
103 *  In the dual CPU mode, this function should be called on both cores in the
104 *  following sequence:
105 *   - call this function on CM0+ core to initialize the Controller.
106 *   - start CM4 core by calling Cy_SysEnableCM4() function.
107 *   - call this function on CM4 core to initialize the Host and Profiles.
108 *
109 *  NOTE: BLE requires a call to Cy_IPC_Sema_Init(), Cy_IPC_Pipe_Config(),
110 *    Cy_IPC_Pipe_Init() functions before use.
111 *    These functions are called in the SystemInit() function for proper flash write
112 *    and erase operations. If the default startup file is not used, or the function
113 *    SystemInit() is not called in your project, call the following functions:
114 *    -# Cy_IPC_Sema_Init()
115 *    -# Cy_IPC_Pipe_Config()
116 *    -# Cy_IPC_Pipe_Init()
117 *
118 * \return
119 * \ref cy_en_ble_api_result_t : Return value indicates if the function succeeded
120 *      or failed. The following are possible error codes.
121 *
122 *  <table>
123 *    <tr>
124 *      <th>Error codes</th>
125 *      <th>Description</th>
126 *    </tr>
127 *    <tr>
128 *      <td>CY_BLE_SUCCESS</td>
129 *      <td>On successful operation.</td>
130 *    </tr>
131 *    <tr>
132 *      <td>CY_BLE_ERROR_REPEATED_ATTEMPTS</td>
133 *      <td>On invoking this function more than once without calling
134 *          Cy_BLE_Disable() function between calls to this function.</td>
135 *    </tr>
136 *    <tr>
137 *      <td>CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED</td>
138 *      <td>There is insufficient memory available.</td>
139 *    </tr>
140 *  </table>
141 *
142 ******************************************************************************/
Cy_BLE_Enable(void)143 cy_en_ble_api_result_t Cy_BLE_Enable(void)
144 {
145     cy_en_ble_api_result_t apiResult ;
146 
147 #if (CY_BLE_STACK_IPC_CONTR_CORE)
148     /* Registers IPC pipe callback. The PSoC 6 BLE Middleware when it
149      * operates in BLE dual CPU mode. */
150     apiResult = Cy_BLE_HAL_RegisterCommonPipeCallback();
151 
152 #elif (CY_BLE_STACK_IPC_HOST_CORE)
153     /* Enable BLE ECO clock with default configuration */
154     apiResult = Cy_BLE_HAL_EnableDefaultEco();
155 
156     /* Enable BLE controller portion of BLE over IPC */
157     if (apiResult == CY_BLE_SUCCESS)
158     {
159         apiResult = Cy_BLE_EnableControllerFromHost();
160     }
161 
162     /* Enable BLE host portion of BLE over IPC */
163     if (apiResult == CY_BLE_SUCCESS)
164     {
165         apiResult = Cy_BLE_EnableHost();
166     }
167 
168 #elif (CY_BLE_MODE_HCI)
169     /* Start the Controller portion of the BLE (HCI mode) */
170     apiResult = Cy_BLE_EnableHCIModeController();
171 
172 #else
173     /* Enable BLE host portion of the BLE (single CPU mode) */
174     apiResult = Cy_BLE_EnableHost();
175 
176 #endif /* end stack mode condition */
177 
178     return(apiResult);
179 }
180 
181 
182 /******************************************************************************
183 * Function Name: Cy_BLE_Disable
184 ***************************************************************************//**
185 *
186 *  This function stops any ongoing operation in the BLE Stack and forces the
187 *  BLE Stack to shut down.
188 *
189 *  Calling this function results in generation of a
190 *  #CY_BLE_EVT_STACK_SHUTDOWN_COMPLETE event on a successful stack shutdown.
191 *
192 *  For HCI mode:
193 *  This is a blocking function and no event is generated.
194 *  Only #CY_BLE_SUCCESS will be returned and other error codes are not applicable.
195 *  UART interface will be stopped and UART data will not be processed by stack
196 *  until Cy_BLE_Enable() is invoked.
197 *
198 * \return
199 * \ref cy_en_ble_api_result_t : Return value indicates if the function succeeded or
200 *  failed. The following are possible error codes.
201 *
202 *  <table>
203 *    <tr>
204 *      <th>Error codes</th>
205 *      <th>Description</th>
206 *    </tr>
207 *    <tr>
208 *      <td>CY_BLE_SUCCESS</td>
209 *      <td>On successful operation.</td>
210 *    </tr>
211 *    <tr>
212 *      <td>CY_BLE_ERROR_INVALID_OPERATION</td>
213 *      <td>On calling Cy_BLE_Disable before calling Cy_BLE_Enable()
214 *          or on Controller core.</td>
215 *    </tr>
216 *  </table>
217 *
218 ******************************************************************************/
Cy_BLE_Disable(void)219 cy_en_ble_api_result_t Cy_BLE_Disable(void)
220 {
221     cy_en_ble_api_result_t apiResult;
222 
223     #if (CY_BLE_STACK_IPC_CONTR_CORE) || (CY_BLE_MODE_HCI)
224 
225         /* To stop Controller (in dual CPU mode) call Cy_BLE_Disable()
226          * function on Host core */
227         apiResult = CY_BLE_SUCCESS;
228 
229     #else
230 
231         /* Stops all ongoing activities */
232         apiResult = Cy_BLE_StackShutdown();
233 
234     #endif     /* CY_BLE_STACK_IPC_CONTR_CORE */
235 
236     return(apiResult);
237 }
238 
239 
240 /******************************************************************************
241 * Function Name: Cy_BLE_EnableLowPowerMode
242 ***************************************************************************//**
243 *
244 *  This function enables BLE low power mode
245 *
246 ******************************************************************************/
Cy_BLE_EnableLowPowerMode(void)247 void Cy_BLE_EnableLowPowerMode(void)
248 {
249     #if CY_BLE_STACK_IPC_HOST_CORE
250 
251         /* Enable LPM in BLE dual CPU mode (host) */
252         Cy_BLE_EnableHostLowPowerMode();
253 
254     #elif CY_BLE_STACK_IPC_CONTR_CORE
255 
256         /* Enable LPM in BLE dual CPU mode (controller) */
257         Cy_BLE_EnableControllerLowPowerMode();
258 
259     #else
260 
261         /* Enable LPM in BLE single CPU mode */
262         Cy_BLE_EnableSystemLowPowerMode();
263 
264     #endif /* end stack mode condition */
265 }
266 
267 
268 /******************************************************************************
269 * Function Name: Cy_BLE_ServiceInit
270 ***************************************************************************//**
271 *
272 *  Initializes all included services.
273 *
274 ******************************************************************************/
Cy_BLE_ServiceInit(void)275 void Cy_BLE_ServiceInit(void)
276 {
277 #if (CY_BLE_MODE_PROFILE)
278     /* Init GAP/GATT server service */
279     #if (CY_BLE_GATT_ROLE_SERVER)
280     (void)Cy_BLE_GATTS_Init(&cy_ble_gattsConfig);
281     (void)Cy_BLE_GAPS_Init(&cy_ble_gapsConfig);
282     #endif /* (CY_BLE_GATT_ROLE_SERVER) */
283 
284     /* Init GAP/GATT client service */
285     #if (CY_BLE_GATT_ROLE_CLIENT)
286     (void)Cy_BLE_GATTC_Init(&cy_ble_gattcConfig);
287     (void)Cy_BLE_GAPC_Init(&cy_ble_gapcConfig);
288     #endif /* (CY_BLE_GATT_ROLE_SERVER) */
289 
290     /* Init ANCS service */
291     #ifdef CY_BLE_ANCS_SERVER
292     (void)Cy_BLE_ANCSS_Init(&cy_ble_ancssConfig);
293     #endif /* CY_BLE_ANCS_SERVER */
294 
295     #ifdef CY_BLE_ANCS_CLIENT
296     (void)Cy_BLE_ANCSC_Init(&cy_ble_ancscConfig);
297     #endif /* CY_BLE_ANCS_CLIENT */
298 
299     /* Init ANS service */
300     #ifdef CY_BLE_ANS_SERVER
301     (void)Cy_BLE_ANSS_Init(&cy_ble_anssConfig);
302     #endif /* CY_BLE_ANS_SERVER */
303 
304     #ifdef CY_BLE_ANS_CLIENT
305     (void)Cy_BLE_ANSC_Init(&cy_ble_anscConfig);
306     #endif /* CY_BLE_ANS_CLIENT */
307 
308     /* Init AIOS service */
309     #ifdef CY_BLE_AIOS_SERVER
310     (void)Cy_BLE_AIOSS_Init(&cy_ble_aiossConfig);
311     #endif /* CY_BLE_AIOS_SERVER */
312 
313     #ifdef CY_BLE_AIOS_CLIENT
314     (void)Cy_BLE_AIOSC_Init(&cy_ble_aioscConfig);
315     #endif /* CY_BLE_AIOS_CLIENT */
316 
317     /* Init BAS service */
318     #ifdef CY_BLE_BAS_SERVER
319     (void)Cy_BLE_BASS_Init(&cy_ble_bassConfig);
320     #endif /* CY_BLE_BAS_SERVER */
321 
322     #ifdef CY_BLE_BAS_CLIENT
323     (void)Cy_BLE_BASC_Init(&cy_ble_bascConfig);
324     #endif /* CY_BLE_BAS_CLIENT */
325 
326     /* Init BLS service */
327     #ifdef CY_BLE_BLS_SERVER
328     (void)Cy_BLE_BLSS_Init(&cy_ble_blssConfig);
329     #endif /* CY_BLE_BLS_SERVER */
330 
331     #ifdef CY_BLE_BLS_CLIENT
332     (void)Cy_BLE_BLSC_Init(&cy_ble_blscConfig);
333     #endif /* CY_BLE_BLS_CLIENT */
334 
335     /* Init BCS service */
336     #ifdef CY_BLE_BCS_SERVER
337     (void)Cy_BLE_BCSS_Init(&cy_ble_bcssConfig);
338     #endif /* CY_BLE_BLS_SERVER */
339 
340     #ifdef CY_BLE_BCS_CLIENT
341     (void)Cy_BLE_BCSC_Init(&cy_ble_bcscConfig);
342     #endif /* CY_BLE_BCS_CLIENT */
343 
344     /* Init BMS service */
345     #ifdef CY_BLE_BMS_SERVER
346     (void)Cy_BLE_BMSS_Init(&cy_ble_bmssConfig);
347     #endif /* CY_BLE_BMS_SERVER */
348 
349     #ifdef CY_BLE_BMS_CLIENT
350     (void)Cy_BLE_BMSC_Init(&cy_ble_bmscConfig);
351     #endif /* CY_BLE_BMS_CLIENT */
352 
353      /* Init BTS service */
354     #ifdef CY_BLE_BTS_SERVER
355     (void)Cy_BLE_BTSS_Init(&cy_ble_btssConfig);
356     #endif /* CY_BLE_BTS_SERVER */
357 
358     /* Init CGMS service */
359     #ifdef CY_BLE_CGMS_SERVER
360     (void)Cy_BLE_CGMSS_Init(&cy_ble_cgmssConfig);
361     #endif /* CY_BLE_CGMS_SERVER */
362 
363     #ifdef CY_BLE_CGMS_CLIENT
364     (void)Cy_BLE_CGMSC_Init(&cy_ble_cgmscConfig);
365     #endif /* CY_BLE_CGMS_CLIENT */
366 
367     /* Init CPS service */
368     #ifdef CY_BLE_CPS_SERVER
369     (void)Cy_BLE_CPSS_Init(&cy_ble_cpssConfig);
370     #endif /* CY_BLE_CPS_SERVER */
371 
372     #ifdef CY_BLE_CPS_CLIENT
373     (void)Cy_BLE_CPSC_Init(&cy_ble_cpscConfig);
374     #endif /* CY_BLE_CPS_CLIENT */
375 
376     /* Init CSCS service */
377     #ifdef CY_BLE_CSCS_SERVER
378     (void)Cy_BLE_CSCSS_Init(&cy_ble_cscssConfig);
379     #endif /* CY_BLE_CSCS_SERVER */
380 
381     #ifdef CY_BLE_CSCS_CLIENT
382     (void)Cy_BLE_CSCSC_Init(&cy_ble_cscscConfig);
383     #endif /* CY_BLE_CSCS_CLIENT */
384 
385     /* Init CTS service */
386     #ifdef CY_BLE_CTS_SERVER
387     (void)Cy_BLE_CTSS_Init(&cy_ble_ctssConfig);
388     #endif /* CY_BLE_CTS_SERVER */
389 
390     #ifdef CY_BLE_CTS_CLIENT
391     (void)Cy_BLE_CTSC_Init(&cy_ble_ctscConfig);
392     #endif /* CY_BLE_CTS_CLIENT */
393 
394     /* Init CUSTOM service */
395     #ifdef CY_BLE_CUSTOM_SERVER
396     (void)Cy_BLE_CUSTOMS_Init(&cy_ble_customsConfig);
397     #endif /* CY_BLE_CUSTOM_SERVER */
398 
399     #ifdef CY_BLE_CUSTOM_CLIENT
400     (void)Cy_BLE_CUSTOMC_Init(&cy_ble_customcConfig);
401     #endif /* CY_BLE_CUSTOM_CLIENT */
402 
403     /* Init DIS service */
404     #ifdef CY_BLE_DIS_SERVER
405     (void)Cy_BLE_DISS_Init(&cy_ble_dissConfig);
406     #endif /* CY_BLE_DIS_SERVER */
407 
408     #ifdef CY_BLE_DIS_CLIENT
409     (void)Cy_BLE_DISC_Init(&cy_ble_discConfig);
410     #endif /* CY_BLE_DIS_CLIENT */
411 
412     /* Init ESS service */
413     #ifdef CY_BLE_ESS_SERVER
414     (void)Cy_BLE_ESSS_Init(&cy_ble_esssConfig);
415     #endif /* CY_BLE_ESS_SERVER */
416 
417     #ifdef CY_BLE_ESS_CLIENT
418     (void)Cy_BLE_ESSC_Init(&cy_ble_esscConfig);
419     #endif /* CY_BLE_ESS_CLIENT */
420 
421     /* Init GLS service */
422     #ifdef CY_BLE_GLS_SERVER
423     (void)Cy_BLE_GLSS_Init(&cy_ble_glssConfig);
424     #endif /* CY_BLE_GLS_SERVER */
425 
426     #ifdef CY_BLE_GLS_CLIENT
427     (void)Cy_BLE_GLSC_Init(&cy_ble_glscConfig);
428     #endif /* CY_BLE_GLS_CLIENT */
429 
430     /* Init HID service */
431     #ifdef CY_BLE_HIDS_SERVER
432     (void)Cy_BLE_HIDSS_Init(&cy_ble_hidssConfig);
433     #endif /* CY_BLE_HIDS_SERVER */
434 
435     #ifdef CY_BLE_HIDS_CLIENT
436     (void)Cy_BLE_HIDSC_Init(&cy_ble_hidscConfig);
437     #endif /* CY_BLE_HIDS_CLIENT */
438 
439     /* Init HPS service */
440     #ifdef CY_BLE_HPS_SERVER
441     (void)Cy_BLE_HPSS_Init(&cy_ble_hpssConfig);
442     #endif /* CY_BLE_HPS_SERVER */
443 
444     #ifdef CY_BLE_HPS_CLIENT
445     (void)Cy_BLE_HPSC_Init(&cy_ble_hpscConfig);
446     #endif /* CY_BLE_HPS_CLIENT */
447 
448     /* Init HRS service */
449     #ifdef CY_BLE_HRS_SERVER
450     (void)Cy_BLE_HRSS_Init(&cy_ble_hrssConfig);
451     #endif /* CY_BLE_HRS_SERVER */
452 
453     #ifdef CY_BLE_HRS_CLIENT
454     (void)Cy_BLE_HRSC_Init(&cy_ble_hrscConfig);
455     #endif /* CY_BLE_HRS_CLIENT */
456 
457     /* Init HTS service */
458     #ifdef CY_BLE_HTS_SERVER
459     (void)Cy_BLE_HTSS_Init(&cy_ble_htssConfig);
460     #endif /* CY_BLE_HTS_SERVER */
461 
462     #ifdef CY_BLE_HTS_CLIENT
463     (void)Cy_BLE_HTSC_Init(&cy_ble_htscConfig);
464     #endif /* CY_BLE_HTS_CLIENT */
465 
466     /* Init IAS service */
467     #ifdef CY_BLE_IAS_SERVER
468     (void)Cy_BLE_IASS_Init(&cy_ble_iassConfig);
469     #endif /* CY_BLE_IAS_SERVER */
470 
471     #ifdef CY_BLE_IAS_CLIENT
472     (void)Cy_BLE_IASC_Init(&cy_ble_iascConfig);
473     #endif /* CY_BLE_IAS_CLIENT */
474 
475     /* Init IPS service */
476     #ifdef CY_BLE_IPS_SERVER
477     (void)Cy_BLE_IPSS_Init(&cy_ble_ipssConfig);
478     #endif /* CY_BLE_IPS_SERVER */
479 
480     #ifdef CY_BLE_IPS_CLIENT
481     (void)Cy_BLE_IPSC_Init(&cy_ble_ipscConfig);
482     #endif /* CY_BLE_IPS_CLIENT */
483 
484     /* Init LLS service */
485     #ifdef CY_BLE_LLS_SERVER
486     (void)Cy_BLE_LLSS_Init(&cy_ble_llssConfig);
487     #endif /* CY_BLE_LLS_SERVER */
488 
489     #ifdef CY_BLE_LLS_CLIENT
490     (void)Cy_BLE_LLSC_Init(&cy_ble_llscConfig);
491     #endif /* CY_BLE_LLS_CLIENT */
492 
493     /* Init LNS service */
494     #ifdef CY_BLE_LNS_SERVER
495     (void)Cy_BLE_LNSS_Init(&cy_ble_lnssConfig);
496     #endif /* CY_BLE_LNS_SERVER */
497 
498     #ifdef CY_BLE_LNS_CLIENT
499     (void)Cy_BLE_LNSC_Init(&cy_ble_lnscConfig);
500     #endif /* CY_BLE_LNS_CLIENT */
501 
502     /* Init NDCS service */
503     #ifdef CY_BLE_NDCS_SERVER
504     (void)Cy_BLE_NDCSS_Init(&cy_ble_ndcssConfig);
505     #endif /* CY_BLE_NDCS_SERVER */
506 
507     #ifdef CY_BLE_NDCS_CLIENT
508     (void)Cy_BLE_NDCSC_Init(&cy_ble_ndcscConfig);
509     #endif /* CY_BLE_NDCS_CLIENT */
510 
511     /* Init PASS service */
512     #ifdef CY_BLE_PASS_SERVER
513     (void)Cy_BLE_PASSS_Init(&cy_ble_passsConfig);
514     #endif /* CY_BLE_PASS_SERVER */
515 
516     #ifdef CY_BLE_PASS_CLIENT
517     (void)Cy_BLE_PASSC_Init(&cy_ble_passcConfig);
518     #endif /* CY_BLE_PASS_CLIENT */
519 
520     /* Init PLXS service */
521     #ifdef CY_BLE_PLXS_SERVER
522     (void)Cy_BLE_PLXSS_Init(&cy_ble_plxssConfig);
523     #endif /* CY_BLE_PLXS_SERVER */
524 
525     #ifdef CY_BLE_PLXS_CLIENT
526     (void)Cy_BLE_PLXSC_Init(&cy_ble_plxscConfig);
527     #endif /* CY_BLE_PLXS_CLIENT */
528 
529     /* Init RSCS service */
530     #ifdef CY_BLE_RSCS_SERVER
531     (void)Cy_BLE_RSCSS_Init(&cy_ble_rscssConfig);
532     #endif /* CY_BLE_RSCS_SERVER */
533 
534     #ifdef CY_BLE_RSCS_CLIENT
535     (void)Cy_BLE_RSCSC_Init(&cy_ble_rscscConfig);
536     #endif /* CY_BLE_RSCS_CLIENT */
537 
538     /* Init RTUS service */
539     #ifdef CY_BLE_RTUS_SERVER
540     (void)Cy_BLE_RTUSS_Init(&cy_ble_rtussConfig);
541     #endif /* CY_BLE_RTUS_SERVER */
542 
543     #ifdef CY_BLE_RTUS_CLIENT
544     (void)Cy_BLE_RTUSC_Init(&cy_ble_rtuscConfig);
545     #endif /* CY_BLE_RTUS_CLIENT */
546 
547     /* Init SCPS service */
548     #ifdef CY_BLE_SCPS_SERVER
549     (void)Cy_BLE_SCPSS_Init(&cy_ble_scpssConfig);
550     #endif /* CY_BLE_SCPS_SERVER */
551 
552     #ifdef CY_BLE_SCPS_CLIENT
553     (void)Cy_BLE_SCPSC_Init(&cy_ble_scpscConfig);
554     #endif /* CY_BLE_SCPS_CLIENT */
555 
556     /* Init TPS service */
557     #ifdef CY_BLE_TPS_SERVER
558     (void)Cy_BLE_TPSS_Init(&cy_ble_tpssConfig);
559     #endif /* CY_BLE_TPS_SERVER */
560 
561     #ifdef CY_BLE_TPS_CLIENT
562     (void)Cy_BLE_TPSC_Init(&cy_ble_tpscConfig);
563     #endif /* CY_BLE_TPS_CLIENT */
564 
565      /* Init UDS service */
566     #ifdef CY_BLE_UDS_SERVER
567     (void)Cy_BLE_UDSS_Init(&cy_ble_udssConfig);
568     #endif /* CY_BLE_UDS_SERVER */
569 
570     #ifdef CY_BLE_UDS_CLIENT
571     (void)Cy_BLE_UDSC_Init(&cy_ble_udscConfig);
572     #endif /* CY_BLE_UDS_CLIENT */
573 
574     /* Init WPTS service */
575     #ifdef CY_BLE_WPTS_SERVER
576     (void)Cy_BLE_WPTSS_Init(&cy_ble_wptssConfig);
577     #endif /* CY_BLE_WPTS_SERVER */
578 
579     #ifdef CY_BLE_WPTS_CLIENT
580     (void)Cy_BLE_WPTSC_Init(&cy_ble_wptscConfig);
581     #endif /* CY_BLE_WPTS_CLIENT */
582 
583     /* Init WSS service */
584     #ifdef CY_BLE_WSS_SERVER
585     (void)Cy_BLE_WSSS_Init(&cy_ble_wsssConfig);
586     #endif /* CY_BLE_WSS_SERVER */
587 
588     #ifdef CY_BLE_WSS_CLIENT
589     (void)Cy_BLE_WSSC_Init(&cy_ble_wsscConfig);
590     #endif /* CY_BLE_WSS_CLIENT */
591 
592     #ifdef CY_BLE_IPSS_CLIENT
593     {
594         uint32_t idx;
595         for(idx = 0u; idx < CY_BLE_GATTC_COUNT; idx++)
596         {
597             cy_ble_serverInfo[idx][CY_BLE_SRVI_IPSS].uuid = CY_BLE_UUID_INTERNET_PROTOCOL_SUPPORT_SERVICE;
598         }
599     }
600     #endif     /* CY_BLE_IPSS_CLIENT */
601 #endif /* (CY_BLE_MODE_PROFILE) */
602 }
603 
604 
605 
606 /******************************************************************************
607 * Mapping Functions for stack size optimization  (internal usage only)
608 ***************************************************************************//**/
609 
Cy_BLE_HAL_EccHeapInit(uint8_t * heapMem,uint8_t numOfConn)610 void Cy_BLE_HAL_EccHeapInit(uint8_t *heapMem, uint8_t numOfConn)
611 {
612     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
613         Cy_BLE_HAL_MappingEccHeapInit(heapMem, numOfConn);
614     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
615 
616     /* Suppress unused variable warning */
617     (void) heapMem;
618     (void) numOfConn;
619 }
620 
Cy_BLE_HAL_EccHeapDeInit(void)621 void Cy_BLE_HAL_EccHeapDeInit(void)
622 {
623     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
624         Cy_BLE_HAL_MappingEccHeapDeInit();
625     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
626 }
627 
Cy_BLE_HAL_EccGetFeatureHeapReq(uint8_t numOfConn)628 uint16_t Cy_BLE_HAL_EccGetFeatureHeapReq(uint8_t numOfConn)
629 {
630     /* Suppress unused variable warning */
631     (void) numOfConn;
632 
633     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
634         return(Cy_BLE_HAL_MappingEccGetFeatureHeapReq(numOfConn));
635     #else
636         return(0u);
637     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
638 }
639 
Cy_BLE_HAL_EccGenerateSecurityKeypair(uint8_t p_publicKey[],uint8_t p_privateKey[],uint8_t randomData[])640 cy_en_ble_api_result_t Cy_BLE_HAL_EccGenerateSecurityKeypair(uint8_t p_publicKey[],
641                                                              uint8_t p_privateKey[],
642                                                              uint8_t randomData[])
643 {
644     /* Suppress unused variable warning */
645     (void) p_publicKey;
646     (void) p_privateKey;
647     (void) randomData;
648 
649     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
650         return(Cy_BLE_HAL_MappingEccGenerateSecurityKeypair(p_publicKey, p_privateKey, randomData));
651     #else
652         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
653     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
654 }
655 
Cy_BLE_HAL_EccGenerateDHKey(const uint8_t p_publicKey[],const uint8_t p_privateKey[],uint8_t p_secret[],uint8_t ci)656 cy_en_ble_api_result_t Cy_BLE_HAL_EccGenerateDHKey(const uint8_t p_publicKey[],
657                                                    const uint8_t p_privateKey[],
658                                                    uint8_t p_secret[], uint8_t ci)
659 {
660     /* Suppress unused variable warning */
661     (void) p_publicKey;
662     (void) p_privateKey;
663     (void) p_secret;
664     (void) ci;
665 
666     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
667         return(Cy_BLE_HAL_MappingEccGenerateDHKey(p_publicKey, p_privateKey, p_secret, ci));
668     #else
669         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
670     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
671 }
672 
Cy_BLE_HAL_EccValidPublicKey(const uint8_t p_publicKey[])673 cy_en_ble_api_result_t Cy_BLE_HAL_EccValidPublicKey(const uint8_t p_publicKey[])
674 {
675     /* Suppress unused variable warning */
676     (void) p_publicKey;
677 
678     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
679         return(Cy_BLE_HAL_MappingEccValidPublicKey(p_publicKey));
680     #else
681         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
682     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
683 }
684 
Cy_BLE_HAL_PairingLocalPublicKeyHandler(void * param)685 cy_en_ble_api_result_t Cy_BLE_HAL_PairingLocalPublicKeyHandler(void *param)
686 {
687     /* Suppress unused variable warning */
688     (void) param;
689 
690     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
691         return(Cy_BLE_HAL_MappingPairingLocalPublicKeyHandler(param));
692     #else
693         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
694     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
695 }
696 
Cy_BLE_HAL_PairingRemoteKeyHandler(void * param)697 cy_en_ble_api_result_t Cy_BLE_HAL_PairingRemoteKeyHandler(void *param)
698 {
699     /* Suppress unused variable warning */
700     (void) param;
701 
702     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
703         return(Cy_BLE_HAL_MappingPairingRemoteKeyHandler(param));
704     #else
705         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
706     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
707 }
708 
Cy_BLE_HAL_PairingDhkeyHandler(void * param)709 cy_en_ble_api_result_t Cy_BLE_HAL_PairingDhkeyHandler(void *param)
710 {
711     /* Suppress unused variable warning */
712     (void) param;
713 
714     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
715         return(Cy_BLE_HAL_MappingPairingDhkeyHandler(param));
716     #else
717         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
718     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
719 }
720 
Cy_BLE_HAL_PairingDhkeyCheckHandler(void * param)721 cy_en_ble_api_result_t Cy_BLE_HAL_PairingDhkeyCheckHandler(void *param)
722 {
723     /* Suppress unused variable warning */
724     (void) param;
725 
726     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
727         return(Cy_BLE_HAL_MappingPairingDhkeyCheckHandler(param));
728     #else
729         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
730     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
731 }
732 
Cy_BLE_HAL_PairingKeypressNotificationHandler(void * param)733 cy_en_ble_api_result_t Cy_BLE_HAL_PairingKeypressNotificationHandler(void *param)
734 {
735     /* Suppress unused variable warning */
736     (void) param;
737 
738     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
739         return(Cy_BLE_HAL_MappingPairingKeypressNotificationHandler(param));
740     #else
741         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
742     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
743 }
744 
Cy_BLE_HAL_PairingRandHandler(void * param)745 cy_en_ble_api_result_t Cy_BLE_HAL_PairingRandHandler(void *param)
746 {
747     /* Suppress unused variable warning */
748     (void) param;
749 
750     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
751         return(Cy_BLE_HAL_MappingPairingRandHandler(param));
752     #else
753         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
754     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
755 }
756 
Cy_BLE_HAL_PairingConfirmHandler(void * param)757 cy_en_ble_api_result_t Cy_BLE_HAL_PairingConfirmHandler(void *param)
758 {
759     /* Suppress unused variable warning */
760     (void) param;
761 
762     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
763         return(Cy_BLE_HAL_MappingPairingConfirmHandler(param));
764     #else
765         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
766     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
767 }
768 
Cy_BLE_HAL_PairingLrConfirmingHandler(void * param)769 cy_en_ble_api_result_t Cy_BLE_HAL_PairingLrConfirmingHandler(void *param)
770 {
771     /* Suppress unused variable warning */
772     (void) param;
773 
774     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
775         return(Cy_BLE_HAL_MappingPairingLrConfirmingHandler(param));
776     #else
777         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
778     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
779 }
780 
Cy_BLE_HAL_PairingScTbxDhkeyGenerateComplete(void * param)781 cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxDhkeyGenerateComplete(void *param)
782 {
783     /* Suppress unused variable warning */
784     (void) param;
785 
786     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
787         Cy_BLE_HAL_MappingTbxDhkeyGenerateComplete(param);
788     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
789 
790     return(CY_BLE_SUCCESS);
791 }
792 
Cy_BLE_HAL_PairingScTbxLocalPubkeyGenerateComplete(void * param)793 cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxLocalPubkeyGenerateComplete(void *param)
794 {
795     /* Suppress unused variable warning */
796     (void) param;
797 
798     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
799         Cy_BLE_HAL_MappingTbxLocalPubkeyGenerateComplete(param);
800     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
801 
802     return(CY_BLE_SUCCESS);
803 }
804 
Cy_BLE_HAL_PairingScTbxGenerateLocalP256PublicKey(uint8_t param)805 cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxGenerateLocalP256PublicKey(uint8_t param)
806 {
807     /* Suppress unused variable warning */
808     (void) param;
809 
810     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
811         return(Cy_BLE_HAL_MappingTbxGenerateLocalP256PublicKey(param));
812     #else
813         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
814     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
815 }
816 
Cy_BLE_HAL_PairingScTbxGenerateDHkey(void * param1,void * param2,uint8_t param3)817 cy_en_ble_api_result_t Cy_BLE_HAL_PairingScTbxGenerateDHkey(void  *param1, void  *param2, uint8_t param3)
818 {
819     /* Suppress unused variable warning */
820     (void) param1;
821     (void) param2;
822     (void) param3;
823 
824     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
825         return(Cy_BLE_HAL_MappingTbxGenerateDHkey(param1, param2, param3));
826     #else
827         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
828     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
829 }
830 
Cy_BLE_HAL_SmpScCmacComplete(uint8_t param)831 void Cy_BLE_HAL_SmpScCmacComplete(uint8_t param)
832 {
833     /* Suppress unused variable warning */
834     (void) param;
835 
836     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
837         Cy_BLE_HAL_MappingSmpScCmacComplete(param);
838     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
839 }
840 
Cy_BLE_HAL_SeSmpScUserPasskeyHandler(void * param1,void * param2)841 cy_en_ble_api_result_t Cy_BLE_HAL_SeSmpScUserPasskeyHandler(void *param1,
842                                                             void *param2)
843 {
844     /* Suppress unused variable warning */
845     (void) param1;
846     (void) param2;
847 
848     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
849         return(Cy_BLE_HAL_MappingSeSmpScUserPasskeyHandler(param1, param2));
850     #else
851         return(CY_BLE_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
852     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
853 }
854 
Cy_BLE_HAL_EccPointMult(uint8_t param)855 void Cy_BLE_HAL_EccPointMult(uint8_t param)
856 {
857     /* Suppress unused variable warning */
858     (void) param;
859 
860     #if (CY_BLE_SECURE_CONN_FEATURE_ENABLED)
861         Cy_BLE_HAL_MappingEccPointMult(param);
862     #endif /* CY_BLE_SECURE_CONN_FEATURE_ENABLED */
863 }
864 
865 /* Controller stack functions */
Cy_BLE_MappingIsControllerActive(cy_en_ble_controller_sleep_mode_t checkForMode)866 cy_en_ble_api_result_t Cy_BLE_MappingIsControllerActive(cy_en_ble_controller_sleep_mode_t checkForMode)
867 {
868     /* Suppress unused variable warning */
869     (void) checkForMode;
870 
871     #if CY_BLE_STACK_CONTR_CORE
872         return(Cy_BLE_IsControllerActive(checkForMode));
873     #else
874         return(CY_BLE_SUCCESS);
875     #endif /* CY_BLE_STACK_CONTR_CORE */
876 
877 }
878 
Cy_BLE_HAL_MappingBlessInterruptHandler(void)879 bool Cy_BLE_HAL_MappingBlessInterruptHandler(void)
880 {
881     #if CY_BLE_STACK_CONTR_CORE
882         return(Cy_BLE_HAL_BlessInterruptHandler());
883     #else
884         return(false);
885     #endif /* CY_BLE_STACK_CONTR_CORE */
886 }
887 
Cy_BLE_MappingLlIsrExitLowPowerMode(void)888 void Cy_BLE_MappingLlIsrExitLowPowerMode(void)
889 {
890     #if (CY_BLE_STACK_CONTR_CORE)
891         Cy_BLE_LlIsrExitLowPowerMode();
892     #endif /* CY_BLE_STACK_CONTR_CORE */
893 }
894 
Cy_BLE_HAL_MappingUartRxDataHandler(uint8_t byte)895 void Cy_BLE_HAL_MappingUartRxDataHandler(uint8_t byte)
896 {
897     /* Suppress unused variable warning */
898     (void) byte;
899 
900     #if ((CY_BLE_STACK_CONTR_CORE) && (CY_BLE_MODE_HCI) && (CY_BLE_MODE_HCI_LEGACY))
901         Cy_BLE_HAL_UartRxDataHandler(byte);
902     #endif /* CY_BLE_STACK_CONTR_CORE */
903 }
904 
Cy_BLE_HAL_MappingUartTxCompltHandler(void)905 void Cy_BLE_HAL_MappingUartTxCompltHandler(void)
906 {
907     #if ((CY_BLE_STACK_CONTR_CORE) && (CY_BLE_MODE_HCI) && (CY_BLE_MODE_HCI_LEGACY))
908         Cy_BLE_HAL_UartTxCompltHandler();
909     #endif /* CY_BLE_STACK_CONTR_CORE */
910 }
911 
Cy_BLE_HAL_MappingSoftHciHostReceiveControllerPkt(cy_stc_ble_hci_tx_packet_info_t * hciPkt)912 void Cy_BLE_HAL_MappingSoftHciHostReceiveControllerPkt(cy_stc_ble_hci_tx_packet_info_t *hciPkt)
913 {
914     /* Suppress unused variable warning */
915     (void) hciPkt;
916 
917     #if (CY_BLE_MODE_PROFILE) && (CY_BLE_STACK_MODE_SOC)
918         Cy_BLE_HAL_SoftHciHostReceiveControllerPkt(hciPkt);
919     #endif /* (CY_BLE_MODE_PROFILE) && (CY_BLE_STACK_MODE_SOC) */
920 }
921 
Cy_BLE_HAL_MappingSoftHciControllerReceiveHostPkt(cy_stc_ble_hci_tx_packet_info_t * hciPkt)922 cy_en_ble_api_result_t Cy_BLE_HAL_MappingSoftHciControllerReceiveHostPkt(cy_stc_ble_hci_tx_packet_info_t *hciPkt)
923 {
924     /* Suppress unused variable warning */
925     (void) hciPkt;
926 
927     #if (CY_BLE_MODE_PROFILE) && (CY_BLE_STACK_MODE_SOC)
928         return(Cy_BLE_HAL_SoftHciControllerReceiveHostPkt(hciPkt));
929     #else
930         return(CY_BLE_SUCCESS);
931     #endif /* (CY_BLE_MODE_PROFILE) && (CY_BLE_STACK_MODE_IPC) */
932 }
933 
Cy_BLE_MappingStackEnterLPM(cy_en_ble_lp_mode_t pwrMode)934 cy_en_ble_lp_mode_t Cy_BLE_MappingStackEnterLPM(cy_en_ble_lp_mode_t pwrMode)
935 {
936     /* Suppress unused variable warning */
937     (void) pwrMode;
938 
939     #if ( (CY_BLE_STACK_IPC_CONTR_CORE) || (CY_BLE_MODE_PROFILE) ||\
940           ((CY_BLE_STACK_CONTR_CORE) && (CY_BLE_MODE_HCI) && (CY_BLE_MODE_HCI_LEGACY)) )
941         return(Cy_BLE_StackEnterLPM(pwrMode));
942     #elif ((CY_BLE_STACK_CONTR_CORE) && (CY_BLE_MODE_HCI) )
943         return(Cy_BLE_ControllerEnterLPM(pwrMode));
944     #endif /* (CY_BLE_MODE_PROFILE) && (CY_BLE_STACK_MODE_IPC) */
945 }
946 
947 
948 #endif /* defined(CY_IP_MXBLESS) */
949 
950 /* [] END OF FILE */
951