aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1 | /* |
| 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.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 30 | /** 02 F8 29 |
| 31 | * return the size of the string // |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 32 | */ |
| 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); |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 36 | ///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.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 38 | |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 39 | 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.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 41 | //auto mnc3 = (unsigned char)(((unsigned char)(data[1] & (unsigned char)0x0F) >> (unsigned char)4) ); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 42 | auto mnc3 = (unsigned char)(((unsigned char)((unsigned char)data[2] & (unsigned char)0xF0)) >> (unsigned char)4); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 43 | |
| 44 | int j = 0; |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 45 | if (mnc1 != 15) { |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 46 | j = snprintf(plmnId, 20, "%s%1d%1d%1d_%1d%1d%1d", type, mcc1, mcc2, mcc3, mnc1, mnc2, mnc3); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 47 | } |
| 48 | else { |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 49 | j = snprintf(plmnId, 20, "%s%1d%1d%1d_0%1d%1d", type, mcc1, mcc2, mcc3, mnc2, mnc3); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | return j; |
| 53 | } |
| 54 | |
| 55 | static int translateBitStringToChar(char *ranName, BIT_STRING_t &data) { |
| 56 | // dont care of last unused bits |
| 57 | char buffer[256] {}; |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 58 | auto j = snprintf(buffer, 256, "%s_", ranName); |
aa7133@att.com | 24e9fa4 | 2020-11-13 20:32:53 +0200 | [diff] [blame] | 59 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 60 | memcpy(ranName, buffer, j); |
aa7133@att.com | 24e9fa4 | 2020-11-13 20:32:53 +0200 | [diff] [blame] | 61 | /* |
| 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.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 74 | |
| 75 | unsigned b1 = 0; |
| 76 | unsigned b2 = 0; |
czichy | 039fe32 | 2022-06-17 11:31:47 +0300 | [diff] [blame] | 77 | unsigned tmp_digit=0; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 78 | for (auto i = 0; i < (int)data.size; i++) { |
czichy | 039fe32 | 2022-06-17 11:31:47 +0300 | [diff] [blame] | 79 | // |
| 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.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 86 | b1 = b1 >> (unsigned)4; |
| 87 | j = snprintf(buffer, 256, "%s%1x", ranName, b1); |
| 88 | memcpy(ranName, buffer, j); |
czichy | 039fe32 | 2022-06-17 11:31:47 +0300 | [diff] [blame] | 89 | b2 = tmp_digit & (unsigned)0x0F; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 90 | j = snprintf(buffer, 256, "%s%1x", ranName, b2); |
| 91 | memcpy(ranName, buffer, j); |
| 92 | } |
| 93 | return j; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | int 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; |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 101 | translatePlmnId(ranName, (const unsigned char *)gnb->global_gNB_ID.plmn_id.buf, (const char *)"gnb_"); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 102 | 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, |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 110 | (const unsigned char *)enGnb->global_en_gNB_ID.pLMN_Identity.buf, |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 111 | (const char *)"en_gnb_"); |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 112 | 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.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 114 | } |
| 115 | break; |
| 116 | } |
| 117 | case GlobalE2node_ID_PR_ng_eNB: { |
| 118 | auto *ngEnb = ie->value.choice.GlobalE2node_ID.choice.ng_eNB; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 119 | switch (ngEnb->global_ng_eNB_ID.enb_id.present) { |
| 120 | case ENB_ID_Choice_PR_enb_ID_macro: { |
swc | 58d4f5d | 2020-10-20 15:08:38 +0900 | [diff] [blame] | 121 | 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.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 123 | break; |
| 124 | } |
| 125 | case ENB_ID_Choice_PR_enb_ID_shortmacro: { |
swc | 58d4f5d | 2020-10-20 15:08:38 +0900 | [diff] [blame] | 126 | 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.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 128 | break; |
| 129 | } |
| 130 | case ENB_ID_Choice_PR_enb_ID_longmacro: { |
swc | 58d4f5d | 2020-10-20 15:08:38 +0900 | [diff] [blame] | 131 | 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.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 134 | } |
| 135 | case ENB_ID_Choice_PR_NOTHING: { |
| 136 | break; |
| 137 | } |
| 138 | default: |
| 139 | break; |
| 140 | } |
pwpmurthy | 1c7b331 | 2023-03-07 16:41:17 +0000 | [diff] [blame] | 141 | break; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 142 | } |
| 143 | case GlobalE2node_ID_PR_eNB: { |
| 144 | auto *enb = ie->value.choice.GlobalE2node_ID.choice.eNB; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 145 | switch (enb->global_eNB_ID.eNB_ID.present) { |
| 146 | case ENB_ID_PR_macro_eNB_ID: { |
swc | 58d4f5d | 2020-10-20 15:08:38 +0900 | [diff] [blame] | 147 | 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.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 149 | break; |
| 150 | } |
| 151 | case ENB_ID_PR_home_eNB_ID: { |
swc | 58d4f5d | 2020-10-20 15:08:38 +0900 | [diff] [blame] | 152 | 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.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 154 | break; |
| 155 | } |
| 156 | case ENB_ID_PR_short_Macro_eNB_ID: { |
swc | 58d4f5d | 2020-10-20 15:08:38 +0900 | [diff] [blame] | 157 | 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.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 159 | break; |
| 160 | } |
| 161 | case ENB_ID_PR_long_Macro_eNB_ID: { |
swc | 58d4f5d | 2020-10-20 15:08:38 +0900 | [diff] [blame] | 162 | 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.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 164 | break; |
| 165 | } |
swc | 58d4f5d | 2020-10-20 15:08:38 +0900 | [diff] [blame] | 166 | case ENB_ID_PR_NOTHING: { |
| 167 | break; |
| 168 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 169 | default: { |
| 170 | break; |
| 171 | } |
| 172 | } |
pwpmurthy | 1c7b331 | 2023-03-07 16:41:17 +0000 | [diff] [blame] | 173 | break; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 174 | } |
| 175 | case GlobalE2node_ID_PR_NOTHING: |
| 176 | default: |
| 177 | return -1; |
| 178 | } |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | |
| 183 | #endif //E2_BUILDRUNNAME_H |