CRC and Rx Data Indication
[o-du/l2.git] / src / 5gnrmac / mac_rach.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
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 /* header include files (.h) */
19 #include "envopt.h"        /* environment options */
20 #include "envdep.h"        /* environment dependent */
21 #include "envind.h"        /* environment independent */
22 #include "gen.h"           /* general */
23 #include "ssi.h"           /* system services */
24 #include "cm_tkns.h"       /* Common Token Defines */
25 #include "cm_llist.h"      /* Common Link List Defines */
26 #include "cm_hash.h"       /* Common Hash List Defines */
27 #include "cm_mblk.h"       /* common memory link list library */
28 #include "cm_lte.h"        /* Common LTE Defines */
29 #include "tfu.h"           /* RGU Interface includes */
30 #include "lrg.h"
31 #include "gen.x"           /* general */
32 #include "ssi.x"           /* system services */
33 #include "cm5.x"           /* system services */
34 #include "cm_tkns.x"       /* Common Token Definitions */
35 #include "cm_llist.x"      /* Common Link List Definitions */
36 #include "cm_lib.x"        /* Common Library Definitions */
37 #include "cm_hash.x"       /* Common Hash List Definitions */
38 #include "cm_mblk.x"       /* common memory link list library */
39 #include "cm_lte.x"        /* Common LTE Defines */
40 #include "tfu.x"           /* RGU Interface includes */
41 #include "lrg.x"
42 #include "du_app_mac_inf.h"
43 #include "mac.h"
44 #include "du_log.h"
45
46 /* Function pointer for sending rach ind from MAC to SCH */
47 MacSchRachIndFunc macSchRachIndOpts[]=
48 {
49    packMacSchRachInd,
50    macSchRachInd,
51    packMacSchRachInd
52 };
53
54 /* Function pointer for sending crc ind from MAC to SCH */
55 MacSchCrcIndFunc macSchCrcIndOpts[]=
56 {
57    packMacSchCrcInd,
58    macSchCrcInd,
59    packMacSchCrcInd
60 };
61
62 /*******************************************************************
63  *
64  * @brief Sends RACH indication to SCH
65  *
66  * @details
67  *
68  *    Function : sendRachIndMacToSch
69  *
70  *    Functionality:
71  *     Sends RACH indication to SCH
72  *
73  * @params[in] RACH indication info
74  * @return ROK     - success
75  *         RFAILED - failure
76  *
77  * ****************************************************************/
78 int sendRachIndMacToSch(RachIndInfo *rachInd)
79 {
80    Pst pst;
81     
82    fillMacToSchPst(&pst);
83    pst.event = EVENT_RACH_IND_TO_SCH;
84     
85    return(*macSchRachIndOpts[pst.selector])(&pst, rachInd); 
86 }
87
88 /*******************************************************************
89  *
90  * @brief Sends CRC Indication to SCH
91  *
92  * @details
93  *
94  *    Function : sendCrcIndMacToSch 
95  *
96  *    Functionality:
97  *       Sends CRC Indication to SCH
98  *
99  * @params[in] 
100  * @return ROK     - success
101  *         RFAILED - failure
102  *
103  * ****************************************************************/
104 int sendCrcIndMacToSch(CrcIndInfo *crcInd)
105 {
106    Pst pst;
107   
108    fillMacToSchPst(&pst);
109    pst.event = EVENT_CRC_IND_TO_SCH;
110  
111    return(*macSchCrcIndOpts[pst.selector])(&pst, crcInd);
112 }
113
114  
115 /*******************************************************************
116  *
117  * @brief Processes RACH indication from PHY
118  *
119  * @details
120  *
121  *    Function : fapiMacRachInd
122  *
123  *    Functionality:
124  *      Processes RACH indication from PHY
125  *
126  * @params[in] Post structure
127  *             Rach indication message
128  * @return ROK     - success
129  *         RFAILED - failure
130  *
131  * ****************************************************************/ 
132 uint16_t fapiMacRachInd(Pst *pst, RachInd *rachInd)
133 {
134    uint8_t      pduIdx;
135    uint8_t      preambleIdx;
136    RachIndInfo  *rachIndInfo;
137
138    DU_LOG("\nMAC : Received RACH indication");
139    /* Considering one pdu and one preamble */
140    pduIdx = 0;
141    preambleIdx = 0;
142
143    rachIndInfo = &macCb.macCell->raCb;
144
145    rachIndInfo->cellId = rachInd->rachPdu[pduIdx].pci;
146    /* TODO : Allocate unique crnti for each ue */
147    rachIndInfo->crnti = 100;
148    rachIndInfo->timingInfo.sfn = rachInd->timingInfo.sfn;
149    rachIndInfo->timingInfo.slot = rachInd->timingInfo.slot;
150    rachIndInfo->slotIdx = rachInd->rachPdu[pduIdx].slotIdx;
151    rachIndInfo->symbolIdx = rachInd->rachPdu[pduIdx].symbolIdx;
152    rachIndInfo->freqIdx = rachInd->rachPdu[pduIdx].freqIdx;
153    rachIndInfo->preambleIdx = \
154       rachInd->rachPdu[pduIdx].preamInfo[preambleIdx].preamIdx;
155    rachIndInfo->timingAdv = \
156       rachInd->rachPdu[pduIdx].preamInfo[preambleIdx].timingAdv;
157
158    return(sendRachIndMacToSch(rachIndInfo));
159 }
160
161 /*******************************************************************
162  *
163  * @brief Processes CRC Indication from PHY
164  *
165  * @details
166  *
167  *    Function : fapiMacCrcInd
168  *
169  *    Functionality:
170  *       Processes CRC Indication from PHY
171  *
172  * @params[in] Post Structure Pointer
173  *             Crc Indication Pointer
174  * @return ROK     - success
175  *         RFAILED - failure
176  *
177  * ****************************************************************/
178 uint16_t fapiMacCrcInd(Pst *pst, CrcInd *crcInd)
179 {
180    CrcIndInfo   crcIndInfo;
181
182    DU_LOG("\nMAC : Received CRC indication");
183    /* Considering one pdu and one preamble */
184    
185    crcIndInfo.cellId = macCb.macCell->cellId;;
186    crcIndInfo.crnti = crcInd->crcInfo[0].rnti;
187    crcIndInfo.timingInfo.sfn = crcInd->timingInfo.sfn;
188    crcIndInfo.timingInfo.slot = crcInd->timingInfo.slot;
189    crcIndInfo.numCrcInd = crcInd->crcInfo[0].numCb;
190    crcIndInfo.crcInd[0] = crcInd->crcInfo[0].cbCrcStatus[0];
191    
192    return(sendCrcIndMacToSch(&crcIndInfo));
193 }
194
195  
196 /* spec-38.211 Table 6.3.3.1-7 */
197 uint8_t UnrestrictedSetNcsTable[MAX_ZERO_CORR_CFG_IDX] = 
198 {0, 2, 4, 6, 8, 10, 12, 13, 15, 17, 19, 23, 27, 34, 46, 69};
199
200 int MacProcUlSchInfo(Pst *pst, UlSchInfo *ulSchInfo)
201 {
202    if(ulSchInfo != NULLP)
203         {
204       MacUlSlot *currUlSlot = 
205            &macCb.macCell->ulSlot[ulSchInfo->slotIndInfo.slot % MAX_SLOT_SUPPORTED];
206       memcpy(&currUlSlot->ulCellInfo, ulSchInfo, sizeof(UlSchInfo)); 
207    }
208    return ROK;
209 }
210
211 /*******************************************************************
212  *
213  * @brief Process Rx Data Ind at MAC
214  *
215  * @details
216  *
217  *    Function : fapiMacRxDataInd
218  *
219  *    Functionality:
220  *       Process Rx Data Ind at MAC
221  *
222  * @params[in] Post structure
223  *             Rx Data Indication
224  * @return ROK     - success
225  *         RFAILED - failure
226  *
227  * ****************************************************************/
228 uint16_t fapiMacRxDataInd(Pst *pst, RxDataInd *rxDataInd)
229 {
230    DU_LOG("\nMAC : Received Rx Data indication");
231    /* TODO : Demuxing */
232    return ROK;
233 }
234
235
236 /**********************************************************************
237   End of file
238  **********************************************************************/
239