363f0b956772e9dca5c7a6f4fc2103968099566c
[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 "common_def.h"
20 #include "lrg.h"
21 #include "lrg.x"
22 #include "du_app_mac_inf.h"
23 #include "mac_sch_interface.h"
24 #include "lwr_mac_upr_inf.h"
25 #include "mac.h"
26 #include "mac_utils.h"
27
28 /* Function pointer for sending rach ind from MAC to SCH */
29 MacSchRachIndFunc macSchRachIndOpts[]=
30 {
31    packMacSchRachInd,
32    MacSchRachInd,
33    packMacSchRachInd
34 };
35
36 /*******************************************************************
37  *
38  * @brief Sends RACH indication to SCH
39  *
40  * @details
41  *
42  *    Function : sendRachIndMacToSch
43  *
44  *    Functionality:
45  *     Sends RACH indication to SCH
46  *
47  * @params[in] RACH indication info
48  * @return ROK     - success
49  *         RFAILED - failure
50  *
51  * ****************************************************************/
52 uint8_t sendRachIndMacToSch(RachIndInfo *rachInd)
53 {
54    Pst pst;
55
56    FILL_PST_MAC_TO_SCH(pst, EVENT_RACH_IND_TO_SCH);
57    return(*macSchRachIndOpts[pst.selector])(&pst, rachInd); 
58 }
59
60 /*******************************************************************
61  *
62  * @brief Processes RACH indication from PHY
63  *
64  * @details
65  *
66  *    Function : fapiMacRachInd
67  *
68  *    Functionality:
69  *      Processes RACH indication from PHY
70  *
71  * @params[in] Post structure
72  *             Rach indication message
73  * @return ROK     - success
74  *         RFAILED - failure
75  *
76  * ****************************************************************/ 
77 uint8_t fapiMacRachInd(Pst *pst, RachInd *rachInd)
78 {
79    uint8_t      pduIdx;
80    uint8_t      preambleIdx;
81    RachIndInfo  *rachIndInfo;
82
83    DU_LOG("\nINFO  -->  MAC : Received RACH indication");
84    /* Considering one pdu and one preamble */
85    pduIdx = 0;
86    preambleIdx = 0;
87
88    MAC_ALLOC(rachIndInfo, sizeof(RachIndInfo));
89    if(!rachIndInfo)
90    {
91       DU_LOG("\nERROR  --> MAC : Memory allocation failure in fapiMacRachInd");
92       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rachInd, sizeof(RachInd));
93       return RFAILED;
94    }
95
96    rachIndInfo->cellId = rachInd->cellId;
97    rachIndInfo->timingInfo.sfn = rachInd->timingInfo.sfn;
98    rachIndInfo->timingInfo.slot = rachInd->timingInfo.slot;
99    rachIndInfo->slotIdx = rachInd->rachPdu[pduIdx].slotIdx;
100    rachIndInfo->symbolIdx = rachInd->rachPdu[pduIdx].symbolIdx;
101    rachIndInfo->freqIdx = rachInd->rachPdu[pduIdx].freqIdx;
102    rachIndInfo->preambleIdx = \
103       rachInd->rachPdu[pduIdx].preamInfo[preambleIdx].preamIdx;
104    rachIndInfo->timingAdv = \
105       rachInd->rachPdu[pduIdx].preamInfo[preambleIdx].timingAdv;
106
107    /* Store the value in macRaCb */
108    createMacRaCb(rachIndInfo);
109
110    /* Free sharable buffer used to send RACH Indication from lower MAC to MAC */
111    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rachInd, sizeof(RachInd));
112
113    /* Send RACH Indication to SCH */
114    return(sendRachIndMacToSch(rachIndInfo));
115 }
116
117 /* spec-38.211 Table 6.3.3.1-7 */
118 uint8_t UnrestrictedSetNcsTable[MAX_ZERO_CORR_CFG_IDX] = 
119 {0, 2, 4, 6, 8, 10, 12, 13, 15, 17, 19, 23, 27, 34, 46, 69};
120
121 /*******************************************************************
122  *
123  * @brief Processes UL scheduling info from SCH
124  *
125  * @details
126  *
127  *    Function : MacProcUlSchInfo
128  *
129  *    Functionality: Processes UL scheduling info from SCH
130  *
131  * @params[in] Post structure
132  *             UL scheduling info
133  * @return ROK     - success
134  *         RFAILED - failure
135  *
136  * ****************************************************************/
137 uint8_t MacProcUlSchInfo(Pst *pst, UlSchedInfo *ulSchedInfo)
138 {
139    uint16_t  cellIdx;
140
141 #ifdef CALL_FLOW_DEBUG_LOG
142    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_UL_SCH_INFO\n");
143 #endif
144
145    GET_CELL_IDX(ulSchedInfo->cellId, cellIdx);
146    if(ulSchedInfo != NULLP)
147    {
148       MacUlSlot *currUlSlot = 
149          &macCb.macCell[cellIdx]->ulSlot[ulSchedInfo->slotIndInfo.slot % MAX_SLOTS];
150       memcpy(&currUlSlot->ulInfo, ulSchedInfo, sizeof(UlSchedInfo)); 
151    }
152    return ROK;
153 }
154
155 /**********************************************************************
156   End of file
157  **********************************************************************/
158