E2AP changes Part2 00/3000/4
authorbalajihands <balaji.shankaran@radisys.com>
Thu, 26 Mar 2020 17:03:36 +0000 (22:33 +0530)
committerBalaji Shankaran <balaji.shankaran@radisys.com>
Fri, 3 Apr 2020 13:07:47 +0000 (18:37 +0530)
Change-Id: Iab427035f1fef6cd77d2e4a5f0066b54faab20a2
Signed-off-by: balajihands <balaji.shankaran@radisys.com>
Signed-off-by: Balaji Shankaran <balaji.shankaran@radisys.com>
41 files changed:
Dockerfile
Dockerfile-cu-stub
Dockerfile-ric-stub
build/common/asn_e2ap.mak
build/common/e2ap.mak [deleted file]
build/odu/makefile
src/codec_utils/E2AP/BIT_STRING.c [deleted file]
src/codec_utils/E2AP/BIT_STRING.h [deleted file]
src/codec_utils/E2AP/BIT_STRING_oer.c [deleted file]
src/codec_utils/E2AP/OCTET_STRING.c [deleted file]
src/codec_utils/E2AP/OCTET_STRING.h [deleted file]
src/codec_utils/E2AP/OCTET_STRING_oer.c [deleted file]
src/codec_utils/E2AP/per_encoder.c [deleted file]
src/codec_utils/F1AP/ANY.c [deleted file]
src/codec_utils/F1AP/ANY.h [deleted file]
src/codec_utils/common/ANY.c [moved from src/codec_utils/E2AP/ANY.c with 100% similarity]
src/codec_utils/common/ANY.h [moved from src/codec_utils/E2AP/ANY.h with 100% similarity]
src/codec_utils/common/OCTET_STRING.c [changed mode: 0755->0644]
src/codec_utils/common/asn_internal.h
src/codec_utils/common/odu_common_codec.c [new file with mode: 0644]
src/codec_utils/common/odu_common_codec.h
src/cu_stub/cu_f1ap_msg_hdl.c
src/cu_stub/cu_f1ap_msg_hdl.h
src/cu_stub/cu_stub.h
src/cu_stub/cu_stub_sctp.c
src/cu_stub/cu_stub_sctp.h
src/du_app/du_cell_mgr.h
src/du_app/du_cfg.h
src/du_app/du_e2ap_msg_hdl.c
src/du_app/du_f1ap_msg_hdl.c
src/du_app/du_mgr.h
src/du_app/du_mgr_ex_ms.c
src/du_app/du_msg_hdl.c
src/du_app/du_sctp.c
src/du_app/du_sctp.h
src/ric_stub/ric_e2ap_msg_hdl.c
src/ric_stub/ric_e2ap_msg_hdl.h
src/ric_stub/ric_stub.c
src/ric_stub/ric_stub.h
src/ric_stub/ric_stub_sctp.c
src/ric_stub/ric_stub_sctp.h

index 5e11f7c..738b44f 100644 (file)
@@ -1,4 +1,4 @@
-FROM nexus3.o-ran-sc.org:10004/bldr-ubuntu16-c-go:3-u16.04-nng as ubuntu
+FROM nexus3.o-ran-sc.org:10004/bldr-ubuntu18-c-go:6-u18.04-nng as ubuntu
 
 ADD . /opt/o-du-l2
 WORKDIR /opt/o-du-l2
index 8fb9f97..afefba0 100644 (file)
@@ -1,4 +1,4 @@
-FROM nexus3.o-ran-sc.org:10004/bldr-ubuntu16-c-go:3-u16.04-nng as ubuntu
+FROM nexus3.o-ran-sc.org:10004/bldr-ubuntu18-c-go:6-u18.04-nng as ubuntu
 
 ADD . /opt/o-du-l2
 WORKDIR /opt/o-du-l2
index e9d3511..dbc3818 100644 (file)
@@ -1,4 +1,4 @@
-FROM nexus3.o-ran-sc.org:10004/bldr-ubuntu16-c-go:3-u16.04-nng as ubuntu
+FROM nexus3.o-ran-sc.org:10004/bldr-ubuntu18-c-go:6-u18.04-nng as ubuntu
 
 ADD . /opt/o-du-l2
 WORKDIR /opt/o-du-l2
