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