1 /**
2  ****************************************************************************************
3  *
4  * @file prf.c
5  *
6  * @brief Entry point of profile source file.
7  *
8  * Used to manage life cycle of profiles
9  *
10  * Copyright (C) RivieraWaves 2009-2016
11  *
12  ****************************************************************************************
13  */
14 
15 
16 /**
17  ****************************************************************************************
18  * @addtogroup PRF
19  * @{
20  ****************************************************************************************
21  */
22 
23 /*
24  * INCLUDE FILES
25  ****************************************************************************************
26  */
27 
28 #include "rwip_config.h"
29 
30 #if (BLE_PROFILES)
31 #include "prf.h"
32 #include "att.h"
33 
34 
35 #if (BLE_HT_THERMOM)
36 extern const struct prf_task_cbs* htpt_prf_itf_get(void);
37 #endif // (BLE_HT_THERMOM)
38 
39 #if (BLE_HT_COLLECTOR)
40 extern const struct prf_task_cbs* htpc_prf_itf_get(void);
41 #endif // (BLE_HT_COLLECTOR)
42 
43 #if (BLE_DIS_SERVER)
44 extern const struct prf_task_cbs* diss_prf_itf_get(void);
45 #endif // (BLE_HT_THERMOM)
46 
47 #if (BLE_DIS_CLIENT)
48 extern const struct prf_task_cbs* disc_prf_itf_get(void);
49 #endif // (BLE_DIS_CLIENT)
50 
51 #if (BLE_BP_SENSOR)
52 extern const struct prf_task_cbs* blps_prf_itf_get(void);
53 #endif // (BLE_BP_SENSOR)
54 
55 #if (BLE_BP_COLLECTOR)
56 extern const struct prf_task_cbs* blpc_prf_itf_get(void);
57 #endif // (BLE_BP_COLLECTOR)
58 
59 #if (BLE_TIP_SERVER)
60 extern const struct prf_task_cbs* tips_prf_itf_get(void);
61 #endif // (BLE_TIP_SERVER)
62 
63 #if (BLE_TIP_CLIENT)
64 extern const struct prf_task_cbs* tipc_prf_itf_get(void);
65 #endif // (BLE_TIP_CLIENT)
66 
67 #if (BLE_HR_SENSOR)
68 extern const struct prf_task_cbs* hrps_prf_itf_get(void);
69 #endif // (BLE_HR_SENSOR)
70 
71 #if (BLE_HR_COLLECTOR)
72 extern const struct prf_task_cbs* hrpc_prf_itf_get(void);
73 #endif // (BLE_HR_COLLECTOR)
74 
75 #if (BLE_FINDME_LOCATOR)
76 extern const struct prf_task_cbs* findl_prf_itf_get(void);
77 #endif // (BLE_FINDME_LOCATOR)
78 
79 #if (BLE_FINDME_TARGET)
80 extern const struct prf_task_cbs* findt_prf_itf_get(void);
81 #endif // (BLE_FINDME_TARGET)
82 
83 #if (BLE_PROX_MONITOR)
84 extern const struct prf_task_cbs* proxm_prf_itf_get(void);
85 #endif // (BLE_PROX_MONITOR)
86 
87 #if (BLE_PROX_REPORTER)
88 extern const struct prf_task_cbs* proxr_prf_itf_get(void);
89 #endif // (BLE_PROX_REPORTER)
90 
91 #if (BLE_SP_CLIENT)
92 extern const struct prf_task_cbs* scppc_prf_itf_get(void);
93 #endif // (BLE_SP_CLENT)
94 
95 #if (BLE_SP_SERVER)
96 extern const struct prf_task_cbs* scpps_prf_itf_get(void);
97 #endif // (BLE_SP_SERVER)
98 
99 #if (BLE_BATT_CLIENT)
100 extern const struct prf_task_cbs* basc_prf_itf_get(void);
101 #endif // (BLE_BATT_CLIENT)
102 
103 //#if (BLE_BATT_SERVER)
104 //extern const struct prf_task_cbs* bass_prf_itf_get(void);
105 //#endif // (BLE_BATT_SERVER)
106 
107 #if (BLE_HID_DEVICE)
108 extern const struct prf_task_cbs* hogpd_prf_itf_get(void);
109 #endif // (BLE_HID_DEVICE)
110 
111 #if (BLE_HID_BOOT_HOST)
112 extern const struct prf_task_cbs* hogpbh_prf_itf_get(void);
113 #endif // (BLE_HID_BOOT_HOST)
114 
115 #if (BLE_HID_REPORT_HOST)
116 extern const struct prf_task_cbs* hogprh_prf_itf_get(void);
117 #endif // (BLE_HID_REPORT_HOST)
118 
119 #if (BLE_GL_COLLECTOR)
120 extern const struct prf_task_cbs* glpc_prf_itf_get(void);
121 #endif // (BLE_GL_COLLECTOR)
122 
123 #if (BLE_GL_SENSOR)
124 extern const struct prf_task_cbs* glps_prf_itf_get(void);
125 #endif // (BLE_GL_SENSOR)
126 
127 #if (BLE_RSC_COLLECTOR)
128 extern const struct prf_task_cbs* rscpc_prf_itf_get(void);
129 #endif // (BLE_RSC_COLLECTOR)
130 
131 #if (BLE_RSC_SENSOR)
132 extern const struct prf_task_cbs* rscps_prf_itf_get(void);
133 #endif // (BLE_RSC_COLLECTOR)
134 
135 #if (BLE_CSC_COLLECTOR)
136 extern const struct prf_task_cbs* cscpc_prf_itf_get(void);
137 #endif // (BLE_CSC_COLLECTOR)
138 
139 #if (BLE_CSC_SENSOR)
140 extern const struct prf_task_cbs* cscps_prf_itf_get(void);
141 #endif // (BLE_CSC_COLLECTOR)
142 
143 #if (BLE_AN_CLIENT)
144 extern const struct prf_task_cbs* anpc_prf_itf_get(void);
145 #endif // (BLE_AN_CLIENT)
146 
147 #if (BLE_AN_SERVER)
148 extern const struct prf_task_cbs* anps_prf_itf_get(void);
149 #endif // (BLE_AN_SERVER)
150 
151 #if (BLE_PAS_CLIENT)
152 extern const struct prf_task_cbs* paspc_prf_itf_get(void);
153 #endif // (BLE_PAS_CLIENT)
154 
155 #if (BLE_PAS_SERVER)
156 extern const struct prf_task_cbs* pasps_prf_itf_get(void);
157 #endif // (BLE_PAS_SERVER)
158 
159 #if (BLE_CP_COLLECTOR)
160 extern const struct prf_task_cbs* cppc_prf_itf_get(void);
161 #endif //(BLE_CP_COLLECTOR)
162 
163 #if (BLE_CP_SENSOR)
164 extern const struct prf_task_cbs* cpps_prf_itf_get(void);
165 #endif //(BLE_CP_SENSOR)
166 
167 #if (BLE_LN_COLLECTOR)
168 extern const struct prf_task_cbs* lanc_prf_itf_get(void);
169 #endif //(BLE_CP_COLLECTOR)
170 
171 #if (BLE_LN_SENSOR)
172 extern const struct prf_task_cbs* lans_prf_itf_get(void);
173 #endif //(BLE_CP_SENSOR)
174 
175 #if (BLE_IPS_SERVER)
176 extern const struct prf_task_cbs* ipss_prf_itf_get(void);
177 #endif //(BLE_IPS_SERVER)
178 
179 #if (BLE_IPS_CLIENT)
180 extern const struct prf_task_cbs* ipsc_prf_itf_get(void);
181 #endif //(BLE_IPS_CLIENT)
182 
183 #if (BLE_ENV_SERVER)
184 extern const struct prf_task_cbs* envs_prf_itf_get(void);
185 #endif //(BLE_ENV_SERVER)
186 
187 #if (BLE_ENV_CLIENT)
188 extern const struct prf_task_cbs* envc_prf_itf_get(void);
189 #endif //(BLE_ENV_CLIENT
190 
191 #if (BLE_WSC_SERVER)
192 extern const struct prf_task_cbs* wscs_prf_itf_get(void);
193 #endif //(BLE_WSC_SERVER)
194 
195 #if (BLE_WSC_CLIENT)
196 extern const struct prf_task_cbs* wscc_prf_itf_get(void);
197 #endif //(BLE_WSC_CLIENT
198 
199 #if (BLE_BCS_SERVER)
200 extern const struct prf_task_cbs* bcss_prf_itf_get(void);
201 #endif //(BLE_BCS_SERVER)
202 
203 #if (BLE_BCS_CLIENT)
204 extern const struct prf_task_cbs* bcsc_prf_itf_get(void);
205 #endif //(BLE_BCS_CLIENT)
206 
207 #if (BLE_WPT_SERVER)
208 extern const struct prf_task_cbs* wpts_prf_itf_get(void);
209 #endif //(BLE_WPT_SERVER)
210 
211 #if (BLE_WPT_CLIENT)
212 extern const struct prf_task_cbs* wptc_prf_itf_get(void);
213 #endif //(BLE_WPT_CLIENT
214 
215 
216 
217 
218 #ifdef BLE_AM0_HEARING_AID_SERV
219 extern const struct prf_task_cbs* am0_has_prf_itf_get(void);
220 #endif // BLE_AM0_HEARING_AID_SERV
221 
222 #if (BLE_UDS_SERVER)
223 extern const struct prf_task_cbs* udss_prf_itf_get(void);
224 #endif //(BLE_UDS_SERVER)
225 
226 #if (BLE_UDS_CLIENT)
227 extern const struct prf_task_cbs* udsc_prf_itf_get(void);
228 #endif //(BLE_UDS_SERVER)
229 
230 #if (BLE_APP_USER)
231 extern const struct prf_task_cbs* user_prf_itf_get(void);
232 #endif //(BLE_APP_USER)
233 
234 /*
235  * TYPE DEFINITIONS
236  ****************************************************************************************
237  */
238 
239 
240 /*
241  * DEFINES
242  ****************************************************************************************
243  */
244 
245 /*
246  * MACROS
247  ****************************************************************************************
248  */
249 
250 
251 /*
252  * GLOBAL VARIABLE DEFINITIONS
253  ****************************************************************************************
254  */
255 struct prf_env_tag prf_env;
256 
257 /*
258  * LOCAL FUNCTIONS DEFINITIONS
259  ****************************************************************************************
260  */
261 
262 /**
263  ****************************************************************************************
264  * @brief Retrieve profile interface
265  ****************************************************************************************
266  */
prf_itf_get(uint16_t task_id)267 static const struct prf_task_cbs * prf_itf_get(uint16_t task_id)
268 {
269     const struct prf_task_cbs* prf_cbs = NULL;
270 
271     switch (KE_TYPE_GET(task_id))
272     {
273         #if (BLE_HT_THERMOM)
274         case TASK_ID_HTPT:
275             prf_cbs = htpt_prf_itf_get();
276             break;
277         #endif // (BLE_HT_THERMOM)
278 
279         #if (BLE_HT_COLLECTOR)
280         case TASK_ID_HTPC:
281             prf_cbs = htpc_prf_itf_get();
282             break;
283         #endif // (BLE_HT_COLLECTOR)
284 
285         #if (BLE_DIS_SERVER)
286         case TASK_ID_DISS:
287             prf_cbs = diss_prf_itf_get();
288             break;
289         #endif // (BLE_DIS_SERVER)
290 
291         #if (BLE_DIS_CLIENT)
292         case TASK_ID_DISC:
293             prf_cbs = disc_prf_itf_get();
294             break;
295         #endif // (BLE_DIS_CLIENT)
296 
297         #if (BLE_BP_SENSOR)
298         case TASK_ID_BLPS:
299             prf_cbs = blps_prf_itf_get();
300             break;
301         #endif // (BLE_BP_SENSOR)
302 
303         #if (BLE_BP_COLLECTOR)
304         case TASK_ID_BLPC:
305             prf_cbs = blpc_prf_itf_get();
306             break;
307         #endif // (BLE_BP_COLLECTOR)
308 
309         #if (BLE_TIP_SERVER)
310         case TASK_ID_TIPS:
311             prf_cbs = tips_prf_itf_get();
312             break;
313         #endif // (BLE_TIP_SERVER)
314 
315         #if (BLE_TIP_CLIENT)
316         case TASK_ID_TIPC:
317             prf_cbs = tipc_prf_itf_get();
318             break;
319         #endif // (BLE_TIP_CLIENT)
320 
321         #if (BLE_HR_SENSOR)
322         case TASK_ID_HRPS:
323             prf_cbs = hrps_prf_itf_get();
324             break;
325         #endif // (BLE_HR_SENSOR)
326 
327         #if (BLE_HR_COLLECTOR)
328         case TASK_ID_HRPC:
329             prf_cbs = hrpc_prf_itf_get();
330             break;
331         #endif // (BLE_HR_COLLECTOR)
332 
333         #if (BLE_FINDME_LOCATOR)
334         case TASK_ID_FINDL:
335             prf_cbs = findl_prf_itf_get();
336             break;
337         #endif // (BLE_FINDME_LOCATOR)
338 
339         #if (BLE_FINDME_TARGET)
340         case TASK_ID_FINDT:
341             prf_cbs = findt_prf_itf_get();
342             break;
343         #endif // (BLE_FINDME_TARGET)
344 
345         #if (BLE_PROX_MONITOR)
346         case TASK_ID_PROXM:
347             prf_cbs = proxm_prf_itf_get();
348             break;
349         #endif // (BLE_PROX_MONITOR)
350 
351         #if (BLE_PROX_REPORTER)
352         case TASK_ID_PROXR:
353             prf_cbs = proxr_prf_itf_get();
354             break;
355         #endif // (BLE_PROX_REPORTER)
356 
357         #if (BLE_SP_SERVER)
358         case TASK_ID_SCPPS:
359             prf_cbs = scpps_prf_itf_get();
360             break;
361         #endif // (BLE_SP_SERVER)
362 
363         #if (BLE_SP_CLIENT)
364         case TASK_ID_SCPPC:
365             prf_cbs = scppc_prf_itf_get();
366             break;
367         #endif // (BLE_SP_CLIENT)
368 
369 //        #if (BLE_BATT_SERVER)
370 //        case TASK_ID_BASS:
371 //            prf_cbs = bass_prf_itf_get();
372 //            break;
373 //        #endif // (BLE_BATT_SERVER)
374 
375         #if (BLE_BATT_CLIENT)
376         case TASK_ID_BASC:
377             prf_cbs = basc_prf_itf_get();
378             break;
379         #endif // (BLE_BATT_CLIENT)
380 
381         #if (BLE_HID_DEVICE)
382         case TASK_ID_HOGPD:
383             prf_cbs = hogpd_prf_itf_get();
384             break;
385         #endif // (BLE_HID_DEVICE)
386 
387         #if (BLE_HID_BOOT_HOST)
388         case TASK_ID_HOGPBH:
389             prf_cbs = hogpbh_prf_itf_get();
390             break;
391         #endif // (BLE_HID_BOOT_HOST)
392 
393         #if (BLE_HID_REPORT_HOST)
394         case TASK_ID_HOGPRH:
395             prf_cbs = hogprh_prf_itf_get();
396             break;
397         #endif // (BLE_HID_REPORT_HOST)
398 
399         #if (BLE_GL_COLLECTOR)
400         case TASK_ID_GLPC:
401             prf_cbs = glpc_prf_itf_get();
402             break;
403         #endif // (BLE_GL_COLLECTOR)
404 
405         #if (BLE_GL_SENSOR)
406         case TASK_ID_GLPS:
407             prf_cbs = glps_prf_itf_get();
408             break;
409         #endif // (BLE_GL_SENSOR)
410 
411         #if (BLE_RSC_COLLECTOR)
412         case TASK_ID_RSCPC:
413             prf_cbs = rscpc_prf_itf_get();
414             break;
415         #endif // (BLE_RSC_COLLECTOR)
416 
417         #if (BLE_RSC_SENSOR)
418         case TASK_ID_RSCPS:
419             prf_cbs = rscps_prf_itf_get();
420             break;
421         #endif // (BLE_RSC_SENSOR)
422 
423         #if (BLE_CSC_COLLECTOR)
424         case TASK_ID_CSCPC:
425             prf_cbs = cscpc_prf_itf_get();
426             break;
427         #endif // (BLE_CSC_COLLECTOR)
428 
429         #if (BLE_CSC_SENSOR)
430         case TASK_ID_CSCPS:
431             prf_cbs = cscps_prf_itf_get();
432             break;
433         #endif // (BLE_CSC_SENSOR)
434 
435         #if (BLE_CP_COLLECTOR)
436         case TASK_ID_CPPC:
437             prf_cbs = cppc_prf_itf_get();
438             break;
439         #endif // (BLE_CP_COLLECTOR)
440 
441         #if (BLE_CP_SENSOR)
442         case TASK_ID_CPPS:
443             prf_cbs = cpps_prf_itf_get();
444             break;
445         #endif // (BLE_CP_SENSOR)
446 
447         #if (BLE_LN_COLLECTOR)
448         case TASK_ID_LANC:
449             prf_cbs = lanc_prf_itf_get();
450             break;
451         #endif // (BLE_LN_COLLECTOR)
452 
453         #if (BLE_LN_SENSOR)
454         case TASK_ID_LANS:
455             prf_cbs = lans_prf_itf_get();
456             break;
457         #endif // (BLE_LN_SENSOR)
458 
459         #if (BLE_AN_CLIENT)
460         case TASK_ID_ANPC:
461             prf_cbs = anpc_prf_itf_get();
462             break;
463         #endif // (BLE_AN_CLIENT)
464 
465         #if (BLE_AN_SERVER)
466         case TASK_ID_ANPS:
467             prf_cbs = anps_prf_itf_get();
468             break;
469         #endif // (BLE_AN_SERVER)
470 
471         #if (BLE_PAS_CLIENT)
472         case TASK_ID_PASPC:
473             prf_cbs = paspc_prf_itf_get();
474             break;
475         #endif // (BLE_PAS_CLIENT)
476 
477         #if (BLE_PAS_SERVER)
478         case TASK_ID_PASPS:
479             prf_cbs = pasps_prf_itf_get();
480             break;
481         #endif // (BLE_PAS_SERVER)
482 
483         #ifdef BLE_AM0_HEARING_AID_SERV
484         case TASK_ID_AM0_HAS:
485             prf_cbs = am0_has_prf_itf_get();
486             break;
487         #endif // defined(BLE_AM0_HEARING_AID_SERV)
488 
489         #if (BLE_IPS_SERVER)
490         case TASK_ID_IPSS:
491             prf_cbs = ipss_prf_itf_get();
492             break;
493         #endif //(BLE_IPS_SERVER)
494 
495         #if (BLE_IPS_CLIENT)
496         case TASK_ID_IPSC:
497             prf_cbs = ipsc_prf_itf_get();
498             break;
499         #endif //(BLE_IPS_CLIENT)
500 
501         #if (BLE_ENV_SERVER)
502         case TASK_ID_ENVS:
503             prf_cbs = envs_prf_itf_get();
504             break;
505         #endif //(BLE_ENV_SERVER)
506 
507         #if (BLE_ENV_CLIENT)
508         case TASK_ID_ENVC:
509             prf_cbs = envc_prf_itf_get();
510             break;
511         #endif //(BLE_ENV_CLIENT
512 
513         #if (BLE_WSC_SERVER)
514         case TASK_ID_WSCS:
515             prf_cbs = wscs_prf_itf_get();
516             break;
517         #endif //(BLE_WSC_SERVER)
518 
519         #if (BLE_WSC_CLIENT)
520         case TASK_ID_WSCC:
521             prf_cbs = wscc_prf_itf_get();
522             break;
523         #endif //(BLE_WSC_CLIENT
524         #if (BLE_BCS_SERVER)
525         case TASK_ID_BCSS:
526             prf_cbs = bcss_prf_itf_get();
527             break;
528         #endif //(BLE_BCS_SERVER)
529 
530         #if (BLE_BCS_CLIENT)
531         case TASK_ID_BCSC:
532             prf_cbs = bcsc_prf_itf_get();
533             break;
534         #endif //(BLE_BCS_CLIENT)
535 
536         #if (BLE_UDS_SERVER)
537         case TASK_ID_UDSS:
538             prf_cbs = udss_prf_itf_get();
539             break;
540         #endif //(BLE_UDS_SERVER)
541 
542         #if (BLE_UDS_CLIENT)
543         case TASK_ID_UDSC:
544             prf_cbs = udsc_prf_itf_get();
545             break;
546         #endif //(BLE_UDS_CLIENT)
547 
548         #if (BLE_WPT_SERVER)
549         case TASK_ID_WPTS:
550             prf_cbs = wpts_prf_itf_get();
551             break;
552         #endif //(BLE_WPT_SERVER)
553 
554         #if (BLE_WPT_CLIENT)
555         case TASK_ID_WPTC:
556             prf_cbs = wptc_prf_itf_get();
557             break;
558         #endif //(BLE_WPT_CLIENT)
559         #if (BLE_APP_USER)
560         case TASK_ID_USER:
561             prf_cbs = user_prf_itf_get();
562             break;
563 
564         #endif // (BLE_APP_USER)
565 
566         default: /* Nothing to do */ break;
567     }
568 
569     return prf_cbs;
570 }
571 
572 /*
573  * EXPORTED FUNCTIONS DEFINITIONS
574  ****************************************************************************************
575  */
prf_init(bool reset)576 void prf_init(bool reset)
577 {
578 
579     uint8_t i;
580     if (!reset)
581     {
582         // FW boot profile initialization
583         for(i = 0; i < BLE_NB_PROFILES ; i++)
584         {
585             prf_env.prf[i].env  = NULL;
586             prf_env.prf[i].task = TASK_GAPC + i +1;
587             prf_env.prf[i].id   = TASK_ID_INVALID;
588 
589             // Initialize Task Descriptor
590             prf_env.prf[i].desc.default_handler = NULL;
591             prf_env.prf[i].desc.state           = NULL;
592             prf_env.prf[i].desc.idx_max         = 0;
593 
594             prf_env.prf[i].desc.state_max       = 0;
595             prf_env.prf[i].desc.state_handler   = NULL;
596 
597             ke_task_create(prf_env.prf[i].task, &(prf_env.prf[i].desc));
598         }
599     }
600     else
601     {
602         // FW boot profile destruction
603         for(i = 0; i < BLE_NB_PROFILES ; i++)
604         {
605             // Get Profile API
606             const struct prf_task_cbs * cbs = prf_itf_get(prf_env.prf[i].id);
607             if (cbs != NULL)
608             {
609                 // request to destroy profile
610                 cbs->destroy(&(prf_env.prf[i]));
611             }
612             // unregister profile
613             prf_env.prf[i].id   = TASK_ID_INVALID;
614             prf_env.prf[i].desc.default_handler = NULL;
615             prf_env.prf[i].desc.state           = NULL;
616             prf_env.prf[i].desc.idx_max         = 0;
617 
618             // Request kernel to flush task messages
619             ke_task_msg_flush(KE_TYPE_GET(prf_env.prf[i].task));
620         }
621     }
622 }
623 
624 
prf_add_profile(struct gapm_profile_task_add_cmd * params,ke_task_id_t * prf_task)625 uint8_t prf_add_profile(struct gapm_profile_task_add_cmd * params, ke_task_id_t* prf_task)
626 {
627     uint8_t i;
628     uint8_t status = GAP_ERR_NO_ERROR;
629 
630     // retrieve profile callback
631     const struct prf_task_cbs * cbs = prf_itf_get(params->prf_task_id);
632     if (cbs == NULL)
633     {
634         // profile API not available
635         status = GAP_ERR_INVALID_PARAM;
636     }
637 
638     // check if profile not already present in task list
639     if (status == GAP_ERR_NO_ERROR)
640     {
641         for(i = 0; i < BLE_NB_PROFILES ; i++)
642         {
643             if (prf_env.prf[i].id == params->prf_task_id)
644             {
645                 status = GAP_ERR_NOT_SUPPORTED;
646                 break;
647             }
648         }
649     }
650 
651     if (status == GAP_ERR_NO_ERROR)
652     {
653         // find fist available task
654         for(i = 0; i < BLE_NB_PROFILES ; i++)
655         {
656             // available task found
657             if (prf_env.prf[i].id == TASK_ID_INVALID)
658             {
659                 // initialize profile
660                 status = cbs->init(&(prf_env.prf[i]), &(params->start_hdl), params->app_task, params->sec_lvl, params->param);
661 
662                 // initialization succeed
663                 if (status == GAP_ERR_NO_ERROR)
664                 {
665                     // register profile
666                     prf_env.prf[i].id = params->prf_task_id;
667                     *prf_task = prf_env.prf[i].task;
668                 }
669                 break;
670             }
671         }
672 
673         if (i == BLE_NB_PROFILES)
674         {
675             status = GAP_ERR_INSUFF_RESOURCES;
676         }
677     }
678 
679     return (status);
680 }
681 
682 
683 
prf_create(uint8_t conidx)684 void prf_create(uint8_t conidx)
685 {
686     uint8_t i;
687     /* simple connection creation handler, nothing to do. */
688 
689     // execute create function of each profiles
690     for(i = 0; i < BLE_NB_PROFILES ; i++)
691     {
692         // Get Profile API
693         const struct prf_task_cbs * cbs = prf_itf_get(prf_env.prf[i].id);
694         if (cbs != NULL)
695         {
696             // call create callback
697             cbs->create(&(prf_env.prf[i]), conidx);
698         }
699     }
700 }
701 
702 
prf_cleanup(uint8_t conidx,uint8_t reason)703 void prf_cleanup(uint8_t conidx, uint8_t reason)
704 {
705     uint8_t i;
706     /* simple connection creation handler, nothing to do. */
707 
708     // execute create function of each profiles
709     for(i = 0; i < BLE_NB_PROFILES ; i++)
710     {
711         // Get Profile API
712         const struct prf_task_cbs * cbs = prf_itf_get(prf_env.prf[i].id);
713         if (cbs != NULL)
714         {
715             // call cleanup callback
716             cbs->cleanup(&(prf_env.prf[i]), conidx, reason);
717         }
718     }
719 }
720 
721 
prf_env_get(uint16_t prf_id)722 prf_env_t* prf_env_get(uint16_t prf_id)
723 {
724     prf_env_t* env = NULL;
725     uint8_t i;
726     // find if profile present in profile tasks
727     for(i = 0; i < BLE_NB_PROFILES ; i++)
728     {
729         // check if profile identifier is known
730         if (prf_env.prf[i].id == prf_id)
731         {
732             env = prf_env.prf[i].env;
733             break;
734         }
735     }
736 
737     return env;
738 }
739 
prf_src_task_get(prf_env_t * env,uint8_t conidx)740 ke_task_id_t prf_src_task_get(prf_env_t* env, uint8_t conidx)
741 {
742     ke_task_id_t task = PERM_GET(env->prf_task, PRF_TASK);
743 
744     if (PERM_GET(env->prf_task, PRF_MI))
745     {
746         task = KE_BUILD_ID(task, conidx);
747     }
748 
749     return task;
750 }
751 
prf_dst_task_get(prf_env_t * env,uint8_t conidx)752 ke_task_id_t prf_dst_task_get(prf_env_t* env, uint8_t conidx)
753 {
754     ke_task_id_t task = PERM_GET(env->app_task, PRF_TASK);
755 
756     if (PERM_GET(env->app_task, PRF_MI))
757     {
758         task = KE_BUILD_ID(task, conidx);
759     }
760 
761     return task;
762 }
763 
764 
prf_get_id_from_task(ke_msg_id_t task)765 ke_task_id_t prf_get_id_from_task(ke_msg_id_t task)
766 {
767     ke_task_id_t id = TASK_ID_INVALID;
768     uint8_t idx = KE_IDX_GET(task);
769     uint8_t i;
770     task = KE_TYPE_GET(task);
771 
772     // find if profile present in profile tasks
773     for(i = 0; i < BLE_NB_PROFILES ; i++)
774     {
775         // check if profile identifier is known
776         if (prf_env.prf[i].task == task)
777         {
778             id = prf_env.prf[i].id;
779             break;
780         }
781     }
782 
783     return KE_BUILD_ID(id, idx);
784 }
785 
prf_get_task_from_id(ke_msg_id_t id)786 ke_task_id_t prf_get_task_from_id(ke_msg_id_t id)
787 {
788     ke_task_id_t task = TASK_NONE;
789     uint8_t idx = KE_IDX_GET(id);
790     uint8_t i;
791     id = KE_TYPE_GET(id);
792 
793     // find if profile present in profile tasks
794     for(i = 0; i < BLE_NB_PROFILES ; i++)
795     {
796         // check if profile identifier is known
797         if (prf_env.prf[i].id == id)
798         {
799             task = prf_env.prf[i].task;
800             break;
801         }
802     }
803 
804     return KE_BUILD_ID(task, idx);
805 }
806 
807 
808 #endif // (BLE_PROFILES)
809 
810 /// @} PRF
811