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 ASN codec for MIB and SIB1 msgs */
21 #include "du_sys_info_hdl.h"
24 #include "PLMN-IdentityInfo.h"
25 #include "PLMN-IdentitY.h"
28 extern char encBuf[ENC_BUF_MAX_LEN];
30 extern DuCfgParams duCfgParam;
32 /*******************************************************************
34 * @brief Builds MIB message in Served Cell Info
38 * Function : BuildMibMsg
40 * Functionality: Building MIB message in Served Cell Info
42 * @params[in] GNB_DU_System_Information *gnbDuSysInfo
43 * @return ROK - success
46 * ****************************************************************/
50 asn_enc_rval_t encRetVal; /* Encoder return value */
52 DU_ALLOC(mibMsg, sizeof(MIB_t));
55 DU_LOG("DU APP: MIB msg memory allocation failure");
58 mibMsg->systemFrameNumber.size = sizeof(uint8_t);
59 DU_ALLOC(mibMsg->systemFrameNumber.buf,
60 mibMsg->systemFrameNumber.size);
61 if(!(mibMsg->systemFrameNumber.buf))
63 DU_LOG("DU APP: MIB msg memory allocation failure");
67 *(mibMsg->systemFrameNumber.buf) =
68 duCfgParam.mibParams.sysFrmNum;
69 mibMsg->systemFrameNumber.bits_unused = ODU_VALUE_TWO;
71 mibMsg->subCarrierSpacingCommon =\
72 duCfgParam.mibParams.subCarrierSpacingCommon;
73 mibMsg->ssb_SubcarrierOffset =\
74 duCfgParam.mibParams.ssb_SubcarrierOffset;
75 mibMsg->dmrs_TypeA_Position =\
76 duCfgParam.mibParams.dmrs_TypeA_Position;
77 mibMsg->pdcch_ConfigSIB1.controlResourceSetZero = \
78 duCfgParam.mibParams.controlResourceSetZero;
79 mibMsg->pdcch_ConfigSIB1.searchSpaceZero = \
80 duCfgParam.mibParams.searchSpaceZero;
81 mibMsg->cellBarred = duCfgParam.mibParams.cellBarred;
82 mibMsg->intraFreqReselection =
83 duCfgParam.mibParams.intraFreqReselection;
84 mibMsg->spare.size = sizeof(uint8_t);
85 DU_ALLOC(mibMsg->spare.buf,sizeof(uint8_t));
86 if(!mibMsg->spare.buf)
88 DU_LOG("DU APP: MIB msg memory allocation failure");
91 *(mibMsg->spare.buf) = SPARE;
92 mibMsg->spare.bits_unused = ODU_VALUE_SEVEN;
94 xer_fprint(stdout, &asn_DEF_MIB, mibMsg);
95 cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN);
97 encRetVal = aper_encode(&asn_DEF_MIB, 0,
98 mibMsg, PrepFinalEncBuf, encBuf);
99 printf("\nencbufSize:%d\n", encBufSize);
100 if(encRetVal.encoded == -1)
102 DU_LOG("\nDU APP: Could not encode MIB structure(at %s)\n",
103 encRetVal.failed_type?\
104 encRetVal.failed_type->name
109 /* Print encoded buffer */
110 for(int i=0; i< encBufSize; i++)
112 printf("%x\t",encBuf[i]);
116 /* Free allocated memory */
117 DU_FREE(mibMsg->systemFrameNumber.buf,
118 mibMsg->systemFrameNumber.size);
119 DU_FREE(mibMsg->spare.buf, mibMsg->spare.size);
120 DU_FREE(mibMsg, sizeof(MIB_t));
126 /*******************************************************************
128 * @brief Builds CellIdentity within SIB1 message
132 * Function : BuildCellIdentity
134 * Functionality: Building RAN area code in SIB1 message
136 * @params[in] RAN_AreaCode_t **ranAreaCode
137 * @return ROK - success
140 * ****************************************************************/
141 S16 BuildCellIdentity(CellIdentity_t *cellIdentity)
143 cellIdentity->size = ODU_VALUE_FIVE*sizeof(uint8_t);
144 cellIdentity->bits_unused = ODU_VALUE_FOUR;
146 DU_ALLOC(cellIdentity->buf, cellIdentity->size);
147 if(!cellIdentity->buf)
149 DU_LOG("DU APP: CellIdentity memory allocation failure");
152 *cellIdentity->buf = duCfgParam.sib1Params.cellIdentity;
156 /*******************************************************************
158 * @brief Builds RANAC within SIB1 message
162 * Function : BuildRanac
164 * Functionality: Building RAN area code in SIB1 message
166 * @params[in] RAN_AreaCode_t **ranAreaCode
167 * @return ROK - success
170 * ****************************************************************/
171 S16 BuildRanac(RAN_AreaCode_t **ranAreaCode)
173 RAN_AreaCode_t *ranac;
174 DU_ALLOC(ranac, sizeof(RAN_AreaCode_t));
177 DU_LOG("DU APP: RANAC memory allocation failure");
180 *ranac = duCfgParam.sib1Params.ranac;
181 *ranAreaCode = ranac;
184 /*******************************************************************
186 * @brief Builds TAC within SIB1 message
190 * Function : BuildTac
192 * Functionality: Building Tracking area code in SIB1 message
194 * @params[in] TrackingAreaCode_t **tac
195 * @return ROK - success
198 * ****************************************************************/
199 S16 BuildTac(TrackingAreaCode_t **trackAreaCode)
201 TrackingAreaCode_t *tac;
204 DU_ALLOC(tac, sizeof(TrackingAreaCode_t));
207 DU_LOG("DU APP: TAC memory allocation failure");
211 tac->size = ODU_VALUE_THREE*sizeof(uint8_t);
212 DU_ALLOC(tac->buf, tac->size);
215 DU_LOG("DU APP: TAC memory allocation failure");
218 *(tac->buf) = duCfgParam.sib1Params.tac;
219 tac->bits_unused = ODU_VALUE_ZERO;
220 *trackAreaCode = tac;
225 /*******************************************************************
227 * @brief Builds PLMN list within SIB1 message
231 * Function : BuildPlmnList
233 * Functionality: Building PLMN list in SIB1 message
235 * @params[in] CellAccessRelatedInfo_t *cellAccessInfo
236 * @return ROK - success
239 * ****************************************************************/
240 S16 BuildPlmnList(CellAccessRelatedInfo_t *cellAccessInfo)
244 TrackingAreaCode_t **tac;
245 RAN_AreaCode_t **ranac;
246 CellIdentity_t *cellIdentity;
247 struct PLMN_IdentityInfo__plmn_IdentityList
250 DU_ALLOC(cellAccessInfo->plmn_IdentityList.list.array,
251 cellAccessInfo->plmn_IdentityList.list.size);
252 if(!cellAccessInfo->plmn_IdentityList.list.array)
254 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
257 elementCnt = cellAccessInfo->plmn_IdentityList.list.count;
258 for(idx=0; idx<elementCnt; idx++)
260 DU_ALLOC(cellAccessInfo->plmn_IdentityList.list.array[idx],
261 sizeof(PLMN_IdentityInfo_t));
262 if(!cellAccessInfo->plmn_IdentityList.list.array[idx])
264 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
271 elementCnt = ODU_VALUE_ONE;
273 plmnIdInfo = &cellAccessInfo->plmn_IdentityList.list.array[idx]->\
275 plmnIdInfo->list.count = elementCnt;
276 plmnIdInfo->list.size = elementCnt * sizeof(PLMN_IdentitY_t);
277 DU_ALLOC(plmnIdInfo->list.array, plmnIdInfo->list.size);
278 if(!plmnIdInfo->list.array)
280 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
283 for(idx1=0; idx1<elementCnt; idx1++)
285 DU_ALLOC(plmnIdInfo->list.array[idx1],
286 sizeof(PLMN_IdentitY_t));
287 if(!(plmnIdInfo->list.array[idx1]))
289 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
294 DU_ALLOC(plmnIdInfo->list.array[idx1]->mcc,
296 if(!plmnIdInfo->list.array[idx1]->mcc)
298 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
302 elementCnt = ODU_VALUE_THREE;
303 plmnIdInfo->list.array[idx1]->mcc->list.count = elementCnt;
304 plmnIdInfo->list.array[idx1]->mcc->list.size =\
305 elementCnt * sizeof(MCC_MNC_Digit_t);
306 DU_ALLOC(plmnIdInfo->list.array[idx1]->mcc->list.array,
307 plmnIdInfo->list.array[idx1]->mcc->list.size)
308 if(!(plmnIdInfo->list.array[idx1]->mcc->list.array))
310 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
313 for(idx2=0; idx2<elementCnt; idx2++)
315 DU_ALLOC(plmnIdInfo->list.array[idx1]->mcc->list.array[idx2],
316 sizeof(MCC_MNC_Digit_t));
317 if(!plmnIdInfo->list.array[idx1]->mcc->list.array[idx2])
319 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
322 *(plmnIdInfo->list.array[idx1]->mcc->list.array[idx2])=\
323 duCfgParam.sib1Params.plmn.mcc[idx2];
326 plmnIdInfo->list.array[idx1]->mnc.list.count = elementCnt;
327 plmnIdInfo->list.array[idx1]->mnc.list.size =\
328 elementCnt * sizeof(MCC_MNC_Digit_t);
329 DU_ALLOC(plmnIdInfo->list.array[idx1]->mnc.list.array,
330 plmnIdInfo->list.array[idx1]->mnc.list.size);
331 if(!plmnIdInfo->list.array[idx1]->mnc.list.array)
333 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
336 for(idx2=0; idx2<elementCnt; idx2++)
338 DU_ALLOC(plmnIdInfo->list.array[idx1]->mnc.list.array[idx2],
339 sizeof(MCC_MNC_Digit_t));
340 if(!plmnIdInfo->list.array[idx1]->mnc.list.array[idx2])
342 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
345 *(plmnIdInfo->list.array[idx1]->mnc.list.array[idx2])=\
346 duCfgParam.sib1Params.plmn.mnc[idx2];
349 /* Tracking Area Code */
350 tac = &cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode;
354 ranac = &cellAccessInfo->plmn_IdentityList.list.array[idx]->ranac;
359 &cellAccessInfo->plmn_IdentityList.list.array[idx]->cellIdentity;
360 BuildCellIdentity(cellIdentity);
362 /* cellReservedForOperatorUse */
363 cellAccessInfo->plmn_IdentityList.list.array[idx]->\
364 cellReservedForOperatorUse = \
365 duCfgParam.sib1Params.cellResvdForOpUse;
371 /*******************************************************************
373 * @brief Builds SIB message in Served Cell Info
377 * Function : BuildSib1Msg
379 * Functionality: Building SIB message in Served Cell Info
381 * @params[in] GNB_DU_System_Information *gnbDuSysInfo
382 * @return ROK - success
385 * ****************************************************************/
389 CellAccessRelatedInfo_t *cellAccessInfo;
392 asn_enc_rval_t encRetVal;
393 TrackingAreaCode_t *tac;
394 RAN_AreaCode_t *ranac;
395 CellIdentity_t *cellIdentity;
396 struct PLMN_IdentityInfo__plmn_IdentityList
399 DU_ALLOC(sib1Msg, sizeof(SIB1_t));
402 DU_LOG("DU APP: SIB1 msg memory allocation failure");
405 elementCnt = ODU_VALUE_ONE;
408 cellAccessInfo = &sib1Msg->cellAccessRelatedInfo;
409 cellAccessInfo->plmn_IdentityList.list.count =
411 cellAccessInfo->plmn_IdentityList.list.size
412 = elementCnt * sizeof(PLMN_IdentityInfo_t);
414 BuildPlmnList(cellAccessInfo);
416 xer_fprint(stdout, &asn_DEF_SIB1, sib1Msg);
418 /* Encode the F1SetupRequest type as APER */
419 cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN);
421 encRetVal = aper_encode(&asn_DEF_SIB1, 0, sib1Msg, PrepFinalEncBuf,\
423 printf("\nencbufSize: %d\n", encBufSize);
424 if(encRetVal.encoded == -1)
426 DU_LOG("\nDU APP : Could not encode SIB1 structure (at %s)\n",\
427 encRetVal.failed_type ?
428 encRetVal.failed_type->name :
432 for(int i=0; i< encBufSize; i++)
434 printf("%x\t",encBuf[i]);
438 /* Free allocated memeory */
441 for(idx=0; idx<cellAccessInfo->plmn_IdentityList.list.count; idx++)
443 plmnIdInfo = &cellAccessInfo->plmn_IdentityList.list.array[idx]->\
445 for(idx1=0; idx1<plmnIdInfo->list.count; idx1++)
447 for(idx2=0; idx2<plmnIdInfo->list.array[idx1]->mnc.list.count; idx2++)
449 DU_FREE(plmnIdInfo->list.array[idx1]->mcc->list.array[idx2],
450 sizeof(MCC_MNC_Digit_t));
451 DU_FREE(plmnIdInfo->list.array[idx1]->mnc.list.array[idx2],
452 sizeof(MCC_MNC_Digit_t));
454 DU_FREE(plmnIdInfo->list.array[idx1]->mcc->list.array,
455 plmnIdInfo->list.array[idx1]->mcc->list.size);
456 DU_FREE(plmnIdInfo->list.array[idx1]->mnc.list.array,
457 plmnIdInfo->list.array[idx1]->mnc.list.size);
458 DU_FREE(plmnIdInfo->list.array[idx1]->mcc,
460 DU_FREE(plmnIdInfo->list.array[idx1],
461 sizeof(PLMN_IdentitY_t));
463 DU_FREE(cellAccessInfo->plmn_IdentityList.list.array[idx],
464 sizeof(PLMN_IdentityInfo_t));
466 &cellAccessInfo->plmn_IdentityList.list.array[idx]->cellIdentity;
467 DU_FREE(cellIdentity->buf, cellIdentity->size);
469 ranac = cellAccessInfo->plmn_IdentityList.list.array[idx]->ranac;
470 DU_FREE(ranac, sizeof(RAN_AreaCode_t));
472 tac = cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode;
473 DU_FREE(tac->buf, tac->size);
474 DU_FREE(tac, sizeof(TrackingAreaCode_t));
476 DU_FREE(cellAccessInfo->plmn_IdentityList.list.array,
477 cellAccessInfo->plmn_IdentityList.list.size);
479 DU_FREE(sib1Msg, sizeof(SIB1_t));
484 /**********************************************************************
486 **********************************************************************/