index 47087fd..8096c2a 100644 (file)
@@ -23,9 +23,6 @@ COLOR=$(COLOR_RED)
 SRC_DIR=$(ROOT_DIR)/src/codec_utils/E2AP
 C_SRCS=$(wildcard $(SRC_DIR)/*.c)
 C_OBJS=$(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(C_SRCS))
-LOG_FILES=$(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.i,$(C_SRCS))
-BAK_FILES=$(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.i.bak,$(C_SRCS))
-DB_FILES =$(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.i.db,$(C_SRCS))
 
 lib: $(LIB_DIR)/libasn_e2ap.a
 include $(COM_BUILD_DIR)/compile.mak
@@ -47,3 +44,7 @@ clean:
                  @echo $(SRC_DIR) $(CM_DIR)
                  $(Q)\rm -f $(LIB_DIR)/libasn_e2ap.a $(C_OBJS) $(C_WO_PED_OBJS) $(LOG_FILES) $(BAK_FILES)
 
+#-------------------------------------------------------------#
+#End of File
+#-------------------------------------------------------------#
+
diff --git a/build/common/e2ap.mak b/build/common/e2ap.mak
deleted file mode 100644 (file)
index 967d9b8..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-################################################################################
-#   Copyright (c) [2017-2019] [Radisys]                                        #
-#                                                                              #
-#   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.                                             #
-################################################################################
-
-# This is makefile for E2 APP
-
-include ../common/rsys_fancy.mak
-include ../common/env.mak
-COLOR=$(COLOR_RED)
-
-SRC_DIR=$(ROOT_DIR)/src/du_app/E2AP
-C_SRCS=$(wildcard $(SRC_DIR)/*.c)
-C_OBJS=$(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(C_SRCS))
-LOG_FILES=$(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.i,$(C_SRCS))
-BAK_FILES=$(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.i.bak,$(C_SRCS))
-DB_FILES =$(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.i.db,$(C_SRCS))
-
-# prepare the list of common header files
-HDR_FILES+=$(wildcard $(CM_DIR)/env*.[hx])
-HDR_FILES+=$(wildcard $(CM_DIR)/gen*.[hx])
-HDR_FILES+=$(wildcard $(CM_DIR)/ssi*.[hx])
-HDR_FILES+=$(wildcard $(CM_DIR)/cm*.[hx])
-HDR_FILES+=$(wildcard $(CM_DIR)/lkw*.[hx])
-HDR_FILES+=$(wildcard $(CM_DIR)/lrg*.[hx])
-
-
-lib: $(LIB_DIR)/libe2ap.a
-include $(COM_BUILD_DIR)/compile.mak
-
-I_OPTS+=-I$(ROOT_DIR)/src/mt
-I_OPTS+=-I$(ROOT_DIR)/src/du_app
-I_OPTS+=-I$(ROOT_DIR)/src/ric_stub #TODO: Remove this dependency
-I_OPTS+=-I$(ROOT_DIR)/src/du_app/E2AP/asn
-
-
-#-------------------------------------------------------------#
-#Linker macros
-#-------------------------------------------------------------#
-$(LIB_DIR)/libf1ap.a:$(C_OBJS) $(C_WO_PED_OBJS)
-                 @echo -e "Creating Archive $(COLOR) $@ $(REVERT_COLOR)"
-                 $(Q)ar -cr $(LIB_DIR)/libf1ap.a $(C_OBJS) $(C_WO_PED_OBJS)
-
-#-------------------------------------------------------------#
-#Clean macros
-#-------------------------------------------------------------#
-clean:
-                 @echo -e "$(COLOR_RED)Cleaning F1AP$(REVERT_COLOR)"
-                 @echo $(SRC_DIR) $(CM_DIR)
-                 $(Q)\rm -f $(LIB_DIR)/libf1ap.a $(C_OBJS) $(C_WO_PED_OBJS) $(LOG_FILES) $(BAK_FILES)
-
index 2588625..279ee02 100644 (file)
@@ -227,7 +227,6 @@ ric:
         $(Q)$(MAKE) -f $(COM_BUILD_DIR)/ric_stub.mak OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)'
         $(Q)$(MAKE) -f $(COM_BUILD_DIR)/asn_common.mak OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)'
         $(Q)$(MAKE) -f $(COM_BUILD_DIR)/asn_e2ap.mak OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)'
-        $(Q)$(MAKE) -f $(COM_BUILD_DIR)/asn_sysinfo.mak OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)'
         $(Q)$(MAKE) -f $(COM_BUILD_DIR)/cm.mak OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)'
         $(Q)$(MAKE) -f $(COM_BUILD_DIR)/mt.mak OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)'
 
diff --git a/src/codec_utils/E2AP/BIT_STRING.c b/src/codec_utils/E2AP/BIT_STRING.c
deleted file mode 100644 (file)
index e8d7354..0000000
+++ /dev/null
@@ -1,656 +0,0 @@
-/*-
- * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
- * Redistribution and modifications are permitted subject to BSD license.
- */
-#include <asn_internal.h>
-#include <BIT_STRING.h>
-#include <asn_internal.h>
-
-/*
- * BIT STRING basic type description.
- */
-static const ber_tlv_tag_t asn_DEF_BIT_STRING_tags[] = {
-       (ASN_TAG_CLASS_UNIVERSAL | (3 << 2))
-};
-asn_OCTET_STRING_specifics_t asn_SPC_BIT_STRING_specs = {
-       sizeof(BIT_STRING_t),
-       offsetof(BIT_STRING_t, _asn_ctx),
-       ASN_OSUBV_BIT
-};
-asn_TYPE_operation_t asn_OP_BIT_STRING = {
-       OCTET_STRING_free,         /* Implemented in terms of OCTET STRING */
-       BIT_STRING_print,
-       BIT_STRING_compare,
-       OCTET_STRING_decode_ber,   /* Implemented in terms of OCTET STRING */
-       OCTET_STRING_encode_der,   /* Implemented in terms of OCTET STRING */
-       OCTET_STRING_decode_xer_binary,
-       BIT_STRING_encode_xer,
-#ifdef ASN_DISABLE_OER_SUPPORT
-       0,
-       0,
-#else
-       BIT_STRING_decode_oer,
-       BIT_STRING_encode_oer,
-#endif  /* ASN_DISABLE_OER_SUPPORT */
-#ifdef ASN_DISABLE_PER_SUPPORT
-       0,
-       0,
-       0,
-       0,
-#else
-       BIT_STRING_decode_uper, /* Unaligned PER decoder */
-       BIT_STRING_encode_uper, /* Unaligned PER encoder */
-       OCTET_STRING_decode_aper,       /* Aligned PER decoder */
-       OCTET_STRING_encode_aper,       /* Aligned PER encoder */
-#endif  /* ASN_DISABLE_PER_SUPPORT */
-       BIT_STRING_random_fill,
-       0       /* Use generic outmost tag fetcher */
-};
-asn_TYPE_descriptor_t asn_DEF_BIT_STRING = {
-       "BIT STRING",
-       "BIT_STRING",
-       &asn_OP_BIT_STRING,
-       asn_DEF_BIT_STRING_tags,
-       sizeof(asn_DEF_BIT_STRING_tags)
-         / sizeof(asn_DEF_BIT_STRING_tags[0]),
-       asn_DEF_BIT_STRING_tags,        /* Same as above */
-       sizeof(asn_DEF_BIT_STRING_tags)
-         / sizeof(asn_DEF_BIT_STRING_tags[0]),
-       { 0, 0, BIT_STRING_constraint },
-       0, 0,   /* No members */
-       &asn_SPC_BIT_STRING_specs
-};
-
-/*
- * BIT STRING generic constraint.
- */
-int
-BIT_STRING_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
-                      asn_app_constraint_failed_f *ctfailcb, void *app_key) {
-    const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
-
-       if(st && st->buf) {
-               if((st->size == 0 && st->bits_unused)
-               || st->bits_unused < 0 || st->bits_unused > 7) {
-                       ASN__CTFAIL(app_key, td, sptr,
-                               "%s: invalid padding byte (%s:%d)",
-                               td->name, __FILE__, __LINE__);
-                       return -1;
-               }
-       } else {
-               ASN__CTFAIL(app_key, td, sptr,
-                       "%s: value not given (%s:%d)",
-                       td->name, __FILE__, __LINE__);
-               return -1;
-       }
-
-       return 0;
-}
-
-static const char *_bit_pattern[16] = {
-       "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
-       "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"
-};
-
-asn_enc_rval_t
-BIT_STRING_encode_xer(const asn_TYPE_descriptor_t *td, const void *sptr,
-                      int ilevel, enum xer_encoder_flags_e flags,
-                      asn_app_consume_bytes_f *cb, void *app_key) {
-       asn_enc_rval_t er = {0, 0, 0};
-       char scratch[128];
-       char *p = scratch;
-       char *scend = scratch + (sizeof(scratch) - 10);
-       const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
-       int xcan = (flags & XER_F_CANONICAL);
-       uint8_t *buf;
-       uint8_t *end;
-
-       if(!st || !st->buf)
-               ASN__ENCODE_FAILED;
-
-       er.encoded = 0;
-
-       buf = st->buf;
-       end = buf + st->size - 1;       /* Last byte is special */
-
-       /*
-        * Binary dump
-        */
-       for(; buf < end; buf++) {
-               int v = *buf;
-               int nline = xcan?0:(((buf - st->buf) % 8) == 0);
-               if(p >= scend || nline) {
-                       ASN__CALLBACK(scratch, p - scratch);
-                       p = scratch;
-                       if(nline) ASN__TEXT_INDENT(1, ilevel);
-               }
-               memcpy(p + 0, _bit_pattern[v >> 4], 4);
-               memcpy(p + 4, _bit_pattern[v & 0x0f], 4);
-               p += 8;
-       }
-
-       if(!xcan && ((buf - st->buf) % 8) == 0)
-               ASN__TEXT_INDENT(1, ilevel);
-       ASN__CALLBACK(scratch, p - scratch);
-       p = scratch;
-
-       if(buf == end) {
-               int v = *buf;
-               int ubits = st->bits_unused;
-               int i;
-               for(i = 7; i >= ubits; i--)
-                       *p++ = (v & (1 << i)) ? 0x31 : 0x30;
-               ASN__CALLBACK(scratch, p - scratch);
-       }
-
-       if(!xcan) ASN__TEXT_INDENT(1, ilevel - 1);
-
-       ASN__ENCODED_OK(er);
-cb_failed:
-       ASN__ENCODE_FAILED;
-}
-
-
-/*
- * BIT STRING specific contents printer.
- */
-int
-BIT_STRING_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
-                 asn_app_consume_bytes_f *cb, void *app_key) {
-    const char * const h2c = "0123456789ABCDEF";
-       char scratch[64];
-       const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
-       uint8_t *buf;
-       uint8_t *end;
-       char *p = scratch;
-
-       (void)td;       /* Unused argument */
-
-       if(!st || !st->buf)
-               return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
-
-       ilevel++;
-       buf = st->buf;
-       end = buf + st->size;
-
-       /*
-        * Hexadecimal dump.
-        */
-       for(; buf < end; buf++) {
-               if((buf - st->buf) % 16 == 0 && (st->size > 16)
-                               && buf != st->buf) {
-                       _i_INDENT(1);
-                       /* Dump the string */
-                       if(cb(scratch, p - scratch, app_key) < 0) return -1;
-                       p = scratch;
-               }
-               *p++ = h2c[*buf >> 4];
-               *p++ = h2c[*buf & 0x0F];
-               *p++ = 0x20;
-       }
-
-       if(p > scratch) {
-               p--;    /* Eat the tailing space */
-
-               if((st->size > 16)) {
-                       _i_INDENT(1);
-               }
-
-               /* Dump the incomplete 16-bytes row */
-               if(cb(scratch, p - scratch, app_key) < 0)
-                       return -1;
-       }
-
-    if(st->bits_unused) {
-        int ret = snprintf(scratch, sizeof(scratch), " (%d bit%s unused)",
-                           st->bits_unused, st->bits_unused == 1 ? "" : "s");
-        assert(ret > 0 && ret < (ssize_t)sizeof(scratch));
-        if(ret > 0 && ret < (ssize_t)sizeof(scratch)
-           && cb(scratch, ret, app_key) < 0)
-            return -1;
-    }
-
-       return 0;
-}
-
-/*
- * Non-destructively remove the trailing 0-bits from the given bit string.
- */
-static const BIT_STRING_t *
-BIT_STRING__compactify(const BIT_STRING_t *st, BIT_STRING_t *tmp) {
-    const uint8_t *b;
-    union {
-        const uint8_t *c_buf;
-        uint8_t *nc_buf;
-    } unconst;
-
-    if(st->size == 0) {
-        assert(st->bits_unused == 0);
-        return st;
-    } else {
-        for(b = &st->buf[st->size - 1]; b > st->buf && *b == 0; b--) {
-            ;
-        }
-        /* b points to the last byte which may contain data */
-        if(*b) {
-            int unused = 7;
-            uint8_t v = *b;
-            v &= -(int8_t)v;
-            if(v & 0x0F) unused -= 4;
-            if(v & 0x33) unused -= 2;
-            if(v & 0x55) unused -= 1;
-            tmp->size = b-st->buf + 1;
-            tmp->bits_unused = unused;
-        } else {
-            tmp->size = b-st->buf;
-            tmp->bits_unused = 0;
-        }
-
-        assert(b >= st->buf);
-    }
-
-    unconst.c_buf = st->buf;
-    tmp->buf = unconst.nc_buf;
-    return tmp;
-}
-
-/*
- * Lexicographically compare the common prefix of both strings,
- * and if it is the same return -1 for the smallest string.
- */
-int
-BIT_STRING_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
-                   const void *bptr) {
-    /*
-     * Remove information about trailing bits, since
-     * X.680 (08/2015) #22.7 "ensure that different semantics are not"
-     * "associated with [values that differ only in] the trailing 0 bits."
-     */
-    BIT_STRING_t compact_a, compact_b;
-    const BIT_STRING_t *a = BIT_STRING__compactify(aptr, &compact_a);
-    const BIT_STRING_t *b = BIT_STRING__compactify(bptr, &compact_b);
-    const asn_OCTET_STRING_specifics_t *specs = td->specifics;
-
-    assert(specs && specs->subvariant == ASN_OSUBV_BIT);
-
-    if(a && b) {
-        size_t common_prefix_size = a->size <= b->size ? a->size : b->size;
-        int ret = memcmp(a->buf, b->buf, common_prefix_size);
-        if(ret == 0) {
-            /* Figure out which string with equal prefixes is longer. */
-            if(a->size < b->size) {
-                return -1;
-            } else if(a->size > b->size) {
-                return 1;
-            } else {
-                /* Figure out how many unused bits */
-                if(a->bits_unused > b->bits_unused) {
-                    return -1;
-                } else if(a->bits_unused < b->bits_unused) {
-                    return 1;
-                } else {
-                    return 0;
-                }
-            }
-        } else {
-            return ret;
-        }
-    } else if(!a && !b) {
-        return 0;
-    } else if(!a) {
-        return -1;
-    } else {
-        return 1;
-    }
-}
-
-#ifndef  ASN_DISABLE_PER_SUPPORT
-
-#undef  RETURN
-#define RETURN(_code)                       \
-    do {                                    \
-        asn_dec_rval_t tmprval;             \
-        tmprval.code = _code;               \
-        tmprval.consumed = consumed_myself; \
-        return tmprval;                     \
-    } while(0)
-
-static asn_per_constraint_t asn_DEF_BIT_STRING_constraint_size = {
-    APC_SEMI_CONSTRAINED, -1, -1, 0, 0};
-
-asn_dec_rval_t
-BIT_STRING_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
-                       const asn_TYPE_descriptor_t *td,
-                       const asn_per_constraints_t *constraints, void **sptr,
-                       asn_per_data_t *pd) {
-    const asn_OCTET_STRING_specifics_t *specs = td->specifics
-               ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-               : &asn_SPC_BIT_STRING_specs;
-    const asn_per_constraints_t *pc =
-        constraints ? constraints : td->encoding_constraints.per_constraints;
-       const asn_per_constraint_t *csiz;
-       asn_dec_rval_t rval = { RC_OK, 0 };
-       BIT_STRING_t *st = (BIT_STRING_t *)*sptr;
-       ssize_t consumed_myself = 0;
-       int repeat;
-
-       (void)opt_codec_ctx;
-
-       if(pc) {
-               csiz = &pc->size;
-       } else {
-               csiz = &asn_DEF_BIT_STRING_constraint_size;
-       }
-
-       if(specs->subvariant != ASN_OSUBV_BIT) {
-               ASN_DEBUG("Subvariant %d is not BIT OSUBV_BIT", specs->subvariant);
-               RETURN(RC_FAIL);
-    }
-
-       /*
-        * Allocate the string.
-        */
-       if(!st) {
-               st = (BIT_STRING_t *)(*sptr = CALLOC(1, specs->struct_size));
-               if(!st) RETURN(RC_FAIL);
-       }
-
-       ASN_DEBUG("PER Decoding %s size %ld .. %ld bits %d",
-               csiz->flags & APC_EXTENSIBLE ? "extensible" : "non-extensible",
-               csiz->lower_bound, csiz->upper_bound, csiz->effective_bits);
-
-       if(csiz->flags & APC_EXTENSIBLE) {
-               int inext = per_get_few_bits(pd, 1);
-               if(inext < 0) RETURN(RC_WMORE);
-               if(inext) {
-                       csiz = &asn_DEF_BIT_STRING_constraint_size;
-               }
-       }
-
-       if(csiz->effective_bits >= 0) {
-               FREEMEM(st->buf);
-        st->size = (csiz->upper_bound + 7) >> 3;
-        st->buf = (uint8_t *)MALLOC(st->size + 1);
-               if(!st->buf) { st->size = 0; RETURN(RC_FAIL); }
-       }
-
-       /* X.691, #16.5: zero-length encoding */
-       /* X.691, #16.6: short fixed length encoding (up to 2 octets) */
-       /* X.691, #16.7: long fixed length encoding (up to 64K octets) */
-       if(csiz->effective_bits == 0) {
-               int ret;
-        ASN_DEBUG("Encoding BIT STRING size %ld", csiz->upper_bound);
-        ret = per_get_many_bits(pd, st->buf, 0, csiz->upper_bound);
-               if(ret < 0) RETURN(RC_WMORE);
-               consumed_myself += csiz->upper_bound;
-               st->buf[st->size] = 0;
-        st->bits_unused = (8 - (csiz->upper_bound & 0x7)) & 0x7;
-        RETURN(RC_OK);
-       }
-
-       st->size = 0;
-       do {
-               ssize_t raw_len;
-               ssize_t len_bytes;
-               ssize_t len_bits;
-               void *p;
-               int ret;
-
-               /* Get the PER length */
-               raw_len = uper_get_length(pd, csiz->effective_bits, csiz->lower_bound,
-                                         &repeat);
-               if(raw_len < 0) RETURN(RC_WMORE);
-        if(raw_len == 0 && st->buf) break;
-
-               ASN_DEBUG("Got PER length eb %ld, len %ld, %s (%s)",
-                       (long)csiz->effective_bits, (long)raw_len,
-                       repeat ? "repeat" : "once", td->name);
-        len_bits = raw_len;
-        len_bytes = (len_bits + 7) >> 3;
-        if(len_bits & 0x7) st->bits_unused = 8 - (len_bits & 0x7);
-        /* len_bits be multiple of 16K if repeat is set */
-        p = REALLOC(st->buf, st->size + len_bytes + 1);
-               if(!p) RETURN(RC_FAIL);
-               st->buf = (uint8_t *)p;
-
-        ret = per_get_many_bits(pd, &st->buf[st->size], 0, len_bits);
-        if(ret < 0) RETURN(RC_WMORE);
-               st->size += len_bytes;
-       } while(repeat);
-       st->buf[st->size] = 0;  /* nul-terminate */
-
-       return rval;
-}
-
-asn_enc_rval_t
-BIT_STRING_encode_uper(const asn_TYPE_descriptor_t *td,
-                       const asn_per_constraints_t *constraints,
-                       const void *sptr, asn_per_outp_t *po) {
-    const asn_OCTET_STRING_specifics_t *specs =
-        td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-                      : &asn_SPC_BIT_STRING_specs;
-    const asn_per_constraints_t *pc =
-        constraints ? constraints : td->encoding_constraints.per_constraints;
-       const asn_per_constraint_t *csiz;
-       const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
-       BIT_STRING_t compact_bstr;  /* Do not modify this directly! */
-       asn_enc_rval_t er = { 0, 0, 0 };
-       int inext = 0;          /* Lies not within extension root */
-       size_t size_in_bits;
-       const uint8_t *buf;
-       int ret;
-       int ct_extensible;
-
-       if(!st || (!st->buf && st->size))
-               ASN__ENCODE_FAILED;
-
-       if(specs->subvariant == ASN_OSUBV_BIT) {
-        if((st->size == 0 && st->bits_unused) || (st->bits_unused & ~7))
-            ASN__ENCODE_FAILED;
-    } else {
-               ASN__ENCODE_FAILED;
-    }
-
-       if(pc) {
-        csiz = &pc->size;
-    } else {
-               csiz = &asn_DEF_BIT_STRING_constraint_size;
-       }
-       ct_extensible = csiz->flags & APC_EXTENSIBLE;
-
-    /* Figure out the size without the trailing bits */
-    st = BIT_STRING__compactify(st, &compact_bstr);
-    size_in_bits = 8 * st->size - st->bits_unused;
-
-    ASN_DEBUG(
-        "Encoding %s into %" ASN_PRI_SIZE " bits"
-        " (%ld..%ld, effective %d)%s",
-        td->name, size_in_bits, csiz->lower_bound, csiz->upper_bound,
-        csiz->effective_bits, ct_extensible ? " EXT" : "");
-
-    /* Figure out whether size lies within PER visible constraint */
-
-    if(csiz->effective_bits >= 0) {
-        if((ssize_t)size_in_bits > csiz->upper_bound) {
-            if(ct_extensible) {
-                csiz = &asn_DEF_BIT_STRING_constraint_size;
-                inext = 1;
-            } else {
-                ASN__ENCODE_FAILED;
-            }
-        }
-    } else {
-        inext = 0;
-    }
-
-    if(ct_extensible) {
-               /* Declare whether length is [not] within extension root */
-               if(per_put_few_bits(po, inext, 1))
-                       ASN__ENCODE_FAILED;
-       }
-
-    if(csiz->effective_bits >= 0 && !inext) {
-        int add_trailer = (ssize_t)size_in_bits < csiz->lower_bound;
-        ASN_DEBUG(
-            "Encoding %" ASN_PRI_SIZE " bytes (%ld), length (in %d bits) trailer %d; actual "
-            "value %" ASN_PRI_SSIZE "",
-            st->size, size_in_bits - csiz->lower_bound, csiz->effective_bits,
-            add_trailer,
-            add_trailer ? 0 : (ssize_t)size_in_bits - csiz->lower_bound);
-        ret = per_put_few_bits(
-            po, add_trailer ? 0 : (ssize_t)size_in_bits - csiz->lower_bound,
-            csiz->effective_bits);
-        if(ret) ASN__ENCODE_FAILED;
-        ret = per_put_many_bits(po, st->buf, size_in_bits);
-        if(ret) ASN__ENCODE_FAILED;
-        if(add_trailer) {
-            static const uint8_t zeros[16];
-            size_t trailing_zero_bits = csiz->lower_bound - size_in_bits;
-            while(trailing_zero_bits > 0) {
-                if(trailing_zero_bits > 8 * sizeof(zeros)) {
-                    ret = per_put_many_bits(po, zeros, 8 * sizeof(zeros));
-                    trailing_zero_bits -= 8 * sizeof(zeros);
-                } else {
-                    ret = per_put_many_bits(po, zeros, trailing_zero_bits);
-                    trailing_zero_bits = 0;
-                }
-                if(ret) ASN__ENCODE_FAILED;
-            }
-        }
-        ASN__ENCODED_OK(er);
-    }
-
-    ASN_DEBUG("Encoding %" ASN_PRI_SIZE " bytes", st->size);
-
-    buf = st->buf;
-    do {
-        int need_eom = 0;
-        ssize_t maySave = uper_put_length(po, size_in_bits, &need_eom);
-        if(maySave < 0) ASN__ENCODE_FAILED;
-
-        ASN_DEBUG("Encoding %" ASN_PRI_SSIZE " of %" ASN_PRI_SIZE "", maySave, size_in_bits);
-
-        ret = per_put_many_bits(po, buf, maySave);
-        if(ret) ASN__ENCODE_FAILED;
-
-        buf += maySave >> 3;
-        size_in_bits -= maySave;
-        assert(!(maySave & 0x07) || !size_in_bits);
-        if(need_eom && uper_put_length(po, 0, 0))
-            ASN__ENCODE_FAILED; /* End of Message length */
-    } while(size_in_bits);
-
-    ASN__ENCODED_OK(er);
-}
-
-#endif  /* ASN_DISABLE_PER_SUPPORT */
-
-asn_random_fill_result_t
-BIT_STRING_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
-                       const asn_encoding_constraints_t *constraints,
-                       size_t max_length) {
-    const asn_OCTET_STRING_specifics_t *specs =
-        td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-                      : &asn_SPC_BIT_STRING_specs;
-    asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
-    asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
-    asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
-    static unsigned lengths[] = {0,     1,     2,     3,     4,     8,
-                                 126,   127,   128,   16383, 16384, 16385,
-                                 65534, 65535, 65536, 65537};
-    uint8_t *buf;
-    uint8_t *bend;
-    uint8_t *b;
-    size_t rnd_bits, rnd_len;
-    BIT_STRING_t *st;
-
-    if(max_length == 0) return result_skipped;
-
-    switch(specs->subvariant) {
-    case ASN_OSUBV_ANY:
-        return result_failed;
-    case ASN_OSUBV_BIT:
-        break;
-    default:
-        break;
-    }
-
-    /* Figure out how far we should go */
-    rnd_bits = lengths[asn_random_between(
-        0, sizeof(lengths) / sizeof(lengths[0]) - 1)];
-    if(!constraints || !constraints->per_constraints)
-        constraints = &td->encoding_constraints;
-    if(constraints->per_constraints) {
-        const asn_per_constraint_t *pc = &constraints->per_constraints->size;
-        if(pc->flags & APC_CONSTRAINED) {
-            long suggested_upper_bound = pc->upper_bound < (ssize_t)max_length
-                                             ? pc->upper_bound
-                                             : (ssize_t)max_length;
-            if(max_length < (size_t)pc->lower_bound) {
-                return result_skipped;
-            }
-            if(pc->flags & APC_EXTENSIBLE) {
-                switch(asn_random_between(0, 5)) {
-                case 0:
-                    if(pc->lower_bound > 0) {
-                        rnd_bits = pc->lower_bound - 1;
-                        break;
-                    }
-                    /* Fall through */
-                case 1:
-                    rnd_bits = pc->upper_bound + 1;
-                    break;
-                case 2:
-                    /* Keep rnd_bits from the table */
-                    if(rnd_bits < max_length) {
-                        break;
-                    }
-                    /* Fall through */
-                default:
-                    rnd_bits = asn_random_between(pc->lower_bound,
-                                                  suggested_upper_bound);
-                }
-            } else {
-                rnd_bits =
-                    asn_random_between(pc->lower_bound, suggested_upper_bound);
-            }
-        } else {
-            rnd_bits = asn_random_between(0, max_length - 1);
-        }
-    } else if(rnd_bits >= max_length) {
-        rnd_bits = asn_random_between(0, max_length - 1);
-    }
-
-    rnd_len = (rnd_bits + 7) / 8;
-    buf = CALLOC(1, rnd_len + 1);
-    if(!buf) return result_failed;
-
-    bend = &buf[rnd_len];
-
-    for(b = buf; b < bend; b++) {
-        *(uint8_t *)b = asn_random_between(0, 255);
-    }
-    *b = 0; /* Zero-terminate just in case. */
-
-    if(*sptr) {
-        st = *sptr;
-        FREEMEM(st->buf);
-    } else {
-        st = (BIT_STRING_t *)(*sptr = CALLOC(1, specs->struct_size));
-        if(!st) {
-            FREEMEM(buf);
-            return result_failed;
-        }
-    }
-
-    st->buf = buf;
-    st->size = rnd_len;
-    st->bits_unused = (8 - (rnd_bits & 0x7)) & 0x7;
-    if(st->bits_unused) {
-        assert(st->size > 0);
-        st->buf[st->size-1] &= 0xff << st->bits_unused;
-    }
-
-    result_ok.length = st->size;
-    return result_ok;
-}
diff --git a/src/codec_utils/E2AP/BIT_STRING.h b/src/codec_utils/E2AP/BIT_STRING.h
deleted file mode 100644 (file)
index c1bdbbc..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
- * Redistribution and modifications are permitted subject to BSD license.
- */
-#ifndef        _BIT_STRING_H_
-#define        _BIT_STRING_H_
-
-#include <OCTET_STRING.h>      /* Some help from OCTET STRING */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct BIT_STRING_s {
-       uint8_t *buf;   /* BIT STRING body */
-       size_t size;    /* Size of the above buffer */
-
-       int bits_unused;/* Unused trailing bits in the last octet (0..7) */
-
-       asn_struct_ctx_t _asn_ctx;      /* Parsing across buffer boundaries */
-} BIT_STRING_t;
-
-extern asn_TYPE_descriptor_t asn_DEF_BIT_STRING;
-extern asn_TYPE_operation_t asn_OP_BIT_STRING;
-extern asn_OCTET_STRING_specifics_t asn_SPC_BIT_STRING_specs;
-
-asn_struct_print_f BIT_STRING_print;   /* Human-readable output */
-asn_struct_compare_f BIT_STRING_compare;
-asn_constr_check_f BIT_STRING_constraint;
-xer_type_encoder_f BIT_STRING_encode_xer;
-oer_type_decoder_f BIT_STRING_decode_oer;
-oer_type_encoder_f BIT_STRING_encode_oer;
-per_type_decoder_f BIT_STRING_decode_uper;
-per_type_encoder_f BIT_STRING_encode_uper;
-asn_random_fill_f  BIT_STRING_random_fill;
-
-#define BIT_STRING_free              OCTET_STRING_free
-#define BIT_STRING_decode_ber        OCTET_STRING_decode_ber
-#define BIT_STRING_encode_der        OCTET_STRING_encode_der
-#define BIT_STRING_decode_xer        OCTET_STRING_decode_xer_binary
-#define BIT_STRING_decode_aper       OCTET_STRING_decode_aper
-#define BIT_STRING_encode_aper       OCTET_STRING_encode_aper
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _BIT_STRING_H_ */
diff --git a/src/codec_utils/E2AP/BIT_STRING_oer.c b/src/codec_utils/E2AP/BIT_STRING_oer.c
deleted file mode 100644 (file)
index aff5075..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
- * All rights reserved.
- * Redistribution and modifications are permitted subject to BSD license.
- */
-#ifndef ASN_DISABLE_OER_SUPPORT
-
-#include <asn_internal.h>
-#include <BIT_STRING.h>
-#include <errno.h>
-
-asn_dec_rval_t
-BIT_STRING_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
-                      const asn_TYPE_descriptor_t *td,
-                      const asn_oer_constraints_t *constraints, void **sptr,
-                      const void *ptr, size_t size) {
-    BIT_STRING_t *st = (BIT_STRING_t *)*sptr;
-    const asn_oer_constraints_t *cts =
-        constraints ? constraints : td->encoding_constraints.oer_constraints;
-    ssize_t ct_size = cts ? cts->size : -1;
-    asn_dec_rval_t rval = {RC_OK, 0};
-    size_t expected_length = 0;
-
-    (void)opt_codec_ctx;
-
-    if(!st) {
-        st = (BIT_STRING_t *)(*sptr = CALLOC(1, sizeof(*st)));
-        if(!st) ASN__DECODE_FAILED;
-    }
-
-    if(ct_size >= 0) {
-        expected_length = (ct_size + 7) >> 3;
-        st->bits_unused = (8 - (ct_size & 7)) & 7;
-    } else {
-        /*
-         * X.696 (08/2015) #13.3.1
-         * Encode length determinant as _number of octets_, but only
-         * if upper bound is not equal to lower bound.
-         */
-        ssize_t len_len = oer_fetch_length(ptr, size, &expected_length);
-        if(len_len > 0) {
-            ptr = (const char *)ptr + len_len;
-            size -= len_len;
-        } else if(len_len == 0) {
-            ASN__DECODE_STARVED;
-        } else if(len_len < 0) {
-            ASN__DECODE_FAILED;
-        }
-
-        if(expected_length < 1) {
-            ASN__DECODE_FAILED;
-        } else if(expected_length > size) {
-            ASN__DECODE_STARVED;
-        }
-
-        st->bits_unused = ((const uint8_t *)ptr)[0];
-        if(st->bits_unused & ~7) {
-            ASN_DEBUG("%s: unused bits outside of 0..7 range", td->name);
-            ASN__DECODE_FAILED;
-        }
-        ptr = (const char *)ptr + 1;
-        size--;
-        expected_length--;
-        rval.consumed = len_len + 1;
-    }
-
-    if(size < expected_length) {
-        ASN__DECODE_STARVED;
-    } else {
-        uint8_t *buf = MALLOC(expected_length + 1);
-        if(buf == NULL) {
-            ASN__DECODE_FAILED;
-        } else {
-            memcpy(buf, ptr, expected_length);
-            buf[expected_length] = '\0';
-        }
-        FREEMEM(st->buf);
-        st->buf = buf;
-        st->size = expected_length;
-        if(expected_length > 0) {
-            buf[expected_length - 1] &= (0xff << st->bits_unused);
-        }
-
-        rval.consumed += expected_length;
-        return rval;
-    }
-}
-
-/*
- * Encode as Canonical OER.
- */
-asn_enc_rval_t
-BIT_STRING_encode_oer(const asn_TYPE_descriptor_t *td,
-                      const asn_oer_constraints_t *constraints,
-                      const void *sptr, asn_app_consume_bytes_f *cb,
-                      void *app_key) {
-    const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
-    asn_enc_rval_t erval = {0, 0, 0};
-    const asn_oer_constraints_t *cts =
-        constraints ? constraints : td->encoding_constraints.oer_constraints;
-    ssize_t ct_size = cts ? cts->size : -1;
-    size_t trailing_zeros = 0;
-    int fix_last_byte = 0;
-
-    if(!st) ASN__ENCODE_FAILED;
-
-    if(st->bits_unused & ~7) {
-        ASN_DEBUG("BIT STRING unused bits %d out of 0..7 range",
-                  st->bits_unused);
-        ASN__ENCODE_FAILED;
-    }
-    if(st->bits_unused && !(st->size && st->buf)) {
-        ASN_DEBUG("BIT STRING %s size 0 can't support unused bits %d", td->name,
-                  st->bits_unused);
-        ASN__ENCODE_FAILED;
-    }
-
-    if(ct_size >= 0) {
-        size_t ct_bytes = (ct_size + 7) >> 3;
-        if(st->size > ct_bytes) {
-            ASN_DEBUG("More bits in BIT STRING %s (%" ASN_PRI_SSIZE ") than constrained %" ASN_PRI_SSIZE "",
-                      td->name, 8 * st->size - st->bits_unused, ct_size);
-            ASN__ENCODE_FAILED;
-        }
-        trailing_zeros = ct_bytes - st->size;   /* Allow larger constraint */
-    } else {
-        uint8_t ub = st->bits_unused & 7;
-        ssize_t len_len = oer_serialize_length(1 + st->size, cb, app_key);
-        if(len_len < 0) ASN__ENCODE_FAILED;
-        if(cb(&ub, 1, app_key) < 0) {
-            ASN__ENCODE_FAILED;
-        }
-        erval.encoded += len_len + 1;
-    }
-
-    if(st->bits_unused) {
-        if(st->buf[st->size - 1] & (0xff << st->bits_unused)) {
-            fix_last_byte = 1;
-        }
-    }
-
-    if(cb(st->buf, st->size - fix_last_byte, app_key) < 0) {
-        ASN__ENCODE_FAILED;
-    }
-
-    if(fix_last_byte) {
-        uint8_t b = st->buf[st->size - 1] & (0xff << st->bits_unused);
-        if(cb(&b, 1, app_key) < 0) {
-            ASN__ENCODE_FAILED;
-        }
-    }
-
-    erval.encoded += st->size;
-
-    if(trailing_zeros) {
-        static uint8_t zeros[16];
-        while(trailing_zeros > 0) {
-            int ret;
-            if(trailing_zeros < sizeof(zeros)) {
-                ret = cb(zeros, trailing_zeros, app_key);
-                erval.encoded += trailing_zeros;
-            } else {
-                ret = cb(zeros, sizeof(zeros), app_key);
-                erval.encoded += sizeof(zeros);
-            }
-            if(ret < 0) ASN__ENCODE_FAILED;
-        }
-    }
-
-    return erval;
-}
-
-
-#endif  /* ASN_DISABLE_OER_SUPPORT */
diff --git a/src/codec_utils/E2AP/OCTET_STRING.c b/src/codec_utils/E2AP/OCTET_STRING.c
deleted file mode 100644 (file)
index ae34c96..0000000
+++ /dev/null
@@ -1,2411 +0,0 @@
-/*-
- * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>.
- * All rights reserved.
- * Redistribution and modifications are permitted subject to BSD license.
- */
-#include <asn_internal.h>
-#include <OCTET_STRING.h>
-#include <BIT_STRING.h>        /* for .bits_unused member */
-#include <errno.h>
-
-/*
- * OCTET STRING basic type description.
- */
-static const ber_tlv_tag_t asn_DEF_OCTET_STRING_tags[] = {
-       (ASN_TAG_CLASS_UNIVERSAL | (4 << 2))
-};
-asn_OCTET_STRING_specifics_t asn_SPC_OCTET_STRING_specs = {
-       sizeof(OCTET_STRING_t),
-       offsetof(OCTET_STRING_t, _asn_ctx),
-       ASN_OSUBV_STR
-};
-
-asn_TYPE_operation_t asn_OP_OCTET_STRING = {
-       OCTET_STRING_free,
-       OCTET_STRING_print,     /* OCTET STRING generally means a non-ascii sequence */
-       OCTET_STRING_compare,
-       OCTET_STRING_decode_ber,
-       OCTET_STRING_encode_der,
-       OCTET_STRING_decode_xer_hex,
-       OCTET_STRING_encode_xer,
-#ifdef ASN_DISABLE_OER_SUPPORT
-       0,
-       0,
-#else
-       OCTET_STRING_decode_oer,
-       OCTET_STRING_encode_oer,
-#endif  /* ASN_DISABLE_OER_SUPPORT */
-#ifdef ASN_DISABLE_PER_SUPPORT
-       0,
-       0,
-       0,
-       0,
-#else
-       OCTET_STRING_decode_uper,       /* Unaligned PER decoder */
-       OCTET_STRING_encode_uper,       /* Unaligned PER encoder */
-       OCTET_STRING_decode_aper,       /* Aligned PER decoder */
-       OCTET_STRING_encode_aper,       /* Aligned PER encoder */
-#endif /* ASN_DISABLE_PER_SUPPORT */
-       OCTET_STRING_random_fill,
-       0       /* Use generic outmost tag fetcher */
-};
-asn_TYPE_descriptor_t asn_DEF_OCTET_STRING = {
-       "OCTET STRING",         /* Canonical name */
-       "OCTET_STRING",         /* XML tag name */
-       &asn_OP_OCTET_STRING,
-       asn_DEF_OCTET_STRING_tags,
-       sizeof(asn_DEF_OCTET_STRING_tags)
-         / sizeof(asn_DEF_OCTET_STRING_tags[0]),
-       asn_DEF_OCTET_STRING_tags,      /* Same as above */
-       sizeof(asn_DEF_OCTET_STRING_tags)
-         / sizeof(asn_DEF_OCTET_STRING_tags[0]),
-       { 0, 0, asn_generic_no_constraint },
-       0, 0,   /* No members */
-       &asn_SPC_OCTET_STRING_specs
-};
-
-#undef _CH_PHASE
-#undef NEXT_PHASE
-#undef PREV_PHASE
-#define        _CH_PHASE(ctx, inc) do {                                        \
-               if(ctx->phase == 0)                                     \
-                       ctx->context = 0;                               \
-               ctx->phase += inc;                                      \
-       } while(0)
-#define        NEXT_PHASE(ctx) _CH_PHASE(ctx, +1)
-#define        PREV_PHASE(ctx) _CH_PHASE(ctx, -1)
-
-#undef ADVANCE
-#define        ADVANCE(num_bytes)      do {                                    \
-               size_t num = (num_bytes);                               \
-               buf_ptr = ((const char *)buf_ptr) + num;                \
-               size -= num;                                            \
-               consumed_myself += num;                                 \
-       } while(0)
-
-#undef RETURN
-#define        RETURN(_code)   do {                                            \
-               asn_dec_rval_t tmprval;                                 \
-               tmprval.code = _code;                                   \
-               tmprval.consumed = consumed_myself;                     \
-               return tmprval;                                         \
-       } while(0)
-
-#undef APPEND
-#define        APPEND(bufptr, bufsize) do {                                    \
-               size_t _bs = (bufsize);         /* Append size */       \
-               size_t _ns = ctx->context;      /* Allocated now */     \
-               size_t _es = st->size + _bs;    /* Expected size */     \
-               /* int is really a typeof(st->size): */                 \
-               if((int)_es < 0) RETURN(RC_FAIL);                       \
-               if(_ns <= _es) {                                        \
-                       void *ptr;                                      \
-                       /* Be nice and round to the memory allocator */ \
-                       do { _ns = _ns ? _ns << 1 : 16; }               \
-                           while(_ns <= _es);                          \
-                       /* int is really a typeof(st->size): */         \
-                       if((int)_ns < 0) RETURN(RC_FAIL);               \
-                       ptr = REALLOC(st->buf, _ns);                    \
-                       if(ptr) {                                       \
-                               st->buf = (uint8_t *)ptr;               \
-                               ctx->context = _ns;                     \
-                       } else {                                        \
-                               RETURN(RC_FAIL);                        \
-                       }                                               \
-                       ASN_DEBUG("Reallocating into %ld", (long)_ns);  \
-               }                                                       \
-               memcpy(st->buf + st->size, bufptr, _bs);                \
-               /* Convenient nul-termination */                        \
-               st->buf[_es] = '\0';                                    \
-               st->size = _es;                                         \
-       } while(0)
-
-/*
- * The main reason why ASN.1 is still alive is that too much time and effort
- * is necessary for learning it more or less adequately, thus creating a gut
- * necessity to demonstrate that aquired skill everywhere afterwards.
- * No, I am not going to explain what the following stuff is.
- */
-struct _stack_el {
-    ber_tlv_len_t left;     /* What's left to read (or -1) */
-    ber_tlv_len_t got;      /* What was actually processed */
-    unsigned cont_level;    /* Depth of subcontainment */
-    int want_nulls;         /* Want null "end of content" octets? */
-    int bits_chopped;       /* Flag in BIT STRING mode */
-    ber_tlv_tag_t tag;      /* For debugging purposes */
-    struct _stack_el *prev;
-    struct _stack_el *next;
-};
-struct _stack {
-       struct _stack_el *tail;
-       struct _stack_el *cur_ptr;
-};
-
-static struct _stack_el *
-OS__add_stack_el(struct _stack *st) {
-       struct _stack_el *nel;
-
-       /*
-        * Reuse the old stack frame or allocate a new one.
-        */
-       if(st->cur_ptr && st->cur_ptr->next) {
-               nel = st->cur_ptr->next;
-               nel->bits_chopped = 0;
-               nel->got = 0;
-               /* Retain the nel->cont_level, it's correct. */
-       } else {
-               nel = (struct _stack_el *)CALLOC(1, sizeof(struct _stack_el));
-               if(nel == NULL)
-                       return NULL;
-
-               if(st->tail) {
-                       /* Increase a subcontainment depth */
-                       nel->cont_level = st->tail->cont_level + 1;
-                       st->tail->next = nel;
-               }
-               nel->prev = st->tail;
-               st->tail = nel;
-       }
-
-       st->cur_ptr = nel;
-
-       return nel;
-}
-
-static struct _stack *
-_new_stack(void) {
-       return (struct _stack *)CALLOC(1, sizeof(struct _stack));
-}
-
-/*
- * Decode OCTET STRING type.
- */
-asn_dec_rval_t
-OCTET_STRING_decode_ber(const asn_codec_ctx_t *opt_codec_ctx,
-                        const asn_TYPE_descriptor_t *td, void **sptr,
-                        const void *buf_ptr, size_t size, int tag_mode) {
-    const asn_OCTET_STRING_specifics_t *specs = td->specifics
-                               ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-                               : &asn_SPC_OCTET_STRING_specs;
-       BIT_STRING_t *st = (BIT_STRING_t *)*sptr;
-       asn_dec_rval_t rval;
-       asn_struct_ctx_t *ctx;
-       ssize_t consumed_myself = 0;
-       struct _stack *stck;            /* Expectations stack structure */
-       struct _stack_el *sel = 0;      /* Stack element */
-       int tlv_constr;
-       enum asn_OS_Subvariant type_variant = specs->subvariant;
-
-       ASN_DEBUG("Decoding %s as %s (frame %ld)",
-               td->name,
-               (type_variant == ASN_OSUBV_STR) ?
-                       "OCTET STRING" : "OS-SpecialCase",
-               (long)size);
-
-       /*
-        * Create the string if does not exist.
-        */
-       if(st == NULL) {
-               st = (BIT_STRING_t *)(*sptr = CALLOC(1, specs->struct_size));
-               if(st == NULL) RETURN(RC_FAIL);
-       }
-
-       /* Restore parsing context */
-       ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset);
-
-       switch(ctx->phase) {
-       case 0:
-               /*
-                * Check tags.
-                */
-               rval = ber_check_tags(opt_codec_ctx, td, ctx,
-                       buf_ptr, size, tag_mode, -1,
-                       &ctx->left, &tlv_constr);
-               if(rval.code != RC_OK)
-                       return rval;
-
-               if(tlv_constr) {
-                       /*
-                        * Complex operation, requires stack of expectations.
-                        */
-                       ctx->ptr = _new_stack();
-                       if(!ctx->ptr) {
-                               RETURN(RC_FAIL);
-                       }
-               } else {
-                       /*
-                        * Jump into stackless primitive decoding.
-                        */
-                       _CH_PHASE(ctx, 3);
-                       if(type_variant == ASN_OSUBV_ANY && tag_mode != 1)
-                               APPEND(buf_ptr, rval.consumed);
-                       ADVANCE(rval.consumed);
-                       goto phase3;
-               }
-
-               NEXT_PHASE(ctx);
-               /* Fall through */
-       case 1:
-       phase1:
-               /*
-                * Fill the stack with expectations.
-                */
-               stck = (struct _stack *)ctx->ptr;
-               sel = stck->cur_ptr;
-         do {
-               ber_tlv_tag_t tlv_tag;
-               ber_tlv_len_t tlv_len;
-               ber_tlv_tag_t expected_tag;
-               ssize_t tl, ll, tlvl;
-                               /* This one works even if (sel->left == -1) */
-               size_t Left = ((!sel||(size_t)sel->left >= size)
-                                       ?size:(size_t)sel->left);
-
-
-               ASN_DEBUG("%p, s->l=%ld, s->wn=%ld, s->g=%ld\n", (void *)sel,
-                       (long)(sel?sel->left:0),
-                       (long)(sel?sel->want_nulls:0),
-                       (long)(sel?sel->got:0)
-               );
-               if(sel && sel->left <= 0 && sel->want_nulls == 0) {
-                       if(sel->prev) {
-                               struct _stack_el *prev = sel->prev;
-                               if(prev->left != -1) {
-                                       if(prev->left < sel->got)
-                                               RETURN(RC_FAIL);
-                                       prev->left -= sel->got;
-                               }
-                               prev->got += sel->got;
-                               sel = stck->cur_ptr = prev;
-                               if(!sel) break;
-                               tlv_constr = 1;
-                               continue;
-                       } else {
-                               sel = stck->cur_ptr = 0;
-                               break;  /* Nothing to wait */
-                       }
-               }
-
-               tl = ber_fetch_tag(buf_ptr, Left, &tlv_tag);
-               ASN_DEBUG("fetch tag(size=%ld,L=%ld), %sstack, left=%ld, wn=%ld, tl=%ld",
-                       (long)size, (long)Left, sel?"":"!",
-                       (long)(sel?sel->left:0),
-                       (long)(sel?sel->want_nulls:0),
-                       (long)tl);
-               switch(tl) {
-               case -1: RETURN(RC_FAIL);
-               case 0: RETURN(RC_WMORE);
-               }
-
-               tlv_constr = BER_TLV_CONSTRUCTED(buf_ptr);
-
-               ll = ber_fetch_length(tlv_constr,
-                               (const char *)buf_ptr + tl,Left - tl,&tlv_len);
-               ASN_DEBUG("Got tag=%s, tc=%d, left=%ld, tl=%ld, len=%ld, ll=%ld",
-                       ber_tlv_tag_string(tlv_tag), tlv_constr,
-                               (long)Left, (long)tl, (long)tlv_len, (long)ll);
-               switch(ll) {
-               case -1: RETURN(RC_FAIL);
-               case 0: RETURN(RC_WMORE);
-               }
-
-               if(sel && sel->want_nulls
-                       && ((const uint8_t *)buf_ptr)[0] == 0
-                       && ((const uint8_t *)buf_ptr)[1] == 0)
-               {
-
-                       ASN_DEBUG("Eat EOC; wn=%d--", sel->want_nulls);
-
-                       if(type_variant == ASN_OSUBV_ANY
-                       && (tag_mode != 1 || sel->cont_level))
-                               APPEND("\0\0", 2);
-
-                       ADVANCE(2);
-                       sel->got += 2;
-                       if(sel->left != -1) {
-                               sel->left -= 2; /* assert(sel->left >= 2) */
-                       }
-
-                       sel->want_nulls--;
-                       if(sel->want_nulls == 0) {
-                               /* Move to the next expectation */
-                               sel->left = 0;
-                               tlv_constr = 1;
-                       }
-
-                       continue;
-               }
-
-               /*
-                * Set up expected tags,
-                * depending on ASN.1 type being decoded.
-                */
-               switch(type_variant) {
-               case ASN_OSUBV_BIT:
-                       /* X.690: 8.6.4.1, NOTE 2 */
-                       /* Fall through */
-               case ASN_OSUBV_STR:
-               default:
-                       if(sel) {
-                               unsigned level = sel->cont_level;
-                               if(level < td->all_tags_count) {
-                                       expected_tag = td->all_tags[level];
-                                       break;
-                               } else if(td->all_tags_count) {
-                                       expected_tag = td->all_tags
-                                               [td->all_tags_count - 1];
-                                       break;
-                               }
-                               /* else, Fall through */
-                       }
-                       /* Fall through */
-               case ASN_OSUBV_ANY:
-                       expected_tag = tlv_tag;
-                       break;
-               }
-
-
-               if(tlv_tag != expected_tag) {
-                       char buf[2][32];
-                       ber_tlv_tag_snprint(tlv_tag,
-                               buf[0], sizeof(buf[0]));
-                       ber_tlv_tag_snprint(td->tags[td->tags_count-1],
-                               buf[1], sizeof(buf[1]));
-                       ASN_DEBUG("Tag does not match expectation: %s != %s",
-                               buf[0], buf[1]);
-                       RETURN(RC_FAIL);
-               }
-
-               tlvl = tl + ll; /* Combined length of T and L encoding */
-               if((tlv_len + tlvl) < 0) {
-                       /* tlv_len value is too big */
-                       ASN_DEBUG("TLV encoding + length (%ld) is too big",
-                               (long)tlv_len);
-                       RETURN(RC_FAIL);
-               }
-
-               /*
-                * Append a new expectation.
-                */
-               sel = OS__add_stack_el(stck);
-               if(!sel) RETURN(RC_FAIL);
-
-               sel->tag = tlv_tag;
-
-               sel->want_nulls = (tlv_len==-1);
-               if(sel->prev && sel->prev->left != -1) {
-                       /* Check that the parent frame is big enough */
-                       if(sel->prev->left < tlvl + (tlv_len==-1?0:tlv_len))
-                               RETURN(RC_FAIL);
-                       if(tlv_len == -1)
-                               sel->left = sel->prev->left - tlvl;
-                       else
-                               sel->left = tlv_len;
-               } else {
-                       sel->left = tlv_len;
-               }
-               if(type_variant == ASN_OSUBV_ANY
-               && (tag_mode != 1 || sel->cont_level))
-                       APPEND(buf_ptr, tlvl);
-               sel->got += tlvl;
-               ADVANCE(tlvl);
-
-               ASN_DEBUG("+EXPECT2 got=%ld left=%ld, wn=%d, clvl=%u",
-                       (long)sel->got, (long)sel->left,
-                       sel->want_nulls, sel->cont_level);
-
-         } while(tlv_constr);
-               if(sel == NULL) {
-                       /* Finished operation, "phase out" */
-                       ASN_DEBUG("Phase out");
-                       _CH_PHASE(ctx, +3);
-                       break;
-               }
-
-               NEXT_PHASE(ctx);
-               /* Fall through */
-       case 2:
-               stck = (struct _stack *)ctx->ptr;
-               sel = stck->cur_ptr;
-               ASN_DEBUG("Phase 2: Need %ld bytes, size=%ld, alrg=%ld, wn=%d",
-                       (long)sel->left, (long)size, (long)sel->got,
-                               sel->want_nulls);
-           {
-               ber_tlv_len_t len;
-
-               assert(sel->left >= 0);
-
-               len = ((ber_tlv_len_t)size < sel->left)
-                               ? (ber_tlv_len_t)size : sel->left;
-               if(len > 0) {
-                       if(type_variant == ASN_OSUBV_BIT
-                       && sel->bits_chopped == 0) {
-                               /* Put the unused-bits-octet away */
-                               st->bits_unused = *(const uint8_t *)buf_ptr;
-                               APPEND(((const char *)buf_ptr+1), (len - 1));
-                               sel->bits_chopped = 1;
-                       } else {
-                               APPEND(buf_ptr, len);
-                       }
-                       ADVANCE(len);
-                       sel->left -= len;
-                       sel->got += len;
-               }
-
-               if(sel->left) {
-                       ASN_DEBUG("OS left %ld, size = %ld, wn=%d\n",
-                               (long)sel->left, (long)size, sel->want_nulls);
-                       RETURN(RC_WMORE);
-               }
-
-               PREV_PHASE(ctx);
-               goto phase1;
-           }
-               break;
-       case 3:
-       phase3:
-               /*
-                * Primitive form, no stack required.
-                */
-               assert(ctx->left >= 0);
-
-               if(size < (size_t)ctx->left) {
-                       if(!size) RETURN(RC_WMORE);
-                       if(type_variant == ASN_OSUBV_BIT && !ctx->context) {
-                               st->bits_unused = *(const uint8_t *)buf_ptr;
-                               ctx->left--;
-                               ADVANCE(1);
-                       }
-                       APPEND(buf_ptr, size);
-                       assert(ctx->context > 0);
-                       ctx->left -= size;
-                       ADVANCE(size);
-                       RETURN(RC_WMORE);
-               } else {
-                       if(type_variant == ASN_OSUBV_BIT
-                       && !ctx->context && ctx->left) {
-                               st->bits_unused = *(const uint8_t *)buf_ptr;
-                               ctx->left--;
-                               ADVANCE(1);
-                       }
-                       APPEND(buf_ptr, ctx->left);
-                       ADVANCE(ctx->left);
-                       ctx->left = 0;
-
-                       NEXT_PHASE(ctx);
-               }
-               break;
-       }
-
-       if(sel) {
-               ASN_DEBUG("3sel p=%p, wn=%d, l=%ld, g=%ld, size=%ld",
-                       (void *)sel->prev, sel->want_nulls,
-                       (long)sel->left, (long)sel->got, (long)size);
-               if(sel->prev || sel->want_nulls > 1 || sel->left > 0) {
-                       RETURN(RC_WMORE);
-               }
-       }
-
-       /*
-        * BIT STRING-specific processing.
-        */
-       if(type_variant == ASN_OSUBV_BIT) {
-        if(st->size) {
-                       if(st->bits_unused < 0 || st->bits_unused > 7) {
-                               RETURN(RC_FAIL);
-                       }
-                       /* Finalize BIT STRING: zero out unused bits. */
-                       st->buf[st->size-1] &= 0xff << st->bits_unused;
-               } else {
-                       if(st->bits_unused) {
-                               RETURN(RC_FAIL);
-                       }
-               }
-       }
-
-       ASN_DEBUG("Took %ld bytes to encode %s: [%s]:%ld",
-               (long)consumed_myself, td->name,
-               (type_variant == ASN_OSUBV_STR) ? (char *)st->buf : "<data>",
-               (long)st->size);
-
-
-       RETURN(RC_OK);
-}
-
-/*
- * Encode OCTET STRING type using DER.
- */
-asn_enc_rval_t
-OCTET_STRING_encode_der(const asn_TYPE_descriptor_t *td, const void *sptr,
-                        int tag_mode, ber_tlv_tag_t tag,
-                        asn_app_consume_bytes_f *cb, void *app_key) {
-    asn_enc_rval_t er = { 0, 0, 0 };
-       const asn_OCTET_STRING_specifics_t *specs = td->specifics
-                               ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-                               : &asn_SPC_OCTET_STRING_specs;
-       const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
-       enum asn_OS_Subvariant type_variant = specs->subvariant;
-       int fix_last_byte = 0;
-
-       ASN_DEBUG("%s %s as OCTET STRING",
-               cb?"Estimating":"Encoding", td->name);
-
-       /*
-        * Write tags.
-        */
-       if(type_variant != ASN_OSUBV_ANY || tag_mode == 1) {
-               er.encoded = der_write_tags(td,
-                               (type_variant == ASN_OSUBV_BIT) + st->size,
-                       tag_mode, type_variant == ASN_OSUBV_ANY, tag,
-                       cb, app_key);
-               if(er.encoded == -1) {
-                       er.failed_type = td;
-                       er.structure_ptr = sptr;
-                       return er;
-               }
-       } else {
-               /* Disallow: [<tag>] IMPLICIT ANY */
-               assert(type_variant != ASN_OSUBV_ANY || tag_mode != -1);
-               er.encoded = 0;
-       }
-
-       if(!cb) {
-               er.encoded += (type_variant == ASN_OSUBV_BIT) + st->size;
-               ASN__ENCODED_OK(er);
-       }
-
-       /*
-        * Prepare to deal with the last octet of BIT STRING.
-        */
-       if(type_variant == ASN_OSUBV_BIT) {
-               uint8_t b = st->bits_unused & 0x07;
-               if(b && st->size) fix_last_byte = 1;
-               ASN__CALLBACK(&b, 1);
-       }
-
-       /* Invoke callback for the main part of the buffer */
-       ASN__CALLBACK(st->buf, st->size - fix_last_byte);
-
-       /* The last octet should be stripped off the unused bits */
-       if(fix_last_byte) {
-               uint8_t b = st->buf[st->size-1] & (0xff << st->bits_unused);
-               ASN__CALLBACK(&b, 1);
-       }
-
-       ASN__ENCODED_OK(er);
-cb_failed:
-       ASN__ENCODE_FAILED;
-}
-
-asn_enc_rval_t
-OCTET_STRING_encode_xer(const asn_TYPE_descriptor_t *td, const void *sptr,
-                        int ilevel, enum xer_encoder_flags_e flags,
-                        asn_app_consume_bytes_f *cb, void *app_key) {
-    const char * const h2c = "0123456789ABCDEF";
-       const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
-       asn_enc_rval_t er = { 0, 0, 0 };
-       char scratch[16 * 3 + 4];
-       char *p = scratch;
-       uint8_t *buf;
-       uint8_t *end;
-       size_t i;
-
-       if(!st || (!st->buf && st->size))
-               ASN__ENCODE_FAILED;
-
-       er.encoded = 0;
-
-       /*
-        * Dump the contents of the buffer in hexadecimal.
-        */
-       buf = st->buf;
-       end = buf + st->size;
-       if(flags & XER_F_CANONICAL) {
-               char *scend = scratch + (sizeof(scratch) - 2);
-               for(; buf < end; buf++) {
-                       if(p >= scend) {
-                               ASN__CALLBACK(scratch, p - scratch);
-                               p = scratch;
-                       }
-                       *p++ = h2c[(*buf >> 4) & 0x0F];
-                       *p++ = h2c[*buf & 0x0F];
-               }
-
-               ASN__CALLBACK(scratch, p-scratch);      /* Dump the rest */
-       } else {
-               for(i = 0; buf < end; buf++, i++) {
-                       if(!(i % 16) && (i || st->size > 16)) {
-                               ASN__CALLBACK(scratch, p-scratch);
-                               p = scratch;
-                               ASN__TEXT_INDENT(1, ilevel);
-                       }
-                       *p++ = h2c[(*buf >> 4) & 0x0F];
-                       *p++ = h2c[*buf & 0x0F];
-                       *p++ = 0x20;
-               }
-               if(p - scratch) {
-                       p--;    /* Remove the tail space */
-                       ASN__CALLBACK(scratch, p-scratch); /* Dump the rest */
-                       if(st->size > 16)
-                               ASN__TEXT_INDENT(1, ilevel-1);
-               }
-       }
-
-       ASN__ENCODED_OK(er);
-cb_failed:
-       ASN__ENCODE_FAILED;
-}
-
-static const struct OCTET_STRING__xer_escape_table_s {
-       const char *string;
-       int size;
-} OCTET_STRING__xer_escape_table[] = {
-#define        OSXET(s)        { s, sizeof(s) - 1 }
-       OSXET("\074\156\165\154\057\076"),      /* <nul/> */
-       OSXET("\074\163\157\150\057\076"),      /* <soh/> */
-       OSXET("\074\163\164\170\057\076"),      /* <stx/> */
-       OSXET("\074\145\164\170\057\076"),      /* <etx/> */
-       OSXET("\074\145\157\164\057\076"),      /* <eot/> */
-       OSXET("\074\145\156\161\057\076"),      /* <enq/> */
-       OSXET("\074\141\143\153\057\076"),      /* <ack/> */
-       OSXET("\074\142\145\154\057\076"),      /* <bel/> */
-       OSXET("\074\142\163\057\076"),          /* <bs/> */
-       OSXET("\011"),                          /* \t */
-       OSXET("\012"),                          /* \n */
-       OSXET("\074\166\164\057\076"),          /* <vt/> */
-       OSXET("\074\146\146\057\076"),          /* <ff/> */
-       OSXET("\015"),                          /* \r */
-       OSXET("\074\163\157\057\076"),          /* <so/> */
-       OSXET("\074\163\151\057\076"),          /* <si/> */
-       OSXET("\074\144\154\145\057\076"),      /* <dle/> */
-       OSXET("\074\144\143\061\057\076"),      /* <de1/> */
-       OSXET("\074\144\143\062\057\076"),      /* <de2/> */
-       OSXET("\074\144\143\063\057\076"),      /* <de3/> */
-       OSXET("\074\144\143\064\057\076"),      /* <de4/> */
-       OSXET("\074\156\141\153\057\076"),      /* <nak/> */
-       OSXET("\074\163\171\156\057\076"),      /* <syn/> */
-       OSXET("\074\145\164\142\057\076"),      /* <etb/> */
-       OSXET("\074\143\141\156\057\076"),      /* <can/> */
-       OSXET("\074\145\155\057\076"),          /* <em/> */
-       OSXET("\074\163\165\142\057\076"),      /* <sub/> */
-       OSXET("\074\145\163\143\057\076"),      /* <esc/> */
-       OSXET("\074\151\163\064\057\076"),      /* <is4/> */
-       OSXET("\074\151\163\063\057\076"),      /* <is3/> */
-       OSXET("\074\151\163\062\057\076"),      /* <is2/> */
-       OSXET("\074\151\163\061\057\076"),      /* <is1/> */
-       { 0, 0 },       /* " " */
-       { 0, 0 },       /* ! */
-       { 0, 0 },       /* \" */
-       { 0, 0 },       /* # */
-       { 0, 0 },       /* $ */
-       { 0, 0 },       /* % */
-       OSXET("\046\141\155\160\073"),  /* &amp; */
-       { 0, 0 },       /* ' */
-       {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, /* ()*+,-./ */
-       {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, /* 01234567 */
-       {0,0},{0,0},{0,0},{0,0},                         /* 89:; */
-       OSXET("\046\154\164\073"),      /* &lt; */
-       { 0, 0 },       /* = */
-       OSXET("\046\147\164\073"),      /* &gt; */
-};
-
-static int
-OS__check_escaped_control_char(const void *buf, int size) {
-       size_t i;
-       /*
-        * Inefficient algorithm which translates the escape sequences
-        * defined above into characters. Returns -1 if not found.
-        * TODO: replace by a faster algorithm (bsearch(), hash or
-        * nested table lookups).
-        */
-       for(i = 0; i < 32 /* Don't spend time on the bottom half */; i++) {
-               const struct OCTET_STRING__xer_escape_table_s *el;
-               el = &OCTET_STRING__xer_escape_table[i];
-               if(el->size == size && memcmp(buf, el->string, size) == 0)
-                       return i;
-       }
-       return -1;
-}
-
-static int
-OCTET_STRING__handle_control_chars(void *struct_ptr, const void *chunk_buf, size_t chunk_size) {
-       /*
-        * This might be one of the escape sequences
-        * for control characters. Check it out.
-        * #11.15.5
-        */
-       int control_char = OS__check_escaped_control_char(chunk_buf,chunk_size);
-       if(control_char >= 0) {
-               OCTET_STRING_t *st = (OCTET_STRING_t *)struct_ptr;
-               void *p = REALLOC(st->buf, st->size + 2);
-               if(p) {
-                       st->buf = (uint8_t *)p;
-                       st->buf[st->size++] = control_char;
-                       st->buf[st->size] = '\0';       /* nul-termination */
-                       return 0;
-               }
-       }
-
-       return -1;      /* No, it's not */
-}
-
-asn_enc_rval_t
-OCTET_STRING_encode_xer_utf8(const asn_TYPE_descriptor_t *td, const void *sptr,
-                             int ilevel, enum xer_encoder_flags_e flags,
-                             asn_app_consume_bytes_f *cb, void *app_key) {
-       const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
-       asn_enc_rval_t er = { 0, 0, 0 };
-       uint8_t *buf, *end;
-       uint8_t *ss;    /* Sequence start */
-       ssize_t encoded_len = 0;
-
-       (void)ilevel;   /* Unused argument */
-       (void)flags;    /* Unused argument */
-
-       if(!st || (!st->buf && st->size))
-               ASN__ENCODE_FAILED;
-
-       buf = st->buf;
-       end = buf + st->size;
-       for(ss = buf; buf < end; buf++) {
-               unsigned int ch = *buf;
-               int s_len;      /* Special encoding sequence length */
-
-               /*
-                * Escape certain characters: X.680/11.15
-                */
-               if(ch < sizeof(OCTET_STRING__xer_escape_table)
-                       /sizeof(OCTET_STRING__xer_escape_table[0])
-               && (s_len = OCTET_STRING__xer_escape_table[ch].size)) {
-                       if(((buf - ss) && cb(ss, buf - ss, app_key) < 0)
-                       || cb(OCTET_STRING__xer_escape_table[ch].string, s_len,
-                                       app_key) < 0)
-                               ASN__ENCODE_FAILED;
-                       encoded_len += (buf - ss) + s_len;
-                       ss = buf + 1;
-               }
-       }
-
-       encoded_len += (buf - ss);
-       if((buf - ss) && cb(ss, buf - ss, app_key) < 0)
-               ASN__ENCODE_FAILED;
-
-       er.encoded = encoded_len;
-       ASN__ENCODED_OK(er);
-}
-
-/*
- * Convert from hexadecimal format (cstring): "AB CD EF"
- */
-static ssize_t OCTET_STRING__convert_hexadecimal(void *sptr, const void *chunk_buf, size_t chunk_size, int have_more) {
-       OCTET_STRING_t *st = (OCTET_STRING_t *)sptr;
-       const char *chunk_stop = (const char *)chunk_buf;
-       const char *p = chunk_stop;
-       const char *pend = p + chunk_size;
-       unsigned int clv = 0;
-       int half = 0;   /* Half bit */
-       uint8_t *buf;
-
-       /* Reallocate buffer according to high cap estimation */
-       size_t new_size = st->size + (chunk_size + 1) / 2;
-       void *nptr = REALLOC(st->buf, new_size + 1);
-       if(!nptr) return -1;
-       st->buf = (uint8_t *)nptr;
-       buf = st->buf + st->size;
-
-       /*
-        * If something like " a b c " appears here, the " a b":3 will be
-        * converted, and the rest skipped. That is, unless buf_size is greater
-        * than chunk_size, then it'll be equivalent to "ABC0".
-        */
-       for(; p < pend; p++) {
-               int ch = *(const unsigned char *)p;
-               switch(ch) {
-               case 0x09: case 0x0a: case 0x0c: case 0x0d:
-               case 0x20:
-                       /* Ignore whitespace */
-                       continue;
-               case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: /*01234*/
-               case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: /*56789*/
-                       clv = (clv << 4) + (ch - 0x30);
-                       break;
-               case 0x41: case 0x42: case 0x43:        /* ABC */
-               case 0x44: case 0x45: case 0x46:        /* DEF */
-                       clv = (clv << 4) + (ch - 0x41 + 10);
-                       break;
-               case 0x61: case 0x62: case 0x63:        /* abc */
-               case 0x64: case 0x65: case 0x66:        /* def */
-                       clv = (clv << 4) + (ch - 0x61 + 10);
-                       break;
-               default:
-                       *buf = 0;       /* JIC */
-                       return -1;
-               }
-               if(half++) {
-                       half = 0;
-                       *buf++ = clv;
-                       chunk_stop = p + 1;
-               }
-       }
-
-       /*
-        * Check partial decoding.
-        */
-       if(half) {
-               if(have_more) {
-                       /*
-                        * Partial specification is fine,
-                        * because no more more PXER_TEXT data is available.
-                        */
-                       *buf++ = clv << 4;
-                       chunk_stop = p;
-               }
-       } else {
-               chunk_stop = p;
-       }
-
-       st->size = buf - st->buf;       /* Adjust the buffer size */
-       assert(st->size <= new_size);
-       st->buf[st->size] = 0;          /* Courtesy termination */
-
-       return (chunk_stop - (const char *)chunk_buf);  /* Converted size */
-}
-
-/*
- * Convert from binary format: "00101011101"
- */
-static ssize_t OCTET_STRING__convert_binary(void *sptr, const void *chunk_buf, size_t chunk_size, int have_more) {
-       BIT_STRING_t *st = (BIT_STRING_t *)sptr;
-       const char *p = (const char *)chunk_buf;
-       const char *pend = p + chunk_size;
-       int bits_unused = st->bits_unused & 0x7;
-       uint8_t *buf;
-
-       /* Reallocate buffer according to high cap estimation */
-       size_t new_size = st->size + (chunk_size + 7) / 8;
-       void *nptr = REALLOC(st->buf, new_size + 1);
-       if(!nptr) return -1;
-       st->buf = (uint8_t *)nptr;
-       buf = st->buf + st->size;
-
-       (void)have_more;
-
-       if(bits_unused == 0)
-               bits_unused = 8;
-       else if(st->size)
-               buf--;
-
-       /*
-        * Convert series of 0 and 1 into the octet string.
-        */
-       for(; p < pend; p++) {
-               int ch = *(const unsigned char *)p;
-               switch(ch) {
-               case 0x09: case 0x0a: case 0x0c: case 0x0d:
-               case 0x20:
-                       /* Ignore whitespace */
-                       break;
-               case 0x30:
-               case 0x31:
-                       if(bits_unused-- <= 0) {
-                               *++buf = 0;     /* Clean the cell */
-                               bits_unused = 7;
-                       }
-                       *buf |= (ch&1) << bits_unused;
-                       break;
-               default:
-                       st->bits_unused = bits_unused;
-                       return -1;
-               }
-       }
-
-       if(bits_unused == 8) {
-               st->size = buf - st->buf;
-               st->bits_unused = 0;
-       } else {
-               st->size = buf - st->buf + 1;
-               st->bits_unused = bits_unused;
-       }
-
-       assert(st->size <= new_size);
-       st->buf[st->size] = 0;          /* Courtesy termination */
-
-       return chunk_size;      /* Converted in full */
-}
-
-/*
- * Something like strtod(), but with stricter rules.
- */
-static int
-OS__strtoent(int base, const char *buf, const char *end, int32_t *ret_value) {
-       const int32_t last_unicode_codepoint = 0x10ffff;
-       int32_t val = 0;
-       const char *p;
-
-       for(p = buf; p < end; p++) {
-               int ch = *p;
-
-               switch(ch) {
-               case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: /*01234*/
-               case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: /*56789*/
-                       val = val * base + (ch - 0x30);
-                       break;
-               case 0x41: case 0x42: case 0x43:        /* ABC */
-               case 0x44: case 0x45: case 0x46:        /* DEF */
-                       val = val * base + (ch - 0x41 + 10);
-                       break;
-               case 0x61: case 0x62: case 0x63:        /* abc */
-               case 0x64: case 0x65: case 0x66:        /* def */
-                       val = val * base + (ch - 0x61 + 10);
-                       break;
-               case 0x3b:      /* ';' */
-                       *ret_value = val;
-                       return (p - buf) + 1;
-               default:
-                       return -1;      /* Character set error */
-               }
-
-               /* Value exceeds the Unicode range. */
-               if(val > last_unicode_codepoint) {
-                       return -1;
-               }
-       }
-
-       *ret_value = -1;
-       return (p - buf);
-}
-
-/*
- * Convert from the plain UTF-8 format, expanding entity references: "2 &lt; 3"
- */
-static ssize_t
-OCTET_STRING__convert_entrefs(void *sptr, const void *chunk_buf,
-                              size_t chunk_size, int have_more) {
-    OCTET_STRING_t *st = (OCTET_STRING_t *)sptr;
-       const char *p = (const char *)chunk_buf;
-       const char *pend = p + chunk_size;
-       uint8_t *buf;
-
-       /* Reallocate buffer */
-       size_t new_size = st->size + chunk_size;
-       void *nptr = REALLOC(st->buf, new_size + 1);
-       if(!nptr) return -1;
-       st->buf = (uint8_t *)nptr;
-       buf = st->buf + st->size;
-
-       /*
-        * Convert series of 0 and 1 into the octet string.
-        */
-       for(; p < pend; p++) {
-               int ch = *(const unsigned char *)p;
-               int len;        /* Length of the rest of the chunk */
-
-               if(ch != 0x26 /* '&' */) {
-                       *buf++ = ch;
-                       continue;       /* That was easy... */
-               }
-
-               /*
-                * Process entity reference.
-                */
-               len = chunk_size - (p - (const char *)chunk_buf);
-               if(len == 1 /* "&" */) goto want_more;
-               if(p[1] == 0x23 /* '#' */) {
-                       const char *pval;       /* Pointer to start of digits */
-                       int32_t val = 0;        /* Entity reference value */
-                       int base;
-
-                       if(len == 2 /* "&#" */) goto want_more;
-                       if(p[2] == 0x78 /* 'x' */)
-                               pval = p + 3, base = 16;
-                       else
-                               pval = p + 2, base = 10;
-                       len = OS__strtoent(base, pval, p + len, &val);
-                       if(len == -1) {
-                               /* Invalid charset. Just copy verbatim. */
-                               *buf++ = ch;
-                               continue;
-                       }
-                       if(!len || pval[len-1] != 0x3b) goto want_more;
-                       assert(val > 0);
-                       p += (pval - p) + len - 1; /* Advance past entref */
-
-                       if(val < 0x80) {
-                               *buf++ = (char)val;
-                       } else if(val < 0x800) {
-                               *buf++ = 0xc0 | ((val >> 6));
-                               *buf++ = 0x80 | ((val & 0x3f));
-                       } else if(val < 0x10000) {
-                               *buf++ = 0xe0 | ((val >> 12));
-                               *buf++ = 0x80 | ((val >> 6) & 0x3f);
-                               *buf++ = 0x80 | ((val & 0x3f));
-                       } else if(val < 0x200000) {
-                               *buf++ = 0xf0 | ((val >> 18));
-                               *buf++ = 0x80 | ((val >> 12) & 0x3f);
-                               *buf++ = 0x80 | ((val >> 6) & 0x3f);
-                               *buf++ = 0x80 | ((val & 0x3f));
-                       } else if(val < 0x4000000) {
-                               *buf++ = 0xf8 | ((val >> 24));
-                               *buf++ = 0x80 | ((val >> 18) & 0x3f);
-                               *buf++ = 0x80 | ((val >> 12) & 0x3f);
-                               *buf++ = 0x80 | ((val >> 6) & 0x3f);
-                               *buf++ = 0x80 | ((val & 0x3f));
-                       } else {
-                               *buf++ = 0xfc | ((val >> 30) & 0x1);
-                               *buf++ = 0x80 | ((val >> 24) & 0x3f);
-                               *buf++ = 0x80 | ((val >> 18) & 0x3f);
-                               *buf++ = 0x80 | ((val >> 12) & 0x3f);
-                               *buf++ = 0x80 | ((val >> 6) & 0x3f);
-                               *buf++ = 0x80 | ((val & 0x3f));
-                       }
-               } else {
-                       /*
-                        * Ugly, limited parsing of &amp; &gt; &lt;
-                        */
-                       char *sc = (char *)memchr(p, 0x3b, len > 5 ? 5 : len);
-                       if(!sc) goto want_more;
-                       if((sc - p) == 4
-                               && p[1] == 0x61 /* 'a' */
-                               && p[2] == 0x6d /* 'm' */
-                               && p[3] == 0x70 /* 'p' */) {
-                               *buf++ = 0x26;
-                               p = sc;
-                               continue;
-                       }
-                       if((sc - p) == 3) {
-                               if(p[1] == 0x6c) {
-                                       *buf = 0x3c;    /* '<' */
-                               } else if(p[1] == 0x67) {
-                                       *buf = 0x3e;    /* '>' */
-                               } else {
-                                       /* Unsupported entity reference */
-                                       *buf++ = ch;
-                                       continue;
-                               }
-                               if(p[2] != 0x74) {
-                                       /* Unsupported entity reference */
-                                       *buf++ = ch;
-                                       continue;
-                               }
-                               buf++;
-                               p = sc;
-                               continue;
-                       }
-                       /* Unsupported entity reference */
-                       *buf++ = ch;
-               }
-
-               continue;
-       want_more:
-               if(have_more) {
-                       /*
-                        * We know that no more data (of the same type)
-                        * is coming. Copy the rest verbatim.
-                        */
-                       *buf++ = ch;
-                       continue;
-               }
-               chunk_size = (p - (const char *)chunk_buf);
-               /* Processing stalled: need more data */
-               break;
-       }
-
-       st->size = buf - st->buf;
-       assert(st->size <= new_size);
-       st->buf[st->size] = 0;          /* Courtesy termination */
-
-       return chunk_size;      /* Converted in full */
-}
-
-/*
- * Decode OCTET STRING from the XML element's body.
- */
-static asn_dec_rval_t
-OCTET_STRING__decode_xer(
-    const asn_codec_ctx_t *opt_codec_ctx, const asn_TYPE_descriptor_t *td,
-    void **sptr, const char *opt_mname, const void *buf_ptr, size_t size,
-    int (*opt_unexpected_tag_decoder)(void *struct_ptr, const void *chunk_buf,
-                                      size_t chunk_size),
-    ssize_t (*body_receiver)(void *struct_ptr, const void *chunk_buf,
-                             size_t chunk_size, int have_more)) {
-    OCTET_STRING_t *st = (OCTET_STRING_t *)*sptr;
-       const asn_OCTET_STRING_specifics_t *specs = td->specifics
-                               ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-                               : &asn_SPC_OCTET_STRING_specs;
-       const char *xml_tag = opt_mname ? opt_mname : td->xml_tag;
-       asn_struct_ctx_t *ctx;          /* Per-structure parser context */
-       asn_dec_rval_t rval;            /* Return value from the decoder */
-       int st_allocated;
-
-       /*
-        * Create the string if does not exist.
-        */
-       if(!st) {
-               st = (OCTET_STRING_t *)CALLOC(1, specs->struct_size);
-               *sptr = (void *)st;
-               if(!st) goto sta_failed;
-               st_allocated = 1;
-       } else {
-               st_allocated = 0;
-       }
-       if(!st->buf) {
-               /* This is separate from above section */
-               st->buf = (uint8_t *)CALLOC(1, 1);
-               if(!st->buf) {
-                       if(st_allocated) {
-                               *sptr = 0;
-                               goto stb_failed;
-                       } else {
-                               goto sta_failed;
-                       }
-               }
-       }
-
-       /* Restore parsing context */
-       ctx = (asn_struct_ctx_t *)(((char *)*sptr) + specs->ctx_offset);
-
-       return xer_decode_general(opt_codec_ctx, ctx, *sptr, xml_tag,
-               buf_ptr, size, opt_unexpected_tag_decoder, body_receiver);
-
-stb_failed:
-       FREEMEM(st);
-sta_failed:
-       rval.code = RC_FAIL;
-       rval.consumed = 0;
-       return rval;
-}
-
-/*
- * Decode OCTET STRING from the hexadecimal data.
- */
-asn_dec_rval_t
-OCTET_STRING_decode_xer_hex(const asn_codec_ctx_t *opt_codec_ctx,
-                            const asn_TYPE_descriptor_t *td, void **sptr,
-                            const char *opt_mname, const void *buf_ptr,
-                            size_t size) {
-    return OCTET_STRING__decode_xer(opt_codec_ctx, td, sptr, opt_mname,
-               buf_ptr, size, 0, OCTET_STRING__convert_hexadecimal);
-}
-
-/*
- * Decode OCTET STRING from the binary (0/1) data.
- */
-asn_dec_rval_t
-OCTET_STRING_decode_xer_binary(const asn_codec_ctx_t *opt_codec_ctx,
-                               const asn_TYPE_descriptor_t *td, void **sptr,
-                               const char *opt_mname, const void *buf_ptr,
-                               size_t size) {
-    return OCTET_STRING__decode_xer(opt_codec_ctx, td, sptr, opt_mname,
-               buf_ptr, size, 0, OCTET_STRING__convert_binary);
-}
-
-/*
- * Decode OCTET STRING from the string (ASCII/UTF-8) data.
- */
-asn_dec_rval_t
-OCTET_STRING_decode_xer_utf8(const asn_codec_ctx_t *opt_codec_ctx,
-                             const asn_TYPE_descriptor_t *td, void **sptr,
-                             const char *opt_mname, const void *buf_ptr,
-                             size_t size) {
-    return OCTET_STRING__decode_xer(opt_codec_ctx, td, sptr, opt_mname,
-               buf_ptr, size,
-               OCTET_STRING__handle_control_chars,
-               OCTET_STRING__convert_entrefs);
-}
-
-#ifndef  ASN_DISABLE_PER_SUPPORT
-
-static int
-OCTET_STRING_per_get_characters(asn_per_data_t *po, uint8_t *buf,
-               size_t units, unsigned int bpc, unsigned int unit_bits,
-               long lb, long ub, const asn_per_constraints_t *pc) {
-       uint8_t *end = buf + units * bpc;
-
-       ASN_DEBUG("Expanding %d characters into (%ld..%ld):%d",
-               (int)units, lb, ub, unit_bits);
-
-       /* X.691: 27.5.4 */
-       if((unsigned long)ub <= ((unsigned long)2 << (unit_bits - 1))) {
-               /* Decode without translation */
-               lb = 0;
-       } else if(pc && pc->code2value) {
-               if(unit_bits > 16)
-                       return 1;       /* FATAL: can't have constrained
-                                        * UniversalString with more than
-                                        * 16 million code points */
-               for(; buf < end; buf += bpc) {
-                       int value;
-                       int code = per_get_few_bits(po, unit_bits);
-                       if(code < 0) return -1; /* WMORE */
-                       value = pc->code2value(code);
-                       if(value < 0) {
-                               ASN_DEBUG("Code %d (0x%02x) is"
-                                       " not in map (%ld..%ld)",
-                                       code, code, lb, ub);
-                               return 1;       /* FATAL */
-                       }
-                       switch(bpc) {
-                       case 1: *buf = value; break;
-                       case 2: buf[0] = value >> 8; buf[1] = value; break;
-                       case 4: buf[0] = value >> 24; buf[1] = value >> 16;
-                               buf[2] = value >> 8; buf[3] = value; break;
-                       }
-               }
-               return 0;
-       }
-
-       /* Shortcut the no-op copying to the aligned structure */
-       if(lb == 0 && (unit_bits == 8 * bpc)) {
-               return per_get_many_bits(po, buf, 0, unit_bits * units);
-       }
-
-       for(; buf < end; buf += bpc) {
-               int32_t code = per_get_few_bits(po, unit_bits);
-               int32_t ch = code + lb;
-               if(code < 0) return -1; /* WMORE */
-               if(ch > ub) {
-                       ASN_DEBUG("Code %d is out of range (%ld..%ld)",
-                               ch, lb, ub);
-                       return 1;       /* FATAL */
-               }
-               switch(bpc) {
-               case 1: *buf = ch; break;
-               case 2: buf[0] = ch >> 8; buf[1] = ch; break;
-               case 4: buf[0] = ch >> 24; buf[1] = ch >> 16;
-                       buf[2] = ch >> 8; buf[3] = ch; break;
-               }
-       }
-
-       return 0;
-}
-
-static int
-OCTET_STRING_per_put_characters(asn_per_outp_t *po, const uint8_t *buf,
-               size_t units, unsigned int bpc, unsigned int unit_bits,
-               long lb, long ub, const asn_per_constraints_t *pc) {
-       const uint8_t *end = buf + units * bpc;
-
-       ASN_DEBUG("Squeezing %d characters into (%ld..%ld):%d (%d bpc)",
-               (int)units, lb, ub, unit_bits, bpc);
-
-       /* X.691: 27.5.4 */
-       if((unsigned long)ub <= ((unsigned long)2 << (unit_bits - 1))) {
-               /* Encode as is */
-               lb = 0;
-       } else if(pc && pc->value2code) {
-               for(; buf < end; buf += bpc) {
-                       int code;
-                       uint32_t value;
-                       switch(bpc) {
-                       case 1: value = *(const uint8_t *)buf; break;
-                       case 2: value = (buf[0] << 8) | buf[1]; break;
-                       case 4: value = (buf[0] << 24) | (buf[1] << 16)
-                                       | (buf[2] << 8) | buf[3]; break;
-                       default: return -1;
-                       }
-                       code = pc->value2code(value);
-                       if(code < 0) {
-                               ASN_DEBUG("Character %d (0x%02x) is"
-                                       " not in map (%ld..%ld)",
-                                       *buf, *buf, lb, ub);
-                               return -1;
-                       }
-                       if(per_put_few_bits(po, code, unit_bits))
-                               return -1;
-               }
-       }
-
-       /* Shortcut the no-op copying to the aligned structure */
-       if(lb == 0 && (unit_bits == 8 * bpc)) {
-               return per_put_many_bits(po, buf, unit_bits * units);
-       }
-
-    for(ub -= lb; buf < end; buf += bpc) {
-        int ch;
-        uint32_t value;
-        switch(bpc) {
-        case 1:
-            value = *(const uint8_t *)buf;
-            break;
-        case 2:
-            value = (buf[0] << 8) | buf[1];
-            break;
-        case 4:
-            value = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
-            break;
-        default:
-            return -1;
-        }
-        ch = value - lb;
-        if(ch < 0 || ch > ub) {
-            ASN_DEBUG("Character %d (0x%02x) is out of range (%ld..%ld)", *buf,
-                      value, lb, ub + lb);
-            return -1;
-        }
-        if(per_put_few_bits(po, ch, unit_bits)) return -1;
-    }
-
-    return 0;
-}
-
-static asn_per_constraints_t asn_DEF_OCTET_STRING_constraints = {
-       { APC_CONSTRAINED, 8, 8, 0, 255 },
-       { APC_SEMI_CONSTRAINED, -1, -1, 0, 0 },
-       0, 0
-};
-
-asn_dec_rval_t
-OCTET_STRING_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
-                         const asn_TYPE_descriptor_t *td,
-                         const asn_per_constraints_t *constraints, void **sptr,
-                         asn_per_data_t *pd) {
-    const asn_OCTET_STRING_specifics_t *specs = td->specifics
-               ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-               : &asn_SPC_OCTET_STRING_specs;
-    const asn_per_constraints_t *pc =
-        constraints ? constraints : td->encoding_constraints.per_constraints;
-    const asn_per_constraint_t *cval;
-       const asn_per_constraint_t *csiz;
-       asn_dec_rval_t rval = { RC_OK, 0 };
-       OCTET_STRING_t *st = (OCTET_STRING_t *)*sptr;
-       ssize_t consumed_myself = 0;
-       int repeat;
-       enum {
-               OS__BPC_CHAR    = 1,
-               OS__BPC_U16     = 2,
-               OS__BPC_U32     = 4
-       } bpc;  /* Bytes per character */
-       unsigned int unit_bits;
-       unsigned int canonical_unit_bits;
-
-       (void)opt_codec_ctx;
-
-       if(pc) {
-               cval = &pc->value;
-               csiz = &pc->size;
-       } else {
-               cval = &asn_DEF_OCTET_STRING_constraints.value;
-               csiz = &asn_DEF_OCTET_STRING_constraints.size;
-       }
-
-       switch(specs->subvariant) {
-       default:
-       case ASN_OSUBV_ANY:
-       case ASN_OSUBV_BIT:
-               ASN_DEBUG("Unrecognized subvariant %d", specs->subvariant);
-               RETURN(RC_FAIL);
-               break;
-       case ASN_OSUBV_STR:
-               canonical_unit_bits = unit_bits = 8;
-               if(cval->flags & APC_CONSTRAINED)
-                       unit_bits = cval->range_bits;
-               bpc = OS__BPC_CHAR;
-               break;
-       case ASN_OSUBV_U16:
-               canonical_unit_bits = unit_bits = 16;
-               if(cval->flags & APC_CONSTRAINED)
-                       unit_bits = cval->range_bits;
-               bpc = OS__BPC_U16;
-               break;
-       case ASN_OSUBV_U32:
-               canonical_unit_bits = unit_bits = 32;
-               if(cval->flags & APC_CONSTRAINED)
-                       unit_bits = cval->range_bits;
-               bpc = OS__BPC_U32;
-               break;
-       }
-
-       /*
-        * Allocate the string.
-        */
-       if(!st) {
-               st = (OCTET_STRING_t *)(*sptr = CALLOC(1, specs->struct_size));
-               if(!st) RETURN(RC_FAIL);
-       }
-
-       ASN_DEBUG("PER Decoding %s size %ld .. %ld bits %d",
-               csiz->flags & APC_EXTENSIBLE ? "extensible" : "non-extensible",
-               csiz->lower_bound, csiz->upper_bound, csiz->effective_bits);
-
-       if(csiz->flags & APC_EXTENSIBLE) {
-               int inext = per_get_few_bits(pd, 1);
-               if(inext < 0) RETURN(RC_WMORE);
-               if(inext) {
-                       csiz = &asn_DEF_OCTET_STRING_constraints.size;
-                       unit_bits = canonical_unit_bits;
-               }
-       }
-
-       if(csiz->effective_bits >= 0) {
-               FREEMEM(st->buf);
-               if(bpc) {
-                       st->size = csiz->upper_bound * bpc;
-               } else {
-                       st->size = (csiz->upper_bound + 7) >> 3;
-               }
-               st->buf = (uint8_t *)MALLOC(st->size + 1);
-               if(!st->buf) { st->size = 0; RETURN(RC_FAIL); }
-       }
-
-       /* X.691, #16.5: zero-length encoding */
-       /* X.691, #16.6: short fixed length encoding (up to 2 octets) */
-       /* X.691, #16.7: long fixed length encoding (up to 64K octets) */
-       if(csiz->effective_bits == 0) {
-               int ret;
-               if(bpc) {
-                       ASN_DEBUG("Encoding OCTET STRING size %ld",
-                               csiz->upper_bound);
-                       ret = OCTET_STRING_per_get_characters(pd, st->buf,
-                               csiz->upper_bound, bpc, unit_bits,
-                               cval->lower_bound, cval->upper_bound, pc);
-                       if(ret > 0) RETURN(RC_FAIL);
-               } else {
-                       ASN_DEBUG("Encoding BIT STRING size %ld",
-                               csiz->upper_bound);
-                       ret = per_get_many_bits(pd, st->buf, 0,
-                                           unit_bits * csiz->upper_bound);
-               }
-               if(ret < 0) RETURN(RC_WMORE);
-               consumed_myself += unit_bits * csiz->upper_bound;
-               st->buf[st->size] = 0;
-               RETURN(RC_OK);
-       }
-
-       st->size = 0;
-       do {
-               ssize_t raw_len;
-               ssize_t len_bytes;
-               void *p;
-               int ret;
-
-               /* Get the PER length */
-               raw_len = uper_get_length(pd, csiz->effective_bits, csiz->lower_bound,
-                                         &repeat);
-               if(raw_len < 0) RETURN(RC_WMORE);
-               if(raw_len == 0 && st->buf) break;
-
-               ASN_DEBUG("Got PER length eb %ld, len %ld, %s (%s)",
-                       (long)csiz->effective_bits, (long)raw_len,
-                       repeat ? "repeat" : "once", td->name);
-        len_bytes = raw_len * bpc;
-               p = REALLOC(st->buf, st->size + len_bytes + 1);
-               if(!p) RETURN(RC_FAIL);
-               st->buf = (uint8_t *)p;
-
-        ret = OCTET_STRING_per_get_characters(pd, &st->buf[st->size], raw_len,
-                                              bpc, unit_bits, cval->lower_bound,
-                                              cval->upper_bound, pc);
-        if(ret > 0) RETURN(RC_FAIL);
-               if(ret < 0) RETURN(RC_WMORE);
-               st->size += len_bytes;
-       } while(repeat);
-       st->buf[st->size] = 0;  /* nul-terminate */
-
-       return rval;
-}
-
-asn_enc_rval_t
-OCTET_STRING_encode_uper(const asn_TYPE_descriptor_t *td,
-                         const asn_per_constraints_t *constraints,
-                         const void *sptr, asn_per_outp_t *po) {
-    const asn_OCTET_STRING_specifics_t *specs = td->specifics
-               ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-               : &asn_SPC_OCTET_STRING_specs;
-       const asn_per_constraints_t *pc = constraints ? constraints
-                               : td->encoding_constraints.per_constraints;
-       const asn_per_constraint_t *cval;
-       const asn_per_constraint_t *csiz;
-       const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
-       asn_enc_rval_t er = { 0, 0, 0 };
-       int inext = 0;          /* Lies not within extension root */
-       unsigned int unit_bits;
-       unsigned int canonical_unit_bits;
-       size_t size_in_units;
-       const uint8_t *buf;
-       int ret;
-       enum {
-               OS__BPC_CHAR    = 1,
-               OS__BPC_U16     = 2,
-               OS__BPC_U32     = 4
-       } bpc;  /* Bytes per character */
-       int ct_extensible;
-
-       if(!st || (!st->buf && st->size))
-               ASN__ENCODE_FAILED;
-
-       if(pc) {
-               cval = &pc->value;
-               csiz = &pc->size;
-       } else {
-               cval = &asn_DEF_OCTET_STRING_constraints.value;
-               csiz = &asn_DEF_OCTET_STRING_constraints.size;
-       }
-       ct_extensible = csiz->flags & APC_EXTENSIBLE;
-
-       switch(specs->subvariant) {
-       default:
-       case ASN_OSUBV_ANY:
-       case ASN_OSUBV_BIT:
-               ASN__ENCODE_FAILED;
-       case ASN_OSUBV_STR:
-               canonical_unit_bits = unit_bits = 8;
-               if(cval->flags & APC_CONSTRAINED)
-                       unit_bits = cval->range_bits;
-               bpc = OS__BPC_CHAR;
-               size_in_units = st->size;
-               break;
-       case ASN_OSUBV_U16:
-               canonical_unit_bits = unit_bits = 16;
-               if(cval->flags & APC_CONSTRAINED)
-                       unit_bits = cval->range_bits;
-               bpc = OS__BPC_U16;
-               size_in_units = st->size >> 1;
-               if(st->size & 1) {
-                       ASN_DEBUG("%s string size is not modulo 2", td->name);
-                       ASN__ENCODE_FAILED;
-               }
-               break;
-       case ASN_OSUBV_U32:
-               canonical_unit_bits = unit_bits = 32;
-               if(cval->flags & APC_CONSTRAINED)
-                       unit_bits = cval->range_bits;
-               bpc = OS__BPC_U32;
-               size_in_units = st->size >> 2;
-               if(st->size & 3) {
-                       ASN_DEBUG("%s string size is not modulo 4", td->name);
-                       ASN__ENCODE_FAILED;
-               }
-               break;
-       }
-
-       ASN_DEBUG("Encoding %s into %" ASN_PRI_SIZE " units of %d bits"
-               " (%ld..%ld, effective %d)%s",
-               td->name, size_in_units, unit_bits,
-               csiz->lower_bound, csiz->upper_bound,
-               csiz->effective_bits, ct_extensible ? " EXT" : "");
-
-       /* Figure out whether size lies within PER visible constraint */
-
-    if(csiz->effective_bits >= 0) {
-        if((ssize_t)size_in_units < csiz->lower_bound
-           || (ssize_t)size_in_units > csiz->upper_bound) {
-            if(ct_extensible) {
-                csiz = &asn_DEF_OCTET_STRING_constraints.size;
-                unit_bits = canonical_unit_bits;
-                inext = 1;
-            } else {
-                ASN__ENCODE_FAILED;
-            }
-        }
-    } else {
-        inext = 0;
-    }
-
-    if(ct_extensible) {
-               /* Declare whether length is [not] within extension root */
-               if(per_put_few_bits(po, inext, 1))
-                       ASN__ENCODE_FAILED;
-       }
-
-    if(csiz->effective_bits >= 0 && !inext) {
-        ASN_DEBUG("Encoding %" ASN_PRI_SIZE " bytes (%ld), length in %d bits", st->size,
-                  size_in_units - csiz->lower_bound, csiz->effective_bits);
-        ret = per_put_few_bits(po, size_in_units - csiz->lower_bound,
-                               csiz->effective_bits);
-        if(ret) ASN__ENCODE_FAILED;
-        ret = OCTET_STRING_per_put_characters(po, st->buf, size_in_units, bpc,
-                                              unit_bits, cval->lower_bound,
-                                              cval->upper_bound, pc);
-        if(ret) ASN__ENCODE_FAILED;
-        ASN__ENCODED_OK(er);
-    }
-
-    ASN_DEBUG("Encoding %" ASN_PRI_SIZE " bytes", st->size);
-
-    buf = st->buf;
-    ASN_DEBUG("Encoding %" ASN_PRI_SIZE " in units", size_in_units);
-    do {
-        int need_eom = 0;
-        ssize_t may_save = uper_put_length(po, size_in_units, &need_eom);
-        if(may_save < 0) ASN__ENCODE_FAILED;
-
-        ASN_DEBUG("Encoding %" ASN_PRI_SSIZE " of %" ASN_PRI_SIZE "%s", may_save, size_in_units,
-                  need_eom ? ",+EOM" : "");
-
-        ret = OCTET_STRING_per_put_characters(po, buf, may_save, bpc, unit_bits,
-                                              cval->lower_bound,
-                                              cval->upper_bound, pc);
-        if(ret) ASN__ENCODE_FAILED;
-
-        buf += may_save * bpc;
-        size_in_units -= may_save;
-        assert(!(may_save & 0x07) || !size_in_units);
-        if(need_eom && uper_put_length(po, 0, 0))
-            ASN__ENCODE_FAILED; /* End of Message length */
-    } while(size_in_units);
-
-    ASN__ENCODED_OK(er);
-}
-
-asn_dec_rval_t
-OCTET_STRING_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
-                         const asn_TYPE_descriptor_t *td,
-                         const asn_per_constraints_t *constraints,
-                         void **sptr, asn_per_data_t *pd) {
-
-       const asn_OCTET_STRING_specifics_t *specs = td->specifics
-               ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-               : &asn_SPC_OCTET_STRING_specs;
-       const asn_per_constraints_t *pc = constraints ? constraints
-                               : td->encoding_constraints.per_constraints;
-       const asn_per_constraint_t *cval;
-       const asn_per_constraint_t *csiz;
-       asn_dec_rval_t rval = { RC_OK, 0 };
-       BIT_STRING_t *st = (BIT_STRING_t *)*sptr;
-       ssize_t consumed_myself = 0;
-       int repeat;
-       enum {
-               OS__BPC_BIT     = 0,
-               OS__BPC_CHAR    = 1,
-               OS__BPC_U16     = 2,
-               OS__BPC_U32     = 4
-       } bpc;  /* Bytes per character */
-       unsigned int unit_bits;
-       unsigned int canonical_unit_bits;
-
-       (void)opt_codec_ctx;
-
-       if(pc) {
-               cval = &pc->value;
-               csiz = &pc->size;
-       } else {
-               cval = &asn_DEF_OCTET_STRING_constraints.value;
-               csiz = &asn_DEF_OCTET_STRING_constraints.size;
-       }
-
-       switch(specs->subvariant) {
-       default:
-/*     case ASN_OSUBV_ANY:
-               ASN_DEBUG("Unrecognized subvariant %d", specs->subvariant);
-               RETURN(RC_FAIL);
-*/
-       case ASN_OSUBV_BIT:
-               canonical_unit_bits = unit_bits = 1;
-               bpc = OS__BPC_BIT;
-               break;
-       case ASN_OSUBV_ANY:
-       case ASN_OSUBV_STR:
-               canonical_unit_bits = unit_bits = 8;
-/*             if(cval->flags & APC_CONSTRAINED)
-                       unit_bits = cval->range_bits;
-*/
-               bpc = OS__BPC_CHAR;
-               break;
-       case ASN_OSUBV_U16:
-               canonical_unit_bits = unit_bits = 16;
-               if(cval->flags & APC_CONSTRAINED)
-                       unit_bits = cval->range_bits;
-               bpc = OS__BPC_U16;
-               break;
-       case ASN_OSUBV_U32:
-               canonical_unit_bits = unit_bits = 32;
-               if(cval->flags & APC_CONSTRAINED)
-                       unit_bits = cval->range_bits;
-               bpc = OS__BPC_U32;
-               break;
-       }
-
-       /*
-        * Allocate the string.
-        */
-       if(!st) {
-               st = (BIT_STRING_t *)(*sptr = CALLOC(1, specs->struct_size));
-               if(!st) RETURN(RC_FAIL);
-       }
-
-       ASN_DEBUG("PER Decoding %s size %ld .. %ld bits %d",
-               csiz->flags & APC_EXTENSIBLE ? "extensible" : "non-extensible",
-               csiz->lower_bound, csiz->upper_bound, csiz->effective_bits);
-
-       if(csiz->flags & APC_EXTENSIBLE) {
-               int inext = per_get_few_bits(pd, 1);
-               if(inext < 0) RETURN(RC_WMORE);
-               if(inext) {
-                       csiz = &asn_DEF_OCTET_STRING_constraints.size;
-                       cval = &asn_DEF_OCTET_STRING_constraints.value;
-                       unit_bits = canonical_unit_bits;
-               }
-       }
-
-       if(csiz->effective_bits >= 0) {
-               FREEMEM(st->buf);
-               if(bpc) {
-                       st->size = csiz->upper_bound * bpc;
-               } else {
-                       st->size = (csiz->upper_bound + 7) >> 3;
-               }
-               st->buf = (uint8_t *)MALLOC(st->size + 1);
-               if(!st->buf) { st->size = 0; RETURN(RC_FAIL); }
-       }
-
-       /* X.691, #16.5: zero-length encoding */
-       /* X.691, #16.6: short fixed length encoding (up to 2 octets) */
-       /* X.691, #16.7: long fixed length encoding (up to 64K octets) */
-       if(csiz->effective_bits == 0) {
-               int ret;
-               if (st->size > 2) { /* X.691 #16 NOTE 1 */
-                       if (aper_get_align(pd) < 0)
-                               RETURN(RC_FAIL);
-               }
-               if(bpc) {
-                       ASN_DEBUG("Decoding OCTET STRING size %ld",
-                               csiz->upper_bound);
-                       ret = OCTET_STRING_per_get_characters(pd, st->buf,
-                               csiz->upper_bound, bpc, unit_bits,
-                               cval->lower_bound, cval->upper_bound, pc);
-                       if(ret > 0) RETURN(RC_FAIL);
-               } else {
-                       ASN_DEBUG("Decoding BIT STRING size %ld",
-                               csiz->upper_bound);
-                       ret = per_get_many_bits(pd, st->buf, 0,
-                                           unit_bits * csiz->upper_bound);
-               }
-               if(ret < 0) RETURN(RC_WMORE);
-               consumed_myself += unit_bits * csiz->upper_bound;
-               st->buf[st->size] = 0;
-               if(bpc == 0) {
-                       int ubs = (csiz->upper_bound & 0x7);
-                       st->bits_unused = ubs ? 8 - ubs : 0;
-               }
-               RETURN(RC_OK);
-       }
-
-       st->size = 0;
-       do {
-               ssize_t raw_len;
-               ssize_t len_bytes;
-               ssize_t len_bits;
-               void *p;
-               int ret;
-
-               /* Get the PER length */
-               if (csiz->upper_bound - csiz->lower_bound == 0)
-                       /* Indefinite length case */
-                       raw_len = aper_get_length(pd, -1, csiz->effective_bits, &repeat);
-               else
-                       raw_len = aper_get_length(pd, csiz->upper_bound - csiz->lower_bound + 1, csiz->effective_bits, &repeat);
-               repeat = 0;
-               if(raw_len < 0) RETURN(RC_WMORE);
-               raw_len += csiz->lower_bound;
-
-               ASN_DEBUG("Got PER length eb %ld, len %ld, %s (%s)",
-                       (long)csiz->effective_bits, (long)raw_len,
-                       repeat ? "repeat" : "once", td->name);
-
-               if (raw_len > 2) { /* X.691 #16 NOTE 1 */
-                       if (aper_get_align(pd) < 0)
-                               RETURN(RC_FAIL);
-               }
-
-               if(bpc) {
-                       len_bytes = raw_len * bpc;
-                       len_bits = len_bytes * unit_bits;
-               } else {
-                       len_bits = raw_len;
-                       len_bytes = (len_bits + 7) >> 3;
-                       if(len_bits & 0x7)
-                               st->bits_unused = 8 - (len_bits & 0x7);
-                       /* len_bits be multiple of 16K if repeat is set */
-               }
-               p = REALLOC(st->buf, st->size + len_bytes + 1);
-               if(!p) RETURN(RC_FAIL);
-               st->buf = (uint8_t *)p;
-
-               if(bpc) {
-                       ret = OCTET_STRING_per_get_characters(pd,
-                               &st->buf[st->size], raw_len, bpc, unit_bits,
-                               cval->lower_bound, cval->upper_bound, pc);
-                       if(ret > 0) RETURN(RC_FAIL);
-               } else {
-                       ret = per_get_many_bits(pd, &st->buf[st->size],
-                               0, len_bits);
-               }
-               if(ret < 0) RETURN(RC_WMORE);
-               st->size += len_bytes;
-       } while(repeat);
-       st->buf[st->size] = 0;  /* nul-terminate */
-
-       return rval;
-}
-
-asn_enc_rval_t
-OCTET_STRING_encode_aper(const asn_TYPE_descriptor_t *td,
-                         const asn_per_constraints_t *constraints,
-                         const void *sptr, asn_per_outp_t *po) {
-
-       const asn_OCTET_STRING_specifics_t *specs = td->specifics
-               ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-               : &asn_SPC_OCTET_STRING_specs;
-       const asn_per_constraints_t *pc = constraints ? constraints
-       : td->encoding_constraints.per_constraints;
-       const asn_per_constraint_t *cval;
-       const asn_per_constraint_t *csiz;
-       const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
-       asn_enc_rval_t er = { 0, 0, 0 };
-       int inext = 0;          /* Lies not within extension root */
-       unsigned int unit_bits;
-       unsigned int canonical_unit_bits;
-       unsigned int sizeinunits;
-       const uint8_t *buf;
-       int ret;
-       enum {
-               OS__BPC_BIT     = 0,
-               OS__BPC_CHAR    = 1,
-               OS__BPC_U16     = 2,
-               OS__BPC_U32     = 4
-       } bpc;  /* Bytes per character */
-       int ct_extensible;
-
-       if(!st || (!st->buf && st->size))
-               ASN__ENCODE_FAILED;
-
-       if(pc) {
-               cval = &pc->value;
-               csiz = &pc->size;
-       } else {
-               cval = &asn_DEF_OCTET_STRING_constraints.value;
-               csiz = &asn_DEF_OCTET_STRING_constraints.size;
-       }
-       ct_extensible = csiz->flags & APC_EXTENSIBLE;
-
-       switch(specs->subvariant) {
-               default:
-                       /*         case ASN_OSUBV_ANY:
-                                        ASN__ENCODE_FAILED;
-                       */
-               case ASN_OSUBV_BIT:
-                       canonical_unit_bits = unit_bits = 1;
-                       bpc = OS__BPC_BIT;
-                       sizeinunits = st->size * 8 - (st->bits_unused & 0x07);
-                       ASN_DEBUG("BIT STRING of %d bytes",
-                                                               sizeinunits);
-               break;
-        case ASN_OSUBV_ANY:
-       case ASN_OSUBV_STR:
-               canonical_unit_bits = unit_bits = 8;
-/*             if(cval->flags & APC_CONSTRAINED)
-                       unit_bits = 8;
-*/
-               bpc = OS__BPC_CHAR;
-               sizeinunits = st->size;
-               break;
-       case ASN_OSUBV_U16:
-               canonical_unit_bits = unit_bits = 16;
-               if(cval->flags & APC_CONSTRAINED)
-                       unit_bits = cval->range_bits;
-               bpc = OS__BPC_U16;
-               sizeinunits = st->size / 2;
-               break;
-       case ASN_OSUBV_U32:
-               canonical_unit_bits = unit_bits = 32;
-               if(cval->flags & APC_CONSTRAINED)
-                       unit_bits = cval->range_bits;
-               bpc = OS__BPC_U32;
-               sizeinunits = st->size / 4;
-               break;
-       }
-
-       ASN_DEBUG("Encoding %s into %d units of %d bits"
-               " (%ld..%ld, effective %d)%s",
-               td->name, sizeinunits, unit_bits,
-               csiz->lower_bound, csiz->upper_bound,
-               csiz->effective_bits, ct_extensible ? " EXT" : "");
-
-       /* Figure out wheter size lies within PER visible constraint */
-
-       if(csiz->effective_bits >= 0) {
-               if((int)sizeinunits < csiz->lower_bound
-               || (int)sizeinunits > csiz->upper_bound) {
-                       if(ct_extensible) {
-                               cval = &asn_DEF_OCTET_STRING_constraints.value;
-                               csiz = &asn_DEF_OCTET_STRING_constraints.size;
-                               unit_bits = canonical_unit_bits;
-                               inext = 1;
-                       } else
-                               ASN__ENCODE_FAILED;
-               }
-       } else {
-               inext = 0;
-       }
-
-
-       if(ct_extensible) {
-               /* Declare whether length is [not] within extension root */
-               if(per_put_few_bits(po, inext, 1))
-                       ASN__ENCODE_FAILED;
-       }
-
-       /* X.691, #16.5: zero-length encoding */
-       /* X.691, #16.6: short fixed length encoding (up to 2 octets) */
-       /* X.691, #16.7: long fixed length encoding (up to 64K octets) */
-       if(csiz->effective_bits >= 0) {
-               ASN_DEBUG("Encoding %lu bytes (%ld), length in %d bits",
-                               st->size, sizeinunits - csiz->lower_bound,
-                               csiz->effective_bits);
-               if (csiz->effective_bits > 0) {
-                       ret = aper_put_length(po, csiz->upper_bound - csiz->lower_bound + 1, sizeinunits - csiz->lower_bound);
-                       if(ret) ASN__ENCODE_FAILED;
-               }
-               /* EB MOD
-                   AFAIU if lb != ub it is aligned whatever the number of bits */
-               if ((st->size > 2) || (csiz->lower_bound != csiz->upper_bound)) { /* X.691 #16.11 */
-                       if (aper_put_align(po) < 0)
-                               ASN__ENCODE_FAILED;
-               }
-               if(bpc) {
-                       ret = OCTET_STRING_per_put_characters(po, st->buf,
-                               sizeinunits, bpc, unit_bits,
-                               cval->lower_bound, cval->upper_bound, pc);
-               } else {
-                       ret = per_put_many_bits(po, st->buf,
-                               sizeinunits * unit_bits);
-               }
-               if(ret) ASN__ENCODE_FAILED;
-               ASN__ENCODED_OK(er);
-       }
-
-       ASN_DEBUG("Encoding %lu bytes", st->size);
-
-       if(sizeinunits == 0) {
-               if(aper_put_length(po, -1, 0))
-                       ASN__ENCODE_FAILED;
-               ASN__ENCODED_OK(er);
-       }
-
-       buf = st->buf;
-       while(sizeinunits) {
-               ssize_t maySave = aper_put_length(po, -1, sizeinunits);
-
-               if(maySave < 0) ASN__ENCODE_FAILED;
-
-               ASN_DEBUG("Encoding %ld of %ld",
-                       (long)maySave, (long)sizeinunits);
-
-               if(bpc) {
-                       ret = OCTET_STRING_per_put_characters(po, buf,
-                               maySave, bpc, unit_bits,
-                               cval->lower_bound, cval->upper_bound, pc);
-               } else {
-                       ret = per_put_many_bits(po, buf, maySave * unit_bits);
-               }
-               if(ret) ASN__ENCODE_FAILED;
-
-               if(bpc)
-                       buf += maySave * bpc;
-               else
-                       buf += maySave >> 3;
-               sizeinunits -= maySave;
-               assert(!(maySave & 0x07) || !sizeinunits);
-       }
-
-       ASN__ENCODED_OK(er);
-}
-
-#endif  /* ASN_DISABLE_PER_SUPPORT */
-
-int
-OCTET_STRING_print(const asn_TYPE_descriptor_t *td, const void *sptr,
-                   int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
-    const char * const h2c = "0123456789ABCDEF";
-       const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
-       char scratch[16 * 3 + 4];
-       char *p = scratch;
-       uint8_t *buf;
-       uint8_t *end;
-       size_t i;
-
-       (void)td;       /* Unused argument */
-
-       if(!st || (!st->buf && st->size))
-               return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
-
-       /*
-        * Dump the contents of the buffer in hexadecimal.
-        */
-       buf = st->buf;
-       end = buf + st->size;
-       for(i = 0; buf < end; buf++, i++) {
-               if(!(i % 16) && (i || st->size > 16)) {
-                       if(cb(scratch, p - scratch, app_key) < 0)
-                               return -1;
-                       _i_INDENT(1);
-                       p = scratch;
-               }
-               *p++ = h2c[(*buf >> 4) & 0x0F];
-               *p++ = h2c[*buf & 0x0F];
-               *p++ = 0x20;
-       }
-
-       if(p > scratch) {
-               p--;    /* Remove the tail space */
-               if(cb(scratch, p - scratch, app_key) < 0)
-                       return -1;
-       }
-
-       return 0;
-}
-
-int
-OCTET_STRING_print_utf8(const asn_TYPE_descriptor_t *td, const void *sptr,
-                        int ilevel, asn_app_consume_bytes_f *cb,
-                        void *app_key) {
-    const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
-
-       (void)td;       /* Unused argument */
-       (void)ilevel;   /* Unused argument */
-
-       if(st && (st->buf || !st->size)) {
-               return (cb(st->buf, st->size, app_key) < 0) ? -1 : 0;
-       } else {
-               return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
-       }
-}
-
-void
-OCTET_STRING_free(const asn_TYPE_descriptor_t *td, void *sptr,
-                  enum asn_struct_free_method method) {
-       OCTET_STRING_t *st = (OCTET_STRING_t *)sptr;
-       const asn_OCTET_STRING_specifics_t *specs;
-       asn_struct_ctx_t *ctx;
-       struct _stack *stck;
-
-       if(!td || !st)
-               return;
-
-       specs = td->specifics
-                   ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-                   : &asn_SPC_OCTET_STRING_specs;
-       ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset);
-
-       ASN_DEBUG("Freeing %s as OCTET STRING", td->name);
-
-       if(st->buf) {
-               FREEMEM(st->buf);
-               st->buf = 0;
-       }
-
-       /*
-        * Remove decode-time stack.
-        */
-       stck = (struct _stack *)ctx->ptr;
-       if(stck) {
-               while(stck->tail) {
-                       struct _stack_el *sel = stck->tail;
-                       stck->tail = sel->prev;
-                       FREEMEM(sel);
-               }
-               FREEMEM(stck);
-       }
-
-    switch(method) {
-    case ASFM_FREE_EVERYTHING:
-        FREEMEM(sptr);
-        break;
-    case ASFM_FREE_UNDERLYING:
-        break;
-    case ASFM_FREE_UNDERLYING_AND_RESET:
-        memset(sptr, 0,
-               td->specifics
-                   ? ((const asn_OCTET_STRING_specifics_t *)(td->specifics))
-                         ->struct_size
-                   : sizeof(OCTET_STRING_t));
-        break;
-    }
-}
-
-/*
- * Conversion routines.
- */
-int
-OCTET_STRING_fromBuf(OCTET_STRING_t *st, const char *str, int len) {
-       void *buf;
-
-       if(st == 0 || (str == 0 && len)) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       /*
-        * Clear the OCTET STRING.
-        */
-       if(str == NULL) {
-               FREEMEM(st->buf);
-               st->buf = 0;
-               st->size = 0;
-               return 0;
-       }
-
-       /* Determine the original string size, if not explicitly given */
-       if(len < 0)
-               len = strlen(str);
-
-       /* Allocate and fill the memory */
-       buf = MALLOC(len + 1);
-       if(buf == NULL)
-               return -1;
-
-       memcpy(buf, str, len);
-       ((uint8_t *)buf)[len] = '\0';   /* Couldn't use memcpy(len+1)! */
-       FREEMEM(st->buf);
-       st->buf = (uint8_t *)buf;
-       st->size = len;
-
-       return 0;
-}
-
-OCTET_STRING_t *
-OCTET_STRING_new_fromBuf(const asn_TYPE_descriptor_t *td, const char *str,
-                         int len) {
-    const asn_OCTET_STRING_specifics_t *specs =
-        td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-                      : &asn_SPC_OCTET_STRING_specs;
-    OCTET_STRING_t *st;
-
-       st = (OCTET_STRING_t *)CALLOC(1, specs->struct_size);
-       if(st && str && OCTET_STRING_fromBuf(st, str, len)) {
-               FREEMEM(st);
-               st = NULL;
-       }
-
-       return st;
-}
-
-/*
- * Lexicographically compare the common prefix of both strings,
- * and if it is the same return -1 for the smallest string.
- */
-int
-OCTET_STRING_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
-                     const void *bptr) {
-    const asn_OCTET_STRING_specifics_t *specs = td->specifics;
-    const OCTET_STRING_t *a = aptr;
-    const OCTET_STRING_t *b = bptr;
-
-    assert(!specs || specs->subvariant != ASN_OSUBV_BIT);
-
-    if(a && b) {
-        size_t common_prefix_size = a->size <= b->size ? a->size : b->size;
-        int ret = memcmp(a->buf, b->buf, common_prefix_size);
-        if(ret == 0) {
-            /* Figure out which string with equal prefixes is longer. */
-            if(a->size < b->size) {
-                return -1;
-            } else if(a->size > b->size) {
-                return 1;
-            } else {
-                return 0;
-            }
-        } else {
-            return ret < 0 ? -1 : 1;
-        }
-    } else if(!a && !b) {
-        return 0;
-    } else if(!a) {
-        return -1;
-    } else {
-        return 1;
-    }
-
-}
-
-/*
- * Biased function for randomizing character values around their limits.
- */
-static uint32_t
-OCTET_STRING__random_char(unsigned long lb, unsigned long ub) {
-    assert(lb <= ub);
-    switch(asn_random_between(0, 16)) {
-    case 0:
-        if(lb < ub) return lb + 1;
-        /* Fall through */
-    case 1:
-        return lb;
-    case 2:
-        if(lb < ub) return ub - 1;
-        /* Fall through */
-    case 3:
-        return ub;
-    default:
-        return asn_random_between(lb, ub);
-    }
-}
-
-
-size_t
-OCTET_STRING_random_length_constrained(
-    const asn_TYPE_descriptor_t *td,
-    const asn_encoding_constraints_t *constraints, size_t max_length) {
-    const unsigned lengths[] = {0,     1,     2,     3,     4,     8,
-                                126,   127,   128,   16383, 16384, 16385,
-                                65534, 65535, 65536, 65537};
-    size_t rnd_len;
-
-    /* Figure out how far we should go */
-    rnd_len = lengths[asn_random_between(
-        0, sizeof(lengths) / sizeof(lengths[0]) - 1)];
-
-    if(!constraints || !constraints->per_constraints)
-        constraints = &td->encoding_constraints;
-    if(constraints->per_constraints) {
-        const asn_per_constraint_t *pc = &constraints->per_constraints->size;
-        if(pc->flags & APC_CONSTRAINED) {
-            long suggested_upper_bound = pc->upper_bound < (ssize_t)max_length
-                                             ? pc->upper_bound
-                                             : (ssize_t)max_length;
-            if(max_length <= (size_t)pc->lower_bound) {
-                return pc->lower_bound;
-            }
-            if(pc->flags & APC_EXTENSIBLE) {
-                switch(asn_random_between(0, 5)) {
-                case 0:
-                    if(pc->lower_bound > 0) {
-                        rnd_len = pc->lower_bound - 1;
-                        break;
-                    }
-                    /* Fall through */
-                case 1:
-                    rnd_len = pc->upper_bound + 1;
-                    break;
-                case 2:
-                    /* Keep rnd_len from the table */
-                    if(rnd_len <= max_length) {
-                        break;
-                    }
-                    /* Fall through */
-                default:
-                    rnd_len = asn_random_between(pc->lower_bound,
-                                                 suggested_upper_bound);
-                }
-            } else {
-                rnd_len =
-                    asn_random_between(pc->lower_bound, suggested_upper_bound);
-            }
-        } else {
-            rnd_len = asn_random_between(0, max_length);
-        }
-    } else if(rnd_len > max_length) {
-        rnd_len = asn_random_between(0, max_length);
-    }
-
-    return rnd_len;
-}
-
-asn_random_fill_result_t
-OCTET_STRING_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
-                         const asn_encoding_constraints_t *constraints,
-                         size_t max_length) {
-       const asn_OCTET_STRING_specifics_t *specs = td->specifics
-                               ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-                               : &asn_SPC_OCTET_STRING_specs;
-    asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
-    asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
-    asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
-    unsigned int unit_bytes = 1;
-    unsigned long clb = 0;  /* Lower bound on char */
-    unsigned long cub = 255;  /* Higher bound on char value */
-    uint8_t *buf;
-    uint8_t *bend;
-    uint8_t *b;
-    size_t rnd_len;
-    OCTET_STRING_t *st;
-
-    if(max_length == 0 && !*sptr) return result_skipped;
-
-    switch(specs->subvariant) {
-    default:
-    case ASN_OSUBV_ANY:
-        return result_failed;
-    case ASN_OSUBV_BIT:
-        /* Handled by BIT_STRING itself. */
-        return result_failed;
-    case ASN_OSUBV_STR:
-        unit_bytes = 1;
-        clb = 0;
-        cub = 255;
-        break;
-    case ASN_OSUBV_U16:
-        unit_bytes = 2;
-        clb = 0;
-        cub = 65535;
-        break;
-    case ASN_OSUBV_U32:
-        unit_bytes = 4;
-        clb = 0;
-        cub = 0x10FFFF;
-        break;
-    }
-
-    if(!constraints || !constraints->per_constraints)
-        constraints = &td->encoding_constraints;
-    if(constraints->per_constraints) {
-        const asn_per_constraint_t *pc = &constraints->per_constraints->value;
-        if(pc->flags & APC_SEMI_CONSTRAINED) {
-            clb = pc->lower_bound;
-        } else if(pc->flags & APC_CONSTRAINED) {
-            clb = pc->lower_bound;
-            cub = pc->upper_bound;
-        }
-    }
-
-    rnd_len =
-        OCTET_STRING_random_length_constrained(td, constraints, max_length);
-
-    buf = CALLOC(unit_bytes, rnd_len + 1);
-    if(!buf) return result_failed;
-
-    bend = &buf[unit_bytes * rnd_len];
-
-    switch(unit_bytes) {
-    case 1:
-        for(b = buf; b < bend; b += unit_bytes) {
-            *(uint8_t *)b = OCTET_STRING__random_char(clb, cub);
-        }
-        *(uint8_t *)b = 0;
-        break;
-    case 2:
-        for(b = buf; b < bend; b += unit_bytes) {
-            uint32_t code = OCTET_STRING__random_char(clb, cub);
-            b[0] = code >> 8;
-            b[1] = code;
-        }
-        *(uint16_t *)b = 0;
-        break;
-    case 4:
-        for(b = buf; b < bend; b += unit_bytes) {
-            uint32_t code = OCTET_STRING__random_char(clb, cub);
-            b[0] = code >> 24;
-            b[1] = code >> 16;
-            b[2] = code >> 8;
-            b[3] = code;
-        }
-        *(uint32_t *)b = 0;
-        break;
-    }
-
-    if(*sptr) {
-        st = *sptr;
-        FREEMEM(st->buf);
-    } else {
-        st = (OCTET_STRING_t *)(*sptr = CALLOC(1, specs->struct_size));
-        if(!st) {
-            FREEMEM(buf);
-            return result_failed;
-        }
-    }
-
-    st->buf = buf;
-    st->size = unit_bytes * rnd_len;
-
-    result_ok.length = st->size;
-    return result_ok;
-}
diff --git a/src/codec_utils/E2AP/OCTET_STRING.h b/src/codec_utils/E2AP/OCTET_STRING.h
deleted file mode 100644 (file)
index c2f8bae..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*-
- * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
- * Redistribution and modifications are permitted subject to BSD license.
- */
-#ifndef        _OCTET_STRING_H_
-#define        _OCTET_STRING_H_
-
-#include <asn_application.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct OCTET_STRING {
-       uint8_t *buf;   /* Buffer with consecutive OCTET_STRING bits */
-       size_t size;    /* Size of the buffer */
-
-       asn_struct_ctx_t _asn_ctx;      /* Parsing across buffer boundaries */
-} OCTET_STRING_t;
-
-extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING;
-extern asn_TYPE_operation_t asn_OP_OCTET_STRING;
-
-asn_struct_free_f OCTET_STRING_free;
-asn_struct_print_f OCTET_STRING_print;
-asn_struct_print_f OCTET_STRING_print_utf8;
-asn_struct_compare_f OCTET_STRING_compare;
-ber_type_decoder_f OCTET_STRING_decode_ber;
-der_type_encoder_f OCTET_STRING_encode_der;
-xer_type_decoder_f OCTET_STRING_decode_xer_hex;                /* Hexadecimal */
-xer_type_decoder_f OCTET_STRING_decode_xer_binary;     /* 01010111010 */
-xer_type_decoder_f OCTET_STRING_decode_xer_utf8;       /* ASCII/UTF-8 */
-xer_type_encoder_f OCTET_STRING_encode_xer;
-xer_type_encoder_f OCTET_STRING_encode_xer_utf8;
-oer_type_decoder_f OCTET_STRING_decode_oer;
-oer_type_encoder_f OCTET_STRING_encode_oer;
-per_type_decoder_f OCTET_STRING_decode_uper;
-per_type_encoder_f OCTET_STRING_encode_uper;
-per_type_decoder_f OCTET_STRING_decode_aper;
-per_type_encoder_f OCTET_STRING_encode_aper;
-asn_random_fill_f  OCTET_STRING_random_fill;
-
-#define OCTET_STRING_constraint  asn_generic_no_constraint
-#define OCTET_STRING_decode_xer  OCTET_STRING_decode_xer_hex
-
-/******************************
- * Handy conversion routines. *
- ******************************/
-
-/*
- * This function clears the previous value of the OCTET STRING (if any)
- * and then allocates a new memory with the specified content (str/size).
- * If size = -1, the size of the original string will be determined
- * using strlen(str).
- * If str equals to NULL, the function will silently clear the
- * current contents of the OCTET STRING.
- * Returns 0 if it was possible to perform operation, -1 otherwise.
- */
-int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size);
-
-/* Handy conversion from the C string into the OCTET STRING. */
-#define        OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1)
-
-/*
- * Allocate and fill the new OCTET STRING and return a pointer to the newly
- * allocated object. NULL is permitted in str: the function will just allocate
- * empty OCTET STRING.
- */
-OCTET_STRING_t *OCTET_STRING_new_fromBuf(const asn_TYPE_descriptor_t *td,
-                                         const char *str, int size);
-
-/****************************
- * Internally useful stuff. *
- ****************************/
-
-typedef struct asn_OCTET_STRING_specifics_s {
-    /*
-     * Target structure description.
-     */
-    unsigned struct_size;   /* Size of the structure */
-    unsigned ctx_offset;    /* Offset of the asn_struct_ctx_t member */
-
-    enum asn_OS_Subvariant {
-        ASN_OSUBV_ANY, /* The open type (ANY) */
-        ASN_OSUBV_BIT, /* BIT STRING */
-        ASN_OSUBV_STR, /* String types, not {BMP,Universal}String  */
-        ASN_OSUBV_U16, /* 16-bit character (BMPString) */
-        ASN_OSUBV_U32  /* 32-bit character (UniversalString) */
-    } subvariant;
-} asn_OCTET_STRING_specifics_t;
-
-extern asn_OCTET_STRING_specifics_t asn_SPC_OCTET_STRING_specs;
-
-size_t OCTET_STRING_random_length_constrained(
-    const asn_TYPE_descriptor_t *, const asn_encoding_constraints_t *,
-    size_t max_length);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _OCTET_STRING_H_ */
diff --git a/src/codec_utils/E2AP/OCTET_STRING_oer.c b/src/codec_utils/E2AP/OCTET_STRING_oer.c
deleted file mode 100644 (file)
index c16faea..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
- * All rights reserved.
- * Redistribution and modifications are permitted subject to BSD license.
- */
-#ifndef ASN_DISABLE_OER_SUPPORT
-
-#include <asn_internal.h>
-#include <OCTET_STRING.h>
-#include <errno.h>
-
-asn_dec_rval_t
-OCTET_STRING_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
-                        const asn_TYPE_descriptor_t *td,
-                        const asn_oer_constraints_t *constraints, void **sptr,
-                        const void *ptr, size_t size) {
-    const asn_OCTET_STRING_specifics_t *specs =
-        td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-                      : &asn_SPC_OCTET_STRING_specs;
-    OCTET_STRING_t *st = (OCTET_STRING_t *)*sptr;
-    const asn_oer_constraints_t *cts =
-        constraints ? constraints : td->encoding_constraints.oer_constraints;
-    ssize_t ct_size = cts ? cts->size : -1;
-    asn_dec_rval_t rval = {RC_OK, 0};
-    size_t expected_length = 0;
-
-    size_t unit_bytes;
-    switch(specs->subvariant) {
-    default:
-    case ASN_OSUBV_BIT:
-        ASN_DEBUG("Invalid use of OCTET STRING to decode BIT STRING");
-        ASN__DECODE_FAILED;
-    case ASN_OSUBV_ANY:
-        /* Fall through */
-    case ASN_OSUBV_STR:
-        unit_bytes = 1;
-        break;
-    case ASN_OSUBV_U16:
-        unit_bytes = 2;
-        break;
-    case ASN_OSUBV_U32:
-        unit_bytes = 4;
-        break;
-    }
-
-    (void)opt_codec_ctx;
-
-    if(!st) {
-        st = (OCTET_STRING_t *)(*sptr = CALLOC(1, specs->struct_size));
-        if(!st) ASN__DECODE_FAILED;
-    }
-
-    if(ct_size >= 0) {
-        expected_length = unit_bytes * ct_size;
-    } else {
-        /*
-         * X.696 (08/2015) #27.2
-         * Encode length determinant as _number of octets_, but only
-         * if upper bound is not equal to lower bound.
-         */
-        ssize_t len_len = oer_fetch_length(ptr, size, &expected_length);
-        if(len_len > 0) {
-            rval.consumed = len_len;
-            ptr = (const char *)ptr + len_len;
-            size -= len_len;
-        } else if(len_len == 0) {
-            ASN__DECODE_STARVED;
-        } else if(len_len < 0) {
-            ASN__DECODE_FAILED;
-        }
-
-        if(expected_length % unit_bytes != 0) {
-            ASN_DEBUG(
-                "Data size %" ASN_PRI_SIZE " bytes is not consistent with multiplier %" ASN_PRI_SIZE "",
-                expected_length, unit_bytes);
-            ASN__DECODE_FAILED;
-        }
-    }
-
-    if(size < expected_length) {
-        ASN__DECODE_STARVED;
-    } else {
-        uint8_t *buf = MALLOC(expected_length + 1);
-        if(buf == NULL) {
-            ASN__DECODE_FAILED;
-        } else {
-            memcpy(buf, ptr, expected_length);
-            buf[expected_length] = '\0';
-        }
-        FREEMEM(st->buf);
-        st->buf = buf;
-        st->size = expected_length;
-
-        rval.consumed += expected_length;
-        return rval;
-    }
-}
-
-/*
- * Encode as Canonical OER.
- */
-asn_enc_rval_t
-OCTET_STRING_encode_oer(const asn_TYPE_descriptor_t *td,
-                        const asn_oer_constraints_t *constraints,
-                        const void *sptr, asn_app_consume_bytes_f *cb,
-                        void *app_key) {
-    const asn_OCTET_STRING_specifics_t *specs =
-        td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-                      : &asn_SPC_OCTET_STRING_specs;
-    const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
-    const asn_oer_constraints_t *cts =
-        constraints ? constraints : td->encoding_constraints.oer_constraints;
-    ssize_t ct_size = cts ? cts->size : -1;
-    asn_enc_rval_t er = {0, 0, 0};
-
-    if(!st) ASN__ENCODE_FAILED;
-
-    ASN_DEBUG("Encoding %s %" ASN_PRI_SIZE " as OCTET STRING", td ? td->name : "", st->size);
-
-    if(ct_size >= 0) {
-        /*
-         * Check that available data matches the constraint
-         */
-        size_t unit_bytes;
-        switch(specs->subvariant) {
-        default:
-        case ASN_OSUBV_BIT:
-            ASN_DEBUG("Invalid use of OCTET STRING to encode BIT STRING");
-            ASN__ENCODE_FAILED;
-        case ASN_OSUBV_ANY:
-            /* Fall through */
-        case ASN_OSUBV_STR:
-            unit_bytes = 1;
-            break;
-        case ASN_OSUBV_U16:
-            unit_bytes = 2;
-            break;
-        case ASN_OSUBV_U32:
-            unit_bytes = 4;
-            break;
-        }
-
-        if(st->size != unit_bytes * (size_t)ct_size) {
-            ASN_DEBUG(
-                "Trying to encode %s (%" ASN_PRI_SIZE " bytes) which doesn't fit SIZE "
-                "constraint (%" ASN_PRI_SIZE ")",
-                td->name, st->size, ct_size);
-            ASN__ENCODE_FAILED;
-        }
-    } else {
-        /*
-         * X.696 (08/2015) #27.2
-         * Encode length determinant as _number of octets_, but only
-         * if upper bound is not equal to lower bound.
-         */
-        ssize_t ret = oer_serialize_length(st->size, cb, app_key);
-        if(ret < 0) {
-            ASN__ENCODE_FAILED;
-        }
-        er.encoded += ret;
-    }
-
-    er.encoded += st->size;
-    if(cb(st->buf, st->size, app_key) < 0) {
-        ASN__ENCODE_FAILED;
-    } else {
-        ASN__ENCODED_OK(er);
-    }
-}
-
-#endif  /* ASN_DISABLE_OER_SUPPORT */
diff --git a/src/codec_utils/E2AP/per_encoder.c b/src/codec_utils/E2AP/per_encoder.c
deleted file mode 100644 (file)
index a35e1f0..0000000
+++ /dev/null
@@ -1,265 +0,0 @@
-#include <asn_application.h>
-#include <asn_internal.h>
-#include <per_encoder.h>
-
-static int _uper_encode_flush_outp(asn_per_outp_t *po);
-
-static int
-ignore_output(const void *data, size_t size, void *app_key) {
-    (void)data;
-    (void)size;
-    (void)app_key;
-    return 0;
-}
-
-asn_enc_rval_t
-uper_encode(const asn_TYPE_descriptor_t *td,
-            const asn_per_constraints_t *constraints, const void *sptr,
-            asn_app_consume_bytes_f *cb, void *app_key) {
-    asn_per_outp_t po;
-    asn_enc_rval_t er = {0,0,0};
-
-    /*
-     * Invoke type-specific encoder.
-     */
-    if(!td || !td->op->uper_encoder)
-        ASN__ENCODE_FAILED;    /* PER is not compiled in */
-
-    po.buffer = po.tmpspace;
-    po.nboff = 0;
-    po.nbits = 8 * sizeof(po.tmpspace);
-    po.output = cb ? cb : ignore_output;
-    po.op_key = app_key;
-    po.flushed_bytes = 0;
-
-    er = td->op->uper_encoder(td, constraints, sptr, &po);
-    if(er.encoded != -1) {
-        size_t bits_to_flush;
-
-        bits_to_flush = ((po.buffer - po.tmpspace) << 3) + po.nboff;
-
-        /* Set number of bits encoded to a firm value */
-        er.encoded = (po.flushed_bytes << 3) + bits_to_flush;
-
-        if(_uper_encode_flush_outp(&po)) ASN__ENCODE_FAILED;
-    }
-
-    return er;
-}
-
-/*
- * Argument type and callback necessary for uper_encode_to_buffer().
- */
-typedef struct enc_to_buf_arg {
-       void *buffer;
-       size_t left;
-} enc_to_buf_arg;
-static int encode_to_buffer_cb(const void *buffer, size_t size, void *key) {
-       enc_to_buf_arg *arg = (enc_to_buf_arg *)key;
-
-       if(arg->left < size)
-               return -1;      /* Data exceeds the available buffer size */
-
-       memcpy(arg->buffer, buffer, size);
-       arg->buffer = ((char *)arg->buffer) + size;
-       arg->left -= size;
-
-       return 0;
-}
-
-asn_enc_rval_t
-uper_encode_to_buffer(const asn_TYPE_descriptor_t *td,
-                      const asn_per_constraints_t *constraints,
-                      const void *sptr, void *buffer, size_t buffer_size) {
-    enc_to_buf_arg key;
-
-    key.buffer = buffer;
-    key.left = buffer_size;
-
-    if(td) ASN_DEBUG("Encoding \"%s\" using UNALIGNED PER", td->name);
-
-    return uper_encode(td, constraints, sptr, encode_to_buffer_cb, &key);
-}
-
-typedef struct enc_dyn_arg {
-       void *buffer;
-       size_t length;
-       size_t allocated;
-} enc_dyn_arg;
-static int
-encode_dyn_cb(const void *buffer, size_t size, void *key) {
-    enc_dyn_arg *arg = key;
-    if(arg->length + size >= arg->allocated) {
-        size_t new_size = arg->allocated ? arg->allocated : 8;
-        void *p;
-
-        do {
-            new_size <<= 2;
-        } while(arg->length + size >= new_size);
-
-        p = REALLOC(arg->buffer, new_size);
-        if(!p) {
-            FREEMEM(arg->buffer);
-            memset(arg, 0, sizeof(*arg));
-            return -1;
-        }
-        arg->buffer = p;
-        arg->allocated = new_size;
-    }
-    memcpy(((char *)arg->buffer) + arg->length, buffer, size);
-    arg->length += size;
-    return 0;
-}
-ssize_t
-uper_encode_to_new_buffer(const asn_TYPE_descriptor_t *td,
-                          const asn_per_constraints_t *constraints,
-                          const void *sptr, void **buffer_r) {
-    asn_enc_rval_t er = {0,0,0};
-       enc_dyn_arg key;
-
-       memset(&key, 0, sizeof(key));
-
-       er = uper_encode(td, constraints, sptr, encode_dyn_cb, &key);
-       switch(er.encoded) {
-       case -1:
-               FREEMEM(key.buffer);
-               return -1;
-       case 0:
-               FREEMEM(key.buffer);
-               key.buffer = MALLOC(1);
-               if(key.buffer) {
-                       *(char *)key.buffer = '\0';
-                       *buffer_r = key.buffer;
-                       return 1;
-               } else {
-                       return -1;
-               }
-       default:
-               *buffer_r = key.buffer;
-               ASN_DEBUG("Complete encoded in %ld bits", (long)er.encoded);
-               return ((er.encoded + 7) >> 3);
-       }
-}
-
-/*
- * Internally useful functions.
- */
-
-/* Flush partially filled buffer */
-static int
-_uper_encode_flush_outp(asn_per_outp_t *po) {
-       uint8_t *buf;
-
-       if(po->nboff == 0 && po->buffer == po->tmpspace)
-               return 0;
-
-       buf = po->buffer + (po->nboff >> 3);
-       /* Make sure we account for the last, partially filled */
-       if(po->nboff & 0x07) {
-               buf[0] &= 0xff << (8 - (po->nboff & 0x07));
-               buf++;
-       }
-
-       return po->output(po->tmpspace, buf - po->tmpspace, po->op_key);
-}
-
-asn_enc_rval_t
-aper_encode_to_buffer(const asn_TYPE_descriptor_t *td,
-                      const asn_per_constraints_t *constraints,
-                      const void *sptr, void *buffer, size_t buffer_size) {
-    enc_to_buf_arg key;
-
-    key.buffer = buffer;
-    key.left = buffer_size;
-
-    if(td) ASN_DEBUG("Encoding \"%s\" using ALIGNED PER", td->name);
-
-    return aper_encode(td, constraints, sptr, encode_to_buffer_cb, &key);
-}
-
-ssize_t
-aper_encode_to_new_buffer(const asn_TYPE_descriptor_t *td,
-                          const asn_per_constraints_t *constraints,
-                          const void *sptr, void **buffer_r) {
-    asn_enc_rval_t er = {0,0,0};
-       enc_dyn_arg key;
-
-       memset(&key, 0, sizeof(key));
-
-       er = aper_encode(td, constraints, sptr, encode_dyn_cb, &key);
-       switch(er.encoded) {
-       case -1:
-               FREEMEM(key.buffer);
-               return -1;
-       case 0:
-               FREEMEM(key.buffer);
-               key.buffer = MALLOC(1);
-               if(key.buffer) {
-                       *(char *)key.buffer = '\0';
-                       *buffer_r = key.buffer;
-                       return 1;
-               } else {
-                       return -1;
-               }
-       default:
-               *buffer_r = key.buffer;
-               ASN_DEBUG("Complete encoded in %ld bits", (long)er.encoded);
-               return ((er.encoded + 7) >> 3);
-       }
-}
-
-static int
-_aper_encode_flush_outp(asn_per_outp_t *po) {
-       uint8_t *buf;
-
-       if(po->nboff == 0 && po->buffer == po->tmpspace)
-               return 0;
-
-       buf = po->buffer + (po->nboff >> 3);
-       /* Make sure we account for the last, partially filled */
-       if(po->nboff & 0x07) {
-               buf[0] &= 0xff << (8 - (po->nboff & 0x07));
-               buf++;
-       }
-
-       if (po->output) {
-               return po->output(po->tmpspace, buf - po->tmpspace, po->op_key);
-       }
-       return 0;
-}
-
-asn_enc_rval_t
-aper_encode(const asn_TYPE_descriptor_t *td,
-        const asn_per_constraints_t *constraints,
-        const void *sptr, asn_app_consume_bytes_f *cb, void *app_key) {
-       asn_per_outp_t po;
-       asn_enc_rval_t er = {0,0,0};
-
-       /*
-        * Invoke type-specific encoder.
-        */
-       if(!td || !td->op->aper_encoder)
-               ASN__ENCODE_FAILED;      /* PER is not compiled in */
-
-       po.buffer = po.tmpspace;
-       po.nboff = 0;
-       po.nbits = 8 * sizeof(po.tmpspace);
-       po.output = cb;
-       po.op_key = app_key;
-       po.flushed_bytes = 0;
-
-       er = td->op->aper_encoder(td, constraints, sptr, &po);
-       if(er.encoded != -1) {
-               size_t bits_to_flush;
-
-               bits_to_flush = ((po.buffer - po.tmpspace) << 3) + po.nboff;
-
-               /* Set number of bits encoded to a firm value */
-               er.encoded = (po.flushed_bytes << 3) + bits_to_flush;
-
-               if(_aper_encode_flush_outp(&po))
-                       ASN__ENCODE_FAILED;
-       }
-
-       return er;
-}
diff --git a/src/codec_utils/F1AP/ANY.c b/src/codec_utils/F1AP/ANY.c
deleted file mode 100755 (executable)
index 0b81557..0000000
+++ /dev/null
@@ -1,450 +0,0 @@
-/*
- * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
- * Redistribution and modifications are permitted subject to BSD license.
- */
-#include <asn_internal.h>
-#include <ANY.h>
-#include <errno.h>
-
-asn_OCTET_STRING_specifics_t asn_SPC_ANY_specs = {
-       sizeof(ANY_t),
-       offsetof(ANY_t, _asn_ctx),
-       ASN_OSUBV_ANY
-};
-asn_TYPE_operation_t asn_OP_ANY = {
-       OCTET_STRING_free,
-       OCTET_STRING_print,
-       OCTET_STRING_compare,
-       OCTET_STRING_decode_ber,
-       OCTET_STRING_encode_der,
-       OCTET_STRING_decode_xer_hex,
-       ANY_encode_xer,
-#ifdef ASN_DISABLE_OER_SUPPORT
-       0,
-       0,
-#else
-       0,
-       0,
-#endif  /* ASN_DISABLE_OER_SUPPORT */
-#ifdef ASN_DISABLE_PER_SUPPORT
-       0, 0, 0, 0,
-#else
-       ANY_decode_uper,
-       ANY_encode_uper,
-       ANY_decode_aper,
-       ANY_encode_aper,
-#endif  /* ASN_DISABLE_PER_SUPPORT */
-       0,      /* Random fill is not defined for ANY type */
-       0       /* Use generic outmost tag fetcher */
-};
-asn_TYPE_descriptor_t asn_DEF_ANY = {
-       "ANY",
-       "ANY",
-       &asn_OP_ANY,
-       0, 0, 0, 0,
-       { 0, 0, asn_generic_no_constraint },    /* No constraints */
-       0, 0,   /* No members */
-       &asn_SPC_ANY_specs,
-};
-
-#undef RETURN
-#define RETURN(_code)                       \
-    do {                                    \
-        asn_dec_rval_t tmprval;             \
-        tmprval.code = _code;               \
-        tmprval.consumed = consumed_myself; \
-        return tmprval;                     \
-    } while(0)
-
-asn_enc_rval_t
-ANY_encode_xer(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
-               enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb,
-               void *app_key) {
-    if(flags & XER_F_CANONICAL) {
-               /*
-                * Canonical XER-encoding of ANY type is not supported.
-                */
-               ASN__ENCODE_FAILED;
-       }
-
-       /* Dump as binary */
-       return OCTET_STRING_encode_xer(td, sptr, ilevel, flags, cb, app_key);
-}
-
-struct _callback_arg {
-       uint8_t *buffer;
-       size_t offset;
-       size_t size;
-};
-
-static int ANY__consume_bytes(const void *buffer, size_t size, void *key);
-
-int
-ANY_fromType(ANY_t *st, asn_TYPE_descriptor_t *td, void *sptr) {
-       struct _callback_arg arg;
-       asn_enc_rval_t erval = {0,0,0};
-
-       if(!st || !td) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       if(!sptr) {
-               if(st->buf) FREEMEM(st->buf);
-               st->size = 0;
-               return 0;
-       }
-
-       arg.offset = arg.size = 0;
-       arg.buffer = 0;
-
-       erval = der_encode(td, sptr, ANY__consume_bytes, &arg);
-       if(erval.encoded == -1) {
-               if(arg.buffer) FREEMEM(arg.buffer);
-               return -1;
-       }
-       assert((size_t)erval.encoded == arg.offset);
-
-       if(st->buf) FREEMEM(st->buf);
-       st->buf = arg.buffer;
-       st->size = arg.offset;
-
-       return 0;
-}
-
-int
-ANY_fromType_aper(ANY_t *st, asn_TYPE_descriptor_t *td, void *sptr) {
-       uint8_t *buffer = NULL;
-       ssize_t erval;
-
-       if(!st || !td) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       if(!sptr) {
-               if(st->buf) FREEMEM(st->buf);
-               st->size = 0;
-               return 0;
-       }
-
-       erval = aper_encode_to_new_buffer(td, td->encoding_constraints.per_constraints, sptr, (void**)&buffer);
-
-       if(erval == -1) {
-               if(buffer) FREEMEM(buffer);
-               return -1;
-       }
-       assert((size_t)erval > 0);
-
-       if(st->buf) FREEMEM(st->buf);
-       st->buf = buffer;
-       st->size = erval;
-
-       return 0;
-}
-
-ANY_t *
-ANY_new_fromType(asn_TYPE_descriptor_t *td, void *sptr) {
-       ANY_t tmp;
-       ANY_t *st;
-
-       if(!td || !sptr) {
-               errno = EINVAL;
-               return 0;
-       }
-
-       memset(&tmp, 0, sizeof(tmp));
-
-       if(ANY_fromType(&tmp, td, sptr)) return 0;
-
-       st = (ANY_t *)CALLOC(1, sizeof(ANY_t));
-       if(st) {
-               *st = tmp;
-               return st;
-       } else {
-               FREEMEM(tmp.buf);
-               return 0;
-       }
-}
-
-ANY_t *
-ANY_new_fromType_aper(asn_TYPE_descriptor_t *td, void *sptr) {
-       ANY_t tmp;
-       ANY_t *st;
-
-       if(!td || !sptr) {
-               errno = EINVAL;
-               return 0;
-       }
-
-       memset(&tmp, 0, sizeof(tmp));
-
-       if(ANY_fromType_aper(&tmp, td, sptr)) return 0;
-
-       st = (ANY_t *)CALLOC(1, sizeof(ANY_t));
-       if(st) {
-               *st = tmp;
-               return st;
-       } else {
-               FREEMEM(tmp.buf);
-               return 0;
-       }
-}
-
-int
-ANY_to_type(ANY_t *st, asn_TYPE_descriptor_t *td, void **struct_ptr) {
-       asn_dec_rval_t rval;
-       void *newst = 0;
-
-       if(!st || !td || !struct_ptr) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       if(st->buf == 0) {
-               /* Nothing to convert, make it empty. */
-               *struct_ptr = (void *)0;
-               return 0;
-       }
-
-       rval = ber_decode(0, td, (void **)&newst, st->buf, st->size);
-       if(rval.code == RC_OK) {
-               *struct_ptr = newst;
-               return 0;
-       } else {
-               /* Remove possibly partially decoded data. */
-               ASN_STRUCT_FREE(*td, newst);
-               return -1;
-       }
-}
-
-int
-ANY_to_type_aper(ANY_t *st, asn_TYPE_descriptor_t *td, void **struct_ptr) {
-       asn_dec_rval_t rval;
-       void *newst = 0;
-
-       if(!st || !td || !struct_ptr) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       if(st->buf == 0) {
-               /* Nothing to convert, make it empty. */
-               *struct_ptr = (void *)0;
-               return 0;
-       }
-
-       rval = aper_decode(0, td, (void **)&newst, st->buf, st->size, 0, 0);
-       if(rval.code == RC_OK) {
-               *struct_ptr = newst;
-               return 0;
-       } else {
-               /* Remove possibly partially decoded data. */
-               ASN_STRUCT_FREE(*td, newst);
-               return -1;
-       }
-}
-
-static int ANY__consume_bytes(const void *buffer, size_t size, void *key) {
-       struct _callback_arg *arg = (struct _callback_arg *)key;
-
-       if((arg->offset + size) >= arg->size) {
-               size_t nsize = (arg->size ? arg->size << 2 : 16) + size;
-               void *p = REALLOC(arg->buffer, nsize);
-               if(!p) return -1;
-               arg->buffer = (uint8_t *)p;
-               arg->size = nsize;
-       }
-
-       memcpy(arg->buffer + arg->offset, buffer, size);
-       arg->offset += size;
-       assert(arg->offset < arg->size);
-
-       return 0;
-}
-
-#ifndef ASN_DISABLE_PER_SUPPORT
-
-asn_dec_rval_t
-ANY_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
-                const asn_TYPE_descriptor_t *td,
-                const asn_per_constraints_t *constraints, void **sptr,
-                asn_per_data_t *pd) {
-    const asn_OCTET_STRING_specifics_t *specs =
-        td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-                      : &asn_SPC_ANY_specs;
-    size_t consumed_myself = 0;
-    int repeat;
-    ANY_t *st = (ANY_t *)*sptr;
-
-    (void)opt_codec_ctx;
-    (void)constraints;
-
-    /*
-     * Allocate the structure.
-     */
-    if(!st) {
-        st = (ANY_t *)(*sptr = CALLOC(1, specs->struct_size));
-        if(!st) RETURN(RC_FAIL);
-    }
-
-    ASN_DEBUG("UPER Decoding ANY type");
-
-    st->size = 0;
-    do {
-        ssize_t raw_len;
-        ssize_t len_bytes;
-        ssize_t len_bits;
-        void *p;
-        int ret;
-
-        /* Get the PER length */
-        raw_len = uper_get_length(pd, -1, 0, &repeat);
-        if(raw_len < 0) RETURN(RC_WMORE);
-        if(raw_len == 0 && st->buf) break;
-
-        ASN_DEBUG("Got PER length len %" ASN_PRI_SIZE ", %s (%s)", raw_len,
-                  repeat ? "repeat" : "once", td->name);
-        len_bytes = raw_len;
-        len_bits = len_bytes * 8;
-
-        p = REALLOC(st->buf, st->size + len_bytes + 1);
-        if(!p) RETURN(RC_FAIL);
-        st->buf = (uint8_t *)p;
-
-        ret = per_get_many_bits(pd, &st->buf[st->size], 0, len_bits);
-        if(ret < 0) RETURN(RC_WMORE);
-        consumed_myself += len_bits;
-        st->size += len_bytes;
-    } while(repeat);
-    st->buf[st->size] = 0; /* nul-terminate */
-
-    RETURN(RC_OK);
-}
-
-asn_enc_rval_t
-ANY_encode_uper(const asn_TYPE_descriptor_t *td,
-                const asn_per_constraints_t *constraints, const void *sptr,
-                asn_per_outp_t *po) {
-    const ANY_t *st = (const ANY_t *)sptr;
-    asn_enc_rval_t er = {0, 0, 0};
-    const uint8_t *buf;
-    size_t size;
-    int ret;
-
-    (void)constraints;
-
-    if(!st || (!st->buf && st->size)) ASN__ENCODE_FAILED;
-
-    buf = st->buf;
-    size = st->size;
-    do {
-        int need_eom = 0;
-        ssize_t may_save = uper_put_length(po, size, &need_eom);
-        if(may_save < 0) ASN__ENCODE_FAILED;
-
-        ret = per_put_many_bits(po, buf, may_save * 8);
-        if(ret) ASN__ENCODE_FAILED;
-
-        buf += may_save;
-        size -= may_save;
-        assert(!(may_save & 0x07) || !size);
-        if(need_eom && uper_put_length(po, 0, 0))
-            ASN__ENCODE_FAILED; /* End of Message length */
-    } while(size);
-
-    ASN__ENCODED_OK(er);
-}
-
-asn_dec_rval_t
-ANY_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
-                const asn_TYPE_descriptor_t *td,
-                const asn_per_constraints_t *constraints, void **sptr,
-                asn_per_data_t *pd) {
-    const asn_OCTET_STRING_specifics_t *specs =
-        td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics
-                      : &asn_SPC_ANY_specs;
-    size_t consumed_myself = 0;
-    int repeat;
-    ANY_t *st = (ANY_t *)*sptr;
-
-    (void)opt_codec_ctx;
-    (void)constraints;
-
-    /*
-     * Allocate the structure.
-     */
-    if(!st) {
-        st = (ANY_t *)(*sptr = CALLOC(1, specs->struct_size));
-        if(!st) RETURN(RC_FAIL);
-    }
-
-    ASN_DEBUG("APER Decoding ANY type");
-
-    st->size = 0;
-    do {
-        ssize_t raw_len;
-        ssize_t len_bytes;
-        ssize_t len_bits;
-        void *p;
-        int ret;
-
-        /* Get the PER length */
-        raw_len = aper_get_length(pd, -1, 0, &repeat);
-        if(raw_len < 0) RETURN(RC_WMORE);
-        if(raw_len == 0 && st->buf) break;
-
-        ASN_DEBUG("Got PER length len %" ASN_PRI_SIZE ", %s (%s)", raw_len,
-                  repeat ? "repeat" : "once", td->name);
-        len_bytes = raw_len;
-        len_bits = len_bytes * 8;
-
-        p = REALLOC(st->buf, st->size + len_bytes + 1);
-        if(!p) RETURN(RC_FAIL);
-        st->buf = (uint8_t *)p;
-
-        ret = per_get_many_bits(pd, &st->buf[st->size], 0, len_bits);
-        if(ret < 0) RETURN(RC_WMORE);
-        consumed_myself += len_bits;
-        st->size += len_bytes;
-    } while(repeat);
-    st->buf[st->size] = 0; /* nul-terminate */
-
-    RETURN(RC_OK);
-}
-
-asn_enc_rval_t
-ANY_encode_aper(const asn_TYPE_descriptor_t *td,
-                const asn_per_constraints_t *constraints, const void *sptr,
-                asn_per_outp_t *po) {
-    const ANY_t *st = (const ANY_t *)sptr;
-    asn_enc_rval_t er = {0, 0, 0};
-    const uint8_t *buf;
-    size_t size;
-    int ret;
-
-    (void)constraints;
-
-    if(!st || (!st->buf && st->size)) ASN__ENCODE_FAILED;
-
-    buf = st->buf;
-    size = st->size;
-    do {
-        int need_eom = 0;
-        ssize_t may_save = uper_put_length(po, size, &need_eom);
-        if(may_save < 0) ASN__ENCODE_FAILED;
-
-        ret = per_put_many_bits(po, buf, may_save * 8);
-        if(ret) ASN__ENCODE_FAILED;
-
-        buf += may_save;
-        size -= may_save;
-        assert(!(may_save & 0x07) || !size);
-        if(need_eom && uper_put_length(po, 0, 0))
-            ASN__ENCODE_FAILED; /* End of Message length */
-    } while(size);
-
-    ASN__ENCODED_OK(er);
-}
-#endif /* ASN_DISABLE_PER_SUPPORT */
-
diff --git a/src/codec_utils/F1AP/ANY.h b/src/codec_utils/F1AP/ANY.h
deleted file mode 100755 (executable)
index b30381f..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
- * Redistribution and modifications are permitted subject to BSD license.
- */
-#ifndef ASN_TYPE_ANY_H
-#define ASN_TYPE_ANY_H
-
-#include <OCTET_STRING.h>      /* Implemented via OCTET STRING type */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct ANY {
-       uint8_t *buf;   /* BER-encoded ANY contents */
-       int size;       /* Size of the above buffer */
-
-       asn_struct_ctx_t _asn_ctx;      /* Parsing across buffer boundaries */
-} ANY_t;
-
-extern asn_TYPE_descriptor_t asn_DEF_ANY;
-extern asn_TYPE_operation_t asn_OP_ANY;
-extern asn_OCTET_STRING_specifics_t asn_SPC_ANY_specs;
-
-asn_struct_free_f ANY_free;
-asn_struct_print_f ANY_print;
-ber_type_decoder_f ANY_decode_ber;
-der_type_encoder_f ANY_encode_der;
-xer_type_encoder_f ANY_encode_xer;
-per_type_decoder_f ANY_decode_uper;
-per_type_encoder_f ANY_encode_uper;
-per_type_decoder_f ANY_decode_aper;
-per_type_encoder_f ANY_encode_aper;
-
-#define ANY_free         OCTET_STRING_free
-#define ANY_print        OCTET_STRING_print
-#define ANY_compare      OCTET_STRING_compare
-#define ANY_constraint   asn_generic_no_constraint
-#define ANY_decode_ber   OCTET_STRING_decode_ber
-#define ANY_encode_der   OCTET_STRING_encode_der
-#define ANY_decode_xer   OCTET_STRING_decode_xer_hex
-
-/******************************
- * Handy conversion routines. *
- ******************************/
-
-/* Convert another ASN.1 type into the ANY. This implies DER encoding. */
-int ANY_fromType(ANY_t *, asn_TYPE_descriptor_t *td, void *struct_ptr);
-int ANY_fromType_aper(ANY_t *st, asn_TYPE_descriptor_t *td, void *sptr);
-ANY_t *ANY_new_fromType(asn_TYPE_descriptor_t *td, void *struct_ptr);
-ANY_t *ANY_new_fromType_aper(asn_TYPE_descriptor_t *td, void *sptr);
-
-/* Convert the contents of the ANY type into the specified type. */
-int ANY_to_type(ANY_t *, asn_TYPE_descriptor_t *td, void **struct_ptr);
-int ANY_to_type_aper(ANY_t *, asn_TYPE_descriptor_t *td, void **struct_ptr);
-
-#define        ANY_fromBuf(s, buf, size)       OCTET_STRING_fromBuf((s), (buf), (size))
-#define        ANY_new_fromBuf(buf, size)      OCTET_STRING_new_fromBuf(       \
-                                               &asn_DEF_ANY, (buf), (size))
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* ASN_TYPE_ANY_H */
old mode 100755 (executable)
new mode 100644 (file)
index 432ce5a..ae34c96
@@ -157,7 +157,7 @@ OS__add_stack_el(struct _stack *st) {
                nel = (struct _stack_el *)CALLOC(1, sizeof(struct _stack_el));
                if(nel == NULL)
                        return NULL;
-       
+
                if(st->tail) {
                        /* Increase a subcontainment depth */
                        nel->cont_level = st->tail->cont_level + 1;
@@ -745,7 +745,7 @@ OCTET_STRING__handle_control_chars(void *struct_ptr, const void *chunk_buf, size
                        return 0;
                }
        }
-       
+
        return -1;      /* No, it's not */
 }
 
