Merge "SIB1 optional parameters, Cell start request, stop request and slot indication"
[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 uint16_t 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          RETVALUE(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       RETVALUE(SPstTsk(pst,mBuf));
77    } 
78 }
79
80 /**************************************************************************
81  * @brief Function to pack Loose Coupled 
82  *        MAC cell config parameters required by MAC
83  *
84  * @details
85  *
86  *      Function : unpackDuMacCellCfg
87  *
88  *      Functionality:
89  *           packs the macCellCfg parameters
90  *
91  * @param[in] DuMacCellCfgReq func; function pointer
92  * @param[in] Pst     *pst, Post structure of the primitive.
93  * @param[in] Buffer *mBuf
94  * @return ROK     - success
95  *         RFAILED - failure
96  *
97  ***************************************************************************/
98 void unpackDuMacCellCfg(
99    DuMacCellCfgReq func,
100    Pst *pst,
101    Buffer *mBuf)
102 {
103    U16 ret = ROK;
104    MacCellCfg *macCellCfg;
105
106    if(pst->selector == DU_SELECTOR_LWLC)
107    {
108       /* unpack the address of the structure */
109       CMCHKUNPK(cmUnpkPtr, (PTR *)&macCellCfg, mBuf);
110       ret = (*func)(pst, macCellCfg);
111    }
112    else
113    {
114       /* only LWLC is implemented now */
115       ret = ROK;
116    }
117  
118    return ret;
119 }
120
121 /**************************************************************************
122  * @brief Function to pack Loose Coupled 
123  *        MAC cell config confirm message
124  *
125  * @details
126  *
127  *      Function : packMacCellCfgCfm
128  *
129  *      Functionality:
130  *           packs the transaction ID  
131  *
132  * @param[in] Pst     *pst, Post structure of the primitive.
133  * @param[in] MacCellCfgCfm  *macCellCfgCfm, mac cell config confirm.
134  * @return ROK     - success
135  *         RFAILED - failure
136  *
137  ***************************************************************************/
138 uint16_t packMacCellCfgCfm(Pst *pst, MacCellCfgCfm *macCellCfgCfm)
139 {
140    if(pst->selector == DU_SELECTOR_LC)
141    {
142       Buffer *mBuf = NULLP;
143       if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK) 
144       {
145          RETVALUE(RFAILED);
146       }
147
148       /* pack the transaction ID in CNF structure */
149                 CMCHKPK(SPkU8, macCellCfgCfm->rsp, mBuf);
150       CMCHKPK(SPkU16, macCellCfgCfm->transId, mBuf);
151
152       RETVALUE(SPstTsk(pst,mBuf));
153    }
154    else if(pst->selector == DU_SELECTOR_LWLC)
155    {
156       /* only LC is supported */
157       return RFAILED;
158    }
159    return ROK;
160 }
161
162 /**************************************************************************
163  * @brief Function to pack MAC cell config confirm message
164  *
165  * @details
166  *
167  *      Function : unpackMacCellCfgCfm
168  *
169  *      Functionality:
170  *           packs the transaction ID  
171  *
172  * @param[in] DuMacCellCfgCfm func; function pointer
173  * @param[in] Pst     *pst, Post structure of the primitive.
174  * @param[in] Buffer *mBuf
175  * @return ROK     - success
176  *         RFAILED - failure
177  *
178  ***************************************************************************/
179 uint16_t unpackMacCellCfgCfm(
180    DuMacCellCfgCfm func, 
181    Pst *pst,
182    Buffer *mBuf)
183 {
184    MacCellCfgCfm macCellCfgCfm;
185
186    if(pst->selector == DU_SELECTOR_LC)
187    {
188       /* unpack the transaction ID in CNF structure */
189       CMCHKUNPK(SUnpkU16, &(macCellCfgCfm.transId), mBuf);
190       CMCHKUNPK(SUnpkU8, &(macCellCfgCfm.rsp), mBuf);
191
192       RETVALUE((*func)(&macCellCfgCfm));
193    }
194    else
195    {
196       /* only loose coupling is suported */
197    }
198 }
199
200 /*******************************************************************
201  *
202  * @brief Packs and Send Cell Start Request to MAC
203  *
204  * @details
205  *
206  *    Function : packMacCellStartReq
207  *
208  *    Functionality:
209  *      Packs and Sends Cell Start Request to MAC
210  *
211  * @params[in] Post structure pointer
212  *             MacCellStartInfo pointer
213  * @return ROK     - success
214  *         RFAILED - failure
215  *
216  * ****************************************************************/
217 uint16_t packMacCellStartReq(Pst *pst, MacCellStartInfo  *cellStartInfo)
218 {
219    if(pst->selector == DU_SELECTOR_LC)
220    {
221       /* Loose coupling not supported */
222       return RFAILED;
223    }
224    else if(pst->selector == DU_SELECTOR_LWLC)
225    {
226       Buffer *mBuf = NULLP;
227
228       if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
229       {
230          DU_LOG("\nDU APP : Memory allocation failed for cell start req pack");
231          RETVALUE(RFAILED);
232       }
233
234       /* pack the address of the structure */
235       CMCHKPK(cmPkPtr,(PTR)cellStartInfo, mBuf);
236
237       return SPstTsk(pst,mBuf);
238    }
239    return ROK;
240 }
241
242 /*******************************************************************
243  *
244  * @brief Unpacks MAC Cell Start Request from DU APP
245  *
246  * @details
247  *
248  *    Function : unpackMaCellStartReq
249  *
250  *    Functionality:
251  *      Unpacks MAC Cell Start Request from DU APP
252  *
253  * @params[in] Function pointer of cell start request handler
254  *             Post structure pointer
255  *             Cell Start Request Info Pointer
256  * @return ROK     - success
257  *         RFAILED - failure
258  *
259  * ****************************************************************/
260 uint16_t unpackMacCellStartReq(DuMacCellStartReq func, Pst *pst, Buffer *mBuf)
261 {
262    MacCellStartInfo  *cellStartInfo;
263  
264    if(pst->selector == DU_SELECTOR_LWLC)
265    {
266       /* unpack the address of the structure */
267       CMCHKUNPK(cmUnpkPtr, (PTR *)&cellStartInfo, mBuf);
268       SPutMsg(mBuf); 
269       return (*func)(pst, cellStartInfo);
270    }
271    else
272    {
273       /* Nothing to do for loose coupling */
274       SPutMsg(mBuf);
275       return ROK;
276    }
277 }
278
279 /*******************************************************************
280  *
281  * @brief Packs and Send cell stop request to MAC
282  *
283  * @details
284  *
285  *    Function : packMacCellStopReq
286  *
287  *    Functionality:
288  *       Packs and Send cell stop request to MAC
289  *
290  * @params[in] Post structure pointer
291  *             Cell stop info structure 
292  * @return ROK     - success
293  *         RFAILED - failure
294  *
295  * ****************************************************************/
296 uint16_t packMacCellStopReq(Pst *pst, MacCellStopInfo  *cellStopInfo)
297 {
298    if(pst->selector == DU_SELECTOR_LC)
299    {
300       /* Loose coupling not supported */
301       return RFAILED;
302    }
303    else if(pst->selector == DU_SELECTOR_LWLC)
304    {
305       Buffer *mBuf = NULLP;
306  
307       if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
308       {
309          DU_LOG("\nDU APP : Memory allocation failed for cell stop req pack");
310          RETVALUE(RFAILED);
311       }
312  
313       /* pack the address of the structure */
314       CMCHKPK(cmPkPtr,(PTR)cellStopInfo, mBuf);
315
316       return SPstTsk(pst,mBuf);
317    }
318    return ROK;
319 }
320
321 /*******************************************************************
322  *
323  * @brief Unpacks cell stop request from DU APP 
324  *
325  * @details
326  *
327  *    Function : unpackMaCellStopReq 
328  *
329  *    Functionality:
330  *       Unpacks cell stop request from DU APP 
331  *
332  * @params[in] Handler function pointer
333  *             Post structure pointer
334  *             Message Buffer
335  * @return ROK     - success
336  *         RFAILED - failure
337  *
338  * ****************************************************************/
339 uint16_t unpackMacCellStopReq(DuMacCellStopReq func, Pst *pst, Buffer *mBuf)
340 {
341    MacCellStopInfo  *cellStopInfo;
342   
343    if(pst->selector == DU_SELECTOR_LWLC)
344    {
345       /* unpack the address of the structure */
346       CMCHKUNPK(cmUnpkPtr, (PTR *)&cellStopInfo, mBuf);
347       SPutMsg(mBuf);
348       return (*func)(pst, cellStopInfo);
349    }
350    else
351    {
352       /* Nothing to do for loose coupling */
353       SPutMsg(mBuf);
354       return ROK;
355    }
356 }
357
358 /*******************************************************************
359  *
360  * @brief Packs and Sends slot ind from MAC to DUAPP
361  *
362  * @details
363  *
364  *    Function : packMacSlotInd
365  *
366  *    Functionality:
367  *       Packs and Sends slot ind from MAC to DUAPP
368  *
369  * @params[in] Post structure pointer
370  *             Slot Info pointer              
371  * @return ROK     - success
372  *         RFAILED - failure
373  *
374  * ****************************************************************/
375 uint16_t packMacSlotInd(Pst *pst, SlotInfo *slotInfo )
376 {
377    if(pst->selector == DU_SELECTOR_LC || pst->selector == DU_SELECTOR_TC)
378    {
379       /* Loose coupling not supported */
380       DU_LOG("\nDU APP : Only LWLC supported");
381       return RFAILED;
382    }
383    else if(pst->selector == DU_SELECTOR_LWLC)
384    {
385       Buffer *mBuf = NULLP;
386
387       if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
388       {
389          DU_LOG("\nDU APP : Memory allocation failed for cell start req pack");
390          RETVALUE(RFAILED);
391       }
392  
393       /* pack the address of the structure */
394       CMCHKPK(cmPkPtr,(PTR)slotInfo, mBuf);
395
396       return SPstTsk(pst,mBuf);
397    }
398    return ROK;
399 }
400
401 /*******************************************************************
402  *
403  * @brief Unpacks slot indication from MAC
404  *
405  * @details
406  *
407  *    Function : unpackMacSlotInd
408  *
409  *    Functionality:
410  *         Unpacks slot indication from MAC
411  *
412  * @params[in] Pointer to Handler
413  *             Post structure pointer
414  *             Message Buffer
415  * @return ROK     - success
416  *         RFAILED - failure
417  *
418  * ****************************************************************/
419 uint16_t unpackMacSlotInd(DuMacSlotInd func, Pst *pst, Buffer *mBuf)
420 {
421    SlotInfo *slotInfo;
422   
423    if(pst->selector == DU_SELECTOR_LWLC)
424    {
425       /* unpack the address of the structure */
426       CMCHKUNPK(cmUnpkPtr, (PTR *)&slotInfo, mBuf);
427       SPutMsg(mBuf);
428       return (*func)(pst, slotInfo);
429    }
430    else
431    {
432       /* Nothing to do for loose coupling */
433       SPutMsg(mBuf);
434       return ROK;
435    }
436    return ROK;
437 }
438
439 /**********************************************************************
440          End of file
441 **********************************************************************/