reader versions updated to 23
[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 #include <string.h>
21 #include <errno.h>
22 #undef NDEBUG
23 #include <assert.h>
24 #include <asn_application.h>
25 #include <E2AP-PDU.h>
26 #include <ProcedureCode.h>
27 #include <SuccessfulOutcome.h>
28 #include <UnsuccessfulOutcome.h>
29 #include <ProtocolIE-ID.h>
30 #include <ProtocolIE-Field.h>
31 #include <configuration_update_wrapper.h>
32
33 /*
34  * Build and pack ENB Configuration Update Acknowledge (successful outcome response).
35  * Abort the process on allocation failure.
36  *  packed_buf_size - in: size of packed_buf; out: number of chars used.
37  */
38 bool
39 build_pack_x2enb_configuration_update_ack(
40                 size_t* packed_buf_size,
41         unsigned char* packed_buf,
42                 size_t err_buf_size,
43                 char* err_buf)
44 {
45         bool rc = true;
46         E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
47         SuccessfulOutcome_t *successfulOutcome = calloc(1, sizeof(SuccessfulOutcome_t));
48         ENBConfigurationUpdateAcknowledge_t *enbConfigurationUpdateAcknowledge;
49         ENBConfigurationUpdateAcknowledge_IEs_t *enbConfigurationUpdateAcknowledge_IEs = calloc(1, sizeof(ENBConfigurationUpdateAcknowledge_IEs_t));
50
51     assert(pdu != 0);
52     assert(successfulOutcome != 0);
53     assert(enbConfigurationUpdateAcknowledge_IEs != 0);
54
55     pdu->present = E2AP_PDU_PR_successfulOutcome;
56     pdu->choice.successfulOutcome = successfulOutcome;
57
58     successfulOutcome->procedureCode = ProcedureCode_id_eNBConfigurationUpdate;
59     successfulOutcome->criticality = Criticality_reject;
60     successfulOutcome->value.present = SuccessfulOutcome__value_PR_ENBConfigurationUpdateAcknowledge;
61     enbConfigurationUpdateAcknowledge = &successfulOutcome->value.choice.ENBConfigurationUpdateAcknowledge;
62
63     enbConfigurationUpdateAcknowledge_IEs->id = ProtocolIE_ID_id_CriticalityDiagnostics;
64         enbConfigurationUpdateAcknowledge_IEs->criticality = Criticality_ignore;
65         enbConfigurationUpdateAcknowledge_IEs->value.present =  ENBConfigurationUpdateAcknowledge_IEs__value_PR_CriticalityDiagnostics;
66
67     ASN_SEQUENCE_ADD(&enbConfigurationUpdateAcknowledge->protocolIEs, enbConfigurationUpdateAcknowledge_IEs);
68
69         rc = per_pack_pdu(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf);
70
71     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
72     return rc;
73 }
74
75 /*
76  * Build and pack ENB Configuration Update Failure (unsuccessful outcome message).
77  * Abort the process on allocation failure.
78  *  packed_buf_size - in: size of packed_buf; out: number of chars used.
79  */
80 bool
81 build_pack_x2enb_configuration_update_failure(
82                 size_t* packed_buf_size,
83         unsigned char* packed_buf,
84         size_t err_buf_size,
85                 char* err_buf)
86 {
87         bool rc = true;
88         E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
89         UnsuccessfulOutcome_t *unsuccessfulOutcome = calloc(1, sizeof(UnsuccessfulOutcome_t));
90         ENBConfigurationUpdateFailure_t *enbConfigurationUpdateFailure;
91         ENBConfigurationUpdateFailure_IEs_t *enbConfigurationUpdateFailure_IEs = calloc(1, sizeof(ENBConfigurationUpdateFailure_IEs_t));
92
93     assert(pdu != 0);
94     assert(unsuccessfulOutcome != 0);
95     assert(enbConfigurationUpdateFailure_IEs != 0);
96
97
98     pdu->present = E2AP_PDU_PR_unsuccessfulOutcome;
99     pdu->choice.unsuccessfulOutcome = unsuccessfulOutcome;
100
101     unsuccessfulOutcome->procedureCode = ProcedureCode_id_eNBConfigurationUpdate;
102     unsuccessfulOutcome->criticality = Criticality_reject;
103     unsuccessfulOutcome->value.present = UnsuccessfulOutcome__value_PR_ENBConfigurationUpdateFailure;
104     enbConfigurationUpdateFailure = &unsuccessfulOutcome->value.choice.ENBConfigurationUpdateFailure;
105
106     enbConfigurationUpdateFailure_IEs->id = ProtocolIE_ID_id_Cause;
107         enbConfigurationUpdateFailure_IEs->criticality = Criticality_ignore;
108         enbConfigurationUpdateFailure_IEs->value.present = ENBConfigurationUpdateFailure_IEs__value_PR_Cause;
109         enbConfigurationUpdateFailure_IEs->value.choice.Cause.present = Cause_PR_protocol;
110         enbConfigurationUpdateFailure_IEs->value.choice.Cause.choice.protocol= CauseProtocol_abstract_syntax_error_reject;
111     ASN_SEQUENCE_ADD(&enbConfigurationUpdateFailure->protocolIEs, enbConfigurationUpdateFailure_IEs);
112
113
114     rc = per_pack_pdu(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf);
115
116     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
117     return rc;
118 }
119
120 /*
121  * Build and pack ENDC Configuration Update Acknowledge (successful outcome response).
122  * Abort the process on allocation failure.
123  *  packed_buf_size - in: size of packed_buf; out: number of chars used.
124  */
125 bool
126 build_pack_endc_configuration_update_ack(
127                 size_t* packed_buf_size,
128                 unsigned char* packed_buf,
129                 size_t err_buf_size,
130                 char* err_buf)
131 {
132         bool rc = true;
133         E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
134         SuccessfulOutcome_t *successfulOutcome = calloc(1, sizeof(SuccessfulOutcome_t));
135         ENDCConfigurationUpdateAcknowledge_t *endcConfigurationUpdateAcknowledge;
136         ENDCConfigurationUpdateAcknowledge_IEs_t *endcConfigurationUpdateAcknowledge_IEs = calloc(1, sizeof(ENDCConfigurationUpdateAcknowledge_IEs_t));
137
138     assert(pdu != 0);
139     assert(successfulOutcome != 0);
140     assert(endcConfigurationUpdateAcknowledge_IEs != 0);
141
142     pdu->present = E2AP_PDU_PR_successfulOutcome;
143     pdu->choice.successfulOutcome = successfulOutcome;
144
145     successfulOutcome->procedureCode = ProcedureCode_id_endcConfigurationUpdate;
146     successfulOutcome->criticality = Criticality_reject;
147     successfulOutcome->value.present = SuccessfulOutcome__value_PR_ENDCConfigurationUpdateAcknowledge;
148     endcConfigurationUpdateAcknowledge = &successfulOutcome->value.choice.ENDCConfigurationUpdateAcknowledge;
149     ASN_SEQUENCE_ADD(&endcConfigurationUpdateAcknowledge->protocolIEs, endcConfigurationUpdateAcknowledge_IEs);
150
151     endcConfigurationUpdateAcknowledge_IEs->id = ProtocolIE_ID_id_RespondingNodeType_EndcConfigUpdate;
152         endcConfigurationUpdateAcknowledge_IEs->criticality = Criticality_reject;
153         endcConfigurationUpdateAcknowledge_IEs->value.present = ENDCConfigurationUpdateAcknowledge_IEs__value_PR_RespondingNodeType_EndcConfigUpdate;
154         endcConfigurationUpdateAcknowledge_IEs->value.choice.RespondingNodeType_EndcConfigUpdate.present = RespondingNodeType_EndcConfigUpdate_PR_respond_eNB;
155
156         ProtocolIE_Container_119P95_t *enb_ENDCConfigUpdateAckIEs_Container = calloc(1, sizeof(ProtocolIE_Container_119P95_t));
157         assert(enb_ENDCConfigUpdateAckIEs_Container != 0);
158         endcConfigurationUpdateAcknowledge_IEs->value.choice.RespondingNodeType_EndcConfigUpdate.choice.respond_eNB = (struct ProtocolIE_Container*)enb_ENDCConfigUpdateAckIEs_Container;
159
160         //Leave the respond_eNB container empty (ENB_ENDCConfigUpdateAckIEs_t is an empty element).
161
162     rc = per_pack_pdu(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf);
163
164     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
165     return rc;
166 }
167
168 /*
169  * Build and pack ENDC Configuration Update Failure (unsuccessful outcome message).
170  * Abort the process on allocation failure.
171  *  packed_buf_size - in: size of packed_buf; out: number of chars used.
172  */
173 bool
174 build_pack_endc_configuration_update_failure(
175                 size_t* packed_buf_size,
176         unsigned char* packed_buf,
177         size_t err_buf_size,
178                 char* err_buf)
179 {
180         bool rc = true;
181         E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
182         UnsuccessfulOutcome_t *unsuccessfulOutcome = calloc(1, sizeof(UnsuccessfulOutcome_t));
183         ENDCConfigurationUpdateFailure_t *endcConfigurationUpdateFailure;
184         ENDCConfigurationUpdateFailure_IEs_t *endcConfigurationUpdateFailure_IEs = calloc(1, sizeof(ENDCConfigurationUpdateFailure_IEs_t));
185
186     assert(pdu != 0);
187     assert(unsuccessfulOutcome != 0);
188     assert(endcConfigurationUpdateFailure_IEs != 0);
189
190
191     pdu->present = E2AP_PDU_PR_unsuccessfulOutcome;
192     pdu->choice.unsuccessfulOutcome = unsuccessfulOutcome;
193
194     unsuccessfulOutcome->procedureCode = ProcedureCode_id_endcConfigurationUpdate;
195     unsuccessfulOutcome->criticality = Criticality_reject;
196     unsuccessfulOutcome->value.present = UnsuccessfulOutcome__value_PR_ENDCConfigurationUpdateFailure;
197     endcConfigurationUpdateFailure = &unsuccessfulOutcome->value.choice.ENDCConfigurationUpdateFailure;
198
199     endcConfigurationUpdateFailure_IEs->id = ProtocolIE_ID_id_Cause;
200     endcConfigurationUpdateFailure_IEs->criticality = Criticality_ignore;
201     endcConfigurationUpdateFailure_IEs->value.present = ENDCConfigurationUpdateFailure_IEs__value_PR_Cause;
202     endcConfigurationUpdateFailure_IEs->value.choice.Cause.present = Cause_PR_protocol;
203     endcConfigurationUpdateFailure_IEs->value.choice.Cause.choice.protocol= CauseProtocol_abstract_syntax_error_reject;
204     ASN_SEQUENCE_ADD(&endcConfigurationUpdateFailure->protocolIEs, endcConfigurationUpdateFailure_IEs);
205
206     rc = per_pack_pdu(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf);
207
208     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
209     return rc;
210 }
211