@@ -1956,7 +1956,9 @@ OCTET_STRING_encode_aper(const asn_TYPE_descriptor_t *td,
                        ret = aper_put_length(po, csiz->upper_bound - csiz->lower_bound + 1, sizeinunits - csiz->lower_bound);
                        if(ret) ASN__ENCODE_FAILED;
                }
-               if (st->size > 2) { /* X.691 #16 NOTE 1 */
+               /* EB MOD
+                   AFAIU if lb != ub it is aligned whatever the number of bits */
+               if ((st->size > 2) || (csiz->lower_bound != csiz->upper_bound)) { /* X.691 #16.11 */
                        if (aper_put_align(po) < 0)
                                ASN__ENCODE_FAILED;
                }
index 0f850d2..c4105ad 100644 (file)
@@ -73,15 +73,7 @@ void CC_PRINTFLIKE(1, 2) ASN_DEBUG_f(const char *fmt, ...);
 #endif /* C99 */
 #else  /* ASN_EMIT_DEBUG != 1 */
 #if __STDC_VERSION__ >= 199901L
-#if 1
 #define ASN_DEBUG(...) do{}while(0)
-#else
-#define        ASN_DEBUG(fmt, args...) do {                    \
-               fprintf(stderr, fmt, ##args);           \
-               fprintf(stderr, " (%s:%d)\n",           \
-                       __FILE__, __LINE__);            \
-  } while(0)
-#endif
 #else   /* not C99 */
 static void CC_PRINTFLIKE(1, 2) ASN_DEBUG(const char *fmt, ...) { (void)fmt; }
 #endif  /* C99 or better */
diff --git a/src/codec_utils/common/odu_common_codec.c b/src/codec_utils/common/odu_common_codec.c
new file mode 100644 (file)
index 0000000..5f52c25
--- /dev/null
@@ -0,0 +1,77 @@
+#include "odu_common_codec.h"
+
+/*******************************************************************
+ *
+ * @brief Builds PLMN ID 
+ *
+ * @details
+ *
+ *    Function : plmnBuildId
+ *
+ *    Functionality: Building the PLMN ID
+ *
+ * @params[in] PLMNID plmn
+ *             OCTET_STRING_t *octe
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+S16 buildPlmnId(Plmn plmn, OCTET_STRING_t *octe)
+{
+   U8 mncCnt;
+   mncCnt = 2;
+   octe->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
+   if(mncCnt == 2)
+   {
+      octe->buf[1]  = ((0xf0) | (plmn.mcc[2]));
+      octe->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
+   }
+   else
+   {
+      octe->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
+      octe->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
+   }
+   RETVALUE(ROK);
+}
+
+/*******************************************************************
+ *
+ * @brief Fills the RicId
+ *
+ * @details
+ *
+ *    Function : FillRicId
+ *
+ *    Functionality: Fills the RicId
+ *
+ * @params[in] BIT_STRING_t *nbid,
+ *             U8 unusedBits
+ *             U8 byteSize
+ *             U8 val
+ *
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+
+S16 fillBitString(BIT_STRING_t *id, U8 unusedBits, U8 byteSize, U8 val)
+{
+   U8 tmp;
+   if(id->buf == NULLP)
+   {
+      RETVALUE(RFAILED);
+   }
+
+   for (tmp = 0 ; tmp < (byteSize-1); tmp++)
+   {
+      id->buf[tmp] = tmp;
+   }
+   id->buf[byteSize-1]   = val;
+   id->bits_unused = unusedBits;
+   RETVALUE(ROK);
+}
+
+
+/**********************************************************************
+  End of file
+ **********************************************************************/
index 36f5702..4d16da3 100644 (file)
 #ifndef __ODU_COMMON_CODEC_H__
 #define __ODU_COMMON_CODEC_H__
 
+#include "envopt.h"        /* Environment options */
+#include "envdep.h"        /* Environment dependent */
+#include "envind.h"        /* Environment independent */
+
+#include "gen.h"           /* General */
+#include "gen.x"           /* General */
+#include "ssi.h"
+#include "OCTET_STRING.h"
+#include "BIT_STRING.h"
 #include "asn_codecs.h"
 
 #define ENC_BUF_MAX_LEN 200
 #define ENCODE_FAIL -1
 
+typedef struct PlmnIdentity 
+{
+   uint8_t mcc[3];
+   uint8_t mnc[3];
+}Plmn;
+
+S16 buildPlmnId(Plmn plmn, OCTET_STRING_t *octe);
+S16 fillBitString(BIT_STRING_t *id, U8 unusedBits, U8 byteSize, U8 val);
+
 char encBuf[ENC_BUF_MAX_LEN];
 int  encBufSize;
 
index 4313f69..a7ce195 100644 (file)
 #include "cu_stub_sctp.h"
 #include "cu_f1ap_msg_hdl.h"
 
-char encBuf[ENC_BUF_MAX_LEN];
-
-/*******************************************************************
- *
- * @brief Writes the encoded chunks into a buffer
- *
- * @details
- *
- *    Function : PrepFinalEncBuf 
- *
- *    Functionality:Fills the encoded buffer
- *
- * @params[in] void *buffer,initial encoded data
- * @params[in] size_t size,size of buffer
- * @params[in] void *encodedBuf,final buffer
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-static int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf)
-{
-   memcpy(encodedBuf + encBufSize, buffer, size);
-   encBufSize += size;
-   return 0;
-} /* PrepFinalEncBuf */
-
 /*******************************************************************
 *
 * @brief Sends F1 msg over SCTP
@@ -97,24 +71,6 @@ S16 SendF1APMsg(Region region, Pool pool)
    RETVALUE(ROK);
 } /* SendF1APMsg */
 
-
-void plmnBuildCU(Plmn plmn, OCTET_STRING_t *octe)
-{
-   U8 mncCnt;
-   mncCnt = 2;
-   octe->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
-   if(mncCnt == 2)
-   {
-      octe->buf[1]  = ((0xf0) | (plmn.mcc[2]));
-      octe->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
-   }
-   else
-   {
-      octe->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
-      octe->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
-   }
-}
-
 /*******************************************************************
 *
 * @brief Builds NRCell ID 
@@ -347,7 +303,7 @@ S16 BuildAndSendF1SetupRsp()
       CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
       RETVALUE(RFAILED);
    }
-    plmnBuildCU(cuCfgParams.plmn , &cellToActivate->list.array[0]->value.choice.\
+    buildPlmnId(cuCfgParams.plmn , &cellToActivate->list.array[0]->value.choice.\
          Cells_to_be_Activated_List_Item.nRCGI.pLMN_Identity);
    cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
       nRCGI.nRCellIdentity.size = 5;
@@ -1052,7 +1008,7 @@ void F1APMsgHdlr(Buffer *mBuf)
             {
                DU_LOG("\nF1AP : F1 setup request received");
                BuildAndSendF1SetupRsp();
-                                 break;
+              break;
             }
 
             case InitiatingMessage__value_PR_GNBDUConfigurationUpdate:
index 7991de6..d213a90 100644 (file)
@@ -75,9 +75,6 @@
 
 
 
-extern char encBuf[ENC_BUF_MAX_LEN];
-int  encBufSize;
-
 void F1APMsgHdlr(Buffer *mBuf);
 
 /**********************************************************************
index d87c10c..62a465c 100644 (file)
@@ -47,6 +47,7 @@
 #include "cm_inet.x"
 #include "cm_llist.x"      /* Common link list  defines  */
 #include "cm_hash.x"       /* Common hashlist  defines */
+#include "odu_common_codec.h"
 
 #include "du_log.h"
 #define MAX_IPV6_LEN 16
@@ -89,12 +90,6 @@ typedef struct RrcVersion
   U32   extRrcVer;  /* Latest RRC version extended */
 }RrcVersion;
 
