RAR_message
[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
55 /*******************************************************************
56  *
57  * @brief Sends RACH indication to SCH
58  *
59  * @details
60  *
61  *    Function : sendRachIndMacToSch
62  *
63  *    Functionality:
64  *     Sends RACH indication to SCH
65  *
66  * @params[in] RACH indication info
67  * @return ROK     - success
68  *         RFAILED - failure
69  *
70  * ****************************************************************/
71 int sendRachIndMacToSch(RachIndInfo *rachInd)
72 {
73    Pst pst;
74     
75    fillMacToSchPst(&pst);
76    pst.event = EVENT_RACH_IND_TO_SCH;
77     
78    return(*macSchRachIndOpts[pst.selector])(&pst, rachInd); 
79 }
80  
81 /*******************************************************************
82  *
83  * @brief Processes RACH indication from PHY
84  *
85  * @details
86  *
87  *    Function : fapiMacRachInd
88  *
89  *    Functionality:
90  *      Processes RACH indication from PHY
91  *
92  * @params[in] Post structure
93  *             Rach indication message
94  * @return ROK     - success
95  *         RFAILED - failure
96  *
97  * ****************************************************************/ 
98 uint16_t fapiMacRachInd(Pst *pst, RachInd *rachInd)
99 {
100    uint8_t      pduIdx;
101    uint8_t      preambleIdx;
102    RachIndInfo  *rachIndInfo;
103
104    DU_LOG("\nMAC : Received RACH indication");
105    /* Considering one pdu and one preamble */
106    pduIdx = 0;
107    preambleIdx = 0;
108
109    rachIndInfo = &macCb.macCell->raCb;
110
111    rachIndInfo->cellId = rachInd->rachPdu[pduIdx].pci;
112    /* TODO : Allocate unique crnti for each ue */
113    rachIndInfo->crnti = 100;
114    rachIndInfo->timingInfo.sfn = rachInd->timingInfo.sfn;
115    rachIndInfo->timingInfo.slot = rachInd->timingInfo.slot;
116    rachIndInfo->slotIdx = rachInd->rachPdu[pduIdx].slotIdx;
117    rachIndInfo->symbolIdx = rachInd->rachPdu[pduIdx].symbolIdx;
118    rachIndInfo->freqIdx = rachInd->rachPdu[pduIdx].freqIdx;
119    rachIndInfo->preambleIdx = \
120       rachInd->rachPdu[pduIdx].preamInfo[preambleIdx].preamIdx;
121    rachIndInfo->timingAdv = \
122       rachInd->rachPdu[pduIdx].preamInfo[preambleIdx].timingAdv;
123
124    return(sendRachIndMacToSch(rachIndInfo));
125 }
126
127  
128 /* spec-38.211 Table 6.3.3.1-7 */
129 uint8_t UnrestrictedSetNcsTable[MAX_ZERO_CORR_CFG_IDX] = 
130 {0, 2, 4, 6, 8, 10, 12, 13, 15, 17, 19, 23, 27, 34, 46, 69};
131
132 int MacProcUlSchInfo(Pst *pst, UlSchInfo *ulSchInfo)
133 {
134    if(ulSchInfo != NULLP)
135         {
136       MacUlSlot *currUlSlot = 
137            &macCb.macCell->ulSlot[ulSchInfo->slotIndInfo.slot % MAX_SLOT_SUPPORTED];
138       memcpy(&currUlSlot->ulCellInfo, ulSchInfo, sizeof(UlSchInfo)); 
139    }
140    return ROK;
141 }
142
143 /**********************************************************************
144   End of file
145  **********************************************************************/
146