2 * Copyright 2019 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 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 * platform project (RICP).
28 #include <asn_application.h>
30 #include <ProcedureCode.h>
31 #include <InitiatingMessage.h>
32 #include <X2SetupRequest.h>
33 #include <GlobalENB-ID.h>
34 #include <PLMN-Identity.h>
37 #include <ServedCells.h>
38 #include <ProtocolIE-ID.h>
39 #include <ProtocolIE-Field.h>
40 #include <x2setup_request_wrapper.h>
42 static void assignPLMN_Identity (PLMN_Identity_t *pLMN_Identity, uint8_t const* pLMNId);
43 static void assignENB_ID(GlobalENB_ID_t *globalENB_ID,uint8_t const* eNBId, unsigned int bitqty);
44 static void assignServedCell_Information(ServedCell_Information_t *servedCell_Information,uint8_t const* pLMN_Identity, uint8_t const* eNBId, unsigned int bitqty,uint8_t const *ric_flag);
47 * Build and pack X2 setup request.
48 * Abort the process on allocation failure.
49 * packed_buf_size - in: size of packed_buf; out: number of chars used.
53 build_pack_x2setup_request(
54 uint8_t const* pLMN_Identity, uint8_t const* eNBId, unsigned int bitqty /*18, 20, 21, 28*/, uint8_t const *ric_flag,
55 size_t* packed_buf_size, unsigned char* packed_buf,size_t err_buf_size, char* err_buf
58 return build_pack_x2setup_request_aux(
59 pLMN_Identity, eNBId, bitqty, ric_flag,
60 packed_buf_size, packed_buf,err_buf_size,err_buf,ATS_ALIGNED_BASIC_PER);
65 build_pack_x2setup_request_aux(
66 uint8_t const* pLMN_Identity, uint8_t const* eNBId, unsigned int bitqty /*18, 20, 21, 28*/, uint8_t const *ric_flag,
67 size_t* packed_buf_size, unsigned char* packed_buf,size_t err_buf_size, char* err_buf,enum asn_transfer_syntax syntax
71 E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
72 InitiatingMessage_t *initiatingMessage = calloc(1, sizeof(InitiatingMessage_t));
73 X2SetupRequest_t *x2SetupRequest;
76 assert(initiatingMessage != 0);
79 pdu->present = E2AP_PDU_PR_initiatingMessage;
80 pdu->choice.initiatingMessage = initiatingMessage;
82 initiatingMessage->procedureCode = ProcedureCode_id_x2Setup;
83 initiatingMessage->criticality = Criticality_reject;
84 initiatingMessage->value.present = InitiatingMessage__value_PR_X2SetupRequest;
85 x2SetupRequest = &initiatingMessage->value.choice.X2SetupRequest;
87 X2SetupRequest_IEs_t *globalENB_ID_ie = calloc(1, sizeof(X2SetupRequest_IEs_t));
88 assert(globalENB_ID_ie != 0);
89 ASN_SEQUENCE_ADD(&x2SetupRequest->protocolIEs, globalENB_ID_ie);
91 globalENB_ID_ie->id = ProtocolIE_ID_id_GlobalENB_ID;
92 globalENB_ID_ie->criticality = Criticality_reject;
93 globalENB_ID_ie->value.present = X2SetupRequest_IEs__value_PR_GlobalENB_ID;
94 GlobalENB_ID_t *globalENB_ID = &globalENB_ID_ie->value.choice.GlobalENB_ID;
96 assignPLMN_Identity(&globalENB_ID->pLMN_Identity, pLMN_Identity);
97 assignENB_ID(globalENB_ID, eNBId, bitqty);
99 X2SetupRequest_IEs_t *servedCells_ie = calloc(1, sizeof(X2SetupRequest_IEs_t));
100 assert(servedCells_ie != 0);
101 ASN_SEQUENCE_ADD(&x2SetupRequest->protocolIEs, servedCells_ie);
103 servedCells_ie->id = ProtocolIE_ID_id_ServedCells;
104 servedCells_ie->criticality = Criticality_reject;
105 servedCells_ie->value.present = X2SetupRequest_IEs__value_PR_ServedCells;
107 ServedCells__Member *servedCells__Member = calloc(1,sizeof(ServedCells__Member));
108 assert(servedCells__Member !=0);
109 ASN_SEQUENCE_ADD(&servedCells_ie->value.choice.ServedCells, servedCells__Member);
111 assignServedCell_Information(&servedCells__Member->servedCellInfo, pLMN_Identity,eNBId, bitqty,ric_flag);
113 rc = pack_pdu_aux(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf,syntax);
115 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
119 static void assignPLMN_Identity (PLMN_Identity_t *pLMN_Identity, uint8_t const* pLMNId)
121 pLMN_Identity->size = pLMN_Identity_size;
122 pLMN_Identity->buf = calloc(1,pLMN_Identity->size);
123 assert(pLMN_Identity->buf != 0);
124 memcpy(pLMN_Identity->buf, pLMNId, pLMN_Identity->size);
128 * Calculate and assign the value of ENB_ID.
129 * Abort the process on allocation failure.
131 static void assignENB_ID(GlobalENB_ID_t *globalENB_ID,uint8_t const* eNBId, unsigned int bitqty)
133 size_t size_in_bytes = (bitqty / 8) + ((bitqty % 8) > 0);
134 int unused_bits = 8 - (bitqty % 8);
137 case shortMacro_eNB_ID_size:
138 globalENB_ID->eNB_ID.present = ENB_ID_PR_short_Macro_eNB_ID;
139 globalENB_ID->eNB_ID.choice.short_Macro_eNB_ID.size = size_in_bytes;
140 globalENB_ID->eNB_ID.choice.short_Macro_eNB_ID.bits_unused = unused_bits;
141 tbuf = globalENB_ID->eNB_ID.choice.short_Macro_eNB_ID.buf = calloc(1, size_in_bytes);
142 assert(globalENB_ID->eNB_ID.choice.short_Macro_eNB_ID.buf != 0);
143 memcpy(globalENB_ID->eNB_ID.choice.short_Macro_eNB_ID.buf,eNBId, size_in_bytes) ;
144 tbuf[size_in_bytes - 1] <<= unused_bits;
146 case macro_eNB_ID_size:
147 globalENB_ID->eNB_ID.present =ENB_ID_PR_macro_eNB_ID;
148 globalENB_ID->eNB_ID.choice.macro_eNB_ID.size = size_in_bytes;
149 globalENB_ID->eNB_ID.choice.macro_eNB_ID.bits_unused = unused_bits;
150 tbuf = globalENB_ID->eNB_ID.choice.macro_eNB_ID.buf = calloc(1, size_in_bytes);
151 assert(globalENB_ID->eNB_ID.choice.macro_eNB_ID.buf != 0);
152 memcpy(globalENB_ID->eNB_ID.choice.macro_eNB_ID.buf,eNBId,size_in_bytes);
153 tbuf[size_in_bytes - 1] <<= unused_bits;
155 case longMacro_eNB_ID_size:
156 globalENB_ID->eNB_ID.present =ENB_ID_PR_long_Macro_eNB_ID;
157 globalENB_ID->eNB_ID.choice.long_Macro_eNB_ID.size = size_in_bytes;
158 globalENB_ID->eNB_ID.choice.long_Macro_eNB_ID.bits_unused = unused_bits;
159 tbuf = globalENB_ID->eNB_ID.choice.long_Macro_eNB_ID.buf = calloc(1, size_in_bytes);
160 assert(globalENB_ID->eNB_ID.choice.long_Macro_eNB_ID.buf != 0);
161 memcpy(globalENB_ID->eNB_ID.choice.long_Macro_eNB_ID.buf,eNBId,size_in_bytes);
162 tbuf[size_in_bytes - 1] <<= unused_bits;
164 case home_eNB_ID_size:
165 globalENB_ID->eNB_ID.present = ENB_ID_PR_home_eNB_ID;
166 globalENB_ID->eNB_ID.choice.home_eNB_ID.size = size_in_bytes;
167 globalENB_ID->eNB_ID.choice.home_eNB_ID.bits_unused =unused_bits;
168 tbuf = globalENB_ID->eNB_ID.choice.home_eNB_ID.buf = calloc(1,size_in_bytes);
169 assert(globalENB_ID->eNB_ID.choice.home_eNB_ID.buf != 0);
170 memcpy(globalENB_ID->eNB_ID.choice.home_eNB_ID.buf,eNBId,size_in_bytes);
171 tbuf[size_in_bytes - 1] <<= unused_bits;
180 * Calculate and assign the value of ServedCell_Information.
181 * Abort the process on allocation failure.
183 static void assignServedCell_Information(
184 ServedCell_Information_t *servedCell_Information,
185 uint8_t const* pLMN_Identity,
186 uint8_t const* eNBId,
188 uint8_t const *ric_flag)
190 size_t size_in_bytes = (eUTRANcellIdentifier_size / 8) + ((eUTRANcellIdentifier_size % 8) > 0);
191 int unused_bits = 8 - (eUTRANcellIdentifier_size % 8);
192 size_t bitqty_size_in_bytes = (bitqty / 8) + ((bitqty % 8) > 0);
193 int bitqty_unused_bits = 8 - (bitqty % 8);
195 servedCell_Information->pCI = 503;
196 assignPLMN_Identity(&servedCell_Information->cellId.pLMN_Identity, pLMN_Identity);
198 servedCell_Information->cellId.eUTRANcellIdentifier.size = size_in_bytes;
199 servedCell_Information->cellId.eUTRANcellIdentifier.bits_unused = unused_bits;
200 servedCell_Information->cellId.eUTRANcellIdentifier.buf = calloc(1,servedCell_Information->cellId.eUTRANcellIdentifier.size);
201 assert(servedCell_Information->cellId.eUTRANcellIdentifier.buf != 0);
202 memcpy(servedCell_Information->cellId.eUTRANcellIdentifier.buf, eNBId, bitqty_size_in_bytes);
203 if (bitqty < eUTRANcellIdentifier_size) {
204 servedCell_Information->cellId.eUTRANcellIdentifier.buf[bitqty_size_in_bytes - 1] <<= bitqty_unused_bits;
206 servedCell_Information->cellId.eUTRANcellIdentifier.buf[size_in_bytes - 1] <<= unused_bits;
209 servedCell_Information->tAC.size = 2;
210 servedCell_Information->tAC.buf = calloc(1,servedCell_Information->tAC.size);
211 assert(servedCell_Information->tAC.buf != 0);
214 PLMN_Identity_t *broadcastPLMN_Identity = calloc(1, sizeof(PLMN_Identity_t));
215 assert(broadcastPLMN_Identity != 0);
216 ASN_SEQUENCE_ADD(&servedCell_Information->broadcastPLMNs, broadcastPLMN_Identity);
218 assignPLMN_Identity(broadcastPLMN_Identity, pLMN_Identity); //ric_flag: disabled because a real eNB rejects the message
220 servedCell_Information->eUTRA_Mode_Info.present= EUTRA_Mode_Info_PR_fDD;
221 servedCell_Information->eUTRA_Mode_Info.choice.fDD = calloc(1, sizeof(FDD_Info_t));
222 assert(servedCell_Information->eUTRA_Mode_Info.choice.fDD != 0);
223 servedCell_Information->eUTRA_Mode_Info.choice.fDD->uL_EARFCN = 0;
224 servedCell_Information->eUTRA_Mode_Info.choice.fDD->dL_EARFCN = 0;
225 servedCell_Information->eUTRA_Mode_Info.choice.fDD->uL_Transmission_Bandwidth = Transmission_Bandwidth_bw6;
226 servedCell_Information->eUTRA_Mode_Info.choice.fDD->dL_Transmission_Bandwidth = Transmission_Bandwidth_bw15;
229 /* Build and pack X2 setup request.
230 * Abort the process on allocation failure.
231 * packed_buf_size - in: size of packed_buf; out: number of chars used.
234 build_pack_endc_x2setup_request(
235 uint8_t const* pLMN_Identity, uint8_t const* eNBId, unsigned int bitqty /*18, 20, 21, 28*/, uint8_t const *ric_flag,
236 size_t* packed_buf_size, unsigned char* packed_buf,size_t err_buf_size, char* err_buf
239 return build_pack_endc_x2setup_request_aux(
240 pLMN_Identity, eNBId, bitqty, ric_flag,
241 packed_buf_size, packed_buf,err_buf_size, err_buf,ATS_ALIGNED_BASIC_PER
246 build_pack_endc_x2setup_request_aux(
247 uint8_t const* pLMN_Identity, uint8_t const* eNBId, unsigned int bitqty /*18, 20, 21, 28*/, uint8_t const *ric_flag,
248 size_t* packed_buf_size, unsigned char* packed_buf,size_t err_buf_size, char* err_buf,enum asn_transfer_syntax syntax
252 E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
253 InitiatingMessage_t *initiatingMessage = calloc(1, sizeof(InitiatingMessage_t));
254 ENDCX2SetupRequest_t *endcX2SetupRequest;
257 assert(initiatingMessage != 0);
259 pdu->present = E2AP_PDU_PR_initiatingMessage;
260 pdu->choice.initiatingMessage = initiatingMessage;
262 initiatingMessage->procedureCode = ProcedureCode_id_endcX2Setup;
263 initiatingMessage->criticality = Criticality_reject;
264 initiatingMessage->value.present = InitiatingMessage__value_PR_ENDCX2SetupRequest;
265 endcX2SetupRequest = &initiatingMessage->value.choice.ENDCX2SetupRequest;
266 ENDCX2SetupRequest_IEs_t *endcX2SetupRequest_IEs = calloc(1, sizeof(ENDCX2SetupRequest_IEs_t));
267 assert(endcX2SetupRequest_IEs != 0);
268 ASN_SEQUENCE_ADD(&endcX2SetupRequest->protocolIEs, endcX2SetupRequest_IEs);
269 endcX2SetupRequest_IEs->id = ProtocolIE_ID_id_InitiatingNodeType_EndcX2Setup;
270 endcX2SetupRequest_IEs->criticality = Criticality_reject;
271 endcX2SetupRequest_IEs->value.present = ENDCX2SetupRequest_IEs__value_PR_InitiatingNodeType_EndcX2Setup;
272 endcX2SetupRequest_IEs->value.choice.InitiatingNodeType_EndcX2Setup.present = InitiatingNodeType_EndcX2Setup_PR_init_eNB;
274 ProtocolIE_Container_119P85_t *enb_ENDCX2SetupReqIE_Container = calloc(1, sizeof(ProtocolIE_Container_119P85_t));
275 assert(enb_ENDCX2SetupReqIE_Container != 0);
276 endcX2SetupRequest_IEs->value.choice.InitiatingNodeType_EndcX2Setup.choice.init_eNB = (struct ProtocolIE_Container*)enb_ENDCX2SetupReqIE_Container;
277 ENB_ENDCX2SetupReqIEs_t *globalENB_ID_ie = calloc(1, sizeof(ENB_ENDCX2SetupReqIEs_t));
278 assert(globalENB_ID_ie != 0);
279 ASN_SEQUENCE_ADD(enb_ENDCX2SetupReqIE_Container,globalENB_ID_ie);
280 globalENB_ID_ie->id = ProtocolIE_ID_id_GlobalENB_ID;
281 globalENB_ID_ie->criticality = Criticality_reject;
282 globalENB_ID_ie->value.present = ENB_ENDCX2SetupReqIEs__value_PR_GlobalENB_ID;
284 GlobalENB_ID_t *globalENB_ID = &globalENB_ID_ie->value.choice.GlobalENB_ID;
285 assignPLMN_Identity(&globalENB_ID->pLMN_Identity, pLMN_Identity);
286 assignENB_ID(globalENB_ID, eNBId, bitqty);
289 ENB_ENDCX2SetupReqIEs_t *ServedEUTRAcellsENDCX2ManagementList_ie = calloc(1, sizeof(ENB_ENDCX2SetupReqIEs_t));
290 assert(ServedEUTRAcellsENDCX2ManagementList_ie != 0);
291 ASN_SEQUENCE_ADD(enb_ENDCX2SetupReqIE_Container, ServedEUTRAcellsENDCX2ManagementList_ie);
293 ServedEUTRAcellsENDCX2ManagementList_ie->id = ProtocolIE_ID_id_ServedEUTRAcellsENDCX2ManagementList;
294 ServedEUTRAcellsENDCX2ManagementList_ie->criticality = Criticality_reject;
295 ServedEUTRAcellsENDCX2ManagementList_ie->value.present = ENB_ENDCX2SetupReqIEs__value_PR_ServedEUTRAcellsENDCX2ManagementList;
298 ServedEUTRAcellsENDCX2ManagementList__Member *servedEUTRAcellsENDCX2ManagementList__Member = calloc(1, sizeof(ServedEUTRAcellsENDCX2ManagementList__Member));
299 assert(servedEUTRAcellsENDCX2ManagementList__Member != 0);
300 ASN_SEQUENCE_ADD(&ServedEUTRAcellsENDCX2ManagementList_ie->value.choice.ServedEUTRAcellsENDCX2ManagementList, servedEUTRAcellsENDCX2ManagementList__Member);
302 assignServedCell_Information(&servedEUTRAcellsENDCX2ManagementList__Member->servedEUTRACellInfo, pLMN_Identity, eNBId, bitqty,ric_flag);
304 rc = pack_pdu_aux(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf, syntax);
306 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);