Configured cell list changes
[o-du/l2.git] / src / cu_stub / cu_f1ap_msg_hdl.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 /* This file contains F1AP message handler functions */
20
21 #include "cu_stub_sctp.h"
22 #include "cu_f1ap_msg_hdl.h"
23
24 char encBuf[ENC_BUF_MAX_LEN];
25
26 /*******************************************************************
27  *
28  * @brief Writes the encoded chunks into a buffer
29  *
30  * @details
31  *
32  *    Function : PrepFinalEncBuf 
33  *
34  *    Functionality:Fills the encoded buffer
35  *
36  * @params[in] void *buffer,initial encoded data
37  * @params[in] size_t size,size of buffer
38  * @params[in] void *encodedBuf,final buffer
39  * @return ROK     - success
40  *         RFAILED - failure
41  *
42  * ****************************************************************/
43 static int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf)
44 {
45    memcpy(encodedBuf + encBufSize, buffer, size);
46    encBufSize += size;
47    return 0;
48 } /* PrepFinalEncBuf */
49
50 /*******************************************************************
51 *
52 * @brief Sends F1 msg over SCTP
53 *
54 * @details
55 *
56 *    Function : SendF1APMsg
57 *
58 *    Functionality: Sends F1 msg over SCTP
59 *
60 * @params[in] Region region
61 *             Pool pool
62 * @return ROK     - success
63 *         RFAILED - failure
64 *
65 * ****************************************************************/
66 S16 SendF1APMsg(Region region, Pool pool)
67 {
68    Buffer *mBuf;
69
70    if(SGetMsg(region, pool, &mBuf) == ROK)
71    {
72       if(SAddPstMsgMult((Data *)encBuf, encBufSize, mBuf) == ROK)
73       {
74          SPrntMsg(mBuf, 0,0);
75  
76          if(sctpSend(mBuf) != ROK)
77          {
78             DU_LOG("\nF1AP : SCTP Send failed");
79             SPutMsg(mBuf);
80             RETVALUE(RFAILED);
81          }
82       }
83       else
84       {
85          DU_LOG("\nF1AP : SAddPstMsgMult failed");
86          SPutMsg(mBuf);
87          RETVALUE(RFAILED);
88       }
89       SPutMsg(mBuf);
90    }
91    else
92    {
93       DU_LOG("\nF1AP : Failed to allocate memory");
94       RETVALUE(RFAILED);
95    }
96  
97    RETVALUE(ROK);
98 } /* SendF1APMsg */
99
100
101 void plmnBuildCU(Plmn plmn, OCTET_STRING_t *octe)
102 {
103    U8 mncCnt;
104    mncCnt = 2;
105    octe->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
106    if(mncCnt == 2)
107    {
108       octe->buf[1]  = ((0xf0) | (plmn.mcc[2]));
109       octe->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
110    }
111    else
112    {
113       octe->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
114       octe->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
115    }
116 }
117
118 /*******************************************************************
119 *
120 * @brief Builds NRCell ID 
121 *
122 * @details
123 *
124 *    Function : BuildNrCellId
125 *
126 *    Functionality: Building the NR Cell ID
127 *
128 * @params[in] BIT_STRING_t *nrcell
129 * @return ROK     - success
130 *         RFAILED - failure
131 *
132 * ****************************************************************/
133  
134 S16 BuildNrCellId(BIT_STRING_t *nrcell)
135 {
136    U8 tmp;
137    for (tmp = 0 ; tmp < nrcell->size-1; tmp++)
138    {
139       nrcell->buf[tmp] = 0;
140    }
141    nrcell->buf[4]   = 16; 
142    nrcell->bits_unused = 4;
143    nrcell->size = 5 * sizeof(uint8_t);
144    RETVALUE(ROK);
145 }
146
147 /********************************************************************
148  *
149  * @brief Builds and sends the F1SetupResponse
150  *
151  * @details
152  *
153  *    Function : BuildAndSendF1SetupRsp
154  *
155  *    Functionality: Constructs the F1SetupResponse message and sends
156  *                   it back to the DU through SCTP.
157  *
158  * @params[in] void **buf,Buffer to which encoded pattern is written into
159  * @params[in] int *size,size of buffer
160  *
161  * @return ROK     - success
162  *         RFAILED - failure
163  *
164  * ****************************************************************/
165 S16 BuildAndSendF1SetupRsp()
166 {
167    U8    idx,idy;
168    U8    elementCnt,cellCnt;
169    F1AP_PDU_t         *f1apMsg = NULL;
170    F1SetupResponse_t  *f1SetupRsp;
171    GNB_CU_Name_t      *cuName;
172    Cells_to_be_Activated_List_t *cellToActivate;
173         RRC_Version_t      *rrcVer;
174         asn_enc_rval_t     encRetVal; 
175         DU_LOG("\nF1AP : Building F1 Setup Response\n");
176
177    /* Allocate the memory for F1SetupRequest_t */
178    CU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t)); 
179    if(f1apMsg == NULLP)
180    {
181       DU_LOG("\nF1AP : Memory allocation for F1AP-PDU failed");
182       RETVALUE(RFAILED);
183    }
184    f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
185
186    CU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
187    if(f1apMsg->choice.successfulOutcome == NULLP)
188    {
189       DU_LOG("\nF1AP : Memory allocation for F1AP-PDU failed");
190       CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
191       RETVALUE(RFAILED);  
192    }
193
194    f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_F1Setup;
195    f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
196    f1apMsg->choice.successfulOutcome->value.present = \
197          SuccessfulOutcome__value_PR_F1SetupResponse;
198    f1SetupRsp = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
199
200    elementCnt = 4;
201    f1SetupRsp->protocolIEs.list.count = elementCnt;
202    f1SetupRsp->protocolIEs.list.size = elementCnt*sizeof(F1SetupResponseIEs_t *);
203
204    CU_ALLOC(f1SetupRsp->protocolIEs.list.array, \
205          elementCnt * sizeof(F1SetupResponseIEs_t *));
206    if(f1SetupRsp->protocolIEs.list.array == NULLP)
207    {
208       DU_LOG("\nF1AP : Memory allocation for F1ResponseIEs failed");
209       CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
210       CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
211       RETVALUE(RFAILED);
212    }
213
214    for(idx=0; idx<elementCnt; idx++)
215    {
216       CU_ALLOC(f1SetupRsp->protocolIEs.list.array[idx], \
217             sizeof(F1SetupResponseIEs_t)); 
218       if(f1SetupRsp->protocolIEs.list.array[idx] == NULLP)
219       {  
220          CU_FREE(f1SetupRsp->protocolIEs.list.array,\
221                elementCnt * sizeof(F1SetupResponseIEs_t *));
222          CU_FREE(f1apMsg->choice.successfulOutcome, \
223                sizeof(SuccessfulOutcome_t));
224          CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
225          RETVALUE(RFAILED);
226       }    
227    }
228
229    /*TransactionID*/
230    idx = 0;
231    f1SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
232    f1SetupRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
233    f1SetupRsp->protocolIEs.list.array[idx]->value.present = \
234                                      F1SetupResponseIEs__value_PR_TransactionID;
235    f1SetupRsp->protocolIEs.list.array[idx]->value.choice.TransactionID =\
236                                                                        TRANS_ID;
237
238    /*CU Name*/
239    idx++;
240    f1SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_gNB_CU_Name;
241    f1SetupRsp->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
242    f1SetupRsp->protocolIEs.list.array[idx]->value.present = \
243                                        F1SetupResponseIEs__value_PR_GNB_CU_Name;
244    cuName = &f1SetupRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_Name;
245    cuName->size = sizeof(cuCfgParams.cuName);
246
247    CU_ALLOC(cuName->buf, sizeof(cuName->size)); 
248    if(cuName->buf == NULLP)
249       {
250          for(idy=0; idy<elementCnt; idy++)
251          {
252             CU_FREE(f1SetupRsp->protocolIEs.list.array[idy],\
253                   sizeof(F1SetupResponseIEs_t));
254          }
255          CU_FREE(f1SetupRsp->protocolIEs.list.array,\
256                elementCnt * sizeof(F1SetupResponseIEs_t *));
257          CU_FREE(f1apMsg->choice.successfulOutcome,\
258                sizeof(SuccessfulOutcome_t));
259          CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
260          RETVALUE(RFAILED);
261       }
262    strcpy((char*)cuName->buf, (char*)cuCfgParams.cuName);
263  
264    /*Cells to be activated list*/
265    idx++;
266    f1SetupRsp->protocolIEs.list.array[idx]->id = \
267                               ProtocolIE_ID_id_Cells_to_be_Activated_List ;
268    f1SetupRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
269    f1SetupRsp->protocolIEs.list.array[idx]->value.present = \
270                      F1SetupResponseIEs__value_PR_Cells_to_be_Activated_List;
271    cellToActivate = &f1SetupRsp->protocolIEs.list.array[idx]->value.choice.\
272                     Cells_to_be_Activated_List;
273    cellCnt=1;
274    cellToActivate->list.count = cellCnt;
275    cellToActivate->list.size = \
276                cellCnt*sizeof(struct Cells_to_be_Activated_List_ItemIEs  *);
277    CU_ALLOC(cellToActivate->list.array,\
278          sizeof(struct Cells_to_be_Activated_List_ItemIEs  *));
279    if(cellToActivate->list.array == NULLP)
280    {
281       CU_FREE(cuName->buf, sizeof(cuName->size));
282       for(idy=0; idy<elementCnt; idy++)
283       {
284          CU_FREE(f1SetupRsp->protocolIEs.list.array[idy],\
285                sizeof(F1SetupResponseIEs_t));
286       }
287       CU_FREE(f1SetupRsp->protocolIEs.list.array,\
288             elementCnt * sizeof(F1SetupResponseIEs_t *));
289       CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
290       CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
291       RETVALUE(RFAILED);
292    }
293    for(idy=0; idy<cellCnt; idy++)
294    {
295       CU_ALLOC(cellToActivate->list.array[idy],\
296             sizeof(struct Cells_to_be_Activated_List_ItemIEs ));
297       if(cellToActivate->list.array[idy] == NULLP)
298       {
299          CU_FREE(cellToActivate->list.array,\
300                sizeof(struct Cells_to_be_Activated_List_ItemIEs  *));
301          CU_FREE(cuName->buf, sizeof(cuName->size));
302          for(idy=0; idy<elementCnt; idy++)
303          {
304             CU_FREE(f1SetupRsp->protocolIEs.list.array[idy], \
305                   sizeof(F1SetupResponseIEs_t));
306          }
307          CU_FREE(f1SetupRsp->protocolIEs.list.array, \
308                elementCnt * sizeof(F1SetupResponseIEs_t *));
309          CU_FREE(f1apMsg->choice.successfulOutcome, \
310                sizeof(SuccessfulOutcome_t));
311          CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
312          RETVALUE(RFAILED);
313       }
314    }
315    cellToActivate->list.array[0]->id = \
316                               ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
317    cellToActivate->list.array[0]->criticality = Criticality_ignore;
318    cellToActivate->list.array[0]->value.present = \
319        Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item;
320    cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
321       nRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
322    CU_ALLOC(cellToActivate->list.array[0]->\
323          value.choice.Cells_to_be_Activated_List_Item.nRCGI.pLMN_Identity.buf,\
324          3*sizeof(uint8_t));
325    if(cellToActivate->list.array[0]->value.choice.\
326          Cells_to_be_Activated_List_Item.nRCGI.pLMN_Identity.buf == NULLP)
327    {
328
329       for(idy=0; idy<cellCnt; idy++)
330       {
331          CU_FREE(cellToActivate->list.array[idy],\
332                sizeof(struct Cells_to_be_Activated_List_ItemIEs ));
333       }
334
335       CU_FREE(cellToActivate->list.array,\
336             sizeof(struct Cells_to_be_Activated_List_ItemIEs  *));
337       CU_FREE(cuName->buf, sizeof(cuName->size));
338       for(idy=0; idy<elementCnt; idy++)
339       {
340          CU_FREE(f1SetupRsp->protocolIEs.list.array[idy], \
341                sizeof(F1SetupResponseIEs_t));
342       }
343       CU_FREE(f1SetupRsp->protocolIEs.list.array, \
344             elementCnt * sizeof(F1SetupResponseIEs_t *));
345       CU_FREE(f1apMsg->choice.successfulOutcome, \
346             sizeof(SuccessfulOutcome_t));
347       CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
348       RETVALUE(RFAILED);
349    }
350     plmnBuildCU(cuCfgParams.plmn , &cellToActivate->list.array[0]->value.choice.\
351          Cells_to_be_Activated_List_Item.nRCGI.pLMN_Identity);
352    cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
353       nRCGI.nRCellIdentity.size = 5;
354    CU_ALLOC(cellToActivate->list.array[0]->value.choice.\
355          Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf,\
356          5*sizeof(uint8_t));
357    if(cellToActivate->list.array[0]->value.choice.\
358        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf == NULLP)
359    {
360       CU_FREE(cellToActivate->list.array[0]->\
361           value.choice.Cells_to_be_Activated_List_Item.nRCGI.pLMN_Identity.buf,\
362           3*sizeof(uint8_t));
363       for(idy=0; idy<cellCnt; idy++)
364       {
365          CU_FREE(cellToActivate->list.array[idy],\
366                sizeof(struct Cells_to_be_Activated_List_ItemIEs ));
367       }
368
369       CU_FREE(cellToActivate->list.array,\
370             sizeof(struct Cells_to_be_Activated_List_ItemIEs  *));
371       CU_FREE(cuName->buf, sizeof(cuName->size));
372       for(idy=0; idy<elementCnt; idy++)
373       {
374          CU_FREE(f1SetupRsp->protocolIEs.list.array[idy], \
375                sizeof(F1SetupResponseIEs_t));
376       }
377       CU_FREE(f1SetupRsp->protocolIEs.list.array, \
378             elementCnt * sizeof(F1SetupResponseIEs_t *));
379       CU_FREE(f1apMsg->choice.successfulOutcome, \
380             sizeof(SuccessfulOutcome_t));
381       CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
382       RETVALUE(RFAILED);
383    }
384    BuildNrCellId(&(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity));
385    /* RRC Version */
386    idx++;
387    f1SetupRsp->protocolIEs.list.array[idx]->id = \
388                                         ProtocolIE_ID_id_GNB_CU_RRC_Version;
389    f1SetupRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
390    f1SetupRsp->protocolIEs.list.array[idx]->value.present = \
391                                     F1SetupResponseIEs__value_PR_RRC_Version;
392    rrcVer = &f1SetupRsp->protocolIEs.list.array[idx]->value.choice.RRC_Version;
393    rrcVer->latest_RRC_Version.size = RRC_SIZE; 
394
395    CU_ALLOC(rrcVer->latest_RRC_Version.buf, sizeof(U8));
396    if(rrcVer->latest_RRC_Version.buf == NULLP)
397    {  
398       CU_FREE(cuName->buf, sizeof(cuName->size));
399       for(idy=0; idy<elementCnt; idx++)
400       {
401          CU_FREE(f1SetupRsp->protocolIEs.list.array[idy], \
402                sizeof(F1SetupResponseIEs_t));
403       } 
404       CU_FREE(f1SetupRsp->protocolIEs.list.array,\
405             elementCnt * sizeof(F1SetupResponseIEs_t *));
406       CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
407       CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
408       RETVALUE(RFAILED);
409    }
410
411   /* Need to check RRC Version */
412    rrcVer->latest_RRC_Version.buf[0] = cuCfgParams.rrcVersion.rrcVer; 
413    rrcVer->latest_RRC_Version.bits_unused = 5; //TODO: pick from cuCfgParam. If not present, add it
414    CU_ALLOC(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
415    if(rrcVer->iE_Extensions == NULLP)
416    {
417       CU_FREE(rrcVer->latest_RRC_Version.buf, sizeof(U8));
418       CU_FREE(cuName->buf, sizeof(cuName->size));
419       for(idy=0; idy<elementCnt; idy++)
420       {
421          CU_FREE(f1SetupRsp->protocolIEs.list.array[idy], \
422                sizeof(F1SetupResponseIEs_t));
423       } 
424       CU_FREE(f1SetupRsp->protocolIEs.list.array,\
425             elementCnt * sizeof(F1SetupResponseIEs_t *));
426       CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
427       CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
428       RETVALUE(RFAILED);
429    }
430    rrcVer->iE_Extensions->list.count = 1;
431    rrcVer->iE_Extensions->list.size = sizeof(struct RRC_Version_ExtIEs *);
432    CU_ALLOC(rrcVer->iE_Extensions->list.array,\
433          sizeof(struct RRC_Version_ExtIEs *));
434    if(rrcVer->iE_Extensions->list.array == NULLP)
435    {
436       CU_FREE(rrcVer->iE_Extensions,\
437             sizeof(ProtocolExtensionContainer_4624P81_t));
438       CU_FREE(rrcVer->latest_RRC_Version.buf, sizeof(U8));
439       CU_FREE(cuName->buf, sizeof(cuName->size));
440       for(idy=0; idy<elementCnt; idy++)
441       {
442          CU_FREE(f1SetupRsp->protocolIEs.list.array[idy], \
443                sizeof(F1SetupResponseIEs_t));
444       } 
445       CU_FREE(f1SetupRsp->protocolIEs.list.array,\
446             elementCnt * sizeof(F1SetupResponseIEs_t *));
447       CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
448       CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
449       RETVALUE(RFAILED);
450    }
451    CU_ALLOC(rrcVer->iE_Extensions->list.array[0],\
452          sizeof(struct RRC_Version_ExtIEs));
453    if(rrcVer->iE_Extensions->list.array[0] == NULLP)
454    {
455       CU_FREE(rrcVer->iE_Extensions->list.array,\
456             sizeof(struct RRC_Version_ExtIEs *));
457       CU_FREE(rrcVer->iE_Extensions,\
458             sizeof(ProtocolExtensionContainer_4624P81_t));
459       CU_FREE(rrcVer->latest_RRC_Version.buf, sizeof(U8));
460       CU_FREE(cuName->buf, sizeof(cuName->size));
461       for(idy=0; idy<elementCnt; idy++)
462       {
463          CU_FREE(f1SetupRsp->protocolIEs.list.array[idy], \
464                sizeof(F1SetupResponseIEs_t));
465       } 
466       CU_FREE(f1SetupRsp->protocolIEs.list.array,\
467             elementCnt * sizeof(F1SetupResponseIEs_t *));
468       CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
469       CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
470       RETVALUE(RFAILED);
471    }
472    rrcVer->iE_Extensions->list.array[0]->id = \
473                                 ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
474    rrcVer->iE_Extensions->list.array[0]->criticality = Criticality_reject;
475    rrcVer->iE_Extensions->list.array[0]->extensionValue.present = \
476              RRC_Version_ExtIEs__extensionValue_PR_Latest_RRC_Version_Enhanced;
477    rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.\
478       Latest_RRC_Version_Enhanced.size = 3*sizeof(U8);
479    CU_ALLOC(rrcVer->iE_Extensions->list.\
480          array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf,\
481          3*sizeof(U8));
482    if(rrcVer->iE_Extensions->list.\
483       array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf == NULLP)
484    {
485       CU_FREE(rrcVer->iE_Extensions->list.array[0],\
486              sizeof(struct RRC_Version_ExtIEs));
487       CU_FREE(rrcVer->iE_Extensions->list.array,\
488             sizeof(struct RRC_Version_ExtIEs *));
489       CU_FREE(rrcVer->iE_Extensions,\
490             sizeof(ProtocolExtensionContainer_4624P81_t));
491       CU_FREE(rrcVer->latest_RRC_Version.buf, sizeof(U8));
492       CU_FREE(cuName->buf, sizeof(cuName->size));
493       for(idy=0; idy<elementCnt; idy++)
494       {
495          CU_FREE(f1SetupRsp->protocolIEs.list.array[idy], \
496                sizeof(F1SetupResponseIEs_t));
497       } 
498       CU_FREE(f1SetupRsp->protocolIEs.list.array,\
499             elementCnt * sizeof(F1SetupResponseIEs_t *));
500       CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
501       CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
502       RETVALUE(RFAILED);
503    }
504    rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.\
505       Latest_RRC_Version_Enhanced.buf[0] = 0;
506    rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.\
507       Latest_RRC_Version_Enhanced.buf[1] = 5;
508    rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.\
509       Latest_RRC_Version_Enhanced.buf[2] = 15;
510
511    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
512
513    /* Encode the F1SetupRequest type as UPER */
514    cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN);
515    encBufSize = 0;
516    encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
517
518    /* Clean up */
519    CU_FREE(rrcVer->latest_RRC_Version.buf, sizeof(U8));
520    CU_FREE(cuName->buf, sizeof(cuName->size));
521    for(idx=0; idx<elementCnt; idx++)
522    {
523       CU_FREE(f1SetupRsp->protocolIEs.list.array[idx], sizeof(F1SetupResponseIEs_t));
524    }             
525    CU_FREE(f1SetupRsp->protocolIEs.list.array, elementCnt * sizeof(F1SetupResponseIEs_t *));
526    CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
527    CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
528
529    /* Check encode results */
530    if(encRetVal.encoded == ENCODE_FAIL)
531    {
532            DU_LOG("\nF1AP : Could not encode F1SetupResponse structure (at %s)\n",\
533                            encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
534            RETVALUE(RFAILED);   
535    } 
536    else 
537    {
538            DU_LOG("\nF1AP : Created APER encoded buffer for F1SetupResponse\n");
539            for(int i=0; i< encBufSize; i++)
540            {
541                    printf("%x",encBuf[i]);
542            } 
543    }
544
545    /* Sending msg */
546    if(SendF1APMsg(CU_APP_MEM_REG, CU_POOL) != ROK)
547    {
548            DU_LOG("\nF1AP : Sending F1 Setup Response failed");      
549            RETVALUE(RFAILED);
550    }
551
552    RETVALUE(ROK);
553 }/* End of BuildAndSendF1SetupRsp */
554
555 /*******************************************************************
556  *
557  * @brief Builds and sends the DUUpdateAcknowledge
558  *
559  * @details
560  *
561  *    Function : BuildAndSendDUUpdateAck
562  *
563  *    Functionality: Constructs the DU Update Acknowledge message and sends
564  *                   it to the DU through SCTP.
565  *
566  * @params[in] void **buf,Buffer to which encoded pattern is written into
567  * @params[in] int *size,size of buffer
568  *
569  * @return ROK     - success
570  *         RFAILED - failure
571  *
572  * ****************************************************************/
573
574 S16 BuildAndSendDUUpdateAck()
575 {
576    U8   idx;
577    U8   elementCnt;
578    F1AP_PDU_t *f1apMsg = NULL;
579    GNBDUConfigurationUpdateAcknowledge_t *gNBDuCfgAck;
580    asn_enc_rval_t enRetVal; /* Encoder return value */
581
582    DU_LOG("\nF1AP : Building GNB-DU Config Update Ack\n");
583
584    /* Allocate the memory for F1SetupRequest_t */
585    CU_ALLOC(f1apMsg, (Size)sizeof(F1AP_PDU_t));
586    if(f1apMsg == NULLP)
587    {
588       DU_LOG("\nF1AP : Memory allocation for F1AP-PDU failed");
589       RETVALUE(RFAILED);
590    }
591
592    f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
593
594    CU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
595    if(f1apMsg->choice.successfulOutcome == NULLP)
596    {
597       DU_LOG("\nF1AP : Memory allocation for F1AP-PDU failed");
598       CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
599       RETVALUE(RFAILED);
600    }
601
602    f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_gNBDUConfigurationUpdate;
603    f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
604    f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge;
605    gNBDuCfgAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
606
607    elementCnt = 1;
608    gNBDuCfgAck->protocolIEs.list.count = elementCnt;
609    gNBDuCfgAck->protocolIEs.list.size = elementCnt*sizeof(GNBDUConfigurationUpdateAcknowledgeIEs_t);
610
611    /* Initialize the F1Setup members */
612    CU_ALLOC(gNBDuCfgAck->protocolIEs.list.array, elementCnt * sizeof(GNBDUConfigurationUpdateAcknowledgeIEs_t *));
613    if(gNBDuCfgAck->protocolIEs.list.array == NULLP)
614    {
615       DU_LOG("\nF1AP : Memory allocation for DuUpdateAcknowledgeIEs failed");
616       CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
617       CU_FREE(f1apMsg,(Size)sizeof(F1AP_PDU_t));
618       RETVALUE(RFAILED);
619    }
620
621    for(idx=0; idx<elementCnt; idx++)
622    {
623       CU_ALLOC(gNBDuCfgAck->protocolIEs.list.array[idx], sizeof(GNBDUConfigurationUpdateAcknowledgeIEs_t));
624       if(gNBDuCfgAck->protocolIEs.list.array[idx] == NULLP)
625       {
626          CU_FREE(gNBDuCfgAck->protocolIEs.list.array, elementCnt * sizeof(GNBDUConfigurationUpdateAcknowledgeIEs_t *));
627          CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
628          CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
629          RETVALUE(RFAILED);
630       }
631    }
632
633    /*TransactionID*/ 
634    idx = 0;
635    gNBDuCfgAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID ;
636    gNBDuCfgAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
637    gNBDuCfgAck->protocolIEs.list.array[idx]->value.present = GNBDUConfigurationUpdateAcknowledgeIEs__value_PR_TransactionID;
638    gNBDuCfgAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
639
640    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
641  
642    /* Encode the F1SetupRequest type as UPER */
643    cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN);
644    encBufSize = 0;
645    enRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
646
647    /* Clean up */
648    for(idx=0; idx<elementCnt; idx++)
649    {
650       CU_FREE(gNBDuCfgAck->protocolIEs.list.array[idx], sizeof(GNBDUConfigurationUpdateAcknowledgeIEs_t));
651    }
652    CU_FREE(gNBDuCfgAck->protocolIEs.list.array, elementCnt * sizeof(GNBDUConfigurationUpdateAcknowledgeIEs_t *));
653    CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
654    CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
655
656    /* Checking encode results */
657    if(enRetVal.encoded == ENCODE_FAIL) 
658    {
659       DU_LOG("\nF1AP : Could not encode DUConfigUpdateAcknowledge structure (at %s)",enRetVal.failed_type ? enRetVal.failed_type->name : "unknown");
660       RETVALUE(RFAILED); 
661    } 
662    else 
663    {
664     DU_LOG("\nF1AP : Created APER encoded buffer for DuConfigUpdateAcknowledge\n");  
665       for(int i=0; i< encBufSize; i++)
666       {
667          printf("%x",encBuf[i]);
668       } 
669    }
670
671    /* Sending msg */
672    if(SendF1APMsg(CU_APP_MEM_REG, CU_POOL) != ROK)
673    {
674       DU_LOG("\nF1AP : Sending GNB-DU Config Update Ack failed");
675       RETVALUE(RFAILED);
676    }
677
678    RETVALUE(ROK);
679
680 }/* End of BuildAndSendDUUpdateAck*/
681
682 /*******************************************************************
683  *
684  * @brief Builds and sends the DLRRCMessageTransfer 
685  *
686  * @details
687  *
688  *    Function : BuildAndSendDLRRCMessageTransfer
689  *
690  *    Functionality: Constructs the DL RRC Message Transfer and sends
691  *                   it to the CU through SCTP.
692  *
693  * @params[in] 
694  *
695  * @return ROK     - success
696  *         RFAILED - failure
697  *
698  * ****************************************************************/
699 S16 BuildAndSendDLRRCMessageTransfer()
700 {
701         S16  ret;
702         U8   elementCnt;
703         U8   ieId;
704         U8   idx;
705         F1AP_PDU_t                              *f1apMsg = NULL;
706    DLRRCMessageTransfer_t       *dlRRCMsg;
707         asn_enc_rval_t                          encRetVal;        /* Encoder return value */
708
709         DU_LOG("\n F1AP : Building DL RRC Message Transfer Message\n");
710
711         CU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
712         if(f1apMsg == NULLP)
713         {
714                 DU_LOG(" F1AP : Memory allocation for F1AP-PDU failed");
715                 RETVALUE(RFAILED);
716         }
717
718         f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
719         CU_ALLOC(f1apMsg->choice.initiatingMessage,
720                         sizeof(InitiatingMessage_t));
721         if(f1apMsg->choice.initiatingMessage == NULLP)
722         {
723                 DU_LOG(" F1AP : Memory allocation for   F1AP-PDU failed");
724                 CU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
725                 RETVALUE(RFAILED);
726         }
727
728         f1apMsg->choice.initiatingMessage->procedureCode = \
729                                                                                                 ProcedureCode_id_DLRRCMessageTransfer;
730         f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
731         f1apMsg->choice.initiatingMessage->value.present = \
732                                                                 InitiatingMessage__value_PR_DLRRCMessageTransfer;
733         dlRRCMsg =
734                 &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
735         elementCnt = 3;
736         dlRRCMsg->protocolIEs.list.count = elementCnt;
737         dlRRCMsg->protocolIEs.list.size = \
738                                                                         elementCnt * sizeof(DLRRCMessageTransferIEs_t *);
739
740         /* Initialize the F1Setup members */
741         CU_ALLOC(dlRRCMsg->protocolIEs.list.array, \
742                         elementCnt * sizeof(DLRRCMessageTransferIEs_t *));
743         if(dlRRCMsg->protocolIEs.list.array == NULLP)
744         {
745                 DU_LOG(" F1AP : Memory allocation for DL RRC MessageTransferIEs failed");
746                 CU_FREE(f1apMsg->choice.initiatingMessage,
747                                 sizeof(InitiatingMessage_t));
748                 CU_FREE(f1apMsg,(Size)sizeof(F1AP_PDU_t));
749                 RETVALUE(RFAILED);
750         }
751
752         for(idx=0; idx<elementCnt; idx++)
753         {
754                 CU_ALLOC(dlRRCMsg->protocolIEs.list.array[idx],\
755                                                                                 sizeof(DLRRCMessageTransferIEs_t));
756                 if(dlRRCMsg->protocolIEs.list.array[idx] == NULLP)
757                 {
758                         for(ieId=0; ieId<idx; ieId++)
759                         {
760                                 CU_FREE(dlRRCMsg->protocolIEs.list.array[ieId],\
761                                                 sizeof(DLRRCMessageTransferIEs_t));
762                         }
763                         CU_FREE(dlRRCMsg->protocolIEs.list.array,\
764                                         elementCnt * sizeof(DLRRCMessageTransferIEs_t *));
765                         CU_FREE(f1apMsg->choice.initiatingMessage,\
766                                                                                                 sizeof(InitiatingMessage_t));
767                         CU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
768                         RETVALUE(RFAILED);
769                 }
770         }
771
772         idx = 0;
773
774         /*GNB CU UE F1AP ID*/
775         dlRRCMsg->protocolIEs.list.array[idx]->id       = \
776                                                                                  ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
777         dlRRCMsg->protocolIEs.list.array[idx]->criticality      =       Criticality_reject;
778         dlRRCMsg->protocolIEs.list.array[idx]->value.present = \
779                                 DLRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
780         dlRRCMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = CU_ID;
781
782         /*GNB DU UE F1AP ID*/
783         idx++;
784         dlRRCMsg->protocolIEs.list.array[idx]->id       = \
785                                                                                  ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
786         dlRRCMsg->protocolIEs.list.array[idx]->criticality      =       Criticality_reject;
787         dlRRCMsg->protocolIEs.list.array[idx]->value.present = \
788                                 DLRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
789         dlRRCMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = DU_ID;
790
791         /*SRBID*/
792         idx++;
793         dlRRCMsg->protocolIEs.list.array[idx]->id       = \
794                                                                                                                  ProtocolIE_ID_id_SRBID;
795         dlRRCMsg->protocolIEs.list.array[idx]->criticality      =       Criticality_reject;
796         dlRRCMsg->protocolIEs.list.array[idx]->value.present = \
797                                                                 DLRRCMessageTransferIEs__value_PR_SRBID;
798         dlRRCMsg->protocolIEs.list.array[idx]->value.choice.SRBID = DL_SRBID;
799
800         /*RRCContainer*/
801         //YET TO FILL
802
803         xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
804
805         /* Encode the F1SetupRequest type as APER */
806         cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN);
807         encBufSize = 0;
808         encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
809                         encBuf);
810         /* Encode results */
811         if(encRetVal.encoded == ENCODE_FAIL)
812         {
813                 DU_LOG( "\n F1AP : Could not encode DL RRC Message Transfer structure (at %s)\n",\
814                                 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
815                 RETVALUE(RFAILED);
816         }
817         else
818         {
819                 DU_LOG("\n F1AP : Created APER encoded buffer for DL RRC Message transfer\n");
820                 for(int i=0; i< encBufSize; i++)
821                 {
822                         printf("%x",encBuf[i]);
823                 }
824         }
825
826         /* Sending  msg  */
827         if(SendF1APMsg(CU_APP_MEM_REG,CU_POOL)  !=      ROK)
828         {
829                 DU_LOG("\n F1AP : Sending       DL RRC Message Transfer Failed");
830                 RETVALUE(RFAILED);
831         }
832
833         RETVALUE(ROK);
834 }/* End of BuildAndSendDLRRCMessageTransfer */
835
836
837 /*******************************************************************
838  *
839  * @brief Builds and sends the UE Setup Response
840  *
841  * @details
842  *
843  *    Function : BuildAndSendUESetRsp
844  *
845  *    Functionality: Constructs the UE Setup Response and sends
846  *                   it to the DU through SCTP.
847  *
848  * @params[in] 
849  *
850  * @return ROK     - success
851  *         RFAILED - failure
852  *
853  * ****************************************************************/
854 S16 BuildAndSendUESetRsp()
855 {
856         S16  ret;
857         U8   elementCnt;
858         U8   cellCnt;
859         U8   ieId;
860         U8   idx;
861         U8   drbCnt;
862         U8   drbId;
863         F1AP_PDU_t                                                      *f1apMsg = NULL;
864    UEContextSetupResponse_t                     *ueSetRsp;
865         asn_enc_rval_t                                                  encRetVal;        /* Encoder return value */
866
867         DU_LOG("\n F1AP : Building UE Context Setup Response\n");
868
869         CU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
870         if(f1apMsg == NULLP)
871         {
872                 DU_LOG(" F1AP : Memory allocation for F1AP-PDU failed");
873                 RETVALUE(RFAILED);
874         }
875
876         f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
877         CU_ALLOC(f1apMsg->choice.successfulOutcome,
878                         sizeof(SuccessfulOutcome_t));
879         if(f1apMsg->choice.successfulOutcome == NULLP)
880         {
881                 DU_LOG(" F1AP : Memory allocation for   F1AP-PDU failed");
882                 CU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
883                 RETVALUE(RFAILED);
884         }
885
886         f1apMsg->choice.successfulOutcome->procedureCode = \
887                                                                                                         ProcedureCode_id_UEContextSetup;
888         f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
889         f1apMsg->choice.successfulOutcome->value.present = \
890                                    SuccessfulOutcome__value_PR_UEContextSetupResponse;
891         ueSetRsp =
892                 &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
893         elementCnt = 2;
894         ueSetRsp->protocolIEs.list.count = elementCnt;
895         ueSetRsp->protocolIEs.list.size = \
896                                                                         elementCnt * sizeof(UEContextSetupResponse_t *);
897
898         /* Initialize the UESetup members */
899         CU_ALLOC(ueSetRsp->protocolIEs.list.array, \
900                                 ueSetRsp->protocolIEs.list.size);
901         if(ueSetRsp->protocolIEs.list.array == NULLP)
902         {
903                 DU_LOG(" F1AP : Memory allocation for UE Setup Response failed");
904                 CU_FREE(f1apMsg->choice.successfulOutcome,
905                                 sizeof(SuccessfulOutcome_t));
906                 CU_FREE(f1apMsg,(Size)sizeof(F1AP_PDU_t));
907                 RETVALUE(RFAILED);
908         }
909
910         for(idx=0; idx<elementCnt; idx++)
911         {
912                 CU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
913                                                                                 sizeof(UEContextSetupResponseIEs_t));
914                 if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
915                 {
916                         for(ieId=0; ieId<idx; ieId++)
917                         {
918                                 CU_FREE(ueSetRsp->protocolIEs.list.array[ieId],\
919                                                 sizeof(UEContextSetupResponseIEs_t));
920                         }
921                         CU_FREE(ueSetRsp->protocolIEs.list.array,\
922                                                  ueSetRsp->protocolIEs.list.size);
923                         CU_FREE(f1apMsg->choice.successfulOutcome,\
924                                                                                                 sizeof(SuccessfulOutcome_t));
925                         CU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
926                         RETVALUE(RFAILED);
927                 }
928         }
929
930         idx = 0;
931
932         /*GNB CU UE F1AP ID*/
933         ueSetRsp->protocolIEs.list.array[idx]->id       = \
934                                                                                  ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
935         ueSetRsp->protocolIEs.list.array[idx]->criticality      =       Criticality_reject;
936         ueSetRsp->protocolIEs.list.array[idx]->value.present = \
937                                                 UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
938         ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = CU_ID;
939         
940         /*GNB DU UE F1AP ID*/
941         idx++;
942         ueSetRsp->protocolIEs.list.array[idx]->id       = \
943                                                                                  ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
944         ueSetRsp->protocolIEs.list.array[idx]->criticality      =       Criticality_reject;
945         ueSetRsp->protocolIEs.list.array[idx]->value.present = \
946                                                 UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
947         ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = DU_ID;
948         
949
950         xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
951
952         /* Encode the F1SetupRequest type as APER */
953         cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN);
954         encBufSize = 0;
955         encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
956                         encBuf);
957         /* Encode results */
958         if(encRetVal.encoded == ENCODE_FAIL)
959         {
960                 DU_LOG( "\n F1AP : Could not encode UE Context Setup Request structure (at %s)\n",\
961                                 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
962                 RETVALUE(RFAILED);
963         }
964         else
965         {
966                 DU_LOG("\n F1AP : Created APER encoded buffer for UE Context Setup Request\n");
967                 for(int i=0; i< encBufSize; i++)
968                 {
969                         printf("%x",encBuf[i]);
970                 }
971         }
972
973         /* Sending  msg  */
974         if(SendF1APMsg(CU_APP_MEM_REG,CU_POOL)  !=      ROK)
975         {
976                 DU_LOG("\n F1AP : Sending       UE Context Setup Request Failed");
977                 RETVALUE(RFAILED);
978         }
979
980         RETVALUE(ROK);
981 }/* End of BuildAndSendUESetRsp */
982 /*******************************************************************
983 *
984 * @brief Handles received F1AP message and sends back response  
985 *
986 * @details
987 *
988 *    Function : F1APMsgHdlr
989 *
990 *    Functionality:
991 *         - Decodes received F1AP control message
992 *         - Prepares response message, encodes and sends to SCTP
993 *
994 * @params[in] 
995 * @return ROK     - success
996 *         RFAILED - failure
997 *
998 * ****************************************************************/
999 void F1APMsgHdlr(Buffer *mBuf)
1000 {
1001    int i;
1002    char *recvBuf;
1003    MsgLen copyCnt;
1004    MsgLen recvBufLen;
1005    F1AP_PDU_t *f1apMsg;
1006    asn_dec_rval_t rval; /* Decoder return value */
1007    F1AP_PDU_t f1apasnmsg ;
1008  
1009    DU_LOG("\nF1AP : Received F1AP message buffer");
1010    SPrntMsg(mBuf, 0,0);
1011  
1012    /* Copy mBuf into char array to decode it */
1013    SFndLenMsg(mBuf, &recvBufLen);
1014    if(SGetSBuf(DFLT_REGION, DFLT_POOL, (Data **)&recvBuf, (Size)recvBufLen) != ROK)
1015    {
1016       DU_LOG("\nF1AP : Memory allocation failed");
1017       return;
1018    }
1019    if(SCpyMsgFix(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
1020    {
1021       DU_LOG("\nF1AP : Failed while copying %d", copyCnt);
1022       return;
1023    }
1024
1025    printf("\nF1AP : Received flat buffer to be decoded : ");
1026    for(i=0; i< recvBufLen; i++)
1027    {
1028         printf("%x",recvBuf[i]);
1029    }
1030
1031    /* Decoding flat buffer into F1AP messsage */
1032    f1apMsg = &f1apasnmsg;
1033    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
1034  
1035    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
1036    SPutSBuf(DFLT_REGION, DFLT_POOL, (Data *)recvBuf, (Size)recvBufLen);
1037    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
1038    {
1039       DU_LOG("\nF1AP : ASN decode failed");
1040       return;
1041    }
1042    printf("\n");
1043    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1044
1045    switch(f1apMsg->present)
1046    {
1047       case F1AP_PDU_PR_initiatingMessage:
1048       {
1049          switch(f1apMsg->choice.initiatingMessage->value.present)
1050          {
1051             case InitiatingMessage__value_PR_F1SetupRequest:
1052             {
1053                DU_LOG("\nF1AP : F1 setup request received");
1054                BuildAndSendF1SetupRsp();
1055                                   break;
1056             }
1057
1058             case InitiatingMessage__value_PR_GNBDUConfigurationUpdate:
1059             {
1060                DU_LOG("\nF1AP : GNB-DU config update received");
1061                BuildAndSendDUUpdateAck();
1062                break;
1063             }
1064
1065             default:
1066             {
1067                DU_LOG("\nF1AP : Invalid type of intiating message [%d]",f1apMsg->choice.initiatingMessage->value.present);
1068                return;
1069             }
1070          }/* End of switch(initiatingMessage) */
1071          break;
1072       }
1073
1074    }/* End of switch(f1apMsg->present) */
1075  
1076 } /* End of F1APMsgHdlr */
1077  
1078 /**********************************************************************
1079   End of file
1080  **********************************************************************/