-typedef struct
-{
-   U8 f1Itf;
-   U8 e2Itf;
-}ItfType;
-
 typedef struct egtpParams
 {
    SctpIpAddr  localIp;
@@ -105,28 +100,20 @@ typedef struct egtpParams
    U32       maxTunnelId;
 }EgtpParams;
 
-typedef struct sctpParamsCu
+typedef struct CuSctpParams
 {
    SctpIpAddr  duIpAddr;
    U16         duPort;
    SctpIpAddr  cuIpAddr;
    U16         cuPort;
-   ItfType     itfType;
-}SctpParamsCu;
-
-typedef struct fPLMN
-{
-   U8 mcc[3];
-   U8 mnc[3];
-}Plmn;
-
+}CuSctpParams;
 
 typedef struct cuCfgParams
 {
    U32              cuId;
    char             cuName[CU_DU_NAME_LEN_MAX];
-   SctpParamsCu     sctpParams;
-   Plmn            plmn;
+   CuSctpParams     sctpParams;
+   Plmn             plmn;
    EgtpParams       egtpParams;
    RrcVersion       rrcVersion;
 }CuCfgParams;
index 8c36c12..c23a30e 100644 (file)
@@ -103,14 +103,11 @@ S16 sctpCfgReq()
    f1Params.destPort             = sctpCfg.duPort;
    f1Params.srcPort              = sctpCfg.cuPort;
    f1Params.bReadFdSet           = ROK;
