Update RMR to v4.8.0
[ric-plt/e2mgr.git] / E2Manager / 3rdparty / asn1codec / src / x2reset_response_wrapper.c
1 /*
2  * Copyright 2019 AT&T Intellectual Property
3  * Copyright 2019 Nokia
4  *
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 /*
19  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
20  * platform project (RICP).
21  */
22
23
24 #include <string.h>
25 #include <errno.h>
26 #undef NDEBUG
27 #include <assert.h>
28 #include <asn_application.h>
29 #include <E2AP-PDU.h>
30 #include <ProcedureCode.h>
31 #include <SuccessfulOutcome.h>
32 #include <ProtocolIE-ID.h>
33 #include <ProtocolIE-Field.h>
34 #include <x2reset_response_wrapper.h>
35
36 /*
37  * Build and pack a reset response.
38  * Abort the process on allocation failure.
39  *  packed_buf_size - in: size of packed_buf; out: number of chars used.
40  */
41
42 bool
43 build_pack_x2reset_response(size_t* packed_buf_size, unsigned char* packed_buf,size_t err_buf_size, char* err_buf)
44 {
45         bool rc = true;
46     E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
47
48     ResetResponse_t *resetResponse;
49     SuccessfulOutcome_t *successfulOutcome = calloc(1, sizeof(SuccessfulOutcome_t));
50     ResetResponse_IEs_t *resetResponse_ie = calloc(1, sizeof(ResetResponse_IEs_t));
51
52     assert(pdu != 0);
53     assert(successfulOutcome != 0);
54     assert(resetResponse_ie != 0);
55
56     pdu->present = E2AP_PDU_PR_successfulOutcome;
57     pdu->choice.successfulOutcome = successfulOutcome;
58
59     successfulOutcome->procedureCode = ProcedureCode_id_reset;
60     successfulOutcome->criticality = Criticality_reject;
61     successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetResponse;
62     resetResponse = &successfulOutcome->value.choice.ResetResponse;
63
64     resetResponse_ie->id = ProtocolIE_ID_id_CriticalityDiagnostics;
65     resetResponse_ie->criticality = Criticality_ignore;
66     resetResponse_ie->value.present =  ResetResponse_IEs__value_PR_CriticalityDiagnostics;
67
68     ASN_SEQUENCE_ADD(&resetResponse->protocolIEs, resetResponse_ie);
69
70     CriticalityDiagnostics_IE_List_t *critList = calloc(1, sizeof(CriticalityDiagnostics_IE_List_t));
71     assert(critList != 0);
72
73     CriticalityDiagnostics_IE_List__Member *member= calloc(1, sizeof(CriticalityDiagnostics_IE_List__Member));
74     assert(member != 0);
75
76     ASN_SEQUENCE_ADD(critList ,member);
77     ASN_SEQUENCE_ADD(resetResponse_ie->value.choice.CriticalityDiagnostics.iEsCriticalityDiagnostics, critList);
78
79     rc = per_pack_pdu(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf);
80     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
81
82     return rc;
83 }
84