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