1b621bf020f5e4dc49c5debcd952f55ceef6a82c
[o-du/l2.git] / src / 5gnrrlc / mac_stub.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 #ifdef EGTP_TEST
20
21 #include "mac_stub.h"
22
23 uint8_t rlcDatSn = 0;
24 uint64_t ulDatNum = 0;
25
26 PUBLIC S16 macStubBOStatus(Pst *pst, SpId spId, RlcMacBOStatus *boSta)
27 {
28   Pst rspPst;
29   RlcMacSchedRepInfo *schRep;
30
31   DU_LOG("\nMAC : Received BO status from RLC");
32
33 //  SGetSBuf(pst->region, pst->pool, (Data **)&rspPst, sizeof(Pst));
34
35   rspPst.selector  = RGU_SEL_TC;
36   rspPst.srcEnt    = pst->dstEnt;
37   rspPst.dstEnt    = pst->srcEnt;
38   rspPst.dstInst   = pst->srcInst;
39   rspPst.dstProcId = pst->srcProcId;
40   rspPst.srcProcId = pst->dstProcId;
41   rspPst.region    = pst->region; 
42   rspPst.pool    = pst->pool;
43
44   /* Filling Scheduling Report */
45   KW_SHRABL_STATIC_BUF_ALLOC(pst->region, pst->pool, schRep, sizeof(RlcMacSchedRepInfo));
46    
47   schRep->cellId = boSta->cellId;
48   schRep->rnti   = boSta->rnti;
49   schRep->nmbLch = 1;
50   schRep->lchSta[0].commCh = boSta->commCh;
51   schRep->lchSta[0].lchStaInd.lcId = boSta->lcId;
52   schRep->lchSta[0].lchStaInd.totBufSize = boSta->bo + 5; /* Extra buffer space including RLC and MAC Header size */
53
54   DU_LOG("\nMAC : Sending scheduling report to RLC");
55   
56   RlcMacProcSchedRep(&rspPst, 1, schRep);
57
58   return ROK;
59
60 }
61
62 PUBLIC S16 macStubSendDlData(Pst *pst, SpId spId, RlcMacData *dlData)
63 {
64    U32 availmem;
65
66    Pst rspPst;
67    Buffer *mBuf;
68    RlcMacData *ulData;
69
70    DU_LOG("\nMAC_STUB : Received DL data from RLC to be sent to PHY"); 
71
72    SPutMsg(dlData->pduInfo[0].pduBuf);
73    dlData->pduInfo[0].pduBuf = NULL;
74
75 #if 0
76    KW_FREE_SHRABL_BUF(pst->region, pst->pool,
77                         dlData, sizeof(RlcMacData));
78 {
79    KW_ALLOC_SHRABL_BUF(pst->region, pst->pool,
80                           ulData, sizeof(RlcMacData));
81
82    SRegInfoShow(2, &availmem);
83    cmMemcpy((U8 *)ulData, (U8 *)dlData, sizeof(RlcMacData));
84 #endif
85    
86    ulData = dlData;
87    SGetMsg(pst->region, pst->pool, &mBuf);
88    macStubBuildUlData(mBuf);
89    ulData->pduInfo[0].pduBuf = mBuf;
90
91    /* Fill response post */
92    rspPst.selector  = RGU_SEL_TC;
93    rspPst.srcEnt    = pst->dstEnt;
94    rspPst.dstEnt    = pst->srcEnt;
95    rspPst.dstInst   = pst->srcInst;
96    rspPst.dstProcId = pst->srcProcId;
97    rspPst.srcProcId = pst->dstProcId;
98    rspPst.region    = pst->region;
99    rspPst.pool      = pst->pool;
100
101    ulDatNum++;
102    DU_LOG("\nMAC_STUB : UL data number %d", ulDatNum);
103    RlcMacProcUlData(&rspPst, 1, ulData);
104    return ROK;
105 }
106
107 void macStubBuildUlData(Buffer *mBuf)
108 {
109    char data[30] = "This is EGTP data from DU";
110    int datSize = 30;
111    U32 availmem;
112
113    SAddPstMsgMult((Data *)data, datSize, mBuf);
114
115    /* filling IPv4 header */
116    CmIpv4Hdr ipv4Hdr;
117    MsgLen    mLen;
118    U32 ipv4_du, ipv4_cu;
119    
120    cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du);
121    cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
122
123    mLen = 0;
124    SFndLenMsg(mBuf, &mLen);
125  
126    cmMemset((U8 *)&ipv4Hdr, 0, sizeof(CmIpv4Hdr));
127    ipv4Hdr.length = CM_IPV4_HDRLEN + mLen;
128    ipv4Hdr.hdrVer = 0x45;
129    ipv4Hdr.proto = 1;
130    ipv4Hdr.srcAddr = CM_INET_NTOH_U32(ipv4_du);
131    ipv4Hdr.destAddr = CM_INET_NTOH_U32(ipv4_cu);
132   
133    /* Packing IPv4 header into buffer */
134    S16          ret, cnt, idx;
135    Data         revPkArray[CM_IPV4_HDRLEN];
136    Data         pkArray[CM_IPV4_HDRLEN];
137   
138    /* initialize locals */
139    cnt = 0;
140    cmMemset(revPkArray, 0, CM_IPV4_HDRLEN);
141    cmMemset(pkArray, 0, CM_IPV4_HDRLEN);
142  
143    /* Pack Header Version */
144    pkArray[cnt++] = ipv4Hdr.hdrVer;
145   
146    /* Pack TOS */
147    pkArray[cnt++] = ipv4Hdr.tos;
148   
149    pkArray[cnt++] = (Data)GetHiByte(ipv4Hdr.length);
150    pkArray[cnt++] = (Data)GetLoByte(ipv4Hdr.length);
151     
152    /* Pack Id */
153    pkArray[cnt++] = (Data) GetHiByte(ipv4Hdr.id);
154    pkArray[cnt++] = (Data) GetLoByte(ipv4Hdr.id);
155     
156    /* Pack Offset */
157    pkArray[cnt++] = (Data)GetHiByte(ipv4Hdr.off);
158    pkArray[cnt++] = (Data)GetLoByte(ipv4Hdr.off);
159    
160    /* Pack TTL */
161    pkArray[cnt++] = ipv4Hdr.ttl;
162     
163    /* Pack Protocol */
164    pkArray[cnt++] = ipv4Hdr.proto;
165     
166    /* Pack Checksum */
167    pkArray[cnt++] = (Data)GetHiByte(ipv4Hdr.chkSum);
168    pkArray[cnt++] = (Data)GetLoByte(ipv4Hdr.chkSum);
169     
170    /* Pack Source Address */
171    pkArray[cnt++] = (Data)GetHiByte(GetHiWord(ipv4Hdr.srcAddr));
172    pkArray[cnt++] = (Data)GetLoByte(GetHiWord(ipv4Hdr.srcAddr));
173    pkArray[cnt++] = (Data)GetHiByte(GetLoWord(ipv4Hdr.srcAddr));
174    pkArray[cnt++] = (Data)GetLoByte(GetLoWord(ipv4Hdr.srcAddr));
175     
176    /* Pack Destination Address */
177    pkArray[cnt++] = (Data)GetHiByte(GetHiWord(ipv4Hdr.destAddr));
178    pkArray[cnt++] = (Data)GetLoByte(GetHiWord(ipv4Hdr.destAddr));
179    pkArray[cnt++] = (Data)GetHiByte(GetLoWord(ipv4Hdr.destAddr));
180    pkArray[cnt++] = (Data)GetLoByte(GetLoWord(ipv4Hdr.destAddr));
181     
182    for (idx = 0;  idx < CM_IPV4_HDRLEN;  idx++)
183         revPkArray[idx] = pkArray[CM_IPV4_HDRLEN - idx -1];
184     
185    /* this function automatically reverses revPkArray */
186    ret = SAddPreMsgMult(revPkArray, (MsgLen)cnt, mBuf);
187
188    SAddPreMsgMult((Data *)&rlcDatSn, sizeof(uint8_t), mBuf);
189 #if 0
190    SRegInfoShow(0, &availmem);
191    SRegInfoShow(1, &availmem);
192    SRegInfoShow(2, &availmem);
193    SRegInfoShow(3, &availmem);
194    SRegInfoShow(4, &availmem);
195 #endif
196    //rlcDatSn++;
197    //
198    if(rlcDatSn++ >15 )
199       rlcDatSn = 0;
200
201 } /* macStubBuildUlData */
202
203 #endif /* EGTP_TEST */
204
205 /**********************************************************************
206          End of file
207 **********************************************************************/