1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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 *******************************************************************************/
19 /* This file contains F1AP message handler functions */
20 #include "common_def.h"
21 #include "cu_stub_sctp.h"
22 #include "cu_stub_egtp.h"
23 #include "OCTET_STRING.h"
24 #include "cu_f1ap_msg_hdl.h"
27 /*******************************************************************
29 * @brief Build And send dummy Xn Setup request
33 * Function : BuildAndSendXnSetupReq
36 * Build And send dummy Xn Setup request
41 ******************************************************************/
42 void BuildAndSendXnSetupReq()
46 CuSctpAssocCb *assocCb = NULLP;
48 for(assocIdx = 0; assocIdx < sctpCb.numAssoc; assocIdx++)
50 assocCb = &sctpCb.assocCb[assocIdx];
51 if(assocCb->connUp && assocCb->intf == XN_INTERFACE && assocCb->destId == 0)
53 if(ODU_GET_MSG_BUF(1, 1, &mBuf) == ROK)
55 CMCHKPK(oduUnpackUInt8,(Data *)CU_ID, mBuf);
56 CMCHKPK(oduUnpackUInt8,XN_SETUP_REQ, mBuf);
57 ODU_PRINT_MSG(mBuf, 0,0);
58 if(sendOnSctpAssoc(assocCb, mBuf) != ROK)
60 DU_LOG("\nERROR --> CU_STUB: Failed to send XN setup request to peer CU");
68 /*******************************************************************
70 * @brief Process received Xn Setup request
74 * Function : XNAPProcXnSetupReq
77 * Fetch peer CU ID and store in assocCb
79 * @params[in] Pointer to destination Id
80 * Pointer to message buffer
83 ******************************************************************/
84 void XNAPProcXnSetupReq(uint32_t *destId, Buffer *mBuf)
88 DU_LOG("\nINFO --> CU STUB : Received XN Setup Request");
89 CMCHKUNPK(oduPackUInt8, &(cuId), mBuf)
92 BuildAndSendXnSetupRsp(*destId);
95 /*******************************************************************
97 * @brief Build And send dummy Xn Setup response
101 * Function : BuildAndSendXnSetupRsp
104 * Build And send dummy Xn Setup response
109 ******************************************************************/
110 void BuildAndSendXnSetupRsp(uint32_t destId)
112 Buffer *mBuf = NULLP;
114 if(ODU_GET_MSG_BUF(1, 1, &mBuf) == ROK)
116 CMCHKPK(oduUnpackUInt8, CU_ID, mBuf);
117 CMCHKPK(oduUnpackUInt8, XN_SETUP_RSP, mBuf);
118 if(sctpSend(XN_INTERFACE, destId, mBuf))
120 DU_LOG("\nERROR --> CU_STUB: Failed to send XN setup response to peer CU");
125 /*******************************************************************
127 * @brief Process received Xn Setup response
131 * Function : XNAPProcXnSetupRsp
134 * Fetch peer CU ID and store in assocCb
136 * @params[in] Pointer to destination Id
137 * Pointer to message buffer
140 ******************************************************************/
141 void XNAPProcXnSetupRsp(uint32_t *destId, Buffer *mBuf)
145 DU_LOG("\nINFO --> CU STUB : Received XN Setup Response");
146 CMCHKUNPK(oduPackUInt8, &(cuId), mBuf)
150 /*******************************************************************
152 * @brief Build And send dummy Handover request to Peer CU
156 * Function : BuildAndSendHOReq
159 * Build And send dummy Handover request to Peer CU
161 * @params[in] Pointer to UE Cb
167 ******************************************************************/
168 void BuildAndSendHOReq(CuUeCb *ueCb, XnEventType event, char *xnMsg, MsgLen xnMsgLen)
170 Buffer *mBuf = NULLP;
172 if(ODU_GET_MSG_BUF(1, 1, &mBuf) == ROK)
174 if(ODU_ADD_POST_MSG_MULT((Data *)xnMsg, xnMsgLen, mBuf) == ROK)
176 CMCHKPK(oduUnpackUInt8, event, mBuf);
177 if(sctpSend(XN_INTERFACE, ueCb->hoInfo.targetId, mBuf) != ROK)
179 DU_LOG("\nERROR --> CU_STUB: Failed to send handover request to peer CU");
180 ueCb->state = UE_ACTIVE;
181 memset(&ueCb->hoInfo, 0, sizeof(HandoverInfo));
187 /*******************************************************************
189 * @brief Handle incoming messages at Xn interface
193 * Function : XNAPMsgHdlr
196 * Fetch event type from message buffer and call appropriate
199 * @params[in] Pointer to destination Id
200 * Pointer to message buffer
203 ******************************************************************/
204 void XNAPMsgHdlr(uint32_t *destId, Buffer *mBuf)
208 CMCHKUNPK(oduPackUInt8, &event, mBuf);
214 XNAPProcXnSetupReq(destId, mBuf);
220 XNAPProcXnSetupRsp(destId, mBuf);
226 DU_LOG("\nINFO --> CU STUB : Received Handover Request at XNAP");
228 //Handling of HO Request to be added in next gerrit
233 F1AP_PDU_t *f1apMsg = NULLP;
234 asn_dec_rval_t rval; /* Decoder return value */
235 F1AP_PDU_t f1apasnmsg ;
237 ODU_PRINT_MSG(mBuf, 0,0);
239 /* Copy mBuf into char array to decode it */
240 ODU_GET_MSG_LEN(mBuf, &recvBufLen);
241 CU_ALLOC(recvBuf, (Size)recvBufLen);
245 DU_LOG("\nERROR --> F1AP : Memory allocation failed");
248 if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
250 DU_LOG("\nERROR --> F1AP : Failed while copying %d", copyCnt);
254 DU_LOG("\nDEBUG --> F1AP : Received flat buffer to be decoded : ");
255 for(i=0; i< recvBufLen; i++)
257 DU_LOG("%x",recvBuf[i]);
260 /* Decoding flat buffer into F1AP messsage */
261 f1apMsg = &f1apasnmsg;
262 memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
263 rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
264 CU_FREE(recvBuf, (Size)recvBufLen);
266 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
268 DU_LOG("\nERROR --> F1AP : ASN decode failed");
272 xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
274 procUeContextModificationResponse(0, f1apMsg, recvBuf, recvBufLen);
279 DU_LOG("\nERROR --> CU_STUB : Invalid event [%d] received at XN interface", event);
284 /**********************************************************************
286 **********************************************************************/