1 /******************************************************************************
2  * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************/
18 #ifndef LL_EXT_ADV_H_
19 #define LL_EXT_ADV_H_
20 
21 
22 #include "stack/ble/hci/hci_cmd.h"
23 
24 
25 /* maximum number of advertising sets this SDK can support, periodic advertising is included. */
26 #define			ADV_SETS_NUMBER_MAX								4
27 
28 
29 /* Note: user can't modify this value,and this value must 4 byte aligned
30  *  if use BLUETOOTH_VER_5_2 this value is 680 other than 572
31  */
32 #define 		ADV_SET_PARAM_LENGTH							680//572
33 
34 
35 
36 #if 0
37 /* if use legacy ADV, primary ADV packet maximum length is 44 */
38 #define 		MAX_LENGTH_PRIMARY_ADV_PKT_LEGACY				44
39 
40 /* if use extended ADV, primary ADV packet maximum length is 28 */
41 #define 		MAX_LENGTH_PRIMARY_ADV_PKT_EXTENDED				28
42 
43 /* if not sure which kind of ADV will be used, use the bigger value is recommended.
44  * For example, when used as BLE Controller, BLE Host can use either legacy or extended ADV */
45 #define 		MAX_LENGTH_PRIMARY_ADV_PKT						44
46 
47 
48 
49 #define 		MAX_LENGTH_SECOND_ADV_PKT						264   //sizeof(rf_pkt_ext_adv_t) = 261
50 #endif
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 /**
66  * @brief      for user to initialize extended advertising module
67  * 			   notice that: 1. only one module can be selected between legacy advertising module and extended advertising module
68  *							2. this API must be used before any other extended ADV initialization APIs.
69  * @param	   none
70  * @return     none
71  */
72 void 		blc_ll_initExtendedAdvertising_module(void);
73 
74 /**
75  * @brief      for user to allocate single or multiple advertising sets buffer
76  * 			   notice that: this API must used after "blc_ll_initExtendedAdvertising_module",
77  * 			                and before any other extended ADV initialization APIs.
78  * @param[in]  pBuff_advSets - global buffer allocated by application layer.
79  * @param[in]  num_advSets - number of application adv_sets
80  * @return     Status - 0x00: command succeeded;
81  * 						0x12: num_advSets exceed maximum number of supported adv_sets.
82  */
83 ble_sts_t 	blc_ll_initExtendedAdvSetBuffer(u8 *pBuff_advSets, int num_advSets);
84 
85 /**
86  * @brief      initialize Advertising Data buffer for all adv_set
87  * @param[in]  pExtAdvData -
88  * @param[in]  max_len_advData -
89  * @return     none
90  */
91 void 		blc_ll_initExtAdvDataBuffer(u8 *pExtAdvData, int max_len_advData);
92 
93 /**
94  * @brief      initialize Advertising Data buffer for specific adv_set.
95  * @param[in]  adv_handle - Used to identify an advertising set
96  * @param[in]  pExtAdvData -
97  * @param[in]  max_len_advData -
98  * @return     Status - 0x00: succeed.
99  * 						0x12: adv_handle out of range.
100  */
101 ble_sts_t 	blc_ll_initExtAdvDataBuffer_by_advHandle( u8 adv_handle, u8 *pExtAdvData, int max_len_advData);
102 
103 /**
104  * @brief      initialize Scan Response Data Buffer for all adv_set
105  * @param[in]  pScanRspData -
106  * @param[in]  max_len_scanRspData -
107  * @return     none
108  */
109 void 		blc_ll_initExtScanRspDataBuffer(u8 *pScanRspData, int max_len_scanRspData);
110 
111 /**
112  * @brief      initialize Scan Response Data Buffer buffer for specific adv_set.
113  * @param[in]  adv_handle - Used to identify an advertising set
114  * @param[in]  pScanRspData -
115  * @param[in]  max_len_scanRspData -
116  * @return     Status - 0x00: succeed.
117  * 						0x12: adv_handle out of range.
118  */
119 ble_sts_t 	blc_ll_initExtScanRspDataBuffer_by_advHandle(u8 adv_handle, u8 *pScanRspData, int max_len_scanRspData);
120 
121 
122 
123 
124 
125 
126 
127 /**
128  * @brief      This function is used to set the advertising parameters
129  * @param[in]  adv_handle - Used to identify an advertising set
130  * @param[in]  adv_evt_prop -
131  * @param[in]  pri_advInter_min & pri_advInter_max
132  * @param[in]
133  * @param[in]
134  * @param[in]
135  * @param[in]
136  * @return     Status - 0x00: command succeeded;
137  * 						0x12:  1. adv_handle out of range;
138  * 						       2. pri_advChnMap out of range
139  * 						0x0C:  advertising is enabled for the specified advertising set
140  */
141 ble_sts_t 	blc_ll_setExtAdvParam(  u8 adv_handle, 		 			advEvtProp_type_t adv_evt_prop,	u32 pri_advInter_min, 		u32 pri_advInter_max,
142 									adv_chn_map_t pri_advChnMap,	own_addr_type_t ownAddrType, 	u8 peerAddrType, 			u8  *peerAddr,
143 									adv_fp_type_t advFilterPolicy,  tx_power_t adv_tx_pow,			le_phy_type_t pri_adv_phy, 	u8 sec_adv_max_skip,
144 									le_phy_type_t sec_adv_phy, 	 	u8 adv_sid, 					u8 scan_req_noti_en);
145 
146 
147 
148 /**
149  * @brief      This function is used to set the data used in advertising PDU that have a data field
150  * 			   notice that: setting legacy ADV data also use this API, data length can not exceed 31
151  * @param[in]  adv_handle - Used to identify an advertising set
152  * @param[in]  *advData -
153  * @param[in]  advData_len -
154  * @return     Status - 0x00: command succeeded; 0x01-0xFF: command failed
155  */
156 ble_sts_t	blc_ll_setExtAdvData (u8 adv_handle, int advData_len, u8 *advData);
157 
158 
159 
160 
161 
162 
163 /**
164  * @brief      This function is used to provide scan response data used in scanning response PDUs.
165  * 			   notice that: setting legacy scan response data also use this API, data length can not exceed 31
166  * @param[in]  adv_handle - Used to identify an advertising set
167  * @param[in]  scanRspData_len -
168  * @param[in]  *scanRspData -
169  * @return     Status - 0x00: command succeeded; 0x01-0xFF: command failed
170  */
171 ble_sts_t 	blc_ll_setExtScanRspData(u8 adv_handle, int scanRspData_len, u8 *scanRspData);
172 
173 
174 
175 
176 
177 /**
178  * @brief      This function is used to request the Controller to enable or disable one or more advertising sets using the
179 			   advertising sets identified by the adv_handle
180  * @param[in]  enable -
181  * @param[in]  adv_handle - Used to identify an advertising set
182  * @param[in]  duration -	the duration for which that advertising set is enabled
183  * 							Range: 0x0001 to 0xFFFF, Time = N * 10 ms, Time Range: 10 ms to 655,350 ms
184  * @param[in]  max_extAdvEvt - Maximum number of extended advertising events the Controller shall
185  *                             attempt to send prior to terminating the extended advertising
186  * @return     Status - 0x00: command succeeded; 0x01-0xFF: command failed
187  */
188 ble_sts_t 	blc_ll_setExtAdvEnable(adv_en_t enable, u8 adv_handle, u16 duration, u8 max_extAdvEvt);
189 
190 
191 
192 /**
193  * @brief      This function is used by the Host to set the random device address specified by the Random_Address
194 			   parameter
195  * @param[in]  adv_handle - Used to identify an advertising set
196  * @param[in]  *rand_addr - Random Device Address
197  * @return     Status - 0x00: command succeeded; 0x01-0xFF: command failed
198  */
199 ble_sts_t	blc_ll_setAdvRandomAddr(u8 adv_handle, u8* rand_addr);
200 
201 
202 
203 /**
204  * @brief      This function is is used to remove an advertising set from the Controller.
205  * @param[in]  adv_handle - Used to identify an advertising set
206  * @return     Status - 0x00: command succeeded; 0x01-0xFF: command failed
207  */
208 ble_sts_t	blc_ll_removeAdvSet(u8 adv_handle);
209 
210 
211 
212 /**
213  * @brief      This function is used to remove all existing advertising sets from the Controller.
214  * @param[in]  none.
215  * @return     Status - 0x00: command succeeded; 0x01-0xFF: command failed
216  */
217 ble_sts_t	blc_ll_clearAdvSets(void);
218 
219 
220 
221 
222 //only for Debug
223 ble_sts_t	blc_ll_setAuxAdvChnIdxByCustomers(u8 aux_chn);
224 
225 
226 
227 
228 #endif /* LL_EXT_ADV_H_ */
229