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 ******************************************************************************/
21 #include "ActionParameter-Item.h"
22 #include "ActionParameter-Value.h"
23 #include "PLMN-Identity.h"
24 #include "GlobalENB-ID.h"
25 #include "GlobalGNB-ID.h"
26 #include "Interface-ID.h"
27 #include "ProtocolIE-Field.h"
28 #include "InterfaceMessageType.h"
29 #include "InterfaceProtocolIE-Item.h"
31 static PLMN_Identity_t *createPLMN_ID(const unsigned char *data) {
33 PLMN_Identity_t *plmnId = calloc(1, sizeof(PLMN_Identity_t));
34 ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, plmnId);
36 plmnId->buf = calloc(1, 3);
37 memcpy(plmnId->buf, data, 3);
42 static GNB_ID_t *createGnb_id(const unsigned char *data, int numOfBits) {
44 if (numOfBits < 22 || numOfBits > 32) {
45 printf("[Error] GNB_ID_t number of bits = %d, needs to be 22 .. 32", numOfBits);
49 GNB_ID_t *gnb = calloc(1, sizeof(GNB_ID_t));
50 ASN_STRUCT_RESET(asn_DEF_GNB_ID, gnb);
52 gnb->present = GNB_ID_PR_gNB_ID;
53 gnb->choice.gNB_ID.size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
54 gnb->choice.gNB_ID.bits_unused = gnb->choice.gNB_ID.size * 8 - numOfBits;
55 gnb->choice.gNB_ID.buf = calloc(1, gnb->choice.gNB_ID.size);
56 memcpy(gnb->choice.gNB_ID.buf, data, gnb->choice.gNB_ID.size);
57 gnb->choice.gNB_ID.buf[gnb->choice.gNB_ID.size - 1] =
58 ((unsigned)(gnb->choice.gNB_ID.buf[gnb->choice.gNB_ID.size - 1] >> (unsigned)gnb->choice.gNB_ID.bits_unused)
59 << (unsigned)gnb->choice.gNB_ID.bits_unused);
64 static GlobalGNB_ID_t *createGlobalGNB_ID(PLMN_Identity_t *plmnIdentity, GNB_ID_t *gnb) {
66 GlobalGNB_ID_t *ggnbId = calloc(1, sizeof(GlobalGNB_ID_t));
67 ASN_STRUCT_RESET(asn_DEF_GlobalGNB_ID, ggnbId);
69 memcpy(&ggnbId->pLMN_Identity, plmnIdentity, sizeof(PLMN_Identity_t));
70 memcpy(&ggnbId->gNB_ID, gnb, sizeof(GNB_ID_t));
75 static Interface_ID_t *createInterfaceIDForGnb(GlobalGNB_ID_t *gnb) {
77 Interface_ID_t *interfaceId = calloc(1, sizeof(Interface_ID_t));
78 ASN_STRUCT_RESET(asn_DEF_Interface_ID, interfaceId);
80 interfaceId->present = Interface_ID_PR_global_gNB_ID;
81 interfaceId->choice.global_gNB_ID = gnb;
86 static InterfaceMessageType_t *createInterfaceMessageInitiating(long procedureCode) {
88 InterfaceMessageType_t *intMsgT = calloc(1, sizeof(InterfaceMessageType_t));
89 ASN_STRUCT_RESET(asn_DEF_InterfaceMessageType, intMsgT);
91 intMsgT->procedureCode = procedureCode;
92 intMsgT->typeOfMessage = TypeOfMessage_initiating_message;
97 E2SM_gNB_X2_eventTriggerDefinition_t* create_eventTriggerDefinition(void)
100 unsigned char plmnidData[3] = {0x33, 0xF4, 0x55};
101 PLMN_Identity_t *plmnid = createPLMN_ID(plmnidData);
102 // xer_fprint(stdout, &asn_DEF_PLMN_Identity, (void *)plmnid);
105 unsigned char gnbData[3] = {0x99, 0xaa, 0xbb};
106 GNB_ID_t *gnb = createGnb_id(gnbData, 26);
107 // xer_fprint(stdout, &asn_DEF_GNB_ID, (void *)gnb);
110 GlobalGNB_ID_t *globaGnb = createGlobalGNB_ID(plmnid, gnb);
111 // xer_fprint(stdout, &asn_DEF_GlobalGNB_ID, (void *)globaGnb);
114 Interface_ID_t *gnbInterfaceId = createInterfaceIDForGnb(globaGnb);
115 // xer_fprint(stdout, &asn_DEF_Interface_ID, (void *)gnbInterfaceId);
117 //InterfaceMessageType
118 InterfaceMessageType_t *initiatingInterface = createInterfaceMessageInitiating(35);
120 //EventTriggerDefinition
121 E2SM_gNB_X2_eventTriggerDefinition_t *eventTrigger = calloc(1, sizeof(E2SM_gNB_X2_eventTriggerDefinition_t));
122 ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, eventTrigger);
124 memcpy(&eventTrigger->interface_ID , gnbInterfaceId, sizeof(Interface_ID_t));
126 eventTrigger->interfaceDirection = 0;
127 memcpy(&eventTrigger->interfaceMessageType, initiatingInterface, sizeof(InterfaceMessageType_t));
132 #define E2AP_ASN1C_FIND_PROTOCOLIE_BY_ID(IE_TYPE, ie, container, IE_ID) \
136 for (ptr = container->protocolIEs.list.array; \
137 ptr < &container->protocolIEs.list.array[container->protocolIEs.list.count]; \
139 if((*ptr)->id == IE_ID) { \
147 void test_eventTriggerDefinition(void)
149 E2SM_gNB_X2_eventTriggerDefinition_t *eventTrigger = create_eventTriggerDefinition();
151 xer_fprint(stdout, &asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, (void *)eventTrigger);
157 eventBuff_len = aper_encode_to_new_buffer(&asn_DEF_E2SM_gNB_X2_eventTriggerDefinition,
158 0, eventTrigger, (void **)&eventBuff);
160 LOG_I("Encoded eventBuff_len = %d", eventBuff_len);
162 //-----------------------------------------------------------------------
163 E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest.xml");
164 e2ap_asn1c_print_pdu(pdu);
166 InitiatingMessage_t *initiatingMessage = pdu->choice.initiatingMessage;
167 xer_fprint(stdout, &asn_DEF_InitiatingMessage, (void *)initiatingMessage);
169 RICsubscriptionRequest_t *request = &initiatingMessage->value.choice.RICsubscriptionRequest;
170 xer_fprint(stdout, &asn_DEF_RICsubscriptionRequest, (void *)request);
172 LOG_I("num of IEs = %d", request->protocolIEs.list.count);
175 RICsubscriptionRequest_IEs_t *ie;
177 ie = request->protocolIEs.list.array[2];
179 // E2AP_ASN1C_FIND_PROTOCOLIE_BY_ID(RICsubscriptionRequest_IEs_t, ie, request, ProtocolIE_ID_id_RICsubscription);
180 // E2AP_ASN1C_FIND_PROTOCOLIE_BY_ID(RICsubscriptionRequest_IEs_t, ie, request, ProtocolIE_ID_id_RICrequestID);
184 xer_fprint(stdout, &asn_DEF_RICsubscription, (void *)ie);
185 // xer_fprint(stdout, &asn_DEF_RICrequestID, (void *)ie);
191 // typedef struct ProtocolIE_Container_119P0 {
192 // A_SEQUENCE_OF(struct RICsubscriptionRequest_IEs) list;
194 // /* Context for parsing across buffer boundaries */
195 // asn_struct_ctx_t _asn_ctx;
196 // } ProtocolIE_Container_119P0_t;