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 IAL_H_
19 #define IAL_H_
20 
21 
22 
23 
24 #include "stack/ble/controller/ll/iso/iso.h"
25 
26 
27 
28 
29 /*
30  * First fragment of sdu, data field
31  */
32 #define HCI_ISO_PKT_HDR_HANDLE_LEN					(2)
33 #define HCI_ISO_PKT_HDR_DATA_LEN					(2)
34 #define	HCI_ISO_LOAD_HDR_TIMESTAMP_LEN				(4)
35 #define	HCI_ISO_LOAD_HDR_PACKET_SN_LEN				(2)
36 #define	HCI_ISO_LOAD_SDU_LEN						(2)
37 
38 #define HCI_ISO_PKT_HDR_LEN							(HCI_ISO_PKT_HDR_HANDLE_LEN + HCI_ISO_PKT_HDR_DATA_LEN)
39 
40 #define HCI_ISO_LOAD_HDR_LEN_MAX					(HCI_ISO_LOAD_HDR_TIMESTAMP_LEN + HCI_ISO_LOAD_HDR_PACKET_SN_LEN + HCI_ISO_LOAD_SDU_LEN)
41 #define HCI_ISO_LOAD_HDR_LEN_MIN					(HCI_ISO_LOAD_HDR_PACKET_SN_LEN + HCI_ISO_LOAD_SDU_LEN)
42 
43 
44 #define ISO_FRAMED_SEGM_HEADER_LEN					(2)
45 #define	ISO_FRAMED_TIMEOFFSET_LEN					(3)
46 
47 
48 /*
49  * HCI ISO data packet
50  */
51 typedef struct{
52 
53 //0
54 	u32 timestamp;
55 	u16 offset;
56 	u16 sn_offset;
57 
58 
59 //8
60 	u16 connHandle		 :12;
61 	u16 pb         	 	 :2;
62 	u16 ts				 :1;
63 	u16 RFU2			 :1;
64 //10
65 	u16 iso_dl_len		 :14;  //iso_data_load_length
66 	u16 RFU3			 :2;
67 
68 
69 //11
70 	u8 data[1];
71 
72 }iso_data_packet_t;
73 
74 
75 
76 
77 
78 
79 /******************************* Macro & Enumeration & Structure Definition for Stack End ******************************/
80 
81 
82 
83 
84 
85 
86 /******************************* Macro & Enumeration variables for User Begin ******************************************/
87 
88 
89 
90 /******************************* Macro & Enumeration variables for User End ********************************************/
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 /******************************* User Interface  Begin *****************************************************************/
106 
107 /**
108  * @brief      This function is used to initialize the ISOAL module.
109  */
110 void 		blc_ial_initSdu_module(void);
111 
112 /**
113  * @brief      This function is used to initialize sdu buff.
114  * @param[in]  rx_fifo
115  * @param[in]  rx_fifo_size
116  * @param[in]  rx_fifo_num
117  * @param[in]  tx_fifo
118  * @param[in]  tx_fifo_size
119  * @param[in]  tx_fifo_num
120  */
121 void 		blc_ial_initCisSduBuff(u8 *rx_fifo,u16 rx_fifo_size, u8 rx_fifo_num, u8 *tx_fifo,u16 tx_fifo_size, u8 tx_fifo_num);
122 
123 /**
124  * @brief      This function is used to initialize cis sdu buff.
125  * @param[in]  rx_fifo
126  * @param[in]  rx_fifo_size
127  * @param[in]  rx_fifo_num
128  * @param[in]  tx_fifo
129  * @param[in]  tx_fifo_size
130  * @param[in]  tx_fifo_num
131  */
132 void		blc_ial_initBisSduBuff(u8 *rx_fifo,u16 rx_fifo_size, u8 rx_fifo_num, u8 *tx_fifo,u16 tx_fifo_size, u8 tx_fifo_num);
133 
134 /**
135  * @brief      This function is used to pack HCI ISO data packet to SDU packet.
136  * @param[in]  cis_connHandle - point to handle of cis.
137  * @param[in]  pIsoData - point to hci ISO Data packet buff.
138  * @return     Status - 0x00: command succeeded; 0x01-0xFF: command failed
139  */
140 ble_sts_t 	blc_hci_packIsoData(u16 cis_connHandle, u8 *pIsoData);
141 
142 /**
143  * @brief      This function is used to setup ISO Data Path.
144  * @param[in]  refer to the structure 'hci_le_setupIsoDataPathCmdParams_t'
145  * @return     Status - 0x00: command succeeded; 0x01-0xFF: command failed
146  */
147 ble_sts_t	blc_isoal_le_setupISODataPath_cmd(hci_le_setupIsoDataPathCmdParams_t *para);
148 
149 /**
150  * @brief      This function is used to segmentation SDU to one Framed PDUs.
151  * @param[in]  cis_connHandle
152  * @return      Status - 0x00: command succeeded; IAL_ERR_SDU_LEN_EXCEED_SDU_MAX
153  * 						 LL_ERR_INVALID_PARAMETER: command failed
154  */
155 ble_sts_t	blc_ial_splitCisSdu2FramedPdu(u16 cis_connHandle);
156 
157 
158 /**
159  * @brief      This function is used to fragmentation SDU to one or more Unframed PDUs.
160  * @param[in]  cis_connHandle
161  * @param[in]  sdu  point to sdu buff
162  * @return      Status - 0x00: command succeeded; IAL_ERR_SDU_LEN_EXCEED_SDU_MAX
163  * 						 LL_ERR_INVALID_PARAMETER: command failed
164  */
165 ble_sts_t 	blc_ial_cis_splitSdu2UnframedPdu(u16 cisHandle, iso_data_packet_t *sdu);
166 
167 
168 /**
169  * @brief      This function is used to fragmentation SDU to one or more Unframed PDUs.
170  * @param[in]  bis_connHandle
171  * @param[in]  sdu  point to sdu buff
172  * @return      Status - 0x00: command succeeded; IAL_ERR_SDU_LEN_EXCEED_SDU_MAX
173  * 						 LL_ERR_INVALID_PARAMETER: command failed
174  */
175 ble_sts_t 	blc_ial_bis_splitSdu2UnframedPdu(u16 bis_connHandle, iso_data_packet_t *sdu);
176 
177 
178 /******************************* User Interface  End  ******************************************************************/
179 
180 
181 
182 #endif
183 
184 
185