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_H_
19 #define LL_H_
20 
21 
22 
23 /**
24  * @brief	Telink defined LinkLayer Event Callback
25  */
26 typedef void (*blt_event_callback_t)(u8 e, u8 *p, int n);
27 
28 
29 
30 
31 typedef enum{
32 	BLT_EV_FLAG_ADV_DURATION_TIMEOUT	=	0,
33 	BLT_EV_FLAG_RX_DATA_ABANDOM,
34 	BLT_EV_FLAG_GPIO_EARLY_WAKEUP,
35 	BLT_EV_FLAG_SLEEP_ENTER,
36 	BLT_EV_FLAG_SUSPEND_EXIT,
37 	BLT_EV_FLAG_LL_REJECT_IND,
38 	BLT_EV_MAX_NUM,
39 }blt_ev_flag_t;
40 
41 
42 
43 
44 
45 
46 
47 typedef enum{
48 	LL_FEATURE_ENABLE	= 1,
49 	LL_FEATURE_DISABLE  = 0,
50 }ll_feature_value_t;
51 
52 
53 
54 /**
55  * @brief	Telink defined LinkLayer Event callBack
56  * @param[in]	e - event number, must use element of "blt_ev_flag_t"
57  * @param[in]	p - callBack function
58  * @return	none
59  */
60 void 		blc_ll_registerTelinkControllerEventCallback (u8 e, blt_event_callback_t p);
61 
62 /**
63  * @brief	irq_handler for BLE stack, process system tick interrupt and RF interrupt
64  * @param	none
65  * @return	none
66  */
67 void 		blc_sdk_irq_handler(void);
68 
69 /**
70  * @brief   main_loop for BLE stack, process data and event
71  * @param	none
72  * @return	none
73  */
74 void 		blc_sdk_main_loop (void);
75 
76 
77 
78 /**
79  * @brief      for user to initialize MCU
80  * @param	   none
81  * @return     none
82  */
83 void 		blc_ll_initBasicMCU (void);
84 
85 
86 
87 /**
88  * @brief      for user to initialize link layer Standby state
89  * @param	   none
90  * @return     none
91  */
92 void 		blc_ll_initStandby_module (u8 *public_adr);
93 
94 
95 /**
96  * @brief      this function is used to read MAC address
97  * @param[in]  *addr -  The address where the read value(MAC address) prepare to write.
98  * @return     status, 0x00:  succeed
99  * 					   other: failed
100  */
101 ble_sts_t   blc_ll_readBDAddr(u8 *addr);
102 
103 
104 /**
105  * @brief      this function is used to set the LE Random Device Address in the Controller
106  * @param[in]  *randomAddr -  Random Device Address
107  * @return     status, 0x00:  succeed
108  * 					   other: failed
109  */
110 ble_sts_t 	blc_ll_setRandomAddr(u8 *randomAddr);
111 
112 
113 /**
114  * @brief      This function is used to check if the address's type is public
115  * @param[in]  *addr -  The address need to check.
116  * @return     bool, 0x00: no public, 0x01: Public
117  */
118 bool 		blc_ll_isValidPublicAddr(u8* addr);
119 
120 
121 /**
122  * @brief      This function is used to check if the address's type is random
123  * @param[in]  *addr -  The address need to check.
124  * @return     bool, 0x00: no random, 0x01: random
125  */
126 bool 		blc_ll_isValidRandomAddr(u8* addr);
127 
128 
129 /**
130  * @brief      This function is used to check if owner's address type is valid
131  * @param[in]  ownAddrType -  Owner address type.
132  * @param[in]  randomAddr -  If Owner's address type is Random, input Random address.
133  * @return     bool, 0x00: invalid, 0x01: valid
134  */
135 bool 		blc_ll_isValidOwnAddrByAddrType(u8 ownAddrType, u8* randomAddr);
136 
137 
138 /**
139  * @brief      this function is used by the Host to specify a channel classification based on its local information,
140  *             only the master role is valid.
141  * @param[in]  bit_number - Bit position in the FeatureSet.
142  * @param[in]  bit_value - refer to the struct "ll_feature_value_t".
143  * @return     status, 0x00:  succeed
144  * 			           other: failed
145  */
146 ble_sts_t	blc_hci_le_setHostFeature(u8 bit_number, ll_feature_value_t bit_value);
147 
148 
149 /**
150  * @brief      this function is used check if any controller buffer initialized by application incorrect.
151  * 			   attention: this function must be called at the end of BLE LinkLayer Initialization.
152  * @param	   none
153  * @return     status, 0x00:  succeed, no buffer error
154  * 					   other: buffer error code
155  */
156 ble_sts_t	blc_controller_check_appBufferInitialization(void);
157 
158 
159 
160 /**
161  * @brief      this function is used by the Host to specify a channel classification based on its local information,
162  *             only the master role is valid.
163  * @param[in]  *map - channel map
164  * @return     status, 0x00:  succeed
165  * 			           other: failed
166  */
167 ble_sts_t 	blc_ll_setHostChannel(u8 * chnMap);
168 
169 
170 /**
171  * @brief      this function is used to reset module of all.
172  * @param	   none
173  * @return     status, 0x00:  succeed, no buffer error
174  * 					   other: buffer error code
175  */
176 ble_sts_t  		blc_hci_reset(void);
177 ble_sts_t 	blc_hci_le_getRemoteSupportedFeatures(u16 connHandle);
178 ble_sts_t 	blc_hci_le_readChannelMap(u16 connHandle, u8 *returnChannelMap);
179 
180 #endif /* LL_H_ */
181