-   cmMemset ((U8 *)&f1Params.sockFd, -1, sizeof(CmInetFd));
-   cmMemset ((U8 *)&f1Params.lstnSockFd, -1, sizeof(CmInetFd));
+   memset(&f1Params.sockFd, -1, sizeof(CmInetFd));
+   memset(&f1Params.lstnSockFd, -1, sizeof(CmInetFd));
    fillDestNetAddr(&f1Params.destIpNetAddr, &sctpCfg.duIpAddr);
 
-/* Set polling to FALSE */
-   pollingState = FALSE;  
-
- RETVALUE(ROK);
+   RETVALUE(ROK);
 }
 
 
@@ -225,7 +222,7 @@ S16 sctpStartReq()
  * ****************************************************************/
 S16 sctpSetSockOpts(CmInetFd *sock_Fd)
 {
-   S16  ret = ROK;
+   S16 ret = ROK;
    CmSctpEvent sctpEvent;
   
    sctpEvent.dataIoEvent          = TRUE;
@@ -265,6 +262,7 @@ S16 sctpSetSockOpts(CmInetFd *sock_Fd)
 S16 sctpAccept(CmInetFd *lstnSock_Fd, CmInetAddr *peerAddr, CmInetFd *sock_Fd)
 {
    U8  ret;
+
    ret = cmInetListen(lstnSock_Fd, 1);
    if (ret != ROK)
    {
@@ -470,12 +468,12 @@ S16 sctpSockPoll()
  *         RFAILED - failure
  *
  * ****************************************************************/
-  
+
 S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, U32 *timeoutPtr, CmInetMemInfo *memInfo)
 {
    U16 ret = ROK;
    CM_INET_FD_SET(sockFd, &pollParams->readFd);
-   ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &pollParams->numFds);
+   ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &pollParams->numFd);
    if(CM_INET_FD_ISSET(sockFd, &pollParams->readFd))
    {
       CM_INET_FD_CLR(sockFd, &pollParams->readFd);
index 5102cc7..7e17fcf 100644 (file)
@@ -29,9 +29,6 @@
 #include "cm_tpt.x"
 
 #define MAX_RETRY 5
-#define DU_SCTP_DOWN 0
-#define DU_SCTP_UP 1
-#define DU_SCTP_CONNECTING 2
 
 /* Global variable declaration */
 U8   socket_type;      /* Socket type */
@@ -39,11 +36,11 @@ Bool nonblocking;      /* Blocking/Non-blocking socket */
 Bool connUp;           /* Is connection up */
 int  assocId;          /* Assoc Id of connected assoc */
   
-SctpParamsCu sctpCfg;            /* SCTP configurations at DU */
-Bool pollingState; 
+CuSctpParams sctpCfg;            /* SCTP configurations at DU */
+
 typedef struct
 {
-   S16           numFds;
+   S16           numFd;
    U16           port;   
    U32           flag;
    Buffer        *mBuf;
index 3940f86..1f9a6e3 100644 (file)
@@ -29,7 +29,6 @@
 
 S16 procF1SetupRsp(F1AP_PDU_t *f1apMsg);
 S16 procCellsToBeActivated(Cells_to_be_Activated_List_t cellsToBeActivated);
-S16 procE2SetupRsp(E2AP_PDU_t *e2apMsg);
 S16 duSendSchGnbCfg();
 S16 duSendSchGnbCfgToMac(RgrCfgReqInfo *cfgReq, U32 trans_id);
 #endif
index 91ecd45..395c1ce 100644 (file)
@@ -22,7 +22,7 @@
 #include "stdbool.h"
 #include "du_app_mac_inf.h"
 #include "du_log.h"
-#include "BIT_STRING.h"
+#include "odu_common_codec.h"
 
 /* MACROS */
 #define DU_INST 0
@@ -47,6 +47,7 @@
 #define PLMN_MNC0 4
 #define PLMN_MNC1 8
 #define PLMN_MNC2 0
+#define PLMN_SIZE 3
 #define NR_ARFCN  2079427
 #define SUL_ARFCN 100
 #define NR_FREQ_BAND 257
@@ -393,15 +394,9 @@ typedef struct f1ResetType
    }type;
 }F1ResetType;
 
-typedef struct f1PLMN
-{
-  uint8_t mcc[3];
-  uint8_t mnc[3];
-}PlmnId;
-
 typedef struct nrEcgi
 {
-  PlmnId  plmn;
+  Plmn  plmn;
   uint16_t     cellId;
 }NrEcgi;
 
@@ -505,14 +500,14 @@ typedef struct f1TaiSliceSuppLst
 
 typedef struct f1SrvdPlmn
 {
-   PlmnId              plmn;
+   Plmn              plmn;
    F1TaiSliceSuppLst   taiSliceSuppLst;
 }F1SrvdPlmn;
 
 typedef struct f1BrdcstPlmnInfo
 {
-   PlmnId   plmn[MAX_PLMN];     /* PLMN id list */
-   PlmnId   extPlmn[MAX_PLMN];   /* Extended PLMN id list */
+   Plmn   plmn[MAX_PLMN];     /* PLMN id list */
+   Plmn   extPlmn[MAX_PLMN];   /* Extended PLMN id list */
    uint16_t      tac;                     /* 5GS-TAC */
    uint32_t      nrCellId;                /* NR Cell id */
    uint8_t       ranac;                   /* RAN Area code */
@@ -522,8 +517,8 @@ typedef struct f1CellInfo
 {
    NrEcgi   nrCgi;                   /* Cell global Identity */
    uint32_t      nrPci;                   /* Physical Cell Identity */
-   PlmnId   plmn[MAX_PLMN];     /* Available PLMN list */
-   PlmnId   extPlmn[MAX_PLMN];  /* Extended available PLMN list */
+   Plmn   plmn[MAX_PLMN];     /* Available PLMN list */
+   Plmn   extPlmn[MAX_PLMN];  /* Extended available PLMN list */
 }F1CellInfo;
 
 typedef struct f1DuCellInfo
@@ -666,7 +661,7 @@ typedef struct f1UacType
 /* Unified Access Class Assistance Information */
 typedef struct f1UacAssistInfo
 {
-   PlmnId      plmn[MAXNUMOFUACPLMN];        /* UAC PLMN list */
+   Plmn      plmn[MAXNUMOFUACPLMN];        /* UAC PLMN list */
    F1UacType   uacType[MAXNUMOFUACPERPLMN];  /* UAC Type list */
 }F1UacAssistInfo;
 
@@ -889,7 +884,7 @@ typedef struct mibParams
 
 typedef struct sib1Params
 {
-       PlmnId    plmn;
+       Plmn    plmn;
        uint8_t   tac;
        long      ranac;
        uint8_t   cellIdentity;
@@ -898,18 +893,17 @@ typedef struct sib1Params
 
 typedef struct duCfgParams
 {
-   SctpParams         sctpParams;                    /* SCTP Params */
-   F1EgtpParams       egtpParams;                    /* EGTP Params */
+   SctpParams         sctpParams;                  /* SCTP Params */
+   F1EgtpParams       egtpParams;                  /* EGTP Params */
    uint32_t           maxUe;
    uint32_t           duId;
    uint8_t            duName[CU_DU_NAME_LEN_MAX];
    SchedulerCfg       schedCfg;
-   F1DuSrvdCellInfo   srvdCellLst[DU_MAX_CELLS];   /* Serving cell list *///TODO: this must be removed eventually
-   F1RrcVersion       rrcVersion;                    /* RRC version */
-
-   MacCellCfg        macCellCfg;       /* MAC cell configuration */
-   MibParams          mibParams;                     /* MIB Params */
-       Sib1Params         sib1Params;                    /* SIB1 Params */
+   F1DuSrvdCellInfo   srvdCellLst[DU_MAX_CELLS];  /* Serving cell list *///TODO: this must be removed eventually
+   F1RrcVersion       rrcVersion;                 /* RRC version */
+   MacCellCfg         macCellCfg;                    /* MAC cell configuration */
+   MibParams          mibParams;                  /* MIB Params */
+   Sib1Params         sib1Params;                 /* SIB1 Params */
 }DuCfgParams;
 
 /*function declarations */
index 4ee88c6..26dfbce 100644 (file)
 
 /* Global variable */
 DuCfgParams duCfgParam;
-char encBuf[ENC_BUF_MAX_LEN];
-int  encBufSize;
-
-/*******************************************************************
- *
- * @brief Writes the encoded chunks into a buffer
- *
- * @details
- *
- *    Function : PrepFinalEncBuf
- *
- *    Functionality:Fills the encoded buffer
- *
- * @params[in] void *buffer,initial encoded data
- * @params[in] size_t size,size of buffer
- * @params[in] void *encodedBuf,final buffer
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-static int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf)
-{
-   memcpy(encodedBuf + encBufSize, buffer, size);
-   encBufSize += size;
-   return 0;
-} /* PrepFinalEncBuf */
-
-/*******************************************************************
- *
- * @brief Builds PLMN ID 
- *
- * @details
- *
- *    Function : BuildPlmnId
- *
- *    Functionality: Building the PLMN ID
- *
- * @params[in] PLMNID plmn
- *             OCTET_STRING_t *plmnid
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-
-S16 BuildPlmnId(PlmnId plmn, OCTET_STRING_t *plmnid)
-{
-   U8 mncCnt;
-   plmnid->size = 3;
-   DU_ALLOC(plmnid->buf,  plmnid->size * sizeof(U8));
-   if(plmnid->buf == NULLP)
-   {
-      RETVALUE(RFAILED);
-   }
-   mncCnt = 2;
-   plmnid->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
-   if(mncCnt == 2)
-   {
-      plmnid->buf[1]  = ((0xf0) | (plmn.mcc[2]));
-      plmnid->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
-   }
-   else
-   {
-      plmnid->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
-      plmnid->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
-   }
-  RETVALUE(ROK);
-}
-
-/*******************************************************************
- *
- * @brief Builds NodeB Id
- *
- * @details
- *
- *    Function : BuildNodeBId
- *
- *    Functionality: Building the NodeBId
- *
- * @params[in] BIT_STRING_t *nbid,
- *             U8 unusedBits
- *             U8 byteSize
- *             U8 val
- *
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-
-S16 BuildNodeBId(BIT_STRING_t *nbid, U8 unusedBits, U8 byteSize, U8 val)
-{
-   U8 tmp;
-   nbid->size = byteSize;
-   DU_ALLOC(nbid->buf, nbid->size * sizeof(U8));
-   if(nbid->buf == NULLP)
-   {
-      RETVALUE(RFAILED);
-   }
-
-   for (tmp = 0 ; tmp < ((nbid->size)-1); tmp++)
-   {
-      nbid->buf[tmp] = 0;
-   }
-   nbid->buf[byteSize-1] = val; 
-   nbid->bits_unused = unusedBits;
-   RETVALUE(ROK);
-}
 
 /*******************************************************************
  *
@@ -153,13 +47,20 @@ S16 BuildGlobalgNB(GlobalE2node_gNB_ID_t *gNbId)
    U8 val = 1;
    if(gNbId != NULLP)
    {
-      BuildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
+      /* Allocate Buffer size */ 
+      gNbId->global_gNB_ID.plmn_id.size = 3 * sizeof(U8);
+      DU_ALLOC(gNbId->global_gNB_ID.plmn_id.buf , gNbId->global_gNB_ID.plmn_id.size);
+      buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
        &gNbId->global_gNB_ID.plmn_id); 
+
       /* fill gND Id */
-      gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID; 
-      BuildNodeBId(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, val);
+      gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
+      /* Allocate Buffer size */ 
+      gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = byteSize * sizeof(U8);
+      DU_ALLOC(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf, gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
+      fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, val);
    }
-   RETVALUE(ROK);   
+   return ROK;   
 }
 
 /*******************************************************************
@@ -193,7 +94,7 @@ S16 BuildAndSendE2SetupReq()
    if(e2apMsg == NULLP)
    {
       DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
 
    e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
@@ -202,7 +103,7 @@ S16 BuildAndSendE2SetupReq()
    {
       DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
       DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
    e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2setup;
@@ -224,7 +125,7 @@ S16 BuildAndSendE2SetupReq()
       DU_LOG("\nE2AP : Memory allocation for E2RequestIEs failed");
       DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
       DU_FREE(e2apMsg, (Size)sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    
    for(idx=0; idx<elementCnt; idx++)
@@ -243,7 +144,7 @@ S16 BuildAndSendE2SetupReq()
          DU_FREE(e2apMsg->choice.initiatingMessage, \
                sizeof(InitiatingMessageE2_t));
          DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
-         RETVALUE(RFAILED);
+         return RFAILED;
       }
    }
 
@@ -273,7 +174,7 @@ S16 BuildAndSendE2SetupReq()
    {
           DU_LOG("\nE2AP : Could not encode E2SetupRequest structure (at %s)\n",\
                           encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
-          RETVALUE(RFAILED);
+          return RFAILED;
    }
    else
    {
@@ -287,10 +188,10 @@ S16 BuildAndSendE2SetupReq()
    if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
    {
           DU_LOG("\nE2AP : Sending E2 Setup request failed");
-          RETVALUE(RFAILED);
+          return RFAILED;
    }
 
-   RETVALUE(ROK);
+   return ROK;
 }/* End of BuildAndSendE2SetupReq */
 
 /*******************************************************************
@@ -316,7 +217,7 @@ S16 BuildRicRequestId(RICrequestID_t *ricReqId)
       ricReqId->ricRequestorID = 1;
       ricReqId->ricInstanceID  = 1;
    }
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /*******************************************************************
@@ -345,7 +246,7 @@ S16 fillRicAdmitList(RICaction_Admitted_ItemIEs_t *ricAdmitItems)
       ricAdmitItems->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
       ricAdmitItems->value.choice.RICaction_Admitted_Item.ricActionID = 1; 
    }
-   RETVALUE(ROK);
+   return ROK;
 }
 /*******************************************************************
  *
@@ -374,12 +275,12 @@ S16 BuildRicAdmitList(RICaction_Admitted_List_t *admitListPtr)
    if(admitListPtr->list.array == NULLP)
    {
       DU_LOG("\nE2AP : Memory allocation for RIC Admit List failed");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    DU_ALLOC(admitListPtr->list.array[0], sizeof(RICaction_Admitted_ItemIEs_t));
    fillRicAdmitList(admitListPtr->list.array[0]);
 
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /*******************************************************************
@@ -413,7 +314,7 @@ S16 BuildAndSendRicSubscriptionRsp()
    if(e2apRicMsg == NULLP)
    {
       DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    e2apRicMsg->present =  E2AP_PDU_PR_successfulOutcome;
    DU_ALLOC(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
@@ -421,7 +322,7 @@ S16 BuildAndSendRicSubscriptionRsp()
    {
       DU_LOG("\nE2AP : Memory allocation for Ric subscription Response failed");
       DU_FREE(e2apRicMsg, sizeof(RICsubscriptionResponse_t));
-      RETVALUE(RFAILED);  
+      return RFAILED;  
    }
 
    e2apRicMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
@@ -441,7 +342,7 @@ S16 BuildAndSendRicSubscriptionRsp()
       DU_LOG("\nE2AP : Memory allocation for RICsubscriptionResponseIE failed");
       DU_FREE(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
       DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
 
    for(idx=0; idx<elementCnt; idx++)
@@ -455,7 +356,7 @@ S16 BuildAndSendRicSubscriptionRsp()
          DU_FREE(e2apRicMsg->choice.successfulOutcome, \
                sizeof(SuccessfulOutcomeE2_t));
          DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
-         RETVALUE(RFAILED);
+         return RFAILED;
       }    
    }
    idx = 0;
@@ -491,7 +392,7 @@ S16 BuildAndSendRicSubscriptionRsp()
    {
           DU_LOG("\nE2AP : Could not encode RIC Subscription Response structure (at %s)\n",\
                           encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
-          RETVALUE(RFAILED);
+          return RFAILED;
    }
    else
    {
@@ -505,10 +406,10 @@ S16 BuildAndSendRicSubscriptionRsp()
    if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
    {
       DU_LOG("\nE2AP : Sending RIC Subscription Response failed");      
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    
-   RETVALUE(ROK);
+   return ROK;
 }
 /******************************************************************
 *
@@ -548,10 +449,10 @@ S16 procE2SetupRsp(E2AP_PDU_t *e2apMsg)
             recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID.pLMN_Identity);
 
             bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID.ric_ID, &e2SetupRspDb.ricId);
-            
-            aper_decode(0, &asn_DEF_PLMN_IdentityE2, (void **)&e2SetupRspDb.plmn, &e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID.pLMN_Identity, recvBufLen, 0, 0);
-            //xer_fprint(stdout, &asn_DEF_PLMN_IdentityE2, &e2SetupRspDb.plmn);
+            aper_decode(0, &asn_DEF_PLMN_IdentityE2, (void **)&e2SetupRspDb.plmn, \
+              &e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID.pLMN_Identity, recvBufLen, 0, 0);
 
+            xer_fprint(stdout, &asn_DEF_PLMN_IdentityE2, &e2SetupRspDb.plmn);
             break;
          }
          default:
@@ -560,7 +461,7 @@ S16 procE2SetupRsp(E2AP_PDU_t *e2apMsg)
             break;
       }
    }
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /******************************************************************
@@ -597,13 +498,16 @@ S16 procRicSubsReq(E2AP_PDU_t *e2apMsg)
       {
          case ProtocolIE_IDE2_id_RICrequestID:
          {
-            ricReqDb.ricReqId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID;
-            ricReqDb.ricInstanceId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID;
+            ricReqDb.ricReqId = ricSubsReq->protocolIEs.list.array[idx]->\
+                                   value.choice.RICrequestID.ricRequestorID;
+            ricReqDb.ricInstanceId = ricSubsReq->protocolIEs.list.array[idx]-> \
+                                       value.choice.RICrequestID.ricInstanceID;
             break;
          }
          case ProtocolIE_IDE2_id_RANfunctionID:
          {
-            ricReqDb.ranFuncId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RANfunctionID; 
+            ricReqDb.ranFuncId = ricSubsReq->protocolIEs.list.array[idx]-> \
+                                   value.choice.RANfunctionID; 
             break;
          }
          case ProtocolIE_IDE2_id_RICsubscriptionDetails:
@@ -614,7 +518,7 @@ S16 procRicSubsReq(E2AP_PDU_t *e2apMsg)
             recvBufLen = sizeof(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition);
 
             aper_decode(0, &asn_DEF_RICeventTriggerDefinition, (void **)&ricReqDb.ricEventTrigger, &(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition), recvBufLen, 0, 0);
-            //xer_fprint(stdout, &asn_DEF_RICeventTriggerDefinition, &ricReqDb.ricEventTrigger);
+            xer_fprint(stdout, &asn_DEF_RICeventTriggerDefinition, &ricReqDb.ricEventTrigger);
 
             actionItem = *ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.list.array;
             
@@ -682,7 +586,7 @@ S16 BuildAndSendRicIndication()
    if(e2apMsg == NULLP)
    {
       DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
 
    e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
@@ -691,7 +595,7 @@ S16 BuildAndSendRicIndication()
    {
       DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
       DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICindication;
    e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
@@ -713,7 +617,7 @@ S16 BuildAndSendRicIndication()
       DU_LOG("\nE2AP : Memory allocation for RICindicationIEs failed");
       DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
       DU_FREE(e2apMsg, (Size)sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    
    for(idx=0; idx<elementCnt; idx++)
@@ -732,7 +636,7 @@ S16 BuildAndSendRicIndication()
          DU_FREE(e2apMsg->choice.initiatingMessage, \
                sizeof(InitiatingMessageE2_t));
          DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
-         RETVALUE(RFAILED);
+         return RFAILED;
       }
    }
    idx = 0;
@@ -772,17 +676,23 @@ S16 BuildAndSendRicIndication()
    ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
    ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
                                    RICindication_IEs__value_PR_RICindicationHeader;
-   BuildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
+   ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size = 3 * sizeof(U8);
+   DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf ,\
+     ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
+   buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
                 &ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader);
 
    /* TO BE CHANGED: RIC INDICATION DATA */
