blob: cf7039b059198b125ec2a352881e0e170252d31b [file] [log] [blame]
aa7133@att.com84bd3342020-03-16 18:04:57 +02001/*
2 * Copyright 2020 AT&T Intellectual Property
3 * Copyright 2020 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
18
19#ifndef E2_BUILDRUNNAME_H
20#define E2_BUILDRUNNAME_H
21
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"
29
aa7133@att.com96c9b882020-03-25 14:50:40 +020030/** 02 F8 29
31 * return the size of the string //
aa7133@att.com84bd3342020-03-16 18:04:57 +020032 */
33static 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);
aa7133@att.com96c9b882020-03-25 14:50:40 +020036 ///auto mcc3 = (unsigned char)((data[1] & (unsigned char)0xF0) >> (unsigned char)4);
37 auto mcc3 = (unsigned char)((unsigned char)(data[1] & (unsigned char)0x0F));
aa7133@att.com84bd3342020-03-16 18:04:57 +020038
sandeekuea662102022-11-08 18:51:20 +053039 auto mnc1 = (unsigned char)(((unsigned char)((unsigned char)data[1] & (unsigned char)0xF0)) >> (unsigned char)4);
40 auto mnc2 = (unsigned char)((unsigned char)data[2] & (unsigned char)0x0F) ;
aa7133@att.com96c9b882020-03-25 14:50:40 +020041 //auto mnc3 = (unsigned char)(((unsigned char)(data[1] & (unsigned char)0x0F) >> (unsigned char)4) );
sandeekuea662102022-11-08 18:51:20 +053042 auto mnc3 = (unsigned char)(((unsigned char)((unsigned char)data[2] & (unsigned char)0xF0)) >> (unsigned char)4);
aa7133@att.com84bd3342020-03-16 18:04:57 +020043
44 int j = 0;
sandeekuea662102022-11-08 18:51:20 +053045 if (mnc1 != 15) {
ss412g4aeeda22020-06-16 14:12:41 +030046 j = snprintf(plmnId, 20, "%s%1d%1d%1d_%1d%1d%1d", type, mcc1, mcc2, mcc3, mnc1, mnc2, mnc3);
aa7133@att.com84bd3342020-03-16 18:04:57 +020047 }
48 else {
sandeekuea662102022-11-08 18:51:20 +053049 j = snprintf(plmnId, 20, "%s%1d%1d%1d_0%1d%1d", type, mcc1, mcc2, mcc3, mnc2, mnc3);
aa7133@att.com84bd3342020-03-16 18:04:57 +020050 }
51
52 return j;
53}
54
55static int translateBitStringToChar(char *ranName, BIT_STRING_t &data) {
56 // dont care of last unused bits
57 char buffer[256] {};
ss412g4aeeda22020-06-16 14:12:41 +030058 auto j = snprintf(buffer, 256, "%s_", ranName);
aa7133@att.com24e9fa42020-11-13 20:32:53 +020059
aa7133@att.com84bd3342020-03-16 18:04:57 +020060 memcpy(ranName, buffer, j);
aa7133@att.com24e9fa42020-11-13 20:32:53 +020061/*
62 // ran name decimal
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];
67 }
68
69 j = snprintf(buffer, 256, "%s%ld", ranName, bitValue);
70
71 memcpy(ranName, buffer, j);
72*/
73
aa7133@att.com84bd3342020-03-16 18:04:57 +020074
75 unsigned b1 = 0;
76 unsigned b2 = 0;
czichy039fe322022-06-17 11:31:47 +030077 unsigned tmp_digit=0;
aa7133@att.com84bd3342020-03-16 18:04:57 +020078 for (auto i = 0; i < (int)data.size; i++) {
czichy039fe322022-06-17 11:31:47 +030079 //
80 // we need to shift trailing zeros in the bit string (from asn1c) to leading zeros
81 //
82 tmp_digit = (0==i ? (uint8_t) 0: (uint8_t) data.buf[i-1])<<(8-data.bits_unused);
83 tmp_digit = tmp_digit | ((unsigned) data.buf[i] >> data.bits_unused);
84
85 b1 = tmp_digit & (unsigned)0xF0;
aa7133@att.com84bd3342020-03-16 18:04:57 +020086 b1 = b1 >> (unsigned)4;
87 j = snprintf(buffer, 256, "%s%1x", ranName, b1);
88 memcpy(ranName, buffer, j);
czichy039fe322022-06-17 11:31:47 +030089 b2 = tmp_digit & (unsigned)0x0F;
aa7133@att.com84bd3342020-03-16 18:04:57 +020090 j = snprintf(buffer, 256, "%s%1x", ranName, b2);
91 memcpy(ranName, buffer, j);
92 }
93 return j;
94}
95
96
97int buildRanName(char *ranName, E2setupRequestIEs_t *ie) {
98 switch (ie->value.choice.GlobalE2node_ID.present) {
99 case GlobalE2node_ID_PR_gNB: {
100 auto *gnb = ie->value.choice.GlobalE2node_ID.choice.gNB;
ss412g4aeeda22020-06-16 14:12:41 +0300101 translatePlmnId(ranName, (const unsigned char *)gnb->global_gNB_ID.plmn_id.buf, (const char *)"gnb_");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200102 if (gnb->global_gNB_ID.gnb_id.present == GNB_ID_Choice_PR_gnb_ID) {
103 translateBitStringToChar(ranName, gnb->global_gNB_ID.gnb_id.choice.gnb_ID);
104 }
105 break;
106 }
107 case GlobalE2node_ID_PR_en_gNB: {
108 auto *enGnb = ie->value.choice.GlobalE2node_ID.choice.en_gNB;
109 translatePlmnId(ranName,
czichy2175dd32022-05-17 15:24:51 +0300110 (const unsigned char *)enGnb->global_en_gNB_ID.pLMN_Identity.buf,
ss412g4aeeda22020-06-16 14:12:41 +0300111 (const char *)"en_gnb_");
czichy2175dd32022-05-17 15:24:51 +0300112 if (enGnb->global_en_gNB_ID.gNB_ID.present == ENGNB_ID_PR_gNB_ID) {
113 translateBitStringToChar(ranName, enGnb->global_en_gNB_ID.gNB_ID.choice.gNB_ID);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200114 }
115 break;
116 }
117 case GlobalE2node_ID_PR_ng_eNB: {
118 auto *ngEnb = ie->value.choice.GlobalE2node_ID.choice.ng_eNB;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200119 switch (ngEnb->global_ng_eNB_ID.enb_id.present) {
120 case ENB_ID_Choice_PR_enb_ID_macro: {
swc58d4f5d2020-10-20 15:08:38 +0900121 translatePlmnId(ranName, (const unsigned char *)ngEnb->global_ng_eNB_ID.plmn_id.buf, (const char *)"ng_enB_macro_");
122 translateBitStringToChar(ranName, ngEnb->global_ng_eNB_ID.enb_id.choice.enb_ID_macro);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200123 break;
124 }
125 case ENB_ID_Choice_PR_enb_ID_shortmacro: {
swc58d4f5d2020-10-20 15:08:38 +0900126 translatePlmnId(ranName, (const unsigned char *)ngEnb->global_ng_eNB_ID.plmn_id.buf, (const char *)"ng_enB_shortmacro_");
127 translateBitStringToChar(ranName, ngEnb->global_ng_eNB_ID.enb_id.choice.enb_ID_shortmacro);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200128 break;
129 }
130 case ENB_ID_Choice_PR_enb_ID_longmacro: {
swc58d4f5d2020-10-20 15:08:38 +0900131 translatePlmnId(ranName, (const unsigned char *)ngEnb->global_ng_eNB_ID.plmn_id.buf, (const char *)"ng_enB_longmacro_");
132 translateBitStringToChar(ranName, ngEnb->global_ng_eNB_ID.enb_id.choice.enb_ID_longmacro);
133 break;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200134 }
135 case ENB_ID_Choice_PR_NOTHING: {
136 break;
137 }
138 default:
139 break;
140 }
pwpmurthy1c7b3312023-03-07 16:41:17 +0000141 break;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200142 }
143 case GlobalE2node_ID_PR_eNB: {
144 auto *enb = ie->value.choice.GlobalE2node_ID.choice.eNB;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200145 switch (enb->global_eNB_ID.eNB_ID.present) {
146 case ENB_ID_PR_macro_eNB_ID: {
swc58d4f5d2020-10-20 15:08:38 +0900147 translatePlmnId(ranName, (const unsigned char *)enb->global_eNB_ID.pLMN_Identity.buf, (const char *)"enB_macro_");
148 translateBitStringToChar(ranName, enb->global_eNB_ID.eNB_ID.choice.macro_eNB_ID);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200149 break;
150 }
151 case ENB_ID_PR_home_eNB_ID: {
swc58d4f5d2020-10-20 15:08:38 +0900152 translatePlmnId(ranName, (const unsigned char *)enb->global_eNB_ID.pLMN_Identity.buf, (const char *)"enB_home_");
153 translateBitStringToChar(ranName, enb->global_eNB_ID.eNB_ID.choice.home_eNB_ID);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200154 break;
155 }
156 case ENB_ID_PR_short_Macro_eNB_ID: {
swc58d4f5d2020-10-20 15:08:38 +0900157 translatePlmnId(ranName, (const unsigned char *)enb->global_eNB_ID.pLMN_Identity.buf, (const char *)"enB_shortmacro_");
158 translateBitStringToChar(ranName, enb->global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200159 break;
160 }
161 case ENB_ID_PR_long_Macro_eNB_ID: {
swc58d4f5d2020-10-20 15:08:38 +0900162 translatePlmnId(ranName, (const unsigned char *)enb->global_eNB_ID.pLMN_Identity.buf, (const char *)"enB_longmacro_");
163 translateBitStringToChar(ranName, enb->global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200164 break;
165 }
swc58d4f5d2020-10-20 15:08:38 +0900166 case ENB_ID_PR_NOTHING: {
167 break;
168 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200169 default: {
170 break;
171 }
172 }
pwpmurthy1c7b3312023-03-07 16:41:17 +0000173 break;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200174 }
175 case GlobalE2node_ID_PR_NOTHING:
176 default:
177 return -1;
178 }
179 return 0;
180}
181
182
183#endif //E2_BUILDRUNNAME_H