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>
37 //#include <mdclog/mdclog.h>
40 #include "oranE2/E2AP-PDU.h"
41 #include "oranE2/InitiatingMessage.h"
42 #include "oranE2/SuccessfulOutcome.h"
43 #include "oranE2/UnsuccessfulOutcome.h"
45 #include "oranE2/ProtocolIE-Field.h"
46 #include "oranE2/ENB-ID.h"
47 #include "oranE2/GlobalENB-ID.h"
48 #include "oranE2/GlobalE2node-gNB-ID.h"
49 #include "oranE2/constr_TYPE.h"
50 #include "oranE2/asn_constant.h"
54 #define printEntry(type, function); fprintf(stdout, "start Test %s , %s", type, function);
57 static void checkAndPrint(asn_TYPE_descriptor_t *typeDescriptor, void *data, char *dataType, const char *function) {
58 char errbuf[128]; /* Buffer for error message */
59 size_t errlen = sizeof(errbuf); /* Size of the buffer */
60 if (asn_check_constraints(typeDescriptor, data, errbuf, &errlen) != 0) {
61 fprintf(stderr, "%s Constraint validation failed: %s", dataType, errbuf);
63 fprintf(stdout, "%s successes function %s", dataType, function);
66 void createPLMN_IDByMCCandMNC(PLMN_Identity_t *plmnId, int mcc, int mnc) {
68 //printEntry("PLMN_Identity_t", __func__)
70 ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, plmnId);
72 plmnId->buf = (uint8_t *) calloc(1, 3);
73 volatile auto mcc1 = (unsigned int) (mcc / 100);
74 volatile auto mcc2 = (unsigned int) (mcc / 10 % 10);
75 volatile auto mcc3 = (unsigned int) (mcc % 10);
76 plmnId->buf[0] = mcc2 << 4 | mcc1;
78 volatile auto mnc1 = (unsigned int)0;
79 volatile auto mnc2 = (unsigned int)0;
80 volatile auto mnc3 = (unsigned int)0;
83 mnc1 = (unsigned int) (mnc / 100);
84 mnc2 = (unsigned int) (mnc / 10 % 10);
85 mnc3 = (unsigned int) (mnc % 10);
87 mnc1 = (unsigned int) (mnc / 10);
88 mnc2 = (unsigned int) (mnc % 10);
91 plmnId->buf[1] = mcc3 << 4 | mnc3 ;
92 plmnId->buf[2] = mnc2 << 4 | mnc1 ;
94 //checkAndPrint(&asn_DEF_PLMN_Identity, plmnId, (char *) "PLMN_Identity_t", __func__);
99 PLMN_Identity_t *createPLMN_ID(const unsigned char *data) {
100 printEntry("PLMN_Identity_t", __func__)
101 auto *plmnId = (PLMN_Identity_t *) calloc(1, sizeof(PLMN_Identity_t));
102 ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, plmnId);
104 plmnId->buf = (uint8_t *) calloc(1, 3);
105 memcpy(plmnId->buf, data, 3);
107 checkAndPrint(&asn_DEF_PLMN_Identity, plmnId, (char *) "PLMN_Identity_t", __func__);
112 BIT_STRING_t *createBIT_STRING(int size, int unusedBits, uint8_t *data) {
113 printEntry("BIT_STRING_t", __func__)
114 auto *bitString = (BIT_STRING_t *) calloc(1, sizeof(BIT_STRING_t));
115 ASN_STRUCT_RESET(asn_DEF_BIT_STRING, bitString);
116 bitString->size = size;
117 bitString->bits_unused = unusedBits;
118 bitString->buf = (uint8_t *) calloc(1, size);
120 data[bitString->size - 1] = ((unsigned) (data[bitString->size - 1] >>
121 (unsigned) bitString->bits_unused)
122 << (unsigned) bitString->bits_unused);
123 memcpy(bitString->buf, data, size);
125 checkAndPrint(&asn_DEF_BIT_STRING, bitString, (char *) "BIT_STRING_t", __func__);
131 OCTET_STRING_t *createOCTET_STRING(const unsigned char *data, int size) {
132 printEntry("OCTET_STRING_t", __func__)
133 auto *octs = (PLMN_Identity_t *) calloc(1, sizeof(PLMN_Identity_t));
134 ASN_STRUCT_RESET(asn_DEF_OCTET_STRING, octs);
136 octs->buf = (uint8_t *) calloc(1, size);
137 memcpy(octs->buf, data, size);
139 checkAndPrint(&asn_DEF_OCTET_STRING, octs, (char *) "OCTET_STRING_t", __func__);
144 ENB_ID_t *createENB_ID(ENB_ID_PR enbType, unsigned char *data) {
145 printEntry("ENB_ID_t", __func__)
146 auto *enb = (ENB_ID_t *) calloc(1, sizeof(ENB_ID_t));
147 ASN_STRUCT_RESET(asn_DEF_ENB_ID, enb);
149 enb->present = enbType;
152 case ENB_ID_PR_macro_eNB_ID: { // 20 bit 3 bytes
153 enb->choice.macro_eNB_ID.size = 3;
154 enb->choice.macro_eNB_ID.bits_unused = 4;
156 enb->present = ENB_ID_PR_macro_eNB_ID;
158 enb->choice.macro_eNB_ID.buf = (uint8_t *) calloc(1, enb->choice.macro_eNB_ID.size);
159 data[enb->choice.macro_eNB_ID.size - 1] = ((unsigned) (data[enb->choice.macro_eNB_ID.size - 1] >>
160 (unsigned) enb->choice.macro_eNB_ID.bits_unused)
161 << (unsigned) enb->choice.macro_eNB_ID.bits_unused);
162 memcpy(enb->choice.macro_eNB_ID.buf, data, enb->choice.macro_eNB_ID.size);
166 case ENB_ID_PR_home_eNB_ID: { // 28 bit 4 bytes
167 enb->choice.home_eNB_ID.size = 4;
168 enb->choice.home_eNB_ID.bits_unused = 4;
169 enb->present = ENB_ID_PR_home_eNB_ID;
171 enb->choice.home_eNB_ID.buf = (uint8_t *) calloc(1, enb->choice.home_eNB_ID.size);
172 data[enb->choice.home_eNB_ID.size - 1] = ((unsigned) (data[enb->choice.home_eNB_ID.size - 1] >>
173 (unsigned) enb->choice.home_eNB_ID.bits_unused)
174 << (unsigned) enb->choice.home_eNB_ID.bits_unused);
175 memcpy(enb->choice.home_eNB_ID.buf, data, enb->choice.home_eNB_ID.size);
178 case ENB_ID_PR_short_Macro_eNB_ID: { // 18 bit - 3 bytes
179 enb->choice.short_Macro_eNB_ID.size = 3;
180 enb->choice.short_Macro_eNB_ID.bits_unused = 6;
181 enb->present = ENB_ID_PR_short_Macro_eNB_ID;
183 enb->choice.short_Macro_eNB_ID.buf = (uint8_t *) calloc(1, enb->choice.short_Macro_eNB_ID.size);
184 data[enb->choice.short_Macro_eNB_ID.size - 1] = (
185 (unsigned) (data[enb->choice.short_Macro_eNB_ID.size - 1] >>
186 (unsigned) enb->choice.short_Macro_eNB_ID.bits_unused)
187 << (unsigned) enb->choice.short_Macro_eNB_ID.bits_unused);
188 memcpy(enb->choice.short_Macro_eNB_ID.buf, data, enb->choice.short_Macro_eNB_ID.size);
191 case ENB_ID_PR_long_Macro_eNB_ID: { // 21
192 enb->choice.long_Macro_eNB_ID.size = 3;
193 enb->choice.long_Macro_eNB_ID.bits_unused = 3;
194 enb->present = ENB_ID_PR_long_Macro_eNB_ID;
196 enb->choice.long_Macro_eNB_ID.buf = (uint8_t *) calloc(1, enb->choice.long_Macro_eNB_ID.size);
197 data[enb->choice.long_Macro_eNB_ID.size - 1] =
198 ((unsigned) (data[enb->choice.long_Macro_eNB_ID.size - 1] >> (unsigned) enb->choice.long_Macro_eNB_ID.bits_unused)
199 << (unsigned) enb->choice.long_Macro_eNB_ID.bits_unused);
200 memcpy(enb->choice.long_Macro_eNB_ID.buf, data, enb->choice.long_Macro_eNB_ID.size);
208 checkAndPrint(&asn_DEF_ENB_ID, enb, (char *) "ENB_ID_t", __func__);
212 GlobalENB_ID_t *createGlobalENB_ID(PLMN_Identity_t *plmnIdentity, ENB_ID_t *enbId) {
213 printEntry("GlobalENB_ID_t", __func__)
214 auto *genbId = (GlobalENB_ID_t *) calloc(1, sizeof(GlobalENB_ID_t));
215 ASN_STRUCT_RESET(asn_DEF_GlobalENB_ID, genbId);
216 memcpy(&genbId->pLMN_Identity, plmnIdentity, sizeof(PLMN_Identity_t));
217 memcpy(&genbId->eNB_ID, enbId, sizeof(ENB_ID_t));
219 checkAndPrint(&asn_DEF_GlobalENB_ID, genbId, (char *) "GlobalENB_ID_t", __func__);
224 //static void buildInitiatingMessagePDU(E2AP_PDU_t &pdu, InitiatingMessage_t *initMsg) {
225 // pdu.present = E2AP_PDU_PR_initiatingMessage;
226 // pdu.choice.initiatingMessage = initMsg;
230 static void buildInitMsg(InitiatingMessage_t &initMsg,
231 InitiatingMessage__value_PR present,
232 ProcedureCode_t procedureCode,
233 Criticality_t criticality,
235 initMsg.value.present = present;
236 initMsg.procedureCode = procedureCode;
237 initMsg.criticality = criticality;
240 case InitiatingMessage__value_PR_RICsubscriptionRequest: {
241 memcpy(&initMsg.value.choice.RICsubscriptionRequest, value, sizeof(*value));
244 case InitiatingMessage__value_PR_RICsubscriptionDeleteRequest: {
245 memcpy(&initMsg.value.choice.RICsubscriptionDeleteRequest, value, sizeof(*value));
248 case InitiatingMessage__value_PR_RICserviceUpdate: {
249 memcpy(&initMsg.value.choice.RICserviceUpdate, value, sizeof(*value));
252 case InitiatingMessage__value_PR_RICcontrolRequest: {
253 memcpy(&initMsg.value.choice.RICcontrolRequest, value, sizeof(*value));
256 case InitiatingMessage__value_PR_RICindication: {
257 memcpy(&initMsg.value.choice.RICindication, value, sizeof(*value));
260 case InitiatingMessage__value_PR_RICserviceQuery: {
261 memcpy(&initMsg.value.choice.RICserviceQuery, value, sizeof(*value));
264 case InitiatingMessage__value_PR_NOTHING:
271 //static void buildSuccsesfulMessagePDU(E2AP_PDU_t &pdu, SuccessfulOutcome_t *succMsg) {
272 // pdu.present = E2AP_PDU_PR_successfulOutcome;
273 // pdu.choice.successfulOutcome = succMsg;
277 static void buildSuccMsg(SuccessfulOutcome_t &succMsg,
278 SuccessfulOutcome__value_PR present,
279 ProcedureCode_t procedureCode,
280 Criticality_t criticality,
282 succMsg.value.present = present;
283 succMsg.procedureCode = procedureCode;
284 succMsg.criticality = criticality;
287 case SuccessfulOutcome__value_PR_RICsubscriptionResponse: {
288 memcpy(&succMsg.value.choice.RICsubscriptionResponse, value, sizeof(*value));
291 case SuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse: {
292 memcpy(&succMsg.value.choice.RICsubscriptionDeleteResponse, value, sizeof(*value));
295 case SuccessfulOutcome__value_PR_RICserviceUpdateAcknowledge: {
296 memcpy(&succMsg.value.choice.RICserviceUpdateAcknowledge, value, sizeof(*value));
299 case SuccessfulOutcome__value_PR_RICcontrolAcknowledge: {
300 memcpy(&succMsg.value.choice.RICcontrolAcknowledge, value, sizeof(*value));
303 case SuccessfulOutcome__value_PR_ResetResponse: {
304 memcpy(&succMsg.value.choice.ResetResponse, value, sizeof(*value));
307 case SuccessfulOutcome__value_PR_NOTHING:
314 //static void buildUnSucssesfullMessagePDU(E2AP_PDU_t &pdu, UnsuccessfulOutcome_t *unSuccMsg) {
315 // pdu.present = E2AP_PDU_PR_unsuccessfulOutcome;
316 // pdu.choice.unsuccessfulOutcome = unSuccMsg;
320 static void buildUnSuccMsg(UnsuccessfulOutcome_t &unSuccMsg,
321 UnsuccessfulOutcome__value_PR present,
322 ProcedureCode_t procedureCode,
323 Criticality_t criticality,
325 unSuccMsg.value.present = present;
326 unSuccMsg.procedureCode = procedureCode;
327 unSuccMsg.criticality = criticality;
330 case UnsuccessfulOutcome__value_PR_RICsubscriptionFailure: {
331 memcpy(&unSuccMsg.value.choice.RICsubscriptionFailure, value, sizeof(*value));
334 case UnsuccessfulOutcome__value_PR_RICsubscriptionDeleteFailure: {
335 memcpy(&unSuccMsg.value.choice.RICsubscriptionDeleteFailure, value, sizeof(*value));
338 case UnsuccessfulOutcome__value_PR_RICserviceUpdateFailure: {
339 memcpy(&unSuccMsg.value.choice.RICserviceUpdateFailure, value, sizeof(*value));
342 case UnsuccessfulOutcome__value_PR_RICcontrolFailure: {
343 memcpy(&unSuccMsg.value.choice.RICcontrolFailure, value, sizeof(*value));
347 case UnsuccessfulOutcome__value_PR_NOTHING:
354 //static void createPLMN_ID(PLMN_Identity_t &plmnId, const unsigned char *data) {
355 // //printEntry("PLMN_Identity_t", __func__)
356 // //PLMN_Identity_t *plmnId = calloc(1, sizeof(PLMN_Identity_t));
357 // ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, &plmnId);
358 // plmnId.size = 3;// uint64_t st = 0;
359 //// uint32_t aux1 = 0;
360 //// st = rdtscp(aux1);
362 // plmnId.buf = (uint8_t *) calloc(1, 3);
363 // memcpy(plmnId.buf, data, 3);
365 // checkAndPrint(&asn_DEF_PLMN_Identity, &plmnId, (char *) "PLMN_Identity_t", __func__);
369 static void createENB_ID(ENB_ID_t &enb, ENB_ID_PR enbType, unsigned char *data) {
370 //printEntry("ENB_ID_t", __func__)
371 ASN_STRUCT_RESET(asn_DEF_ENB_ID, &enb);
372 enb.present = enbType;
374 case ENB_ID_PR_macro_eNB_ID: { // 20 bit 3 bytes
375 enb.choice.macro_eNB_ID.size = 3;
376 enb.choice.macro_eNB_ID.bits_unused = 4;
378 enb.present = ENB_ID_PR_macro_eNB_ID;
380 enb.choice.macro_eNB_ID.buf = (uint8_t *) calloc(1, enb.choice.macro_eNB_ID.size);
381 data[enb.choice.macro_eNB_ID.size - 1] = ((unsigned) (data[enb.choice.macro_eNB_ID.size - 1]
382 >> (unsigned) enb.choice.macro_eNB_ID.bits_unused)
383 << (unsigned) enb.choice.macro_eNB_ID.bits_unused);
384 memcpy(enb.choice.macro_eNB_ID.buf, data, enb.choice.macro_eNB_ID.size);
388 case ENB_ID_PR_home_eNB_ID: { // 28 bit 4 bytes
389 enb.choice.home_eNB_ID.size = 4;
390 enb.choice.home_eNB_ID.bits_unused = 4;
391 enb.present = ENB_ID_PR_home_eNB_ID;
393 enb.choice.home_eNB_ID.buf = (uint8_t *) calloc(1, enb.choice.home_eNB_ID.size);
394 data[enb.choice.home_eNB_ID.size - 1] = ((unsigned) (data[enb.choice.home_eNB_ID.size - 1]
395 >> (unsigned) enb.choice.home_eNB_ID.bits_unused)
396 << (unsigned) enb.choice.home_eNB_ID.bits_unused);
397 memcpy(enb.choice.home_eNB_ID.buf, data, enb.choice.home_eNB_ID.size);
400 case ENB_ID_PR_short_Macro_eNB_ID: { // 18 bit - 3 bytes
401 enb.choice.short_Macro_eNB_ID.size = 3;
402 enb.choice.short_Macro_eNB_ID.bits_unused = 6;
403 enb.present = ENB_ID_PR_short_Macro_eNB_ID;
405 enb.choice.short_Macro_eNB_ID.buf = (uint8_t *) calloc(1, enb.choice.short_Macro_eNB_ID.size);
406 data[enb.choice.short_Macro_eNB_ID.size - 1] = ((unsigned) (data[enb.choice.short_Macro_eNB_ID.size - 1]
407 >> (unsigned) enb.choice.short_Macro_eNB_ID.bits_unused)
408 << (unsigned) enb.choice.short_Macro_eNB_ID.bits_unused);
409 memcpy(enb.choice.short_Macro_eNB_ID.buf, data, enb.choice.short_Macro_eNB_ID.size);
412 case ENB_ID_PR_long_Macro_eNB_ID: { // 21
413 enb.choice.long_Macro_eNB_ID.size = 3;
414 enb.choice.long_Macro_eNB_ID.bits_unused = 3;
415 enb.present = ENB_ID_PR_long_Macro_eNB_ID;
417 enb.choice.long_Macro_eNB_ID.buf = (uint8_t *) calloc(1, enb.choice.long_Macro_eNB_ID.size);
418 data[enb.choice.long_Macro_eNB_ID.size - 1] = ((unsigned) (data[enb.choice.long_Macro_eNB_ID.size - 1]
419 >> (unsigned) enb.choice.long_Macro_eNB_ID.bits_unused)
420 << (unsigned) enb.choice.long_Macro_eNB_ID.bits_unused);
421 memcpy(enb.choice.long_Macro_eNB_ID.buf, data, enb.choice.long_Macro_eNB_ID.size);
428 checkAndPrint(&asn_DEF_ENB_ID, &enb, (char *) "ENB_ID_t", __func__);
432 static void buildGlobalENB_ID(GlobalENB_ID_t *gnbId,
433 const unsigned char *gnbData,
435 unsigned char *enbData) {
436 auto *plmnID = createPLMN_ID(gnbData);
437 memcpy(&gnbId->pLMN_Identity, plmnID, sizeof(PLMN_Identity_t));
438 createENB_ID(gnbId->eNB_ID, enbType, enbData);
439 checkAndPrint(&asn_DEF_GlobalENB_ID, gnbId, (char *) "GlobalENB_ID_t", __func__);
443 void buildSetupRequest(E2AP_PDU_t *pdu, int mcc, int mnc) {
444 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
446 pdu->choice.initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t));
447 auto *initiatingMessage = pdu->choice.initiatingMessage;
448 ASN_STRUCT_RESET(asn_DEF_InitiatingMessage, initiatingMessage);
449 initiatingMessage->procedureCode = ProcedureCode_id_E2setup;
450 initiatingMessage->criticality = Criticality_reject;
451 initiatingMessage->value.present = InitiatingMessage__value_PR_E2setupRequest;
453 auto *e2SetupRequestIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
454 ASN_STRUCT_RESET(asn_DEF_E2setupRequestIEs, e2SetupRequestIEs);
456 e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.gNB = (GlobalE2node_gNB_ID_t *)calloc(1, sizeof(GlobalE2node_gNB_ID_t));
457 auto *globalE2NodeGNbId = e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.gNB;
458 ASN_STRUCT_RESET(asn_DEF_GlobalE2node_gNB_ID, globalE2NodeGNbId);
460 createPLMN_IDByMCCandMNC(&globalE2NodeGNbId->global_gNB_ID.plmn_id, mcc, mnc);
461 globalE2NodeGNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
462 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = 4;
463 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf =
464 (uint8_t *) calloc(1, globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size); //22..32 bits
465 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.bits_unused = 0;
466 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[0] = 0xB5;
467 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[1] = 0xC6;
468 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[2] = 0x77;
469 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[3] = 0x88;
471 e2SetupRequestIEs->criticality = Criticality_reject;
472 e2SetupRequestIEs->id = ProtocolIE_ID_id_GlobalE2node_ID;
473 e2SetupRequestIEs->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
474 e2SetupRequestIEs->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
477 auto *e2SetupRequest = &initiatingMessage->value.choice.E2setupRequest;
479 ASN_STRUCT_RESET(asn_DEF_E2setupRequest, e2SetupRequest);
480 ASN_SEQUENCE_ADD(&e2SetupRequest->protocolIEs.list, e2SetupRequestIEs);
482 pdu->present = E2AP_PDU_PR_initiatingMessage;
485 void buildSetupRequestWithFunc(E2AP_PDU_t *pdu, int mcc, int mnc) {
486 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
488 pdu->choice.initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t));
489 auto *initiatingMessage = pdu->choice.initiatingMessage;
490 ASN_STRUCT_RESET(asn_DEF_InitiatingMessage, initiatingMessage);
491 initiatingMessage->procedureCode = ProcedureCode_id_E2setup;
492 initiatingMessage->criticality = Criticality_reject;
493 initiatingMessage->value.present = InitiatingMessage__value_PR_E2setupRequest;
495 auto *e2SetupRequestIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
496 ASN_STRUCT_RESET(asn_DEF_E2setupRequestIEs, e2SetupRequestIEs);
498 e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.gNB = (GlobalE2node_gNB_ID_t *)calloc(1, sizeof(GlobalE2node_gNB_ID_t));
499 auto *globalE2NodeGNbId = e2SetupRequestIEs->value.choice.GlobalE2node_ID.choice.gNB;
500 ASN_STRUCT_RESET(asn_DEF_GlobalE2node_gNB_ID, globalE2NodeGNbId);
502 createPLMN_IDByMCCandMNC(&globalE2NodeGNbId->global_gNB_ID.plmn_id, mcc, mnc);
503 globalE2NodeGNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
504 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = 4;
505 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf =
506 (uint8_t *) calloc(1, globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size); //22..32 bits
507 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.bits_unused = 0;
508 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[0] = 0xB5;
509 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[1] = 0xC6;
510 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[2] = 0x77;
511 globalE2NodeGNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf[3] = 0x88;
513 e2SetupRequestIEs->criticality = Criticality_reject;
514 e2SetupRequestIEs->id = ProtocolIE_ID_id_GlobalE2node_ID;
515 e2SetupRequestIEs->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
516 e2SetupRequestIEs->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
519 auto *e2SetupRequest = &initiatingMessage->value.choice.E2setupRequest;
521 ASN_STRUCT_RESET(asn_DEF_E2setupRequest, e2SetupRequest);
522 ASN_SEQUENCE_ADD(&e2SetupRequest->protocolIEs.list, e2SetupRequestIEs);
524 auto *ranFlistIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
525 ASN_STRUCT_RESET(asn_DEF_E2setupRequestIEs, ranFlistIEs);
526 ranFlistIEs->criticality = Criticality_reject;
527 ranFlistIEs->id = ProtocolIE_ID_id_RANfunctionsAdded;
528 ranFlistIEs->value.present = E2setupRequestIEs__value_PR_RANfunctions_List;
530 auto *itemIes = (RANfunction_ItemIEs_t *)calloc(1, sizeof(RANfunction_ItemIEs_t));
531 ASN_STRUCT_RESET(asn_DEF_RANfunction_ItemIEs, itemIes);
534 E2SM_gNB_NRT_RANfunction_Definition_t ranFunDef;
535 uint8_t funcDes[] = "asdfghjklpoiuytrewq\0";
536 ranFunDef.ranFunction_Name.ranFunction_Description.buf = (uint8_t *)calloc(1, strlen((char *)funcDes));
537 ranFunDef.ranFunction_Name.ranFunction_Description.size = strlen((char *)funcDes);
538 memcpy(ranFunDef.ranFunction_Name.ranFunction_Description.buf, funcDes, strlen((char *)funcDes));
540 uint8_t funcOID[] = "ABCDEFGHIJ1234567890\0";
541 ranFunDef.ranFunction_Name.ranFunction_E2SM_OID.buf = (uint8_t *)calloc(1, strlen((char *)funcOID));
542 ranFunDef.ranFunction_Name.ranFunction_E2SM_OID.size = strlen((char *)funcOID);
543 memcpy(ranFunDef.ranFunction_Name.ranFunction_E2SM_OID.buf, funcOID, strlen((char *)funcOID));
545 uint8_t shortName[] = "Nothing to declare\0";
546 ranFunDef.ranFunction_Name.ranFunction_ShortName.buf = (uint8_t *)calloc(1, strlen((char *)shortName));
547 ranFunDef.ranFunction_Name.ranFunction_ShortName.size = strlen((char *)shortName);
548 memcpy(ranFunDef.ranFunction_Name.ranFunction_ShortName.buf, shortName, strlen((char *)shortName));
551 RIC_InsertStyle_List_t insertStyleList;
552 insertStyleList.ric_CallProcessIDFormat_Type = 28l;
553 insertStyleList.ric_IndicationHeaderFormat_Type = 29;
554 insertStyleList.ric_IndicationMessageFormat_Type = 30;
555 insertStyleList.ric_InsertActionFormat_Type = 31l;
557 uint8_t styleName[] = "What a style\0";
559 insertStyleList.ric_InsertStyle_Name.buf = (uint8_t *)calloc(1, strlen((char *)styleName));
560 insertStyleList.ric_InsertStyle_Name.size = strlen((char *)styleName);
561 memcpy(insertStyleList.ric_InsertStyle_Name.buf, styleName, strlen((char *)styleName));
564 insertStyleList.ric_InsertStyle_Type = 23;
566 RANparameterDef_Item_t raNparameterDefItem;
567 raNparameterDefItem.ranParameter_ID = 8;
568 raNparameterDefItem.ranParameter_Type = 12;
570 uint8_t ItemName[] = "What a style\0";
571 raNparameterDefItem.ranParameter_Name.buf = (uint8_t *)calloc(1, strlen((char *)ItemName));
572 raNparameterDefItem.ranParameter_Name.size = strlen((char *)ItemName);
573 memcpy(raNparameterDefItem.ranParameter_Name.buf, ItemName, strlen((char *)ItemName));
575 ASN_SEQUENCE_ADD(&insertStyleList.ric_InsertRanParameterDef_List.list, &raNparameterDefItem);
577 ASN_SEQUENCE_ADD(&ranFunDef.ric_InsertStyle_List->list, &insertStyleList);
578 //ranFunDef.ric_InsertStyle_List.
580 uint8_t buffer[8192];
581 size_t buffer_size = 8192;
582 auto *ranDef = &itemIes->value.choice.RANfunction_Item.ranFunctionDefinition;
584 auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, &ranFunDef, buffer, buffer_size);
585 if (er.encoded == -1) {
586 cerr << "encoding of " << asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name << " failed, " << strerror(errno) << endl;
588 } else if (er.encoded > (ssize_t) buffer_size) {
589 cerr << "Buffer of size " << buffer_size << " is to small for " << asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name << endl;
592 ranDef->buf = (uint8_t *)calloc(1, er.encoded);
593 ranDef->size = er.encoded;
594 memcpy(ranDef->buf, buffer, ranDef->size);
599 itemIes->id = ProtocolIE_ID_id_RANfunction_Item;
600 itemIes->criticality = Criticality_reject;
601 itemIes->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
602 itemIes->value.choice.RANfunction_Item.ranFunctionID = 1;
603 // auto *ranDef = &itemIes->value.choice.RANfunction_Item.ranFunctionDefinition;
605 // ranDef->buf = (uint8_t *)calloc(1, ranDef->size);
606 // memcpy(ranDef->buf, buf, ranDef->size);
608 ASN_SEQUENCE_ADD(&ranFlistIEs->value.choice.RANfunctions_List.list, itemIes);
610 auto *itemIes1 = (RANfunction_ItemIEs_t *)calloc(1, sizeof(RANfunction_ItemIEs_t));
611 ASN_STRUCT_RESET(asn_DEF_RANfunction_ItemIEs, itemIes1);
612 itemIes1->id = ProtocolIE_ID_id_RANfunction_Item;
613 itemIes1->criticality = Criticality_reject;
614 itemIes1->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
615 itemIes1->value.choice.RANfunction_Item.ranFunctionID = 7;
616 ranDef = &itemIes1->value.choice.RANfunction_Item.ranFunctionDefinition;
618 ranDef->buf = (uint8_t *)calloc(1, er.encoded);
619 ranDef->size = er.encoded;
620 memcpy(ranDef->buf, buffer, ranDef->size);
622 ASN_SEQUENCE_ADD(&ranFlistIEs->value.choice.RANfunctions_List.list, itemIes1);
625 ASN_SEQUENCE_ADD(&e2SetupRequest->protocolIEs.list, ranFlistIEs);
627 pdu->present = E2AP_PDU_PR_initiatingMessage;
634 void buildSetupSuccsessfulResponse(E2AP_PDU_t *pdu, int mcc, int mnc, uint8_t *data) {
635 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
637 pdu->choice.successfulOutcome = (SuccessfulOutcome_t *)calloc(1, sizeof(SuccessfulOutcome_t));
638 SuccessfulOutcome_t *successfulOutcome = pdu->choice.successfulOutcome;
639 ASN_STRUCT_RESET(asn_DEF_E2setupResponse, &successfulOutcome->value.choice.E2setupResponse);
640 successfulOutcome->procedureCode = ProcedureCode_id_E2setup;
641 successfulOutcome->criticality = Criticality_reject;
642 successfulOutcome->value.present = SuccessfulOutcome__value_PR_E2setupResponse;
645 auto *globalRicidIE = (E2setupResponseIEs_t *)calloc(1, sizeof(E2setupResponseIEs_t));
646 ASN_STRUCT_RESET(asn_DEF_E2setupResponseIEs, globalRicidIE);
648 globalRicidIE->criticality = Criticality_reject;
649 globalRicidIE->id = ProtocolIE_ID_id_GlobalRIC_ID;
650 globalRicidIE->value.present = E2setupResponseIEs__value_PR_GlobalRIC_ID;
651 createPLMN_IDByMCCandMNC(&globalRicidIE->value.choice.GlobalRIC_ID.pLMN_Identity, mcc, mnc);
653 globalRicidIE->value.choice.GlobalRIC_ID.ric_ID = {nullptr, 3, 4};
654 globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.buf = (uint8_t *)calloc(1, globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.size);
655 memcpy(globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.buf, data, globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.size);
656 globalRicidIE->value.choice.GlobalRIC_ID.ric_ID.buf[2] &= (unsigned)0xF0;
659 ASN_STRUCT_RESET(asn_DEF_E2setupResponse, &successfulOutcome->value.choice.E2setupResponse);
660 ASN_SEQUENCE_ADD(&successfulOutcome->value.choice.E2setupResponse.protocolIEs.list, globalRicidIE);
662 auto *ranFunctionAdd = (E2setupResponseIEs_t *)calloc(1, sizeof(E2setupResponseIEs_t));
663 ASN_STRUCT_RESET(asn_DEF_E2setupResponseIEs, ranFunctionAdd);
664 ranFunctionAdd->criticality = Criticality_reject;
665 ranFunctionAdd->id = ProtocolIE_ID_id_RANfunctionsAccepted;
666 ranFunctionAdd->value.present = E2setupResponseIEs__value_PR_RANfunctionsID_List;
668 auto *ranFuncIdItemIEs = (RANfunctionID_ItemIEs_t *)calloc(1, sizeof(RANfunctionID_ItemIEs_t));
670 ranFuncIdItemIEs->criticality = Criticality_ignore;
671 ranFuncIdItemIEs->id = ProtocolIE_ID_id_RANfunctionID_Item;
672 ranFuncIdItemIEs->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item;
673 ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionID = 10;
674 ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionRevision = 1;
676 ASN_SEQUENCE_ADD(&ranFunctionAdd->value.choice.RANfunctionsID_List.list, ranFuncIdItemIEs);
677 ASN_SEQUENCE_ADD(&successfulOutcome->value.choice.E2setupResponse.protocolIEs.list, ranFunctionAdd);
683 pdu->present = E2AP_PDU_PR_successfulOutcome;
687 void buildSetupUnSuccsessfulResponse(E2AP_PDU_t *pdu) {
688 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
690 pdu->choice.unsuccessfulOutcome = (UnsuccessfulOutcome_t *)calloc(1, sizeof(UnsuccessfulOutcome_t));
691 UnsuccessfulOutcome_t *uns = pdu->choice.unsuccessfulOutcome;
692 uns->procedureCode = ProcedureCode_id_E2setup;
693 uns->criticality = Criticality_reject;
694 uns->value.present = UnsuccessfulOutcome__value_PR_E2setupFailure;
696 ASN_STRUCT_RESET(asn_DEF_E2setupFailure, &uns->value.choice.E2setupFailure);
700 auto *e2SetupFIE = (E2setupFailureIEs_t *) calloc(1, sizeof(E2setupFailureIEs_t));
701 ASN_STRUCT_RESET(asn_DEF_E2setupFailureIEs, e2SetupFIE);
703 e2SetupFIE->criticality = Criticality_ignore;
704 e2SetupFIE->id = ProtocolIE_ID_id_Cause;
705 e2SetupFIE->value.present = E2setupFailureIEs__value_PR_Cause;
706 e2SetupFIE->value.choice.Cause.present = Cause_PR_transport;
707 e2SetupFIE->value.choice.Cause.choice.transport = CauseTransport_transport_resource_unavailable;
710 ASN_SEQUENCE_ADD(&uns->value.choice.E2setupFailure.protocolIEs.list, e2SetupFIE);
714 auto *e2SetupFIE = (E2setupFailureIEs_t *) calloc(1, sizeof(E2setupFailureIEs_t));
715 ASN_STRUCT_RESET(asn_DEF_E2setupFailureIEs, e2SetupFIE);
717 e2SetupFIE->criticality = Criticality_ignore;
718 e2SetupFIE->id = ProtocolIE_ID_id_TimeToWait;
719 e2SetupFIE->value.present = E2setupFailureIEs__value_PR_TimeToWait;
720 e2SetupFIE->value.choice.TimeToWait = TimeToWait_v60s;
722 ASN_SEQUENCE_ADD(&uns->value.choice.E2setupFailure.protocolIEs.list, e2SetupFIE);
725 auto *e2SetupFIE = (E2setupFailureIEs_t *) calloc(1, sizeof(E2setupFailureIEs_t));
726 ASN_STRUCT_RESET(asn_DEF_E2setupFailureIEs, e2SetupFIE);
728 e2SetupFIE->criticality = Criticality_ignore;
729 e2SetupFIE->id = ProtocolIE_ID_id_CriticalityDiagnostics;
730 e2SetupFIE->value.present = E2setupFailureIEs__value_PR_CriticalityDiagnostics;
731 e2SetupFIE->value.choice.CriticalityDiagnostics.procedureCode = (ProcedureCode_t *)calloc(1,sizeof(ProcedureCode_t));
732 *e2SetupFIE->value.choice.CriticalityDiagnostics.procedureCode = ProcedureCode_id_E2setup;
733 e2SetupFIE->value.choice.CriticalityDiagnostics.triggeringMessage = (TriggeringMessage_t *)calloc(1,sizeof(TriggeringMessage_t));
734 *e2SetupFIE->value.choice.CriticalityDiagnostics.triggeringMessage = TriggeringMessage_initiating_message;
735 e2SetupFIE->value.choice.CriticalityDiagnostics.procedureCriticality = (Criticality_t *)calloc(1, sizeof(Criticality_t));
736 *e2SetupFIE->value.choice.CriticalityDiagnostics.procedureCriticality = Criticality_reject;
737 ASN_SEQUENCE_ADD(&uns->value.choice.E2setupFailure.protocolIEs.list, e2SetupFIE);
740 pdu->present = E2AP_PDU_PR_unsuccessfulOutcome;
743 #endif //E2_E2BUILDER_H