1 /*
2  * Copyright (c) 2018-2021 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 int lll_adv_data_init(struct lll_adv_pdu *pdu);
8 int lll_adv_data_reset(struct lll_adv_pdu *pdu);
9 int lll_adv_data_release(struct lll_adv_pdu *pdu);
10 
lll_adv_pdu_enqueue(struct lll_adv_pdu * pdu,uint8_t idx)11 static inline void lll_adv_pdu_enqueue(struct lll_adv_pdu *pdu, uint8_t idx)
12 {
13 	pdu->last = idx;
14 }
15 
16 struct pdu_adv *lll_adv_pdu_alloc(struct lll_adv_pdu *pdu, uint8_t *idx);
17 
lll_adv_data_alloc(struct lll_adv * lll,uint8_t * idx)18 static inline struct pdu_adv *lll_adv_data_alloc(struct lll_adv *lll, uint8_t *idx)
19 {
20 	return lll_adv_pdu_alloc(&lll->adv_data, idx);
21 }
22 
lll_adv_data_enqueue(struct lll_adv * lll,uint8_t idx)23 static inline void lll_adv_data_enqueue(struct lll_adv *lll, uint8_t idx)
24 {
25 	lll_adv_pdu_enqueue(&lll->adv_data, idx);
26 }
27 
lll_adv_data_peek(struct lll_adv * lll)28 static inline struct pdu_adv *lll_adv_data_peek(struct lll_adv *lll)
29 {
30 	return (void *)lll->adv_data.pdu[lll->adv_data.last];
31 }
32 
lll_adv_data_curr_get(struct lll_adv * lll)33 static inline struct pdu_adv *lll_adv_data_curr_get(struct lll_adv *lll)
34 {
35 	return (void *)lll->adv_data.pdu[lll->adv_data.first];
36 }
37 
lll_adv_scan_rsp_alloc(struct lll_adv * lll,uint8_t * idx)38 static inline struct pdu_adv *lll_adv_scan_rsp_alloc(struct lll_adv *lll, uint8_t *idx)
39 {
40 	return lll_adv_pdu_alloc(&lll->scan_rsp, idx);
41 }
42 
lll_adv_scan_rsp_enqueue(struct lll_adv * lll,uint8_t idx)43 static inline void lll_adv_scan_rsp_enqueue(struct lll_adv *lll, uint8_t idx)
44 {
45 	lll_adv_pdu_enqueue(&lll->scan_rsp, idx);
46 }
47 
lll_adv_scan_rsp_peek(struct lll_adv * lll)48 static inline struct pdu_adv *lll_adv_scan_rsp_peek(struct lll_adv *lll)
49 {
50 	return (void *)lll->scan_rsp.pdu[lll->scan_rsp.last];
51 }
52 
53 #if defined(CONFIG_BT_CTLR_ADV_EXT)
lll_adv_aux_data_alloc(struct lll_adv_aux * lll,uint8_t * idx)54 static inline struct pdu_adv *lll_adv_aux_data_alloc(struct lll_adv_aux *lll, uint8_t *idx)
55 {
56 	return lll_adv_pdu_alloc(&lll->data, idx);
57 }
58 
lll_adv_aux_data_enqueue(struct lll_adv_aux * lll,uint8_t idx)59 static inline void lll_adv_aux_data_enqueue(struct lll_adv_aux *lll, uint8_t idx)
60 {
61 	lll_adv_pdu_enqueue(&lll->data, idx);
62 }
63 
lll_adv_aux_data_peek(struct lll_adv_aux * lll)64 static inline struct pdu_adv *lll_adv_aux_data_peek(struct lll_adv_aux *lll)
65 {
66 	return (void *)lll->data.pdu[lll->data.last];
67 }
68 
lll_adv_aux_data_curr_get(struct lll_adv_aux * lll)69 static inline struct pdu_adv *lll_adv_aux_data_curr_get(struct lll_adv_aux *lll)
70 {
71 	return (void *)lll->data.pdu[lll->data.first];
72 }
73 
74 #if defined(CONFIG_BT_CTLR_ADV_PERIODIC)
75 int lll_adv_and_extra_data_release(struct lll_adv_pdu *pdu);
76 
77 struct pdu_adv *lll_adv_pdu_and_extra_data_alloc(struct lll_adv_pdu *pdu, void **extra_data,
78 						 uint8_t *idx);
79 
lll_adv_sync_data_alloc(struct lll_adv_sync * lll,void ** extra_data,uint8_t * idx)80 static inline struct pdu_adv *lll_adv_sync_data_alloc(struct lll_adv_sync *lll, void **extra_data,
81 						      uint8_t *idx)
82 {
83 #if defined(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY)
84 	return lll_adv_pdu_and_extra_data_alloc(&lll->data, extra_data, idx);
85 #else
86 	return lll_adv_pdu_alloc(&lll->data, idx);
87 #endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */
88 }
89 
lll_adv_sync_data_release(struct lll_adv_sync * lll)90 static inline void lll_adv_sync_data_release(struct lll_adv_sync *lll)
91 {
92 #if defined(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY)
93 	lll_adv_and_extra_data_release(&lll->data);
94 #else
95 	lll_adv_data_release(&lll->data);
96 #endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */
97 }
98 
lll_adv_sync_data_enqueue(struct lll_adv_sync * lll,uint8_t idx)99 static inline void lll_adv_sync_data_enqueue(struct lll_adv_sync *lll, uint8_t idx)
100 {
101 	lll_adv_pdu_enqueue(&lll->data, idx);
102 }
103 
lll_adv_sync_data_peek(struct lll_adv_sync * lll,void ** extra_data)104 static inline struct pdu_adv *lll_adv_sync_data_peek(struct lll_adv_sync *lll, void **extra_data)
105 {
106 	uint8_t last = lll->data.last;
107 
108 #if defined(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY)
109 	if (extra_data) {
110 		*extra_data = lll->data.extra_data[last];
111 	}
112 #endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */
113 
114 	return (void *)lll->data.pdu[last];
115 }
116 
lll_adv_sync_data_curr_get(struct lll_adv_sync * lll)117 static inline struct pdu_adv *lll_adv_sync_data_curr_get(struct lll_adv_sync *lll)
118 {
119 	return (void *)lll->data.pdu[lll->data.first];
120 }
121 
122 #endif /* CONFIG_BT_CTLR_ADV_PERIODIC */
123 #endif /* CONFIG_BT_CTLR_ADV_EXT */
124