[RICPLT-1854] Refactor X2/ENDC Setup/Setup Failure Response
[ric-plt/e2mgr.git] / E2Manager / asn1codec / src / x2reset_response_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 <ProtocolIE-ID.h>
29 #include <ProtocolIE-Field.h>
30 #include <x2reset_response_wrapper.h>
31
32 /*
33  * Build and pack a reset response.
34  * Abort the process on allocation failure.
35  *  packed_buf_size - in: size of packed_buf; out: number of chars used.
36  */
37
38 bool
39 build_pack_x2reset_response(size_t* packed_buf_size, unsigned char* packed_buf,size_t err_buf_size, char* err_buf)
40 {
41         bool rc = true;
42     E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
43
44     ResetResponse_t *resetResponse;
45     SuccessfulOutcome_t *successfulOutcome = calloc(1, sizeof(SuccessfulOutcome_t));
46     ResetResponse_IEs_t *resetResponse_ie = calloc(1, sizeof(ResetResponse_IEs_t));
47
48     assert(pdu != 0);
49     assert(successfulOutcome != 0);
50     assert(resetResponse_ie != 0);
51
52     pdu->present = E2AP_PDU_PR_successfulOutcome;
53     pdu->choice.successfulOutcome = successfulOutcome;
54
55     successfulOutcome->procedureCode = ProcedureCode_id_reset;
56     successfulOutcome->criticality = Criticality_reject;
57     successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetResponse;
58     resetResponse = &successfulOutcome->value.choice.ResetResponse;
59
60     resetResponse_ie->id = ProtocolIE_ID_id_CriticalityDiagnostics;
61     resetResponse_ie->criticality = Criticality_ignore;
62     resetResponse_ie->value.present =  ResetResponse_IEs__value_PR_CriticalityDiagnostics;
63
64     ASN_SEQUENCE_ADD(&resetResponse->protocolIEs, resetResponse_ie);
65
66     CriticalityDiagnostics_IE_List_t *critList = calloc(1, sizeof(CriticalityDiagnostics_IE_List_t));
67     assert(critList != 0);
68
69     CriticalityDiagnostics_IE_List__Member *member= calloc(1, sizeof(CriticalityDiagnostics_IE_List__Member));
70     assert(member != 0);
71
72     ASN_SEQUENCE_ADD(critList ,member);
73     ASN_SEQUENCE_ADD(resetResponse_ie->value.choice.CriticalityDiagnostics.iEsCriticalityDiagnostics, critList);
74
75     rc = per_pack_pdu(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf);
76     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
77
78     return rc;
79 }
80