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 */
23 #include "BCCH-BCH-Message.h"
26 #include "PLMN-IdentityInfo.h"
27 #include "PLMN-IdentitY.h"
29 #include "du_sys_info_hdl.h"
31 extern char encBuf[ENC_BUF_MAX_LEN];
33 extern DuCfgParams duCfgParam;
35 /*******************************************************************
43 * Functionality: Building MIB
45 * @return ROK - success
48 * ****************************************************************/
49 int BuildMib(MIB_t *mib)
51 mib->systemFrameNumber.size = sizeof(uint8_t);
52 DU_ALLOC(mib->systemFrameNumber.buf,
53 mib->systemFrameNumber.size);
54 if(!(mib->systemFrameNumber.buf))
56 DU_LOG("DU APP: MIB msg memory allocation failure");
60 *(mib->systemFrameNumber.buf) =
61 duCfgParam.mibParams.sysFrmNum;
62 mib->systemFrameNumber.bits_unused = ODU_VALUE_TWO;
64 mib->subCarrierSpacingCommon =\
65 duCfgParam.mibParams.subCarrierSpacingCommon;
66 mib->ssb_SubcarrierOffset =\
67 duCfgParam.mibParams.ssb_SubcarrierOffset;
68 mib->dmrs_TypeA_Position =\
69 duCfgParam.mibParams.dmrs_TypeA_Position;
70 mib->pdcch_ConfigSIB1.controlResourceSetZero = \
71 duCfgParam.mibParams.controlResourceSetZero;
72 mib->pdcch_ConfigSIB1.searchSpaceZero = \
73 duCfgParam.mibParams.searchSpaceZero;
74 mib->cellBarred = duCfgParam.mibParams.cellBarred;
75 mib->intraFreqReselection =
76 duCfgParam.mibParams.intraFreqReselection;
77 mib->spare.size = sizeof(uint8_t);
78 DU_ALLOC(mib->spare.buf,sizeof(uint8_t));
81 DU_LOG("DU APP: MIB msg memory allocation failure");
84 *(mib->spare.buf) = SPARE;
85 mib->spare.bits_unused = ODU_VALUE_SEVEN;
88 /*******************************************************************
90 * @brief Builds MIB PDU for broadcast
94 * Function : BuildMibPdu
96 * Functionality: Building MIB PDU for system broadcast
98 * @return ROK - success
101 * ****************************************************************/
104 BCCH_BCH_Message_t *bcchMsg;
105 asn_enc_rval_t encRetVal; /* Encoder return value */
107 DU_ALLOC(bcchMsg, sizeof(BCCH_BCH_Message_t));
110 DU_LOG("\nMemory allocation failure in BuildMibPdu");
114 bcchMsg->message.present = BCCH_BCH_MessageType_PR_mib;
115 DU_ALLOC(bcchMsg->message.choice.mib, sizeof(MIB_t));
116 if(!bcchMsg->message.choice.mib)
118 DU_LOG("\nMemory allocation failure in BuildMibPdu");
121 BuildMib(bcchMsg->message.choice.mib);
122 xer_fprint(stdout, &asn_DEF_BCCH_BCH_Message, bcchMsg);
123 cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN);
125 encRetVal = aper_encode(&asn_DEF_BCCH_BCH_Message, 0,
126 bcchMsg, PrepFinalEncBuf, encBuf);
127 printf("\nencbufSize:%d\n", encBufSize);
128 if(encRetVal.encoded == -1)
130 DU_LOG("\nDU APP: Could not encode BCCH BCH Message Type structure(at %s)\n",
131 encRetVal.failed_type?\
132 encRetVal.failed_type->name
137 /* Print encoded buffer */
138 for(int i=0; i< encBufSize; i++)
140 printf("%x\t",encBuf[i]);
144 /* Free allocated memory */
145 DU_FREE(bcchMsg->message.choice.mib->systemFrameNumber.buf,
146 bcchMsg->message.choice.mib->systemFrameNumber.size);
147 DU_FREE(bcchMsg->message.choice.mib->spare.buf,
148 bcchMsg->message.choice.mib->spare.size);
149 DU_FREE(bcchMsg->message.choice.mib, sizeof(MIB_t));
150 DU_FREE(bcchMsg, sizeof(BCCH_BCH_MessageType_t));
155 /*******************************************************************
157 * @brief Builds MIB message in Served Cell Info
161 * Function : BuildMibMsg
163 * Functionality: Building MIB message in Served Cell Info
165 * @return ROK - success
168 * ****************************************************************/
172 asn_enc_rval_t encRetVal; /* Encoder return value */
174 DU_ALLOC(mibMsg, sizeof(MIB_t));
177 DU_LOG("DU APP: MIB msg memory allocation failure");
182 xer_fprint(stdout, &asn_DEF_MIB, mibMsg);
183 cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN);
185 encRetVal = aper_encode(&asn_DEF_MIB, 0,
186 mibMsg, PrepFinalEncBuf, encBuf);
187 printf("\nencbufSize:%d\n", encBufSize);
188 if(encRetVal.encoded == -1)
190 DU_LOG("\nDU APP: Could not encode MIB structure(at %s)\n",
191 encRetVal.failed_type?\
192 encRetVal.failed_type->name
197 /* Print encoded buffer */
198 for(int i=0; i< encBufSize; i++)
200 printf("%x\t",encBuf[i]);
204 /* Free allocated memory */
205 DU_FREE(mibMsg->systemFrameNumber.buf,
206 mibMsg->systemFrameNumber.size);
207 DU_FREE(mibMsg->spare.buf, mibMsg->spare.size);
208 DU_FREE(mibMsg, sizeof(MIB_t));
214 /*******************************************************************
216 * @brief Builds CellIdentity within SIB1 message
220 * Function : BuildCellIdentity
222 * Functionality: Building RAN area code in SIB1 message
224 * @params[in] RAN_AreaCode_t **ranAreaCode
225 * @return ROK - success
228 * ****************************************************************/
229 int BuildCellIdentity(CellIdentity_t *cellIdentity)
231 cellIdentity->size = ODU_VALUE_FIVE*sizeof(uint8_t);
232 cellIdentity->bits_unused = ODU_VALUE_FOUR;
234 DU_ALLOC(cellIdentity->buf, cellIdentity->size);
235 if(!cellIdentity->buf)
237 DU_LOG("DU APP: CellIdentity memory allocation failure");
240 *cellIdentity->buf = duCfgParam.sib1Params.cellIdentity;
244 /*******************************************************************
246 * @brief Builds RANAC within SIB1 message
250 * Function : BuildRanac
252 * Functionality: Building RAN area code in SIB1 message
254 * @params[in] RAN_AreaCode_t **ranAreaCode
255 * @return ROK - success
258 * ****************************************************************/
259 int BuildRanac(RAN_AreaCode_t **ranAreaCode)
261 RAN_AreaCode_t *ranac;
262 DU_ALLOC(ranac, sizeof(RAN_AreaCode_t));
265 DU_LOG("DU APP: RANAC memory allocation failure");
268 *ranac = duCfgParam.sib1Params.ranac;
269 *ranAreaCode = ranac;
272 /*******************************************************************
274 * @brief Builds TAC within SIB1 message
278 * Function : BuildTac
280 * Functionality: Building Tracking area code in SIB1 message
282 * @params[in] TrackingAreaCode_t **tac
283 * @return ROK - success
286 * ****************************************************************/
287 int BuildTac(TrackingAreaCode_t **trackAreaCode)
289 TrackingAreaCode_t *tac;
292 DU_ALLOC(tac, sizeof(TrackingAreaCode_t));
295 DU_LOG("DU APP: TAC memory allocation failure");
299 tac->size = ODU_VALUE_THREE*sizeof(uint8_t);
300 DU_ALLOC(tac->buf, tac->size);
303 DU_LOG("DU APP: TAC memory allocation failure");
306 *(tac->buf) = duCfgParam.sib1Params.tac;
307 tac->bits_unused = ODU_VALUE_ZERO;
308 *trackAreaCode = tac;
313 /*******************************************************************
315 * @brief Builds PLMN list within SIB1 message
319 * Function : BuildPlmnList
321 * Functionality: Building PLMN list in SIB1 message
323 * @params[in] CellAccessRelatedInfo_t *cellAccessInfo
324 * @return ROK - success
327 * ****************************************************************/
328 int BuildPlmnList(CellAccessRelatedInfo_t *cellAccessInfo)
332 TrackingAreaCode_t **tac;
333 RAN_AreaCode_t **ranac;
334 CellIdentity_t *cellIdentity;
335 struct PLMN_IdentityInfo__plmn_IdentityList
338 DU_ALLOC(cellAccessInfo->plmn_IdentityList.list.array,
339 cellAccessInfo->plmn_IdentityList.list.size);
340 if(!cellAccessInfo->plmn_IdentityList.list.array)
342 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
345 elementCnt = cellAccessInfo->plmn_IdentityList.list.count;
346 for(idx=0; idx<elementCnt; idx++)
348 DU_ALLOC(cellAccessInfo->plmn_IdentityList.list.array[idx],
349 sizeof(PLMN_IdentityInfo_t));
350 if(!cellAccessInfo->plmn_IdentityList.list.array[idx])
352 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
359 elementCnt = ODU_VALUE_ONE;
361 plmnIdInfo = &cellAccessInfo->plmn_IdentityList.list.array[idx]->\
363 plmnIdInfo->list.count = elementCnt;
364 plmnIdInfo->list.size = elementCnt * sizeof(PLMN_IdentitY_t);
365 DU_ALLOC(plmnIdInfo->list.array, plmnIdInfo->list.size);
366 if(!plmnIdInfo->list.array)
368 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
371 for(idx1=0; idx1<elementCnt; idx1++)
373 DU_ALLOC(plmnIdInfo->list.array[idx1],
374 sizeof(PLMN_IdentitY_t));
375 if(!(plmnIdInfo->list.array[idx1]))
377 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
382 DU_ALLOC(plmnIdInfo->list.array[idx1]->mcc,
384 if(!plmnIdInfo->list.array[idx1]->mcc)
386 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
390 elementCnt = ODU_VALUE_THREE;
391 plmnIdInfo->list.array[idx1]->mcc->list.count = elementCnt;
392 plmnIdInfo->list.array[idx1]->mcc->list.size =\
393 elementCnt * sizeof(MCC_MNC_Digit_t);
394 DU_ALLOC(plmnIdInfo->list.array[idx1]->mcc->list.array,
395 plmnIdInfo->list.array[idx1]->mcc->list.size)
396 if(!(plmnIdInfo->list.array[idx1]->mcc->list.array))
398 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
401 for(idx2=0; idx2<elementCnt; idx2++)
403 DU_ALLOC(plmnIdInfo->list.array[idx1]->mcc->list.array[idx2],
404 sizeof(MCC_MNC_Digit_t));
405 if(!plmnIdInfo->list.array[idx1]->mcc->list.array[idx2])
407 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
410 *(plmnIdInfo->list.array[idx1]->mcc->list.array[idx2])=\
411 duCfgParam.sib1Params.plmn.mcc[idx2];
414 plmnIdInfo->list.array[idx1]->mnc.list.count = elementCnt;
415 plmnIdInfo->list.array[idx1]->mnc.list.size =\
416 elementCnt * sizeof(MCC_MNC_Digit_t);
417 DU_ALLOC(plmnIdInfo->list.array[idx1]->mnc.list.array,
418 plmnIdInfo->list.array[idx1]->mnc.list.size);
419 if(!plmnIdInfo->list.array[idx1]->mnc.list.array)
421 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
424 for(idx2=0; idx2<elementCnt; idx2++)
426 DU_ALLOC(plmnIdInfo->list.array[idx1]->mnc.list.array[idx2],
427 sizeof(MCC_MNC_Digit_t));
428 if(!plmnIdInfo->list.array[idx1]->mnc.list.array[idx2])
430 DU_LOG("DU APP: BuildPlmnList memory allocation failure");
433 *(plmnIdInfo->list.array[idx1]->mnc.list.array[idx2])=\
434 duCfgParam.sib1Params.plmn.mnc[idx2];
437 /* Tracking Area Code */
438 tac = &cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode;
442 ranac = &cellAccessInfo->plmn_IdentityList.list.array[idx]->ranac;
447 &cellAccessInfo->plmn_IdentityList.list.array[idx]->cellIdentity;
448 BuildCellIdentity(cellIdentity);
450 /* cellReservedForOperatorUse */
451 cellAccessInfo->plmn_IdentityList.list.array[idx]->\
452 cellReservedForOperatorUse = \
453 duCfgParam.sib1Params.cellResvdForOpUse;
459 /*******************************************************************
461 * @brief Builds SIB message in Served Cell Info
465 * Function : BuildSib1Msg
467 * Functionality: Building SIB message in Served Cell Info
469 * @return ROK - success
472 * ****************************************************************/
476 CellAccessRelatedInfo_t *cellAccessInfo;
479 asn_enc_rval_t encRetVal;
480 TrackingAreaCode_t *tac;
481 RAN_AreaCode_t *ranac;
482 CellIdentity_t *cellIdentity;
483 struct PLMN_IdentityInfo__plmn_IdentityList
486 DU_ALLOC(sib1Msg, sizeof(SIB1_t));
489 DU_LOG("DU APP: SIB1 msg memory allocation failure");
492 elementCnt = ODU_VALUE_ONE;
495 cellAccessInfo = &sib1Msg->cellAccessRelatedInfo;
496 cellAccessInfo->plmn_IdentityList.list.count =
498 cellAccessInfo->plmn_IdentityList.list.size
499 = elementCnt * sizeof(PLMN_IdentityInfo_t);
501 BuildPlmnList(cellAccessInfo);
503 xer_fprint(stdout, &asn_DEF_SIB1, sib1Msg);
505 /* Encode the F1SetupRequest type as APER */
506 cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN);
508 encRetVal = aper_encode(&asn_DEF_SIB1, 0, sib1Msg, PrepFinalEncBuf,\
510 printf("\nencbufSize: %d\n", encBufSize);
511 if(encRetVal.encoded == -1)
513 DU_LOG("\nDU APP : Could not encode SIB1 structure (at %s)\n",\
514 encRetVal.failed_type ?
515 encRetVal.failed_type->name :
519 for(int i=0; i< encBufSize; i++)
521 printf("%x\t",encBuf[i]);
525 /* Free allocated memeory */
528 for(idx=0; idx<cellAccessInfo->plmn_IdentityList.list.count; idx++)
530 plmnIdInfo = &cellAccessInfo->plmn_IdentityList.list.array[idx]->\
532 for(idx1=0; idx1<plmnIdInfo->list.count; idx1++)
534 for(idx2=0; idx2<plmnIdInfo->list.array[idx1]->mnc.list.count; idx2++)
536 DU_FREE(plmnIdInfo->list.array[idx1]->mcc->list.array[idx2],
537 sizeof(MCC_MNC_Digit_t));
538 DU_FREE(plmnIdInfo->list.array[idx1]->mnc.list.array[idx2],
539 sizeof(MCC_MNC_Digit_t));
541 DU_FREE(plmnIdInfo->list.array[idx1]->mcc->list.array,
542 plmnIdInfo->list.array[idx1]->mcc->list.size);
543 DU_FREE(plmnIdInfo->list.array[idx1]->mnc.list.array,
544 plmnIdInfo->list.array[idx1]->mnc.list.size);
545 DU_FREE(plmnIdInfo->list.array[idx1]->mcc,
547 DU_FREE(plmnIdInfo->list.array[idx1],
548 sizeof(PLMN_IdentitY_t));
550 DU_FREE(cellAccessInfo->plmn_IdentityList.list.array[idx],
551 sizeof(PLMN_IdentityInfo_t));
553 &cellAccessInfo->plmn_IdentityList.list.array[idx]->cellIdentity;
554 DU_FREE(cellIdentity->buf, cellIdentity->size);
556 ranac = cellAccessInfo->plmn_IdentityList.list.array[idx]->ranac;
557 DU_FREE(ranac, sizeof(RAN_AreaCode_t));
559 tac = cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode;
560 DU_FREE(tac->buf, tac->size);
561 DU_FREE(tac, sizeof(TrackingAreaCode_t));
563 DU_FREE(cellAccessInfo->plmn_IdentityList.list.array,
564 cellAccessInfo->plmn_IdentityList.list.size);
566 DU_FREE(sib1Msg, sizeof(SIB1_t));
571 /**********************************************************************
573 **********************************************************************/