2 ==================================================================================
4 Copyright (c) 2019-2020 AT&T Intellectual Property.
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
10 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
20 * ric_control_request.c
22 * Created on: Jul 11, 2019
23 * Author: sjana, Ashwin Sridharan
26 #include "e2ap_control.hpp"
28 // Set up memory allocations for each IE for encoding
29 // We are responsible for memory management for each IE for encoding
30 // Hence destructor should clear out memory
31 // When decoding, we rely on asn1c macro (ASN_STRUCT_FREE to be called
32 // for releasing memory by external calling function)
33 ric_control_request::ric_control_request(void){
36 e2ap_pdu_obj = (E2AP_PDU_t * )calloc(1, sizeof(E2AP_PDU_t));
37 assert(e2ap_pdu_obj != 0);
40 initMsg = (InitiatingMessage_t * )calloc(1, sizeof(InitiatingMessage_t));
44 IE_array = (RICcontrolRequest_IEs_t *)calloc(NUM_CONTROL_REQUEST_IES, sizeof(RICcontrolRequest_IEs_t));
45 assert(IE_array != 0);
47 e2ap_pdu_obj->present = E2AP_PDU_PR_initiatingMessage;
48 e2ap_pdu_obj->choice.initiatingMessage = initMsg;
54 // Clear assigned protocolIE list from RIC control_request IE container
55 ric_control_request::~ric_control_request(void){
57 mdclog_write(MDCLOG_DEBUG, "Freeing E2AP Control Request object memory");
59 RICcontrolRequest_t *ricControl_Request = &(initMsg->value.choice.RICcontrolRequest);
60 for(int i = 0; i < ricControl_Request->protocolIEs.list.size; i++){
61 ricControl_Request->protocolIEs.list.array[i] = 0;
64 if (ricControl_Request->protocolIEs.list.size > 0){
65 free(ricControl_Request->protocolIEs.list.array);
66 ricControl_Request->protocolIEs.list.size = 0;
67 ricControl_Request->protocolIEs.list.count = 0;
72 e2ap_pdu_obj->choice.initiatingMessage = 0;
74 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, e2ap_pdu_obj);
75 mdclog_write(MDCLOG_DEBUG, "Freed E2AP Control Request object mempory");
80 bool ric_control_request::encode_e2ap_control_request(unsigned char *buf, size_t *size, ric_control_helper & dinput){
82 initMsg->procedureCode = ProcedureCode_id_RICcontrol;
83 initMsg->criticality = Criticality_ignore;
84 initMsg->value.present = InitiatingMessage__value_PR_RICcontrolRequest;
88 res = set_fields(initMsg, dinput);
93 int ret_constr = asn_check_constraints(&asn_DEF_E2AP_PDU, (void *) e2ap_pdu_obj, errbuf, &errbuf_len);
95 error_string.assign(errbuf, errbuf_len);
96 error_string = "Constraints failed for encoding control . Reason = " + error_string;
100 //xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2ap_pdu_obj);
102 asn_enc_rval_t retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, e2ap_pdu_obj, buf, *size);
104 if(retval.encoded == -1){
105 error_string.assign(strerror(errno));
109 if(*size < retval.encoded){
110 std::stringstream ss;
111 ss <<"Error encoding event trigger definition. Reason = encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl;
112 error_string = ss.str();
117 *size = retval.encoded;
122 bool ric_control_request::set_fields(InitiatingMessage_t *initMsg, ric_control_helper &dinput){
123 unsigned int ie_index;
126 error_string = "Invalid reference for E2AP Control_Request message in set_fields";
130 RICcontrolRequest_t * ric_control_request = &(initMsg->value.choice.RICcontrolRequest);
131 ric_control_request->protocolIEs.list.count = 0; // reset
133 // for(i = 0; i < NUM_CONTROL_REQUEST_IES;i++){
134 // memset(&(IE_array[i]), 0, sizeof(RICcontrolRequest_IEs_t));
139 RICcontrolRequest_IEs_t *ies_ricreq = &IE_array[ie_index];
140 ies_ricreq->criticality = Criticality_reject;
141 ies_ricreq->id = ProtocolIE_ID_id_RICrequestID;
142 ies_ricreq->value.present = RICcontrolRequest_IEs__value_PR_RICrequestID;
143 RICrequestID_t *ricrequest_ie = &ies_ricreq->value.choice.RICrequestID;
144 ricrequest_ie->ricRequestorID = dinput.req_id;
145 //ricrequest_ie->ricRequestSequenceNumber = dinput.req_seq_no;
146 ASN_SEQUENCE_ADD(&(ric_control_request->protocolIEs), &(IE_array[ie_index]));
150 RICcontrolRequest_IEs_t *ies_ranfunc = &IE_array[ie_index];
151 ies_ranfunc->criticality = Criticality_reject;
152 ies_ranfunc->id = ProtocolIE_ID_id_RANfunctionID;
153 ies_ranfunc->value.present = RICcontrolRequest_IEs__value_PR_RANfunctionID;
154 RANfunctionID_t *ranfunction_ie = &ies_ranfunc->value.choice.RANfunctionID;
155 *ranfunction_ie = dinput.func_id;
156 ASN_SEQUENCE_ADD(&(ric_control_request->protocolIEs), &(IE_array[ie_index]));
161 RICcontrolRequest_IEs_t *ies_richead = &IE_array[ie_index];
162 ies_richead->criticality = Criticality_reject;
163 ies_richead->id = ProtocolIE_ID_id_RICcontrolHeader;
164 ies_richead->value.present = RICcontrolRequest_IEs__value_PR_RICcontrolHeader;
165 RICcontrolHeader_t *richeader_ie = &ies_richead->value.choice.RICcontrolHeader;
166 richeader_ie->buf = dinput.control_header;
167 richeader_ie->size = dinput.control_header_size;
168 ASN_SEQUENCE_ADD(&(ric_control_request->protocolIEs), &(IE_array[ie_index]));
172 RICcontrolRequest_IEs_t *ies_indmsg = &IE_array[ie_index];
173 ies_indmsg->criticality = Criticality_reject;
174 ies_indmsg->id = ProtocolIE_ID_id_RICcontrolMessage;
175 ies_indmsg->value.present = RICcontrolRequest_IEs__value_PR_RICcontrolMessage;
176 RICcontrolMessage_t *ricmsg_ie = &ies_indmsg->value.choice.RICcontrolMessage;
177 ricmsg_ie->buf = dinput.control_msg;
178 ricmsg_ie->size = dinput.control_msg_size;
179 ASN_SEQUENCE_ADD(&(ric_control_request->protocolIEs), &(IE_array[ie_index]));
183 if (dinput.control_ack >= 0){
184 RICcontrolRequest_IEs_t *ies_indtyp = &IE_array[ie_index];
185 ies_indtyp->criticality = Criticality_reject;
186 ies_indtyp->id = ProtocolIE_ID_id_RICcontrolAckRequest;
187 ies_indtyp->value.present = RICcontrolRequest_IEs__value_PR_RICcontrolAckRequest;
188 RICcontrolAckRequest_t *ricackreq_ie = &ies_indtyp->value.choice.RICcontrolAckRequest;
189 *ricackreq_ie = dinput.control_ack;
190 ASN_SEQUENCE_ADD(&(ric_control_request->protocolIEs), &(IE_array[ie_index]));
195 if(dinput.call_process_id_size > 0){
196 RICcontrolRequest_IEs_t *ies_callprocid = &IE_array[ie_index];
197 ies_callprocid->criticality = Criticality_reject;
198 ies_callprocid->id = ProtocolIE_ID_id_RICcallProcessID;
199 ies_callprocid->value.present = RICcontrolRequest_IEs__value_PR_RICcallProcessID;
200 RICcallProcessID_t *riccallprocessid_ie = &ies_callprocid->value.choice.RICcallProcessID;
201 riccallprocessid_ie->buf = dinput.call_process_id;
202 riccallprocessid_ie->size = dinput.call_process_id_size;
203 ASN_SEQUENCE_ADD(&(ric_control_request->protocolIEs), &(IE_array[ie_index]));
213 bool ric_control_request:: get_fields(InitiatingMessage_t * init_msg, ric_control_helper &dout)
216 error_string = "Invalid reference for E2AP Control_Request message in get_fields";
221 for(int edx = 0; edx < init_msg->value.choice.RICcontrolRequest.protocolIEs.list.count; edx++) {
222 RICcontrolRequest_IEs_t *memb_ptr = init_msg->value.choice.RICcontrolRequest.protocolIEs.list.array[edx];
226 case (ProtocolIE_ID_id_RICcontrolHeader):
227 dout.control_header = memb_ptr->value.choice.RICcontrolHeader.buf;
228 dout.control_header_size = memb_ptr->value.choice.RICcontrolHeader.size;
231 case (ProtocolIE_ID_id_RICcontrolMessage):
232 dout.control_msg = memb_ptr->value.choice.RICcontrolMessage.buf;
233 dout.control_msg_size = memb_ptr->value.choice.RICcontrolMessage.size;
236 case (ProtocolIE_ID_id_RICcallProcessID):
237 dout.call_process_id = memb_ptr->value.choice.RICcallProcessID.buf;
238 dout.call_process_id_size = memb_ptr->value.choice.RICcallProcessID.size;
241 case (ProtocolIE_ID_id_RICrequestID):
242 dout.req_id = memb_ptr->value.choice.RICrequestID.ricRequestorID;
243 //dout.req_seq_no = memb_ptr->value.choice.RICrequestID.ricRequestSequenceNumber;
246 case (ProtocolIE_ID_id_RANfunctionID):
247 dout.func_id = memb_ptr->value.choice.RANfunctionID;
250 case (ProtocolIE_ID_id_RICcontrolAckRequest):
251 dout.control_ack = memb_ptr->value.choice.RICcontrolAckRequest;
264 InitiatingMessage_t * ric_control_request::get_message(void) {