cea1aa9b4499826a3823c83696a9ad77ed4f9e04
[ric-plt/e2mgr.git] / E2Manager / asn1codec / src / configuration_update_wrapper.c
1 /*
2  *
3  * Copyright 2019 AT&T Intellectual Property
4  * Copyright 2019 Nokia
5  *
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 /*******************************************************************************
21  *
22  *   Copyright (c) 2019 AT&T Intellectual Property.
23  *
24  *   Licensed under the Apache License, Version 2.0 (the "License");
25  *   you may not use this file except in compliance with the License.
26  *   You may obtain a copy of the License at
27  *
28  *       http://www.apache.org/licenses/LICENSE-2.0
29  *
30  *   Unless required by applicable law or agreed to in writing, software
31  *   distributed under the License is distributed on an "AS IS" BASIS,
32  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33  *   See the License for the specific language governing permissions and
34  *   limitations under the License.
35  *
36  *******************************************************************************/
37
38 // Standard Includes: ANSI C/C++, MSA, and Third-Party Libraries
39
40 // Platform Includes: Platform specific classes, functions, and libraries
41
42 // Local Includes: Application specific classes, functions, and libraries
43
44 #include <string.h>
45 #include <errno.h>
46 #undef NDEBUG
47 #include <assert.h>
48 #include <asn_application.h>
49 #include <E2AP-PDU.h>
50 #include <ProcedureCode.h>
51 #include <SuccessfulOutcome.h>
52 #include <UnsuccessfulOutcome.h>
53 #include <ProtocolIE-ID.h>
54 #include <ProtocolIE-Field.h>
55 #include <configuration_update_wrapper.h>
56
57 /*
58  * Build and pack ENB Configuration Update Acknowledge (successful outcome response).
59  * Abort the process on allocation failure.
60  *  packed_buf_size - in: size of packed_buf; out: number of chars used.
61  */
62 bool
63 build_pack_x2enb_configuration_update_ack(
64                 size_t* packed_buf_size,
65         unsigned char* packed_buf,
66                 size_t err_buf_size,
67                 char* err_buf)
68 {
69         bool rc = true;
70         E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
71         SuccessfulOutcome_t *successfulOutcome = calloc(1, sizeof(SuccessfulOutcome_t));
72         ENBConfigurationUpdateAcknowledge_t *enbConfigurationUpdateAcknowledge;
73         ENBConfigurationUpdateAcknowledge_IEs_t *enbConfigurationUpdateAcknowledge_IEs = calloc(1, sizeof(ENBConfigurationUpdateAcknowledge_IEs_t));
74
75     assert(pdu != 0);
76     assert(successfulOutcome != 0);
77     assert(enbConfigurationUpdateAcknowledge_IEs != 0);
78
79     pdu->present = E2AP_PDU_PR_successfulOutcome;
80     pdu->choice.successfulOutcome = successfulOutcome;
81
82     successfulOutcome->procedureCode = ProcedureCode_id_eNBConfigurationUpdate;
83     successfulOutcome->criticality = Criticality_reject;
84     successfulOutcome->value.present = SuccessfulOutcome__value_PR_ENBConfigurationUpdateAcknowledge;
85     enbConfigurationUpdateAcknowledge = &successfulOutcome->value.choice.ENBConfigurationUpdateAcknowledge;
86
87     enbConfigurationUpdateAcknowledge_IEs->id = ProtocolIE_ID_id_CriticalityDiagnostics;
88         enbConfigurationUpdateAcknowledge_IEs->criticality = Criticality_ignore;
89         enbConfigurationUpdateAcknowledge_IEs->value.present =  ENBConfigurationUpdateAcknowledge_IEs__value_PR_CriticalityDiagnostics;
90
91     ASN_SEQUENCE_ADD(&enbConfigurationUpdateAcknowledge->protocolIEs, enbConfigurationUpdateAcknowledge_IEs);
92
93         rc = per_pack_pdu(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf);
94
95     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
96     return rc;
97 }
98
99 /*
100  * Build and pack ENB Configuration Update Failure (unsuccessful outcome message).
101  * Abort the process on allocation failure.
102  *  packed_buf_size - in: size of packed_buf; out: number of chars used.
103  */
104 bool
105 build_pack_x2enb_configuration_update_failure(
106                 size_t* packed_buf_size,
107         unsigned char* packed_buf,
108         size_t err_buf_size,
109                 char* err_buf)
110 {
111         bool rc = true;
112         E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
113         UnsuccessfulOutcome_t *unsuccessfulOutcome = calloc(1, sizeof(UnsuccessfulOutcome_t));
114         ENBConfigurationUpdateFailure_t *enbConfigurationUpdateFailure;
115         ENBConfigurationUpdateFailure_IEs_t *enbConfigurationUpdateFailure_IEs = calloc(1, sizeof(ENBConfigurationUpdateFailure_IEs_t));
116
117     assert(pdu != 0);
118     assert(unsuccessfulOutcome != 0);
119     assert(enbConfigurationUpdateFailure_IEs != 0);
120
121
122     pdu->present = E2AP_PDU_PR_unsuccessfulOutcome;
123     pdu->choice.unsuccessfulOutcome = unsuccessfulOutcome;
124
125     unsuccessfulOutcome->procedureCode = ProcedureCode_id_eNBConfigurationUpdate;
126     unsuccessfulOutcome->criticality = Criticality_reject;
127     unsuccessfulOutcome->value.present = UnsuccessfulOutcome__value_PR_ENBConfigurationUpdateFailure;
128     enbConfigurationUpdateFailure = &unsuccessfulOutcome->value.choice.ENBConfigurationUpdateFailure;
129
130     enbConfigurationUpdateFailure_IEs->id = ProtocolIE_ID_id_Cause;
131         enbConfigurationUpdateFailure_IEs->criticality = Criticality_ignore;
132         enbConfigurationUpdateFailure_IEs->value.present = ENBConfigurationUpdateFailure_IEs__value_PR_Cause;
133         enbConfigurationUpdateFailure_IEs->value.choice.Cause.present = Cause_PR_protocol;
134         enbConfigurationUpdateFailure_IEs->value.choice.Cause.choice.protocol= CauseProtocol_abstract_syntax_error_reject;
135     ASN_SEQUENCE_ADD(&enbConfigurationUpdateFailure->protocolIEs, enbConfigurationUpdateFailure_IEs);
136
137
138     rc = per_pack_pdu(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf);
139
140     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
141     return rc;
142 }
143
144 /*
145  * Build and pack ENDC Configuration Update Acknowledge (successful outcome response).
146  * Abort the process on allocation failure.
147  *  packed_buf_size - in: size of packed_buf; out: number of chars used.
148  */
149 bool
150 build_pack_endc_configuration_update_ack(
151                 size_t* packed_buf_size,
152                 unsigned char* packed_buf,
153                 size_t err_buf_size,
154                 char* err_buf)
155 {
156         bool rc = true;
157         E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
158         SuccessfulOutcome_t *successfulOutcome = calloc(1, sizeof(SuccessfulOutcome_t));
159         ENDCConfigurationUpdateAcknowledge_t *endcConfigurationUpdateAcknowledge;
160         ENDCConfigurationUpdateAcknowledge_IEs_t *endcConfigurationUpdateAcknowledge_IEs = calloc(1, sizeof(ENDCConfigurationUpdateAcknowledge_IEs_t));
161
162     assert(pdu != 0);
163     assert(successfulOutcome != 0);
164     assert(endcConfigurationUpdateAcknowledge_IEs != 0);
165
166     pdu->present = E2AP_PDU_PR_successfulOutcome;
167     pdu->choice.successfulOutcome = successfulOutcome;
168
169     successfulOutcome->procedureCode = ProcedureCode_id_endcConfigurationUpdate;
170     successfulOutcome->criticality = Criticality_reject;
171     successfulOutcome->value.present = SuccessfulOutcome__value_PR_ENDCConfigurationUpdateAcknowledge;
172     endcConfigurationUpdateAcknowledge = &successfulOutcome->value.choice.ENDCConfigurationUpdateAcknowledge;
173     ASN_SEQUENCE_ADD(&endcConfigurationUpdateAcknowledge->protocolIEs, endcConfigurationUpdateAcknowledge_IEs);
174
175     endcConfigurationUpdateAcknowledge_IEs->id = ProtocolIE_ID_id_RespondingNodeType_EndcConfigUpdate;
176         endcConfigurationUpdateAcknowledge_IEs->criticality = Criticality_reject;
177         endcConfigurationUpdateAcknowledge_IEs->value.present = ENDCConfigurationUpdateAcknowledge_IEs__value_PR_RespondingNodeType_EndcConfigUpdate;
178         endcConfigurationUpdateAcknowledge_IEs->value.choice.RespondingNodeType_EndcConfigUpdate.present = RespondingNodeType_EndcConfigUpdate_PR_respond_eNB;
179
180         ProtocolIE_Container_119P95_t *enb_ENDCConfigUpdateAckIEs_Container = calloc(1, sizeof(ProtocolIE_Container_119P95_t));
181         assert(enb_ENDCConfigUpdateAckIEs_Container != 0);
182         endcConfigurationUpdateAcknowledge_IEs->value.choice.RespondingNodeType_EndcConfigUpdate.choice.respond_eNB = (struct ProtocolIE_Container*)enb_ENDCConfigUpdateAckIEs_Container;
183
184         //Leave the respond_eNB container empty (ENB_ENDCConfigUpdateAckIEs_t is an empty element).
185
186     rc = per_pack_pdu(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf);
187
188     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
189     return rc;
190 }
191
192 /*
193  * Build and pack ENDC Configuration Update Failure (unsuccessful outcome message).
194  * Abort the process on allocation failure.
195  *  packed_buf_size - in: size of packed_buf; out: number of chars used.
196  */
197 bool
198 build_pack_endc_configuration_update_failure(
199                 size_t* packed_buf_size,
200         unsigned char* packed_buf,
201         size_t err_buf_size,
202                 char* err_buf)
203 {
204         bool rc = true;
205         E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
206         UnsuccessfulOutcome_t *unsuccessfulOutcome = calloc(1, sizeof(UnsuccessfulOutcome_t));
207         ENDCConfigurationUpdateFailure_t *endcConfigurationUpdateFailure;
208         ENDCConfigurationUpdateFailure_IEs_t *endcConfigurationUpdateFailure_IEs = calloc(1, sizeof(ENDCConfigurationUpdateFailure_IEs_t));
209
210     assert(pdu != 0);
211     assert(unsuccessfulOutcome != 0);
212     assert(endcConfigurationUpdateFailure_IEs != 0);
213
214
215     pdu->present = E2AP_PDU_PR_unsuccessfulOutcome;
216     pdu->choice.unsuccessfulOutcome = unsuccessfulOutcome;
217
218     unsuccessfulOutcome->procedureCode = ProcedureCode_id_endcConfigurationUpdate;
219     unsuccessfulOutcome->criticality = Criticality_reject;
220     unsuccessfulOutcome->value.present = UnsuccessfulOutcome__value_PR_ENDCConfigurationUpdateFailure;
221     endcConfigurationUpdateFailure = &unsuccessfulOutcome->value.choice.ENDCConfigurationUpdateFailure;
222
223     endcConfigurationUpdateFailure_IEs->id = ProtocolIE_ID_id_Cause;
224     endcConfigurationUpdateFailure_IEs->criticality = Criticality_ignore;
225     endcConfigurationUpdateFailure_IEs->value.present = ENDCConfigurationUpdateFailure_IEs__value_PR_Cause;
226     endcConfigurationUpdateFailure_IEs->value.choice.Cause.present = Cause_PR_protocol;
227     endcConfigurationUpdateFailure_IEs->value.choice.Cause.choice.protocol= CauseProtocol_abstract_syntax_error_reject;
228     ASN_SEQUENCE_ADD(&endcConfigurationUpdateFailure->protocolIEs, endcConfigurationUpdateFailure_IEs);
229
230     rc = per_pack_pdu(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf);
231
232     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
233     return rc;
234 }
235