Update release version to 4.4.0
[ric-plt/e2mgr.git] / E2Manager / 3rdparty / asn1codec / src / x2reset_request_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 <ProcedureCode.h>
29 #include <InitiatingMessage.h>
30 #include <ProtocolIE-ID.h>
31 #include <x2reset_request_wrapper.h>
32
33 /*
34  * Build and pack a reset request.
35  * Abort the process on allocation failure.
36  *  packed_buf_size - in: size of packed_buf; out: number of chars used.
37  */
38
39 bool
40 build_pack_x2reset_request(enum Cause_PR cause_group, int cause_value, size_t* packed_buf_size, unsigned char* packed_buf,size_t err_buf_size, char* err_buf)
41 {
42         return build_pack_x2reset_request_aux(cause_group, cause_value, packed_buf_size, packed_buf,err_buf_size,err_buf,ATS_ALIGNED_BASIC_PER);
43
44 }
45
46 bool
47 build_pack_x2reset_request_aux(enum Cause_PR cause_group, int cause_value, size_t* packed_buf_size, unsigned char* packed_buf,size_t err_buf_size, char* err_buf,enum asn_transfer_syntax syntax)
48 {
49         bool rc = true;
50         E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
51         InitiatingMessage_t *initiatingMessage = calloc(1, sizeof(InitiatingMessage_t));
52         ResetRequest_t   *resetRequest;
53
54     assert(pdu != 0);
55     assert(initiatingMessage != 0);
56
57
58     pdu->present = E2AP_PDU_PR_initiatingMessage;
59     pdu->choice.initiatingMessage = initiatingMessage;
60
61     initiatingMessage->procedureCode = ProcedureCode_id_reset;
62     initiatingMessage->criticality = Criticality_reject;
63     initiatingMessage->value.present = InitiatingMessage__value_PR_ResetRequest;
64     resetRequest = &initiatingMessage->value.choice.ResetRequest;
65
66     ResetRequest_IEs_t *cause_ie = calloc(1, sizeof(ResetRequest_IEs_t));
67     assert(cause_ie != 0);
68     ASN_SEQUENCE_ADD(&resetRequest->protocolIEs, cause_ie);
69
70     cause_ie->id = ProtocolIE_ID_id_Cause;
71     cause_ie->criticality = Criticality_ignore;
72     cause_ie->value.present = ResetRequest_IEs__value_PR_Cause;
73     Cause_t *cause = &cause_ie->value.choice.Cause;
74     cause->present = cause_group;
75     switch (cause->present) {
76     case Cause_PR_radioNetwork:
77         cause->choice.radioNetwork = cause_value;
78         break;
79     case Cause_PR_transport:
80         cause->choice.transport = cause_value;
81         break;
82     case Cause_PR_protocol:
83         cause->choice.protocol = cause_value;
84         break;
85     case Cause_PR_misc:
86         cause->choice.misc = cause_value;
87         break;
88     default:
89         cause->choice.misc = CauseMisc_om_intervention;
90         break;
91     }
92
93     rc = pack_pdu_aux(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf,syntax);
94
95     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
96     return rc;
97 }
98