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