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.
25 //#include <mdclog/mdclog.h>
28 #include "oranE2/E2AP-PDU.h"
29 #include "oranE2/InitiatingMessage.h"
30 #include "oranE2/SuccessfulOutcome.h"
31 #include "oranE2/UnsuccessfulOutcome.h"
33 #include "oranE2/ProtocolIE-Field.h"
34 #include "oranE2/ENB-ID.h"
35 #include "oranE2/GlobalENB-ID.h"
36 #include "oranE2/GlobalE2node-gNB-ID.h"
37 #include "oranE2/constr_TYPE.h"
39 #include "E2Builder.h"
44 #include "BuildRunName.h"
46 void buildRanName(E2AP_PDU_t *pdu, unsigned char *buffer) {
47 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) {
48 auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i];
49 if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) {
50 if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) {
51 memset(buffer, 0, 128);
52 buildRanName( (char *) buffer, ie);
59 void extractPdu(E2AP_PDU_t *pdu, unsigned char *buffer, int buffer_size) {
61 er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size);
62 if (er.encoded == -1) {
63 cerr << "encoding of " << asn_DEF_E2AP_PDU.name << " failed, " << strerror(errno) << endl;
65 } else if (er.encoded > (ssize_t) buffer_size) {
66 cerr << "Buffer of size " << buffer_size << " is to small for " << asn_DEF_E2AP_PDU.name << endl;
69 cout << "XML result = " << buffer << endl;
74 unsigned char setupBuffer[309] = {
75 0x00, 0x01, 0x00, 0x82, 0x64, 0x00, 0x00, 0x02, 0x00, 0x03,
76 0x00, 0x08, 0x00, 0x02, 0xf8, 0x21, 0x03, 0x03, 0x03, 0x00,
77 0x00, 0xa0, 0x08, 0x25, 0x00, 0x00, 0x30, 0x00, 0x84, 0x08,
78 0x0d, 0xf0, 0x00, 0x00, 0x18, 0x0d, 0x87, 0x90, 0x28, 0x06,
79 0x74, 0xe4, 0x22, 0xd5, 0x83, 0x20, 0x00, 0x02, 0x03, 0x12,
80 0xe3, 0x32, 0xe3, 0x62, 0xe3, 0x12, 0xe3, 0x42, 0xe3, 0x12,
81 0xe3, 0x23, 0x83, 0x43, 0x53, 0x82, 0xe3, 0x93, 0x92, 0xe3,
82 0x02, 0xe3, 0x23, 0x12, 0xe3, 0x32, 0xe3, 0x32, 0xe3, 0x12,
83 0xe3, 0x20, 0xb8, 0x06, 0x74, 0xe4, 0x22, 0x05, 0x83, 0x22,
84 0x04, 0xe6, 0x57, 0x47, 0x76, 0xf7, 0x26, 0xb2, 0x04, 0x96,
85 0xe7, 0x46, 0x57, 0x26, 0x66, 0x16, 0x36, 0x50, 0x10, 0x00,
86 0x00, 0x10, 0x10, 0x80, 0x04, 0xd6, 0x57, 0x37, 0x36, 0x16,
87 0x76, 0x52, 0x05, 0x47, 0x97, 0x06, 0x52, 0x06, 0xf6, 0xe6,
88 0xc7, 0x90, 0x10, 0x10, 0x00, 0x10, 0x10, 0x78, 0x04, 0x36,
89 0xf6, 0xd7, 0x06, 0xc6, 0x57, 0x46, 0x52, 0x06, 0xd6, 0x57,
90 0x37, 0x36, 0x16, 0x76, 0x50, 0x10, 0x10, 0x00, 0x00, 0x10,
91 0x58, 0x04, 0x16, 0x46, 0x45, 0x46, 0x96, 0xd6, 0x57, 0x37,
92 0x46, 0x16, 0xd7, 0x02, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00,
93 0x10, 0x10, 0x78, 0x04, 0x36, 0xf6, 0xd7, 0x06, 0xc6, 0x57,
94 0x46, 0x52, 0x06, 0xd6, 0x57, 0x37, 0x36, 0x16, 0x76, 0x50,
95 0x10, 0x10, 0x00, 0x00, 0x10, 0x58, 0x04, 0x16, 0x46, 0x45,
96 0x46, 0x96, 0xd6, 0x57, 0x37, 0x46, 0x16, 0xd7, 0x02, 0x00,
97 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x78,
98 0x04, 0x36, 0xf6, 0xd7, 0x06, 0xc6, 0x57, 0x46, 0x52, 0x06,
99 0xd6, 0x57, 0x37, 0x36, 0x16, 0x76, 0x50, 0x10, 0x10, 0x10,
100 0x10, 0x10, 0x10, 0x00, 0x10, 0x00, 0x84, 0x08, 0x0a, 0xc0,
101 0x00, 0x00, 0x28, 0x0a, 0x56, 0x80, 0x30, 0x06, 0x74, 0xe4,
102 0x22, 0xd4, 0xe5, 0x25, 0x40, 0x00, 0x02, 0x03, 0x12, 0xe3,
103 0x32, 0xe3, 0x62, 0xe3, 0x12, 0xe3, 0x42, 0xe3, 0x12, 0xe3,
104 0x23, 0x83, 0x43, 0x53, 0x82, 0xe3, 0x93, 0x92, 0xe3, 0x02,
105 0xe3, 0x23, 0x12, 0xe3, 0x32, 0xe3, 0x32, 0xe3, 0};
107 auto main(const int argc, char **argv) -> int {
111 FILE *stream = open_memstream(&printBuffer, &size);
112 auto buffer_size = 8192;
113 unsigned char buffer[8192] = {};
116 buildSetupRequest(&pdu, 311, 410);
117 asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu);
118 cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl;
119 fseek(stream,0,SEEK_SET);
121 extractPdu(&pdu, buffer, buffer_size);
122 buildRanName(&pdu, buffer);
123 cout << "Ran name = " << buffer << endl;
125 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, &pdu);
126 memset(buffer, 0, buffer_size);
128 buildSetupRequestWithFunc(&pdu, 311, 410);
129 extractPdu(&pdu, buffer, buffer_size);
131 buildRanName(&pdu, buffer);
132 cout << "Ran name = " << buffer << endl;
134 cout << "Sucessesfull outcome" << endl;
135 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, &pdu);
136 memset(buffer, 0, buffer_size);
137 uint8_t data[4] = {0x99, 0xAA, 0xBB, 0};
139 buildSetupSuccsessfulResponse(&pdu, 311, 410, data);
141 asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu);
142 cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl;
143 fseek(stream,0,SEEK_SET);
145 extractPdu(&pdu, buffer, buffer_size);
147 cout << "Failure outcome" << endl;
148 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, &pdu);
149 memset(buffer, 0, buffer_size);
151 buildSetupUnSuccsessfulResponse(&pdu);
152 asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu);
153 cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl;
154 fseek(stream,0,SEEK_SET);
156 extractPdu(&pdu, buffer, buffer_size);