kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 1 | #include <errno.h> |
| 2 | #include "wrapper.h" |
| 3 | |
Balint Uveges | e9608cd | 2019-09-20 18:00:32 +0000 | [diff] [blame^] | 4 | size_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 | |
| 14 | E2AP_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 | |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 27 | ssize_t encode_RIC_subscription_request(RICsubscriptionRequest_t* pdu, void* buffer, size_t buf_size) |
| 28 | { |
| 29 | asn_enc_rval_t encode_result; |
| 30 | encode_result = aper_encode_to_buffer(&asn_DEF_RICsubscriptionRequest, NULL, pdu, buffer, buf_size); |
| 31 | if(encode_result.encoded == -1) { |
| 32 | return -1; |
| 33 | } |
| 34 | return encode_result.encoded; |
| 35 | } |
| 36 | |
| 37 | RICsubscriptionRequest_t* decode_RIC_subscription_request(const void *buffer, size_t buf_size) |
| 38 | { |
| 39 | asn_dec_rval_t decode_result; |
| 40 | RICsubscriptionRequest_t *pdu = 0; |
| 41 | decode_result = aper_decode_complete(NULL, &asn_DEF_RICsubscriptionRequest, (void **)&pdu, buffer, buf_size); |
| 42 | if(decode_result.code == RC_OK) { |
| 43 | return pdu; |
| 44 | } else { |
| 45 | ASN_STRUCT_FREE(asn_DEF_RICsubscriptionRequest, pdu); |
| 46 | return 0; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | long e2ap_get_ric_subscription_request_sequence_number(void *buffer, size_t buf_size) |
| 51 | { |
Balint Uveges | e9608cd | 2019-09-20 18:00:32 +0000 | [diff] [blame^] | 52 | E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size); |
| 53 | if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 54 | { |
Balint Uveges | e9608cd | 2019-09-20 18:00:32 +0000 | [diff] [blame^] | 55 | InitiatingMessageE2_t* initiatingMessage = pdu->choice.initiatingMessage; |
| 56 | RICsubscriptionRequest_t *ric_subscription_request = &(initiatingMessage->value.choice.RICsubscriptionRequest); |
| 57 | for (int i = 0; i < ric_subscription_request->protocolIEs.list.count; ++i ) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 58 | { |
Balint Uveges | e9608cd | 2019-09-20 18:00:32 +0000 | [diff] [blame^] | 59 | if ( ric_subscription_request->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID ) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 60 | { |
Balint Uveges | e9608cd | 2019-09-20 18:00:32 +0000 | [diff] [blame^] | 61 | return ric_subscription_request->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber; |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | } |
| 65 | return -1; |
| 66 | } |
| 67 | |
| 68 | ssize_t e2ap_set_ric_subscription_request_sequence_number(void *buffer, size_t buf_size, long sequence_number) |
| 69 | { |
Balint Uveges | e9608cd | 2019-09-20 18:00:32 +0000 | [diff] [blame^] | 70 | E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size); |
| 71 | if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 72 | { |
Balint Uveges | e9608cd | 2019-09-20 18:00:32 +0000 | [diff] [blame^] | 73 | InitiatingMessageE2_t* initiatingMessage = pdu->choice.initiatingMessage; |
| 74 | RICsubscriptionRequest_t *ric_subscription_request = &(initiatingMessage->value.choice.RICsubscriptionRequest); |
| 75 | for (int i = 0; i < ric_subscription_request->protocolIEs.list.count; ++i ) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 76 | { |
Balint Uveges | e9608cd | 2019-09-20 18:00:32 +0000 | [diff] [blame^] | 77 | if ( ric_subscription_request->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID ) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 78 | { |
Balint Uveges | e9608cd | 2019-09-20 18:00:32 +0000 | [diff] [blame^] | 79 | ric_subscription_request->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number; |
| 80 | return encode_E2AP_PDU(pdu, buffer, buf_size); |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | } |
| 84 | return -1; |
| 85 | } |
| 86 | |
| 87 | /* RICsubscriptionResponse */ |
| 88 | ssize_t encode_RIC_subscription_response(RICsubscriptionResponse_t* pdu, void* buffer, size_t buf_size) |
| 89 | { |
| 90 | asn_enc_rval_t encode_result; |
| 91 | encode_result = aper_encode_to_buffer(&asn_DEF_RICsubscriptionResponse, NULL, pdu, buffer, buf_size); |
| 92 | if(encode_result.encoded == -1) { |
| 93 | return -1; |
| 94 | } |
| 95 | return encode_result.encoded; |
| 96 | } |
| 97 | |
| 98 | RICsubscriptionResponse_t* decode_RIC_subscription_response(const void *buffer, size_t buf_size) |
| 99 | { |
| 100 | asn_dec_rval_t decode_result; |
| 101 | RICsubscriptionResponse_t *pdu = 0; |
| 102 | decode_result = aper_decode_complete(NULL, &asn_DEF_RICsubscriptionResponse, (void **)&pdu, buffer, buf_size); |
| 103 | if(decode_result.code == RC_OK) { |
| 104 | fprintf(stdout, "decoded bytes: %ld\n", decode_result.consumed); |
| 105 | return pdu; |
| 106 | } else { |
| 107 | ASN_STRUCT_FREE(asn_DEF_RICsubscriptionResponse, pdu); |
| 108 | return 0; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | long e2ap_get_ric_subscription_response_sequence_number(void *buffer, size_t buf_size) |
| 113 | { |
| 114 | RICsubscriptionResponse_t *pdu = decode_RIC_subscription_response(buffer, buf_size); |
| 115 | if ( pdu != NULL ) |
| 116 | { |
| 117 | for (int i = 0; i < pdu->protocolIEs.list.count; ++i ) |
| 118 | { |
| 119 | if ( pdu->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID ) |
| 120 | { |
| 121 | return pdu->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber; |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | return -1; |
| 126 | } |
| 127 | |
| 128 | ssize_t e2ap_set_ric_subscription_response_sequence_number(void *buffer, size_t buf_size, long sequence_number) |
| 129 | { |
| 130 | RICsubscriptionResponse_t *pdu = decode_RIC_subscription_response(buffer, buf_size); |
| 131 | if ( pdu != NULL ) |
| 132 | { |
| 133 | for (int i = 0; i < pdu->protocolIEs.list.count; ++i ) |
| 134 | { |
| 135 | if ( pdu->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID ) |
| 136 | { |
| 137 | pdu->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number; |
| 138 | return encode_RIC_subscription_response(pdu, buffer, buf_size); |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | return -1; |
| 143 | } |
| 144 | |
| 145 | /* RICsubscriptionDeleteRequest */ |
| 146 | ssize_t encode_RIC_subscription_delete_request(RICsubscriptionDeleteRequest_t* pdu, void* buffer, size_t buf_size) |
| 147 | { |
| 148 | asn_enc_rval_t encode_result; |
| 149 | encode_result = aper_encode_to_buffer(&asn_DEF_RICsubscriptionDeleteRequest, NULL, pdu, buffer, buf_size); |
| 150 | if(encode_result.encoded == -1) { |
| 151 | return -1; |
| 152 | } |
| 153 | return encode_result.encoded; |
| 154 | } |
| 155 | |
| 156 | RICsubscriptionDeleteRequest_t* decode_RIC_subscription_delete_request(const void *buffer, size_t buf_size) |
| 157 | { |
| 158 | asn_dec_rval_t decode_result; |
| 159 | RICsubscriptionDeleteRequest_t *pdu = 0; |
| 160 | decode_result = aper_decode_complete(NULL, &asn_DEF_RICsubscriptionDeleteRequest, (void **)&pdu, buffer, buf_size); |
| 161 | if(decode_result.code == RC_OK) { |
Balint Uveges | e9608cd | 2019-09-20 18:00:32 +0000 | [diff] [blame^] | 162 | fprintf(stdout, "decoded bytes: %ld\n", decode_result.consumed); |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 163 | return pdu; |
| 164 | } else { |
| 165 | ASN_STRUCT_FREE(asn_DEF_RICsubscriptionDeleteRequest, pdu); |
| 166 | return 0; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | long e2ap_get_ric_subscription_delete_request_sequence_number(void *buffer, size_t buf_size) |
| 171 | { |
| 172 | RICsubscriptionDeleteRequest_t *pdu = decode_RIC_subscription_delete_request(buffer, buf_size); |
| 173 | if ( pdu != NULL ) |
| 174 | { |
| 175 | for (int i = 0; i < pdu->protocolIEs.list.count; ++i ) |
| 176 | { |
| 177 | /* TODO */ |
| 178 | if ( pdu->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID ) |
| 179 | { |
| 180 | return pdu->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber; |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | return -1; |
| 185 | } |
| 186 | |
| 187 | ssize_t e2ap_set_ric_subscription_delete_request_sequence_number(void *buffer, size_t buf_size, long sequence_number) |
| 188 | { |
| 189 | RICsubscriptionDeleteRequest_t *pdu = decode_RIC_subscription_delete_request(buffer, buf_size); |
| 190 | if ( pdu != NULL ) |
| 191 | { |
| 192 | for (int i = 0; i < pdu->protocolIEs.list.count; ++i ) |
| 193 | { |
| 194 | /* TODO */ |
| 195 | if ( pdu->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID ) |
| 196 | { |
| 197 | pdu->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number; |
| 198 | return encode_RIC_subscription_delete_request(pdu, buffer, buf_size); |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | return -1; |
| 203 | } |
| 204 | |
| 205 | /* RICsubscriptionDeleteResponse */ |
| 206 | ssize_t encode_RIC_subscription_delete_response(RICsubscriptionDeleteResponse_t* pdu, void* buffer, size_t buf_size) |
| 207 | { |
| 208 | asn_enc_rval_t encode_result; |
| 209 | encode_result = aper_encode_to_buffer(&asn_DEF_RICsubscriptionDeleteResponse, NULL, pdu, buffer, buf_size); |
| 210 | if(encode_result.encoded == -1) { |
| 211 | return -1; |
| 212 | } |
| 213 | return encode_result.encoded; |
| 214 | } |
| 215 | |
| 216 | RICsubscriptionDeleteResponse_t* decode_RIC_subscription_delete_response(const void *buffer, size_t buf_size) |
| 217 | { |
| 218 | asn_dec_rval_t decode_result; |
| 219 | RICsubscriptionDeleteResponse_t *pdu = 0; |
| 220 | decode_result = aper_decode_complete(NULL, &asn_DEF_RICsubscriptionDeleteResponse, (void **)&pdu, buffer, buf_size); |
| 221 | if(decode_result.code == RC_OK) { |
| 222 | fprintf(stdout, "decoded bytes: %ld\n", decode_result.consumed); |
| 223 | return pdu; |
| 224 | } else { |
| 225 | ASN_STRUCT_FREE(asn_DEF_RICsubscriptionDeleteResponse, pdu); |
| 226 | return 0; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | long e2ap_get_ric_subscription_delete_response_sequence_number(void *buffer, size_t buf_size) |
| 231 | { |
| 232 | RICsubscriptionDeleteResponse_t *pdu = decode_RIC_subscription_delete_response(buffer, buf_size); |
| 233 | if ( pdu != NULL ) |
| 234 | { |
| 235 | for (int i = 0; i < pdu->protocolIEs.list.count; ++i ) |
| 236 | { |
| 237 | if ( pdu->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID ) |
| 238 | { |
| 239 | /* TODO */ |
| 240 | return pdu->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber; |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | return -1; |
| 245 | } |
| 246 | |
| 247 | ssize_t e2ap_set_ric_subscription_delete_response_sequence_number(void *buffer, size_t buf_size, long sequence_number) |
| 248 | { |
| 249 | RICsubscriptionDeleteResponse_t *pdu = decode_RIC_subscription_delete_response(buffer, buf_size); |
| 250 | if ( pdu != NULL ) |
| 251 | { |
| 252 | for (int i = 0; i < pdu->protocolIEs.list.count; ++i ) |
| 253 | { |
| 254 | if ( pdu->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID ) |
| 255 | { |
| 256 | /* todo */ |
| 257 | pdu->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number; |
| 258 | return encode_RIC_subscription_delete_response(pdu, buffer, buf_size); |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | return -1; |
| 263 | } |