-   /* Foe now filling a dummy octect data, need to tested with PRBs*/ 
+   /* For now filling a dummy octect data, need to tested with PRBs*/ 
    idx++;
    ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationMessage;
    ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
    ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
                                   RICindication_IEs__value_PR_RICindicationMessage;
-   BuildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
+   ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size = 3 * sizeof(U8);
+   DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf ,\
+     ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
+   buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
                 &ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage);
   
    /* Prints the Msg formed */
@@ -796,7 +706,7 @@ S16 BuildAndSendRicIndication()
    {
           DU_LOG("\nE2AP : Could not encode RIC Indication Message (at %s)\n",\
                           encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
-          RETVALUE(RFAILED);
+          return RFAILED;
    }
    else
    {
@@ -810,9 +720,9 @@ S16 BuildAndSendRicIndication()
    if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
    {
       DU_LOG("\nE2AP : Sending RIC Indication Message");      
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /*******************************************************************
@@ -846,24 +756,24 @@ S16 SendE2APMsg(Region region, Pool pool)
          {
             DU_LOG("\nE2AP : SCTP Send for E2  failed");
             SPutMsg(mBuf);
-            RETVALUE(RFAILED);
+            return RFAILED;
          }
       }
       else
       {
          DU_LOG("\nE2AP : SAddPstMsgMult failed");
          SPutMsg(mBuf);
-         RETVALUE(RFAILED);
+         return RFAILED;
       }
       SPutMsg(mBuf);
    }
    else
    {
       DU_LOG("\nE2AP : Failed to allocate memory");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
  
-   RETVALUE(ROK);
+   return ROK;
 } /* SendE2APMsg */
 
 /*******************************************************************
index 51c31ab..af4782b 100644 (file)
@@ -107,79 +107,7 @@ S16 BuildDLNRInfo(NRFreqInfo_t *dlnrfreq)
       dlnrfreq->freqBandListNr.list.array[idx]->supportedSULBandList.list.count = SUL_BAND_COUNT;
    RETVALUE(ROK);
 }
-/*******************************************************************
- *
- * @brief Builds PLMN ID 
- *
- * @details
- *
- *    Function : BuildPlmn
- *
- *    Functionality: Building the PLMN ID
- *
- * @params[in] PLMNID plmn
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-
-S16 BuildPlmn(PlmnId plmn, OCTET_STRING_t *plmnid)
-{
-   U8 mncCnt;
-   plmnid->size = 3;
-   DU_ALLOC(plmnid->buf,  plmnid->size * sizeof(U8));
-   if(plmnid->buf == NULLP)
-   {
-      RETVALUE(RFAILED);
-   }
-   mncCnt = 2;
-   plmnid->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
-   if(mncCnt == 2)
-   {
-      plmnid->buf[1]  = ((0xf0) | (plmn.mcc[2]));
-      plmnid->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
-   }
-   else
-   {
-      plmnid->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
-      plmnid->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
-   }
-  RETVALUE(ROK);
-}
-/*******************************************************************
- *
- * @brief Builds NRCell ID 
- *
- * @details
- *
- *    Function : BuildNrCellId
- *
- *    Functionality: Building the NR Cell ID
- *
- * @params[in] BIT_STRING_t *nrcell
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-
-S16 BuildNrCellId(BIT_STRING_t *nrcell)
-{
-   U8 tmp;
-   nrcell->size = 5;
-   DU_ALLOC(nrcell->buf, nrcell->size * sizeof(U8));
-   if(nrcell->buf == NULLP)
-   {
-      RETVALUE(RFAILED);
-   }
 
-   for (tmp = 0 ; tmp < nrcell->size-1; tmp++)
-   {
-      nrcell->buf[tmp] = 0;
-   }
-   nrcell->buf[4]   = 16;//change this 
-   nrcell->bits_unused = 4;
-   RETVALUE(ROK);
-}
 /*******************************************************************
  *
  * @brief Builds Nrcgi 
@@ -198,15 +126,26 @@ S16 BuildNrCellId(BIT_STRING_t *nrcell)
 S16 BuildNrcgi(NRCGI_t *nrcgi)
 {
    S16 ret;
+   U8 unused = 4;
+   U8 byteSize = 5;
+   U8 val = 16;
+
    GNB_DU_Served_Cells_Item_t *srvCellItem;
-   ret = BuildPlmn(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
+   /* Allocate Buffer Memory */
+   nrcgi->pLMN_Identity.size = PLMN_SIZE * sizeof(U8);
+   DU_ALLOC(nrcgi->pLMN_Identity.buf, nrcgi->pLMN_Identity.size);
+   ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
          &nrcgi->pLMN_Identity); // Building PLMN function 
    if(ret != ROK)
    {
       RETVALUE(RFAILED);
    }
    /*nrCellIdentity*/
-   ret = BuildNrCellId(&nrcgi->nRCellIdentity);
+   //ret = BuildNrCellId(&nrcgi->nRCellIdentity);
+   nrcgi->nRCellIdentity.size = byteSize * sizeof(U8);
+   DU_ALLOC(nrcgi->nRCellIdentity.buf, nrcgi->nRCellIdentity.size); 
+   ret = fillBitString(&nrcgi->nRCellIdentity, unused, byteSize, val);
+
    if(ret != ROK)
    {
       DU_FREE(srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
@@ -552,7 +491,10 @@ S16  BuildServedPlmn(ServedPLMNs_List_t *srvplmn)
          RETVALUE(RFAILED);
       }
    }
-   ret = BuildPlmn(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
+   /* Allocate Memory to Buffer */
+   srvplmn->list.array[0]->pLMN_Identity.size = PLMN_SIZE * sizeof(U8);
+   DU_ALLOC(srvplmn->list.array[0]->pLMN_Identity.buf, srvplmn->list.array[0]->pLMN_Identity.size);
+   ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
          &srvplmn->list.array[0]->pLMN_Identity);
    if(ret!= ROK)
    {
@@ -1431,40 +1373,6 @@ S16 BuildAndSendF1SetupReq()
    RETVALUE(ROK);
 }/* End of BuildAndSendF1SetupReq */
 
-/*******************************************************************
- *
- * @brief Builds the PLMN Id 
- *
- * @details
- *
- *    Function : plmnBuild
- *
- *    Functionality: Builds the PLMN Id 
- *
- * @params[in] PlmnId plmn
- * @params[in] OCTET_STRING_t *octe
- * 
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-void plmnBuild(PlmnId plmn, OCTET_STRING_t *octe)
-{
-   U8 mncCnt;
-   mncCnt = 2;
-   octe->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
-   if(mncCnt == 2)
-   {
-      octe->buf[1]  = ((0xf0) | (plmn.mcc[2]));
-      octe->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
-   }
-   else
-   {
-      octe->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
-      octe->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
-   }
-}
-
 /*******************************************************************
  *
  * @brief Builds and sends the DUConfigUpdate
@@ -1643,7 +1551,7 @@ S16 BuildAndSendDUConfigUpdate()
          RETVALUE(RFAILED);
       }
    }
-   plmnBuild(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
+   buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
          &modifyItem->oldNRCGI.pLMN_Identity);
    /*nRCellIdentity*/
    modifyItem->oldNRCGI.nRCellIdentity.size = 5;
@@ -1700,7 +1608,7 @@ S16 BuildAndSendDUConfigUpdate()
       DU_FREE(f1apDuCfg, sizeof(F1AP_PDU_t));
       RETVALUE(RFAILED);
    }
-   plmnBuild(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
+   buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
          &modifyItem->served_Cell_Information.nRCGI.pLMN_Identity);
    modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size = 5;
    DU_ALLOC(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
@@ -1841,7 +1749,7 @@ S16 BuildAndSendDUConfigUpdate()
       DU_FREE(f1apDuCfg, sizeof(F1AP_PDU_t));
       RETVALUE(RFAILED);
    }
-   plmnBuild(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.plmn[0],\
+   buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.plmn[0],\
          &modifyItem->served_Cell_Information.servedPLMNs.list.array[0]->pLMN_Identity);
    DU_ALLOC(modifyItem->served_Cell_Information.servedPLMNs.list.\
        array[0]->iE_Extensions,sizeof(struct ProtocolExtensionContainer_4624P3));
index b00e548..fc23787 100644 (file)
 /* Events */
 #define EVTCFG 0
 #define EVTSCTPSTRT  1
-#define EVTSCTPDATA  2
-#define EVTSCTPNTFY  3
+#define EVENT_CU_DATA  2
+#define EVENT_SCTP_NTFY  3
 #define EVTSRVOPENREQ  4
 #define EVTSRVOPENCFM  5
 #define EVTTNLMGMTREQ  6
 #define EVTTNLMGMTCFM  7
 #define EVTTTIIND    8
 #define EVTSTARTPOLL  9
-#define EVTRICDATA  10
+#define EVENT_RIC_DATA  10
 
 /* Selector */
 #define DU_SELECTOR_LC   0
@@ -152,7 +152,7 @@ typedef struct cellCfgParams
    NrEcgi      nrEcgi;         /* ECGI */
    U16         nrPci;          /* PCI */
    U16         fiveGsTac;         /* 5gSTac */
-   PlmnId      plmn[MAX_PLMN]; /* List of serving PLMN IDs */
+   Plmn      plmn[MAX_PLMN]; /* List of serving PLMN IDs */
    U32         maxUe;          /* max UE per slot */
 }CellCfgParams;
 
