4 size_t encode_E2AP_PDU(E2AP_PDU_t* pdu, void* buffer, size_t buf_size)
6 asn_enc_rval_t encode_result;
7 encode_result = aper_encode_to_buffer(&asn_DEF_E2AP_PDU, NULL, pdu, buffer, buf_size);
8 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
9 if(encode_result.encoded == -1) {
10 fprintf(stderr, "Cannot encode %s: %s\n", encode_result.failed_type->name, strerror(errno));
13 return encode_result.encoded;
17 E2AP_PDU_t* decode_E2AP_PDU(const void* buffer, size_t buf_size)
19 asn_dec_rval_t decode_result;
21 decode_result = aper_decode_complete(NULL, &asn_DEF_E2AP_PDU, (void **)&pdu, buffer, buf_size);
22 if(decode_result.code == RC_OK) {
25 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
30 ssize_t e2ap_encode_ric_control_request_message(void *buffer, size_t buf_size, long ricRequestorID, long ricRequestSequenceNumber,
31 long ranFunctionID, void *ricControlHdr, size_t ricControlHdrSize, void *ricControlMsg, size_t ricControlMsgSize)
34 E2AP_PDU_t *init = (E2AP_PDU_t *)calloc(1, sizeof(E2AP_PDU_t));
36 fprintf(stderr, "alloc E2AP_PDU failed\n");
41 InitiatingMessage_t *initiatingMsg = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t));
43 fprintf(stderr, "alloc InitiatingMessage failed\n");
44 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, init);
48 init->choice.initiatingMessage = initiatingMsg;
49 init->present = E2AP_PDU_PR_initiatingMessage;
51 initiatingMsg->procedureCode = ProcedureCode_id_RICcontrol;
52 initiatingMsg->criticality = Criticality_reject;
53 initiatingMsg->value.present = InitiatingMessage__value_PR_RICcontrolRequest;
55 RICcontrolRequest_t *control_request = &initiatingMsg->value.choice.RICcontrolRequest;
59 RICcontrolRequest_IEs_t *controlReqID = (RICcontrolRequest_IEs_t *)calloc(1, sizeof(RICcontrolRequest_IEs_t));
61 fprintf(stderr, "alloc RICrequestID failed\n");
62 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, init);
66 controlReqID->criticality = Criticality_reject;
67 controlReqID->id = ProtocolIE_ID_id_RICrequestID;
69 controlReqID->value.present = RICcontrolRequest_IEs__value_PR_RICrequestID;
70 RICrequestID_t *ricrequest_ie = &controlReqID->value.choice.RICrequestID;
71 ricrequest_ie->ricRequestorID = ricRequestorID;
72 ricrequest_ie->ricInstanceID = ricRequestSequenceNumber;
73 ASN_SEQUENCE_ADD(&control_request->protocolIEs.list, controlReqID);
76 RICcontrolRequest_IEs_t *controlReqFunID = (RICcontrolRequest_IEs_t *)calloc(1, sizeof(RICcontrolRequest_IEs_t));
77 if(!controlReqFunID) {
78 fprintf(stderr, "alloc RICrequestID failed\n");
79 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, init);
83 controlReqFunID->criticality = Criticality_reject;
84 controlReqFunID->id = ProtocolIE_ID_id_RANfunctionID;
85 controlReqFunID->value.present = RICcontrolRequest_IEs__value_PR_RANfunctionID;
86 RANfunctionID_t *ranfunction_ie = &controlReqFunID->value.choice.RANfunctionID;
87 *ranfunction_ie = ranFunctionID;
88 ASN_SEQUENCE_ADD(&control_request->protocolIEs.list, controlReqFunID);
91 RICcontrolRequest_IEs_t *controlReqHdr = (RICcontrolRequest_IEs_t *)calloc(1, sizeof(RICcontrolRequest_IEs_t));
93 fprintf(stderr, "alloc RICcontrolRequest_IEs_t failed\n");
94 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, init);
97 controlReqHdr->criticality = Criticality_reject;
98 controlReqHdr->id = ProtocolIE_ID_id_RICcontrolHeader;
99 controlReqHdr->value.present = RICcontrolRequest_IEs__value_PR_RICcontrolHeader;
100 RICcontrolHeader_t *controlHdr = &controlReqHdr->value.choice.RICcontrolHeader;
101 controlHdr->buf = (uint8_t *)calloc(1, ricControlHdrSize);
102 if(!controlHdr->buf) {
103 fprintf(stderr, "alloc RICcontrolHeader_t buf failed\n");
104 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, init);
108 memcpy(controlHdr->buf, ricControlHdr, ricControlHdrSize);
109 controlHdr->size = ricControlHdrSize;
110 ASN_SEQUENCE_ADD(&control_request->protocolIEs.list, controlReqHdr);
112 //Ric Control Message
113 RICcontrolRequest_IEs_t *controlReqMsg = (RICcontrolRequest_IEs_t *)calloc(1, sizeof(RICcontrolRequest_IEs_t));
115 fprintf(stderr, "alloc RICcontrolRequest_IEs_t failed\n");
116 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, init);
119 controlReqMsg->criticality = Criticality_reject;
120 controlReqMsg->id = ProtocolIE_ID_id_RICcontrolMessage;
121 controlReqMsg->value.present = RICcontrolRequest_IEs__value_PR_RICcontrolMessage;
122 RICcontrolMessage_t *controlMsg = &controlReqMsg->value.choice.RICcontrolMessage;
123 controlMsg->buf = (uint8_t *)calloc(1, ricControlMsgSize);
124 if(!controlMsg->buf) {
125 fprintf(stderr, "alloc RICcontrolMessage_t buf failed\n");
126 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, init);
130 memcpy(controlMsg->buf, ricControlMsg, ricControlMsgSize);
131 controlMsg->size = ricControlMsgSize;
132 ASN_SEQUENCE_ADD(&control_request->protocolIEs.list, controlReqMsg);
134 fprintf(stderr, "showing xer of asn_DEF_E2AP_PDU data\n");
135 xer_fprint(stderr, &asn_DEF_E2AP_PDU, init);
136 fprintf(stderr, "\n");
137 fprintf(stderr, "After xer of asn_DEF_E2AP_PDU data\n");
139 return encode_E2AP_PDU(init, buffer, buf_size);
142 RICControlAcknowledge* e2ap_decode_ric_control_acknowledge_message(void *buffer, size_t buf_size)
144 E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
145 if ( pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome)
147 SuccessfulOutcome_t* successfulOutcome = pdu->choice.successfulOutcome;
148 if ( successfulOutcome->procedureCode == ProcedureCode_id_RICcontrol
149 && successfulOutcome->value.present == SuccessfulOutcome__value_PR_RICcontrolAcknowledge)
151 RICcontrolAcknowledge_t *controlAck = &(successfulOutcome->value.choice.RICcontrolAcknowledge);
152 RICControlAcknowledge *msg = (RICControlAcknowledge *)calloc(1, sizeof(RICControlAcknowledge));
154 for (i; i < controlAck->protocolIEs.list.count; ++i )
156 if(controlAck->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
158 msg->requestorID = controlAck->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestorID;
159 msg->instanceID = controlAck->protocolIEs.list.array[i]->value.choice.RICrequestID.ricInstanceID;
161 else if (controlAck->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RANfunctionID) {
162 msg->ranfunctionID = controlAck->protocolIEs.list.array[i]->value.choice.RANfunctionID;
164 else if(controlAck->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICcallProcessID) {
165 size_t callProcessIDSize = controlAck->protocolIEs.list.array[i]->value.choice.RICcallProcessID.size;
166 msg->callProcessID = calloc(1, callProcessIDSize);
167 if (!msg->callProcessID) {
168 fprintf(stderr, "alloc RICcallProcessID failed\n");
169 e2ap_free_decoded_ric_control_ack(msg);
170 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
174 memcpy(msg->callProcessID, controlAck->protocolIEs.list.array[i]->value.choice.RICcallProcessID.buf, callProcessIDSize);
175 msg->callProcessIDSize = callProcessIDSize;
177 else if(controlAck->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICcontrolOutcome) {
178 size_t ricControlOutComeSize = controlAck->protocolIEs.list.array[i]->value.choice.RICcontrolOutcome.size;
179 msg->ricControlOutCome = calloc(1, ricControlOutComeSize);
180 if (!msg->ricControlOutCome) {
181 fprintf(stderr, "alloc ricControlOutCome failed\n");
182 e2ap_free_decoded_ric_control_ack(msg);
183 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
187 memcpy(msg->ricControlOutCome, controlAck->protocolIEs.list.array[i]->value.choice.RICcontrolOutcome.buf, ricControlOutComeSize);
188 msg->ricControlOutComeSize = ricControlOutComeSize;
192 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
198 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
202 void e2ap_free_decoded_ric_control_ack(RICControlAcknowledge* msg) {
206 if(msg->callProcessID != NULL) {
207 free(msg->callProcessID);
208 msg->callProcessID = NULL;
210 if(msg->ricControlOutCome != NULL) {
211 free(msg->ricControlOutCome);
212 msg->ricControlOutCome = NULL;
218 RICControlFailure* e2ap_decode_ric_control_failure_message(void *buffer, size_t buf_size)
220 E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
221 if ( pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome)
223 UnsuccessfulOutcome_t* unSuccessfulOutcome = pdu->choice.unsuccessfulOutcome;
224 if ( unSuccessfulOutcome->procedureCode == ProcedureCode_id_RICcontrol
225 && unSuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICcontrolFailure)
227 RICcontrolFailure_t *controlFailure = &(unSuccessfulOutcome->value.choice.RICcontrolFailure);
228 RICControlFailure *msg = (RICControlFailure *)calloc(1, sizeof(RICControlFailure));
230 for (i; i < controlFailure->protocolIEs.list.count; ++i )
232 if(controlFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
234 msg->requestorID = controlFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestorID;
235 msg->instanceID = controlFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricInstanceID;
237 else if (controlFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RANfunctionID) {
238 msg->ranfunctionID = controlFailure->protocolIEs.list.array[i]->value.choice.RANfunctionID;
240 else if(controlFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICcallProcessID) {
241 size_t callProcessIDSize = controlFailure->protocolIEs.list.array[i]->value.choice.RICcallProcessID.size;
242 msg->callProcessID = calloc(1, callProcessIDSize);
243 if (!msg->callProcessID) {
244 fprintf(stderr, "alloc RICcallProcessID failed\n");
245 e2ap_free_decoded_ric_control_failure(msg);
246 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
250 memcpy(msg->callProcessID, controlFailure->protocolIEs.list.array[i]->value.choice.RICcallProcessID.buf, callProcessIDSize);
251 msg->callProcessIDSize = callProcessIDSize;
253 else if(controlFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICcontrolOutcome) {
254 msg->causeType = controlFailure->protocolIEs.list.array[i]->value.choice.Cause.present;
255 if (msg->causeType == Cause_PR_ricRequest) {
256 msg->causeValue = controlFailure->protocolIEs.list.array[i]->value.choice.Cause.choice.ricRequest;
257 } else if (msg->causeType == Cause_PR_ricService) {
258 msg->causeValue = controlFailure->protocolIEs.list.array[i]->value.choice.Cause.choice.ricService;
259 } else if (msg->causeType == Cause_PR_transport) {
260 msg->causeValue = controlFailure->protocolIEs.list.array[i]->value.choice.Cause.choice.transport;
261 } else if (msg->causeType == Cause_PR_protocol) {
262 msg->causeValue = controlFailure->protocolIEs.list.array[i]->value.choice.Cause.choice.protocol;
263 } else if (msg->causeType == Cause_PR_misc) {
264 msg->causeValue = controlFailure->protocolIEs.list.array[i]->value.choice.Cause.choice.misc;
266 msg->causeType == Cause_PR_NOTHING;
269 else if(controlFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICcontrolOutcome) {
270 size_t ricControlOutComeSize = controlFailure->protocolIEs.list.array[i]->value.choice.RICcontrolOutcome.size;
271 msg->ricControlOutCome = calloc(1, ricControlOutComeSize);
272 if (!msg->ricControlOutCome) {
273 fprintf(stderr, "alloc ricControlOutCome failed\n");
274 e2ap_free_decoded_ric_control_failure(msg);
275 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
279 memcpy(msg->ricControlOutCome, controlFailure->protocolIEs.list.array[i]->value.choice.RICcontrolOutcome.buf, ricControlOutComeSize);
280 msg->ricControlOutComeSize = ricControlOutComeSize;
285 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
292 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
297 void e2ap_free_decoded_ric_control_failure(RICControlFailure* msg) {
301 if(msg->callProcessID != NULL) {
302 free(msg->callProcessID);
303 msg->callProcessID = NULL;
305 if(msg->ricControlOutCome != NULL) {
306 free(msg->ricControlOutCome);
307 msg->ricControlOutCome = NULL;