MAC Clean-up [Issue-ID: ODUHIGH-212]
[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  * @brief De-mux of MAC-Sub PDUs from Rx Data Ind Pdu
32  *
33  * @detail
34  *
35  *    Function : unpackRxData
36  *
37  *    Functionality:
38  *     De-mux of MAC-Sub PDUs from Rx Data Ind Pdu
39  *
40  * @params[in] Pointer to PDU received
41  *             PDU length
42  * @return ROK
43  *         RFAILED
44  *
45  * ****************************************************************/
46 uint8_t unpackRxData(uint16_t cellId, RxDataIndPdu *rxDataIndPdu)
47 {
48    uint8_t   lcId;
49    uint8_t   idx = 0;
50    uint16_t  length;
51    uint8_t   *pdu;
52    uint16_t  pduLen;
53    uint8_t   *rxDataPdu;
54    uint16_t  cellIdx;
55
56    GET_CELL_IDX(cellId, cellIdx);
57    pduLen = rxDataIndPdu->pduLength;
58    rxDataPdu = rxDataIndPdu->pduData;
59
60    while(pduLen > 0)
61    {
62       /* LC id is the 6 LSB in 1st octet */
63       lcId = (~((~0) << 6)) & rxDataPdu[idx];
64
65       switch(lcId)
66       {
67          case MAC_LCID_CCCH :
68             {
69                pduLen--;
70
71                /* for UL CCCH,fixed length of MAC SDU */
72                length = 6;
73
74                /*  Allocating sharable memory to send ul ccch msg to du app*/
75                MAC_ALLOC_SHRABL_BUF(pdu, length);
76                if(!pdu)
77                {
78                   DU_LOG("\nMAC : UL CCCH PDU memory allocation failed");
79                   return RFAILED;
80                }  
81                idx++;
82                memcpy(pdu, &rxDataPdu[idx], length);
83                pduLen -= length;
84                idx = idx + length;
85
86                /* store msg3 pdu in macRaCb for CRI value */
87                memcpy(macCb.macCell[cellIdx]->macRaCb[0].msg3Pdu, pdu, length);
88
89                /* Send UL-CCCH Indication to DU APP */
90                macSendUlCcchInd(pdu, macCb.macCell[cellIdx]->cellId, rxDataIndPdu->rnti); 
91                break;
92             }
93
94          case MAC_DEDLC_MIN_LCID ... MAC_DEDLC_MAX_LCID :
95             break;
96
97          case MAC_LCID_RESERVED_MIN ... MAC_LCID_RESERVED_MAX :
98             break;
99
100          case MAC_LCID_CCCH_48BIT :
101             break;
102
103          case MAC_LCID_BIT_RATE_QUERY :
104             break;
105
106          case MAC_LCID_MULT_PHR_FOUR_OCT :
107             break;
108
109          case MAC_LCID_CFG_GRANT_CFM :
110             break;
111
112          case MAC_LCID_MULT_PHR_ONE_OCT:
113             break;
114
115          case MAC_LCID_SINGLE_PHR :
116             break;
117
118          case MAC_LCID_CRNTI :
119             break;
120
121          case MAC_LCID_SHORT_TRUNC_BSR :
122             break;
123
124          case MAC_LCID_LONG_TRUNC_BSR :
125             break;
126
127          case MAC_LCID_SHORT_BSR :
128             break;
129
130          case MAC_LCID_LONG_BSR :
131             break;
132
133          case MAC_LCID_PADDING :
134             {
135                break;
136             }
137
138          default:
139             {
140                DU_LOG("\nMAC : Invalid LC Id %d", lcId);
141                return RFAILED;
142             }
143       } /* End of switch */
144
145       if(lcId == MAC_LCID_PADDING)
146          break;
147
148    } /* End of While */
149
150    return ROK;
151 } /* End of unpackRxData */
152
153 /**********************************************************************
154   End of file
155  **********************************************************************/