blob: f31cd941be11980f0dc39e244f14baac34a35d2d [file] [log] [blame]
kalnagy93cc3e22019-09-19 11:29:29 +02001#include <errno.h>
2#include "wrapper.h"
3
Balint Uvegese9608cd2019-09-20 18:00:32 +00004size_t encode_E2AP_PDU(E2AP_PDU_t* pdu, void* buffer, size_t buf_size)
5{
6 asn_enc_rval_t encode_result;
7 encode_result = aper_encode_to_buffer(&asn_DEF_E2AP_PDU, NULL, pdu, buffer, buf_size);
8 if(encode_result.encoded == -1) {
9 return -1;
10 }
11 return encode_result.encoded;
12}
13
14E2AP_PDU_t* decode_E2AP_PDU(const void* buffer, size_t buf_size)
15{
16 asn_dec_rval_t decode_result;
17 E2AP_PDU_t *pdu = 0;
18 decode_result = aper_decode_complete(NULL, &asn_DEF_E2AP_PDU, (void **)&pdu, buffer, buf_size);
19 if(decode_result.code == RC_OK) {
20 return pdu;
21 } else {
22 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
23 return 0;
24 }
25}
26
kalnagy93cc3e22019-09-19 11:29:29 +020027long e2ap_get_ric_subscription_request_sequence_number(void *buffer, size_t buf_size)
28{
Balint Uvegese9608cd2019-09-20 18:00:32 +000029 E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
30 if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
kalnagy93cc3e22019-09-19 11:29:29 +020031 {
Balint Uvegese9608cd2019-09-20 18:00:32 +000032 InitiatingMessageE2_t* initiatingMessage = pdu->choice.initiatingMessage;
kalnagye0018682019-09-26 16:28:25 +020033 if ( initiatingMessage->procedureCode == ProcedureCode_id_ricSubscription
34 && initiatingMessage->value.present == InitiatingMessageE2__value_PR_RICsubscriptionRequest)
kalnagy93cc3e22019-09-19 11:29:29 +020035 {
kalnagye0018682019-09-26 16:28:25 +020036 RICsubscriptionRequest_t *ric_subscription_request = &(initiatingMessage->value.choice.RICsubscriptionRequest);
37 for (int i = 0; i < ric_subscription_request->protocolIEs.list.count; ++i )
kalnagy93cc3e22019-09-19 11:29:29 +020038 {
kalnagye0018682019-09-26 16:28:25 +020039 if ( ric_subscription_request->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
40 {
41 return ric_subscription_request->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
42 }
kalnagy93cc3e22019-09-19 11:29:29 +020043 }
44 }
45 }
46 return -1;
47}
48
49ssize_t e2ap_set_ric_subscription_request_sequence_number(void *buffer, size_t buf_size, long sequence_number)
50{
Balint Uvegese9608cd2019-09-20 18:00:32 +000051 E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
52 if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
kalnagy93cc3e22019-09-19 11:29:29 +020053 {
Balint Uvegese9608cd2019-09-20 18:00:32 +000054 InitiatingMessageE2_t* initiatingMessage = pdu->choice.initiatingMessage;
kalnagye0018682019-09-26 16:28:25 +020055 if ( initiatingMessage->procedureCode == ProcedureCode_id_ricSubscription
56 && initiatingMessage->value.present == InitiatingMessageE2__value_PR_RICsubscriptionRequest)
kalnagy93cc3e22019-09-19 11:29:29 +020057 {
kalnagye0018682019-09-26 16:28:25 +020058 RICsubscriptionRequest_t *ricSubscriptionRequest = &initiatingMessage->value.choice.RICsubscriptionRequest;
59 for (int i = 0; i < ricSubscriptionRequest->protocolIEs.list.count; ++i )
kalnagy93cc3e22019-09-19 11:29:29 +020060 {
kalnagye0018682019-09-26 16:28:25 +020061 if ( ricSubscriptionRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
62 {
63 ricSubscriptionRequest->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
64 return encode_E2AP_PDU(pdu, buffer, buf_size);
65 }
kalnagy93cc3e22019-09-19 11:29:29 +020066 }
67 }
68 }
69 return -1;
70}
71
72/* RICsubscriptionResponse */
kalnagy93cc3e22019-09-19 11:29:29 +020073long e2ap_get_ric_subscription_response_sequence_number(void *buffer, size_t buf_size)
74{
kalnagye0018682019-09-26 16:28:25 +020075 E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
76 if ( pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome )
kalnagy93cc3e22019-09-19 11:29:29 +020077 {
kalnagye0018682019-09-26 16:28:25 +020078 SuccessfulOutcomeE2_t* successfulOutcome = pdu->choice.successfulOutcome;
79 if ( successfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
80 && successfulOutcome->value.present == SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse)
kalnagy93cc3e22019-09-19 11:29:29 +020081 {
kalnagye0018682019-09-26 16:28:25 +020082 RICsubscriptionResponse_t *ricSubscriptionResponse = &successfulOutcome->value.choice.RICsubscriptionResponse;
83 for (int i = 0; i < ricSubscriptionResponse->protocolIEs.list.count; ++i )
kalnagy93cc3e22019-09-19 11:29:29 +020084 {
kalnagye0018682019-09-26 16:28:25 +020085 if ( ricSubscriptionResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
86 {
87 return ricSubscriptionResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
88 }
kalnagy93cc3e22019-09-19 11:29:29 +020089 }
90 }
91 }
92 return -1;
93}
94
95ssize_t e2ap_set_ric_subscription_response_sequence_number(void *buffer, size_t buf_size, long sequence_number)
96{
kalnagye0018682019-09-26 16:28:25 +020097 E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
98 if ( pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome )
kalnagy93cc3e22019-09-19 11:29:29 +020099 {
kalnagye0018682019-09-26 16:28:25 +0200100 SuccessfulOutcomeE2_t* successfulOutcome = pdu->choice.successfulOutcome;
101 if ( successfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
102 && successfulOutcome->value.present == SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse)
kalnagy93cc3e22019-09-19 11:29:29 +0200103 {
kalnagye0018682019-09-26 16:28:25 +0200104 RICsubscriptionResponse_t *ricSubscriptionResponse = &successfulOutcome->value.choice.RICsubscriptionResponse;
105 for (int i = 0; i < ricSubscriptionResponse->protocolIEs.list.count; ++i )
kalnagy93cc3e22019-09-19 11:29:29 +0200106 {
kalnagye0018682019-09-26 16:28:25 +0200107 if ( ricSubscriptionResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
108 {
109 ricSubscriptionResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
110 return encode_E2AP_PDU(pdu, buffer, buf_size);
111 }
kalnagy93cc3e22019-09-19 11:29:29 +0200112 }
113 }
114 }
115 return -1;
116}
117
118/* RICsubscriptionDeleteRequest */
kalnagy93cc3e22019-09-19 11:29:29 +0200119long e2ap_get_ric_subscription_delete_request_sequence_number(void *buffer, size_t buf_size)
120{
kalnagye0018682019-09-26 16:28:25 +0200121 E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
122 if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage )
kalnagy93cc3e22019-09-19 11:29:29 +0200123 {
kalnagye0018682019-09-26 16:28:25 +0200124 InitiatingMessageE2_t* initiatingMessage = pdu->choice.initiatingMessage;
125 if ( initiatingMessage->procedureCode == ProcedureCode_id_ricSubscriptionDelete
126 && initiatingMessage->value.present == InitiatingMessageE2__value_PR_RICsubscriptionDeleteRequest )
kalnagy93cc3e22019-09-19 11:29:29 +0200127 {
kalnagye0018682019-09-26 16:28:25 +0200128 RICsubscriptionDeleteRequest_t *subscriptionDeleteRequest = &initiatingMessage->value.choice.RICsubscriptionDeleteRequest;
129 for (int i = 0; i < subscriptionDeleteRequest->protocolIEs.list.count; ++i )
kalnagy93cc3e22019-09-19 11:29:29 +0200130 {
kalnagye0018682019-09-26 16:28:25 +0200131 if ( subscriptionDeleteRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
132 {
133 return subscriptionDeleteRequest->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
134 }
kalnagy93cc3e22019-09-19 11:29:29 +0200135 }
136 }
137 }
138 return -1;
139}
140
141ssize_t e2ap_set_ric_subscription_delete_request_sequence_number(void *buffer, size_t buf_size, long sequence_number)
142{
kalnagye0018682019-09-26 16:28:25 +0200143 E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
144 if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage )
kalnagy93cc3e22019-09-19 11:29:29 +0200145 {
kalnagye0018682019-09-26 16:28:25 +0200146 InitiatingMessageE2_t* initiatingMessage = pdu->choice.initiatingMessage;
147 if ( initiatingMessage->procedureCode == ProcedureCode_id_ricSubscriptionDelete
148 && initiatingMessage->value.present == InitiatingMessageE2__value_PR_RICsubscriptionDeleteRequest )
kalnagy93cc3e22019-09-19 11:29:29 +0200149 {
kalnagye0018682019-09-26 16:28:25 +0200150 RICsubscriptionDeleteRequest_t* subscriptionDeleteRequest = &initiatingMessage->value.choice.RICsubscriptionDeleteRequest;
151 for (int i = 0; i < subscriptionDeleteRequest->protocolIEs.list.count; ++i )
kalnagy93cc3e22019-09-19 11:29:29 +0200152 {
kalnagye0018682019-09-26 16:28:25 +0200153 if ( subscriptionDeleteRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
154 {
155 subscriptionDeleteRequest->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
156 return encode_E2AP_PDU(pdu, buffer, buf_size);
157 }
kalnagy93cc3e22019-09-19 11:29:29 +0200158 }
159 }
160 }
161 return -1;
162}
163
164/* RICsubscriptionDeleteResponse */
kalnagy93cc3e22019-09-19 11:29:29 +0200165long e2ap_get_ric_subscription_delete_response_sequence_number(void *buffer, size_t buf_size)
166{
kalnagye0018682019-09-26 16:28:25 +0200167 E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
168 if ( pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome )
kalnagy93cc3e22019-09-19 11:29:29 +0200169 {
kalnagye0018682019-09-26 16:28:25 +0200170 SuccessfulOutcomeE2_t* successfulOutcome = pdu->choice.successfulOutcome;
171 if ( successfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
172 && successfulOutcome->value.present == SuccessfulOutcomeE2__value_PR_RICsubscriptionDeleteResponse )
kalnagy93cc3e22019-09-19 11:29:29 +0200173 {
kalnagye0018682019-09-26 16:28:25 +0200174 RICsubscriptionDeleteResponse_t* subscriptionDeleteResponse = &successfulOutcome->value.choice.RICsubscriptionDeleteResponse;
175 for (int i = 0; i < subscriptionDeleteResponse->protocolIEs.list.count; ++i )
kalnagy93cc3e22019-09-19 11:29:29 +0200176 {
kalnagye0018682019-09-26 16:28:25 +0200177 if ( subscriptionDeleteResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
178 {
179 return subscriptionDeleteResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
180 }
kalnagy93cc3e22019-09-19 11:29:29 +0200181 }
182 }
183 }
184 return -1;
185}
186
187ssize_t e2ap_set_ric_subscription_delete_response_sequence_number(void *buffer, size_t buf_size, long sequence_number)
188{
kalnagye0018682019-09-26 16:28:25 +0200189 E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
190 if ( pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome )
kalnagy93cc3e22019-09-19 11:29:29 +0200191 {
kalnagye0018682019-09-26 16:28:25 +0200192 SuccessfulOutcomeE2_t* successfulOutcome = pdu->choice.successfulOutcome;
193 if ( successfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
194 && successfulOutcome->value.present == SuccessfulOutcomeE2__value_PR_RICsubscriptionDeleteResponse )
kalnagy93cc3e22019-09-19 11:29:29 +0200195 {
kalnagye0018682019-09-26 16:28:25 +0200196 RICsubscriptionDeleteResponse_t* subscriptionDeleteResponse;
197 for (int i = 0; i < subscriptionDeleteResponse->protocolIEs.list.count; ++i )
kalnagy93cc3e22019-09-19 11:29:29 +0200198 {
kalnagye0018682019-09-26 16:28:25 +0200199 if ( subscriptionDeleteResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
200 {
201 subscriptionDeleteResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
202 return encode_E2AP_PDU(pdu, buffer, buf_size);
203 }
kalnagy93cc3e22019-09-19 11:29:29 +0200204 }
205 }
206 }
207 return -1;
208}