blob: 9915948fcfc0082202923f9dfb510508421c624a [file] [log] [blame]
ss412g1a79bdf2019-10-24 12:03:05 +03001/*
2 * Copyright 2019 AT&T Intellectual Property
3 * Copyright 2019 Nokia
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
nm755n2e268142019-11-28 16:40:23 +000018/*
19 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 * platform project (RICP).
21 */
22
23
ss412g1a79bdf2019-10-24 12:03:05 +030024//
25// Created by adi ENZEL on 6/19/19.
26//
27
28#include "e2sm.h"
29
30#define printEntry(type, function) \
31 if (mdclog_level_get() >= MDCLOG_DEBUG) { \
32 mdclog_write(MDCLOG_DEBUG, "start Test %s , %s", type, function); \
33 }
34
35
36static void checkAndPrint(asn_TYPE_descriptor_t *typeDescriptor, void *data, char *dataType, const char *function) {
37 char errbuf[128]; /* Buffer for error message */
38 size_t errlen = sizeof(errbuf); /* Size of the buffer */
39 if (asn_check_constraints(typeDescriptor, data, errbuf, &errlen) != 0) {
40 mdclog_write(MDCLOG_ERR, "%s Constraint validation failed: %s", dataType, errbuf);
41 } else if (mdclog_level_get() >= MDCLOG_DEBUG) {
42 mdclog_write(MDCLOG_DEBUG, "%s successes function %s", dataType, function);
43 }
44}
45
46static size_t encodebuff(int codingType,
47 asn_TYPE_descriptor_t *typeDescriptor,
48 void *objectData,
49 uint8_t *buffer,
50 size_t buffer_size) {
51 asn_enc_rval_t er;
52 struct timespec start = {0,0};
53 struct timespec end = {0,0};
54 clock_gettime(CLOCK_MONOTONIC, &start);
55 er = asn_encode_to_buffer(0, codingType, typeDescriptor, objectData, buffer, buffer_size);
56 clock_gettime(CLOCK_MONOTONIC, &end);
57 if (er.encoded == -1) {
58 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2SM_gNB_X2_eventTriggerDefinition.name, strerror(errno));
59 } else if (er.encoded > buffer_size) {
60 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s", (int) buffer_size,
61 typeDescriptor->name);
62 } else if (mdclog_level_get() >= MDCLOG_DEBUG) {
63 if (codingType == ATS_BASIC_XER) {
64 mdclog_write(MDCLOG_DEBUG, "Buffer of size %d, data = %s", (int) er.encoded, buffer);
65 }
66 else {
67 if (mdclog_level_get() >= MDCLOG_INFO) {
68 char *printBuffer;
69 size_t size;
70 FILE *stream = open_memstream(&printBuffer, &size);
71 asn_fprint(stream, typeDescriptor, objectData);
72 mdclog_write(MDCLOG_DEBUG, "Encoding E2SM PDU past : %s", printBuffer);
73 }
74
75
76 mdclog_write(MDCLOG_DEBUG, "Buffer of size %d", (int) er.encoded);
77 }
78 }
79 mdclog_write(MDCLOG_INFO, "Encoding type %d, time is %ld seconds, %ld nanoseconds", codingType, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
80 //mdclog_write(MDCLOG_INFO, "Encoding time is %3.9f seconds", ((double)end.tv_sec + 1.0e-9 * end.tv_nsec) - ((double)start.tv_sec + 1.0e-9 * start.tv_nsec));
81 return er.encoded;
82}
83
84PLMN_Identity_t *createPLMN_ID(const unsigned char *data) {
85 printEntry("PLMN_Identity_t", __func__);
86 PLMN_Identity_t *plmnId = calloc(1, sizeof(PLMN_Identity_t));
87 ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, plmnId);
88 plmnId->size = 3;
89 plmnId->buf = calloc(1, 3);
90 memcpy(plmnId->buf, data, 3);
91
92 if (mdclog_level_get() >= MDCLOG_DEBUG) {
93 checkAndPrint(&asn_DEF_PLMN_Identity, plmnId, "PLMN_Identity_t", __func__);
94 }
95
96 return plmnId;
97}
98
99ENB_ID_t *createENB_ID(ENB_ID_PR enbType, unsigned char *data) {
100 printEntry("ENB_ID_t", __func__);
101 ENB_ID_t *enb = calloc(1, sizeof(ENB_ID_t));
102 ASN_STRUCT_RESET(asn_DEF_ENB_ID, enb);
103 switch (enbType) {
104 case ENB_ID_PR_macro_eNB_ID: { // 20 bit 3 bytes
105 enb->choice.macro_eNB_ID.size = 3;
106 enb->choice.macro_eNB_ID.bits_unused = 4;
107
108 enb->present = ENB_ID_PR_macro_eNB_ID;
109
110 enb->choice.macro_eNB_ID.buf = calloc(1, enb->choice.macro_eNB_ID.size);
111 data[enb->choice.macro_eNB_ID.size - 1] = ((unsigned)(data[enb->choice.macro_eNB_ID.size - 1] >>
112 (unsigned)enb->choice.macro_eNB_ID.bits_unused) << (unsigned)enb->choice.macro_eNB_ID.bits_unused);
113 memcpy(enb->choice.macro_eNB_ID.buf, data, enb->choice.macro_eNB_ID.size);
114
115 break;
116 }
117 case ENB_ID_PR_home_eNB_ID: { // 28 bit 4 bytes
118 enb->choice.home_eNB_ID.size = 4;
119 enb->choice.home_eNB_ID.bits_unused = 4;
120 enb->present = ENB_ID_PR_home_eNB_ID;
121
122 enb->choice.home_eNB_ID.buf = calloc(1, enb->choice.home_eNB_ID.size);
123 data[enb->choice.home_eNB_ID.size - 1] = ((unsigned)(data[enb->choice.home_eNB_ID.size - 1] >>
124 (unsigned)enb->choice.home_eNB_ID.bits_unused) << (unsigned)enb->choice.home_eNB_ID.bits_unused);
125 memcpy(enb->choice.home_eNB_ID.buf, data, enb->choice.home_eNB_ID.size);
126 break;
127 }
128 case ENB_ID_PR_short_Macro_eNB_ID: { // 18 bit - 3 bytes
129 enb->choice.short_Macro_eNB_ID.size = 3;
130 enb->choice.short_Macro_eNB_ID.bits_unused = 6;
131 enb->present = ENB_ID_PR_short_Macro_eNB_ID;
132
133 enb->choice.short_Macro_eNB_ID.buf = calloc(1, enb->choice.short_Macro_eNB_ID.size);
134 data[enb->choice.short_Macro_eNB_ID.size - 1] = ((unsigned)(data[enb->choice.short_Macro_eNB_ID.size - 1] >>
135 (unsigned)enb->choice.short_Macro_eNB_ID.bits_unused) << (unsigned)enb->choice.short_Macro_eNB_ID.bits_unused);
136 memcpy(enb->choice.short_Macro_eNB_ID.buf, data, enb->choice.short_Macro_eNB_ID.size);
137 break;
138 }
139 case ENB_ID_PR_long_Macro_eNB_ID: { // 21
140 enb->choice.long_Macro_eNB_ID.size = 3;
141 enb->choice.long_Macro_eNB_ID.bits_unused = 3;
142 enb->present = ENB_ID_PR_long_Macro_eNB_ID;
143
144 enb->choice.long_Macro_eNB_ID.buf = calloc(1, enb->choice.long_Macro_eNB_ID.size);
145 data[enb->choice.long_Macro_eNB_ID.size - 1] = ((unsigned)(data[enb->choice.long_Macro_eNB_ID.size - 1] >>
146 (unsigned)enb->choice.long_Macro_eNB_ID.bits_unused) << (unsigned)enb->choice.long_Macro_eNB_ID.bits_unused);
147 memcpy(enb->choice.long_Macro_eNB_ID.buf, data, enb->choice.long_Macro_eNB_ID.size);
148 break;
149 }
150 default:
151 free(enb);
152 return NULL;
153
154 }
155
156 if (mdclog_level_get() >= MDCLOG_DEBUG) {
157 checkAndPrint(&asn_DEF_ENB_ID, enb, "ENB_ID_t", __func__);
158 }
159 return enb;
160}
161
162GNB_ID_t *createGnb_id(const unsigned char *data, int numOfBits) {
163 printEntry("GNB_ID_t", __func__);
164 if (numOfBits < 22 || numOfBits > 32) {
165 mdclog_write(MDCLOG_ERR, "GNB_ID_t number of bits = %d, needs to be 22 .. 32", numOfBits);
166 return NULL;
167 }
168 GNB_ID_t *gnb = calloc(1, sizeof(GNB_ID_t));
169 ASN_STRUCT_RESET(asn_DEF_GNB_ID, gnb);
170
171 gnb->present = GNB_ID_PR_gNB_ID;
172 gnb->choice.gNB_ID.size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
173 gnb->choice.gNB_ID.bits_unused = gnb->choice.gNB_ID.size * 8 - numOfBits;
174 gnb->choice.gNB_ID.buf = calloc(1, gnb->choice.gNB_ID.size);
175 memcpy(gnb->choice.gNB_ID.buf, data, gnb->choice.gNB_ID.size);
176 gnb->choice.gNB_ID.buf[gnb->choice.gNB_ID.size - 1] =
177 ((unsigned)(gnb->choice.gNB_ID.buf[gnb->choice.gNB_ID.size - 1] >> (unsigned)gnb->choice.gNB_ID.bits_unused)
178 << (unsigned)gnb->choice.gNB_ID.bits_unused);
179
180 if (mdclog_level_get() >= MDCLOG_DEBUG) {
181 checkAndPrint(&asn_DEF_GNB_ID, gnb, "GNB_ID_t", __func__);
182 }
183
184 return gnb;
185
186}
187
188GlobalENB_ID_t *createGlobalENB_ID(PLMN_Identity_t *plmnIdentity, ENB_ID_t *enbId) {
189 printEntry("GlobalENB_ID_t", __func__);
190 GlobalENB_ID_t *genbId = calloc(1, sizeof(GlobalENB_ID_t));
191 ASN_STRUCT_RESET(asn_DEF_GlobalENB_ID, genbId);
192 memcpy(&genbId->pLMN_Identity, plmnIdentity, sizeof(PLMN_Identity_t));
193 memcpy(&genbId->eNB_ID, enbId, sizeof(ENB_ID_t));
194
195 if (mdclog_level_get() >= MDCLOG_DEBUG) {
196 checkAndPrint(&asn_DEF_GlobalENB_ID, genbId, "GlobalENB_ID_t", __func__);
197 }
198 return genbId;
199}
200
201GlobalGNB_ID_t *createGlobalGNB_ID(PLMN_Identity_t *plmnIdentity, GNB_ID_t *gnb) {
202 printEntry("GlobalGNB_ID_t", __func__);
203 GlobalGNB_ID_t *ggnbId = calloc(1, sizeof(GlobalGNB_ID_t));
204 ASN_STRUCT_RESET(asn_DEF_GlobalGNB_ID, ggnbId);
205
206 memcpy(&ggnbId->pLMN_Identity, plmnIdentity, sizeof(PLMN_Identity_t));
207 memcpy(&ggnbId->gNB_ID, gnb, sizeof(GNB_ID_t));
208
209 if (mdclog_level_get() >= MDCLOG_DEBUG) {
210 checkAndPrint(&asn_DEF_GlobalGNB_ID, ggnbId, "GlobalGNB_ID_t", __func__);
211 }
212
213 return ggnbId;
214}
215
216
217Interface_ID_t *createInterfaceIDForGnb(GlobalGNB_ID_t *gnb) {
218 printEntry("Interface_ID_t", __func__);
219 Interface_ID_t *interfaceId = calloc(1, sizeof(Interface_ID_t));
220 ASN_STRUCT_RESET(asn_DEF_Interface_ID, interfaceId);
221
222 interfaceId->present = Interface_ID_PR_global_gNB_ID;
223 //memcpy(&interfaceId->choice.global_gNB_ID, gnb, sizeof(GlobalGNB_ID_t));
224 interfaceId->choice.global_gNB_ID = gnb;
225
226 if (mdclog_level_get() >= MDCLOG_DEBUG) {
227 checkAndPrint(&asn_DEF_Interface_ID, interfaceId, "Interface_ID_t", __func__);
228 }
229
230 return interfaceId;
231}
232
233Interface_ID_t *createInterfaceIDForEnb(GlobalENB_ID_t *enb) {
234 printEntry("Interface_ID_t", __func__);
235 Interface_ID_t *interfaceId = calloc(1, sizeof(Interface_ID_t));
236 ASN_STRUCT_RESET(asn_DEF_Interface_ID, interfaceId);
237
238 interfaceId->present = Interface_ID_PR_global_eNB_ID;
239 //memcpy(&interfaceId->choice.global_eNB_ID, enb, sizeof(GlobalENB_ID_t));
240 interfaceId->choice.global_eNB_ID = enb;
241
242 if (mdclog_level_get() >= MDCLOG_DEBUG) {
243 checkAndPrint(&asn_DEF_Interface_ID, interfaceId, "Interface_ID_t", __func__);
244 }
245
246 return interfaceId;
247}
248
249
250
251InterfaceMessageType_t *createInterfaceMessageInitiating(long procedureCode) {
252 printEntry("InterfaceMessageType_t", __func__);
253 InterfaceMessageType_t *intMsgT = calloc(1, sizeof(InterfaceMessageType_t));
254 ASN_STRUCT_RESET(asn_DEF_InterfaceMessageType, intMsgT);
255
256 intMsgT->procedureCode = procedureCode;
257 intMsgT->typeOfMessage = TypeOfMessage_initiating_message;
258
259 if (mdclog_level_get() >= MDCLOG_DEBUG) {
260 checkAndPrint(&asn_DEF_InterfaceMessageType, intMsgT, "InterfaceMessageType_t", __func__);
261 }
262
263 return intMsgT;
264}
265
266InterfaceMessageType_t *createInterfaceMessageSuccsesful(long procedureCode) {
267 printEntry("InterfaceMessageType_t", __func__);
268 InterfaceMessageType_t *intMsgT = calloc(1, sizeof(InterfaceMessageType_t));
269 ASN_STRUCT_RESET(asn_DEF_InterfaceMessageType, intMsgT);
270
271 intMsgT->procedureCode = procedureCode;
272 intMsgT->typeOfMessage = TypeOfMessage_successful_outcome;
273
274 if (mdclog_level_get() >= MDCLOG_DEBUG) {
275 checkAndPrint(&asn_DEF_InterfaceMessageType, intMsgT, "InterfaceMessageType_t", __func__);
276 }
277
278 return intMsgT;
279}
280
281InterfaceMessageType_t *createInterfaceMessageUnsuccessful(long procedureCode) {
282 printEntry("InterfaceMessageType_t", __func__);
283 InterfaceMessageType_t *intMsgT = calloc(1, sizeof(InterfaceMessageType_t));
284 ASN_STRUCT_RESET(asn_DEF_InterfaceMessageType, intMsgT);
285
286 intMsgT->procedureCode = procedureCode;
287 intMsgT->typeOfMessage = TypeOfMessage_unsuccessful_outcome;
288
289 if (mdclog_level_get() >= MDCLOG_DEBUG) {
290 checkAndPrint(&asn_DEF_InterfaceMessageType, intMsgT, "InterfaceMessageType_t", __func__);
291 }
292
293 return intMsgT;
294}
295
296InterfaceProtocolIE_Value_t *createInterfaceProtocolValueInt(long number) {
297 printEntry("InterfaceProtocolIE_Value_t", __func__);
298 InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
299 ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
300
301 value->present = InterfaceProtocolIE_Value_PR_valueInt;
302 value->choice.valueInt = number;
303
304 if (mdclog_level_get() >= MDCLOG_DEBUG) {
305 checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
306 }
307
308 return value;
309}
310
311InterfaceProtocolIE_Value_t *createInterfaceProtocolValueEnum(long number) {
312 printEntry("InterfaceProtocolIE_Value_t", __func__);
313 InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
314 ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
315
316 value->present = InterfaceProtocolIE_Value_PR_valueEnum;
317 value->choice.valueEnum = number;
318
319 if (mdclog_level_get() >= MDCLOG_DEBUG) {
320 checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
321 }
322
323 return value;
324}
325
326InterfaceProtocolIE_Value_t *createInterfaceProtocolValueBool(int val) {
327 printEntry("InterfaceProtocolIE_Value_t", __func__);
328 InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
329 ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
330
331 value->present = InterfaceProtocolIE_Value_PR_valueBool;
332 value->choice.valueBool = val == 0 ? 0 : 1;
333
334 if (mdclog_level_get() >= MDCLOG_DEBUG) {
335 checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
336 }
337
338 return value;
339}
340
341
342InterfaceProtocolIE_Value_t *createInterfaceProtocolValueBitString(unsigned char *buf, int numOfBits) {
343 printEntry("InterfaceProtocolIE_Value_t", __func__);
344 size_t size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
345 if (strlen((const char *)buf) < size) {
346 mdclog_write(MDCLOG_ERR, "size of buffer is small : %d needs to be %d in %s", (int)strlen((const char *)buf), (int)size, __func__);
347 }
348 InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
349 ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
350
351 value->present = InterfaceProtocolIE_Value_PR_valueBitS;
352 value->choice.valueBitS.size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
353 value->choice.valueBitS.buf = calloc(1, value->choice.valueBitS.size);
354 int bits_unused = value->choice.valueBitS.size * 8 - numOfBits;
355 value->choice.valueBitS.bits_unused = bits_unused;
356
357 memcpy(value->choice.valueBitS.buf, buf, value->choice.valueBitS.size);
358 value->choice.valueBitS.buf[size -1] = ((unsigned)(buf[size - 1]) >> (unsigned)bits_unused << (unsigned)bits_unused);
359
360 if (mdclog_level_get() >= MDCLOG_DEBUG) {
361 checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
362 }
363
364 return value;
365}
366
367
368InterfaceProtocolIE_Value_t *createInterfaceProtocolValueOCTETS(uint8_t *buf) {
369 printEntry("InterfaceProtocolIE_Value_t", __func__);
370 size_t size = strlen((const char *)buf);
371 InterfaceProtocolIE_Value_t *value = calloc(1, sizeof(InterfaceProtocolIE_Value_t));
372 ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Value, value);
373
374 value->present = InterfaceProtocolIE_Value_PR_valueOctS;
375 value->choice.valueOctS.size = size;
376 value->choice.valueOctS.buf = calloc(1, value->choice.valueOctS.size);
377 memcpy(value->choice.valueOctS.buf, buf, value->choice.valueOctS.size);
378
379 if (mdclog_level_get() >= MDCLOG_DEBUG) {
380 checkAndPrint(&asn_DEF_InterfaceProtocolIE_Value, value, "InterfaceProtocolIE_Value_t", __func__);
381 }
382
383 return value;
384}
385
386
387InterfaceProtocolIE_Item_t *createInterfaceProtocolIE_Item(long id, long test, InterfaceProtocolIE_Value_t *value) {
388 printEntry("InterfaceProtocolIE_Item_t", __func__);
389 if (test < InterfaceProtocolIE_Test_equal || test > InterfaceProtocolIE_Test_present) {
390 mdclog_write(MDCLOG_ERR, "InterfaceProtocolIE_Item_t test value is %ld, out of scope %d .. %d ",
391 test, InterfaceProtocolIE_Test_equal, InterfaceProtocolIE_Test_present);
392 return NULL;
393 }
394 InterfaceProtocolIE_Item_t *intProtIt = calloc(1, sizeof(InterfaceProtocolIE_Item_t));
395 ASN_STRUCT_RESET(asn_DEF_InterfaceProtocolIE_Item, intProtIt);
396
397
398 intProtIt->interfaceProtocolIE_ID = id;
399
400 intProtIt->interfaceProtocolIE_Test = test;
401
402 memcpy(&intProtIt->interfaceProtocolIE_Value, value, sizeof(InterfaceProtocolIE_Value_t));
403
404 if (mdclog_level_get() >= MDCLOG_DEBUG) {
405 checkAndPrint(&asn_DEF_InterfaceProtocolIE_Item, intProtIt, "InterfaceProtocolIE_Item_t", __func__);
406 }
407
408 return intProtIt;
409
410}
411
412
413
414ActionParameter_Value_t *createActionParameterValue_Int(long number) {
415 printEntry("ActionParameter_Value_t", __func__);
416 ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
417 ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
418
419 value->present = ActionParameter_Value_PR_valueInt;
420 value->choice.valueInt = number;
421
422 if (mdclog_level_get() >= MDCLOG_DEBUG) {
423 checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
424 }
425
426 return value;
427}
428
429ActionParameter_Value_t *createActionParameterValue_Enum(long number) {
430 printEntry("ActionParameter_Value_t", __func__);
431 ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
432 ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
433
434 value->present = ActionParameter_Value_PR_valueEnum;
435 value->choice.valueEnum = number;
436
437 if (mdclog_level_get() >= MDCLOG_DEBUG) {
438 checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
439 }
440
441 return value;
442}
443
444ActionParameter_Value_t *createActionParameterValue_Bool(int val) {
445 printEntry("ActionParameter_Value_t", __func__);
446 ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
447 ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
448
449 value->present = ActionParameter_Value_PR_valueBool;
450 value->choice.valueBool = val == 0 ? 0 : 1;
451
452 if (mdclog_level_get() >= MDCLOG_DEBUG) {
453 checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
454 }
455
456 return value;
457}
458
459
460ActionParameter_Value_t *createActionParameterValue_Bit_String(unsigned char *buf, int numOfBits) {
461 printEntry("ActionParameter_Value_t", __func__);
462 size_t size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
463 if (strlen((const char *)buf) < size) {
464 mdclog_write(MDCLOG_ERR, "size of buffer is small : %d needs to be %d in %s", (int)strlen((const char *)buf), (int)size, __func__);
465 }
466 int bits_unused = size * 8 - numOfBits;
467
468 ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
469 ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
470
471 value->present = ActionParameter_Value_PR_valueBitS;
472 value->choice.valueBitS.size = size;
473 value->choice.valueBitS.buf = calloc(1, size);
474 value->choice.valueBitS.bits_unused = bits_unused;
475
476 memcpy(value->choice.valueBitS.buf, buf, size);
477 value->choice.valueBitS.buf[size -1] = ((unsigned)(buf[size - 1]) >> (unsigned)bits_unused << (unsigned)bits_unused);
478
479 if (mdclog_level_get() >= MDCLOG_DEBUG) {
480 checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
481 }
482
483 return value;
484}
485
486
487ActionParameter_Value_t *createActionParameterValue_OCTETS(uint8_t *buf) {
488 printEntry("ActionParameter_Value_t", __func__);
489 size_t size = strlen((const char *)buf);
490 ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
491 ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
492
493 value->present = ActionParameter_Value_PR_valueOctS;
494 value->choice.valueOctS.size = size;
495 value->choice.valueOctS.buf = calloc(1, value->choice.valueOctS.size);
496 memcpy(value->choice.valueOctS.buf, buf, value->choice.valueOctS.size);
497
498 if (mdclog_level_get() >= MDCLOG_DEBUG) {
499 checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
500 }
501
502 return value;
503}
504
505/**
506 *
507 * @param buf buffer that must be null terminated
508 * @return ActionParameter_Value_t *
509 */
510ActionParameter_Value_t *createActionParameterValue_PRINTS(char *buf) {
511 printEntry("ActionParameter_Value_t", __func__);
512 size_t size = strlen((const char *)buf);
513 ActionParameter_Value_t *value = calloc(1, sizeof(ActionParameter_Value_t));
514 ASN_STRUCT_RESET(asn_DEF_ActionParameter_Value, value);
515
516 value->present = ActionParameter_Value_PR_valuePrtS;
517 value->choice.valuePrtS.size = size;
518 value->choice.valuePrtS.buf = calloc(1, value->choice.valuePrtS.size);
519 memcpy(value->choice.valuePrtS.buf, buf, value->choice.valuePrtS.size);
520
521 if (mdclog_level_get() >= MDCLOG_DEBUG) {
522 checkAndPrint(&asn_DEF_ActionParameter_Value, value, "ActionParameter_Value_t", __func__);
523 }
524
525 return value;
526}
527
528ActionParameter_Item_t *creatActionParameter_Item(long id, ActionParameter_Value_t *val) {
529 printEntry("ActionParameter_Item_t", __func__);
530 if (id < 0 || id > 255) {
531 mdclog_write(MDCLOG_ERR, "ActionParameter_Item_t id = %ld, values are 0 .. 255", id);
532 return NULL;
533 }
534 ActionParameter_Item_t *actionParameterItem = calloc(1, sizeof(ActionParameter_Item_t));
535 ASN_STRUCT_RESET(asn_DEF_ActionParameter_Item, actionParameterItem);
536
537 actionParameterItem->actionParameter_ID = id;
538 memcpy(&actionParameterItem->actionParameter_Value, val, sizeof(ActionParameter_Value_t));
539
540 if (mdclog_level_get() >= MDCLOG_DEBUG) {
541 checkAndPrint(&asn_DEF_ActionParameter_Item, actionParameterItem, "ActionParameter_Item_t", __func__);
542 }
543
544 return actionParameterItem;
545}
546
547/**
548 *
549 * @param interfaceId
550 * @param direction
551 * @param messageType
552 * @param interfaceProtocolItemList
553 * @param listSize
554 * @param buffer
555 * @param buffer_size
556 * @return
557 */
558size_t createEventTrigger(Interface_ID_t *interfaceId, long direction,
559 InterfaceMessageType_t *messageType,
560 InterfaceProtocolIE_Item_t interfaceProtocolItemList[],
561 int listSize,
562 uint8_t *buffer,
563 size_t buffer_size) {
564 printEntry("E2SM_gNB_X2_eventTriggerDefinition_t", __func__);
565 if (direction < InterfaceDirection_incoming || direction > InterfaceDirection_outgoing) {
566 mdclog_write(MDCLOG_ERR, "E2SM_gNB_X2_eventTriggerDefinition_t direction = %ld, values are %d .. %d",
567 direction, InterfaceDirection_incoming, InterfaceDirection_outgoing);
568 return -1;
569 }
570
571 E2SM_gNB_X2_eventTriggerDefinition_t *eventTrigger = calloc(1, sizeof(E2SM_gNB_X2_eventTriggerDefinition_t));
572 ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, eventTrigger);
573
574 memcpy(&eventTrigger->interface_ID , interfaceId, sizeof(Interface_ID_t));
575
576 eventTrigger->interfaceDirection = direction;
577 memcpy(&eventTrigger->interfaceMessageType, messageType, sizeof(InterfaceMessageType_t));
578
579 for (int i = 0; i < listSize; i++) {
580 ASN_SEQUENCE_ADD(eventTrigger->interfaceProtocolIE_List, &interfaceProtocolItemList[i]);
581 }
582
583 if (mdclog_level_get() >= MDCLOG_DEBUG) {
584 checkAndPrint(&asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, eventTrigger, "E2SM_gNB_X2_eventTriggerDefinition_t", __func__);
585 }
586
587 size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_eventTriggerDefinition,
588 eventTrigger,
589 buffer,
590 buffer_size);
591
592
593 if (mdclog_level_get() >= MDCLOG_INFO) {
594 uint8_t buf1[4096];
595 asn_enc_rval_t er1;
596 encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_eventTriggerDefinition,
597 eventTrigger,
598 buf1,
599 4096);
600
601 }
602
603 return len;
604}
605
606
607size_t createActionDefinition(long styleId, ActionParameter_Item_t actionParamList[], int listSize,
608 uint8_t *buffer,
609 size_t buffer_size) {
610 printEntry("E2SM_gNB_X2_actionDefinition_t", __func__);
611 E2SM_gNB_X2_actionDefinition_t *actDef = calloc(1, sizeof(E2SM_gNB_X2_actionDefinition_t));
612 ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_actionDefinition, actDef);
613
614 actDef->style_ID = styleId;
615 for (int i = 0; i < listSize; i++) {
616 ASN_SEQUENCE_ADD(actDef->actionParameter_List, &actionParamList[i]);
617 }
618
619 if (mdclog_level_get() >= MDCLOG_DEBUG) {
620 checkAndPrint(&asn_DEF_E2SM_gNB_X2_actionDefinition, actDef, "E2SM_gNB_X2_actionDefinition_t", __func__);
621 }
622
623 size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_actionDefinition,
624 actDef,
625 buffer,
626 buffer_size);
627
628
629 if (mdclog_level_get() >= MDCLOG_INFO) {
630 uint8_t buf1[4096];
631 asn_enc_rval_t er1;
632 encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_actionDefinition,
633 actDef,
634 buf1,
635 4096);
636
637 }
638
639 return len;
640}
641
642size_t createE2SM_gNB_X2_indicationHeader(long direction,
643 Interface_ID_t *interfaceId,
644 uint8_t *timestamp, //can put NULL if size == 0
645 int size,
646 uint8_t *buffer,
647 size_t buffer_size) {
648 printEntry("E2SM_gNB_X2_indicationHeader_t", __func__);
649 if (direction < InterfaceDirection_incoming || direction > InterfaceDirection_outgoing) {
650 mdclog_write(MDCLOG_ERR, "E2SM_gNB_X2_indicationHeader_t direction = %ld, values are %d .. %d",
651 direction, InterfaceDirection_incoming, InterfaceDirection_outgoing);
652 return -1;
653 }
654
655 E2SM_gNB_X2_indicationHeader_t *indiHead = calloc(1, sizeof(E2SM_gNB_X2_indicationHeader_t));
656 ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_indicationHeader, indiHead);
657
658 indiHead->interfaceDirection = direction;
659 memcpy(&indiHead->interface_ID, interfaceId, sizeof(Interface_ID_t));
660 if (size > 0) {
661 indiHead->timestamp->size = size;
662 indiHead->timestamp->buf = calloc(1, sizeof(uint8_t) * size);
663 memcpy(indiHead->timestamp->buf, timestamp, size);
664 }
665
666 if (mdclog_level_get() >= MDCLOG_DEBUG) {
667 checkAndPrint(&asn_DEF_E2SM_gNB_X2_indicationHeader, indiHead, "E2SM_gNB_X2_indicationHeader_t", __func__);
668 }
669
670 size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_indicationHeader,
671 indiHead,
672 buffer,
673 buffer_size);
674
675 if (mdclog_level_get() >= MDCLOG_INFO) {
676 uint8_t buf1[4096];
677 asn_enc_rval_t er1;
678 encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_indicationHeader,
679 indiHead,
680 buf1,
681 4096);
682
683 }
684
685 return len;
686}
687
688size_t createE2SM_gNB_X2_indicationMessage(uint8_t *message, uint msgSize,
689 uint8_t *buffer,
690 size_t buffer_size) {
691 printEntry("E2SM_gNB_X2_indicationMessage_t", __func__);
692 if (msgSize <= 0) {
693 mdclog_write(MDCLOG_ERR, "E2SM_gNB_X2_indicationMessage_t failed messsage size = %d", msgSize);
694 return -1;
695 }
696
697 E2SM_gNB_X2_indicationMessage_t *indicationMessage = calloc(1, sizeof(E2SM_gNB_X2_indicationMessage_t));
698 ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_indicationMessage, indicationMessage);
699
700 indicationMessage->interfaceMessage.size = msgSize;
701 indicationMessage->interfaceMessage.buf = calloc(1, sizeof(uint8_t) * msgSize);
702 memcpy(indicationMessage->interfaceMessage.buf, message, msgSize);
703
704 if (mdclog_level_get() >= MDCLOG_DEBUG) {
705 checkAndPrint(&asn_DEF_E2SM_gNB_X2_indicationMessage, indicationMessage, "E2SM_gNB_X2_indicationMessage_t", __func__);
706 }
707
708 size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_indicationMessage,
709 indicationMessage,
710 buffer,
711 buffer_size);
712
713
714 if (mdclog_level_get() >= MDCLOG_INFO) {
715 uint8_t buf1[4096];
716 asn_enc_rval_t er1;
717 encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_indicationMessage,
718 indicationMessage,
719 buf1,
720 4096);
721
722 }
723
724 return len;
725}
726
727
728size_t createE2SM_gNB_X2_callProcessID(long callProcess_Id,
729 uint8_t *buffer,
730 size_t buffer_size) {
731 printEntry("E2SM_gNB_X2_callProcessID_t", __func__);
732 E2SM_gNB_X2_callProcessID_t *callProcessId = calloc(1, sizeof(E2SM_gNB_X2_callProcessID_t));
733 ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_callProcessID, callProcessId);
734
735 callProcessId->callProcess_ID = callProcess_Id;
736
737 if (mdclog_level_get() >= MDCLOG_DEBUG) {
738 checkAndPrint(&asn_DEF_E2SM_gNB_X2_callProcessID, callProcessId, "E2SM_gNB_X2_indicationMessage_t", __func__);
739 }
740
741 size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_callProcessID,
742 callProcessId,
743 buffer,
744 buffer_size);
745
746
747 if (mdclog_level_get() >= MDCLOG_INFO) {
748 uint8_t buf1[4096];
749 asn_enc_rval_t er1;
750 encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_callProcessID,
751 callProcessId,
752 buf1,
753 4096);
754
755 }
756
757 return len;
758}
759
760size_t createE2SM_gNB_X2_controlHeader(Interface_ID_t *interfaceId, long direction,
761 uint8_t *buffer,
762 size_t buffer_size) {
763 printEntry("E2SM_gNB_X2_controlHeader_t", __func__);
764 if (direction < InterfaceDirection_incoming || direction > InterfaceDirection_outgoing) {
765 mdclog_write(MDCLOG_ERR, "E2SM_gNB_X2_controlHeader_t direction = %ld, values are %d .. %d",
766 direction, InterfaceDirection_incoming, InterfaceDirection_outgoing);
767 return -1;
768 }
769 E2SM_gNB_X2_controlHeader_t *controlHeader = calloc(1, sizeof(E2SM_gNB_X2_controlHeader_t));
770 ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_controlHeader, controlHeader);
771
772 memcpy(&controlHeader->interface_ID, interfaceId, sizeof(Interface_ID_t));
773 controlHeader->interfaceDirection = direction;
774
775 if (mdclog_level_get() >= MDCLOG_DEBUG) {
776 checkAndPrint(&asn_DEF_E2SM_gNB_X2_controlHeader, controlHeader, "E2SM_gNB_X2_controlHeader_t", __func__);
777 }
778
779 size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_controlHeader,
780 controlHeader,
781 buffer,
782 buffer_size);
783
784
785 if (mdclog_level_get() >= MDCLOG_INFO) {
786 uint8_t buf1[4096];
787 asn_enc_rval_t er1;
788 encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_controlHeader,
789 controlHeader,
790 buf1,
791 4096);
792
793 }
794
795 return len;
796}
797
798
799size_t createE2SM_gNB_X2_controlMessage(uint8_t *message, uint msgSize,
800 uint8_t *buffer,
801 size_t buffer_size) {
802 printEntry("E2SM_gNB_X2_controlMessage_t", __func__);
803 E2SM_gNB_X2_controlMessage_t *controlMsg = calloc(1, sizeof(E2SM_gNB_X2_controlMessage_t));
804 ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_controlMessage, controlMsg);
805
806 controlMsg->interfaceMessage.size = msgSize;
807 controlMsg->interfaceMessage.buf = calloc(1, sizeof(uint8_t) * msgSize);
808 memcpy(controlMsg->interfaceMessage.buf, message, msgSize);
809
810 if (mdclog_level_get() >= MDCLOG_DEBUG) {
811 checkAndPrint(&asn_DEF_E2SM_gNB_X2_controlMessage, controlMsg, "E2SM_gNB_X2_controlMessage_t", __func__);
812 }
813
814 size_t len = encodebuff(ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_controlMessage,
815 controlMsg,
816 buffer,
817 buffer_size);
818
819
820 if (mdclog_level_get() >= MDCLOG_INFO) {
821 uint8_t buf1[4096];
822 asn_enc_rval_t er1;
823 encodebuff(ATS_BASIC_XER, &asn_DEF_E2SM_gNB_X2_controlMessage,
824 controlMsg,
825 buf1,
826 4096);
827
828 }
829
830 return len;
831}