Slot indication from MAC to DU APP : LWLC fix and LC
[o-du/l2.git] / src / cm / du_app_mac_inf.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 #include "envopt.h"        /* Environment options */
20 #include "envdep.h"        /* Environment dependent */
21 #include "envind.h"        /* Environment independent */
22 #include "gen.h"           /* General */
23 #include "ssi.h"           /* System services */
24 #include "ss_queue.h"
25 #include "ss_task.h"
26 #include "ss_msg.h"
27
28 #include "gen.x"           /* general */
29 #include "ssi.x"           /* system services */
30 #include "cm_tkns.x"       /* Common Token Definitions */
31 #include "cm_llist.x"      /* Common Link List Definitions */
32 #include "cm_lib.x"        /* Common Library Definitions */
33 #include "cm_hash.x"       /* Common Hash List Definitions */
34 #include "cm_lte.x"        /* Common LTE Defines */
35
36 #include "du_cfg.h"
37 #include "du_app_mac_inf.h"
38
39 /**************************************************************************
40  * @brief Function to pack Loose Coupled 
41  *        MAC cell config parameters required by MAC
42  *
43  * @details
44  *
45  *      Function : packMacCellCfg
46  *
47  *      Functionality:
48  *           packs the macCellCfg parameters
49  *
50  * @param[in] Pst     *pst, Post structure of the primitive.
51  * @param[in] MacCellCfg  *macCellCfg, mac cell config parameters.
52  * @return ROK     - success
53  *         RFAILED - failure
54  *
55  ***************************************************************************/
56 int  packMacCellCfg(Pst *pst, MacCellCfg *macCellCfg)
57 {
58    if(pst->selector == DU_SELECTOR_LC)
59    {
60       /* we are now implemented only light wieght lossely coupled interface */
61       return RFAILED;
62    }
63    else if(pst->selector == DU_SELECTOR_LWLC)
64    {
65       Buffer *mBuf = NULLP;
66
67       if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK) 
68       {
69          return RFAILED;
70       }
71
72       /* pack the address of the structure */
73       CMCHKPK(cmPkPtr,(PTR)macCellCfg, mBuf);
74
75       DU_LOG("\nDU-APP : MAC CELL config sent");
76       return SPstTsk(pst,mBuf);
77    } 
78    return ROK;
79 }
80
81 /**************************************************************************
82  * @brief Function to pack Loose Coupled 
83  *        MAC cell config parameters required by MAC
84  *
85  * @details
86  *
87  *      Function : unpackDuMacCellCfg
88  *
89  *      Functionality:
90  *           packs the macCellCfg parameters
91  *
92  * @param[in] DuMacCellCfgReq func; function pointer
93  * @param[in] Pst     *pst, Post structure of the primitive.
94  * @param[in] Buffer *mBuf
95  * @return ROK     - success
96  *         RFAILED - failure
97  *
98  ***************************************************************************/
99 int  unpackDuMacCellCfg(
100    DuMacCellCfgReq func,
101    Pst *pst,
102    Buffer *mBuf)
103 {
104    U16 ret = ROK;
105    MacCellCfg *macCellCfg;
106
107    if(pst->selector == DU_SELECTOR_LWLC)
108    {
109       /* unpack the address of the structure */
110       CMCHKUNPK(cmUnpkPtr, (PTR *)&macCellCfg, mBuf);
111       ret = (*func)(pst, macCellCfg);
112    }
113    else
114    {
115       /* only LWLC is implemented now */
116       ret = ROK;
117    }
118  
119    return ret;
120 }
121
122 /**************************************************************************
123  * @brief Function to pack Loose Coupled 
124  *        MAC cell config confirm message
125  *
126  * @details
127  *
128  *      Function : packMacCellCfgCfm
129  *
130  *      Functionality:
131  *           packs the transaction ID  
132  *
133  * @param[in] Pst     *pst, Post structure of the primitive.
134  * @param[in] MacCellCfgCfm  *macCellCfgCfm, mac cell config confirm.
135  * @return ROK     - success
136  *         RFAILED - failure
137  *
138  ***************************************************************************/
139 int  packMacCellCfgCfm(Pst *pst, MacCellCfgCfm *macCellCfgCfm)
140 {
141    if(pst->selector == DU_SELECTOR_LC)
142    {
143       Buffer *mBuf = NULLP;
144       if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK) 
145       {
146          return RFAILED;
147       }
148
149       /* pack the transaction ID in CNF structure */
150                 CMCHKPK(SPkU8, macCellCfgCfm->rsp, mBuf);
151       CMCHKPK(SPkU16, macCellCfgCfm->transId, mBuf);
152
153       return SPstTsk(pst,mBuf);
154    }
155    else if(pst->selector == DU_SELECTOR_LWLC)
156    {
157       /* only LC is supported */
158       return RFAILED;
159    }
160    return ROK;
161 }
162
163 /**************************************************************************
164  * @brief Function to pack MAC cell config confirm message
165  *
166  * @details
167  *
168  *      Function : unpackMacCellCfgCfm
169  *
170  *      Functionality:
171  *           packs the transaction ID  
172  *
173  * @param[in] DuMacCellCfgCfm func; function pointer
174  * @param[in] Pst     *pst, Post structure of the primitive.
175  * @param[in] Buffer *mBuf
176  * @return ROK     - success
177  *         RFAILED - failure
178  *
179  ***************************************************************************/
180 int unpackMacCellCfgCfm(
181    DuMacCellCfgCfm func, 
182    Pst *pst,
183    Buffer *mBuf)
184 {
185    MacCellCfgCfm macCellCfgCfm;
186
187    if(pst->selector == DU_SELECTOR_LC)
188    {
189       /* unpack the transaction ID in CNF structure */
190       CMCHKUNPK(SUnpkU16, &(macCellCfgCfm.transId), mBuf);
191       CMCHKUNPK(SUnpkU8, &(macCellCfgCfm.rsp), mBuf);
192
193       return (*func)(pst, &macCellCfgCfm);
194    }
195    else
196    {
197       /* only loose coupling is suported */
198                 return ROK;
199    }
200 }
201
202 /*******************************************************************
203  *
204  * @brief Packs and Send Cell Start Request to MAC
205  *
206  * @details
207  *
208  *    Function : packMacCellStartReq
209  *
210  *    Functionality:
211  *      Packs and Sends Cell Start Request to MAC
212  *
213  * @params[in] Post structure pointer
214  *             MacCellStartInfo pointer
215  * @return ROK     - success
216  *         RFAILED - failure
217  *
218  * ****************************************************************/
219 uint16_t packMacCellStartReq(Pst *pst, MacCellStartInfo  *cellStartInfo)
220 {
221    if(pst->selector == DU_SELECTOR_LC)
222    {
223       /* Loose coupling not supported */
224       return RFAILED;
225    }
226    else if(pst->selector == DU_SELECTOR_LWLC)
227    {
228       Buffer *mBuf = NULLP;
229
230       if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
231       {
232          DU_LOG("\nDU APP : Memory allocation failed for cell start req pack");
233          return RFAILED;
234       }
235
236       /* pack the address of the structure */
237       CMCHKPK(cmPkPtr,(PTR)cellStartInfo, mBuf);
238
239       return SPstTsk(pst,mBuf);
240    }
241    return ROK;
242 }
243
244 /*******************************************************************
245  *
246  * @brief Unpacks MAC Cell Start Request from DU APP
247  *
248  * @details
249  *
250  *    Function : unpackMaCellStartReq
251  *
252  *    Functionality:
253  *      Unpacks MAC Cell Start Request from DU APP
254  *
255  * @params[in] Function pointer of cell start request handler
256  *             Post structure pointer
257  *             Cell Start Request Info Pointer
258  * @return ROK     - success
259  *         RFAILED - failure
260  *
261  * ****************************************************************/
262 uint16_t unpackMacCellStartReq(DuMacCellStartReq func, Pst *pst, Buffer *mBuf)
263 {
264    MacCellStartInfo  *cellStartInfo;
265  
266    if(pst->selector == DU_SELECTOR_LWLC)
267    {
268       /* unpack the address of the structure */
269       CMCHKUNPK(cmUnpkPtr, (PTR *)&cellStartInfo, mBuf);
270       SPutMsg(mBuf); 
271       return (*func)(pst, cellStartInfo);
272    }
273    else
274    {
275       /* Nothing to do for loose coupling */
276       SPutMsg(mBuf);
277       return ROK;
278    }
279 }
280
281 /*******************************************************************
282  *
283  * @brief Packs and Send cell stop request to MAC
284  *
285  * @details
286  *
287  *    Function : packMacCellStopReq
288  *
289  *    Functionality:
290  *       Packs and Send cell stop request to MAC
291  *
292  * @params[in] Post structure pointer
293  *             Cell stop info structure 
294  * @return ROK     - success
295  *         RFAILED - failure
296  *
297  * ****************************************************************/
298 uint16_t packMacCellStopReq(Pst *pst, MacCellStopInfo  *cellStopInfo)
299 {
300    if(pst->selector == DU_SELECTOR_LC)
301    {
302       /* Loose coupling not supported */
303       return RFAILED;
304    }
305    else if(pst->selector == DU_SELECTOR_LWLC)
306    {
307       Buffer *mBuf = NULLP;
308  
309       if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
310       {
311          DU_LOG("\nDU APP : Memory allocation failed for cell stop req pack");
312          return RFAILED;
313       }
314  
315       /* pack the address of the structure */
316       CMCHKPK(cmPkPtr,(PTR)cellStopInfo, mBuf);
317
318       return SPstTsk(pst,mBuf);
319    }
320    return ROK;
321 }
322
323 /*******************************************************************
324  *
325  * @brief Unpacks cell stop request from DU APP 
326  *
327  * @details
328  *
329  *    Function : unpackMaCellStopReq 
330  *
331  *    Functionality:
332  *       Unpacks cell stop request from DU APP 
333  *
334  * @params[in] Handler function pointer
335  *             Post structure pointer
336  *             Message Buffer
337  * @return ROK     - success
338  *         RFAILED - failure
339  *
340  * ****************************************************************/
341 uint16_t unpackMacCellStopReq(DuMacCellStopReq func, Pst *pst, Buffer *mBuf)
342 {
343    MacCellStopInfo  *cellStopInfo;
344   
345    if(pst->selector == DU_SELECTOR_LWLC)
346    {
347       /* unpack the address of the structure */
348       CMCHKUNPK(cmUnpkPtr, (PTR *)&cellStopInfo, mBuf);
349       SPutMsg(mBuf);
350       return (*func)(pst, cellStopInfo);
351    }
352    else
353    {
354       /* Nothing to do for loose coupling */
355       SPutMsg(mBuf);
356       return ROK;
357    }
358 }
359
360 /*******************************************************************
361  *
362  * @brief Packs and Sends slot ind from MAC to DUAPP
363  *
364  * @details
365  *
366  *    Function : packMacSlotInd
367  *
368  *    Functionality:
369  *       Packs and Sends slot ind from MAC to DUAPP
370  *
371  * @params[in] Post structure pointer
372  *             Slot Info pointer              
373  * @return ROK     - success
374  *         RFAILED - failure
375  *
376  * ****************************************************************/
377 uint16_t packMacSlotInd(Pst *pst, SlotInfo *slotInfo )
378 {
379    Buffer *mBuf = NULLP;
380  
381    if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
382    {
383       DU_LOG("\nDU APP : Memory allocation failed for cell start req pack");
384       return RFAILED;
385    }
386  
387    if(pst->selector == DU_SELECTOR_LC)
388    {
389       CMCHKPK(SPkU16, slotInfo->cellId, mBuf);
390       CMCHKPK(SPkU16, slotInfo->sfn, mBuf);
391       CMCHKPK(SPkU16, slotInfo->slot, mBuf);
392
393                 SPutStaticBuffer(pst->region, pst->pool, slotInfo, sizeof(SlotInfo), 0);
394                 slotInfo = NULL;
395    }
396    else if(pst->selector == DU_SELECTOR_LWLC)
397    {
398       /* pack the address of the structure */
399       CMCHKPK(cmPkPtr,(PTR)slotInfo, mBuf);
400    }
401    else
402    {
403       SPutMsg(mBuf);
404    }
405
406    return SPstTsk(pst,mBuf);
407 }
408
409 /*******************************************************************
410  *
411  * @brief Unpacks slot indication from MAC
412  *
413  * @details
414  *
415  *    Function : unpackMacSlotInd
416  *
417  *    Functionality:
418  *         Unpacks slot indication from MAC
419  *
420  * @params[in] Pointer to Handler
421  *             Post structure pointer
422  *             Message Buffer
423  * @return ROK     - success
424  *         RFAILED - failure
425  *
426  * ****************************************************************/
427 uint16_t unpackMacSlotInd(DuMacSlotInd func, Pst *pst, Buffer *mBuf)
428 {
429    if(pst->selector == DU_SELECTOR_LWLC)
430    {
431       SlotInfo *slotInfo;
432
433       /* unpack the address of the structure */
434       CMCHKUNPK(cmUnpkPtr, (PTR *)&slotInfo, mBuf);
435       SPutMsg(mBuf);
436       return (*func)(pst, slotInfo);
437    }
438    else if(pst->selector == DU_SELECTOR_LC)
439    {
440       SlotInfo slotInfo;
441
442       CMCHKUNPK(SUnpkU16, &(slotInfo.slot), mBuf);
443       CMCHKUNPK(SUnpkU16, &(slotInfo.sfn), mBuf);
444       CMCHKUNPK(SUnpkU16, &(slotInfo.cellId), mBuf);
445
446       SPutMsg(mBuf);
447       return (*func)(pst, &slotInfo);
448
449    }
450    else
451    {
452       /* Nothing to do for loose coupling */
453       SPutMsg(mBuf);
454       return ROK;
455    }
456    return ROK;
457 }
458
459 /**********************************************************************
460          End of file
461 **********************************************************************/