index 12f63cc..5d6d547 100644 (file)
@@ -202,22 +202,21 @@ S16 duActvTsk(Pst *pst, Buffer *mBuf)
          {
             switch(pst->event)
             {
-               case EVTSCTPDATA:
+               case EVENT_CU_DATA:
                {
                   F1APMsgHdlr(mBuf);
                   break;
                }
-               case EVTSCTPNTFY:
+               case EVENT_SCTP_NTFY:
                {
                   ret = cmUnpkSctpNtfy(duSctpNtfyHdl, pst, mBuf);
                   break;
                }
-               case EVTRICDATA:
+               case EVENT_RIC_DATA:
                {
                   E2APMsgHdlr(mBuf);
                   break;
                }
-
                default:
                {
                   DU_LOG("\nDU_APP : Invalid event received at duActvTsk from ENTSCTP");
index 7d27911..ab80cea 100644 (file)
@@ -921,39 +921,26 @@ S16 duBindUnbindRlcToMacSap(U8 inst, U8 action)
 
 S16 duSctpNtfyHdl(Buffer *mBuf, CmInetSctpNotification *ntfy)
 {
-   switch(ntfy->header.nType)
+   if(f1Params.assocId == ntfy->u.assocChange.assocId)
    {
-      case CM_INET_SCTP_ASSOC_CHANGE:
-         switch(ntfy->u.assocChange.state)
-         {
-            case CM_INET_SCTP_COMM_UP:
-               {
-                  DU_LOG("\nDU_APP : SCTP communication UP");
-                  //Setup F1-C
-                  if(ntfy->u.assocChange.assocId == f1Params.assocId)
-                  {
-                     /* Build and send F1 Setup response */
-                     if(BuildAndSendF1SetupReq() != ROK)
-                     {
-                        RETVALUE(RFAILED);
-                     }
-                  }
-                  //Setup E2
-                  if(ntfy->u.assocChange.assocId == ricParams.assocId)
-                  {
-                     /* Build and send F1 Setup response */
-                     if(BuildAndSendE2SetupReq() != ROK)
-                     {
-                        RETVALUE(RFAILED);
-                     }
-                  }
-
-                  break;
-               }
-         }
-         break;
+      if(BuildAndSendF1SetupReq() != ROK)
+      {
+         return RFAILED;
+      }
    }
-   RETVALUE(ROK);
+   else if(ricParams.assocId == ntfy->u.assocChange.assocId)
+   {
+      if(BuildAndSendE2SetupReq() != ROK)
+      {
+         return RFAILED;
+      }
+   }
+   else
+       {
+      DU_LOG("\nDU_APP : Invalid assocId %d received", ntfy->u.assocChange.assocId);
+               return RFAILED;
+       }
+   return ROK;
 }
 
 /*******************************************************************
@@ -1442,7 +1429,7 @@ S16 duLayerConfigComplete()
       DU_LOG("\nDU_APP : Failed configuring Sctp Params");
       ret = RFAILED;
    }
-       if((ret = duSctpAssocReq(F1_INTERFACE)) != ROK)
+   if((ret = duSctpAssocReq(F1_INTERFACE)) != ROK)
    {
       DU_LOG("\nDU_APP : Failed to send AssocReq F1");
       ret = RFAILED;
index 28576af..25bccb3 100644 (file)
@@ -291,7 +291,7 @@ S16 establishReq(DuSctpDestCb *paramPtr)
    }
    if((ret == ROK) & (paramPtr->itfState == DU_SCTP_DOWN))
    {
-      paramPtr->itfState = DU_SCTP_UP;
+      paramPtr->itfState = DU_SCTP_CONNECTING;
    }
 
    /* Post the EVTSTARTPOLL Msg */
@@ -505,7 +505,7 @@ void sendToDuApp(Buffer *mBuf, Event event)
  *         RFAILED - failure
  *
  * ****************************************************************/
-S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy)
+S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy, U8 *itfState)
 {
    Pst pst;
 
@@ -517,23 +517,23 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy)
          {
             case CM_INET_SCTP_COMM_UP:
                DU_LOG("Event : COMMUNICATION UP");
-               connUp = TRUE;
+               *itfState = DU_SCTP_UP;
                break;
             case CM_INET_SCTP_COMM_LOST:
                DU_LOG("Event : COMMUNICATION LOST");
-               connUp = FALSE;
+               *itfState = DU_SCTP_DOWN;
                break;
             case CM_INET_SCTP_RESTART:
                DU_LOG("Event : SCTP RESTART");
-               connUp = FALSE;
+               *itfState = DU_SCTP_DOWN;
                break;
             case CM_INET_SCTP_SHUTDOWN_COMP: /* association gracefully shutdown */
                DU_LOG("Event : SHUTDOWN COMPLETE");
-               connUp = FALSE;
+               *itfState = DU_SCTP_DOWN;
                break;
             case CM_INET_SCTP_CANT_STR_ASSOC:
                DU_LOG("Event : CANT START ASSOC");
-               connUp = FALSE;
+               *itfState = DU_SCTP_DOWN;
                break;
             default:
                DU_LOG("\nInvalid event");
@@ -552,7 +552,7 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy)
          break;
       case CM_INET_SCTP_SHUTDOWN_EVENT : /* peer socket gracefully closed */
          DU_LOG("\nSCTP : Shutdown Event notification received\n");
-         connUp = FALSE;
+         *itfState = DU_SCTP_DOWN;
          exit(0);
          break;
       case CM_INET_SCTP_ADAPTATION_INDICATION :
@@ -576,7 +576,7 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy)
    pst.dstEnt = (Ent)ENTDUAPP;
    pst.dstInst = (Inst)DU_INST;
    pst.dstProcId = pst.srcProcId;
-   pst.event = EVTSCTPNTFY;
+   pst.event = EVENT_SCTP_NTFY;
    pst.selector = DU_SELECTOR_LC;
    pst.pool= DU_POOL;
    pst.region = DFLT_REGION;
@@ -616,13 +616,13 @@ S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, U32 *timeou
 {
    U16 ret = ROK;
    CM_INET_FD_SET(sockFd, &pollParams->readFd);
-   ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &pollParams->numFds);
+   ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &pollParams->numFd);
    if(CM_INET_FD_ISSET(sockFd, &pollParams->readFd))
    {
       CM_INET_FD_CLR(sockFd, &pollParams->readFd);
       ret = cmInetSctpRecvMsg(sockFd, &pollParams->addr, &pollParams->port, memInfo, &(pollParams->mBuf), &pollParams->bufLen, &pollParams->info, &pollParams->flag, &pollParams->ntfy);
         
-      if(connUp && ret != ROK)
+      if(ret != ROK)
       {
          DU_LOG("\n SCTP: Failed to receive sctp msg for sockFd[%d]\n", sockFd->fd);
          recvMsgSet = RFAILED;
@@ -635,29 +635,31 @@ S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, U32 *timeou
             {
                f1Params.assocId = pollParams->ntfy.u.assocChange.assocId;
                DU_LOG("\nSCTP : AssocId assigned to F1Params from PollParams [%d]\n", f1Params.assocId);
+               ret = sctpNtfyHdlr(&pollParams->ntfy, &f1Params.itfState);
             }
             else if(pollParams->port == ricParams.destPort)
             {
                ricParams.assocId = pollParams->ntfy.u.assocChange.assocId;
                DU_LOG("\nSCTP : AssocId assigned to ricParams from PollParams [%d]\n", ricParams.assocId);
+               ret = sctpNtfyHdlr(&pollParams->ntfy, &ricParams.itfState);
             }
             else
             {
                DU_LOG("\nSCTP : Failed to fill AssocId\n");
-            }  
-            ret = sctpNtfyHdlr(&pollParams->ntfy);
+               RETVALUE(RFAILED);
+            }
             if(ret != ROK)
             {
                DU_LOG("\nSCTP : Failed to process sctp notify msg\n");
             }
          }
-         else if(connUp & (pollParams->port == f1Params.destPort))
+         else if(f1Params.itfState & (pollParams->port == f1Params.destPort))
          {  
-            sendToDuApp(pollParams->mBuf, EVTSCTPDATA);
+            sendToDuApp(pollParams->mBuf, EVENT_CU_DATA);
          }
