X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fe2-interface.git;a=blobdiff_plain;f=e2sim%2Fe2apv1sim%2Fe2sim%2Fsrc%2FX2AP%2Fx2ap_asn_codec.c;fp=e2sim%2Fe2apv1sim%2Fe2sim%2Fsrc%2FX2AP%2Fx2ap_asn_codec.c;h=959e7efd0f4d0470dc8bb3fd95cc2bab560f9848;hp=0000000000000000000000000000000000000000;hb=3ebf932d23dcbec9ed19f4a51f9d00a0a54f5124;hpb=6896318f2b4ff01b4a88b16019c3dc93b0b693f5 diff --git a/e2sim/e2apv1sim/e2sim/src/X2AP/x2ap_asn_codec.c b/e2sim/e2apv1sim/e2sim/src/X2AP/x2ap_asn_codec.c new file mode 100644 index 0000000..959e7ef --- /dev/null +++ b/e2sim/e2apv1sim/e2sim/src/X2AP/x2ap_asn_codec.c @@ -0,0 +1,64 @@ +/* + * + * Copyright 2019 AT&T Intellectual Property + * Copyright 2019 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "x2ap_asn_codec.h" +#include "per_decoder.h" +#include "per_encoder.h" + +/* Encode X2AP PDU ASN1 buffer*/ +int X2AP_ASN_encode(X2AP_PDU_t *pdu, uint8_t **buffer, uint32_t *len) +{ + ssize_t encoded; + + assert(pdu != NULL); + assert(buffer != NULL); + assert(len != NULL); + + encoded = aper_encode_to_new_buffer(&asn_DEF_X2AP_PDU, 0, pdu, (void **)buffer); + + if (encoded < 0) + { + return -1; + } + + *len = encoded; + + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_PDU, pdu); + return encoded; +} + +/* Decode XASN1 buffer to X2AP PDU*/ +int X2AP_ASN_decode(X2AP_PDU_t *pdu, const uint8_t *const buffer, const int len) +{ + asn_dec_rval_t dec_ret; + + assert(buffer != NULL); + + dec_ret = aper_decode(NULL, &asn_DEF_X2AP_PDU, (void **)&pdu, buffer, + len, 0, 0); + + //xer_fprint(stdout, &asn_DEF_X2AP_PDU, pdu); + + if (dec_ret.code != RC_OK) { + fprintf(stderr, "ERROR: Failed to decode pdu\n"); + return -1; + } + + return 0; +}