2 * Copyright 2019 AT&T Intellectual Property
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.
19 // Created by adi ENZEL on 12/10/19.
22 #ifndef E2_E2BUILDER_H
23 #define E2_E2BUILDER_H
29 #include <sys/types.h>
32 #include <3rdparty/oranE2SM/E2SM-gNB-NRT-RANfunction-Definition.h>
33 #include <3rdparty/oranE2SM/RIC-InsertStyle-List.h>
34 #include <3rdparty/oranE2SM/RANparameterDef-Item.h>
35 #include <3rdparty/oranE2/GlobalE2node-en-gNB-ID.h>
38 //#include <mdclog/mdclog.h>
41 #include "oranE2/E2AP-PDU.h"
42 #include "oranE2/InitiatingMessage.h"
43 #include "oranE2/SuccessfulOutcome.h"
44 #include "oranE2/UnsuccessfulOutcome.h"
46 #include "oranE2/ProtocolIE-Field.h"
47 #include "oranE2/ENB-ID.h"
48 #include "oranE2/GlobalENB-ID.h"
49 #include "oranE2/GlobalE2node-gNB-ID.h"
50 #include "oranE2/constr_TYPE.h"
51 #include "oranE2/asn_constant.h"
55 #define printEntry(type, function); fprintf(stdout, "start Test %s , %s", type, function);
58 static void checkAndPrint(asn_TYPE_descriptor_t *typeDescriptor, void *data, char *dataType, const char *function) {
59 char errbuf[128]; /* Buffer for error message */
60 size_t errlen = sizeof(errbuf); /* Size of the buffer */
61 if (asn_check_constraints(typeDescriptor, data, errbuf, &errlen) != 0) {
62 fprintf(stderr, "%s Constraint validation failed: %s", dataType, errbuf);
64 fprintf(stdout, "%s successes function %s", dataType, function);
67 void createPLMN_IDByMCCandMNC(PLMN_Identity_t *plmnId, int mcc, int mnc) {
69 //printEntry("PLMN_Identity_t", __func__)
71 ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, plmnId);
73 plmnId->buf = (uint8_t *) calloc(1, 3);
74 volatile auto mcc1 = (unsigned int) (mcc / 100);
75 volatile auto mcc2 = (unsigned int) (mcc / 10 % 10);
76 volatile auto mcc3 = (unsigned int) (mcc % 10);
77 plmnId->buf[0] = mcc2 << 4 | mcc1;
79 volatile auto mnc1 = (unsigned int)0;
80 volatile auto mnc2 = (unsigned int)0;
81 volatile auto mnc3 = (unsigned int)0;
84 mnc1 = (unsigned int) (mnc / 100);
85 mnc2 = (unsigned int) (mnc / 10 % 10);
86 mnc3 = (unsigned int) (mnc % 10);
88 mnc1 = (unsigned int) (mnc / 10);
89 mnc2 = (unsigned int) (mnc % 10);
92 plmnId->buf[1] = mcc3 << 4 | mnc3 ;
93 plmnId->buf[2] = mnc2 << 4 | mnc1 ;
95 //checkAndPrint(&asn_DEF_PLMN_Identity, plmnId, (char *) "PLMN_Identity_t", __func__);
100 PLMN_Identity_t *createPLMN_ID(const unsigned char *data) {
101 printEntry("PLMN_Identity_t", __func__)
102 auto *plmnId = (PLMN_Identity_t *) calloc(1, sizeof(PLMN_Identity_t));
103 ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, plmnId);
105 plmnId->buf = (uint8_t *) calloc(1, 3);
106 memcpy(plmnId->buf, data, 3);
108 checkAndPrint(&asn_DEF_PLMN_Identity, plmnId, (char *) "PLMN_Identity_t", __func__);
113 BIT_STRING_t *createBIT_STRING(int size, int unusedBits, uint8_t *data) {
114 printEntry("BIT_STRING_t", __func__)
115 auto *bitString = (BIT_STRING_t *) calloc(1, sizeof(BIT_STRING_t));
116 ASN_STRUCT_RESET(asn_DEF_BIT_STRING, bitString);
117 bitString->size = size;
118 bitString->bits_unused = unusedBits;
119 bitString->buf = (uint8_t *) calloc(1, size);
121 data[bitString->size - 1] = ((unsigned) (data[bitString->size - 1] >>
122 (unsigned) bitString->bits_unused)
123 << (unsigned) bitString->bits_unused);
124 memcpy(bitString->buf, data, size);
126 checkAndPrint(&asn_DEF_BIT_STRING, bitString, (char *) "BIT_STRING_t", __func__);
132 OCTET_STRING_t *createOCTET_STRING(const unsigned char *data, int size) {
133 printEntry("OCTET_STRING_t", __func__)
134 auto *octs = (PLMN_Identity_t *) calloc(1, sizeof(PLMN_Identity_t));
135 ASN_STRUCT_RESET(asn_DEF_OCTET_STRING, octs);
137 octs->buf = (uint8_t *) calloc(1, size);
138 memcpy(octs->buf, data, size);
140 checkAndPrint(&asn_DEF_OCTET_STRING, octs, (char *) "OCTET_STRING_t", __func__);
145 ENB_ID_t *createENB_ID(ENB_ID_PR enbType, unsigned char *data) {
146 printEntry("ENB_ID_t", __func__)
147 auto *enb = (ENB_ID_t *) calloc(1, sizeof(ENB_ID_t));
148 ASN_STRUCT_RESET(asn_DEF_ENB_ID, enb);
150 enb->present = enbType;
153 case ENB_ID_PR_macro_eNB_ID: { // 20 bit 3 bytes
154 enb->choice.macro_eNB_ID.size = 3;
155 enb->choice.macro_eNB_ID.bits_unused = 4;
157 enb->present = ENB_ID_PR_macro_eNB_ID;
159 enb->choice.macro_eNB_ID.buf = (uint8_t *) calloc(1, enb->choice.macro_eNB_ID.size);
160 data[enb->choice.macro_eNB_ID.size - 1] = ((unsigned) (data[enb->choice.macro_eNB_ID.size - 1] >>
161 (unsigned) enb->choice.macro_eNB_ID.bits_unused)
162 << (unsigned) enb->choice.macro_eNB_ID.bits_unused);
163 memcpy(enb->choice.macro_eNB_ID.buf, data, enb->choice.macro_eNB_ID.size);
167 case ENB_ID_PR_home_eNB_ID: { // 28 bit 4 bytes
168 enb->choice.home_eNB_ID.size = 4;
169 enb->choice.home_eNB_ID.bits_unused = 4;
170 enb->present = ENB_ID_PR_home_eNB_ID;
172 enb->choice.home_eNB_ID.buf = (uint8_t *) calloc(1, enb->choice.home_eNB_ID.size);
173 data[enb->choice.home_eNB_ID.size - 1] = ((unsigned) (data[enb->choice.home_eNB_ID.size - 1] >>
174 (unsigned) enb->choice.home_eNB_ID.bits_unused)
175 << (unsigned) enb->choice.home_eNB_ID.bits_unused);
176 memcpy(enb->choice.home_eNB_ID.buf, data, enb->choice.home_eNB_ID.size);
179 case ENB_ID_PR_short_Macro_eNB_ID: { // 18 bit - 3 bytes
180 enb->choice.short_Macro_eNB_ID.size = 3;
181 enb->choice.short_Macro_eNB_ID.bits_unused = 6;
182 enb->present = ENB_ID_PR_short_Macro_eNB_ID;
184 enb->choice.short_Macro_eNB_ID.buf = (uint8_t *) calloc(1, enb->choice.short_Macro_eNB_ID.size);
185 data[enb->choice.short_Macro_eNB_ID.size - 1] = (
186 (unsigned) (data[enb->choice.short_Macro_eNB_ID.size - 1] >>
187 (unsigned) enb->choice.short_Macro_eNB_ID.bits_unused)
188 << (unsigned) enb->choice.short_Macro_eNB_ID.bits_unused);
189 memcpy(enb->choice.short_Macro_eNB_ID.buf, data, enb->choice.short_Macro_eNB_ID.size);
192 case ENB_ID_PR_long_Macro_eNB_ID: { // 21
193 enb->choice.long_Macro_eNB_ID.size = 3;
194 enb->choice.long_Macro_eNB_ID.bits_unused = 3;
195 enb->present = ENB_ID_PR_long_Macro_eNB_ID;
197 enb->choice.long_Macro_eNB_ID.buf = (uint8_t *) calloc(1, enb->choice.long_Macro_eNB_ID.size);
198 data[enb->choice.long_Macro_eNB_ID.size - 1] =
199 ((unsigned) (data[enb->choice.long_Macro_eNB_ID.size - 1] >> (unsigned) enb->choice.long_Macro_eNB_ID.bits_unused)
200 << (unsigned) enb->choice.long_Macro_eNB_ID.bits_unused);
201 memcpy(enb->choice.long_Macro_eNB_ID.buf, data, enb->choice.long_Macro_eNB_ID.size);
209 checkAndPrint(&asn_DEF_ENB_ID, enb, (char *) "ENB_ID_t", __func__);
213 GlobalENB_ID_t *createGlobalENB_ID(PLMN_Identity_t *plmnIdentity, ENB_ID_t *enbId) {
214 printEntry("GlobalENB_ID_t", __func__)
215 auto *genbId = (GlobalENB_ID_t *) calloc(1, sizeof(GlobalENB_ID_t));
216 ASN_STRUCT_RESET(asn_DEF_GlobalENB_ID, genbId);
217 memcpy(&genbId->pLMN_Identity, plmnIdentity, sizeof(PLMN_Identity_t));
218 memcpy(&genbId->eNB_ID, enbId, sizeof(ENB_ID_t));
220 checkAndPrint(&asn_DEF_GlobalENB_ID, genbId, (char *) "GlobalENB_ID_t", __func__);
225 //static void buildInitiatingMessagePDU(E2AP_PDU_t &pdu, InitiatingMessage_t *initMsg) {
226 // pdu.present = E2AP_PDU_PR_initiatingMessage;
227 // pdu.choice.initiatingMessage = initMsg;
231 static void buildInitMsg(InitiatingMessage_t &initMsg,
232 InitiatingMessage__value_PR present,
233 ProcedureCode_t procedureCode,
234 Criticality_t criticality,
236 initMsg.value.present = present;
237 initMsg.procedureCode = procedureCode;
238 initMsg.criticality = criticality;
241 case InitiatingMessage__value_PR_RICsubscriptionRequest: {
242 memcpy(&initMsg.value.choice.RICsubscriptionRequest, value, sizeof(*value));
245 case InitiatingMessage__value_PR_RICsubscriptionDeleteRequest: {
246 memcpy(&initMsg.value.choice.RICsubscriptionDeleteRequest, value, sizeof(*value));
249 case InitiatingMessage__value_PR_RICserviceUpdate: {
250 memcpy(&initMsg.value.choice.RICserviceUpdate, value, sizeof(*value));
253 case InitiatingMessage__value_PR_RICcontrolRequest: {
254 memcpy(&initMsg.value.choice.RICcontrolRequest, value, sizeof(*value));
257 case InitiatingMessage__value_PR_RICindication: {
258 memcpy(&initMsg.value.choice.RICindication, value, sizeof(*value));
261 case InitiatingMessage__value_PR_RICserviceQuery: {
262 memcpy(&initMsg.value.choice.RICserviceQuery, value, sizeof(*value));
265 case InitiatingMessage__value_PR_NOTHING:
272 //static void buildSuccsesfulMessagePDU(E2AP_PDU_t &pdu, SuccessfulOutcome_t *succMsg) {
273 // pdu.present = E2AP_PDU_PR_successfulOutcome;
274 // pdu.choice.successfulOutcome = succMsg;
278 static void buildSuccMsg(SuccessfulOutcome_t &succMsg,
279 SuccessfulOutcome__value_PR present,
280 ProcedureCode_t procedureCode,
281 Criticality_t criticality,
283 succMsg.value.present = present;
284 succMsg.procedureCode = procedureCode;
285 succMsg.criticality = criticality;
288 case SuccessfulOutcome__value_PR_RICsubscriptionResponse: {
289 memcpy(&succMsg.value.choice.RICsubscriptionResponse, value, sizeof(*value));
292 case SuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse: {
293 memcpy(&succMsg.value.choice.RICsubscriptionDeleteResponse, value, sizeof(*value));
296 case SuccessfulOutcome__value_PR_RICserviceUpdateAcknowledge: {
297 memcpy(&succMsg.value.choice.RICserviceUpdateAcknowledge, value, sizeof(*value));
300 case SuccessfulOutcome__value_PR_RICcontrolAcknowledge: {
301 memcpy(&succMsg.value.choice.RICcontrolAcknowledge, value, sizeof(*value));
304 case SuccessfulOutcome__value_PR_ResetResponse: {
305 memcpy(&succMsg.value.choice.ResetResponse, value, sizeof(*value));
308 case SuccessfulOutcome__value_PR_NOTHING:
315 //static void buildUnSucssesfullMessagePDU(E2AP_PDU_t &pdu, UnsuccessfulOutcome_t *unSuccMsg) {
316 // pdu.present = E2AP_PDU_PR_unsuccessfulOutcome;
317 // pdu.choice.unsuccessfulOutcome = unSuccMsg;
321 static void buildUnSuccMsg(UnsuccessfulOutcome_t &unSuccMsg,
322 UnsuccessfulOutcome__value_PR present,
323 ProcedureCode_t procedureCode,
324 Criticality_t criticality,
326 unSuccMsg.value.present = present;
327 unSuccMsg.procedureCode = procedureCode;
328 unSuccMsg.criticality = criticality;
331 case UnsuccessfulOutcome__value_PR_RICsubscriptionFailure: {
332 memcpy(&unSuccMsg.value.choice.RICsubscriptionFailure, value, sizeof(*value));
335 case UnsuccessfulOutcome__value_PR_RICsubscriptionDeleteFailure: {
336 memcpy(&unSuccMsg.value.choice.RICsubscriptionDeleteFailure, value, sizeof(*value));
339 case UnsuccessfulOutcome__value_PR_RICserviceUpdateFailure: {
340 memcpy(&unSuccMsg.value.choice.RICserviceUpdateFailure, value, sizeof(*value));
343 case UnsuccessfulOutcome__value_PR_RICcontrolFailure: {
344 memcpy(&unSuccMsg.value.choice.RICcontrolFailure, value, sizeof(*value));
348 case UnsuccessfulOutcome__value_PR_NOTHING:
355 //static void createPLMN_ID(PLMN_Identity_t &plmnId, const unsigned char *data) {
356 // //printEntry("PLMN_Identity_t", __func__)
357 // //PLMN_Identity_t *plmnId = calloc(1, sizeof(PLMN_Identity_t));
358 // ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, &plmnId);
359 // plmnId.size = 3;// uint64_t st = 0;
360 //// uint32_t aux1 = 0;
361 //// st = rdtscp(aux1);
363 // plmnId.buf = (uint8_t *) calloc(1, 3);
364 // memcpy(plmnId.buf, data, 3);
366 // checkAndPrint(&asn_DEF_PLMN_Identity, &plmnId, (char *) "PLMN_Identity_t", __func__);
370 static void createENB_ID(ENB_ID_t &enb, ENB_ID_PR enbType, unsigned char *data) {
371 //printEntry("ENB_ID_t", __func__)
372 ASN_STRUCT_RESET(asn_DEF_ENB_ID, &enb);
373 enb.present = enbType;
375 case ENB_ID_PR_macro_eNB_ID: { // 20 bit 3 bytes
376 enb.choice.macro_eNB_ID.size = 3;
377 enb.choice.macro_eNB_ID.bits_unused = 4;
379 enb.present = ENB_ID_PR_macro_eNB_ID;
381 enb.choice.macro_eNB_ID.buf = (uint8_t *) calloc(1, enb.choice.macro_eNB_ID.size);
382 data[enb.choice.macro_eNB_ID.size - 1] = ((unsigned) (data[enb.choice.macro_eNB_ID.size - 1]
383 >> (unsigned) enb.choice.macro_eNB_ID.bits_unused)
384 << (unsigned) enb.choice.macro_eNB_ID.bits_unused);
385 memcpy(enb.choice.macro_eNB_ID.buf, data, enb.choice.macro_eNB_ID.size);
389 case ENB_ID_PR_home_eNB_ID: { // 28 bit 4 bytes
390 enb.choice.home_eNB_ID.size = 4;
391 enb.choice.home_eNB_ID.bits_unused = 4;
392 enb.present = ENB_ID_PR_home_eNB_ID;
394 enb.choice.home_eNB_ID.buf = (uint8_t *) calloc(1, enb.choice.home_eNB_ID.size);
395 data[enb.choice.home_eNB_ID.size - 1] = ((unsigned) (data[enb.choice.home_eNB_ID.size - 1]
396 >> (unsigned) enb.choice.home_eNB_ID.bits_unused)
397 << (unsigned) enb.choice.home_eNB_ID.bits_unused);
398 memcpy(enb.choice.home_eNB_ID.buf, data, enb.choice.home_eNB_ID.size);
401 case ENB_ID_PR_short_Macro_eNB_ID: { // 18 bit - 3 bytes
402 enb.choice.short_Macro_eNB_ID.size = 3;
403 enb.choice.short_Macro_eNB_ID.bits_unused = 6;
404 enb.present = ENB_ID_PR_short_Macro_eNB_ID;
406 enb.choice.short_Macro_eNB_ID.buf = (uint8_t *) calloc(1, enb.choice.short_Macro_eNB_ID.size);
407 data[enb.choice.short_Macro_eNB_ID.size - 1] = ((unsigned) (data[enb.choice.short_Macro_eNB_ID.size - 1]
408 >> (unsigned) enb.choice.short_Macro_eNB_ID.bits_unused)
409 << (unsigned) enb.choice.short_Macro_eNB_ID.bits_unused);
410 memcpy(enb.choice.short_Macro_eNB_ID.buf, data, enb.choice.short_Macro_eNB_ID.size);
413 case ENB_ID_PR_long_Macro_eNB_ID: { // 21
414 enb.choice.long_Macro_eNB_ID.size = 3;
415 enb.choice.long_Macro_eNB_ID.bits_unused = 3;
416 enb.present = ENB_ID_PR_long_Macro_eNB_ID;
418 enb.choice.long_Macro_eNB_ID.buf = (uint8_t *) calloc(1, enb.choice.long_Macro_eNB_ID.size);
419 data[enb.choice.long_Macro_eNB_ID.size - 1] = ((unsigned) (data[enb.choice.long_Macro_eNB_ID.size - 1]
420 >> (unsigned) enb.choice.long_Macro_eNB_ID.bits_unused)
421 << (unsigned) enb.choice.long_Macro_eNB_ID.bits_unused);
422 memcpy(enb.choice.long_Macro_eNB_ID.buf, data, enb.choice.long_Macro_eNB_ID.size);
429 checkAndPrint(&asn_DEF_ENB_ID, &enb, (char *) "ENB_ID_t", __func__);
433 static void buildGlobalENB_ID(GlobalENB_ID_t *gnbId,
434 const unsigned char *gnbData,
436 unsigned char *enbData) {
437 auto *plmnID = createPLMN_ID(gnbData);
438 memcpy(&gnbId->pLMN_Identity, plmnID, sizeof(PLMN_Identity_t));
439 createENB_ID(gnbId->eNB_ID, enbType, enbData);
440 checkAndPrint(&asn_DEF_GlobalENB_ID, gnbId, (char *) "GlobalENB_ID_t", __func__);
444 void buildSetupRequest(E2AP_PDU_t *pdu, int mcc, int mnc) {
445 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
447 pdu->choice.initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t));
448 auto *initiatingMessage = pdu->choice.initiatingMessage;
449 ASN_STRUCT_RESET(asn_DEF_InitiatingMessage, initiatingMessage);
450 initiatingMessage->procedureCode = ProcedureCode_id_E2setup;
451 initiatingMessage->criticality = Criticality_reject;
452 initiatingMessage->value.present = InitiatingMessage__value_PR_E2setupRequest;
454 auto *e2SetupRequestIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
455 ASN_STRUCT_RESET(asn_DEF_E2setupRequestIEs, e2SetupRequestIEs);
457 e2SetupRequestIEs->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
458 e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.gNB = (GlobalE2node_gNB_ID_t *)calloc(1, sizeof(GlobalE2node_gNB_ID_t));
459 auto *globalE2NodeGNbId = e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.gNB;
460 ASN_STRUCT_RESET(asn_DEF_GlobalE2node_gNB_ID, globalE2NodeGNbId);
462 createPLMN_IDByMCCandMNC(&globalE2NodeGNbId->global_gNB_ID.plmn_id, mcc, mnc);
463 globalE2NodeGNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
464 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = 4;
465 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf =
466 (uint8_t *) calloc(1, globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size); //22..32 bits
467 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.bits_unused = 0;
468 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[0] = 0xB5;
469 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[1] = 0xC6;
470 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[2] = 0x77;
471 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[3] = 0x88;
473 e2SetupRequestIEs->criticality = Criticality_reject;
474 e2SetupRequestIEs->id = ProtocolIE_ID_id_GlobalE2node_ID;
475 e2SetupRequestIEs->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
478 auto *e2SetupRequest = &initiatingMessage->value.choice.E2setupRequest;
480 ASN_STRUCT_RESET(asn_DEF_E2setupRequest, e2SetupRequest);
481 ASN_SEQUENCE_ADD(&e2SetupRequest->protocolIEs.list, e2SetupRequestIEs);
483 pdu->present = E2AP_PDU_PR_initiatingMessage;
486 void buildSetupRequesteenGNB(E2AP_PDU_t *pdu, int mcc, int mnc) {
487 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
489 pdu->choice.initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t));
490 auto *initiatingMessage = pdu->choice.initiatingMessage;
491 ASN_STRUCT_RESET(asn_DEF_InitiatingMessage, initiatingMessage);
492 initiatingMessage->procedureCode = ProcedureCode_id_E2setup;
493 initiatingMessage->criticality = Criticality_reject;
494 initiatingMessage->value.present = InitiatingMessage__value_PR_E2setupRequest;
496 auto *e2SetupRequestIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
497 ASN_STRUCT_RESET(asn_DEF_E2setupRequestIEs, e2SetupRequestIEs);
499 e2SetupRequestIEs->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_en_gNB;
500 e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.en_gNB = (GlobalE2node_en_gNB_ID_t *)calloc(1, sizeof(GlobalE2node_en_gNB_ID_t));
501 auto *globalE2NodeEN_GNb = e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.en_gNB;
502 ASN_STRUCT_RESET(asn_DEF_GlobalE2node_en_gNB_ID, globalE2NodeEN_GNb);
504 globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.present = ENGNB_ID_PR_gNB_ID;
505 createPLMN_IDByMCCandMNC(&globalE2NodeEN_GNb->global_gNB_ID.pLMN_Identity, mcc, mnc);
506 globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.size = 4;
507 globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.buf =
508 (uint8_t *) calloc(1, globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.size); //22..32 bits
509 globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.buf[0] = 0xC5;
510 globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.buf[1] = 0xC6;
511 globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.buf[2] = 0xC7;
512 globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.buf[3] = 0xF8;
513 globalE2NodeEN_GNb->global_gNB_ID.gNB_ID.choice.gNB_ID.bits_unused = 0;
514 e2SetupRequestIEs->criticality = Criticality_reject;
515 e2SetupRequestIEs->id = ProtocolIE_ID_id_GlobalE2node_ID;
516 e2SetupRequestIEs->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
519 auto *e2SetupRequest = &initiatingMessage->value.choice.E2setupRequest;
521 ASN_STRUCT_RESET(asn_DEF_E2setupRequest, e2SetupRequest);
522 ASN_SEQUENCE_ADD(&e2SetupRequest->protocolIEs.list, e2SetupRequestIEs);
524 pdu->present = E2AP_PDU_PR_initiatingMessage;
529 void buildSetupRequestWithFunc(E2AP_PDU_t *pdu, int mcc, int mnc) {
530 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
532 pdu->choice.initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t));
533 auto *initiatingMessage = pdu->choice.initiatingMessage;
534 ASN_STRUCT_RESET(asn_DEF_InitiatingMessage, initiatingMessage);
535 initiatingMessage->procedureCode = ProcedureCode_id_E2setup;
536 initiatingMessage->criticality = Criticality_reject;
537 initiatingMessage->value.present = InitiatingMessage__value_PR_E2setupRequest;
539 auto *e2SetupRequestIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
540 ASN_STRUCT_RESET(asn_DEF_E2setupRequestIEs, e2SetupRequestIEs);
542 e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.gNB = (GlobalE2node_gNB_ID_t *)calloc(1, sizeof(GlobalE2node_gNB_ID_t));
543 auto *globalE2NodeGNbId = e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.gNB;
544 ASN_STRUCT_RESET(asn_DEF_GlobalE2node_gNB_ID, globalE2NodeGNbId);
546 createPLMN_IDByMCCandMNC(&globalE2NodeGNbId->global_gNB_ID.plmn_id, mcc, mnc);
547 globalE2NodeGNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
548 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = 4;
549 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf =
550 (uint8_t *) calloc(1, globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size); //22..32 bits
551 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.bits_unused = 0;
552 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[0] = 0xB5;
553 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[1] = 0xC6;
554 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[2] = 0x77;
555 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[3] = 0x88;
557 e2SetupRequestIEs->criticality = Criticality_reject;
558 e2SetupRequestIEs->id = ProtocolIE_ID_id_GlobalE2node_ID;
559 e2SetupRequestIEs->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
560 e2SetupRequestIEs->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
563 auto *e2SetupRequest = &initiatingMessage->value.choice.E2setupRequest;
565 ASN_STRUCT_RESET(asn_DEF_E2setupRequest, e2SetupRequest);
566 ASN_SEQUENCE_ADD(&e2SetupRequest->protocolIEs.list, e2SetupRequestIEs);
568 auto *ranFlistIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
569 ASN_STRUCT_RESET(asn_DEF_E2setupRequestIEs, ranFlistIEs);
570 ranFlistIEs->criticality = Criticality_reject;
571 ranFlistIEs->id = ProtocolIE_ID_id_RANfunctionsAdded;
572 ranFlistIEs->value.present = E2setupRequestIEs__value_PR_RANfunctions_List;
574 auto *itemIes = (RANfunction_ItemIEs_t *)calloc(1, sizeof(RANfunction_ItemIEs_t));
575 ASN_STRUCT_RESET(asn_DEF_RANfunction_ItemIEs, itemIes);
578 E2SM_gNB_NRT_RANfunction_Definition_t ranFunDef;
579 uint8_t funcDes[] = "asdfghjklpoiuytrewq\0";
580 ranFunDef.ranFunction_Name.ranFunction_Description.buf = (uint8_t *)calloc(1, strlen((char *)funcDes));
581 ranFunDef.ranFunction_Name.ranFunction_Description.size = strlen((char *)funcDes);
582 memcpy(ranFunDef.ranFunction_Name.ranFunction_Description.buf, funcDes, strlen((char *)funcDes));
584 uint8_t funcOID[] = "ABCDEFGHIJ1234567890\0";
585 ranFunDef.ranFunction_Name.ranFunction_E2SM_OID.buf = (uint8_t *)calloc(1, strlen((char *)funcOID));
586 ranFunDef.ranFunction_Name.ranFunction_E2SM_OID.size = strlen((char *)funcOID);
587 memcpy(ranFunDef.ranFunction_Name.ranFunction_E2SM_OID.buf, funcOID, strlen((char *)funcOID));
589 uint8_t shortName[] = "Nothing to declare\0";
590 ranFunDef.ranFunction_Name.ranFunction_ShortName.buf = (uint8_t *)calloc(1, strlen((char *)shortName));
591 ranFunDef.ranFunction_Name.ranFunction_ShortName.size = strlen((char *)shortName);
592 memcpy(ranFunDef.ranFunction_Name.ranFunction_ShortName.buf, shortName, strlen((char *)shortName));
595 RIC_InsertStyle_List_t insertStyleList;
596 insertStyleList.ric_CallProcessIDFormat_Type = 28l;
597 insertStyleList.ric_IndicationHeaderFormat_Type = 29;
598 insertStyleList.ric_IndicationMessageFormat_Type = 30;
599 insertStyleList.ric_InsertActionFormat_Type = 31l;
601 uint8_t styleName[] = "What a style\0";
603 insertStyleList.ric_InsertStyle_Name.buf = (uint8_t *)calloc(1, strlen((char *)styleName));
604 insertStyleList.ric_InsertStyle_Name.size = strlen((char *)styleName);
605 memcpy(insertStyleList.ric_InsertStyle_Name.buf, styleName, strlen((char *)styleName));
608 insertStyleList.ric_InsertStyle_Type = 23;
610 RANparameterDef_Item_t raNparameterDefItem;
611 raNparameterDefItem.ranParameter_ID = 8;
612 raNparameterDefItem.ranParameter_Type = 12;
614 uint8_t ItemName[] = "What a style\0";
615 raNparameterDefItem.ranParameter_Name.buf = (uint8_t *)calloc(1, strlen((char *)ItemName));
616 raNparameterDefItem.ranParameter_Name.size = strlen((char *)ItemName);
617 memcpy(raNparameterDefItem.ranParameter_Name.buf, ItemName, strlen((char *)ItemName));
619 ASN_SEQUENCE_ADD(&insertStyleList.ric_InsertRanParameterDef_List.list, &raNparameterDefItem);
621 ASN_SEQUENCE_ADD(&ranFunDef.ric_InsertStyle_List->list, &insertStyleList);
622 //ranFunDef.ric_InsertStyle_List.
624 uint8_t buffer[8192];
625 size_t buffer_size = 8192;
626 auto *ranDef = &itemIes->value.choice.RANfunction_Item.ranFunctionDefinition;
628 auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, &ranFunDef, buffer, buffer_size);
629 if (er.encoded == -1) {
630 cerr << "encoding of " << asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name << " failed, " << strerror(errno) << endl;
632 } else if (er.encoded > (ssize_t) buffer_size) {
633 cerr << "Buffer of size " << buffer_size << " is to small for " << asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name << endl;
636 ranDef->buf = (uint8_t *)calloc(1, er.encoded);
637 ranDef->size = er.encoded;
638 memcpy(ranDef->buf, buffer, ranDef->size);
643 itemIes->id = ProtocolIE_ID_id_RANfunction_Item;
644 itemIes->criticality = Criticality_reject;
645 itemIes->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
646 itemIes->value.choice.RANfunction_Item.ranFunctionID = 1;
647 // auto *ranDef = &itemIes->value.choice.RANfunction_Item.ranFunctionDefinition;
649 // ranDef->buf = (uint8_t *)calloc(1, ranDef->size);
650 // memcpy(ranDef->buf, buf, ranDef->size);
652 ASN_SEQUENCE_ADD(&ranFlistIEs->value.choice.RANfunctions_List.list, itemIes);
654 auto *itemIes1 = (RANfunction_ItemIEs_t *)calloc(1, sizeof(RANfunction_ItemIEs_t));
655 ASN_STRUCT_RESET(asn_DEF_RANfunction_ItemIEs, itemIes1);
656 itemIes1->id = ProtocolIE_ID_id_RANfunction_Item;
657 itemIes1->criticality = Criticality_reject;
658 itemIes1->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
659 itemIes1->value.choice.RANfunction_Item.ranFunctionID = 7;
660 ranDef = &itemIes1->value.choice.RANfunction_Item.ranFunctionDefinition;
662 ranDef->buf = (uint8_t *)calloc(1, er.encoded);
663 ranDef->size = er.encoded;
664 memcpy(ranDef->buf, buffer, ranDef->size);
666 ASN_SEQUENCE_ADD(&ranFlistIEs->value.choice.RANfunctions_List.list, itemIes1);
669 ASN_SEQUENCE_ADD(&e2SetupRequest->protocolIEs.list, ranFlistIEs);
671 pdu->present = E2AP_PDU_PR_initiatingMessage;
678 void buildSetupSuccsessfulResponse(E2AP_PDU_t *pdu, int mcc, int mnc, uint8_t *data) {
679 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
681 pdu->choice.successfulOutcome = (SuccessfulOutcome_t *)calloc(1, sizeof(SuccessfulOutcome_t));
682 SuccessfulOutcome_t *successfulOutcome = pdu->choice.successfulOutcome;
683 ASN_STRUCT_RESET(asn_DEF_E2setupResponse, &successfulOutcome->value.choice.E2setupResponse);
684 successfulOutcome->procedureCode = ProcedureCode_id_E2setup;
685 successfulOutcome->criticality = Criticality_reject;
686 successfulOutcome->value.present = SuccessfulOutcome__value_PR_E2setupResponse;
689 auto *globalRicidIE = (E2setupResponseIEs_t *)calloc(1, sizeof(E2setupResponseIEs_t));
690 ASN_STRUCT_RESET(asn_DEF_E2setupResponseIEs, globalRicidIE);
692 globalRicidIE->criticality = Criticality_reject;
693 globalRicidIE->id = ProtocolIE_ID_id_GlobalRIC_ID;
694 globalRicidIE->value.present = E2setupResponseIEs__value_PR_GlobalRIC_ID;
695 createPLMN_IDByMCCandMNC(&globalRicidIE->value.choice.GlobalRIC_ID.pLMN_Identity, mcc, mnc);
697 globalRicidIE->value.choice.GlobalRIC_ID.ric_ID = {nullptr, 3, 4};
698 globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.buf = (uint8_t *)calloc(1, globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.size);
699 memcpy(globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.buf, data, globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.size);
700 globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.buf[2] &= (unsigned)0xF0;
703 ASN_STRUCT_RESET(asn_DEF_E2setupResponse, &successfulOutcome->value.choice.E2setupResponse);
704 ASN_SEQUENCE_ADD(&successfulOutcome->value.choice.E2setupResponse.protocolIEs.list, globalRicidIE);
706 auto *ranFunctionAdd = (E2setupResponseIEs_t *)calloc(1, sizeof(E2setupResponseIEs_t));
707 ASN_STRUCT_RESET(asn_DEF_E2setupResponseIEs, ranFunctionAdd);
708 ranFunctionAdd->criticality = Criticality_reject;
709 ranFunctionAdd->id = ProtocolIE_ID_id_RANfunctionsAccepted;
710 ranFunctionAdd->value.present = E2setupResponseIEs__value_PR_RANfunctionsID_List;
712 auto *ranFuncIdItemIEs = (RANfunctionID_ItemIEs_t *)calloc(1, sizeof(RANfunctionID_ItemIEs_t));
714 ranFuncIdItemIEs->criticality = Criticality_ignore;
715 ranFuncIdItemIEs->id = ProtocolIE_ID_id_RANfunctionID_Item;
716 ranFuncIdItemIEs->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item;
717 ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionID = 10;
718 ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionRevision = 1;
720 ASN_SEQUENCE_ADD(&ranFunctionAdd->value.choice.RANfunctionsID_List.list, ranFuncIdItemIEs);
721 ASN_SEQUENCE_ADD(&successfulOutcome->value.choice.E2setupResponse.protocolIEs.list, ranFunctionAdd);
727 pdu->present = E2AP_PDU_PR_successfulOutcome;
731 void buildSetupUnSuccsessfulResponse(E2AP_PDU_t *pdu) {
732 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
734 pdu->choice.unsuccessfulOutcome = (UnsuccessfulOutcome_t *)calloc(1, sizeof(UnsuccessfulOutcome_t));
735 UnsuccessfulOutcome_t *uns = pdu->choice.unsuccessfulOutcome;
736 uns->procedureCode = ProcedureCode_id_E2setup;
737 uns->criticality = Criticality_reject;
738 uns->value.present = UnsuccessfulOutcome__value_PR_E2setupFailure;
740 ASN_STRUCT_RESET(asn_DEF_E2setupFailure, &uns->value.choice.E2setupFailure);
744 auto *e2SetupFIE = (E2setupFailureIEs_t *) calloc(1, sizeof(E2setupFailureIEs_t));
745 ASN_STRUCT_RESET(asn_DEF_E2setupFailureIEs, e2SetupFIE);
747 e2SetupFIE->criticality = Criticality_ignore;
748 e2SetupFIE->id = ProtocolIE_ID_id_Cause;
749 e2SetupFIE->value.present = E2setupFailureIEs__value_PR_Cause;
750 e2SetupFIE->value.choice.Cause.present = Cause_PR_transport;
751 e2SetupFIE->value.choice.Cause.choice.transport = CauseTransport_transport_resource_unavailable;
754 ASN_SEQUENCE_ADD(&uns->value.choice.E2setupFailure.protocolIEs.list, e2SetupFIE);
758 auto *e2SetupFIE = (E2setupFailureIEs_t *) calloc(1, sizeof(E2setupFailureIEs_t));
759 ASN_STRUCT_RESET(asn_DEF_E2setupFailureIEs, e2SetupFIE);
761 e2SetupFIE->criticality = Criticality_ignore;
762 e2SetupFIE->id = ProtocolIE_ID_id_TimeToWait;
763 e2SetupFIE->value.present = E2setupFailureIEs__value_PR_TimeToWait;
764 e2SetupFIE->value.choice.TimeToWait = TimeToWait_v60s;
766 ASN_SEQUENCE_ADD(&uns->value.choice.E2setupFailure.protocolIEs.list, e2SetupFIE);
769 auto *e2SetupFIE = (E2setupFailureIEs_t *) calloc(1, sizeof(E2setupFailureIEs_t));
770 ASN_STRUCT_RESET(asn_DEF_E2setupFailureIEs, e2SetupFIE);
772 e2SetupFIE->criticality = Criticality_ignore;
773 e2SetupFIE->id = ProtocolIE_ID_id_CriticalityDiagnostics;
774 e2SetupFIE->value.present = E2setupFailureIEs__value_PR_CriticalityDiagnostics;
775 e2SetupFIE->value.choice.CriticalityDiagnostics.procedureCode = (ProcedureCode_t *)calloc(1,sizeof(ProcedureCode_t));
776 *e2SetupFIE->value.choice.CriticalityDiagnostics.procedureCode = ProcedureCode_id_E2setup;
777 e2SetupFIE->value.choice.CriticalityDiagnostics.triggeringMessage = (TriggeringMessage_t *)calloc(1,sizeof(TriggeringMessage_t));
778 *e2SetupFIE->value.choice.CriticalityDiagnostics.triggeringMessage = TriggeringMessage_initiating_message;
779 e2SetupFIE->value.choice.CriticalityDiagnostics.procedureCriticality = (Criticality_t *)calloc(1, sizeof(Criticality_t));
780 *e2SetupFIE->value.choice.CriticalityDiagnostics.procedureCriticality = Criticality_reject;
781 ASN_SEQUENCE_ADD(&uns->value.choice.E2setupFailure.protocolIEs.list, e2SetupFIE);
784 pdu->present = E2AP_PDU_PR_unsuccessfulOutcome;
787 #endif //E2_E2BUILDER_H