Moving all common header file into common_def.h file
[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 "tfu.h"           /* RGU Interface includes */
21 #include "lrg.h"
22
23 #include "tfu.x"           /* RGU Interface includes */
24 #include "lrg.x"
25 #include "du_app_mac_inf.h"
26 #include "mac.h"
27 #include "du_log.h"
28
29 /* Function pointer for sending rach ind from MAC to SCH */
30 MacSchRachIndFunc macSchRachIndOpts[]=
31 {
32    packMacSchRachInd,
33    macSchRachInd,
34    packMacSchRachInd
35 };
36
37 /*******************************************************************
38  *
39  * @brief Sends RACH indication to SCH
40  *
41  * @details
42  *
43  *    Function : sendRachIndMacToSch
44  *
45  *    Functionality:
46  *     Sends RACH indication to SCH
47  *
48  * @params[in] RACH indication info
49  * @return ROK     - success
50  *         RFAILED - failure
51  *
52  * ****************************************************************/
53 int sendRachIndMacToSch(RachIndInfo *rachInd)
54 {
55    Pst pst;
56     
57    fillMacToSchPst(&pst);
58    pst.event = EVENT_RACH_IND_TO_SCH;
59     
60    return(*macSchRachIndOpts[pst.selector])(&pst, rachInd); 
61 }
62
63 /*******************************************************************
64  *
65  * @brief Processes RACH indication from PHY
66  *
67  * @details
68  *
69  *    Function : fapiMacRachInd
70  *
71  *    Functionality:
72  *      Processes RACH indication from PHY
73  *
74  * @params[in] Post structure
75  *             Rach indication message
76  * @return ROK     - success
77  *         RFAILED - failure
78  *
79  * ****************************************************************/ 
80 uint16_t fapiMacRachInd(Pst *pst, RachInd *rachInd)
81 {
82    uint8_t      pduIdx;
83    uint8_t      preambleIdx;
84    RachIndInfo  rachIndInfo;
85
86    DU_LOG("\nMAC : Received RACH indication");
87    /* Considering one pdu and one preamble */
88    pduIdx = 0;
89    preambleIdx = 0;
90
91    rachIndInfo.cellId = rachInd->rachPdu[pduIdx].pci;
92    /* TODO : A.ocate unique crnti for each ue */
93    rachIndInfo.crnti = 100;
94    rachIndInfo.timingInfo.sfn = rachInd->timingInfo.sfn;
95    rachIndInfo.timingInfo.slot = rachInd->timingInfo.slot;
96    rachIndInfo.slotIdx = rachInd->rachPdu[pduIdx].slotIdx;
97    rachIndInfo.symbolIdx = rachInd->rachPdu[pduIdx].symbolIdx;
98    rachIndInfo.freqIdx = rachInd->rachPdu[pduIdx].freqIdx;
99    rachIndInfo.preambleIdx = \
100       rachInd->rachPdu[pduIdx].preamInfo[preambleIdx].preamIdx;
101    rachIndInfo.timingAdv = \
102       rachInd->rachPdu[pduIdx].preamInfo[preambleIdx].timingAdv;
103
104    /* storing the value in macRaCb */
105    createMacRaCb(rachIndInfo.cellId, rachIndInfo.crnti);
106
107    return(sendRachIndMacToSch(&rachIndInfo));
108 }
109
110 /* spec-38.211 Table 6.3.3.1-7 */
111 uint8_t UnrestrictedSetNcsTable[MAX_ZERO_CORR_CFG_IDX] = 
112 {0, 2, 4, 6, 8, 10, 12, 13, 15, 17, 19, 23, 27, 34, 46, 69};
113
114 int MacProcUlSchInfo(Pst *pst, UlSchedInfo *ulSchedInfo)
115 {
116    if(ulSchedInfo != NULLP)
117         {
118       MacUlSlot *currUlSlot = 
119            &macCb.macCell->ulSlot[ulSchedInfo->slotIndInfo.slot % MAX_SLOT_SUPPORTED];
120       memcpy(&currUlSlot->ulInfo, ulSchedInfo, sizeof(UlSchedInfo)); 
121    }
122    return ROK;
123 }
124
125 /**********************************************************************
126   End of file
127  **********************************************************************/
128