2 ==================================================================================
4 Copyright (c) 2018-2019 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 ==================================================================================
22 * Created on: Jul 11, 2019
23 * Author: sjana, Ashwin Sridharan
26 #include "e2ap_indication.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_indication::ric_indication(void){
36 e2ap_pdu_obj = (E2N_E2AP_PDU_t * )calloc(1, sizeof(E2N_E2AP_PDU_t));
37 assert(e2ap_pdu_obj != 0);
40 initMsg = (E2N_InitiatingMessage_t * )calloc(1, sizeof(E2N_InitiatingMessage_t));
44 IE_array = (E2N_RICindication_IEs_t *)calloc(NUM_INDICATION_IES, sizeof(E2N_RICindication_IEs_t));
45 assert(IE_array != 0);
47 e2ap_pdu_obj->present = E2N_E2AP_PDU_PR_initiatingMessage;
48 e2ap_pdu_obj->choice.initiatingMessage = initMsg;
57 // Clear assigned protocolIE list from RIC indication IE container
58 ric_indication::~ric_indication(void){
60 mdclog_write(MDCLOG_DEBUG, "Freeing E2AP Indication object memory");
61 E2N_RICindication_t *ricIndication = &(initMsg->value.choice.RICindication);
62 for(int i = 0; i < ricIndication->protocolIEs.list.size; i++){
63 ricIndication->protocolIEs.list.array[i] = 0;
65 if (ricIndication->protocolIEs.list.size > 0){
66 free(ricIndication->protocolIEs.list.array);
67 ricIndication->protocolIEs.list.array = 0;
68 ricIndication->protocolIEs.list.count = 0;
69 ricIndication->protocolIEs.list.size = 0;
73 ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_pdu_obj);
74 mdclog_write(MDCLOG_DEBUG, "Freed E2AP Indication object mempory");
78 bool ric_indication::encode_e2ap_indication(unsigned char *buf, size_t *size, ric_indication_helper & dinput){
80 initMsg->procedureCode = E2N_ProcedureCode_id_ricIndication;
81 initMsg->criticality = E2N_Criticality_ignore;
82 initMsg->value.present = E2N_InitiatingMessage__value_PR_RICindication;
85 asn_enc_rval_t retval;
87 res = set_fields(initMsg, dinput);
92 int ret_constr = asn_check_constraints(&asn_DEF_E2N_E2AP_PDU, e2ap_pdu_obj, errbuf, &errbuf_len);
94 error_string.assign(&errbuf[0], errbuf_len);
95 error_string = "Error encoding E2AP Indication message. Reason = " + error_string;
99 // std::cout <<"Constraint check ok ...." << std::endl;
100 // xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2ap_pdu_obj);
102 retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2N_E2AP_PDU, e2ap_pdu_obj, buf, *size);
103 if(retval.encoded == -1){
104 error_string.assign(strerror(errno));
109 if(*size < retval.encoded){
110 std::stringstream ss;
111 ss <<"Error encoding E2AP Indication . Reason = encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl;
112 error_string = ss.str();
117 *size = retval.encoded;
122 bool ric_indication::set_fields(E2N_InitiatingMessage_t *initMsg, ric_indication_helper &dinput){
123 unsigned int ie_index;
126 error_string = "Invalid reference for E2AP Indication message in set_fields";
131 E2N_RICindication_t * ric_indication = &(initMsg->value.choice.RICindication);
132 ric_indication->protocolIEs.list.count = 0;
136 E2N_RICindication_IEs_t *ies_ricreq = &IE_array[ie_index];
137 ies_ricreq->criticality = E2N_Criticality_reject;
138 ies_ricreq->id = E2N_ProtocolIE_ID_id_RICrequestID;
139 ies_ricreq->value.present = E2N_RICindication_IEs__value_PR_RICrequestID;
140 E2N_RICrequestID_t *ricrequest_ie = &ies_ricreq->value.choice.RICrequestID;
141 ricrequest_ie->ricRequestorID = dinput.req_id;
142 ricrequest_ie->ricRequestSequenceNumber = dinput.req_seq_no;
143 ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index]));
146 E2N_RICindication_IEs_t *ies_ranfunc = &IE_array[ie_index];
147 ies_ranfunc->criticality = E2N_Criticality_reject;
148 ies_ranfunc->id = E2N_ProtocolIE_ID_id_RANfunctionID;
149 ies_ranfunc->value.present = E2N_RICindication_IEs__value_PR_RANfunctionID;
150 E2N_RANfunctionID_t *ranfunction_ie = &ies_ranfunc->value.choice.RANfunctionID;
151 *ranfunction_ie = dinput.func_id;
152 ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index]));
155 E2N_RICindication_IEs_t *ies_actid = &IE_array[ie_index];
156 ies_actid->criticality = E2N_Criticality_reject;
157 ies_actid->id = E2N_ProtocolIE_ID_id_RICactionID;
158 ies_actid->value.present = E2N_RICindication_IEs__value_PR_RICactionID;
159 E2N_RICactionID_t *ricaction_ie = &ies_actid->value.choice.RICactionID;
160 *ricaction_ie = dinput.action_id;
161 ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index]));
164 E2N_RICindication_IEs_t *ies_ricsn = &IE_array[ie_index];
165 ies_ricsn->criticality = E2N_Criticality_reject;
166 ies_ricsn->id = E2N_ProtocolIE_ID_id_RICindicationSN;
167 ies_ricsn->value.present = E2N_RICindication_IEs__value_PR_RICindicationSN;
168 E2N_RICindicationSN_t *ricsn_ie = &ies_ricsn->value.choice.RICindicationSN;
169 *ricsn_ie = dinput.indication_sn;
170 ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index]));
174 E2N_RICindication_IEs_t *ies_indtyp = &IE_array[ie_index];
175 ies_indtyp->criticality = E2N_Criticality_reject;
176 ies_indtyp->id = E2N_ProtocolIE_ID_id_RICindicationType;
177 ies_indtyp->value.present = E2N_RICindication_IEs__value_PR_RICindicationType;
178 E2N_RICindicationType_t *rictype_ie = &ies_indtyp->value.choice.RICindicationType;
179 *rictype_ie = dinput.indication_type;
180 ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index]));
183 E2N_RICindication_IEs_t *ies_richead = &IE_array[ie_index];
184 ies_richead->criticality = E2N_Criticality_reject;
185 ies_richead->id = E2N_ProtocolIE_ID_id_RICindicationHeader;
186 ies_richead->value.present = E2N_RICindication_IEs__value_PR_RICindicationHeader;
187 E2N_RICindicationHeader_t *richeader_ie = &ies_richead->value.choice.RICindicationHeader;
188 richeader_ie->buf = dinput.indication_header;
189 richeader_ie->size = dinput.indication_header_size;
190 ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index]));
193 E2N_RICindication_IEs_t *ies_indmsg = &IE_array[ie_index];
194 ies_indmsg->criticality = E2N_Criticality_reject;
195 ies_indmsg->id = E2N_ProtocolIE_ID_id_RICindicationMessage;
196 ies_indmsg->value.present = E2N_RICindication_IEs__value_PR_RICindicationMessage;
197 E2N_RICindicationMessage_t *ricmsg_ie = &ies_indmsg->value.choice.RICindicationMessage;
198 ricmsg_ie->buf = dinput.indication_msg;
199 ricmsg_ie->size = dinput.indication_msg_size;
200 ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index]));
203 // optional call process id ..
204 if (dinput.call_process_id_size > 0){
206 E2N_RICindication_IEs_t *ies_ind_callprocessid = &IE_array[ie_index];
207 ies_ind_callprocessid->criticality = E2N_Criticality_reject;
208 ies_ind_callprocessid->id = E2N_ProtocolIE_ID_id_RICcallProcessID;
209 ies_ind_callprocessid->value.present = E2N_RICindication_IEs__value_PR_RICcallProcessID;
210 E2N_RICcallProcessID_t *riccallprocessid_ie = &ies_ind_callprocessid->value.choice.RICcallProcessID;
211 riccallprocessid_ie->buf = dinput.indication_msg;
212 riccallprocessid_ie->size = dinput.indication_msg_size;
213 ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index]));
223 bool ric_indication:: get_fields(E2N_InitiatingMessage_t * init_msg, ric_indication_helper &dout)
226 error_string = "Invalid reference for E2AP Indication message in get_fields";
231 for(int edx = 0; edx < init_msg->value.choice.RICindication.protocolIEs.list.count; edx++) {
232 E2N_RICindication_IEs_t *memb_ptr = init_msg->value.choice.RICindication.protocolIEs.list.array[edx];
236 case (E2N_ProtocolIE_ID_id_RICindicationHeader):
237 dout.indication_header = memb_ptr->value.choice.RICindicationHeader.buf;
238 dout.indication_header_size = memb_ptr->value.choice.RICindicationHeader.size;
241 case (E2N_ProtocolIE_ID_id_RICindicationMessage):
242 dout.indication_msg = memb_ptr->value.choice.RICindicationMessage.buf;
243 dout.indication_msg_size = memb_ptr->value.choice.RICindicationMessage.size;
246 case (E2N_ProtocolIE_ID_id_RICrequestID):
247 dout.req_id = memb_ptr->value.choice.RICrequestID.ricRequestorID;
248 dout.req_seq_no = memb_ptr->value.choice.RICrequestID.ricRequestSequenceNumber;
251 case (E2N_ProtocolIE_ID_id_RANfunctionID):
252 dout.func_id = memb_ptr->value.choice.RANfunctionID;
255 case (E2N_ProtocolIE_ID_id_RICindicationSN):
256 dout.indication_sn = memb_ptr->value.choice.RICindicationSN;
259 case (E2N_ProtocolIE_ID_id_RICindicationType):
260 dout.indication_type = memb_ptr->value.choice.RICindicationType;
263 case (E2N_ProtocolIE_ID_id_RICactionID):
264 dout.action_id = memb_ptr->value.choice.RICactionID;
267 case (E2N_ProtocolIE_ID_id_RICcallProcessID):
268 dout.call_process_id = memb_ptr->value.choice.RICcallProcessID.buf;
269 dout.call_process_id_size = memb_ptr->value.choice.RICcallProcessID.size;
281 E2N_InitiatingMessage_t * ric_indication::get_message(void) {