1 /*****************************************************************************
3 # Copyright 2019 AT&T Intellectual Property *
4 # Copyright 2019 Nokia *
6 # Licensed under the Apache License, Version 2.0 (the "License"); *
7 # you may not use this file except in compliance with the License. *
8 # You may obtain a copy of the License at *
10 # http://www.apache.org/licenses/LICENSE-2.0 *
12 # Unless required by applicable law or agreed to in writing, software *
13 # distributed under the License is distributed on an "AS IS" BASIS, *
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15 # See the License for the specific language governing permissions and *
16 # limitations under the License. *
18 ******************************************************************************/
19 #include "asn_e2ap.hpp"
20 #include "asn_e2ap_wrapper.hpp"
22 /*-----------------------------------------------------------------------
24 -------------------------------------------------------------------------
26 e2ap_pdu_t* new_e2ap_pdu(void)
28 E2APpduWrapper* pduWrapper = new E2APpduWrapper();
29 return reinterpret_cast<e2ap_pdu_t*>(pduWrapper);
32 void e2ap_asn_print(e2ap_pdu_t* pdu, char* buf, size_t buf_size)
34 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
38 strncat(buf, asn::get_printed(pduWrapper->ref_pdu()).c_str(), buf_size - 1);
41 int e2ap_asn_per_encode(e2ap_pdu_t* pdu, unsigned char* buf, size_t buf_size,
42 char* err_buf, size_t err_buf_size)
44 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
46 asn::per::EncoderCtx ctx{ buf, buf_size };
48 if (!asn::per::pack(pduWrapper->ref_pdu(), ctx)) {
50 //strncat(err_buf, ctx.refErrorCtx().toString().c_str(), err_buf_size - 1);
53 return static_cast<int>(ctx.refBuffer().getBytesUsed());
58 int e2ap_asn_per_decode(e2ap_pdu_t* pdu, unsigned char const* buf, size_t buf_size,
59 char* err_buf, size_t err_buf_size)
61 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
63 asn::per::DecoderCtx ctx{ buf,
65 pduWrapper->m_allocation_buffer,
66 pduWrapper->m_allocation_buffer_size };
68 if (!asn::per::unpack(pduWrapper->ref_pdu(), ctx)) {
70 //strncat(err_buf, ctx.refErrorCtx().toString().c_str(), err_buf_size - 1);
78 int e2ap_get_index(e2ap_pdu_t* pdu)
80 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
82 return pduWrapper->ref_pdu().get_index();
85 int e2ap_get_procedureCode(e2ap_pdu_t* pdu)
87 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
89 switch(pduWrapper->ref_pdu().get_index())
92 return pduWrapper->ref_pdu().get_initiatingMessage()->ref_procedureCode().get();
96 return pduWrapper->ref_pdu().get_successfulOutcome()->ref_procedureCode().get();
100 return pduWrapper->ref_pdu().get_unsuccessfulOutcome()->ref_procedureCode().get();
109 /*-----------------------------------------------------------------------
111 -------------------------------------------------------------------------
114 bool e2ap_init_X2SetupRequest(e2ap_pdu_t* pdu)
116 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
119 pduWrapper->ref_pdu().select_initiatingMessage();
120 pduWrapper->ref_pdu().select_initiatingMessage().clear();
121 pduWrapper->ref_pdu().select_initiatingMessage().ref_procedureCode().select_id_x2Setup();
122 pduWrapper->ref_pdu().select_initiatingMessage().ref_criticality().select_id_x2Setup();
123 pduWrapper->ref_pdu().select_initiatingMessage().ref_value().select_id_x2Setup();
128 bool e2ap_create_X2SetupRequest(e2ap_pdu_t* pdu, eNB_config &cfg)
130 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
133 pduWrapper->ref_pdu().select_initiatingMessage().ref_procedureCode().select_id_x2Setup();
134 pduWrapper->ref_pdu().select_initiatingMessage().ref_criticality().select_id_x2Setup();
136 X2SetupRequest* container =
137 &(pduWrapper->ref_pdu().select_initiatingMessage().ref_value().select_id_x2Setup());
139 using IE_value_t = X2SetupRequest::protocolIEs_t::value_type;
141 /* X2SetupRequest-IEs : GlobalENB-ID*/
142 IE_value_t* val_GlobalENB_ID = new IE_value_t;
143 container->ref_protocolIEs().push_back(*val_GlobalENB_ID);
145 val_GlobalENB_ID->ref_id().select_id_GlobalENB_ID();
146 val_GlobalENB_ID->ref_criticality().select_id_GlobalENB_ID();
147 val_GlobalENB_ID->ref_value().select_id_GlobalENB_ID().ref_pLMN_Identity()
148 .set(3, cfg.pLMN_Identity);
149 val_GlobalENB_ID->ref_value().select_id_GlobalENB_ID().ref_eNB_ID()
150 .select_macro_eNB_ID().set_buffer(20, cfg.macro_eNB_ID);
152 /* X2SetupRequest-IEs : ServedCells*/
153 IE_value_t* val_ServedCells = new IE_value_t;
154 container->ref_protocolIEs().push_back(*val_ServedCells);
156 val_ServedCells->ref_id().select_id_ServedCells();
157 val_ServedCells->ref_criticality().select_id_ServedCells();
158 val_ServedCells->ref_value().select_id_ServedCells();
161 ServedCells::value_type* elm = new ServedCells::value_type();
162 ServedCell_Information* info = &(elm->ref_servedCellInfo());
164 //Set ServedCell-Information: pCI, cellId, tAC, broadcastPLMNs, eUTRA-Mode-Info
165 info->ref_pCI().set(cfg.pCI);
166 info->ref_cellId().ref_pLMN_Identity().set(3, cfg.pLMN_Identity);
167 info->ref_cellId().ref_eUTRANcellIdentifier().set_buffer(28, cfg.eUTRANcellIdentifier);
168 info->ref_tAC().set(2, cfg.tAC);
170 BroadcastPLMNs_Item::value_type* item = new BroadcastPLMNs_Item::value_type();
171 item->set(3, cfg.pLMN_Identity);
172 info->ref_broadcastPLMNs().push_back(*item);
174 info->ref_eUTRA_Mode_Info().select_fDD().ref_uL_EARFCN().set(cfg.uL_EARFCN);
175 info->ref_eUTRA_Mode_Info().select_fDD().ref_dL_EARFCN().set(cfg.dL_EARFCN);
176 info->ref_eUTRA_Mode_Info().select_fDD().ref_uL_Transmission_Bandwidth()
177 .set(static_cast<Transmission_Bandwidth::index_t>(cfg.uL_Bandwidth));
178 info->ref_eUTRA_Mode_Info().select_fDD().ref_dL_Transmission_Bandwidth()
179 .set(static_cast<Transmission_Bandwidth::index_t>(cfg.dL_Bandwidth));
181 val_ServedCells->ref_value().select_id_ServedCells().push_back(*elm);
186 bool e2ap_create_X2SetupResponse(e2ap_pdu_t* pdu, eNB_config &cfg)
188 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
191 pduWrapper->ref_pdu().select_successfulOutcome().ref_procedureCode().select_id_x2Setup();
192 pduWrapper->ref_pdu().select_successfulOutcome().ref_criticality().select_id_x2Setup();
194 X2SetupResponse* container =
195 &(pduWrapper->ref_pdu().select_successfulOutcome().ref_value().select_id_x2Setup());
197 using IE_value_t = X2SetupResponse::protocolIEs_t::value_type;
199 /* X2SetupResponse-IEs : GlobalENB-ID*/
200 IE_value_t* val_GlobalENB_ID = new IE_value_t;
201 container->ref_protocolIEs().push_back(*val_GlobalENB_ID);
203 val_GlobalENB_ID->ref_id().select_id_GlobalENB_ID();
204 val_GlobalENB_ID->ref_criticality().select_id_GlobalENB_ID();
205 val_GlobalENB_ID->ref_value().select_id_GlobalENB_ID().ref_pLMN_Identity()
206 .set(3, cfg.pLMN_Identity);
208 val_GlobalENB_ID->ref_value().select_id_GlobalENB_ID().ref_eNB_ID()
209 .select_macro_eNB_ID().set_buffer(20, cfg.macro_eNB_ID);
211 /* X2SetupResponse-IEs : ServedCells*/
212 IE_value_t* val_ServedCells = new IE_value_t;
213 container->ref_protocolIEs().push_back(*val_ServedCells);
215 val_ServedCells->ref_id().select_id_ServedCells();
216 val_ServedCells->ref_criticality().select_id_ServedCells();
217 val_ServedCells->ref_value().select_id_ServedCells();
220 ServedCells::value_type* elm = new ServedCells::value_type();
221 ServedCell_Information* info = &(elm->ref_servedCellInfo());
223 //Set ServedCell-Information: pCI, cellId, tAC, broadcastPLMNs, eUTRA-Mode-Info
224 info->ref_pCI().set(cfg.pCI);
225 info->ref_cellId().ref_pLMN_Identity().set(3, cfg.pLMN_Identity);
226 info->ref_cellId().ref_eUTRANcellIdentifier().set_buffer(28, cfg.eUTRANcellIdentifier);
227 info->ref_tAC().set(2, cfg.tAC);
229 BroadcastPLMNs_Item::value_type* item = new BroadcastPLMNs_Item::value_type();
230 item->set(3, cfg.pLMN_Identity);
231 info->ref_broadcastPLMNs().push_back(*item);
233 info->ref_eUTRA_Mode_Info().select_fDD().ref_uL_EARFCN().set(cfg.uL_EARFCN);
234 info->ref_eUTRA_Mode_Info().select_fDD().ref_dL_EARFCN().set(cfg.dL_EARFCN);
235 info->ref_eUTRA_Mode_Info().select_fDD().ref_uL_Transmission_Bandwidth()
236 .set(static_cast<Transmission_Bandwidth::index_t>(cfg.uL_Bandwidth));
237 info->ref_eUTRA_Mode_Info().select_fDD().ref_dL_Transmission_Bandwidth()
238 .set(static_cast<Transmission_Bandwidth::index_t>(cfg.dL_Bandwidth));
240 val_ServedCells->ref_value().select_id_ServedCells().push_back(*elm);
245 bool e2ap_create_X2SetupFailure(e2ap_pdu_t* pdu)
247 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
250 pduWrapper->ref_pdu().select_unsuccessfulOutcome().ref_procedureCode().select_id_x2Setup();
251 pduWrapper->ref_pdu().select_unsuccessfulOutcome().ref_criticality().select_id_x2Setup();
253 X2SetupFailure* container =
254 &(pduWrapper->ref_pdu().select_unsuccessfulOutcome().ref_value().select_id_x2Setup());
256 using IE_value_t = X2SetupFailure::protocolIEs_t::value_type;
258 /* X2SetupFailure-IEs << id-Cause */
259 IE_value_t* val_cause = new IE_value_t;
260 container->ref_protocolIEs().push_back(*val_cause);
262 val_cause->ref_id().select_id_Cause();
263 val_cause->ref_criticality().select_id_Cause();
265 /* Cause << radioNetwork */
266 val_cause->ref_value().select_id_Cause().select_radioNetwork();
268 /* CauseRadioNetwork = ho-target-not-allowed (enum = 8)*/
269 val_cause->ref_value().select_id_Cause().select_radioNetwork()
270 .set(static_cast<CauseRadioNetwork::index_t>(8));
276 bool e2ap_create_ENDCX2SetupRequest(e2ap_pdu_t* pdu, eNB_config &cfg)
278 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
281 pduWrapper->ref_pdu().select_initiatingMessage().ref_procedureCode().select_id_endcX2Setup();
282 pduWrapper->ref_pdu().select_initiatingMessage().ref_criticality().select_id_endcX2Setup();
284 ENDCX2SetupRequest* container =
285 &(pduWrapper->ref_pdu().select_initiatingMessage().ref_value().select_id_endcX2Setup());
287 using IE_value_t = ENDCX2SetupRequest::protocolIEs_t::value_type;
289 /* ENDCX2SetupRequest-IEs = id-InitiatingNodeType-EndcX2Setup */
290 IE_value_t* ie = new IE_value_t;
291 container->ref_protocolIEs().push_back(*ie);
292 ie->ref_id().select_id_InitiatingNodeType_EndcX2Setup();
293 ie->ref_criticality().select_id_InitiatingNodeType_EndcX2Setup();
294 ie->ref_value().select_id_InitiatingNodeType_EndcX2Setup();
296 /* InitiatingNodeType-EndcX2Setup = init-eNB {ENB-ENDCX2SetupReqIEs} */
297 ie->ref_value().select_id_InitiatingNodeType_EndcX2Setup().select_init_eNB();
299 using eNB_val_t = InitiatingNodeType_EndcX2Setup::init_eNB_t::value_type;
301 ProtocolIE_Container<ENB_ENDCX2SetupReqIEs>* eNB_node =
302 &(ie->ref_value().select_id_InitiatingNodeType_EndcX2Setup().select_init_eNB());
304 /* ENB-ENDCX2SetupReqIEs <-- id-GlobalENB-ID */
305 eNB_val_t* val_GlobalENB_ID = new eNB_val_t;
306 eNB_node->push_back(*val_GlobalENB_ID);
308 val_GlobalENB_ID->ref_id().select_id_GlobalENB_ID();
309 val_GlobalENB_ID->ref_criticality().select_id_GlobalENB_ID();
310 val_GlobalENB_ID->ref_value().select_id_GlobalENB_ID()
311 .ref_pLMN_Identity().set(3, cfg.pLMN_Identity);
312 val_GlobalENB_ID->ref_value().select_id_GlobalENB_ID().ref_eNB_ID()
313 .select_macro_eNB_ID().set_buffer(20, cfg.macro_eNB_ID);
315 /* ENB-ENDCX2SetupReqIEs <-- id-ServedEUTRAcellsENDCX2ManagementList */
316 eNB_val_t* val_EUTRAlist = new eNB_val_t;
317 eNB_node->push_back(*val_EUTRAlist);
319 val_EUTRAlist->ref_id().select_id_ServedEUTRAcellsENDCX2ManagementList();
320 val_EUTRAlist->ref_criticality().select_id_ServedEUTRAcellsENDCX2ManagementList();
321 val_EUTRAlist->ref_value().select_id_ServedEUTRAcellsENDCX2ManagementList();
323 /* ServedEUTRAcellsENDCX2ManagementList <-- servedEUTRACellInfo */
324 ServedEUTRAcellsENDCX2ManagementList::value_type* elm =
325 new ServedEUTRAcellsENDCX2ManagementList::value_type();
326 ServedCell_Information* info = &(elm->ref_servedEUTRACellInfo());
328 //Set ServedCell-Information: pCI, cellId, tAC, broadcastPLMNs, eUTRA-Mode-Info
329 info->ref_pCI().set(cfg.pCI);
330 info->ref_cellId().ref_pLMN_Identity().set(3, cfg.pLMN_Identity);
331 info->ref_cellId().ref_eUTRANcellIdentifier().set_buffer(28, cfg.eUTRANcellIdentifier);
332 info->ref_tAC().set(2, cfg.tAC);
334 BroadcastPLMNs_Item::value_type* item = new BroadcastPLMNs_Item::value_type();
335 item->set(3, cfg.pLMN_Identity);
336 info->ref_broadcastPLMNs().push_back(*item);
338 info->ref_eUTRA_Mode_Info().select_fDD().ref_uL_EARFCN().set(cfg.uL_EARFCN);
339 info->ref_eUTRA_Mode_Info().select_fDD().ref_dL_EARFCN().set(cfg.dL_EARFCN);
340 info->ref_eUTRA_Mode_Info().select_fDD().ref_uL_Transmission_Bandwidth()
341 .set(static_cast<Transmission_Bandwidth::index_t>(cfg.uL_Bandwidth));
342 info->ref_eUTRA_Mode_Info().select_fDD().ref_dL_Transmission_Bandwidth()
343 .set(static_cast<Transmission_Bandwidth::index_t>(cfg.dL_Bandwidth));
345 val_EUTRAlist->ref_value().select_id_ServedEUTRAcellsENDCX2ManagementList()
351 bool e2ap_create_ENDCX2SetupResponse(e2ap_pdu_t* pdu, gNB_config &gnb_cfg)
353 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
356 pduWrapper->ref_pdu().select_successfulOutcome().ref_procedureCode().select_id_endcX2Setup();
357 pduWrapper->ref_pdu().select_successfulOutcome().ref_criticality().select_id_endcX2Setup();
359 ENDCX2SetupResponse* container =
360 &(pduWrapper->ref_pdu().select_successfulOutcome().ref_value().select_id_endcX2Setup());
362 using IE_value_t = ENDCX2SetupResponse::protocolIEs_t::value_type;
364 /* ENDCX2SetupRequest-IEs = id-RespondingNodeType-EndcX2Setup */
365 IE_value_t* ie = new IE_value_t;
366 container->ref_protocolIEs().push_back(*ie);
367 ie->ref_id().select_id_RespondingNodeType_EndcX2Setup();
368 ie->ref_criticality().select_id_RespondingNodeType_EndcX2Setup();
369 ie->ref_value().select_id_RespondingNodeType_EndcX2Setup();
371 /* RespondingNodeType-EndcX2Setup = respond-en-gNB {En-gNB-ENDCX2SetupReqAckIEs} */
372 ie->ref_value().select_id_RespondingNodeType_EndcX2Setup().select_respond_en_gNB();
374 using gNB_val_t = RespondingNodeType_EndcX2Setup::respond_en_gNB_t::value_type;
376 ProtocolIE_Container<En_gNB_ENDCX2SetupReqAckIEs>* gNB_node =
377 &(ie->ref_value().select_id_RespondingNodeType_EndcX2Setup().select_respond_en_gNB());
379 /* En-gNB-ENDCX2SetupReqAckIEs << id-Globalen-gNB-ID */
380 gNB_val_t* val_Globalen_gNB_ID = new gNB_val_t;
381 gNB_node->push_back(*val_Globalen_gNB_ID);
383 val_Globalen_gNB_ID->ref_id().select_id_Globalen_gNB_ID();
384 val_Globalen_gNB_ID->ref_criticality().select_id_Globalen_gNB_ID();
385 val_Globalen_gNB_ID->ref_value().select_id_Globalen_gNB_ID()
386 .ref_pLMN_Identity().set(3, gnb_cfg.pLMN_Identity);
387 val_Globalen_gNB_ID->ref_value().select_id_Globalen_gNB_ID().ref_gNB_ID()
388 .select_gNB_ID().set_buffer(22, gnb_cfg.gNB_ID);
390 /* En-gNB-ENDCX2SetupReqAckIEs << id-ServedNRcellsENDCX2ManagementList */
391 gNB_val_t* val_ServedNRCells = new gNB_val_t;
392 gNB_node->push_back(*val_ServedNRCells);
394 val_ServedNRCells->ref_id().select_id_ServedNRcellsENDCX2ManagementList();
395 val_ServedNRCells->ref_criticality().select_id_ServedNRcellsENDCX2ManagementList();
396 val_ServedNRCells->ref_value().select_id_ServedNRcellsENDCX2ManagementList();
398 /* ServedNRcellsENDCX2ManagementList <-- servedNRCellInfo*/
399 ServedNRcellsENDCX2ManagementList::value_type* elm =
400 new ServedNRcellsENDCX2ManagementList::value_type();
403 ServedNRCell-Information ::= SEQUENCE {
406 fiveGS-TAC FiveGS-TAC OPTIONAL,
407 configured-TAC TAC OPTIONAL,
408 broadcastPLMNs BroadcastPLMNs-Item,
410 fdd FDD-InfoServedNRCell-Information,
411 tdd TDD-InfoServedNRCell-Information,
414 measurementTimingConfiguration OCTET STRING,
415 iE-Extensions ProtocolExtensionContainer { {ServedNRCell-Information-ExtIEs} } OPTIONAL,
419 ServedNRCell_Information* info = &(elm->ref_servedNRCellInfo());
422 info->ref_nrpCI().set(gnb_cfg.nrpCI);
427 pLMN-Identity PLMN-Identity,
428 nRcellIdentifier NRCellIdentifier,
429 iE-Extensions ProtocolExtensionContainer { {NRCGI-ExtIEs} } OPTIONAL,
433 info->ref_nrCellID().ref_pLMN_Identity().set(3, gnb_cfg.pLMN_Identity);
434 info->ref_nrCellID().ref_nRcellIdentifier().set_buffer(36, gnb_cfg.nRcellIdentifier);
436 /* broadcastPLMNs BroadcastPLMNs-Item */
437 BroadcastPLMNs_Item::value_type* item = new BroadcastPLMNs_Item::value_type();
438 item->set(3, gnb_cfg.pLMN_Identity);
439 info->ref_broadcastPLMNs().push_back(*item);
441 /* nrModeInfo CHOICE {
442 fdd FDD-InfoServedNRCell-Information,
443 tdd TDD-InfoServedNRCell-Information,
447 FDD-InfoServedNRCell-Information ::= SEQUENCE {
448 ul-NRFreqInfo NRFreqInfo,
449 dl-NRFreqInfo NRFreqInfo,
452 iE-Extensions ProtocolExtensionContainer { {FDD-InfoServedNRCell-Information-ExtIEs} } OPTIONAL,
456 NRFreqInfo ::= SEQUENCE{
457 nRARFCN INTEGER (0.. 3279165),
458 freqBandListNr SEQUENCE (SIZE(1..maxnoofNrCellBands)) OF FreqBandNrItem,
459 sULInformation SULInformation OPTIONAL,
460 iE-Extensions ProtocolExtensionContainer { {NRFreqInfo-ExtIEs} } OPTIONAL,
466 info->ref_nrModeInfo().select_fdd().ref_ul_NRFreqInfo().ref_nRARFCN().set(gnb_cfg.uL_nRARFCN);
467 info->ref_nrModeInfo().select_fdd().ref_dl_NRFreqInfo().ref_nRARFCN().set(gnb_cfg.dL_nRARFCN);
470 FreqBandNrItem ::= SEQUENCE {
471 freqBandIndicatorNr INTEGER (1..1024,...),
472 supportedSULBandList SEQUENCE (SIZE(0..maxnoofNrCellBands)) OF SupportedSULFreqBandItem,
473 iE-Extensions ProtocolExtensionContainer { {FreqBandNrItem-ExtIEs} } OPTIONAL,
478 asn::sequenceof<NRFreqInfo::freqBandListNr_t_elm>::value_type* ul_band_item =
479 new asn::sequenceof<NRFreqInfo::freqBandListNr_t_elm>::value_type();
481 ul_band_item->ref_freqBandIndicatorNr().set(gnb_cfg.ul_freqBandIndicatorNr);
484 SupportedSULFreqBandItem ::= SEQUENCE {
485 freqBandIndicatorNr INTEGER (1..1024,...),
486 iE-Extensions ProtocolExtensionContainer { {SupportedSULFreqBandItem-ExtIEs} } OPTIONAL,
491 asn::sequenceof<FreqBandNrItem::supportedSULBandList_t_elm>::value_type* ul_supported_band_item =
492 new asn::sequenceof<FreqBandNrItem::supportedSULBandList_t_elm>::value_type();
494 ul_supported_band_item->ref_freqBandIndicatorNr().set(gnb_cfg.ul_freqBandIndicatorNr);
496 ul_band_item->ref_supportedSULBandList().push_back(*ul_supported_band_item);
498 info->ref_nrModeInfo().select_fdd().ref_ul_NRFreqInfo()
499 .ref_freqBandListNr().push_back(*ul_band_item);
502 asn::sequenceof<NRFreqInfo::freqBandListNr_t_elm>::value_type* dl_band_item =
503 new asn::sequenceof<NRFreqInfo::freqBandListNr_t_elm>::value_type();
505 dl_band_item->ref_freqBandIndicatorNr().set(gnb_cfg.dl_freqBandIndicatorNr);
508 SupportedSULFreqBandItem ::= SEQUENCE {
509 freqBandIndicatorNr INTEGER (1..1024,...),
510 iE-Extensions ProtocolExtensionContainer { {SupportedSULFreqBandItem-ExtIEs} } OPTIONAL,
515 asn::sequenceof<FreqBandNrItem::supportedSULBandList_t_elm>::value_type* dl_supported_band_item =
516 new asn::sequenceof<FreqBandNrItem::supportedSULBandList_t_elm>::value_type();
518 dl_supported_band_item->ref_freqBandIndicatorNr().set(gnb_cfg.dl_freqBandIndicatorNr);
520 dl_band_item->ref_supportedSULBandList().push_back(*dl_supported_band_item);
522 info->ref_nrModeInfo().select_fdd().ref_dl_NRFreqInfo()
523 .ref_freqBandListNr().push_back(*dl_band_item);
526 NR-TxBW ::= SEQUENCE {
529 iE-Extensions ProtocolExtensionContainer { {NR-TxBW-ExtIEs} } OPTIONAL,
534 info->ref_nrModeInfo().select_fdd().ref_ul_NR_TxBW().ref_nRNRB()
535 .set( static_cast<NRNRB::index_t>(gnb_cfg.uL_NRNRB) );
536 info->ref_nrModeInfo().select_fdd().ref_ul_NR_TxBW().ref_nRSCS()
537 .set( static_cast<NRSCS::index_t>(gnb_cfg.uL_NRSCS) );
539 info->ref_nrModeInfo().select_fdd().ref_dl_NR_TxBW().ref_nRNRB()
540 .set( static_cast<NRNRB::index_t>(gnb_cfg.dL_NRNRB) );
541 info->ref_nrModeInfo().select_fdd().ref_dl_NR_TxBW().ref_nRSCS()
542 .set( static_cast<NRSCS::index_t>(gnb_cfg.dL_NRSCS) );
546 measurementTimingConfiguration OCTET STRING,
548 info->ref_measurementTimingConfiguration().set(gnb_cfg.measurementTimingConfiguration);
550 val_ServedNRCells->ref_value().select_id_ServedNRcellsENDCX2ManagementList().push_back(*elm);
557 bool e2ap_create_ENDCX2SetupFailure(e2ap_pdu_t* pdu)
560 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
563 pduWrapper->ref_pdu().select_unsuccessfulOutcome().ref_procedureCode().select_id_endcX2Setup();
564 pduWrapper->ref_pdu().select_unsuccessfulOutcome().ref_criticality().select_id_endcX2Setup();
566 ENDCX2SetupFailure* container =
567 &(pduWrapper->ref_pdu().select_unsuccessfulOutcome().ref_value().select_id_endcX2Setup());
569 using IE_value_t = ENDCX2SetupFailure::protocolIEs_t::value_type;
571 /* ENDCX2SetupFailure-IEs := id-Cause*/
572 IE_value_t* val_cause = new IE_value_t;
573 container->ref_protocolIEs().push_back(*val_cause);
575 val_cause->ref_id().select_id_Cause();
576 val_cause->ref_criticality().select_id_Cause();
578 /* Cause << radioNetwork */
579 val_cause->ref_value().select_id_Cause().select_radioNetwork();
581 /* CauseRadioNetwork = ho-target-not-allowed (enum = 8)*/
582 val_cause->ref_value().select_id_Cause().select_radioNetwork()
583 .set(static_cast<CauseRadioNetwork::index_t>(8));
589 bool e2ap_create_RICsubscriptionRequest(e2ap_pdu_t* pdu, RICsubscription_params_t ¶ms)
591 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
594 pduWrapper->ref_pdu().select_initiatingMessage()
595 .ref_procedureCode().select_id_ricSubscription();
596 pduWrapper->ref_pdu().select_initiatingMessage()
597 .ref_criticality().select_id_ricSubscription();
599 RICsubscriptionRequest* container = &(pduWrapper->ref_pdu()
600 .select_initiatingMessage().ref_value().select_id_ricSubscription());
602 using IE_value_t = RICsubscriptionRequest::protocolIEs_t::value_type;
604 /* RICsubscriptionRequest-IEs : RICrequestID */
605 IE_value_t* ie_RICrequestID = new IE_value_t;
606 container->ref_protocolIEs().push_back(*ie_RICrequestID);
608 ie_RICrequestID->ref_id().select_id_RICrequestID();
609 ie_RICrequestID->ref_criticality().select_id_RICrequestID();
610 ie_RICrequestID->ref_value().select_id_RICrequestID()
611 .ref_ricRequestorID().set(params.request_id);
612 ie_RICrequestID->ref_value().select_id_RICrequestID()
613 .ref_ricRequestSequenceNumber().set(params.seq_number);
615 /* RICsubscriptionRequest-IEs : RANfunctionID */
616 IE_value_t* ie_RANfunctionID = new IE_value_t;
617 container->ref_protocolIEs().push_back(*ie_RANfunctionID);
619 ie_RANfunctionID->ref_id().select_id_RANfunctionID();
620 ie_RANfunctionID->ref_criticality().select_id_RANfunctionID();
621 ie_RANfunctionID->ref_value().select_id_RANfunctionID().set(params.ran_func_id);
625 RICsubscription ::= SEQUENCE {
626 ricEventTriggerDefinition RICeventTriggerDefinition,
627 ricAction-ToBeSetup-List RICactions-ToBeSetup-List,
631 RICeventTriggerDefinition ::= OCTET STRING
632 RICactions-ToBeSetup-List ::= SEQUENCE (SIZE(1..maxofRICactionID)) OF ProtocolIE-Single-Container { {RICaction-ToBeSetup-ItemIEs} }
634 RICaction-ToBeSetup-ItemIEs X2AP-PROTOCOL-IES ::= {
635 { ID id-RICaction-ToBeSetup-Item CRITICALITY ignore TYPE RICaction-ToBeSetup-Item PRESENCE mandatory },
639 RICaction-ToBeSetup-Item ::= SEQUENCE {
640 ricActionID RICactionID,
641 ricActionType RICactionType,
642 ricActionDefinition RICactionDefinition OPTIONAL,
643 ricSubsequentAction RICsubsequentAction OPTIONAL,
647 RICactionID ::= INTEGER (0..255)
649 RICactionType ::= ENUMERATED{
657 /* RICsubscriptionRequest-IEs : RICsubscription */
658 IE_value_t* ie_RICsubscription = new IE_value_t;
659 container->ref_protocolIEs().push_back(*ie_RICsubscription);
661 ie_RICsubscription->ref_id().select_id_RICsubscription();
662 ie_RICsubscription->ref_criticality().select_id_RICsubscription();
664 // RICeventTriggerDefinition
665 ie_RICsubscription->ref_value().select_id_RICsubscription()
666 .ref_ricEventTriggerDefinition().set<std::string>(params.event_trigger_def);
668 //RICactions-ToBeSetup-List
669 for( auto const &action : params.actionList)
671 RICactions_ToBeSetup_List::value_type* item =
672 new RICactions_ToBeSetup_List::value_type();
674 ie_RICsubscription->ref_value().select_id_RICsubscription()
675 .ref_ricAction_ToBeSetup_List().push_back(*item);
677 item->ref_id().select_id_RICaction_ToBeSetup_Item();
678 item->ref_criticality().select_id_RICaction_ToBeSetup_Item();
679 item->ref_value().select_id_RICaction_ToBeSetup_Item()
680 .ref_ricActionID().set(action.action_id);
681 item->ref_value().select_id_RICaction_ToBeSetup_Item()
682 .ref_ricActionType().set(action.action_type);
689 bool e2ap_parse_RICsubscriptionRequest(e2ap_pdu_t* pdu, RICsubscription_params_t ¶ms)
691 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
693 RICsubscriptionRequest* container = &(pduWrapper->ref_pdu()
694 .select_initiatingMessage().ref_value().select_id_ricSubscription());
697 for(auto &e : container->ref_protocolIEs())
699 /*See struct RICsubscriptionRequest_IEs*/
700 size_t type = e.ref_value().get_index();
704 case 1: //RICrequestID
706 params.request_id = e.ref_value().select_id_RICrequestID().ref_ricRequestorID().get();
707 params.seq_number = e.ref_value().select_id_RICrequestID().ref_ricRequestSequenceNumber().get();
711 case 2: //RANfunctionID
712 params.ran_func_id = e.ref_value().select_id_RANfunctionID().get();
715 case 3: //RICsubscription
717 auto event = e.ref_value().select_id_RICsubscription().ref_ricEventTriggerDefinition().get();
718 (params.event_trigger_def).assign(std::string(event.data(), event.data() + event.size()));
720 //ricAction_ToBeSetup_List
721 for (auto & f : e.ref_value().select_id_RICsubscription().ref_ricAction_ToBeSetup_List())
724 action.action_id = f.ref_value()
725 .select_id_RICaction_ToBeSetup_Item().ref_ricActionID().get();
726 action.action_type = static_cast<enum_RICactionType>(f.ref_value()
727 .select_id_RICaction_ToBeSetup_Item().ref_ricActionType().get());
729 params.actionList.push_back(action);
735 printf("Unknown IE type = %d\n", (int)type);
743 bool e2ap_create_RICsubscriptionResponse(e2ap_pdu_t* pdu, RICsubscription_params_t ¶ms)
745 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
748 pduWrapper->ref_pdu().select_successfulOutcome().ref_procedureCode().select_id_ricSubscription();
749 pduWrapper->ref_pdu().select_successfulOutcome().ref_criticality().select_id_ricSubscription();
751 RICsubscriptionResponse* container = &(pduWrapper->ref_pdu()
752 .select_successfulOutcome().ref_value().select_id_ricSubscription());
754 using IE_value_t = RICsubscriptionResponse::protocolIEs_t::value_type;
756 /* RICsubscriptionResponse-IEs : RICrequestID */
757 IE_value_t* ie_RICrequestID = new IE_value_t;
758 container->ref_protocolIEs().push_back(*ie_RICrequestID);
760 ie_RICrequestID->ref_id().select_id_RICrequestID();
761 ie_RICrequestID->ref_criticality().select_id_RICrequestID();
762 ie_RICrequestID->ref_value().select_id_RICrequestID()
763 .ref_ricRequestorID().set(params.request_id);
764 ie_RICrequestID->ref_value().select_id_RICrequestID()
765 .ref_ricRequestSequenceNumber().set(params.seq_number);
767 /* RICsubscriptionResponse-IEs : RANfunctionID */
768 IE_value_t* ie_RANfunctionID = new IE_value_t;
769 container->ref_protocolIEs().push_back(*ie_RANfunctionID);
771 ie_RANfunctionID->ref_id().select_id_RANfunctionID();
772 ie_RANfunctionID->ref_criticality().select_id_RANfunctionID();
773 ie_RANfunctionID->ref_value().select_id_RANfunctionID().set(params.ran_func_id);
775 /* RICsubscriptionResponse-IEs : RICaction-Admitted-List */
776 IE_value_t* ie_admittedList = new IE_value_t;
777 container->ref_protocolIEs().push_back(*ie_admittedList);
779 ie_admittedList->ref_id().select_id_RICactions_Admitted();
780 ie_admittedList->ref_criticality().select_id_RICactions_Admitted();
782 /* RICsubscriptionResponse-IEs : RICaction-NotAdmitted-List */
783 IE_value_t* ie_notAdmittedList = new IE_value_t;
784 container->ref_protocolIEs().push_back(*ie_notAdmittedList);
786 ie_notAdmittedList->ref_id().select_id_RICactions_NotAdmitted();
787 ie_notAdmittedList->ref_criticality().select_id_RICactions_NotAdmitted();
789 //add action to admitted and not-admitted list
790 for(auto const &a : params.actionList)
794 RICaction_Admitted_List::value_type* item = new RICaction_Admitted_List::value_type();
796 ie_admittedList->ref_value().select_id_RICactions_Admitted().push_back(*item);
798 item->ref_id().select_id_RICaction_Admitted_Item();
799 item->ref_criticality().select_id_RICaction_Admitted_Item();
800 item->ref_value().select_id_RICaction_Admitted_Item().ref_ricActionID().set(a.action_id);
804 RICaction_NotAdmitted_List::value_type* item = new RICaction_NotAdmitted_List::value_type();
806 ie_notAdmittedList->ref_value().select_id_RICactions_NotAdmitted().push_back(*item);
808 item->ref_id().select_id_RICaction_NotAdmitted_Item();
809 item->ref_criticality().select_id_RICaction_NotAdmitted_Item();
810 item->ref_value().select_id_RICaction_NotAdmitted_Item().ref_ricActionID().set(a.action_id);
812 // set cause and sub-cause
813 switch(a.notAdmitted_cause)
815 case RICcause_radioNetwork:
816 item->ref_value().select_id_RICaction_NotAdmitted_Item().ref_ricCause().select_radioNetwork().set(a.notAdmitted_subCause);
819 case RICcause_transport:
820 item->ref_value().select_id_RICaction_NotAdmitted_Item().ref_ricCause().select_transport().set(a.notAdmitted_subCause);
823 case RICcause_protocol:
824 item->ref_value().select_id_RICaction_NotAdmitted_Item().ref_ricCause().select_protocol().set(a.notAdmitted_subCause);
828 item->ref_value().select_id_RICaction_NotAdmitted_Item().ref_ricCause().select_misc().set(a.notAdmitted_subCause);
832 item->ref_value().select_id_RICaction_NotAdmitted_Item().ref_ricCause().select_ric().set(a.notAdmitted_subCause);
836 printf("Unknown cause for action not admitted = %d", (int)a.notAdmitted_cause);
844 bool e2ap_create_RICsubscriptionFailure(e2ap_pdu_t* pdu, RICsubscription_params_t ¶ms)
846 E2APpduWrapper* pduWrapper = reinterpret_cast<E2APpduWrapper*>(pdu);
849 pduWrapper->ref_pdu().select_unsuccessfulOutcome().ref_procedureCode().select_id_ricSubscription();
850 pduWrapper->ref_pdu().select_unsuccessfulOutcome().ref_criticality().select_id_ricSubscription();
852 RICsubscriptionFailure* container = &(pduWrapper->ref_pdu()
853 .select_unsuccessfulOutcome().ref_value().select_id_ricSubscription());
855 using IE_value_t = RICsubscriptionFailure::protocolIEs_t::value_type;
857 /* RICsubscriptionFailure-IEs : RICrequestID */
858 IE_value_t* ie_RICrequestID = new IE_value_t;
859 container->ref_protocolIEs().push_back(*ie_RICrequestID);
861 ie_RICrequestID->ref_id().select_id_RICrequestID();
862 ie_RICrequestID->ref_criticality().select_id_RICrequestID();
863 ie_RICrequestID->ref_value().select_id_RICrequestID()
864 .ref_ricRequestorID().set(params.request_id);
865 ie_RICrequestID->ref_value().select_id_RICrequestID()
866 .ref_ricRequestSequenceNumber().set(params.seq_number);
868 /* RICsubscriptionFailure-IEs : RANfunctionID */
869 IE_value_t* ie_RANfunctionID = new IE_value_t;
870 container->ref_protocolIEs().push_back(*ie_RANfunctionID);
872 ie_RANfunctionID->ref_id().select_id_RANfunctionID();
873 ie_RANfunctionID->ref_criticality().select_id_RANfunctionID();
874 ie_RANfunctionID->ref_value().select_id_RANfunctionID().set(params.ran_func_id);
876 /* RICsubscriptionFailure-IEs : RICaction-NotAdmitted-List */
877 IE_value_t* ie_notAdmittedList = new IE_value_t;
878 container->ref_protocolIEs().push_back(*ie_notAdmittedList);
880 ie_notAdmittedList->ref_id().select_id_RICactions_NotAdmitted();
881 ie_notAdmittedList->ref_criticality().select_id_RICactions_NotAdmitted();
883 for(auto const &a : params.actionList)
887 RICaction_NotAdmitted_List::value_type* item = new RICaction_NotAdmitted_List::value_type();
889 ie_notAdmittedList->ref_value().select_id_RICactions_NotAdmitted().push_back(*item);
891 item->ref_id().select_id_RICaction_NotAdmitted_Item();
892 item->ref_criticality().select_id_RICaction_NotAdmitted_Item();
893 item->ref_value().select_id_RICaction_NotAdmitted_Item().ref_ricActionID().set(a.action_id);
895 // set cause and sub-cause
896 switch(a.notAdmitted_cause)
898 case RICcause_radioNetwork:
899 item->ref_value().select_id_RICaction_NotAdmitted_Item().ref_ricCause().select_radioNetwork().set(a.notAdmitted_subCause);
902 case RICcause_transport:
903 item->ref_value().select_id_RICaction_NotAdmitted_Item().ref_ricCause().select_transport().set(a.notAdmitted_subCause);
906 case RICcause_protocol:
907 item->ref_value().select_id_RICaction_NotAdmitted_Item().ref_ricCause().select_protocol().set(a.notAdmitted_subCause);
911 item->ref_value().select_id_RICaction_NotAdmitted_Item().ref_ricCause().select_misc().set(a.notAdmitted_subCause);
915 item->ref_value().select_id_RICaction_NotAdmitted_Item().ref_ricCause().select_ric().set(a.notAdmitted_subCause);
919 printf("Unknown cause for action not admitted = %d", (int)a.notAdmitted_cause);
928 /*-----------------------------------------------------------------------
930 -------------------------------------------------------------------------
932 void test_E2AP_X2Setup_codec(void)
934 e2ap_pdu_t* pdu = new_e2ap_pdu();
936 // e2ap_init_X2SetupRequest(pdu);
938 e2ap_create_X2SetupRequest(pdu, cfg);
941 e2ap_asn_print(pdu, pdu_str, sizeof(pdu_str));
942 printf("%s\n", pdu_str);
945 unsigned char packed_buf[4096];
948 int packed_len = e2ap_asn_per_encode(pdu, packed_buf, sizeof(packed_buf),
949 err_buf, sizeof(err_buf));
950 if(packed_len != -1) {
951 printf("Encode successful, packed_len = %d\n", packed_len);
953 printf("Encode Error: %s\n", err_buf);
957 e2ap_pdu_t* pdu2 = new_e2ap_pdu();
958 int rc = e2ap_asn_per_decode(pdu2, packed_buf, packed_len, err_buf, sizeof(err_buf));
960 printf("Decode error: %s\n", err_buf);
962 printf("Decode successful\n");
965 e2ap_asn_print(pdu2, pdu_str, sizeof(pdu_str));
966 printf("%s\n", pdu_str);
968 printf("index = %d\n", e2ap_get_index(pdu2));
969 printf("procedureCode = %d\n", e2ap_get_procedureCode(pdu2));
971 //Test X2SetupResponse
972 e2ap_pdu_t* pdu_resp = new_e2ap_pdu();
973 e2ap_create_X2SetupResponse(pdu_resp, cfg);
974 e2ap_asn_print(pdu_resp, pdu_str, sizeof(pdu_str));
975 printf("%s\n", pdu_str);
977 //Test X2SetupFailure
978 e2ap_pdu_t* pdu_failure = new_e2ap_pdu();
979 e2ap_create_X2SetupFailure(pdu_failure);
980 e2ap_asn_print(pdu_failure, pdu_str, sizeof(pdu_str));
981 printf("%s \n", pdu_str);