2 * Copyright 2020 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 #ifndef E2_BUILDRUNNAME_H
20 #define E2_BUILDRUNNAME_H
22 #include <3rdparty/oranE2/ProtocolIE-Field.h>
23 #include "oranE2/ProtocolIE-Container.h"
24 #include "oranE2/ProtocolIE-Field.h"
25 #include "oranE2/GlobalE2node-gNB-ID.h"
26 #include "oranE2/GlobalE2node-en-gNB-ID.h"
27 #include "oranE2/GlobalE2node-ng-eNB-ID.h"
28 #include "oranE2/GlobalE2node-eNB-ID.h"
31 * return the size of the string
33 static int translatePlmnId(char * plmnId, const unsigned char *data, const char* type) {
34 auto mcc1 = (unsigned char)((unsigned char)data[0] & (unsigned char)0x0F);
35 auto mcc2 = (unsigned char)(((unsigned char)((unsigned char)data[0] & (unsigned char)0xF0)) >> (unsigned char)4);
36 auto mcc3 = (unsigned char)((data[1] & (unsigned char)0xF0) >> (unsigned char)4);
38 auto mnc1 = (unsigned char)(data[2] & (unsigned char)0x0F);
39 auto mnc2 = (unsigned char)(((unsigned char)(data[2] & (unsigned char)0xF0) >> (unsigned char)4));
40 auto mnc3 = (unsigned char)(((unsigned char)(data[1] & (unsigned char)0x0F) >> (unsigned char)4) );
44 j = snprintf(plmnId, 20, "%s%1d%1d%1d-%1d%1d%1d", type, mcc1, mcc2, mcc3, mnc1, mnc2, mnc3);
47 j = snprintf(plmnId, 20, "%s%1d%1d%1d-0%1d%1d", type, mcc1, mcc2, mcc3, mnc1, mnc2);
53 static int translateBitStringToChar(char *ranName, BIT_STRING_t &data) {
54 // dont care of last unused bits
56 auto j = snprintf(buffer, 256, "%s-", ranName);
57 memcpy(ranName, buffer, j);
61 for (auto i = 0; i < (int)data.size; i++) {
62 b1 = data.buf[i] & (unsigned)0xF0;
63 b1 = b1 >> (unsigned)4;
64 j = snprintf(buffer, 256, "%s%1x", ranName, b1);
65 memcpy(ranName, buffer, j);
66 b2 = data.buf[i] & (unsigned)0x0F;
67 j = snprintf(buffer, 256, "%s%1x", ranName, b2);
68 memcpy(ranName, buffer, j);
74 int buildRanName(char *ranName, E2setupRequestIEs_t *ie) {
75 switch (ie->value.choice.GlobalE2node_ID.present) {
76 case GlobalE2node_ID_PR_gNB: {
77 auto *gnb = ie->value.choice.GlobalE2node_ID.choice.gNB;
78 translatePlmnId(ranName, (const unsigned char *)gnb->global_gNB_ID.plmn_id.buf, (const char *)"gnb:");
79 if (gnb->global_gNB_ID.gnb_id.present == GNB_ID_Choice_PR_gnb_ID) {
80 translateBitStringToChar(ranName, gnb->global_gNB_ID.gnb_id.choice.gnb_ID);
84 case GlobalE2node_ID_PR_en_gNB: {
85 auto *enGnb = ie->value.choice.GlobalE2node_ID.choice.en_gNB;
86 translatePlmnId(ranName,
87 (const unsigned char *)enGnb->global_gNB_ID.pLMN_Identity.buf,
88 (const char *)"en-gnb:");
89 if (enGnb->global_gNB_ID.gNB_ID.present == ENGNB_ID_PR_gNB_ID) {
90 translateBitStringToChar(ranName, enGnb->global_gNB_ID.gNB_ID.choice.gNB_ID);
94 case GlobalE2node_ID_PR_ng_eNB: {
95 auto *ngEnb = ie->value.choice.GlobalE2node_ID.choice.ng_eNB;
96 char *buf = (char *)ngEnb->global_ng_eNB_ID.plmn_id.buf;
98 BIT_STRING_t *data = nullptr;
99 switch (ngEnb->global_ng_eNB_ID.enb_id.present) {
100 case ENB_ID_Choice_PR_enb_ID_macro: {
101 strncpy(str, (const char *)"ng-enB-macro:", 13);
102 data = &ngEnb->global_ng_eNB_ID.enb_id.choice.enb_ID_macro;
105 case ENB_ID_Choice_PR_enb_ID_shortmacro: {
106 strncpy(str, (const char *)"ng-enB-shortmacro:", 18);
107 data = &ngEnb->global_ng_eNB_ID.enb_id.choice.enb_ID_shortmacro;
110 case ENB_ID_Choice_PR_enb_ID_longmacro: {
111 strncpy(str, (const char *)"ng-enB-longmacro:", 17);
112 data = &ngEnb->global_ng_eNB_ID.enb_id.choice.enb_ID_longmacro;
114 case ENB_ID_Choice_PR_NOTHING: {
120 translatePlmnId(ranName, (const unsigned char *)buf, (const char *)str);
121 translateBitStringToChar(ranName, *data);
124 case GlobalE2node_ID_PR_eNB: {
125 auto *enb = ie->value.choice.GlobalE2node_ID.choice.eNB;
126 char *buf = (char *)enb->global_eNB_ID.pLMN_Identity.buf;
128 BIT_STRING_t *data = nullptr;
130 switch (enb->global_eNB_ID.eNB_ID.present) {
131 case ENB_ID_PR_macro_eNB_ID: {
132 strncpy(str, (const char *)"enB-macro:", 10);
133 data = &enb->global_eNB_ID.eNB_ID.choice.macro_eNB_ID;
136 case ENB_ID_PR_home_eNB_ID: {
137 strncpy(str, (const char *)"enB-home:", 9);
138 data = &enb->global_eNB_ID.eNB_ID.choice.home_eNB_ID;
141 case ENB_ID_PR_short_Macro_eNB_ID: {
142 strncpy(str, (const char *)"enB-shortmacro:", 15);
143 data = &enb->global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID;
146 case ENB_ID_PR_long_Macro_eNB_ID: {
147 strncpy(str, (const char *)"enB-longmacro:", 14);
148 data = &enb->global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID;
151 case ENB_ID_PR_NOTHING:
156 translatePlmnId(ranName, (const unsigned char *)buf, (const char *)str);
157 translateBitStringToChar(ranName, *data);
160 case GlobalE2node_ID_PR_NOTHING:
168 #endif //E2_BUILDRUNNAME_H