Merge "Cleanup of message sib1"
[o-du/l2.git] / src / 5gnrsch / sch_slot_ind.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
19 /************************************************************************
20
21 Name:     5G NR SCH layer
22
23 Type:     C source file
24
25 Desc:     C source code for Entry point fucntions for slot indications
26
27 File:     sch_slot_ind.c
28
29  **********************************************************************/
30
31 /** @file sch_slot_ind.c
32   @brief This module processes slot indications
33  */
34 #include "stdbool.h"
35 #include "envopt.h"        /* environment options */
36 #include "envdep.h"        /* environment dependent */
37 #include "envind.h"        /* environment independent */
38 #include "gen.h"           /* general layer */
39 #include "ssi.h"           /* system service interface */
40 #include "cm_tkns.h"       /* Common Token Defines */
41 #include "cm_llist.h"      /* Common Link List Defines */
42 #include "cm_hash.h"       /* Common Hash List Defines */
43 #include "cm_mblk.h"       /* common memory link list library */
44 #include "cm_lte.h"        /* Common LTE Defines */
45 #include "tfu.h"
46 #include "lrg.h"
47
48 #include "gen.x"           /* general layer typedefs */
49 #include "ssi.x"           /* system services typedefs */
50 #include "cm5.x"           /* system services */
51 #include "cm_tkns.x"       /* Common Token Definitions */
52 #include "cm_llist.x"      /* Common Link List Definitions */
53 #include "cm_lib.x"        /* Common Library Definitions */
54 #include "cm_hash.x"       /* Common Hash List Definitions */
55 #include "cm_mblk.x"       /* common memory link list library */
56 #include "cm_lte.x"        /* Common LTE Defines */
57 #include "tfu.x"
58 #include "lrg.x"
59 #include "du_log.h"
60 #include "du_app_mac_inf.h"
61 #include "mac_sch_interface.h"
62 #include "sch.h"
63 #include "sch_utils.h"
64
65 SchMacDlAllocFunc schMacDlAllocOpts[] =
66 {
67         packSchMacDlAlloc,
68         MacProcDlAlloc,
69         packSchMacDlAlloc
70 };
71
72 extern SchCb schCb[SCH_MAX_INST];
73 extern int schFillRar(RarAlloc *rarAlloc, uint16_t raRnti, uint16_t pci, uint8_t
74 offsetPointA);
75
76 /*******************************************************************
77  *
78  * @brief Handles sending DL broadcast alloc to MAC 
79  *
80  * @details
81  *
82  *    Function : sendDlAllocToMac
83  *
84  *    Functionality:
85  *     Sends DL Broadcast Resource Allocation to MAC from SCH
86  *
87  * @params[in] 
88  * @return ROK     - success
89  *         RFAILED - failure
90  *
91  * ****************************************************************/
92 int sendDlAllocToMac(DlAlloc *dlAlloc, Inst inst)
93 {
94         Pst pst;
95
96    memset(&pst, 0, sizeof(Pst));
97    SCH_FILL_RSP_PST(pst, inst);
98         pst.event = EVENT_DL_ALLOC;
99
100         return(*schMacDlAllocOpts[pst.selector])(&pst, dlAlloc);
101
102 }
103
104 /*******************************************************************
105  *
106  * @brief Handles slot indication at SCH 
107  *
108  * @details
109  *
110  *    Function : schProcessSlotInd
111  *
112  *    Functionality:
113  *     Handles TTI indication received from PHY
114  *
115  * @params[in] 
116  * @return ROK     - success
117  *         RFAILED - failure
118  *
119  * ****************************************************************/
120 uint8_t schProcessSlotInd(SlotIndInfo *slotInd, Inst schInst)
121 {
122    int ret = ROK;
123         uint8_t ssb_rep;
124         uint16_t sfn  = slotInd->sfn;
125         uint16_t slot = slotInd->slot;
126         uint16_t sfnSlot = 0;
127         DlAlloc dlAlloc;
128         memset(&dlAlloc,0,sizeof(DlAlloc));
129    DlBrdcstAlloc *dlBrdcstAlloc = &dlAlloc.brdcstAlloc;
130         RarAlloc *rarAlloc = &dlAlloc.rarAlloc;
131    Msg4Alloc *msg4Alloc;
132         dlBrdcstAlloc->ssbTrans = NO_SSB;
133    dlBrdcstAlloc->sib1Trans = NO_SIB1;
134         
135
136         SchCellCb *cell = schCb[schInst].cells[schInst];
137
138 #ifdef LTE_L2_MEAS
139    glblTtiCnt++;
140 #endif
141   
142 //   schDlResAlloc(cell, slotInd);
143
144         ssb_rep = cell->cellCfg.ssbSchCfg.ssbPeriod;
145         memcpy(&cell->slotInfo, slotInd, sizeof(SlotIndInfo));
146         dlBrdcstAlloc->ssbIdxSupported = 1;
147
148    if((slot + SCHED_DELTA) >= SCH_NUM_SLOTS)
149         {
150       sfn = (sfn+1)%SCH_MAX_SFN;
151         }
152         slot = ((slot + SCHED_DELTA) % SCH_NUM_SLOTS);
153    sfnSlot = ((sfn * 10) + slot);
154
155         dlAlloc.slotIndInfo.sfn = sfn;
156         dlAlloc.slotIndInfo.slot = slot;
157         dlAlloc.cellId = cell->cellId;
158
159         /* Identify SSB ocassion*/
160         if (sfnSlot % SCH_MIB_TRANS == 0)
161         {
162                 dlBrdcstAlloc->ssbTrans = SSB_TRANSMISSION;
163         }
164         else if (sfnSlot % ssb_rep == 0)
165         {
166                 dlBrdcstAlloc->ssbTrans = SSB_REPEAT;
167         }
168         else
169         {
170            /* not SSB occassion */
171         }
172
173    /* Identify SIB1 occasions */
174    if(sfnSlot % cell->cellCfg.sib1SchCfg.sib1NewTxPeriod == 0)
175         {
176            dlBrdcstAlloc->sib1Trans = SIB1_TRANSMISSION;
177         }
178         else if (sfnSlot % cell->cellCfg.sib1SchCfg.sib1RepetitionPeriod == 0)
179         {
180            dlBrdcstAlloc->sib1Trans = SIB1_REPITITION;
181         }
182         else
183         {
184            /* not SIB1 occassion */
185         }
186
187         if(dlBrdcstAlloc->ssbTrans || dlBrdcstAlloc->sib1Trans)
188         {
189            dlAlloc.isBroadcastPres = true;
190            ret = schBroadcastAlloc(cell, dlBrdcstAlloc,slot);
191       if(ret != ROK)
192       {
193          DU_LOG("\nschBroadcastAlloc failed");
194          RETVALUE(ret);
195       }
196    }
197
198    /* check for RAR */
199         if(cell->dlAlloc[slot]->rarPres == true)
200         {
201            dlAlloc.isRarPres = true;
202            /* RAR info is copied, this was earlier filled in schProcessRachInd */
203            memcpy(&rarAlloc->rarInfo, &cell->dlAlloc[slot]->rarInfo, sizeof(RarInfo));
204
205                 /* pdcch and pdsch data is filled */
206       schFillRar(rarAlloc,
207                    cell->dlAlloc[slot]->rarInfo.raRnti,
208                    cell->cellCfg.phyCellId,
209                    cell->cellCfg.ssbSchCfg.ssbOffsetPointA);
210
211      cell->dlAlloc[slot]->rarPres = false;
212    }
213
214    /* check for MSG4 */
215    if(cell->dlAlloc[slot]->msg4Info)
216    {
217             SCH_ALLOC(msg4Alloc, sizeof(Msg4Alloc));
218                  if(!msg4Alloc)
219                  {
220                     DU_LOG("\nMAC: Memory Allocation failed for msg4 alloc");
221                          return RFAILED;
222                  }
223                  
224                  dlAlloc.msg4Alloc = msg4Alloc;
225
226        /* Msg4 info is copied, this was earlier filled in macSchDlRlcBoInfo */
227        memcpy(&msg4Alloc->msg4Info, cell->dlAlloc[slot]->msg4Info, \
228           sizeof(Msg4Info));
229              
230        /* pdcch and pdsch data is filled */
231        schDlRsrcAllocMsg4(msg4Alloc, cell, slot); 
232                  SCH_FREE(cell->dlAlloc[slot]->msg4Info, sizeof(Msg4Info));
233                  cell->dlAlloc[slot]->msg4Info = NULL;
234    }
235
236
237         /* send msg to MAC */
238    ret = sendDlAllocToMac(&dlAlloc, schInst);
239    if(ret != ROK)
240    {
241       DU_LOG("\nSending DL Broadcast allocation from SCH to MAC failed");
242       RETVALUE(ret);
243    }
244     
245         schUlResAlloc(cell, schInst);
246
247         return ret;
248 }
249
250 /**********************************************************************
251   End of file
252  **********************************************************************/
253
254