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