-         else if(connUp & (pollParams->port == ricParams.destPort))
+         else if(ricParams.itfState & (pollParams->port == ricParams.destPort))
          {  
-            sendToDuApp(pollParams->mBuf, EVTRICDATA);
+            sendToDuApp(pollParams->mBuf, EVENT_RIC_DATA);
          }
 
          else
index 37d5b9e..cff8ea6 100644 (file)
@@ -44,7 +44,7 @@ CmInetNetAddrLst remoteAddrLst;
 
 typedef struct
 {
-   S16           numFds;            /* Total count number of receivers socket Fd */
+   S16           numFd;            /* Total count number of receivers socket Fd */
    U16           port;              /* Filled by the InetSctpRecvMsg during polling */              
    U32           flag;              /* Refers to the notifyHandler Flag during successful InetSctpRecvMsg*/
    Buffer        *mBuf;             /* Buffer filled during Socket polling*/
index 565d17f..b8ddf2b 100644 (file)
 #include "ric_stub_sctp.h"
 #include "ric_e2ap_msg_hdl.h"
 #include "GlobalE2node-gNB-ID.h"
+#include "odu_common_codec.h"
 
-char encBuf[ENC_BUF_MAX_LEN];
 Bool ricSubsStatus;
-S16 SendE2APMsg(Region , Pool );
-
-/*******************************************************************
- *
- * @brief Writes the encoded chunks into a buffer
- *
- * @details
- *
- *    Function : PrepFinalEncBuf
- *
- *    Functionality:Fills the encoded buffer
- *
- * @params[in] void *buffer,initial encoded data
- * @params[in] size_t size,size of buffer
- * @params[in] void *encodedBuf,final buffer
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-static int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf)
-{
-   memcpy(encodedBuf + encBufSize, buffer, size);
-   encBufSize += size;
-   return 0;
-} /* PrepFinalEncBuf */
 
 /*******************************************************************
 *
@@ -79,107 +54,28 @@ S16 SendE2APMsg(Region region, Pool pool)
  
          if(sctpSend(mBuf) != ROK)
          {
-            DU_LOG("\nF1AP : SCTP Send for E2  failed");
+            DU_LOG("\nE2AP : SCTP Send for E2  failed");
             SPutMsg(mBuf);
-            RETVALUE(RFAILED);
+            return RFAILED;
          }
       }
       else
       {
-         DU_LOG("\nF1AP : SAddPstMsgMult failed");
+         DU_LOG("\nE2AP : SAddPstMsgMult failed");
          SPutMsg(mBuf);
-         RETVALUE(RFAILED);
+         return RFAILED;
       }
       SPutMsg(mBuf);
    }
    else
    {
-      DU_LOG("\nF1AP : Failed to allocate memory");
-      RETVALUE(RFAILED);
+      DU_LOG("\nE2AP : Failed to allocate memory");
+      return RFAILED;
    }
  
-   RETVALUE(ROK);
+   return ROK;
 } /* SendE2APMsg */
 
-/*******************************************************************
- *
- * @brief Builds PLMN ID 
- *
- * @details
- *
- *    Function : plmnBuildRic
- *
- *    Functionality: Building the PLMN ID
- *
- * @params[in] PLMNID plmn
- *             OCTET_STRING_t *octe
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-
-void plmnBuildRic(Plmn plmn, OCTET_STRING_t *octe)
-{
-   U8 mncCnt;
-   octe->size = 3;
-   RIC_ALLOC(octe->buf,  octe->size * sizeof(U8));
-   if(octe->buf == NULLP)
-   {
-      RETVALUE(RFAILED);
-   }
-   mncCnt = 2;
-   octe->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
-   if(mncCnt == 2)
-   {
-      octe->buf[1]  = ((0xf0) | (plmn.mcc[2]));
-      octe->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
-   }
-   else
-   {
-      octe->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
-      octe->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
-   }
-}
-
-/*******************************************************************
- *
- * @brief Fills the RicId
- *
- * @details
- *
- *    Function : FillRicId
- *
- *    Functionality: Fills the RicId
- *
- * @params[in] BIT_STRING_t *nbid,
- *             U8 unusedBits
- *             U8 byteSize
- *             U8 val
- *
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-
-S16 FillRicId(BIT_STRING_t *id, U8 unusedBits, U8 byteSize, U8 val)
-{
-   U8 tmp;
-   id->size = byteSize;
-   RIC_ALLOC(id->buf, id->size * sizeof(U8));
-   if(id->buf == NULLP)
-   {
-      RETVALUE(RFAILED);
-   }
-
-   for (tmp = 0 ; tmp < (byteSize-1); tmp++)
-   {
-      id->buf[tmp] = tmp;
-   }
-   id->buf[byteSize-1]   = val;  //change this 
-   id->bits_unused = unusedBits;
-   RETVALUE(ROK);
-}
-
 /*******************************************************************
  *
  * @brief Builds Global RIC Id Params
@@ -203,45 +99,16 @@ S16 BuildGlobalRicId(GlobalRIC_ID_t *ricId)
    U8 val = 1;
    if(ricId != NULLP)
    {
-      plmnBuildRic(cuCfgParams.plmn , &ricId->pLMN_Identity);
+      ricId->pLMN_Identity.size = byteSize * sizeof(U8);
+      RIC_ALLOC(ricId->pLMN_Identity.buf,  ricId->pLMN_Identity.size);
+      buildPlmnId(ricCfgParams.plmn , &ricId->pLMN_Identity);
       /* fill ric Id */
-      FillRicId(&ricId->ric_ID, unused, byteSize, val);
-   }
-   RETVALUE(ROK);   
-}
-#if 0
-RANfunctionID_ItemIEs_t* FillRanFuncItems(RANfunctionID_ItemIEs_t *items)
-{
-  if(items != NULLP)
-  {
-     items->id = ProtocolIE_IDE2_id_RANfunction_Item;
-     items->criticality = CriticalityE2_reject;
-     items->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item; 
-     items->value.choice.RANfunctionID_Item.ranFunctionID = 1;
-     items->value.choice.RANfunctionID_Item.ranFunctionRevision = 4;
-  }
-  RETVALUE(items);
-}
-
-S16 BuildRANfuncIdList(RANfunctionsID_List_t *funcIdList)
-{
-   U8 elementCnt;
-   RANfunctionID_ItemIEs_t *funcIdItems;
-
-   elementCnt = 1; 
-   funcIdList->list.count = elementCnt;
-   funcIdList->list.size  = elementCnt * sizeof(RANfunctionID_ItemIEs_t);
-   RIC_ALLOC(funcIdList->list.array, funcIdList->list.size);
-   if(funcIdList->list.array == NULLP)
-   {
-      DU_LOG("\nE2AP : Memory allocation for RAN Function List failed");
-      RETVALUE(RFAILED);
+      ricId->ric_ID.size = byteSize * sizeof(U8);
+      RIC_ALLOC(ricId->ric_ID.buf, ricId->ric_ID.size);
+      fillBitString(&ricId->ric_ID, unused, byteSize, val);
    }
-   RIC_ALLOC(funcIdList->list.array[0], sizeof(RANfunctionID_ItemIEs_t));
-   FillRanFuncItems(funcIdList->list.array[0]);
-   RETVALUE(ROK);
+   return ROK;   
 }
-#endif
 
 /*******************************************************************
  *
@@ -276,7 +143,7 @@ S16 BuildAndSendE2SetupRsp()
    if(e2apMsg == NULLP)
    {
       DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    e2apMsg->present =  E2AP_PDU_PR_successfulOutcome;
    RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
@@ -284,7 +151,7 @@ S16 BuildAndSendE2SetupRsp()
    {
       DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
       RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);  
+      return RFAILED;  
    }
 
    e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_E2setup;
@@ -304,7 +171,7 @@ S16 BuildAndSendE2SetupRsp()
       DU_LOG("\nE2AP : Memory allocation for E2ResponseIEs failed");
       RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
       RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
 
    for(idx=0; idx<elementCnt; idx++)
@@ -318,7 +185,7 @@ S16 BuildAndSendE2SetupRsp()
          RIC_FREE(e2apMsg->choice.successfulOutcome, \
                sizeof(SuccessfulOutcomeE2_t));
          RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
-         RETVALUE(RFAILED);
+         return RFAILED;
       }    
    }
    /* Global RIC ID */
@@ -340,7 +207,7 @@ S16 BuildAndSendE2SetupRsp()
    {
           DU_LOG("\nE2AP : Could not encode E2SetupResponse structure (at %s)\n",\
                           encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
-          RETVALUE(RFAILED);   
+          return RFAILED;   
    } 
    else 
    {
@@ -354,11 +221,11 @@ S16 BuildAndSendE2SetupRsp()
 
    if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL) != ROK)
    {
-      DU_LOG("\nF1AP : Sending E2 Setup Response failed");      
-      RETVALUE(RFAILED);
+      DU_LOG("\nE2AP : Sending E2 Setup Response failed");      
+      return RFAILED;
    }
 
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /*******************************************************************
@@ -385,7 +252,7 @@ S16 BuildRicRequestId(RICrequestID_t *ricReqId)
       ricReqId->ricRequestorID = 1;
       ricReqId->ricInstanceID  = 1;
    }
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /*******************************************************************
@@ -439,7 +306,7 @@ S16 fillSubsDetails(RICaction_ToBeSetup_ItemIEs_t *items)
       items->value.present =  RICaction_ToBeSetup_ItemIEs__value_PR_RICaction_ToBeSetup_Item;
       fillSetupItems(&(items->value.choice.RICaction_ToBeSetup_Item));
    }
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /*******************************************************************
@@ -465,8 +332,12 @@ S16 BuildRicSubsDetails(RICsubscriptionDetails_t *subsDetails)
 
    if(subsDetails != NULLP)
    {
-      /* Plmn is not called */
-      plmnBuildRic(cuCfgParams.plmn, &subsDetails->ricEventTriggerDefinition);
+      /* Octet string to be build here */
+      /* Sending PLMN as Octect string */
+      U8 byteSize = 3;
+      subsDetails->ricEventTriggerDefinition.size = byteSize * sizeof(U8);
+      RIC_ALLOC(subsDetails->ricEventTriggerDefinition.buf,  subsDetails->ricEventTriggerDefinition.size);
+      buildPlmnId(ricCfgParams.plmn, &subsDetails->ricEventTriggerDefinition);
       elementCnt = 1;
       subsDetails->ricAction_ToBeSetup_List.list.count = elementCnt;
       subsDetails->ricAction_ToBeSetup_List.list.size = \
@@ -476,13 +347,13 @@ S16 BuildRicSubsDetails(RICsubscriptionDetails_t *subsDetails)
       if(subsDetails->ricAction_ToBeSetup_List.list.array  == NULLP)
       {
          DU_LOG("\nE2AP : Memory allocation for RICactionToBeSetup Items failed");
-         RETVALUE(RFAILED);
+         return RFAILED;
       } 
       RIC_ALLOC(subsDetails->ricAction_ToBeSetup_List.list.array[0],\
                    sizeof(RICaction_ToBeSetup_ItemIEs_t));
       fillSubsDetails(subsDetails->ricAction_ToBeSetup_List.list.array[0]);
    }
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /*******************************************************************
@@ -518,7 +389,7 @@ S16 BuildAndSendRicSubscriptionReq()
    if(e2apRicMsg == NULLP)
    {
       DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
 
    e2apRicMsg->present = E2AP_PDU_PR_initiatingMessage;
@@ -527,7 +398,7 @@ S16 BuildAndSendRicSubscriptionReq()
    {
       DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
       RIC_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    e2apRicMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICsubscription;
    e2apRicMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
@@ -548,7 +419,7 @@ S16 BuildAndSendRicSubscriptionReq()
       DU_LOG("\nE2AP : Memory allocation for RICSubscriptionRequestIEs failed");
       RIC_FREE(e2apRicMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
       RIC_FREE(e2apRicMsg, (Size)sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    
    for(idx=0; idx<elementCnt; idx++)
@@ -567,7 +438,7 @@ S16 BuildAndSendRicSubscriptionReq()
          RIC_FREE(e2apRicMsg->choice.initiatingMessage, \
                sizeof(InitiatingMessageE2_t));
          RIC_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
-         RETVALUE(RFAILED);
+         return RFAILED;
       }
    }
 
@@ -611,7 +482,7 @@ S16 BuildAndSendRicSubscriptionReq()
    {
       DU_LOG("\nE2AP : Could not encode RicSubscriptionRequest structure (at %s)\n",\
       encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    else
    {
@@ -627,10 +498,10 @@ S16 BuildAndSendRicSubscriptionReq()
    if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL) != ROK)
    {
       DU_LOG("\nE2AP : Sending RIC subscription Request failed");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
 
-   RETVALUE(ROK);
+   return ROK;
 }
 
  
@@ -683,7 +554,7 @@ void E2APMsgHdlr(Buffer *mBuf)
         printf("%x",recvBuf[i]);
    }
 
-   /* Decoding flat buffer into F1AP messsage */
+   /* Decoding flat buffer into E2AP messsage */
    e2apMsg = &e2apasnmsg;
    memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
 
index 7891086..d1ed8a5 100644 (file)
@@ -20,7 +20,7 @@
 #include<stdio.h>
 #include<sys/types.h>
 #include<string.h>
-#include<ProtocolIE-FieldE2.h>
+#include "ProtocolIE-FieldE2.h"
 #include "E2AP-PDU.h"
 
 #include "envopt.h"        /* Environment options */
 
 
 
-extern char encBuf[ENC_BUF_MAX_LEN];
-int  encBufSize;
-
 void E2APMsgHdlr(Buffer *mBuf);
 S16 BuildAndSendE2SetupReq();
+S16 SendE2APMsg(Region , Pool );
 
 /**********************************************************************
          End of file
index dd07ec4..e314439 100644 (file)
@@ -60,18 +60,18 @@ void sctpNtfyInd(CmInetSctpNotification *ntfy)
 
 void init_log()
 {
-       openlog("CU_STUB",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
+       openlog("RIC_STUB",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
 }
 /*******************************************************************
  *
- * @brief Main function of CU APP
+ * @brief Main function of E2 APP
  *
  * @details
  *
  *    Function : main
  *
  *    Functionality:
- *         - Reads CU related configurations
+ *         - Reads RIC related configurations
  *         - Initialize SCTP Parameters
  *         - Start SCTP receiver thread
  *
@@ -86,17 +86,14 @@ S16 tst()
    init_log();   
  
    DU_LOG("\nStarting RIC_STUB");
-   /* Read CU configurations */
+   /* Read RIC configurations */
    readRicCfg();
 
-   /* Initializing SCTP global parameters */
-   sctpActvInit();
-   /* Start CU-SCTP to listen on incoming connection */
+   /* Start RIC-SCTP to listen on incoming connection */
    sctpCfgReq();
    sctpStartReq();
 
-   RETVALUE(ROK);
+   return ROK;
 }
 /*******************************************************************
  *
@@ -124,30 +121,26 @@ void readRicCfg()
    cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du);
    cmInetAddr((S8*)RIC_IP_V4_ADDR, &ipv4_ric);
  
-   cuCfgParams.cuId = RIC_ID;
-   strcpy(cuCfgParams.cuName, RIC_NAME);
+   ricCfgParams.ricId = RIC_ID;
+   strcpy(ricCfgParams.ricName, RIC_NAME);
  
    /* DU IP Address and Port*/
-   cuCfgParams.sctpParams.duIpAddr.ipV4Addr = ipv4_du;
-   cuCfgParams.sctpParams.duIpAddr.ipV6Pres = false;
-   cuCfgParams.sctpParams.duPort = DU_PORT;
+   ricCfgParams.sctpParams.duIpAddr.ipV4Addr = ipv4_du;
+   ricCfgParams.sctpParams.duIpAddr.ipV6Pres = false;
+   ricCfgParams.sctpParams.duPort = DU_PORT;
 
    /* RIC IP Address and Port*/
-   cuCfgParams.sctpParams.ricIpAddr.ipV4Addr = ipv4_ric;
-   cuCfgParams.sctpParams.ricIpAddr.ipV6Pres = false;
-   cuCfgParams.sctpParams.ricPort = RIC_PORT;
+   ricCfgParams.sctpParams.ricIpAddr.ipV4Addr = ipv4_ric;
+   ricCfgParams.sctpParams.ricIpAddr.ipV6Pres = false;
+   ricCfgParams.sctpParams.ricPort = RIC_PORT;
 
    /*PLMN*/
-   cuCfgParams.plmn.mcc[0] = PLMN_MCC0;
-   cuCfgParams.plmn.mcc[1] = PLMN_MCC1;
-   cuCfgParams.plmn.mcc[2] = PLMN_MCC2;
-   cuCfgParams.plmn.mnc[0] = PLMN_MNC0;
-   cuCfgParams.plmn.mnc[1] = PLMN_MNC1;
-   cuCfgParams.plmn.mnc[2] = PLMN_MNC2;
-
-   /*RRC Version*/
-   cuCfgParams.rrcVersion.rrcVer = RRC_VER;
-   cuCfgParams.rrcVersion.extRrcVer = EXT_RRC_VER;
+   ricCfgParams.plmn.mcc[0] = PLMN_MCC0;
+   ricCfgParams.plmn.mcc[1] = PLMN_MCC1;
+   ricCfgParams.plmn.mcc[2] = PLMN_MCC2;
+   ricCfgParams.plmn.mnc[0] = PLMN_MNC0;
+   ricCfgParams.plmn.mnc[1] = PLMN_MNC1;
+   ricCfgParams.plmn.mnc[2] = PLMN_MNC2;
   
 } /* End of readCuCfg */
 /**********************************************************************
index c487758..2b8fc45 100644 (file)
@@ -16,8 +16,8 @@
 ################################################################################
 *******************************************************************************/
 
-#ifndef __CU_MGR_MAIN_H__
-#define __CU_MGR_MAIN_H__
+#ifndef __RIC_MGR_MAIN_H__
+#define __RIC_MGR_MAIN_H__
 
 
 #include "stdio.h"
@@ -47,6 +47,7 @@
 #include "cm_inet.x"
 #include "cm_llist.x"      /* Common link list  defines  */
 #include "cm_hash.x"       /* Common hashlist  defines */
+#include "odu_common_codec.h"
 
 #include "du_log.h"
 #define MAX_IPV6_LEN 16
@@ -62,7 +63,7 @@
    _ret = SGetSBuf(RIC_APP_MEM_REG, RIC_POOL,                  \
                      (Data **)&_datPtr, _size);                  \
    if(_ret == ROK)                                              \
-      cmMemset((U8*)_datPtr, 0, _size);                         \
+      cmMemset((uint8_t*)_datPtr, 0, _size);                         \
    else                                                         \
       _datPtr = NULLP;                                          \
 }
 
 typedef struct ipAddr
 {
Bool ipV4Pres;
U32  ipV4Addr;
Bool ipV6Pres;
U8   ipV6Addr[MAX_IPV6_LEN];
bool ipV4Pres;
uint32_t  ipV4Addr;
bool ipV6Pres;
uint8_t   ipV6Addr[MAX_IPV6_LEN];
 }SctpIpAddr;
 
-typedef struct RrcVersion
-{
-  U8    rrcVer;     /* Latest RRC Version */
-  U32   extRrcVer;  /* Latest RRC version extended */
-}RrcVersion;
-
-typedef struct sctpParamsRic
+typedef struct RicSctpParams
 {
    SctpIpAddr  duIpAddr;
-   U16         duPort;
+   uint16_t         duPort;
    SctpIpAddr  ricIpAddr;
-   U16         ricPort;
-}SctpParamsRic;
-
-typedef struct fPLMN
-{
-   U8 mcc[3];
-   U8 mnc[3];
-}Plmn;
-
+   uint16_t         ricPort;
+}RicSctpParams;
 
-typedef struct cuCfgParams
+typedef struct ricCfgParams
 {
-   U32             cuId;
-   char            cuName[RIC_DU_NAME_LEN_MAX];
-   SctpParamsRic   sctpParams;
+   uint32_t             ricId;
+   char            ricName[RIC_DU_NAME_LEN_MAX];
+   RicSctpParams   sctpParams;
    Plmn            plmn;
-   RrcVersion      rrcVersion;
-}CuCfgParams;
-CuCfgParams cuCfgParams; //global variable to hold all configs
+}RicCfgParams;
+RicCfgParams ricCfgParams; //global variable to hold all configs
 
 void readRicCfg();
 void cuAppInmsgHdlr(Buffer *mBuf);
index 8cd4973..a32a9b3 100644 (file)
 
 CuSctpDestCb ricParams;
 
-/**************************************************************************
- * @brief Task Initiation callback function. 
- *
- * @details
- *
- *     Function : sctpActvInit 
- *    
- *     Functionality:
- *             This function is supplied as one of parameters during SCTP's 
- *             task registration. SSI will invoke this function once, after
- *             it creates and attaches this TAPA Task to a system task.
- *     
- * @param[in]  Ent entity, the entity ID of this task.     
- * @param[in]  Inst inst, the instance ID of this task.
- * @param[in]  Region region, the region ID registered for memory 
- *              usage of this task.
- * @param[in]  Reason reason.
- * @return ROK     - success
- *         RFAILED - failure
- ***************************************************************************/
-S16 sctpActvInit()
-{
-   DU_LOG("\n\nSCTP : Initializing");
-   connUp = FALSE;
-   assocId = 0;
-   nonblocking = FALSE;
-   sctpCfg = cuCfgParams.sctpParams;
-   return ROK;
-
-}
 
-/**************************************************************************
- * @brief Task Activation callback function. 
- *
- * @details
- *
- *      Function : sctpActvTsk 
- * 
- *      Functionality:
- *           This function handles all SCTP messages received
- *           This API is registered with SSI during the 
- *           Task Registration of DU APP.
- *     
- * @param[in]  Pst     *pst, Post structure of the primitive.     
- * @param[in]  Buffer *mBuf, Packed primitive parameters in the
- *  buffer.
- * @return ROK     - success
- *         RFAILED - failure
- *
- ***************************************************************************/
-S16 sctpActvTsk(Pst *pst, Buffer *mBuf)
-{
-
-//TODO: TBD
-   return ROK;
-}
 /**************************************************************************
  * @brief Function to configure the Sctp Params during config Request
  *
  * @details
  *
- *      Function : duSctpCfgReq
+ *      Function : sctpCfgReq
  * 
  *      Functionality:
  *           This function configures SCTP Params during the config Request
@@ -97,16 +42,18 @@ S16 sctpActvTsk(Pst *pst, Buffer *mBuf)
 
 S16 sctpCfgReq()
 {
+   connUp = FALSE;
+   sctpCfg = ricCfgParams.sctpParams;
 
 /* Fill F1 Params */
    ricParams.destPort             = sctpCfg.duPort;
    ricParams.srcPort              = sctpCfg.ricPort;
    ricParams.bReadFdSet           = ROK;
-   cmMemset ((U8 *)&ricParams.sockFd, -1, sizeof(CmInetFd));
-   cmMemset ((U8 *)&ricParams.lstnSockFd, -1, sizeof(CmInetFd));
+   memset(&ricParams.sockFd, -1, sizeof(CmInetFd));
+   memset(&ricParams.lstnSockFd, -1, sizeof(CmInetFd));
    fillDestNetAddr(&ricParams.destIpNetAddr, &sctpCfg.duIpAddr);
 
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /*******************************************************************
@@ -133,7 +80,7 @@ S16 fillAddrLst(CmInetNetAddrLst *addrLstPtr, SctpIpAddr *ipAddr)
    addrLstPtr->addrs[(addrLstPtr->count - 1)].type = CM_INET_IPV4ADDR_TYPE;
    addrLstPtr->addrs[(addrLstPtr->count - 1)].u.ipv4NetAddr = CM_INET_NTOH_U32(ipAddr->ipV4Addr);
 
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /******************************************************************************
@@ -158,7 +105,7 @@ S16 fillDestNetAddr(CmInetNetAddr *destAddrPtr, SctpIpAddr *dstIpPtr)
    /* Filling destination address */
    destAddrPtr->type = CM_INET_IPV4ADDR_TYPE;
    destAddrPtr->u.ipv4NetAddr = CM_INET_NTOH_U32(dstIpPtr->ipV4Addr);
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /******************************************************************************
@@ -190,11 +137,11 @@ S16 sctpStartReq()
    } 
    else if((ret = cmInetSctpBindx(&ricParams.lstnSockFd, &ricParams.localAddrLst, ricParams.srcPort)) != ROK)
    {
-      DU_LOG("\nSCTP: Binding failed at CU");
+      DU_LOG("\nSCTP: Binding failed at RIC");
    }
    else if((ret = sctpAccept(&ricParams.lstnSockFd, &ricParams.peerAddr, &ricParams.sockFd)) != ROK)
    {
-      DU_LOG("\nSCTP: Unable to accept the connection at CU");
+      DU_LOG("\nSCTP: Unable to accept the connection at RIC");
    }
    else if(sctpSockPoll() != ROK)
    {
@@ -260,13 +207,13 @@ S16 sctpSetSockOpts(CmInetFd *sock_Fd)
 S16 sctpAccept(CmInetFd *lstnSock_Fd, CmInetAddr *peerAddr, CmInetFd *sock_Fd)
 {
    U8  ret;
-   
-   ret = cmInetListen(lstnSock_Fd, 1);;
+
+   ret = cmInetListen(lstnSock_Fd, 1);
    if (ret != ROK)
    {
       DU_LOG("\nSCTP : Listening on socket failed");
       cmInetClose(lstnSock_Fd);
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    
    DU_LOG("\nSCTP : Connecting");
@@ -281,7 +228,7 @@ S16 sctpAccept(CmInetFd *lstnSock_Fd, CmInetAddr *peerAddr, CmInetFd *sock_Fd)
       else if(ret != ROK)
       {
          DU_LOG("\nSCTP : Failed to accept connection");
-         RETVALUE(RFAILED);
+         return RFAILED;
       }
       else
       {
@@ -292,7 +239,7 @@ S16 sctpAccept(CmInetFd *lstnSock_Fd, CmInetAddr *peerAddr, CmInetFd *sock_Fd)
    }
    DU_LOG("\nSCTP : Connection established");
 
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /*******************************************************************
@@ -372,7 +319,7 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy)
    }
 
    sctpNtfyInd(ntfy);
-   RETVALUE(ROK);
+   return ROK;
 }/* End of sctpNtfyHdlr */
 
 /*******************************************************************
@@ -423,7 +370,7 @@ S16 sctpSockPoll()
    {
       if((ret = processPolling(&e2PollParams, &ricParams.sockFd, timeoutPtr, &memInfo)) != ROK)
       {
-         DU_LOG("\nSCTP : Failed to RecvMsg for E2 at CU \n");
+         DU_LOG("\nSCTP : Failed to RecvMsg for E2 at RIC \n");
       }
    };
    RETVALUE(ret);
@@ -457,7 +404,7 @@ S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, U32 *timeou
 {
    U16 ret = ROK;
    CM_INET_FD_SET(sockFd, &pollParams->readFd);
-   ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &pollParams->numFds);
+   ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &pollParams->numFd);
    if(CM_INET_FD_ISSET(sockFd, &pollParams->readFd))
    {
       CM_INET_FD_CLR(sockFd, &pollParams->readFd);
@@ -487,7 +434,7 @@ S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, U32 *timeou
          }
       } 
   }
-  RETVALUE(ROK);
+  return ROK;
 }/* End of sctpSockPoll() */
 
 /*******************************************************************
@@ -520,10 +467,10 @@ S16 sctpSend(Buffer *mBuf)
    if(ret != ROK && ret != RWOULDBLOCK)
    {
       DU_LOG("\nSCTP : Send message failed");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
 
-   RETVALUE(ROK);
+   return ROK;
 } /* End of sctpSend */
 /**********************************************************************
          End of file
index 86fb14c..33355d8 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef __RIC_SCTP_H__
 #define __RIC_SCTP_H__
 
+#include "stdbool.h"
 #include "ric_stub.h"
 #include "cm_inet.h"
 #include "cm_tpt.h"
 #include "cm_tpt.x"
 
 #define MAX_RETRY 5
-#define DU_SCTP_UP 1
-#define DU_SCTP_DOWN 0
 
 /* Global variable declaration */
 U8   socket_type;      /* Socket type */
-Bool nonblocking;      /* Blocking/Non-blocking socket */
-Bool connUp;           /* Is connection up */
+bool nonblocking;      /* Blocking/Non-blocking socket */
+bool connUp;           /* Is connection up */
 int  assocId;          /* Assoc Id of connected assoc */
   
-SctpParamsRic sctpCfg;            /* SCTP configurations at DU */
+RicSctpParams sctpCfg;            /* SCTP configurations at DU */
 typedef struct
 {
-   S16           numFds;
-   U16           port;   
-   U32           flag;
-   Buffer        *mBuf;
-   MsgLen        bufLen; 
-   CmInetNetAddr addr;
-   CmInetFdSet      readFd;
+   uint16_t           numFd;
+   uint16_t           port;   
+   uint32_t           flag;
+   Buffer            *mBuf;
+   MsgLen             bufLen; 
+   CmInetNetAddr      addr;
+   CmInetFdSet        readFd;
    CmInetSctpSndRcvInfo   info;
    CmInetSctpNotification ntfy;
 }sctpSockPollParams;
 
 typedef struct
 {
-   U8               itfState;
-   U16              destPort;         /* DU PORTS */
-   U16              srcPort;
-   Bool             bReadFdSet;
-   CmInetFd         sockFd;           /* Socket file descriptor */
-   CmInetAddr       peerAddr;
-   CmInetFd         lstnSockFd;       /* Listening Socket file descriptor */
-   CmInetNetAddrLst destAddrLst;      /* DU Ip address */
-   CmInetNetAddrLst localAddrLst;
-   CmInetNetAddr    destIpNetAddr;    /* DU Ip address */ 
+   uint16_t              destPort;         /* DU PORTS */
+   uint16_t              srcPort;
+   bool                  bReadFdSet;
+   CmInetFd              sockFd;           /* Socket file descriptor */
+   CmInetAddr            peerAddr;
+   CmInetFd              lstnSockFd;       /* Listening Socket file descriptor */
+   CmInetNetAddrLst      destAddrLst;      /* DU Ip address */
+   CmInetNetAddrLst      localAddrLst;
+   CmInetNetAddr         destIpNetAddr;    /* DU Ip address */ 
 }CuSctpDestCb;
 
 EXTERN S16 sctpActvInit();