UL data path changes at Phy stub, RLC UL UM and DU APP [Issue-ID: ODUHIGH-262]
[o-du/l2.git] / src / 5gnrmac / mac_demux.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 /* header include files -- defines (.h) */
20 #include "common_def.h"
21 #include "lrg.h"           /* Layer manager interface includes*/
22 #include "lrg.x"           /* layer management typedefs for MAC */
23 #include "du_app_mac_inf.h"
24 #include "mac_sch_interface.h"
25 #include "lwr_mac_upr_inf.h"
26 #include "mac.h"
27 #include "mac_utils.h"
28
29
30 /*******************************************************************
31  *
32  * @brief De-mux of MAC-Sub PDUs from Rx Data Ind Pdu
33  *
34  * @detail
35  *
36  *    Function : unpackRxData
37  *
38  *    Functionality:
39  *     De-mux of MAC-Sub PDUs from Rx Data Ind Pdu
40  *
41  * @params[in] Pointer to PDU received
42  *             PDU length
43  * @return ROK
44  *         RFAILED
45  *
46  * ****************************************************************/
47 uint8_t unpackRxData(uint16_t cellId, SlotIndInfo slotInfo, RxDataIndPdu *rxDataIndPdu)
48 {
49    uint8_t   ueIdx = 0;       /* Iterator for UE list */
50    uint8_t   lcId = 0;        /* LC ID of a sub pdu */
51    uint8_t   fBit = 0;        /* Value of F Bit in MAC sub-header */
52    uint8_t   idx = 0;         /* Iterator for received PDU */
53    uint16_t  length = 0;      /* Length of payload in a sub-PDU */ 
54    uint8_t   *pdu = NULLP;    /* Payload in sub-PDU */
55    uint16_t  pduLen = 0;      /* Length of undecoded PDU */
56    uint8_t   *rxDataPdu = NULLP;  /* Received PDU in Rx Data Ind */
57    uint16_t  cellIdx = 0;     /* Cell Index */
58    uint8_t   ret =ROK;
59
60    GET_CELL_IDX(cellId, cellIdx);
61    pduLen = rxDataIndPdu->pduLength;
62    rxDataPdu = rxDataIndPdu->pduData;
63    GET_UE_IDX(rxDataIndPdu->rnti, ueIdx);
64    ueIdx = ueIdx -1;
65
66    while(pduLen > 0)
67    {
68       /* MSB in 1st octet is Reserved bit. Hence not decoding it. 
69          2nd MSB in 1st octet is R/F bit depending upon type of payload */
70       fBit = (1 << 7) & rxDataPdu[idx];
71
72       /* LC id is the 6 LSB in 1st octet */
73       lcId = (~((~0) << 6)) & rxDataPdu[idx];
74
75       switch(lcId)
76       {
77          case MAC_LCID_CCCH :
78             {
79                pduLen--;
80
81                /* for UL CCCH,fixed length of MAC SDU */
82                length = 6;
83
84                /*  Allocating sharable memory to send ul ccch msg to du app*/
85                MAC_ALLOC_SHRABL_BUF(pdu, length);
86                if(!pdu)
87                {
88                   DU_LOG("\nERROR  -->  MAC : UL CCCH PDU memory allocation failed");
89                   return RFAILED;
90                }  
91                idx++;
92                memcpy(pdu, &rxDataPdu[idx], length);
93                pduLen -= length;
94                idx = idx + length;
95
96                /* store msg3 pdu in macRaCb for CRI value */
97                memcpy(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg3Pdu, pdu, length);
98
99                /* Send UL-CCCH Indication to DU APP */
100                ret = macProcUlCcchInd(macCb.macCell[cellIdx]->cellId, rxDataIndPdu->rnti, length, pdu);
101                break;
102             }
103
104          case MAC_LCID_MIN ... MAC_LCID_MAX :
105             {
106                DU_LOG("\nINFO   -->  MAC : PDU received for LC ID %d", lcId);
107                pduLen--;
108                idx++;
109
110                length = rxDataPdu[idx];
111                if(fBit)
112                {
113                   pduLen--;
114                   idx++;
115                   length = (length << 8) & rxDataPdu[idx];
116                }
117
118                /*  Copying the payload to send to RLC */
119                MAC_ALLOC_SHRABL_BUF(pdu, length);
120                if(!pdu)
121                {
122                   DU_LOG("\nERROR  -->  MAC : Memory allocation failed while demuxing Rx Data PDU");
123                   return RFAILED;
124                }
125                pduLen--;
126                idx++;
127                memcpy(pdu, &rxDataPdu[idx], length);
128                pduLen -= length;
129                idx = idx + length;
130
131                /* Delete RA cb once RRC setup complete received */
132                if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == rxDataIndPdu->rnti)
133                {
134                   MAC_FREE(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
135                      macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
136                   MAC_FREE(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, \
137                       macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize);
138                   memset(&macCb.macCell[cellIdx]->macRaCb[ueIdx], 0, sizeof(MacRaCbInfo));
139                }
140
141                /* Send UL Data to RLC */
142                ret = macProcUlData(cellId, rxDataIndPdu->rnti, slotInfo, lcId, length, pdu);
143
144                break;
145             }
146          case MAC_LCID_RESERVED_MIN ... MAC_LCID_RESERVED_MAX :
147             break;
148
149          case MAC_LCID_CCCH_48BIT :
150             break;
151
152          case MAC_LCID_BIT_RATE_QUERY :
153             break;
154
155          case MAC_LCID_MULT_PHR_FOUR_OCT :
156             break;
157
158          case MAC_LCID_CFG_GRANT_CFM :
159             break;
160
161          case MAC_LCID_MULT_PHR_ONE_OCT:
162             break;
163
164          case MAC_LCID_SINGLE_PHR :
165             break;
166
167          case MAC_LCID_CRNTI :
168             break;
169
170          case MAC_LCID_SHORT_TRUNC_BSR :
171             break;
172
173          case MAC_LCID_LONG_TRUNC_BSR :
174             break;
175
176          case MAC_LCID_SHORT_BSR :
177             {
178                uint8_t  lcgId         = 0;
179                uint8_t  bufferSizeIdx = 0;
180                uint8_t  crnti         = 0;
181                uint32_t bufferSize    = 0;
182
183                pduLen--;
184
185                idx++;
186                crnti = rxDataIndPdu->rnti;
187                /* 5 LSB bits in pdu represent buffer size */
188                bufferSizeIdx = (~((~0) << 5)) & rxDataPdu[idx];
189                /* first 3 MSB bits in pdu represent LCGID */
190                lcgId = (rxDataPdu[idx]) >> 5;
191                /* determine actual number of bytes requested */
192                bufferSize = shortBsrBytesTable[bufferSizeIdx];
193                ret = macProcShortBsr(macCb.macCell[cellIdx]->cellId, crnti, lcgId, bufferSize);
194                pduLen--;
195                idx++;
196         
197                break;
198             }
199
200          case MAC_LCID_LONG_BSR :
201             break;
202
203          case MAC_LCID_PADDING :
204             break;
205          
206          default:
207             {
208                DU_LOG("\nERROR  -->  MAC : Invalid LC Id %d", lcId);
209                return RFAILED;
210             }
211       } /* End of switch */
212
213       if(lcId == MAC_LCID_PADDING)
214       {
215          break;
216       }
217    } /* End of While */
218
219    return ret;
220 } /* End of unpackRxData */
221
222 /**********************************************************************
223   End of file
224  **********************************************************************/