2 * Copyright 2020 AT&T Intellectual Property
4 * Copyright 2023 Capgemini
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.
20 #ifndef E2_BUILDRUNNAME_H
21 #define E2_BUILDRUNNAME_H
23 #include <3rdparty/oranE2/ProtocolIE-Field.h>
24 #include "oranE2/ProtocolIE-Container.h"
25 #include "oranE2/ProtocolIE-Field.h"
26 #include "oranE2/GlobalE2node-gNB-ID.h"
27 #include "oranE2/GlobalE2node-en-gNB-ID.h"
28 #include "oranE2/GlobalE2node-ng-eNB-ID.h"
29 #include "oranE2/GlobalE2node-eNB-ID.h"
32 * return the size of the string //
34 static int translatePlmnId(char * plmnId, const unsigned char *data, const char* type) {
35 auto mcc1 = (unsigned char)((unsigned char)data[0] & (unsigned char)0x0F);
36 auto mcc2 = (unsigned char)(((unsigned char)((unsigned char)data[0] & (unsigned char)0xF0)) >> (unsigned char)4);
37 ///auto mcc3 = (unsigned char)((data[1] & (unsigned char)0xF0) >> (unsigned char)4);
38 auto mcc3 = (unsigned char)((unsigned char)(data[1] & (unsigned char)0x0F));
40 auto mnc1 = (unsigned char)(((unsigned char)((unsigned char)data[1] & (unsigned char)0xF0)) >> (unsigned char)4);
41 auto mnc2 = (unsigned char)((unsigned char)data[2] & (unsigned char)0x0F) ;
42 //auto mnc3 = (unsigned char)(((unsigned char)(data[1] & (unsigned char)0x0F) >> (unsigned char)4) );
43 auto mnc3 = (unsigned char)(((unsigned char)((unsigned char)data[2] & (unsigned char)0xF0)) >> (unsigned char)4);
47 j = snprintf(plmnId, 20, "%s%1d%1d%1d_%1d%1d%1d", type, mcc1, mcc2, mcc3, mnc1, mnc2, mnc3);
50 j = snprintf(plmnId, 20, "%s%1d%1d%1d_0%1d%1d", type, mcc1, mcc2, mcc3, mnc2, mnc3);
56 static int translateBitStringToChar(char *ranName, BIT_STRING_t &data, long cuid, long duid) {
57 // dont care of last unused bits
59 // auto j = snprintf(buffer, 256, "%s_", ranName);
63 unsigned long bitValue = 0;
64 for (auto i = 0; i < (int)data.size; i++) {
65 bitValue <<= (unsigned long)8;
66 bitValue += data.buf[i];
69 j = snprintf(buffer, 256, "%s%ld", ranName, bitValue);
71 memcpy(ranName, buffer, j);
78 j = snprintf(buffer, 256, "%s_", ranName);
79 memcpy(ranName, buffer, j);
80 for (auto i = 0; i < (int)data.size; i++) {
82 // we need to shift trailing zeros in the bit string (from asn1c) to leading zeros
84 tmp_digit = (0==i ? (uint8_t) 0: (uint8_t) data.buf[i-1])<<(8-data.bits_unused);
85 tmp_digit = tmp_digit | ((unsigned) data.buf[i] >> data.bits_unused);
87 b1 = tmp_digit & (unsigned)0xF0;
88 b1 = b1 >> (unsigned)4;
89 j = snprintf(buffer, 256, "%s%1x", ranName, b1);
90 memcpy(ranName, buffer, j);
91 b2 = tmp_digit & (unsigned)0x0F;
92 j = snprintf(buffer, 256, "%s%1x", ranName, b2);
93 memcpy(ranName, buffer, j);
96 /*Note: Deployment where CU-UP and DU are combined
97 (but do not include the CP-CP) and have a single E2 connection
98 is not supported. The combination of CU-CP, CU-UP, and DU will be
99 treated as a single gNB and expect it to have only the
100 global gNB ID in its E2 Setup ID*/
102 if ( cuid >= 0 && duid >= 0){
103 j= snprintf(buffer, 256, "%s", ranName);
104 } else if ( cuid >= 0 ){
105 j= snprintf(buffer, 256, "%s_%lx", ranName,cuid);
106 }else if ( duid >= 0 ){
107 j= snprintf(buffer, 256, "%s_%lx", ranName,duid);
109 j= snprintf(buffer, 256, "%s", ranName);
111 printf("cuupid =%ld\n",cuid);
112 printf("duid =%ld\n",duid);
113 printf("ranName =%s\n",ranName);
114 memcpy(ranName, buffer, j);
120 int buildRanName(char *ranName, E2setupRequestIEs_t *ie) {
121 switch (ie->value.choice.GlobalE2node_ID.present) {
122 case GlobalE2node_ID_PR_gNB: {
123 auto *gnb = ie->value.choice.GlobalE2node_ID.choice.gNB;
127 if (gnb->global_gNB_ID.gnb_id.present == GNB_ID_Choice_PR_gnb_ID) {
128 if (gnb->gNB_CU_UP_ID != NULL && gnb->gNB_DU_ID != NULL){
129 printf("\ngNB_CU_UP_ID and gNB_DU_ID is not null\n");
130 asn_INTEGER2long(gnb->gNB_CU_UP_ID,&cuupid);
131 asn_INTEGER2long(gnb->gNB_DU_ID,&duid);
132 translatePlmnId(ranName, (const unsigned char *)gnb->global_gNB_ID.plmn_id.buf, (const char *)"gnb_");
133 }else if (gnb->gNB_DU_ID == NULL && gnb->gNB_CU_UP_ID == NULL ){
134 printf("\ngNB_CU_UP_ID and gNB_DU_ID is null\n");
135 translatePlmnId(ranName, (const unsigned char *)gnb->global_gNB_ID.plmn_id.buf, (const char *)"gnb_");
136 }else if (gnb->gNB_CU_UP_ID != NULL ){
137 printf("\ngNB_CU_UP_ID is not null\n");
138 asn_INTEGER2long(gnb->gNB_CU_UP_ID,&cuupid);
139 translatePlmnId(ranName, (const unsigned char *)gnb->global_gNB_ID.plmn_id.buf, (const char *)"gnbc_");
140 }else if (gnb->gNB_DU_ID != NULL ){
141 printf("\ngNB_DU_ID is not null\n");
142 asn_INTEGER2long(gnb->gNB_DU_ID,&duid);
143 translatePlmnId(ranName, (const unsigned char *)gnb->global_gNB_ID.plmn_id.buf, (const char *)"gnbd_");
145 translateBitStringToChar(ranName, gnb->global_gNB_ID.gnb_id.choice.gnb_ID,cuupid,duid);
147 translatePlmnId(ranName, (const unsigned char *)gnb->global_gNB_ID.plmn_id.buf, (const char *)"gnb_");
151 case GlobalE2node_ID_PR_en_gNB: {
152 auto *enGnb = ie->value.choice.GlobalE2node_ID.choice.en_gNB;
153 translatePlmnId(ranName,
154 (const unsigned char *)enGnb->global_en_gNB_ID.pLMN_Identity.buf,
155 (const char *)"en_gnb_");
156 if (enGnb->global_en_gNB_ID.gNB_ID.present == ENGNB_ID_PR_gNB_ID) {
157 translateBitStringToChar(ranName, enGnb->global_en_gNB_ID.gNB_ID.choice.gNB_ID,-1,-1);
161 case GlobalE2node_ID_PR_ng_eNB: {
162 auto *ngEnb = ie->value.choice.GlobalE2node_ID.choice.ng_eNB;
163 switch (ngEnb->global_ng_eNB_ID.enb_id.present) {
164 case ENB_ID_Choice_PR_enb_ID_macro: {
165 translatePlmnId(ranName, (const unsigned char *)ngEnb->global_ng_eNB_ID.plmn_id.buf, (const char *)"ng_enB_macro_");
166 translateBitStringToChar(ranName, ngEnb->global_ng_eNB_ID.enb_id.choice.enb_ID_macro,-1,-1);
169 case ENB_ID_Choice_PR_enb_ID_shortmacro: {
170 translatePlmnId(ranName, (const unsigned char *)ngEnb->global_ng_eNB_ID.plmn_id.buf, (const char *)"ng_enB_shortmacro_");
171 translateBitStringToChar(ranName, ngEnb->global_ng_eNB_ID.enb_id.choice.enb_ID_shortmacro,-1,-1);
174 case ENB_ID_Choice_PR_enb_ID_longmacro: {
175 translatePlmnId(ranName, (const unsigned char *)ngEnb->global_ng_eNB_ID.plmn_id.buf, (const char *)"ng_enB_longmacro_");
176 translateBitStringToChar(ranName, ngEnb->global_ng_eNB_ID.enb_id.choice.enb_ID_longmacro,-1,-1);
179 case ENB_ID_Choice_PR_NOTHING: {
187 case GlobalE2node_ID_PR_eNB: {
188 auto *enb = ie->value.choice.GlobalE2node_ID.choice.eNB;
189 switch (enb->global_eNB_ID.eNB_ID.present) {
190 case ENB_ID_PR_macro_eNB_ID: {
191 translatePlmnId(ranName, (const unsigned char *)enb->global_eNB_ID.pLMN_Identity.buf, (const char *)"enB_macro_");
192 translateBitStringToChar(ranName, enb->global_eNB_ID.eNB_ID.choice.macro_eNB_ID,-1,-1);
195 case ENB_ID_PR_home_eNB_ID: {
196 translatePlmnId(ranName, (const unsigned char *)enb->global_eNB_ID.pLMN_Identity.buf, (const char *)"enB_home_");
197 translateBitStringToChar(ranName, enb->global_eNB_ID.eNB_ID.choice.home_eNB_ID,-1,-1);
200 case ENB_ID_PR_short_Macro_eNB_ID: {
201 translatePlmnId(ranName, (const unsigned char *)enb->global_eNB_ID.pLMN_Identity.buf, (const char *)"enB_shortmacro_");
202 translateBitStringToChar(ranName, enb->global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID,-1,-1);
205 case ENB_ID_PR_long_Macro_eNB_ID: {
206 translatePlmnId(ranName, (const unsigned char *)enb->global_eNB_ID.pLMN_Identity.buf, (const char *)"enB_longmacro_");
207 translateBitStringToChar(ranName, enb->global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID,-1,-1);
210 case ENB_ID_PR_NOTHING: {
219 case GlobalE2node_ID_PR_NOTHING:
227 #endif //E2_BUILDRUNNAME_H