diff --git a/CMakeLists.txt b/CMakeLists.txt index fc6e2267e..be8b36096 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -290,6 +290,11 @@ set(SM_ENCODING_CCC "JSON" CACHE STRING "The CCC SM encoding to use") set_property(CACHE SM_ENCODING_CCC PROPERTY STRINGS "JSON") message(STATUS "Selected CCC SM_ENCODING: ${SM_ENCODING_CCC}") +# E2SM-DAPP Service Model +set(SM_ENCODING_DAPP "ASN" CACHE STRING "The DAPP SM encoding to use") +set_property(CACHE SM_ENCODING_DAPP PROPERTY STRINGS "ASN") +message(STATUS "Selected DAPP SM_ENCODING: ${SM_ENCODING_DAPP}") + ####### ## Flatbuffer encoding ####### @@ -345,6 +350,7 @@ install(TARGETS gtp_sm DESTINATION ${CMAKE_INSTALL_LIBDIR}/flexric) install(TARGETS kpm_sm DESTINATION ${CMAKE_INSTALL_LIBDIR}/flexric) install(TARGETS rc_sm DESTINATION ${CMAKE_INSTALL_LIBDIR}/flexric) install(TARGETS ccc_sm DESTINATION ${CMAKE_INSTALL_LIBDIR}/flexric) +install(TARGETS dapp_sm DESTINATION ${CMAKE_INSTALL_LIBDIR}/flexric) ####### ## Install globally nearRT-RIC diff --git a/examples/xApp/c/CMakeLists.txt b/examples/xApp/c/CMakeLists.txt index f5abd7c6b..818e2887c 100644 --- a/examples/xApp/c/CMakeLists.txt +++ b/examples/xApp/c/CMakeLists.txt @@ -10,4 +10,5 @@ add_subdirectory(tc) add_subdirectory(kpm_rc) add_subdirectory(orange) add_subdirectory(rc_handover) +add_subdirectory(spectrum) diff --git a/examples/xApp/c/spectrum/CMakeLists.txt b/examples/xApp/c/spectrum/CMakeLists.txt new file mode 100644 index 000000000..f2bd03ebb --- /dev/null +++ b/examples/xApp/c/spectrum/CMakeLists.txt @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: LicenseRef-CSSL-1.0 + +add_executable(xapp_spectrum + xapp_spectrum.c + ../../../../src/util/alg_ds/alg/defer.c +) + +target_link_libraries(xapp_spectrum PUBLIC + e42_xapp + -pthread + -lsctp + -ldl +) \ No newline at end of file diff --git a/examples/xApp/c/spectrum/xapp_spectrum.c b/examples/xApp/c/spectrum/xapp_spectrum.c new file mode 100644 index 000000000..5d918e07f --- /dev/null +++ b/examples/xApp/c/spectrum/xapp_spectrum.c @@ -0,0 +1,695 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +/** + * @file xapp_spectrum.c + * @brief Demo xApp for the E2SM-DAPP service model. + * + * This xApp shows how to handle subscription, indications, and controls + * for the E2SM-DAPP Service Model over the E2 interface via FlexRIC. + * + * Subscription behavior is controlled by the report style type: + * - Style 1 (DAPP_STYLE_E3_DATA): receives only E3 data reports. + * - Style 2 (DAPP_STYLE_SUBSCRIPTION_MAP): receives only subscription + * map updates. + * + * This version creates two independent subscriptions per E2 node: + * - Subscription A: Style 1 (E3 data only) → sm_cb_dapp_frmt1 + * - Subscription B: Style 2 (subscription map only) → sm_cb_dapp_frmt2 + * + * Each subscription receives a distinct ric_req_id, so both the xApp-side + * active-procedure registry and the agent-side bimap track them + * independently. Deletion is safe: each handle is removed by its own + * ric_req_id without affecting the other. + * + * Indication callbacks: + * - sm_cb_dapp_frmt1: handles Format 1 (E3 data, e.g. spectrum PRBs) + * - sm_cb_dapp_frmt2: handles Format 2 (dApp E3 subscription map) + * + * Control: predefined spectrum control variants can be sent periodically + * to all E2 nodes. + */ + +#include "../../../../src/util/alg_ds/ds/lock_guard/lock_guard.h" +#include "../../../../src/xApp/e42_xapp_api.h" +#include "../../../../src/util/time_now_us.h" +#include "../../../../src/util/e.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** @brief DAPP SM identifier (RAN Function ID 255). */ +int const DAPP_SM_ID = 255; + +/** @brief E3 RAN function IDs used by inner service models. */ +enum { + E3_RAN_FUNC_ID_SPECTRUM = 1, +}; + +/** + * @brief E2SM-DAPP report style types. + * + * These correspond to the styles advertised in the RAN Function Definition: + * - Style 1: E3 data reports only (indication format 1) + * - Style 2: E3 subscription map only (indication format 2) + */ +enum { + DAPP_STYLE_E3_DATA = 1, + DAPP_STYLE_SUBSCRIPTION_MAP = 2, +}; + +/** @brief Global termination flag, set by the signal handler thread. */ +static volatile sig_atomic_t g_terminate = 0; + +/** + * @brief Dedicated thread that waits for SIGINT or SIGTERM. + * + * Uses sigwait() on a pre-blocked signal set so that the main thread + * and all other threads are not interrupted. Sets g_terminate = 1 + * when a signal is received. + */ +static void* signal_thread(void* arg) +{ + sigset_t* set = (sigset_t*)arg; + int sig; + + if (sigwait(set, &sig) == 0) { + g_terminate = 1; + } + return NULL; +} + +/* ------------------------------------------------------------------ */ +/* Predefined control message variants */ +/* ------------------------------------------------------------------ */ + +/** @brief A list of PRB indices to be blocked. */ +typedef struct { + size_t count; + uint16_t prbs[273]; +} prb_list_t; + + +/** + * @brief Next value of this xApp's control-request correlation counter. + * + * The correlation id is part of the E2SM-DAPP wire format, so it is produced + * unconditionally: + * wire-visible correlation id, not a benchmarking-only one, so it must not + * depend on that build flag. Starts at 1 -- 0 is the E2SM-DAPP "no id + * assigned" sentinel (see e2sm_dapp_v0_standard.asn's SequenceId comment). + */ +static uint32_t next_sequence_id(void) { + static uint32_t counter; + return ++counter; +} + +/** + * @brief Predefined spectrum control variants for testing. + */ +static const prb_list_t ctrl_variants[] = { + {.count = 4, .prbs = {75, 80, 85, 90}}, + {.count = 5, .prbs = {100, 101, 102, 103, 104, 105}}, + {.count = 6, .prbs = {75, 76, 77, 103, 104, 105}}, + {.count = 3, .prbs = {80, 90, 100}}, + {.count = 0, .prbs = {0}}, +}; + +#define NUM_VARIANTS (sizeof(ctrl_variants) / sizeof(ctrl_variants[0])) + +/** + * @brief Print E2 node identity fields common to both header formats. + * + * @param node_type ngran_node_t cast to uint8_t. + * @param plmn_id 3-byte packed PLMN identity. + * @param node_nb_id gNB / eNB numeric identity. + * @param cu_du_present Whether the CU-DU ID is valid. + * @param cu_du_id CU-DU ID (only valid when cu_du_present is true). + */ +static void print_node_identity(uint8_t node_type, + const uint8_t plmn_id[3], + uint32_t node_nb_id, + bool cu_du_present, + uint64_t cu_du_id) +{ + printf("[DAPP][SM_CB] node_type=%u, plmn_id=%02x%02x%02x, node_nb_id=%u\n", + node_type, + plmn_id[0], + plmn_id[1], + plmn_id[2], + node_nb_id); + if (cu_du_present) { + printf("[DAPP][SM_CB] node_cu_du_id=%lu\n", (unsigned long)cu_du_id); + } +} + +/* ------------------------------------------------------------------ */ +/* Callback: Format 1 — E3 data reports */ +/* ------------------------------------------------------------------ */ + +/** + * @brief Indication callback for Format 1 (E3 data report) indications. + * + * Expects indication header format 1 (ran_function_id, dapp_id, node + * identity) and indication message format 1 (raw E3 data payload). + * Dispatches on the E3 SM type to decode and print the inner payload. + * + * Currently supports: + * - DAPP_E3_SM_SPECTRUM: prints the list of PRBs. + */ +static void sm_cb_dapp_frmt1(sm_ag_if_rd_t const* rd) +{ + assert(rd != NULL); + assert(rd->type == INDICATION_MSG_AGENT_IF_ANS_V0); + /* The SM callback runs on the dispatcher thread, not the E2 receive loop, so + * it has neither that thread's ring nor its key: open one here (idempotent) + * and stamp a point event to pair with the E2AP receive loop's stamps by + * time. lat_rep also keys XAPP_PROCESS_DONE below, marking B4's exit -- + * this function *is* the xApp's decision, so its return is the decision. */ + + const e2sm_dapp_ind_hdr_t* hdr = &rd->ind.dapp.ind.hdr; + const e2sm_dapp_ind_msg_t* msg = &rd->ind.dapp.ind.msg; + const dapp_e3_ind_payload_t* e3 = &rd->ind.dapp.ind.e3; + + assert(hdr->format == FORMAT_1_E2SM_DAPP_IND_HDR); + assert(msg->format == FORMAT_1_E2SM_DAPP_IND_MSG); + + const e2sm_dapp_ind_hdr_frmt_1_t* h1 = &hdr->frmt_1; + printf("[DAPP][FMT1] Indication: ran_function_id=%u, dapp_id=%u, age=%" PRId64 + " us, sequence_id=%" PRId64 "\n", + h1->ran_function_id, h1->dapp_id, + (time_now_ns() - h1->timestamp_ns) / 1000, h1->sequence_id); + print_node_identity(h1->node_type, h1->node_plmn_id, h1->node_nb_id, h1->node_cu_du_id_present, h1->node_cu_du_id); + + const e2sm_dapp_ind_msg_frmt_1_t* m1 = &msg->frmt_1; + + if (m1->data == NULL || m1->data_size == 0) { + printf("[DAPP][FMT1] Payload: \n"); + return; + } + + printf("[DAPP][FMT1] data_size=%u\n", (unsigned)m1->data_size); + + if (e3->type == DAPP_E3_SM_SPECTRUM) { + const spectrum_sm_report_t* rep = &e3->u.spectrum; + printf("[DAPP][FMT1] Spectrum E3 payload: prb_count=%ld, dApp-to-xApp=%" PRId64 " us\n", + rep->prb_count, (time_now_ns() - rep->timestamp_ns) / 1000); + printf("[DAPP][FMT1] %ld PRBs:", rep->prb_count); + for (long i = 0; i < rep->prb_count; ++i) { + printf(" %u", rep->prbs[i]); + } + printf("\n"); + } +} + +/* ------------------------------------------------------------------ */ +/* Callback: Format 2 — dApp E3 subscription map */ +/* ------------------------------------------------------------------ */ + +/** + * @brief Indication callback for Format 2 (subscription map) indications. + * + * Expects indication header format 2 (node identity only) and indication + * message format 2 (dApp E3 subscription list). + * + * Prints the current subscription map: which dApps are connected and + * which E3 RAN functions each is subscribed to. If no dApps are + * registered, prints an explicit "no dApps" message. + */ +static void sm_cb_dapp_frmt2(sm_ag_if_rd_t const* rd) +{ + assert(rd != NULL); + assert(rd->type == INDICATION_MSG_AGENT_IF_ANS_V0); + + const e2sm_dapp_ind_hdr_t* hdr = &rd->ind.dapp.ind.hdr; + const e2sm_dapp_ind_msg_t* msg = &rd->ind.dapp.ind.msg; + + assert(hdr->format == FORMAT_2_E2SM_DAPP_IND_HDR); + assert(msg->format == FORMAT_2_E2SM_DAPP_IND_MSG); + + const e2sm_dapp_ind_hdr_frmt_2_t* h2 = &hdr->frmt_2; + printf("[DAPP][FMT2] Indication (subscription map): age=%" PRId64 + " us, sequence_id=%" PRId64 "\n", + (time_now_ns() - h2->timestamp_ns) / 1000, h2->sequence_id); + print_node_identity(h2->node_type, h2->node_plmn_id, h2->node_nb_id, h2->node_cu_du_id_present, h2->node_cu_du_id); + + const e2sm_dapp_ind_msg_frmt_2_t* m2 = &msg->frmt_2; + const dapp_e3_subscription_list_t* subs = &m2->dapp_e3_subs; + + if (subs->sz_dapp_e3_subscriptions == 0 || subs->dapp_e3_subscriptions == NULL) { + printf("[DAPP][FMT2] No dApps currently registered on this E2 node\n"); + return; + } + + printf("[DAPP][FMT2] dApp E3 subscriptions: %zu dApp(s)\n", subs->sz_dapp_e3_subscriptions); + + for (size_t i = 0; i < subs->sz_dapp_e3_subscriptions; ++i) { + const dapp_e3_subscription_item_t* item = &subs->dapp_e3_subscriptions[i]; + printf("[DAPP][FMT2] dapp_id=%u, e3_ran_functions(%zu):", item->dapp_id, item->sz_subscribed_e3_ran_functions); + for (size_t j = 0; j < item->sz_subscribed_e3_ran_functions; ++j) { + printf(" %u", item->subscribed_e3_ran_functions[j]); + } + printf("\n"); + } +} + +/* ------------------------------------------------------------------ */ +/* Control helpers */ +/* ------------------------------------------------------------------ */ + +/** + * @brief Send a DAPP control message to all connected E2 nodes. + * + * Builds a dapp_ctrl_req_data_t with the given RAN function ID, dApp ID, + * and E3 control payload, then sends it to each E2 node via + * control_sm_xapp_api(). + * + * @param nodes Connected E2 nodes. + * @param SM_ID SM identifier (DAPP_SM_ID). + * @param ran_function_id Target E3 RAN function ID. + * @param dapp_id Target dApp ID. + * @param e3_payload E3 control payload to forward. + */ +static void send_control_message(e2_node_arr_xapp_t nodes, + int SM_ID, + uint32_t ran_function_id, + uint32_t dapp_id, + const dapp_e3_ctrl_payload_t* e3_payload) +{ + dapp_ctrl_req_data_t ctrl = (dapp_ctrl_req_data_t){0}; + + ctrl.hdr.format = FORMAT_1_E2SM_DAPP_CTRL_HDR; + ctrl.hdr.frmt_1.ran_function_id = ran_function_id; + ctrl.hdr.frmt_1.dapp_id = dapp_id; + ctrl.hdr.frmt_1.timestamp_ns = time_now_ns(); + ctrl.hdr.frmt_1.sequence_id = next_sequence_id(); + + ctrl.msg.format = FORMAT_1_E2SM_DAPP_CTRL_MSG; + ctrl.msg.frmt_1.data = NULL; + ctrl.msg.frmt_1.data_size = 0; + + ctrl.e3 = *e3_payload; + + /* Stamped before the call: control_sm_xapp_api() is synchronous, so a stamp + * after it records the completed round trip, not the send. The key is + * published for the library stages further down the same thread + * (ENCODE_E2SM_BEGIN/DONE, then ENCODE_E2AP_BEGIN/DONE). */ + for (int i = 0; i < nodes.len; i++) { + sm_ans_xapp_t ans = control_sm_xapp_api(&nodes.n[i].id, SM_ID, &ctrl); + assert(ans.success == true); + } + + free_dapp_ctrl_req_data(&ctrl); +} + +/** + * @brief Build and send a test Spectrum SM control message. + * + * Selects a predefined PRB blacklist variant (cycling through + * ctrl_variants[]) and sends it to all E2 nodes as a spectrum + * control payload. + * + * @param nodes Connected E2 nodes. + * @param variant_idx Index into ctrl_variants (wraps with modulo). + */ +static void generate_control_message_spectrum(e2_node_arr_xapp_t nodes, unsigned variant_idx) +{ + const prb_list_t* v = &ctrl_variants[variant_idx % NUM_VARIANTS]; + + spectrum_sm_control_t ctrl = (spectrum_sm_control_t){0}; + ctrl.timestamp_ns = time_now_ns(); + ctrl.prb_count = (long)v->count; + + if (ctrl.prb_count > 0) { + ctrl.blockedPRBs = calloc(ctrl.prb_count, sizeof(uint16_t)); + assert(ctrl.blockedPRBs != NULL && "Failed to allocate PRB list"); + for (size_t i = 0; i < v->count; ++i) + ctrl.blockedPRBs[i] = v->prbs[i]; + } else { + ctrl.blockedPRBs = NULL; + } + + printf("[DAPP RC]: Sending control variant %u — %ld blocked PRBs:", variant_idx % (unsigned)NUM_VARIANTS, ctrl.prb_count); + for (long i = 0; i < ctrl.prb_count; ++i) + printf(" %u", ctrl.blockedPRBs[i]); + printf("\n"); + + dapp_e3_ctrl_payload_t payload = (dapp_e3_ctrl_payload_t){0}; + payload.type = DAPP_E3_SM_SPECTRUM; + payload.u.spectrum = ctrl; + + send_control_message(nodes, DAPP_SM_ID, E3_RAN_FUNC_ID_SPECTRUM, /*dapp_id=*/1, &payload); +} + +/* ------------------------------------------------------------------ */ +/* Subscription generation */ +/* ------------------------------------------------------------------ */ + +/** + * @brief Generate a DAPP subscription with the given report style. + * + * Builds a dapp_sub_data_t containing: + * - Event trigger: Format 1 (common to all styles) + * - Action definition: Format 1 with the requested ric_style_type + * + * The style type determines what indications the agent will send: + * 1 = E3 data only + * 2 = subscription map only + * + * @param ran_func The RAN function definition. + * @param style_type Report style type (1 or 2). + * @return Populated subscription data (caller must free via + * free_dapp_sub_data()). + */ +static dapp_sub_data_t gen_dapp_subs(e2sm_dapp_func_def_t const* ran_func, uint32_t style_type) +{ + assert(ran_func != NULL); + dapp_sub_data_t dapp_sub = {0}; + + dapp_sub.et.format = FORMAT_1_E2SM_DAPP_EV_TRIGGER_FORMAT; + dapp_sub.et.frmt_1 = (e2sm_dapp_ev_trg_frmt_1_t){}; + + dapp_sub.action_def = calloc(1, sizeof(e2sm_dapp_action_def_t)); + assert(dapp_sub.action_def != NULL); + dapp_sub.action_def->format = FORMAT_1_E2SM_DAPP_ACTION_DEF; + dapp_sub.action_def->ric_style_type = style_type; + dapp_sub.action_def->frmt_1 = (e2sm_dapp_action_def_frmt_1_t){}; + + return dapp_sub; +} + +/** + * @brief Find the index of a RAN function by SM ID in a RAN function array. + * + * @param rf Array of RAN functions. + * @param sz Size of the array. + * @param f Predicate function: returns true if the element matches. + * @param id The SM ID to search for. + * @return Index of the matching element. Asserts if not found. + */ +static size_t find_sm_idx(sm_ran_function_t* rf, size_t sz, bool (*f)(sm_ran_function_t const*, int const), int const id) +{ + for (size_t i = 0; i < sz; i++) { + if (f(&rf[i], id)) + return i; + } + + assert(0 != 0 && "SM ID could not be found in the RAN Function List"); +} + +/** + * @brief Predicate: returns true if elem->id matches the given SM ID. + */ +static bool eq_sm(sm_ran_function_t const* elem, int const id) +{ + if (elem->id == id) + return true; + + return false; +} + +/** + * @brief Print dApp E3 subscription list with configurable indentation. + * + * Prints which dApps are subscribed and which E3 RAN functions each + * is registered for. If the list is NULL or empty, prints "none". + * + * @param subs Pointer to the subscription list (may be NULL). + * @param indent Prefix string for each output line (e.g. " "). + */ +static void print_dapp_e3_subs(const dapp_e3_subscription_list_t* subs, const char* indent) +{ + if (subs == NULL || subs->sz_dapp_e3_subscriptions == 0 || subs->dapp_e3_subscriptions == NULL) { + printf("%sdApp E3 subscriptions: none\n", indent); + return; + } + + printf("%sdApp E3 subscriptions (%zu):\n", indent, subs->sz_dapp_e3_subscriptions); + for (size_t i = 0; i < subs->sz_dapp_e3_subscriptions; ++i) { + const dapp_e3_subscription_item_t* sub = &subs->dapp_e3_subscriptions[i]; + printf("%s - dApp %u: subscribed to %zu E3 RAN function(s):", indent, sub->dapp_id, sub->sz_subscribed_e3_ran_functions); + for (size_t j = 0; j < sub->sz_subscribed_e3_ran_functions; ++j) { + printf(" %u", sub->subscribed_e3_ran_functions[j]); + } + printf("\n"); + } +} + +/** + * @brief Print detailed information about a DAPP RAN function definition. + * + * Displays SM ID, name, description, OID, event trigger presence, + * all report styles (with per-style dApp E3 subscriptions), and + * all control styles (with per-style dApp E3 subscriptions). + * + * @param idx Index of the RAN function in the node's RF array. + * @param n The E2 node whose RAN function to print. + */ +static void print_dapp_sm_info(size_t idx, e2_node_connected_xapp_t const* n) +{ + assert(n != NULL); + assert(idx < n->len_rf); + + const sm_ran_function_t* rf = &n->rf[idx]; + + assert(rf->defn.type == DAPP_RAN_FUNC_DEF_E); + + const e2sm_dapp_func_def_t* d = &rf->defn.dapp; + + printf("[DAPP xApp] RAN function @idx=%zu\n", idx); + printf(" SM ID: %d\n", rf->id); + + if (d->name.name.buf && d->name.name.len > 0) { + printf(" Name: %.*s\n", (int)d->name.name.len, (const char*)d->name.name.buf); + } + + if (d->name.description.buf && d->name.description.len > 0) { + printf(" Description: %.*s\n", (int)d->name.description.len, (const char*)d->name.description.buf); + } + + if (d->name.oid.buf && d->name.oid.len > 0) { + printf(" OID: %.*s\n", (int)d->name.oid.len, (const char*)d->name.oid.buf); + } + + if (d->ev_trig == NULL) { + printf(" Event trigger: none\n"); + } else { + printf(" Event trigger: present (details omitted)\n"); + } + + if (d->report != NULL && d->report->sz_seq_report_sty > 0 && d->report->seq_report_sty != NULL) { + printf(" Report styles (%zu):\n", d->report->sz_seq_report_sty); + + for (size_t i = 0; i < d->report->sz_seq_report_sty; ++i) { + const seq_report_sty_dapp_sm_t* s = &d->report->seq_report_sty[i]; + + printf( + " - report_type=%u, name=%.*s, " + "ind_hdr_type=%u, ind_msg_type=%u\n", + s->report_type, + (int)s->name.len, + (const char*)s->name.buf, + s->ind_hdr_type, + s->ind_msg_type); + + print_dapp_e3_subs(s->dapp_e3_subs, " "); + } + } else { + printf(" Report styles: none\n"); + } + + if (d->ctrl != NULL && d->ctrl->sz_seq_ctrl_style > 0 && d->ctrl->seq_ctrl_style != NULL) { + printf(" Control styles (%zu):\n", d->ctrl->sz_seq_ctrl_style); + + for (size_t i = 0; i < d->ctrl->sz_seq_ctrl_style; ++i) { + const seq_ctrl_style_dapp_sm_t* s = &d->ctrl->seq_ctrl_style[i]; + + printf( + " - style_type=%u, name=%.*s, " + "hdr_type=%u, msg_type=%u, out_frmt_type=%u\n", + s->style_type, + (int)s->name.len, + (const char*)s->name.buf, + s->hdr, + s->msg, + s->out_frmt); + + print_dapp_e3_subs(s->dapp_e3_subs, " "); + } + } else { + printf(" Control styles: none\n"); + } +} + +/* ------------------------------------------------------------------ */ +/* Subscription management */ +/* ------------------------------------------------------------------ */ + +/** + * @brief Subscribe to the DAPP SM on all connected E2 nodes. + * + * For each E2 node: + * - Locates the DAPP RAN function in the node's RF list. + * - Prints the RAN function definition for debugging. + * - Builds a subscription with the requested report style. + * - Installs the subscription via report_sm_xapp_api(). + * - Stores the subscription handle in hndl[i]. + * + * @param nodes Connected E2 nodes. + * @param hndl Output array for subscription handles (one per node). + * @param style_type Report style (1 = E3 data, 2 = sub map). + * @param cb Indication callback function. + * @param label Human-readable label for log messages. + */ +static void subscribe_sm(e2_node_arr_xapp_t nodes, sm_ans_xapp_t* hndl, uint32_t style_type, sm_cb cb, const char* label) +{ + for (size_t i = 0; i < nodes.len; ++i) { + e2_node_connected_xapp_t* n = &nodes.n[i]; + + size_t const idx = find_sm_idx(n->rf, n->len_rf, eq_sm, DAPP_SM_ID); + assert(n->rf[idx].defn.type == DAPP_RAN_FUNC_DEF_E && "DAPP is not the received RAN Function"); + + if (n->rf[idx].defn.dapp.name.name.buf != NULL) { + print_dapp_sm_info(idx, n); + + dapp_sub_data_t dapp_sub = gen_dapp_subs(&n->rf[idx].defn.dapp, style_type); + + printf("[DAPP RC]: Installing %s (style %u) subscription on E2 node %zu\n", label, style_type, i); + hndl[i] = report_sm_xapp_api(&n->id, DAPP_SM_ID, &dapp_sub, cb); + assert(hndl[i].success == true); + + free_dapp_sub_data(&dapp_sub); + } + } +} + +/** + * @brief Remove DAPP SM subscriptions from all E2 nodes. + * + * Iterates over the handle array and calls rm_report_sm_xapp_api() + * for each successful subscription. + * + * @param hndl Array of subscription handles. + * @param nodes Connected E2 nodes (used for array length). + */ +static void delete_subscriptions(sm_ans_xapp_t* hndl, e2_node_arr_xapp_t nodes) +{ + for (int i = 0; i < nodes.len; ++i) { + if (hndl[i].success == true) { + rm_report_sm_xapp_api(hndl[i].u.handle); + } + } +} + +/* ------------------------------------------------------------------ */ +/* main */ +/* ------------------------------------------------------------------ */ + +/** + * @brief Entry point for the DAPP xApp. + * + * Workflow: + * 1. Parse command-line args and initialize the xApp API. + * 2. Set up a dedicated signal-handling thread for clean shutdown. + * 3. Retrieve connected E2 nodes. + * 4. Subscribe to the DAPP SM twice (E3 data + subscription map). + * 5. Enter a periodic loop (indications are handled asynchronously + * by the registered callbacks). + * 6. On SIGINT/SIGTERM or timeout: unsubscribe both, stop the API, + * and exit. + */ +int main(int argc, char* argv[]) +{ + fr_args_t args = init_fr_args(argc, argv); + + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGINT); + sigaddset(&set, SIGTERM); + + int rc = pthread_sigmask(SIG_BLOCK, &set, NULL); + assert(rc == 0); + + pthread_t sig_thr; + rc = pthread_create(&sig_thr, NULL, signal_thread, &set); + assert(rc == 0); + + init_xapp_api(&args); + sleep(1); + + e2_node_arr_xapp_t nodes = e2_nodes_xapp_api(); + assert(nodes.len > 0); + + printf("[DAPP RC]: Connected E2 nodes = %d\n", nodes.len); + + /* Allocate two independent handle arrays — one per subscription */ + sm_ans_xapp_t* hndl_e3_data = calloc(nodes.len, sizeof(sm_ans_xapp_t)); + assert(hndl_e3_data != NULL); + + sm_ans_xapp_t* hndl_sub_map = calloc(nodes.len, sizeof(sm_ans_xapp_t)); + assert(hndl_sub_map != NULL); + + /* + * Two subscriptions per E2 node, each with its own ric_req_id: + * + * Subscription A — Style 1 (E3 data only): + * Receives Format 1 indications (E3 data reports). + * Callback: sm_cb_dapp_frmt1 + * + * Subscription B — Style 2 (subscription map only): + * Receives Format 2 indications (dApp E3 subscription map). + * Callback: sm_cb_dapp_frmt2 + * + * Both subscriptions target the same ran_func_id (DAPP_SM_ID = 255) + * but receive distinct ric_req_ids, so the xApp active-procedure + * registry and the agent bimap track them independently. + */ + subscribe_sm(nodes, hndl_e3_data, DAPP_STYLE_E3_DATA, sm_cb_dapp_frmt1, "DAPP (E3 data)"); + subscribe_sm(nodes, hndl_sub_map, DAPP_STYLE_SUBSCRIPTION_MAP, sm_cb_dapp_frmt2, "DAPP (subscription map)"); + + /* ---- Periodic loop ---- */ + const unsigned ctrl_period_sec = 5; + const unsigned max_runtime_sec = 600; + unsigned elapsed = 0; + unsigned variant = 0; + + while (!g_terminate && elapsed < max_runtime_sec) { + generate_control_message_spectrum(nodes, variant); + variant++; + + for (unsigned s = 0; s < ctrl_period_sec && !g_terminate; ++s) { + sleep(1); + ++elapsed; + } + } + + if (g_terminate) { + printf("[DAPP RC]: Termination signal received, shutting down...\n"); + } else { + printf("[DAPP RC]: Max runtime reached, shutting down...\n"); + } + + /* Delete both subscriptions independently */ + + delete_subscriptions(hndl_e3_data, nodes); + delete_subscriptions(hndl_sub_map, nodes); + + free(hndl_e3_data); + free(hndl_sub_map); + + sleep(1); + + while (try_stop_xapp_api() == false) + usleep(1000); + + free_e2_node_arr_xapp(&nodes); + + printf("[DAPP RC]: Test xApp run SUCCESSFULLY\n"); +} diff --git a/examples/xApp/python3/xapp_spectrum.py b/examples/xApp/python3/xapp_spectrum.py new file mode 100644 index 000000000..f166bbf61 --- /dev/null +++ b/examples/xApp/python3/xapp_spectrum.py @@ -0,0 +1,215 @@ +# SPDX-License-Identifier: LicenseRef-CSSL-1.0 + +""" +xapp_spectrum.py — Python port of the E2SM-DAPP spectrum xApp. + +Mirrors the behaviour of examples/xApp/c/spectrum/xapp_spectrum.c: + - Two independent subscriptions per E2 node: + Subscription A (Style 1): E3 data reports → DAPPFrmt1Callback + Subscription B (Style 2): subscription map → DAPPFrmt2Callback + - A periodic control loop that cycles through predefined PRB blacklists + and sends them to every connected E2 node. + - Clean shutdown on SIGINT / SIGTERM. + +Usage: + python3 xapp_spectrum.py +""" + +import xapp_sdk as ric +import time +import signal +import threading + +########################################################################## +# Constants +########################################################################## + +DAPP_SM_ID = 255 +E3_RAN_FUNC_ID_SPECTRUM = 1 +DAPP_ID = 1 + +CTRL_PERIOD_SEC = 5 +MAX_RUNTIME_SEC = 600 + +# Predefined PRB blacklist variants (mirrors ctrl_variants[] in the C xApp) +CTRL_VARIANTS = [ + [75, 80, 85, 90], + [100, 101, 102, 103, 104], + [75, 76, 77, 103, 104, 105], + [80, 90, 100], + [], # empty = unblock all +] + +########################################################################## +# Indication callbacks +########################################################################## + +class DAPPFrmt1Callback(ric.dapp_e3_data_cb): + """Handles Format 1 indications: E3 data reports (spectrum PRBs).""" + + def __init__(self): + ric.dapp_e3_data_cb.__init__(self) + + def handle(self, ind): + age_us = (time.time_ns() - ind.timestamp_ns) // 1000 + print( + f"[DAPP][FMT1] Indication: ran_function_id={ind.ran_function_id}, " + f"dapp_id={ind.dapp_id}, age={age_us} us" + ) + print( + f"[DAPP][FMT1] node_type={ind.node_type}, " + f"plmn_id={ind.plmn_0:02x}{ind.plmn_1:02x}{ind.plmn_2:02x}, " + f"node_nb_id={ind.node_nb_id}" + ) + if ind.node_cu_du_id_present: + print(f"[DAPP][FMT1] node_cu_du_id={ind.node_cu_du_id}") + + prbs = list(ind.prbs) + print(f"[DAPP][FMT1] Spectrum E3 payload: prb_count={len(prbs)}") + print(f"[DAPP][FMT1] PRBs: {prbs}") + + +class DAPPFrmt2Callback(ric.dapp_sub_map_cb): + """Handles Format 2 indications: dApp E3 subscription map.""" + + def __init__(self): + ric.dapp_sub_map_cb.__init__(self) + + def handle(self, ind): + age_us = (time.time_ns() - ind.timestamp_ns) // 1000 + print(f"[DAPP][FMT2] Indication (subscription map): age={age_us} us") + print( + f"[DAPP][FMT2] node_type={ind.node_type}, " + f"plmn_id={ind.plmn_0:02x}{ind.plmn_1:02x}{ind.plmn_2:02x}, " + f"node_nb_id={ind.node_nb_id}" + ) + if ind.node_cu_du_id_present: + print(f"[DAPP][FMT2] node_cu_du_id={ind.node_cu_du_id}") + + subs = list(ind.dapp_subs) + if not subs: + print("[DAPP][FMT2] No dApps currently registered on this E2 node") + return + + print(f"[DAPP][FMT2] dApp E3 subscriptions: {len(subs)} dApp(s)") + for item in subs: + funcs = list(item.e3_ran_functions) + print(f"[DAPP][FMT2] dapp_id={item.dapp_id}, " + f"e3_ran_functions({len(funcs)}): {funcs}") + + +########################################################################## +# Control helper +########################################################################## + +def send_spectrum_control(conn, variant_idx): + """Send a PRB blacklist control to every connected E2 node.""" + prbs = CTRL_VARIANTS[variant_idx % len(CTRL_VARIANTS)] + + # Build a SWIG uint16_t vector + prb_vec = ric.DAPP_PRBVector() + for p in prbs: + prb_vec.push_back(p) + + print( + f"[DAPP RC] Sending control variant {variant_idx % len(CTRL_VARIANTS)} " + f"— {len(prbs)} blocked PRBs: {prbs}" + ) + + for node in conn: + ric.control_dapp_spectrum_sm(node.id, E3_RAN_FUNC_ID_SPECTRUM, DAPP_ID, prb_vec) + + +########################################################################## +# Signal handling — mirrors the C xApp's signal_thread pattern +# +# init_xapp_api() (called by ric.init()) installs a C-level SIGINT handler +# that calls try_stop_xapp_api() + exit(), bypassing Python cleanup. +# We prevent that by: +# 1. Blocking SIGINT/SIGTERM in the main thread *before* ric.init(). +# 2. Running a dedicated Python thread that waits for the signal via +# signal.sigwait() and sets g_terminate — exactly like the C xApp's +# signal_thread / sigwait() pattern. +# +# With the signal blocked everywhere, the C sig_handler is never invoked; +# our thread catches the signal, sets g_terminate, and the main loop +# exits cleanly to run the unsubscribe / cleanup code. +########################################################################## + +g_terminate = False + +def _signal_thread(): + global g_terminate + signal.sigwait({signal.SIGINT, signal.SIGTERM}) + g_terminate = True + +# Block SIGINT/SIGTERM before ric.init() so the C sig_handler never fires. +signal.pthread_sigmask(signal.SIG_BLOCK, {signal.SIGINT, signal.SIGTERM}) + +sig_thr = threading.Thread(target=_signal_thread, daemon=True) +sig_thr.start() + +########################################################################## +# Main +########################################################################## + +ric.init() + +conn = ric.conn_e2_nodes() +assert len(conn) > 0, "No E2 nodes connected" +print(f"[DAPP RC] Connected E2 nodes = {len(conn)}") + +# ----- Print DAPP RAN function definition (mirrors print_dapp_sm_info in C xApp) ----- +for node in conn: + ric.print_dapp_ran_func_info(node.id) + +# ----- Subscribe: Style 1 — E3 data (one handle per node) ----- +cb_e3_data = DAPPFrmt1Callback() +cb_sub_map = DAPPFrmt2Callback() + +hndl_e3_data = [] +hndl_sub_map = [] + +for node in conn: + h1 = ric.report_dapp_e3_data_sm(node.id, cb_e3_data) + hndl_e3_data.append(h1) + print(f"[DAPP RC] Installed E3-data subscription (style 1), handle={h1}") + +# ----- Subscribe: Style 2 — subscription map ----- +for node in conn: + h2 = ric.report_dapp_sub_map_sm(node.id, cb_sub_map) + hndl_sub_map.append(h2) + print(f"[DAPP RC] Installed sub-map subscription (style 2), handle={h2}") + +# ----- Periodic control loop ----- +elapsed = 0 +variant = 0 + +while not g_terminate and elapsed < MAX_RUNTIME_SEC: + send_spectrum_control(conn, variant) + variant += 1 + + for _ in range(CTRL_PERIOD_SEC): + if g_terminate: + break + time.sleep(1) + elapsed += 1 + +if g_terminate: + print("[DAPP RC] Termination signal received, shutting down...") +else: + print("[DAPP RC] Max runtime reached, shutting down...") + +# ----- Unsubscribe ----- +for h in hndl_e3_data: + ric.rm_report_dapp_e3_data_sm(h) + +for h in hndl_sub_map: + ric.rm_report_dapp_sub_map_sm(h) + +time.sleep(1) + +while ric.try_stop() == False: + time.sleep(0.001) + +print("[DAPP RC] Test xApp run SUCCESSFULLY") diff --git a/src/agent/e2_agent.c b/src/agent/e2_agent.c index 59a4780b4..2f8ac5952 100644 --- a/src/agent/e2_agent.c +++ b/src/agent/e2_agent.c @@ -619,3 +619,15 @@ void e2_send_control_failure(e2_agent_t* ag, const ric_control_failure_t* cf) free_byte_array(ba); } +void e2_send_ric_service_update(e2_agent_t* ag, const ric_service_update_t* su) +{ + assert(ag != NULL); + assert(su != NULL); + + e2ap_msg_t msg = {.type = RIC_SERVICE_UPDATE}; + msg.u_msgs.ric_serv_updt = *su; + + byte_array_t ba = e2ap_msg_enc_ag(&ag->ap, &msg); + e2ap_send_bytes_agent(&ag->ep, ba); + free_byte_array(ba); +} diff --git a/src/agent/e2_agent.h b/src/agent/e2_agent.h index fed1209c9..0283f3a76 100644 --- a/src/agent/e2_agent.h +++ b/src/agent/e2_agent.h @@ -97,6 +97,8 @@ void e2_send_control_acknowledge(e2_agent_t* ag, const ric_control_acknowledge_t void e2_send_control_failure(e2_agent_t* ag, const ric_control_failure_t* cf); +void e2_send_ric_service_update(e2_agent_t* ag, const ric_service_update_t* su); + //////////////////////////////////////////////// #undef NUM_HANDLE_MSG diff --git a/src/agent/e2_agent_api.c b/src/agent/e2_agent_api.c index f5d746aff..b857a6d10 100644 --- a/src/agent/e2_agent_api.c +++ b/src/agent/e2_agent_api.c @@ -6,6 +6,8 @@ #include // for assert #include // for pthread_cr... +#include +#include // for strdup, strlen #include #include // for NULL #include "e2_agent.h" // for e2_free_agent @@ -112,3 +114,49 @@ void async_event_agent_api(uint32_t ric_req_id, void* ind_data) e2_async_event_agent(agent, ric_req_id, ind_data); } +/* Re-advertise one RAN function to the RIC with a bumped revision. + * + * A service model whose RAN function definition changes at runtime -- because + * what it exposes depends on state the RAN learns after E2 SETUP -- has no way + * to tell the RIC without this: E2 SETUP happens once. The revision is + * per-call and monotonic, which is what makes the RIC replace the stored + * definition rather than reject it as a duplicate. */ +void trigger_ric_service_update_api(uint16_t ran_func_id) +{ + if (agent == NULL) { + printf("[E2 AGENT]: not initialised yet, skipping RIC Service Update\n"); + return; + } + + sm_agent_t* sm = sm_plugin_ag(&agent->plugin, ran_func_id); + if (sm == NULL) { + printf("[E2 AGENT]: no service model for RAN function %u, cannot send RIC Service Update\n", ran_func_id); + return; + } + + static _Atomic uint16_t service_update_rev = 1; + + sm_e2_setup_data_t setup = sm->proc.on_e2_setup(sm); + + ric_service_update_t su = {0}; + su.trans_id = (uint8_t)(atomic_load(&service_update_rev) % 256); + + su.len_modified = 1; + su.modified = calloc(1, sizeof(ran_function_t)); + assert(su.modified != NULL && "Memory exhausted"); + + su.modified[0].id = sm->info.id(); + su.modified[0].rev = atomic_fetch_add(&service_update_rev, 1); + su.modified[0].defn.buf = setup.ran_fun_def; + su.modified[0].defn.len = setup.len_rfd; + + const char* oid = sm->info.oid(); + su.modified[0].oid.buf = (uint8_t*)strdup(oid); + su.modified[0].oid.len = strlen(oid); + + e2_send_ric_service_update(agent, &su); + + free(su.modified[0].defn.buf); + free(su.modified[0].oid.buf); + free(su.modified); +} diff --git a/src/agent/e2_agent_api.h b/src/agent/e2_agent_api.h index 32622248b..4494264ca 100644 --- a/src/agent/e2_agent_api.h +++ b/src/agent/e2_agent_api.h @@ -8,6 +8,7 @@ #include "../sm/sm_io.h" #include "../util/conf_file.h" #include "../util/ngran_types.h" +#include void init_agent_api(int mcc, int mnc, @@ -22,5 +23,7 @@ void stop_agent_api(void); void async_event_agent_api(uint32_t ric_req_id, void* ind_data); +void trigger_ric_service_update_api(uint16_t ran_func_id); + #endif diff --git a/src/agent/msg_handler_agent.c b/src/agent/msg_handler_agent.c index 52570e3f0..8e2b33fa7 100644 --- a/src/agent/msg_handler_agent.c +++ b/src/agent/msg_handler_agent.c @@ -426,7 +426,16 @@ e2ap_msg_t e2ap_handle_service_update_ack_agent(e2_agent_t* ag, const e2ap_msg_t { assert(ag != NULL); assert(msg != NULL); - assert(0!=0 && "Not implemented"); + assert(msg->type == RIC_SERVICE_UPDATE_ACKNOWLEDGE); + + const ric_service_update_ack_t* ack = &msg->u_msgs.ric_serv_updt_ack; + printf("[E2-AGENT]: RIC SERVICE UPDATE ACKNOWLEDGE rx (accepted=%zu, rejected=%zu)\n", + ack->len_accepted, ack->len_rejected); + + for (size_t i = 0; i < ack->len_rejected; ++i) { + printf("[E2-AGENT]: RAN function %d REJECTED by the RIC, cause group %d\n", + ack->rejected[i].id, ack->rejected[i].cause.present); + } e2ap_msg_t ans = {.type = NONE_E2_MSG_TYPE}; return ans; diff --git a/src/lib/e2ap/v1_01/e2ap_types/ric_service_update.c b/src/lib/e2ap/v1_01/e2ap_types/ric_service_update.c index 69e8c616e..234caa962 100644 --- a/src/lib/e2ap/v1_01/e2ap_types/ric_service_update.c +++ b/src/lib/e2ap/v1_01/e2ap_types/ric_service_update.c @@ -25,7 +25,7 @@ bool eq_ric_service_update(const ric_service_update_t* m0, const ric_service_upd return false; for(size_t i = 0; i < m0->len_modified; ++i){ - if(eq_ran_function(&m0->modified[i], &m1->modified[i])) + if(eq_ran_function(&m0->modified[i], &m1->modified[i]) == false) return false; } diff --git a/src/lib/e2ap/v1_01/e2ap_types/ric_service_update.h b/src/lib/e2ap/v1_01/e2ap_types/ric_service_update.h index eb0981971..4f72db957 100644 --- a/src/lib/e2ap/v1_01/e2ap_types/ric_service_update.h +++ b/src/lib/e2ap/v1_01/e2ap_types/ric_service_update.h @@ -9,6 +9,7 @@ #include "common/e2ap_ran_function.h" #include "common/e2ap_ran_function_id_rev.h" +#include "common/e2ap_global_node_id.h" typedef struct { @@ -20,6 +21,8 @@ typedef struct { e2ap_ran_function_id_rev_t* deleted; size_t len_deleted; + + global_e2_node_id_t e2_node_id; } ric_service_update_t; bool eq_ric_service_update(const ric_service_update_t* m0, const ric_service_update_t* m1); diff --git a/src/lib/e2ap/v1_01/free/e2ap_msg_free.c b/src/lib/e2ap/v1_01/free/e2ap_msg_free.c index abfc82426..1b5daaab9 100644 --- a/src/lib/e2ap/v1_01/free/e2ap_msg_free.c +++ b/src/lib/e2ap/v1_01/free/e2ap_msg_free.c @@ -400,6 +400,8 @@ void e2ap_free_service_update(ric_service_update_t* su) free(su->modified); free(su->deleted); + + free_global_e2_node_id(&su->e2_node_id); } // RIC -> E2 diff --git a/src/lib/e2ap/v2_03/dec/e2ap_msg_dec_asn.c b/src/lib/e2ap/v2_03/dec/e2ap_msg_dec_asn.c index f35d9086c..6cdad8328 100644 --- a/src/lib/e2ap/v2_03/dec/e2ap_msg_dec_asn.c +++ b/src/lib/e2ap/v2_03/dec/e2ap_msg_dec_asn.c @@ -1990,8 +1990,6 @@ e2ap_msg_t e2ap_dec_service_update(const E2AP_PDU_t* pdu) { assert(pdu != NULL); - assert(0!=0 && "Untested code"); - e2ap_msg_t ret = {.type = RIC_SERVICE_UPDATE}; ric_service_update_t* su = &ret.u_msgs.ric_serv_updt; @@ -2002,63 +2000,56 @@ e2ap_msg_t e2ap_dec_service_update(const E2AP_PDU_t* pdu) assert(pdu->choice.initiatingMessage->value.present == InitiatingMessage__value_PR_RICserviceUpdate); const RICserviceUpdate_t *out = &pdu->choice.initiatingMessage->value.choice.RICserviceUpdate; + assert(out->protocolIEs.list.count >= 1); - // TransactionID. Mandatory + // TransactionID. Mandatory (first IE) const RICserviceUpdate_IEs_t* trans_id = out->protocolIEs.list.array[0]; assert(trans_id->id == ProtocolIE_ID_id_TransactionID); assert(trans_id->criticality == Criticality_reject); assert(trans_id->value.present == RICserviceUpdate_IEs__value_PR_TransactionID); su->trans_id = trans_id->value.choice.TransactionID; - // List of RAN Functions Added - const RICserviceUpdate_IEs_t* ran_add = out->protocolIEs.list.array[1]; - assert(ran_add->id == ProtocolIE_ID_id_RANfunctionsAdded); - assert(ran_add->criticality == Criticality_reject); - assert(ran_add->value.present == RICserviceUpdate_IEs__value_PR_RANfunctions_List); - const int sz_add = ran_add->value.choice.RANfunctions_List.list.count; - su->added = calloc(sz_add, sizeof(ran_function_t)); - su->len_added = sz_add; - for(int i = 0; i < sz_add; ++i){ - const RANfunction_ItemIEs_t* r = (const RANfunction_ItemIEs_t*)ran_add->value.choice.RANfunctions_List.list.array[i]; - assert(r->id == ProtocolIE_ID_id_RANfunction_Item); - assert(r->criticality == Criticality_reject); - assert(r->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item); - su->added[i] = copy_ran_function(&r->value.choice.RANfunction_Item); - } - - // List of RAN Functions Modified - const RICserviceUpdate_IEs_t* ran_mod = out->protocolIEs.list.array[2]; - assert(ran_mod->id == ProtocolIE_ID_id_RANfunctionsModified); - assert(ran_mod->criticality == Criticality_reject); - assert(ran_mod->value.present == RICserviceUpdate_IEs__value_PR_RANfunctions_List); - - const int sz_mod = ran_mod->value.choice.RANfunctions_List.list.count; - su->modified = calloc(sz_mod, sizeof(ran_function_t)); - su->len_modified = sz_mod; - for(int i = 0; i < sz_mod; ++i){ - const RANfunction_ItemIEs_t* r = (const RANfunction_ItemIEs_t*)ran_mod->value.choice.RANfunctions_List.list.array[i]; - assert(r->id == ProtocolIE_ID_id_RANfunction_Item); - assert(r->criticality == Criticality_reject); - assert(r->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item); - su->modified[i] = copy_ran_function(&r->value.choice.RANfunction_Item); + // Remaining IEs are optional — iterate by ID + for (int elm = 1; elm < out->protocolIEs.list.count; ++elm) { + const RICserviceUpdate_IEs_t* ie = out->protocolIEs.list.array[elm]; + + if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) { + assert(ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctions_List); + const int sz = ie->value.choice.RANfunctions_List.list.count; + su->added = calloc(sz, sizeof(ran_function_t)); + su->len_added = sz; + for (int i = 0; i < sz; ++i) { + const RANfunction_ItemIEs_t* r = (const RANfunction_ItemIEs_t*)ie->value.choice.RANfunctions_List.list.array[i]; + assert(r->id == ProtocolIE_ID_id_RANfunction_Item); + assert(r->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item); + su->added[i] = copy_ran_function(&r->value.choice.RANfunction_Item); + } + } else if (ie->id == ProtocolIE_ID_id_RANfunctionsModified) { + assert(ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctions_List_1); + const int sz = ie->value.choice.RANfunctions_List_1.list.count; + su->modified = calloc(sz, sizeof(ran_function_t)); + su->len_modified = sz; + for (int i = 0; i < sz; ++i) { + const RANfunction_ItemIEs_t* r = (const RANfunction_ItemIEs_t*)ie->value.choice.RANfunctions_List_1.list.array[i]; + assert(r->id == ProtocolIE_ID_id_RANfunction_Item); + assert(r->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item); + su->modified[i] = copy_ran_function(&r->value.choice.RANfunction_Item); + } + } else if (ie->id == ProtocolIE_ID_id_RANfunctionsDeleted) { + assert(ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctionsID_List); + const int sz = ie->value.choice.RANfunctionsID_List.list.count; + su->deleted = calloc(sz, sizeof(e2ap_ran_function_id_rev_t)); + su->len_deleted = sz; + for (int i = 0; i < sz; ++i) { + const RANfunctionID_ItemIEs_t* r = (const RANfunctionID_ItemIEs_t*)ie->value.choice.RANfunctionsID_List.list.array[i]; + assert(r->id == ProtocolIE_ID_id_RANfunctionID_Item); + assert(r->value.present == RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item); + su->deleted[i].id = r->value.choice.RANfunctionID_Item.ranFunctionID; + su->deleted[i].rev = r->value.choice.RANfunctionID_Item.ranFunctionRevision; + } + } } - // List of RAN Functions Deleted - const RICserviceUpdate_IEs_t* ran_del = out->protocolIEs.list.array[3]; - assert(ran_del->id == ProtocolIE_ID_id_RANfunctionsDeleted); - assert(ran_del->criticality == Criticality_reject); - assert(ran_del->value.present == RICserviceUpdate_IEs__value_PR_RANfunctionsID_List); - const int sz_del = ran_del->value.choice.RANfunctions_List.list.count; - su->deleted = calloc(sz_del, sizeof(e2ap_ran_function_id_rev_t)); - su->len_deleted = sz_del; - for(int i = 0; i < sz_del; ++i){ - const RANfunction_ItemIEs_t* r = (const RANfunction_ItemIEs_t*)ran_del->value.choice.RANfunctions_List.list.array[i]; - assert(r->id == ProtocolIE_ID_id_RANfunction_Item); - assert(r->criticality == Criticality_reject); - assert(r->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item); - su->deleted[i].id = r->value.choice.RANfunction_Item.ranFunctionID; - su->deleted[i].rev = r->value.choice.RANfunction_Item.ranFunctionRevision; - } return ret; } @@ -2068,8 +2059,6 @@ e2ap_msg_t e2ap_dec_service_update_ack(const E2AP_PDU_t* pdu) { assert(pdu != NULL); - assert(0!=0 && "Untested code"); - e2ap_msg_t ret = {.type = RIC_SERVICE_UPDATE_ACKNOWLEDGE}; ric_service_update_ack_t* su = &ret.u_msgs.ric_serv_updt_ack; // Message Type. Mandatory @@ -2096,14 +2085,14 @@ e2ap_msg_t e2ap_dec_service_update_ack(const E2AP_PDU_t* pdu) if(up_ack->id == ProtocolIE_ID_id_RANfunctionsAccepted){ // List of RAN Functions Accepted RICserviceUpdateAcknowledge_IEs_t* update_ack = up_ack; - assert(update_ack->criticality == Criticality_ignore); + assert(update_ack->criticality == Criticality_reject); assert(update_ack->value.present == RICserviceUpdateAcknowledge_IEs__value_PR_RANfunctionsID_List); const int sz_acc = update_ack->value.choice.RANfunctionsID_List.list.count; su->accepted = calloc(sz_acc, sizeof(ran_function_id_t)); su->len_accepted = sz_acc; for(int i = 0; i < sz_acc; ++i){ const RANfunctionID_ItemIEs_t* r = (const RANfunctionID_ItemIEs_t*)update_ack->value.choice.RANfunctionsID_List.list.array[i]; - assert(r->id == ProtocolIE_ID_id_RANfunction_Item); + assert(r->id == ProtocolIE_ID_id_RANfunctionID_Item); assert(r->criticality == Criticality_reject); assert(r->value.present == RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item); su->accepted[i].id = r->value.choice.RANfunctionID_Item.ranFunctionID; @@ -2113,13 +2102,13 @@ e2ap_msg_t e2ap_dec_service_update_ack(const E2AP_PDU_t* pdu) // List of RAN Functions Rejected RICserviceUpdateAcknowledge_IEs_t* func_reject_ie = up_ack; assert(func_reject_ie->id == ProtocolIE_ID_id_RANfunctionsRejected); - assert(func_reject_ie->criticality == Criticality_ignore); + assert(func_reject_ie->criticality == Criticality_reject); assert(func_reject_ie->value.present == RICserviceUpdateAcknowledge_IEs__value_PR_RANfunctionsID_List); const int sz_rej = func_reject_ie->value.choice.RANfunctionsIDcause_List.list.count; su->rejected = calloc(sz_rej, sizeof( rejected_ran_function_t)); for(int i = 0; i < sz_rej; ++i){ const RANfunctionIDcause_ItemIEs_t * r = (const RANfunctionIDcause_ItemIEs_t * )func_reject_ie->value.choice.RANfunctionsIDcause_List.list.array[i]; - assert(r->criticality == Criticality_ignore); + assert(r->criticality == Criticality_reject); assert(r->id == ProtocolIE_ID_id_RANfunctionIEcause_Item); assert(r->value.present == RANfunctionIDcause_ItemIEs__value_PR_RANfunctionIDcause_Item); diff --git a/src/lib/e2ap/v2_03/e2ap_types/ric_service_update.c b/src/lib/e2ap/v2_03/e2ap_types/ric_service_update.c index 6c98532c4..6eccbe708 100644 --- a/src/lib/e2ap/v2_03/e2ap_types/ric_service_update.c +++ b/src/lib/e2ap/v2_03/e2ap_types/ric_service_update.c @@ -28,7 +28,7 @@ bool eq_ric_service_update(const ric_service_update_t* m0, const ric_service_upd return false; for(size_t i = 0; i < m0->len_modified; ++i){ - if(eq_ran_function(&m0->modified[i], &m1->modified[i])) + if(eq_ran_function(&m0->modified[i], &m1->modified[i]) == false) return false; } diff --git a/src/lib/e2ap/v2_03/e2ap_types/ric_service_update.h b/src/lib/e2ap/v2_03/e2ap_types/ric_service_update.h index a0ca81bcf..fec4dbf59 100644 --- a/src/lib/e2ap/v2_03/e2ap_types/ric_service_update.h +++ b/src/lib/e2ap/v2_03/e2ap_types/ric_service_update.h @@ -9,6 +9,7 @@ #include "common/e2ap_ran_function.h" #include "common/e2ap_ran_function_id_rev.h" +#include "common/e2ap_global_node_id.h" typedef struct { uint8_t trans_id; @@ -21,6 +22,8 @@ typedef struct { e2ap_ran_function_id_rev_t* deleted; size_t len_deleted; + + global_e2_node_id_t e2_node_id; } ric_service_update_t; bool eq_ric_service_update(const ric_service_update_t* m0, const ric_service_update_t* m1); diff --git a/src/lib/e2ap/v2_03/enc/e2ap_msg_enc_asn.c b/src/lib/e2ap/v2_03/enc/e2ap_msg_enc_asn.c index 19d74a1df..aa0c762a9 100644 --- a/src/lib/e2ap/v2_03/enc/e2ap_msg_enc_asn.c +++ b/src/lib/e2ap/v2_03/enc/e2ap_msg_enc_asn.c @@ -2054,13 +2054,10 @@ byte_array_t e2ap_enc_service_update_asn_msg(const e2ap_msg_t* msg) E2AP_PDU_t* e2ap_enc_service_update_asn_pdu(const ric_service_update_t* su) { assert(su->len_added <= (size_t)MAX_NUM_RAN_FUNC_ID); - assert(su->len_deleted <= (size_t)MAX_NUM_RAN_FUNC_ID ); + assert(su->len_deleted <= (size_t)MAX_NUM_RAN_FUNC_ID); assert(su->len_modified <= (size_t)MAX_NUM_RAN_FUNC_ID); - assert(0!=0 && "Untested code"); - - // Message Type - E2AP_PDU_t* pdu = calloc(1, sizeof( E2AP_PDU_t ) ); + E2AP_PDU_t* pdu = calloc(1, sizeof(E2AP_PDU_t)); pdu->present = E2AP_PDU_PR_initiatingMessage; pdu->choice.initiatingMessage = calloc(1, sizeof(InitiatingMessage_t)); pdu->choice.initiatingMessage->procedureCode = ProcedureCode_id_RICserviceUpdate; @@ -2069,62 +2066,76 @@ E2AP_PDU_t* e2ap_enc_service_update_asn_pdu(const ric_service_update_t* su) RICserviceUpdate_t *out = &pdu->choice.initiatingMessage->value.choice.RICserviceUpdate; - // List of RAN Functions Added - RICserviceUpdate_IEs_t* ran_add = calloc(1,sizeof(RICserviceUpdate_IEs_t)); - ran_add->id = ProtocolIE_ID_id_RANfunctionsAdded; - ran_add->criticality = Criticality_reject; - ran_add->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List; - - for(size_t i = 0; i < su->len_added; ++i){ - RANfunction_ItemIEs_t* r = calloc(1, sizeof(RANfunction_ItemIEs_t)); - r->id = ProtocolIE_ID_id_RANfunction_Item; - r->criticality = Criticality_reject; - r->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item; - r->value.choice.RANfunction_Item = copy_ran_function(&su->added[i]); - int rc = ASN_SEQUENCE_ADD(&ran_add->value.choice.RANfunctions_List.list, r); + // Transaction ID. Mandatory + RICserviceUpdate_IEs_t* trans_id_ie = calloc(1, sizeof(RICserviceUpdate_IEs_t)); + trans_id_ie->id = ProtocolIE_ID_id_TransactionID; + trans_id_ie->criticality = Criticality_reject; + trans_id_ie->value.present = RICserviceUpdate_IEs__value_PR_TransactionID; + trans_id_ie->value.choice.TransactionID = su->trans_id; + int rc = ASN_SEQUENCE_ADD(&out->protocolIEs.list, trans_id_ie); + assert(rc == 0); + + // List of RAN Functions Added. Optional + if (su->len_added > 0) { + RICserviceUpdate_IEs_t* ran_add = calloc(1, sizeof(RICserviceUpdate_IEs_t)); + ran_add->id = ProtocolIE_ID_id_RANfunctionsAdded; + ran_add->criticality = Criticality_reject; + ran_add->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List; + + for (size_t i = 0; i < su->len_added; ++i) { + RANfunction_ItemIEs_t* r = calloc(1, sizeof(RANfunction_ItemIEs_t)); + r->id = ProtocolIE_ID_id_RANfunction_Item; + r->criticality = Criticality_reject; + r->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item; + r->value.choice.RANfunction_Item = copy_ran_function(&su->added[i]); + int rc = ASN_SEQUENCE_ADD(&ran_add->value.choice.RANfunctions_List.list, r); + assert(rc == 0); + } + int rc = ASN_SEQUENCE_ADD(&out->protocolIEs.list, ran_add); assert(rc == 0); } - int rc = ASN_SEQUENCE_ADD(&out->protocolIEs.list,ran_add); - assert(rc == 0); - // List of RAN Functions Modified - RICserviceUpdate_IEs_t* ran_mod = calloc(1,sizeof(RICserviceUpdate_IEs_t)); - ran_mod->id = ProtocolIE_ID_id_RANfunctionsModified; - ran_mod->criticality = Criticality_reject; - ran_mod->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List; - - for(size_t i = 0; i < su->len_modified; ++i){ - RANfunction_ItemIEs_t* r = calloc(1, sizeof(RANfunction_ItemIEs_t)); - r->id = ProtocolIE_ID_id_RANfunction_Item; - r->criticality = Criticality_reject; - r->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item; - r->value.choice.RANfunction_Item = copy_ran_function(&su->modified[i]); - rc = ASN_SEQUENCE_ADD(&ran_mod->value.choice.RANfunctions_List.list, r); + // List of RAN Functions Modified. Optional + if (su->len_modified > 0) { + RICserviceUpdate_IEs_t* ran_mod = calloc(1, sizeof(RICserviceUpdate_IEs_t)); + ran_mod->id = ProtocolIE_ID_id_RANfunctionsModified; + ran_mod->criticality = Criticality_reject; + ran_mod->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List_1; + + for (size_t i = 0; i < su->len_modified; ++i) { + RANfunction_ItemIEs_t* r = calloc(1, sizeof(RANfunction_ItemIEs_t)); + r->id = ProtocolIE_ID_id_RANfunction_Item; + r->criticality = Criticality_reject; + r->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item; + r->value.choice.RANfunction_Item = copy_ran_function(&su->modified[i]); + rc = ASN_SEQUENCE_ADD(&ran_mod->value.choice.RANfunctions_List_1.list, r); + assert(rc == 0); + } + rc = ASN_SEQUENCE_ADD(&out->protocolIEs.list, ran_mod); assert(rc == 0); } - rc = ASN_SEQUENCE_ADD(&out->protocolIEs.list, ran_mod); - assert(rc == 0); - // List of RAN Functions Deleted - RICserviceUpdate_IEs_t* ran_del = calloc(1,sizeof(RICserviceUpdate_IEs_t)); - ran_del->id = ProtocolIE_ID_id_RANfunctionsDeleted; - ran_del->criticality = Criticality_reject; - ran_del->value.present = RICserviceUpdate_IEs__value_PR_RANfunctionsID_List; - - for(size_t i = 0; i < su->len_deleted; ++i){ - RANfunction_ItemIEs_t* r = calloc(1, sizeof(RANfunction_ItemIEs_t)); - r->id = ProtocolIE_ID_id_RANfunction_Item; - r->criticality = Criticality_reject; - r->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item; - RANfunction_Item_t* dst = &r->value.choice.RANfunction_Item; - const e2ap_ran_function_id_rev_t* src = &su->deleted[i]; - dst->ranFunctionID = src->id; - dst->ranFunctionRevision = src->rev; - rc = ASN_SEQUENCE_ADD(&ran_mod->value.choice.RANfunctions_List.list, r); + // List of RAN Functions Deleted. Optional + if (su->len_deleted > 0) { + RICserviceUpdate_IEs_t* ran_del = calloc(1, sizeof(RICserviceUpdate_IEs_t)); + ran_del->id = ProtocolIE_ID_id_RANfunctionsDeleted; + ran_del->criticality = Criticality_reject; + ran_del->value.present = RICserviceUpdate_IEs__value_PR_RANfunctionsID_List; + + for (size_t i = 0; i < su->len_deleted; ++i) { + RANfunctionID_ItemIEs_t* r = calloc(1, sizeof(RANfunctionID_ItemIEs_t)); + r->id = ProtocolIE_ID_id_RANfunctionID_Item; + r->criticality = Criticality_reject; + r->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item; + r->value.choice.RANfunctionID_Item.ranFunctionID = su->deleted[i].id; + r->value.choice.RANfunctionID_Item.ranFunctionRevision = su->deleted[i].rev; + rc = ASN_SEQUENCE_ADD(&ran_del->value.choice.RANfunctionsID_List.list, r); + assert(rc == 0); + } + rc = ASN_SEQUENCE_ADD(&out->protocolIEs.list, ran_del); assert(rc == 0); } - rc = ASN_SEQUENCE_ADD(&out->protocolIEs.list, ran_del); - assert(rc == 0); + return pdu; } @@ -2150,8 +2161,6 @@ E2AP_PDU_t* e2ap_enc_service_update_ack_asn_pdu(const ric_service_update_ack_t* assert(su->len_accepted <= (size_t)MAX_NUM_RAN_FUNC_ID); assert(su->len_rejected <= (size_t)MAX_NUM_RAN_FUNC_ID); - assert(0!=0 && "Untested code"); - // Message Type. Mandatory E2AP_PDU_t* pdu = calloc(1, sizeof(E2AP_PDU_t)); pdu->present = E2AP_PDU_PR_successfulOutcome; @@ -2162,15 +2171,24 @@ E2AP_PDU_t* e2ap_enc_service_update_ack_asn_pdu(const ric_service_update_ack_t* RICserviceUpdateAcknowledge_t* out = &pdu->choice.successfulOutcome->value.choice.RICserviceUpdateAcknowledge; + // TransactionID. Mandatory + RICserviceUpdateAcknowledge_IEs_t* trans_id_ie = calloc(1, sizeof(RICserviceUpdateAcknowledge_IEs_t)); + trans_id_ie->id = ProtocolIE_ID_id_TransactionID; + trans_id_ie->criticality = Criticality_reject; + trans_id_ie->value.present = RICserviceUpdateAcknowledge_IEs__value_PR_TransactionID; + trans_id_ie->value.choice.TransactionID = su->trans_id; + int rc = ASN_SEQUENCE_ADD(&out->protocolIEs.list, trans_id_ie); + assert(rc == 0); + if(su->len_accepted > 0){ // List of RAN Functions Accepted RICserviceUpdateAcknowledge_IEs_t* update_ack = calloc(1,sizeof(RICserviceUpdateAcknowledge_IEs_t)); update_ack->id = ProtocolIE_ID_id_RANfunctionsAccepted; - update_ack->criticality = Criticality_ignore; + update_ack->criticality = Criticality_reject; update_ack->value.present = RICserviceUpdateAcknowledge_IEs__value_PR_RANfunctionsID_List; for(size_t i = 0; i < su->len_accepted; ++i){ RANfunctionID_ItemIEs_t* r = calloc(1, sizeof( RANfunctionID_ItemIEs_t)); - r->id = ProtocolIE_ID_id_RANfunction_Item; + r->id = ProtocolIE_ID_id_RANfunctionID_Item; r->criticality = Criticality_reject; r->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item; r->value.choice.RANfunctionID_Item.ranFunctionID = su->accepted[i].id; @@ -2186,11 +2204,11 @@ E2AP_PDU_t* e2ap_enc_service_update_ack_asn_pdu(const ric_service_update_ack_t* // List of RAN Functions Rejected RICserviceUpdateAcknowledge_IEs_t* func_reject_ie = calloc(1,sizeof(RICserviceUpdateAcknowledge_IEs_t)); func_reject_ie->id = ProtocolIE_ID_id_RANfunctionsRejected; - func_reject_ie->criticality = Criticality_ignore; + func_reject_ie->criticality = Criticality_reject; func_reject_ie->value.present = RICserviceUpdateAcknowledge_IEs__value_PR_RANfunctionsID_List; for(size_t i =0; i < su->len_rejected; ++i){ RANfunctionIDcause_ItemIEs_t * r = calloc(1,sizeof(RANfunctionIDcause_ItemIEs_t)); - r->criticality = Criticality_ignore; + r->criticality = Criticality_reject; r->id = ProtocolIE_ID_id_RANfunctionIEcause_Item; r->value.present = RANfunctionIDcause_ItemIEs__value_PR_RANfunctionIDcause_Item; RANfunctionIDcause_Item_t* dst = &r->value.choice.RANfunctionIDcause_Item; diff --git a/src/lib/e2ap/v2_03/free/e2ap_msg_free.c b/src/lib/e2ap/v2_03/free/e2ap_msg_free.c index d58e79cf4..054c1b35d 100644 --- a/src/lib/e2ap/v2_03/free/e2ap_msg_free.c +++ b/src/lib/e2ap/v2_03/free/e2ap_msg_free.c @@ -408,6 +408,8 @@ void e2ap_free_service_update(ric_service_update_t* su) free(su->modified); free(su->deleted); + + free_global_e2_node_id(&su->e2_node_id); } // RIC -> E2 diff --git a/src/lib/e2ap/v3_01/e2ap_types/ric_service_update.c b/src/lib/e2ap/v3_01/e2ap_types/ric_service_update.c index 6c98532c4..6eccbe708 100644 --- a/src/lib/e2ap/v3_01/e2ap_types/ric_service_update.c +++ b/src/lib/e2ap/v3_01/e2ap_types/ric_service_update.c @@ -28,7 +28,7 @@ bool eq_ric_service_update(const ric_service_update_t* m0, const ric_service_upd return false; for(size_t i = 0; i < m0->len_modified; ++i){ - if(eq_ran_function(&m0->modified[i], &m1->modified[i])) + if(eq_ran_function(&m0->modified[i], &m1->modified[i]) == false) return false; } diff --git a/src/lib/e2ap/v3_01/e2ap_types/ric_service_update.h b/src/lib/e2ap/v3_01/e2ap_types/ric_service_update.h index a0ca81bcf..fec4dbf59 100644 --- a/src/lib/e2ap/v3_01/e2ap_types/ric_service_update.h +++ b/src/lib/e2ap/v3_01/e2ap_types/ric_service_update.h @@ -9,6 +9,7 @@ #include "common/e2ap_ran_function.h" #include "common/e2ap_ran_function_id_rev.h" +#include "common/e2ap_global_node_id.h" typedef struct { uint8_t trans_id; @@ -21,6 +22,8 @@ typedef struct { e2ap_ran_function_id_rev_t* deleted; size_t len_deleted; + + global_e2_node_id_t e2_node_id; } ric_service_update_t; bool eq_ric_service_update(const ric_service_update_t* m0, const ric_service_update_t* m1); diff --git a/src/lib/e2ap/v3_01/free/e2ap_msg_free.c b/src/lib/e2ap/v3_01/free/e2ap_msg_free.c index f2a551b7a..cfad44ea8 100644 --- a/src/lib/e2ap/v3_01/free/e2ap_msg_free.c +++ b/src/lib/e2ap/v3_01/free/e2ap_msg_free.c @@ -406,6 +406,8 @@ void e2ap_free_service_update(ric_service_update_t* su) free(su->modified); free(su->deleted); + + free_global_e2_node_id(&su->e2_node_id); } // RIC -> E2 diff --git a/src/lib/msg_hand/reg_e2_nodes.c b/src/lib/msg_hand/reg_e2_nodes.c index 4a5084a4b..8975ef50f 100644 --- a/src/lib/msg_hand/reg_e2_nodes.c +++ b/src/lib/msg_hand/reg_e2_nodes.c @@ -289,8 +289,14 @@ sm_ran_function_def_t mv_rd_e2_setup(sm_ag_if_rd_e2setup_t const* src) } else if(src->type == RAN_CTRL_V1_3_AGENT_IF_E2_SETUP_ANS_V0){ dst.type = RC_RAN_FUNC_DEF_E; dst.rc = src->rc.ran_func_def; + } else if(src->type == DAPP_AGENT_IF_E2_SETUP_ANS_V0){ + dst.type = DAPP_RAN_FUNC_DEF_E; + dst.dapp = src->dapp.ran_func_def; } else { - assert(0!=0 && "Unknown types"); + /* Tolerate service-model definition types this build does not model instead + of aborting the E2 node: subscriptions target a service model by + RAN-function id, so a type that is not modelled here is simply never + selected. dst stays zeroed. */ } return dst; @@ -502,3 +508,61 @@ void rm_reg_e2_node(reg_e2_nodes_t* n, global_e2_node_id_t const* id) } } +void update_reg_e2_node(reg_e2_nodes_t* n, + global_e2_node_id_t const* id, + size_t len_added, ran_function_t const* added, + size_t len_modified, ran_function_t const* modified, + size_t len_deleted, e2ap_ran_function_id_rev_t const* deleted) +{ + assert(n != NULL); + assert(id != NULL); + + lock_guard(&n->mtx); + + void* it = assoc_front(&n->node_to_rf); + void* end = assoc_end(&n->node_to_rf); + it = find_if(&n->node_to_rf, it, end, id, eq_global_e2_node_id_wrapper); + assert(it != end && "E2 Node not found in reg_e2_nodes"); + + pair_rf_cca_t* rf_cca = assoc_value(&n->node_to_rf, it); + seq_arr_t* arr = &rf_cca->ran_func; + + for (size_t i = 0; i < len_deleted; ++i) { + void* rf_it = seq_front(arr); + void* rf_end = seq_end(arr); + while (rf_it != rf_end) { + ran_function_t* rf = (ran_function_t*)rf_it; + if (rf->id == deleted[i].id) { + void* rf_next = seq_next(arr, rf_it); + free_ran_function(rf); + seq_erase(arr, rf_it, rf_next); + break; + } + rf_it = seq_next(arr, rf_it); + } + } + + for (size_t i = 0; i < len_modified; ++i) { + void* rf_it = seq_front(arr); + void* rf_end = seq_end(arr); + while (rf_it != rf_end) { + ran_function_t* rf = (ran_function_t*)rf_it; + if (rf->id == modified[i].id) { + free_ran_function(rf); + *rf = cp_ran_function(&modified[i]); + break; + } + rf_it = seq_next(arr, rf_it); + } + } + + for (size_t i = 0; i < len_added; ++i) { + ran_function_t tmp = cp_ran_function(&added[i]); + seq_push_back(arr, &tmp, sizeof(ran_function_t)); + } + + printf("[REG-E2-NODES]: Updated node MCC %d MNC %d NB_ID %u " + "(added=%zu, modified=%zu, deleted=%zu)\n", + id->plmn.mcc, id->plmn.mnc, id->nb_id.nb_id, + len_added, len_modified, len_deleted); +} diff --git a/src/lib/msg_hand/reg_e2_nodes.h b/src/lib/msg_hand/reg_e2_nodes.h index 1f5092759..7dd5ca9cd 100644 --- a/src/lib/msg_hand/reg_e2_nodes.h +++ b/src/lib/msg_hand/reg_e2_nodes.h @@ -10,6 +10,15 @@ #include "../e2ap/e2_node_connected_wrapper.h" #include "e2_node_arr.h" #include "../../xApp/e2_node_arr_xapp.h" +#ifdef E2AP_V1 +#include "../e2ap/v1_01/e2ap_types/common/e2ap_ran_function_id_rev.h" +#elif defined(E2AP_V2) +#include "../e2ap/v2_03/e2ap_types/common/e2ap_ran_function_id_rev.h" +#elif defined(E2AP_V3) +#include "../e2ap/v3_01/e2ap_types/common/e2ap_ran_function_id_rev.h" +#else +static_assert(0!=0, "Unknown E2AP Version"); +#endif #include #include @@ -52,5 +61,11 @@ e2_node_arr_t generate_e2_node_arr(reg_e2_nodes_t* n); e2_node_arr_xapp_t generate_e2_node_arr_xapp(reg_e2_nodes_t* n, plugin_ric_t const* plg_ric); +void update_reg_e2_node(reg_e2_nodes_t* n, + global_e2_node_id_t const* id, + size_t len_added, ran_function_t const* added, + size_t len_modified, ran_function_t const* modified, + size_t len_deleted, e2ap_ran_function_id_rev_t const* deleted); + #endif diff --git a/src/ric/iApp/e42_iapp.c b/src/ric/iApp/e42_iapp.c index c20774172..97b11b74f 100644 --- a/src/ric/iApp/e42_iapp.c +++ b/src/ric/iApp/e42_iapp.c @@ -342,7 +342,8 @@ void notify_msg_iapp(e42_iapp_t* iapp, e2ap_msg_t const* msg) || msg->type == RIC_SUBSCRIPTION_RESPONSE || msg->type == RIC_SUBSCRIPTION_DELETE_RESPONSE || msg->type == RIC_CONTROL_ACKNOWLEDGE - || msg->type == RIC_CONTROL_FAILURE); + || msg->type == RIC_CONTROL_FAILURE + || msg->type == RIC_SERVICE_UPDATE); e2ap_msg_t ans = e2ap_msg_handle_iapp(iapp, msg); diff --git a/src/ric/iApp/msg_handler_iapp.c b/src/ric/iApp/msg_handler_iapp.c index 6ff451132..98396654b 100644 --- a/src/ric/iApp/msg_handler_iapp.c +++ b/src/ric/iApp/msg_handler_iapp.c @@ -12,6 +12,7 @@ #include "util/compare.h" #include "util/alg_ds/ds/lock_guard/lock_guard.h" #include "util/time_now_us.h" +#include "../../lib/msg_hand/reg_e2_nodes.h" #include "iapp_if_generic.h" #include "xapp_ric_id.h" @@ -33,7 +34,8 @@ bool check_valid_msg_type(e2_msg_type_t msg_type ) || msg_type == RIC_CONTROL_ACKNOWLEDGE || msg_type == RIC_INDICATION || msg_type == RIC_SUBSCRIPTION_DELETE_RESPONSE - || msg_type == RIC_CONTROL_FAILURE; + || msg_type == RIC_CONTROL_FAILURE + || msg_type == RIC_SERVICE_UPDATE; } void init_handle_msg_iapp(size_t len, handle_msg_fp_iapp (*handle_msg)[len]) @@ -51,6 +53,7 @@ void init_handle_msg_iapp(size_t len, handle_msg_fp_iapp (*handle_msg)[len]) (*handle_msg)[RIC_CONTROL_FAILURE] = e2ap_handle_e42_ric_control_failure_iapp; (*handle_msg)[RIC_INDICATION] = e2ap_handle_ric_indication_iapp; (*handle_msg)[RIC_SUBSCRIPTION_DELETE_RESPONSE] = e2ap_handle_subscription_delete_response_iapp; + (*handle_msg)[RIC_SERVICE_UPDATE] = e2ap_handle_ric_service_update_iapp; // (*handle_msg)[RIC_SUBSCRIPTION_REQUEST] = e2ap_handle_subscription_request_iapp; // (*handle_msg)[RIC_SUBSCRIPTION_DELETE_REQUEST] = e2ap_handle_subscription_delete_request_iapp; @@ -491,7 +494,27 @@ e2ap_msg_t e2ap_handle_reset_response_iapp(e42_iapp_t* iapp, const e2ap_msg_t* m e2ap_msg_t ans = {.type = NONE_E2_MSG_TYPE}; return ans; } - + +e2ap_msg_t e2ap_handle_ric_service_update_iapp(e42_iapp_t* iapp, const e2ap_msg_t* msg) +{ + assert(iapp != NULL); + assert(msg != NULL); + assert(msg->type == RIC_SERVICE_UPDATE); + + ric_service_update_t const* su = &msg->u_msgs.ric_serv_updt; + + printf("[iApp]: RIC SERVICE UPDATE rx (added=%zu, modified=%zu, deleted=%zu)\n", + su->len_added, su->len_modified, su->len_deleted); + + update_reg_e2_node(&iapp->e2_nodes, &su->e2_node_id, + su->len_added, su->added, + su->len_modified, su->modified, + su->len_deleted, su->deleted); + + e2ap_msg_t ans = {.type = NONE_E2_MSG_TYPE}; + return ans; +} + e2ap_msg_t e2ap_handle_service_update_ack_iapp(e42_iapp_t* iapp, const e2ap_msg_t* msg) { assert(iapp != NULL); diff --git a/src/ric/iApp/msg_handler_iapp.h b/src/ric/iApp/msg_handler_iapp.h index eca7ab11b..53b3059cc 100644 --- a/src/ric/iApp/msg_handler_iapp.h +++ b/src/ric/iApp/msg_handler_iapp.h @@ -104,5 +104,8 @@ e2ap_msg_t e2ap_handle_e42_ric_control_ack_iapp(e42_iapp_t* iapp, const e2ap_msg // iApp -> xApp e2ap_msg_t e2ap_handle_e42_ric_control_failure_iapp(e42_iapp_t* iapp, const e2ap_msg_t* msg); +// RIC -> iApp (forwarded from near_ric msg handler) +e2ap_msg_t e2ap_handle_ric_service_update_iapp(e42_iapp_t* iapp, const e2ap_msg_t* msg); + #endif diff --git a/src/ric/iApps/influx.c b/src/ric/iApps/influx.c index 03342f7d0..06aa390a4 100644 --- a/src/ric/iApps/influx.c +++ b/src/ric/iApps/influx.c @@ -169,7 +169,7 @@ void notify_influx_listener(sm_ag_if_rd_ind_t const* data) assert(data->type == MAC_STATS_V0 || data->type == RLC_STATS_V0 || data->type == PDCP_STATS_V0 || data->type == SLICE_STATS_V0 || data->type == KPM_STATS_V3_0 || data->type == GTP_STATS_V0 - || data->type == TC_STATS_V0 || data->type == RAN_CTRL_STATS_V1_03 || data->type == CCC_STATS_V6); + || data->type == TC_STATS_V0 || data->type == RAN_CTRL_STATS_V1_03 || data->type == CCC_STATS_V6 || data->type == DAPP_STATS_V0); return; diff --git a/src/ric/iApps/redis.c b/src/ric/iApps/redis.c index ad7dde11c..7f565e26f 100644 --- a/src/ric/iApps/redis.c +++ b/src/ric/iApps/redis.c @@ -13,7 +13,7 @@ void notify_redis_listener(sm_ag_if_rd_ind_t const* data) assert(data != NULL); assert(data->type == MAC_STATS_V0 || data->type == RLC_STATS_V0 || data->type == PDCP_STATS_V0 || data->type == SLICE_STATS_V0 || data->type == KPM_STATS_V3_0 || data->type == GTP_STATS_V0 - || data->type == RAN_CTRL_STATS_V1_03 || data->type == TC_STATS_V0 || data->type == CCC_STATS_V6); + || data->type == RAN_CTRL_STATS_V1_03 || data->type == TC_STATS_V0 || data->type == CCC_STATS_V6 || data->type == DAPP_STATS_V0); /* if(data->type == MAC_STATS_V0) diff --git a/src/ric/iApps/stdout.c b/src/ric/iApps/stdout.c index 53d2119df..32e5dff93 100644 --- a/src/ric/iApps/stdout.c +++ b/src/ric/iApps/stdout.c @@ -340,7 +340,9 @@ void notify_stdout_listener(sm_ag_if_rd_ind_t const* data) (int)data->ccc.msg.format2.list_of_cells_reported.len, data->ccc.msg.format2.list_of_cells_reported.data); } - } else { + } else if (data->type == DAPP_STATS_V0){ + // The payload is opaque to the RIC; nothing to print. + } else { assert(0 != 0 && "Unknown data type"); } } diff --git a/src/ric/map_e2_node_sockaddr.c b/src/ric/map_e2_node_sockaddr.c index 50ef4e8dd..65e0e5252 100644 --- a/src/ric/map_e2_node_sockaddr.c +++ b/src/ric/map_e2_node_sockaddr.c @@ -143,3 +143,23 @@ sctp_info_t find_map_e2_node_sad(map_e2_node_sockaddr_t* m, global_e2_node_id_t return *s; } +bool find_map_sad_e2_node(map_e2_node_sockaddr_t* m, sctp_info_t const* s, global_e2_node_id_t* id) +{ + assert(m != NULL); + assert(s != NULL); + assert(id != NULL); + + lock_guard(&m->mtx); + + assoc_rb_tree_t* tree = &m->map.right; + + void* it = assoc_front(tree); + void* end = assoc_end(tree); + + it = find_if(tree, it, end, (sctp_info_t*)s, eq_sctp_info_wrapper); + if (it == end) + return false; + + *id = cp_global_e2_node_id(assoc_value(tree, it)); + return true; +} diff --git a/src/ric/map_e2_node_sockaddr.h b/src/ric/map_e2_node_sockaddr.h index 4e205055e..e96190bff 100644 --- a/src/ric/map_e2_node_sockaddr.h +++ b/src/ric/map_e2_node_sockaddr.h @@ -40,5 +40,10 @@ sctp_info_t find_map_e2_node_sad(map_e2_node_sockaddr_t* m, global_e2_node_id_t sctp_info_t find_map_e2_node_sad(map_e2_node_sockaddr_t * m, global_e2_node_id_t const* id); +/* Reverse lookup: the E2 node registered for a socket. Returns false when the + socket has no node registered, rather than asserting -- the caller is driven + by inbound SCTP traffic. */ +bool find_map_sad_e2_node(map_e2_node_sockaddr_t* m, sctp_info_t const* s, global_e2_node_id_t* id); + #endif diff --git a/src/ric/msg_handler_ric.c b/src/ric/msg_handler_ric.c index 18195a499..9da127964 100644 --- a/src/ric/msg_handler_ric.c +++ b/src/ric/msg_handler_ric.c @@ -212,7 +212,7 @@ void publish_ind_msg(near_ric_t* ric, uint16_t ran_func_id, sm_ag_if_rd_ind_t* assert(d.type == MAC_STATS_V0 || d.type == RLC_STATS_V0 || d.type == PDCP_STATS_V0 || d.type == SLICE_STATS_V0 || d.type == KPM_STATS_V3_0 || d.type == RAN_CTRL_STATS_V1_03 - || d.type == GTP_STATS_V0 || d.type == TC_STATS_V0 || d.type == CCC_STATS_V6 ); + || d.type == GTP_STATS_V0 || d.type == TC_STATS_V0 || d.type == CCC_STATS_V6 || d.type == DAPP_STATS_V0); publish_ind_msg(ric, ran_func_id, &d); @@ -366,14 +366,96 @@ void publish_ind_msg(near_ric_t* ric, uint16_t ran_func_id, sm_ag_if_rd_ind_t* } // E2 -> RIC - e2ap_msg_t e2ap_handle_service_update_ric(near_ric_t* ric, const e2ap_msg_t* msg) +e2ap_msg_t e2ap_handle_service_update_ric(near_ric_t* ric, const e2ap_msg_t* msg) { assert(ric != NULL); assert(msg != NULL); assert(msg->type == RIC_SERVICE_UPDATE); - assert(0 != 0 && "Not Implemented"); - e2ap_msg_t ans = {.type = NONE_E2_MSG_TYPE}; + const ric_service_update_t* su = &msg->u_msgs.ric_serv_updt; + + printf("[NEAR-RIC]: RIC SERVICE UPDATE rx (added=%zu, modified=%zu, deleted=%zu)\n", + su->len_added, su->len_modified, su->len_deleted); + { + lock_guard(&ric->conn_e2_nodes_mtx); + + e2_node_t* node = NULL; + void* it = seq_front(&ric->conn_e2_nodes); + void* end_it = seq_end(&ric->conn_e2_nodes); + while (it != end_it) { + e2_node_t* n = (e2_node_t*)it; + if (eq_global_e2_node_id(&n->id, &su->e2_node_id)) { + node = n; + break; + } + it = seq_next(&ric->conn_e2_nodes, it); + } + if (node == NULL) { + /* The update names a node the RIC has no E2 SETUP for. Dropping it is + better than asserting: this path is driven by whatever arrives on the + SCTP socket, so an assertion here lets a malformed or stale update from + any peer take the RIC down. */ + printf("[NEAR-RIC]: RIC SERVICE UPDATE for an unknown E2 node, dropped\n"); + e2ap_msg_t none = {.type = NONE_E2_MSG_TYPE}; + return none; + } + + for (size_t i = 0; i < su->len_deleted; ++i) { + for (size_t j = 0; j < node->len_acc; ++j) { + if (node->accepted[j] == su->deleted[i].id) { + memmove(&node->accepted[j], &node->accepted[j + 1], + (node->len_acc - j - 1) * sizeof(accepted_ran_function_t)); + node->len_acc--; + break; + } + } + } + + if (su->len_added > 0) { + size_t new_len = node->len_acc + su->len_added; + node->accepted = realloc(node->accepted, new_len * sizeof(accepted_ran_function_t)); + assert(node->accepted != NULL && "Memory exhausted"); + for (size_t i = 0; i < su->len_added; ++i) { + node->accepted[node->len_acc + i] = su->added[i].id; + } + node->len_acc = new_len; + } + + } + +#ifndef TEST_AGENT_RIC + notify_msg_iapp_api(msg); +#endif + + e2ap_msg_t ans = {.type = RIC_SERVICE_UPDATE_ACKNOWLEDGE}; + ric_service_update_ack_t* ack = &ans.u_msgs.ric_serv_updt_ack; + ack->trans_id = su->trans_id; + ack->len_accepted = 0; + ack->accepted = NULL; + ack->len_rejected = 0; + ack->rejected = NULL; + + if (su->len_modified > 0) { + ack->len_accepted = su->len_modified; + ack->accepted = calloc(su->len_modified, sizeof(ran_function_id_t)); + assert(ack->accepted != NULL && "Memory exhausted"); + for (size_t i = 0; i < su->len_modified; ++i) { + ack->accepted[i].id = su->modified[i].id; + ack->accepted[i].rev = su->modified[i].rev; + } + } + + if (su->len_added > 0) { + size_t prev = ack->len_accepted; + ack->len_accepted += su->len_added; + ack->accepted = realloc(ack->accepted, ack->len_accepted * sizeof(ran_function_id_t)); + assert(ack->accepted != NULL && "Memory exhausted"); + for (size_t i = 0; i < su->len_added; ++i) { + ack->accepted[prev + i].id = su->added[i].id; + ack->accepted[prev + i].rev = su->added[i].rev; + } + } + return ans; } diff --git a/src/ric/near_ric.c b/src/ric/near_ric.c index aae2a2c23..5634be38e 100644 --- a/src/ric/near_ric.c +++ b/src/ric/near_ric.c @@ -389,8 +389,8 @@ void sctp_msg_arrived_event(void* arg) sctp_msg_t const* sctp_msg = &ric_ev->msg; defer({free_sctp_msg((sctp_msg_t*)sctp_msg);}); - e2ap_msg_t const msg = e2ap_msg_dec_ric(&ric->ap, sctp_msg->ba); - defer({e2ap_msg_free_ric(&ric->ap, (e2ap_msg_t*)&msg); } ); + e2ap_msg_t msg = e2ap_msg_dec_ric(&ric->ap, sctp_msg->ba); + defer({e2ap_msg_free_ric(&ric->ap, &msg); } ); if(msg.type == E2_SETUP_REQUEST){ global_e2_node_id_t const* id = &msg.u_msgs.e2_stp_req.id; @@ -398,6 +398,13 @@ void sctp_msg_arrived_event(void* arg) e2ap_reg_sock_addr_ric(&ric->ep, id, &sctp_msg->info); } + if(msg.type == RIC_SERVICE_UPDATE){ + // The update itself does not carry the node id; it is implied by the socket + // it arrived on. An unregistered socket leaves the id zeroed and the handler + // drops the message. + find_map_sad_e2_node(&ric->ep.e2_nodes, &sctp_msg->info, &msg.u_msgs.ric_serv_updt.e2_node_id); + } + e2ap_msg_t ans = e2ap_msg_handle_ric(ric, &msg); defer({e2ap_msg_free_ric(&ric->ap, &ans);}); diff --git a/src/sm/CMakeLists.txt b/src/sm/CMakeLists.txt index dae317117..5b12d39f9 100644 --- a/src/sm/CMakeLists.txt +++ b/src/sm/CMakeLists.txt @@ -9,3 +9,4 @@ add_subdirectory(tc_sm) add_subdirectory(gtp_sm) add_subdirectory(rc_sm) add_subdirectory(ccc_sm) +add_subdirectory(dapp_sm) diff --git a/src/sm/agent_if/ans/sm_ag_if_ans.h b/src/sm/agent_if/ans/sm_ag_if_ans.h index 7d8eaa701..3d1ca9aaa 100644 --- a/src/sm/agent_if/ans/sm_ag_if_ans.h +++ b/src/sm/agent_if/ans/sm_ag_if_ans.h @@ -13,6 +13,7 @@ #include "../../gtp_sm/ie/gtp_data_ie.h" #include "../../rc_sm/ie/rc_data_ie.h" #include "../../ccc_sm/ie/ccc_data_ie.h" +#include "../../dapp_sm/ie/dapp_data_ie.h" #include "../write/subscription_aperiod.h" #include "../write/subscription_period.h" @@ -39,6 +40,7 @@ typedef enum{ GTP_AGENT_IF_CTRL_ANS_V0, RAN_CTRL_V1_3_AGENT_IF_CTRL_ANS_V0, CCC_AGENT_IF_CTRL_ANS_V0, + DAPP_AGENT_IF_CTRL_ANS_V0, SM_AGENT_IF_CTRL_ANS_V0_END, } sm_ag_if_ans_ctrl_e; @@ -54,6 +56,7 @@ typedef struct{ gtp_ctrl_out_t gtp; e2sm_rc_ctrl_out_t rc; ccc_ctrl_out_t ccc; + e2sm_dapp_ctrl_out_t dapp; }; } sm_ag_if_ans_ctrl_t; diff --git a/src/sm/agent_if/read/sm_ag_if_rd.c b/src/sm/agent_if/read/sm_ag_if_rd.c index 2a25e00ca..b4686c507 100644 --- a/src/sm/agent_if/read/sm_ag_if_rd.c +++ b/src/sm/agent_if/read/sm_ag_if_rd.c @@ -37,6 +37,8 @@ void free_sm_ag_if_rd_ind(sm_ag_if_rd_ind_t* d) free_kpm_ind_data(&d->kpm.ind); } else if(d->type == RAN_CTRL_STATS_V1_03 ){ free_rc_ind_data(&d->rc.ind); + } else if(d->type == DAPP_STATS_V0){ + free_dapp_ind_data(&d->dapp.ind); } else { assert(0!=0 && "Unforeseen case"); } diff --git a/src/sm/agent_if/read/sm_ag_if_rd.h b/src/sm/agent_if/read/sm_ag_if_rd.h index 8d28ae842..b4fbcfa3a 100644 --- a/src/sm/agent_if/read/sm_ag_if_rd.h +++ b/src/sm/agent_if/read/sm_ag_if_rd.h @@ -18,6 +18,7 @@ #include "../../ccc_sm/ie/ccc_data_ie.h" #include "../../rc_sm/ie/rc_data_ie.h" #include "../../kpm_sm/kpm_data_ie_wrapper.h" +#include "../../dapp_sm/ie/dapp_data_ie.h" #include "../write/subscribe_timer.h" @@ -36,6 +37,7 @@ typedef enum{ CCC_STATS_V6, KPM_STATS_V3_0, RAN_CTRL_STATS_V1_03, + DAPP_STATS_V0, SM_AGENT_IF_READ_V0_END, } sm_ag_if_rd_ind_e; @@ -58,6 +60,12 @@ typedef struct{ ccc_action_def_t const* act_def; } ccc_rd_ind_data_t; +typedef struct{ + dapp_ind_data_t ind; + // Non-owning pointer + uint32_t ric_id; +} dapp_rd_ind_data_t; + // ToDo: Change it for pointers, to break the dependencies typedef struct{ sm_ag_if_rd_ind_e type; @@ -72,6 +80,7 @@ typedef struct{ ccc_ind_data_t ccc; kpm_rd_ind_data_t kpm; rc_rd_ind_data_t rc; + dapp_rd_ind_data_t dapp; }; } sm_ag_if_rd_ind_t; @@ -93,6 +102,7 @@ typedef enum{ CCC_AGENT_IF_E2_SETUP_ANS_V0, KPM_V3_0_AGENT_IF_E2_SETUP_ANS_V0, RAN_CTRL_V1_3_AGENT_IF_E2_SETUP_ANS_V0, + DAPP_AGENT_IF_E2_SETUP_ANS_V0, SM_AGENT_IF_E2_SETUP_ANS_V0_END, } sm_ag_if_rd_e2setup_e; @@ -108,6 +118,7 @@ typedef struct{ ccc_e2_setup_data_t ccc; kpm_e2_setup_t kpm; rc_e2_setup_t rc; + dapp_e2_setup_t dapp; }; } sm_ag_if_rd_e2setup_t; @@ -125,6 +136,7 @@ typedef enum{ CCC_AGENT_IF_RIC_SERV_UPDATE_CTRL_ANS_V0, KPM_V3_0_AGENT_IF_RIC_SERV_UPDATE_CTRL_ANS_V0, RAN_CTRL_V1_3_AGENT_IF_RIC_SERV_UPDATE_CTRL_ANS_V0, + DAPP_AGENT_IF_RIC_SERV_UPDATE_CTRL_ANS_V0, SM_AGENT_IF_RIC_SERV_UPDATE_CTRL_ANS_V0_END, } sm_ag_if_rd_rsu_e; @@ -141,6 +153,7 @@ typedef struct{ ccc_ric_service_update_t ccc; kpm_ric_service_update_t kpm; rc_ric_service_update_t rc; + dapp_ric_service_update_t dapp; }; } sm_ag_if_rd_rsu_t; diff --git a/src/sm/agent_if/write/sm_ag_if_wr.h b/src/sm/agent_if/write/sm_ag_if_wr.h index 91fd174e4..8355ab8fd 100644 --- a/src/sm/agent_if/write/sm_ag_if_wr.h +++ b/src/sm/agent_if/write/sm_ag_if_wr.h @@ -16,6 +16,7 @@ #include "../../kpm_sm/kpm_data_ie_wrapper.h" #include "../../rc_sm/ie/rc_data_ie.h" #include "../../ccc_sm/ie/ccc_data_ie.h" +#include "../../dapp_sm/ie/dapp_data_ie.h" ////////////////////// ////////////////////// @@ -33,6 +34,7 @@ typedef enum{ GTP_CTRL_REQ_V0 = 5, RAN_CONTROL_CTRL_V1_03 = 6, CCC_CTRL_REQ_V0 = 7, + DAPP_CTRL_V0 = 8, SM_AGENT_IF_WRITE_CTRL_V0_END, } sm_ag_if_ctrl_e; @@ -47,6 +49,7 @@ typedef struct{ gtp_ctrl_req_data_t gtp_ctrl; rc_ctrl_req_data_t rc_ctrl; ccc_ctrl_req_data_t ccc_ctrl; + dapp_ctrl_req_data_t dapp_ctrl; }; } sm_ag_if_wr_ctrl_t; @@ -67,6 +70,7 @@ typedef enum{ CCC_SUBS_V0, KPM_SUBS_V3_0, RAN_CTRL_SUBS_V1_03, + DAPP_SUBS_V0, SM_AGENT_IF_WRITE_SUBS_V0_END, } sm_ag_if_subs_e; @@ -75,6 +79,11 @@ typedef struct{ rc_sub_data_t rc; } wr_rc_sub_data_t; +typedef struct{ + uint32_t ric_req_id; + dapp_sub_data_t dapp; +} wr_dapp_sub_data_t; + typedef struct{ sm_ag_if_subs_e type; @@ -88,6 +97,7 @@ typedef struct{ ccc_sub_data_t ccc; kpm_sub_data_t kpm; wr_rc_sub_data_t wr_rc; + wr_dapp_sub_data_t wr_dapp; }; } sm_ag_if_wr_subs_t; diff --git a/src/sm/dapp_sm/CMakeLists.txt b/src/sm/dapp_sm/CMakeLists.txt new file mode 100644 index 000000000..22172aace --- /dev/null +++ b/src/sm/dapp_sm/CMakeLists.txt @@ -0,0 +1,92 @@ +# SPDX-License-Identifier: LicenseRef-CSSL-1.0 + +cmake_minimum_required(VERSION 3.15) # setting this is required +project(dapp_sm) # this sets the project name + +set(SM_ENCODING_DAPP_SRC + ../sm_proc_data.c + dapp_sm_agent.c + dapp_sm_ric.c + ../../util/byte_array.c + ../../util/alg_ds/alg/defer.c + ../../util/alg_ds/alg/eq_float.c + ../../util/alg_ds/ds/seq_container/seq_arr.c + ../../util/alg_ds/ds/seq_container/seq_ring.c + ../../util/alg_ds/ds/assoc_container/assoc_rb_tree.c + ../../util/alg_ds/ds/assoc_container/bimap.c + ie/dapp_data_ie.c + ) + +if(SM_ENCODING_DAPP STREQUAL "ASN") + # The E2SM-DAPP ASN.1 codec lives in libe3; flexric only adapts its IR structs to it. + find_package(libe3 0.3.0 CONFIG QUIET COMPONENTS e2sm_dapp) + if(NOT libe3_FOUND) + message(FATAL_ERROR "E2SM-DAPP needs libe3 >= 0.3.0 built with LIBE3_ENABLE_E2SM_DAPP; install it or set CMAKE_PREFIX_PATH") + endif() + # Consumers of dapp_sm_static (tests in other directories) resolve the link dependency too. + set_target_properties(libe3::e2sm_dapp PROPERTIES IMPORTED_GLOBAL TRUE) + # libe3_e2sm_dapp is a static C++ archive: the C++ runtime has to come with it. + if(APPLE) + set(DAPP_CXX_RUNTIME c++) + else() + set(DAPP_CXX_RUNTIME stdc++) + endif() + + add_subdirectory(ie/ir) + add_subdirectory(e3) + + set(SM_ENCODING_DAPP_SRC_ASN + ${SM_ENCODING_DAPP_SRC} + enc/dapp_enc_asn.c + dec/dapp_dec_asn.c + # This dependency sucks! + $ + $ + $ + $ + $ + $ + ) + + # Shared + add_library(dapp_sm SHARED ${SM_ENCODING_DAPP_SRC_ASN}) + + target_include_directories(dapp_sm PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/ie" + "${CMAKE_CURRENT_SOURCE_DIR}/ie/ir" + "${CMAKE_CURRENT_SOURCE_DIR}/../../util" + "${CMAKE_CURRENT_SOURCE_DIR}/e3" + ) + target_compile_options(dapp_sm PRIVATE "-DASN_DISABLE_OER_SUPPORT" "-DASN_DISABLE_JER_SUPPORT" ) + target_compile_options(dapp_sm PRIVATE -fPIC -Wno-missing-field-initializers -Wno-unused-parameter -fvisibility=hidden) + + target_link_libraries(dapp_sm PRIVATE + -lm + e2sm_dapp_e3_spectrum_asn1_obj + libe3::e2sm_dapp + ${DAPP_CXX_RUNTIME} + ) + # Keep libe3's C/C++ API and its asn1c runtime out of libdapp_sm.so's exports. + if(APPLE) + target_link_options(dapp_sm PRIVATE "LINKER:-load_hidden,$") + else() + target_link_options(dapp_sm PRIVATE "LINKER:--exclude-libs,ALL") + endif() + + # Static + add_library(dapp_sm_static STATIC ${SM_ENCODING_DAPP_SRC_ASN}) + target_include_directories(dapp_sm_static PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/ie" + "${CMAKE_CURRENT_SOURCE_DIR}/ie/ir" + "${CMAKE_CURRENT_SOURCE_DIR}/../../util" + "${CMAKE_CURRENT_SOURCE_DIR}/e3" + ) + target_compile_options(dapp_sm_static PRIVATE "-DASN_DISABLE_JER_SUPPORT" "-DASN_DISABLE_OER_SUPPORT") + target_compile_options(dapp_sm_static PRIVATE -Wno-missing-field-initializers -Wno-unused-parameter -fvisibility=hidden ) + target_link_libraries(dapp_sm_static PRIVATE libe3::e2sm_dapp ${DAPP_CXX_RUNTIME} -lm) +else() + message(FATAL_ERROR "E2SM-DAPP only supports the ASN encoding") +endif() + +target_compile_definitions(dapp_sm PUBLIC ${SM_ENCODING_DAPP} ${E2AP_VERSION} ${KPM_VERSION} ) +target_compile_definitions(dapp_sm_static PUBLIC ${SM_ENCODING_DAPP} ${E2AP_VERSION} ${KPM_VERSION} ) diff --git a/src/sm/dapp_sm/dapp_sm_agent.c b/src/sm/dapp_sm/dapp_sm_agent.c new file mode 100644 index 000000000..79cc25d01 --- /dev/null +++ b/src/sm/dapp_sm/dapp_sm_agent.c @@ -0,0 +1,335 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "dapp_sm_agent.h" + +#include "../../util/alg_ds/alg/defer.h" +#include "dapp_sm_id.h" +#include "enc/dapp_enc_generic.h" +#include "dec/dapp_dec_generic.h" + +#include +#include +#include + +typedef struct { + sm_agent_t base; + +#ifdef ASN + dapp_enc_asn_t enc; +#elif FLATBUFFERS + dapp_enc_fb_t enc; +#elif PLAIN + dapp_enc_plain_t enc; +#else + static_assert(false, "No encoding type selected"); +#endif + +} sm_dapp_agent_t; + +/** + * @brief Handle a new subscription for the DAPP service model on the agent. + * + * Decodes the E2SM-DAPP event trigger and action definition from the + * incoming subscription data, wraps them in a wr_dapp_sub_data_t, and + * forwards the subscription to the RAN via sm->base.io.write_subs(). + * + * The action definition carries the report style type, which determines + * what indication formats the agent will send to this subscriber: + * - Style 1: Format 1 only (E3 data reports) + * - Style 2: Format 2 only (E3 subscription map) + * + * @param sm_agent The DAPP SM agent instance. + * @param data Raw subscription data from the E2AP layer (event trigger + * and action definition as encoded byte arrays). + * @return Subscription outcome (APERIODIC_SUBSCRIPTION_FLRC). + */ +static sm_ag_if_ans_subs_t on_subscription_dapp_sm_ag(sm_agent_t const* sm_agent, const sm_subs_data_t* data) +{ + assert(sm_agent != NULL); + sm_dapp_agent_t* sm = (sm_dapp_agent_t*)sm_agent; + assert(data != NULL); + + wr_dapp_sub_data_t wr_dapp = {0}; + wr_dapp.ric_req_id = data->ric_req_id; + + /* Decode E2SM-DAPP event trigger */ + wr_dapp.dapp.et = dapp_dec_event_trigger(&sm->enc, data->len_et, data->event_trigger); + defer({ free_e2sm_dapp_event_trigger(&wr_dapp.dapp.et); }); + + /* Decode E2SM-DAPP action definition (if present) */ + if (data->action_def != NULL && data->len_ad > 0) { + wr_dapp.dapp.action_def = calloc(1, sizeof(e2sm_dapp_action_def_t)); + assert(wr_dapp.dapp.action_def != NULL && "Memory exhausted"); + *wr_dapp.dapp.action_def = dapp_dec_action_def(&sm->enc, data->len_ad, data->action_def); + } + defer({ + if (wr_dapp.dapp.action_def != NULL) { + free_e2sm_dapp_action_def(wr_dapp.dapp.action_def); + free(wr_dapp.dapp.action_def); + } + }); + + /* Forward subscription to the RAN via the SM I/O interface */ + sm_ag_if_ans_t subs = sm->base.io.write_subs(&wr_dapp); + assert(subs.type == SUBS_OUTCOME_SM_AG_IF_ANS_V0); + assert(subs.subs_out.type == APERIODIC_SUBSCRIPTION_FLRC); + + return subs.subs_out; +} + +/** + * @brief Encode and export an indication for the DAPP service model. + * + * Takes an internal dapp_ind_data_t (header + message + E3 payload), + * encodes the indication header and message using the E2SM-DAPP codec, + * and returns an exp_ind_data_t containing the raw encoded buffers. + * + * Supports both indication formats: + * - Format 1: E3 data report (header with ran_function_id/dapp_id) + * - Format 2: E3 subscription map (header with node identity only) + * + * The encoded buffers are sent over E2AP as OCTET STRINGs in the + * RIC INDICATION message. + * + * @param sm_agent The DAPP SM agent instance. + * @param ind_data Pointer to a heap-allocated dapp_ind_data_t. Ownership + * is transferred — the function frees it before returning. + * @return Encoded indication header and message buffers. + */ +static exp_ind_data_t on_indication_dapp_sm_ag(sm_agent_t const* sm_agent, void* ind_data) +{ + assert(sm_agent != NULL); + assert(ind_data != NULL && "Indication data needed for this SM"); + sm_dapp_agent_t* sm = (sm_dapp_agent_t*)sm_agent; + + exp_ind_data_t ret = {.has_value = true}; + + dapp_ind_data_t* ind = (dapp_ind_data_t*)ind_data; + defer({ + free_dapp_ind_data(ind); + free(ind); + }); + + /* Encode indication header */ + byte_array_t ba_hdr = dapp_enc_ind_hdr(&sm->enc, &ind->hdr); + assert(ba_hdr.len < 16 * 1024 && "Are you really encoding so much info?"); + ret.data.ind_hdr = ba_hdr.buf; + ret.data.len_hdr = ba_hdr.len; + + /* Encode indication message */ + byte_array_t ba_msg = dapp_enc_ind_msg(&sm->enc, &ind->msg); + assert(ba_msg.len < 16 * 1024 && "Are you really encoding so much info?"); + ret.data.ind_msg = ba_msg.buf; + ret.data.len_msg = ba_msg.len; + + return ret; +} + +/** + * @brief Handle a control request for the DAPP service model on the agent. + * + * Decodes the E2SM-DAPP control header and message from the incoming + * request, forwards them to the RAN via sm->base.io.write_ctrl(), and + * encodes the resulting control outcome back into a byte array. + * + * The RAN-side implementation of write_ctrl is what forwards the control on + * to its destination; this service model only relays it. + * + * @param sm_agent The DAPP SM agent instance. + * @param data Encoded control header and message from the RIC. + * @return Encoded control outcome to send back to the RIC. + */ +static sm_ctrl_out_data_t on_control_dapp_sm_ag(sm_agent_t const* sm_agent, sm_ctrl_req_data_t const* data) +{ + assert(sm_agent != NULL); + assert(data != NULL); + sm_dapp_agent_t* sm = (sm_dapp_agent_t*)sm_agent; + + /* Decode the E2SM-DAPP control request */ + dapp_ctrl_req_data_t dapp_ctrl = {0}; + dapp_ctrl.hdr = dapp_dec_ctrl_hdr(&sm->enc, data->len_hdr, data->ctrl_hdr); + dapp_ctrl.msg = dapp_dec_ctrl_msg(&sm->enc, data->len_msg, data->ctrl_msg); + defer({ free_dapp_ctrl_req_data(&dapp_ctrl); }); + + /* Forward control to the RAN via the SM I/O interface */ + sm_ag_if_ans_t ret = sm->base.io.write_ctrl(&dapp_ctrl); + assert(ret.type == CTRL_OUTCOME_SM_AG_IF_ANS_V0); + assert(ret.ctrl_out.type == DAPP_AGENT_IF_CTRL_ANS_V0); + defer({ free_e2sm_dapp_ctrl_out(&ret.ctrl_out.dapp); }); + + /* Encode the E2SM-DAPP control outcome */ + byte_array_t ba = dapp_enc_ctrl_out(&sm->enc, &ret.ctrl_out.dapp); + sm_ctrl_out_data_t ans = {.ctrl_out = ba.buf, .len_out = ba.len}; + + return ans; +} + +/** + * @brief Build the RAN function name, OID, and description for the DAPP SM. + * + * Uses the constants defined in dapp_sm_id.h (SM_DAPP_SHORT_NAME, + * SM_DAPP_OID, SM_DAPP_DESCRIPTION). + * + * @return Populated ran_function_name_t (caller owns the byte arrays). + */ +static ran_function_name_t fill_ran_func_name(void) +{ + ran_function_name_t dst = {0}; + + // RAN Function Short Name + dst.name = cp_str_to_ba(SM_DAPP_SHORT_NAME); + + // RAN Function Service Model OID + dst.oid = cp_str_to_ba(SM_DAPP_OID); + + // RAN Function Description + dst.description = cp_str_to_ba(SM_DAPP_DESCRIPTION); + + return dst; +} + +/** + * @brief Build the E2 Setup data for the DAPP SM on the agent. + * + * Called during E2 setup and RIC service update. Retrieves the DAPP + * RAN function definition from the RAN (which includes report styles, + * control styles, and the current dApp E3 subscription map), sets the + * RAN function name/OID/description, and encodes the full definition + * into a byte array for inclusion in the E2 SETUP REQUEST or + * RIC SERVICE UPDATE message. + * + * @param sm_agent The DAPP SM agent instance. + * @return Encoded RAN function definition. + */ +static sm_e2_setup_data_t on_e2_setup_dapp_sm_ag(sm_agent_t const* sm_agent) +{ + assert(sm_agent != NULL); + + sm_dapp_agent_t* sm = (sm_dapp_agent_t*)sm_agent; + + dapp_e2_setup_t dapp = {0}; + /* An agent that only emulates the RAN side leaves read_setup NULL; the RAN + function definition below is then built from the SM's own constants. */ + if (sm->base.io.read_setup) + sm->base.io.read_setup(&dapp); + + free_ran_function_name(&dapp.ran_func_def.name); + dapp.ran_func_def.name = fill_ran_func_name(); + + assert(dapp.ran_func_def.name.name.buf != NULL); + assert(dapp.ran_func_def.name.name.len > 0); + + e2sm_dapp_func_def_t* ran_func = &dapp.ran_func_def; + + byte_array_t ba = dapp_enc_func_def(&sm->enc, ran_func); + + defer({ free_e2sm_dapp_func_def(ran_func); }); + + sm_e2_setup_data_t setup = {0}; + setup.len_rfd = ba.len; + setup.ran_fun_def = ba.buf; + + return setup; +} + +/** + * @brief Handle RIC Service Update for the DAPP SM on the agent. + * + * Currently a stub that returns an empty sm_ric_service_update_data_t, + * as RIC Service Update is not used for this service model. + */ +static sm_ric_service_update_data_t on_ric_service_update_dapp_sm_ag(sm_agent_t const* sm_agent) +{ + sm_ric_service_update_data_t dst = {0}; + return dst; +} + +/** + * @brief Free the DAPP service model agent instance. + * + * Releases the memory allocated for sm_dapp_agent_t. + */ +static void free_dapp_sm_ag(sm_agent_t* sm_agent) +{ + assert(sm_agent != NULL); + sm_dapp_agent_t* sm = (sm_dapp_agent_t*)sm_agent; + free(sm); +} + +/** + * @brief Return the human-readable definition (short name) of the DAPP SM. + */ +static char const* def_dapp_sm_ag(void) +{ + return SM_DAPP_SHORT_NAME; +} + +/** + * @brief Return the RAN function ID of the DAPP service model. + */ +static uint16_t id_dapp_sm_ag(void) +{ + return SM_DAPP_ID; +} + +/** + * @brief Return the revision number of the DAPP service model. + */ +static uint16_t rev_dapp_sm_ag(void) +{ + return SM_DAPP_REV; +} + +/** + * @brief Return the OID string of the DAPP service model. + */ +static char const* oid_dapp_sm_ag(void) +{ + return SM_DAPP_OID; +} + +/** + * @brief Allocate and initialize the DAPP service model agent. + * + * Creates the internal sm_dapp_agent_t, wires the I/O callbacks from + * the sm_io_ag_ran_t table, and registers all SM procedure handlers: + * - on_subscription: decodes event trigger + action definition, + * forwards to write_subs which routes by report style type + * - on_indication: encodes Format 1 or Format 2 indications + * - on_control: decodes/forwards/encodes control requests + * - on_e2_setup: builds the RAN function definition + * - on_ric_service_update: stub (updates triggered externally) + * + * @param io I/O callback table connecting the SM to the RAN functions. + * @return Pointer to the initialized SM agent (caller owns). + */ +sm_agent_t* make_dapp_sm_agent(sm_io_ag_ran_t io) +{ + sm_dapp_agent_t* sm = calloc(1, sizeof(sm_dapp_agent_t)); + assert(sm != NULL && "Memory exhausted!!!"); + + sm->base.io.read_ind = io.read_ind_tbl[DAPP_STATS_V0]; + sm->base.io.read_setup = io.read_setup_tbl[DAPP_AGENT_IF_E2_SETUP_ANS_V0]; + + sm->base.io.write_ctrl = io.write_ctrl_tbl[DAPP_CTRL_V0]; + sm->base.io.write_subs = io.write_subs_tbl[DAPP_SUBS_V0]; + + sm->base.free_sm = free_dapp_sm_ag; + sm->base.free_act_def = NULL; + + sm->base.proc.on_subscription = on_subscription_dapp_sm_ag; + sm->base.proc.on_indication = on_indication_dapp_sm_ag; + sm->base.proc.on_control = on_control_dapp_sm_ag; + sm->base.proc.on_ric_service_update = on_ric_service_update_dapp_sm_ag; + sm->base.proc.on_e2_setup = on_e2_setup_dapp_sm_ag; + sm->base.handle = NULL; + + sm->base.info.def = def_dapp_sm_ag; + sm->base.info.id = id_dapp_sm_ag; + sm->base.info.rev = rev_dapp_sm_ag; + sm->base.info.oid = oid_dapp_sm_ag; + + return &sm->base; +} diff --git a/src/sm/dapp_sm/dapp_sm_agent.h b/src/sm/dapp_sm/dapp_sm_agent.h new file mode 100644 index 000000000..c90994488 --- /dev/null +++ b/src/sm/dapp_sm/dapp_sm_agent.h @@ -0,0 +1,14 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef DAPP_SERVICE_MODEL_AGENT_H +#define DAPP_SERVICE_MODEL_AGENT_H + +#include +#include +#include "../sm_agent.h" + +__attribute__((visibility("default"))) sm_agent_t* make_dapp_sm_agent(sm_io_ag_ran_t io); + +#endif diff --git a/src/sm/dapp_sm/dapp_sm_id.h b/src/sm/dapp_sm/dapp_sm_id.h new file mode 100644 index 000000000..2f4f1ffb4 --- /dev/null +++ b/src/sm/dapp_sm/dapp_sm_id.h @@ -0,0 +1,25 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef DAPP_SERVICE_MODEL_ID_H +#define DAPP_SERVICE_MODEL_ID_H + +#include + +static const uint16_t SM_DAPP_ID = 255; + +static const uint16_t SM_DAPP_REV = 1; + +#define SM_DAPP_SHORT_NAME "E2SM-DAPP" +// iso(1) identified-organization(3) +// dod(6) internet(1) private(4) +// enterprise(1) 53148 e2(1) +// version1 (1) e2sm(2) e2sm-DAPP- +// IEs (3) + +#define SM_DAPP_OID "1.3.6.1.4.1.53148.1.1.255.3" + +#define SM_DAPP_DESCRIPTION "DAPP Service Model for E2/E3 bridge" + +#endif diff --git a/src/sm/dapp_sm/dapp_sm_ric.c b/src/sm/dapp_sm/dapp_sm_ric.c new file mode 100644 index 000000000..3b0db25ce --- /dev/null +++ b/src/sm/dapp_sm/dapp_sm_ric.c @@ -0,0 +1,402 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "dapp_sm_ric.h" +#include "dapp_sm_id.h" + +#include +#include + +#include "ie/dapp_data_ie.h" +#include "e3/dapp_dec_e3.h" +#include "e3/dapp_enc_e3.h" + +#include "enc/dapp_enc_generic.h" +#include "dec/dapp_dec_generic.h" + +typedef struct { + sm_ric_t base; + +#ifdef ASN + dapp_enc_asn_t enc; +#elif FLATBUFFERS + dapp_enc_fb_t enc; +#elif PLAIN + dapp_enc_plain_t enc; +#else + static_assert(false, "No encoding type selected"); +#endif +} sm_dapp_ric_t; + +/** + * @brief Build an E2 subscription for the DAPP SM on the RIC. + * + * Takes a high-level dapp_sub_data_t containing: + * - Event trigger (common to all styles, Format 1) + * - Action definition (optional, carries the report style type) + * + * Encodes both into byte arrays and returns an sm_subs_data_t ready + * to be sent over E2AP in a RIC SUBSCRIPTION REQUEST. + * + * The action definition's ric_style_type determines what indications + * the agent will send: + * - Style 1: Format 1 only (E3 data reports) + * - Style 2: Format 2 only (E3 subscription map) + * + * @param sm_ric The RIC-side DAPP SM instance (codec context). + * @param cmd Pointer to a dapp_sub_data_t with event trigger and + * action definition. + * @return Encoded subscription data (event trigger + action definition). + */ +static sm_subs_data_t on_subscription_dapp_sm_ric(sm_ric_t const* sm_ric, void* cmd) +{ + assert(sm_ric != NULL); + assert(cmd != NULL); + dapp_sub_data_t const* src = cmd; + sm_dapp_ric_t* sm = (sm_dapp_ric_t*)sm_ric; + sm_subs_data_t dst = {0}; + + /* Encode E2SM-DAPP event trigger */ + const byte_array_t ba_et = dapp_enc_event_trigger(&sm->enc, &src->et); + dst.event_trigger = ba_et.buf; + dst.len_et = ba_et.len; + + /* Encode E2SM-DAPP action definition */ + if (src->action_def != NULL) { + const byte_array_t ba_ad = dapp_enc_action_def(&sm->enc, src->action_def); + dst.action_def = ba_ad.buf; + dst.len_ad = ba_ad.len; + } + + return dst; +} + +/** + * @brief RIC-side indication handler for the DAPP service model. + * + * Called when the RIC receives an indication message for the DAPP SM + * from the E2 agent. Performs a two-stage decode: + * + * 1) E2SM-DAPP layer: + * - Decodes the indication header and message using the DAPP codec. + * - Fills dst.dapp.ind.hdr and dst.dapp.ind.msg. + * + * 2) Inner payload (format-dependent): + * - Format 1 (E3 data report): + * Extracts the RAN function ID from the header. If the message + * carries a non-empty data buffer, calls dapp_dec_e3_indication() + * to decode the inner E3 payload into dst.dapp.ind.e3. + * - Format 2 (subscription map): + * The subscription list is already fully decoded by the E2SM-DAPP + * message decoder. Sets dst.dapp.ind.e3.type = DAPP_E3_SM_NONE + * (no inner E3 payload). + * + * @param sm_ric The RIC-side DAPP SM instance (codec context). + * @param src Raw indication data received from the E2 agent. + * @return Decoded indication container (type DAPP_STATS_V0). + */ +static sm_ag_if_rd_ind_t on_indication_dapp_sm_ric(sm_ric_t const* sm_ric, sm_ind_data_t const* src) +{ + assert(sm_ric != NULL); + assert(src != NULL); + sm_dapp_ric_t* sm = (sm_dapp_ric_t*)sm_ric; + + sm_ag_if_rd_ind_t dst = {.type = DAPP_STATS_V0}; + + /* Decode the E2SM-DAPP indication header, message and, for format 1, the + * inner E3 payload the message carries. */ + dst.dapp.ind.hdr = dapp_dec_ind_hdr(&sm->enc, src->len_hdr, src->ind_hdr); + dst.dapp.ind.msg = dapp_dec_ind_msg(&sm->enc, src->len_msg, src->ind_msg); + dst.dapp.ric_id = 0; + + if (dst.dapp.ind.msg.format == FORMAT_1_E2SM_DAPP_IND_MSG) { + /* Format 1: decode inner E3 payload from raw bytes */ + assert(dst.dapp.ind.hdr.format == FORMAT_1_E2SM_DAPP_IND_HDR); + + e2sm_dapp_ind_msg_frmt_1_t* m1 = &dst.dapp.ind.msg.frmt_1; + uint32_t ran_function_id = dst.dapp.ind.hdr.frmt_1.ran_function_id; + + if (m1->data_size > 0 && m1->data != NULL) { + bool ok = dapp_dec_e3_indication(ran_function_id, m1->data, m1->data_size, &dst.dapp.ind.e3); + if (!ok) { + assert(0 && "Failed to decode inner E3 payload"); + } + } else { + dst.dapp.ind.e3.type = DAPP_E3_SM_NONE; + } + } else if (dst.dapp.ind.msg.format == FORMAT_2_E2SM_DAPP_IND_MSG) { + /* Format 2: subscription map — no inner E3 payload to decode */ + assert(dst.dapp.ind.hdr.format == FORMAT_2_E2SM_DAPP_IND_HDR); + dst.dapp.ind.e3.type = DAPP_E3_SM_NONE; + } else { + assert(0 != 0 && "Unknown indication message format"); + } + + return dst; +} + +/** + * @brief RIC-side handler for DAPP SM control requests. + * + * This function is called when the RIC plugin receives a control request + * for the DAPP SM from the xApp side. + * + * High-level behavior: + * - Interprets @p ctrl as a dapp_ctrl_req_data_t (E2SM-DAPP control IR). + * - If the request carries a non-empty E3 control payload (tmp.e3.type != + * DAPP_E3_SM_NONE) and the E2SM-DAPP ControlMessage (format 1) currently + * has no inner data (data == NULL, data_size == 0), it: + * 1) Encodes the E3 control payload into a binary buffer using + * dapp_enc_e3_control(), based on the ran_function_id in the header. + * 2) Injects the encoded E3 buffer into tmp.msg.frmt_1.data / data_size. + * 3) Encodes the DAPP ControlHeader and ControlMessage into byte arrays + * using dapp_enc_ctrl_hdr() and dapp_enc_ctrl_msg(). + * 4) Releases the temporary E3 buffer once dapp_enc_ctrl_msg() has + * copied its bytes into the outer ControlMessage encoding. + * - Fills a sm_ctrl_req_data_t structure with: + * * ctrl_hdr / len_hdr: encoded E2SM-DAPP ControlHeader + * * ctrl_msg / len_msg: encoded E2SM-DAPP ControlMessage + * - Returns the filled sm_ctrl_req_data_t, which the FlexRIC core then + * forwards over the E2 interface. + * + * @param sm_ric Pointer to the RIC-side DAPP SM instance (codec context). + * @param ctrl Pointer to a dapp_ctrl_req_data_t describing the control. + * + * @return Encoded control header and message ready to be sent over E2. + */ +static sm_ctrl_req_data_t ric_on_control_req_dapp_sm_ric(sm_ric_t const* sm_ric, void* ctrl) +{ + assert(sm_ric != NULL); + assert(ctrl != NULL); + + sm_dapp_ric_t* sm = (sm_dapp_ric_t*)sm_ric; + + dapp_ctrl_req_data_t const* req = (dapp_ctrl_req_data_t const*)ctrl; + sm_ctrl_req_data_t dst = (sm_ctrl_req_data_t){0}; + + dapp_ctrl_req_data_t tmp = *req; + + if (tmp.e3.type != DAPP_E3_SM_NONE && tmp.msg.format == FORMAT_1_E2SM_DAPP_CTRL_MSG && tmp.msg.frmt_1.data == NULL + && tmp.msg.frmt_1.data_size == 0) { + uint8_t* e3_buf = NULL; + size_t e3_len = 0; + + bool ok = dapp_enc_e3_control(tmp.hdr.frmt_1.ran_function_id, &tmp.e3, &e3_buf, &e3_len); + if (!ok) { + fprintf(stderr, "[DAPP][RIC] Failed to encode E3 control payload\n"); + assert(0 && "E3 control encoding failed"); + } + + tmp.msg.frmt_1.data = e3_buf; + tmp.msg.frmt_1.data_size = (uint32_t)e3_len; + + byte_array_t ba_hdr = dapp_enc_ctrl_hdr(&sm->enc, &tmp.hdr); + dst.ctrl_hdr = ba_hdr.buf; + dst.len_hdr = ba_hdr.len; + + byte_array_t ba_msg = dapp_enc_ctrl_msg(&sm->enc, &tmp.msg); + dst.ctrl_msg = ba_msg.buf; + dst.len_msg = ba_msg.len; + + free(e3_buf); + } + + return dst; +} + +/** + * @brief Decode a DAPP control outcome received at the RIC. + * + * - Takes raw control outcome bytes from the agent. + * - Decodes them into the dapp-specific control outcome structure. + */ +static sm_ag_if_ans_ctrl_t ric_on_control_out_dapp_sm_ric(sm_ric_t const* sm_ric, const sm_ctrl_out_data_t* src) +{ + assert(sm_ric != NULL); + assert(src != NULL); + sm_dapp_ric_t* sm = (sm_dapp_ric_t*)sm_ric; + + /* Decode E2SM-DAPP control outcome */ + sm_ag_if_ans_ctrl_t dst = {.type = DAPP_AGENT_IF_CTRL_ANS_V0}; + dst.dapp = dapp_dec_ctrl_out(&sm->enc, src->len_out, src->ctrl_out); + + return dst; +} + +/** + * @brief Decode the E2 Setup Response for the DAPP SM at the RIC. + * + * - Parses the RAN function definition from the E2 setup data. + * - Wraps it into an sm_ag_if_rd_e2setup_t with type DAPP_AGENT_IF_E2_SETUP_ANS_V0. + */ +static sm_ag_if_rd_e2setup_t ric_on_e2_setup_dapp_sm_ric(sm_ric_t const* sm_ric, sm_e2_setup_data_t const* src) +{ + assert(sm_ric != NULL); + assert(src != NULL); + sm_dapp_ric_t* sm = (sm_dapp_ric_t*)sm_ric; + + sm_ag_if_rd_e2setup_t dst = {.type = DAPP_AGENT_IF_E2_SETUP_ANS_V0}; + + dst.dapp.ran_func_def = dapp_dec_func_def(&sm->enc, src->len_rfd, src->ran_fun_def); + + return dst; +} +/** + * @brief Handle RIC Service Update messages for the DAPP SM. + * + * Currently a placeholder that returns an empty sm_ag_if_rd_rsu_t. + */ +static sm_ag_if_rd_rsu_t on_ric_service_update_dapp_sm_ric(sm_ric_t const* sm_ric, sm_ric_service_update_data_t const* src) +{ + assert(sm_ric != NULL); + assert(src != NULL); + sm_ag_if_rd_rsu_t dst = {0}; + return dst; +} + +/** + * @brief Free the DAPP SM RIC instance allocated by make_dapp_sm_ric(). + * + * Releases the sm_dapp_ric_t container itself; the framework's plugin + * loader stores no extra heap state beyond it. + */ +static void free_dapp_sm_ric(sm_ric_t* sm_ric) +{ + assert(sm_ric != NULL); + sm_dapp_ric_t* sm = (sm_dapp_ric_t*)sm_ric; + free(sm); +} + +/* + * The six alloc.free_* callbacks below are the duals of the on_* procedures + * in sm_e2ap_procedures_ric_t — each one releases the heap memory the + * matching procedure returned. The framework currently invokes + * free_ind_data after every on_indication (msg_handler_ric.c); the others + * are wired in for forward-compatibility. + */ + +/** + * @brief Free the sm_subs_data_t produced by on_subscription_dapp_sm_ric. + * + * Releases the encoded event_trigger and action_def byte buffers. + */ +static void free_subs_data_dapp_sm_ric(void* msg) +{ + assert(msg != NULL); + free_sm_subs_data((sm_subs_data_t*)msg); +} + +/** + * @brief Free the sm_ag_if_rd_ind_t produced by on_indication_dapp_sm_ric. + * + * The framework calls this after publishing the indication. Releases the + * decoded DAPP indication header, message, and inner E3 payload. + */ +static void free_ind_data_dapp_sm_ric(void* msg) +{ + assert(msg != NULL); + sm_ag_if_rd_ind_t* rd_ind = (sm_ag_if_rd_ind_t*)msg; + assert(rd_ind->type == DAPP_STATS_V0); + free_dapp_ind_data(&rd_ind->dapp.ind); +} + +/** + * @brief Free the sm_ctrl_req_data_t produced by ric_on_control_req_dapp_sm_ric. + * + * Releases the encoded ctrl_hdr and ctrl_msg byte buffers. + */ +static void free_ctrl_req_data_dapp_sm_ric(void* msg) +{ + assert(msg != NULL); + free_sm_ctrl_req_data((sm_ctrl_req_data_t*)msg); +} + +/** + * @brief Free the sm_ag_if_ans_ctrl_t produced by ric_on_control_out_dapp_sm_ric. + * + * Releases the decoded DAPP control outcome in the .dapp union member. + */ +static void free_ctrl_out_data_dapp_sm_ric(void* msg) +{ + assert(msg != NULL); + sm_ag_if_ans_ctrl_t* ans = (sm_ag_if_ans_ctrl_t*)msg; + assert(ans->type == DAPP_AGENT_IF_CTRL_ANS_V0); + free_e2sm_dapp_ctrl_out(&ans->dapp); +} + +/** + * @brief Free the sm_ag_if_rd_e2setup_t produced by ric_on_e2_setup_dapp_sm_ric. + * + * Releases the decoded RAN function definition in the .dapp union member. + */ +static void free_e2_setup_dapp_sm_ric(void* msg) +{ + assert(msg != NULL); + sm_ag_if_rd_e2setup_t* e2 = (sm_ag_if_rd_e2setup_t*)msg; + assert(e2->type == DAPP_AGENT_IF_E2_SETUP_ANS_V0); + free_e2sm_dapp_func_def(&e2->dapp.ran_func_def); +} + +/** + * @brief Free the sm_ag_if_rd_rsu_t produced by on_ric_service_update_dapp_sm_ric. + * + * The matching procedure is currently a stub that returns a zero-initialized + * structure, so there is nothing to release; the function exists only to + * keep the alloc.free_* table fully populated. + */ +static void free_ric_service_update_dapp_sm_ric(void* msg) +{ + assert(msg != NULL); + (void)msg; +} + +/** + * @brief Allocate and initialize the DAPP Service Model instance at the RIC. + * + * - Allocates sm_dapp_ric_t. + * - Sets the RAN function ID, name, and all function pointers for + * subscription, indication, control, E2 setup, and service update handlers. + */ +sm_ric_t* make_dapp_sm_ric(void) +{ + sm_dapp_ric_t* sm = calloc(1, sizeof(sm_dapp_ric_t)); + assert(sm != NULL && "Memory exhausted"); + + *((uint16_t*)&sm->base.ran_func_id) = SM_DAPP_ID; + + sm->base.free_sm = free_dapp_sm_ric; + + sm->base.alloc.free_subs_data_msg = free_subs_data_dapp_sm_ric; + sm->base.alloc.free_ind_data = free_ind_data_dapp_sm_ric; + sm->base.alloc.free_ctrl_req_data = free_ctrl_req_data_dapp_sm_ric; + sm->base.alloc.free_ctrl_out_data = free_ctrl_out_data_dapp_sm_ric; + + sm->base.alloc.free_e2_setup = free_e2_setup_dapp_sm_ric; + sm->base.alloc.free_ric_service_update = free_ric_service_update_dapp_sm_ric; + + sm->base.proc.on_subscription = on_subscription_dapp_sm_ric; + sm->base.proc.on_indication = on_indication_dapp_sm_ric; + + sm->base.proc.on_control_req = ric_on_control_req_dapp_sm_ric; + sm->base.proc.on_control_out = ric_on_control_out_dapp_sm_ric; + + sm->base.proc.on_e2_setup = ric_on_e2_setup_dapp_sm_ric; + sm->base.proc.on_ric_service_update = on_ric_service_update_dapp_sm_ric; + sm->base.handle = NULL; + + assert(strlen(SM_DAPP_SHORT_NAME) < sizeof(sm->base.ran_func_name)); + memcpy(sm->base.ran_func_name, SM_DAPP_SHORT_NAME, strlen(SM_DAPP_SHORT_NAME)); + + return &sm->base; +} + +/** + * @brief Return the RAN function ID for the given DAPP SM RIC instance. + */ +uint16_t id_sm_dapp_ric(sm_ric_t const* sm_ric) +{ + assert(sm_ric != NULL); + sm_dapp_ric_t* sm = (sm_dapp_ric_t*)sm_ric; + return sm->base.ran_func_id; +} diff --git a/src/sm/dapp_sm/dapp_sm_ric.h b/src/sm/dapp_sm/dapp_sm_ric.h new file mode 100644 index 000000000..616484491 --- /dev/null +++ b/src/sm/dapp_sm/dapp_sm_ric.h @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef DAPP_SERVICE_MODEL_SERVER_H +#define DAPP_SERVICE_MODEL_SERVER_H + +#include +#include +#include "../../sm/sm_ric.h" + +__attribute__((visibility("default"))) sm_ric_t* make_dapp_sm_ric(void); + +uint16_t id_dapp_sm_ric(sm_ric_t const*); + +#endif diff --git a/src/sm/dapp_sm/dec/dapp_dec_asn.c b/src/sm/dapp_sm/dec/dapp_dec_asn.c new file mode 100644 index 000000000..ad2292bf3 --- /dev/null +++ b/src/sm/dapp_sm/dec/dapp_dec_asn.c @@ -0,0 +1,280 @@ +#include "dapp_dec_asn.h" + +#include +#include +#include +#include + +#include + +/* libe3 owns the ASN.1 and hands back malloc'ed memory. Each decoder moves what + * the IR keeps into IR structs (the pointers are plain malloc, so the IR's free_ + * helpers release them), nulls it in libe3's struct, and lets libe3's free_ + * release the rest. */ + +/* Move the bytes out of `b`; the result is released with free_byte_array(). */ +static byte_array_t take_bytes(libe3_e2sm_dapp_bytes_t* b) +{ + byte_array_t ba = {.len = b->len, .buf = b->data}; + b->data = NULL; + b->len = 0; + return ba; +} + +static dapp_e3_subscription_list_t take_subs(libe3_e2sm_dapp_sub_list_t* src) +{ + dapp_e3_subscription_list_t dst = {.sz_dapp_e3_subscriptions = src->n_items}; + + if (src->n_items == 0) + return dst; + + dst.dapp_e3_subscriptions = calloc(src->n_items, sizeof(*dst.dapp_e3_subscriptions)); + assert(dst.dapp_e3_subscriptions != NULL && "Memory exhausted"); + + for (size_t i = 0; i < src->n_items; ++i) { + libe3_e2sm_dapp_sub_item_t* item = &src->items[i]; + dst.dapp_e3_subscriptions[i] = (dapp_e3_subscription_item_t){.dapp_id = item->dapp_id, + .sz_subscribed_e3_ran_functions = item->n_ran_functions, + .subscribed_e3_ran_functions = item->ran_functions}; + item->ran_functions = NULL; + } + + return dst; +} + +/* A failed decode is a bug in the peer or in us, as it has always been here. */ +static void check_decoded(e3_error_t rc) +{ + assert(rc == E3_SUCCESS && "E2SM-DAPP decode failed"); + (void)rc; +} + +e2sm_dapp_event_trigger_t dapp_dec_event_trigger_asn(size_t len, uint8_t const buf[len]) +{ + assert(buf != NULL); + assert(len != 0); + + libe3_e2sm_dapp_event_trigger_t src = {0}; + check_decoded(libe3_e2sm_dapp_decode_event_trigger(buf, len, &src)); + assert(src.format == LIBE3_E2SM_DAPP_EVENT_TRIGGER_FORMAT_1 && "Unknown format"); + + e2sm_dapp_event_trigger_t dst = {.format = FORMAT_1_E2SM_DAPP_EV_TRIGGER_FORMAT}; + libe3_e2sm_dapp_free_event_trigger(&src); + return dst; +} + +e2sm_dapp_action_def_t dapp_dec_action_def_asn(size_t len, uint8_t const buf[len]) +{ + assert(buf != NULL); + assert(len != 0); + + libe3_e2sm_dapp_action_definition_t src = {0}; + check_decoded(libe3_e2sm_dapp_decode_action_definition(buf, len, &src)); + assert(src.format == LIBE3_E2SM_DAPP_ACTION_DEFINITION_FORMAT_1 && "Unknown action definition format"); + + e2sm_dapp_action_def_t dst = {.format = FORMAT_1_E2SM_DAPP_ACTION_DEF, .ric_style_type = (uint32_t)src.ric_style_type}; + libe3_e2sm_dapp_free_action_definition(&src); + return dst; +} + +e2sm_dapp_ind_hdr_t dapp_dec_ind_hdr_asn(size_t len, uint8_t const ind_hdr[len]) +{ + assert(ind_hdr != NULL); + assert(len != 0); + + libe3_e2sm_dapp_ind_hdr_t src = {0}; + check_decoded(libe3_e2sm_dapp_decode_ind_hdr(ind_hdr, len, &src)); + + /* Absent timestamp and sequence id are 0 in the IR, as is a node_cu_du_id that is not present. */ + e2sm_dapp_ind_hdr_t dst = {0}; + + if (src.format == LIBE3_E2SM_DAPP_IND_HDR_FORMAT_1) { + libe3_e2sm_dapp_ind_hdr_format1_t const* f = &src.frmt_1; + dst.format = FORMAT_1_E2SM_DAPP_IND_HDR; + dst.frmt_1 = (e2sm_dapp_ind_hdr_frmt_1_t){.ran_function_id = f->ran_function_id, + .dapp_id = f->dapp_id, + .node_type = f->node_type, + .node_nb_id = f->node_nb_id, + .node_cu_du_id_present = f->has_node_cu_du_id, + .node_cu_du_id = f->has_node_cu_du_id ? f->node_cu_du_id : 0, + .timestamp_ns = f->has_timestamp ? f->timestamp : 0, + .sequence_id = f->has_sequence_id ? f->sequence_id : 0}; + memcpy(dst.frmt_1.node_plmn_id, f->node_plmn_id, 3); + } else if (src.format == LIBE3_E2SM_DAPP_IND_HDR_FORMAT_2) { + libe3_e2sm_dapp_ind_hdr_format2_t const* f = &src.frmt_2; + dst.format = FORMAT_2_E2SM_DAPP_IND_HDR; + dst.frmt_2 = (e2sm_dapp_ind_hdr_frmt_2_t){.node_type = f->node_type, + .node_nb_id = f->node_nb_id, + .node_cu_du_id_present = f->has_node_cu_du_id, + .node_cu_du_id = f->has_node_cu_du_id ? f->node_cu_du_id : 0, + .timestamp_ns = f->has_timestamp ? f->timestamp : 0, + .sequence_id = f->has_sequence_id ? f->sequence_id : 0}; + memcpy(dst.frmt_2.node_plmn_id, f->node_plmn_id, 3); + } else { + assert(0 != 0 && "Unknown format"); + } + + libe3_e2sm_dapp_free_ind_hdr(&src); + return dst; +} + +e2sm_dapp_ind_msg_t dapp_dec_ind_msg_asn(size_t len, uint8_t const ind_msg[len]) +{ + assert(ind_msg != NULL); + assert(len != 0); + + libe3_e2sm_dapp_ind_msg_t src = {0}; + check_decoded(libe3_e2sm_dapp_decode_ind_msg(ind_msg, len, &src)); + + e2sm_dapp_ind_msg_t dst = {0}; + + if (src.format == LIBE3_E2SM_DAPP_IND_MSG_FORMAT_1) { + dst.format = FORMAT_1_E2SM_DAPP_IND_MSG; + dst.frmt_1.data_size = src.frmt_1.data.len; + dst.frmt_1.data = take_bytes(&src.frmt_1.data).buf; + } else if (src.format == LIBE3_E2SM_DAPP_IND_MSG_FORMAT_2) { + dst.format = FORMAT_2_E2SM_DAPP_IND_MSG; + dst.frmt_2.dapp_e3_subs = take_subs(&src.frmt_2.dapp_e3_subscriptions); + } else { + assert(0 != 0 && "Unknown format type"); + } + + libe3_e2sm_dapp_free_ind_msg(&src); + return dst; +} + +e2sm_dapp_ctrl_hdr_t dapp_dec_ctrl_hdr_asn(size_t len, uint8_t const ctrl_hdr[len]) +{ + assert(ctrl_hdr != NULL); + + libe3_e2sm_dapp_ctrl_hdr_t src = {0}; + check_decoded(libe3_e2sm_dapp_decode_ctrl_hdr(ctrl_hdr, len, &src)); + assert(src.format == LIBE3_E2SM_DAPP_CTRL_HDR_FORMAT_1 && "Unknown format type"); + + e2sm_dapp_ctrl_hdr_t dst = {.format = FORMAT_1_E2SM_DAPP_CTRL_HDR, + .frmt_1 = {.ran_function_id = src.ran_function_id, + .dapp_id = src.dapp_id, + .timestamp_ns = src.has_timestamp ? src.timestamp : 0, + .sequence_id = src.has_sequence_id ? src.sequence_id : 0}}; + libe3_e2sm_dapp_free_ctrl_hdr(&src); + return dst; +} + +e2sm_dapp_ctrl_msg_t dapp_dec_ctrl_msg_asn(size_t len, uint8_t const ctrl_msg[len]) +{ + assert(ctrl_msg != NULL); + assert(len > 0); + + libe3_e2sm_dapp_ctrl_msg_t src = {0}; + check_decoded(libe3_e2sm_dapp_decode_ctrl_msg(ctrl_msg, len, &src)); + assert(src.format == LIBE3_E2SM_DAPP_CTRL_MSG_FORMAT_1 && "Unknown format"); + + e2sm_dapp_ctrl_msg_t dst = {.format = FORMAT_1_E2SM_DAPP_CTRL_MSG}; + dst.frmt_1.data_size = (uint32_t)src.data.len; + dst.frmt_1.data = take_bytes(&src.data).buf; + + libe3_e2sm_dapp_free_ctrl_msg(&src); + return dst; +} + +e2sm_dapp_ctrl_out_t dapp_dec_ctrl_out_asn(size_t len, uint8_t const ctrl_out[len]) +{ + assert(ctrl_out != NULL); + assert(len > 0); + + libe3_e2sm_dapp_ctrl_outcome_t src = {0}; + check_decoded(libe3_e2sm_dapp_decode_ctrl_outcome(ctrl_out, len, &src)); + assert(src.format == LIBE3_E2SM_DAPP_CTRL_OUTCOME_FORMAT_1 && "Unknown format"); + + e2sm_dapp_ctrl_out_t dst = {.format = FORMAT_1_E2SM_DAPP_CTRL_OUT, + .frmt_1 = {.timestamp_ns = src.has_timestamp ? src.timestamp : 0, + .sequence_id = src.has_sequence_id ? src.sequence_id : 0}}; + + /* An empty outcome is the same as an absent one: NULL with size 0. */ + if (src.has_e3_control_outcome && src.e3_control_outcome.len > 0) { + dst.frmt_1.e3_control_outcome_size = (uint32_t)src.e3_control_outcome.len; + dst.frmt_1.e3_control_outcome = take_bytes(&src.e3_control_outcome).buf; + } + + libe3_e2sm_dapp_free_ctrl_outcome(&src); + return dst; +} + +e2sm_dapp_func_def_t dapp_dec_func_def_asn(size_t len, uint8_t const func_def[len]) +{ + assert(func_def != NULL); + assert(len > 0); + + libe3_e2sm_dapp_ran_function_definition_t src = {0}; + check_decoded(libe3_e2sm_dapp_decode_ran_function_definition(func_def, len, &src)); + + e2sm_dapp_func_def_t dst = {0}; + + dst.name.name = take_bytes(&src.name.short_name); + dst.name.oid = take_bytes(&src.name.e2sm_oid); + dst.name.description = take_bytes(&src.name.description); + /* The instance is dropped: cp_ran_function_name() still asserts it is NULL. */ + + if (src.has_event_trigger) { + dst.ev_trig = calloc(1, sizeof(ran_func_def_ev_trig_dapp_sm_t)); + assert(dst.ev_trig != NULL && "Memory exhausted"); + } + + if (src.has_report) { + dst.report = calloc(1, sizeof(ran_func_def_report_dapp_sm_t)); + assert(dst.report != NULL && "Memory exhausted"); + dst.report->sz_seq_report_sty = src.n_report_styles; + + if (src.n_report_styles > 0) { + dst.report->seq_report_sty = calloc(src.n_report_styles, sizeof(seq_report_sty_dapp_sm_t)); + assert(dst.report->seq_report_sty != NULL && "Memory exhausted"); + } + + for (size_t i = 0; i < src.n_report_styles; ++i) { + libe3_e2sm_dapp_report_style_t* s = &src.report_styles[i]; + seq_report_sty_dapp_sm_t* out = &dst.report->seq_report_sty[i]; + + out->report_type = (uint32_t)s->report_style_type; + out->name = take_bytes(&s->name); + out->ind_hdr_type = (uint32_t)s->ind_hdr_format_type; + out->ind_msg_type = (uint32_t)s->ind_msg_format_type; + + if (s->has_dapp_e3_subscriptions) { + out->dapp_e3_subs = calloc(1, sizeof(dapp_e3_subscription_list_t)); + assert(out->dapp_e3_subs != NULL && "Memory exhausted"); + *out->dapp_e3_subs = take_subs(&s->dapp_e3_subscriptions); + } + } + } + + if (src.has_ctrl) { + dst.ctrl = calloc(1, sizeof(ran_func_def_ctrl_dapp_sm_t)); + assert(dst.ctrl != NULL && "Memory exhausted"); + dst.ctrl->sz_seq_ctrl_style = src.n_ctrl_styles; + + if (src.n_ctrl_styles > 0) { + dst.ctrl->seq_ctrl_style = calloc(src.n_ctrl_styles, sizeof(seq_ctrl_style_dapp_sm_t)); + assert(dst.ctrl->seq_ctrl_style != NULL && "Memory exhausted"); + } + + for (size_t i = 0; i < src.n_ctrl_styles; ++i) { + libe3_e2sm_dapp_ctrl_style_t* s = &src.ctrl_styles[i]; + seq_ctrl_style_dapp_sm_t* out = &dst.ctrl->seq_ctrl_style[i]; + + out->style_type = (uint32_t)s->ctrl_style_type; + out->name = take_bytes(&s->name); + out->hdr = (uint32_t)s->ctrl_hdr_format_type; + out->msg = (uint32_t)s->ctrl_msg_format_type; + out->out_frmt = (uint32_t)s->ctrl_outcome_format_type; + + if (s->has_dapp_e3_subscriptions) { + out->dapp_e3_subs = calloc(1, sizeof(dapp_e3_subscription_list_t)); + assert(out->dapp_e3_subs != NULL && "Memory exhausted"); + *out->dapp_e3_subs = take_subs(&s->dapp_e3_subscriptions); + } + } + } + + libe3_e2sm_dapp_free_ran_function_definition(&src); + return dst; +} diff --git a/src/sm/dapp_sm/dec/dapp_dec_asn.h b/src/sm/dapp_sm/dec/dapp_dec_asn.h new file mode 100644 index 000000000..cee2234b8 --- /dev/null +++ b/src/sm/dapp_sm/dec/dapp_dec_asn.h @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef DAPP_DECRYPTION_ASN_H +#define DAPP_DECRYPTION_ASN_H + +#include +#include "../ie/dapp_data_ie.h" + +__attribute__((visibility("default"))) e2sm_dapp_event_trigger_t dapp_dec_event_trigger_asn(size_t len, uint8_t const ev_tr[len]); + +__attribute__((visibility("default"))) e2sm_dapp_action_def_t dapp_dec_action_def_asn(size_t len, uint8_t const buf[len]); + +__attribute__((visibility("default"))) e2sm_dapp_ind_hdr_t dapp_dec_ind_hdr_asn(size_t len, uint8_t const ind_hdr[len]); + +__attribute__((visibility("default"))) e2sm_dapp_ind_msg_t dapp_dec_ind_msg_asn(size_t len, uint8_t const ind_msg[len]); + +__attribute__((visibility("default"))) e2sm_dapp_ctrl_hdr_t dapp_dec_ctrl_hdr_asn(size_t len, uint8_t const ctrl_hdr[len]); + +__attribute__((visibility("default"))) e2sm_dapp_ctrl_msg_t dapp_dec_ctrl_msg_asn(size_t len, uint8_t const ctrl_msg[len]); + +__attribute__((visibility("default"))) e2sm_dapp_ctrl_out_t dapp_dec_ctrl_out_asn(size_t len, uint8_t const ctrl_out[len]); + +__attribute__((visibility("default"))) e2sm_dapp_func_def_t dapp_dec_func_def_asn(size_t len, uint8_t const func_def[len]); + +#endif diff --git a/src/sm/dapp_sm/dec/dapp_dec_generic.h b/src/sm/dapp_sm/dec/dapp_dec_generic.h new file mode 100644 index 000000000..b71329154 --- /dev/null +++ b/src/sm/dapp_sm/dec/dapp_dec_generic.h @@ -0,0 +1,22 @@ +#ifndef DAPP_DECRYPTION_GENERIC +#define DAPP_DECRYPTION_GENERIC + +#include "dapp_dec_asn.h" + +#define dapp_dec_event_trigger(T, U, V) _Generic((T), dapp_enc_asn_t *: dapp_dec_event_trigger_asn)(U, V) + +#define dapp_dec_action_def(T, U, V) _Generic((T), dapp_enc_asn_t *: dapp_dec_action_def_asn)(U, V) + +#define dapp_dec_ind_hdr(T, U, V) _Generic((T), dapp_enc_asn_t *: dapp_dec_ind_hdr_asn)(U, V) + +#define dapp_dec_ind_msg(T, U, V) _Generic((T), dapp_enc_asn_t *: dapp_dec_ind_msg_asn)(U, V) + +#define dapp_dec_ctrl_hdr(T, U, V) _Generic((T), dapp_enc_asn_t *: dapp_dec_ctrl_hdr_asn)(U, V) + +#define dapp_dec_ctrl_msg(T, U, V) _Generic((T), dapp_enc_asn_t *: dapp_dec_ctrl_msg_asn)(U, V) + +#define dapp_dec_ctrl_out(T, U, V) _Generic((T), dapp_enc_asn_t *: dapp_dec_ctrl_out_asn)(U, V) + +#define dapp_dec_func_def(T, U, V) _Generic((T), dapp_enc_asn_t *: dapp_dec_func_def_asn)(U, V) + +#endif diff --git a/src/sm/dapp_sm/e3/CMakeLists.txt b/src/sm/dapp_sm/e3/CMakeLists.txt new file mode 100644 index 000000000..98d6b6922 --- /dev/null +++ b/src/sm/dapp_sm/e3/CMakeLists.txt @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: LicenseRef-CSSL-1.0 + +add_subdirectory(service_models/spectrum_sm/asn/defs) + +set(DAPP_E3_SRC + # Generic E3 + dapp_dec_e3.c + dapp_enc_e3.c + + # Spectrum SM + service_models/spectrum_sm/asn/decoder.c + service_models/spectrum_sm/asn/encoder.c + service_models/spectrum_sm/ir/spectrum_report.c + service_models/spectrum_sm/ir/spectrum_control.c + +) + +add_library(e3sm_obj OBJECT ${DAPP_E3_SRC}) + +target_include_directories(e3sm_obj PUBLIC + # Spectrum SM + ${CMAKE_CURRENT_SOURCE_DIR}/service_models/spectrum_sm/asn + ${CMAKE_CURRENT_SOURCE_DIR}/service_models/spectrum_sm/asn/defs/compiled_output + ${CMAKE_CURRENT_SOURCE_DIR}/service_models/spectrum_sm/ir +) + +target_compile_options(e3sm_obj PRIVATE -Wno-missing-field-initializers -Wno-unused-parameter -fPIC -fvisibility=hidden) + +set(DAPP_E3_IR_SRC + service_models/spectrum_sm/ir/spectrum_report.c + service_models/spectrum_sm/ir/spectrum_control.c +) + +add_library(e3sm_ir_obj OBJECT ${DAPP_E3_IR_SRC}) + +target_include_directories(e3sm_ir_obj PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/service_models/spectrum_sm/ir +) + +target_compile_options(e3sm_ir_obj PRIVATE -Wno-missing-field-initializers -Wno-unused-parameter -fPIC -fvisibility=hidden) diff --git a/src/sm/dapp_sm/e3/dapp_dec_e3.c b/src/sm/dapp_sm/e3/dapp_dec_e3.c new file mode 100644 index 000000000..d6b3d4e6d --- /dev/null +++ b/src/sm/dapp_sm/e3/dapp_dec_e3.c @@ -0,0 +1,31 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "dapp_dec_e3.h" +#include "service_models/spectrum_sm/asn/decoder.h" +#include + +bool dapp_dec_e3_indication(uint32_t ran_function_id, const uint8_t* buf, size_t len, dapp_e3_ind_payload_t* out) +{ + assert(out != NULL); + + out->type = DAPP_E3_SM_NONE; + + if (buf == NULL || len == 0) + return false; + + switch (ran_function_id) { + case 1: // RAN Function ID 1 -> Spectrum PRB blacklist SM + out->type = DAPP_E3_SM_SPECTRUM; + if (!spectrum_sm_dec_report(buf, len, &out->u.spectrum)) { + out->type = DAPP_E3_SM_NONE; + return false; + } + return true; + + default: + // unknown or unsupported RAN function + return false; + } +} diff --git a/src/sm/dapp_sm/e3/dapp_dec_e3.h b/src/sm/dapp_sm/e3/dapp_dec_e3.h new file mode 100644 index 000000000..7c1ed20f5 --- /dev/null +++ b/src/sm/dapp_sm/e3/dapp_dec_e3.h @@ -0,0 +1,40 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef DAPP_DEC_E3_H +#define DAPP_DEC_E3_H + +#include +#include +#include +#include "../ie/dapp_data_ie.h" + +/** + * @brief Decode an E3 indication payload based on the RAN function ID. + * + * This function takes the raw ASN.1-encoded bytes received on the E3 interface + * and decodes them into a typed dapp_e3_ind_payload_t structure. + * + * Behavior: + * - Initializes @p out with type DAPP_E3_SM_NONE. + * - Returns false immediately if the input buffer is NULL or has zero length. + * - Dispatches decoding based on @p ran_function_id. + * - If decoding fails for a supported RAN function, it resets out->type to + * DAPP_E3_SM_NONE and returns false. + * - For unknown/unsupported RAN function IDs, it returns false without + * modifying @p out beyond the initial DAPP_E3_SM_NONE. + * + * @param ran_function_id RAN Function ID selecting which SM to decode. + * @param buf Pointer to raw encoded indication bytes. + * @param len Length of @p buf in bytes. + * @param out Output container for the decoded E3 payload. + * + * @return true on successful decode of a known SM, false otherwise. + */ +__attribute__((visibility("default"))) bool dapp_dec_e3_indication(uint32_t ran_function_id, + const uint8_t* buf, + size_t len, + dapp_e3_ind_payload_t* out); + +#endif diff --git a/src/sm/dapp_sm/e3/dapp_enc_e3.c b/src/sm/dapp_sm/e3/dapp_enc_e3.c new file mode 100644 index 000000000..722ab343c --- /dev/null +++ b/src/sm/dapp_sm/e3/dapp_enc_e3.c @@ -0,0 +1,44 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "dapp_enc_e3.h" + +#include +#include + +#include "service_models/spectrum_sm/asn/encoder.h" + +bool dapp_enc_e3_control(uint32_t ran_function_id, const dapp_e3_ctrl_payload_t* payload, uint8_t** out_buf, size_t* out_size) +{ + assert(out_buf != NULL); + assert(out_size != NULL); + + *out_buf = NULL; + *out_size = 0; + + if (payload == NULL) + return false; + + switch (ran_function_id) { + case 1: { // Spectrum RAN function ID + if (payload->type != DAPP_E3_SM_SPECTRUM) { + fprintf(stderr, "[DAPP][E3][ENC] Invalid spectrum payload type=%d\n", (int)payload->type); + return false; + } + + const spectrum_sm_control_t* ctrl = &payload->u.spectrum; + + if (ctrl->prb_count > 0 && ctrl->blockedPRBs == NULL) { + fprintf(stderr, "[DAPP][E3][ENC] blockedPRBs == NULL but prb_count > 0\n"); + return false; + } + + return spectrum_sm_enc_control(ctrl, out_buf, out_size); + } + + default: + fprintf(stderr, "[DAPP][E3][ENC] Unsupported ran_function_id=%u\n", ran_function_id); + return false; + } +} diff --git a/src/sm/dapp_sm/e3/dapp_enc_e3.h b/src/sm/dapp_sm/e3/dapp_enc_e3.h new file mode 100644 index 000000000..9cac4fb3e --- /dev/null +++ b/src/sm/dapp_sm/e3/dapp_enc_e3.h @@ -0,0 +1,44 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef DAPP_ENC_E3_H +#define DAPP_ENC_E3_H + +#include +#include +#include +#include "../ie/dapp_data_ie.h" + +/** + * @brief Encode an E3 control payload into a wire-format buffer. + * + * This function takes a typed DAPP E3 control payload and encodes it into + * an ASN.1 wire-format buffer, dispatching to the appropriate service-model + * encoder based on the RAN function ID. + * + * Behavior: + * - Validates @p out_buf and @p out_size, and initializes them to NULL/0. + * - Returns false immediately if @p payload is NULL. + * - Switches on @p ran_function_id. + * - For unsupported RAN function IDs, prints an error and returns false. + * + * On success: + * - *out_buf points to an allocated buffer containing the encoded bytes. + * - *out_size contains the buffer length in bytes. + * The caller is responsible for eventually freeing *out_buf according to the + * allocation semantics of the underlying encoder (typically free()). + * + * @param ran_function_id RAN Function ID. + * @param payload Typed E3 control payload to encode. + * @param out_buf Output pointer to the encoded buffer. + * @param out_size Output length of the encoded buffer in bytes. + * + * @return true if encoding succeeds, false otherwise. + */ +__attribute__((visibility("default"))) bool dapp_enc_e3_control(uint32_t ran_function_id, + const dapp_e3_ctrl_payload_t* payload, + uint8_t** out_buf, + size_t* out_size); + +#endif \ No newline at end of file diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/decoder.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/decoder.c new file mode 100644 index 000000000..b45e36e26 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/decoder.c @@ -0,0 +1,80 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "decoder.h" + +#include "defs/compiled_output/Spectrum-DAppReportData.h" +#include "defs/compiled_output/Spectrum-PRBBlacklistReport.h" +#include +#include +#include + +bool spectrum_sm_dec_report(const uint8_t* buf, size_t len, spectrum_sm_report_t* out) +{ + assert(out != NULL); + + if (buf == NULL || len == 0) + return false; + + Spectrum_DAppReportData_t asn; + memset(&asn, 0, sizeof(asn)); + + Spectrum_DAppReportData_t* asn_ref = &asn; + + // Decode APER-encoded Spectrum-Report + asn_dec_rval_t ret = aper_decode(NULL, &asn_DEF_Spectrum_DAppReportData, (void**)&asn_ref, buf, len, 0, 0); + if (ret.code != RC_OK) { + ASN_STRUCT_RESET(asn_DEF_Spectrum_DAppReportData, &asn); + return false; + } + + out->prb_count = 0; + out->prbs = NULL; + out->timestamp_ns = asn.timestamp != NULL ? (int64_t)*asn.timestamp : 0; + + if (asn.reportPayload.present != Spectrum_DAppReportPayload_PR_prbBlacklistReport + || asn.reportPayload.choice.prbBlacklistReport == NULL) { + ASN_STRUCT_RESET(asn_DEF_Spectrum_DAppReportData, &asn); + return false; + } + + const Spectrum_PRBBlacklistReport_t* rep = asn.reportPayload.choice.prbBlacklistReport; + const int n = rep->blacklistedPRBs.list.count; + if (n < 0 || n > 273) { + ASN_STRUCT_RESET(asn_DEF_Spectrum_DAppReportData, &asn); + return false; + } + + out->prb_count = (uint32_t)n; + + if (out->prb_count == 0) { + ASN_STRUCT_RESET(asn_DEF_Spectrum_DAppReportData, &asn); + return true; + } + + out->prbs = (uint16_t*)malloc((size_t)out->prb_count * sizeof(uint16_t)); + assert(out->prbs != NULL && "Memory exhausted in spectrum_sm_dec_report"); + + for (int i = 0; i < n; ++i) { + if (rep->blacklistedPRBs.list.array[i] == NULL) { + out->prbs[i] = 0; + continue; + } + + long v = *(rep->blacklistedPRBs.list.array[i]); + + if (v < 0 || v > 272) { + ASN_STRUCT_RESET(asn_DEF_Spectrum_DAppReportData, &asn); + free(out->prbs); + out->prbs = NULL; + out->prb_count = 0; + return false; + } + + out->prbs[i] = (uint16_t)v; + } + + ASN_STRUCT_RESET(asn_DEF_Spectrum_DAppReportData, &asn); + return true; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/decoder.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/decoder.h new file mode 100644 index 000000000..15deaac17 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/decoder.h @@ -0,0 +1,44 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef DAPP_E3_SPECTRUM_DECODER_H +#define DAPP_E3_SPECTRUM_DECODER_H + +#include +#include +#include +#include "../ir/spectrum_report.h" + +/** + * @brief Decode a Spectrum SM report from ASN.1 PER into IR. + * + * This function parses a PER-encoded Spectrum_Report message and fills + * a @ref spectrum_sm_report_t intermediate representation. + * + * Behavior: + * - Returns false if @p buf is NULL or @p len == 0. + * - Uses aper_decode() to decode the ASN.1 Spectrum_PRBBlacklistReport_t structure. + * - Validates prbCount (must be >= 0). + * - Sets out->prb_count from asn.prbCount. + * * If prb_count == 0, out->prbs is left NULL and the function returns true. + * - For prb_count > 0: + * * Checks that blacklistedPRBs has at least prb_count * sizeof(uint16_t) bytes. + * * Allocates out->prbs with prb_count entries. + * * Unpacks each PRB index from little-endian (low byte, high byte). + * - Resets the internal ASN.1 structure with ASN_STRUCT_RESET() before returning. + * + * Memory ownership: + * - On success with prb_count > 0, the caller owns out->prbs and must free it + * via free_spectrum_sm_report() or an equivalent helper. + * - On failure, out->prb_count is set to 0 and out->prbs is NULL. + * + * @param buf Pointer to the PER-encoded Spectrum-Report buffer. + * @param len Length of @p buf in bytes. + * @param out Output structure to be filled with decoded data. + * + * @return true on successful decode, false otherwise. + */ +bool spectrum_sm_dec_report(const uint8_t* buf, size_t len, spectrum_sm_report_t* out); + +#endif diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/CMakeLists.txt b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/CMakeLists.txt new file mode 100644 index 000000000..cb8fda975 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/CMakeLists.txt @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: LicenseRef-CSSL-1.0 + +# Generated from e3sm_spectrum.asn with +# +# asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER \ +# -fno-include-deps -fcompound-names -findirect-choice -no-gen-example \ +# -D compiled_output e3sm_spectrum.asn +# +# The output is committed, as it is for every other service model here. +# +# e3sm_spectrum.asn is a shared schema, kept byte-identical with the gNB's and +# the dApps' copies, so it declares types this side never sends (the sensing +# indication, the dApp control). asn1c generates all of them; only the report +# and xApp-control chain is compiled in here. The ASN.1 runtime those types +# need comes from e2sm_dapp_asn1_obj, which both link into dapp_sm -- this +# archive deliberately carries no second copy of it. + +set(ASN_DAPP_XAPP_SRC + compiled_output/Spectrum-PRBBlacklistReport.c + compiled_output/Spectrum-DAppReportPayload.c + compiled_output/Spectrum-DAppReportData.c + compiled_output/Spectrum-PRBBlockedControl.c + compiled_output/Spectrum-ConfigControl.c + compiled_output/Spectrum-XAppControlPayload.c + compiled_output/Spectrum-XAppControlData.c +) + +add_library(e2sm_dapp_e3_spectrum_asn1_obj STATIC ${ASN_DAPP_XAPP_SRC}) + +target_include_directories(e2sm_dapp_e3_spectrum_asn1_obj PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/compiled_output) + +target_compile_options(e2sm_dapp_e3_spectrum_asn1_obj PUBLIC "-DASN_DISABLE_OER_SUPPORT") +target_compile_options(e2sm_dapp_e3_spectrum_asn1_obj PUBLIC "-DASN_DISABLE_JER_SUPPORT") +target_compile_options(e2sm_dapp_e3_spectrum_asn1_obj PRIVATE -Wno-missing-field-initializers -Wno-unused-parameter -fPIC -fvisibility=hidden) diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ANY.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ANY.c new file mode 100644 index 000000000..3cbe1e272 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ANY.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2004-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +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, +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + OCTET_STRING_print, +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + OCTET_STRING_compare, + OCTET_STRING_copy, +#if !defined(ASN_DISABLE_BER_SUPPORT) + OCTET_STRING_decode_ber, + OCTET_STRING_encode_der, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + OCTET_STRING_decode_xer_hex, + ANY_encode_xer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + OCTET_STRING_decode_jer_hex, + ANY_encode_jer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, + 0, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + ANY_decode_uper, + ANY_encode_uper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + ANY_decode_aper, + ANY_encode_aper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_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, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + asn_generic_no_constraint + }, /* No constraints */ + 0, 0, /* No members */ + &asn_SPC_ANY_specs, +}; diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ANY.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ANY.h new file mode 100644 index 000000000..6434aab71 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ANY.h @@ -0,0 +1,86 @@ +/*- + * Copyright (c) 2004-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_TYPE_ANY_H +#define ASN_TYPE_ANY_H + +#include /* 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; + +#define ANY_free OCTET_STRING_free + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +#define ANY_print OCTET_STRING_print +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +#define ANY_compare OCTET_STRING_compare +#define ANY_copy OCTET_STRING_copy + +#define ANY_constraint asn_generic_no_constraint + +#if !defined(ASN_DISABLE_BER_SUPPORT) +#define ANY_decode_ber OCTET_STRING_decode_ber +#define ANY_encode_der OCTET_STRING_encode_der +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +#define ANY_decode_xer OCTET_STRING_decode_xer_hex +xer_type_encoder_f ANY_encode_xer; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +jer_type_decoder_f ANY_decode_jer; +jer_type_encoder_f ANY_encode_jer; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +per_type_decoder_f ANY_decode_uper; +per_type_encoder_f ANY_encode_uper; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +per_type_decoder_f ANY_decode_aper; +per_type_encoder_f ANY_encode_aper; +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +/****************************** + * 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); +ANY_t *ANY_new_fromType(asn_TYPE_descriptor_t *td, void *struct_ptr); +#if !defined(ASN_DISABLE_APER_SUPPORT) +int ANY_fromType_aper(ANY_t *st, asn_TYPE_descriptor_t *td, void *sptr); +ANY_t *ANY_new_fromType_aper(asn_TYPE_descriptor_t *td, void *sptr); +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +/* 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); +#if !defined(ASN_DISABLE_APER_SUPPORT) +int ANY_to_type_aper(ANY_t *, asn_TYPE_descriptor_t *td, void **struct_ptr); +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#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 */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ANY_aper.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ANY_aper.c new file mode 100644 index 000000000..91d727769 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ANY_aper.c @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +#undef RETURN +#define RETURN(_code) \ + do { \ + asn_dec_rval_t tmprval; \ + tmprval.code = _code; \ + tmprval.consumed = consumed_myself; \ + return tmprval; \ + } while(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_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_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; + } +} + +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, -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 = aper_put_length(po, -1, -1, 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 && aper_put_length(po, -1, -1, 0, NULL)) + ASN__ENCODE_FAILED; /* End of Message length */ + } while(size); + + ASN__ENCODED_OK(er); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ANY_xer.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ANY_xer.c new file mode 100644 index 000000000..112c21328 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ANY_xer.c @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +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); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING.c new file mode 100644 index 000000000..208ac14c7 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING.c @@ -0,0 +1,250 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* + * 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 */ +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + BIT_STRING_print, +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + BIT_STRING_compare, + BIT_STRING_copy, +#if !defined(ASN_DISABLE_BER_SUPPORT) + OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ + OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + OCTET_STRING_decode_xer_binary, + BIT_STRING_encode_xer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + OCTET_STRING_decode_jer_hex, + BIT_STRING_encode_jer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + BIT_STRING_decode_oer, + BIT_STRING_encode_oer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + BIT_STRING_decode_uper, /* Unaligned PER decoder */ + BIT_STRING_encode_uper, /* Unaligned PER encoder */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + OCTET_STRING_decode_aper, /* Aligned PER decoder */ + OCTET_STRING_encode_aper, /* Aligned PER encoder */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + BIT_STRING_random_fill, +#else + 0, +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + 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]), + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 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; +} + +/* + * Non-destructively remove the trailing 0-bits from the given bit string. + */ +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; + + (void)specs; + 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; + } +} + +int +BIT_STRING_copy(const asn_TYPE_descriptor_t *td, void **aptr, + const void *bptr) { + const asn_OCTET_STRING_specifics_t *specs = td->specifics; + BIT_STRING_t *a = (BIT_STRING_t *)*aptr; + const BIT_STRING_t *b = (const BIT_STRING_t *)bptr; + + if(!b) { + if(a) { + FREEMEM(a->buf); + FREEMEM(a); + *aptr = 0; + } + return 0; + } + + if(!a) { + a = *aptr = CALLOC(1, specs->struct_size); + if(!a) return -1; + } + + uint8_t* buf = MALLOC(b->size + 1); + if(!buf) return -1; + memcpy(buf, b->buf, b->size); + buf[b->size] = 0; + + FREEMEM(a->buf); + a->buf = buf; + a->size = b->size; + a->bits_unused = b->bits_unused; + + return 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING.h new file mode 100644 index 000000000..0b71feb7b --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING.h @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _BIT_STRING_H_ +#define _BIT_STRING_H_ + +#include /* 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; + +#define BIT_STRING_free OCTET_STRING_free + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +asn_struct_print_f BIT_STRING_print; /* Human-readable output */ +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +asn_struct_compare_f BIT_STRING_compare; +asn_struct_copy_f BIT_STRING_copy; + +asn_constr_check_f BIT_STRING_constraint; + +#if !defined(ASN_DISABLE_BER_SUPPORT) +#define BIT_STRING_decode_ber OCTET_STRING_decode_ber +#define BIT_STRING_encode_der OCTET_STRING_encode_der +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +#define BIT_STRING_decode_xer OCTET_STRING_decode_xer_binary +xer_type_encoder_f BIT_STRING_encode_xer; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +#define BIT_STRING_decode_jer OCTET_STRING_decode_jer_binary +jer_type_encoder_f BIT_STRING_encode_jer; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_OER_SUPPORT) +oer_type_decoder_f BIT_STRING_decode_oer; +oer_type_encoder_f BIT_STRING_encode_oer; +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +per_type_decoder_f BIT_STRING_decode_uper; +per_type_encoder_f BIT_STRING_encode_uper; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +#define BIT_STRING_decode_aper OCTET_STRING_decode_aper +#define BIT_STRING_encode_aper OCTET_STRING_encode_aper +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#if !defined(ASN_DISABLE_RFILL_SUPPORT) +asn_random_fill_f BIT_STRING_random_fill; +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + +const BIT_STRING_t *BIT_STRING__compactify(const BIT_STRING_t *st, BIT_STRING_t *tmp); + +#ifdef __cplusplus +} +#endif + +#endif /* _BIT_STRING_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING_print.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING_print.c new file mode 100644 index 000000000..bab1ea522 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING_print.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* + * 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("", 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; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING_rfill.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING_rfill.c new file mode 100644 index 000000000..a6e6a9544 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING_rfill.c @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +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 !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 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 { +#else + if(!constraints) constraints = &td->encoding_constraints; + { +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 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/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING_xer.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING_xer.c new file mode 100644 index 000000000..67d5cb8db --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BIT_STRING_xer.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +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; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN.c new file mode 100644 index 000000000..7075f095b --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN.c @@ -0,0 +1,157 @@ +/*- + * Copyright (c) 2003, 2005 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* + * BOOLEAN basic type description. + */ +static const ber_tlv_tag_t asn_DEF_BOOLEAN_tags[] = { + (ASN_TAG_CLASS_UNIVERSAL | (1 << 2)) +}; +asn_TYPE_operation_t asn_OP_BOOLEAN = { + BOOLEAN_free, +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + BOOLEAN_print, +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + BOOLEAN_compare, + BOOLEAN_copy, +#if !defined(ASN_DISABLE_BER_SUPPORT) + BOOLEAN_decode_ber, + BOOLEAN_encode_der, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + BOOLEAN_decode_xer, + BOOLEAN_encode_xer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + BOOLEAN_decode_jer, + BOOLEAN_encode_jer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + BOOLEAN_decode_oer, + BOOLEAN_encode_oer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + BOOLEAN_decode_uper, /* Unaligned PER decoder */ + BOOLEAN_encode_uper, /* Unaligned PER encoder */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + BOOLEAN_decode_aper, /* Aligned PER decoder */ + BOOLEAN_encode_aper, /* Aligned PER encoder */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + BOOLEAN_random_fill, +#else + 0, +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + 0 /* Use generic outmost tag fetcher */ +}; +asn_TYPE_descriptor_t asn_DEF_BOOLEAN = { + "BOOLEAN", + "BOOLEAN", + &asn_OP_BOOLEAN, + asn_DEF_BOOLEAN_tags, + sizeof(asn_DEF_BOOLEAN_tags) / sizeof(asn_DEF_BOOLEAN_tags[0]), + asn_DEF_BOOLEAN_tags, /* Same as above */ + sizeof(asn_DEF_BOOLEAN_tags) / sizeof(asn_DEF_BOOLEAN_tags[0]), + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + asn_generic_no_constraint + }, + 0, 0, /* No members */ + 0 /* No specifics */ +}; + +void +BOOLEAN_free(const asn_TYPE_descriptor_t *td, void *ptr, + enum asn_struct_free_method method) { + if(td && ptr) { + switch(method) { + case ASFM_FREE_EVERYTHING: + FREEMEM(ptr); + break; + case ASFM_FREE_UNDERLYING: + break; + case ASFM_FREE_UNDERLYING_AND_RESET: + memset(ptr, 0, sizeof(BOOLEAN_t)); + break; + } + } +} + +int +BOOLEAN_compare(const asn_TYPE_descriptor_t *td, const void *aptr, + const void *bptr) { + const BOOLEAN_t *a = aptr; + const BOOLEAN_t *b = bptr; + + (void)td; + + if(a && b) { + if(!*a == !*b) { /* TRUE can be encoded by any non-zero byte. */ + return 0; + } else if(!*a) { + return -1; + } else { + return 1; + } + } else if(!a) { + return -1; + } else { + return 1; + } +} + +int +BOOLEAN_copy(const asn_TYPE_descriptor_t *td, void **aptr, + const void *bptr) { + BOOLEAN_t *a = *aptr; + const BOOLEAN_t *b = bptr; + + (void)td; + + if(!b) { + if(a) { + FREEMEM(a); + *aptr = 0; + } + return 0; + } + + if(!a) { + a = *aptr = MALLOC(sizeof(BOOLEAN_t)); + if(!a) return -1; + } + + *a = *b; + + return 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN.h new file mode 100644 index 000000000..8b9b496b4 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN.h @@ -0,0 +1,72 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _BOOLEAN_H_ +#define _BOOLEAN_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The underlying integer may contain various values, but everything + * non-zero is capped to 0xff by the DER encoder. The BER decoder may + * yield non-zero values different from 1, beware. + */ +typedef unsigned BOOLEAN_t; + +extern asn_TYPE_descriptor_t asn_DEF_BOOLEAN; +extern asn_TYPE_operation_t asn_OP_BOOLEAN; + +asn_struct_free_f BOOLEAN_free; + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +asn_struct_print_f BOOLEAN_print; +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +asn_struct_compare_f BOOLEAN_compare; +asn_struct_copy_f BOOLEAN_copy; + +#define BOOLEAN_constraint asn_generic_no_constraint + +#if !defined(ASN_DISABLE_BER_SUPPORT) +ber_type_decoder_f BOOLEAN_decode_ber; +der_type_encoder_f BOOLEAN_encode_der; +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +xer_type_decoder_f BOOLEAN_decode_xer; +xer_type_encoder_f BOOLEAN_encode_xer; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +jer_type_decoder_f BOOLEAN_decode_jer; +jer_type_encoder_f BOOLEAN_encode_jer; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_OER_SUPPORT) +oer_type_decoder_f BOOLEAN_decode_oer; +oer_type_encoder_f BOOLEAN_encode_oer; +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +per_type_decoder_f BOOLEAN_decode_uper; +per_type_encoder_f BOOLEAN_encode_uper; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +per_type_decoder_f BOOLEAN_decode_aper; +per_type_encoder_f BOOLEAN_encode_aper; +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#if !defined(ASN_DISABLE_RFILL_SUPPORT) +asn_random_fill_f BOOLEAN_random_fill; +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + +#ifdef __cplusplus +} +#endif + +#endif /* _BOOLEAN_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN_aper.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN_aper.c new file mode 100644 index 000000000..d697cf571 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN_aper.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_dec_rval_t +BOOLEAN_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) { + asn_dec_rval_t rv; + BOOLEAN_t *st = (BOOLEAN_t *)*sptr; + + (void)opt_codec_ctx; + (void)constraints; + (void)td; + + if(!st) { + st = (BOOLEAN_t *)(*sptr = MALLOC(sizeof(*st))); + if(!st) ASN__DECODE_FAILED; + } + + /* + * Extract a single bit + */ + switch(per_get_few_bits(pd, 1)) { + case 1: + *st = 1; + break; + case 0: + *st = 0; + break; + case -1: + default: + ASN__DECODE_STARVED; + } + + ASN_DEBUG("%s decoded as %s", td->name, *st ? "TRUE" : "FALSE"); + + rv.code = RC_OK; + rv.consumed = 1; + return rv; +} + +asn_enc_rval_t +BOOLEAN_encode_aper(const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, + const void *sptr, asn_per_outp_t *po) { + const BOOLEAN_t *st = (const BOOLEAN_t *)sptr; + asn_enc_rval_t er = { 0, 0, 0 }; + + (void)constraints; + + if(!st) ASN__ENCODE_FAILED; + + if(per_put_few_bits(po, *st ? 1 : 0, 1)) + ASN__ENCODE_FAILED; + + ASN__ENCODED_OK(er); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN_print.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN_print.c new file mode 100644 index 000000000..23aaadea8 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN_print.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +int +BOOLEAN_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, + asn_app_consume_bytes_f *cb, void *app_key) { + const BOOLEAN_t *st = (const BOOLEAN_t *)sptr; + const char *buf; + size_t buflen; + + (void)td; /* Unused argument */ + (void)ilevel; /* Unused argument */ + + if(st) { + if(*st) { + buf = "TRUE"; + buflen = 4; + } else { + buf = "FALSE"; + buflen = 5; + } + } else { + buf = ""; + buflen = 8; + } + + return (cb(buf, buflen, app_key) < 0) ? -1 : 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN_rfill.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN_rfill.c new file mode 100644 index 000000000..5ec628bbf --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN_rfill.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_random_fill_result_t +BOOLEAN_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, + const asn_encoding_constraints_t *constraints, + size_t max_length) { + 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}; + BOOLEAN_t *st = *sptr; + + if(max_length == 0) return result_skipped; + + if(st == NULL) { + st = (BOOLEAN_t *)(*sptr = CALLOC(1, sizeof(*st))); + if(st == NULL) { + return result_failed; + } + } + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 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_CONSTRAINED) { + *st = asn_random_between(pc->lower_bound, pc->upper_bound); + return result_ok; + } + } +#else + if(!constraints) constraints = &td->encoding_constraints; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + + /* Simulate booleans that are sloppily set and biased. */ + switch(asn_random_between(0, 7)) { + case 0: + case 1: + case 2: + *st = 0; break; + case 3: *st = -1; break; + case 4: *st = 1; break; + case 5: *st = INT_MIN; break; + case 6: *st = INT_MAX; break; + default: + *st = asn_random_between(INT_MIN, INT_MAX); + break; + } + return result_ok; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN_xer.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN_xer.c new file mode 100644 index 000000000..7e9d8f853 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/BOOLEAN_xer.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include +#include + +/* + * Decode the chunk of XML text encoding INTEGER. + */ +static enum xer_pbd_rval +BOOLEAN__xer_body_decode(const asn_TYPE_descriptor_t *td, void *sptr, + const void *chunk_buf, size_t chunk_size) { + BOOLEAN_t *st = (BOOLEAN_t *)sptr; + const char *p = (const char *)chunk_buf; + + (void)td; + + if(chunk_size && p[0] == 0x3c /* '<' */) { + switch(xer_check_tag(chunk_buf, chunk_size, "false")) { + case XCT_BOTH: + /* "" */ + *st = 0; + break; + case XCT_UNKNOWN_BO: + if(xer_check_tag(chunk_buf, chunk_size, "true") != XCT_BOTH) + return XPBD_BROKEN_ENCODING; + /* "" */ + *st = 1; /* Or 0xff as in DER?.. */ + break; + default: + return XPBD_BROKEN_ENCODING; + } + return XPBD_BODY_CONSUMED; + } else { + return XPBD_BROKEN_ENCODING; + } +} + + +asn_dec_rval_t +BOOLEAN_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) { + return xer_decode_primitive(opt_codec_ctx, td, + sptr, sizeof(BOOLEAN_t), opt_mname, buf_ptr, size, + BOOLEAN__xer_body_decode); +} + +asn_enc_rval_t +BOOLEAN_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 BOOLEAN_t *st = (const BOOLEAN_t *)sptr; + asn_enc_rval_t er = {0, 0, 0}; + + (void)ilevel; + (void)flags; + + if(!st) ASN__ENCODE_FAILED; + + if(*st) { + ASN__CALLBACK("", 7); + } else { + ASN__CALLBACK("", 8); + } + + ASN__ENCODED_OK(er); +cb_failed: + ASN__ENCODE_FAILED; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/EXTERNAL.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/EXTERNAL.c new file mode 100644 index 000000000..885ebe5a3 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/EXTERNAL.c @@ -0,0 +1,223 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "ASN1C-UsefulInformationObjectClasses" + * found in "/opt/asn1c/share/asn1c/standard-modules/ASN1C-UsefulInformationObjectClasses.asn1" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "EXTERNAL.h" + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_type_encoding_constr_5 CC_NOTUSED = { + { APC_CONSTRAINED, 2, 2, 0, 2 } /* (0..2) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +static asn_TYPE_member_t asn_MBR_encoding_5[] = { + { ATF_NOFLAGS, 0, offsetof(struct EXTERNAL__encoding, choice.single_ASN1_type), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + +1, /* EXPLICIT tag at current level */ + &asn_DEF_ANY, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "single-ASN1-type" + }, + { ATF_NOFLAGS, 0, offsetof(struct EXTERNAL__encoding, choice.octet_aligned), + (ASN_TAG_CLASS_CONTEXT | (1 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_OCTET_STRING, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "octet-aligned" + }, + { ATF_NOFLAGS, 0, offsetof(struct EXTERNAL__encoding, choice.arbitrary), + (ASN_TAG_CLASS_CONTEXT | (2 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_BIT_STRING, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "arbitrary" + }, +}; +static const asn_TYPE_tag2member_t asn_MAP_encoding_tag2el_5[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* single-ASN1-type */ + { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* octet-aligned */ + { (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 } /* arbitrary */ +}; +static asn_CHOICE_specifics_t asn_SPC_encoding_specs_5 = { + sizeof(struct EXTERNAL__encoding), + offsetof(struct EXTERNAL__encoding, _asn_ctx), + offsetof(struct EXTERNAL__encoding, present), + sizeof(((struct EXTERNAL__encoding *)0)->present), + asn_MAP_encoding_tag2el_5, + 3, /* Count of tags in the map */ + 0, 0, + -1 /* Extensions start */ +}; +static /* Use -fall-defs-global to expose */ +asn_TYPE_descriptor_t asn_DEF_encoding_5 = { + "encoding", + "encoding", + &asn_OP_CHOICE, + 0, /* No effective tags (pointer) */ + 0, /* No effective tags (count) */ + 0, /* No tags (pointer) */ + 0, /* No tags (count) */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_type_encoding_constr_5, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + CHOICE_constraint + }, + asn_MBR_encoding_5, + 3, /* Elements count */ + &asn_SPC_encoding_specs_5 /* Additional specs */ +}; + +static asn_TYPE_member_t asn_MBR_EXTERNAL_1[] = { + { ATF_POINTER, 3, offsetof(struct EXTERNAL, direct_reference), + (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), + 0, + &asn_DEF_OBJECT_IDENTIFIER, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "direct-reference" + }, + { ATF_POINTER, 2, offsetof(struct EXTERNAL, indirect_reference), + (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), + 0, + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "indirect-reference" + }, + { ATF_POINTER, 1, offsetof(struct EXTERNAL, data_value_descriptor), + (ASN_TAG_CLASS_UNIVERSAL | (7 << 2)), + 0, + &asn_DEF_ObjectDescriptor, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "data-value-descriptor" + }, + { ATF_NOFLAGS, 0, offsetof(struct EXTERNAL, encoding), + -1 /* Ambiguous tag (CHOICE?) */, + 0, + &asn_DEF_encoding_5, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "encoding" + }, +}; +static const int asn_MAP_EXTERNAL_oms_1[] = { 0, 1, 2 }; +static const ber_tlv_tag_t asn_DEF_EXTERNAL_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (8 << 2)), + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static const asn_TYPE_tag2member_t asn_MAP_EXTERNAL_tag2el_1[] = { + { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 1, 0, 0 }, /* indirect-reference */ + { (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), 0, 0, 0 }, /* direct-reference */ + { (ASN_TAG_CLASS_UNIVERSAL | (7 << 2)), 2, 0, 0 }, /* data-value-descriptor */ + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 3, 0, 0 }, /* single-ASN1-type */ + { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 3, 0, 0 }, /* octet-aligned */ + { (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 3, 0, 0 } /* arbitrary */ +}; +static asn_SEQUENCE_specifics_t asn_SPC_EXTERNAL_specs_1 = { + sizeof(struct EXTERNAL), + offsetof(struct EXTERNAL, _asn_ctx), + asn_MAP_EXTERNAL_tag2el_1, + 6, /* Count of tags in the map */ + asn_MAP_EXTERNAL_oms_1, /* Optional members */ + 3, 0, /* Root/Additions */ + -1, /* First extension addition */ +}; +asn_TYPE_descriptor_t asn_DEF_EXTERNAL = { + "EXTERNAL", + "EXTERNAL", + &asn_OP_SEQUENCE, + asn_DEF_EXTERNAL_tags_1, + sizeof(asn_DEF_EXTERNAL_tags_1) + /sizeof(asn_DEF_EXTERNAL_tags_1[0]) - 1, /* 1 */ + asn_DEF_EXTERNAL_tags_1, /* Same as above */ + sizeof(asn_DEF_EXTERNAL_tags_1) + /sizeof(asn_DEF_EXTERNAL_tags_1[0]), /* 2 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_constraint + }, + asn_MBR_EXTERNAL_1, + 4, /* Elements count */ + &asn_SPC_EXTERNAL_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/EXTERNAL.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/EXTERNAL.h new file mode 100644 index 000000000..f1096ebb9 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/EXTERNAL.h @@ -0,0 +1,65 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "ASN1C-UsefulInformationObjectClasses" + * found in "/opt/asn1c/share/asn1c/standard-modules/ASN1C-UsefulInformationObjectClasses.asn1" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _EXTERNAL_H_ +#define _EXTERNAL_H_ + + +#include + +/* Including external dependencies */ +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum EXTERNAL__encoding_PR { + EXTERNAL__encoding_PR_NOTHING, /* No components present */ + EXTERNAL__encoding_PR_single_ASN1_type, + EXTERNAL__encoding_PR_octet_aligned, + EXTERNAL__encoding_PR_arbitrary +} EXTERNAL__encoding_PR; + +/* EXTERNAL */ +typedef struct EXTERNAL { + OBJECT_IDENTIFIER_t *direct_reference; /* OPTIONAL */ + long *indirect_reference; /* OPTIONAL */ + ObjectDescriptor_t *data_value_descriptor; /* OPTIONAL */ + struct EXTERNAL__encoding { + EXTERNAL__encoding_PR present; + union EXTERNAL__encoding_u { + ANY_t single_ASN1_type; + OCTET_STRING_t octet_aligned; + BIT_STRING_t arbitrary; + } choice; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; + } encoding; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} EXTERNAL_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_EXTERNAL; + +#ifdef __cplusplus +} +#endif + +#endif /* _EXTERNAL_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/GraphicString.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/GraphicString.c new file mode 100644 index 000000000..0f2fc39ba --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/GraphicString.c @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 2003 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* + * GraphicString basic type description. + */ +static const ber_tlv_tag_t asn_DEF_GraphicString_tags[] = { + (ASN_TAG_CLASS_UNIVERSAL | (25 << 2)), /* [UNIVERSAL 25] IMPLICIT ...*/ + (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ +}; +asn_TYPE_operation_t asn_OP_GraphicString = { + OCTET_STRING_free, +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + OCTET_STRING_print, /* non-ascii string */ +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + OCTET_STRING_compare, + OCTET_STRING_copy, +#if !defined(ASN_DISABLE_BER_SUPPORT) + OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ + OCTET_STRING_encode_der, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + OCTET_STRING_decode_xer_hex, + OCTET_STRING_encode_xer, /* Can't expect it to be ASCII/UTF8 */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + OCTET_STRING_decode_jer_hex, + OCTET_STRING_encode_jer, /* Can't expect it to be ASCII/UTF8 */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + OCTET_STRING_decode_oer, + OCTET_STRING_encode_oer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + OCTET_STRING_decode_uper, /* Implemented in terms of OCTET STRING */ + OCTET_STRING_encode_uper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + OCTET_STRING_decode_aper, /* Implemented in terms of OCTET STRING */ + OCTET_STRING_encode_aper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + OCTET_STRING_random_fill, +#else + 0, +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + 0 /* Use generic outmost tag fetcher */ +}; +asn_TYPE_descriptor_t asn_DEF_GraphicString = { + "GraphicString", + "GraphicString", + &asn_OP_GraphicString, + asn_DEF_GraphicString_tags, + sizeof(asn_DEF_GraphicString_tags) + / sizeof(asn_DEF_GraphicString_tags[0]) - 1, + asn_DEF_GraphicString_tags, + sizeof(asn_DEF_GraphicString_tags) + / sizeof(asn_DEF_GraphicString_tags[0]), + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + asn_generic_unknown_constraint + }, + 0, 0, /* No members */ + 0 /* No specifics */ +}; diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/GraphicString.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/GraphicString.h new file mode 100644 index 000000000..9368e507b --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/GraphicString.h @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _GraphicString_H_ +#define _GraphicString_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef OCTET_STRING_t GraphicString_t; /* Implemented via OCTET STRING */ + +extern asn_TYPE_descriptor_t asn_DEF_GraphicString; +extern asn_TYPE_operation_t asn_OP_GraphicString; + +#define GraphicString_free OCTET_STRING_free + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +#define GraphicString_print OCTET_STRING_print +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +#define GraphicString_compare OCTET_STRING_compare +#define GraphicString_copy OCTET_STRING_copy + +#define GraphicString_constraint asn_generic_unknown_constraint + +#if !defined(ASN_DISABLE_BER_SUPPORT) +#define GraphicString_decode_ber OCTET_STRING_decode_ber +#define GraphicString_encode_der OCTET_STRING_encode_der +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +#define GraphicString_decode_xer OCTET_STRING_decode_xer_hex +#define GraphicString_encode_xer OCTET_STRING_encode_xer +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +#define GraphicString_decode_jer OCTET_STRING_decode_jer +#define GraphicString_encode_jer OCTET_STRING_encode_jer +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +#define GraphicString_decode_uper OCTET_STRING_decode_uper +#define GraphicString_encode_uper OCTET_STRING_encode_uper +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +#define GraphicString_decode_aper OCTET_STRING_decode_aper +#define GraphicString_encode_aper OCTET_STRING_encode_aper +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#ifdef __cplusplus +} +#endif + +#endif /* _GraphicString_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER.c new file mode 100644 index 000000000..e81cfb280 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER.c @@ -0,0 +1,805 @@ +/* + * Copyright (c) 2003-2019 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include +#include + +/* + * INTEGER basic type description. + */ +static const ber_tlv_tag_t asn_DEF_INTEGER_tags[] = { + (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)) +}; +asn_TYPE_operation_t asn_OP_INTEGER = { + INTEGER_free, +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + INTEGER_print, +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + INTEGER_compare, + INTEGER_copy, +#if !defined(ASN_DISABLE_BER_SUPPORT) + ber_decode_primitive, + INTEGER_encode_der, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + INTEGER_decode_xer, + INTEGER_encode_xer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + INTEGER_decode_jer, + INTEGER_encode_jer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + INTEGER_decode_oer, /* OER decoder */ + INTEGER_encode_oer, /* Canonical OER encoder */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + INTEGER_decode_uper, /* Unaligned PER decoder */ + INTEGER_encode_uper, /* Unaligned PER encoder */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + INTEGER_decode_aper, /* Aligned PER decoder */ + INTEGER_encode_aper, /* Aligned PER encoder */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + INTEGER_random_fill, +#else + 0, +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ +0 /* Use generic outmost tag fetcher */ +}; +asn_TYPE_descriptor_t asn_DEF_INTEGER = { + "INTEGER", + "INTEGER", + &asn_OP_INTEGER, + asn_DEF_INTEGER_tags, + sizeof(asn_DEF_INTEGER_tags) / sizeof(asn_DEF_INTEGER_tags[0]), + asn_DEF_INTEGER_tags, /* Same as above */ + sizeof(asn_DEF_INTEGER_tags) / sizeof(asn_DEF_INTEGER_tags[0]), + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + asn_generic_no_constraint + }, + 0, 0, /* No members */ + 0 /* No specifics */ +}; + +/* + * INTEGER specific human-readable output. + */ +ssize_t +INTEGER__dump(const asn_TYPE_descriptor_t *td, const INTEGER_t *st, asn_app_consume_bytes_f *cb, void *app_key, int plainOrXER) { + const asn_INTEGER_specifics_t *specs = + (const asn_INTEGER_specifics_t *)td->specifics; + char scratch[32]; + uint8_t *buf = st->buf; + uint8_t *buf_end = st->buf + st->size; + intmax_t value = 0; + ssize_t wrote = 0; + char *p = NULL; + int ret = -1; + + if(specs && specs->field_unsigned) + ret = asn_INTEGER2umax(st, (uintmax_t *)&value); + else + ret = asn_INTEGER2imax(st, &value); + + /* Simple case: the integer size is small */ + if(ret == 0) { + const asn_INTEGER_enum_map_t *el; + el = (value >= 0 || !specs || !specs->field_unsigned) + ? INTEGER_map_value2enum(specs, value) : 0; + if(el) { + if(plainOrXER == 0) + return asn__format_to_callback(cb, app_key, + "%" ASN_PRIdMAX " (%s)", value, el->enum_name); + else + return asn__format_to_callback(cb, app_key, + "<%s/>", el->enum_name); + } else if(plainOrXER && specs && specs->strict_enumeration) { + ASN_DEBUG("ASN.1 forbids dealing with " + "unknown value of ENUMERATED type"); + errno = EPERM; + return -1; + } else { + return asn__format_to_callback(cb, app_key, + (specs && specs->field_unsigned) + ? "%" ASN_PRIuMAX + : "%" ASN_PRIdMAX, + value); + } + } else if(plainOrXER && specs && specs->strict_enumeration) { + /* + * Here and earlier, we cannot encode the ENUMERATED values + * if there is no corresponding identifier. + */ + ASN_DEBUG("ASN.1 forbids dealing with " + "unknown value of ENUMERATED type"); + errno = EPERM; + return -1; + } + + /* Output in the long xx:yy:zz... format */ + /* TODO: replace with generic algorithm (Knuth TAOCP Vol 2, 4.3.1) */ + for(p = scratch; buf < buf_end; buf++) { + const char * const h2c = "0123456789ABCDEF"; + if((p - scratch) >= (ssize_t)(sizeof(scratch) - 4)) { + /* Flush buffer */ + if(cb(scratch, p - scratch, app_key) < 0) + return -1; + wrote += p - scratch; + p = scratch; + } + *p++ = h2c[*buf >> 4]; + *p++ = h2c[*buf & 0x0F]; + *p++ = 0x3a; /* ":" */ + } + if(p != scratch) + p--; /* Remove the last ":" */ + + wrote += p - scratch; + return (cb(scratch, p - scratch, app_key) < 0) ? -1 : wrote; +} + +static int +INTEGER__compar_value2enum(const void *kp, const void *am) { + long a = *(const long *)kp; + const asn_INTEGER_enum_map_t *el = (const asn_INTEGER_enum_map_t *)am; + long b = el->nat_value; + if(a < b) return -1; + else if(a == b) return 0; + else return 1; +} + +const asn_INTEGER_enum_map_t * +INTEGER_map_value2enum(const asn_INTEGER_specifics_t *specs, long value) { + int count = specs ? specs->map_count : 0; + if(!count) return 0; + return (asn_INTEGER_enum_map_t *)bsearch(&value, specs->value2enum, + count, sizeof(specs->value2enum[0]), + INTEGER__compar_value2enum); +} + +static intmax_t +asn__integer_convert(const uint8_t *b, const uint8_t *end) { + uintmax_t value; + + /* Perform the sign initialization */ + /* Actually value = -(*b >> 7); gains nothing, yet unreadable! */ + if((*b >> 7)) { + value = (uintmax_t)(-1); + } else { + value = 0; + } + + /* Conversion engine */ + for(; b < end; b++) { + value = (value << 8) | *b; + } + + return value; +} + +int +asn_INTEGER2imax(const INTEGER_t *iptr, intmax_t *lptr) { + uint8_t *b, *end; + size_t size = 0; + + /* Sanity checking */ + if(!iptr || !iptr->buf || !lptr) { + errno = EINVAL; + return -1; + } + + /* Cache the begin/end of the buffer */ + b = iptr->buf; /* Start of the INTEGER buffer */ + size = iptr->size; + end = b + size; /* Where to stop */ + + if(size > sizeof(intmax_t)) { + uint8_t *end1 = end - 1; + /* + * Slightly more advanced processing, + * able to process INTEGERs with >sizeof(intmax_t) bytes + * when the actual value is small, e.g. for intmax_t == int32_t + * (0x0000000000abcdef INTEGER would yield a fine 0x00abcdef int32_t) + */ + /* Skip out the insignificant leading bytes */ + for(; b < end1; b++) { + switch(*b) { + case 0x00: if((b[1] & 0x80) == 0) continue; break; + case 0xff: if((b[1] & 0x80) != 0) continue; break; + } + break; + } + + size = end - b; + if(size > sizeof(intmax_t)) { + /* Still cannot fit the sizeof(intmax_t) */ + errno = ERANGE; + return -1; + } + } + + /* Shortcut processing of a corner case */ + if(end == b) { + *lptr = 0; + return 0; + } + + *lptr = asn__integer_convert(b, end); + return 0; +} + +/* FIXME: negative INTEGER values are silently interpreted as large unsigned ones. */ +int +asn_INTEGER2umax(const INTEGER_t *iptr, uintmax_t *lptr) { + uint8_t *b, *end; + uintmax_t value; + size_t size; + + if(!iptr || !iptr->buf || !lptr) { + errno = EINVAL; + return -1; + } + + b = iptr->buf; + size = iptr->size; + end = b + size; + + /* If all extra leading bytes are zeroes, ignore them */ + for(; size > sizeof(value); b++, size--) { + if(*b) { + /* Value won't fit into uintmax_t */ + errno = ERANGE; + return -1; + } + } + + /* Conversion engine */ + for(value = 0; b < end; b++) + value = (value << 8) | *b; + + *lptr = value; + return 0; +} + +int +asn_umax2INTEGER(INTEGER_t *st, uintmax_t value) { + uint8_t *buf; + uint8_t *end; + uint8_t *b; + int shr; + + if(value <= ((~(uintmax_t)0) >> 1)) { + return asn_imax2INTEGER(st, value); + } + + buf = (uint8_t *)MALLOC(1 + sizeof(value)); + if(!buf) return -1; + + end = buf + (sizeof(value) + 1); + buf[0] = 0; /* INTEGERs are signed. 0-byte indicates positive. */ + for(b = buf + 1, shr = (sizeof(value) - 1) * 8; b < end; shr -= 8, b++) + *b = (uint8_t)(value >> shr); + + if(st->buf) FREEMEM(st->buf); + st->buf = buf; + st->size = 1 + sizeof(value); + + return 0; +} + +int +asn_imax2INTEGER(INTEGER_t *st, intmax_t value) { + uint8_t *buf, *bp; + volatile uint8_t *p; + volatile uint8_t *pstart; + volatile uint8_t *pend1; + int littleEndian = 1; /* Run-time detection */ + volatile int add; + + if(!st) { + errno = EINVAL; + return -1; + } + + buf = (uint8_t *)(long *)MALLOC(sizeof(value)); + if(!buf) return -1; + + if(*(char *)&littleEndian) { + pstart = (uint8_t *)&value + sizeof(value) - 1; + pend1 = (uint8_t *)&value; + add = -1; + } else { + pstart = (uint8_t *)&value; + pend1 = pstart + sizeof(value) - 1; + add = 1; + } + + /* + * If the contents octet consists of more than one octet, + * then bits of the first octet and bit 8 of the second octet: + * a) shall not all be ones; and + * b) shall not all be zero. + */ + for(p = pstart; p != pend1; p += add) { + switch(*p) { + case 0x00: if((*(p+add) & 0x80) == 0) + continue; + break; + case 0xff: if((*(p+add) & 0x80)) + continue; + break; + } + break; + } + /* Copy the integer body */ + for(bp = buf, pend1 += add; p != pend1; p += add) + *bp++ = *p; + + if(st->buf) FREEMEM(st->buf); + st->buf = buf; + st->size = bp - buf; + + return 0; +} + +int +asn_INTEGER2long(const INTEGER_t *iptr, long *l) { + intmax_t v; + if(asn_INTEGER2imax(iptr, &v) == 0) { + if(v < LONG_MIN || v > LONG_MAX) { + errno = ERANGE; + return -1; + } + *l = v; + return 0; + } else { + return -1; + } +} + +int +asn_INTEGER2ulong(const INTEGER_t *iptr, unsigned long *l) { + uintmax_t v; + if(asn_INTEGER2umax(iptr, &v) == 0) { + if(v > ULONG_MAX) { + errno = ERANGE; + return -1; + } + *l = v; + return 0; + } else { + return -1; + } +} + +int +asn_long2INTEGER(INTEGER_t *st, long value) { + return asn_imax2INTEGER(st, value); +} + +int +asn_ulong2INTEGER(INTEGER_t *st, unsigned long value) { + return asn_imax2INTEGER(st, value); +} + +int asn_INTEGER2int64(const INTEGER_t *st, int64_t *value) { + intmax_t v; + if(asn_INTEGER2imax(st, &v) == 0) { + if(v < INT64_MIN || v > INT64_MAX) { + errno = ERANGE; + return -1; + } + *value = v; + return 0; + } else { + return -1; + } +} + +int asn_INTEGER2uint64(const INTEGER_t *st, uint64_t *value) { + uintmax_t v; + if(asn_INTEGER2umax(st, &v) == 0) { + if(v > UINT64_MAX) { + errno = ERANGE; + return -1; + } + *value = v; + return 0; + } else { + return -1; + } +} + +int +asn_uint642INTEGER(INTEGER_t *st, uint64_t value) { + uint8_t *buf; + uint8_t *end; + uint8_t *b; + int shr; + + if(value <= INT64_MAX) + return asn_int642INTEGER(st, value); + + buf = (uint8_t *)MALLOC(1 + sizeof(value)); + if(!buf) return -1; + + end = buf + (sizeof(value) + 1); + buf[0] = 0; + for(b = buf + 1, shr = (sizeof(value)-1)*8; b < end; shr -= 8, b++) + *b = (uint8_t)(value >> shr); + + if(st->buf) FREEMEM(st->buf); + st->buf = buf; + st->size = 1 + sizeof(value); + + return 0; +} + +int +asn_int642INTEGER(INTEGER_t *st, int64_t value) { + uint8_t *buf, *bp; + volatile uint8_t *p; + volatile uint8_t *pstart; + volatile uint8_t *pend1; + int littleEndian = 1; /* Run-time detection */ + volatile int add; + + if(!st) { + errno = EINVAL; + return -1; + } + + buf = (uint8_t *)MALLOC(sizeof(value)); + if(!buf) return -1; + + if(*(char *)&littleEndian) { + pstart = (uint8_t *)&value + sizeof(value) - 1; + pend1 = (uint8_t *)&value; + add = -1; + } else { + pstart = (uint8_t *)&value; + pend1 = pstart + sizeof(value) - 1; + add = 1; + } + + /* + * If the contents octet consists of more than one octet, + * then bits of the first octet and bit 8 of the second octet: + * a) shall not all be ones; and + * b) shall not all be zero. + */ + for(p = pstart; p != pend1; p += add) { + switch(*p) { + case 0x00: if((*(p+add) & 0x80) == 0) + continue; + break; + case 0xff: if((*(p+add) & 0x80)) + continue; + break; + } + break; + } + /* Copy the integer body */ + for(pstart = p, bp = buf, pend1 += add; p != pend1; p += add) + *bp++ = *p; + + if(st->buf) FREEMEM(st->buf); + st->buf = buf; + st->size = bp - buf; + + return 0; +} + +/* + * Parse the number in the given string until the given *end position, + * returning the position after the last parsed character back using the + * same (*end) pointer. + * WARNING: This behavior is different from the standard strtol/strtoimax(3). + */ +enum asn_strtox_result_e +asn_strtoimax_lim(const char *str, const char **end, intmax_t *intp) { + int sign = 1; + intmax_t value; + + const intmax_t asn1_intmax_max = ((~(uintmax_t)0) >> 1); + const intmax_t upper_boundary = asn1_intmax_max / 10; + intmax_t last_digit_max = asn1_intmax_max % 10; + + if(str >= *end) return ASN_STRTOX_ERROR_INVAL; + + switch(*str) { + case '-': + last_digit_max++; + sign = -1; + /* FALL THROUGH */ + case '+': + str++; + if(str >= *end) { + *end = str; + return ASN_STRTOX_EXPECT_MORE; + } + } + + for(value = 0; str < (*end); str++) { + if(*str >= 0x30 && *str <= 0x39) { + int d = *str - '0'; + if(value < upper_boundary) { + value = value * 10 + d; + } else if(value == upper_boundary) { + if(d <= last_digit_max) { + if(sign > 0) { + value = value * 10 + d; + } else { + sign = 1; + value = -value * 10 - d; + } + str += 1; + if(str < *end) { + // If digits continue, we're guaranteed out of range. + *end = str; + if(*str >= 0x30 && *str <= 0x39) { + return ASN_STRTOX_ERROR_RANGE; + } else { + *intp = sign * value; + return ASN_STRTOX_EXTRA_DATA; + } + } + break; + } else { + *end = str; + return ASN_STRTOX_ERROR_RANGE; + } + } else { + *end = str; + return ASN_STRTOX_ERROR_RANGE; + } + } else { + *end = str; + *intp = sign * value; + return ASN_STRTOX_EXTRA_DATA; + } + } + + *end = str; + *intp = sign * value; + return ASN_STRTOX_OK; +} + +/* + * Parse the number in the given string until the given *end position, + * returning the position after the last parsed character back using the + * same (*end) pointer. + * WARNING: This behavior is different from the standard strtoul/strtoumax(3). + */ +enum asn_strtox_result_e +asn_strtoumax_lim(const char *str, const char **end, uintmax_t *uintp) { + uintmax_t value; + + const uintmax_t asn1_uintmax_max = ((~(uintmax_t)0)); + const uintmax_t upper_boundary = asn1_uintmax_max / 10; + uintmax_t last_digit_max = asn1_uintmax_max % 10; + + if(str >= *end) return ASN_STRTOX_ERROR_INVAL; + + switch(*str) { + case '-': + return ASN_STRTOX_ERROR_INVAL; + case '+': + str++; + if(str >= *end) { + *end = str; + return ASN_STRTOX_EXPECT_MORE; + } + } + + for(value = 0; str < (*end); str++) { + if(*str >= 0x30 && *str <= 0x39) { + unsigned int d = *str - '0'; + if(value < upper_boundary) { + value = value * 10 + d; + } else if(value == upper_boundary) { + if(d <= last_digit_max) { + value = value * 10 + d; + str += 1; + if(str < *end) { + // If digits continue, we're guaranteed out of range. + *end = str; + if(*str >= 0x30 && *str <= 0x39) { + return ASN_STRTOX_ERROR_RANGE; + } else { + *uintp = value; + return ASN_STRTOX_EXTRA_DATA; + } + } + break; + } else { + *end = str; + return ASN_STRTOX_ERROR_RANGE; + } + } else { + *end = str; + return ASN_STRTOX_ERROR_RANGE; + } + } else { + *end = str; + *uintp = value; + return ASN_STRTOX_EXTRA_DATA; + } + } + + *end = str; + *uintp = value; + return ASN_STRTOX_OK; +} + +enum asn_strtox_result_e +asn_strtol_lim(const char *str, const char **end, long *lp) { + intmax_t value; + switch(asn_strtoimax_lim(str, end, &value)) { + case ASN_STRTOX_ERROR_RANGE: + return ASN_STRTOX_ERROR_RANGE; + case ASN_STRTOX_ERROR_INVAL: + return ASN_STRTOX_ERROR_INVAL; + case ASN_STRTOX_EXPECT_MORE: + return ASN_STRTOX_EXPECT_MORE; + case ASN_STRTOX_OK: + if(value >= LONG_MIN && value <= LONG_MAX) { + *lp = value; + return ASN_STRTOX_OK; + } else { + return ASN_STRTOX_ERROR_RANGE; + } + case ASN_STRTOX_EXTRA_DATA: + if(value >= LONG_MIN && value <= LONG_MAX) { + *lp = value; + return ASN_STRTOX_EXTRA_DATA; + } else { + return ASN_STRTOX_ERROR_RANGE; + } + } + + assert(!"Unreachable"); + return ASN_STRTOX_ERROR_INVAL; +} + +enum asn_strtox_result_e +asn_strtoul_lim(const char *str, const char **end, unsigned long *ulp) { + uintmax_t value; + switch(asn_strtoumax_lim(str, end, &value)) { + case ASN_STRTOX_ERROR_RANGE: + return ASN_STRTOX_ERROR_RANGE; + case ASN_STRTOX_ERROR_INVAL: + return ASN_STRTOX_ERROR_INVAL; + case ASN_STRTOX_EXPECT_MORE: + return ASN_STRTOX_EXPECT_MORE; + case ASN_STRTOX_OK: + if(value <= ULONG_MAX) { + *ulp = value; + return ASN_STRTOX_OK; + } else { + return ASN_STRTOX_ERROR_RANGE; + } + case ASN_STRTOX_EXTRA_DATA: + if(value <= ULONG_MAX) { + *ulp = value; + return ASN_STRTOX_EXTRA_DATA; + } else { + return ASN_STRTOX_ERROR_RANGE; + } + } + + assert(!"Unreachable"); + return ASN_STRTOX_ERROR_INVAL; +} + +int +INTEGER_compare(const asn_TYPE_descriptor_t *td, const void *aptr, + const void *bptr) { + const INTEGER_t *a = aptr; + const INTEGER_t *b = bptr; + + (void)td; + + if(a && b) { + if(a->size && b->size) { + int sign_a = (a->buf[0] & 0x80) ? -1 : 1; + int sign_b = (b->buf[0] & 0x80) ? -1 : 1; + + if(sign_a < sign_b) return -1; + if(sign_a > sign_b) return 1; + + /* The shortest integer wins, unless comparing negatives */ + if(a->size < b->size) { + return -1 * sign_a; + } else if(a->size > b->size) { + return 1 * sign_b; + } + + return sign_a * memcmp(a->buf, b->buf, a->size); + } else if(a->size) { + int sign = (a->buf[0] & 0x80) ? -1 : 1; + return (1) * sign; + } else if(b->size) { + int sign = (a->buf[0] & 0x80) ? -1 : 1; + return (-1) * sign; + } else { + return 0; + } + } else if(!a && !b) { + return 0; + } else if(!a) { + return -1; + } else { + return 1; + } + +} + +int +INTEGER_copy(const asn_TYPE_descriptor_t *td, void **aptr, + const void *bptr) { + (void)td; + INTEGER_t *a = *aptr; + const INTEGER_t *b = bptr; + + if(!b) { + if(a) { + FREEMEM(a->buf); + FREEMEM(a); + *aptr = 0; + } + return 0; + } + + if(!a) { + a = *aptr = CALLOC(1, sizeof(*a)); + if(!a) return -1; + } + + if(b->size) { + uint8_t* buf = MALLOC(b->size); + if(!buf) return -1; + memcpy(buf, b->buf, b->size); + FREEMEM(a->buf); + a->buf = buf; + a->size = b->size; + } else { + FREEMEM(a->buf); + a->buf = 0; + a->size = 0; + } + + return 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER.h new file mode 100644 index 000000000..5fa1c7b8d --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER.h @@ -0,0 +1,143 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _INTEGER_H_ +#define _INTEGER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef ASN__PRIMITIVE_TYPE_t INTEGER_t; + +extern asn_TYPE_descriptor_t asn_DEF_INTEGER; +extern asn_TYPE_operation_t asn_OP_INTEGER; + +/* Map with to integer value association */ +typedef struct asn_INTEGER_enum_map_s { + long nat_value; /* associated native integer value */ + size_t enum_len; /* strlen("tag") */ + const char *enum_name; /* "tag" */ +} asn_INTEGER_enum_map_t; + +/* This type describes an enumeration for INTEGER and ENUMERATED types */ +typedef struct asn_INTEGER_specifics_s { + const asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */ + const unsigned int *enum2value; /* "tag" => N; sorted by tag */ + int map_count; /* Elements in either map */ + int extension; /* This map is extensible */ + int strict_enumeration; /* Enumeration set is fixed */ + int field_width; /* Size of native integer */ + int field_unsigned; /* Signed=0, unsigned=1 */ +} asn_INTEGER_specifics_t; + +ssize_t INTEGER__dump(const asn_TYPE_descriptor_t *td, + const INTEGER_t *st, + asn_app_consume_bytes_f *cb, + void *app_key, int plainOrXER); + +#define INTEGER_free ASN__PRIMITIVE_TYPE_free + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +asn_struct_print_f INTEGER_print; +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +asn_struct_compare_f INTEGER_compare; +asn_struct_copy_f INTEGER_copy; + +#define INTEGER_constraint asn_generic_no_constraint + +#if !defined(ASN_DISABLE_BER_SUPPORT) +#define INTEGER_decode_ber ber_decode_primitive +der_type_encoder_f INTEGER_encode_der; +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +xer_type_decoder_f INTEGER_decode_xer; +xer_type_encoder_f INTEGER_encode_xer; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +jer_type_decoder_f INTEGER_decode_jer; +jer_type_encoder_f INTEGER_encode_jer; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_OER_SUPPORT) +oer_type_decoder_f INTEGER_decode_oer; +oer_type_encoder_f INTEGER_encode_oer; +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +per_type_decoder_f INTEGER_decode_uper; +per_type_encoder_f INTEGER_encode_uper; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +per_type_decoder_f INTEGER_decode_aper; +per_type_encoder_f INTEGER_encode_aper; +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#if !defined(ASN_DISABLE_RFILL_SUPPORT) +asn_random_fill_f INTEGER_random_fill; +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + +/*********************************** + * Some handy conversion routines. * + ***********************************/ + +/* + * Natiwe size-independent conversion of native integers to/from INTEGER. + * (l_size) is in bytes. + * Returns 0 if it was possible to convert, -1 otherwise. + * -1/EINVAL: Mandatory argument missing + * -1/ERANGE: Value encoded is out of range for long representation + * -1/ENOMEM: Memory allocation failed (in asn_*2INTEGER()). + */ +int asn_INTEGER2imax(const INTEGER_t *i, intmax_t *l); +int asn_INTEGER2umax(const INTEGER_t *i, uintmax_t *l); +int asn_imax2INTEGER(INTEGER_t *i, intmax_t l); +int asn_umax2INTEGER(INTEGER_t *i, uintmax_t l); + +/* + * Size-specific conversion helpers. + */ +int asn_INTEGER2long(const INTEGER_t *i, long *l); +int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l); +int asn_long2INTEGER(INTEGER_t *i, long l); +int asn_ulong2INTEGER(INTEGER_t *i, unsigned long l); +int asn_INTEGER2int64(const INTEGER_t *i, int64_t *l); +int asn_INTEGER2uint64(const INTEGER_t *i, uint64_t *l); +int asn_int642INTEGER(INTEGER_t *i, int64_t l); +int asn_uint642INTEGER(INTEGER_t *i, uint64_t l); + +/* A version of strtol/strtoimax(3) with nicer error reporting. */ +enum asn_strtox_result_e { + ASN_STRTOX_ERROR_RANGE = -3, /* Input outside of supported numeric range */ + ASN_STRTOX_ERROR_INVAL = -2, /* Invalid data encountered (e.g., "+-") */ + ASN_STRTOX_EXPECT_MORE = -1, /* More data expected (e.g. "+") */ + ASN_STRTOX_OK = 0, /* Conversion succeeded, number ends at (*end) */ + ASN_STRTOX_EXTRA_DATA = 1 /* Conversion succeeded, but the string has extra stuff */ +}; +enum asn_strtox_result_e asn_strtol_lim(const char *str, const char **end, + long *l); +enum asn_strtox_result_e asn_strtoul_lim(const char *str, const char **end, + unsigned long *l); +enum asn_strtox_result_e asn_strtoimax_lim(const char *str, const char **end, + intmax_t *l); +enum asn_strtox_result_e asn_strtoumax_lim(const char *str, const char **end, + uintmax_t *l); + +/* + * Convert the integer value into the corresponding enumeration map entry. + */ +const asn_INTEGER_enum_map_t *INTEGER_map_value2enum( + const asn_INTEGER_specifics_t *specs, long value); + +#ifdef __cplusplus +} +#endif + +#endif /* _INTEGER_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER_aper.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER_aper.c new file mode 100644 index 000000000..2bfa96fb8 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER_aper.c @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_dec_rval_t +INTEGER_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_INTEGER_specifics_t *specs = (const asn_INTEGER_specifics_t *)td->specifics; + asn_dec_rval_t rval = { RC_OK, 0 }; + INTEGER_t *st = (INTEGER_t *)*sptr; + const asn_per_constraint_t *ct; + int repeat; + + (void)opt_codec_ctx; + + if(!st) { + st = (INTEGER_t *)(*sptr = CALLOC(1, sizeof(*st))); + if(!st) ASN__DECODE_FAILED; + } + + if(!constraints) constraints = td->encoding_constraints.per_constraints; + ct = constraints ? &constraints->value : 0; + + if(ct && ct->flags & APC_EXTENSIBLE) { + int inext = per_get_few_bits(pd, 1); + if(inext < 0) ASN__DECODE_STARVED; + if(inext) ct = 0; + } + + FREEMEM(st->buf); + st->buf = 0; + st->size = 0; + if(ct) { + if(ct->flags & APC_SEMI_CONSTRAINED) { + st->buf = (uint8_t *)CALLOC(1, 2); + if(!st->buf) ASN__DECODE_FAILED; + st->size = 1; + } else if(ct->flags & APC_CONSTRAINED && ct->range_bits >= 0) { + size_t size = (ct->range_bits + 7) >> 3; + st->buf = (uint8_t *)MALLOC(1 + size + 1); + if(!st->buf) ASN__DECODE_FAILED; + st->size = size; + } + } + + /* X.691, #12.2.2 */ + if(ct && ct->flags != APC_UNCONSTRAINED) { + /* #10.5.6 */ + ASN_DEBUG("Integer with range %d bits", ct->range_bits); + if(ct->range_bits >= 0) { + if (ct->range_bits > 16) { + int max_range_bytes = (ct->range_bits >> 3) + + (((ct->range_bits % 8) > 0) ? 1 : 0); + int length = 0, i; + intmax_t value = 0; + + for (i = 1; ; i++) { + int upper = 1 << i; + if (upper >= max_range_bytes) + break; + } + ASN_DEBUG("Can encode %d (%d bytes) in %d bits", ct->range_bits, + max_range_bytes, i); + + if ((length = per_get_few_bits(pd, i)) < 0) + ASN__DECODE_FAILED; + + /* X.691 #12.2.6 length determinant + lb (1) */ + length += 1; + ASN_DEBUG("Got length %d", length); + if (aper_get_align(pd) != 0) + ASN__DECODE_FAILED; + while (length--) { + int buf = per_get_few_bits(pd, 8); + if (buf < 0) + ASN__DECODE_FAILED; + value += (((intmax_t)buf) << (8 * length)); + } + + value += ct->lower_bound; + if((specs && specs->field_unsigned) + ? asn_umax2INTEGER(st, (uintmax_t)value) + : asn_imax2INTEGER(st, value)) + ASN__DECODE_FAILED; + ASN_DEBUG("Got value %"ASN_PRIdMAX" + low %"ASN_PRIdMAX"", + value, (intmax_t)ct->lower_bound); + } else { + intmax_t value = 0; + if (ct->range_bits < 8) { + value = per_get_few_bits(pd, ct->range_bits); + if(value < 0) ASN__DECODE_STARVED; + } else if (ct->range_bits == 8) { + if (aper_get_align(pd) < 0) + ASN__DECODE_FAILED; + value = per_get_few_bits(pd, ct->range_bits); + if(value < 0) ASN__DECODE_STARVED; + } else { + /* Align */ + if (aper_get_align(pd) < 0) + ASN__DECODE_FAILED; + value = per_get_few_bits(pd, 16); + if(value < 0) ASN__DECODE_STARVED; + } + value += ct->lower_bound; + if((specs && specs->field_unsigned) + ? asn_umax2INTEGER(st, (uintmax_t)value) + : asn_imax2INTEGER(st, value)) + ASN__DECODE_FAILED; + ASN_DEBUG("Got value %"ASN_PRIdMAX" + low %"ASN_PRIdMAX"", + value, (intmax_t)ct->lower_bound); + } + return rval; + } else { + ASN__DECODE_FAILED; + } + } else { + ASN_DEBUG("Decoding unconstrained integer %s", td->name); + } + + /* X.691, #12.2.3, #12.2.4 */ + do { + ssize_t len; + void *p; + int ret; + + /* Get the PER length */ + len = aper_get_length(pd, -1, -1, -1, &repeat); + if(len < 0) ASN__DECODE_STARVED; + + p = REALLOC(st->buf, st->size + len + 1); + if(!p) ASN__DECODE_FAILED; + st->buf = (uint8_t *)p; + + ret = per_get_many_bits(pd, &st->buf[st->size], 0, 8 * len); + if(ret < 0) ASN__DECODE_STARVED; + st->size += len; + } while(repeat); + st->buf[st->size] = 0; /* JIC */ + + /* #12.2.3 */ + if(ct && ct->lower_bound) { + /* + * TODO: replace by in-place arithmetics. + */ + long value; + if(asn_INTEGER2long(st, &value)) + ASN__DECODE_FAILED; + if(asn_long2INTEGER(st, value + ct->lower_bound)) + ASN__DECODE_FAILED; + } + + return rval; +} + +asn_enc_rval_t +INTEGER_encode_aper(const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, + const void *sptr, asn_per_outp_t *po) { + const asn_INTEGER_specifics_t *specs = (const asn_INTEGER_specifics_t *)td->specifics; + asn_enc_rval_t er = {0,0,0}; + const INTEGER_t *st = (const INTEGER_t *)sptr; + const uint8_t *buf; + const uint8_t *end; + const asn_per_constraint_t *ct; + intmax_t value = 0; + + if(!st || st->size == 0) ASN__ENCODE_FAILED; + + if(!constraints) constraints = td->encoding_constraints.per_constraints; + ct = constraints ? &constraints->value : 0; + + er.encoded = 0; + + if(ct) { + int inext = 0; + if(specs && specs->field_unsigned) { + uintmax_t uval; + if(asn_INTEGER2umax(st, &uval)) + ASN__ENCODE_FAILED; + /* Check proper range */ + if(ct->flags & APC_SEMI_CONSTRAINED) { + if(uval < (uintmax_t)ct->lower_bound) + inext = 1; + } else if(ct->range_bits >= 0) { + if(uval < (uintmax_t)ct->lower_bound + || uval > (uintmax_t)ct->upper_bound) + inext = 1; + } + ASN_DEBUG("Value %"ASN_PRIdMAX" (%02x/%"ASN_PRI_SIZE") lb %"ASN_PRIdMAX" ub %"ASN_PRIdMAX" %s", + uval, st->buf[0], st->size, + (intmax_t)ct->lower_bound, + (intmax_t)ct->upper_bound, + inext ? "ext" : "fix"); + value = uval; + } else { + if(asn_INTEGER2imax(st, &value)) ASN__ENCODE_FAILED; + /* Check proper range */ + if(ct->flags & APC_SEMI_CONSTRAINED) { + if(value < ct->lower_bound) + inext = 1; + } else if(ct->range_bits >= 0) { + if(value < ct->lower_bound + || value > ct->upper_bound) + inext = 1; + } + ASN_DEBUG("Value %"ASN_PRIdMAX" (%02x/%"ASN_PRI_SIZE") lb %"ASN_PRIdMAX" ub %"ASN_PRIdMAX" %s", + value, st->buf[0], st->size, + (intmax_t)ct->lower_bound, + (intmax_t)ct->upper_bound, + inext ? "ext" : "fix"); + } + if(ct->flags & APC_EXTENSIBLE) { + if(per_put_few_bits(po, inext, 1)) + ASN__ENCODE_FAILED; + if(inext) ct = 0; + } else if(inext) { + ASN__ENCODE_FAILED; + } + } + + /* X.691, #12.2.2 */ + if(ct && ct->range_bits >= 0) { + uintmax_t v; + + /* #10.5.6 */ + ASN_DEBUG("Encoding integer %"ASN_PRIdMAX" (%"ASN_PRIdMAX") with range %d bits", + value, (intmax_t)(value - ct->lower_bound), + ct->range_bits); + + v = value - ct->lower_bound; + + /* #12 <= 8 -> alignment ? */ + int range = ct->upper_bound - ct->lower_bound + 1; + if (ct->range_bits < 8 || (ct->range_bits == 8 && range < 256)) { + if(per_put_few_bits(po, 0x00 | v, ct->range_bits)) + ASN__ENCODE_FAILED; + } else if (ct->range_bits == 8) { + if(aper_put_align(po) < 0) + ASN__ENCODE_FAILED; + if(per_put_few_bits(po, 0x00 | v, ct->range_bits)) + ASN__ENCODE_FAILED; + } else if (ct->range_bits <= 16) { + /* Consume the bytes to align on octet */ + if(aper_put_align(po) < 0) + ASN__ENCODE_FAILED; + if(per_put_few_bits(po, 0x0000 | v, 16)) + ASN__ENCODE_FAILED; + } else { + /* TODO: extend to >64 bits */ + int64_t v64 = v; + int i, j; + int max_range_bytes = (ct->range_bits >> 3) + + (((ct->range_bits % 8) > 0) ? 1 : 0); + + for (i = 1; ; i++) { + int upper = 1 << i; + if (upper >= max_range_bytes) + break; + } + + for (j = sizeof(int64_t) -1; j != 0; j--) { + int64_t val; + val = v64 >> (j * 8); + if (val != 0) + break; + } + + /* Putting length in the minimum number of bits ex: 5 = 3bits */ + if (per_put_few_bits(po, j, i)) + ASN__ENCODE_FAILED; + + /* Consume the bits to align on octet */ + if (aper_put_align(po) < 0) + ASN__ENCODE_FAILED; + /* Put the value */ + for (i = 0; i <= j; i++) { + if(per_put_few_bits(po, (v64 >> (8 * (j - i))) & 0xff, 8)) + ASN__ENCODE_FAILED; + } + } + ASN__ENCODED_OK(er); + } + + if(ct && ct->lower_bound) { + ASN_DEBUG("Adjust lower bound to %"ASN_PRIdMAX"", (intmax_t)ct->lower_bound); + /* TODO: adjust lower bound */ + ASN__ENCODE_FAILED; + } + + for(buf = st->buf, end = st->buf + st->size; buf < end;) { + int need_eom = 0; + ssize_t mayEncode = aper_put_length(po, -1, -1, end - buf, &need_eom); + if(mayEncode < 0) + ASN__ENCODE_FAILED; + if(per_put_many_bits(po, buf, 8 * mayEncode)) + ASN__ENCODE_FAILED; + buf += mayEncode; + if(need_eom && (aper_put_length(po, -1, -1, 0, NULL) < 0)) + ASN__ENCODE_FAILED; + } + + ASN__ENCODED_OK(er); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER_print.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER_print.c new file mode 100644 index 000000000..2d37dee01 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER_print.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* + * INTEGER specific human-readable output. + */ +int +INTEGER_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, + asn_app_consume_bytes_f *cb, void *app_key) { + const INTEGER_t *st = (const INTEGER_t *)sptr; + ssize_t ret; + + (void)ilevel; + + if(!st || !st->buf) + ret = cb("", 8, app_key); + else + ret = INTEGER__dump(td, st, cb, app_key, 0); + + return (ret < 0) ? -1 : 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER_rfill.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER_rfill.c new file mode 100644 index 000000000..fab002385 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER_rfill.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_random_fill_result_t +INTEGER_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, + const asn_encoding_constraints_t *constraints, + size_t max_length) { + const asn_INTEGER_specifics_t *specs = + (const asn_INTEGER_specifics_t *)td->specifics; + 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}; + INTEGER_t *st = *sptr; + const asn_INTEGER_enum_map_t *emap; + size_t emap_len; + intmax_t value; + int find_inside_map; + + if(max_length == 0) return result_skipped; + + if(st == NULL) { + st = (INTEGER_t *)CALLOC(1, sizeof(*st)); + if(st == NULL) { + return result_failed; + } + } + + if(specs) { + emap = specs->value2enum; + emap_len = specs->map_count; + if(specs->strict_enumeration) { + find_inside_map = emap_len > 0; + } else { + find_inside_map = emap_len ? asn_random_between(0, 1) : 0; + } + } else { + emap = 0; + emap_len = 0; + find_inside_map = 0; + } + + if(find_inside_map) { + assert(emap_len > 0); + value = emap[asn_random_between(0, emap_len - 1)].nat_value; + } else { + static const long variants[] = { + -65536, -65535, -65534, -32769, -32768, -32767, -16385, -16384, + -16383, -257, -256, -255, -254, -129, -128, -127, + -126, -1, 0, 1, 126, 127, 128, 129, + 254, 255, 256, 257, 16383, 16384, 16385, 32767, + 32768, 32769, 65534, 65535, 65536, 65537}; + if(specs && specs->field_unsigned) { + assert(variants[18] == 0); + value = variants[asn_random_between( + 18, sizeof(variants) / sizeof(variants[0]) - 1)]; + } else { + value = variants[asn_random_between( + 0, sizeof(variants) / sizeof(variants[0]) - 1)]; + } + + if(!constraints) constraints = &td->encoding_constraints; +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + const asn_per_constraints_t *ct; + + ct = constraints ? constraints->per_constraints : 0; + if(ct && (ct->value.flags & APC_CONSTRAINED)) { + if(value < ct->value.lower_bound || value > ct->value.upper_bound) { + value = asn_random_between(ct->value.lower_bound, + ct->value.upper_bound); + } + } +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + } + + if(asn_imax2INTEGER(st, value)) { + if(st == *sptr) { + ASN_STRUCT_RESET(*td, st); + } else { + ASN_STRUCT_FREE(*td, st); + } + return result_failed; + } else { + *sptr = st; + result_ok.length = st->size; + return result_ok; + } +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER_xer.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER_xer.c new file mode 100644 index 000000000..4f21c86a9 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/INTEGER_xer.c @@ -0,0 +1,351 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +struct e2v_key { + const char *start; + const char *stop; + const asn_INTEGER_enum_map_t *vemap; + const unsigned int *evmap; +}; +static int +INTEGER__compar_enum2value(const void *kp, const void *am) { + const struct e2v_key *key = (const struct e2v_key *)kp; + const asn_INTEGER_enum_map_t *el = (const asn_INTEGER_enum_map_t *)am; + const char *ptr, *end, *name; + + /* Remap the element (sort by different criterion) */ + el = key->vemap + key->evmap[el - key->vemap]; + + /* Compare strings */ + for(ptr = key->start, end = key->stop, name = el->enum_name; + ptr < end; ptr++, name++) { + if(*ptr != *name || !*name) + return *(const unsigned char *)ptr - *(const unsigned char *)name; + } + return name[0] ? -1 : 0; +} + +static const asn_INTEGER_enum_map_t * +INTEGER_map_enum2value(const asn_INTEGER_specifics_t *specs, const char *lstart, + const char *lstop) { + const asn_INTEGER_enum_map_t *el_found; + int count = specs ? specs->map_count : 0; + struct e2v_key key; + const char *lp; + + if(!count) return NULL; + + /* Guaranteed: assert(lstart < lstop); */ + /* Figure out the tag name */ + for(lstart++, lp = lstart; lp < lstop; lp++) { + switch(*lp) { + case 9: case 10: case 11: case 12: case 13: case 32: /* WSP */ + case 0x2f: /* '/' */ case 0x3e: /* '>' */ + break; + default: + continue; + } + break; + } + if(lp == lstop) return NULL; /* No tag found */ + lstop = lp; + + key.start = lstart; + key.stop = lstop; + key.vemap = specs->value2enum; + key.evmap = specs->enum2value; + el_found = (asn_INTEGER_enum_map_t *)bsearch(&key, + specs->value2enum, count, sizeof(specs->value2enum[0]), + INTEGER__compar_enum2value); + if(el_found) { + /* Remap enum2value into value2enum */ + el_found = key.vemap + key.evmap[el_found - key.vemap]; + } + return el_found; +} + +static int +INTEGER_st_prealloc(INTEGER_t *st, int min_size) { + void *p = MALLOC(min_size + 1); + if(p) { + void *b = st->buf; + st->size = 0; + st->buf = p; + FREEMEM(b); + return 0; + } else { + return -1; + } +} + +/* + * Decode the chunk of XML text encoding INTEGER. + */ +static enum xer_pbd_rval +INTEGER__xer_body_decode(const asn_TYPE_descriptor_t *td, void *sptr, + const void *chunk_buf, size_t chunk_size) { + const asn_INTEGER_specifics_t *specs = + (const asn_INTEGER_specifics_t *)td->specifics; + INTEGER_t *st = (INTEGER_t *)sptr; + intmax_t dec_value; + intmax_t hex_value = 0; + const char *lp; + const char *lstart = (const char *)chunk_buf; + const char *lstop = lstart + chunk_size; + enum { + ST_LEADSPACE, + ST_SKIPSPHEX, + ST_WAITDIGITS, + ST_DIGITS, + ST_DIGITS_TRAILSPACE, + ST_HEXDIGIT1, + ST_HEXDIGIT2, + ST_HEXDIGITS_TRAILSPACE, + ST_HEXCOLON, + ST_END_ENUM, + ST_UNEXPECTED + } state = ST_LEADSPACE; + const char *dec_value_start = 0; /* INVARIANT: always !0 in ST_DIGITS */ + const char *dec_value_end = 0; + + if(chunk_size) + ASN_DEBUG("INTEGER body %ld 0x%2x..0x%2x", + (long)chunk_size, *lstart, lstop[-1]); + + if(INTEGER_st_prealloc(st, (chunk_size/3) + 1)) + return XPBD_SYSTEM_FAILURE; + + /* + * We may have received a tag here. It will be processed inline. + * Use strtoul()-like code and serialize the result. + */ + for(lp = lstart; lp < lstop; lp++) { + int lv = *lp; + switch(lv) { + case 0x09: case 0x0a: case 0x0d: case 0x20: + switch(state) { + case ST_LEADSPACE: + case ST_DIGITS_TRAILSPACE: + case ST_HEXDIGITS_TRAILSPACE: + case ST_SKIPSPHEX: + continue; + case ST_DIGITS: + dec_value_end = lp; + state = ST_DIGITS_TRAILSPACE; + continue; + case ST_HEXCOLON: + state = ST_HEXDIGITS_TRAILSPACE; + continue; + default: + break; + } + break; + case 0x2d: /* '-' */ + if(state == ST_LEADSPACE) { + dec_value = 0; + dec_value_start = lp; + state = ST_WAITDIGITS; + continue; + } + break; + case 0x2b: /* '+' */ + if(state == ST_LEADSPACE) { + dec_value = 0; + dec_value_start = lp; + state = ST_WAITDIGITS; + continue; + } + break; + case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: + case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: + switch(state) { + case ST_DIGITS: continue; + case ST_SKIPSPHEX: /* Fall through */ + case ST_HEXDIGIT1: + hex_value = (lv - 0x30) << 4; + state = ST_HEXDIGIT2; + continue; + case ST_HEXDIGIT2: + hex_value += (lv - 0x30); + state = ST_HEXCOLON; + st->buf[st->size++] = (uint8_t)hex_value; + continue; + case ST_HEXCOLON: + return XPBD_BROKEN_ENCODING; + case ST_LEADSPACE: + dec_value = 0; + dec_value_start = lp; + /* FALL THROUGH */ + case ST_WAITDIGITS: + state = ST_DIGITS; + continue; + default: + break; + } + break; + case 0x3c: /* '<', start of XML encoded enumeration */ + if(state == ST_LEADSPACE) { + const asn_INTEGER_enum_map_t *el; + el = INTEGER_map_enum2value( + (const asn_INTEGER_specifics_t *) + td->specifics, lstart, lstop); + if(el) { + ASN_DEBUG("Found \"%s\" => %ld", + el->enum_name, el->nat_value); + dec_value = el->nat_value; + state = ST_END_ENUM; + lp = lstop - 1; + continue; + } + ASN_DEBUG("Unknown identifier for INTEGER"); + } + return XPBD_BROKEN_ENCODING; + case 0x3a: /* ':' */ + if(state == ST_HEXCOLON) { + /* This colon is expected */ + state = ST_HEXDIGIT1; + continue; + } else if(state == ST_DIGITS) { + /* The colon here means that we have + * decoded the first two hexadecimal + * places as a decimal value. + * Switch decoding mode. */ + ASN_DEBUG("INTEGER re-evaluate as hex form"); + state = ST_SKIPSPHEX; + dec_value_start = 0; + lp = lstart - 1; + continue; + } else { + ASN_DEBUG("state %d at %ld", state, (long)(lp - lstart)); + break; + } + /* [A-Fa-f] */ + case 0x41:case 0x42:case 0x43:case 0x44:case 0x45:case 0x46: + case 0x61:case 0x62:case 0x63:case 0x64:case 0x65:case 0x66: + switch(state) { + case ST_SKIPSPHEX: + case ST_LEADSPACE: /* Fall through */ + case ST_HEXDIGIT1: + hex_value = lv - ((lv < 0x61) ? 0x41 : 0x61); + hex_value += 10; + hex_value <<= 4; + state = ST_HEXDIGIT2; + continue; + case ST_HEXDIGIT2: + hex_value += lv - ((lv < 0x61) ? 0x41 : 0x61); + hex_value += 10; + st->buf[st->size++] = (uint8_t)hex_value; + state = ST_HEXCOLON; + continue; + case ST_DIGITS: + ASN_DEBUG("INTEGER re-evaluate as hex form"); + state = ST_SKIPSPHEX; + dec_value_start = 0; + lp = lstart - 1; + continue; + default: + break; + } + break; + } + + /* Found extra non-numeric stuff */ + ASN_DEBUG("INTEGER :: Found non-numeric 0x%2x at %ld", + lv, (long)(lp - lstart)); + state = ST_UNEXPECTED; + break; + } + + switch(state) { + case ST_END_ENUM: + /* Got a complete and valid enumeration encoded as a tag. */ + break; + case ST_DIGITS: + dec_value_end = lstop; + /* FALL THROUGH */ + case ST_DIGITS_TRAILSPACE: + /* The last symbol encountered was a digit. */ + switch(asn_strtoimax_lim(dec_value_start, &dec_value_end, &dec_value)) { + case ASN_STRTOX_OK: + if(specs && specs->field_unsigned && (uintmax_t) dec_value <= ULONG_MAX) { + break; + } else if(dec_value >= LONG_MIN && dec_value <= LONG_MAX) { + break; + } else { + /* + * We model INTEGER on long for XER, + * to avoid rewriting all the tests at once. + */ + ASN_DEBUG("INTEGER exceeds long range"); + } + /* Fall through */ + case ASN_STRTOX_ERROR_RANGE: + ASN_DEBUG("INTEGER decode %s hit range limit", td->name); + return XPBD_DECODER_LIMIT; + case ASN_STRTOX_ERROR_INVAL: + case ASN_STRTOX_EXPECT_MORE: + case ASN_STRTOX_EXTRA_DATA: + return XPBD_BROKEN_ENCODING; + } + break; + case ST_HEXCOLON: + case ST_HEXDIGITS_TRAILSPACE: + st->buf[st->size] = 0; /* Just in case termination */ + return XPBD_BODY_CONSUMED; + case ST_HEXDIGIT1: + case ST_HEXDIGIT2: + case ST_SKIPSPHEX: + return XPBD_BROKEN_ENCODING; + case ST_LEADSPACE: + /* Content not found */ + return XPBD_NOT_BODY_IGNORE; + case ST_WAITDIGITS: + case ST_UNEXPECTED: + ASN_DEBUG("INTEGER: No useful digits (state %d)", state); + return XPBD_BROKEN_ENCODING; /* No digits */ + } + + /* + * Convert the result of parsing of enumeration or a straight + * decimal value into a BER representation. + */ + if(asn_imax2INTEGER(st, dec_value)) { + ASN_DEBUG("INTEGER decode %s conversion failed", td->name); + return XPBD_SYSTEM_FAILURE; + } + + return XPBD_BODY_CONSUMED; +} + +asn_dec_rval_t +INTEGER_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) { + return xer_decode_primitive(opt_codec_ctx, td, + sptr, sizeof(INTEGER_t), opt_mname, + buf_ptr, size, INTEGER__xer_body_decode); +} + +asn_enc_rval_t +INTEGER_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 INTEGER_t *st = (const INTEGER_t *)sptr; + asn_enc_rval_t er = {0,0,0}; + + (void)ilevel; + (void)flags; + + if(!st || !st->buf) + ASN__ENCODE_FAILED; + + er.encoded = INTEGER__dump(td, st, cb, app_key, 1); + if(er.encoded < 0) ASN__ENCODE_FAILED; + + ASN__ENCODED_OK(er); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Makefile.am.libasncodec b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Makefile.am.libasncodec new file mode 100644 index 000000000..a3ed05e82 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Makefile.am.libasncodec @@ -0,0 +1,156 @@ +ASN_MODULE_SRCS= \ + compiled_output/Spectrum-RanFunctionData.c \ + compiled_output/Spectrum-SensingIndication.c \ + compiled_output/Spectrum-PRBBlacklistControl.c \ + compiled_output/Spectrum-SensingPolicyControl.c \ + compiled_output/Spectrum-DAppControlPayload.c \ + compiled_output/Spectrum-DAppControlData.c \ + compiled_output/Spectrum-PRBBlacklistReport.c \ + compiled_output/Spectrum-DAppReportPayload.c \ + compiled_output/Spectrum-DAppReportData.c \ + compiled_output/Spectrum-PRBBlockedControl.c \ + compiled_output/Spectrum-ConfigControl.c \ + compiled_output/Spectrum-XAppControlPayload.c \ + compiled_output/Spectrum-XAppControlData.c \ + compiled_output/EXTERNAL.c + +ASN_MODULE_HDRS= \ + compiled_output/Spectrum-RanFunctionData.h \ + compiled_output/Spectrum-SensingIndication.h \ + compiled_output/Spectrum-PRBBlacklistControl.h \ + compiled_output/Spectrum-SensingPolicyControl.h \ + compiled_output/Spectrum-DAppControlPayload.h \ + compiled_output/Spectrum-DAppControlData.h \ + compiled_output/Spectrum-PRBBlacklistReport.h \ + compiled_output/Spectrum-DAppReportPayload.h \ + compiled_output/Spectrum-DAppReportData.h \ + compiled_output/Spectrum-PRBBlockedControl.h \ + compiled_output/Spectrum-ConfigControl.h \ + compiled_output/Spectrum-XAppControlPayload.h \ + compiled_output/Spectrum-XAppControlData.h \ + compiled_output/EXTERNAL.h + +ASN_MODULE_HDRS+=compiled_output/ANY.h +ASN_MODULE_SRCS+=compiled_output/ANY.c +ASN_MODULE_HDRS+=compiled_output/OCTET_STRING.h +ASN_MODULE_HDRS+=compiled_output/OPEN_TYPE.h +ASN_MODULE_SRCS+=compiled_output/OPEN_TYPE.c +ASN_MODULE_HDRS+=compiled_output/constr_CHOICE.h +ASN_MODULE_HDRS+=compiled_output/BOOLEAN.h +ASN_MODULE_SRCS+=compiled_output/BOOLEAN.c +ASN_MODULE_HDRS+=compiled_output/GraphicString.h +ASN_MODULE_SRCS+=compiled_output/GraphicString.c +ASN_MODULE_HDRS+=compiled_output/INTEGER.h +ASN_MODULE_SRCS+=compiled_output/INTEGER.c +ASN_MODULE_HDRS+=compiled_output/NativeInteger.h +ASN_MODULE_SRCS+=compiled_output/NativeInteger.c +ASN_MODULE_HDRS+=compiled_output/OBJECT_IDENTIFIER.h +ASN_MODULE_SRCS+=compiled_output/OBJECT_IDENTIFIER.c +ASN_MODULE_HDRS+=compiled_output/asn_codecs_prim.h +ASN_MODULE_HDRS+=compiled_output/ObjectDescriptor.h +ASN_MODULE_SRCS+=compiled_output/ObjectDescriptor.c +ASN_MODULE_HDRS+=compiled_output/asn_SEQUENCE_OF.h +ASN_MODULE_SRCS+=compiled_output/asn_SEQUENCE_OF.c +ASN_MODULE_HDRS+=compiled_output/asn_SET_OF.h +ASN_MODULE_SRCS+=compiled_output/asn_SET_OF.c +ASN_MODULE_SRCS+=compiled_output/constr_CHOICE.c +ASN_MODULE_HDRS+=compiled_output/constr_SEQUENCE.h +ASN_MODULE_SRCS+=compiled_output/constr_SEQUENCE.c +ASN_MODULE_HDRS+=compiled_output/constr_SEQUENCE_OF.h +ASN_MODULE_SRCS+=compiled_output/constr_SEQUENCE_OF.c +ASN_MODULE_HDRS+=compiled_output/constr_SET_OF.h +ASN_MODULE_SRCS+=compiled_output/constr_SET_OF.c +ASN_MODULE_HDRS+=compiled_output/asn_application.h +ASN_MODULE_SRCS+=compiled_output/asn_application.c +ASN_MODULE_HDRS+=compiled_output/asn_ioc.h +ASN_MODULE_HDRS+=compiled_output/asn_system.h +ASN_MODULE_HDRS+=compiled_output/asn_codecs.h +ASN_MODULE_HDRS+=compiled_output/asn_internal.h +ASN_MODULE_SRCS+=compiled_output/asn_internal.c +ASN_MODULE_HDRS+=compiled_output/asn_bit_data.h +ASN_MODULE_SRCS+=compiled_output/asn_bit_data.c +ASN_MODULE_SRCS+=compiled_output/OCTET_STRING.c +ASN_MODULE_HDRS+=compiled_output/BIT_STRING.h +ASN_MODULE_SRCS+=compiled_output/BIT_STRING.c +ASN_MODULE_SRCS+=compiled_output/asn_codecs_prim.c +ASN_MODULE_HDRS+=compiled_output/ber_tlv_length.h +ASN_MODULE_SRCS+=compiled_output/ber_tlv_length.c +ASN_MODULE_HDRS+=compiled_output/ber_tlv_tag.h +ASN_MODULE_SRCS+=compiled_output/ber_tlv_tag.c +ASN_MODULE_HDRS+=compiled_output/constr_TYPE.h +ASN_MODULE_SRCS+=compiled_output/constr_TYPE.c +ASN_MODULE_HDRS+=compiled_output/constraints.h +ASN_MODULE_SRCS+=compiled_output/constraints.c +ASN_MODULE_HDRS+=compiled_output/xer_support.h +ASN_MODULE_HDRS+=compiled_output/xer_decoder.h +ASN_MODULE_HDRS+=compiled_output/xer_encoder.h +ASN_MODULE_SRCS+=compiled_output/xer_support.c +ASN_MODULE_SRCS+=compiled_output/xer_decoder.c +ASN_MODULE_SRCS+=compiled_output/xer_encoder.c +ASN_MODULE_SRCS+=compiled_output/ANY_xer.c +ASN_MODULE_SRCS+=compiled_output/BIT_STRING_xer.c +ASN_MODULE_SRCS+=compiled_output/BOOLEAN_xer.c +ASN_MODULE_SRCS+=compiled_output/INTEGER_xer.c +ASN_MODULE_SRCS+=compiled_output/NativeInteger_xer.c +ASN_MODULE_SRCS+=compiled_output/OBJECT_IDENTIFIER_xer.c +ASN_MODULE_SRCS+=compiled_output/OCTET_STRING_xer.c +ASN_MODULE_SRCS+=compiled_output/OPEN_TYPE_xer.c +ASN_MODULE_SRCS+=compiled_output/asn_codecs_prim_xer.c +ASN_MODULE_SRCS+=compiled_output/constr_CHOICE_xer.c +ASN_MODULE_SRCS+=compiled_output/constr_SEQUENCE_OF_xer.c +ASN_MODULE_SRCS+=compiled_output/constr_SEQUENCE_xer.c +ASN_MODULE_SRCS+=compiled_output/constr_SET_OF_xer.c +ASN_MODULE_HDRS+=compiled_output/per_decoder.h +ASN_MODULE_HDRS+=compiled_output/per_encoder.h +ASN_MODULE_HDRS+=compiled_output/per_support.h +ASN_MODULE_HDRS+=compiled_output/per_opentype.h +ASN_MODULE_SRCS+=compiled_output/per_decoder.c +ASN_MODULE_SRCS+=compiled_output/per_encoder.c +ASN_MODULE_SRCS+=compiled_output/per_support.c +ASN_MODULE_SRCS+=compiled_output/per_opentype.c +ASN_MODULE_HDRS+=compiled_output/aper_decoder.h +ASN_MODULE_HDRS+=compiled_output/aper_encoder.h +ASN_MODULE_HDRS+=compiled_output/aper_support.h +ASN_MODULE_HDRS+=compiled_output/aper_opentype.h +ASN_MODULE_SRCS+=compiled_output/aper_decoder.c +ASN_MODULE_SRCS+=compiled_output/aper_encoder.c +ASN_MODULE_SRCS+=compiled_output/aper_support.c +ASN_MODULE_SRCS+=compiled_output/aper_opentype.c +ASN_MODULE_SRCS+=compiled_output/ANY_aper.c +ASN_MODULE_SRCS+=compiled_output/BOOLEAN_aper.c +ASN_MODULE_SRCS+=compiled_output/INTEGER_aper.c +ASN_MODULE_SRCS+=compiled_output/NativeInteger_aper.c +ASN_MODULE_SRCS+=compiled_output/OCTET_STRING_aper.c +ASN_MODULE_SRCS+=compiled_output/OPEN_TYPE_aper.c +ASN_MODULE_SRCS+=compiled_output/constr_CHOICE_aper.c +ASN_MODULE_SRCS+=compiled_output/constr_SEQUENCE_OF_aper.c +ASN_MODULE_SRCS+=compiled_output/constr_SEQUENCE_aper.c +ASN_MODULE_SRCS+=compiled_output/constr_SET_OF_aper.c +ASN_MODULE_SRCS+=compiled_output/BIT_STRING_print.c +ASN_MODULE_SRCS+=compiled_output/BOOLEAN_print.c +ASN_MODULE_SRCS+=compiled_output/INTEGER_print.c +ASN_MODULE_SRCS+=compiled_output/NativeInteger_print.c +ASN_MODULE_SRCS+=compiled_output/OBJECT_IDENTIFIER_print.c +ASN_MODULE_SRCS+=compiled_output/OCTET_STRING_print.c +ASN_MODULE_SRCS+=compiled_output/constr_CHOICE_print.c +ASN_MODULE_SRCS+=compiled_output/constr_SEQUENCE_print.c +ASN_MODULE_SRCS+=compiled_output/constr_SET_OF_print.c +ASN_MODULE_HDRS+=compiled_output/asn_random_fill.h +ASN_MODULE_SRCS+=compiled_output/asn_random_fill.c +ASN_MODULE_SRCS+=compiled_output/BIT_STRING_rfill.c +ASN_MODULE_SRCS+=compiled_output/BOOLEAN_rfill.c +ASN_MODULE_SRCS+=compiled_output/INTEGER_rfill.c +ASN_MODULE_SRCS+=compiled_output/NativeInteger_rfill.c +ASN_MODULE_SRCS+=compiled_output/OBJECT_IDENTIFIER_rfill.c +ASN_MODULE_SRCS+=compiled_output/OCTET_STRING_rfill.c +ASN_MODULE_SRCS+=compiled_output/constr_CHOICE_rfill.c +ASN_MODULE_SRCS+=compiled_output/constr_SEQUENCE_rfill.c +ASN_MODULE_SRCS+=compiled_output/constr_SET_OF_rfill.c + +ASN_MODULE_CFLAGS=-DASN_DISABLE_BER_SUPPORT -DASN_DISABLE_OER_SUPPORT -DASN_DISABLE_UPER_SUPPORT + +lib_LTLIBRARIES+=libasncodec.la +libasncodec_la_SOURCES=$(ASN_MODULE_SRCS) $(ASN_MODULE_HDRS) +libasncodec_la_CPPFLAGS=-I$(top_srcdir)/compiled_output/ +libasncodec_la_CFLAGS=$(ASN_MODULE_CFLAGS) +libasncodec_la_LDFLAGS=-lm diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger.c new file mode 100644 index 000000000..8957b65c3 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger.c @@ -0,0 +1,182 @@ +/*- + * Copyright (c) 2004, 2005, 2006 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +/* + * Read the NativeInteger.h for the explanation wrt. differences between + * INTEGER and NativeInteger. + * Basically, both are decoders and encoders of ASN.1 INTEGER type, but this + * implementation deals with the standard (machine-specific) representation + * of them instead of using the platform-independent buffer. + */ +#include +#include + +/* + * NativeInteger basic type description. + */ +static const ber_tlv_tag_t asn_DEF_NativeInteger_tags[] = { + (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)) +}; +asn_TYPE_operation_t asn_OP_NativeInteger = { + NativeInteger_free, +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + NativeInteger_print, +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + NativeInteger_compare, + NativeInteger_copy, +#if !defined(ASN_DISABLE_BER_SUPPORT) + NativeInteger_decode_ber, + NativeInteger_encode_der, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + NativeInteger_decode_xer, + NativeInteger_encode_xer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + NativeInteger_decode_jer, + NativeInteger_encode_jer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + NativeInteger_decode_oer, /* OER decoder */ + NativeInteger_encode_oer, /* Canonical OER encoder */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + NativeInteger_decode_uper, /* Unaligned PER decoder */ + NativeInteger_encode_uper, /* Unaligned PER encoder */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + NativeInteger_decode_aper, /* Aligned PER decoder */ + NativeInteger_encode_aper, /* Aligned PER encoder */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + NativeInteger_random_fill, +#else + 0, +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + 0 /* Use generic outmost tag fetcher */ +}; +asn_TYPE_descriptor_t asn_DEF_NativeInteger = { + "INTEGER", /* The ASN.1 type is still INTEGER */ + "INTEGER", + &asn_OP_NativeInteger, + asn_DEF_NativeInteger_tags, + sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]), + asn_DEF_NativeInteger_tags, /* Same as above */ + sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]), + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + asn_generic_no_constraint + }, + 0, 0, /* No members */ + 0 /* No specifics */ +}; + +void +NativeInteger_free(const asn_TYPE_descriptor_t *td, void *ptr, + enum asn_struct_free_method method) { + if(!td || !ptr) + return; + + ASN_DEBUG("Freeing %s as INTEGER (%d, %p, Native)", + td->name, method, ptr); + + switch(method) { + case ASFM_FREE_EVERYTHING: + FREEMEM(ptr); + break; + case ASFM_FREE_UNDERLYING: + break; + case ASFM_FREE_UNDERLYING_AND_RESET: + memset(ptr, 0, sizeof(long)); + break; + } +} + +int +NativeInteger_compare(const asn_TYPE_descriptor_t *td, const void *aptr, const void *bptr) { + (void)td; + + if(aptr && bptr) { + const asn_INTEGER_specifics_t *specs = + (const asn_INTEGER_specifics_t *)td->specifics; + if(specs && specs->field_unsigned) { + const unsigned long *a = aptr; + const unsigned long *b = bptr; + if(*a < *b) { + return -1; + } else if(*a > *b) { + return 1; + } else { + return 0; + } + } else { + const long *a = aptr; + const long *b = bptr; + if(*a < *b) { + return -1; + } else if(*a > *b) { + return 1; + } else { + return 0; + } + } + } else if(!aptr) { + return -1; + } else { + return 1; + } +} + +int +NativeInteger_copy(const asn_TYPE_descriptor_t *td, void **aptr, const void *bptr) { + unsigned long *a = *aptr; + const unsigned long *b = bptr; + + (void)td; + + /* Check if source has data */ + if(!b) { + /* Clear destination */ + if(a) { + FREEMEM(a); + *aptr = 0; + } + return 0; + } + + if(!a) { + a = *aptr = MALLOC(sizeof(*a)); + if(!a) return -1; + } + + *a = *b; + + return 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger.h new file mode 100644 index 000000000..352926b41 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger.h @@ -0,0 +1,73 @@ +/*- + * Copyright (c) 2004-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +/* + * This type differs from the standard INTEGER in that it is modelled using + * the fixed machine type (long, int, short), so it can hold only values of + * limited length. There is no type (i.e., NativeInteger_t, any integer type + * will do). + * This type may be used when integer range is limited by subtype constraints. + */ +#ifndef _NativeInteger_H_ +#define _NativeInteger_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern asn_TYPE_descriptor_t asn_DEF_NativeInteger; +extern asn_TYPE_operation_t asn_OP_NativeInteger; + +asn_struct_free_f NativeInteger_free; + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +asn_struct_print_f NativeInteger_print; +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +asn_struct_compare_f NativeInteger_compare; +asn_struct_copy_f NativeInteger_copy; + +#define NativeInteger_constraint asn_generic_no_constraint + +#if !defined(ASN_DISABLE_BER_SUPPORT) +ber_type_decoder_f NativeInteger_decode_ber; +der_type_encoder_f NativeInteger_encode_der; +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +xer_type_decoder_f NativeInteger_decode_xer; +xer_type_encoder_f NativeInteger_encode_xer; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +jer_type_decoder_f NativeInteger_decode_jer; +jer_type_encoder_f NativeInteger_encode_jer; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_OER_SUPPORT) +oer_type_decoder_f NativeInteger_decode_oer; +oer_type_encoder_f NativeInteger_encode_oer; +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +per_type_decoder_f NativeInteger_decode_uper; +per_type_encoder_f NativeInteger_encode_uper; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +per_type_decoder_f NativeInteger_decode_aper; +per_type_encoder_f NativeInteger_encode_aper; +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#if !defined(ASN_DISABLE_RFILL_SUPPORT) +asn_random_fill_f NativeInteger_random_fill; +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + +#ifdef __cplusplus +} +#endif + +#endif /* _NativeInteger_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger_aper.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger_aper.c new file mode 100644 index 000000000..1d13070a3 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger_aper.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_dec_rval_t +NativeInteger_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_INTEGER_specifics_t *specs = (const asn_INTEGER_specifics_t *)td->specifics; + asn_dec_rval_t rval; + long *native = (long *)*sptr; + INTEGER_t tmpint; + void *tmpintptr = &tmpint; + + (void)opt_codec_ctx; + ASN_DEBUG("Decoding NativeInteger %s (APER)", td->name); + + if(!native) { + native = (long *)(*sptr = CALLOC(1, sizeof(*native))); + if(!native) ASN__DECODE_FAILED; + } + + memset(&tmpint, 0, sizeof tmpint); + rval = INTEGER_decode_aper(opt_codec_ctx, td, constraints, + &tmpintptr, pd); + if(rval.code == RC_OK) { + if((specs&&specs->field_unsigned) + ? asn_INTEGER2ulong(&tmpint, (unsigned long *)native) + : asn_INTEGER2long(&tmpint, native)) + rval.code = RC_FAIL; + else + ASN_DEBUG("NativeInteger %s got value %ld", + td->name, *native); + } + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint); + + return rval; +} + +asn_enc_rval_t +NativeInteger_encode_aper(const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, + const void *sptr, asn_per_outp_t *po) { + + const asn_INTEGER_specifics_t *specs = (const asn_INTEGER_specifics_t *)td->specifics; + asn_enc_rval_t er = {0,0,0}; + long native; + INTEGER_t tmpint; + + if(!sptr) ASN__ENCODE_FAILED; + + native = *(const long *)sptr; + + ASN_DEBUG("Encoding NativeInteger %s %ld (APER)", td->name, native); + + memset(&tmpint, 0, sizeof(tmpint)); + if((specs&&specs->field_unsigned) + ? asn_ulong2INTEGER(&tmpint, (unsigned long)native) + : asn_long2INTEGER(&tmpint, native)) + ASN__ENCODE_FAILED; + er = INTEGER_encode_aper(td, constraints, &tmpint, po); + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint); + return er; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger_print.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger_print.c new file mode 100644 index 000000000..0602e0d20 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger_print.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* + * INTEGER specific human-readable output. + */ +int +NativeInteger_print(const asn_TYPE_descriptor_t *td, const void *sptr, + int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { + const asn_INTEGER_specifics_t *specs = + (const asn_INTEGER_specifics_t *)td->specifics; + const long *native = (const long *)sptr; + char scratch[32]; /* Enough for 64-bit int */ + int ret; + + (void)td; /* Unused argument */ + (void)ilevel; /* Unused argument */ + + if(native) { + long value = *native; + ret = snprintf(scratch, sizeof(scratch), + (specs && specs->field_unsigned) ? "%lu" : "%ld", value); + assert(ret > 0 && (size_t)ret < sizeof(scratch)); + if(cb(scratch, ret, app_key) < 0) return -1; + if(specs && (value >= 0 || !specs->field_unsigned)) { + const asn_INTEGER_enum_map_t *el = + INTEGER_map_value2enum(specs, value); + if(el) { + if(cb(" (", 2, app_key) < 0) return -1; + if(cb(el->enum_name, el->enum_len, app_key) < 0) return -1; + if(cb(")", 1, app_key) < 0) return -1; + } + } + return 0; + } else { + return (cb("", 8, app_key) < 0) ? -1 : 0; + } +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger_rfill.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger_rfill.c new file mode 100644 index 000000000..fddd14968 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger_rfill.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_random_fill_result_t +NativeInteger_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, + const asn_encoding_constraints_t *constraints, + size_t max_length) { + const asn_INTEGER_specifics_t *specs = + (const asn_INTEGER_specifics_t *)td->specifics; + 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}; + long *st = *sptr; + const asn_INTEGER_enum_map_t *emap; + size_t emap_len; + intmax_t value; + int find_inside_map; + + if(max_length == 0) return result_skipped; + + if(st == NULL) { + st = (long *)CALLOC(1, sizeof(*st)); + if(st == NULL) { + return result_failed; + } + } + + if(specs) { + emap = specs->value2enum; + emap_len = specs->map_count; + if(specs->strict_enumeration) { + find_inside_map = emap_len > 0; + } else { + find_inside_map = emap_len ? asn_random_between(0, 1) : 0; + } + } else { + emap = 0; + emap_len = 0; + find_inside_map = 0; + } + + if(find_inside_map) { + assert(emap_len > 0); + value = emap[asn_random_between(0, emap_len - 1)].nat_value; + } else { + static const long variants[] = { + -65536, -65535, -65534, -32769, -32768, -32767, -16385, -16384, + -16383, -257, -256, -255, -254, -129, -128, -127, + -126, -1, 0, 1, 126, 127, 128, 129, + 254, 255, 256, 257, 16383, 16384, 16385, 32767, + 32768, 32769, 65534, 65535, 65536, 65537}; + if(specs && specs->field_unsigned) { + assert(variants[18] == 0); + value = variants[asn_random_between( + 18, sizeof(variants) / sizeof(variants[0]) - 1)]; + } else { + value = variants[asn_random_between( + 0, sizeof(variants) / sizeof(variants[0]) - 1)]; + } + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + if(!constraints || !constraints->per_constraints) + constraints = &td->encoding_constraints; + + const asn_per_constraints_t *ct; + + ct = constraints ? constraints->per_constraints : 0; + if(ct && (ct->value.flags & APC_CONSTRAINED)) { + if(value < ct->value.lower_bound || value > ct->value.upper_bound) { + value = asn_random_between(ct->value.lower_bound, + ct->value.upper_bound); + } + } +#else + if(!constraints) constraints = &td->encoding_constraints; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + } + + *sptr = st; + *st = value; + return result_ok; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger_xer.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger_xer.c new file mode 100644 index 000000000..18ec59af2 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/NativeInteger_xer.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* + * Decode the chunk of XML text encoding INTEGER. + */ +asn_dec_rval_t +NativeInteger_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) { + const asn_INTEGER_specifics_t *specs = + (const asn_INTEGER_specifics_t *)td->specifics; + asn_dec_rval_t rval; + INTEGER_t st; + void *st_ptr = (void *)&st; + long *native = (long *)*sptr; + + if(!native) { + native = (long *)(*sptr = CALLOC(1, sizeof(*native))); + if(!native) ASN__DECODE_FAILED; + } + + memset(&st, 0, sizeof(st)); + rval = INTEGER_decode_xer(opt_codec_ctx, td, &st_ptr, + opt_mname, buf_ptr, size); + if(rval.code == RC_OK) { + long l; + if((specs&&specs->field_unsigned) + ? asn_INTEGER2ulong(&st, (unsigned long *)&l) /* sic */ + : asn_INTEGER2long(&st, &l)) { + rval.code = RC_FAIL; + rval.consumed = 0; + } else { + *native = l; + } + } else { + /* + * Cannot restart from the middle; + * there is no place to save state in the native type. + * Request a continuation from the very beginning. + */ + rval.consumed = 0; + } + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &st); + return rval; +} + + +asn_enc_rval_t +NativeInteger_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 asn_INTEGER_specifics_t *specs = + (const asn_INTEGER_specifics_t *)td->specifics; + char scratch[32]; /* Enough for 64-bit int */ + asn_enc_rval_t er = {0,0,0}; + const long *native = (const long *)sptr; + + (void)ilevel; + (void)flags; + + if(!native) ASN__ENCODE_FAILED; + + er.encoded = snprintf(scratch, sizeof(scratch), + (specs && specs->field_unsigned) + ? "%lu" : "%ld", *native); + if(er.encoded <= 0 || (size_t)er.encoded >= sizeof(scratch) + || cb(scratch, er.encoded, app_key) < 0) + ASN__ENCODE_FAILED; + + ASN__ENCODED_OK(er); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER.c new file mode 100644 index 000000000..c5ab38ea3 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER.c @@ -0,0 +1,535 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include +#include +#include /* for CHAR_BIT */ +#include +#include + +/* + * OBJECT IDENTIFIER basic type description. + */ +static const ber_tlv_tag_t asn_DEF_OBJECT_IDENTIFIER_tags[] = { + (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)) +}; +asn_TYPE_operation_t asn_OP_OBJECT_IDENTIFIER = { + ASN__PRIMITIVE_TYPE_free, +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + OBJECT_IDENTIFIER_print, +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + OCTET_STRING_compare, /* Implemented in terms of a string comparison */ + OCTET_STRING_copy, /* Implemented in terms of a string copy */ +#if !defined(ASN_DISABLE_BER_SUPPORT) + ber_decode_primitive, + der_encode_primitive, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + OBJECT_IDENTIFIER_decode_xer, + OBJECT_IDENTIFIER_encode_xer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + OBJECT_IDENTIFIER_decode_jer, + OBJECT_IDENTIFIER_encode_jer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + OBJECT_IDENTIFIER_decode_oer, + OBJECT_IDENTIFIER_encode_oer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + OCTET_STRING_decode_uper, + OCTET_STRING_encode_uper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + OCTET_STRING_decode_aper, + OCTET_STRING_encode_aper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + OBJECT_IDENTIFIER_random_fill, +#else + 0, +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + 0 /* Use generic outmost tag fetcher */ +}; +asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER = { + "OBJECT IDENTIFIER", + "OBJECT_IDENTIFIER", + &asn_OP_OBJECT_IDENTIFIER, + asn_DEF_OBJECT_IDENTIFIER_tags, + sizeof(asn_DEF_OBJECT_IDENTIFIER_tags) + / sizeof(asn_DEF_OBJECT_IDENTIFIER_tags[0]), + asn_DEF_OBJECT_IDENTIFIER_tags, /* Same as above */ + sizeof(asn_DEF_OBJECT_IDENTIFIER_tags) + / sizeof(asn_DEF_OBJECT_IDENTIFIER_tags[0]), + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + OBJECT_IDENTIFIER_constraint + }, + 0, 0, /* No members */ + 0 /* No specifics */ +}; + +int +OBJECT_IDENTIFIER_constraint(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, + void *app_key) { + const OBJECT_IDENTIFIER_t *st = (const OBJECT_IDENTIFIER_t *)sptr; + + if(st && st->buf) { + if(st->size < 1) { + ASN__CTFAIL(app_key, td, sptr, + "%s: at least one numerical value " + "expected (%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 ssize_t +OBJECT_IDENTIFIER_get_first_arcs(const uint8_t *arcbuf, size_t arcbuf_len, + asn_oid_arc_t *arc0, asn_oid_arc_t *arc1) { + asn_oid_arc_t value; + + ssize_t rd = OBJECT_IDENTIFIER_get_single_arc(arcbuf, arcbuf_len, &value); + if(rd <= 0) return rd; + + if(value >= 80) { + *arc0 = 2; + *arc1 = value - 80; + } else if(value >= 40) { + *arc0 = 1; + *arc1 = value - 40; + } else { + *arc0 = 0; + *arc1 = value; + } + + return rd; +} + +ssize_t +OBJECT_IDENTIFIER_get_single_arc(const uint8_t *arcbuf, size_t arcbuf_len, + asn_oid_arc_t *ret_value) { + const uint8_t *b = arcbuf; + const uint8_t *arcend = arcbuf + arcbuf_len; /* End of arc */ + + if(arcbuf == arcend) { + return 0; + } else { + asn_oid_arc_t accum; + asn_oid_arc_t upper_limit = (ASN_OID_ARC_MAX >> 7); + /* When the value reaches "upper_limit", it can take */ + /* at most one more digit. If it exceeds "upper_limit" */ + /* but there are more digits - it's an Overflow condition */ + /* Gather all bits into the accumulator */ + for(accum = 0; b < arcend; b++) { + accum = (accum << 7) | (*b & ~0x80); + if((*b & 0x80) == 0) { // no more digits + if(accum <= ASN_OID_ARC_MAX) { + *ret_value = accum; + return 1 + (b - arcbuf); + } else { + errno = ERANGE; /* Overflow */ + return -1; + } + } else { // to make sure we aren't wrapping around + if(accum > upper_limit) { + errno = ERANGE; /* Overflow */ + return -1; + } + } + } + errno = EINVAL; + return -1; + } + +} + +ssize_t +OBJECT_IDENTIFIER__dump_body(const OBJECT_IDENTIFIER_t *st, + asn_app_consume_bytes_f *cb, void *app_key) { + char scratch[32]; + asn_oid_arc_t arc0 = 0; + asn_oid_arc_t arc1 = 0; + size_t produced = 0; + size_t off = 0; + ssize_t rd; + int ret; + + rd = OBJECT_IDENTIFIER_get_first_arcs(st->buf, st->size, &arc0, &arc1); + if(rd <= 0) { + return -1; + } + + ret = snprintf(scratch, sizeof(scratch), "%"PRIu32".%"PRIu32, arc0, arc1); + if(ret >= (ssize_t)sizeof(scratch)) { + return -1; + } + produced += ret; + if(cb(scratch, ret, app_key) < 0) + return -1; + + for(off = rd; ; ) { + asn_oid_arc_t arc; + rd = OBJECT_IDENTIFIER_get_single_arc(st->buf + off, st->size - off, + &arc); + if(rd < 0) { + return -1; + } else if(rd == 0) { + /* No more arcs. */ + break; + } else { + off += rd; + assert(off <= st->size); + ret = snprintf(scratch, sizeof(scratch), ".%" PRIu32, arc); + if(ret >= (ssize_t)sizeof(scratch)) { + return -1; + } + produced += ret; + if(cb(scratch, ret, app_key) < 0) return -1; + } + } + + if(off != st->size) { + ASN_DEBUG("Could not scan to the end of Object Identifier"); + return -1; + } + + return produced; +} + +ssize_t +OBJECT_IDENTIFIER_get_arcs(const OBJECT_IDENTIFIER_t *st, asn_oid_arc_t *arcs, + size_t arc_slots) { + asn_oid_arc_t arc0 = 0; + asn_oid_arc_t arc1 = 0; + size_t num_arcs = 0; + size_t off; + ssize_t rd; + + if(!st || !st->buf) { + errno = EINVAL; + return -1; + } + + rd = OBJECT_IDENTIFIER_get_first_arcs(st->buf, st->size, &arc0, &arc1); + if(rd <= 0) { + return -1; + } + num_arcs = 2; + switch(arc_slots) { + default: + case 2: + arcs[1] = arc1; + /* Fall through */ + case 1: + arcs[0] = arc0; + /* Fall through */ + case 0: + break; + } + + for(off = rd; ; ) { + asn_oid_arc_t arc; + rd = OBJECT_IDENTIFIER_get_single_arc(st->buf + off, st->size - off, + &arc); + if(rd < 0) { + return -1; + } else if(rd == 0) { + /* No more arcs. */ + break; + } else { + off += rd; + if(num_arcs < arc_slots) { + arcs[num_arcs] = arc; + } + num_arcs++; + } + } + + if(off != st->size) { + return -1; + } + + return num_arcs; +} + + +/* + * Save the single value as an object identifier arc. + */ +ssize_t +OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, size_t arcbuf_len, + asn_oid_arc_t value) { + /* + * The following conditions must hold: + * assert(arcbuf); + */ + uint8_t scratch[((sizeof(value) * CHAR_BIT + 6) / 7)]; + uint8_t *scratch_end = &scratch[sizeof(scratch)-1]; + uint8_t *b; + size_t result_len; + uint8_t mask; + + for(b = scratch_end, mask = 0; ; mask = 0x80, b--) { + *b = mask | (value & 0x7f); + value >>= 7; + if(!value) { + break; + } + } + + result_len = (scratch_end - b) + 1; + + if(result_len > arcbuf_len) { + return -1; + } + + memcpy(arcbuf, b, result_len); + + return result_len; +} + +int +OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *st, const asn_oid_arc_t *arcs, + size_t arc_slots) { + uint8_t *buf; + uint8_t *bp; + ssize_t wrote; + asn_oid_arc_t arc0; + asn_oid_arc_t arc1; + size_t size; + size_t i; + + if(!st || !arcs || arc_slots < 2) { + errno = EINVAL; + return -1; + } + + arc0 = arcs[0]; + arc1 = arcs[1]; + + if(arc0 <= 1) { + if(arc1 >= 40) { + /* 8.19.4: At most 39 subsequent values (including 0) */ + errno = ERANGE; + return -1; + } + } else if(arc0 == 2) { + if(arc1 > ASN_OID_ARC_MAX - 80) { + errno = ERANGE; + return -1; + } + } else if(arc0 > 2) { + /* 8.19.4: Only three values are allocated from the root node */ + errno = ERANGE; + return -1; + } + + /* + * After above tests it is known that the value of arc0 is completely + * trustworthy (0..2). However, the arc1's value is still meaningless. + */ + + /* + * Roughly estimate the maximum size necessary to encode these arcs. + * This estimation implicitly takes in account the following facts, + * that cancel each other: + * * the first two arcs are encoded in a single value. + * * the first value may require more space (+1 byte) + * * the value of the first arc which is in range (0..2) + */ + size = ((sizeof(asn_oid_arc_t) * CHAR_BIT + 6) / 7) * arc_slots; + bp = buf = (uint8_t *)MALLOC(size + 1); + if(!buf) { + /* ENOMEM */ + return -1; + } + + wrote = OBJECT_IDENTIFIER_set_single_arc(bp, size, arc0 * 40 + arc1); + if(wrote <= 0) { + FREEMEM(buf); + return -1; + } + assert((size_t)wrote <= size); + bp += wrote; + size -= wrote; + + for(i = 2; i < arc_slots; i++) { + wrote = OBJECT_IDENTIFIER_set_single_arc(bp, size, arcs[i]); + if(wrote <= 0) { + FREEMEM(buf); + return -1; + } + assert((size_t)wrote <= size); + bp += wrote; + size -= wrote; + } + + /* + * Replace buffer. + */ + st->size = bp - buf; + bp = st->buf; + st->buf = buf; + st->buf[st->size] = '\0'; + if(bp) FREEMEM(bp); + + return 0; +} + +ssize_t +OBJECT_IDENTIFIER_parse_arcs(const char *oid_text, ssize_t oid_txt_length, + asn_oid_arc_t *arcs, size_t arcs_count, + const char **opt_oid_text_end) { + size_t num_arcs = 0; + const char *oid_end; + enum { + ST_LEADSPACE, + ST_TAILSPACE, + ST_AFTERVALUE, /* Next character ought to be '.' or a space */ + ST_WAITDIGITS /* Next character is expected to be a digit */ + } state = ST_LEADSPACE; + + if(!oid_text || oid_txt_length < -1 || (arcs_count && !arcs)) { + if(opt_oid_text_end) *opt_oid_text_end = oid_text; + errno = EINVAL; + return -1; + } + + if(oid_txt_length == -1) + oid_txt_length = strlen(oid_text); + +#define _OID_CAPTURE_ARC(oid_text, oid_end) \ + do { \ + const char *endp = oid_end; \ + unsigned long value; \ + switch(asn_strtoul_lim(oid_text, &endp, &value)) { \ + case ASN_STRTOX_EXTRA_DATA: \ + case ASN_STRTOX_OK: \ + if(value <= ASN_OID_ARC_MAX) { \ + if(num_arcs < arcs_count) arcs[num_arcs] = value; \ + num_arcs++; \ + oid_text = endp - 1; \ + break; \ + } \ + /* Fall through */ \ + case ASN_STRTOX_ERROR_RANGE: \ + if(opt_oid_text_end) *opt_oid_text_end = oid_text; \ + errno = ERANGE; \ + return -1; \ + case ASN_STRTOX_ERROR_INVAL: \ + case ASN_STRTOX_EXPECT_MORE: \ + if(opt_oid_text_end) *opt_oid_text_end = oid_text; \ + errno = EINVAL; \ + return -1; \ + } \ + } while(0) + + for(oid_end = oid_text + oid_txt_length; oid_text broken OID */ + return -1; + case ST_LEADSPACE: + case ST_WAITDIGITS: + _OID_CAPTURE_ARC(oid_text, oid_end); + state = ST_AFTERVALUE; + continue; + } + break; + default: + /* Unexpected symbols */ + state = ST_WAITDIGITS; + break; + } /* switch() */ + break; + } /* for() */ + + + if(opt_oid_text_end) *opt_oid_text_end = oid_text; + + /* Finalize last arc */ + switch(state) { + case ST_LEADSPACE: + return 0; /* No OID found in input data */ + case ST_WAITDIGITS: + errno = EINVAL; /* Broken OID */ + return -1; + case ST_AFTERVALUE: + case ST_TAILSPACE: + return num_arcs; + } + + errno = EINVAL; /* Broken OID */ + return -1; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER.h new file mode 100644 index 000000000..cef8c6cde --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER.h @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _OBJECT_IDENTIFIER_H_ +#define _OBJECT_IDENTIFIER_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef uint32_t asn_oid_arc_t; +#define ASN_OID_ARC_MAX (~((asn_oid_arc_t)0)) + +typedef ASN__PRIMITIVE_TYPE_t OBJECT_IDENTIFIER_t; + +extern asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER; +extern asn_TYPE_operation_t asn_OP_OBJECT_IDENTIFIER; + +ssize_t OBJECT_IDENTIFIER__dump_body(const OBJECT_IDENTIFIER_t *st, + asn_app_consume_bytes_f *cb, + void *app_key); + +#define OBJECT_IDENTIFIER_free ASN__PRIMITIVE_TYPE_free + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +asn_struct_print_f OBJECT_IDENTIFIER_print; +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +#define OBJECT_IDENTIFIER_compare OCTET_STRING_compare +#define OBJECT_IDENTIFIER_copy OCTET_STRING_copy + +asn_constr_check_f OBJECT_IDENTIFIER_constraint; + +#if !defined(ASN_DISABLE_BER_SUPPORT) +#define OBJECT_IDENTIFIER_decode_ber ber_decode_primitive +#define OBJECT_IDENTIFIER_encode_der der_encode_primitive +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +xer_type_decoder_f OBJECT_IDENTIFIER_decode_xer; +xer_type_encoder_f OBJECT_IDENTIFIER_encode_xer; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +jer_type_decoder_f OBJECT_IDENTIFIER_decode_jer; +jer_type_encoder_f OBJECT_IDENTIFIER_encode_jer; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_OER_SUPPORT) +#define OBJECT_IDENTIFIER_decode_oer oer_decode_primitive +#define OBJECT_IDENTIFIER_encode_oer oer_encode_primitive +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +#define OBJECT_IDENTIFIER_decode_uper OCTET_STRING_decode_uper +#define OBJECT_IDENTIFIER_encode_uper OCTET_STRING_encode_uper +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +#define OBJECT_IDENTIFIER_decode_aper OCTET_STRING_decode_aper +#define OBJECT_IDENTIFIER_encode_aper OCTET_STRING_encode_aper +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#if !defined(ASN_DISABLE_RFILL_SUPPORT) +asn_random_fill_f OBJECT_IDENTIFIER_random_fill; +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + +/********************************** + * Some handy conversion routines * + **********************************/ + +/* + * This function fills an (arcs) array with OBJECT IDENTIFIER arcs + * up to specified (arc_slots) elements. + * + * EXAMPLE: + * void print_arcs(OBJECT_IDENTIFIER_t *oid) { + * asn_oid_arc_t fixed_arcs[10]; // Try with fixed space first + * asn_oid_arc_t *arcs = fixed_arcs; + * size_t arc_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10 + * ssize_t count; // Real number of arcs. + * int i; + * + * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, arc_slots); + * // If necessary, reallocate arcs array and try again. + * if(count > arc_slots) { + * arc_slots = count; + * arcs = malloc(sizeof(asn_oid_arc_t) * arc_slots); + * if(!arcs) return; + * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, arc_slots); + * assert(count == arc_slots); + * } + * + * // Print the contents of the arcs array. + * for(i = 0; i < count; i++) + * printf("%"PRIu32"\n", arcs[i]); + * + * // Avoid memory leak. + * if(arcs != fixed_arcs) free(arcs); + * } + * + * RETURN VALUES: + * -1/EINVAL: Invalid arguments (oid is missing) + * -1/ERANGE: One or more arcs have value out of array cell type range. + * >=0: Number of arcs contained in the OBJECT IDENTIFIER + * + * WARNING: The function always returns the actual number of arcs, + * even if there is no sufficient (arc_slots) provided. + */ +ssize_t OBJECT_IDENTIFIER_get_arcs(const OBJECT_IDENTIFIER_t *oid, + asn_oid_arc_t *arcs, size_t arc_slots); + +/* + * This functions initializes the OBJECT IDENTIFIER object with + * the given set of arcs. + * The minimum of two arcs must be present; some restrictions apply. + * RETURN VALUES: + * -1/EINVAL: Invalid arguments + * -1/ERANGE: The first two arcs do not conform to ASN.1 restrictions. + * -1/ENOMEM: Memory allocation failed + * 0: The object was initialized with new arcs. + */ +int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *oid, + const asn_oid_arc_t *arcs, size_t arcs_count); + + +/* + * Parse the OBJECT IDENTIFIER textual representation ("1.3.6.1.4.1.9363"). + * No arc can exceed the (0..ASN_OID_ARC_MAX, which is the same as UINT32_MAX). + * This function is not specific to OBJECT IDENTIFIER, it may be used to parse + * the RELATIVE-OID data, or any other data consisting of dot-separated + * series of numeric values. + * + * If (oid_txt_length == -1), the strlen() will be invoked to determine the + * size of the (oid_text) string. + * + * After return, the optional (opt_oid_text_end) is set to the character after + * the last parsed one. (opt_oid_text_end) is never less than (oid_text). + * + * RETURN VALUES: + * -1: Parse error. + * >= 0: Number of arcs contained in the OBJECT IDENTIFIER. + * + * WARNING: The function always returns the real number of arcs, + * even if there is no sufficient (arc_slots) provided. + * This is useful for (arc_slots) value estimation. + */ +ssize_t OBJECT_IDENTIFIER_parse_arcs(const char *oid_text, + ssize_t oid_txt_length, + asn_oid_arc_t *arcs, size_t arcs_count, + const char **opt_oid_text_end); + +/* + * Internal functions. + * Used by RELATIVE-OID implementation in particular. + */ + +/* + * Retrieve a single arc of size from the (arcbuf) buffer. + * RETURN VALUES: + * -1: Failed to retrieve the value from the (arcbuf). + * >0: Number of bytes consumed from the (arcbuf), <= (arcbuf_len). + */ +ssize_t OBJECT_IDENTIFIER_get_single_arc(const uint8_t *arcbuf, + size_t arcbuf_len, + asn_oid_arc_t *ret_value); + +/* + * Write the unterminated arc value into the (arcbuf) which has the size at + * least (arcbuf_len). + * RETURN VALUES: + * -1: (arcbuf_len) size is not sufficient to write the value. + * : Number of bytes appended to the arcbuf (<= arcbuf_len). + */ +ssize_t OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, size_t arcbuf_len, + asn_oid_arc_t arc_value); + +#ifdef __cplusplus +} +#endif + +#endif /* _OBJECT_IDENTIFIER_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER_print.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER_print.c new file mode 100644 index 000000000..b0c3a9e84 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER_print.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +int +OBJECT_IDENTIFIER_print(const asn_TYPE_descriptor_t *td, const void *sptr, + int ilevel, asn_app_consume_bytes_f *cb, + void *app_key) { + const OBJECT_IDENTIFIER_t *st = (const OBJECT_IDENTIFIER_t *)sptr; + + (void)td; /* Unused argument */ + (void)ilevel; /* Unused argument */ + + if(!st || !st->buf) + return (cb("", 8, app_key) < 0) ? -1 : 0; + + /* Dump preamble */ + if(cb("{ ", 2, app_key) < 0) + return -1; + + if(OBJECT_IDENTIFIER__dump_body(st, cb, app_key) < 0) { + return -1; + } + + return (cb(" }", 2, app_key) < 0) ? -1 : 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER_rfill.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER_rfill.c new file mode 100644 index 000000000..55093c8e1 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER_rfill.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* + * Generate values from the list of interesting values, or just a random + * value up to the upper limit. + */ +static asn_oid_arc_t +OBJECT_IDENTIFIER__biased_random_arc(asn_oid_arc_t upper_bound) { + const asn_oid_arc_t values[] = {0, 1, 127, 128, 129, 254, 255, 256}; + size_t idx; + + switch(asn_random_between(0, 2)) { + case 0: + idx = asn_random_between(0, sizeof(values) / sizeof(values[0]) - 1); + if(values[idx] < upper_bound) { + return values[idx]; + } + /* Fall through */ + case 1: + return asn_random_between(0, upper_bound); + case 2: + default: + return upper_bound; + } +} + +asn_random_fill_result_t +OBJECT_IDENTIFIER_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, + const asn_encoding_constraints_t *constraints, + size_t max_length) { + 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}; + OBJECT_IDENTIFIER_t *st; + asn_oid_arc_t arcs[5]; + size_t arcs_len = asn_random_between(2, 5); + size_t i; + + (void)constraints; + + if(max_length < arcs_len) return result_skipped; + + if(*sptr) { + st = *sptr; + } else { + st = CALLOC(1, sizeof(*st)); + } + + arcs[0] = asn_random_between(0, 2); + arcs[1] = OBJECT_IDENTIFIER__biased_random_arc( + arcs[0] <= 1 ? 39 : (ASN_OID_ARC_MAX - 80)); + for(i = 2; i < arcs_len; i++) { + arcs[i] = OBJECT_IDENTIFIER__biased_random_arc(ASN_OID_ARC_MAX); + } + + if(OBJECT_IDENTIFIER_set_arcs(st, arcs, arcs_len)) { + if(st != *sptr) { + ASN_STRUCT_FREE(*td, st); + } + return result_failed; + } + + *sptr = st; + + result_ok.length = st->size; + return result_ok; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER_xer.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER_xer.c new file mode 100644 index 000000000..706e51a94 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OBJECT_IDENTIFIER_xer.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +static enum xer_pbd_rval +OBJECT_IDENTIFIER__xer_body_decode(const asn_TYPE_descriptor_t *td, void *sptr, + const void *chunk_buf, size_t chunk_size) { + OBJECT_IDENTIFIER_t *st = (OBJECT_IDENTIFIER_t *)sptr; + const char *chunk_end = (const char *)chunk_buf + chunk_size; + const char *endptr; + asn_oid_arc_t s_arcs[10]; + asn_oid_arc_t *arcs = s_arcs; + ssize_t num_arcs; + ssize_t ret; + + (void)td; + + num_arcs = OBJECT_IDENTIFIER_parse_arcs( + (const char *)chunk_buf, chunk_size, arcs, + sizeof(s_arcs) / sizeof(s_arcs[0]), &endptr); + if(num_arcs < 0) { + /* Expecting more than zero arcs */ + return XPBD_BROKEN_ENCODING; + } else if(num_arcs == 0) { + return XPBD_NOT_BODY_IGNORE; + } + (void)chunk_end; + assert(endptr == chunk_end); + + if((size_t)num_arcs > sizeof(s_arcs)/sizeof(s_arcs[0])) { + arcs = (asn_oid_arc_t *)MALLOC(num_arcs * sizeof(asn_oid_arc_t)); + if(!arcs) return XPBD_SYSTEM_FAILURE; + ret = OBJECT_IDENTIFIER_parse_arcs((const char *)chunk_buf, chunk_size, + arcs, num_arcs, &endptr); + if(ret != num_arcs) + return XPBD_SYSTEM_FAILURE; /* assert?.. */ + } + + /* + * Convert arcs into BER representation. + */ + ret = OBJECT_IDENTIFIER_set_arcs(st, arcs, num_arcs); + if(arcs != s_arcs) FREEMEM(arcs); + + return ret ? XPBD_SYSTEM_FAILURE : XPBD_BODY_CONSUMED; +} + +asn_dec_rval_t +OBJECT_IDENTIFIER_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) { + return xer_decode_primitive(opt_codec_ctx, td, + sptr, sizeof(OBJECT_IDENTIFIER_t), opt_mname, + buf_ptr, size, OBJECT_IDENTIFIER__xer_body_decode); +} + +asn_enc_rval_t +OBJECT_IDENTIFIER_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 OBJECT_IDENTIFIER_t *st = (const OBJECT_IDENTIFIER_t *)sptr; + asn_enc_rval_t er = {0,0,0}; + + (void)ilevel; + (void)flags; + + if(!st || !st->buf) { + ASN__ENCODE_FAILED; + } + + er.encoded = OBJECT_IDENTIFIER__dump_body(st, cb, app_key); + if(er.encoded < 0) ASN__ENCODE_FAILED; + + ASN__ENCODED_OK(er); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING.c new file mode 100644 index 000000000..fc983b4e2 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING.c @@ -0,0 +1,423 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +/* + * 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, +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + OCTET_STRING_print, /* OCTET STRING generally means a non-ascii sequence */ +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + OCTET_STRING_compare, + OCTET_STRING_copy, +#if !defined(ASN_DISABLE_BER_SUPPORT) + OCTET_STRING_decode_ber, + OCTET_STRING_encode_der, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + OCTET_STRING_decode_xer_hex, + OCTET_STRING_encode_xer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + OCTET_STRING_decode_jer_hex, + OCTET_STRING_encode_jer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + OCTET_STRING_decode_oer, + OCTET_STRING_encode_oer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + OCTET_STRING_decode_uper, /* Unaligned PER decoder */ + OCTET_STRING_encode_uper, /* Unaligned PER encoder */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + OCTET_STRING_decode_aper, /* Aligned PER decoder */ + OCTET_STRING_encode_aper, /* Aligned PER encoder */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + OCTET_STRING_random_fill, +#else + 0, +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + 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]), + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + asn_generic_no_constraint + }, + 0, 0, /* No members */ + &asn_SPC_OCTET_STRING_specs +}; + +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; + + if(!td || !st) + return; + + ASN_DEBUG("Freeing %s as OCTET STRING", td->name); + + if(st->buf) { + FREEMEM(st->buf); + st->buf = 0; + } + +#if !defined(ASN_DISABLE_BER_SUPPORT) + const asn_OCTET_STRING_specifics_t *specs; + asn_struct_ctx_t *ctx; + + 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); + + /* + * Remove decode-time stack. + */ + struct _stack *stck; + stck = (struct _stack *)ctx->ptr; + if(stck) { + while(stck->tail) { + struct _stack_el *sel = stck->tail; + stck->tail = sel->prev; + FREEMEM(sel); + } + FREEMEM(stck); + } +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + + 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; + + (void)specs; + 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; + } + +} + +int +OCTET_STRING_copy(const asn_TYPE_descriptor_t *td, void **aptr, + const void *bptr) { + 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 *a = *aptr; + const OCTET_STRING_t *b = bptr; + + if(!b) { + if(a) { + FREEMEM(a->buf); + a->buf = 0; + a->size = 0; + FREEMEM(a); + } + *aptr = 0; + return 0; + } + + if(!a) { + a = *aptr = (OCTET_STRING_t *)CALLOC(1, specs->struct_size); + if(!a) return -1; + } + + void *buf = MALLOC(b->size + 1); + if(!buf) return -1; + memcpy(buf, b->buf, b->size); + ((uint8_t *)buf)[b->size] = '\0'; + + FREEMEM(a->buf); + a->buf = (uint8_t *)buf; + a->size = b->size; + + return 0; +} + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +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; +} + +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; +} +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING.h new file mode 100644 index 000000000..1340865da --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING.h @@ -0,0 +1,168 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _OCTET_STRING_H_ +#define _OCTET_STRING_H_ + +#include + +#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; + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +asn_struct_print_f OCTET_STRING_print; +asn_struct_print_f OCTET_STRING_print_utf8; +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +asn_struct_compare_f OCTET_STRING_compare; +asn_struct_copy_f OCTET_STRING_copy; + +#define OCTET_STRING_constraint asn_generic_no_constraint + +#if !defined(ASN_DISABLE_BER_SUPPORT) +ber_type_decoder_f OCTET_STRING_decode_ber; +der_type_encoder_f OCTET_STRING_encode_der; +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +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; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +jer_type_decoder_f OCTET_STRING_decode_jer_hex; /* Hexadecimal */ +jer_type_decoder_f OCTET_STRING_decode_jer_utf8; /* ASCII/UTF-8 */ +jer_type_encoder_f OCTET_STRING_encode_jer; +jer_type_encoder_f OCTET_STRING_encode_jer_utf8; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_OER_SUPPORT) +oer_type_decoder_f OCTET_STRING_decode_oer; +oer_type_encoder_f OCTET_STRING_encode_oer; +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +per_type_decoder_f OCTET_STRING_decode_uper; +per_type_encoder_f OCTET_STRING_encode_uper; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +per_type_decoder_f OCTET_STRING_decode_aper; +per_type_encoder_f OCTET_STRING_encode_aper; +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#if !defined(ASN_DISABLE_RFILL_SUPPORT) +asn_random_fill_f OCTET_STRING_random_fill; +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +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); + +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); +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +/****************************** + * 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); + +#if !defined(ASN_DISABLE_BER_SUPPORT) +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; +}; +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#ifdef __cplusplus +} +#endif + +#endif /* _OCTET_STRING_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING_aper.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING_aper.c new file mode 100644 index 000000000..260138319 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING_aper.c @@ -0,0 +1,413 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include /* for .bits_unused member */ + +#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_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_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 %lld .. %lld bits %d", + csiz->flags & APC_EXTENSIBLE ? "extensible" : "non-extensible", + (long long int)csiz->lower_bound, (long long int)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; + /* X.691 #16 NOTE 1 for fixed length (<= 16 bits) strings */ + if (st->size > 2 || csiz->range_bits != 0) { + if (aper_get_align(pd) < 0) + RETURN(RC_FAIL); + } + if(bpc) { + ASN_DEBUG("Decoding OCTET STRING size %lld", + (long long int)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 %lld", + (long long int)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; + + repeat = 0; + /* Get the PER length */ + if (csiz->upper_bound - csiz->lower_bound == 0) + /* Indefinite length case */ + raw_len = aper_get_length(pd, -1, -1, csiz->effective_bits, &repeat); + else + raw_len = aper_get_length(pd, csiz->lower_bound, csiz->upper_bound, + csiz->effective_bits, &repeat); + if(raw_len < 0) RETURN(RC_WMORE); + + ASN_DEBUG("Got PER length eb %ld, len %ld, %s (%s)", + (long)csiz->effective_bits, (long)raw_len, + repeat ? "repeat" : "once", td->name); + + /* X.691 #16 NOTE 1 for fixed length (<=16 bits) strings */ + if ((raw_len > 2) || (csiz->upper_bound > 2) || (csiz->range_bits != 0)) + { + 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" + " (%lld..%lld, effective %d)%s", + td->name, sizeinunits, unit_bits, + (long long int)csiz->lower_bound, + (long long int)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 %zu bytes (%lld), length in %d bits", + st->size, (long long int)(sizeinunits - csiz->lower_bound), + csiz->effective_bits); + if (csiz->effective_bits > 0) { + ret = aper_put_length(po, csiz->lower_bound, csiz->upper_bound, + sizeinunits - csiz->lower_bound, NULL); + if(ret < 0) ASN__ENCODE_FAILED; + } + if (csiz->effective_bits > 0 || (st->size > 2) + || (csiz->upper_bound > (2 * 8 / unit_bits)) + || (csiz->range_bits != 0)) + { /* X.691 #16 NOTE 1 for fixed length (<=16 bits) strings*/ + 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 %zu bytes", st->size); + + if(sizeinunits == 0) { + if(aper_put_length(po, -1, -1, 0, NULL) < 0) + ASN__ENCODE_FAILED; + ASN__ENCODED_OK(er); + } + + buf = st->buf; + while(sizeinunits) { + int need_eom = 0; + ssize_t maySave = aper_put_length(po, -1, -1, sizeinunits, &need_eom); + + 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); + if(need_eom && (aper_put_length(po, -1, -1, 0, NULL) < 0)) + ASN__ENCODE_FAILED; /* End of Message length */ + } + + ASN__ENCODED_OK(er); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING_print.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING_print.c new file mode 100644 index 000000000..6daa33e9f --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING_print.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +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("", 8, app_key) < 0) ? -1 : 0; + + /* + * Dump the contents of the buffer in hexadecimal. + */ + buf = st->buf; + end = (buf == NULL)? NULL : 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("", 8, app_key) < 0) ? -1 : 0; + } +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING_rfill.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING_rfill.c new file mode 100644 index 000000000..5c8b0648e --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING_rfill.c @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* + * 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); + } +} + +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 !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 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; + } + } +#else + if(!constraints) constraints = &td->encoding_constraints; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + + 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; +} + +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 !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 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 { +#else + if(!constraints) constraints = &td->encoding_constraints; + { +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + if(rnd_len > max_length) { + rnd_len = asn_random_between(0, max_length); + } + } + + return rnd_len; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING_xer.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING_xer.c new file mode 100644 index 000000000..490f362a9 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OCTET_STRING_xer.c @@ -0,0 +1,627 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include /* for .bits_unused member */ + +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"), /* */ + OSXET("\074\163\157\150\057\076"), /* */ + OSXET("\074\163\164\170\057\076"), /* */ + OSXET("\074\145\164\170\057\076"), /* */ + OSXET("\074\145\157\164\057\076"), /* */ + OSXET("\074\145\156\161\057\076"), /* */ + OSXET("\074\141\143\153\057\076"), /* */ + OSXET("\074\142\145\154\057\076"), /* */ + OSXET("\074\142\163\057\076"), /* */ + OSXET("\011"), /* \t */ + OSXET("\012"), /* \n */ + OSXET("\074\166\164\057\076"), /* */ + OSXET("\074\146\146\057\076"), /* */ + OSXET("\015"), /* \r */ + OSXET("\074\163\157\057\076"), /* */ + OSXET("\074\163\151\057\076"), /* */ + OSXET("\074\144\154\145\057\076"), /* */ + OSXET("\074\144\143\061\057\076"), /* */ + OSXET("\074\144\143\062\057\076"), /* */ + OSXET("\074\144\143\063\057\076"), /* */ + OSXET("\074\144\143\064\057\076"), /* */ + OSXET("\074\156\141\153\057\076"), /* */ + OSXET("\074\163\171\156\057\076"), /* */ + OSXET("\074\145\164\142\057\076"), /* */ + OSXET("\074\143\141\156\057\076"), /* */ + OSXET("\074\145\155\057\076"), /* */ + OSXET("\074\163\165\142\057\076"), /* */ + OSXET("\074\145\163\143\057\076"), /* */ + OSXET("\074\151\163\064\057\076"), /* */ + OSXET("\074\151\163\063\057\076"), /* */ + OSXET("\074\151\163\062\057\076"), /* */ + OSXET("\074\151\163\061\057\076"), /* */ + { 0, 0 }, /* " " */ + { 0, 0 }, /* ! */ + { 0, 0 }, /* \" */ + { 0, 0 }, /* # */ + { 0, 0 }, /* $ */ + { 0, 0 }, /* % */ + OSXET("\046\141\155\160\073"), /* & */ + { 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"), /* < */ + { 0, 0 }, /* = */ + OSXET("\046\147\164\073"), /* > */ +}; + +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 == NULL)? NULL : 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 < 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 & > < + */ + 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); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OPEN_TYPE.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OPEN_TYPE.c new file mode 100644 index 000000000..75f9b9585 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OPEN_TYPE.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +asn_TYPE_operation_t asn_OP_OPEN_TYPE = { + OPEN_TYPE_free, +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + OPEN_TYPE_print, +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + OPEN_TYPE_compare, + OPEN_TYPE_copy, +#if !defined(ASN_DISABLE_BER_SUPPORT) + OPEN_TYPE_decode_ber, + OPEN_TYPE_encode_der, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + OPEN_TYPE_decode_xer, + OPEN_TYPE_encode_xer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + OPEN_TYPE_decode_jer, + OPEN_TYPE_encode_jer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + OPEN_TYPE_decode_oer, + OPEN_TYPE_encode_oer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + OPEN_TYPE_decode_uper, + OPEN_TYPE_encode_uper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + OPEN_TYPE_decode_aper, + OPEN_TYPE_encode_aper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + 0, /* Random fill is not supported for open type */ +#else + 0, +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + 0 /* Use generic outmost tag fetcher */ +}; diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OPEN_TYPE.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OPEN_TYPE.h new file mode 100644 index 000000000..c4b5d1b81 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OPEN_TYPE.h @@ -0,0 +1,128 @@ +/*- + * Copyright (c) 2017-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_OPEN_TYPE_H +#define ASN_OPEN_TYPE_H + +#include +///////////#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Decode an Open Type which is potentially constraiend + * by the other members of the parent structure. + */ + +#undef ADVANCE +#define ADVANCE(num_bytes) \ + do { \ + size_t num = num_bytes; \ + ptr = ((const char *)ptr) + num; \ + size -= num; \ + consumed_myself += num; \ + } while(0) + +#define OPEN_TYPE_free CHOICE_free + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +#define OPEN_TYPE_print CHOICE_print +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +#define OPEN_TYPE_compare CHOICE_compare +#define OPEN_TYPE_copy CHOICE_copy + +#define OPEN_TYPE_constraint CHOICE_constraint + +#if !defined(ASN_DISABLE_BER_SUPPORT) +asn_dec_rval_t OPEN_TYPE_ber_get( + const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *parent_type, + void *parent_structure, + const asn_TYPE_member_t *element, + const void *ptr, size_t size); +#define OPEN_TYPE_decode_ber NULL +#define OPEN_TYPE_encode_der CHOICE_encode_der +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +asn_dec_rval_t OPEN_TYPE_xer_get( + const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *parent_type, + void *parent_structure, + const asn_TYPE_member_t *element, + const void *ptr, size_t size); +#define OPEN_TYPE_decode_xer NULL +#define OPEN_TYPE_encode_xer CHOICE_encode_xer +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +asn_dec_rval_t OPEN_TYPE_jer_get( + const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *parent_type, + void *parent_structure, + const asn_TYPE_member_t *element, + const void *ptr, size_t size); +#define OPEN_TYPE_decode_jer NULL +#define OPEN_TYPE_encode_jer CHOICE_encode_jer +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_OER_SUPPORT) +asn_dec_rval_t OPEN_TYPE_oer_get( + const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *parent_type, + void *parent_structure, + asn_TYPE_member_t *element, const void *ptr, + size_t size); +#define OPEN_TYPE_decode_oer NULL +asn_enc_rval_t OPEN_TYPE_encode_oer( + const asn_TYPE_descriptor_t *type_descriptor, + const asn_oer_constraints_t *constraints, const void *struct_ptr, + asn_app_consume_bytes_f *consume_bytes_cb, void *app_key); +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +asn_dec_rval_t OPEN_TYPE_uper_get( + const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *parent_type, + void *parent_structure, + const asn_TYPE_member_t *element, + asn_per_data_t *pd); +#define OPEN_TYPE_decode_uper NULL +asn_enc_rval_t OPEN_TYPE_encode_uper( + const asn_TYPE_descriptor_t *type_descriptor, + const asn_per_constraints_t *constraints, const void *struct_ptr, + asn_per_outp_t *per_output); +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +asn_dec_rval_t OPEN_TYPE_aper_get( + const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *parent_type, + void *parent_structure, + const asn_TYPE_member_t *element, + asn_per_data_t *pd); +#define OPEN_TYPE_decode_aper NULL +asn_enc_rval_t OPEN_TYPE_encode_aper( + const asn_TYPE_descriptor_t *type_descriptor, + const asn_per_constraints_t *constraints, const void *struct_ptr, + asn_per_outp_t *per_output); + +int OPEN_TYPE_aper_is_unknown_type( + const asn_TYPE_descriptor_t *td, + void *sptr, + const asn_TYPE_member_t *elm); + +asn_dec_rval_t OPEN_TYPE_aper_unknown_type_discard_bytes( + asn_per_data_t *pd); +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +extern asn_TYPE_operation_t asn_OP_OPEN_TYPE; + +#ifdef __cplusplus +} +#endif + +#endif /* ASN_OPEN_TYPE_H */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OPEN_TYPE_aper.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OPEN_TYPE_aper.c new file mode 100644 index 000000000..78799ff6d --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OPEN_TYPE_aper.c @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include +#include + +asn_dec_rval_t +OPEN_TYPE_aper_get(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void *sptr, + const asn_TYPE_member_t *elm, asn_per_data_t *pd) { + asn_type_selector_result_t selected; + void *memb_ptr; /* Pointer to the member */ + void **memb_ptr2; /* Pointer to that pointer */ + void *inner_value; + asn_dec_rval_t rv; + + if(!(elm->flags & ATF_OPEN_TYPE)) { + ASN__DECODE_FAILED; + } + + if(!elm->type_selector) { + ASN_DEBUG("Type selector is not defined for Open Type %s->%s->%s", + td->name, elm->name, elm->type->name); + ASN__DECODE_FAILED; + } + + selected = elm->type_selector(td, sptr); + if(!selected.presence_index) { + ASN__DECODE_FAILED; + } + + /* Fetch the pointer to this member */ + assert(elm->flags == ATF_OPEN_TYPE); + if(elm->flags & ATF_POINTER) { + memb_ptr2 = (void **)((char *)sptr + elm->memb_offset); + } else { + memb_ptr = (char *)sptr + elm->memb_offset; + memb_ptr2 = &memb_ptr; + } + if(*memb_ptr2 != NULL) { + /* Make sure we reset the structure first before encoding */ + if(CHOICE_variant_set_presence(elm->type, *memb_ptr2, 0) + != 0) { + ASN__DECODE_FAILED; + } + } + + inner_value = + (char *)*memb_ptr2 + + elm->type->elements[selected.presence_index - 1].memb_offset; + + rv = aper_open_type_get(opt_codec_ctx, selected.type_descriptor, + elm->type->elements[selected.presence_index - 1].encoding_constraints.per_constraints, + &inner_value, pd); + switch(rv.code) { + case RC_OK: + if(CHOICE_variant_set_presence(elm->type, *memb_ptr2, + selected.presence_index) + == 0) { + break; + } else { + rv.code = RC_FAIL; + } + /* Fall through */ + case RC_WMORE: + case RC_FAIL: + if(*memb_ptr2) { + if(elm->flags & ATF_POINTER) { + ASN_STRUCT_FREE(*selected.type_descriptor, inner_value); + *memb_ptr2 = NULL; + } else { + ASN_STRUCT_RESET(*selected.type_descriptor, + inner_value); + } + } + } + return rv; +} + +asn_enc_rval_t +OPEN_TYPE_encode_aper(const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, + const void *sptr, asn_per_outp_t *po) { + const void *memb_ptr; /* Pointer to the member */ + asn_TYPE_member_t *elm; /* CHOICE's element */ + asn_enc_rval_t er = {0,0,0}; + unsigned present; + + (void)constraints; + + present = CHOICE_variant_get_presence(td, sptr); + if(present == 0 || present > td->elements_count) { + ASN__ENCODE_FAILED; + } else { + present--; + } + + ASN_DEBUG("Encoding %s OPEN TYPE element %d", td->name, present); + + elm = &td->elements[present]; + if(elm->flags & ATF_POINTER) { + /* Member is a pointer to another structure */ + memb_ptr = + *(const void *const *)((const char *)sptr + elm->memb_offset); + if(!memb_ptr) ASN__ENCODE_FAILED; + } else { + memb_ptr = (const char *)sptr + elm->memb_offset; + } + + if(aper_open_type_put(elm->type, elm->encoding_constraints.per_constraints, memb_ptr, po) < 0) { + ASN__ENCODE_FAILED; + } + + er.encoded = 0; + ASN__ENCODED_OK(er); +} + + +int OPEN_TYPE_aper_is_unknown_type(const asn_TYPE_descriptor_t *td, void *sptr, const asn_TYPE_member_t *elm) { + asn_type_selector_result_t selected; + + if(!elm->type_selector) { + return 1; + } + else { + selected = elm->type_selector(td, sptr); + if(!selected.presence_index) { + return 1; + } + } + return 0; +} + +asn_dec_rval_t +OPEN_TYPE_aper_unknown_type_discard_bytes (asn_per_data_t *pd) { +#define ASN_DUMMY_BYTES 256 + unsigned char dummy[ASN_DUMMY_BYTES], *dummy_ptr = NULL; + ssize_t bytes; + int repeat; + asn_dec_rval_t rv; + + rv.consumed = 0; + rv.code = RC_FAIL; + + do { + bytes = aper_get_length(pd, -1, -1, -1, &repeat); + if (bytes > 10 * ASN_DUMMY_BYTES) + { + return rv; + } + else if (bytes > ASN_DUMMY_BYTES) + { + dummy_ptr = CALLOC(1, bytes); + if (!dummy_ptr) + return rv; + } + + per_get_many_bits(pd, (dummy_ptr ? dummy_ptr : dummy), 0, bytes << 3); + + if (dummy_ptr) + { + FREEMEM(dummy_ptr); + dummy_ptr = NULL; + } + } while (repeat); + + rv.code = RC_OK; + return rv; +#undef ASN_DUMMY_BYTES +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OPEN_TYPE_xer.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OPEN_TYPE_xer.c new file mode 100644 index 000000000..fc38562e9 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/OPEN_TYPE_xer.c @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +asn_dec_rval_t +OPEN_TYPE_xer_get(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void *sptr, + const asn_TYPE_member_t *elm, const void *ptr, size_t size) { + size_t consumed_myself = 0; + asn_type_selector_result_t selected; + void *memb_ptr; /* Pointer to the member */ + void **memb_ptr2; /* Pointer to that pointer */ + void *inner_value; + asn_dec_rval_t rv; + + int xer_context = 0; + ssize_t ch_size; + pxer_chunk_type_e ch_type; + + if(!(elm->flags & ATF_OPEN_TYPE)) { + ASN__DECODE_FAILED; + } + + if(!elm->type_selector) { + ASN_DEBUG("Type selector is not defined for Open Type %s->%s->%s", + td->name, elm->name, elm->type->name); + ASN__DECODE_FAILED; + } + + selected = elm->type_selector(td, sptr); + if(!selected.presence_index) { + ASN__DECODE_FAILED; + } + + /* Fetch the pointer to this member */ + assert(elm->flags == ATF_OPEN_TYPE); + if(elm->flags & ATF_POINTER) { + memb_ptr2 = (void **)((char *)sptr + elm->memb_offset); + } else { + memb_ptr = (char *)sptr + elm->memb_offset; + memb_ptr2 = &memb_ptr; + } + if(*memb_ptr2 != NULL) { + /* Make sure we reset the structure first before encoding */ + if(CHOICE_variant_set_presence(elm->type, *memb_ptr2, 0) + != 0) { + ASN__DECODE_FAILED; + } + } + + /* + * Confirm wrapper. + */ + for(;;) { + ch_size = xer_next_token(&xer_context, ptr, size, &ch_type); + if(ch_size < 0) { + ASN__DECODE_FAILED; + } else { + switch(ch_type) { + case PXER_WMORE: + ASN__DECODE_STARVED; + case PXER_COMMENT: + case PXER_TEXT: + ADVANCE(ch_size); + continue; + case PXER_TAG: + break; + } + break; + } + } + + /* + * Wrapper value confirmed. + */ + switch(xer_check_tag(ptr, ch_size, elm->name)) { + case XCT_OPENING: + ADVANCE(ch_size); + break; + case XCT_BROKEN: + default: + ASN__DECODE_FAILED; + } + + inner_value = + (char *)*memb_ptr2 + + elm->type->elements[selected.presence_index - 1].memb_offset; + + rv = selected.type_descriptor->op->xer_decoder( + opt_codec_ctx, selected.type_descriptor, &inner_value, NULL, ptr, size); + ADVANCE(rv.consumed); + rv.consumed = 0; + switch(rv.code) { + case RC_OK: + if(CHOICE_variant_set_presence(elm->type, *memb_ptr2, + selected.presence_index) + == 0) { + break; + } else { + rv.code = RC_FAIL; + } + /* Fall through */ + case RC_FAIL: + /* Point to a best position where failure occurred */ + rv.consumed = consumed_myself; + /* Fall through */ + case RC_WMORE: + /* Wrt. rv.consumed==0: + * In case a genuine RC_WMORE, the whole Open Type decoding + * will have to be restarted. + */ + if(*memb_ptr2) { + if(elm->flags & ATF_POINTER) { + ASN_STRUCT_FREE(*selected.type_descriptor, inner_value); + *memb_ptr2 = NULL; + } else { + ASN_STRUCT_RESET(*selected.type_descriptor, + inner_value); + } + } + return rv; + } + + /* + * Finalize wrapper. + */ + for(;;) { + ch_size = xer_next_token(&xer_context, ptr, size, &ch_type); + if(ch_size < 0) { + ASN__DECODE_FAILED; + } else { + switch(ch_type) { + case PXER_WMORE: + ASN__DECODE_STARVED; + case PXER_COMMENT: + case PXER_TEXT: + ADVANCE(ch_size); + continue; + case PXER_TAG: + break; + } + break; + } + } + + /* + * Wrapper value confirmed. + */ + switch(xer_check_tag(ptr, ch_size, elm->name)) { + case XCT_CLOSING: + ADVANCE(ch_size); + break; + case XCT_BROKEN: + default: + ASN__DECODE_FAILED; + } + + rv.consumed += consumed_myself; + + return rv; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ObjectDescriptor.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ObjectDescriptor.c new file mode 100644 index 000000000..4b3560af1 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ObjectDescriptor.c @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* + * ObjectDescriptor basic type description. + */ +static const ber_tlv_tag_t asn_DEF_ObjectDescriptor_tags[] = { + (ASN_TAG_CLASS_UNIVERSAL | (7 << 2)), /* [UNIVERSAL 7] IMPLICIT ... */ + (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ +}; +asn_TYPE_operation_t asn_OP_ObjectDescriptor = { + OCTET_STRING_free, +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + OCTET_STRING_print_utf8, /* Treat as ASCII subset (it's not) */ +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + OCTET_STRING_compare, + OCTET_STRING_copy, +#if !defined(ASN_DISABLE_BER_SUPPORT) + OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ + OCTET_STRING_encode_der, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + OCTET_STRING_decode_xer_utf8, + OCTET_STRING_encode_xer_utf8, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + OCTET_STRING_decode_jer_utf8, + OCTET_STRING_encode_jer_utf8, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, + 0, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + OCTET_STRING_decode_uper, + OCTET_STRING_encode_uper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + OCTET_STRING_decode_aper, + OCTET_STRING_encode_aper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + 0, /* Not supported for ObjectDescriptor */ +#else + 0, +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + 0 /* Use generic outmost tag fetcher */ +}; +asn_TYPE_descriptor_t asn_DEF_ObjectDescriptor = { + "ObjectDescriptor", + "ObjectDescriptor", + &asn_OP_ObjectDescriptor, + asn_DEF_ObjectDescriptor_tags, + sizeof(asn_DEF_ObjectDescriptor_tags) + / sizeof(asn_DEF_ObjectDescriptor_tags[0]) - 1, + asn_DEF_ObjectDescriptor_tags, + sizeof(asn_DEF_ObjectDescriptor_tags) + / sizeof(asn_DEF_ObjectDescriptor_tags[0]), + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + asn_generic_unknown_constraint + }, + 0, 0, /* No members */ + 0 /* No specifics */ +}; diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ObjectDescriptor.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ObjectDescriptor.h new file mode 100644 index 000000000..b70c0cbaf --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ObjectDescriptor.h @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _ObjectDescriptor_H_ +#define _ObjectDescriptor_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef GraphicString_t ObjectDescriptor_t; /* Implemented via GraphicString */ + +extern asn_TYPE_descriptor_t asn_DEF_ObjectDescriptor; +extern asn_TYPE_operation_t asn_OP_ObjectDescriptor; + +#define ObjectDescriptor_free OCTET_STRING_free + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +#define ObjectDescriptor_print OCTET_STRING_print_utf8 +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +#define ObjectDescriptor_constraint asn_generic_unknown_constraint + +#if !defined(ASN_DISABLE_BER_SUPPORT) +#define ObjectDescriptor_decode_ber OCTET_STRING_decode_ber +#define ObjectDescriptor_encode_der OCTET_STRING_encode_der +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +#define ObjectDescriptor_decode_xer OCTET_STRING_decode_xer_utf8 +#define ObjectDescriptor_encode_xer OCTET_STRING_encode_xer_utf8 +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +#define ObjectDescriptor_decode_jer OCTET_STRING_decode_jer_utf8 +#define ObjectDescriptor_encode_jer OCTET_STRING_encode_jer_utf8 +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +#define ObjectDescriptor_decode_uper OCTET_STRING_decode_uper +#define ObjectDescriptor_encode_uper OCTET_STRING_encode_uper +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +#define ObjectDescriptor_decode_aper OCTET_STRING_decode_aper +#define ObjectDescriptor_encode_aper OCTET_STRING_encode_aper +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#ifdef __cplusplus +} +#endif + +#endif /* _ObjectDescriptor_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-ConfigControl.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-ConfigControl.c new file mode 100644 index 000000000..0262f2907 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-ConfigControl.c @@ -0,0 +1,168 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "Spectrum-ConfigControl.h" + +static int +memb_noiseFloorThreshold_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= -100L && value <= 100L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_averagingFrames_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 1L && value <= 255L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_noiseFloorThreshold_constr_2 CC_NOTUSED = { + { APC_CONSTRAINED, 8, 8, -100, 100 } /* (-100..100) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_averagingFrames_constr_3 CC_NOTUSED = { + { APC_CONSTRAINED, 8, 8, 1, 255 } /* (1..255) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +asn_TYPE_member_t asn_MBR_Spectrum_ConfigControl_1[] = { + { ATF_POINTER, 3, offsetof(struct Spectrum_ConfigControl, noiseFloorThreshold), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_noiseFloorThreshold_constr_2, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_noiseFloorThreshold_constraint_1 + }, + 0, 0, /* No default value */ + "noiseFloorThreshold" + }, + { ATF_POINTER, 2, offsetof(struct Spectrum_ConfigControl, averagingFrames), + (ASN_TAG_CLASS_CONTEXT | (1 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_averagingFrames_constr_3, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_averagingFrames_constraint_1 + }, + 0, 0, /* No default value */ + "averagingFrames" + }, + { ATF_POINTER, 1, offsetof(struct Spectrum_ConfigControl, enable), + (ASN_TAG_CLASS_CONTEXT | (2 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_BOOLEAN, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "enable" + }, +}; +static const int asn_MAP_Spectrum_ConfigControl_oms_1[] = { 0, 1, 2 }; +static const ber_tlv_tag_t asn_DEF_Spectrum_ConfigControl_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static const asn_TYPE_tag2member_t asn_MAP_Spectrum_ConfigControl_tag2el_1[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* noiseFloorThreshold */ + { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* averagingFrames */ + { (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 } /* enable */ +}; +asn_SEQUENCE_specifics_t asn_SPC_Spectrum_ConfigControl_specs_1 = { + sizeof(struct Spectrum_ConfigControl), + offsetof(struct Spectrum_ConfigControl, _asn_ctx), + asn_MAP_Spectrum_ConfigControl_tag2el_1, + 3, /* Count of tags in the map */ + asn_MAP_Spectrum_ConfigControl_oms_1, /* Optional members */ + 3, 0, /* Root/Additions */ + -1, /* First extension addition */ +}; +asn_TYPE_descriptor_t asn_DEF_Spectrum_ConfigControl = { + "Spectrum-ConfigControl", + "Spectrum-ConfigControl", + &asn_OP_SEQUENCE, + asn_DEF_Spectrum_ConfigControl_tags_1, + sizeof(asn_DEF_Spectrum_ConfigControl_tags_1) + /sizeof(asn_DEF_Spectrum_ConfigControl_tags_1[0]), /* 1 */ + asn_DEF_Spectrum_ConfigControl_tags_1, /* Same as above */ + sizeof(asn_DEF_Spectrum_ConfigControl_tags_1) + /sizeof(asn_DEF_Spectrum_ConfigControl_tags_1[0]), /* 1 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_constraint + }, + asn_MBR_Spectrum_ConfigControl_1, + 3, /* Elements count */ + &asn_SPC_Spectrum_ConfigControl_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-ConfigControl.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-ConfigControl.h new file mode 100644 index 000000000..c4fbd6ac1 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-ConfigControl.h @@ -0,0 +1,43 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _Spectrum_ConfigControl_H_ +#define _Spectrum_ConfigControl_H_ + + +#include + +/* Including external dependencies */ +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Spectrum-ConfigControl */ +typedef struct Spectrum_ConfigControl { + long *noiseFloorThreshold; /* OPTIONAL */ + long *averagingFrames; /* OPTIONAL */ + BOOLEAN_t *enable; /* OPTIONAL */ + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Spectrum_ConfigControl_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Spectrum_ConfigControl; +extern asn_SEQUENCE_specifics_t asn_SPC_Spectrum_ConfigControl_specs_1; +extern asn_TYPE_member_t asn_MBR_Spectrum_ConfigControl_1[3]; + +#ifdef __cplusplus +} +#endif + +#endif /* _Spectrum_ConfigControl_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppControlData.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppControlData.c new file mode 100644 index 000000000..ce919d678 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppControlData.c @@ -0,0 +1,66 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "Spectrum-DAppControlData.h" + +static asn_TYPE_member_t asn_MBR_Spectrum_DAppControlData_1[] = { + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_DAppControlData, controlPayload), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + +1, /* EXPLICIT tag at current level */ + &asn_DEF_Spectrum_DAppControlPayload, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "controlPayload" + }, +}; +static const ber_tlv_tag_t asn_DEF_Spectrum_DAppControlData_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static const asn_TYPE_tag2member_t asn_MAP_Spectrum_DAppControlData_tag2el_1[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 } /* controlPayload */ +}; +static asn_SEQUENCE_specifics_t asn_SPC_Spectrum_DAppControlData_specs_1 = { + sizeof(struct Spectrum_DAppControlData), + offsetof(struct Spectrum_DAppControlData, _asn_ctx), + asn_MAP_Spectrum_DAppControlData_tag2el_1, + 1, /* Count of tags in the map */ + 0, 0, 0, /* Optional elements (not needed) */ + -1, /* First extension addition */ +}; +asn_TYPE_descriptor_t asn_DEF_Spectrum_DAppControlData = { + "Spectrum-DAppControlData", + "Spectrum-DAppControlData", + &asn_OP_SEQUENCE, + asn_DEF_Spectrum_DAppControlData_tags_1, + sizeof(asn_DEF_Spectrum_DAppControlData_tags_1) + /sizeof(asn_DEF_Spectrum_DAppControlData_tags_1[0]), /* 1 */ + asn_DEF_Spectrum_DAppControlData_tags_1, /* Same as above */ + sizeof(asn_DEF_Spectrum_DAppControlData_tags_1) + /sizeof(asn_DEF_Spectrum_DAppControlData_tags_1[0]), /* 1 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_constraint + }, + asn_MBR_Spectrum_DAppControlData_1, + 1, /* Elements count */ + &asn_SPC_Spectrum_DAppControlData_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppControlData.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppControlData.h new file mode 100644 index 000000000..45b677d3a --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppControlData.h @@ -0,0 +1,38 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _Spectrum_DAppControlData_H_ +#define _Spectrum_DAppControlData_H_ + + +#include + +/* Including external dependencies */ +#include "Spectrum-DAppControlPayload.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Spectrum-DAppControlData */ +typedef struct Spectrum_DAppControlData { + Spectrum_DAppControlPayload_t controlPayload; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Spectrum_DAppControlData_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Spectrum_DAppControlData; + +#ifdef __cplusplus +} +#endif + +#endif /* _Spectrum_DAppControlData_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppControlPayload.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppControlPayload.c new file mode 100644 index 000000000..e32d86759 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppControlPayload.c @@ -0,0 +1,90 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "Spectrum-DAppControlPayload.h" + +#include "Spectrum-PRBBlacklistControl.h" +#include "Spectrum-SensingPolicyControl.h" +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +asn_per_constraints_t asn_PER_type_Spectrum_DAppControlPayload_constr_1 CC_NOTUSED = { + { APC_CONSTRAINED | APC_EXTENSIBLE, 0, 0, 0, 0 } /* (0..0,...) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +asn_TYPE_member_t asn_MBR_Spectrum_DAppControlPayload_1[] = { + { ATF_POINTER, 0, offsetof(struct Spectrum_DAppControlPayload, choice.prbBlacklistControl), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_Spectrum_PRBBlacklistControl, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "prbBlacklistControl" + }, + { ATF_POINTER, 0, offsetof(struct Spectrum_DAppControlPayload, choice.sensingPolicyControl), + (ASN_TAG_CLASS_CONTEXT | (1 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_Spectrum_SensingPolicyControl, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "sensingPolicyControl" + }, +}; +static const asn_TYPE_tag2member_t asn_MAP_Spectrum_DAppControlPayload_tag2el_1[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* prbBlacklistControl */ + { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* sensingPolicyControl */ +}; +asn_CHOICE_specifics_t asn_SPC_Spectrum_DAppControlPayload_specs_1 = { + sizeof(struct Spectrum_DAppControlPayload), + offsetof(struct Spectrum_DAppControlPayload, _asn_ctx), + offsetof(struct Spectrum_DAppControlPayload, present), + sizeof(((struct Spectrum_DAppControlPayload *)0)->present), + asn_MAP_Spectrum_DAppControlPayload_tag2el_1, + 2, /* Count of tags in the map */ + 0, 0, + 1 /* Extensions start */ +}; +asn_TYPE_descriptor_t asn_DEF_Spectrum_DAppControlPayload = { + "Spectrum-DAppControlPayload", + "Spectrum-DAppControlPayload", + &asn_OP_CHOICE, + 0, /* No effective tags (pointer) */ + 0, /* No effective tags (count) */ + 0, /* No tags (pointer) */ + 0, /* No tags (count) */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_type_Spectrum_DAppControlPayload_constr_1, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + CHOICE_constraint + }, + asn_MBR_Spectrum_DAppControlPayload_1, + 2, /* Elements count */ + &asn_SPC_Spectrum_DAppControlPayload_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppControlPayload.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppControlPayload.h new file mode 100644 index 000000000..00b9e1ca0 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppControlPayload.h @@ -0,0 +1,60 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _Spectrum_DAppControlPayload_H_ +#define _Spectrum_DAppControlPayload_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum Spectrum_DAppControlPayload_PR { + Spectrum_DAppControlPayload_PR_NOTHING, /* No components present */ + Spectrum_DAppControlPayload_PR_prbBlacklistControl, + /* Extensions may appear below */ + Spectrum_DAppControlPayload_PR_sensingPolicyControl +} Spectrum_DAppControlPayload_PR; + +/* Forward declarations */ +struct Spectrum_PRBBlacklistControl; +struct Spectrum_SensingPolicyControl; + +/* Spectrum-DAppControlPayload */ +typedef struct Spectrum_DAppControlPayload { + Spectrum_DAppControlPayload_PR present; + union Spectrum_DAppControlPayload_u { + struct Spectrum_PRBBlacklistControl *prbBlacklistControl; + /* + * This type is extensible, + * possible extensions are below. + */ + struct Spectrum_SensingPolicyControl *sensingPolicyControl; + } choice; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Spectrum_DAppControlPayload_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Spectrum_DAppControlPayload; +extern asn_CHOICE_specifics_t asn_SPC_Spectrum_DAppControlPayload_specs_1; +extern asn_TYPE_member_t asn_MBR_Spectrum_DAppControlPayload_1[2]; +extern asn_per_constraints_t asn_PER_type_Spectrum_DAppControlPayload_constr_1; + +#ifdef __cplusplus +} +#endif + +#endif /* _Spectrum_DAppControlPayload_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppReportData.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppReportData.c new file mode 100644 index 000000000..300f75cb4 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppReportData.c @@ -0,0 +1,86 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "Spectrum-DAppReportData.h" + +static asn_TYPE_member_t asn_MBR_Spectrum_DAppReportData_1[] = { + { ATF_POINTER, 1, offsetof(struct Spectrum_DAppReportData, timestamp), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "timestamp" + }, + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_DAppReportData, reportPayload), + (ASN_TAG_CLASS_CONTEXT | (1 << 2)), + +1, /* EXPLICIT tag at current level */ + &asn_DEF_Spectrum_DAppReportPayload, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "reportPayload" + }, +}; +static const int asn_MAP_Spectrum_DAppReportData_oms_1[] = { 0 }; +static const ber_tlv_tag_t asn_DEF_Spectrum_DAppReportData_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static const asn_TYPE_tag2member_t asn_MAP_Spectrum_DAppReportData_tag2el_1[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* timestamp */ + { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* reportPayload */ +}; +static asn_SEQUENCE_specifics_t asn_SPC_Spectrum_DAppReportData_specs_1 = { + sizeof(struct Spectrum_DAppReportData), + offsetof(struct Spectrum_DAppReportData, _asn_ctx), + asn_MAP_Spectrum_DAppReportData_tag2el_1, + 2, /* Count of tags in the map */ + asn_MAP_Spectrum_DAppReportData_oms_1, /* Optional members */ + 1, 0, /* Root/Additions */ + -1, /* First extension addition */ +}; +asn_TYPE_descriptor_t asn_DEF_Spectrum_DAppReportData = { + "Spectrum-DAppReportData", + "Spectrum-DAppReportData", + &asn_OP_SEQUENCE, + asn_DEF_Spectrum_DAppReportData_tags_1, + sizeof(asn_DEF_Spectrum_DAppReportData_tags_1) + /sizeof(asn_DEF_Spectrum_DAppReportData_tags_1[0]), /* 1 */ + asn_DEF_Spectrum_DAppReportData_tags_1, /* Same as above */ + sizeof(asn_DEF_Spectrum_DAppReportData_tags_1) + /sizeof(asn_DEF_Spectrum_DAppReportData_tags_1[0]), /* 1 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_constraint + }, + asn_MBR_Spectrum_DAppReportData_1, + 2, /* Elements count */ + &asn_SPC_Spectrum_DAppReportData_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppReportData.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppReportData.h new file mode 100644 index 000000000..79e5ebc2f --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppReportData.h @@ -0,0 +1,40 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _Spectrum_DAppReportData_H_ +#define _Spectrum_DAppReportData_H_ + + +#include + +/* Including external dependencies */ +#include +#include "Spectrum-DAppReportPayload.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Spectrum-DAppReportData */ +typedef struct Spectrum_DAppReportData { + long *timestamp; /* OPTIONAL */ + Spectrum_DAppReportPayload_t reportPayload; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Spectrum_DAppReportData_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Spectrum_DAppReportData; + +#ifdef __cplusplus +} +#endif + +#endif /* _Spectrum_DAppReportData_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppReportPayload.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppReportPayload.c new file mode 100644 index 000000000..28fe6f84e --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppReportPayload.c @@ -0,0 +1,71 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "Spectrum-DAppReportPayload.h" + +#include "Spectrum-PRBBlacklistReport.h" +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +asn_per_constraints_t asn_PER_type_Spectrum_DAppReportPayload_constr_1 CC_NOTUSED = { + { APC_CONSTRAINED | APC_EXTENSIBLE, 0, 0, 0, 0 } /* (0..0,...) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +asn_TYPE_member_t asn_MBR_Spectrum_DAppReportPayload_1[] = { + { ATF_POINTER, 0, offsetof(struct Spectrum_DAppReportPayload, choice.prbBlacklistReport), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_Spectrum_PRBBlacklistReport, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "prbBlacklistReport" + }, +}; +static const asn_TYPE_tag2member_t asn_MAP_Spectrum_DAppReportPayload_tag2el_1[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 } /* prbBlacklistReport */ +}; +asn_CHOICE_specifics_t asn_SPC_Spectrum_DAppReportPayload_specs_1 = { + sizeof(struct Spectrum_DAppReportPayload), + offsetof(struct Spectrum_DAppReportPayload, _asn_ctx), + offsetof(struct Spectrum_DAppReportPayload, present), + sizeof(((struct Spectrum_DAppReportPayload *)0)->present), + asn_MAP_Spectrum_DAppReportPayload_tag2el_1, + 1, /* Count of tags in the map */ + 0, 0, + 1 /* Extensions start */ +}; +asn_TYPE_descriptor_t asn_DEF_Spectrum_DAppReportPayload = { + "Spectrum-DAppReportPayload", + "Spectrum-DAppReportPayload", + &asn_OP_CHOICE, + 0, /* No effective tags (pointer) */ + 0, /* No effective tags (count) */ + 0, /* No tags (pointer) */ + 0, /* No tags (count) */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_type_Spectrum_DAppReportPayload_constr_1, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + CHOICE_constraint + }, + asn_MBR_Spectrum_DAppReportPayload_1, + 1, /* Elements count */ + &asn_SPC_Spectrum_DAppReportPayload_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppReportPayload.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppReportPayload.h new file mode 100644 index 000000000..46d3643b9 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-DAppReportPayload.h @@ -0,0 +1,58 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _Spectrum_DAppReportPayload_H_ +#define _Spectrum_DAppReportPayload_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum Spectrum_DAppReportPayload_PR { + Spectrum_DAppReportPayload_PR_NOTHING, /* No components present */ + Spectrum_DAppReportPayload_PR_prbBlacklistReport + /* Extensions may appear below */ + +} Spectrum_DAppReportPayload_PR; + +/* Forward declarations */ +struct Spectrum_PRBBlacklistReport; + +/* Spectrum-DAppReportPayload */ +typedef struct Spectrum_DAppReportPayload { + Spectrum_DAppReportPayload_PR present; + union Spectrum_DAppReportPayload_u { + struct Spectrum_PRBBlacklistReport *prbBlacklistReport; + /* + * This type is extensible, + * possible extensions are below. + */ + } choice; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Spectrum_DAppReportPayload_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Spectrum_DAppReportPayload; +extern asn_CHOICE_specifics_t asn_SPC_Spectrum_DAppReportPayload_specs_1; +extern asn_TYPE_member_t asn_MBR_Spectrum_DAppReportPayload_1[1]; +extern asn_per_constraints_t asn_PER_type_Spectrum_DAppReportPayload_constr_1; + +#ifdef __cplusplus +} +#endif + +#endif /* _Spectrum_DAppReportPayload_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlacklistControl.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlacklistControl.c new file mode 100644 index 000000000..6169db9c7 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlacklistControl.c @@ -0,0 +1,293 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "Spectrum-PRBBlacklistControl.h" + +static int +memb_NativeInteger_constraint_2(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 0L && value <= 272L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_blacklistedPRBs_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + size_t size; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + /* Determine the number of elements */ + size = _A_CSEQUENCE_FROM_VOID(sptr)->count; + + if((size <= 273UL)) { + /* Perform validation of the inner elements */ + return SEQUENCE_OF_constraint(td, sptr, ctfailcb, app_key); + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_samplingThreshold_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 0L && value <= 100L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_validityPeriod_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 1L && value <= 3600L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_Member_constr_3 CC_NOTUSED = { + { APC_CONSTRAINED, 9, 9, 0, 272 } /* (0..272) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_type_blacklistedPRBs_constr_2 CC_NOTUSED = { + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + { APC_CONSTRAINED, 9, 9, 0, 273 } /* (SIZE(0..273)) */, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_blacklistedPRBs_constr_2 CC_NOTUSED = { + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + { APC_CONSTRAINED, 9, 9, 0, 273 } /* (SIZE(0..273)) */, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_samplingThreshold_constr_4 CC_NOTUSED = { + { APC_CONSTRAINED, 7, 7, 0, 100 } /* (0..100) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_validityPeriod_constr_5 CC_NOTUSED = { + { APC_CONSTRAINED, 12, 12, 1, 3600 } /* (1..3600) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +static asn_TYPE_member_t asn_MBR_blacklistedPRBs_2[] = { + { ATF_POINTER, 0, 0, + (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), + 0, + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_Member_constr_3, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_NativeInteger_constraint_2 + }, + 0, 0, /* No default value */ + "" + }, +}; +static const ber_tlv_tag_t asn_DEF_blacklistedPRBs_tags_2[] = { + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static asn_SET_OF_specifics_t asn_SPC_blacklistedPRBs_specs_2 = { + sizeof(struct Spectrum_PRBBlacklistControl__blacklistedPRBs), + offsetof(struct Spectrum_PRBBlacklistControl__blacklistedPRBs, _asn_ctx), + 0, /* XER encoding is XMLDelimitedItemList */ +}; +static /* Use -fall-defs-global to expose */ +asn_TYPE_descriptor_t asn_DEF_blacklistedPRBs_2 = { + "blacklistedPRBs", + "blacklistedPRBs", + &asn_OP_SEQUENCE_OF, + asn_DEF_blacklistedPRBs_tags_2, + sizeof(asn_DEF_blacklistedPRBs_tags_2) + /sizeof(asn_DEF_blacklistedPRBs_tags_2[0]) - 1, /* 1 */ + asn_DEF_blacklistedPRBs_tags_2, /* Same as above */ + sizeof(asn_DEF_blacklistedPRBs_tags_2) + /sizeof(asn_DEF_blacklistedPRBs_tags_2[0]), /* 2 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_type_blacklistedPRBs_constr_2, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_OF_constraint + }, + asn_MBR_blacklistedPRBs_2, + 1, /* Single element */ + &asn_SPC_blacklistedPRBs_specs_2 /* Additional specs */ +}; + +asn_TYPE_member_t asn_MBR_Spectrum_PRBBlacklistControl_1[] = { + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_PRBBlacklistControl, blacklistedPRBs), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + 0, + &asn_DEF_blacklistedPRBs_2, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_blacklistedPRBs_constr_2, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_blacklistedPRBs_constraint_1 + }, + 0, 0, /* No default value */ + "blacklistedPRBs" + }, + { ATF_POINTER, 2, offsetof(struct Spectrum_PRBBlacklistControl, samplingThreshold), + (ASN_TAG_CLASS_CONTEXT | (1 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_samplingThreshold_constr_4, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_samplingThreshold_constraint_1 + }, + 0, 0, /* No default value */ + "samplingThreshold" + }, + { ATF_POINTER, 1, offsetof(struct Spectrum_PRBBlacklistControl, validityPeriod), + (ASN_TAG_CLASS_CONTEXT | (2 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_validityPeriod_constr_5, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_validityPeriod_constraint_1 + }, + 0, 0, /* No default value */ + "validityPeriod" + }, +}; +static const int asn_MAP_Spectrum_PRBBlacklistControl_oms_1[] = { 1, 2 }; +static const ber_tlv_tag_t asn_DEF_Spectrum_PRBBlacklistControl_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static const asn_TYPE_tag2member_t asn_MAP_Spectrum_PRBBlacklistControl_tag2el_1[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* blacklistedPRBs */ + { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* samplingThreshold */ + { (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 } /* validityPeriod */ +}; +asn_SEQUENCE_specifics_t asn_SPC_Spectrum_PRBBlacklistControl_specs_1 = { + sizeof(struct Spectrum_PRBBlacklistControl), + offsetof(struct Spectrum_PRBBlacklistControl, _asn_ctx), + asn_MAP_Spectrum_PRBBlacklistControl_tag2el_1, + 3, /* Count of tags in the map */ + asn_MAP_Spectrum_PRBBlacklistControl_oms_1, /* Optional members */ + 2, 0, /* Root/Additions */ + -1, /* First extension addition */ +}; +asn_TYPE_descriptor_t asn_DEF_Spectrum_PRBBlacklistControl = { + "Spectrum-PRBBlacklistControl", + "Spectrum-PRBBlacklistControl", + &asn_OP_SEQUENCE, + asn_DEF_Spectrum_PRBBlacklistControl_tags_1, + sizeof(asn_DEF_Spectrum_PRBBlacklistControl_tags_1) + /sizeof(asn_DEF_Spectrum_PRBBlacklistControl_tags_1[0]), /* 1 */ + asn_DEF_Spectrum_PRBBlacklistControl_tags_1, /* Same as above */ + sizeof(asn_DEF_Spectrum_PRBBlacklistControl_tags_1) + /sizeof(asn_DEF_Spectrum_PRBBlacklistControl_tags_1[0]), /* 1 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_constraint + }, + asn_MBR_Spectrum_PRBBlacklistControl_1, + 3, /* Elements count */ + &asn_SPC_Spectrum_PRBBlacklistControl_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlacklistControl.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlacklistControl.h new file mode 100644 index 000000000..8b79c6d23 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlacklistControl.h @@ -0,0 +1,49 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _Spectrum_PRBBlacklistControl_H_ +#define _Spectrum_PRBBlacklistControl_H_ + + +#include + +/* Including external dependencies */ +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Spectrum-PRBBlacklistControl */ +typedef struct Spectrum_PRBBlacklistControl { + struct Spectrum_PRBBlacklistControl__blacklistedPRBs { + A_SEQUENCE_OF(long) list; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; + } blacklistedPRBs; + long *samplingThreshold; /* OPTIONAL */ + long *validityPeriod; /* OPTIONAL */ + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Spectrum_PRBBlacklistControl_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Spectrum_PRBBlacklistControl; +extern asn_SEQUENCE_specifics_t asn_SPC_Spectrum_PRBBlacklistControl_specs_1; +extern asn_TYPE_member_t asn_MBR_Spectrum_PRBBlacklistControl_1[3]; + +#ifdef __cplusplus +} +#endif + +#endif /* _Spectrum_PRBBlacklistControl_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlacklistReport.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlacklistReport.c new file mode 100644 index 000000000..94e2119db --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlacklistReport.c @@ -0,0 +1,191 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "Spectrum-PRBBlacklistReport.h" + +static int +memb_NativeInteger_constraint_2(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 0L && value <= 272L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_blacklistedPRBs_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + size_t size; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + /* Determine the number of elements */ + size = _A_CSEQUENCE_FROM_VOID(sptr)->count; + + if((size <= 273UL)) { + /* Perform validation of the inner elements */ + return SEQUENCE_OF_constraint(td, sptr, ctfailcb, app_key); + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_Member_constr_3 CC_NOTUSED = { + { APC_CONSTRAINED, 9, 9, 0, 272 } /* (0..272) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_type_blacklistedPRBs_constr_2 CC_NOTUSED = { + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + { APC_CONSTRAINED, 9, 9, 0, 273 } /* (SIZE(0..273)) */, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_blacklistedPRBs_constr_2 CC_NOTUSED = { + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + { APC_CONSTRAINED, 9, 9, 0, 273 } /* (SIZE(0..273)) */, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +static asn_TYPE_member_t asn_MBR_blacklistedPRBs_2[] = { + { ATF_POINTER, 0, 0, + (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), + 0, + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_Member_constr_3, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_NativeInteger_constraint_2 + }, + 0, 0, /* No default value */ + "" + }, +}; +static const ber_tlv_tag_t asn_DEF_blacklistedPRBs_tags_2[] = { + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static asn_SET_OF_specifics_t asn_SPC_blacklistedPRBs_specs_2 = { + sizeof(struct Spectrum_PRBBlacklistReport__blacklistedPRBs), + offsetof(struct Spectrum_PRBBlacklistReport__blacklistedPRBs, _asn_ctx), + 0, /* XER encoding is XMLDelimitedItemList */ +}; +static /* Use -fall-defs-global to expose */ +asn_TYPE_descriptor_t asn_DEF_blacklistedPRBs_2 = { + "blacklistedPRBs", + "blacklistedPRBs", + &asn_OP_SEQUENCE_OF, + asn_DEF_blacklistedPRBs_tags_2, + sizeof(asn_DEF_blacklistedPRBs_tags_2) + /sizeof(asn_DEF_blacklistedPRBs_tags_2[0]) - 1, /* 1 */ + asn_DEF_blacklistedPRBs_tags_2, /* Same as above */ + sizeof(asn_DEF_blacklistedPRBs_tags_2) + /sizeof(asn_DEF_blacklistedPRBs_tags_2[0]), /* 2 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_type_blacklistedPRBs_constr_2, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_OF_constraint + }, + asn_MBR_blacklistedPRBs_2, + 1, /* Single element */ + &asn_SPC_blacklistedPRBs_specs_2 /* Additional specs */ +}; + +asn_TYPE_member_t asn_MBR_Spectrum_PRBBlacklistReport_1[] = { + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_PRBBlacklistReport, blacklistedPRBs), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + 0, + &asn_DEF_blacklistedPRBs_2, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_blacklistedPRBs_constr_2, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_blacklistedPRBs_constraint_1 + }, + 0, 0, /* No default value */ + "blacklistedPRBs" + }, +}; +static const ber_tlv_tag_t asn_DEF_Spectrum_PRBBlacklistReport_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static const asn_TYPE_tag2member_t asn_MAP_Spectrum_PRBBlacklistReport_tag2el_1[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 } /* blacklistedPRBs */ +}; +asn_SEQUENCE_specifics_t asn_SPC_Spectrum_PRBBlacklistReport_specs_1 = { + sizeof(struct Spectrum_PRBBlacklistReport), + offsetof(struct Spectrum_PRBBlacklistReport, _asn_ctx), + asn_MAP_Spectrum_PRBBlacklistReport_tag2el_1, + 1, /* Count of tags in the map */ + 0, 0, 0, /* Optional elements (not needed) */ + -1, /* First extension addition */ +}; +asn_TYPE_descriptor_t asn_DEF_Spectrum_PRBBlacklistReport = { + "Spectrum-PRBBlacklistReport", + "Spectrum-PRBBlacklistReport", + &asn_OP_SEQUENCE, + asn_DEF_Spectrum_PRBBlacklistReport_tags_1, + sizeof(asn_DEF_Spectrum_PRBBlacklistReport_tags_1) + /sizeof(asn_DEF_Spectrum_PRBBlacklistReport_tags_1[0]), /* 1 */ + asn_DEF_Spectrum_PRBBlacklistReport_tags_1, /* Same as above */ + sizeof(asn_DEF_Spectrum_PRBBlacklistReport_tags_1) + /sizeof(asn_DEF_Spectrum_PRBBlacklistReport_tags_1[0]), /* 1 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_constraint + }, + asn_MBR_Spectrum_PRBBlacklistReport_1, + 1, /* Elements count */ + &asn_SPC_Spectrum_PRBBlacklistReport_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlacklistReport.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlacklistReport.h new file mode 100644 index 000000000..3211d3532 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlacklistReport.h @@ -0,0 +1,47 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _Spectrum_PRBBlacklistReport_H_ +#define _Spectrum_PRBBlacklistReport_H_ + + +#include + +/* Including external dependencies */ +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Spectrum-PRBBlacklistReport */ +typedef struct Spectrum_PRBBlacklistReport { + struct Spectrum_PRBBlacklistReport__blacklistedPRBs { + A_SEQUENCE_OF(long) list; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; + } blacklistedPRBs; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Spectrum_PRBBlacklistReport_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Spectrum_PRBBlacklistReport; +extern asn_SEQUENCE_specifics_t asn_SPC_Spectrum_PRBBlacklistReport_specs_1; +extern asn_TYPE_member_t asn_MBR_Spectrum_PRBBlacklistReport_1[1]; + +#ifdef __cplusplus +} +#endif + +#endif /* _Spectrum_PRBBlacklistReport_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlockedControl.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlockedControl.c new file mode 100644 index 000000000..1af689c82 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlockedControl.c @@ -0,0 +1,191 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "Spectrum-PRBBlockedControl.h" + +static int +memb_NativeInteger_constraint_2(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 0L && value <= 272L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_blockedPRBs_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + size_t size; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + /* Determine the number of elements */ + size = _A_CSEQUENCE_FROM_VOID(sptr)->count; + + if((size <= 273UL)) { + /* Perform validation of the inner elements */ + return SEQUENCE_OF_constraint(td, sptr, ctfailcb, app_key); + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_Member_constr_3 CC_NOTUSED = { + { APC_CONSTRAINED, 9, 9, 0, 272 } /* (0..272) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_type_blockedPRBs_constr_2 CC_NOTUSED = { + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + { APC_CONSTRAINED, 9, 9, 0, 273 } /* (SIZE(0..273)) */, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_blockedPRBs_constr_2 CC_NOTUSED = { + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + { APC_CONSTRAINED, 9, 9, 0, 273 } /* (SIZE(0..273)) */, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +static asn_TYPE_member_t asn_MBR_blockedPRBs_2[] = { + { ATF_POINTER, 0, 0, + (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), + 0, + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_Member_constr_3, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_NativeInteger_constraint_2 + }, + 0, 0, /* No default value */ + "" + }, +}; +static const ber_tlv_tag_t asn_DEF_blockedPRBs_tags_2[] = { + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static asn_SET_OF_specifics_t asn_SPC_blockedPRBs_specs_2 = { + sizeof(struct Spectrum_PRBBlockedControl__blockedPRBs), + offsetof(struct Spectrum_PRBBlockedControl__blockedPRBs, _asn_ctx), + 0, /* XER encoding is XMLDelimitedItemList */ +}; +static /* Use -fall-defs-global to expose */ +asn_TYPE_descriptor_t asn_DEF_blockedPRBs_2 = { + "blockedPRBs", + "blockedPRBs", + &asn_OP_SEQUENCE_OF, + asn_DEF_blockedPRBs_tags_2, + sizeof(asn_DEF_blockedPRBs_tags_2) + /sizeof(asn_DEF_blockedPRBs_tags_2[0]) - 1, /* 1 */ + asn_DEF_blockedPRBs_tags_2, /* Same as above */ + sizeof(asn_DEF_blockedPRBs_tags_2) + /sizeof(asn_DEF_blockedPRBs_tags_2[0]), /* 2 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_type_blockedPRBs_constr_2, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_OF_constraint + }, + asn_MBR_blockedPRBs_2, + 1, /* Single element */ + &asn_SPC_blockedPRBs_specs_2 /* Additional specs */ +}; + +asn_TYPE_member_t asn_MBR_Spectrum_PRBBlockedControl_1[] = { + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_PRBBlockedControl, blockedPRBs), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + 0, + &asn_DEF_blockedPRBs_2, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_blockedPRBs_constr_2, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_blockedPRBs_constraint_1 + }, + 0, 0, /* No default value */ + "blockedPRBs" + }, +}; +static const ber_tlv_tag_t asn_DEF_Spectrum_PRBBlockedControl_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static const asn_TYPE_tag2member_t asn_MAP_Spectrum_PRBBlockedControl_tag2el_1[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 } /* blockedPRBs */ +}; +asn_SEQUENCE_specifics_t asn_SPC_Spectrum_PRBBlockedControl_specs_1 = { + sizeof(struct Spectrum_PRBBlockedControl), + offsetof(struct Spectrum_PRBBlockedControl, _asn_ctx), + asn_MAP_Spectrum_PRBBlockedControl_tag2el_1, + 1, /* Count of tags in the map */ + 0, 0, 0, /* Optional elements (not needed) */ + -1, /* First extension addition */ +}; +asn_TYPE_descriptor_t asn_DEF_Spectrum_PRBBlockedControl = { + "Spectrum-PRBBlockedControl", + "Spectrum-PRBBlockedControl", + &asn_OP_SEQUENCE, + asn_DEF_Spectrum_PRBBlockedControl_tags_1, + sizeof(asn_DEF_Spectrum_PRBBlockedControl_tags_1) + /sizeof(asn_DEF_Spectrum_PRBBlockedControl_tags_1[0]), /* 1 */ + asn_DEF_Spectrum_PRBBlockedControl_tags_1, /* Same as above */ + sizeof(asn_DEF_Spectrum_PRBBlockedControl_tags_1) + /sizeof(asn_DEF_Spectrum_PRBBlockedControl_tags_1[0]), /* 1 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_constraint + }, + asn_MBR_Spectrum_PRBBlockedControl_1, + 1, /* Elements count */ + &asn_SPC_Spectrum_PRBBlockedControl_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlockedControl.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlockedControl.h new file mode 100644 index 000000000..7e86b7e3c --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-PRBBlockedControl.h @@ -0,0 +1,47 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _Spectrum_PRBBlockedControl_H_ +#define _Spectrum_PRBBlockedControl_H_ + + +#include + +/* Including external dependencies */ +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Spectrum-PRBBlockedControl */ +typedef struct Spectrum_PRBBlockedControl { + struct Spectrum_PRBBlockedControl__blockedPRBs { + A_SEQUENCE_OF(long) list; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; + } blockedPRBs; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Spectrum_PRBBlockedControl_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Spectrum_PRBBlockedControl; +extern asn_SEQUENCE_specifics_t asn_SPC_Spectrum_PRBBlockedControl_specs_1; +extern asn_TYPE_member_t asn_MBR_Spectrum_PRBBlockedControl_1[1]; + +#ifdef __cplusplus +} +#endif + +#endif /* _Spectrum_PRBBlockedControl_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-RanFunctionData.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-RanFunctionData.c new file mode 100644 index 000000000..afc0ca9ef --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-RanFunctionData.c @@ -0,0 +1,200 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "Spectrum-RanFunctionData.h" + +static int +memb_name_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr; + size_t size; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + size = st->size; + + if((size >= 1UL && size <= 32UL)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_version_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 0L && value <= 65535L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_description_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr; + size_t size; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + size = st->size; + + if((size >= 1UL && size <= 128UL)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_name_constr_2 CC_NOTUSED = { + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + { APC_CONSTRAINED, 5, 5, 1, 32 } /* (SIZE(1..32)) */, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_version_constr_3 CC_NOTUSED = { + { APC_CONSTRAINED, 16, 16, 0, 65535 } /* (0..65535) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_description_constr_4 CC_NOTUSED = { + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + { APC_CONSTRAINED, 7, 7, 1, 128 } /* (SIZE(1..128)) */, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +static asn_TYPE_member_t asn_MBR_Spectrum_RanFunctionData_1[] = { + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_RanFunctionData, name), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_OCTET_STRING, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_name_constr_2, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_name_constraint_1 + }, + 0, 0, /* No default value */ + "name" + }, + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_RanFunctionData, version), + (ASN_TAG_CLASS_CONTEXT | (1 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_version_constr_3, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_version_constraint_1 + }, + 0, 0, /* No default value */ + "version" + }, + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_RanFunctionData, description), + (ASN_TAG_CLASS_CONTEXT | (2 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_OCTET_STRING, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_description_constr_4, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_description_constraint_1 + }, + 0, 0, /* No default value */ + "description" + }, +}; +static const ber_tlv_tag_t asn_DEF_Spectrum_RanFunctionData_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static const asn_TYPE_tag2member_t asn_MAP_Spectrum_RanFunctionData_tag2el_1[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* name */ + { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* version */ + { (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 } /* description */ +}; +static asn_SEQUENCE_specifics_t asn_SPC_Spectrum_RanFunctionData_specs_1 = { + sizeof(struct Spectrum_RanFunctionData), + offsetof(struct Spectrum_RanFunctionData, _asn_ctx), + asn_MAP_Spectrum_RanFunctionData_tag2el_1, + 3, /* Count of tags in the map */ + 0, 0, 0, /* Optional elements (not needed) */ + -1, /* First extension addition */ +}; +asn_TYPE_descriptor_t asn_DEF_Spectrum_RanFunctionData = { + "Spectrum-RanFunctionData", + "Spectrum-RanFunctionData", + &asn_OP_SEQUENCE, + asn_DEF_Spectrum_RanFunctionData_tags_1, + sizeof(asn_DEF_Spectrum_RanFunctionData_tags_1) + /sizeof(asn_DEF_Spectrum_RanFunctionData_tags_1[0]), /* 1 */ + asn_DEF_Spectrum_RanFunctionData_tags_1, /* Same as above */ + sizeof(asn_DEF_Spectrum_RanFunctionData_tags_1) + /sizeof(asn_DEF_Spectrum_RanFunctionData_tags_1[0]), /* 1 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_constraint + }, + asn_MBR_Spectrum_RanFunctionData_1, + 3, /* Elements count */ + &asn_SPC_Spectrum_RanFunctionData_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-RanFunctionData.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-RanFunctionData.h new file mode 100644 index 000000000..e1d958d7d --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-RanFunctionData.h @@ -0,0 +1,41 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _Spectrum_RanFunctionData_H_ +#define _Spectrum_RanFunctionData_H_ + + +#include + +/* Including external dependencies */ +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Spectrum-RanFunctionData */ +typedef struct Spectrum_RanFunctionData { + OCTET_STRING_t name; + long version; + OCTET_STRING_t description; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Spectrum_RanFunctionData_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Spectrum_RanFunctionData; + +#ifdef __cplusplus +} +#endif + +#endif /* _Spectrum_RanFunctionData_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-SensingIndication.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-SensingIndication.c new file mode 100644 index 000000000..eae813963 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-SensingIndication.c @@ -0,0 +1,336 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "Spectrum-SensingIndication.h" + +static int +memb_sfn_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 0L && value <= 65535L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_slot_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 0L && value <= 65535L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_beam_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 0L && value <= 3L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_shmWriteIdx_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 0L && value <= 65535L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_nRanges_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 0L && value <= 128L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_sfn_constr_3 CC_NOTUSED = { + { APC_CONSTRAINED, 16, 16, 0, 65535 } /* (0..65535) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_slot_constr_4 CC_NOTUSED = { + { APC_CONSTRAINED, 16, 16, 0, 65535 } /* (0..65535) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_beam_constr_5 CC_NOTUSED = { + { APC_CONSTRAINED, 2, 2, 0, 3 } /* (0..3) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_shmWriteIdx_constr_7 CC_NOTUSED = { + { APC_CONSTRAINED, 16, 16, 0, 65535 } /* (0..65535) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_nRanges_constr_8 CC_NOTUSED = { + { APC_CONSTRAINED, 8, 8, 0, 128 } /* (0..128) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +static asn_TYPE_member_t asn_MBR_Spectrum_SensingIndication_1[] = { + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_SensingIndication, timestamp), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "timestamp" + }, + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_SensingIndication, sfn), + (ASN_TAG_CLASS_CONTEXT | (1 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_sfn_constr_3, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_sfn_constraint_1 + }, + 0, 0, /* No default value */ + "sfn" + }, + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_SensingIndication, slot), + (ASN_TAG_CLASS_CONTEXT | (2 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_slot_constr_4, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_slot_constraint_1 + }, + 0, 0, /* No default value */ + "slot" + }, + { ATF_POINTER, 1, offsetof(struct Spectrum_SensingIndication, beam), + (ASN_TAG_CLASS_CONTEXT | (3 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_beam_constr_5, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_beam_constraint_1 + }, + 0, 0, /* No default value */ + "beam" + }, + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_SensingIndication, shmName), + (ASN_TAG_CLASS_CONTEXT | (4 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_OCTET_STRING, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "shmName" + }, + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_SensingIndication, shmWriteIdx), + (ASN_TAG_CLASS_CONTEXT | (5 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_shmWriteIdx_constr_7, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_shmWriteIdx_constraint_1 + }, + 0, 0, /* No default value */ + "shmWriteIdx" + }, + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_SensingIndication, nRanges), + (ASN_TAG_CLASS_CONTEXT | (6 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_nRanges_constr_8, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_nRanges_constraint_1 + }, + 0, 0, /* No default value */ + "nRanges" + }, +}; +static const int asn_MAP_Spectrum_SensingIndication_oms_1[] = { 3 }; +static const ber_tlv_tag_t asn_DEF_Spectrum_SensingIndication_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static const asn_TYPE_tag2member_t asn_MAP_Spectrum_SensingIndication_tag2el_1[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* timestamp */ + { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* sfn */ + { (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 }, /* slot */ + { (ASN_TAG_CLASS_CONTEXT | (3 << 2)), 3, 0, 0 }, /* beam */ + { (ASN_TAG_CLASS_CONTEXT | (4 << 2)), 4, 0, 0 }, /* shmName */ + { (ASN_TAG_CLASS_CONTEXT | (5 << 2)), 5, 0, 0 }, /* shmWriteIdx */ + { (ASN_TAG_CLASS_CONTEXT | (6 << 2)), 6, 0, 0 } /* nRanges */ +}; +static asn_SEQUENCE_specifics_t asn_SPC_Spectrum_SensingIndication_specs_1 = { + sizeof(struct Spectrum_SensingIndication), + offsetof(struct Spectrum_SensingIndication, _asn_ctx), + asn_MAP_Spectrum_SensingIndication_tag2el_1, + 7, /* Count of tags in the map */ + asn_MAP_Spectrum_SensingIndication_oms_1, /* Optional members */ + 1, 0, /* Root/Additions */ + -1, /* First extension addition */ +}; +asn_TYPE_descriptor_t asn_DEF_Spectrum_SensingIndication = { + "Spectrum-SensingIndication", + "Spectrum-SensingIndication", + &asn_OP_SEQUENCE, + asn_DEF_Spectrum_SensingIndication_tags_1, + sizeof(asn_DEF_Spectrum_SensingIndication_tags_1) + /sizeof(asn_DEF_Spectrum_SensingIndication_tags_1[0]), /* 1 */ + asn_DEF_Spectrum_SensingIndication_tags_1, /* Same as above */ + sizeof(asn_DEF_Spectrum_SensingIndication_tags_1) + /sizeof(asn_DEF_Spectrum_SensingIndication_tags_1[0]), /* 1 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_constraint + }, + asn_MBR_Spectrum_SensingIndication_1, + 7, /* Elements count */ + &asn_SPC_Spectrum_SensingIndication_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-SensingIndication.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-SensingIndication.h new file mode 100644 index 000000000..69c72439e --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-SensingIndication.h @@ -0,0 +1,45 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _Spectrum_SensingIndication_H_ +#define _Spectrum_SensingIndication_H_ + + +#include + +/* Including external dependencies */ +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Spectrum-SensingIndication */ +typedef struct Spectrum_SensingIndication { + long timestamp; + long sfn; + long slot; + long *beam; /* OPTIONAL */ + OCTET_STRING_t shmName; + long shmWriteIdx; + long nRanges; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Spectrum_SensingIndication_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Spectrum_SensingIndication; + +#ifdef __cplusplus +} +#endif + +#endif /* _Spectrum_SensingIndication_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-SensingPolicyControl.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-SensingPolicyControl.c new file mode 100644 index 000000000..82d890c39 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-SensingPolicyControl.c @@ -0,0 +1,284 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "Spectrum-SensingPolicyControl.h" + +static int +memb_NativeInteger_constraint_2(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 0L && value <= 16383L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_maskPerSlot_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + size_t size; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + /* Determine the number of elements */ + size = _A_CSEQUENCE_FROM_VOID(sptr)->count; + + if((size >= 1UL && size <= 160UL)) { + /* Perform validation of the inner elements */ + return SEQUENCE_OF_constraint(td, sptr, ctfailcb, app_key); + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +static int +memb_validityPeriod_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + long value; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + value = *(const long *)sptr; + + if((value >= 1L && value <= 3600L)) { + /* Constraint check succeeded */ + return 0; + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: constraint failed (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_Member_constr_3 CC_NOTUSED = { + { APC_CONSTRAINED, 14, 14, 0, 16383 } /* (0..16383) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_type_maskPerSlot_constr_2 CC_NOTUSED = { + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + { APC_CONSTRAINED, 8, 8, 1, 160 } /* (SIZE(1..160)) */, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_maskPerSlot_constr_2 CC_NOTUSED = { + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + { APC_CONSTRAINED, 8, 8, 1, 160 } /* (SIZE(1..160)) */, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +static asn_per_constraints_t asn_PER_memb_validityPeriod_constr_5 CC_NOTUSED = { + { APC_CONSTRAINED, 12, 12, 1, 3600 } /* (1..3600) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +static asn_TYPE_member_t asn_MBR_maskPerSlot_2[] = { + { ATF_POINTER, 0, 0, + (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), + 0, + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_Member_constr_3, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_NativeInteger_constraint_2 + }, + 0, 0, /* No default value */ + "" + }, +}; +static const ber_tlv_tag_t asn_DEF_maskPerSlot_tags_2[] = { + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static asn_SET_OF_specifics_t asn_SPC_maskPerSlot_specs_2 = { + sizeof(struct Spectrum_SensingPolicyControl__maskPerSlot), + offsetof(struct Spectrum_SensingPolicyControl__maskPerSlot, _asn_ctx), + 0, /* XER encoding is XMLDelimitedItemList */ +}; +static /* Use -fall-defs-global to expose */ +asn_TYPE_descriptor_t asn_DEF_maskPerSlot_2 = { + "maskPerSlot", + "maskPerSlot", + &asn_OP_SEQUENCE_OF, + asn_DEF_maskPerSlot_tags_2, + sizeof(asn_DEF_maskPerSlot_tags_2) + /sizeof(asn_DEF_maskPerSlot_tags_2[0]) - 1, /* 1 */ + asn_DEF_maskPerSlot_tags_2, /* Same as above */ + sizeof(asn_DEF_maskPerSlot_tags_2) + /sizeof(asn_DEF_maskPerSlot_tags_2[0]), /* 2 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_type_maskPerSlot_constr_2, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_OF_constraint + }, + asn_MBR_maskPerSlot_2, + 1, /* Single element */ + &asn_SPC_maskPerSlot_specs_2 /* Additional specs */ +}; + +static int asn_DFL_4_cmp_0(const void *sptr) { + const BOOLEAN_t *st = sptr; + + if(!st) { + return -1; /* No value is not a default value */ + } + + /* Test default value 0 */ + return (*st != 0); +} +static int asn_DFL_4_set_0(void **sptr) { + BOOLEAN_t *st = *sptr; + + if(!st) { + st = (*sptr = CALLOC(1, sizeof(*st))); + if(!st) return -1; + } + + /* Install default value 0 */ + *st = 0; + return 0; +} +asn_TYPE_member_t asn_MBR_Spectrum_SensingPolicyControl_1[] = { + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_SensingPolicyControl, maskPerSlot), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + 0, + &asn_DEF_maskPerSlot_2, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_maskPerSlot_constr_2, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_maskPerSlot_constraint_1 + }, + 0, 0, /* No default value */ + "maskPerSlot" + }, + { ATF_NOFLAGS, 2, offsetof(struct Spectrum_SensingPolicyControl, deactivate), + (ASN_TAG_CLASS_CONTEXT | (1 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_BOOLEAN, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + &asn_DFL_4_cmp_0, /* Compare DEFAULT 0 */ + &asn_DFL_4_set_0, /* Set DEFAULT 0 */ + "deactivate" + }, + { ATF_POINTER, 1, offsetof(struct Spectrum_SensingPolicyControl, validityPeriod), + (ASN_TAG_CLASS_CONTEXT | (2 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_memb_validityPeriod_constr_5, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + memb_validityPeriod_constraint_1 + }, + 0, 0, /* No default value */ + "validityPeriod" + }, +}; +static const int asn_MAP_Spectrum_SensingPolicyControl_oms_1[] = { 1, 2 }; +static const ber_tlv_tag_t asn_DEF_Spectrum_SensingPolicyControl_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static const asn_TYPE_tag2member_t asn_MAP_Spectrum_SensingPolicyControl_tag2el_1[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* maskPerSlot */ + { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* deactivate */ + { (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 } /* validityPeriod */ +}; +asn_SEQUENCE_specifics_t asn_SPC_Spectrum_SensingPolicyControl_specs_1 = { + sizeof(struct Spectrum_SensingPolicyControl), + offsetof(struct Spectrum_SensingPolicyControl, _asn_ctx), + asn_MAP_Spectrum_SensingPolicyControl_tag2el_1, + 3, /* Count of tags in the map */ + asn_MAP_Spectrum_SensingPolicyControl_oms_1, /* Optional members */ + 2, 0, /* Root/Additions */ + -1, /* First extension addition */ +}; +asn_TYPE_descriptor_t asn_DEF_Spectrum_SensingPolicyControl = { + "Spectrum-SensingPolicyControl", + "Spectrum-SensingPolicyControl", + &asn_OP_SEQUENCE, + asn_DEF_Spectrum_SensingPolicyControl_tags_1, + sizeof(asn_DEF_Spectrum_SensingPolicyControl_tags_1) + /sizeof(asn_DEF_Spectrum_SensingPolicyControl_tags_1[0]), /* 1 */ + asn_DEF_Spectrum_SensingPolicyControl_tags_1, /* Same as above */ + sizeof(asn_DEF_Spectrum_SensingPolicyControl_tags_1) + /sizeof(asn_DEF_Spectrum_SensingPolicyControl_tags_1[0]), /* 1 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_constraint + }, + asn_MBR_Spectrum_SensingPolicyControl_1, + 3, /* Elements count */ + &asn_SPC_Spectrum_SensingPolicyControl_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-SensingPolicyControl.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-SensingPolicyControl.h new file mode 100644 index 000000000..7413b2e46 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-SensingPolicyControl.h @@ -0,0 +1,50 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _Spectrum_SensingPolicyControl_H_ +#define _Spectrum_SensingPolicyControl_H_ + + +#include + +/* Including external dependencies */ +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Spectrum-SensingPolicyControl */ +typedef struct Spectrum_SensingPolicyControl { + struct Spectrum_SensingPolicyControl__maskPerSlot { + A_SEQUENCE_OF(long) list; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; + } maskPerSlot; + BOOLEAN_t deactivate; /* DEFAULT FALSE */ + long *validityPeriod; /* OPTIONAL */ + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Spectrum_SensingPolicyControl_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Spectrum_SensingPolicyControl; +extern asn_SEQUENCE_specifics_t asn_SPC_Spectrum_SensingPolicyControl_specs_1; +extern asn_TYPE_member_t asn_MBR_Spectrum_SensingPolicyControl_1[3]; + +#ifdef __cplusplus +} +#endif + +#endif /* _Spectrum_SensingPolicyControl_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-XAppControlData.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-XAppControlData.c new file mode 100644 index 000000000..a56f9a08f --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-XAppControlData.c @@ -0,0 +1,86 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "Spectrum-XAppControlData.h" + +static asn_TYPE_member_t asn_MBR_Spectrum_XAppControlData_1[] = { + { ATF_POINTER, 1, offsetof(struct Spectrum_XAppControlData, timestamp), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NativeInteger, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "timestamp" + }, + { ATF_NOFLAGS, 0, offsetof(struct Spectrum_XAppControlData, controlPayload), + (ASN_TAG_CLASS_CONTEXT | (1 << 2)), + +1, /* EXPLICIT tag at current level */ + &asn_DEF_Spectrum_XAppControlPayload, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "controlPayload" + }, +}; +static const int asn_MAP_Spectrum_XAppControlData_oms_1[] = { 0 }; +static const ber_tlv_tag_t asn_DEF_Spectrum_XAppControlData_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static const asn_TYPE_tag2member_t asn_MAP_Spectrum_XAppControlData_tag2el_1[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* timestamp */ + { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* controlPayload */ +}; +static asn_SEQUENCE_specifics_t asn_SPC_Spectrum_XAppControlData_specs_1 = { + sizeof(struct Spectrum_XAppControlData), + offsetof(struct Spectrum_XAppControlData, _asn_ctx), + asn_MAP_Spectrum_XAppControlData_tag2el_1, + 2, /* Count of tags in the map */ + asn_MAP_Spectrum_XAppControlData_oms_1, /* Optional members */ + 1, 0, /* Root/Additions */ + -1, /* First extension addition */ +}; +asn_TYPE_descriptor_t asn_DEF_Spectrum_XAppControlData = { + "Spectrum-XAppControlData", + "Spectrum-XAppControlData", + &asn_OP_SEQUENCE, + asn_DEF_Spectrum_XAppControlData_tags_1, + sizeof(asn_DEF_Spectrum_XAppControlData_tags_1) + /sizeof(asn_DEF_Spectrum_XAppControlData_tags_1[0]), /* 1 */ + asn_DEF_Spectrum_XAppControlData_tags_1, /* Same as above */ + sizeof(asn_DEF_Spectrum_XAppControlData_tags_1) + /sizeof(asn_DEF_Spectrum_XAppControlData_tags_1[0]), /* 1 */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + SEQUENCE_constraint + }, + asn_MBR_Spectrum_XAppControlData_1, + 2, /* Elements count */ + &asn_SPC_Spectrum_XAppControlData_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-XAppControlData.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-XAppControlData.h new file mode 100644 index 000000000..2c704e825 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-XAppControlData.h @@ -0,0 +1,40 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _Spectrum_XAppControlData_H_ +#define _Spectrum_XAppControlData_H_ + + +#include + +/* Including external dependencies */ +#include +#include "Spectrum-XAppControlPayload.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Spectrum-XAppControlData */ +typedef struct Spectrum_XAppControlData { + long *timestamp; /* OPTIONAL */ + Spectrum_XAppControlPayload_t controlPayload; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Spectrum_XAppControlData_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Spectrum_XAppControlData; + +#ifdef __cplusplus +} +#endif + +#endif /* _Spectrum_XAppControlData_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-XAppControlPayload.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-XAppControlPayload.c new file mode 100644 index 000000000..157d1e323 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-XAppControlPayload.c @@ -0,0 +1,90 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#include "Spectrum-XAppControlPayload.h" + +#include "Spectrum-PRBBlockedControl.h" +#include "Spectrum-ConfigControl.h" +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +asn_per_constraints_t asn_PER_type_Spectrum_XAppControlPayload_constr_1 CC_NOTUSED = { + { APC_CONSTRAINED | APC_EXTENSIBLE, 1, 1, 0, 1 } /* (0..1,...) */, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ +asn_TYPE_member_t asn_MBR_Spectrum_XAppControlPayload_1[] = { + { ATF_POINTER, 0, offsetof(struct Spectrum_XAppControlPayload, choice.prbBlockedControl), + (ASN_TAG_CLASS_CONTEXT | (0 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_Spectrum_PRBBlockedControl, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "prbBlockedControl" + }, + { ATF_POINTER, 0, offsetof(struct Spectrum_XAppControlPayload, choice.configControl), + (ASN_TAG_CLASS_CONTEXT | (1 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_Spectrum_ConfigControl, + 0, + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + 0 + }, + 0, 0, /* No default value */ + "configControl" + }, +}; +static const asn_TYPE_tag2member_t asn_MAP_Spectrum_XAppControlPayload_tag2el_1[] = { + { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* prbBlockedControl */ + { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* configControl */ +}; +asn_CHOICE_specifics_t asn_SPC_Spectrum_XAppControlPayload_specs_1 = { + sizeof(struct Spectrum_XAppControlPayload), + offsetof(struct Spectrum_XAppControlPayload, _asn_ctx), + offsetof(struct Spectrum_XAppControlPayload, present), + sizeof(((struct Spectrum_XAppControlPayload *)0)->present), + asn_MAP_Spectrum_XAppControlPayload_tag2el_1, + 2, /* Count of tags in the map */ + 0, 0, + 2 /* Extensions start */ +}; +asn_TYPE_descriptor_t asn_DEF_Spectrum_XAppControlPayload = { + "Spectrum-XAppControlPayload", + "Spectrum-XAppControlPayload", + &asn_OP_CHOICE, + 0, /* No effective tags (pointer) */ + 0, /* No effective tags (count) */ + 0, /* No tags (pointer) */ + 0, /* No tags (count) */ + { +#if !defined(ASN_DISABLE_OER_SUPPORT) + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + &asn_PER_type_Spectrum_XAppControlPayload_constr_1, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + CHOICE_constraint + }, + asn_MBR_Spectrum_XAppControlPayload_1, + 2, /* Elements count */ + &asn_SPC_Spectrum_XAppControlPayload_specs_1 /* Additional specs */ +}; + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-XAppControlPayload.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-XAppControlPayload.h new file mode 100644 index 000000000..1b20b9eed --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/Spectrum-XAppControlPayload.h @@ -0,0 +1,61 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "SPECTRUM-SM" + * found in "e3sm_spectrum.asn" + * `asn1c -pdu=all -no-gen-BER -no-gen-UPER -no-gen-OER -no-gen-JER -fno-include-deps -fcompound-names -findirect-choice -no-gen-example -D compiled_output` + */ + +#ifndef _Spectrum_XAppControlPayload_H_ +#define _Spectrum_XAppControlPayload_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum Spectrum_XAppControlPayload_PR { + Spectrum_XAppControlPayload_PR_NOTHING, /* No components present */ + Spectrum_XAppControlPayload_PR_prbBlockedControl, + Spectrum_XAppControlPayload_PR_configControl + /* Extensions may appear below */ + +} Spectrum_XAppControlPayload_PR; + +/* Forward declarations */ +struct Spectrum_PRBBlockedControl; +struct Spectrum_ConfigControl; + +/* Spectrum-XAppControlPayload */ +typedef struct Spectrum_XAppControlPayload { + Spectrum_XAppControlPayload_PR present; + union Spectrum_XAppControlPayload_u { + struct Spectrum_PRBBlockedControl *prbBlockedControl; + struct Spectrum_ConfigControl *configControl; + /* + * This type is extensible, + * possible extensions are below. + */ + } choice; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Spectrum_XAppControlPayload_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Spectrum_XAppControlPayload; +extern asn_CHOICE_specifics_t asn_SPC_Spectrum_XAppControlPayload_specs_1; +extern asn_TYPE_member_t asn_MBR_Spectrum_XAppControlPayload_1[2]; +extern asn_per_constraints_t asn_PER_type_Spectrum_XAppControlPayload_constr_1; + +#ifdef __cplusplus +} +#endif + +#endif /* _Spectrum_XAppControlPayload_H_ */ +#include diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_decoder.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_decoder.c new file mode 100644 index 000000000..0637b6a5a --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_decoder.c @@ -0,0 +1,91 @@ +#include +#include +#include + +asn_dec_rval_t +aper_decode_complete(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **sptr, + const void *buffer, size_t size) { + asn_dec_rval_t rval; + + rval = aper_decode(opt_codec_ctx, td, sptr, buffer, size, 0, 0); + if(rval.consumed) { + /* + * We've always given 8-aligned data, + * so convert bits to integral bytes. + */ + rval.consumed += 7; + rval.consumed >>= 3; + } else if(rval.code == RC_OK) { + if(size) { + if(((const uint8_t *)buffer)[0] == 0) { + rval.consumed = 1; /* 1 byte */ + } else { + ASN_DEBUG("Expecting single zeroed byte"); + rval.code = RC_FAIL; + } + } else { + /* Must contain at least 8 bits. */ + rval.code = RC_WMORE; + } + } + + return rval; +} + +asn_dec_rval_t +aper_decode(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **sptr, const void *buffer, + size_t size, int skip_bits, int unused_bits) { + asn_codec_ctx_t s_codec_ctx; + asn_dec_rval_t rval; + asn_per_data_t pd; + + if(skip_bits < 0 || skip_bits > 7 + || unused_bits < 0 || unused_bits > 7 + || (unused_bits > 0 && !size)) + ASN__DECODE_FAILED; + + /* + * Stack checker requires that the codec context + * must be allocated on the stack. + */ + if(opt_codec_ctx) { + if(opt_codec_ctx->max_stack_size) { + s_codec_ctx = *opt_codec_ctx; + opt_codec_ctx = &s_codec_ctx; + } + } else { + /* If context is not given, be security-conscious anyway */ + memset(&s_codec_ctx, 0, sizeof(s_codec_ctx)); + s_codec_ctx.max_stack_size = ASN__DEFAULT_STACK_MAX; + opt_codec_ctx = &s_codec_ctx; + } + + /* Fill in the position indicator */ + memset(&pd, 0, sizeof(pd)); + pd.buffer = (const uint8_t *)buffer; + pd.nboff = skip_bits; + pd.nbits = 8 * size - unused_bits; /* 8 is CHAR_BIT from */ + if(pd.nboff > pd.nbits) + ASN__DECODE_FAILED; + + /* + * Invoke type-specific decoder. + */ + if(!td->op->aper_decoder) + ASN__DECODE_FAILED; /* PER is not compiled in */ + rval = td->op->aper_decoder(opt_codec_ctx, td, 0, sptr, &pd); + if(rval.code == RC_OK) { + /* Return the number of consumed bits */ + rval.consumed = ((pd.buffer - (const uint8_t *)buffer) << 3) + + pd.nboff - skip_bits; + ASN_DEBUG("PER decoding consumed %zu, counted %zu", + rval.consumed, pd.moved); + assert(rval.consumed == pd.moved); + } else { + /* PER codec is not a restartable */ + rval.consumed = 0; + } + return rval; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_decoder.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_decoder.h new file mode 100644 index 000000000..10352c710 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_decoder.h @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 2005-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _APER_DECODER_H_ +#define _APER_DECODER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* + * Aligned PER decoder of a "complete encoding" as per X.691#10.1. + * On success, this call always returns (.consumed >= 1), in BITS, as per X.691#10.1.3. + */ +asn_dec_rval_t aper_decode_complete( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *type_descriptor, /* Type to decode */ + void **struct_ptr, /* Pointer to a target structure's pointer */ + const void *buffer, /* Data to be decoded */ + size_t size /* Size of data buffer */ + ); + +/* + * Aligned PER decoder of any ASN.1 type. May be invoked by the application. + * WARNING: This call returns the number of BITS read from the stream. Beware. + */ +asn_dec_rval_t aper_decode( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *type_descriptor, /* Type to decode */ + void **struct_ptr, /* Pointer to a target structure's pointer */ + const void *buffer, /* Data to be decoded */ + size_t size, /* Size of data buffer */ + int skip_bits, /* Number of unused leading bits, 0..7 */ + int unused_bits /* Number of unused tailing bits, 0..7 */ + ); + +#ifdef __cplusplus +} +#endif + +#endif /* _APER_DECODER_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_encoder.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_encoder.c new file mode 100644 index 000000000..d9b1c1df1 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_encoder.c @@ -0,0 +1,129 @@ +#include +#include +#include + +/* + * Argument type and callback necessary for aper_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 +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); + } +} + +/* + * Internally useful functions. + */ + +/* Flush partially filled buffer */ +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 ? cb : ignore_output; + 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/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_encoder.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_encoder.h new file mode 100644 index 000000000..957b0bdbe --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_encoder.h @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2006-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _APER_ENCODER_H_ +#define _APER_ENCODER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* + * Aligned PER encoder of any ASN.1 type. May be invoked by the application. + * WARNING: This function returns the number of encoded bits in the .encoded + * field of the return value. Use the following formula to convert to bytes: + * bytes = ((.encoded + 7) / 8) + */ +asn_enc_rval_t aper_encode( + const struct asn_TYPE_descriptor_s *type_descriptor, + const asn_per_constraints_t *constraints, + const void *struct_ptr, /* Structure to be encoded */ + asn_app_consume_bytes_f *consume_bytes_cb, /* Data collector */ + void *app_key /* Arbitrary callback argument */ +); + +/* + * A variant of aper_encode() which encodes data into the existing buffer + * WARNING: This function returns the number of encoded bits in the .encoded + * field of the return value. + */ +asn_enc_rval_t aper_encode_to_buffer( + const struct asn_TYPE_descriptor_s *type_descriptor, + const asn_per_constraints_t *constraints, + const void *struct_ptr, /* Structure to be encoded */ + void *buffer, /* Pre-allocated buffer */ + size_t buffer_size /* Initial buffer size (max) */ +); + +/* + * A variant of aper_encode_to_buffer() which allocates buffer itself. + * Returns the number of bytes in the buffer or -1 in case of failure. + * WARNING: This function produces a "Production of the complete encoding", + * with length of at least one octet. Contrast this to precise bit-packing + * encoding of aper_encode() and aper_encode_to_buffer(). + */ +ssize_t +aper_encode_to_new_buffer( + const struct asn_TYPE_descriptor_s *td, + const asn_per_constraints_t *constraints, + const void *sptr, + void **buffer_r +); + +#ifdef __cplusplus +} +#endif + +#endif /* _APER_ENCODER_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_opentype.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_opentype.c new file mode 100644 index 000000000..cdd5999b2 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_opentype.c @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2007 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include +#include + +static asn_dec_rval_t +aper_open_type_get_simple(const asn_codec_ctx_t *ctx, + const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) { + asn_dec_rval_t rv; + ssize_t chunk_bytes; + int repeat; + uint8_t *buf = 0; + size_t bufLen = 0; + size_t bufSize = 0; + asn_per_data_t spd; + size_t padding; + + ASN__STACK_OVERFLOW_CHECK(ctx); + + ASN_DEBUG("Getting open type %s...", td->name); + + do { + chunk_bytes = aper_get_length(pd, -1, -1, -1, &repeat); + if(chunk_bytes < 0) { + FREEMEM(buf); + ASN__DECODE_STARVED; + } + if(bufLen + chunk_bytes > bufSize) { + void *ptr; + bufSize = chunk_bytes + (bufSize << 2); + ptr = REALLOC(buf, bufSize); + if(!ptr) { + FREEMEM(buf); + ASN__DECODE_FAILED; + } + buf = ptr; + } + if(per_get_many_bits(pd, buf + bufLen, 0, chunk_bytes << 3)) { + FREEMEM(buf); + ASN__DECODE_STARVED; + } + bufLen += chunk_bytes; + } while(repeat); + + ASN_DEBUG("Getting open type %s encoded in %ld bytes", td->name, + (long)bufLen); + + memset(&spd, 0, sizeof(spd)); + spd.buffer = buf; + spd.nbits = bufLen << 3; + + ASN_DEBUG_INDENT_ADD(+4); + rv = td->op->aper_decoder(ctx, td, constraints, sptr, &spd); + ASN_DEBUG_INDENT_ADD(-4); + + if(rv.code == RC_OK) { + /* Check padding validity */ + padding = spd.nbits - spd.nboff; + if (((padding > 0 && padding < 8) || + /* X.691#10.1.3 */ + (spd.nboff == 0 && spd.nbits == 8 && spd.buffer == buf)) && + per_get_few_bits(&spd, padding) == 0) { + /* Everything is cool */ + FREEMEM(buf); + return rv; + } + FREEMEM(buf); + if(padding >= 8) { + ASN_DEBUG("Too large padding %d in open type", (int)padding); + ASN__DECODE_FAILED; + } else { + ASN_DEBUG("No padding"); + } + } else { + FREEMEM(buf); + /* rv.code could be RC_WMORE, nonsense in this context */ + rv.code = RC_FAIL; /* Noone would give us more */ + } + + return rv; +} + +int +aper_open_type_put(const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, + const void *sptr, asn_per_outp_t *po) { + void *buf; + void *bptr; + ssize_t size; + size_t toGo; + + ASN_DEBUG("Open type put %s ...", td->name); + + size = aper_encode_to_new_buffer(td, constraints, sptr, &buf); + if(size <= 0) return -1; + + for(bptr = buf, toGo = size; toGo;) { + int need_eom = 0; + ssize_t maySave = aper_put_length(po, -1, -1, toGo, &need_eom); + if(maySave < 0) break; + if(per_put_many_bits(po, bptr, maySave * 8)) break; + bptr = (char *)bptr + maySave; + toGo -= maySave; + if(need_eom && (aper_put_length(po, -1, -1, 0, NULL) < 0)) { + FREEMEM(buf); + return -1; + } + } + + FREEMEM(buf); + if(toGo) return -1; + + ASN_DEBUG("Open type put %s of length %zd + overhead (1byte?)", + td->name, size); + + return 0; +} + +asn_dec_rval_t +aper_open_type_get(const asn_codec_ctx_t *ctx, + const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, + void **sptr, asn_per_data_t *pd) { + + return aper_open_type_get_simple(ctx, td, constraints, sptr, pd); +} + +int +aper_open_type_skip(const asn_codec_ctx_t *ctx, asn_per_data_t *pd) { + asn_TYPE_descriptor_t s_td; + asn_dec_rval_t rv; + asn_TYPE_operation_t op_t; + + memset(&op_t, 0, sizeof(op_t)); + s_td.name = ""; + s_td.op = &op_t; + s_td.op->aper_decoder = uper_sot_suck; + + rv = aper_open_type_get(ctx, &s_td, 0, 0, pd); + if(rv.code != RC_OK) + return -1; + else + return 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_opentype.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_opentype.h new file mode 100644 index 000000000..451b01c3b --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_opentype.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2007-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _APER_OPENTYPE_H_ +#define _APER_OPENTYPE_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +asn_dec_rval_t aper_open_type_get(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); + + +int aper_open_type_skip(const asn_codec_ctx_t *opt_codec_ctx, asn_per_data_t *pd); + +int aper_open_type_put(const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, + const void *sptr, asn_per_outp_t *po); + +#ifdef __cplusplus +} +#endif + +#endif /* _APER_OPENTYPE_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_support.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_support.c new file mode 100644 index 000000000..6731c1c76 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_support.c @@ -0,0 +1,360 @@ +/* + * Copyright (c) 2005-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +int32_t +aper_get_align(asn_per_data_t *pd) { + + if(pd->nboff & 0x7) { + ASN_DEBUG("Aligning %ld bits", 8 - ((unsigned long)pd->nboff & 0x7)); + return per_get_few_bits(pd, 8 - (pd->nboff & 0x7)); + } + return 0; +} + +ssize_t +aper_get_length(asn_per_data_t *pd, ssize_t lb, ssize_t ub, + int ebits, int *repeat) { + int constrained = (lb >= 0) && (ub >= 0); + ssize_t value; + + *repeat = 0; + + if (constrained && ub < 65536) { + return aper_get_constrained_whole_number(pd, lb, ub); + } + + if (aper_get_align(pd) < 0) + return -1; + + if(ebits >= 0) return per_get_few_bits(pd, ebits); + + value = per_get_few_bits(pd, 8); + if(value < 0) return -1; + if((value & 128) == 0) /* #11.9.3.6 */ + return (value & 0x7F); + if((value & 64) == 0) { /* #11.9.3.7 */ + value = ((value & 63) << 8) | per_get_few_bits(pd, 8); + if(value < 0) return -1; + return value; + } + value &= 63; /* this is "m" from X.691, #11.9.3.8 */ + if(value < 1 || value > 4) + return -1; + *repeat = 1; + return (16384 * value); +} + +ssize_t +aper_get_nslength(asn_per_data_t *pd) { + ssize_t length; + + ASN_DEBUG("Getting normally small length"); + + if(per_get_few_bits(pd, 1) == 0) { + length = per_get_few_bits(pd, 6) + 1; + if(length <= 0) return -1; + ASN_DEBUG("l=%zd", length); + return length; + } else { + int repeat; + length = aper_get_length(pd, -1, -1, -1, &repeat); + if(length >= 0 && !repeat) return length; + return -1; /* Error, or do not support >16K extensions */ + } +} + +ssize_t +aper_get_nsnnwn(asn_per_data_t *pd) { + int b; + int length; + + ASN_DEBUG("getting nsnnwn"); + + b = per_get_few_bits(pd, 1); + if (b == -1) + return -1; + + /* X.691 2002 10.6.1 */ + if (b == 0) + return per_get_few_bits(pd, 6); + + if (aper_get_align(pd) < 0) + return -1; + + /* X.691 2002 10.6.2 */ + /* X.691 2002 10.9.3.5 */ + b = per_get_few_bits(pd, 1); + if (b == -1) + return -1; + + if (b == 1) { + /* other 10.9.3.x cases not handled, it's doubtful we reach them in practice */ + ASN_DEBUG("todo: X.691 2002 10.9.3.x"); + return -1; + } + + /* X.691 2002 10.9.3.6 */ + length = per_get_few_bits(pd, 7); + if (length > 4) { + /* todo */ + ASN_DEBUG("todo: X.691 2002 10.9.3.6 for length > 4"); + return -1; + } + ASN_DEBUG("length %d\n", length); + + /* todo: 0xffffffff will be seen as -1 and will lead to decoding failure */ + return per_get_few_bits(pd, length * 8); +} + +/* X.691 2002 10.5 - Decoding of a constrained whole number */ +long +aper_get_constrained_whole_number(asn_per_data_t *pd, long lb, long ub) { + assert(ub >= lb); + long range = ub - lb + 1; + int range_len; + int value_len; + long value; + + ASN_DEBUG("aper get constrained_whole_number with lb %ld and ub %ld", lb, ub); + + /* X.691 2002 10.5.4 */ + if (range == 1) + return lb; + + /* X.691 2002 10.5.7.1 - The bit-field case. */ + if (range <= 255) { + int bitfield_size = 8; + for (bitfield_size = 8; bitfield_size >= 2; bitfield_size--) + if ((range - 1) & (1 << (bitfield_size-1))) + break; + value = per_get_few_bits(pd, bitfield_size); + if (value < 0 || value >= range) + return -1; + return value + lb; + } + + /* X.691 2002 10.5.7.2 - The one-octet case. */ + if (range == 256) { + if (aper_get_align(pd)) + return -1; + value = per_get_few_bits(pd, 8); + if (value < 0 || value >= range) + return -1; + return value + lb; + } + + /* X.691 2002 10.5.7.3 - The two-octet case. */ + if (range <= 65536) { + if (aper_get_align(pd)) + return -1; + value = per_get_few_bits(pd, 16); + if (value < 0 || value >= range) + return -1; + return value + lb; + } + + /* X.691 2002 10.5.7.4 - The indefinite length case. */ + /* since we limit input to be 'long' we don't handle all numbers */ + /* and so length determinant is retrieved as X.691 2002 10.9.3.3 */ + /* number of bytes to store the range */ + for (range_len = 3; ; range_len++) { + long bits = ((long)1) << (8 * range_len); + if (range - 1 < bits) + break; + } + value_len = aper_get_constrained_whole_number(pd, 1, range_len); + if (value_len == -1) + return -1; + if (value_len > 4) { + ASN_DEBUG("todo: aper_get_constrained_whole_number: value_len > 4"); + return -1; + } + if (aper_get_align(pd)) + return -1; + value = per_get_few_bits(pd, value_len * 8); + if (value < 0 || value >= range) + return -1; + return value + lb; +} + +int aper_put_align(asn_per_outp_t *po) { + + if(po->nboff & 0x7) { + ASN_DEBUG("Aligning %ld bits", 8 - ((unsigned long)po->nboff & 0x7)); + if(per_put_few_bits(po, 0x00, (8 - (po->nboff & 0x7)))) + return -1; + } + return 0; +} + +ssize_t +aper_put_length(asn_per_outp_t *po, ssize_t lb, ssize_t ub, size_t n, int *need_eom) { + int constrained = (lb >= 0) && (ub >= 0); + int dummy = 0; + if(!need_eom) need_eom = &dummy; + + *need_eom = 0; + + + ASN_DEBUG("APER put length %zu with range (%zd..%zd)", n, lb, ub); + + /* X.691 2002 10.9.3.3 */ + if (constrained && ub < 65536) + return aper_put_constrained_whole_number(po, lb, ub, n + lb) ? -1 : (ssize_t)n; + + if (aper_put_align(po) < 0) + return -1; + + if(n <= 127) { /* #11.9.3.6 */ + return per_put_few_bits(po, n, 8) + ? -1 : (ssize_t)n; + } + else if(n < 16384) /* #11.9.3.7 */ + return per_put_few_bits(po, n|0x8000, 16) + ? -1 : (ssize_t)n; + + *need_eom = 0 == (n & 16383); + n >>= 14; + if(n > 4) { + *need_eom = 0; + n = 4; + } + + return per_put_few_bits(po, 0xC0 | n, 8) + ? -1 : (ssize_t)(n << 14); +} + + +int +aper_put_nslength(asn_per_outp_t *po, size_t length) { + + if(length <= 64) { + /* #11.9.3.4 */ + if(length == 0) return -1; + return per_put_few_bits(po, length-1, 7) ? -1 : 0; + } else { + if(aper_put_length(po, -1, -1, length, NULL) != (ssize_t)length) { + /* This might happen in case of >16K extensions */ + return -1; + } + } + + return 0; +} + +int +aper_put_nsnnwn(asn_per_outp_t *po, int number) { + int len; + + ASN_DEBUG("aper put nsnnwn %d", number); + + if (number <= 63) { + if (per_put_few_bits(po, 0, 1)) + return -1; + return per_put_few_bits(po, number, 6); + } + + if (per_put_few_bits(po, 1, 1)) + return -1; + + if (number < 256) { + len = 1; + } else if (number < 65536) { + len = 2; + } else { /* number > 64K */ + int i; + for (i = 3; ; i++) { + int bits = 1 << (8 * i); + if (number < bits) + break; + } + len = i; + } + + if (aper_put_align(po) < 0) + return -1; + + /* put the length which is a non-constrained whole number */ + if (len <= 127) { + if(per_put_few_bits(po, 0, 1)) + return -1; + if(per_put_few_bits(po, len, 7)) + return -1; + } else { + /* todo but not big problem, it's very doubtful that the + * number of bytes to encode 'number' will be > 127 + */ + return -1; + } + if(aper_put_align(po) < 0) /* Aligning on octet */ + return -1; + return per_put_few_bits(po, number, 8 * len); +} + +/* X.691 2002 10.5 - Encoding of a constrained whole number */ +int +aper_put_constrained_whole_number(asn_per_outp_t *po, long lb, long ub, long number) { + assert(ub >= lb); + long range = ub - lb + 1; + long value = number - lb; + int range_len; + int value_len; + + ASN_DEBUG("aper put constrained_whole_number %ld with lb %ld and ub %ld", number, lb, ub); + + if (number < lb || number > ub) + return -1; + + /* X.691 2002 10.5.4 */ + if (range == 1) + return 0; + + /* X.691 2002 10.5.7.1 - The bit-field case. */ + if (range <= 255) { + int bitfield_size = 8; + for (bitfield_size = 8; bitfield_size >= 2; bitfield_size--) + if ((range - 1) & (1 << (bitfield_size-1))) + break; + return per_put_few_bits(po, value, bitfield_size); + } + + /* X.691 2002 10.5.7.2 - The one-octet case. */ + if (range == 256) { + if (aper_put_align(po)) + return -1; + return per_put_few_bits(po, value, 8); + } + + /* X.691 2002 10.5.7.3 - The two-octet case. */ + if (range <= 65536) { + if (aper_put_align(po)) + return -1; + return per_put_few_bits(po, value, 16); + } + + /* X.691 2002 10.5.7.4 - The indefinite length case. */ + /* since we limit input to be 'long' we don't handle all numbers */ + /* and so length determinant is stored as X.691 2002 10.9.3.3 */ + /* number of bytes to store the range */ + for (range_len = 3; ; range_len++) { + int bits = 1 << (8 * range_len); + if (range - 1 < bits) + break; + } + /* number of bytes to store the value */ + for (value_len = 1; ; value_len++) { + long bits = ((long)1) << (8 * value_len); + if (value < bits) + break; + } + if (aper_put_constrained_whole_number(po, 1, range_len, value_len)) + return -1; + if (aper_put_align(po)) + return -1; + return per_put_few_bits(po, value, value_len * 8); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_support.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_support.h new file mode 100644 index 000000000..62d37905e --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/aper_support.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2005-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _APER_SUPPORT_H_ +#define _APER_SUPPORT_H_ + +#include /* Platform-specific types */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * X.691 (08/2015) #11.9 "General rules for encoding a length determinant" + * Get the length "n" from the Aligned PER stream. + */ +ssize_t aper_get_length(asn_per_data_t *pd, ssize_t lb, ssize_t ub, + int effective_bound_bits, int *repeat); + +/* + * Get the normally small length "n". + */ +ssize_t aper_get_nslength(asn_per_data_t *pd); + +/* + * Get the normally small non-negative whole number. + */ +ssize_t aper_get_nsnnwn(asn_per_data_t *pd); + +/* + * Get the constrained whole number. + */ +long aper_get_constrained_whole_number(asn_per_data_t *po, long lb, long ub); + +/* + * X.691 (08/2015) #11.9 "General rules for encoding a length determinant" + * Put the length "n" to the Aligned PER stream. + * If (opt_need_eom) is given, it will be set to 1 if final 0-n is needed. + * In that case, invoke aper_put_length(po, -1, -1, 0, NULL) after encoding the + * last block. + * This function returns the number of units which may be flushed + * in the next units saving iteration. + */ +ssize_t aper_put_length(asn_per_outp_t *po, ssize_t lb, ssize_t ub, size_t n, + int *opt_need_eom); + +/* Align the current bit position to octet bundary */ +int aper_put_align(asn_per_outp_t *po); +int32_t aper_get_align(asn_per_data_t *pd); + +/* + * Put the normally small length "n" to the Unaligned PER stream. + * Returns 0 or -1. + */ +int aper_put_nslength(asn_per_outp_t *po, size_t length); + +/* + * Put the normally small non-negative whole number. + */ +int aper_put_nsnnwn(asn_per_outp_t *po, int number); + +/* + * Put the constrained whole number. + */ +int aper_put_constrained_whole_number(asn_per_outp_t *po, long lb, long ub, long number); + +#ifdef __cplusplus +} +#endif + +#endif /* _APER_SUPPORT_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_SEQUENCE_OF.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_SEQUENCE_OF.c new file mode 100644 index 000000000..ec952fc99 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_SEQUENCE_OF.c @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +typedef A_SEQUENCE_OF(void) asn_sequence; + +void +asn_sequence_del(void *asn_sequence_of_x, int number, int _do_free) { + asn_sequence *as = (asn_sequence *)asn_sequence_of_x; + + if(as) { + void *ptr; + int n; + + if(number < 0 || number >= as->count) + return; /* Nothing to delete */ + + if(_do_free && as->free) { + ptr = as->array[number]; + } else { + ptr = 0; + } + + /* + * Shift all elements to the left to hide the gap. + */ + --as->count; + for(n = number; n < as->count; n++) + as->array[n] = as->array[n+1]; + + /* + * Invoke the third-party function only when the state + * of the parent structure is consistent. + */ + if(ptr) as->free(ptr); + } +} + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_SEQUENCE_OF.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_SEQUENCE_OF.h new file mode 100644 index 000000000..e35bc447a --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_SEQUENCE_OF.h @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_SEQUENCE_OF_H +#define ASN_SEQUENCE_OF_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * SEQUENCE OF is the same as SET OF with a tiny difference: + * the delete operation preserves the initial order of elements + * and thus MAY operate in non-constant time. + */ +#define A_SEQUENCE_OF(type) A_SET_OF(type) + +#define ASN_SEQUENCE_ADD(headptr, ptr) \ + asn_sequence_add((headptr), (ptr)) + +/*********************************************** + * Implementation of the SEQUENCE OF structure. + */ + +#define asn_sequence_add asn_set_add +#define asn_sequence_empty asn_set_empty + +/* + * Delete the element from the set by its number (base 0). + * This is NOT a constant-time operation. + * The order of elements is preserved. + * If _do_free is given AND the (*free) is initialized, the element + * will be freed using the custom (*free) function as well. + */ +void asn_sequence_del(void *asn_sequence_of_x, int number, int _do_free); + +/* + * Cope with different conversions requirements to/from void in C and C++. + * This is mostly useful for support library. + */ +typedef A_SEQUENCE_OF(void) asn_anonymous_sequence_; +#define _A_SEQUENCE_FROM_VOID(ptr) ((asn_anonymous_sequence_ *)(ptr)) +#define _A_CSEQUENCE_FROM_VOID(ptr) ((const asn_anonymous_sequence_ *)(ptr)) + +#ifdef __cplusplus +} +#endif + +#endif /* ASN_SEQUENCE_OF_H */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_SET_OF.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_SET_OF.c new file mode 100644 index 000000000..944f2cb8a --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_SET_OF.c @@ -0,0 +1,88 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +/* + * Add another element into the set. + */ +int +asn_set_add(void *asn_set_of_x, void *ptr) { + asn_anonymous_set_ *as = _A_SET_FROM_VOID(asn_set_of_x); + + if(as == 0 || ptr == 0) { + errno = EINVAL; /* Invalid arguments */ + return -1; + } + + /* + * Make sure there's enough space to insert an element. + */ + if(as->count == as->size) { + int _newsize = as->size ? (as->size << 1) : 4; + void *_new_arr; + _new_arr = REALLOC(as->array, _newsize * sizeof(as->array[0])); + if(_new_arr) { + as->array = (void **)_new_arr; + as->size = _newsize; + } else { + /* ENOMEM */ + return -1; + } + } + + as->array[as->count++] = ptr; + + return 0; +} + +void +asn_set_del(void *asn_set_of_x, int number, int _do_free) { + asn_anonymous_set_ *as = _A_SET_FROM_VOID(asn_set_of_x); + + if(as) { + void *ptr; + if(number < 0 || number >= as->count) + return; + + if(_do_free && as->free) { + ptr = as->array[number]; + } else { + ptr = 0; + } + + as->array[number] = as->array[--as->count]; + + /* + * Invoke the third-party function only when the state + * of the parent structure is consistent. + */ + if(ptr) as->free(ptr); + } +} + +/* + * Free the contents of the set, do not free the set itself. + */ +void +asn_set_empty(void *asn_set_of_x) { + asn_anonymous_set_ *as = _A_SET_FROM_VOID(asn_set_of_x); + + if(as) { + if(as->array) { + if(as->free) { + while(as->count--) + as->free(as->array[as->count]); + } + FREEMEM(as->array); + as->array = 0; + } + as->count = 0; + as->size = 0; + } + +} + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_SET_OF.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_SET_OF.h new file mode 100644 index 000000000..882e1a47d --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_SET_OF.h @@ -0,0 +1,72 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_SET_OF_H +#define ASN_SET_OF_H + +#ifdef __cplusplus +#define A_SET_OF(type) \ + struct { \ + type **array; \ + int count; /* Meaningful size */ \ + int size; /* Allocated size */ \ + void (*free)(decltype(*array)); \ + } +#else /* C */ +#define A_SET_OF(type) \ + struct { \ + type **array; \ + int count; /* Meaningful size */ \ + int size; /* Allocated size */ \ + void (*free)(type *); \ + } +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define ASN_SET_ADD(headptr, ptr) \ + asn_set_add((headptr), (ptr)) + +/******************************************* + * Implementation of the SET OF structure. + */ + +/* + * Add another structure into the set by its pointer. + * RETURN VALUES: + * 0 for success and -1/errno for failure. + */ +int asn_set_add(void *asn_set_of_x, void *ptr); + +/* + * Delete the element from the set by its number (base 0). + * This is a constant-time operation. The order of elements before the + * deleted ones is guaranteed, the order of elements after the deleted + * one is NOT guaranteed. + * If _do_free is given AND the (*free) is initialized, the element + * will be freed using the custom (*free) function as well. + */ +void asn_set_del(void *asn_set_of_x, int number, int _do_free); + +/* + * Empty the contents of the set. Will free the elements, if (*free) is given. + * Will NOT free the set itself. + */ +void asn_set_empty(void *asn_set_of_x); + +/* + * Cope with different conversions requirements to/from void in C and C++. + * This is mostly useful for support library. + */ +typedef A_SET_OF(void) asn_anonymous_set_; +#define _A_SET_FROM_VOID(ptr) ((asn_anonymous_set_ *)(ptr)) +#define _A_CSET_FROM_VOID(ptr) ((const asn_anonymous_set_ *)(ptr)) + +#ifdef __cplusplus +} +#endif + +#endif /* ASN_SET_OF_H */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_application.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_application.c new file mode 100644 index 000000000..4309593d0 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_application.c @@ -0,0 +1,556 @@ +/* + * Copyright (c) 2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +static asn_enc_rval_t asn_encode_internal(const asn_codec_ctx_t *opt_codec_ctx, + enum asn_transfer_syntax syntax, + const asn_TYPE_descriptor_t *td, + const void *sptr, + asn_app_consume_bytes_f *callback, + void *callback_key); + + +struct callback_count_bytes_key { + asn_app_consume_bytes_f *callback; + void *callback_key; + size_t computed_size; +}; + +/* + * Encoder which just counts bytes that come through it. + */ +static int +callback_count_bytes_cb(const void *data, size_t size, void *keyp) { + struct callback_count_bytes_key *key = keyp; + int ret; + + ret = key->callback(data, size, key->callback_key); + if(ret >= 0) { + key->computed_size += size; + } + + return ret; +} + +struct overrun_encoder_key { + void *buffer; + size_t buffer_size; + size_t computed_size; +}; + +struct dynamic_encoder_key { + void *buffer; + size_t buffer_size; + size_t computed_size; +}; + +struct callback_failure_catch_key { + asn_app_consume_bytes_f *callback; + void *callback_key; + int callback_failed; +}; + +/* + * Encoder which doesn't stop counting bytes + * even if it reaches the end of the buffer. + */ +static int +overrun_encoder_cb(const void *data, size_t size, void *keyp) { + struct overrun_encoder_key *key = keyp; + + if(key->computed_size + size > key->buffer_size) { + /* + * Avoid accident on the next call: + * stop adding bytes to the buffer. + */ + key->buffer_size = 0; + } else { + memcpy((char *)key->buffer + key->computed_size, data, size); + } + key->computed_size += size; + + return 0; +} + +/* + * Encoder which dynamically allocates output, and continues + * to count even if allocation failed. + */ +static int +dynamic_encoder_cb(const void *data, size_t size, void *keyp) { + struct dynamic_encoder_key *key = keyp; + + if(key->buffer) { + if(key->computed_size + size >= key->buffer_size) { + void *p; + size_t new_size = key->buffer_size; + + do { + new_size *= 2; + } while(new_size <= key->computed_size + size); + + p = REALLOC(key->buffer, new_size); + if(p) { + key->buffer = p; + key->buffer_size = new_size; + } else { + FREEMEM(key->buffer); + key->buffer = 0; + key->buffer_size = 0; + key->computed_size += size; + return 0; + } + } + memcpy((char *)key->buffer + key->computed_size, data, size); + } + + key->computed_size += size; + + return 0; +} + +/* + * Encoder which help convert the application level encoder failure into EIO. + */ +static int +callback_failure_catch_cb(const void *data, size_t size, void *keyp) { + struct callback_failure_catch_key *key = keyp; + int ret; + + ret = key->callback(data, size, key->callback_key); + if(ret < 0) { + key->callback_failed = 1; + } + + return ret; +} + +asn_enc_rval_t +asn_encode(const asn_codec_ctx_t *opt_codec_ctx, + enum asn_transfer_syntax syntax, const asn_TYPE_descriptor_t *td, + const void *sptr, asn_app_consume_bytes_f *callback, void *callback_key) { + struct callback_failure_catch_key cb_key; + asn_enc_rval_t er = {0,0,0}; + + if(!callback) { + errno = EINVAL; + ASN__ENCODE_FAILED; + } + + cb_key.callback = callback; + cb_key.callback_key = callback_key; + cb_key.callback_failed = 0; + + er = asn_encode_internal(opt_codec_ctx, syntax, td, sptr, + callback_failure_catch_cb, &cb_key); + if(cb_key.callback_failed) { + assert(er.encoded == -1); + assert(errno == EBADF); + errno = EIO; + } + + return er; +} + +asn_enc_rval_t +asn_encode_to_buffer(const asn_codec_ctx_t *opt_codec_ctx, + enum asn_transfer_syntax syntax, + const asn_TYPE_descriptor_t *td, const void *sptr, + void *buffer, size_t buffer_size) { + struct overrun_encoder_key buf_key; + asn_enc_rval_t er = {0,0,0}; + + if(buffer_size > 0 && !buffer) { + errno = EINVAL; + ASN__ENCODE_FAILED; + } + + buf_key.buffer = buffer; + buf_key.buffer_size = buffer_size; + buf_key.computed_size = 0; + + er = asn_encode_internal(opt_codec_ctx, syntax, td, sptr, + overrun_encoder_cb, &buf_key); + + if(er.encoded >= 0 && (size_t)er.encoded != buf_key.computed_size) { + ASN_DEBUG("asn_encode() returned %" ASN_PRI_SSIZE + " yet produced %" ASN_PRI_SIZE " bytes", + er.encoded, buf_key.computed_size); + assert(er.encoded < 0 || (size_t)er.encoded == buf_key.computed_size); + } + + return er; +} + +asn_encode_to_new_buffer_result_t +asn_encode_to_new_buffer(const asn_codec_ctx_t *opt_codec_ctx, + enum asn_transfer_syntax syntax, + const asn_TYPE_descriptor_t *td, const void *sptr) { + struct dynamic_encoder_key buf_key; + asn_encode_to_new_buffer_result_t res; + + buf_key.buffer_size = 16; + buf_key.buffer = MALLOC(buf_key.buffer_size); + buf_key.computed_size = 0; + + res.result = asn_encode_internal(opt_codec_ctx, syntax, td, sptr, + dynamic_encoder_cb, &buf_key); + + if(res.result.encoded >= 0 + && (size_t)res.result.encoded != buf_key.computed_size) { + ASN_DEBUG("asn_encode() returned %" ASN_PRI_SSIZE + " yet produced %" ASN_PRI_SIZE " bytes", + res.result.encoded, buf_key.computed_size); + assert(res.result.encoded < 0 + || (size_t)res.result.encoded == buf_key.computed_size); + } + + res.buffer = buf_key.buffer; + + /* 0-terminate just in case. */ + if(res.buffer) { + assert(buf_key.computed_size < buf_key.buffer_size); + ((char *)res.buffer)[buf_key.computed_size] = '\0'; + } + + return res; +} + +static asn_enc_rval_t +asn_encode_internal(const asn_codec_ctx_t *opt_codec_ctx, + enum asn_transfer_syntax syntax, + const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_consume_bytes_f *callback, void *callback_key) { + asn_enc_rval_t er = {0,0,0}; +#if !defined(ASN_DISABLE_XER_SUPPORT) + enum xer_encoder_flags_e xer_flags = XER_F_CANONICAL; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + enum jer_encoder_flags_e jer_flags = JER_F; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + + (void)opt_codec_ctx; /* Parameters are not checked on encode yet. */ + + if(!td || !sptr) { + errno = EINVAL; + ASN__ENCODE_FAILED; + } + + switch(syntax) { + case ATS_NONSTANDARD_PLAINTEXT: + if(td->op->print_struct) { + struct callback_count_bytes_key cb_key; + cb_key.callback = callback; + cb_key.callback_key = callback_key; + cb_key.computed_size = 0; + if(td->op->print_struct(td, sptr, 1, callback_count_bytes_cb, + &cb_key) + < 0 + || callback_count_bytes_cb("\n", 1, &cb_key) < 0) { + errno = EBADF; /* Structure has incorrect form. */ + er.encoded = -1; + er.failed_type = td; + er.structure_ptr = sptr; + } else { + er.encoded = cb_key.computed_size; + er.failed_type = 0; + er.structure_ptr = 0; + } + } else { + errno = ENOENT; /* Transfer syntax is not defined for this type. */ + ASN__ENCODE_FAILED; + } + break; + + case ATS_RANDOM: + errno = ENOENT; /* Randomization doesn't make sense on output. */ + ASN__ENCODE_FAILED; + +#if !defined(ASN_DISABLE_BER_SUPPORT) + case ATS_BER: + /* BER is a superset of DER. */ + /* Fall through. */ + case ATS_DER: + if(td->op->der_encoder) { + er = der_encode(td, sptr, callback, callback_key); + if(er.encoded == -1) { + if(er.failed_type && er.failed_type->op->der_encoder) { + errno = EBADF; /* Structure has incorrect form. */ + } else { + errno = ENOENT; /* DER is not defined for this type. */ + } + } + } else { + errno = ENOENT; /* Transfer syntax is not defined for this type. */ + ASN__ENCODE_FAILED; + } + break; + case ATS_CER: + errno = ENOENT; /* Transfer syntax is not defined for any type. */ + ASN__ENCODE_FAILED; +#else + case ATS_BER: + case ATS_DER: + case ATS_CER: + errno = ENOENT; /* BER is not defined. */ + ASN__ENCODE_FAILED; + +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_OER_SUPPORT) + case ATS_BASIC_OER: + /* CANONICAL-OER is a superset of BASIC-OER. */ + /* Fall through. */ + case ATS_CANONICAL_OER: + if(td->op->oer_encoder) { + er = oer_encode(td, sptr, callback, callback_key); + if(er.encoded == -1) { + if(er.failed_type && er.failed_type->op->oer_encoder) { + errno = EBADF; /* Structure has incorrect form. */ + } else { + errno = ENOENT; /* OER is not defined for this type. */ + } + } + } else { + errno = ENOENT; /* Transfer syntax is not defined for this type. */ + ASN__ENCODE_FAILED; + } + break; +#else + case ATS_BASIC_OER: + case ATS_CANONICAL_OER: + errno = ENOENT; /* OER is not defined. */ + ASN__ENCODE_FAILED; + break; +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) + case ATS_UNALIGNED_BASIC_PER: + /* CANONICAL-UPER is a superset of BASIC-UPER. */ + /* Fall through. */ + case ATS_UNALIGNED_CANONICAL_PER: + if(td->op->uper_encoder) { + er = uper_encode(td, 0, sptr, callback, callback_key); + if(er.encoded == -1) { + if(er.failed_type && er.failed_type->op->uper_encoder) { + errno = EBADF; /* Structure has incorrect form. */ + } else { + errno = ENOENT; /* UPER is not defined for this type. */ + } + } else { + ASN_DEBUG("Complete encoded in %ld bits", (long)er.encoded); + if(er.encoded == 0) { + /* Enforce "Complete Encoding" of X.691 #11.1 */ + if(callback("\0", 1, callback_key) < 0) { + errno = EBADF; + ASN__ENCODE_FAILED; + } + er.encoded = 8; /* Exactly 8 zero bits is added. */ + } + /* Convert bits into bytes */ + er.encoded = (er.encoded + 7) >> 3; + } + } else { + errno = ENOENT; /* Transfer syntax is not defined for this type. */ + ASN__ENCODE_FAILED; + } + break; +#else + case ATS_UNALIGNED_BASIC_PER: + case ATS_UNALIGNED_CANONICAL_PER: + errno = ENOENT; /* UPER is not defined. */ + ASN__ENCODE_FAILED; + break; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + case ATS_ALIGNED_BASIC_PER: + /* CANONICAL-APER is a superset of BASIC-APER. */ + /* Fall through. */ + case ATS_ALIGNED_CANONICAL_PER: + if(td->op->aper_encoder) { + er = aper_encode(td, 0, sptr, callback, callback_key); + if(er.encoded == -1) { + if(er.failed_type && er.failed_type->op->aper_encoder) { + errno = EBADF; /* Structure has incorrect form. */ + } else { + errno = ENOENT; /* APER is not defined for this type. */ + } + } else { + ASN_DEBUG("Complete encoded in %ld bits", (long)er.encoded); + if(er.encoded == 0) { + /* Enforce "Complete Encoding" of X.691 #11.1 */ + if(callback("\0", 1, callback_key) < 0) { + errno = EBADF; + ASN__ENCODE_FAILED; + } + er.encoded = 8; /* Exactly 8 zero bits is added. */ + } + /* Convert bits into bytes */ + er.encoded = (er.encoded + 7) >> 3; + } + } else { + errno = ENOENT; /* Transfer syntax is not defined for this type. */ + ASN__ENCODE_FAILED; + } + break; +#else + case ATS_ALIGNED_BASIC_PER: + case ATS_ALIGNED_CANONICAL_PER: + errno = ENOENT; /* APER is not defined. */ + ASN__ENCODE_FAILED; + break; +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) + case ATS_BASIC_XER: + /* CANONICAL-XER is a superset of BASIC-XER. */ + xer_flags &= ~XER_F_CANONICAL; + xer_flags |= XER_F_BASIC; + /* Fall through. */ + case ATS_CANONICAL_XER: + if(td->op->xer_encoder) { + er = xer_encode(td, sptr, xer_flags, callback, callback_key); + if(er.encoded == -1) { + if(er.failed_type && er.failed_type->op->xer_encoder) { + errno = EBADF; /* Structure has incorrect form. */ + } else { + errno = ENOENT; /* XER is not defined for this type. */ + } + } + } else { + errno = ENOENT; /* Transfer syntax is not defined for this type. */ + ASN__ENCODE_FAILED; + } + break; +#else + case ATS_BASIC_XER: + case ATS_CANONICAL_XER: + errno = ENOENT; /* XER is not defined. */ + ASN__ENCODE_FAILED; + break; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) + case ATS_JER_MINIFIED: + /* Currently JER_F and JER_F_MINIFIED have opposite purposes + * so we just flip the flag. */ + jer_flags &= ~JER_F; + jer_flags |= JER_F_MINIFIED; + /* Fall through. */ + case ATS_JER: + if(td->op->jer_encoder) { + er = jer_encode(td, sptr, jer_flags, callback, callback_key); + if(er.encoded == -1) { + if(er.failed_type && er.failed_type->op->jer_encoder) { + errno = EBADF; /* Structure has incorrect form. */ + } else { + errno = ENOENT; /* JER is not defined for this type. */ + } + } + } else { + errno = ENOENT; /* Transfer syntax is not defined for this type. */ + ASN__ENCODE_FAILED; + } + break; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + default: + errno = ENOENT; + ASN__ENCODE_FAILED; + } + + return er; +} + +asn_dec_rval_t +asn_decode(const asn_codec_ctx_t *opt_codec_ctx, + enum asn_transfer_syntax syntax, const asn_TYPE_descriptor_t *td, + void **sptr, const void *buffer, size_t size) { + if(!td || !td->op || !sptr || (size && !buffer)) { + ASN__DECODE_FAILED; + } + + switch(syntax) { + case ATS_CER: + case ATS_NONSTANDARD_PLAINTEXT: + default: + errno = ENOENT; + ASN__DECODE_FAILED; + + case ATS_RANDOM: +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + if(!td->op->random_fill) { + ASN__DECODE_FAILED; + } else { + if(asn_random_fill(td, sptr, 16000) == 0) { + asn_dec_rval_t ret = {RC_OK, 0}; + return ret; + } else { + ASN__DECODE_FAILED; + } + } + break; +#else + errno = ENOENT; + ASN__DECODE_FAILED; +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + + case ATS_DER: + case ATS_BER: +#if !defined(ASN_DISABLE_BER_SUPPORT) + return ber_decode(opt_codec_ctx, td, sptr, buffer, size); +#else + errno = ENOENT; + ASN__DECODE_FAILED; +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + + case ATS_BASIC_OER: + case ATS_CANONICAL_OER: +#if !defined(ASN_DISABLE_OER_SUPPORT) + return oer_decode(opt_codec_ctx, td, sptr, buffer, size); +#else + errno = ENOENT; + ASN__DECODE_FAILED; +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + + case ATS_UNALIGNED_BASIC_PER: + case ATS_UNALIGNED_CANONICAL_PER: +#if !defined(ASN_DISABLE_UPER_SUPPORT) + return uper_decode_complete(opt_codec_ctx, td, sptr, buffer, size); +#else + errno = ENOENT; + ASN__DECODE_FAILED; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ + + case ATS_ALIGNED_BASIC_PER: + case ATS_ALIGNED_CANONICAL_PER: +#if !defined(ASN_DISABLE_APER_SUPPORT) + return aper_decode_complete(opt_codec_ctx, td, sptr, buffer, size); +#else + errno = ENOENT; + ASN__DECODE_FAILED; +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + + case ATS_BASIC_XER: + case ATS_CANONICAL_XER: +#if !defined(ASN_DISABLE_XER_SUPPORT) + return xer_decode(opt_codec_ctx, td, sptr, buffer, size); +#else + errno = ENOENT; + ASN__DECODE_FAILED; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + + case ATS_JER: + case ATS_JER_MINIFIED: +#if !defined(ASN_DISABLE_JER_SUPPORT) + return jer_decode(opt_codec_ctx, td, sptr, buffer, size); +#else + errno = ENOENT; + ASN__DECODE_FAILED; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + } +} + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_application.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_application.h new file mode 100644 index 000000000..355bc8458 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_application.h @@ -0,0 +1,179 @@ +/*- + * Copyright (c) 2004-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +/* + * Application-level ASN.1 callbacks. + */ +#ifndef ASN_APPLICATION_H +#define ASN_APPLICATION_H + +#include "asn_system.h" /* for platform-dependent types */ +#include "asn_codecs.h" /* for ASN.1 codecs specifics */ +#include "asn_config.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * A selection of ASN.1 Transfer Syntaxes to use with generalized + * encoders and decoders declared further in this .h file. + */ +enum asn_transfer_syntax { + /* Avoid appearance of a default transfer syntax. */ + ATS_INVALID = 0, + /* Plaintext output (not conforming to any standard), for debugging. */ + ATS_NONSTANDARD_PLAINTEXT, + /* Returns a randomly generated structure. */ + ATS_RANDOM, + /* + * X.690: + * BER: Basic Encoding Rules. + * DER: Distinguished Encoding Rules. + * CER: Canonical Encoding Rules. + * DER and CER are more strict variants of BER. + */ + ATS_BER, + ATS_DER, + ATS_CER, /* Only decoding is supported */ + /* + * X.696: + * OER: Octet Encoding Rules. + * CANONICAL-OER is a more strict variant of BASIC-OER. + */ + ATS_BASIC_OER, + ATS_CANONICAL_OER, + /* + * X.691: + * PER: Packed Encoding Rules. + * CANONICAL-PER is a more strict variant of BASIC-PER. + * NOTE: Produces or consumes a complete encoding (X.691 (08/2015) #11.1). + */ + ATS_UNALIGNED_BASIC_PER, + ATS_UNALIGNED_CANONICAL_PER, + ATS_ALIGNED_BASIC_PER, + ATS_ALIGNED_CANONICAL_PER, + /* + * X.693: + * XER: XML Encoding Rules. + * CANONICAL-XER is a more strict variant of BASIC-XER. + */ + ATS_BASIC_XER, + ATS_CANONICAL_XER, + /* + * X.697: + * JER: JSON Encoding Rules. + * MINIFIED produces a whitespace-free JSON. + */ + ATS_JER, + ATS_JER_MINIFIED, +}; + +/* + * A generic encoder for any supported transfer syntax. + * RETURN VALUES: + * The (.encoded) field of the return value is REDEFINED to mean the following: + * >=0: The computed size of the encoded data. Can exceed the (buffer_size). + * -1: Error encoding the structure. See the error code in (errno): + * EINVAL: Incorrect parameters to the function, such as NULLs. + * ENOENT: Encoding transfer syntax is not defined (for this type). + * EBADF: The structure has invalid form or content constraint failed. + * The (.failed_type) and (.structure_ptr) MIGHT be set to the appropriate + * values at the place of failure, if at all possible. + * WARNING: The (.encoded) field of the return value can exceed the buffer_size. + * This is similar to snprintf(3) contract which might return values + * greater than the buffer size. + */ +asn_enc_rval_t asn_encode_to_buffer( + const asn_codec_ctx_t *opt_codec_parameters, /* See asn_codecs.h */ + enum asn_transfer_syntax, + const struct asn_TYPE_descriptor_s *type_to_encode, + const void *structure_to_encode, void *buffer, size_t buffer_size); + +/* + * A variant of asn_encode_to_buffer() with automatically allocated buffer. + * RETURN VALUES: + * On success, returns a newly allocated (.buffer) containing the whole message. + * The message size is returned in (.result.encoded). + * On failure: + * (.buffer) is NULL, + * (.result.encoded) as in asn_encode_to_buffer(), + * The errno codes as in asn_encode_to_buffer(), plus the following: + * ENOMEM: Memory allocation failed due to system or internal limits. + * The user is responsible for freeing the (.buffer). + */ +typedef struct asn_encode_to_new_buffer_result_s { + void *buffer; /* NULL if failed to encode. */ + asn_enc_rval_t result; +} asn_encode_to_new_buffer_result_t; +asn_encode_to_new_buffer_result_t asn_encode_to_new_buffer( + const asn_codec_ctx_t *opt_codec_parameters, /* See asn_codecs.h */ + enum asn_transfer_syntax, + const struct asn_TYPE_descriptor_s *type_to_encode, + const void *structure_to_encode); + + +/* + * Generic type of an application-defined callback to return various + * types of data to the application. + * EXPECTED RETURN VALUES: + * -1: Failed to consume bytes. Abort the mission. + * Non-negative return values indicate success, and ignored. + */ +typedef int(asn_app_consume_bytes_f)(const void *buffer, size_t size, + void *application_specific_key); + + +/* + * A generic encoder for any supported transfer syntax. + * Returns the comprehensive encoding result descriptor (see asn_codecs.h). + * RETURN VALUES: + * The negative (.encoded) field of the return values is accompanied with the + * following error codes (errno): + * EINVAL: Incorrect parameters to the function, such as NULLs. + * ENOENT: Encoding transfer syntax is not defined (for this type). + * EBADF: The structure has invalid form or content constraint failed. + * EIO: The (callback) has returned negative value during encoding. + */ +asn_enc_rval_t asn_encode( + const asn_codec_ctx_t *opt_codec_parameters, /* See asn_codecs.h */ + enum asn_transfer_syntax, + const struct asn_TYPE_descriptor_s *type_to_encode, + const void *structure_to_encode, + asn_app_consume_bytes_f *callback, void *callback_key); + + +/* + * A generic decoder for any supported transfer syntax. + */ +asn_dec_rval_t asn_decode( + const asn_codec_ctx_t *opt_codec_parameters, enum asn_transfer_syntax, + const struct asn_TYPE_descriptor_s *type_to_decode, + void **structure_ptr, /* Pointer to a target structure's pointer */ + const void *buffer, /* Data to be decoded */ + size_t size /* Size of that buffer */ +); + + +/* + * A callback of this type is called whenever constraint validation fails + * on some ASN.1 type. See "constraints.h" for more details on constraint + * validation. + * This callback specifies a descriptor of the ASN.1 type which failed + * the constraint check, as well as human readable message on what + * particular constraint has failed. + */ +typedef void (asn_app_constraint_failed_f)(void *application_specific_key, + const struct asn_TYPE_descriptor_s *type_descriptor_which_failed, + const void *structure_which_failed_ptr, + const char *error_message_format, ...) CC_PRINTFLIKE(4, 5); + + +#ifdef __cplusplus +} +#endif + +#include "constr_TYPE.h" /* for asn_TYPE_descriptor_t */ + +#endif /* ASN_APPLICATION_H */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_bit_data.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_bit_data.c new file mode 100644 index 000000000..fe4b89ba7 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_bit_data.c @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2005-2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +/* + * Create a contiguous non-refillable bit data structure. + * Can be freed by FREEMEM(). + */ +asn_bit_data_t * +asn_bit_data_new_contiguous(const void *data, size_t size_bits) { + size_t size_bytes = (size_bits + 7) / 8; + asn_bit_data_t *pd; + uint8_t *bytes; + + /* Get the extensions map */ + pd = CALLOC(1, sizeof(*pd) + size_bytes + 1); + if(!pd) { + return NULL; + } + bytes = (void *)(((char *)pd) + sizeof(*pd)); + memcpy(bytes, data, size_bytes); + bytes[size_bytes] = 0; + pd->buffer = bytes; + pd->nboff = 0; + pd->nbits = size_bits; + + return pd; +} + + +char * +asn_bit_data_string(asn_bit_data_t *pd) { + static char buf[2][32]; + static int n; + n = (n+1) % 2; + snprintf(buf[n], sizeof(buf[n]), + "{m=%" ASN_PRI_SIZE " span %" ASN_PRI_SIZE "[%" ASN_PRI_SIZE + "..%" ASN_PRI_SIZE "] (%" ASN_PRI_SIZE ")}", + pd->moved, ((uintptr_t)(pd->buffer) & 0xf), pd->nboff, pd->nbits, + pd->nbits - pd->nboff); + return buf[n]; +} + +void +asn_get_undo(asn_bit_data_t *pd, int nbits) { + if((ssize_t)pd->nboff < nbits) { + assert((ssize_t)pd->nboff < nbits); + } else { + pd->nboff -= nbits; + pd->moved -= nbits; + } +} + +/* + * Extract a small number of bits (<= 31) from the specified PER data pointer. + */ +int32_t +asn_get_few_bits(asn_bit_data_t *pd, int nbits) { + size_t off; /* Next after last bit offset */ + ssize_t nleft; /* Number of bits left in this stream */ + uint32_t accum; + const uint8_t *buf; + + if(nbits < 0) + return -1; + + nleft = pd->nbits - pd->nboff; + if(nbits > nleft) { + int32_t tailv, vhead; + if(!pd->refill || nbits > 31) return -1; + /* Accumulate unused bytes before refill */ + ASN_DEBUG("Obtain the rest %d bits (want %d)", + (int)nleft, (int)nbits); + tailv = asn_get_few_bits(pd, nleft); + if(tailv < 0) return -1; + /* Refill (replace pd contents with new data) */ + if(pd->refill(pd)) + return -1; + nbits -= nleft; + vhead = asn_get_few_bits(pd, nbits); + /* Combine the rest of previous pd with the head of new one */ + tailv = (tailv << nbits) | vhead; /* Could == -1 */ + return tailv; + } + + /* + * Normalize position indicator. + */ + if(pd->nboff >= 8) { + pd->buffer += (pd->nboff >> 3); + pd->nbits -= (pd->nboff & ~0x07); + pd->nboff &= 0x07; + } + pd->moved += nbits; + pd->nboff += nbits; + off = pd->nboff; + buf = pd->buffer; + + /* + * Extract specified number of bits. + */ + if(off <= 8) + accum = nbits ? (buf[0]) >> (8 - off) : 0; + else if(off <= 16) + accum = ((buf[0] << 8) + buf[1]) >> (16 - off); + else if(off <= 24) + accum = ((buf[0] << 16) + (buf[1] << 8) + buf[2]) >> (24 - off); + else if(off <= 31) + accum = (((uint32_t)buf[0] << 24) + (buf[1] << 16) + + (buf[2] << 8) + (buf[3])) >> (32 - off); + else if(nbits <= 31) { + asn_bit_data_t tpd = *pd; + /* Here are we with our 31-bits limit plus 1..7 bits offset. */ + asn_get_undo(&tpd, nbits); + /* The number of available bits in the stream allow + * for the following operations to take place without + * invoking the ->refill() function */ + accum = asn_get_few_bits(&tpd, nbits - 24) << 24; + accum |= asn_get_few_bits(&tpd, 24); + } else { + asn_get_undo(pd, nbits); + return -1; + } + + accum &= (((uint32_t)1 << nbits) - 1); + + ASN_DEBUG(" [PER got %2d<=%2d bits => span %d %+ld[%d..%d]:%02x (%d) => 0x%x]", + (int)nbits, (int)nleft, + (int)pd->moved, + (((long)pd->buffer) & 0xf), + (int)pd->nboff, (int)pd->nbits, + ((pd->buffer != NULL)?pd->buffer[0]:0), + (int)(pd->nbits - pd->nboff), + (int)accum); + + return accum; +} + +/* + * Extract a large number of bits from the specified PER data pointer. + */ +int +asn_get_many_bits(asn_bit_data_t *pd, uint8_t *dst, int alright, int nbits) { + int32_t value; + + if(alright && (nbits & 7)) { + /* Perform right alignment of a first few bits */ + value = asn_get_few_bits(pd, nbits & 0x07); + if(value < 0) return -1; + *dst++ = value; /* value is already right-aligned */ + nbits &= ~7; + } + + while(nbits) { + if(nbits >= 24) { + value = asn_get_few_bits(pd, 24); + if(value < 0) return -1; + *(dst++) = value >> 16; + *(dst++) = value >> 8; + *(dst++) = value; + nbits -= 24; + } else { + value = asn_get_few_bits(pd, nbits); + if(value < 0) return -1; + if(nbits & 7) { /* implies left alignment */ + value <<= 8 - (nbits & 7), + nbits += 8 - (nbits & 7); + if(nbits > 24) + *dst++ = value >> 24; + } + if(nbits > 16) + *dst++ = value >> 16; + if(nbits > 8) + *dst++ = value >> 8; + *dst++ = value; + break; + } + } + + return 0; +} + +/* + * Put a small number of bits (<= 31). + */ +int +asn_put_few_bits(asn_bit_outp_t *po, uint32_t bits, int obits) { + size_t off; /* Next after last bit offset */ + size_t omsk; /* Existing last byte meaningful bits mask */ + uint8_t *buf; + + if(obits <= 0 || obits >= 32) return obits ? -1 : 0; + + ASN_DEBUG("[PER put %d bits %x to %p+%d bits]", + obits, (int)bits, (void *)po->buffer, (int)po->nboff); + + /* + * Normalize position indicator. + */ + if(po->nboff >= 8) { + po->buffer += (po->nboff >> 3); + po->nbits -= (po->nboff & ~0x07); + po->nboff &= 0x07; + } + + /* + * Flush whole-bytes output, if necessary. + */ + if(po->nboff + obits > po->nbits) { + size_t complete_bytes; + if(!po->buffer) po->buffer = po->tmpspace; + complete_bytes = (po->buffer - po->tmpspace); + ASN_DEBUG("[PER output %ld complete + %ld]", + (long)complete_bytes, (long)po->flushed_bytes); + if(po->output(po->tmpspace, complete_bytes, po->op_key) < 0) + return -1; + if(po->nboff) + po->tmpspace[0] = po->buffer[0]; + po->buffer = po->tmpspace; + po->nbits = 8 * sizeof(po->tmpspace); + po->flushed_bytes += complete_bytes; + } + + /* + * Now, due to sizeof(tmpspace), we are guaranteed large enough space. + */ + buf = po->buffer; + omsk = ~((1 << (8 - po->nboff)) - 1); + off = (po->nboff + obits); + + /* Clear data of debris before meaningful bits */ + bits &= (((uint32_t)1 << obits) - 1); + + ASN_DEBUG("[PER out %d %u/%x (t=%d,o=%d) %x&%x=%x]", obits, + (int)bits, (int)bits, + (int)po->nboff, (int)off, + buf[0], (int)(omsk&0xff), + (int)(buf[0] & omsk)); + + if(off <= 8) /* Completely within 1 byte */ + po->nboff = off, + bits <<= (8 - off), + buf[0] = (buf[0] & omsk) | bits; + else if(off <= 16) + po->nboff = off, + bits <<= (16 - off), + buf[0] = (buf[0] & omsk) | (bits >> 8), + buf[1] = bits; + else if(off <= 24) + po->nboff = off, + bits <<= (24 - off), + buf[0] = (buf[0] & omsk) | (bits >> 16), + buf[1] = bits >> 8, + buf[2] = bits; + else if(off <= 31) + po->nboff = off, + bits <<= (32 - off), + buf[0] = (buf[0] & omsk) | (bits >> 24), + buf[1] = bits >> 16, + buf[2] = bits >> 8, + buf[3] = bits; + else { + if(asn_put_few_bits(po, bits >> (obits - 24), 24)) return -1; + if(asn_put_few_bits(po, bits, obits - 24)) return -1; + } + + ASN_DEBUG("[PER out %u/%x => %02x buf+%ld]", + (int)bits, (int)bits, buf[0], + (long)(po->buffer - po->tmpspace)); + + return 0; +} + + +/* + * Output a large number of bits. + */ +int +asn_put_many_bits(asn_bit_outp_t *po, const uint8_t *src, int nbits) { + + while(nbits) { + uint32_t value; + + if(nbits >= 24) { + value = (src[0] << 16) | (src[1] << 8) | src[2]; + src += 3; + nbits -= 24; + if(asn_put_few_bits(po, value, 24)) + return -1; + } else { + value = src[0]; + if(nbits > 8) + value = (value << 8) | src[1]; + if(nbits > 16) + value = (value << 8) | src[2]; + if(nbits & 0x07) + value >>= (8 - (nbits & 0x07)); + if(asn_put_few_bits(po, value, nbits)) + return -1; + break; + } + } + + return 0; +} + + +int +asn_put_aligned_flush(asn_bit_outp_t *po) { + uint32_t unused_bits = (0x7 & (8 - (po->nboff & 0x07))); + size_t complete_bytes = + (po->buffer ? po->buffer - po->tmpspace : 0) + ((po->nboff + 7) >> 3); + + if(unused_bits) { + po->buffer[po->nboff >> 3] &= ~0u << unused_bits; + } + + if(po->output(po->tmpspace, complete_bytes, po->op_key) < 0) { + return -1; + } else { + po->buffer = po->tmpspace; + po->nboff = 0; + po->nbits = 8 * sizeof(po->tmpspace); + po->flushed_bytes += complete_bytes; + return 0; + } +} + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_bit_data.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_bit_data.h new file mode 100644 index 000000000..f14714bbd --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_bit_data.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2005-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_BIT_DATA +#define ASN_BIT_DATA + +#include /* Platform-specific types */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This structure describes a position inside an incoming PER bit stream. + */ +typedef struct asn_bit_data_s { + const uint8_t *buffer; /* Pointer to the octet stream */ + size_t nboff; /* Bit offset to the meaningful bit */ + size_t nbits; /* Number of bits in the stream */ + size_t moved; /* Number of bits moved through this bit stream */ + int (*refill)(struct asn_bit_data_s *); + void *refill_key; +} asn_bit_data_t; + +/* + * Create a contiguous non-refillable bit data structure. + * Can be freed by FREEMEM(). + */ +asn_bit_data_t *asn_bit_data_new_contiguous(const void *data, size_t size_bits); + +/* + * Extract a small number of bits (<= 31) from the specified PER data pointer. + * This function returns -1 if the specified number of bits could not be + * extracted due to EOD or other conditions. + */ +int32_t asn_get_few_bits(asn_bit_data_t *, int get_nbits); + +/* Undo the immediately preceding "get_few_bits" operation */ +void asn_get_undo(asn_bit_data_t *, int get_nbits); + +/* + * Extract a large number of bits from the specified PER data pointer. + * This function returns -1 if the specified number of bits could not be + * extracted due to EOD or other conditions. + */ +int asn_get_many_bits(asn_bit_data_t *, uint8_t *dst, int right_align, + int get_nbits); + +/* Non-thread-safe debugging function, don't use it */ +char *asn_bit_data_string(asn_bit_data_t *); + +/* + * This structure supports forming bit output. + */ +typedef struct asn_bit_outp_s { + uint8_t *buffer; /* Pointer into the (tmpspace) */ + size_t nboff; /* Bit offset to the meaningful bit */ + size_t nbits; /* Number of bits left in (tmpspace) */ + uint8_t tmpspace[32]; /* Preliminary storage to hold data */ + int (*output)(const void *data, size_t size, void *op_key); + void *op_key; /* Key for (output) data callback */ + size_t flushed_bytes; /* Bytes already flushed through (output) */ +} asn_bit_outp_t; + +/* Output a small number of bits (<= 31) */ +int asn_put_few_bits(asn_bit_outp_t *, uint32_t bits, int obits); + +/* Output a large number of bits */ +int asn_put_many_bits(asn_bit_outp_t *, const uint8_t *src, int put_nbits); + +/* + * Flush whole bytes (0 or more) through (outper) member. + * The least significant bits which are not used are guaranteed to be set to 0. + * Returns -1 if callback returns -1. Otherwise, 0. + */ +int asn_put_aligned_flush(asn_bit_outp_t *); + +#ifdef __cplusplus +} +#endif + +#endif /* ASN_BIT_DATA */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_codecs.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_codecs.h new file mode 100644 index 000000000..e75c2709c --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_codecs.h @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_CODECS_H +#define ASN_CODECS_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* + * This structure defines a set of parameters that may be passed + * to every ASN.1 encoder or decoder function. + * WARNING: if max_stack_size member is set, and you are calling the + * function pointers of the asn_TYPE_descriptor_t directly, + * this structure must be ALLOCATED ON THE STACK! + * If you can't always satisfy this requirement, use ber_decode(), + * xer_decode() and uper_decode() functions instead. + */ +typedef struct asn_codec_ctx_s { + /* + * Limit the decoder routines to use no (much) more stack than a given + * number of bytes. Most of decoders are stack-based, and this + * would protect against stack overflows if the number of nested + * encodings is high. + * The OCTET STRING, BIT STRING and ANY BER decoders are heap-based, + * and are safe from this kind of overflow. + * A value from getrlimit(RLIMIT_STACK) may be used to initialize + * this variable. Be careful in multithreaded environments, as the + * stack size is rather limited. + */ + size_t max_stack_size; /* 0 disables stack bounds checking */ +} asn_codec_ctx_t; + +/* + * Type of the return value of the encoding functions (der_encode, xer_encode). + */ +typedef struct asn_enc_rval_s { + /* + * Number of bytes encoded. + * -1 indicates failure to encode the structure. + * In this case, the members below this one are meaningful. + */ + ssize_t encoded; + + /* + * Members meaningful when (encoded == -1), for post mortem analysis. + */ + + /* Type which cannot be encoded */ + const struct asn_TYPE_descriptor_s *failed_type; + + /* Pointer to the structure of that type */ + const void *structure_ptr; +} asn_enc_rval_t; +#define ASN__ENCODE_FAILED do { \ + asn_enc_rval_t tmp_error; \ + tmp_error.encoded = -1; \ + tmp_error.failed_type = td; \ + tmp_error.structure_ptr = sptr; \ + ASN_DEBUG("Failed to encode element %s", td ? td->name : ""); \ + return tmp_error; \ +} while(0) +#define ASN__ENCODED_OK(rval) do { \ + rval.structure_ptr = 0; \ + rval.failed_type = 0; \ + return rval; \ +} while(0) + +/* + * Type of the return value of the decoding functions (ber_decode, xer_decode) + * + * Please note that the number of consumed bytes is ALWAYS meaningful, + * even if code==RC_FAIL. This is to indicate the number of successfully + * decoded bytes, hence providing a possibility to fail with more diagnostics + * (i.e., print the offending remainder of the buffer). + */ +enum asn_dec_rval_code_e { + RC_OK, /* Decoded successfully */ + RC_WMORE, /* More data expected, call again */ + RC_FAIL /* Failure to decode data */ +}; +typedef struct asn_dec_rval_s { + enum asn_dec_rval_code_e code; /* Result code */ + size_t consumed; /* Number of bytes consumed */ +} asn_dec_rval_t; +#define ASN__DECODE_FAILED do { \ + asn_dec_rval_t tmp_error; \ + tmp_error.code = RC_FAIL; \ + tmp_error.consumed = 0; \ + ASN_DEBUG("Failed to decode element %s", td ? td->name : ""); \ + return tmp_error; \ +} while(0) +#define ASN__DECODE_STARVED do { \ + asn_dec_rval_t tmp_error; \ + tmp_error.code = RC_WMORE; \ + tmp_error.consumed = 0; \ + return tmp_error; \ +} while(0) + +#ifdef __cplusplus +} +#endif + +#endif /* ASN_CODECS_H */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_codecs_prim.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_codecs_prim.c new file mode 100644 index 000000000..f3fdbfd2b --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_codecs_prim.c @@ -0,0 +1,31 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +void +ASN__PRIMITIVE_TYPE_free(const asn_TYPE_descriptor_t *td, void *sptr, + enum asn_struct_free_method method) { + ASN__PRIMITIVE_TYPE_t *st = (ASN__PRIMITIVE_TYPE_t *)sptr; + + if(!td || !sptr) + return; + + ASN_DEBUG("Freeing %s as a primitive type", td->name); + + if(st->buf) + FREEMEM(st->buf); + + switch(method) { + case ASFM_FREE_EVERYTHING: + FREEMEM(sptr); + break; + case ASFM_FREE_UNDERLYING: + break; + case ASFM_FREE_UNDERLYING_AND_RESET: + memset(sptr, 0, sizeof(ASN__PRIMITIVE_TYPE_t)); + break; + } +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_codecs_prim.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_codecs_prim.h new file mode 100644 index 000000000..8647ab9f7 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_codecs_prim.h @@ -0,0 +1,82 @@ +/*- + * Copyright (c) 2004-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_CODECS_PRIM_H +#define ASN_CODECS_PRIM_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ASN__PRIMITIVE_TYPE_s { + uint8_t *buf; /* Buffer with consecutive primitive encoding bytes */ + size_t size; /* Size of the buffer */ +} ASN__PRIMITIVE_TYPE_t; /* Do not use this type directly! */ + +asn_struct_free_f ASN__PRIMITIVE_TYPE_free; + +#if !defined(ASN_DISABLE_BER_SUPPORT) +ber_type_decoder_f ber_decode_primitive; +der_type_encoder_f der_encode_primitive; +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +/* + * A callback specification for the xer_decode_primitive() function below. + */ +enum xer_pbd_rval { + XPBD_SYSTEM_FAILURE, /* System failure (memory shortage, etc) */ + XPBD_DECODER_LIMIT, /* Hit some decoder limitation or deficiency */ + XPBD_BROKEN_ENCODING, /* Encoding of a primitive body is broken */ + XPBD_NOT_BODY_IGNORE, /* Not a body format, but safe to ignore */ + XPBD_BODY_CONSUMED /* Body is recognized and consumed */ +}; +typedef enum xer_pbd_rval(xer_primitive_body_decoder_f)( + const asn_TYPE_descriptor_t *td, void *struct_ptr, const void *chunk_buf, + size_t chunk_size); + +/* + * Specific function to decode simple primitive types. + * Also see xer_decode_general() in xer_decoder.h + */ +asn_dec_rval_t xer_decode_primitive( + const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *type_descriptor, void **struct_ptr, + size_t struct_size, const char *opt_mname, const void *buf_ptr, size_t size, + xer_primitive_body_decoder_f *prim_body_decoder); +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +/* + * A callback specification for the jer_decode_primitive() function below. + */ +enum jer_pbd_rval { + JPBD_SYSTEM_FAILURE, /* System failure (memory shortage, etc) */ + JPBD_DECODER_LIMIT, /* Hit some decoder limitation or deficiency */ + JPBD_BROKEN_ENCODING, /* Encoding of a primitive body is broken */ + JPBD_NOT_BODY_IGNORE, /* Not a body format, but safe to ignore */ + JPBD_BODY_CONSUMED /* Body is recognized and consumed */ +}; +typedef enum jer_pbd_rval(jer_primitive_body_decoder_f)( + const asn_TYPE_descriptor_t *td, void *struct_ptr, const void *chunk_buf, + size_t chunk_size); + +/* + * Specific function to decode simple primitive types. + * Also see jer_decode_general() in jer_decoder.h + */ +asn_dec_rval_t jer_decode_primitive( + const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *type_descriptor, void **struct_ptr, + size_t struct_size, const void *buf_ptr, size_t size, + jer_primitive_body_decoder_f *prim_body_decoder); +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#ifdef __cplusplus +} +#endif + +#endif /* ASN_CODECS_PRIM_H */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_codecs_prim_xer.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_codecs_prim_xer.c new file mode 100644 index 000000000..70c91bc26 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_codecs_prim_xer.c @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* + * Local internal type passed around as an argument. + */ +struct xdp_arg_s { + const asn_TYPE_descriptor_t *type_descriptor; + void *struct_key; + xer_primitive_body_decoder_f *prim_body_decoder; + int decoded_something; + int want_more; +}; + +/* + * Since some kinds of primitive values can be encoded using value-specific + * tags (, , etc), the primitive decoder must + * be supplied with such tags to parse them as needed. + */ +static int +xer_decode__unexpected_tag(void *key, const void *chunk_buf, size_t chunk_size) { + struct xdp_arg_s *arg = (struct xdp_arg_s *)key; + enum xer_pbd_rval bret; + + /* + * The chunk_buf is guaranteed to start at '<'. + */ + assert(chunk_size && ((const char *)chunk_buf)[0] == 0x3c); + + /* + * Decoding was performed once already. Prohibit doing it again. + */ + if(arg->decoded_something) + return -1; + + bret = arg->prim_body_decoder(arg->type_descriptor, + arg->struct_key, chunk_buf, + chunk_size); + switch(bret) { + case XPBD_SYSTEM_FAILURE: + case XPBD_DECODER_LIMIT: + case XPBD_BROKEN_ENCODING: + break; + case XPBD_BODY_CONSUMED: + /* Tag decoded successfully */ + arg->decoded_something = 1; + /* Fall through */ + case XPBD_NOT_BODY_IGNORE: /* Safe to proceed further */ + return 0; + } + + return -1; +} + +static ssize_t +xer_decode__primitive_body(void *key, const void *chunk_buf, size_t chunk_size, int have_more) { + struct xdp_arg_s *arg = (struct xdp_arg_s *)key; + enum xer_pbd_rval bret; + size_t lead_wsp_size; + + if(arg->decoded_something) { + if(xer_whitespace_span(chunk_buf, chunk_size) == chunk_size) { + /* + * Example: + * "123 " + * ^- chunk_buf position. + */ + return chunk_size; + } + /* + * Decoding was done once already. Prohibit doing it again. + */ + return -1; + } + + if(!have_more) { + /* + * If we've received something like "1", we can't really + * tell whether it is really `1` or `123`, until we know + * that there is no more data coming. + * The have_more argument will be set to 1 once something + * like this is available to the caller of this callback: + * "1want_more = 1; + return -1; + } + + lead_wsp_size = xer_whitespace_span(chunk_buf, chunk_size); + chunk_buf = (chunk_buf == NULL)? NULL : ((const char *)chunk_buf + lead_wsp_size); + chunk_size -= lead_wsp_size; + + bret = arg->prim_body_decoder(arg->type_descriptor, + arg->struct_key, chunk_buf, + chunk_size); + switch(bret) { + case XPBD_SYSTEM_FAILURE: + case XPBD_DECODER_LIMIT: + case XPBD_BROKEN_ENCODING: + break; + case XPBD_BODY_CONSUMED: + /* Tag decoded successfully */ + arg->decoded_something = 1; + /* Fall through */ + case XPBD_NOT_BODY_IGNORE: /* Safe to proceed further */ + return lead_wsp_size + chunk_size; + } + + return -1; +} + +asn_dec_rval_t +xer_decode_primitive(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **sptr, + size_t struct_size, const char *opt_mname, + const void *buf_ptr, size_t size, + xer_primitive_body_decoder_f *prim_body_decoder) { + const char *xml_tag = opt_mname ? opt_mname : td->xml_tag; + asn_struct_ctx_t s_ctx; + struct xdp_arg_s s_arg; + asn_dec_rval_t rc; + + /* + * Create the structure if does not exist. + */ + if(!*sptr) { + *sptr = CALLOC(1, struct_size); + if(!*sptr) ASN__DECODE_FAILED; + } + + memset(&s_ctx, 0, sizeof(s_ctx)); + s_arg.type_descriptor = td; + s_arg.struct_key = *sptr; + s_arg.prim_body_decoder = prim_body_decoder; + s_arg.decoded_something = 0; + s_arg.want_more = 0; + + rc = xer_decode_general(opt_codec_ctx, &s_ctx, &s_arg, + xml_tag, buf_ptr, size, + xer_decode__unexpected_tag, + xer_decode__primitive_body); + switch(rc.code) { + case RC_OK: + if(!s_arg.decoded_something) { + char ch; + ASN_DEBUG("Primitive body is not recognized, " + "supplying empty one"); + /* + * Decoding opportunity has come and gone. + * Where's the result? + * Try to feed with empty body, see if it eats it. + */ + if(prim_body_decoder(s_arg.type_descriptor, + s_arg.struct_key, &ch, 0) + != XPBD_BODY_CONSUMED) { + /* + * This decoder does not like empty stuff. + */ + ASN__DECODE_FAILED; + } + } + break; + case RC_WMORE: + /* + * Redo the whole thing later. + * We don't have a context to save intermediate parsing state. + */ + rc.consumed = 0; + break; + case RC_FAIL: + rc.consumed = 0; + if(s_arg.want_more) + rc.code = RC_WMORE; + else + ASN__DECODE_FAILED; + break; + } + return rc; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_config.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_config.h new file mode 100644 index 000000000..d404f0699 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_config.h @@ -0,0 +1,6 @@ +// Generated automatically. Don't edit manually! + +#define ASN_DISABLE_BER_SUPPORT 1 +#define ASN_DISABLE_OER_SUPPORT 1 +#define ASN_DISABLE_UPER_SUPPORT 1 +#define ASN_DISABLE_JER_SUPPORT 1 diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_constant.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_constant.h new file mode 100644 index 000000000..cb35bb938 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_constant.h @@ -0,0 +1,22 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + */ + +#ifndef _ASN_CONSTANT_H +#define _ASN_CONSTANT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define maxPRBs (273) +#define maxPRBIndex (272) +#define maxSlotsFrame (160) +#define maxSymbolMask (16383) + + +#ifdef __cplusplus +} +#endif + +#endif /* _ASN_CONSTANT_H */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_internal.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_internal.c new file mode 100644 index 000000000..1b282661d --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_internal.c @@ -0,0 +1,50 @@ +#include + +ssize_t +asn__format_to_callback(int (*cb)(const void *, size_t, void *key), void *key, + const char *fmt, ...) { + char scratch[64]; + char *buf = scratch; + size_t buf_size = sizeof(scratch); + int wrote; + int cb_ret; + + do { + va_list args; + va_start(args, fmt); + + wrote = vsnprintf(buf, buf_size, fmt, args); + va_end(args); + if(wrote < (ssize_t)buf_size) { + if(wrote < 0) { + if(buf != scratch) FREEMEM(buf); + return -1; + } + break; + } + + buf_size <<= 1; + if(buf == scratch) { + buf = MALLOC(buf_size); + if(!buf) { + return -1; + } + } else { + void *p = REALLOC(buf, buf_size); + if(!p) { + FREEMEM(buf); + return -1; + } + buf = p; + } + } while(1); + + cb_ret = cb(buf, wrote, key); + if(buf != scratch) FREEMEM(buf); + if(cb_ret < 0) { + return -1; + } + + return wrote; +} + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_internal.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_internal.h new file mode 100644 index 000000000..d6ce61980 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_internal.h @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +/* + * Declarations internally useful for the ASN.1 support code. + */ +#ifndef ASN_INTERNAL_H +#define ASN_INTERNAL_H +#ifndef __EXTENSIONS__ +#define __EXTENSIONS__ /* for Sun */ +#endif + +#include "asn_application.h" /* Application-visible API */ + +#ifndef __NO_ASSERT_H__ /* Include assert.h only for internal use. */ +#include /* for assert() macro */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +#include +#include +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +#include +#include +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +/* Environment version might be used to avoid running with the old library */ +#define ASN1C_ENVIRONMENT_VERSION 923 /* Compile-time version */ +int get_asn1c_environment_version(void); /* Run-time version */ + +#define CALLOC(nmemb, size) calloc(nmemb, size) +#define MALLOC(size) malloc(size) +#define REALLOC(oldptr, size) realloc(oldptr, size) +#define FREEMEM(ptr) free(ptr) + +#define asn_debug_indent 0 +#define ASN_DEBUG_INDENT_ADD(i) do{}while(0) + +#ifdef EMIT_ASN_DEBUG +#warning "Use ASN_EMIT_DEBUG instead of EMIT_ASN_DEBUG" +#define ASN_EMIT_DEBUG EMIT_ASN_DEBUG +#endif + +/* + * A macro for debugging the ASN.1 internals. + * You may enable or override it. + */ +#ifndef ASN_DEBUG /* If debugging code is not defined elsewhere... */ +#if ASN_EMIT_DEBUG == 1 /* And it was asked to emit this code... */ +#if __STDC_VERSION__ >= 199901L +#ifdef ASN_THREAD_SAFE +/* Thread safety requires sacrifice in output indentation: + * Retain empty definition of ASN_DEBUG_INDENT_ADD. */ +#else /* !ASN_THREAD_SAFE */ +#undef ASN_DEBUG_INDENT_ADD +#undef asn_debug_indent +int asn_debug_indent; +#define ASN_DEBUG_INDENT_ADD(i) do { asn_debug_indent += i; } while(0) +#endif /* ASN_THREAD_SAFE */ +#define ASN_DEBUG(fmt, args...) do { \ + int adi = asn_debug_indent; \ + while(adi--) fprintf(stderr, " "); \ + fprintf(stderr, fmt, ##args); \ + fprintf(stderr, " (%s:%d)\n", \ + __FILE__, __LINE__); \ + } while(0) +#else /* !C99 */ +void CC_PRINTFLIKE(1, 2) ASN_DEBUG_f(const char *fmt, ...); +#define ASN_DEBUG ASN_DEBUG_f +#endif /* C99 */ +#else /* ASN_EMIT_DEBUG != 1 */ +#if __STDC_VERSION__ >= 199901L +#define ASN_DEBUG(...) do{}while(0) +#else /* not C99 */ +static void CC_PRINTFLIKE(1, 2) ASN_DEBUG(const char *fmt, ...) { (void)fmt; } +#endif /* C99 or better */ +#endif /* ASN_EMIT_DEBUG */ +#endif /* ASN_DEBUG */ + +/* + * Print to a callback. + * The callback is expected to return negative values on error. + * 0 and positive values are treated as success. + * RETURN VALUES: + * -1: Failed to format or invoke the callback. + * >0: Size of the data that got delivered to the callback. + */ +ssize_t CC_PRINTFLIKE(3, 4) +asn__format_to_callback( + int (*callback)(const void *, size_t, void *key), void *key, + const char *fmt, ...); + +/* + * Invoke the application-supplied callback and fail, if something is wrong. + */ +#define ASN__E_cbc(buf, size) (cb((buf), (size), app_key) < 0) +#define ASN__E_CALLBACK(size, foo) \ + do { \ + if(foo) goto cb_failed; \ + er.encoded += (size); \ + } while(0) +#define ASN__CALLBACK(buf, size) ASN__E_CALLBACK(size, ASN__E_cbc(buf, size)) +#define ASN__CALLBACK2(buf1, size1, buf2, size2) \ + ASN__E_CALLBACK((size1) + (size2), \ + ASN__E_cbc(buf1, size1) || ASN__E_cbc(buf2, size2)) +#define ASN__CALLBACK3(buf1, size1, buf2, size2, buf3, size3) \ + ASN__E_CALLBACK((size1) + (size2) + (size3), \ + ASN__E_cbc(buf1, size1) || ASN__E_cbc(buf2, size2) \ + || ASN__E_cbc(buf3, size3)) + +#define ASN__TEXT_INDENT(nl, level) \ + do { \ + int tmp_level = (level); \ + int tmp_nl = ((nl) != 0); \ + int tmp_i; \ + if(tmp_nl) ASN__CALLBACK("\n", 1); \ + if(tmp_level < 0) tmp_level = 0; \ + for(tmp_i = 0; tmp_i < tmp_level; tmp_i++) ASN__CALLBACK(" ", 4); \ + } while(0) + +#define _i_INDENT(nl) do { \ + int tmp_i; \ + if((nl) && cb("\n", 1, app_key) < 0) \ + return -1; \ + for(tmp_i = 0; tmp_i < ilevel; tmp_i++) \ + if(cb(" ", 4, app_key) < 0) \ + return -1; \ + } while(0) + +/* + * Check stack against overflow, if limit is set. + */ + +/* Since GCC 13, AddressSanitizer started defaulting to +* ASAN_OPTIONS="detect_stack_use_after_return=1", which makes this check +* fail due to apparently jumping stack pointers. +* Hence, disable this check if building with ASan, as documented in: +* GCC: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html +* Clang: https://clang.llvm.org/docs/AddressSanitizer.html#conditional-compilation-with-has-feature-address-sanitizer +*/ +#if defined(__SANITIZE_ADDRESS__) + #define ASN__SANITIZE_ENABLED 1 +#elif defined(__has_feature) +#if __has_feature(address_sanitizer) + #define ASN__SANITIZE_ENABLED 1 +#endif +#endif + +#define ASN__DEFAULT_STACK_MAX (30000) + +#if defined(ASN__SANITIZE_ENABLED) || defined(ASN_DISABLE_STACK_OVERFLOW_CHECK) +static int CC_NOTUSED +ASN__STACK_OVERFLOW_CHECK(const asn_codec_ctx_t *ctx) { + (void)ctx; + return 0; +} +#else +static int CC_NOTUSED +ASN__STACK_OVERFLOW_CHECK(const asn_codec_ctx_t *ctx) { + if(ctx && ctx->max_stack_size) { + + /* ctx MUST be allocated on the stack */ + ptrdiff_t usedstack = ((const char *)ctx - (const char *)&ctx); + if(usedstack > 0) usedstack = -usedstack; /* grows up! */ + + /* double negative required to avoid int wrap-around */ + if(usedstack < -(ptrdiff_t)ctx->max_stack_size) { + ASN_DEBUG("Stack limit %ld reached", + (long)ctx->max_stack_size); + return -1; + } + } + return 0; +} +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* ASN_INTERNAL_H */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_ioc.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_ioc.h new file mode 100644 index 000000000..7de210ee0 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_ioc.h @@ -0,0 +1,51 @@ +/* + * Run-time support for Information Object Classes. + * Copyright (c) 2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_IOC_H +#define ASN_IOC_H + +#include /* Platform-specific types */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; +struct asn_ioc_cell_s; + +/* + * X.681, #13 + */ +typedef struct asn_ioc_set_s { + size_t rows_count; + size_t columns_count; + const struct asn_ioc_cell_s *rows; +} asn_ioc_set_t; + + +typedef struct asn_ioc_cell_s { + const char *field_name; /* Is equal to corresponding column_name */ + enum { + aioc__undefined = 0, + aioc__value, + aioc__type, + aioc__open_type, + } cell_kind; + struct asn_TYPE_descriptor_s *type_descriptor; + const void *value_sptr; + struct { + size_t types_count; + struct { + unsigned choice_position; + } *types; + } open_type; +} asn_ioc_cell_t; + + +#ifdef __cplusplus +} +#endif + +#endif /* ASN_IOC_H */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_random_fill.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_random_fill.c new file mode 100644 index 000000000..4d14cbfdc --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_random_fill.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include +#include + +int +asn_random_fill(const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + size_t length) { + + if(td && td->op->random_fill) { + asn_random_fill_result_t res = + td->op->random_fill(td, struct_ptr, 0, length); + return (res.code == ARFILL_OK) ? 0 : -1; + } else { + return -1; + } +} + +static uintmax_t +asn__intmax_range(intmax_t lb, intmax_t ub) { + assert(lb <= ub); + if((ub < 0) == (lb < 0)) { + return ub - lb; + } else if(lb < 0) { + return 1 + ((uintmax_t)ub + (uintmax_t)-(lb + 1)); + } else { + assert(!"Unreachable"); + return 0; + } +} + +intmax_t +asn_random_between(intmax_t lb, intmax_t rb) { + if(lb == rb) { + return lb; + } else { + const uintmax_t intmax_max = ((~(uintmax_t)0) >> 1); + uintmax_t range = asn__intmax_range(lb, rb); + uintmax_t value = 0; + uintmax_t got_entropy = 0; + (void)intmax_max; + int max = 0xffffff; + +#ifdef __WIN32__ + max = RAND_MAX-1; +#endif + + assert(RAND_MAX > max); /* Seen 7ffffffd! */ + assert(range < intmax_max); + + for(; got_entropy < range;) { + got_entropy = (got_entropy << 24) | max; +#ifdef HAVE_RANDOM + value = (value << 24) | (random() % max); +#else + value = (value << 24) | (rand() % max); +#endif + } + + return lb + (intmax_t)(value % (range + 1)); + } +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_random_fill.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_random_fill.h new file mode 100644 index 000000000..47f9b8af0 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_random_fill.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_RANDOM_FILL +#define ASN_RANDOM_FILL + +/* Forward declarations */ +struct asn_TYPE_descriptor_s; +struct asn_encoding_constraints_s; + +/* + * Initialize a structure with random data according to the type specification + * and optional member constraints. + * ARGUMENTS: + * (max_length) - See (approx_max_length_limit). + * (memb_constraints) - Member constraints, if exist. + * The type can be constrained differently according + * to PER and OER specifications, so we find a value + * at the intersection of these constraints. + * In case the return differs from ARFILL_OK, the (struct_ptr) contents + * and (current_length) value remain in their original state. + */ +typedef struct asn_random_fill_result_s { + enum { + ARFILL_FAILED = -1, /* System error (memory?) */ + ARFILL_OK = 0, /* Initialization succeeded */ + ARFILL_SKIPPED = 1 /* Not done due to (length?) constraint */ + } code; + size_t length; /* Approximate number of bytes created. */ +} asn_random_fill_result_t; +typedef asn_random_fill_result_t(asn_random_fill_f)( + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const struct asn_encoding_constraints_s *memb_constraints, + size_t max_length); + +/* + * Returns 0 if the structure was properly initialized, -1 otherwise. + * The (approx_max_length_limit) specifies the approximate limit of the + * resulting structure in units closely resembling bytes. The actual result + * might be several times larger or smaller than the length limit. + */ +int asn_random_fill(const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + size_t approx_max_length_limit); + +/* + * Returns a random number between min and max. + */ +intmax_t asn_random_between(intmax_t min, intmax_t max); + +#endif /* ASN_RANDOM_FILL */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_system.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_system.h new file mode 100644 index 000000000..194f96a5f --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/asn_system.h @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +/* + * Miscellaneous system-dependent types. + */ +#ifndef ASN_SYSTEM_H +#define ASN_SYSTEM_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE 1 +#endif + +#ifndef _BSD_SOURCE +#define _BSD_SOURCE /* for snprintf() on some linux systems */ +#endif + +#include /* For snprintf(3) */ +#include /* For *alloc(3) */ +#include /* For memcpy(3) */ +#include /* For size_t */ +#include /* For LONG_MAX */ +#include /* For va_start */ +#include /* for offsetof and ptrdiff_t */ +#include /* for PRIdMAX */ + +#ifdef _WIN32 + +#include +#ifndef __MINGW32__ +#define snprintf _snprintf +#define vsnprintf _vsnprintf +#endif + +/* To avoid linking with ws2_32.lib, here's the definition of ntohl() */ +#define sys_ntohl(l) ((((l) << 24) & 0xff000000) \ + | (((l) << 8) & 0xff0000) \ + | (((l) >> 8) & 0xff00) \ + | ((l >> 24) & 0xff)) + +#ifdef _MSC_VER /* MSVS.Net */ +#ifndef __cplusplus +#define inline __inline +#endif +#ifndef ASSUMESTDTYPES /* Standard types have been defined elsewhere */ +#define ssize_t SSIZE_T +#if _MSC_VER < 1600 +typedef char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +#else /* _MSC_VER >= 1600 */ +#include +#endif /* _MSC_VER < 1600 */ +#endif /* ASSUMESTDTYPES */ +#define WIN32_LEAN_AND_MEAN +#include +#include +#define isnan _isnan +#define finite _finite +#define copysign _copysign +#define ilogb _logb +#else /* !_MSC_VER */ +#include +#endif /* _MSC_VER */ + +#else /* !_WIN32 */ + +#if defined(__vxworks) +#include +#else /* !defined(__vxworks) */ + +#include /* C99 specifies this file */ +#ifdef HAVE_ARPA_INET_H +#include /* for ntohl() */ +#define sys_ntohl(foo) ntohl(foo) +#else /* !_HAVE_ARPA_INET_H */ +#ifdef HAVE_NETINET_IN_H +#include /* for ntohl() */ +#define sys_ntohl(foo) ntohl(foo) +#else /* !_HAVE_NETINET_IN_H */ +/* Here's the definition of ntohl() */ +#define sys_ntohl(l) ((((l) << 24) & 0xff000000) \ + | (((l) << 8) & 0xff0000) \ + | (((l) >> 8) & 0xff00) \ + | ((l >> 24) & 0xff)) +#endif /* HAVE_NETINET_IN_H */ +#endif /* HAVE_ARPA_INET_H */ +#endif /* defined(__vxworks) */ + + +#endif /* _WIN32 */ + +#if __GNUC__ >= 3 || defined(__clang__) +#define CC_ATTRIBUTE(attr) __attribute__((attr)) +#else +#define CC_ATTRIBUTE(attr) +#endif +#if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__>= 4) || __GNUC__ > 4) +#define CC_PRINTFLIKE(fmt, var) CC_ATTRIBUTE(format(gnu_printf, fmt, var)) +#elif defined(__GNUC__) +#if defined(ANDROID) +#define CC_PRINTFLIKE(fmt, var) CC_ATTRIBUTE(__format__(__printf__, fmt, var)) +#else +#define CC_PRINTFLIKE(fmt, var) CC_ATTRIBUTE(format(printf, fmt, var)) +#endif +#else +#define CC_PRINTFLIKE(fmt, var) +#endif +#define CC_NOTUSED CC_ATTRIBUTE(unused) +#ifndef CC_ATTR_NO_SANITIZE +#if __GNUC__ < 8 +#define CC_ATTR_NO_SANITIZE(what) +#else +#define CC_ATTR_NO_SANITIZE(what) CC_ATTRIBUTE(no_sanitize(what)) +#endif +#endif + +/* Figure out if thread safety is requested */ +#if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT)) +#define ASN_THREAD_SAFE +#endif /* Thread safety */ + +#ifndef offsetof /* If not defined by */ +#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0)) +#endif /* offsetof */ + +#ifndef MIN /* Suitable for comparing primitive types (integers) */ +#if defined(__GNUC__) +#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \ + ((_a)<(_b)?(_a):(_b)); }) +#else /* !__GNUC__ */ +#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */ +#endif /* __GNUC__ */ +#endif /* MIN */ + +#if __STDC_VERSION__ >= 199901L +#ifndef SIZE_MAX +#define SIZE_MAX ((~((size_t)0)) >> 1) +#endif + +#ifndef RSIZE_MAX /* C11, Annex K */ +#define RSIZE_MAX (SIZE_MAX >> 1) +#endif +#ifndef RSSIZE_MAX /* Halve signed size even further than unsigned */ +#define RSSIZE_MAX ((ssize_t)(RSIZE_MAX >> 1)) +#endif +#else /* Old compiler */ +#undef SIZE_MAX +#undef RSIZE_MAX +#undef RSSIZE_MAX +#define SIZE_MAX ((~((size_t)0)) >> 1) +#define RSIZE_MAX (SIZE_MAX >> 1) +#define RSSIZE_MAX ((ssize_t)(RSIZE_MAX >> 1)) +#endif + +#if __STDC_VERSION__ >= 199901L +#define ASN_PRI_SIZE "zu" +#define ASN_PRI_SSIZE "zd" +#define ASN_PRIuMAX PRIuMAX +#define ASN_PRIdMAX PRIdMAX +#define ASN_PRIu64 PRIu64 +#define ASN_PRId64 PRId64 +#else +#define ASN_PRI_SIZE "lu" +#define ASN_PRI_SSIZE "ld" +#define ASN_PRIu64 "llu" +#define ASN_PRId64 "lld" +#if LLONG_MAX > LONG_MAX +#define ASN_PRIuMAX "llu" +#define ASN_PRIdMAX "lld" +#else +#define ASN_PRIuMAX "lu" +#define ASN_PRIdMAX "ld" +#endif +#endif + +#endif /* ASN_SYSTEM_H */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ber_tlv_length.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ber_tlv_length.c new file mode 100644 index 000000000..0a0deec1a --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ber_tlv_length.c @@ -0,0 +1,168 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +ssize_t +ber_fetch_length(int _is_constructed, const void *bufptr, size_t size, + ber_tlv_len_t *len_r) { + const uint8_t *buf = (const uint8_t *)bufptr; + unsigned oct; + + if(size == 0) + return 0; /* Want more */ + + oct = *(const uint8_t *)buf; + if((oct & 0x80) == 0) { + /* + * Short definite length. + */ + *len_r = oct; /* & 0x7F */ + return 1; + } else { + ber_tlv_len_t len; + size_t skipped; + + if(_is_constructed && oct == 0x80) { + *len_r = -1; /* Indefinite length */ + return 1; + } + + if(oct == 0xff) { + /* Reserved in standard for future use. */ + return -1; + } + + oct &= 0x7F; /* Leave only the 7 LS bits */ + for(len = 0, buf++, skipped = 1; + oct && (++skipped <= size); buf++, oct--) { + + /* Verify that we won't overflow. */ + if(!(len >> ((8 * sizeof(len)) - (8+1)))) { + len = (len << 8) | *buf; + } else { + /* Too large length value. */ + return -1; + } + } + + if(oct == 0) { + if(len < 0 || len > RSSIZE_MAX) { + /* Length value out of sane range. */ + return -1; + } + + *len_r = len; + return skipped; + } + + return 0; /* Want more */ + } + +} + +ssize_t +ber_skip_length(const asn_codec_ctx_t *opt_codec_ctx, + int _is_constructed, const void *ptr, size_t size) { + ber_tlv_len_t vlen; /* Length of V in TLV */ + ssize_t tl; /* Length of L in TLV */ + ssize_t ll; /* Length of L in TLV */ + size_t skip; + + /* + * Make sure we didn't exceed the maximum stack size. + */ + if(ASN__STACK_OVERFLOW_CHECK(opt_codec_ctx)) + return -1; + + /* + * Determine the size of L in TLV. + */ + ll = ber_fetch_length(_is_constructed, ptr, size, &vlen); + if(ll <= 0) return ll; + + /* + * Definite length. + */ + if(vlen >= 0) { + skip = ll + vlen; + if(skip > size) + return 0; /* Want more */ + return skip; + } + + /* + * Indefinite length! + */ + ASN_DEBUG("Skipping indefinite length"); + for(skip = ll, ptr = ((const char *)ptr) + ll, size -= ll;;) { + ber_tlv_tag_t tag; + + /* Fetch the tag */ + tl = ber_fetch_tag(ptr, size, &tag); + if(tl <= 0) return tl; + + ll = ber_skip_length(opt_codec_ctx, + BER_TLV_CONSTRUCTED(ptr), + ((const char *)ptr) + tl, size - tl); + if(ll <= 0) return ll; + + skip += tl + ll; + + /* + * This may be the end of the indefinite length structure, + * two consecutive 0 octets. + * Check if it is true. + */ + if(((const uint8_t *)ptr)[0] == 0 + && ((const uint8_t *)ptr)[1] == 0) + return skip; + + ptr = ((const char *)ptr) + tl + ll; + size -= tl + ll; + } + + /* UNREACHABLE */ +} + +size_t +der_tlv_length_serialize(ber_tlv_len_t len, void *bufp, size_t size) { + size_t required_size; /* Size of len encoding */ + uint8_t *buf = (uint8_t *)bufp; + uint8_t *end; + int i; + + if(len <= 127) { + /* Encoded in 1 octet */ + if(size) *buf = (uint8_t)len; + return 1; + } + + /* + * Compute the size of the subsequent bytes. + */ + for(required_size = 1, i = 8; i < 8 * (int)sizeof(len); i += 8) { + if(len >> i) + required_size++; + else + break; + } + + if(size <= required_size) + return required_size + 1; + + *buf++ = (uint8_t)(0x80 | required_size); /* Length of the encoding */ + + /* + * Produce the len encoding, space permitting. + */ + end = buf + required_size; + for(i -= 8; buf < end; i -= 8, buf++) + *buf = (uint8_t)(len >> i); + + return required_size + 1; +} + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ber_tlv_length.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ber_tlv_length.h new file mode 100644 index 000000000..d1e4d48dd --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ber_tlv_length.h @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _BER_TLV_LENGTH_H_ +#define _BER_TLV_LENGTH_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef ssize_t ber_tlv_len_t; + +/* + * This function tries to fetch the length of the BER TLV value and place it + * in *len_r. + * RETURN VALUES: + * 0: More data expected than bufptr contains. + * -1: Fatal error deciphering length. + * >0: Number of bytes used from bufptr. + * On return with >0, len_r is constrained as -1..MAX, where -1 mean + * that the value is of indefinite length. + */ +ssize_t ber_fetch_length(int _is_constructed, const void *bufptr, size_t size, + ber_tlv_len_t *len_r); + +/* + * This function expects bufptr to be positioned over L in TLV. + * It returns number of bytes occupied by L and V together, suitable + * for skipping. The function properly handles indefinite length. + * RETURN VALUES: + * Standard {-1,0,>0} convention. + */ +ssize_t ber_skip_length( + const struct asn_codec_ctx_s *opt_codec_ctx, /* optional context */ + int _is_constructed, const void *bufptr, size_t size); + +/* + * This function serializes the length (L from TLV) in DER format. + * It always returns number of bytes necessary to represent the length, + * it is a caller's responsibility to check the return value + * against the supplied buffer's size. + */ +size_t der_tlv_length_serialize(ber_tlv_len_t len, void *bufptr, size_t size); + +#ifdef __cplusplus +} +#endif + +#endif /* _BER_TLV_LENGTH_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ber_tlv_tag.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ber_tlv_tag.c new file mode 100644 index 000000000..64ec14f07 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ber_tlv_tag.c @@ -0,0 +1,144 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +ssize_t +ber_fetch_tag(const void *ptr, size_t size, ber_tlv_tag_t *tag_r) { + ber_tlv_tag_t val; + ber_tlv_tag_t tclass; + size_t skipped; + + if(size == 0) + return 0; + + val = *(const uint8_t *)ptr; + tclass = (val >> 6); + if((val &= 0x1F) != 0x1F) { + /* + * Simple form: everything encoded in a single octet. + * Tag Class is encoded using two least significant bits. + */ + *tag_r = (val << 2) | tclass; + return 1; + } + + /* + * Each octet contains 7 bits of useful information. + * The MSB is 0 if it is the last octet of the tag. + */ + for(val = 0, ptr = ((const char *)ptr) + 1, skipped = 2; + skipped <= size; + ptr = ((const char *)ptr) + 1, skipped++) { + unsigned int oct = *(const uint8_t *)ptr; + if(oct & 0x80) { + val = (val << 7) | (oct & 0x7F); + /* + * Make sure there are at least 9 bits spare + * at the MS side of a value. + */ + if(val >> ((8 * sizeof(val)) - 9)) { + /* + * We would not be able to accommodate + * any more tag bits. + */ + return -1; + } + } else { + val = (val << 7) | oct; + *tag_r = (val << 2) | tclass; + return skipped; + } + } + + return 0; /* Want more */ +} + + +ssize_t +ber_tlv_tag_fwrite(ber_tlv_tag_t tag, FILE *f) { + char buf[sizeof("[APPLICATION ]") + 32]; + ssize_t ret; + + ret = ber_tlv_tag_snprint(tag, buf, sizeof(buf)); + if(ret >= (ssize_t)sizeof(buf) || ret < 2) { + errno = EPERM; + return -1; + } + + return fwrite(buf, 1, ret, f); +} + +ssize_t +ber_tlv_tag_snprint(ber_tlv_tag_t tag, char *buf, size_t size) { + const char *type = 0; + int ret; + + switch(tag & 0x3) { + case ASN_TAG_CLASS_UNIVERSAL: type = "UNIVERSAL "; break; + case ASN_TAG_CLASS_APPLICATION: type = "APPLICATION "; break; + case ASN_TAG_CLASS_CONTEXT: type = ""; break; + case ASN_TAG_CLASS_PRIVATE: type = "PRIVATE "; break; + } + + ret = snprintf(buf, size, "[%s%u]", type, ((unsigned)tag) >> 2); + if(ret <= 0 && size) buf[0] = '\0'; /* against broken libc's */ + + return ret; +} + +char * +ber_tlv_tag_string(ber_tlv_tag_t tag) { + static char buf[sizeof("[APPLICATION ]") + 32]; + + (void)ber_tlv_tag_snprint(tag, buf, sizeof(buf)); + + return buf; +} + + +size_t +ber_tlv_tag_serialize(ber_tlv_tag_t tag, void *bufp, size_t size) { + int tclass = BER_TAG_CLASS(tag); + ber_tlv_tag_t tval = BER_TAG_VALUE(tag); + uint8_t *buf = (uint8_t *)bufp; + uint8_t *end; + size_t required_size; + size_t i; + + if(tval <= 30) { + /* Encoded in 1 octet */ + if(size) buf[0] = (tclass << 6) | tval; + return 1; + } else if(size) { + *buf++ = (tclass << 6) | 0x1F; + size--; + } + + /* + * Compute the size of the subsequent bytes. + */ + for(required_size = 1, i = 7; i < 8 * sizeof(tval); i += 7) { + if(tval >> i) + required_size++; + else + break; + } + + if(size < required_size) + return required_size + 1; + + /* + * Fill in the buffer, space permitting. + */ + end = buf + required_size - 1; + for(i -= 7; buf < end; i -= 7, buf++) + *buf = 0x80 | ((tval >> i) & 0x7F); + *buf = (tval & 0x7F); /* Last octet without high bit */ + + return required_size + 1; +} + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ber_tlv_tag.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ber_tlv_tag.h new file mode 100644 index 000000000..ce227add6 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/ber_tlv_tag.h @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _BER_TLV_TAG_H_ +#define _BER_TLV_TAG_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +enum asn_tag_class { + ASN_TAG_CLASS_UNIVERSAL = 0, /* 0b00 */ + ASN_TAG_CLASS_APPLICATION = 1, /* 0b01 */ + ASN_TAG_CLASS_CONTEXT = 2, /* 0b10 */ + ASN_TAG_CLASS_PRIVATE = 3 /* 0b11 */ +}; +typedef unsigned ber_tlv_tag_t; /* BER TAG from Tag-Length-Value */ + +/* + * Tag class is encoded together with tag value for optimization purposes. + */ +#define BER_TAG_CLASS(tag) ((tag) & 0x3) +#define BER_TAG_VALUE(tag) ((tag) >> 2) +#define BER_TLV_CONSTRUCTED(tagptr) (((*(const uint8_t *)tagptr)&0x20)?1:0) + +#define BER_TAGS_EQUAL(tag1, tag2) ((tag1) == (tag2)) + +/* + * Several functions for printing the TAG in the canonical form + * (i.e. "[PRIVATE 0]"). + * Return values correspond to their libc counterparts (if any). + */ +ssize_t ber_tlv_tag_snprint(ber_tlv_tag_t tag, char *buf, size_t buflen); +ssize_t ber_tlv_tag_fwrite(ber_tlv_tag_t tag, FILE *); +char *ber_tlv_tag_string(ber_tlv_tag_t tag); + + +/* + * This function tries to fetch the tag from the input stream. + * RETURN VALUES: + * 0: More data expected than bufptr contains. + * -1: Fatal error deciphering tag. + * >0: Number of bytes used from bufptr. tag_r will contain the tag. + */ +ssize_t ber_fetch_tag(const void *bufptr, size_t size, ber_tlv_tag_t *tag_r); + +/* + * This function serializes the tag (T from TLV) in BER format. + * It always returns number of bytes necessary to represent the tag, + * it is a caller's responsibility to check the return value + * against the supplied buffer's size. + */ +size_t ber_tlv_tag_serialize(ber_tlv_tag_t tag, void *bufptr, size_t size); + +#ifdef __cplusplus +} +#endif + +#endif /* _BER_TLV_TAG_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE.c new file mode 100644 index 000000000..2a20583a1 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE.c @@ -0,0 +1,415 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_TYPE_operation_t asn_OP_CHOICE = { + CHOICE_free, +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + CHOICE_print, +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + CHOICE_compare, + CHOICE_copy, +#if !defined(ASN_DISABLE_BER_SUPPORT) + CHOICE_decode_ber, + CHOICE_encode_der, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + CHOICE_decode_xer, + CHOICE_encode_xer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + CHOICE_decode_jer, + CHOICE_encode_jer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + CHOICE_decode_oer, + CHOICE_encode_oer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + CHOICE_decode_uper, + CHOICE_encode_uper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + CHOICE_decode_aper, + CHOICE_encode_aper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + CHOICE_random_fill, +#else + 0, +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + CHOICE_outmost_tag +}; + +ber_tlv_tag_t +CHOICE_outmost_tag(const asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode, ber_tlv_tag_t tag) { + const asn_CHOICE_specifics_t *specs = (const asn_CHOICE_specifics_t *)td->specifics; + unsigned present; + + assert(tag_mode == 0); (void)tag_mode; + assert(tag == 0); (void)tag; + + /* + * Figure out which CHOICE element is encoded. + */ + present = _fetch_present_idx(ptr, specs->pres_offset, specs->pres_size); + + if(present > 0 && present <= td->elements_count) { + const asn_TYPE_member_t *elm = &td->elements[present-1]; + const void *memb_ptr; + + if(elm->flags & ATF_POINTER) { + memb_ptr = *(const void * const *) + ((const char *)ptr + elm->memb_offset); + } else { + memb_ptr = (const void *) + ((const char *)ptr + elm->memb_offset); + } + + return asn_TYPE_outmost_tag(elm->type, memb_ptr, + elm->tag_mode, elm->tag); + } else { + return (ber_tlv_tag_t)-1; + } +} + +/* + * See the definitions. + */ +static const void *_get_member_ptr(const asn_TYPE_descriptor_t *, + const void *sptr, asn_TYPE_member_t **elm, + unsigned *present); + +int +CHOICE_constraint(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + const asn_CHOICE_specifics_t *specs = + (const asn_CHOICE_specifics_t *)td->specifics; + unsigned present; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + /* + * Figure out which CHOICE element is encoded. + */ + present = _fetch_present_idx(sptr, specs->pres_offset,specs->pres_size); + if(present > 0 && present <= td->elements_count) { + asn_TYPE_member_t *elm = &td->elements[present-1]; + const void *memb_ptr; + + if(elm->flags & ATF_POINTER) { + memb_ptr = *(const void * const *)((const char *)sptr + elm->memb_offset); + if(!memb_ptr) { + if(elm->optional) + return 0; + ASN__CTFAIL(app_key, td, sptr, + "%s: mandatory CHOICE element %s absent (%s:%d)", + td->name, elm->name, __FILE__, __LINE__); + return -1; + } + } else { + memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); + } + + if(elm->encoding_constraints.general_constraints) { + return elm->encoding_constraints.general_constraints(elm->type, memb_ptr, + ctfailcb, app_key); + } else { + return elm->type->encoding_constraints.general_constraints(elm->type, + memb_ptr, ctfailcb, app_key); + } + } else { + ASN__CTFAIL(app_key, td, sptr, + "%s: no CHOICE element given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } +} + +void +CHOICE_free(const asn_TYPE_descriptor_t *td, void *ptr, + enum asn_struct_free_method method) { + const asn_CHOICE_specifics_t *specs; + unsigned present; + + if(!td || !ptr) + return; + + specs = (const asn_CHOICE_specifics_t *)td->specifics; + + ASN_DEBUG("Freeing %s as CHOICE", td->name); + + /* + * Figure out which CHOICE element is encoded. + */ + present = _fetch_present_idx(ptr, specs->pres_offset, specs->pres_size); + + /* + * Free that element. + */ + if(present > 0 && present <= td->elements_count) { + asn_TYPE_member_t *elm = &td->elements[present-1]; + void *memb_ptr; + + if(elm->flags & ATF_POINTER) { + memb_ptr = *(void **)((char *)ptr + elm->memb_offset); + if(memb_ptr) + ASN_STRUCT_FREE(*elm->type, memb_ptr); + } else { + memb_ptr = (void *)((char *)ptr + elm->memb_offset); + ASN_STRUCT_FREE_CONTENTS_ONLY(*elm->type, memb_ptr); + } + } + + switch(method) { + case ASFM_FREE_EVERYTHING: + FREEMEM(ptr); + break; + case ASFM_FREE_UNDERLYING: + break; + case ASFM_FREE_UNDERLYING_AND_RESET: + memset(ptr, 0, specs->struct_size); + break; + } +} + + +/* + * The following functions functions offer protection against -fshort-enums, + * compatible with little- and big-endian machines. + * If assertion is triggered, either disable -fshort-enums, or add an entry + * here with the ->pres_size of your target stracture. + * Unless the target structure is packed, the ".present" member + * is guaranteed to be aligned properly. ASN.1 compiler itself does not + * produce packed code. + */ +unsigned +_fetch_present_idx(const void *struct_ptr, unsigned pres_offset, + unsigned pres_size) { + const void *present_ptr; + unsigned present; + + present_ptr = ((const char *)struct_ptr) + pres_offset; + + switch(pres_size) { + case sizeof(int): present = *(const unsigned int *)present_ptr; break; + case sizeof(short): present = *(const unsigned short *)present_ptr; break; + case sizeof(char): present = *(const unsigned char *)present_ptr; break; + default: + /* ANSI C mandates enum to be equivalent to integer */ + assert(pres_size != sizeof(int)); + return 0; /* If not aborted, pass back safe value */ + } + + return present; +} + +void +_set_present_idx(void *struct_ptr, unsigned pres_offset, unsigned pres_size, + unsigned present) { + void *present_ptr; + present_ptr = ((char *)struct_ptr) + pres_offset; + + switch(pres_size) { + case sizeof(int): *(unsigned int *)present_ptr = present; break; + case sizeof(short): *(unsigned short *)present_ptr = present; break; + case sizeof(char): *(unsigned char *)present_ptr = present; break; + default: + /* ANSI C mandates enum to be equivalent to integer */ + assert(pres_size != sizeof(int)); + } +} + +static const void * +_get_member_ptr(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_TYPE_member_t **elm_ptr, unsigned *present_out) { + const asn_CHOICE_specifics_t *specs = + (const asn_CHOICE_specifics_t *)td->specifics; + unsigned present; + + if(!sptr) { + *elm_ptr = NULL; + *present_out = 0; + return NULL; + } + + /* + * Figure out which CHOICE element is encoded. + */ + present = _fetch_present_idx(sptr, specs->pres_offset, specs->pres_size); + *present_out = present; + + /* + * The presence index is intentionally 1-based to avoid + * treating zeroed structure as a valid one. + */ + if(present > 0 && present <= td->elements_count) { + asn_TYPE_member_t *const elm = &td->elements[present - 1]; + const void *memb_ptr; + + if(elm->flags & ATF_POINTER) { + memb_ptr = + *(const void *const *)((const char *)sptr + elm->memb_offset); + } else { + memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); + } + *elm_ptr = elm; + return memb_ptr; + } else { + *elm_ptr = NULL; + return NULL; + } + +} + +int +CHOICE_compare(const asn_TYPE_descriptor_t *td, const void *aptr, const void *bptr) { + asn_TYPE_member_t *aelm; + asn_TYPE_member_t *belm; + unsigned apresent = 0; + unsigned bpresent = 0; + const void *amember = _get_member_ptr(td, aptr, &aelm, &apresent); + const void *bmember = _get_member_ptr(td, bptr, &belm, &bpresent); + + if(amember && bmember) { + if(apresent == bpresent) { + assert(aelm == belm); + return aelm->type->op->compare_struct(aelm->type, amember, bmember); + } else if(apresent < bpresent) { + return -1; + } else { + return 1; + } + } else if(!amember) { + return -1; + } else { + return 1; + } +} + +int +CHOICE_copy(const asn_TYPE_descriptor_t *td, void **aptr, const void *bptr) { + if(!td) return -1; + + void *st = *aptr; + const asn_CHOICE_specifics_t *specs = + (const asn_CHOICE_specifics_t *)td->specifics; + const asn_TYPE_member_t *elm; /* CHOICE's element */ + int present; + int ret; + void *amemb; + void **amembp; + const void *bmemb; + + if(!bptr) { + if(st) { + ASN_STRUCT_FREE(*td, st); + *aptr = NULL; + } + return 0; + } + + if(!st) { + st = *aptr = CALLOC(1, specs->struct_size); + if(!st) return -1; + } + + present = _fetch_present_idx(bptr, + specs->pres_offset, specs->pres_size); + + if(present <= 0 && (unsigned)present > td->elements_count) return -1; + --present; + + elm = &td->elements[present]; + if(elm->flags & ATF_POINTER) { + /* Member is a pointer to another structure */ + amembp = (void **)((char *)st + elm->memb_offset); + bmemb = *(const void* const*)((const char*)bptr + elm->memb_offset); + } else { + amemb = (char *)st + elm->memb_offset; + amembp = &amemb; + bmemb = (const void*)((const char*)bptr + elm->memb_offset); + } + ret = elm->type->op->copy_struct(elm->type, amembp, bmemb); + if (ret != 0) return ret; + + _set_present_idx(st, + specs->pres_offset, + specs->pres_size, present + 1); + + return 0; +} + +/* + * Return the 1-based choice variant presence index. + * Returns 0 in case of error. + */ +unsigned +CHOICE_variant_get_presence(const asn_TYPE_descriptor_t *td, const void *sptr) { + const asn_CHOICE_specifics_t *specs = + (const asn_CHOICE_specifics_t *)td->specifics; + return _fetch_present_idx(sptr, specs->pres_offset, specs->pres_size); +} + +/* + * Sets or resets the 1-based choice variant presence index. + * In case a previous index is not zero, the currently selected structure + * member is freed and zeroed-out first. + * Returns 0 on success and -1 on error. + */ +int +CHOICE_variant_set_presence(const asn_TYPE_descriptor_t *td, void *sptr, + unsigned present) { + const asn_CHOICE_specifics_t *specs = + (const asn_CHOICE_specifics_t *)td->specifics; + unsigned old_present; + + if(!sptr) { + return -1; + } + + if(present > td->elements_count) + return -1; + + old_present = + _fetch_present_idx(sptr, specs->pres_offset, specs->pres_size); + if(present == old_present) + return 0; + + if(old_present != 0) { + assert(old_present <= td->elements_count); + ASN_STRUCT_RESET(*td, sptr); + } + + _set_present_idx(sptr, specs->pres_offset, specs->pres_size, present); + + return 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE.h new file mode 100644 index 000000000..1bec3cab8 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE.h @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _CONSTR_CHOICE_H_ +#define _CONSTR_CHOICE_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct asn_CHOICE_specifics_s { + /* + * Target structure description. + */ + unsigned struct_size; /* Size of the target structure. */ + unsigned ctx_offset; /* Offset of the asn_codec_ctx_t member */ + unsigned pres_offset; /* Identifier of the present member */ + unsigned pres_size; /* Size of the identifier (enum) */ + + /* + * Tags to members mapping table. + */ + const asn_TYPE_tag2member_t *tag2el; + unsigned tag2el_count; + + /* Canonical ordering of CHOICE elements, for PER */ + const unsigned *to_canonical_order; + const unsigned *from_canonical_order; + + /* + * Extensions-related stuff. + */ + signed ext_start; /* First member of extensions, or -1 */ +} asn_CHOICE_specifics_t; + +/* + * A set specialized functions dealing with the CHOICE type. + */ +asn_struct_free_f CHOICE_free; + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +asn_struct_print_f CHOICE_print; +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +asn_struct_compare_f CHOICE_compare; +asn_struct_copy_f CHOICE_copy; + +asn_constr_check_f CHOICE_constraint; + +#if !defined(ASN_DISABLE_BER_SUPPORT) +ber_type_decoder_f CHOICE_decode_ber; +der_type_encoder_f CHOICE_encode_der; +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +xer_type_decoder_f CHOICE_decode_xer; +xer_type_encoder_f CHOICE_encode_xer; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +jer_type_decoder_f CHOICE_decode_jer; +jer_type_encoder_f CHOICE_encode_jer; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_OER_SUPPORT) +oer_type_decoder_f CHOICE_decode_oer; +oer_type_encoder_f CHOICE_encode_oer; +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +per_type_decoder_f CHOICE_decode_uper; +per_type_encoder_f CHOICE_encode_uper; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +per_type_decoder_f CHOICE_decode_aper; +per_type_encoder_f CHOICE_encode_aper; +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#if !defined(ASN_DISABLE_RFILL_SUPPORT) +asn_random_fill_f CHOICE_random_fill; +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + +asn_outmost_tag_f CHOICE_outmost_tag; + +extern asn_TYPE_operation_t asn_OP_CHOICE; + +unsigned _fetch_present_idx( + const void *struct_ptr, + unsigned off, + unsigned size); + +void _set_present_idx( + void *sptr, + unsigned offset, + unsigned size, + unsigned present); + +/* + * Return the 1-based choice variant presence index. + * Returns 0 in case of error. + */ +unsigned CHOICE_variant_get_presence(const asn_TYPE_descriptor_t *td, + const void *structure_ptr); + +/* + * Sets or resets the 1-based choice variant presence index. + * In case a previous index is not zero, the currently selected structure + * member is freed and zeroed-out first. + * Returns 0 on success and -1 on error. + */ +int CHOICE_variant_set_presence(const asn_TYPE_descriptor_t *td, + void *structure_ptr, unsigned present); + +#ifdef __cplusplus +} +#endif + +#endif /* _CONSTR_CHOICE_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE_aper.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE_aper.c new file mode 100644 index 000000000..0f0742333 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE_aper.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +asn_dec_rval_t +CHOICE_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_CHOICE_specifics_t *specs = (const asn_CHOICE_specifics_t *)td->specifics; + asn_dec_rval_t rv; + const asn_per_constraint_t *ct = NULL; + asn_TYPE_member_t *elm = NULL; /* CHOICE's element */ + void *memb_ptr = NULL; + void **memb_ptr2 = NULL; + void *st = *sptr; + int value = 0; + + if(ASN__STACK_OVERFLOW_CHECK(opt_codec_ctx)) + ASN__DECODE_FAILED; + + /* + * Create the target structure if it is not present already. + */ + if(!st) { + st = *sptr = CALLOC(1, specs->struct_size); + if(!st) ASN__DECODE_FAILED; + } + + if(constraints) ct = &constraints->value; + else if(td->encoding_constraints.per_constraints) + ct = &td->encoding_constraints.per_constraints->value; + else ct = 0; + + if(ct && ct->flags & APC_EXTENSIBLE) { + value = per_get_few_bits(pd, 1); + if(value < 0) ASN__DECODE_STARVED; + if(value) ct = 0; /* Not restricted */ + if((unsigned)value >= td->elements_count) + ASN__DECODE_FAILED; + } + + if(ct && ct->range_bits >= 0) { + value = per_get_few_bits(pd, ct->range_bits); + if(value < 0) ASN__DECODE_STARVED; + ASN_DEBUG("CHOICE %s got index %d in range %d", + td->name, value, ct->range_bits); + if(value > ct->upper_bound) + ASN__DECODE_FAILED; + } else { + if(specs->ext_start == -1) + ASN__DECODE_FAILED; + + if(specs && specs->tag2el_count > (unsigned)specs->ext_start) { + value = aper_get_nsnnwn(pd); /* extension elements range */ + if(value < 0) ASN__DECODE_STARVED; + value += specs->ext_start; + if((unsigned)value >= td->elements_count) + ASN__DECODE_FAILED; + } + } + + /* Adjust if canonical order is different from natural order */ + if(specs->from_canonical_order) + value = specs->from_canonical_order[value]; + + /* Set presence to be able to free it later */ + _set_present_idx(st, specs->pres_offset, specs->pres_size, value + 1); + + elm = &td->elements[value]; + if(elm->flags & ATF_POINTER) { + /* Member is a pointer to another structure */ + memb_ptr2 = (void **)((char *)st + elm->memb_offset); + } else { + memb_ptr = (char *)st + elm->memb_offset; + memb_ptr2 = &memb_ptr; + } + ASN_DEBUG("Discovered CHOICE %s encodes %s", td->name, elm->name); + + if(ct && ct->range_bits >= 0) { + rv = elm->type->op->aper_decoder(opt_codec_ctx, elm->type, + elm->encoding_constraints.per_constraints, memb_ptr2, pd); + } else { + rv = aper_open_type_get(opt_codec_ctx, elm->type, + elm->encoding_constraints.per_constraints, memb_ptr2, pd); + } + + if(rv.code != RC_OK) + ASN_DEBUG("Failed to decode %s in %s (CHOICE) %d", + elm->name, td->name, rv.code); + return rv; +} + +asn_enc_rval_t +CHOICE_encode_aper(const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, + const void *sptr, asn_per_outp_t *po) { + const asn_CHOICE_specifics_t *specs = (const asn_CHOICE_specifics_t *)td->specifics; + const asn_TYPE_member_t *elm; /* CHOICE's element */ + const asn_per_constraint_t *ct; + const void *memb_ptr; + int present; + + if(!sptr) ASN__ENCODE_FAILED; + + ASN_DEBUG("Encoding %s as CHOICE using ALIGNED PER", td->name); + + if(constraints) ct = &constraints->value; + else if(td->encoding_constraints.per_constraints) + ct = &td->encoding_constraints.per_constraints->value; + else ct = 0; + + present = _fetch_present_idx(sptr, + specs->pres_offset, specs->pres_size); + + /* + * If the structure was not initialized properly, it cannot be encoded: + * can't deduce what to encode in the choice type. + */ + if(present <= 0 || (unsigned)present > td->elements_count) + ASN__ENCODE_FAILED; + else + present--; + + /* Adjust if canonical order is different from natural order */ + if(specs->to_canonical_order) + present = specs->to_canonical_order[present]; + + ASN_DEBUG("Encoding %s CHOICE element %d", td->name, present); + + if(ct && ct->range_bits >= 0) { + if(present < ct->lower_bound + || present > ct->upper_bound) { + if(ct->flags & APC_EXTENSIBLE) { + if(per_put_few_bits(po, 1, 1)) + ASN__ENCODE_FAILED; + } else { + ASN__ENCODE_FAILED; + } + ct = 0; + } + } + if(ct && ct->flags & APC_EXTENSIBLE) { + if(per_put_few_bits(po, 0, 1)) + ASN__ENCODE_FAILED; + } + + elm = &td->elements[present]; + if(elm->flags & ATF_POINTER) { + /* Member is a pointer to another structure */ + memb_ptr = *(const void *const *)((const char *)sptr + elm->memb_offset); + if(!memb_ptr) ASN__ENCODE_FAILED; + } else { + memb_ptr = (const char *)sptr + elm->memb_offset; + } + + if(ct && ct->range_bits >= 0) { + if(per_put_few_bits(po, present, ct->range_bits)) + ASN__ENCODE_FAILED; + + return elm->type->op->aper_encoder(elm->type, elm->encoding_constraints.per_constraints, + memb_ptr, po); + } else { + asn_enc_rval_t rval = {0,0,0}; + if(specs->ext_start == -1) + ASN__ENCODE_FAILED; + if(aper_put_nsnnwn(po, present - specs->ext_start)) + ASN__ENCODE_FAILED; + if(aper_open_type_put(elm->type, elm->encoding_constraints.per_constraints, + memb_ptr, po)) + ASN__ENCODE_FAILED; + rval.encoded = 0; + ASN__ENCODED_OK(rval); + } +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE_print.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE_print.c new file mode 100644 index 000000000..a97202fc2 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE_print.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +int +CHOICE_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, + asn_app_consume_bytes_f *cb, void *app_key) { + const asn_CHOICE_specifics_t *specs = (const asn_CHOICE_specifics_t *)td->specifics; + unsigned present; + + if(!sptr) return (cb("", 8, app_key) < 0) ? -1 : 0; + + /* + * Figure out which CHOICE element is encoded. + */ + present = _fetch_present_idx(sptr, specs->pres_offset,specs->pres_size); + + /* + * Print that element. + */ + if(present > 0 && present <= td->elements_count) { + asn_TYPE_member_t *elm = &td->elements[present-1]; + const void *memb_ptr; + + if(elm->flags & ATF_POINTER) { + memb_ptr = *(const void * const *)((const char *)sptr + elm->memb_offset); + if(!memb_ptr) return (cb("", 8, app_key) < 0) ? -1 : 0; + } else { + memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); + } + + /* Print member's name and stuff */ + if(0) { + if(cb(elm->name, strlen(elm->name), app_key) < 0 + || cb(": ", 2, app_key) < 0) + return -1; + } + + return elm->type->op->print_struct(elm->type, memb_ptr, ilevel, + cb, app_key); + } else { + return (cb("", 8, app_key) < 0) ? -1 : 0; + } +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE_rfill.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE_rfill.c new file mode 100644 index 000000000..fd0a10163 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE_rfill.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_random_fill_result_t +CHOICE_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, + const asn_encoding_constraints_t *constr, + size_t max_length) { + const asn_CHOICE_specifics_t *specs = + (const asn_CHOICE_specifics_t *)td->specifics; + asn_random_fill_result_t res; + asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0}; + asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0}; + const asn_TYPE_member_t *elm; + unsigned present; + void *memb_ptr; /* Pointer to the member */ + void **memb_ptr2; /* Pointer to that pointer */ + void *st = *sptr; + + if(max_length == 0) return result_skipped; + + (void)constr; + + if(st == NULL) { + st = CALLOC(1, specs->struct_size); + if(st == NULL) { + return result_failed; + } + } + + present = asn_random_between(1, td->elements_count); + elm = &td->elements[present - 1]; + + if(elm->flags & ATF_POINTER) { + /* Member is a pointer to another structure */ + memb_ptr2 = (void **)((char *)st + elm->memb_offset); + } else { + memb_ptr = (char *)st + elm->memb_offset; + memb_ptr2 = &memb_ptr; + } + + res = elm->type->op->random_fill(elm->type, memb_ptr2, + &elm->encoding_constraints, max_length); + _set_present_idx(st, specs->pres_offset, specs->pres_size, present); + if(res.code == ARFILL_OK) { + *sptr = st; + } else { + if(st == *sptr) { + ASN_STRUCT_RESET(*td, st); + } else { + ASN_STRUCT_FREE(*td, st); + } + } + + return res; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE_xer.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE_xer.c new file mode 100644 index 000000000..90ae02f38 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_CHOICE_xer.c @@ -0,0 +1,316 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* + * Return a standardized complex structure. + */ +#undef RETURN +#define RETURN(_code) \ + do { \ + rval.code = _code; \ + rval.consumed = consumed_myself; \ + return rval; \ + } while(0) + +#undef XER_ADVANCE +#define XER_ADVANCE(num_bytes) \ + do { \ + size_t num = num_bytes; \ + buf_ptr = (const void *)(((const char *)buf_ptr) + num); \ + size -= num; \ + consumed_myself += num; \ + } while(0) + +/* + * Decode the XER (XML) data. + */ +asn_dec_rval_t +CHOICE_decode_xer(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **struct_ptr, + const char *opt_mname, const void *buf_ptr, size_t size) { + /* + * Bring closer parts of structure description. + */ + const asn_CHOICE_specifics_t *specs = (const asn_CHOICE_specifics_t *)td->specifics; + const char *xml_tag = opt_mname ? opt_mname : td->xml_tag; + + /* + * Parts of the structure being constructed. + */ + void *st = *struct_ptr; /* Target structure. */ + asn_struct_ctx_t *ctx; /* Decoder context */ + + asn_dec_rval_t rval; /* Return value of a decoder */ + ssize_t consumed_myself = 0; /* Consumed bytes from ptr */ + size_t edx; /* Element index */ + + /* + * Create the target structure if it is not present already. + */ + if(st == 0) { + st = *struct_ptr = CALLOC(1, specs->struct_size); + if(st == 0) RETURN(RC_FAIL); + } + + /* + * Restore parsing context. + */ + ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset); + if(ctx->phase == 0 && !*xml_tag) + ctx->phase = 1; /* Skip the outer tag checking phase */ + + /* + * Phases of XER/XML processing: + * Phase 0: Check that the opening tag matches our expectations. + * Phase 1: Processing body and reacting on closing tag. + * Phase 2: Processing inner type. + * Phase 3: Only waiting for closing tag. + * Phase 4: Skipping unknown extensions. + * Phase 5: PHASED OUT + */ + for(edx = ctx->step; ctx->phase <= 4;) { + pxer_chunk_type_e ch_type; /* XER chunk type */ + ssize_t ch_size; /* Chunk size */ + xer_check_tag_e tcv; /* Tag check value */ + asn_TYPE_member_t *elm; + + /* + * Go inside the member. + */ + if(ctx->phase == 2) { + asn_dec_rval_t tmprval; + void *memb_ptr; /* Pointer to the member */ + void **memb_ptr2; /* Pointer to that pointer */ + unsigned old_present __attribute__((unused)); + + elm = &td->elements[edx]; + + if(elm->flags & ATF_POINTER) { + /* Member is a pointer to another structure */ + memb_ptr2 = (void **)((char *)st + + elm->memb_offset); + } else { + memb_ptr = (char *)st + elm->memb_offset; + memb_ptr2 = &memb_ptr; + } + + /* Start/Continue decoding the inner member */ + tmprval = elm->type->op->xer_decoder(opt_codec_ctx, + elm->type, memb_ptr2, + elm->name, + buf_ptr, size); + XER_ADVANCE(tmprval.consumed); + ASN_DEBUG("XER/CHOICE: itdf: [%s] code=%d", + elm->type->name, tmprval.code); + old_present = _fetch_present_idx(st, + specs->pres_offset, + specs->pres_size); + assert(old_present == 0 || old_present == edx + 1); + /* Record what we've got */ + _set_present_idx(st, + specs->pres_offset, + specs->pres_size, edx + 1); + if(tmprval.code != RC_OK) + RETURN(tmprval.code); + ctx->phase = 3; + /* Fall through */ + } + + /* No need to wait for closing tag; special mode. */ + if(ctx->phase == 3 && !*xml_tag) { + ctx->phase = 5; /* Phase out */ + RETURN(RC_OK); + } + + /* + * Get the next part of the XML stream. + */ + ch_size = xer_next_token(&ctx->context, buf_ptr, size, &ch_type); + if(ch_size == -1) { + RETURN(RC_FAIL); + } else { + switch(ch_type) { + case PXER_WMORE: + RETURN(RC_WMORE); + case PXER_COMMENT: /* Got XML comment */ + case PXER_TEXT: /* Ignore free-standing text */ + XER_ADVANCE(ch_size); /* Skip silently */ + continue; + case PXER_TAG: + break; /* Check the rest down there */ + } + } + + tcv = xer_check_tag(buf_ptr, ch_size, xml_tag); + ASN_DEBUG("XER/CHOICE checked [%c%c%c%c] vs [%s], tcv=%d", + ch_size>0?((const uint8_t *)buf_ptr)[0]:'?', + ch_size>1?((const uint8_t *)buf_ptr)[1]:'?', + ch_size>2?((const uint8_t *)buf_ptr)[2]:'?', + ch_size>3?((const uint8_t *)buf_ptr)[3]:'?', + xml_tag, tcv); + + /* Skip the extensions section */ + if(ctx->phase == 4) { + ASN_DEBUG("skip_unknown(%d, %ld)", + tcv, (long)ctx->left); + switch(xer_skip_unknown(tcv, &ctx->left)) { + case -1: + ctx->phase = 5; + RETURN(RC_FAIL); + case 1: + ctx->phase = 3; + /* Fall through */ + case 0: + XER_ADVANCE(ch_size); + continue; + case 2: + ctx->phase = 3; + break; + } + } + + switch(tcv) { + case XCT_BOTH: + break; /* No CHOICE? */ + case XCT_CLOSING: + if(ctx->phase != 3) + break; + XER_ADVANCE(ch_size); + ctx->phase = 5; /* Phase out */ + RETURN(RC_OK); + case XCT_OPENING: + if(ctx->phase == 0) { + XER_ADVANCE(ch_size); + ctx->phase = 1; /* Processing body phase */ + continue; + } + /* Fall through */ + case XCT_UNKNOWN_OP: + case XCT_UNKNOWN_BO: + + if(ctx->phase != 1) + break; /* Really unexpected */ + + /* + * Search which inner member corresponds to this tag. + */ + for(edx = 0; edx < td->elements_count; edx++) { + elm = &td->elements[edx]; + tcv = xer_check_tag(buf_ptr,ch_size,elm->name); + switch(tcv) { + case XCT_BOTH: + case XCT_OPENING: + /* + * Process this member. + */ + ctx->step = edx; + ctx->phase = 2; + break; + case XCT_UNKNOWN_OP: + case XCT_UNKNOWN_BO: + continue; + default: + edx = td->elements_count; + break; /* Phase out */ + } + break; + } + if(edx != td->elements_count) + continue; + + /* It is expected extension */ + if(specs->ext_start != -1) { + ASN_DEBUG("Got anticipated extension"); + /* + * Check for (XCT_BOTH or XCT_UNKNOWN_BO) + * By using a mask. Only record a pure + * tags. + */ + if(tcv & XCT_CLOSING) { + /* Found without body */ + ctx->phase = 3; /* Terminating */ + } else { + ctx->left = 1; + ctx->phase = 4; /* Skip ...'s */ + } + XER_ADVANCE(ch_size); + continue; + } + + /* Fall through */ + default: + break; + } + + ASN_DEBUG("Unexpected XML tag [%c%c%c%c] in CHOICE [%s]" + " (ph=%d, tag=%s)", + ch_size>0?((const uint8_t *)buf_ptr)[0]:'?', + ch_size>1?((const uint8_t *)buf_ptr)[1]:'?', + ch_size>2?((const uint8_t *)buf_ptr)[2]:'?', + ch_size>3?((const uint8_t *)buf_ptr)[3]:'?', + td->name, ctx->phase, xml_tag); + break; + } + + ctx->phase = 5; /* Phase out, just in case */ + RETURN(RC_FAIL); +} + +asn_enc_rval_t +CHOICE_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 asn_CHOICE_specifics_t *specs = + (const asn_CHOICE_specifics_t *)td->specifics; + asn_enc_rval_t er = {0,0,0}; + unsigned present = 0; + + if(!sptr) + ASN__ENCODE_FAILED; + + /* + * Figure out which CHOICE element is encoded. + */ + present = _fetch_present_idx(sptr, specs->pres_offset,specs->pres_size); + + if(present == 0 || present > td->elements_count) { + ASN__ENCODE_FAILED; + } else { + asn_enc_rval_t tmper = {0,0,0}; + asn_TYPE_member_t *elm = &td->elements[present-1]; + const void *memb_ptr = NULL; + const char *mname = elm->name; + unsigned int mlen = strlen(mname); + + if(elm->flags & ATF_POINTER) { + memb_ptr = + *(const void *const *)((const char *)sptr + elm->memb_offset); + if(!memb_ptr) ASN__ENCODE_FAILED; + } else { + memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); + } + + er.encoded = 0; + + if(!(flags & XER_F_CANONICAL)) ASN__TEXT_INDENT(1, ilevel); + ASN__CALLBACK3("<", 1, mname, mlen, ">", 1); + + tmper = elm->type->op->xer_encoder(elm->type, memb_ptr, + ilevel + 1, flags, cb, app_key); + if(tmper.encoded == -1) return tmper; + er.encoded += tmper.encoded; + + ASN__CALLBACK3("", 1); + } + + if(!(flags & XER_F_CANONICAL)) ASN__TEXT_INDENT(1, ilevel - 1); + + ASN__ENCODED_OK(er); +cb_failed: + ASN__ENCODE_FAILED; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE.c new file mode 100644 index 000000000..a77b68fac --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE.c @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_TYPE_operation_t asn_OP_SEQUENCE = { + SEQUENCE_free, +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + SEQUENCE_print, +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + SEQUENCE_compare, + SEQUENCE_copy, +#if !defined(ASN_DISABLE_BER_SUPPORT) + SEQUENCE_decode_ber, + SEQUENCE_encode_der, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + SEQUENCE_decode_xer, + SEQUENCE_encode_xer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + SEQUENCE_decode_jer, + SEQUENCE_encode_jer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + SEQUENCE_decode_oer, + SEQUENCE_encode_oer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + SEQUENCE_decode_uper, + SEQUENCE_encode_uper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + SEQUENCE_decode_aper, + SEQUENCE_encode_aper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + SEQUENCE_random_fill, +#else + 0, +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + 0 /* Use generic outmost tag fetcher */ +}; + +void +SEQUENCE_free(const asn_TYPE_descriptor_t *td, void *sptr, + enum asn_struct_free_method method) { + size_t edx; + const asn_SEQUENCE_specifics_t *specs; + asn_struct_ctx_t *ctx; /* Decoder context */ + + if(!td || !sptr) + return; + + specs = (const asn_SEQUENCE_specifics_t *)td->specifics; + + ASN_DEBUG("Freeing %s as SEQUENCE", td->name); + + for(edx = 0; edx < td->elements_count; edx++) { + asn_TYPE_member_t *elm = &td->elements[edx]; + void *memb_ptr; + if(elm->flags & ATF_POINTER) { + memb_ptr = *(void **)((char *)sptr + elm->memb_offset); + if(memb_ptr) + ASN_STRUCT_FREE(*elm->type, memb_ptr); + } else { + memb_ptr = (void *)((char *)sptr + elm->memb_offset); + ASN_STRUCT_FREE_CONTENTS_ONLY(*elm->type, memb_ptr); + } + } + + /* Clean parsing context */ + ctx = (asn_struct_ctx_t *)((char *)sptr + specs->ctx_offset); + FREEMEM(ctx->ptr); + + switch(method) { + case ASFM_FREE_EVERYTHING: + FREEMEM(sptr); + break; + case ASFM_FREE_UNDERLYING: + break; + case ASFM_FREE_UNDERLYING_AND_RESET: + memset( + sptr, 0, + ((const asn_SEQUENCE_specifics_t *)(td->specifics))->struct_size); + break; + } +} + +int +SEQUENCE_constraint(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + size_t edx; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + /* + * Iterate over structure members and check their validity. + */ + for(edx = 0; edx < td->elements_count; edx++) { + asn_TYPE_member_t *elm = &td->elements[edx]; + const void *memb_ptr; + asn_constr_check_f *constr; + int ret; + + if(elm->flags & ATF_POINTER) { + memb_ptr = *(const void * const *)((const char *)sptr + elm->memb_offset); + if(!memb_ptr) { + if(elm->optional) + continue; + ASN__CTFAIL(app_key, td, sptr, + "%s: mandatory element %s absent (%s:%d)", + td->name, elm->name, __FILE__, __LINE__); + return -1; + } + } else { + memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); + } + + constr = elm->encoding_constraints.general_constraints; + if(!constr) + constr = elm->type->encoding_constraints.general_constraints; + + ret = constr(elm->type, memb_ptr, ctfailcb, app_key); + if(ret) return ret; + } + + return 0; +} + +int +SEQUENCE_compare(const asn_TYPE_descriptor_t *td, const void *aptr, + const void *bptr) { + size_t edx; + + for(edx = 0; edx < td->elements_count; edx++) { + asn_TYPE_member_t *elm = &td->elements[edx]; + const void *amemb; + const void *bmemb; + int ret; + + if(elm->flags & ATF_POINTER) { + amemb = + *(const void *const *)((const char *)aptr + elm->memb_offset); + bmemb = + *(const void *const *)((const char *)bptr + elm->memb_offset); + if(!amemb) { + if(!bmemb) continue; + if(elm->default_value_cmp + && elm->default_value_cmp(bmemb) == 0) { + /* A is absent, but B is present and equal to DEFAULT */ + continue; + } + return -1; + } else if(!bmemb) { + if(elm->default_value_cmp + && elm->default_value_cmp(amemb) == 0) { + /* B is absent, but A is present and equal to DEFAULT */ + continue; + } + return 1; + } + } else { + amemb = (const void *)((const char *)aptr + elm->memb_offset); + bmemb = (const void *)((const char *)bptr + elm->memb_offset); + } + + ret = elm->type->op->compare_struct(elm->type, amemb, bmemb); + if(ret != 0) return ret; + } + + return 0; +} + +int +SEQUENCE_copy(const asn_TYPE_descriptor_t *td, void **aptr, + const void *bptr) { + if(!td) return -1; + + const asn_SEQUENCE_specifics_t *specs = + (const asn_SEQUENCE_specifics_t *)td->specifics; + size_t edx; + void *st = *aptr; /* Target structure */ + + if(!bptr) { + if(st) { + SEQUENCE_free(td, st, 0); + *aptr = 0; + } + return 0; + } + + /* + * Create the target structure if it is not present already. + */ + if(st == 0) { + st = *aptr = CALLOC(1, specs->struct_size); + if(st == 0) return -1; + } + + for(edx = 0; edx < td->elements_count; edx++) { + asn_TYPE_member_t *elm = &td->elements[edx]; + void *amemb; + void **amembp; + const void *bmemb; + int ret; + + if(elm->flags & ATF_POINTER) { + /* Member is a pointer to another structure */ + amembp = (void **)((char *)st + elm->memb_offset); + bmemb = *(const void* const*)((const char*)bptr + elm->memb_offset); + } else { + amemb = (char *)st + elm->memb_offset; + amembp = &amemb; + bmemb = (const void*)((const char*)bptr + elm->memb_offset); + } + + ret = elm->type->op->copy_struct(elm->type, amembp, bmemb); + if(ret != 0) return ret; + } + + return 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE.h new file mode 100644 index 000000000..a3f50d112 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE.h @@ -0,0 +1,97 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _CONSTR_SEQUENCE_H_ +#define _CONSTR_SEQUENCE_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct asn_SEQUENCE_specifics_s { + /* + * Target structure description. + */ + unsigned struct_size; /* Size of the target structure. */ + unsigned ctx_offset; /* Offset of the asn_struct_ctx_t member */ + + /* + * Tags to members mapping table (sorted). + */ + const asn_TYPE_tag2member_t *tag2el; + unsigned tag2el_count; + + /* + * Optional members of the extensions root (roms) or additions (aoms). + * Meaningful for PER. + */ + const int *oms; /* Optional MemberS */ + unsigned roms_count; /* Root optional members count */ + unsigned aoms_count; /* Additions optional members count */ + + /* + * Description of an extensions group. + * Root components are clustered at the beginning of the structure, + * whereas extensions are clustered at the end. -1 means not extensible. + */ + signed first_extension; /* First extension addition */ +} asn_SEQUENCE_specifics_t; + + +/* + * A set specialized functions dealing with the SEQUENCE type. + */ +asn_struct_free_f SEQUENCE_free; + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +asn_struct_print_f SEQUENCE_print; +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +asn_struct_compare_f SEQUENCE_compare; +asn_struct_copy_f SEQUENCE_copy; + +asn_constr_check_f SEQUENCE_constraint; + +#if !defined(ASN_DISABLE_BER_SUPPORT) +ber_type_decoder_f SEQUENCE_decode_ber; +der_type_encoder_f SEQUENCE_encode_der; +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +xer_type_decoder_f SEQUENCE_decode_xer; +xer_type_encoder_f SEQUENCE_encode_xer; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +jer_type_decoder_f SEQUENCE_decode_jer; +jer_type_encoder_f SEQUENCE_encode_jer; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_OER_SUPPORT) +oer_type_decoder_f SEQUENCE_decode_oer; +oer_type_encoder_f SEQUENCE_encode_oer; +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +per_type_decoder_f SEQUENCE_decode_uper; +per_type_encoder_f SEQUENCE_encode_uper; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +per_type_decoder_f SEQUENCE_decode_aper; +per_type_encoder_f SEQUENCE_encode_aper; +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#if !defined(ASN_DISABLE_RFILL_SUPPORT) +asn_random_fill_f SEQUENCE_random_fill; +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + +extern asn_TYPE_operation_t asn_OP_SEQUENCE; + +#ifdef __cplusplus +} +#endif + +#endif /* _CONSTR_SEQUENCE_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_OF.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_OF.c new file mode 100644 index 000000000..6ec388857 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_OF.c @@ -0,0 +1,95 @@ +/*- + * Copyright (c) 2003, 2004, 2006 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +asn_TYPE_operation_t asn_OP_SEQUENCE_OF = { + SEQUENCE_OF_free, +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + SEQUENCE_OF_print, +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + SEQUENCE_OF_compare, + SEQUENCE_OF_copy, +#if !defined(ASN_DISABLE_BER_SUPPORT) + SEQUENCE_OF_decode_ber, + SEQUENCE_OF_encode_der, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + SEQUENCE_OF_decode_xer, + SEQUENCE_OF_encode_xer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + SEQUENCE_OF_decode_jer, + SEQUENCE_OF_encode_jer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + SEQUENCE_OF_decode_oer, /* Same as SET OF decoder. */ + SEQUENCE_OF_encode_oer, /* Same as SET OF encoder */ +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + SEQUENCE_OF_decode_uper, /* Same as SET OF decoder */ + SEQUENCE_OF_encode_uper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + SEQUENCE_OF_decode_aper, + SEQUENCE_OF_encode_aper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + SEQUENCE_OF_random_fill, +#else + 0, +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + 0 /* Use generic outmost tag fetcher */ +}; + +int +SEQUENCE_OF_compare(const asn_TYPE_descriptor_t *td, const void *aptr, + const void *bptr) { + const asn_anonymous_sequence_ *a = _A_CSEQUENCE_FROM_VOID(aptr); + const asn_anonymous_sequence_ *b = _A_CSEQUENCE_FROM_VOID(bptr); + ssize_t idx; + + if(a && b) { + ssize_t common_length = (a->count < b->count ? a->count : b->count); + for(idx = 0; idx < common_length; idx++) { + int ret = td->elements->type->op->compare_struct( + td->elements->type, a->array[idx], b->array[idx]); + if(ret) return ret; + } + + if(idx < b->count) /* more elements in b */ + return -1; /* a is shorter, so put it first */ + if(idx < a->count) return 1; + + } else if(!a) { + return -1; + } else if(!b) { + return 1; + } + + return 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_OF.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_OF.h new file mode 100644 index 000000000..978ad8e2a --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_OF.h @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _CONSTR_SEQUENCE_OF_H_ +#define _CONSTR_SEQUENCE_OF_H_ + +#include +#include /* Implemented using SET OF */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * A set specialized functions dealing with the SEQUENCE OF type. + * Generally implemented using SET OF. + */ +#define SEQUENCE_OF_free SET_OF_free + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +#define SEQUENCE_OF_print SET_OF_print +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +asn_struct_compare_f SEQUENCE_OF_compare; +#define SEQUENCE_OF_copy SET_OF_copy + +#define SEQUENCE_OF_constraint SET_OF_constraint + +#if !defined(ASN_DISABLE_BER_SUPPORT) +#define SEQUENCE_OF_decode_ber SET_OF_decode_ber +der_type_encoder_f SEQUENCE_OF_encode_der; +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +#define SEQUENCE_OF_decode_xer SET_OF_decode_xer +xer_type_encoder_f SEQUENCE_OF_encode_xer; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +#define SEQUENCE_OF_decode_jer SET_OF_decode_jer +jer_type_encoder_f SEQUENCE_OF_encode_jer; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_OER_SUPPORT) +#define SEQUENCE_OF_decode_oer SET_OF_decode_oer +#define SEQUENCE_OF_encode_oer SET_OF_encode_oer +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +#define SEQUENCE_OF_decode_uper SET_OF_decode_uper +per_type_encoder_f SEQUENCE_OF_encode_uper; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +#define SEQUENCE_OF_decode_aper SET_OF_decode_aper +per_type_encoder_f SEQUENCE_OF_encode_aper; +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#if !defined(ASN_DISABLE_RFILL_SUPPORT) +#define SEQUENCE_OF_random_fill SET_OF_random_fill +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + +extern asn_TYPE_operation_t asn_OP_SEQUENCE_OF; + +#ifdef __cplusplus +} +#endif + +#endif /* _CONSTR_SET_OF_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_OF_aper.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_OF_aper.c new file mode 100644 index 000000000..ff3ae8bc1 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_OF_aper.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +asn_enc_rval_t +SEQUENCE_OF_encode_aper(const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, + const void *sptr, asn_per_outp_t *po) { + const asn_anonymous_sequence_ *list; + const asn_per_constraint_t *ct; + asn_enc_rval_t er = {0,0,0}; + asn_TYPE_member_t *elm = td->elements; + int seq; + + if(!sptr) ASN__ENCODE_FAILED; + list = _A_CSEQUENCE_FROM_VOID(sptr); + + er.encoded = 0; + + ASN_DEBUG("Encoding %s as SEQUENCE OF size (%d) using ALIGNED PER", td->name, list->count); + + if(constraints) ct = &constraints->size; + else if(td->encoding_constraints.per_constraints) + ct = &td->encoding_constraints.per_constraints->size; + else ct = 0; + + /* If extensible constraint, check if size is in root */ + if(ct) { + int not_in_root = (list->count < ct->lower_bound + || list->count > ct->upper_bound); + ASN_DEBUG("lb %lld ub %lld %s", + (long long int)ct->lower_bound, + (long long int)ct->upper_bound, + ct->flags & APC_EXTENSIBLE ? "ext" : "fix"); + if(ct->flags & APC_EXTENSIBLE) { + /* Declare whether size is in extension root */ + if(per_put_few_bits(po, not_in_root, 1)) + ASN__ENCODE_FAILED; + if(not_in_root) ct = 0; + } else if(not_in_root && ct->effective_bits >= 0) + ASN__ENCODE_FAILED; + } + + if(ct && ct->effective_bits >= 0) { + /* X.691, #19.5: No length determinant */ +/* + if(per_put_few_bits(po, list->count - ct->lower_bound, + ct->effective_bits)) + ASN__ENCODE_FAILED; +*/ + if (ct->lower_bound == ct->upper_bound && ct->upper_bound < 65536) { + /* No length determinant */ + } else if (aper_put_length(po, ct->lower_bound, ct->upper_bound, list->count - ct->lower_bound, 0) < 0) + ASN__ENCODE_FAILED; + } + + for(seq = -1; seq < list->count;) { + ssize_t mayEncode; + int need_eom = 0; + if(seq < 0) seq = 0; + if(ct && ct->effective_bits >= 0) { + mayEncode = list->count; + } else { + mayEncode = aper_put_length(po, -1, -1, list->count - seq, &need_eom); + if(mayEncode < 0) ASN__ENCODE_FAILED; + } + + while(mayEncode--) { + void *memb_ptr = list->array[seq++]; + if(!memb_ptr) ASN__ENCODE_FAILED; + er = elm->type->op->aper_encoder(elm->type, + elm->encoding_constraints.per_constraints, + memb_ptr, po); + if(er.encoded == -1) + ASN__ENCODE_FAILED; + } + + if(need_eom && (aper_put_length(po, -1, -1, 0, NULL) < 0)) + ASN__ENCODE_FAILED; /* End of Message length */ + } + + ASN__ENCODED_OK(er); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_OF_xer.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_OF_xer.c new file mode 100644 index 000000000..7bd323677 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_OF_xer.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +asn_enc_rval_t +SEQUENCE_OF_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}; + const asn_SET_OF_specifics_t *specs = (const asn_SET_OF_specifics_t *)td->specifics; + const asn_TYPE_member_t *elm = td->elements; + const asn_anonymous_sequence_ *list = _A_CSEQUENCE_FROM_VOID(sptr); + const char *mname = specs->as_XMLValueList + ? 0 + : ((*elm->name) ? elm->name : elm->type->xml_tag); + size_t mlen = mname ? strlen(mname) : 0; + int xcan = (flags & XER_F_CANONICAL); + int i; + + if(!sptr) ASN__ENCODE_FAILED; + + er.encoded = 0; + + for(i = 0; i < list->count; i++) { + asn_enc_rval_t tmper = {0,0,0}; + void *memb_ptr = list->array[i]; + if(!memb_ptr) continue; + + if(mname) { + if(!xcan) ASN__TEXT_INDENT(1, ilevel); + ASN__CALLBACK3("<", 1, mname, mlen, ">", 1); + } + + tmper = elm->type->op->xer_encoder(elm->type, memb_ptr, ilevel + 1, + flags, cb, app_key); + if(tmper.encoded == -1) return tmper; + er.encoded += tmper.encoded; + if(tmper.encoded == 0 && specs->as_XMLValueList) { + const char *name = elm->type->xml_tag; + size_t len = strlen(name); + if(!xcan) ASN__TEXT_INDENT(1, ilevel + 1); + ASN__CALLBACK3("<", 1, name, len, "/>", 2); + } + + if(mname) { + ASN__CALLBACK3("", 1); + } + } + + if(!xcan) ASN__TEXT_INDENT(1, ilevel - 1); + + ASN__ENCODED_OK(er); +cb_failed: + ASN__ENCODE_FAILED; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_aper.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_aper.c new file mode 100644 index 000000000..895b6daf3 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_aper.c @@ -0,0 +1,457 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include +#include + +/* + * Check whether we are inside the extensions group. + */ +#define IN_EXTENSION_GROUP(specs, memb_idx) \ + ((specs)->first_extension >= 0 \ + && (unsigned)(specs)->first_extension <= (memb_idx)) + +asn_dec_rval_t +SEQUENCE_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_SEQUENCE_specifics_t *specs = (const asn_SEQUENCE_specifics_t *)td->specifics; + void *st = *sptr; /* Target structure. */ + int extpresent; /* Extension additions are present */ + uint8_t *opres; /* Presence of optional root members */ + asn_per_data_t opmd; + asn_dec_rval_t rv; + size_t edx; + + (void)constraints; + + if(ASN__STACK_OVERFLOW_CHECK(opt_codec_ctx)) + ASN__DECODE_FAILED; + + if(!st) { + st = *sptr = CALLOC(1, specs->struct_size); + if(!st) ASN__DECODE_FAILED; + } + + ASN_DEBUG("Decoding %s as SEQUENCE (APER)", td->name); + + /* Handle extensions */ + if(specs->first_extension < 0) { + extpresent = 0; + } else { + extpresent = per_get_few_bits(pd, 1); + if(extpresent < 0) ASN__DECODE_STARVED; + } + + /* Prepare a place and read-in the presence bitmap */ + memset(&opmd, 0, sizeof(opmd)); + if(specs->roms_count) { + opres = (uint8_t *)MALLOC(((specs->roms_count + 7) >> 3) + 1); + if(!opres) ASN__DECODE_FAILED; + /* Get the presence map */ + if(per_get_many_bits(pd, opres, 0, specs->roms_count)) { + FREEMEM(opres); + ASN__DECODE_STARVED; + } + opmd.buffer = opres; + opmd.nbits = specs->roms_count; + ASN_DEBUG("Read in presence bitmap for %s of %d bits (%x..)", + td->name, specs->roms_count, *opres); + } else { + opres = 0; + } + + /* + * Get the sequence ROOT elements. + */ + for(edx = 0; edx < td->elements_count; edx++) { + asn_TYPE_member_t *elm = &td->elements[edx]; + void *memb_ptr; /* Pointer to the member */ + void **memb_ptr2; /* Pointer to that pointer */ +#if 0 + int padding; +#endif + + if(IN_EXTENSION_GROUP(specs, edx)) + continue; + + /* Fetch the pointer to this member */ + if(elm->flags & ATF_POINTER) { + memb_ptr2 = (void **)((char *)st + elm->memb_offset); + } else { + memb_ptr = (char *)st + elm->memb_offset; + memb_ptr2 = &memb_ptr; + } +#if 0 + /* Get Padding */ + padding = (8 - (pd->moved % 8)) % 8; + if(padding > 0) + ASN_DEBUG("For element %s,offset= %ld Padding bits = %d", td->name, pd->moved, padding); +#if 0 /* old way of removing padding */ + per_get_few_bits(pd, padding); +#else /* Experimental fix proposed by @mhanna123 */ + if(edx != (td->elements_count-1)) + per_get_few_bits(pd, padding); + else { + if(specs->roms_count && (padding > 0)) + ASN_DEBUG(">>>>> not skipping padding of %d bits for element:%ld out of %d", padding, edx, td->elements_count); + else + per_get_few_bits(pd, padding); + } +#endif /* dealing with padding */ +#endif + /* Deal with optionality */ + if(elm->optional) { + int present = per_get_few_bits(&opmd, 1); + ASN_DEBUG("Member %s->%s is optional, p=%d (%d->%d)", + td->name, elm->name, present, + (int)opmd.nboff, (int)opmd.nbits); + if(present == 0) { + /* This element is not present */ + if(elm->default_value_set) { + /* Fill-in DEFAULT */ + if(elm->default_value_set(memb_ptr2)) { + FREEMEM(opres); + ASN__DECODE_FAILED; + } + ASN_DEBUG("Filled-in default"); + } + /* The member is just not present */ + continue; + } + /* Fall through */ + } + + /* Fetch the member from the stream */ + ASN_DEBUG("Decoding member \"%s\" in %s", elm->name, td->name); + + if(elm->flags & ATF_OPEN_TYPE) { + if (OPEN_TYPE_aper_is_unknown_type(td, st, elm)) { + rv = OPEN_TYPE_aper_unknown_type_discard_bytes(pd); + FREEMEM(opres); + return rv; + } + rv = OPEN_TYPE_aper_get(opt_codec_ctx, td, st, elm, pd); + } else { + rv = elm->type->op->aper_decoder(opt_codec_ctx, elm->type, + elm->encoding_constraints.per_constraints, + memb_ptr2, pd); + } + if(rv.code != RC_OK) { + ASN_DEBUG("Failed decode %s in %s", + elm->name, td->name); + FREEMEM(opres); + return rv; + } + } + + /* Optionality map is not needed anymore */ + FREEMEM(opres); + + /* + * Deal with extensions. + */ + if(extpresent) { + ssize_t bmlength; + uint8_t *epres; /* Presence of extension members */ + asn_per_data_t epmd; + + bmlength = aper_get_nslength(pd); + if(bmlength < 0) ASN__DECODE_STARVED; + + ASN_DEBUG("Extensions %" ASN_PRI_SSIZE " present in %s", bmlength, td->name); + + epres = (uint8_t *)MALLOC((bmlength + 15) >> 3); + if(!epres) ASN__DECODE_STARVED; + + /* Get the extensions map */ + if(per_get_many_bits(pd, epres, 0, bmlength)) + ASN__DECODE_STARVED; + + memset(&epmd, 0, sizeof(epmd)); + epmd.buffer = epres; + epmd.nbits = bmlength; + ASN_DEBUG("Read in extensions bitmap for %s of %zd bits (%x..)", + td->name, bmlength, *epres); + + /* Deal with padding */ + if (aper_get_align(pd) < 0) + ASN__DECODE_STARVED; + + /* Go over extensions and read them in */ + for(edx = specs->first_extension; edx < td->elements_count; edx++) { + asn_TYPE_member_t *elm = &td->elements[edx]; + void *memb_ptr; /* Pointer to the member */ + void **memb_ptr2; /* Pointer to that pointer */ + int present; + + if(!IN_EXTENSION_GROUP(specs, edx)) { + ASN_DEBUG("%zu is not extension", edx); + continue; + } + + /* Fetch the pointer to this member */ + if(elm->flags & ATF_POINTER) { + memb_ptr2 = (void **)((char *)st + elm->memb_offset); + } else { + memb_ptr = (void *)((char *)st + elm->memb_offset); + memb_ptr2 = &memb_ptr; + } + + present = per_get_few_bits(&epmd, 1); + if(present <= 0) { + if(present < 0) break; /* No more extensions */ + continue; + } + + ASN_DEBUG("Decoding member %s in %s %p", elm->name, td->name, *memb_ptr2); + rv = aper_open_type_get(opt_codec_ctx, elm->type, + elm->encoding_constraints.per_constraints, + memb_ptr2, pd); + if(rv.code != RC_OK) { + FREEMEM(epres); + return rv; + } + } + + /* Skip over overflow extensions which aren't present + * in this system's version of the protocol */ + for(;;) { + ASN_DEBUG("Getting overflow extensions"); + switch(per_get_few_bits(&epmd, 1)) { + case -1: + break; + case 0: + continue; + default: + if(aper_open_type_skip(opt_codec_ctx, pd)) { + FREEMEM(epres); + ASN__DECODE_STARVED; + } + } + break; + } + + FREEMEM(epres); + } + + /* Fill DEFAULT members in extensions */ + for(edx = specs->roms_count; edx < specs->roms_count + + specs->aoms_count; edx++) { + asn_TYPE_member_t *elm = &td->elements[edx]; + void **memb_ptr2; /* Pointer to member pointer */ + + if(!elm->default_value_set) continue; + + /* Fetch the pointer to this member */ + if(elm->flags & ATF_POINTER) { + memb_ptr2 = (void **)((char *)st + elm->memb_offset); + if(*memb_ptr2) continue; + } else { + continue; /* Extensions are all optionals */ + } + + /* Set default value */ + if(elm->default_value_set(memb_ptr2)) { + ASN__DECODE_FAILED; + } + } + + rv.consumed = 0; + rv.code = RC_OK; + return rv; +} + +static int +SEQUENCE_handle_extensions_aper(const asn_TYPE_descriptor_t *td, + const void *sptr, + asn_per_outp_t *po1, asn_per_outp_t *po2) { + const asn_SEQUENCE_specifics_t *specs + = (const asn_SEQUENCE_specifics_t *)td->specifics; + int exts_present = 0; + int exts_count = 0; + size_t edx; + + if(specs->first_extension < 0) { + return 0; + } + + /* Find out which extensions are present */ + for(edx = specs->first_extension; edx < td->elements_count; edx++) { + asn_TYPE_member_t *elm = &td->elements[edx]; + const void *memb_ptr; /* Pointer to the member */ + const void * const *memb_ptr2; /* Pointer to that pointer */ + int present; + + if(!IN_EXTENSION_GROUP(specs, edx)) { + ASN_DEBUG("%s (@%zu) is not extension", elm->type->name, edx); + continue; + } + + /* Fetch the pointer to this member */ + if(elm->flags & ATF_POINTER) { + memb_ptr2 = (const void * const *)((const char *)sptr + elm->memb_offset); + present = (*memb_ptr2 != 0); + } else { + memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); + memb_ptr2 = &memb_ptr; + present = 1; + } + + ASN_DEBUG("checking %s (@%zu) present => %d", + elm->type->name, edx, present); + exts_count++; + exts_present += present; + + /* Encode as presence marker */ + if(po1 && per_put_few_bits(po1, present, 1)) + return -1; + /* Encode as open type field */ + if(po2 && present && aper_open_type_put(elm->type, + elm->encoding_constraints.per_constraints, + *memb_ptr2, po2)) + return -1; + + } + + return exts_present ? exts_count : 0; +} + +asn_enc_rval_t +SEQUENCE_encode_aper(const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, + const void *sptr, asn_per_outp_t *po) { + const asn_SEQUENCE_specifics_t *specs + = (const asn_SEQUENCE_specifics_t *)td->specifics; + asn_enc_rval_t er = {0,0,0}; + int n_extensions; + size_t edx; + size_t i; + + (void)constraints; + + if(!sptr) + ASN__ENCODE_FAILED; + + er.encoded = 0; + + ASN_DEBUG("Encoding %s as SEQUENCE (APER)", td->name); + + /* + * X.691#18.1 Whether structure is extensible + * and whether to encode extensions + */ + if(specs->first_extension < 0) { + n_extensions = 0; /* There are no extensions to encode */ + } else { + n_extensions = SEQUENCE_handle_extensions_aper(td, sptr, 0, 0); + if(n_extensions < 0) ASN__ENCODE_FAILED; + if(per_put_few_bits(po, n_extensions ? 1 : 0, 1)) { + ASN__ENCODE_FAILED; + } + } + + /* Encode a presence bitmap */ + for(i = 0; i < specs->roms_count; i++) { + asn_TYPE_member_t *elm; + const void *memb_ptr; /* Pointer to the member */ + const void * const *memb_ptr2; /* Pointer to that pointer */ + int present; + + edx = specs->oms[i]; + elm = &td->elements[edx]; + + /* Fetch the pointer to this member */ + if(elm->flags & ATF_POINTER) { + memb_ptr2 = (const void * const *)((const char *)sptr + elm->memb_offset); + present = (*memb_ptr2 != 0); + } else { + memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); + memb_ptr2 = &memb_ptr; + present = 1; + } + + /* Eliminate default values */ + if(present && elm->default_value_cmp + && elm->default_value_cmp(*memb_ptr2) == 0) + present = 0; + + ASN_DEBUG("Element %s %s %s->%s is %s", + elm->flags & ATF_POINTER ? "ptr" : "inline", + elm->default_value_cmp ? "def" : "wtv", + td->name, elm->name, present ? "present" : "absent"); + if(per_put_few_bits(po, present, 1)) + ASN__ENCODE_FAILED; + } + + /* + * Encode the sequence ROOT elements. + */ + ASN_DEBUG("first_extension = %d, elements = %d", specs->first_extension, + td->elements_count); + for(edx = 0; + edx < ((specs->first_extension < 0) ? td->elements_count + : (size_t)specs->first_extension); + edx++) { + asn_TYPE_member_t *elm = &td->elements[edx]; + const void *memb_ptr; /* Pointer to the member */ + const void * const *memb_ptr2; /* Pointer to that pointer */ + + if(IN_EXTENSION_GROUP(specs, edx)) + continue; + + ASN_DEBUG("About to encode %s", elm->type->name); + + /* Fetch the pointer to this member */ + if(elm->flags & ATF_POINTER) { + memb_ptr2 = (const void * const *)((const char *)sptr + elm->memb_offset); + if(!*memb_ptr2) { + ASN_DEBUG("Element %s %zu not present", + elm->name, edx); + if(elm->optional) + continue; + /* Mandatory element is missing */ + ASN__ENCODE_FAILED; + } + } else { + memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); + memb_ptr2 = &memb_ptr; + } + + /* Eliminate default values */ + if(elm->default_value_cmp && elm->default_value_cmp(*memb_ptr2) == 0) + continue; + + ASN_DEBUG("Encoding %s->%s", td->name, elm->name); + er = elm->type->op->aper_encoder(elm->type, + elm->encoding_constraints.per_constraints, + *memb_ptr2, po); + if(er.encoded == -1) + return er; + } + + /* No extensions to encode */ + if(!n_extensions) ASN__ENCODED_OK(er); + + ASN_DEBUG("Length of %d bit-map", n_extensions); + /* #18.8. Write down the presence bit-map length. */ + if(aper_put_nslength(po, n_extensions)) + ASN__ENCODE_FAILED; + + ASN_DEBUG("Bit-map of %d elements", n_extensions); + /* #18.7. Encoding the extensions presence bit-map. */ + /* TODO: act upon NOTE in #18.7 for canonical PER */ + if(SEQUENCE_handle_extensions_aper(td, sptr, po, 0) != n_extensions) + ASN__ENCODE_FAILED; + + ASN_DEBUG("Writing %d extensions", n_extensions); + /* #18.9. Encode extensions as open type fields. */ + if(SEQUENCE_handle_extensions_aper(td, sptr, 0, po) != n_extensions) + ASN__ENCODE_FAILED; + + ASN__ENCODED_OK(er); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_print.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_print.c new file mode 100644 index 000000000..7f9e231a4 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_print.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +int +SEQUENCE_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, + asn_app_consume_bytes_f *cb, void *app_key) { + size_t edx; + int ret; + + if(!sptr) return (cb("", 8, app_key) < 0) ? -1 : 0; + + /* Dump preamble */ + if(cb(td->name, strlen(td->name), app_key) < 0 + || cb(" ::= {", 6, app_key) < 0) + return -1; + + for(edx = 0; edx < td->elements_count; edx++) { + asn_TYPE_member_t *elm = &td->elements[edx]; + const void *memb_ptr; + + if(elm->flags & ATF_POINTER) { + memb_ptr = *(const void * const *)((const char *)sptr + elm->memb_offset); + if(!memb_ptr) { + if(elm->optional) continue; + /* Print line */ + /* Fall through */ + } + } else { + memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); + } + + /* Indentation */ + _i_INDENT(1); + + /* Print the member's name and stuff */ + if(cb(elm->name, strlen(elm->name), app_key) < 0 + || cb(": ", 2, app_key) < 0) + return -1; + + /* Print the member itself */ + ret = elm->type->op->print_struct(elm->type, memb_ptr, ilevel + 1, + cb, app_key); + if(ret) return ret; + } + + ilevel--; + _i_INDENT(1); + + return (cb("}", 1, app_key) < 0) ? -1 : 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_rfill.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_rfill.c new file mode 100644 index 000000000..b464f5722 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_rfill.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_random_fill_result_t +SEQUENCE_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, + const asn_encoding_constraints_t *constr, + size_t max_length) { + const asn_SEQUENCE_specifics_t *specs = + (const asn_SEQUENCE_specifics_t *)td->specifics; + asn_random_fill_result_t result_ok = {ARFILL_OK, 0}; + asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0}; + asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0}; + void *st = *sptr; + size_t edx; + + if(max_length == 0) return result_skipped; + + (void)constr; + + if(st == NULL) { + st = CALLOC(1, specs->struct_size); + if(st == NULL) { + return result_failed; + } + } + + for(edx = 0; edx < td->elements_count; edx++) { + const asn_TYPE_member_t *elm = &td->elements[edx]; + void *memb_ptr; /* Pointer to the member */ + void **memb_ptr2; /* Pointer to that pointer */ + asn_random_fill_result_t tmpres; + + if(elm->optional && asn_random_between(0, 4) == 2) { + /* Sometimes decide not to fill the optional value */ + continue; + } + + if(elm->flags & ATF_POINTER) { + /* Member is a pointer to another structure */ + memb_ptr2 = (void **)((char *)st + elm->memb_offset); + } else { + memb_ptr = (char *)st + elm->memb_offset; + memb_ptr2 = &memb_ptr; + } + + tmpres = elm->type->op->random_fill( + elm->type, memb_ptr2, &elm->encoding_constraints, + max_length > result_ok.length ? max_length - result_ok.length : 0); + switch(tmpres.code) { + case ARFILL_OK: + result_ok.length += tmpres.length; + continue; + case ARFILL_SKIPPED: + assert(!(elm->flags & ATF_POINTER) || *memb_ptr2 == NULL); + continue; + case ARFILL_FAILED: + if(st == *sptr) { + ASN_STRUCT_RESET(*td, st); + } else { + ASN_STRUCT_FREE(*td, st); + } + return tmpres; + } + } + + *sptr = st; + + return result_ok; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_xer.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_xer.c new file mode 100644 index 000000000..c6475f78a --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SEQUENCE_xer.c @@ -0,0 +1,348 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +/* + * Return a standardized complex structure. + */ +#undef RETURN +#define RETURN(_code) \ + do { \ + rval.code = _code; \ + rval.consumed = consumed_myself; \ + return rval; \ + } while(0) + +/* + * Check whether we are inside the extensions group. + */ +#define IN_EXTENSION_GROUP(specs, memb_idx) \ + ((specs)->first_extension >= 0 \ + && (unsigned)(specs)->first_extension <= (memb_idx)) + +#undef XER_ADVANCE +#define XER_ADVANCE(num_bytes) \ + do { \ + size_t num = (num_bytes); \ + ptr = ((const char *)ptr) + num; \ + size -= num; \ + consumed_myself += num; \ + } while(0) + +/* + * Decode the XER (XML) data. + */ +asn_dec_rval_t +SEQUENCE_decode_xer(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **struct_ptr, + const char *opt_mname, const void *ptr, size_t size) { + /* + * Bring closer parts of structure description. + */ + const asn_SEQUENCE_specifics_t *specs + = (const asn_SEQUENCE_specifics_t *)td->specifics; + asn_TYPE_member_t *elements = td->elements; + const char *xml_tag = opt_mname ? opt_mname : td->xml_tag; + + /* + * ... and parts of the structure being constructed. + */ + void *st = *struct_ptr; /* Target structure. */ + asn_struct_ctx_t *ctx; /* Decoder context */ + + asn_dec_rval_t rval; /* Return value from a decoder */ + ssize_t consumed_myself = 0; /* Consumed bytes from ptr */ + size_t edx; /* Element index */ + + /* + * Create the target structure if it is not present already. + */ + if(st == 0) { + st = *struct_ptr = CALLOC(1, specs->struct_size); + if(st == 0) RETURN(RC_FAIL); + } + + /* + * Restore parsing context. + */ + ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset); + + + /* + * Phases of XER/XML processing: + * Phase 0: Check that the opening tag matches our expectations. + * Phase 1: Processing body and reacting on closing tag. + * Phase 2: Processing inner type. + * Phase 3: Skipping unknown extensions. + * Phase 4: PHASED OUT + */ + for(edx = ctx->step; ctx->phase <= 3;) { + pxer_chunk_type_e ch_type; /* XER chunk type */ + ssize_t ch_size; /* Chunk size */ + xer_check_tag_e tcv; /* Tag check value */ + asn_TYPE_member_t *elm; + + /* + * Go inside the inner member of a sequence. + */ + if(ctx->phase == 2) { + asn_dec_rval_t tmprval; + void *memb_ptr_dontuse; /* Pointer to the member */ + void **memb_ptr2; /* Pointer to that pointer */ + + elm = &td->elements[edx]; + + if(elm->flags & ATF_POINTER) { + /* Member is a pointer to another structure */ + memb_ptr2 = (void **)((char *)st + elm->memb_offset); + } else { + memb_ptr_dontuse = (char *)st + elm->memb_offset; + memb_ptr2 = &memb_ptr_dontuse; /* Only use of memb_ptr_dontuse */ + } + + if(elm->flags & ATF_OPEN_TYPE) { + tmprval = OPEN_TYPE_xer_get(opt_codec_ctx, td, st, elm, ptr, size); + } else { + /* Invoke the inner type decoder, m.b. multiple times */ + tmprval = elm->type->op->xer_decoder(opt_codec_ctx, + elm->type, memb_ptr2, elm->name, + ptr, size); + } + XER_ADVANCE(tmprval.consumed); + if(tmprval.code != RC_OK) + RETURN(tmprval.code); + ctx->phase = 1; /* Back to body processing */ + ctx->step = ++edx; + ASN_DEBUG("XER/SEQUENCE phase => %d, step => %d", + ctx->phase, ctx->step); + /* Fall through */ + } + + /* + * Get the next part of the XML stream. + */ + ch_size = xer_next_token(&ctx->context, ptr, size, + &ch_type); + if(ch_size == -1) { + RETURN(RC_FAIL); + } else { + switch(ch_type) { + case PXER_WMORE: + RETURN(RC_WMORE); + case PXER_COMMENT: /* Got XML comment */ + case PXER_TEXT: /* Ignore free-standing text */ + XER_ADVANCE(ch_size); /* Skip silently */ + continue; + case PXER_TAG: + break; /* Check the rest down there */ + } + } + + tcv = xer_check_tag(ptr, ch_size, xml_tag); + ASN_DEBUG("XER/SEQUENCE: tcv = %d, ph=%d [%s]", + tcv, ctx->phase, xml_tag); + + /* Skip the extensions section */ + if(ctx->phase == 3) { + switch(xer_skip_unknown(tcv, &ctx->left)) { + case -1: + ctx->phase = 4; + RETURN(RC_FAIL); + case 0: + XER_ADVANCE(ch_size); + continue; + case 1: + XER_ADVANCE(ch_size); + ctx->phase = 1; + continue; + case 2: + ctx->phase = 1; + break; + } + } + + switch(tcv) { + case XCT_CLOSING: + if(ctx->phase == 0) break; + ctx->phase = 0; + /* Fall through */ + case XCT_BOTH: + if(ctx->phase == 0) { + if(edx >= td->elements_count || + /* Explicit OPTIONAL specs reaches the end */ + (edx + elements[edx].optional == td->elements_count) || + /* All extensions are optional */ + IN_EXTENSION_GROUP(specs, edx)) { + XER_ADVANCE(ch_size); + ctx->phase = 4; /* Phase out */ + RETURN(RC_OK); + } else { + ASN_DEBUG("Premature end of XER SEQUENCE"); + RETURN(RC_FAIL); + } + } + /* Fall through */ + case XCT_OPENING: + if(ctx->phase == 0) { + XER_ADVANCE(ch_size); + ctx->phase = 1; /* Processing body phase */ + continue; + } + /* Fall through */ + case XCT_UNKNOWN_OP: + case XCT_UNKNOWN_BO: + + ASN_DEBUG("XER/SEQUENCE: tcv=%d, ph=%d, edx=%" ASN_PRI_SIZE "", + tcv, ctx->phase, edx); + if(ctx->phase != 1) { + break; /* Really unexpected */ + } + + if(edx < td->elements_count) { + /* + * Search which member corresponds to this tag. + */ + size_t n; + size_t edx_end = edx + elements[edx].optional + 1; + if(edx_end > td->elements_count) + edx_end = td->elements_count; + for(n = edx; n < edx_end; n++) { + elm = &td->elements[n]; + tcv = xer_check_tag(ptr, ch_size, elm->name); + switch(tcv) { + case XCT_BOTH: + case XCT_OPENING: + /* + * Process this member. + */ + ctx->step = edx = n; + ctx->phase = 2; + break; + case XCT_UNKNOWN_OP: + case XCT_UNKNOWN_BO: + continue; + default: + n = edx_end; + break; /* Phase out */ + } + break; + } + if(n != edx_end) + continue; + } else { + ASN_DEBUG("Out of defined members: %" ASN_PRI_SIZE "/%u", + edx, td->elements_count); + } + + /* It is expected extension */ + if(IN_EXTENSION_GROUP(specs, + edx + (edx < td->elements_count + ? elements[edx].optional : 0))) { + ASN_DEBUG("Got anticipated extension at %" ASN_PRI_SIZE "", + edx); + /* + * Check for (XCT_BOTH or XCT_UNKNOWN_BO) + * By using a mask. Only record a pure + * tags. + */ + if(tcv & XCT_CLOSING) { + /* Found without body */ + } else { + ctx->left = 1; + ctx->phase = 3; /* Skip ...'s */ + } + XER_ADVANCE(ch_size); + continue; + } + + /* Fall through */ + default: + break; + } + + ASN_DEBUG("Unexpected XML tag in SEQUENCE [%c%c%c%c%c%c]", + size>0?((const char *)ptr)[0]:'.', + size>1?((const char *)ptr)[1]:'.', + size>2?((const char *)ptr)[2]:'.', + size>3?((const char *)ptr)[3]:'.', + size>4?((const char *)ptr)[4]:'.', + size>5?((const char *)ptr)[5]:'.'); + break; + } + + ctx->phase = 4; /* "Phase out" on hard failure */ + RETURN(RC_FAIL); +} + +asn_enc_rval_t +SEQUENCE_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}; + int xcan = (flags & XER_F_CANONICAL); + asn_TYPE_descriptor_t *tmp_def_val_td = 0; + void *tmp_def_val = 0; + size_t edx; + + if(!sptr) ASN__ENCODE_FAILED; + + er.encoded = 0; + + for(edx = 0; edx < td->elements_count; edx++) { + asn_enc_rval_t tmper = {0,0,0}; + asn_TYPE_member_t *elm = &td->elements[edx]; + const void *memb_ptr; + const char *mname = elm->name; + unsigned int mlen = strlen(mname); + + if(elm->flags & ATF_POINTER) { + memb_ptr = + *(const void *const *)((const char *)sptr + elm->memb_offset); + if(!memb_ptr) { + assert(tmp_def_val == 0); + if(elm->default_value_set) { + if(elm->default_value_set(&tmp_def_val)) { + ASN__ENCODE_FAILED; + } else { + memb_ptr = tmp_def_val; + tmp_def_val_td = elm->type; + } + } else if(elm->optional) { + continue; + } else { + /* Mandatory element is missing */ + ASN__ENCODE_FAILED; + } + } + } else { + memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); + } + + if(!xcan) ASN__TEXT_INDENT(1, ilevel); + ASN__CALLBACK3("<", 1, mname, mlen, ">", 1); + + /* Print the member itself */ + tmper = elm->type->op->xer_encoder(elm->type, memb_ptr, ilevel + 1, + flags, cb, app_key); + if(tmp_def_val) { + ASN_STRUCT_FREE(*tmp_def_val_td, tmp_def_val); + tmp_def_val = 0; + } + if(tmper.encoded == -1) return tmper; + er.encoded += tmper.encoded; + + ASN__CALLBACK3("", 1); + } + + if(!xcan) ASN__TEXT_INDENT(1, ilevel - 1); + + ASN__ENCODED_OK(er); +cb_failed: + if(tmp_def_val) ASN_STRUCT_FREE(*tmp_def_val_td, tmp_def_val); + ASN__ENCODE_FAILED; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF.c new file mode 100644 index 000000000..f5cc3bac9 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF.c @@ -0,0 +1,429 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_TYPE_operation_t asn_OP_SET_OF = { + SET_OF_free, +#if !defined(ASN_DISABLE_PRINT_SUPPORT) + SET_OF_print, +#else + 0, +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + SET_OF_compare, + SET_OF_copy, +#if !defined(ASN_DISABLE_BER_SUPPORT) + SET_OF_decode_ber, + SET_OF_encode_der, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_XER_SUPPORT) + SET_OF_decode_xer, + SET_OF_encode_xer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ +#if !defined(ASN_DISABLE_JER_SUPPORT) + SET_OF_decode_jer, + SET_OF_encode_jer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ +#if !defined(ASN_DISABLE_OER_SUPPORT) + SET_OF_decode_oer, + SET_OF_encode_oer, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + SET_OF_decode_uper, + SET_OF_encode_uper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + SET_OF_decode_aper, + SET_OF_encode_aper, +#else + 0, + 0, +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ +#if !defined(ASN_DISABLE_RFILL_SUPPORT) + SET_OF_random_fill, +#else + 0, +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + 0 /* Use generic outmost tag fetcher */ +}; + +/* Append bytes to the above structure */ +static int _el_addbytes(const void *buffer, size_t size, void *el_buf_ptr) { + struct _el_buffer *el_buf = (struct _el_buffer *)el_buf_ptr; + + if(el_buf->length + size > el_buf->allocated_size) { + size_t new_size = el_buf->allocated_size ? el_buf->allocated_size : 8; + void *p; + + do { + new_size <<= 2; + } while(el_buf->length + size > new_size); + + p = REALLOC(el_buf->buf, new_size); + if(p) { + el_buf->buf = p; + el_buf->allocated_size = new_size; + } else { + return -1; + } + } + + memcpy(el_buf->buf + el_buf->length, buffer, size); + + el_buf->length += size; + return 0; +} + +static void assert_unused_bits(const struct _el_buffer* p) { + if(p->length) { + assert((p->buf[p->length-1] & ~(0xff << p->bits_unused)) == 0); + } else { + assert(p->bits_unused == 0); + } +} + +static int _el_buf_cmp(const void *ap, const void *bp) { + const struct _el_buffer *a = (const struct _el_buffer *)ap; + const struct _el_buffer *b = (const struct _el_buffer *)bp; + size_t common_len; + int ret = 0; + + if(a->length < b->length) + common_len = a->length; + else + common_len = b->length; + + if (a->buf && b->buf) { + ret = memcmp(a->buf, b->buf, common_len); + } + if(ret == 0) { + if(a->length < b->length) + ret = -1; + else if(a->length > b->length) + ret = 1; + /* Ignore unused bits. */ + assert_unused_bits(a); + assert_unused_bits(b); + } + + return ret; +} + +void +SET_OF__encode_sorted_free(struct _el_buffer *el_buf, size_t count) { + size_t i; + + for(i = 0; i < count; i++) { + FREEMEM(el_buf[i].buf); + } + + FREEMEM(el_buf); +} + +struct _el_buffer * +SET_OF__encode_sorted(const asn_TYPE_member_t *elm, + const asn_anonymous_set_ *list, + enum SET_OF__encode_method method) { + struct _el_buffer *encoded_els; + int edx; + + encoded_els = + (struct _el_buffer *)CALLOC(list->count, sizeof(encoded_els[0])); + if(encoded_els == NULL) { + return NULL; + } + + /* + * Encode all members. + */ + for(edx = 0; edx < list->count; edx++) { + const void *memb_ptr = list->array[edx]; + struct _el_buffer *encoding_el = &encoded_els[edx]; + asn_enc_rval_t erval = {0,0,0}; + + if(!memb_ptr) break; + + /* + * Encode the member into the prepared space. + */ + switch(method) { +#if !defined(ASN_DISABLE_BER_SUPPORT) + case SOES_DER: + erval = elm->type->op->der_encoder(elm->type, memb_ptr, 0, elm->tag, + _el_addbytes, encoding_el); + break; +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) + case SOES_CUPER: + erval = uper_encode(elm->type, + elm->encoding_constraints.per_constraints, + memb_ptr, _el_addbytes, encoding_el); + if(erval.encoded != -1) { + size_t extra_bits = erval.encoded % 8; + assert(encoding_el->length == (size_t)(erval.encoded + 7) / 8); + encoding_el->bits_unused = (8 - extra_bits) & 0x7; + } + break; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) + case SOES_CAPER: + erval = aper_encode(elm->type, + elm->encoding_constraints.per_constraints, + memb_ptr, _el_addbytes, encoding_el); + if(erval.encoded != -1) { + size_t extra_bits = erval.encoded % 8; + assert(encoding_el->length == (size_t)(erval.encoded + 7) / 8); + encoding_el->bits_unused = (8 - extra_bits) & 0x7; + } + break; +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + + default: + assert(!"Unreachable"); + break; + } + if(erval.encoded < 0) break; + } + + if(edx == list->count) { + /* + * Sort the encoded elements according to their encoding. + */ + qsort(encoded_els, list->count, sizeof(encoded_els[0]), _el_buf_cmp); + + return encoded_els; + } else { + SET_OF__encode_sorted_free(encoded_els, edx); + return NULL; + } +} + +void +SET_OF_free(const asn_TYPE_descriptor_t *td, void *ptr, + enum asn_struct_free_method method) { + if(td && ptr) { + const asn_SET_OF_specifics_t *specs; + asn_TYPE_member_t *elm = td->elements; + asn_anonymous_set_ *list = _A_SET_FROM_VOID(ptr); + asn_struct_ctx_t *ctx; /* Decoder context */ + int i; + + /* + * Could not use set_of_empty() because of (*free) + * incompatibility. + */ + for(i = 0; i < list->count; i++) { + void *memb_ptr = list->array[i]; + if(memb_ptr) + ASN_STRUCT_FREE(*elm->type, memb_ptr); + } + list->count = 0; /* No meaningful elements left */ + + asn_set_empty(list); /* Remove (list->array) */ + + specs = (const asn_SET_OF_specifics_t *)td->specifics; + ctx = (asn_struct_ctx_t *)((char *)ptr + specs->ctx_offset); + if(ctx->ptr) { + ASN_STRUCT_FREE(*elm->type, ctx->ptr); + ctx->ptr = 0; + } + + switch(method) { + case ASFM_FREE_EVERYTHING: + FREEMEM(ptr); + break; + case ASFM_FREE_UNDERLYING: + break; + case ASFM_FREE_UNDERLYING_AND_RESET: + memset(ptr, 0, specs->struct_size); + break; + } + } +} + +int +SET_OF_constraint(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + const asn_TYPE_member_t *elm = td->elements; + asn_constr_check_f *constr; + const asn_anonymous_set_ *list = _A_CSET_FROM_VOID(sptr); + int i; + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + constr = elm->encoding_constraints.general_constraints; + if(!constr) constr = elm->type->encoding_constraints.general_constraints; + + /* + * Iterate over the members of an array. + * Validate each in turn, until one fails. + */ + for(i = 0; i < list->count; i++) { + const void *memb_ptr = list->array[i]; + int ret; + + if(!memb_ptr) continue; + + ret = constr(elm->type, memb_ptr, ctfailcb, app_key); + if(ret) return ret; + } + + return 0; +} + +struct comparable_ptr { + const asn_TYPE_descriptor_t *td; + const void *sptr; +}; + +static int +SET_OF__compare_cb(const void *aptr, const void *bptr) { + const struct comparable_ptr *a = aptr; + const struct comparable_ptr *b = bptr; + assert(a->td == b->td); + return a->td->op->compare_struct(a->td, a->sptr, b->sptr); +} + +int +SET_OF_compare(const asn_TYPE_descriptor_t *td, const void *aptr, + const void *bptr) { + const asn_anonymous_set_ *a = _A_CSET_FROM_VOID(aptr); + const asn_anonymous_set_ *b = _A_CSET_FROM_VOID(bptr); + + if(a && b) { + struct comparable_ptr *asorted; + struct comparable_ptr *bsorted; + ssize_t common_length; + ssize_t idx; + + if(a->count == 0) { + if(b->count) return -1; + return 0; + } else if(b->count == 0) { + return 1; + } + + asorted = MALLOC(a->count * sizeof(asorted[0])); + bsorted = MALLOC(b->count * sizeof(bsorted[0])); + if(!asorted || !bsorted) { + FREEMEM(asorted); + FREEMEM(bsorted); + return -1; + } + + for(idx = 0; idx < a->count; idx++) { + asorted[idx].td = td->elements->type; + asorted[idx].sptr = a->array[idx]; + } + + for(idx = 0; idx < b->count; idx++) { + bsorted[idx].td = td->elements->type; + bsorted[idx].sptr = b->array[idx]; + } + + qsort(asorted, a->count, sizeof(asorted[0]), SET_OF__compare_cb); + qsort(bsorted, b->count, sizeof(bsorted[0]), SET_OF__compare_cb); + + common_length = (a->count < b->count ? a->count : b->count); + for(idx = 0; idx < common_length; idx++) { + int ret = td->elements->type->op->compare_struct( + td->elements->type, asorted[idx].sptr, bsorted[idx].sptr); + if(ret) { + FREEMEM(asorted); + FREEMEM(bsorted); + return ret; + } + } + + FREEMEM(asorted); + FREEMEM(bsorted); + + if(idx < b->count) /* more elements in b */ + return -1; /* a is shorter, so put it first */ + if(idx < a->count) return 1; + } else if(!a) { + return -1; + } else if(!b) { + return 1; + } + + return 0; +} + +int +SET_OF_copy(const asn_TYPE_descriptor_t *td, void **aptr, + const void *bptr) { + if(!td) return -1; + + const asn_SET_OF_specifics_t *specs = + (const asn_SET_OF_specifics_t *)td->specifics; + void *st = *aptr; + + if(!bptr) { + if(*aptr) { + asn_set_empty(_A_SET_FROM_VOID(*aptr)); + *aptr = 0; + } + return 0; + } + + if(st == 0) { + st = *aptr = CALLOC(1, specs->struct_size); + if(st == 0) return -1; + } + + asn_anonymous_set_ *a = _A_SET_FROM_VOID(*aptr); + const asn_anonymous_set_ *b = _A_CSET_FROM_VOID(bptr); + + if(b->size) { + void *_new_arr; + _new_arr = REALLOC(a->array, b->size * sizeof(b->array[0])); + if(_new_arr) { + a->array = (void **)_new_arr; + a->size = b->size; + } else { + return -1; + } + a->count = b->count; + + for(int i = 0; i < b->count; i++) { + void *bmemb = b->array[i]; + if(bmemb) { + void *amemb = 0; + int ret; + ret = td->elements->type->op->copy_struct( + td->elements->type, + &amemb, bmemb); + if(ret != 0) return ret; + a->array[i] = amemb; + } else { + a->array[i] = 0; + } + } + } + + return 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF.h new file mode 100644 index 000000000..82ead586b --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF.h @@ -0,0 +1,104 @@ +/*- + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef CONSTR_SET_OF_H +#define CONSTR_SET_OF_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct asn_SET_OF_specifics_s { + /* + * Target structure description. + */ + unsigned struct_size; /* Size of the target structure. */ + unsigned ctx_offset; /* Offset of the asn_struct_ctx_t member */ + + /* XER-specific stuff */ + int as_XMLValueList; /* The member type must be encoded like this */ +} asn_SET_OF_specifics_t; + +/* + * A set specialized functions dealing with the SET OF type. + */ +asn_struct_free_f SET_OF_free; + +#if !defined(ASN_DISABLE_PRINT_SUPPORT) +asn_struct_print_f SET_OF_print; +#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ + +asn_struct_compare_f SET_OF_compare; +asn_struct_copy_f SET_OF_copy; + +asn_constr_check_f SET_OF_constraint; + +#if !defined(ASN_DISABLE_BER_SUPPORT) +ber_type_decoder_f SET_OF_decode_ber; +der_type_encoder_f SET_OF_encode_der; +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +xer_type_decoder_f SET_OF_decode_xer; +xer_type_encoder_f SET_OF_encode_xer; +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +jer_type_decoder_f SET_OF_decode_jer; +jer_type_encoder_f SET_OF_encode_jer; +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_OER_SUPPORT) +oer_type_decoder_f SET_OF_decode_oer; +oer_type_encoder_f SET_OF_encode_oer; +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) +per_type_decoder_f SET_OF_decode_uper; +per_type_encoder_f SET_OF_encode_uper; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ +#if !defined(ASN_DISABLE_APER_SUPPORT) +per_type_decoder_f SET_OF_decode_aper; +per_type_encoder_f SET_OF_encode_aper; +#endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ + +#if !defined(ASN_DISABLE_RFILL_SUPPORT) +asn_random_fill_f SET_OF_random_fill; +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + +extern asn_TYPE_operation_t asn_OP_SET_OF; + +/* + * Internally visible buffer holding a single encoded element. + */ +struct _el_buffer { + uint8_t *buf; + size_t length; + size_t allocated_size; + unsigned bits_unused; +}; + +enum SET_OF__encode_method { + SOES_DER, /* Distinguished Encoding Rules */ + SOES_CUPER, /* Canonical Unaligned Packed Encoding Rules */ + SOES_CAPER /* Canonical Aligned Packed Encoding Rules */ +}; + +struct _el_buffer * SET_OF__encode_sorted( + const asn_TYPE_member_t *elm, + const asn_anonymous_set_ *list, + enum SET_OF__encode_method method); + +void SET_OF__encode_sorted_free( + struct _el_buffer *el_buf, + size_t count); + +#ifdef __cplusplus +} +#endif + +#endif /* CONSTR_SET_OF_H */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF_aper.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF_aper.c new file mode 100644 index 000000000..f959b1735 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF_aper.c @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_enc_rval_t +SET_OF_encode_aper(const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, const void *sptr, + asn_per_outp_t *po) { + const asn_anonymous_set_ *list; + const asn_per_constraint_t *ct; + const asn_TYPE_member_t *elm = td->elements; + struct _el_buffer *encoded_els; + asn_enc_rval_t er = {0,0,0}; + int seq; + + if(!sptr) ASN__ENCODE_FAILED; + + list = _A_CSET_FROM_VOID(sptr); + + er.encoded = 0; + + ASN_DEBUG("Encoding %s as SET OF (%d)", td->name, list->count); + + if(constraints) ct = &constraints->size; + else if(td->encoding_constraints.per_constraints) + ct = &td->encoding_constraints.per_constraints->size; + else ct = 0; + + /* If extensible constraint, check if size is in root */ + if(ct) { + int not_in_root = + (list->count < ct->lower_bound || list->count > ct->upper_bound); + ASN_DEBUG("lb %lld ub %lld %s", + (long long int)ct->lower_bound, + (long long int)ct->upper_bound, + ct->flags & APC_EXTENSIBLE ? "ext" : "fix"); + if(ct->flags & APC_EXTENSIBLE) { + /* Declare whether size is in extension root */ + if(per_put_few_bits(po, not_in_root, 1)) ASN__ENCODE_FAILED; + if(not_in_root) ct = 0; + } else if(not_in_root && ct->effective_bits >= 0) { + ASN__ENCODE_FAILED; + } + + } + + if(ct && ct->effective_bits >= 0) { + /* X.691, #19.5: No length determinant */ + /*if(per_put_few_bits(po, list->count - ct->lower_bound, + ct->effective_bits)) + ASN__ENCODE_FAILED;*/ + + if (aper_put_length(po, ct->lower_bound, ct->upper_bound, list->count - ct->lower_bound, 0) < 0) { + ASN__ENCODE_FAILED; + } + } + + /* + * Canonical PER #22.1 mandates dynamic sorting of the SET OF elements + * according to their encodings. Build an array of the encoded elements. + */ + encoded_els = SET_OF__encode_sorted(elm, list, SOES_CAPER); + + for(seq = 0; seq < list->count;) { + ssize_t may_encode; + int need_eom = 0; + if(ct && ct->effective_bits >= 0) { + may_encode = list->count; + } else { + may_encode = + aper_put_length(po, -1, -1, list->count - seq, &need_eom); + if(may_encode < 0) ASN__ENCODE_FAILED; + } + + while(may_encode--) { + const struct _el_buffer *el = &encoded_els[seq++]; + if(asn_put_many_bits(po, el->buf, + (8 * el->length) - el->bits_unused) < 0) { + break; + } + } + if(need_eom && (aper_put_length(po, -1, -1, 0, NULL) < 0)) + ASN__ENCODE_FAILED; /* End of Message length */ + } + + SET_OF__encode_sorted_free(encoded_els, list->count); + + ASN__ENCODED_OK(er); +} + +asn_dec_rval_t +SET_OF_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) { + asn_dec_rval_t rv = {RC_OK, 0}; + const asn_SET_OF_specifics_t *specs = (const asn_SET_OF_specifics_t *)td->specifics; + const asn_TYPE_member_t *elm = td->elements; /* Single one */ + void *st = *sptr; + asn_anonymous_set_ *list; + const asn_per_constraint_t *ct; + int repeat = 0; + ssize_t nelems; + + if(ASN__STACK_OVERFLOW_CHECK(opt_codec_ctx)) + ASN__DECODE_FAILED; + + /* + * Create the target structure if it is not present already. + */ + if(!st) { + st = *sptr = CALLOC(1, specs->struct_size); + if(!st) ASN__DECODE_FAILED; + } + list = _A_SET_FROM_VOID(st); + + /* Figure out which constraints to use */ + if(constraints) ct = &constraints->size; + else if(td->encoding_constraints.per_constraints) + ct = &td->encoding_constraints.per_constraints->size; + else ct = 0; + + if(ct && ct->flags & APC_EXTENSIBLE) { + int value = per_get_few_bits(pd, 1); + if(value < 0) ASN__DECODE_STARVED; + if(value) ct = 0; /* Not restricted! */ + } + + if(ct && ct->upper_bound >= 1 && ct->upper_bound <= 65535 + && ct->upper_bound == ct->lower_bound) { + /* X.691, #19.5: No length determinant */ + nelems = ct->upper_bound; + ASN_DEBUG("Preparing to fetch %ld elements from %s", + (long)nelems, td->name); + } else { + nelems = -1; + } + + do { + int i; + if(nelems < 0) { + if (ct) + nelems = aper_get_length(pd, ct->lower_bound, ct->upper_bound, + ct->effective_bits, &repeat); + else + nelems = aper_get_length(pd, -1, -1, -1, &repeat); + ASN_DEBUG("Got to decode %d elements (eff %d)", + (int)nelems, (int)(ct ? ct->effective_bits : -1)); + if(nelems < 0) ASN__DECODE_STARVED; + } + + for(i = 0; i < nelems; i++) { + void *ptr = 0; + ASN_DEBUG("SET OF %s decoding", elm->type->name); + rv = elm->type->op->aper_decoder(opt_codec_ctx, elm->type, + elm->encoding_constraints.per_constraints, &ptr, pd); + ASN_DEBUG("%s SET OF %s decoded %d, %p", + td->name, elm->type->name, rv.code, ptr); + if(rv.code == RC_OK) { + if(ASN_SET_ADD(list, ptr) == 0) + continue; + ASN_DEBUG("Failed to add element into %s", + td->name); + /* Fall through */ + rv.code = RC_FAIL; + } else { + ASN_DEBUG("Failed decoding %s of %s (SET OF)", + elm->type->name, td->name); + } + if(ptr) ASN_STRUCT_FREE(*elm->type, ptr); + return rv; + } + + nelems = -1; /* Allow uper_get_length() */ + } while(repeat); + + ASN_DEBUG("Decoded %s as SET OF", td->name); + + rv.code = RC_OK; + rv.consumed = 0; + return rv; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF_print.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF_print.c new file mode 100644 index 000000000..748dba767 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF_print.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +int +SET_OF_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, + asn_app_consume_bytes_f *cb, void *app_key) { + asn_TYPE_member_t *elm = td->elements; + const asn_anonymous_set_ *list = _A_CSET_FROM_VOID(sptr); + int ret; + int i; + + if(!sptr) return (cb("", 8, app_key) < 0) ? -1 : 0; + + /* Dump preamble */ + if(cb(td->name, strlen(td->name), app_key) < 0 + || cb(" ::= {", 6, app_key) < 0) + return -1; + + for(i = 0; i < list->count; i++) { + const void *memb_ptr = list->array[i]; + if(!memb_ptr) continue; + + _i_INDENT(1); + + ret = elm->type->op->print_struct(elm->type, memb_ptr, + ilevel + 1, cb, app_key); + if(ret) return ret; + } + + ilevel--; + _i_INDENT(1); + + return (cb("}", 1, app_key) < 0) ? -1 : 0; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF_rfill.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF_rfill.c new file mode 100644 index 000000000..9b2ac5ed2 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF_rfill.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_random_fill_result_t +SET_OF_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, + const asn_encoding_constraints_t *constraints, + size_t max_length) { + const asn_SET_OF_specifics_t *specs = + (const asn_SET_OF_specifics_t *)td->specifics; + asn_random_fill_result_t res_ok = {ARFILL_OK, 0}; + asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0}; + asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0}; + const asn_TYPE_member_t *elm = td->elements; + void *st = *sptr; + long max_elements = 5; + long slb = 0; /* Lower size bound */ + long sub = 0; /* Upper size bound */ + size_t rnd_len; + + if(max_length == 0) return result_skipped; + + if(st == NULL) { + st = (*sptr = CALLOC(1, specs->struct_size)); + if(st == NULL) { + return result_failed; + } + } + + switch(asn_random_between(0, 6)) { + case 0: max_elements = 0; break; + case 1: max_elements = 1; break; + case 2: max_elements = 5; break; + case 3: max_elements = max_length; break; + case 4: max_elements = max_length / 2; break; + case 5: max_elements = max_length / 4; break; + default: break; + } + sub = slb + max_elements; + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + 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_SEMI_CONSTRAINED) { + slb = pc->lower_bound; + sub = pc->lower_bound + max_elements; + } else if(pc->flags & APC_CONSTRAINED) { + slb = pc->lower_bound; + sub = pc->upper_bound; + if(sub - slb > max_elements) sub = slb + max_elements; + } + } +#else + if(!constraints) constraints = &td->encoding_constraints; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + + /* Bias towards edges of allowed space */ + switch(asn_random_between(-1, 4)) { + default: + case -1: +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + /* Prepare lengths somewhat outside of constrained range. */ + if(constraints->per_constraints + && (constraints->per_constraints->size.flags & APC_EXTENSIBLE)) { + switch(asn_random_between(0, 5)) { + default: + case 0: + rnd_len = 0; + break; + case 1: + if(slb > 0) { + rnd_len = slb - 1; + } else { + rnd_len = 0; + } + break; + case 2: + rnd_len = asn_random_between(0, slb); + break; + case 3: + if(sub < (ssize_t)max_length) { + rnd_len = sub + 1; + } else { + rnd_len = max_length; + } + break; + case 4: + if(sub < (ssize_t)max_length) { + rnd_len = asn_random_between(sub + 1, max_length); + } else { + rnd_len = max_length; + } + break; + case 5: + rnd_len = max_length; + break; + } + break; + } +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + /* Fall through */ + case 0: + rnd_len = asn_random_between(slb, sub); + break; + case 1: + if(slb < sub) { + rnd_len = asn_random_between(slb + 1, sub); + break; + } + /* Fall through */ + case 2: + rnd_len = asn_random_between(slb, slb); + break; + case 3: + if(slb < sub) { + rnd_len = asn_random_between(slb, sub - 1); + break; + } + /* Fall through */ + case 4: + rnd_len = asn_random_between(sub, sub); + break; + } + + for(; rnd_len > 0; rnd_len--) { + asn_anonymous_set_ *list = _A_SET_FROM_VOID(st); + void *ptr = 0; + asn_random_fill_result_t tmpres = elm->type->op->random_fill( + elm->type, &ptr, &elm->encoding_constraints, + (max_length > res_ok.length ? max_length - res_ok.length : 0) + / rnd_len); + switch(tmpres.code) { + case ARFILL_OK: + ASN_SET_ADD(list, ptr); + res_ok.length += tmpres.length; + break; + case ARFILL_SKIPPED: + break; + case ARFILL_FAILED: + assert(ptr == 0); + return tmpres; + } + } + + return res_ok; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF_xer.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF_xer.c new file mode 100644 index 000000000..1d97e5be3 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_SET_OF_xer.c @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* + * Return a standardized complex structure. + */ +#undef RETURN +#define RETURN(_code) \ + do { \ + rval.code = _code; \ + rval.consumed = consumed_myself; \ + return rval; \ + } while(0) + +#undef XER_ADVANCE +#define XER_ADVANCE(num_bytes) \ + do { \ + size_t num = num_bytes; \ + buf_ptr = ((const char *)buf_ptr) + num; \ + size -= num; \ + consumed_myself += num; \ + } while(0) + +/* + * Decode the XER (XML) data. + */ +asn_dec_rval_t +SET_OF_decode_xer(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **struct_ptr, + const char *opt_mname, const void *buf_ptr, size_t size) { + /* + * Bring closer parts of structure description. + */ + const asn_SET_OF_specifics_t *specs = (const asn_SET_OF_specifics_t *)td->specifics; + const asn_TYPE_member_t *element = td->elements; + const char *elm_tag; + const char *xml_tag = opt_mname ? opt_mname : td->xml_tag; + + /* + * ... and parts of the structure being constructed. + */ + void *st = *struct_ptr; /* Target structure. */ + asn_struct_ctx_t *ctx; /* Decoder context */ + + asn_dec_rval_t rval = {RC_OK, 0}; /* Return value from a decoder */ + ssize_t consumed_myself = 0; /* Consumed bytes from ptr */ + + /* + * Create the target structure if it is not present already. + */ + if(st == 0) { + st = *struct_ptr = CALLOC(1, specs->struct_size); + if(st == 0) RETURN(RC_FAIL); + } + + /* Which tag is expected for the downstream */ + if(specs->as_XMLValueList) { + elm_tag = (specs->as_XMLValueList == 1) ? 0 : ""; + } else { + elm_tag = (*element->name) + ? element->name : element->type->xml_tag; + } + + /* + * Restore parsing context. + */ + ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset); + + /* + * Phases of XER/XML processing: + * Phase 0: Check that the opening tag matches our expectations. + * Phase 1: Processing body and reacting on closing tag. + * Phase 2: Processing inner type. + */ + for(; ctx->phase <= 2;) { + pxer_chunk_type_e ch_type; /* XER chunk type */ + ssize_t ch_size; /* Chunk size */ + xer_check_tag_e tcv; /* Tag check value */ + + /* + * Go inside the inner member of a set. + */ + if(ctx->phase == 2) { + asn_dec_rval_t tmprval = {RC_OK, 0}; + + /* Invoke the inner type decoder, m.b. multiple times */ + ASN_DEBUG("XER/SET OF element [%s]", elm_tag); + tmprval = element->type->op->xer_decoder(opt_codec_ctx, + element->type, + &ctx->ptr, elm_tag, + buf_ptr, size); + if(tmprval.code == RC_OK) { + asn_anonymous_set_ *list = _A_SET_FROM_VOID(st); + if(ASN_SET_ADD(list, ctx->ptr) != 0) + RETURN(RC_FAIL); + ctx->ptr = 0; + XER_ADVANCE(tmprval.consumed); + } else { + XER_ADVANCE(tmprval.consumed); + RETURN(tmprval.code); + } + ctx->phase = 1; /* Back to body processing */ + ASN_DEBUG("XER/SET OF phase => %d", ctx->phase); + /* Fall through */ + } + + /* + * Get the next part of the XML stream. + */ + ch_size = xer_next_token(&ctx->context, + buf_ptr, size, &ch_type); + if(ch_size == -1) { + RETURN(RC_FAIL); + } else { + switch(ch_type) { + case PXER_WMORE: + RETURN(RC_WMORE); + case PXER_COMMENT: /* Got XML comment */ + case PXER_TEXT: /* Ignore free-standing text */ + XER_ADVANCE(ch_size); /* Skip silently */ + continue; + case PXER_TAG: + break; /* Check the rest down there */ + } + } + + tcv = xer_check_tag(buf_ptr, ch_size, xml_tag); + ASN_DEBUG("XER/SET OF: tcv = %d, ph=%d t=%s", + tcv, ctx->phase, xml_tag); + switch(tcv) { + case XCT_CLOSING: + if(ctx->phase == 0) break; + ctx->phase = 0; + /* Fall through */ + case XCT_BOTH: + if(ctx->phase == 0) { + /* No more things to decode */ + XER_ADVANCE(ch_size); + ctx->phase = 3; /* Phase out */ + RETURN(RC_OK); + } + /* Fall through */ + case XCT_OPENING: + if(ctx->phase == 0) { + XER_ADVANCE(ch_size); + ctx->phase = 1; /* Processing body phase */ + continue; + } + /* Fall through */ + case XCT_UNKNOWN_OP: + case XCT_UNKNOWN_BO: + + ASN_DEBUG("XER/SET OF: tcv=%d, ph=%d", tcv, ctx->phase); + if(ctx->phase == 1) { + /* + * Process a single possible member. + */ + ctx->phase = 2; + continue; + } + /* Fall through */ + default: + break; + } + + ASN_DEBUG("Unexpected XML tag in SET OF"); + break; + } + + ctx->phase = 3; /* "Phase out" on hard failure */ + RETURN(RC_FAIL); +} + +typedef struct xer_tmp_enc_s { + void *buffer; + size_t offset; + size_t size; +} xer_tmp_enc_t; + +static int +SET_OF_encode_xer_callback(const void *buffer, size_t size, void *key) { + xer_tmp_enc_t *t = (xer_tmp_enc_t *)key; + if(t->offset + size >= t->size) { + size_t newsize = (t->size << 2) + size; + void *p = REALLOC(t->buffer, newsize); + if(!p) return -1; + t->buffer = p; + t->size = newsize; + } + memcpy((char *)t->buffer + t->offset, buffer, size); + t->offset += size; + return 0; +} + +static int +SET_OF_xer_order(const void *aptr, const void *bptr) { + const xer_tmp_enc_t *a = (const xer_tmp_enc_t *)aptr; + const xer_tmp_enc_t *b = (const xer_tmp_enc_t *)bptr; + size_t minlen = a->offset; + int ret; + if(b->offset < minlen) minlen = b->offset; + /* Well-formed UTF-8 has this nice lexicographical property... */ + ret = memcmp(a->buffer, b->buffer, minlen); + if(ret != 0) return ret; + if(a->offset == b->offset) + return 0; + if(a->offset == minlen) + return -1; + return 1; +} + +asn_enc_rval_t +SET_OF_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}; + const asn_SET_OF_specifics_t *specs = (const asn_SET_OF_specifics_t *)td->specifics; + const asn_TYPE_member_t *elm = td->elements; + const asn_anonymous_set_ *list = _A_CSET_FROM_VOID(sptr); + const char *mname = specs->as_XMLValueList + ? 0 : ((*elm->name) ? elm->name : elm->type->xml_tag); + size_t mlen = mname ? strlen(mname) : 0; + int xcan = (flags & XER_F_CANONICAL); + xer_tmp_enc_t *encs = 0; + size_t encs_count = 0; + void *original_app_key = app_key; + asn_app_consume_bytes_f *original_cb = cb; + int i; + + if(!sptr) ASN__ENCODE_FAILED; + + if(xcan) { + encs = (xer_tmp_enc_t *)MALLOC(list->count * sizeof(encs[0])); + if(!encs) ASN__ENCODE_FAILED; + cb = SET_OF_encode_xer_callback; + } + + er.encoded = 0; + + for(i = 0; i < list->count; i++) { + asn_enc_rval_t tmper = {0,0,0}; + + void *memb_ptr = list->array[i]; + if(!memb_ptr) continue; + + if(encs) { + memset(&encs[encs_count], 0, sizeof(encs[0])); + app_key = &encs[encs_count]; + encs_count++; + } + + if(mname) { + if(!xcan) ASN__TEXT_INDENT(1, ilevel); + ASN__CALLBACK3("<", 1, mname, mlen, ">", 1); + } + + if(!xcan && specs->as_XMLValueList == 1) + ASN__TEXT_INDENT(1, ilevel + 1); + tmper = elm->type->op->xer_encoder(elm->type, memb_ptr, + ilevel + (specs->as_XMLValueList != 2), + flags, cb, app_key); + if(tmper.encoded == -1) return tmper; + er.encoded += tmper.encoded; + if(tmper.encoded == 0 && specs->as_XMLValueList) { + const char *name = elm->type->xml_tag; + size_t len = strlen(name); + ASN__CALLBACK3("<", 1, name, len, "/>", 2); + } + + if(mname) { + ASN__CALLBACK3("", 1); + } + + } + + if(!xcan) ASN__TEXT_INDENT(1, ilevel - 1); + + if(encs) { + xer_tmp_enc_t *enc = encs; + xer_tmp_enc_t *end = encs + encs_count; + ssize_t control_size = 0; + + er.encoded = 0; + cb = original_cb; + app_key = original_app_key; + qsort(encs, encs_count, sizeof(encs[0]), SET_OF_xer_order); + + for(; enc < end; enc++) { + ASN__CALLBACK(enc->buffer, enc->offset); + FREEMEM(enc->buffer); + enc->buffer = 0; + control_size += enc->offset; + } + assert(control_size == er.encoded); + } + + goto cleanup; +cb_failed: + ASN__ENCODE_FAILED; +cleanup: + if(encs) { + size_t n; + for(n = 0; n < encs_count; n++) { + FREEMEM(encs[n].buffer); + } + FREEMEM(encs); + } + ASN__ENCODED_OK(er); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_TYPE.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_TYPE.c new file mode 100644 index 000000000..5f0212b89 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_TYPE.c @@ -0,0 +1,100 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +/* + * Version of the ASN.1 infrastructure shipped with compiler. + */ +int get_asn1c_environment_version(void) { return ASN1C_ENVIRONMENT_VERSION; } + +static asn_app_consume_bytes_f _print2fp; + +/* + * Return the outmost tag of the type. + */ +ber_tlv_tag_t +asn_TYPE_outmost_tag(const asn_TYPE_descriptor_t *type_descriptor, + const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag) { + + if(tag_mode) + return tag; + + if(type_descriptor->tags_count) + return type_descriptor->tags[0]; + + return type_descriptor->op->outmost_tag(type_descriptor, struct_ptr, 0, 0); +} + +/* + * Print the target language's structure in human readable form. + */ +int +asn_fprint(FILE *stream, const asn_TYPE_descriptor_t *td, + const void *struct_ptr) { + if(!stream) stream = stdout; + if(!td || !struct_ptr) { + errno = EINVAL; + return -1; + } + + /* Invoke type-specific printer */ + if(td->op->print_struct(td, struct_ptr, 1, _print2fp, stream)) { + return -1; + } + + /* Terminate the output */ + if(_print2fp("\n", 1, stream)) { + return -1; + } + + return fflush(stream); +} + +/* + * Copy a structuture. + */ +int +asn_copy(const asn_TYPE_descriptor_t *td, + void **struct_dst, const void *struct_src) { + + if(!td || !struct_dst || !struct_src) { + errno = EINVAL; + return -1; + } + + if(!td->op) { + errno = ENOSYS; + return -1; + } + + return td->op->copy_struct(td, struct_dst, struct_src); +} + +/* Dump the data into the specified stdio stream */ +static int +_print2fp(const void *buffer, size_t size, void *app_key) { + FILE *stream = (FILE *)app_key; + + if(fwrite(buffer, 1, size, stream) != size) + return -1; + + return 0; +} + + +/* + * Some compilers do not support variable args macros. + * This function is a replacement of ASN_DEBUG() macro. + */ +void CC_PRINTFLIKE(1, 2) ASN_DEBUG_f(const char *fmt, ...); +void ASN_DEBUG_f(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + va_end(ap); +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_TYPE.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_TYPE.h new file mode 100644 index 000000000..b64d5b5ea --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constr_TYPE.h @@ -0,0 +1,320 @@ +/* + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +/* + * This file contains the declaration structure called "ASN.1 Type Definition", + * which holds all information necessary for encoding and decoding routines. + * This structure even contains pointer to these encoding and decoding routines + * for each defined ASN.1 type. + */ +#ifndef _CONSTR_TYPE_H_ +#define _CONSTR_TYPE_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ +struct asn_TYPE_member_s; /* Forward declaration */ + +/* + * This type provides the context information for various ASN.1 routines, + * primarily ones doing decoding. A member _asn_ctx of this type must be + * included into certain target language's structures, such as compound types. + */ +typedef struct asn_struct_ctx_s { + short phase; /* Decoding phase */ + short step; /* Elementary step of a phase */ + int context; /* Other context information */ + void *ptr; /* Decoder-specific stuff (stack elements) */ + ber_tlv_len_t left; /* Number of bytes left, -1 for indefinite */ +} asn_struct_ctx_t; + +#if !defined(ASN_DISABLE_BER_SUPPORT) +#include /* Basic Encoding Rules decoder */ +#include /* Distinguished Encoding Rules encoder */ +#else +typedef void (ber_type_decoder_f)(void); +typedef void (der_type_encoder_f)(void); +#endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ + +#if !defined(ASN_DISABLE_XER_SUPPORT) +#include /* Decoder of XER (XML, text) */ +#include /* Encoder into XER (XML, text) */ +#else +typedef void (xer_type_decoder_f)(void); +typedef void (xer_type_encoder_f)(void); +#endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ + +#if !defined(ASN_DISABLE_JER_SUPPORT) +#include /* Decoder of JER (JSON, text) */ +#include /* Encoder into JER (JSON, text) */ +#else +typedef void (jer_type_decoder_f)(void); +typedef void (jer_type_encoder_f)(void); +#endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +#include /* Packet Encoding Rules decoder */ +#include /* Packet Encoding Rules encoder */ +#else +typedef void (per_type_decoder_f)(void); +typedef void (per_type_encoder_f)(void); +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + +#include /* Subtype constraints support */ + +#if !defined(ASN_DISABLE_RFILL_SUPPORT) +#include /* Random structures support */ +#else +typedef void (asn_random_fill_f)(void); +#endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ + +#if !defined(ASN_DISABLE_OER_SUPPORT) +#include /* Octet Encoding Rules encoder */ +#include /* Octet Encoding Rules encoder */ +#else +typedef void (oer_type_decoder_f)(void); +typedef void (oer_type_encoder_f)(void); +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ + +/* + * Free the structure according to its specification. + * Use one of ASN_STRUCT_{FREE,RESET,CONTENTS_ONLY} macros instead. + * Do not use directly. + */ +enum asn_struct_free_method { + ASFM_FREE_EVERYTHING, /* free(struct_ptr) and underlying members */ + ASFM_FREE_UNDERLYING, /* free underlying members */ + ASFM_FREE_UNDERLYING_AND_RESET /* FREE_UNDERLYING + memset(0) */ +}; +typedef void (asn_struct_free_f)( + const struct asn_TYPE_descriptor_s *type_descriptor, + void *struct_ptr, enum asn_struct_free_method); + +/* + * Free the structure including freeing the memory pointed to by ptr itself. + */ +#define ASN_STRUCT_FREE(asn_DEF, ptr) \ + (asn_DEF).op->free_struct(&(asn_DEF), (ptr), ASFM_FREE_EVERYTHING) + +/* + * Free the memory used by the members of the structure without freeing the + * the structure pointer itself. + * ZERO-OUT the structure to the safe clean state. + * (Retaining the pointer may be useful in case the structure is allocated + * statically or arranged on the stack, yet its elements are dynamic.) + */ +#define ASN_STRUCT_RESET(asn_DEF, ptr) \ + (asn_DEF).op->free_struct(&(asn_DEF), (ptr), ASFM_FREE_UNDERLYING_AND_RESET) + +/* + * Free memory used by the members of the structure without freeing + * the structure pointer itself. + * (Retaining the pointer may be useful in case the structure is allocated + * statically or arranged on the stack, yet its elements are dynamic.) + * AVOID using it in the application code; + * Use a safer ASN_STRUCT_RESET() instead. + */ +#define ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF, ptr) \ + (asn_DEF).op->free_struct(&(asn_DEF), (ptr), ASFM_FREE_UNDERLYING) + +/* + * Print the structure according to its specification. + */ +typedef int(asn_struct_print_f)( + const struct asn_TYPE_descriptor_s *type_descriptor, + const void *struct_ptr, + int level, /* Indentation level */ + asn_app_consume_bytes_f *callback, void *app_key); + +/* + * Compare two structs between each other. + * Returns <0 if struct_A is "smaller" than struct_B, >0 if "greater", + * and =0 if "equal to", for some type-specific, stable definition of + * "smaller", "greater" and "equal to". + */ +typedef int (asn_struct_compare_f)( + const struct asn_TYPE_descriptor_s *type_descriptor, + const void *struct_A, + const void *struct_B); + +/* + * Copies struct B into struct A. + * Allocates memory for struct A, if necessary. + */ +typedef int (asn_struct_copy_f)( + const struct asn_TYPE_descriptor_s *type_descriptor, + void **struct_A, + const void *struct_B + ); + +/* + * Return the outmost tag of the type. + * If the type is untagged CHOICE, the dynamic operation is performed. + * NOTE: This function pointer type is only useful internally. + * Do not use it in your application. + */ +typedef ber_tlv_tag_t (asn_outmost_tag_f)( + const struct asn_TYPE_descriptor_s *type_descriptor, + const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag); +/* The instance of the above function type; used internally. */ +asn_outmost_tag_f asn_TYPE_outmost_tag; + +/* + * Fetch the desired type of the Open Type based on the + * Information Object Set driven constraints. + */ +typedef struct asn_type_selector_result_s { + const struct asn_TYPE_descriptor_s *type_descriptor; /* Type encoded. */ + unsigned presence_index; /* Associated choice variant. */ +} asn_type_selector_result_t; +typedef asn_type_selector_result_t(asn_type_selector_f)( + const struct asn_TYPE_descriptor_s *parent_type_descriptor, + const void *parent_structure_ptr); + +/* + * Generalized functions for dealing with the speciic type. + * May be directly invoked by applications. + */ +typedef struct asn_TYPE_operation_s { + asn_struct_free_f *free_struct; /* Free the structure */ + asn_struct_print_f *print_struct; /* Human readable output */ + asn_struct_compare_f *compare_struct; /* Compare two structures */ + asn_struct_copy_f *copy_struct; /* Copy method */ + ber_type_decoder_f *ber_decoder; /* Generic BER decoder */ + der_type_encoder_f *der_encoder; /* Canonical DER encoder */ + xer_type_decoder_f *xer_decoder; /* Generic XER decoder */ + xer_type_encoder_f *xer_encoder; /* [Canonical] XER encoder */ + jer_type_decoder_f *jer_decoder; /* Generic JER encoder */ + jer_type_encoder_f *jer_encoder; /* Generic JER encoder */ + oer_type_decoder_f *oer_decoder; /* Generic OER decoder */ + oer_type_encoder_f *oer_encoder; /* Canonical OER encoder */ + per_type_decoder_f *uper_decoder; /* Unaligned PER decoder */ + per_type_encoder_f *uper_encoder; /* Unaligned PER encoder */ + per_type_decoder_f *aper_decoder; /* Aligned PER decoder */ + per_type_encoder_f *aper_encoder; /* Aligned PER encoder */ + asn_random_fill_f *random_fill; /* Initialize with a random value */ + asn_outmost_tag_f *outmost_tag; /* */ +} asn_TYPE_operation_t; + +/* + * A constraints tuple specifying both the OER and PER constraints. + */ +typedef struct asn_encoding_constraints_s { +#if !defined(ASN_DISABLE_OER_SUPPORT) + const struct asn_oer_constraints_s *oer_constraints; +#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + const struct asn_per_constraints_s *per_constraints; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + asn_constr_check_f *general_constraints; +} asn_encoding_constraints_t; + +/* + * The definitive description of the destination language's structure. + */ +typedef struct asn_TYPE_descriptor_s { + const char *name; /* A name of the ASN.1 type. "" in some cases. */ + const char *xml_tag; /* Name used in XML tag */ + + /* + * Generalized functions for dealing with the specific type. + * May be directly invoked by applications. + */ + asn_TYPE_operation_t *op; + + /*********************************************************************** + * Internally useful members. Not to be used by applications directly. * + **********************************************************************/ + + /* + * Tags that are expected to occur. + */ + const ber_tlv_tag_t *tags; /* Effective tags sequence for this type */ + unsigned tags_count; /* Number of tags which are expected */ + const ber_tlv_tag_t *all_tags; /* Every tag for BER/containment */ + unsigned all_tags_count; /* Number of tags */ + + /* OER, PER, and general constraints */ + asn_encoding_constraints_t encoding_constraints; + + /* + * An ASN.1 production type members (members of SEQUENCE, SET, CHOICE). + */ + struct asn_TYPE_member_s *elements; + unsigned elements_count; + + /* + * Additional information describing the type, used by appropriate + * functions above. + */ + const void *specifics; +} asn_TYPE_descriptor_t; + +/* + * This type describes an element of the constructed type, + * i.e. SEQUENCE, SET, CHOICE, etc. + */ + enum asn_TYPE_flags_e { + ATF_NOFLAGS, + ATF_POINTER = 0x01, /* Represented by the pointer */ + ATF_OPEN_TYPE = 0x02, /* Open Type */ + ATF_ANY_TYPE = 0x04 /* ANY type (deprecated!) */ + }; +typedef struct asn_TYPE_member_s { + enum asn_TYPE_flags_e flags; /* Element's presentation flags */ + unsigned optional; /* Following optional members, including current */ + unsigned memb_offset; /* Offset of the element */ + ber_tlv_tag_t tag; /* Outmost (most immediate) tag */ + int tag_mode; /* IMPLICIT/no/EXPLICIT tag at current level */ + asn_TYPE_descriptor_t *type; /* Member type descriptor */ + asn_type_selector_f *type_selector; /* IoS runtime type selector */ + asn_encoding_constraints_t encoding_constraints; + int (*default_value_cmp)(const void *sptr); /* Compare DEFAULT */ + int (*default_value_set)(void **sptr); /* Set DEFAULT */ + const char *name; /* ASN.1 identifier of the element */ +} asn_TYPE_member_t; + +/* + * BER tag to element number mapping. + */ +typedef struct asn_TYPE_tag2member_s { + ber_tlv_tag_t el_tag; /* Outmost tag of the member */ + unsigned el_no; /* Index of the associated member, base 0 */ + int toff_first; /* First occurrence of the el_tag, relative */ + int toff_last; /* Last occurrence of the el_tag, relative */ +} asn_TYPE_tag2member_t; + +/* + * This function prints out the contents of the target language's structure + * (struct_ptr) into the file pointer (stream) in human readable form. + * RETURN VALUES: + * 0: The structure is printed. + * -1: Problem dumping the structure. + * (See also xer_fprint() in xer_encoder.h) + */ +int asn_fprint(FILE *stream, /* Destination stream descriptor */ + const asn_TYPE_descriptor_t *td, /* ASN.1 type descriptor */ + const void *struct_ptr); /* Structure to be printed */ + +/* + * Copies a source structure (struct_src) into destination structure + * (struct_dst). Allocates memory for the destination structure, if necessary. + * RETURN VALUES: + * 0: Copy OK. + * -1: Problem copying the structure. + */ +int asn_copy(const asn_TYPE_descriptor_t *td, /* ASN.1 type descriptor */ + void **struct_dst, /* Structure to be populated */ + const void *struct_src); /* Structure to be copied */ + +#ifdef __cplusplus +} +#endif + +#endif /* _CONSTR_TYPE_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constraints.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constraints.c new file mode 100644 index 000000000..72137cc5c --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constraints.c @@ -0,0 +1,94 @@ +#include +#include + +int +asn_generic_no_constraint(const asn_TYPE_descriptor_t *type_descriptor, + const void *struct_ptr, + asn_app_constraint_failed_f *cb, void *key) { + (void)type_descriptor; /* Unused argument */ + (void)struct_ptr; /* Unused argument */ + (void)cb; /* Unused argument */ + (void)key; /* Unused argument */ + + /* Nothing to check */ + return 0; +} + +int +asn_generic_unknown_constraint(const asn_TYPE_descriptor_t *type_descriptor, + const void *struct_ptr, + asn_app_constraint_failed_f *cb, void *key) { + (void)type_descriptor; /* Unused argument */ + (void)struct_ptr; /* Unused argument */ + (void)cb; /* Unused argument */ + (void)key; /* Unused argument */ + + /* Unknown how to check */ + return 0; +} + +struct errbufDesc { + const asn_TYPE_descriptor_t *failed_type; + const void *failed_struct_ptr; + char *errbuf; + size_t errlen; +}; + +static void +CC_PRINTFLIKE(4, 5) +_asn_i_ctfailcb(void *key, const asn_TYPE_descriptor_t *td, const void *sptr, + const char *fmt, ...) { + struct errbufDesc *arg = key; + va_list ap; + ssize_t vlen; + ssize_t maxlen; + + arg->failed_type = td; + arg->failed_struct_ptr = sptr; + + maxlen = arg->errlen; + if(maxlen <= 0) + return; + + va_start(ap, fmt); + vlen = vsnprintf(arg->errbuf, maxlen, fmt, ap); + va_end(ap); + if(vlen >= maxlen) { + arg->errbuf[maxlen-1] = '\0'; /* Ensuring libc correctness */ + arg->errlen = maxlen - 1; /* Not counting termination */ + return; + } else if(vlen >= 0) { + arg->errbuf[vlen] = '\0'; /* Ensuring libc correctness */ + arg->errlen = vlen; /* Not counting termination */ + } else { + /* + * The libc on this system is broken. + */ + vlen = sizeof("") - 1; + maxlen--; + arg->errlen = vlen < maxlen ? vlen : maxlen; + memcpy(arg->errbuf, "", arg->errlen); + arg->errbuf[arg->errlen] = 0; + } + + return; +} + +int +asn_check_constraints(const asn_TYPE_descriptor_t *type_descriptor, + const void *struct_ptr, char *errbuf, size_t *errlen) { + struct errbufDesc arg; + int ret; + + arg.failed_type = 0; + arg.failed_struct_ptr = 0; + arg.errbuf = errbuf; + arg.errlen = errlen ? *errlen : 0; + + ret = type_descriptor->encoding_constraints.general_constraints( + type_descriptor, struct_ptr, _asn_i_ctfailcb, &arg); + if(ret == -1 && errlen) *errlen = arg.errlen; + + return ret; +} + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constraints.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constraints.h new file mode 100644 index 000000000..0c093fa82 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/constraints.h @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2004-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN1_CONSTRAINTS_VALIDATOR_H +#define ASN1_CONSTRAINTS_VALIDATOR_H + +#include /* Platform-dependent types */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* + * Validate the structure according to the ASN.1 constraints. + * If errbuf and errlen are given, they shall be pointing to the appropriate + * buffer space and its length before calling this function. Alternatively, + * they could be passed as NULL's. If constraints validation fails, + * errlen will contain the actual number of bytes taken from the errbuf + * to encode an error message (properly 0-terminated). + * + * RETURN VALUES: + * This function returns 0 in case all ASN.1 constraints are met + * and -1 if one or more constraints were failed. + */ +int asn_check_constraints( + const struct asn_TYPE_descriptor_s *type_descriptor, + const void *struct_ptr, /* Target language's structure */ + char *errbuf, /* Returned error description */ + size_t *errlen /* Length of the error description */ +); + + +/* + * Generic type for constraint checking callback, + * associated with every type descriptor. + */ +typedef int(asn_constr_check_f)( + const struct asn_TYPE_descriptor_s *type_descriptor, const void *struct_ptr, + asn_app_constraint_failed_f *optional_callback, /* Log the error */ + void *optional_app_key /* Opaque key passed to a callback */ +); + +/******************************* + * INTERNALLY USEFUL FUNCTIONS * + *******************************/ + +asn_constr_check_f asn_generic_no_constraint; /* No constraint whatsoever */ +asn_constr_check_f asn_generic_unknown_constraint; /* Not fully supported */ + +/* + * Invoke the callback with a complete error message. + */ +#define ASN__CTFAIL if(ctfailcb) ctfailcb + +#ifdef __cplusplus +} +#endif + +#endif /* ASN1_CONSTRAINTS_VALIDATOR_H */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_decoder.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_decoder.c new file mode 100644 index 000000000..42b92cacd --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_decoder.c @@ -0,0 +1,5 @@ +#include +#include +#include + +// Absolutely nothing diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_decoder.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_decoder.h new file mode 100644 index 000000000..3cc0c6bf7 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_decoder.h @@ -0,0 +1,30 @@ +/*- + * Copyright (c) 2005-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _PER_DECODER_H_ +#define _PER_DECODER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* + * Type of the type-specific PER decoder function. + */ +typedef asn_dec_rval_t(per_type_decoder_f)( + const asn_codec_ctx_t *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *type_descriptor, + const asn_per_constraints_t *constraints, void **struct_ptr, + asn_per_data_t *per_data); + +#ifdef __cplusplus +} +#endif + +#endif /* _PER_DECODER_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_encoder.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_encoder.c new file mode 100644 index 000000000..01ab70b06 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_encoder.c @@ -0,0 +1,35 @@ +#include +#include + +int +ignore_output(const void *data, size_t size, void *app_key) { + (void)data; + (void)size; + (void)app_key; + return 0; +} + +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; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_encoder.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_encoder.h new file mode 100644 index 000000000..8bb077170 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_encoder.h @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 2006-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _PER_ENCODER_H_ +#define _PER_ENCODER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* + * Type of the generic PER encoder function. + */ +typedef asn_enc_rval_t(per_type_encoder_f)( + const struct asn_TYPE_descriptor_s *type_descriptor, + const asn_per_constraints_t *constraints, const void *struct_ptr, + asn_per_outp_t *per_output); + +int ignore_output(const void *data, size_t size, void *app_key); + +typedef struct enc_dyn_arg { + void *buffer; + size_t length; + size_t allocated; +} enc_dyn_arg; +int encode_dyn_cb(const void *buffer, size_t size, void *key); + +#ifdef __cplusplus +} +#endif + +#endif /* _PER_ENCODER_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_opentype.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_opentype.c new file mode 100644 index 000000000..5620c5bb9 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_opentype.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2007 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include + +/* + * Internal functions. + */ + +asn_dec_rval_t +uper_sot_suck(const asn_codec_ctx_t *ctx, const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, void **sptr, + asn_per_data_t *pd) { + asn_dec_rval_t rv; + + (void)ctx; + (void)td; + (void)constraints; + (void)sptr; + + while(per_get_few_bits(pd, 1) >= 0); + + rv.code = RC_OK; + rv.consumed = pd->moved; + + return rv; +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_opentype.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_opentype.h new file mode 100644 index 000000000..fc3785566 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_opentype.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2007-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _PER_OPENTYPE_H_ +#define _PER_OPENTYPE_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +asn_dec_rval_t uper_sot_suck( + const asn_codec_ctx_t *, + const asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, + void **sptr, asn_per_data_t *pd); + +#ifdef __cplusplus +} +#endif + +#endif /* _PER_OPENTYPE_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_support.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_support.c new file mode 100644 index 000000000..62d343c74 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_support.c @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2005-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +// Absolutely nothing diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_support.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_support.h new file mode 100644 index 000000000..b3056a21a --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/per_support.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2005-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _PER_SUPPORT_H_ +#define _PER_SUPPORT_H_ + +#include /* Platform-specific types */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Pre-computed PER constraints. + */ +typedef struct asn_per_constraint_s { + enum asn_per_constraint_flags { + APC_UNCONSTRAINED = 0x0, /* No PER visible constraints */ + APC_SEMI_CONSTRAINED = 0x1, /* Constrained at "lb" */ + APC_CONSTRAINED = 0x2, /* Fully constrained */ + APC_EXTENSIBLE = 0x4 /* May have extension */ + } flags; + int range_bits; /* Full number of bits in the range */ + int effective_bits; /* Effective bits */ + intmax_t lower_bound; /* "lb" value */ + intmax_t upper_bound; /* "ub" value */ +} asn_per_constraint_t; +typedef struct asn_per_constraints_s { + asn_per_constraint_t value; + asn_per_constraint_t size; + int (*value2code)(unsigned int value); + int (*code2value)(unsigned int code); +} asn_per_constraints_t; + +/* Temporary compatibility layer. Will get removed. */ +typedef struct asn_bit_data_s asn_per_data_t; +#define per_get_few_bits(data, bits) asn_get_few_bits(data, bits) +#define per_get_undo(data, bits) asn_get_undo(data, bits) +#define per_get_many_bits(data, dst, align, bits) \ + asn_get_many_bits(data, dst, align, bits) + +/* Temporary compatibility layer. Will get removed. */ +typedef struct asn_bit_outp_s asn_per_outp_t; +#define per_put_few_bits(out, bits, obits) asn_put_few_bits(out, bits, obits) +#define per_put_many_bits(out, src, nbits) asn_put_many_bits(out, src, nbits) +#define per_put_aligned_flush(out) asn_put_aligned_flush(out) + +#ifdef __cplusplus +} +#endif + +#endif /* _PER_SUPPORT_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_decoder.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_decoder.c new file mode 100644 index 000000000..2a14557a6 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_decoder.c @@ -0,0 +1,369 @@ +/* + * Copyright (c) 2004-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include /* XER/XML parsing support */ + + +/* + * Decode the XER encoding of a given type. + */ +asn_dec_rval_t +xer_decode(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **struct_ptr, + const void *buffer, size_t size) { + asn_codec_ctx_t s_codec_ctx; + + /* + * Stack checker requires that the codec context + * must be allocated on the stack. + */ + if(opt_codec_ctx) { + if(opt_codec_ctx->max_stack_size) { + s_codec_ctx = *opt_codec_ctx; + opt_codec_ctx = &s_codec_ctx; + } + } else { + /* If context is not given, be security-conscious anyway */ + memset(&s_codec_ctx, 0, sizeof(s_codec_ctx)); + s_codec_ctx.max_stack_size = ASN__DEFAULT_STACK_MAX; + opt_codec_ctx = &s_codec_ctx; + } + + /* + * Invoke type-specific decoder. + */ + return td->op->xer_decoder(opt_codec_ctx, td, struct_ptr, 0, buffer, size); +} + + + +struct xer__cb_arg { + pxml_chunk_type_e chunk_type; + size_t chunk_size; + const void *chunk_buf; + int callback_not_invoked; +}; + +static int +xer__token_cb(pxml_chunk_type_e type, const void *_chunk_data, size_t _chunk_size, void *key) { + struct xer__cb_arg *arg = (struct xer__cb_arg *)key; + arg->chunk_type = type; + arg->chunk_size = _chunk_size; + arg->chunk_buf = _chunk_data; + arg->callback_not_invoked = 0; + return -1; /* Terminate the XML parsing */ +} + +/* + * Fetch the next token from the XER/XML stream. + */ +ssize_t +xer_next_token(int *stateContext, const void *buffer, size_t size, pxer_chunk_type_e *ch_type) { + struct xer__cb_arg arg; + int new_stateContext = *stateContext; + ssize_t ret; + + arg.callback_not_invoked = 1; + ret = pxml_parse(&new_stateContext, buffer, size, xer__token_cb, &arg); + if(ret < 0) return -1; + if(arg.callback_not_invoked) { + assert(ret == 0); /* No data was consumed */ + *ch_type = PXER_WMORE; + return 0; /* Try again with more data */ + } else { + assert(arg.chunk_size); + assert(arg.chunk_buf == buffer); + } + + /* + * Translate the XML chunk types into more convenient ones. + */ + switch(arg.chunk_type) { + case PXML_TEXT: + *ch_type = PXER_TEXT; + break; + case PXML_TAG: + *ch_type = PXER_WMORE; + return 0; /* Want more */ + case PXML_TAG_END: + *ch_type = PXER_TAG; + break; + case PXML_COMMENT: + case PXML_COMMENT_END: + *ch_type = PXER_COMMENT; + break; + } + + *stateContext = new_stateContext; + return arg.chunk_size; +} + +#define CSLASH 0x2f /* '/' */ +#define LANGLE 0x3c /* '<' */ +#define RANGLE 0x3e /* '>' */ + +xer_check_tag_e +xer_check_tag(const void *buf_ptr, int size, const char *need_tag) { + const char *buf = (const char *)buf_ptr; + const char *end; + xer_check_tag_e ct = XCT_OPENING; + + if(size < 2 || buf[0] != LANGLE || buf[size-1] != RANGLE) { + if(size >= 2) + ASN_DEBUG("Broken XML tag: \"%c...%c\"", + buf[0], buf[size - 1]); + return XCT_BROKEN; + } + + /* + * Determine the tag class. + */ + if(buf[1] == CSLASH) { + buf += 2; /* advance past "" */ + ct = XCT_CLOSING; + if(size > 0 && buf[size-1] == CSLASH) + return XCT_BROKEN; /* */ + } else { + buf++; /* advance past "<" */ + size -= 2; /* strip "<" and ">" */ + if(size > 0 && buf[size-1] == CSLASH) { + ct = XCT_BOTH; + size--; /* One more, for "/" */ + } + } + + /* Sometimes we don't care about the tag */ + if(!need_tag || !*need_tag) + return (xer_check_tag_e)(XCT__UNK__MASK | ct); + + /* + * Determine the tag name. + */ + for(end = buf + size; buf < end; buf++, need_tag++) { + int b = *buf, n = *need_tag; + if(b != n) { + if(n == 0) { + switch(b) { + case 0x09: case 0x0a: case 0x0c: case 0x0d: + case 0x20: + /* "": whitespace is normal */ + return ct; + } + } + return (xer_check_tag_e)(XCT__UNK__MASK | ct); + } + if(b == 0) + return XCT_BROKEN; /* Embedded 0 in buf?! */ + } + if(*need_tag) + return (xer_check_tag_e)(XCT__UNK__MASK | ct); + + return ct; +} + + +#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 { \ + rval.code = _code; \ + rval.consumed = consumed_myself; \ + if(rval.code != RC_OK) \ + ASN_DEBUG("Failed with %d", rval.code); \ + return rval; \ + } while(0) + +#define XER_GOT_BODY(chunk_buf, chunk_size, size) do { \ + ssize_t converted_size = body_receiver \ + (struct_key, chunk_buf, chunk_size, \ + (size_t)chunk_size < size); \ + if(converted_size == -1) RETURN(RC_FAIL); \ + if(converted_size == 0 \ + && size == (size_t)chunk_size) \ + RETURN(RC_WMORE); \ + chunk_size = converted_size; \ + } while(0) +#define XER_GOT_EMPTY() do { \ + if(body_receiver(struct_key, 0, 0, size > 0) == -1) \ + RETURN(RC_FAIL); \ + } while(0) + +/* + * Generalized function for decoding the primitive values. + */ +asn_dec_rval_t +xer_decode_general(const asn_codec_ctx_t *opt_codec_ctx, + asn_struct_ctx_t *ctx, /* Type decoder context */ + void *struct_key, + const char *xml_tag, /* Expected XML tag */ + const void *buf_ptr, size_t size, + int (*opt_unexpected_tag_decoder) + (void *struct_key, const void *chunk_buf, size_t chunk_size), + ssize_t (*body_receiver) + (void *struct_key, const void *chunk_buf, size_t chunk_size, + int have_more) + ) { + + asn_dec_rval_t rval; + ssize_t consumed_myself = 0; + + (void)opt_codec_ctx; + + /* + * Phases of XER/XML processing: + * Phase 0: Check that the opening tag matches our expectations. + * Phase 1: Processing body and reacting on closing tag. + */ + if(ctx->phase > 1) RETURN(RC_FAIL); + for(;;) { + pxer_chunk_type_e ch_type; /* XER chunk type */ + ssize_t ch_size; /* Chunk size */ + xer_check_tag_e tcv; /* Tag check value */ + + /* + * Get the next part of the XML stream. + */ + ch_size = xer_next_token(&ctx->context, buf_ptr, size, + &ch_type); + if(ch_size == -1) { + RETURN(RC_FAIL); + } else { + switch(ch_type) { + case PXER_WMORE: + RETURN(RC_WMORE); + case PXER_COMMENT: /* Got XML comment */ + ADVANCE(ch_size); /* Skip silently */ + continue; + case PXER_TEXT: + if(ctx->phase == 0) { + /* + * We have to ignore whitespace here, + * but in order to be forward compatible + * with EXTENDED-XER (EMBED-VALUES, #25) + * any text is just ignored here. + */ + } else { + XER_GOT_BODY(buf_ptr, ch_size, size); + } + ADVANCE(ch_size); + continue; + case PXER_TAG: + break; /* Check the rest down there */ + } + } + + assert(ch_type == PXER_TAG && size); + + tcv = xer_check_tag(buf_ptr, ch_size, xml_tag); + /* + * Phase 0: + * Expecting the opening tag + * for the type being processed. + * Phase 1: + * Waiting for the closing XML tag. + */ + switch(tcv) { + case XCT_BOTH: + if(ctx->phase) break; + /* Finished decoding of an empty element */ + XER_GOT_EMPTY(); + ADVANCE(ch_size); + ctx->phase = 2; /* Phase out */ + RETURN(RC_OK); + case XCT_OPENING: + if(ctx->phase) break; + ADVANCE(ch_size); + ctx->phase = 1; /* Processing body phase */ + continue; + case XCT_CLOSING: + if(!ctx->phase) break; + ADVANCE(ch_size); + ctx->phase = 2; /* Phase out */ + RETURN(RC_OK); + case XCT_UNKNOWN_BO: + /* + * Certain tags in the body may be expected. + */ + if(opt_unexpected_tag_decoder + && opt_unexpected_tag_decoder(struct_key, + buf_ptr, ch_size) >= 0) { + /* Tag's processed fine */ + ADVANCE(ch_size); + if(!ctx->phase) { + /* We are not expecting + * the closing tag anymore. */ + ctx->phase = 2; /* Phase out */ + RETURN(RC_OK); + } + continue; + } + /* Fall through */ + default: + break; /* Unexpected tag */ + } + + ASN_DEBUG("Unexpected XML tag (expected \"%s\")", xml_tag); + break; /* Dark and mysterious things have just happened */ + } + + RETURN(RC_FAIL); +} + + +size_t +xer_whitespace_span(const void *chunk_buf, size_t chunk_size) { + const char *p = (const char *)chunk_buf; + const char *pend = (p == NULL)? NULL : p + chunk_size; + + for(; p < pend; p++) { + switch(*p) { + /* X.693, #8.1.4 + * HORISONTAL TAB (9) + * LINE FEED (10) + * CARRIAGE RETURN (13) + * SPACE (32) + */ + case 0x09: case 0x0a: case 0x0d: case 0x20: + continue; + default: + break; + } + break; + } + return (p - (const char *)chunk_buf); +} + +/* + * This is a vastly simplified, non-validating XML tree skipper. + */ +int +xer_skip_unknown(xer_check_tag_e tcv, ber_tlv_len_t *depth) { + assert(*depth > 0); + switch(tcv) { + case XCT_BOTH: + case XCT_UNKNOWN_BO: + /* These negate each other. */ + return 0; + case XCT_OPENING: + case XCT_UNKNOWN_OP: + ++(*depth); + return 0; + case XCT_CLOSING: + case XCT_UNKNOWN_CL: + if(--(*depth) == 0) + return (tcv == XCT_CLOSING) ? 2 : 1; + return 0; + default: + return -1; + } +} diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_decoder.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_decoder.h new file mode 100644 index 000000000..b951c41d1 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_decoder.h @@ -0,0 +1,106 @@ +/*- + * Copyright (c) 2004-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _XER_DECODER_H_ +#define _XER_DECODER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* + * The XER decoder of any ASN.1 type. May be invoked by the application. + * Decodes CANONICAL-XER and BASIC-XER. + */ +asn_dec_rval_t xer_decode( + const struct asn_codec_ctx_s *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *type_descriptor, + void **struct_ptr, /* Pointer to a target structure's pointer */ + const void *buffer, /* Data to be decoded */ + size_t size /* Size of data buffer */ +); + +/* + * Type of the type-specific XER decoder function. + */ +typedef asn_dec_rval_t(xer_type_decoder_f)( + const asn_codec_ctx_t *opt_codec_ctx, + const struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr, + const char *opt_mname, /* Member name */ + const void *buf_ptr, size_t size); + +/******************************* + * INTERNALLY USEFUL FUNCTIONS * + *******************************/ + +/* + * Generalized function for decoding the primitive values. + * Used by more specialized functions, such as OCTET_STRING_decode_xer_utf8 + * and others. This function should not be used by applications, as its API + * is subject to changes. + */ +asn_dec_rval_t xer_decode_general( + const asn_codec_ctx_t *opt_codec_ctx, + asn_struct_ctx_t *ctx, /* Type decoder context */ + void *struct_key, /* Treated as opaque pointer */ + const char *xml_tag, /* Expected XML tag name */ + const void *buf_ptr, size_t size, + int (*opt_unexpected_tag_decoder)(void *struct_key, const void *chunk_buf, + size_t chunk_size), + ssize_t (*body_receiver)(void *struct_key, const void *chunk_buf, + size_t chunk_size, int have_more)); + + +/* + * Fetch the next XER (XML) token from the stream. + * The function returns the number of bytes occupied by the chunk type, + * returned in the _ch_type. The _ch_type is only set (and valid) when + * the return value is >= 0. + */ + typedef enum pxer_chunk_type { + PXER_WMORE, /* Chunk type is not clear, more data expected. */ + PXER_TAG, /* Complete XER tag */ + PXER_TEXT, /* Plain text between XER tags */ + PXER_COMMENT /* A comment, may be part of */ + } pxer_chunk_type_e; +ssize_t xer_next_token(int *stateContext, + const void *buffer, size_t size, pxer_chunk_type_e *_ch_type); + +/* + * This function checks the buffer against the tag name is expected to occur. + */ + typedef enum xer_check_tag { + XCT_BROKEN = 0, /* The tag is broken */ + XCT_OPENING = 1, /* This is the tag */ + XCT_CLOSING = 2, /* This is the tag */ + XCT_BOTH = 3, /* This is the tag */ + XCT__UNK__MASK = 4, /* Mask of everything unexpected */ + XCT_UNKNOWN_OP = 5, /* Unexpected tag */ + XCT_UNKNOWN_CL = 6, /* Unexpected tag */ + XCT_UNKNOWN_BO = 7 /* Unexpected tag */ + } xer_check_tag_e; +xer_check_tag_e xer_check_tag(const void *buf_ptr, int size, + const char *need_tag); + +/* + * Get the number of bytes consisting entirely of XER whitespace characters. + * RETURN VALUES: + * >=0: Number of whitespace characters in the string. + */ +size_t xer_whitespace_span(const void *chunk_buf, size_t chunk_size); + +/* + * Skip the series of anticipated extensions. + */ +int xer_skip_unknown(xer_check_tag_e tcv, ber_tlv_len_t *depth); + +#ifdef __cplusplus +} +#endif + +#endif /* _XER_DECODER_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_encoder.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_encoder.c new file mode 100644 index 000000000..4177ede5c --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_encoder.c @@ -0,0 +1,237 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include +#include + +/* + * The XER encoder of any type. May be invoked by the application. + */ +asn_enc_rval_t +xer_encode(const asn_TYPE_descriptor_t *td, const void *sptr, + enum xer_encoder_flags_e xer_flags, asn_app_consume_bytes_f *cb, + void *app_key) { + asn_enc_rval_t er = {0, 0, 0}; + asn_enc_rval_t tmper; + const char *mname; + size_t mlen; + int xcan = (xer_flags & XER_F_CANONICAL) ? 1 : 2; + + if(!td || !sptr) goto cb_failed; + + mname = td->xml_tag; + mlen = strlen(mname); + + ASN__CALLBACK3("<", 1, mname, mlen, ">", 1); + + tmper = td->op->xer_encoder(td, sptr, 1, xer_flags, cb, app_key); + if(tmper.encoded == -1) return tmper; + er.encoded += tmper.encoded; + + ASN__CALLBACK3("\n", xcan); + + ASN__ENCODED_OK(er); +cb_failed: + ASN__ENCODE_FAILED; +} + +/* + * This is a helper function for xer_fprint, which directs all incoming data + * into the provided file descriptor. + */ +static int +xer__print2fp(const void *buffer, size_t size, void *app_key) { + FILE *stream = (FILE *)app_key; + + if(fwrite(buffer, 1, size, stream) != size) + return -1; + + return 0; +} + +int +xer_fprint(FILE *stream, const asn_TYPE_descriptor_t *td, const void *sptr) { + asn_enc_rval_t er = {0,0,0}; + + if(!stream) stream = stdout; + if(!td || !sptr) + return -1; + + er = xer_encode(td, sptr, XER_F_BASIC, xer__print2fp, stream); + if(er.encoded == -1) + return -1; + + return fflush(stream); +} + +struct xer_buffer { + char *buffer; + size_t buffer_size; + size_t allocated_size; +}; + +static int +xer__buffer_append(const void *buffer, size_t size, void *app_key) { + struct xer_buffer *xb = app_key; + + while(xb->buffer_size + size + 1 > xb->allocated_size) { + size_t new_size = 2 * (xb->allocated_size ? xb->allocated_size : 64); + char *new_buf = MALLOC(new_size); + if(!new_buf) return -1; + if (xb->buffer) { + memcpy(new_buf, xb->buffer, xb->buffer_size); + } + FREEMEM(xb->buffer); + xb->buffer = new_buf; + xb->allocated_size = new_size; + } + + memcpy(xb->buffer + xb->buffer_size, buffer, size); + xb->buffer_size += size; + xb->buffer[xb->buffer_size] = '\0'; + return 0; +} + +enum xer_equivalence_e +xer_equivalent(const struct asn_TYPE_descriptor_s *td, const void *struct1, + const void *struct2, FILE *opt_debug_stream) { + struct xer_buffer xb1 = {0, 0, 0}; + struct xer_buffer xb2 = {0, 0, 0}; + asn_enc_rval_t e1, e2; + asn_dec_rval_t rval; + void *sptr = NULL; + + if(!td || !struct1 || !struct2) { + if(opt_debug_stream) { + if(!td) fprintf(opt_debug_stream, "Type descriptor missing\n"); + if(!struct1) fprintf(opt_debug_stream, "Structure 1 missing\n"); + if(!struct2) fprintf(opt_debug_stream, "Structure 2 missing\n"); + } + return XEQ_FAILURE; + } + + e1 = xer_encode(td, struct1, XER_F_BASIC, xer__buffer_append, &xb1); + if(e1.encoded == -1) { + if(opt_debug_stream) { + fprintf(stderr, "XER Encoding of %s failed\n", td->name); + } + FREEMEM(xb1.buffer); + return XEQ_ENCODE1_FAILED; + } + + e2 = xer_encode(td, struct2, XER_F_BASIC, xer__buffer_append, &xb2); + if(e2.encoded == -1) { + if(opt_debug_stream) { + fprintf(stderr, "XER Encoding of %s failed\n", td->name); + } + FREEMEM(xb1.buffer); + FREEMEM(xb2.buffer); + return XEQ_ENCODE1_FAILED; + } + + if(xb1.buffer_size != xb2.buffer_size + || memcmp(xb1.buffer, xb2.buffer, xb1.buffer_size) != 0) { + if(opt_debug_stream) { + fprintf(opt_debug_stream, + "Structures XER-encoded into different byte streams:\n=== " + "Structure 1 ===\n%s\n=== Structure 2 ===\n%s\n", + xb1.buffer, xb2.buffer); + } + FREEMEM(xb1.buffer); + FREEMEM(xb2.buffer); + return XEQ_DIFFERENT; + } else { + if(opt_debug_stream) { + fprintf(opt_debug_stream, + "Both structures encoded into the same XER byte stream " + "of size %" ASN_PRI_SIZE ":\n%s", + xb1.buffer_size, xb1.buffer); + } + } + + rval = xer_decode(NULL, td, (void **)&sptr, xb1.buffer, + xb1.buffer_size); + switch(rval.code) { + case RC_OK: + break; + case RC_WMORE: + if(opt_debug_stream) { + fprintf(opt_debug_stream, + "Structure %s XER decode unexpectedly requires " + "more data:\n%s\n", + td->name, xb1.buffer); + } + /* Fall through */ + case RC_FAIL: + default: + if(opt_debug_stream) { + fprintf(opt_debug_stream, + "Structure %s XER decoding resulted in failure.\n", + td->name); + } + ASN_STRUCT_FREE(*td, sptr); + FREEMEM(xb1.buffer); + FREEMEM(xb2.buffer); + return XEQ_DECODE_FAILED; + } + + if(rval.consumed != xb1.buffer_size + && ((rval.consumed > xb1.buffer_size) + || xer_whitespace_span(xb1.buffer + rval.consumed, + xb1.buffer_size - rval.consumed) + != (xb1.buffer_size - rval.consumed))) { + if(opt_debug_stream) { + fprintf(opt_debug_stream, + "Round-trip decode of %s required less bytes (%" ASN_PRI_SIZE ") than " + "encoded (%" ASN_PRI_SIZE ")\n", + td->name, rval.consumed, xb1.buffer_size); + } + ASN_STRUCT_FREE(*td, sptr); + FREEMEM(xb1.buffer); + FREEMEM(xb2.buffer); + return XEQ_ROUND_TRIP_FAILED; + } + + /* + * Reuse xb2 to encode newly decoded structure. + */ + FREEMEM(xb2.buffer); + memset(&xb2, 0, sizeof(xb2)); + + e2 = xer_encode(td, sptr, XER_F_BASIC, xer__buffer_append, &xb2); + if(e2.encoded == -1) { + if(opt_debug_stream) { + fprintf(stderr, "XER Encoding of round-trip decode of %s failed\n", + td->name); + } + ASN_STRUCT_FREE(*td, sptr); + FREEMEM(xb1.buffer); + FREEMEM(xb2.buffer); + return XEQ_ROUND_TRIP_FAILED; + } + + ASN_STRUCT_FREE(*td, sptr); + sptr = 0; + + if(xb1.buffer_size != xb2.buffer_size + || memcmp(xb1.buffer, xb2.buffer, xb1.buffer_size) != 0) { + if(opt_debug_stream) { + fprintf(opt_debug_stream, + "XER Encoding of round-trip decode of %s resulted in " + "different byte stream:\n" + "=== Original ===\n%s\n" + "=== Round-tripped ===\n%s\n", + xb1.buffer, xb2.buffer, td->name); + } + FREEMEM(xb1.buffer); + FREEMEM(xb2.buffer); + return XEQ_ROUND_TRIP_FAILED; + } + + FREEMEM(xb1.buffer); + FREEMEM(xb2.buffer); + return XEQ_SUCCESS; +} + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_encoder.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_encoder.h new file mode 100644 index 000000000..6cfc505fa --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_encoder.h @@ -0,0 +1,83 @@ +/*- + * Copyright (c) 2004-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _XER_ENCODER_H_ +#define _XER_ENCODER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* Flags used by the xer_encode() and (*xer_type_encoder_f), defined below */ +enum xer_encoder_flags_e { + /* Mode of encoding */ + XER_F_BASIC = 0x01, /* BASIC-XER (pretty-printing) */ + XER_F_CANONICAL = 0x02 /* Canonical XER (strict rules) */ +}; + +/* + * The XER encoder of any type. May be invoked by the application. + * Produces CANONICAL-XER and BASIC-XER depending on the (xer_flags). + */ +asn_enc_rval_t xer_encode(const struct asn_TYPE_descriptor_s *type_descriptor, + const void *struct_ptr, /* Structure to be encoded */ + enum xer_encoder_flags_e xer_flags, + asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key /* Arbitrary callback argument */ +); + +/* + * The variant of the above function which dumps the BASIC-XER (XER_F_BASIC) + * output into the chosen file pointer. + * RETURN VALUES: + * 0: The structure is printed. + * -1: Problem printing the structure. + * WARNING: No sensible errno value is returned. + */ +int xer_fprint(FILE *stream, const struct asn_TYPE_descriptor_s *td, + const void *struct_ptr); + +/* + * A helper function that uses XER encoding/decoding to verify that: + * - Both structures encode into the same BASIC XER. + * - Both resulting XER byte streams can be decoded back. + * - Both decoded structures encode into the same BASIC XER (round-trip). + * All of this verifies equivalence between structures and a round-trip. + * ARGUMENTS: + * (opt_debug_stream) - If specified, prints ongoing details. + */ +enum xer_equivalence_e { + XEQ_SUCCESS, /* The only completely positive return value */ + XEQ_FAILURE, /* General failure */ + XEQ_ENCODE1_FAILED, /* First structure XER encoding failed */ + XEQ_ENCODE2_FAILED, /* Second structure XER encoding failed */ + XEQ_DIFFERENT, /* Structures encoded into different XER */ + XEQ_DECODE_FAILED, /* Decode of the XER data failed */ + XEQ_ROUND_TRIP_FAILED /* Bad round-trip */ +}; +enum xer_equivalence_e xer_equivalent( + const struct asn_TYPE_descriptor_s *type_descriptor, const void *struct1, + const void *struct2, FILE *opt_debug_stream); + +/* + * Type of the generic XER encoder. + */ +typedef asn_enc_rval_t(xer_type_encoder_f)( + const struct asn_TYPE_descriptor_s *type_descriptor, + const void *struct_ptr, /* Structure to be encoded */ + int ilevel, /* Level of indentation */ + enum xer_encoder_flags_e xer_flags, + asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ + void *app_key /* Arbitrary callback argument */ +); + +#ifdef __cplusplus +} +#endif + +#endif /* _XER_ENCODER_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_support.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_support.c new file mode 100644 index 000000000..36b4bfbfc --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_support.c @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2003, 2004 X/IO Labs, xiolabs.com. + * Copyright (c) 2003, 2004, 2005 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +/* Parser states */ +typedef enum { + ST_TEXT, + ST_TAG_START, + ST_TAG_BODY, + ST_TAG_QUOTE_WAIT, + ST_TAG_QUOTED_STRING, + ST_TAG_UNQUOTED_STRING, + ST_COMMENT_WAIT_DASH1, /* ""[0] */ + ST_COMMENT_CLO_RT /* "-->"[1] */ +} pstate_e; + +static const int +_charclass[256] = { + 0,0,0,0,0,0,0,0, 0,1,1,0,1,1,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 1,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 2,2,2,2,2,2,2,2, 2,2,0,0,0,0,0,0, /* 01234567 89 */ + 0,3,3,3,3,3,3,3, 3,3,3,3,3,3,3,3, /* ABCDEFG HIJKLMNO */ + 3,3,3,3,3,3,3,3, 3,3,3,0,0,0,0,0, /* PQRSTUVW XYZ */ + 0,3,3,3,3,3,3,3, 3,3,3,3,3,3,3,3, /* abcdefg hijklmno */ + 3,3,3,3,3,3,3,3, 3,3,3,0,0,0,0,0 /* pqrstuvw xyz */ +}; +#define WHITESPACE(c) (_charclass[(unsigned char)(c)] == 1) +#define ALNUM(c) (_charclass[(unsigned char)(c)] >= 2) +#define ALPHA(c) (_charclass[(unsigned char)(c)] == 3) + +/* Aliases for characters, ASCII/UTF-8 */ +#define EXCLAM 0x21 /* '!' */ +#define CQUOTE 0x22 /* '"' */ +#define CDASH 0x2d /* '-' */ +#define CSLASH 0x2f /* '/' */ +#define LANGLE 0x3c /* '<' */ +#define CEQUAL 0x3d /* '=' */ +#define RANGLE 0x3e /* '>' */ +#define CQUEST 0x3f /* '?' */ + +/* Invoke token callback */ +#define TOKEN_CB_CALL(type, _ns, _current_too, _final) do { \ + int _ret; \ + pstate_e ns = _ns; \ + ssize_t _sz = (p - chunk_start) + _current_too; \ + if (!_sz) { \ + /* Shortcut */ \ + state = _ns; \ + break; \ + } \ + _ret = cb(type, chunk_start, _sz, key); \ + if(_ret < _sz) { \ + if(_current_too && _ret == -1) \ + state = ns; \ + goto finish; \ + } \ + chunk_start = p + _current_too; \ + state = ns; \ + } while(0) + +#define TOKEN_CB(_type, _ns, _current_too) \ + TOKEN_CB_CALL(_type, _ns, _current_too, 0) + +#define PXML_TAG_FINAL_CHUNK_TYPE PXML_TAG_END +#define PXML_COMMENT_FINAL_CHUNK_TYPE PXML_COMMENT_END + +#define TOKEN_CB_FINAL(_type, _ns, _current_too) \ + TOKEN_CB_CALL( _type ## _FINAL_CHUNK_TYPE , _ns, _current_too, 1) + +/* + * Parser itself + */ +ssize_t pxml_parse(int *stateContext, const void *xmlbuf, size_t size, pxml_callback_f *cb, void *key) { + pstate_e state = (pstate_e)*stateContext; + const char *chunk_start = (const char *)xmlbuf; + const char *p = chunk_start; + const char *end = p + size; + + for(; p < end; p++) { + int C = *(const unsigned char *)p; + switch(state) { + case ST_TEXT: + /* + * Initial state: we're in the middle of some text, + * or just have started. + */ + if (C == LANGLE) + /* We're now in the tag, probably */ + TOKEN_CB(PXML_TEXT, ST_TAG_START, 0); + break; + case ST_TAG_START: + if (ALPHA(C) || (C == CSLASH)) + state = ST_TAG_BODY; + else if (C == EXCLAM) + state = ST_COMMENT_WAIT_DASH1; + else + /* + * Not characters and not whitespace. + * Must be something like "3 < 4". + */ + TOKEN_CB(PXML_TEXT, ST_TEXT, 1);/* Flush as data */ + break; + case ST_TAG_BODY: + switch(C) { + case RANGLE: + /* End of the tag */ + TOKEN_CB_FINAL(PXML_TAG, ST_TEXT, 1); + break; + case LANGLE: + /* + * The previous tag wasn't completed, but still + * recognized as valid. (Mozilla-compatible) + */ + TOKEN_CB_FINAL(PXML_TAG, ST_TAG_START, 0); + break; + case CEQUAL: + state = ST_TAG_QUOTE_WAIT; + break; + } + break; + case ST_TAG_QUOTE_WAIT: + /* + * State after the equal sign ("=") in the tag. + */ + switch(C) { + case CQUOTE: + state = ST_TAG_QUOTED_STRING; + break; + case RANGLE: + /* End of the tag */ + TOKEN_CB_FINAL(PXML_TAG, ST_TEXT, 1); + break; + default: + if(!WHITESPACE(C)) + /* Unquoted string value */ + state = ST_TAG_UNQUOTED_STRING; + } + break; + case ST_TAG_QUOTED_STRING: + /* + * Tag attribute's string value in quotes. + */ + if(C == CQUOTE) { + /* Return back to the tag state */ + state = ST_TAG_BODY; + } + break; + case ST_TAG_UNQUOTED_STRING: + if(C == RANGLE) { + /* End of the tag */ + TOKEN_CB_FINAL(PXML_TAG, ST_TEXT, 1); + } else if(WHITESPACE(C)) { + /* Return back to the tag state */ + state = ST_TAG_BODY; + } + break; + case ST_COMMENT_WAIT_DASH1: + if(C == CDASH) { + state = ST_COMMENT_WAIT_DASH2; + } else { + /* Some ordinary tag. */ + state = ST_TAG_BODY; + } + break; + case ST_COMMENT_WAIT_DASH2: + if(C == CDASH) { + /* Seen "<--" */ + state = ST_COMMENT; + } else { + /* Some ordinary tag */ + state = ST_TAG_BODY; + } + break; + case ST_COMMENT: + if(C == CDASH) { + state = ST_COMMENT_CLO_DASH2; + } + break; + case ST_COMMENT_CLO_DASH2: + if(C == CDASH) { + state = ST_COMMENT_CLO_RT; + } else { + /* This is not an end of a comment */ + state = ST_COMMENT; + } + break; + case ST_COMMENT_CLO_RT: + if(C == RANGLE) { + TOKEN_CB_FINAL(PXML_COMMENT, ST_TEXT, 1); + } else if(C == CDASH) { + /* Maintain current state, still waiting for '>' */ + } else { + state = ST_COMMENT; + } + break; + } /* switch(*ptr) */ + } /* for() */ + + /* + * Flush the partially processed chunk, state permitting. + */ + if(p - chunk_start) { + switch (state) { + case ST_COMMENT: + TOKEN_CB(PXML_COMMENT, state, 0); + break; + case ST_TEXT: + TOKEN_CB(PXML_TEXT, state, 0); + break; + default: break; /* a no-op */ + } + } + +finish: + *stateContext = (int)state; + return chunk_start - (const char *)xmlbuf; +} + diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_support.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_support.h new file mode 100644 index 000000000..2c3f369b8 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/compiled_output/xer_support.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2003, 2004 X/IO Labs, xiolabs.com. + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _XER_SUPPORT_H_ +#define _XER_SUPPORT_H_ + +#include /* Platform-specific types */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Types of data transferred to the application. + */ +typedef enum { + PXML_TEXT, /* Plain text between XML tags. */ + PXML_TAG, /* A tag, starting with '<'. */ + PXML_COMMENT, /* An XML comment, including "". */ + /* + * The following chunk types are reported if the chunk + * terminates the specified XML element. + */ + PXML_TAG_END, /* Tag ended */ + PXML_COMMENT_END /* Comment ended */ +} pxml_chunk_type_e; + +/* + * Callback function that is called by the parser when parsed data is + * available. The _opaque is the pointer to a field containing opaque user + * data specified in pxml_create() call. The chunk type is _type and the text + * data is the piece of buffer identified by _bufid (as supplied to + * pxml_feed() call) starting at offset _offset and of _size bytes size. + * The chunk is NOT '\0'-terminated. + */ +typedef int (pxml_callback_f)(pxml_chunk_type_e _type, + const void *_chunk_data, size_t _chunk_size, void *_key); + +/* + * Parse the given buffer as it were a chunk of XML data. + * Invoke the specified callback each time the meaningful data is found. + * This function returns number of bytes consumed from the buffer. + * It will always be lesser than or equal to the specified _size. + * The next invocation of this function must account the difference. + */ +ssize_t pxml_parse(int *_stateContext, const void *_buf, size_t _size, + pxml_callback_f *cb, void *_key); + +#ifdef __cplusplus +} +#endif + +#endif /* _XER_SUPPORT_H_ */ diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/e3sm_spectrum.asn b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/e3sm_spectrum.asn new file mode 100644 index 000000000..1d971a5f2 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/defs/e3sm_spectrum.asn @@ -0,0 +1,185 @@ +-- Spectrum Service Model ASN.1 Definitions +-- +-- Copyright (c) 2026 Institute for Intelligent Networked Systems (INSI) +-- at Northeastern University. All rights reserved. +-- SPDX-License-Identifier: LicenseRef-CSSL-1.0 +-- +-- This service model extends E3 messages for spectrum sharing applications +-- +-- Usage with E3 Protocol: +-- - Spectrum-SensingIndication structures are encoded into the protocolData field of E3-IndicationMessage +-- - Spectrum-DAppControlData structures are encoded into the actionData field of E3-DAppControlAction +-- - Spectrum-DAppReportData structures are encoded into the reportData field of E3-DAppReport +-- - Spectrum-XAppControlData structures are encoded into the xAppControlData field of E3-XAppControlAction +-- +-- Each "*Data" envelope is a single-member SEQUENCE holding a Payload CHOICE: +-- the CHOICE alternative is the type discriminator on the ASN.1 wire. The JSON +-- encoding adds an explicit type key (e.g. "controlType") next to the payload +-- for readability; that key is produced and checked by the codecs and is not a +-- schema field. + +SPECTRUM-SM DEFINITIONS AUTOMATIC TAGS ::= BEGIN + +-- ============================================================================ +-- SM SPECTRUM RAN FUNCTION DATA STRUCTURES +-- ============================================================================ + +-- Spectrum RAN function data +Spectrum-RanFunctionData ::= SEQUENCE { + name OCTET STRING (SIZE (1..32)), + version INTEGER (0..65535), + description OCTET STRING (SIZE (1..128)) +} + +-- ============================================================================ +-- INDICATION MESSAGE STRUCTURES +-- ============================================================================ + +-- Sensing-range telemetry indication (one per MAC sensing publish). The +-- sensing ranges are NOT inline: they are written out-of-band into the +-- /e3_l2_sensing POSIX shm ring; this payload carries only a reference into +-- that ring, so the message stays small (a few dozen bytes) regardless of how +-- many tiles the slot held. A dApp maps the named region read-only and reads +-- the ranges (raw sensing_range_t records) at the given write index, after +-- checking the ring slot's own (sfn, slot) tag against this indication +-- (torn/wrap guard). +-- +-- timestamp : CLOCK_MONOTONIC nanoseconds at the publish point. Monotonic, not +-- realtime, because this indication cannot leave the host: it +-- carries only a reference into the local /e3_l2_sensing shm ring, +-- so a dApp elsewhere could not dereference it. Monotonic shares an +-- origin across processes on one host, which is exactly the span +-- this measures. Never difference it against +-- Spectrum-DAppReportData.timestamp, which is realtime. +-- sfn / slot : frame and slot the snapshot belongs to. +-- beam : OPTIONAL - set 0..3 when the upstream sensing scheduler grows +-- multi-beam support; the writer currently always emits 0. +-- shmName : POSIX shm region holding the ranges, e.g. "/e3_l2_sensing". +-- shmWriteIdx : ring slot index just written (the ranges for this (sfn,slot)). +-- nRanges : number of sensing_range_t records live at that index, 0..128. +Spectrum-SensingIndication ::= SEQUENCE { + timestamp INTEGER, + sfn INTEGER (0..65535), + slot INTEGER (0..65535), + beam INTEGER (0..3) OPTIONAL, + shmName OCTET STRING, + shmWriteIdx INTEGER (0..65535), + nRanges INTEGER (0..128) +} + +-- ============================================================================ +-- CONTROL ACTION STRUCTURES +-- ============================================================================ + +-- PRB Blacklist Control (main control message used by spectrum dApp) +Spectrum-PRBBlacklistControl ::= SEQUENCE { + blacklistedPRBs SEQUENCE (SIZE (0..maxPRBs)) OF INTEGER (0..maxPRBIndex), -- List of PRB indices + samplingThreshold INTEGER (0..100) OPTIONAL, -- Sampling ratio for the IQ captures, one delivery each samplingThreshold + validityPeriod INTEGER (1..3600) OPTIONAL -- How long this blacklist is valid (seconds) +} + +-- Sensing Policy Control: per-slot 14-bit symbol bitmap consumed by the +-- masked UL TDA selector. Bit s set in maskPerSlot[k] => "for slot k of +-- the frame, prefer TDAs that don't claim symbol s for the UE so that +-- symbol stays free for sensing". Length of maskPerSlot MUST equal the +-- gNB's numb_slots_frame (e.g. 20 at numerology 1). deactivate=TRUE clears the +-- policy regardless of the mask. +Spectrum-SensingPolicyControl ::= SEQUENCE { + maskPerSlot SEQUENCE (SIZE (1..maxSlotsFrame)) OF INTEGER (0..maxSymbolMask), + deactivate BOOLEAN DEFAULT FALSE, + validityPeriod INTEGER (1..3600) OPTIONAL +} + +-- Extensibility marker (...) keeps the ASN.1 wire bit-width stable when new +-- alternatives are added. Without it, extending a 1-alt CHOICE to 2 +-- alternatives would change the APER encoding width from 0 bits to 1 bit and +-- silently break every existing deployment. +Spectrum-DAppControlPayload ::= CHOICE { + prbBlacklistControl Spectrum-PRBBlacklistControl, + ..., + sensingPolicyControl Spectrum-SensingPolicyControl +} + +-- Top-level dApp control PDU carried by E3-DAppControlAction.actionData +Spectrum-DAppControlData ::= SEQUENCE { + controlPayload Spectrum-DAppControlPayload +} + +-- ============================================================================ +-- dAPP REPORT STRUCTURES +-- ============================================================================ + +Spectrum-PRBBlacklistReport ::= SEQUENCE { + blacklistedPRBs SEQUENCE (SIZE (0..maxPRBs)) OF INTEGER (0..maxPRBIndex) -- List of PRB indices +} + +Spectrum-DAppReportPayload ::= CHOICE { + prbBlacklistReport Spectrum-PRBBlacklistReport, + ... +} + +-- Top-level dApp report PDU carried by E3-DAppReport.reportData +-- +-- timestamp is CLOCK_REALTIME nanoseconds at the dApp, taken when the report is +-- built. The gNB relays reportData without decoding it, so the value reaches the +-- xApp unchanged. +-- +-- CLOCK_REALTIME, unlike Spectrum-SensingIndication.timestamp above: this report +-- is always sent on to an xApp and therefore changes host, while the sensing +-- indication is meant to stay on the same host (it carries only a reference into +-- a local POSIX shm ring, so it is useless anywhere else). The two fields share a +-- name but not a clock and must never be differenced against each other. +-- +-- OPTIONAL: absent means "no producer reference". A dApp that does not stamp is +-- sending a normal message, not a malformed one, so no codec on this path may +-- reject it. Same convention as the E3AP envelope timestamp in libe3. +Spectrum-DAppReportData ::= SEQUENCE { + timestamp INTEGER OPTIONAL, + reportPayload Spectrum-DAppReportPayload +} + +-- ============================================================================ +-- xAPP CONTROL ACTION STRUCTURES +-- ============================================================================ + + +Spectrum-PRBBlockedControl ::= SEQUENCE { + blockedPRBs SEQUENCE (SIZE (0..maxPRBs)) OF INTEGER (0..maxPRBIndex) +} + +-- Spectrum Configuration Control +Spectrum-ConfigControl ::= SEQUENCE { + noiseFloorThreshold INTEGER (-100..100) OPTIONAL, -- Update noise floor threshold + averagingFrames INTEGER (1..255) OPTIONAL, -- Update averaging window + enable BOOLEAN OPTIONAL -- Enable/disable spectrum monitoring +} + +Spectrum-XAppControlPayload ::= CHOICE { + prbBlockedControl Spectrum-PRBBlockedControl, + configControl Spectrum-ConfigControl, + ... +} + +-- Top-level xApp control PDU carried by E3-XAppControlAction.xAppControlData +-- +-- timestamp is CLOCK_REALTIME nanoseconds at the xApp, taken when the control is +-- built. The gNB forwards xAppControlData without decoding it, so the value +-- reaches the dApp unchanged. Realtime for the same reason as the report above: +-- this message always changes host. +Spectrum-XAppControlData ::= SEQUENCE { + timestamp INTEGER OPTIONAL, + controlPayload Spectrum-XAppControlPayload +} + + +-- ============================================================================ +-- CONSTANTS AND CONSTRAINTS +-- ============================================================================ + +-- Maximum values based on 5G NR specifications +maxPRBs INTEGER ::= 273 -- Maximum PRBs in 5G NR +maxPRBIndex INTEGER ::= 272 -- maxPRBs - 1 +maxSlotsFrame INTEGER ::= 160 -- slots per frame at 3GPP numerology 4 (worst case); 20 at numerology 1 (30 kHz SCS) +maxSymbolMask INTEGER ::= 16383 -- 14-bit symbol bitmap = (1 << 14) - 1 + +END diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/encoder.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/encoder.c new file mode 100644 index 000000000..17241e857 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/encoder.c @@ -0,0 +1,88 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "encoder.h" + +#include "defs/compiled_output/Spectrum-XAppControlData.h" +#include "defs/compiled_output/Spectrum-PRBBlockedControl.h" + +#include +#include +#include + +#include "asn_application.h" +#include "per_encoder.h" + +bool spectrum_sm_enc_control(const spectrum_sm_control_t* ctrl, uint8_t** out_buf, size_t* out_size) +{ + assert(out_buf != NULL); + assert(out_size != NULL); + + *out_buf = NULL; + *out_size = 0; + + if (ctrl == NULL) + return false; + + if (ctrl->prb_count < 0 || ctrl->prb_count > 273) + return false; + + Spectrum_XAppControlData_t asn; + memset(&asn, 0, sizeof(asn)); + + /* OPTIONAL: the xApp stamps this and the codec only carries it, but 0 means it + * did not stamp -- a normal message with no producer reference, not a malformed + * one. Encode absent rather than refusing to encode. */ + if (ctrl->timestamp_ns != 0) { + asn.timestamp = calloc(1, sizeof(*asn.timestamp)); + assert(asn.timestamp != NULL && "Memory exhausted in spectrum_sm_enc_control"); + *asn.timestamp = (long)ctrl->timestamp_ns; + } + asn.controlPayload.present = Spectrum_XAppControlPayload_PR_prbBlockedControl; + + Spectrum_PRBBlockedControl_t* blocked = + (Spectrum_PRBBlockedControl_t*)calloc(1, sizeof(*blocked)); + assert(blocked != NULL && "Memory exhausted in spectrum_sm_enc_control"); + asn.controlPayload.choice.prbBlockedControl = blocked; + + for (long i = 0; i < ctrl->prb_count; ++i) { + const uint16_t v = ctrl->blockedPRBs[i]; + + if (v > 272) { + ASN_STRUCT_RESET(asn_DEF_Spectrum_XAppControlData, &asn); + return false; + } + + long* elem = (long*)calloc(1, sizeof(*elem)); + assert(elem != NULL && "Memory exhausted in spectrum_sm_enc_control"); + + *elem = (long)v; + + if (ASN_SEQUENCE_ADD(&blocked->blockedPRBs.list, elem) != 0) { + free(elem); + ASN_STRUCT_RESET(asn_DEF_Spectrum_XAppControlData, &asn); + return false; + } + } + + uint8_t tmp[2048]; + asn_enc_rval_t er = aper_encode_to_buffer(&asn_DEF_Spectrum_XAppControlData, NULL, &asn, tmp, sizeof(tmp)); + + if (er.encoded <= 0) { + ASN_STRUCT_RESET(asn_DEF_Spectrum_XAppControlData, &asn); + return false; + } + + const size_t encoded_bytes = (size_t)((er.encoded + 7) / 8); + uint8_t* out = (uint8_t*)malloc(encoded_bytes); + assert(out != NULL && "Memory exhausted in spectrum_sm_enc_control memcpy"); + + memcpy(out, tmp, encoded_bytes); + + *out_buf = out; + *out_size = encoded_bytes; + + ASN_STRUCT_RESET(asn_DEF_Spectrum_XAppControlData, &asn); + return true; +} \ No newline at end of file diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/encoder.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/encoder.h new file mode 100644 index 000000000..ca2ebfd2e --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/encoder.h @@ -0,0 +1,46 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef SPECTRUM_SM_ENCODER_H +#define SPECTRUM_SM_ENCODER_H + +#include +#include +#include +#include "../ir/spectrum_control.h" + +/** + * @brief Encode a Spectrum SM control IR into ASN.1 PER. + * + * This function converts a high-level @ref spectrum_sm_control_t structure + * into a wire-format ASN.1 PER-encoded Spectrum_PRBBlockedControl message. + * + * Behavior: + * - Validates @p out_buf and @p out_size, initializes them to NULL/0. + * - Returns false if @p ctrl is NULL or if ctrl->prb_count is outside + * the allowed [0, 273] range. + * - Fills a local Spectrum_Control_t ASN.1 struct: + * * prbCount is set to ctrl->prb_count. + * * blacklistedPRBsNotToBlock is allocated with + * prb_count * sizeof(uint16_t) bytes and filled by packing each + * PRB index in little-endian order (low byte, then high byte). + * - Uses aper_encode_to_buffer() to encode into a temporary buffer. + * - On encoding success: + * * Allocates a right-sized buffer, copies the encoded bytes there, + * * Stores the pointer in *out_buf and its length in *out_size. + * - Cleans up the ASN.1 structure with ASN_STRUCT_RESET() before returning. + * + * Memory ownership: + * - On success, the caller owns *out_buf and must free it (e.g., with free()). + * - On failure, *out_buf remains NULL and *out_size is 0. + * + * @param ctrl Input IR control structure to encode. + * @param out_buf Output pointer to the newly allocated encoded buffer. + * @param out_size Output size of the encoded buffer, in bytes. + * + * @return true on successful encoding, false otherwise. + */ +bool spectrum_sm_enc_control(const spectrum_sm_control_t* ctrl, uint8_t** out_buf, size_t* out_size); + +#endif diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_control.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_control.c new file mode 100644 index 000000000..671bcf237 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_control.c @@ -0,0 +1,56 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "spectrum_control.h" + +void free_spectrum_sm_control(spectrum_sm_control_t* src) +{ + assert(src != NULL); + if (src->blockedPRBs) { + free(src->blockedPRBs); + src->blockedPRBs = NULL; + } + src->prb_count = 0; +} + +bool eq_spectrum_sm_control(spectrum_sm_control_t const* m0, spectrum_sm_control_t const* m1) +{ + if (m0 == m1) + return true; + + if (!m0 || !m1) + return false; + + if (m0->prb_count != m1->prb_count) + return false; + + if (m0->timestamp_ns != m1->timestamp_ns) + return false; + + if (m0->prb_count == 0) + return true; + + if (!m0->blockedPRBs || !m1->blockedPRBs) + return false; + + return memcmp(m0->blockedPRBs, m1->blockedPRBs, (size_t)m0->prb_count * sizeof(uint16_t)) == 0; +} + +spectrum_sm_control_t cp_spectrum_sm_control(spectrum_sm_control_t const* src) +{ + assert(src != NULL); + + spectrum_sm_control_t dst; + dst.prb_count = src->prb_count; + dst.blockedPRBs = NULL; + dst.timestamp_ns = src->timestamp_ns; + + if (src->prb_count > 0 && src->blockedPRBs != NULL) { + dst.blockedPRBs = (uint16_t*)malloc((size_t)src->prb_count * sizeof(uint16_t)); + assert(dst.blockedPRBs != NULL && "Memory exhausted in cp_ran_function_1"); + memcpy(dst.blockedPRBs, src->blockedPRBs, (size_t)src->prb_count * sizeof(uint16_t)); + } + + return dst; +} \ No newline at end of file diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_control.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_control.h new file mode 100644 index 000000000..d3ed5779f --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_control.h @@ -0,0 +1,49 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef SPECTRUM_CONTROL_IR +#define SPECTRUM_CONTROL_IR + +#include +#include +#include +#include +#include + +/** + * @brief In-memory representation of a Spectrum SM control command: the PRBs + * the gNB is asked to block. + */ +typedef struct { + long prb_count; + uint16_t* blockedPRBs; + + /* CLOCK_REALTIME nanoseconds, stamped by the xApp that built the control. */ + int64_t timestamp_ns; +} spectrum_sm_control_t; + +/** + * @brief Free all dynamic memory owned by a spectrum_sm_control_t. + * The container itself is not freed, only the internal buffer it owns. + */ +void free_spectrum_sm_control(spectrum_sm_control_t* src); + +/** + * @brief Compare two Spectrum SM control structures for equality. + * + * @param m0 First control structure. + * @param m1 Second control structure. + * @return true if they are equal, false otherwise. + */ +bool eq_spectrum_sm_control(spectrum_sm_control_t const* m0, spectrum_sm_control_t const* m1); + +/** + * @brief Deep copy a Spectrum SM control structure. + * + * @param src Source control structure to copy. + * @return A deep copy of @p src. + */ +spectrum_sm_control_t cp_spectrum_sm_control(spectrum_sm_control_t const* src); + +#endif \ No newline at end of file diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_report.c b/src/sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_report.c new file mode 100644 index 000000000..f4c483563 --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_report.c @@ -0,0 +1,56 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "spectrum_report.h" + +void free_spectrum_sm_report(spectrum_sm_report_t* src) +{ + assert(src != NULL); + if (src->prbs) { + free(src->prbs); + src->prbs = NULL; + } + src->prb_count = 0; +} + +bool eq_spectrum_sm_report(spectrum_sm_report_t const* m0, spectrum_sm_report_t const* m1) +{ + if (m0 == m1) + return true; + + if (!m0 || !m1) + return false; + + if (m0->prb_count != m1->prb_count) + return false; + + if (m0->timestamp_ns != m1->timestamp_ns) + return false; + + if (m0->prb_count == 0) + return true; + + if (!m0->prbs || !m1->prbs) + return false; + + return memcmp(m0->prbs, m1->prbs, (size_t)m0->prb_count * sizeof(uint16_t)) == 0; +} + +spectrum_sm_report_t cp_spectrum_sm_report(spectrum_sm_report_t const* src) +{ + assert(src != NULL); + + spectrum_sm_report_t dst; + dst.prb_count = src->prb_count; + dst.prbs = NULL; + dst.timestamp_ns = src->timestamp_ns; + + if (src->prb_count > 0 && src->prbs != NULL) { + dst.prbs = (uint16_t*)malloc((size_t)src->prb_count * sizeof(uint16_t)); + assert(dst.prbs != NULL && "Memory exhausted in cp_ran_function_1"); + memcpy(dst.prbs, src->prbs, (size_t)src->prb_count * sizeof(uint16_t)); + } + + return dst; +} \ No newline at end of file diff --git a/src/sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_report.h b/src/sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_report.h new file mode 100644 index 000000000..6b0b7082c --- /dev/null +++ b/src/sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_report.h @@ -0,0 +1,51 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef SPECTRUM_SM_REPORT_IR +#define SPECTRUM_SM_REPORT_IR + +#include +#include +#include +#include +#include + +/** + * @brief In-memory representation of a Spectrum SM report. + * + * This is the IR (intermediate representation) produced by the ASN.1 decoder + * and consumed by the xApp / controller logic. + */ +typedef struct { + long prb_count; + uint16_t* prbs; + + /* CLOCK_REALTIME nanoseconds, stamped by the dApp that built the report. */ + int64_t timestamp_ns; +} spectrum_sm_report_t; + +/** + * @brief Free all dynamic memory owned by a spectrum_sm_report_t. + * The container itself is not freed, only the internal buffer. + */ +void free_spectrum_sm_report(spectrum_sm_report_t* src); + +/** + * @brief Compare two Spectrum SM reports for equality. + * + * @param m0 First report. + * @param m1 Second report. + * @return true if they are equal, false otherwise. + */ +bool eq_spectrum_sm_report(spectrum_sm_report_t const* m0, spectrum_sm_report_t const* m1); + +/** + * @brief Deep copy a Spectrum SM report. + * + * @param src Source report to copy. + * @return A deep copy of @p src. + */ +spectrum_sm_report_t cp_spectrum_sm_report(spectrum_sm_report_t const* src); + +#endif diff --git a/src/sm/dapp_sm/enc/dapp_enc_asn.c b/src/sm/dapp_sm/enc/dapp_enc_asn.c new file mode 100644 index 000000000..2b41d00a0 --- /dev/null +++ b/src/sm/dapp_sm/enc/dapp_enc_asn.c @@ -0,0 +1,330 @@ +#include "dapp_enc_asn.h" + +#include +#include +#include +#include + +#include + +#include "../../../util/byte_array.h" + +/* maxE2SMDAPPIndMsgSize in the E2SM-DAPP grammar, which libe3 compiles. */ +#define DAPP_MAX_IND_MSG_SIZE 32768 + +/* The encoders borrow the IR's buffers: only the arrays that libe3's structs need + * and the IR does not have in the same shape are allocated, and freed after the + * encode. libe3 owns the ASN.1; the result is malloc'ed bytes for the caller. */ + +static libe3_e2sm_dapp_bytes_t borrow_ba(byte_array_t ba) +{ + return (libe3_e2sm_dapp_bytes_t){.data = ba.buf, .len = ba.len}; +} + +/* The bytes of a successful encode, to be released with free_byte_array(). */ +static byte_array_t take_encoded(e3_error_t rc, libe3_e2sm_dapp_bytes_t out) +{ + assert(rc == E3_SUCCESS && "E2SM-DAPP encode failed"); + (void)rc; + return (byte_array_t){.len = out.len, .buf = out.data}; +} + +static libe3_e2sm_dapp_sub_list_t borrow_subs(dapp_e3_subscription_list_t const* src) +{ + libe3_e2sm_dapp_sub_list_t dst = {.n_items = src->sz_dapp_e3_subscriptions}; + + if (dst.n_items > 0) { + dst.items = calloc(dst.n_items, sizeof(*dst.items)); + assert(dst.items != NULL && "Memory exhausted"); + } + + for (size_t i = 0; i < dst.n_items; ++i) { + dapp_e3_subscription_item_t const* ir = &src->dapp_e3_subscriptions[i]; + dst.items[i] = (libe3_e2sm_dapp_sub_item_t){.dapp_id = ir->dapp_id, + .n_ran_functions = ir->sz_subscribed_e3_ran_functions, + .ran_functions = ir->subscribed_e3_ran_functions}; + } + + return dst; +} + +byte_array_t dapp_enc_event_trigger_asn(e2sm_dapp_event_trigger_t const* src) +{ + assert(src != NULL); + assert(src->format == FORMAT_1_E2SM_DAPP_EV_TRIGGER_FORMAT && "Unknown format"); + + libe3_e2sm_dapp_event_trigger_t in = {.format = LIBE3_E2SM_DAPP_EVENT_TRIGGER_FORMAT_1}; + + libe3_e2sm_dapp_bytes_t out = {0}; + e3_error_t rc = libe3_e2sm_dapp_encode_event_trigger(&in, &out); + return take_encoded(rc, out); +} + +byte_array_t dapp_enc_action_def_asn(e2sm_dapp_action_def_t const* src) +{ + assert(src != NULL); + assert(src->format == FORMAT_1_E2SM_DAPP_ACTION_DEF && "Unknown action definition format"); + + libe3_e2sm_dapp_action_definition_t in = {.format = LIBE3_E2SM_DAPP_ACTION_DEFINITION_FORMAT_1, + .ric_style_type = src->ric_style_type}; + + libe3_e2sm_dapp_bytes_t out = {0}; + e3_error_t rc = libe3_e2sm_dapp_encode_action_definition(&in, &out); + return take_encoded(rc, out); +} + +byte_array_t dapp_enc_ind_hdr_asn(e2sm_dapp_ind_hdr_t const* src) +{ + assert(src != NULL); + + // Same contract as dapp_enc_ind_msg_asn: an empty byte_array_t means declined. + libe3_e2sm_dapp_ind_hdr_t in = {0}; + + if (src->format == FORMAT_1_E2SM_DAPP_IND_HDR) { + e2sm_dapp_ind_hdr_frmt_1_t const* f = &src->frmt_1; + /* The grammar's node-cu-du-id is 32 bits wide; libe3 would truncate silently. */ + if (f->node_cu_du_id_present && f->node_cu_du_id > UINT32_MAX) { + printf("[E2SM-DAPP]: IndicationHeader node_cu_du_id %llu does not fit in 32 bits, dropping\n", + (unsigned long long)f->node_cu_du_id); + return (byte_array_t){0}; + } + + in.format = LIBE3_E2SM_DAPP_IND_HDR_FORMAT_1; + in.frmt_1 = (libe3_e2sm_dapp_ind_hdr_format1_t){.ran_function_id = f->ran_function_id, + .dapp_id = f->dapp_id, + .node_type = f->node_type, + .node_nb_id = f->node_nb_id, + .has_node_cu_du_id = f->node_cu_du_id_present, + .node_cu_du_id = (uint32_t)f->node_cu_du_id, + /* OPTIONAL: 0 means the producer did not stamp, which is a + * normal message. Encode it as absent. */ + .has_timestamp = f->timestamp_ns != 0, + .timestamp = f->timestamp_ns, + /* Same convention: 0 means no correlation id was assigned. */ + .has_sequence_id = f->sequence_id != 0, + .sequence_id = f->sequence_id}; + memcpy(in.frmt_1.node_plmn_id, f->node_plmn_id, 3); + } else if (src->format == FORMAT_2_E2SM_DAPP_IND_HDR) { + e2sm_dapp_ind_hdr_frmt_2_t const* f = &src->frmt_2; + if (f->node_cu_du_id_present && f->node_cu_du_id > UINT32_MAX) { + printf("[E2SM-DAPP]: IndicationHeader node_cu_du_id %llu does not fit in 32 bits, dropping\n", + (unsigned long long)f->node_cu_du_id); + return (byte_array_t){0}; + } + + in.format = LIBE3_E2SM_DAPP_IND_HDR_FORMAT_2; + in.frmt_2 = (libe3_e2sm_dapp_ind_hdr_format2_t){.node_type = f->node_type, + .node_nb_id = f->node_nb_id, + .has_node_cu_du_id = f->node_cu_du_id_present, + .node_cu_du_id = (uint32_t)f->node_cu_du_id, + .has_timestamp = f->timestamp_ns != 0, + .timestamp = f->timestamp_ns, + .has_sequence_id = f->sequence_id != 0, + .sequence_id = f->sequence_id}; + memcpy(in.frmt_2.node_plmn_id, f->node_plmn_id, 3); + } else { + printf("[E2SM-DAPP]: IndicationHeader with unknown format %d, dropping\n", (int)src->format); + return (byte_array_t){0}; + } + + libe3_e2sm_dapp_bytes_t out = {0}; + e3_error_t rc = libe3_e2sm_dapp_encode_ind_hdr(&in, &out); + if (rc != E3_SUCCESS) { + printf("[E2SM-DAPP]: IndicationHeader could not be encoded (error %d), dropping\n", (int)rc); + return (byte_array_t){0}; + } + + return (byte_array_t){.len = out.len, .buf = out.data}; +} + +/* An IndicationMessage this function will not encode. Rejecting one is not a bug + * in the E2 node: the struct arrives from the RAN, is reached through a union + * discriminated by format, and is encoded on the RAN's own threads, so every + * reason to refuse has to be a return value rather than an assert. */ +static bool valid_ind_msg(e2sm_dapp_ind_msg_t const* src) +{ + if (src->format == FORMAT_1_E2SM_DAPP_IND_MSG) { + /* FORMAT_1_E2SM_DAPP_IND_MSG is 0, so a zeroed or mis-typed struct lands + * here and the payload check is what actually rejects it. */ + if (src->frmt_1.data == NULL || src->frmt_1.data_size == 0) { + printf("[E2SM-DAPP]: IndicationMessage Format 1 carries no payload, dropping\n"); + return false; + } + if (src->frmt_1.data_size > DAPP_MAX_IND_MSG_SIZE) { + printf("[E2SM-DAPP]: IndicationMessage payload of %zu bytes exceeds the %d the grammar allows, dropping\n", + src->frmt_1.data_size, + DAPP_MAX_IND_MSG_SIZE); + return false; + } + return true; + } + + if (src->format == FORMAT_2_E2SM_DAPP_IND_MSG) + return true; + + printf("[E2SM-DAPP]: IndicationMessage with unknown format %d, dropping\n", (int)src->format); + return false; +} + +byte_array_t dapp_enc_ind_msg_asn(e2sm_dapp_ind_msg_t const* src) +{ + assert(src != NULL); + + // An empty byte_array_t is the failure signal; the caller drops the indication. + if (valid_ind_msg(src) == false) + return (byte_array_t){0}; + + libe3_e2sm_dapp_ind_msg_t in = {0}; + + if (src->format == FORMAT_1_E2SM_DAPP_IND_MSG) { + in.format = LIBE3_E2SM_DAPP_IND_MSG_FORMAT_1; + in.frmt_1.data = (libe3_e2sm_dapp_bytes_t){.data = src->frmt_1.data, .len = src->frmt_1.data_size}; + } else { + in.format = LIBE3_E2SM_DAPP_IND_MSG_FORMAT_2; + in.frmt_2.dapp_e3_subscriptions = borrow_subs(&src->frmt_2.dapp_e3_subs); + } + + libe3_e2sm_dapp_bytes_t out = {0}; + e3_error_t rc = libe3_e2sm_dapp_encode_ind_msg(&in, &out); + free(in.frmt_2.dapp_e3_subscriptions.items); + + /* A message that does not encode is one we cannot send, not a reason to take the + * RAN down with us. */ + if (rc != E3_SUCCESS) { + printf("[E2SM-DAPP]: IndicationMessage could not be encoded (error %d), dropping\n", (int)rc); + return (byte_array_t){0}; + } + + return (byte_array_t){.len = out.len, .buf = out.data}; +} + +byte_array_t dapp_enc_ctrl_hdr_asn(e2sm_dapp_ctrl_hdr_t const* src) +{ + assert(src != NULL); + assert(src->format == FORMAT_1_E2SM_DAPP_CTRL_HDR && "Unknown format"); + + e2sm_dapp_ctrl_hdr_frmt_1_t const* f = &src->frmt_1; + libe3_e2sm_dapp_ctrl_hdr_t in = {.format = LIBE3_E2SM_DAPP_CTRL_HDR_FORMAT_1, + .ran_function_id = f->ran_function_id, + .dapp_id = f->dapp_id, + /* 0 means absent, see dapp_enc_ind_hdr_asn. */ + .has_timestamp = f->timestamp_ns != 0, + .timestamp = f->timestamp_ns, + .has_sequence_id = f->sequence_id != 0, + .sequence_id = f->sequence_id}; + + libe3_e2sm_dapp_bytes_t out = {0}; + e3_error_t rc = libe3_e2sm_dapp_encode_ctrl_hdr(&in, &out); + return take_encoded(rc, out); +} + +byte_array_t dapp_enc_ctrl_msg_asn(e2sm_dapp_ctrl_msg_t const* src) +{ + assert(src != NULL); + assert(src->format == FORMAT_1_E2SM_DAPP_CTRL_MSG && "Unknown format type"); + assert(src->frmt_1.data_size > 0); + assert(src->frmt_1.data != NULL); + + libe3_e2sm_dapp_ctrl_msg_t in = {.format = LIBE3_E2SM_DAPP_CTRL_MSG_FORMAT_1, + .data = {.data = src->frmt_1.data, .len = src->frmt_1.data_size}}; + + libe3_e2sm_dapp_bytes_t out = {0}; + e3_error_t rc = libe3_e2sm_dapp_encode_ctrl_msg(&in, &out); + return take_encoded(rc, out); +} + +byte_array_t dapp_enc_ctrl_out_asn(e2sm_dapp_ctrl_out_t const* src) +{ + assert(src != NULL); + assert(src->format == FORMAT_1_E2SM_DAPP_CTRL_OUT && "Unknown format"); + + e2sm_dapp_ctrl_out_frmt_1_t const* f = &src->frmt_1; + libe3_e2sm_dapp_ctrl_outcome_t in = {.format = LIBE3_E2SM_DAPP_CTRL_OUTCOME_FORMAT_1, + /* 0 means absent, see dapp_enc_ind_hdr_asn. */ + .has_timestamp = f->timestamp_ns != 0, + .timestamp = f->timestamp_ns, + .has_sequence_id = f->sequence_id != 0, + .sequence_id = f->sequence_id}; + + /* OPTIONAL: absent when the outcome only acknowledges the control. */ + if (f->e3_control_outcome != NULL && f->e3_control_outcome_size > 0) { + in.has_e3_control_outcome = true; + in.e3_control_outcome = (libe3_e2sm_dapp_bytes_t){.data = f->e3_control_outcome, .len = f->e3_control_outcome_size}; + } + + libe3_e2sm_dapp_bytes_t out = {0}; + e3_error_t rc = libe3_e2sm_dapp_encode_ctrl_outcome(&in, &out); + return take_encoded(rc, out); +} + +byte_array_t dapp_enc_func_def_asn(e2sm_dapp_func_def_t const* src) +{ + assert(src != NULL); + + libe3_e2sm_dapp_ran_function_definition_t in = {0}; + + in.name.short_name = borrow_ba(src->name.name); + in.name.e2sm_oid = borrow_ba(src->name.oid); + in.name.description = borrow_ba(src->name.description); + if (src->name.instance != NULL) { + in.name.has_instance = true; + in.name.instance = *src->name.instance; + } + + in.has_event_trigger = src->ev_trig != NULL; + + if (src->report != NULL) { + in.has_report = true; + in.n_report_styles = src->report->sz_seq_report_sty; + if (in.n_report_styles > 0) { + in.report_styles = calloc(in.n_report_styles, sizeof(*in.report_styles)); + assert(in.report_styles != NULL && "Memory exhausted"); + } + + for (size_t i = 0; i < in.n_report_styles; ++i) { + seq_report_sty_dapp_sm_t const* ir = &src->report->seq_report_sty[i]; + in.report_styles[i] = (libe3_e2sm_dapp_report_style_t){.report_style_type = ir->report_type, + .name = borrow_ba(ir->name), + .ind_hdr_format_type = ir->ind_hdr_type, + .ind_msg_format_type = ir->ind_msg_type}; + if (ir->dapp_e3_subs != NULL) { + in.report_styles[i].has_dapp_e3_subscriptions = true; + in.report_styles[i].dapp_e3_subscriptions = borrow_subs(ir->dapp_e3_subs); + } + } + } + + if (src->ctrl != NULL) { + in.has_ctrl = true; + in.n_ctrl_styles = src->ctrl->sz_seq_ctrl_style; + if (in.n_ctrl_styles > 0) { + in.ctrl_styles = calloc(in.n_ctrl_styles, sizeof(*in.ctrl_styles)); + assert(in.ctrl_styles != NULL && "Memory exhausted"); + } + + for (size_t i = 0; i < in.n_ctrl_styles; ++i) { + seq_ctrl_style_dapp_sm_t const* ir = &src->ctrl->seq_ctrl_style[i]; + in.ctrl_styles[i] = (libe3_e2sm_dapp_ctrl_style_t){.ctrl_style_type = ir->style_type, + .name = borrow_ba(ir->name), + .ctrl_hdr_format_type = ir->hdr, + .ctrl_msg_format_type = ir->msg, + .ctrl_outcome_format_type = ir->out_frmt}; + if (ir->dapp_e3_subs != NULL) { + in.ctrl_styles[i].has_dapp_e3_subscriptions = true; + in.ctrl_styles[i].dapp_e3_subscriptions = borrow_subs(ir->dapp_e3_subs); + } + } + } + + libe3_e2sm_dapp_bytes_t out = {0}; + e3_error_t rc = libe3_e2sm_dapp_encode_ran_function_definition(&in, &out); + + for (size_t i = 0; i < in.n_report_styles; ++i) + free(in.report_styles[i].dapp_e3_subscriptions.items); + free(in.report_styles); + for (size_t i = 0; i < in.n_ctrl_styles; ++i) + free(in.ctrl_styles[i].dapp_e3_subscriptions.items); + free(in.ctrl_styles); + + return take_encoded(rc, out); +} diff --git a/src/sm/dapp_sm/enc/dapp_enc_asn.h b/src/sm/dapp_sm/enc/dapp_enc_asn.h new file mode 100644 index 000000000..3c76d9848 --- /dev/null +++ b/src/sm/dapp_sm/enc/dapp_enc_asn.h @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef DAPP_ENCRYPTIOIN_ASN_H +#define DAPP_ENCRYPTIOIN_ASN_H + +#include "../../../util/byte_array.h" +#include "../ie/dapp_data_ie.h" + +typedef struct { +} dapp_enc_asn_t; + +__attribute__((visibility("default"))) byte_array_t dapp_enc_event_trigger_asn(e2sm_dapp_event_trigger_t const* event_trigger); + +__attribute__((visibility("default"))) byte_array_t dapp_enc_action_def_asn(e2sm_dapp_action_def_t const* action_def); + +__attribute__((visibility("default"))) byte_array_t dapp_enc_ind_hdr_asn(e2sm_dapp_ind_hdr_t const*); + +__attribute__((visibility("default"))) byte_array_t dapp_enc_ind_msg_asn(e2sm_dapp_ind_msg_t const*); + +__attribute__((visibility("default"))) byte_array_t dapp_enc_ctrl_hdr_asn(e2sm_dapp_ctrl_hdr_t const*); + +__attribute__((visibility("default"))) byte_array_t dapp_enc_ctrl_msg_asn(e2sm_dapp_ctrl_msg_t const*); + +__attribute__((visibility("default"))) byte_array_t dapp_enc_ctrl_out_asn(e2sm_dapp_ctrl_out_t const*); + +__attribute__((visibility("default"))) byte_array_t dapp_enc_func_def_asn(e2sm_dapp_func_def_t const*); + +#endif diff --git a/src/sm/dapp_sm/enc/dapp_enc_generic.h b/src/sm/dapp_sm/enc/dapp_enc_generic.h new file mode 100644 index 000000000..1edc6167e --- /dev/null +++ b/src/sm/dapp_sm/enc/dapp_enc_generic.h @@ -0,0 +1,22 @@ +#ifndef DAPP_ENCODE_GENERIC_H +#define DAPP_ENCODE_GENERIC_H + +#include "dapp_enc_asn.h" + +#define dapp_enc_event_trigger(T, U) _Generic((T), dapp_enc_asn_t *: dapp_enc_event_trigger_asn)(U) + +#define dapp_enc_action_def(T, U) _Generic((T), dapp_enc_asn_t *: dapp_enc_action_def_asn)(U) + +#define dapp_enc_ind_hdr(T, U) _Generic((T), dapp_enc_asn_t *: dapp_enc_ind_hdr_asn)(U) + +#define dapp_enc_ind_msg(T, U) _Generic((T), dapp_enc_asn_t *: dapp_enc_ind_msg_asn)(U) + +#define dapp_enc_ctrl_hdr(T, U) _Generic((T), dapp_enc_asn_t *: dapp_enc_ctrl_hdr_asn)(U) + +#define dapp_enc_ctrl_msg(T, U) _Generic((T), dapp_enc_asn_t *: dapp_enc_ctrl_msg_asn)(U) + +#define dapp_enc_ctrl_out(T, U) _Generic((T), dapp_enc_asn_t *: dapp_enc_ctrl_out_asn)(U) + +#define dapp_enc_func_def(T, U) _Generic((T), dapp_enc_asn_t *: dapp_enc_func_def_asn)(U) + +#endif diff --git a/src/sm/dapp_sm/ie/dapp_data_ie.c b/src/sm/dapp_sm/ie/dapp_data_ie.c new file mode 100644 index 000000000..3f25191ab --- /dev/null +++ b/src/sm/dapp_sm/ie/dapp_data_ie.c @@ -0,0 +1,766 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "dapp_data_ie.h" + +#include +#include +#include + +////////////////////////////////////// +// RIC Event Trigger Definition +///////////////////////////////////// + +void free_e2sm_dapp_event_trigger(e2sm_dapp_event_trigger_t* src) +{ + assert(src != NULL); + + if (src->format == FORMAT_1_E2SM_DAPP_EV_TRIGGER_FORMAT) { + free_e2sm_dapp_ev_trg_frmt_1(&src->frmt_1); + + } else { + assert(0 != 0 && "Not implemented"); + } +} + +bool eq_e2sm_dapp_event_trigger(e2sm_dapp_event_trigger_t const* m0, e2sm_dapp_event_trigger_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->format == FORMAT_1_E2SM_DAPP_EV_TRIGGER_FORMAT) { + return eq_e2sm_dapp_ev_trg_frmt_1(&m0->frmt_1, &m1->frmt_1); + + } else { + assert(0 != 0 && "Not implemented"); + } + + assert(0 != 0 && "Impossible path"); + return false; +} + +e2sm_dapp_event_trigger_t cp_e2sm_dapp_event_trigger(e2sm_dapp_event_trigger_t const* src) +{ + assert(src != NULL); + + e2sm_dapp_event_trigger_t dst = {0}; + dst.format = src->format; + + if (src->format == FORMAT_1_E2SM_DAPP_EV_TRIGGER_FORMAT) { + dst.frmt_1 = cp_e2sm_dapp_ev_trg_frmt_1(&src->frmt_1); + + } else { + assert(0 != 0 && "Not implemented"); + } + + return dst; +} + +////////////////////////////////////// +// RIC Action Definition +///////////////////////////////////// + +void free_e2sm_dapp_action_def(e2sm_dapp_action_def_t* src) +{ + assert(src != NULL); + + if (src->format == FORMAT_1_E2SM_DAPP_ACTION_DEF) { + free_e2sm_dapp_action_def_frmt_1(&src->frmt_1); + } else { + assert(0 != 0 && "Unknown format"); + } +} + +e2sm_dapp_action_def_t cp_e2sm_dapp_action_def(e2sm_dapp_action_def_t const* src) +{ + assert(src != NULL); + + e2sm_dapp_action_def_t dst = {0}; + dst.format = src->format; + dst.ric_style_type = src->ric_style_type; + + if (src->format == FORMAT_1_E2SM_DAPP_ACTION_DEF) { + dst.frmt_1 = cp_e2sm_dapp_action_def_frmt_1(&src->frmt_1); + } else { + assert(0 != 0 && "Unknown format"); + } + + return dst; +} + +bool eq_e2sm_dapp_action_def(e2sm_dapp_action_def_t const* m0, e2sm_dapp_action_def_t const* m1) +{ + if (m0 == m1) + return true; + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->format != m1->format) + return false; + if (m0->ric_style_type != m1->ric_style_type) + return false; + + if (m0->format == FORMAT_1_E2SM_DAPP_ACTION_DEF) { + return eq_e2sm_dapp_action_def_frmt_1(&m0->frmt_1, &m1->frmt_1); + } else { + assert(0 != 0 && "Unknown format"); + } + + return false; +} + +////////////////////////////////////// +// RIC Indication Header +///////////////////////////////////// + +void free_e2sm_dapp_ind_hdr(e2sm_dapp_ind_hdr_t* src) +{ + assert(src != NULL); + + if (src->format == FORMAT_1_E2SM_DAPP_IND_HDR) { + free_e2sm_dapp_ind_hdr_frmt_1(&src->frmt_1); + + } else if (src->format == FORMAT_2_E2SM_DAPP_IND_HDR) { + free_e2sm_dapp_ind_hdr_frmt_2(&src->frmt_2); + + } else { + assert(0 != 0 && "Unknown type"); + } +} + +e2sm_dapp_ind_hdr_t cp_e2sm_dapp_ind_hdr(e2sm_dapp_ind_hdr_t const* src) +{ + assert(src != NULL); + e2sm_dapp_ind_hdr_t dst = {.format = src->format}; + + if (src->format == FORMAT_1_E2SM_DAPP_IND_HDR) { + dst.frmt_1 = cp_e2sm_dapp_ind_hdr_frmt_1(&src->frmt_1); + + } else if (src->format == FORMAT_2_E2SM_DAPP_IND_HDR) { + dst.frmt_2 = cp_e2sm_dapp_ind_hdr_frmt_2(&src->frmt_2); + + } else { + assert(0 != 0 && "Unknown type"); + } + + return dst; +} + +bool eq_e2sm_dapp_ind_hdr(e2sm_dapp_ind_hdr_t const* m0, e2sm_dapp_ind_hdr_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->format != m1->format) + return false; + + if (m0->format == FORMAT_1_E2SM_DAPP_IND_HDR) { + return eq_e2sm_dapp_ind_hdr_frmt_1(&m0->frmt_1, &m1->frmt_1); + + } else if (m0->format == FORMAT_2_E2SM_DAPP_IND_HDR) { + return eq_e2sm_dapp_ind_hdr_frmt_2(&m0->frmt_2, &m1->frmt_2); + + } else { + assert(0 != 0 && "Unknown format"); + } + + assert(0 != 0 && "Not implemented"); + + return true; +} + +////////////////////////////////////// +// RIC Indication Message +///////////////////////////////////// + +void free_e2sm_dapp_ind_msg(e2sm_dapp_ind_msg_t* src) +{ + assert(src != NULL); + + if (src->format == FORMAT_1_E2SM_DAPP_IND_MSG) { + free_e2sm_dapp_ind_msg_frmt_1(&src->frmt_1); + + } else if (src->format == FORMAT_2_E2SM_DAPP_IND_MSG) { + free_e2sm_dapp_ind_msg_frmt_2(&src->frmt_2); + + } else { + assert(0 != 0 && "Unknown format"); + } +} + +e2sm_dapp_ind_msg_t cp_e2sm_dapp_ind_msg(e2sm_dapp_ind_msg_t const* src) +{ + assert(src != NULL); + + e2sm_dapp_ind_msg_t dst = {.format = src->format}; + + if (src->format == FORMAT_1_E2SM_DAPP_IND_MSG) { + dst.frmt_1 = cp_e2sm_dapp_ind_msg_frmt_1(&src->frmt_1); + + } else if (src->format == FORMAT_2_E2SM_DAPP_IND_MSG) { + dst.frmt_2 = cp_e2sm_dapp_ind_msg_frmt_2(&src->frmt_2); + } else { + assert(0 != 0 && "Unknown format"); + } + + return dst; +} + +bool eq_e2sm_dapp_ind_msg(e2sm_dapp_ind_msg_t const* m0, e2sm_dapp_ind_msg_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->format != m1->format) + return false; + + if (m0->format == FORMAT_1_E2SM_DAPP_IND_MSG) { + return eq_e2sm_dapp_ind_msg_frmt_1(&m0->frmt_1, &m1->frmt_1); + + } else if (m0->format == FORMAT_2_E2SM_DAPP_IND_MSG) { + return eq_e2sm_dapp_ind_msg_frmt_2(&m0->frmt_2, &m1->frmt_2); + + } else { + assert(0 != 0 && "Unknown format"); + } + + assert(0 != 0 && "Impossible path"); + + return true; +} + +////////////////////////////////////// +// RIC Control Header +///////////////////////////////////// + +void free_e2sm_dapp_ctrl_hdr(e2sm_dapp_ctrl_hdr_t* src) +{ + assert(src != NULL); + if (src->format == FORMAT_1_E2SM_DAPP_CTRL_HDR) { + free_e2sm_dapp_ctrl_hdr_frmt_1(&src->frmt_1); + + } else { + assert(0 != 0 && "Unknown type"); + } +} + +e2sm_dapp_ctrl_hdr_t cp_e2sm_dapp_ctrl_hdr(e2sm_dapp_ctrl_hdr_t const* src) +{ + assert(src != NULL); + e2sm_dapp_ctrl_hdr_t dst = {.format = src->format}; + + if (dst.format == FORMAT_1_E2SM_DAPP_CTRL_HDR) { + dst.frmt_1 = cp_e2sm_dapp_ctrl_hdr_frmt_1(&src->frmt_1); + + } else { + assert(0 != 0 && "Unknown format type"); + } + + return dst; +} + +bool eq_e2sm_dapp_ctrl_hdr(e2sm_dapp_ctrl_hdr_t const* m0, e2sm_dapp_ctrl_hdr_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->format != m1->format) + return false; + + if (m0->format == FORMAT_1_E2SM_DAPP_CTRL_HDR) { + if (eq_e2sm_dapp_ctrl_hdr_frmt_1(&m0->frmt_1, &m1->frmt_1) == false) + return false; + + } else { + assert(0 != 0 && "Unknown type"); + } + + return true; +} + +////////////////////////////////////// +// RIC Control Message +///////////////////////////////////// + +void free_e2sm_dapp_ctrl_msg(e2sm_dapp_ctrl_msg_t* src) +{ + assert(src != NULL); + + if (src->format == FORMAT_1_E2SM_DAPP_CTRL_MSG) { + free_e2sm_dapp_ctrl_msg_frmt_1(&src->frmt_1); + + } else { + assert(0 && "Unknown format"); + } +} + +e2sm_dapp_ctrl_msg_t cp_e2sm_dapp_ctrl_msg(e2sm_dapp_ctrl_msg_t const* src) +{ + assert(src != NULL); + + e2sm_dapp_ctrl_msg_t dst = {.format = src->format}; + + if (src->format == FORMAT_1_E2SM_DAPP_CTRL_MSG) { + dst.frmt_1 = cp_e2sm_dapp_ctrl_msg_frmt_1(&src->frmt_1); + + } else { + assert(0 != 0 && "Unknown format"); + } + + return dst; + ; +} + +bool eq_e2sm_dapp_ctrl_msg(e2sm_dapp_ctrl_msg_t const* m0, e2sm_dapp_ctrl_msg_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->format != m1->format) + return false; + + if (m0->format == FORMAT_1_E2SM_DAPP_CTRL_MSG) { + if (eq_e2sm_dapp_ctrl_msg_frmt_1(&m0->frmt_1, &m1->frmt_1) == false) + return false; + + } else { + assert(0 && "Unknown format"); + } + + return true; +} + +////////////////////////////////////// +// RIC Control Outcome +///////////////////////////////////// + +void free_e2sm_dapp_ctrl_out(e2sm_dapp_ctrl_out_t* src) +{ + assert(src != NULL); + + if (src->format == FORMAT_1_E2SM_DAPP_CTRL_OUT) { + free_e2sm_dapp_ctrl_out_frmt_1(&src->frmt_1); + + } else { + assert(0 != 0 && "Unknown format"); + } +} + +e2sm_dapp_ctrl_out_t cp_e2sm_dapp_ctrl_out(e2sm_dapp_ctrl_out_t const* src) +{ + assert(src != NULL); + + e2sm_dapp_ctrl_out_t dst = {.format = src->format}; + + if (dst.format == FORMAT_1_E2SM_DAPP_CTRL_OUT) { + dst.frmt_1 = cp_e2sm_dapp_ctrl_out_frmt_1(&src->frmt_1); + + } else { + assert(0 != 0 && "Unknown format"); + } + + return dst; +} + +bool eq_e2sm_dapp_ctrl_out(e2sm_dapp_ctrl_out_t const* m0, e2sm_dapp_ctrl_out_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->format != m1->format) + return false; + + if (m0->format == FORMAT_1_E2SM_DAPP_CTRL_OUT) { + if (eq_e2sm_dapp_ctrl_out_frmt_1(&m0->frmt_1, &m1->frmt_1) == false) + return false; + + } else { + assert(0 != 0 && "Unknown format"); + } + + return true; +} + +////////////////////////////////////// +// RAN Function Definition +///////////////////////////////////// + +void free_e2sm_dapp_func_def(e2sm_dapp_func_def_t* src) +{ + assert(src != NULL); + // RAN Function Name + free_ran_function_name(&src->name); + + // RAN Function Definition for EVENT TRIGGER + if (src->ev_trig != NULL) { + free_ran_func_def_ev_trig_dapp_sm(src->ev_trig); + free(src->ev_trig); + } + + // RAN Function Definition for REPORT + if (src->report != NULL) { + free_ran_func_def_report_dapp_sm(src->report); + free(src->report); + } + + // RAN Function Definition for CONTROL + if (src->ctrl != NULL) { + free_ran_func_def_ctrl_dapp_sm(src->ctrl); + free(src->ctrl); + } +} + +e2sm_dapp_func_def_t cp_e2sm_dapp_func_def(e2sm_dapp_func_def_t const* src) +{ + assert(src != NULL); + + e2sm_dapp_func_def_t dst = {0}; + + // RAN Function Name + dst.name = cp_ran_function_name(&src->name); + + // RAN Function Definition for EVENT TRIGGER + if (src->ev_trig != NULL) { + dst.ev_trig = calloc(1, sizeof(ran_func_def_ev_trig_dapp_sm_t)); + assert(dst.ev_trig != NULL && "Memory exhausted"); + *dst.ev_trig = cp_ran_func_def_ev_trig_dapp_sm(src->ev_trig); + } + + // RAN Function Definition for REPORT + if (src->report != NULL) { + dst.report = calloc(1, sizeof(ran_func_def_report_dapp_sm_t)); + assert(dst.report != NULL && "Memory exhausted"); + *dst.report = cp_ran_func_def_report_dapp_sm(src->report); + } + + // RAN Function Definition for CONTROL + if (src->ctrl != NULL) { + dst.ctrl = calloc(1, sizeof(ran_func_def_ctrl_dapp_sm_t)); + assert(dst.ctrl != NULL && "Memory exhausted"); + *dst.ctrl = cp_ran_func_def_ctrl_dapp_sm(src->ctrl); + } + + return dst; +} + +bool eq_e2sm_dapp_func_def(e2sm_dapp_func_def_t const* m0, e2sm_dapp_func_def_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + // RAN Function Name + if (eq_ran_function_name(&m0->name, &m1->name) == false) + return false; + + // RAN Function Definition for EVENT TRIGGER + if (eq_ran_func_def_ev_trig_dapp_sm(m0->ev_trig, m1->ev_trig) == false) + return false; + + // RAN Function Definition for REPORT + if (eq_ran_func_def_report_dapp_sm(m0->report, m1->report) == false) + return false; + + // RAN Function Definition for CONTROL + if (eq_ran_func_def_ctrl_dapp_sm(m0->ctrl, m1->ctrl) == false) + return false; + + return true; +} + +/////////////// +/// RIC Subscription +/////////////// + +void free_dapp_sub_data(dapp_sub_data_t* src) +{ + assert(src != NULL); + free_e2sm_dapp_event_trigger(&src->et); + + if (src->action_def != NULL) { + free_e2sm_dapp_action_def(src->action_def); + free(src->action_def); + } +} + +bool eq_dapp_sub_data(dapp_sub_data_t const* m0, dapp_sub_data_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (eq_e2sm_dapp_event_trigger(&m0->et, &m1->et) == false) + return false; + + return true; +} + +dapp_sub_data_t cp_dapp_sub_data(dapp_sub_data_t const* src) +{ + assert(src != NULL); + dapp_sub_data_t dst = {0}; + + dst.et = cp_e2sm_dapp_event_trigger(&src->et); + + return dst; +} + +/////////////// +// RIC Indication +/////////////// + +void free_dapp_ind_data(dapp_ind_data_t* ind) +{ + assert(ind != NULL); + + free_e2sm_dapp_ind_hdr(&ind->hdr); + free_e2sm_dapp_ind_msg(&ind->msg); + free_dapp_e3_ind_payload(&ind->e3); +} + +bool eq_dapp_ind_data(dapp_ind_data_t const* m0, dapp_ind_data_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (eq_e2sm_dapp_ind_hdr(&m0->hdr, &m1->hdr) == false) { + assert(0 != 0 && "Debug hdr"); + return false; + } + + if (eq_e2sm_dapp_ind_msg(&m0->msg, &m1->msg) == false) { + assert(0 != 0 && "Debug msg"); + return false; + } + + if (eq_dapp_e3_ind_payload(&m0->e3, &m1->e3) == false) { + assert(0 != 0 && "Debug msg"); + return false; + } + + return true; +} + +dapp_ind_data_t cp_dapp_ind_data(dapp_ind_data_t const* src) +{ + assert(src != NULL); + dapp_ind_data_t dst = {0}; + + dst.hdr = cp_e2sm_dapp_ind_hdr(&src->hdr); + dst.msg = cp_e2sm_dapp_ind_msg(&src->msg); + dst.e3 = cp_dapp_e3_ind_payload(&src->e3); + + assert(eq_dapp_ind_data(src, &dst) == true); + + return dst; +} + +/////////////// +// RIC Control +/////////////// + +void free_dapp_ctrl_req_data(dapp_ctrl_req_data_t* src) +{ + assert(src != NULL); + + free_e2sm_dapp_ctrl_hdr(&src->hdr); + free_e2sm_dapp_ctrl_msg(&src->msg); + free_dapp_e3_ctrl_payload(&src->e3); +} + +bool eq_dapp_ctrl_req_data(dapp_ctrl_req_data_t const* m0, dapp_ctrl_req_data_t const* m1) +{ + if (m0 == m1) + return true; + + if (!m0 || !m1) + return false; + + if (!eq_e2sm_dapp_ctrl_hdr(&m0->hdr, &m1->hdr)) + return false; + + if (!eq_e2sm_dapp_ctrl_msg(&m0->msg, &m1->msg)) + return false; + + if (!eq_dapp_e3_ctrl_payload(&m0->e3, &m1->e3)) + return false; + + return true; +} + +dapp_ctrl_req_data_t cp_dapp_ctrl_req_data(dapp_ctrl_req_data_t const* src) +{ + assert(src != NULL); + dapp_ctrl_req_data_t dst = {0}; + + dst.hdr = cp_e2sm_dapp_ctrl_hdr(&src->hdr); + dst.msg = cp_e2sm_dapp_ctrl_msg(&src->msg); + dst.e3 = cp_dapp_e3_ctrl_payload(&src->e3); + + assert(eq_dapp_ctrl_req_data(src, &dst) == true); + return dst; +} + +////////////////////////////////////// +// DAPP E3 Indication Payload +///////////////////////////////////// + +void free_dapp_e3_ind_payload(dapp_e3_ind_payload_t* src) +{ + assert(src != NULL); + + switch (src->type) { + case DAPP_E3_SM_SPECTRUM: + free_spectrum_sm_report(&src->u.spectrum); + break; + + case DAPP_E3_SM_NONE: + default: + break; + } + + src->type = DAPP_E3_SM_NONE; +} + +dapp_e3_ind_payload_t cp_dapp_e3_ind_payload(dapp_e3_ind_payload_t const* src) +{ + assert(src != NULL); + dapp_e3_ind_payload_t dst = {0}; + + dst.type = src->type; + + switch (src->type) { + case DAPP_E3_SM_SPECTRUM: + dst.u.spectrum = cp_spectrum_sm_report(&src->u.spectrum); + break; + + case DAPP_E3_SM_NONE: + default: + break; + } + + return dst; +} + +bool eq_dapp_e3_ind_payload(dapp_e3_ind_payload_t const* m0, dapp_e3_ind_payload_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->type != m1->type) + return false; + + switch (m0->type) { + case DAPP_E3_SM_NONE: + break; + + case DAPP_E3_SM_SPECTRUM: + if (!eq_spectrum_sm_report(&m0->u.spectrum, &m1->u.spectrum)) + return false; + break; + + default: + assert(0 != 0 && "Unknown DAPP E3 SM type"); + return false; + } + + return true; +} + +////////////////////////////////////// +// DAPP E3 Control Payload +///////////////////////////////////// + +void free_dapp_e3_ctrl_payload(dapp_e3_ctrl_payload_t* src) +{ + assert(src != NULL); + + switch (src->type) { + case DAPP_E3_SM_SPECTRUM: + free_spectrum_sm_control(&src->u.spectrum); + break; + + case DAPP_E3_SM_NONE: + default: + break; + } + + src->type = DAPP_E3_SM_NONE; +} + +dapp_e3_ctrl_payload_t cp_dapp_e3_ctrl_payload(dapp_e3_ctrl_payload_t const* src) +{ + assert(src != NULL); + dapp_e3_ctrl_payload_t dst = {0}; + + dst.type = src->type; + + switch (src->type) { + case DAPP_E3_SM_SPECTRUM: + dst.u.spectrum = cp_spectrum_sm_control(&src->u.spectrum); + break; + + case DAPP_E3_SM_NONE: + default: + break; + } + + return dst; +} + +bool eq_dapp_e3_ctrl_payload(dapp_e3_ctrl_payload_t const* m0, dapp_e3_ctrl_payload_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->type != m1->type) + return false; + + switch (m0->type) { + case DAPP_E3_SM_NONE: + break; + + case DAPP_E3_SM_SPECTRUM: + if (!eq_spectrum_sm_control(&m0->u.spectrum, &m1->u.spectrum)) + return false; + break; + + default: + assert(0 != 0 && "Unknown DAPP E3 SM type"); + return false; + } + + return true; +} \ No newline at end of file diff --git a/src/sm/dapp_sm/ie/dapp_data_ie.h b/src/sm/dapp_sm/ie/dapp_data_ie.h new file mode 100644 index 000000000..f3bda9580 --- /dev/null +++ b/src/sm/dapp_sm/ie/dapp_data_ie.h @@ -0,0 +1,396 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef DAPP_DATA_INFORMATION_ELEMENTS_H +#define DAPP_DATA_INFORMATION_ELEMENTS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +////////////////////////////////////// +// DAPP inner E3 service model types +////////////////////////////////////// + +#include "../e3/service_models/spectrum_sm/ir/spectrum_report.h" + +#include "../e3/service_models/spectrum_sm/ir/spectrum_control.h" + +///////////////////////////////////// +// dApp Subscription Info +///////////////////////////////////// + +#include "ir/dapp_e3_subscription_list.h" + +////////////////////////////////////// +// RIC Event Trigger Definition +///////////////////////////////////// + +#include "ir/e2sm_dapp_ev_trg_frmt_1.h" + +///////////////////////////////////// +// RIC Action Definition +///////////////////////////////////// + +#include "ir/e2sm_dapp_action_def.h" + +///////////////////////////////////// +// RIC Indication Header +///////////////////////////////////// + +#include "ir/e2sm_dapp_ind_hdr_frmt_1.h" +#include "ir/e2sm_dapp_ind_hdr_frmt_2.h" + +///////////////////////////////////// +// RIC Indication Message +///////////////////////////////////// + +#include "ir/e2sm_dapp_ind_msg_frmt_1.h" +#include "ir/e2sm_dapp_ind_msg_frmt_2.h" + +///////////////////////////////////// +// RIC Control Header +///////////////////////////////////// + +#include "ir/e2sm_dapp_ctrl_hdr_frmt_1.h" + +///////////////////////////////////// +// RIC Control Message +///////////////////////////////////// + +#include "ir/e2sm_dapp_ctrl_msg_frmt_1.h" + +///////////////////////////////////// +// RIC Control Outcome +///////////////////////////////////// + +#include "ir/e2sm_dapp_ctrl_out_frmt_1.h" + +///////////////////////////////////// +// RAN Function Definition +///////////////////////////////////// + +#include "../../../lib/sm/ie/ran_function_name.h" +#include "ir/ran_func_def_ev_trig.h" +#include "ir/ran_func_def_report.h" +#include "ir/ran_func_def_ctrl.h" + +////////////////////////////////////// +// DAPP inner E3 service model types +////////////////////////////////////// + +typedef enum { DAPP_E3_SM_NONE = 0, DAPP_E3_SM_SPECTRUM = 1 } dapp_e3_sm_type_e; + +typedef struct { + dapp_e3_sm_type_e type; + + union { + spectrum_sm_report_t spectrum; // for DAPP_E3_SM_SPECTRUM + } u; +} dapp_e3_ind_payload_t; + +__attribute__((visibility("default"))) void free_dapp_e3_ind_payload(dapp_e3_ind_payload_t* src); + +__attribute__((visibility("default"))) dapp_e3_ind_payload_t cp_dapp_e3_ind_payload(dapp_e3_ind_payload_t const* src); + +__attribute__((visibility("default"))) bool eq_dapp_e3_ind_payload(dapp_e3_ind_payload_t const* m0, + dapp_e3_ind_payload_t const* m1); + +typedef struct { + dapp_e3_sm_type_e type; + + union { + spectrum_sm_control_t spectrum; // for DAPP_E3_SM_SPECTRUM + } u; + +} dapp_e3_ctrl_payload_t; + +__attribute__((visibility("default"))) void free_dapp_e3_ctrl_payload(dapp_e3_ctrl_payload_t* src); + +__attribute__((visibility("default"))) dapp_e3_ctrl_payload_t cp_dapp_e3_ctrl_payload(dapp_e3_ctrl_payload_t const* src); + +__attribute__((visibility("default"))) bool eq_dapp_e3_ctrl_payload(dapp_e3_ctrl_payload_t const* m0, + dapp_e3_ctrl_payload_t const* m1); + +////////////////////////////////////// +// RIC Event Trigger Definition +///////////////////////////////////// + +typedef enum { + FORMAT_1_E2SM_DAPP_EV_TRIGGER_FORMAT, + END_E2SM_DAPP_EV_TRIGGER_FORMAT + +} e2sm_dapp_ev_trigger_format_e; + +typedef struct { + e2sm_dapp_ev_trigger_format_e format; + + union { + e2sm_dapp_ev_trg_frmt_1_t frmt_1; + }; +} e2sm_dapp_event_trigger_t; + +void free_e2sm_dapp_event_trigger(e2sm_dapp_event_trigger_t* src); + +e2sm_dapp_event_trigger_t cp_e2sm_dapp_event_trigger(e2sm_dapp_event_trigger_t const* src); + +bool eq_e2sm_dapp_event_trigger(e2sm_dapp_event_trigger_t const* m0, e2sm_dapp_event_trigger_t const* m1); + +////////////////////////////////////// +// RIC Action Definition +///////////////////////////////////// + +typedef enum { + FORMAT_1_E2SM_DAPP_ACTION_DEF, + END_E2SM_DAPP_ACTION_DEF + +} e2sm_dapp_action_def_format_e; + +typedef struct { + e2sm_dapp_action_def_format_e format; + uint32_t ric_style_type; + + union { + e2sm_dapp_action_def_frmt_1_t frmt_1; + }; +} e2sm_dapp_action_def_t; + +void free_e2sm_dapp_action_def(e2sm_dapp_action_def_t* src); + +e2sm_dapp_action_def_t cp_e2sm_dapp_action_def(e2sm_dapp_action_def_t const* src); + +bool eq_e2sm_dapp_action_def(e2sm_dapp_action_def_t const* m0, e2sm_dapp_action_def_t const* m1); + +////////////////////////////////////// +// RIC Indication Header +///////////////////////////////////// + +typedef enum { + FORMAT_1_E2SM_DAPP_IND_HDR, + FORMAT_2_E2SM_DAPP_IND_HDR, + END_E2SM_DAPP_IND_HDR + +} e2sm_dapp_ind_hdr_format_e; + +typedef struct { + e2sm_dapp_ind_hdr_format_e format; + + union { + e2sm_dapp_ind_hdr_frmt_1_t frmt_1; + e2sm_dapp_ind_hdr_frmt_2_t frmt_2; + }; +} e2sm_dapp_ind_hdr_t; + +__attribute__((visibility("default"))) void free_e2sm_dapp_ind_hdr(e2sm_dapp_ind_hdr_t* src); + +e2sm_dapp_ind_hdr_t cp_e2sm_dapp_ind_hdr(e2sm_dapp_ind_hdr_t const* src); + +bool eq_e2sm_dapp_ind_hdr(e2sm_dapp_ind_hdr_t const* m0, e2sm_dapp_ind_hdr_t const* m1); + +////////////////////////////////////// +// RIC Indication Message +///////////////////////////////////// + +typedef enum { + FORMAT_1_E2SM_DAPP_IND_MSG, + FORMAT_2_E2SM_DAPP_IND_MSG, + END_E2SM_DAPP_IND_MSG + +} e2sm_dapp_ind_msg_format_e; + +typedef struct { + e2sm_dapp_ind_msg_format_e format; + + union { + e2sm_dapp_ind_msg_frmt_1_t frmt_1; + e2sm_dapp_ind_msg_frmt_2_t frmt_2; + }; + +} e2sm_dapp_ind_msg_t; + +__attribute__((visibility("default"))) void free_e2sm_dapp_ind_msg(e2sm_dapp_ind_msg_t* src); + +e2sm_dapp_ind_msg_t cp_e2sm_dapp_ind_msg(e2sm_dapp_ind_msg_t const* src); + +bool eq_e2sm_dapp_ind_msg(e2sm_dapp_ind_msg_t const* m0, e2sm_dapp_ind_msg_t const* m1); + +////////////////////////////////////// +// RIC Control Header +///////////////////////////////////// + +typedef enum { + FORMAT_1_E2SM_DAPP_CTRL_HDR, + END_E2SM_DAPP_CTRL_HDR + +} e2sm_dapp_ctrl_hdr_e; + +typedef struct { + e2sm_dapp_ctrl_hdr_e format; + + union { + e2sm_dapp_ctrl_hdr_frmt_1_t frmt_1; + }; +} e2sm_dapp_ctrl_hdr_t; + +void free_e2sm_dapp_ctrl_hdr(e2sm_dapp_ctrl_hdr_t* src); + +e2sm_dapp_ctrl_hdr_t cp_e2sm_dapp_ctrl_hdr(e2sm_dapp_ctrl_hdr_t const* src); + +bool eq_e2sm_dapp_ctrl_hdr(e2sm_dapp_ctrl_hdr_t const* m0, e2sm_dapp_ctrl_hdr_t const* m1); + +////////////////////////////////////// +// RIC Control Message +///////////////////////////////////// + +typedef enum { + FORMAT_1_E2SM_DAPP_CTRL_MSG, + END_E2SM_DAPP_CTRL_MSG + +} e2sm_dapp_ctrl_msg_e; + +typedef struct { + e2sm_dapp_ctrl_msg_e format; + + union { + e2sm_dapp_ctrl_msg_frmt_1_t frmt_1; + }; +} e2sm_dapp_ctrl_msg_t; + +void free_e2sm_dapp_ctrl_msg(e2sm_dapp_ctrl_msg_t* src); + +e2sm_dapp_ctrl_msg_t cp_e2sm_dapp_ctrl_msg(e2sm_dapp_ctrl_msg_t const* src); + +bool eq_e2sm_dapp_ctrl_msg(e2sm_dapp_ctrl_msg_t const* m0, e2sm_dapp_ctrl_msg_t const* m1); + +////////////////////////////////////// +// RIC Control Outcome +///////////////////////////////////// + +typedef enum { + FORMAT_1_E2SM_DAPP_CTRL_OUT, + END_E2SM_DAPP_CTRL_OUT + +} e2sm_dapp_ctrl_out_e; + +typedef struct { + e2sm_dapp_ctrl_out_e format; + + union { + e2sm_dapp_ctrl_out_frmt_1_t frmt_1; + }; +} e2sm_dapp_ctrl_out_t; + +void free_e2sm_dapp_ctrl_out(e2sm_dapp_ctrl_out_t* src); + +e2sm_dapp_ctrl_out_t cp_e2sm_dapp_ctrl_out(e2sm_dapp_ctrl_out_t const* src); + +bool eq_e2sm_dapp_ctrl_out(e2sm_dapp_ctrl_out_t const* m0, e2sm_dapp_ctrl_out_t const* m1); + +////////////////////////////////////// +// RAN Function Definition +///////////////////////////////////// + +typedef enum { + DAPP_RIC_STYLE_E3_DATA_REPORT = 1, + DAPP_RIC_STYLE_E3_SUBSCRIPTION_MAP = 2, +} dapp_ric_style_type_e; + +typedef struct { + // RAN Function Name + ran_function_name_t name; + + // RAN Function Definition for EVENT TRIGGER + ran_func_def_ev_trig_dapp_sm_t* ev_trig; + + // RAN Function Definition for REPORT + ran_func_def_report_dapp_sm_t* report; + + // RAN Function Definition for CONTROL + ran_func_def_ctrl_dapp_sm_t* ctrl; + +} e2sm_dapp_func_def_t; + +__attribute__((visibility("default"))) void free_e2sm_dapp_func_def(e2sm_dapp_func_def_t* src); + +e2sm_dapp_func_def_t cp_e2sm_dapp_func_def(e2sm_dapp_func_def_t const* src); + +bool eq_e2sm_dapp_func_def(e2sm_dapp_func_def_t const* m0, e2sm_dapp_func_def_t const* m1); + +///////////////////////////////////////////////// + +/////////////// +/// RIC Subscription +/////////////// + +typedef struct { + e2sm_dapp_event_trigger_t et; + e2sm_dapp_action_def_t* action_def; +} dapp_sub_data_t; + +void free_dapp_sub_data(dapp_sub_data_t* ind); + +bool eq_dapp_sub_data(dapp_sub_data_t const* m0, dapp_sub_data_t const* m1); + +dapp_sub_data_t cp_dapp_sub_data(dapp_sub_data_t const* src); + +/////////////// +// RIC Indication +/////////////// + +typedef struct { + e2sm_dapp_ind_hdr_t hdr; + e2sm_dapp_ind_msg_t msg; + dapp_e3_ind_payload_t e3; +} dapp_ind_data_t; + +void free_dapp_ind_data(dapp_ind_data_t* ind); + +bool eq_dapp_ind_data(dapp_ind_data_t const* m0, dapp_ind_data_t const* m1); + +dapp_ind_data_t cp_dapp_ind_data(dapp_ind_data_t const* src); + +/////////////// +// RIC Control +/////////////// + +typedef struct { + e2sm_dapp_ctrl_hdr_t hdr; + e2sm_dapp_ctrl_msg_t msg; + dapp_e3_ctrl_payload_t e3; +} dapp_ctrl_req_data_t; + +void free_dapp_ctrl_req_data(dapp_ctrl_req_data_t* src); + +bool eq_dapp_ctrl_req_data(dapp_ctrl_req_data_t const* m0, dapp_ctrl_req_data_t const* m1); + +dapp_ctrl_req_data_t cp_dapp_ctrl_req_data(dapp_ctrl_req_data_t const* src); + +typedef struct { + e2sm_dapp_ctrl_out_t* out; +} dapp_ctrl_out_data_t; + +/////////////// +// E2 Setup +/////////////// + +typedef struct { + e2sm_dapp_func_def_t ran_func_def; +} dapp_e2_setup_t; + +/////////////// +// RIC Service Update +/////////////// + +typedef struct { + e2sm_dapp_func_def_t func_def; +} dapp_ric_service_update_t; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/sm/dapp_sm/ie/ir/CMakeLists.txt b/src/sm/dapp_sm/ie/ir/CMakeLists.txt new file mode 100644 index 000000000..6dcef5591 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/CMakeLists.txt @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: LicenseRef-CSSL-1.0 + +set (IR_DAPP_SRC + dapp_e3_subscription_item.c + dapp_e3_subscription_list.c + e2sm_dapp_ctrl_hdr_frmt_1.c + e2sm_dapp_ctrl_msg_frmt_1.c + e2sm_dapp_ctrl_out_frmt_1.c + e2sm_dapp_ev_trg_frmt_1.c + e2sm_dapp_action_def.c + e2sm_dapp_ind_hdr_frmt_1.c + e2sm_dapp_ind_hdr_frmt_2.c + e2sm_dapp_ind_msg_frmt_1.c + e2sm_dapp_ind_msg_frmt_2.c + ran_func_def_ctrl.c + ran_func_def_ev_trig.c + ran_func_def_report.c + seq_ctrl_style.c + seq_report_sty.c + ) + +add_library(e2sm_dapp_ir_obj OBJECT ${IR_DAPP_SRC}) +target_include_directories(e2sm_dapp_ir_obj + PUBLIC + "$" + ) + +target_compile_options(e2sm_dapp_ir_obj PRIVATE -Wno-missing-field-initializers -Wno-unused-parameter -fPIC -fvisibility=hidden ) + + diff --git a/src/sm/dapp_sm/ie/ir/dapp_e3_subscription_item.c b/src/sm/dapp_sm/ie/ir/dapp_e3_subscription_item.c new file mode 100644 index 000000000..cfce864e0 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/dapp_e3_subscription_item.c @@ -0,0 +1,57 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "dapp_e3_subscription_item.h" + +#include +#include + +void free_dapp_e3_subscription_item(dapp_e3_subscription_item_t* src) +{ + assert(src != NULL); + free(src->subscribed_e3_ran_functions); + src->subscribed_e3_ran_functions = NULL; + src->sz_subscribed_e3_ran_functions = 0; +} + +bool eq_dapp_e3_subscription_item(dapp_e3_subscription_item_t const* m0, dapp_e3_subscription_item_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->dapp_id != m1->dapp_id) + return false; + + if (m0->sz_subscribed_e3_ran_functions != m1->sz_subscribed_e3_ran_functions) + return false; + + for (size_t i = 0; i < m0->sz_subscribed_e3_ran_functions; ++i) { + if (m0->subscribed_e3_ran_functions[i] != m1->subscribed_e3_ran_functions[i]) + return false; + } + + return true; +} + +dapp_e3_subscription_item_t cp_dapp_e3_subscription_item(dapp_e3_subscription_item_t const* src) +{ + assert(src != NULL); + dapp_e3_subscription_item_t dst = {0}; + + dst.dapp_id = src->dapp_id; + dst.sz_subscribed_e3_ran_functions = src->sz_subscribed_e3_ran_functions; + + if (src->sz_subscribed_e3_ran_functions > 0) { + assert(src->sz_subscribed_e3_ran_functions < 64); + size_t sz = src->sz_subscribed_e3_ran_functions * sizeof(uint32_t); + dst.subscribed_e3_ran_functions = malloc(sz); + assert(dst.subscribed_e3_ran_functions != NULL && "Memory exhausted"); + memcpy(dst.subscribed_e3_ran_functions, src->subscribed_e3_ran_functions, sz); + } + + return dst; +} \ No newline at end of file diff --git a/src/sm/dapp_sm/ie/ir/dapp_e3_subscription_item.h b/src/sm/dapp_sm/ie/ir/dapp_e3_subscription_item.h new file mode 100644 index 000000000..c5be6d012 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/dapp_e3_subscription_item.h @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef DAPP_SUBSCRIPTION_ITEM_H +#define DAPP_SUBSCRIPTION_ITEM_H + +#include +#include +#include + +typedef struct { + uint32_t dapp_id; + size_t sz_subscribed_e3_ran_functions; + uint32_t* subscribed_e3_ran_functions; +} dapp_e3_subscription_item_t; + +void free_dapp_e3_subscription_item(dapp_e3_subscription_item_t* src); + +bool eq_dapp_e3_subscription_item(dapp_e3_subscription_item_t const* m0, dapp_e3_subscription_item_t const* m1); + +dapp_e3_subscription_item_t cp_dapp_e3_subscription_item(dapp_e3_subscription_item_t const* src); + +#endif \ No newline at end of file diff --git a/src/sm/dapp_sm/ie/ir/dapp_e3_subscription_list.c b/src/sm/dapp_sm/ie/ir/dapp_e3_subscription_list.c new file mode 100644 index 000000000..a9ef47dfc --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/dapp_e3_subscription_list.c @@ -0,0 +1,55 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "dapp_e3_subscription_list.h" + +#include + +void free_dapp_e3_subscription_list(dapp_e3_subscription_list_t* src) +{ + assert(src != NULL); + assert(src->sz_dapp_e3_subscriptions > 0 && src->sz_dapp_e3_subscriptions < 256); + for (size_t i = 0; i < src->sz_dapp_e3_subscriptions; ++i) { + free_dapp_e3_subscription_item(&src->dapp_e3_subscriptions[i]); + } + free(src->dapp_e3_subscriptions); + src->dapp_e3_subscriptions = NULL; + src->sz_dapp_e3_subscriptions = 0; +} + +bool eq_dapp_e3_subscription_list(dapp_e3_subscription_list_t const* m0, dapp_e3_subscription_list_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->sz_dapp_e3_subscriptions != m1->sz_dapp_e3_subscriptions) + return false; + + for (size_t i = 0; i < m0->sz_dapp_e3_subscriptions; ++i) { + if (eq_dapp_e3_subscription_item(&m0->dapp_e3_subscriptions[i], &m1->dapp_e3_subscriptions[i]) == false) + return false; + } + + return true; +} + +dapp_e3_subscription_list_t cp_dapp_e3_subscription_list(dapp_e3_subscription_list_t const* src) +{ + assert(src != NULL); + dapp_e3_subscription_list_t dst = {0}; + assert(src->sz_dapp_e3_subscriptions > 0 && src->sz_dapp_e3_subscriptions < 256); + + dst.sz_dapp_e3_subscriptions = src->sz_dapp_e3_subscriptions; + dst.dapp_e3_subscriptions = calloc(dst.sz_dapp_e3_subscriptions, sizeof(dapp_e3_subscription_item_t)); + assert(dst.dapp_e3_subscriptions != NULL && "Memory exhausted"); + + for (size_t i = 0; i < src->sz_dapp_e3_subscriptions; ++i) { + dst.dapp_e3_subscriptions[i] = cp_dapp_e3_subscription_item(&src->dapp_e3_subscriptions[i]); + } + + return dst; +} \ No newline at end of file diff --git a/src/sm/dapp_sm/ie/ir/dapp_e3_subscription_list.h b/src/sm/dapp_sm/ie/ir/dapp_e3_subscription_list.h new file mode 100644 index 000000000..a63d50cac --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/dapp_e3_subscription_list.h @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef DAPP_E3_SUBSCRIPTION_LIST_H +#define DAPP_E3_SUBSCRIPTION_LIST_H + +#include "dapp_e3_subscription_item.h" + +#include +#include + +typedef struct { + size_t sz_dapp_e3_subscriptions; + dapp_e3_subscription_item_t* dapp_e3_subscriptions; +} dapp_e3_subscription_list_t; + +void free_dapp_e3_subscription_list(dapp_e3_subscription_list_t* src); + +bool eq_dapp_e3_subscription_list(dapp_e3_subscription_list_t const* m0, dapp_e3_subscription_list_t const* m1); + +dapp_e3_subscription_list_t cp_dapp_e3_subscription_list(dapp_e3_subscription_list_t const* src); + +#endif \ No newline at end of file diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_action_def.c b/src/sm/dapp_sm/ie/ir/e2sm_dapp_action_def.c new file mode 100644 index 000000000..e16798f72 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_action_def.c @@ -0,0 +1,29 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "e2sm_dapp_action_def.h" +#include + +void free_e2sm_dapp_action_def_frmt_1(e2sm_dapp_action_def_frmt_1_t* src) +{ + assert(src != NULL); + // All fields are value types — nothing heap-allocated to free. +} + +bool eq_e2sm_dapp_action_def_frmt_1(e2sm_dapp_action_def_frmt_1_t const* m0, e2sm_dapp_action_def_frmt_1_t const* m1) +{ + if (m0 == m1) + return true; + if (m0 == NULL || m1 == NULL) + return false; + + return true; +} + +e2sm_dapp_action_def_frmt_1_t cp_e2sm_dapp_action_def_frmt_1(e2sm_dapp_action_def_frmt_1_t const* src) +{ + assert(src != NULL); + e2sm_dapp_action_def_frmt_1_t dst = {}; + return dst; +} \ No newline at end of file diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_action_def.h b/src/sm/dapp_sm/ie/ir/e2sm_dapp_action_def.h new file mode 100644 index 000000000..1539a6133 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_action_def.h @@ -0,0 +1,21 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef E2SM_DAPP_ACTION_DEFINITION_H +#define E2SM_DAPP_ACTION_DEFINITION_H + +#include +#include +#include + +typedef struct { +} e2sm_dapp_action_def_frmt_1_t; + +void free_e2sm_dapp_action_def_frmt_1(e2sm_dapp_action_def_frmt_1_t* src); + +bool eq_e2sm_dapp_action_def_frmt_1(e2sm_dapp_action_def_frmt_1_t const* m0, e2sm_dapp_action_def_frmt_1_t const* m1); + +e2sm_dapp_action_def_frmt_1_t cp_e2sm_dapp_action_def_frmt_1(e2sm_dapp_action_def_frmt_1_t const* src); + +#endif \ No newline at end of file diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_hdr_frmt_1.c b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_hdr_frmt_1.c new file mode 100644 index 000000000..b3fd7514a --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_hdr_frmt_1.c @@ -0,0 +1,37 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "e2sm_dapp_ctrl_hdr_frmt_1.h" +#include +#include + +void free_e2sm_dapp_ctrl_hdr_frmt_1(e2sm_dapp_ctrl_hdr_frmt_1_t* src) +{ + assert(src != NULL); +} + +bool eq_e2sm_dapp_ctrl_hdr_frmt_1(e2sm_dapp_ctrl_hdr_frmt_1_t const* m0, e2sm_dapp_ctrl_hdr_frmt_1_t const* m1) +{ + if (m0 == m1) + return true; + if (!m0 || !m1) + return false; + + return (m0->ran_function_id == m1->ran_function_id) && + (m0->dapp_id == m1->dapp_id) && + (m0->timestamp_ns == m1->timestamp_ns) && + (m0->sequence_id == m1->sequence_id); +} + +e2sm_dapp_ctrl_hdr_frmt_1_t cp_e2sm_dapp_ctrl_hdr_frmt_1(e2sm_dapp_ctrl_hdr_frmt_1_t const* src) +{ + assert(src != NULL); + + e2sm_dapp_ctrl_hdr_frmt_1_t dst; + dst.ran_function_id = src->ran_function_id; + dst.dapp_id = src->dapp_id; + dst.timestamp_ns = src->timestamp_ns; + dst.sequence_id = src->sequence_id; + return dst; +} diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_hdr_frmt_1.h b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_hdr_frmt_1.h new file mode 100644 index 000000000..17fde449c --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_hdr_frmt_1.h @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef E2SM_DAPP_CTRL_HDR_FRMT_1_E2SM_DAPP_H +#define E2SM_DAPP_CTRL_HDR_FRMT_1_E2SM_DAPP_H + +#include +#include +#include + +typedef struct { + uint32_t ran_function_id; + uint32_t dapp_id; + + /* Nanoseconds since the Unix epoch, from the realtime clock (time_now_ns). */ + int64_t timestamp_ns; + + /* Per-procedure correlation id assigned by the producer; 0 means none was + * assigned, same absent convention as timestamp_ns. */ + int64_t sequence_id; +} e2sm_dapp_ctrl_hdr_frmt_1_t; + +void free_e2sm_dapp_ctrl_hdr_frmt_1(e2sm_dapp_ctrl_hdr_frmt_1_t* src); + +bool eq_e2sm_dapp_ctrl_hdr_frmt_1(e2sm_dapp_ctrl_hdr_frmt_1_t const* m0, e2sm_dapp_ctrl_hdr_frmt_1_t const* m1); + +e2sm_dapp_ctrl_hdr_frmt_1_t cp_e2sm_dapp_ctrl_hdr_frmt_1(e2sm_dapp_ctrl_hdr_frmt_1_t const* src); + +#endif diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_msg_frmt_1.c b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_msg_frmt_1.c new file mode 100644 index 000000000..03a28cfe2 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_msg_frmt_1.c @@ -0,0 +1,54 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "e2sm_dapp_ctrl_msg_frmt_1.h" + +#include +#include +#include + +void free_e2sm_dapp_ctrl_msg_frmt_1(e2sm_dapp_ctrl_msg_frmt_1_t* src) +{ + assert(src != NULL); + if (src->data) { + free(src->data); + src->data = NULL; + } + src->data_size = 0; +} + +bool eq_e2sm_dapp_ctrl_msg_frmt_1(e2sm_dapp_ctrl_msg_frmt_1_t const* m0, e2sm_dapp_ctrl_msg_frmt_1_t const* m1) +{ + if (m0 == m1) + return true; + if (!m0 || !m1) + return false; + + if (m0->data_size != m1->data_size) + return false; + + if (m0->data_size == 0) + return true; + if (!m0->data || !m1->data) + return false; + + return memcmp(m0->data, m1->data, m0->data_size) == 0; +} + +e2sm_dapp_ctrl_msg_frmt_1_t cp_e2sm_dapp_ctrl_msg_frmt_1(e2sm_dapp_ctrl_msg_frmt_1_t const* src) +{ + assert(src != NULL); + + e2sm_dapp_ctrl_msg_frmt_1_t dst; + dst.data_size = src->data_size; + dst.data = NULL; + + if (src->data_size > 0 && src->data != NULL) { + dst.data = (uint8_t*)malloc(src->data_size); + assert(dst.data != NULL && "Memory exhausted in cp_e2sm_dapp_ctrl_msg_frmt_1"); + memcpy(dst.data, src->data, src->data_size); + } + + return dst; +} diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_msg_frmt_1.h b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_msg_frmt_1.h new file mode 100644 index 000000000..8886a70cf --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_msg_frmt_1.h @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef E2SM_DAPP_CTRL_MSG_FRMT_1_H +#define E2SM_DAPP_CTRL_MSG_FRMT_1_H + +#include +#include +#include + +typedef struct { + uint32_t data_size; + uint8_t* data; +} e2sm_dapp_ctrl_msg_frmt_1_t; + +void free_e2sm_dapp_ctrl_msg_frmt_1(e2sm_dapp_ctrl_msg_frmt_1_t* src); + +bool eq_e2sm_dapp_ctrl_msg_frmt_1(e2sm_dapp_ctrl_msg_frmt_1_t const* m0, e2sm_dapp_ctrl_msg_frmt_1_t const* m1); + +e2sm_dapp_ctrl_msg_frmt_1_t cp_e2sm_dapp_ctrl_msg_frmt_1(e2sm_dapp_ctrl_msg_frmt_1_t const* src); + +#endif diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_out_frmt_1.c b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_out_frmt_1.c new file mode 100644 index 000000000..e3e8ef98c --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_out_frmt_1.c @@ -0,0 +1,56 @@ +#include "e2sm_dapp_ctrl_out_frmt_1.h" + +#include +#include +#include + +void free_e2sm_dapp_ctrl_out_frmt_1(e2sm_dapp_ctrl_out_frmt_1_t* src) +{ + assert(src != NULL); + + if (src->e3_control_outcome != NULL) { + free(src->e3_control_outcome); + src->e3_control_outcome = NULL; + } + src->e3_control_outcome_size = 0; +} + +bool eq_e2sm_dapp_ctrl_out_frmt_1(e2sm_dapp_ctrl_out_frmt_1_t const* m0, e2sm_dapp_ctrl_out_frmt_1_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->timestamp_ns != m1->timestamp_ns || m0->sequence_id != m1->sequence_id) + return false; + + if (m0->e3_control_outcome_size != m1->e3_control_outcome_size) + return false; + + if (m0->e3_control_outcome_size == 0) + return true; + + if (m0->e3_control_outcome == NULL || m1->e3_control_outcome == NULL) + return m0->e3_control_outcome == m1->e3_control_outcome; + + return memcmp(m0->e3_control_outcome, m1->e3_control_outcome, m0->e3_control_outcome_size) == 0; +} + +e2sm_dapp_ctrl_out_frmt_1_t cp_e2sm_dapp_ctrl_out_frmt_1(e2sm_dapp_ctrl_out_frmt_1_t const* src) +{ + assert(src != NULL); + + e2sm_dapp_ctrl_out_frmt_1_t dst = {.timestamp_ns = src->timestamp_ns, + .sequence_id = src->sequence_id}; + + if (src->e3_control_outcome != NULL && src->e3_control_outcome_size > 0) { + dst.e3_control_outcome = malloc(src->e3_control_outcome_size); + assert(dst.e3_control_outcome != NULL && "Memory exhausted"); + memcpy(dst.e3_control_outcome, src->e3_control_outcome, src->e3_control_outcome_size); + dst.e3_control_outcome_size = src->e3_control_outcome_size; + } + + return dst; +} diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_out_frmt_1.h b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_out_frmt_1.h new file mode 100644 index 000000000..ddf4857af --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ctrl_out_frmt_1.h @@ -0,0 +1,30 @@ +#ifndef E2SM_DAPP_CTRL_OUT_FRMT_1_H +#define E2SM_DAPP_CTRL_OUT_FRMT_1_H + +#include +#include +#include + +typedef struct { + /* Nanoseconds since the Unix epoch, from the realtime clock (time_now_ns). */ + int64_t timestamp_ns; + + /* Per-procedure correlation id assigned by the producer; 0 means none was + * assigned, same absent convention as timestamp_ns. */ + int64_t sequence_id; + + /* The Service Model's own account of applying the control, encoded by the SM + * named by the control's ran_function_id and opaque here. Owned by this + * struct: freed by free_, deep-copied by cp_. NULL with size 0 when the + * outcome only acknowledges. */ + uint8_t* e3_control_outcome; + uint32_t e3_control_outcome_size; +} e2sm_dapp_ctrl_out_frmt_1_t; + +void free_e2sm_dapp_ctrl_out_frmt_1(e2sm_dapp_ctrl_out_frmt_1_t* src); + +e2sm_dapp_ctrl_out_frmt_1_t cp_e2sm_dapp_ctrl_out_frmt_1(e2sm_dapp_ctrl_out_frmt_1_t const* src); + +bool eq_e2sm_dapp_ctrl_out_frmt_1(e2sm_dapp_ctrl_out_frmt_1_t const* m0, e2sm_dapp_ctrl_out_frmt_1_t const* m1); + +#endif diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ev_trg_frmt_1.c b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ev_trg_frmt_1.c new file mode 100644 index 000000000..0feba84af --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ev_trg_frmt_1.c @@ -0,0 +1,32 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include + +#include "e2sm_dapp_ev_trg_frmt_1.h" + +void free_e2sm_dapp_ev_trg_frmt_1(e2sm_dapp_ev_trg_frmt_1_t* src) +{ + assert(src != NULL); +} + +bool eq_e2sm_dapp_ev_trg_frmt_1(e2sm_dapp_ev_trg_frmt_1_t const* m0, e2sm_dapp_ev_trg_frmt_1_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + return true; +} + +e2sm_dapp_ev_trg_frmt_1_t cp_e2sm_dapp_ev_trg_frmt_1(e2sm_dapp_ev_trg_frmt_1_t const* src) +{ + assert(src != NULL); + + e2sm_dapp_ev_trg_frmt_1_t dst = {}; + + return dst; +} diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ev_trg_frmt_1.h b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ev_trg_frmt_1.h new file mode 100644 index 000000000..006ba4936 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ev_trg_frmt_1.h @@ -0,0 +1,21 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef DAPP_EVENT_TRIGGER_FORMAT_1_SM_DAPP_SM_H +#define DAPP_EVENT_TRIGGER_FORMAT_1_SM_DAPP_SM_H + +#include +#include +#include + +typedef struct { +} e2sm_dapp_ev_trg_frmt_1_t; + +void free_e2sm_dapp_ev_trg_frmt_1(e2sm_dapp_ev_trg_frmt_1_t* src); + +bool eq_e2sm_dapp_ev_trg_frmt_1(e2sm_dapp_ev_trg_frmt_1_t const* m0, e2sm_dapp_ev_trg_frmt_1_t const* m1); + +e2sm_dapp_ev_trg_frmt_1_t cp_e2sm_dapp_ev_trg_frmt_1(e2sm_dapp_ev_trg_frmt_1_t const* src); + +#endif diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_hdr_frmt_1.c b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_hdr_frmt_1.c new file mode 100644 index 000000000..7235fb1ae --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_hdr_frmt_1.c @@ -0,0 +1,62 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "e2sm_dapp_ind_hdr_frmt_1.h" +#include + +void free_e2sm_dapp_ind_hdr_frmt_1(e2sm_dapp_ind_hdr_frmt_1_t* src) +{ + assert(src != NULL); + // All fields are value types — nothing heap-allocated to free. +} + +bool eq_e2sm_dapp_ind_hdr_frmt_1(e2sm_dapp_ind_hdr_frmt_1_t const* m0, e2sm_dapp_ind_hdr_frmt_1_t const* m1) +{ + if (m0 == m1) + return true; + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->ran_function_id != m1->ran_function_id) + return false; + if (m0->dapp_id != m1->dapp_id) + return false; + if (m0->node_type != m1->node_type) + return false; + if (memcmp(m0->node_plmn_id, m1->node_plmn_id, 3) != 0) + return false; + if (m0->node_nb_id != m1->node_nb_id) + return false; + + if (m0->node_cu_du_id_present != m1->node_cu_du_id_present) + return false; + if (m0->node_cu_du_id_present && m0->node_cu_du_id != m1->node_cu_du_id) + return false; + + if (m0->timestamp_ns != m1->timestamp_ns) + return false; + if (m0->sequence_id != m1->sequence_id) + return false; + + return true; +} + +e2sm_dapp_ind_hdr_frmt_1_t cp_e2sm_dapp_ind_hdr_frmt_1(e2sm_dapp_ind_hdr_frmt_1_t const* src) +{ + assert(src != NULL); + + e2sm_dapp_ind_hdr_frmt_1_t dst = { + .ran_function_id = src->ran_function_id, + .dapp_id = src->dapp_id, + .node_type = src->node_type, + .node_nb_id = src->node_nb_id, + .node_cu_du_id_present = src->node_cu_du_id_present, + .node_cu_du_id = src->node_cu_du_id, + .timestamp_ns = src->timestamp_ns, + .sequence_id = src->sequence_id, + }; + memcpy(dst.node_plmn_id, src->node_plmn_id, 3); + + return dst; +} diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_hdr_frmt_1.h b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_hdr_frmt_1.h new file mode 100644 index 000000000..c1a0bc2e9 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_hdr_frmt_1.h @@ -0,0 +1,39 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef E2SM_DAPP_INDICATION_HEADER_FORMAT_1_H +#define E2SM_DAPP_INDICATION_HEADER_FORMAT_1_H + +#include +#include +#include +#include + +typedef struct { + uint32_t ran_function_id; + uint32_t dapp_id; + + uint8_t node_type; + uint8_t node_plmn_id[3]; + uint32_t node_nb_id; + + bool node_cu_du_id_present; + uint64_t node_cu_du_id; + + /* Nanoseconds since the Unix epoch, from the realtime clock (time_now_ns). */ + int64_t timestamp_ns; + + /* Per-procedure correlation id assigned by the producer; 0 means none was + * assigned, same absent convention as timestamp_ns. */ + int64_t sequence_id; + +} e2sm_dapp_ind_hdr_frmt_1_t; + +e2sm_dapp_ind_hdr_frmt_1_t cp_e2sm_dapp_ind_hdr_frmt_1(e2sm_dapp_ind_hdr_frmt_1_t const* src); + +void free_e2sm_dapp_ind_hdr_frmt_1(e2sm_dapp_ind_hdr_frmt_1_t* src); + +bool eq_e2sm_dapp_ind_hdr_frmt_1(e2sm_dapp_ind_hdr_frmt_1_t const* m0, e2sm_dapp_ind_hdr_frmt_1_t const* m1); + +#endif diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_hdr_frmt_2.c b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_hdr_frmt_2.c new file mode 100644 index 000000000..7c762d79c --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_hdr_frmt_2.c @@ -0,0 +1,56 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "e2sm_dapp_ind_hdr_frmt_2.h" +#include + +void free_e2sm_dapp_ind_hdr_frmt_2(e2sm_dapp_ind_hdr_frmt_2_t* src) +{ + assert(src != NULL); + // All fields are value types — nothing heap-allocated to free. +} + +bool eq_e2sm_dapp_ind_hdr_frmt_2(e2sm_dapp_ind_hdr_frmt_2_t const* m0, e2sm_dapp_ind_hdr_frmt_2_t const* m1) +{ + if (m0 == m1) + return true; + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->node_type != m1->node_type) + return false; + if (memcmp(m0->node_plmn_id, m1->node_plmn_id, 3) != 0) + return false; + if (m0->node_nb_id != m1->node_nb_id) + return false; + + if (m0->node_cu_du_id_present != m1->node_cu_du_id_present) + return false; + if (m0->node_cu_du_id_present && m0->node_cu_du_id != m1->node_cu_du_id) + return false; + + if (m0->timestamp_ns != m1->timestamp_ns) + return false; + if (m0->sequence_id != m1->sequence_id) + return false; + + return true; +} + +e2sm_dapp_ind_hdr_frmt_2_t cp_e2sm_dapp_ind_hdr_frmt_2(e2sm_dapp_ind_hdr_frmt_2_t const* src) +{ + assert(src != NULL); + + e2sm_dapp_ind_hdr_frmt_2_t dst = { + .node_type = src->node_type, + .node_nb_id = src->node_nb_id, + .node_cu_du_id_present = src->node_cu_du_id_present, + .node_cu_du_id = src->node_cu_du_id, + .timestamp_ns = src->timestamp_ns, + .sequence_id = src->sequence_id, + }; + memcpy(dst.node_plmn_id, src->node_plmn_id, 3); + + return dst; +} \ No newline at end of file diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_hdr_frmt_2.h b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_hdr_frmt_2.h new file mode 100644 index 000000000..d60c9b052 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_hdr_frmt_2.h @@ -0,0 +1,36 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef E2SM_DAPP_INDICATION_HEADER_FORMAT_2_H +#define E2SM_DAPP_INDICATION_HEADER_FORMAT_2_H + +#include +#include +#include +#include + +typedef struct { + uint8_t node_type; + uint8_t node_plmn_id[3]; + uint32_t node_nb_id; + + bool node_cu_du_id_present; + uint64_t node_cu_du_id; + + /* Nanoseconds since the Unix epoch, from the realtime clock (time_now_ns). */ + int64_t timestamp_ns; + + /* Per-procedure correlation id assigned by the producer; 0 means none was + * assigned, same absent convention as timestamp_ns. */ + int64_t sequence_id; + +} e2sm_dapp_ind_hdr_frmt_2_t; + +e2sm_dapp_ind_hdr_frmt_2_t cp_e2sm_dapp_ind_hdr_frmt_2(e2sm_dapp_ind_hdr_frmt_2_t const* src); + +void free_e2sm_dapp_ind_hdr_frmt_2(e2sm_dapp_ind_hdr_frmt_2_t* src); + +bool eq_e2sm_dapp_ind_hdr_frmt_2(e2sm_dapp_ind_hdr_frmt_2_t const* m0, e2sm_dapp_ind_hdr_frmt_2_t const* m1); + +#endif diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_msg_frmt_1.c b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_msg_frmt_1.c new file mode 100644 index 000000000..c4b9f0e68 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_msg_frmt_1.c @@ -0,0 +1,60 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "e2sm_dapp_ind_msg_frmt_1.h" + +#include +#include + +void free_e2sm_dapp_ind_msg_frmt_1(e2sm_dapp_ind_msg_frmt_1_t* src) +{ + if (!src) + return; + + if (src->data) { + free(src->data); + src->data = NULL; + } + src->data_size = 0; +} + +bool eq_e2sm_dapp_ind_msg_frmt_1(e2sm_dapp_ind_msg_frmt_1_t const* m0, e2sm_dapp_ind_msg_frmt_1_t const* m1) +{ + if (m0 == m1) { + return true; + } + + if (!m0 || !m1) { + return false; + } + + if (m0->data_size != m1->data_size) { + return false; + } + + if (m0->data_size == 0) { + return true; + } + + if (!m0->data || !m1->data) { + return false; + } + + return memcmp(m0->data, m1->data, m0->data_size) == 0; +} + +e2sm_dapp_ind_msg_frmt_1_t cp_e2sm_dapp_ind_msg_frmt_1(e2sm_dapp_ind_msg_frmt_1_t const* src) +{ + assert(src); + + e2sm_dapp_ind_msg_frmt_1_t dst = {.data_size = src->data_size, .data = NULL}; + + if (src->data_size > 0) { + dst.data = malloc(src->data_size); + assert(dst.data); + memcpy(dst.data, src->data, src->data_size); + } + + return dst; +} diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_msg_frmt_1.h b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_msg_frmt_1.h new file mode 100644 index 000000000..85667691b --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_msg_frmt_1.h @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef E2SM_DAPP_INDICATION_MSG_FORMAT_1_H +#define E2SM_DAPP_INDICATION_MSG_FORMAT_1_H + +#include +#include +#include + +typedef struct { + size_t data_size; + uint8_t* data; +} e2sm_dapp_ind_msg_frmt_1_t; + +void free_e2sm_dapp_ind_msg_frmt_1(e2sm_dapp_ind_msg_frmt_1_t* src); + +bool eq_e2sm_dapp_ind_msg_frmt_1(e2sm_dapp_ind_msg_frmt_1_t const* m0, e2sm_dapp_ind_msg_frmt_1_t const* m1); + +e2sm_dapp_ind_msg_frmt_1_t cp_e2sm_dapp_ind_msg_frmt_1(e2sm_dapp_ind_msg_frmt_1_t const* src); + +#endif diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_msg_frmt_2.c b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_msg_frmt_2.c new file mode 100644 index 000000000..ea6b27880 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_msg_frmt_2.c @@ -0,0 +1,80 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "e2sm_dapp_ind_msg_frmt_2.h" + +#include +#include +#include + +void free_e2sm_dapp_ind_msg_frmt_2(e2sm_dapp_ind_msg_frmt_2_t* src) +{ + assert(src != NULL); + + for (size_t i = 0; i < src->dapp_e3_subs.sz_dapp_e3_subscriptions; i++) { + free(src->dapp_e3_subs.dapp_e3_subscriptions[i].subscribed_e3_ran_functions); + } + free(src->dapp_e3_subs.dapp_e3_subscriptions); +} + +bool eq_e2sm_dapp_ind_msg_frmt_2(e2sm_dapp_ind_msg_frmt_2_t const* m0, e2sm_dapp_ind_msg_frmt_2_t const* m1) +{ + if (m0 == m1) + return true; + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->dapp_e3_subs.sz_dapp_e3_subscriptions != m1->dapp_e3_subs.sz_dapp_e3_subscriptions) + return false; + + for (size_t i = 0; i < m0->dapp_e3_subs.sz_dapp_e3_subscriptions; i++) { + const dapp_e3_subscription_item_t* a = &m0->dapp_e3_subs.dapp_e3_subscriptions[i]; + const dapp_e3_subscription_item_t* b = &m1->dapp_e3_subs.dapp_e3_subscriptions[i]; + + if (a->dapp_id != b->dapp_id) + return false; + + if (a->sz_subscribed_e3_ran_functions != b->sz_subscribed_e3_ran_functions) + return false; + + for (size_t j = 0; j < a->sz_subscribed_e3_ran_functions; j++) { + if (a->subscribed_e3_ran_functions[j] != b->subscribed_e3_ran_functions[j]) + return false; + } + } + + return true; +} + +e2sm_dapp_ind_msg_frmt_2_t cp_e2sm_dapp_ind_msg_frmt_2(e2sm_dapp_ind_msg_frmt_2_t const* src) +{ + assert(src != NULL); + + e2sm_dapp_ind_msg_frmt_2_t dst = {0}; + + dst.dapp_e3_subs.sz_dapp_e3_subscriptions = src->dapp_e3_subs.sz_dapp_e3_subscriptions; + + if (src->dapp_e3_subs.sz_dapp_e3_subscriptions > 0) { + size_t n = src->dapp_e3_subs.sz_dapp_e3_subscriptions; + dst.dapp_e3_subs.dapp_e3_subscriptions = calloc(n, sizeof(dapp_e3_subscription_item_t)); + assert(dst.dapp_e3_subs.dapp_e3_subscriptions != NULL && "Memory exhausted"); + + for (size_t i = 0; i < n; i++) { + const dapp_e3_subscription_item_t* s = &src->dapp_e3_subs.dapp_e3_subscriptions[i]; + dapp_e3_subscription_item_t* d = &dst.dapp_e3_subs.dapp_e3_subscriptions[i]; + + d->dapp_id = s->dapp_id; + d->sz_subscribed_e3_ran_functions = s->sz_subscribed_e3_ran_functions; + + if (s->sz_subscribed_e3_ran_functions > 0) { + size_t sz = s->sz_subscribed_e3_ran_functions * sizeof(uint32_t); + d->subscribed_e3_ran_functions = malloc(sz); + assert(d->subscribed_e3_ran_functions != NULL && "Memory exhausted"); + memcpy(d->subscribed_e3_ran_functions, s->subscribed_e3_ran_functions, sz); + } + } + } + + return dst; +} diff --git a/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_msg_frmt_2.h b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_msg_frmt_2.h new file mode 100644 index 000000000..be328b913 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/e2sm_dapp_ind_msg_frmt_2.h @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef E2SM_DAPP_INDICATION_MSG_FORMAT_2_H +#define E2SM_DAPP_INDICATION_MSG_FORMAT_2_H + +#include +#include +#include + +#include "dapp_e3_subscription_list.h" + +typedef struct { + dapp_e3_subscription_list_t dapp_e3_subs; +} e2sm_dapp_ind_msg_frmt_2_t; + +void free_e2sm_dapp_ind_msg_frmt_2(e2sm_dapp_ind_msg_frmt_2_t* src); + +bool eq_e2sm_dapp_ind_msg_frmt_2(e2sm_dapp_ind_msg_frmt_2_t const* m0, e2sm_dapp_ind_msg_frmt_2_t const* m1); + +e2sm_dapp_ind_msg_frmt_2_t cp_e2sm_dapp_ind_msg_frmt_2(e2sm_dapp_ind_msg_frmt_2_t const* src); + +#endif diff --git a/src/sm/dapp_sm/ie/ir/ran_func_def_ctrl.c b/src/sm/dapp_sm/ie/ir/ran_func_def_ctrl.c new file mode 100644 index 000000000..64952be47 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/ran_func_def_ctrl.c @@ -0,0 +1,57 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "ran_func_def_ctrl.h" +#include + +void free_ran_func_def_ctrl_dapp_sm(ran_func_def_ctrl_dapp_sm_t* src) +{ + assert(src != NULL); + assert(src->sz_seq_ctrl_style > 0 && src->sz_seq_ctrl_style < 64); + for (size_t i = 0; i < src->sz_seq_ctrl_style; ++i) { + free_seq_ctrl_style_dapp_sm(&src->seq_ctrl_style[i]); + } + free(src->seq_ctrl_style); +} + +bool eq_ran_func_def_ctrl_dapp_sm(ran_func_def_ctrl_dapp_sm_t const* m0, ran_func_def_ctrl_dapp_sm_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + assert(m0->sz_seq_ctrl_style > 0 && m0->sz_seq_ctrl_style < 64); + assert(m1->sz_seq_ctrl_style > 0 && m1->sz_seq_ctrl_style < 64); + + if (m0->sz_seq_ctrl_style != m1->sz_seq_ctrl_style) + return false; + + for (size_t i = 0; i < m0->sz_seq_ctrl_style; ++i) { + if (eq_seq_ctrl_style_dapp_sm(&m0->seq_ctrl_style[i], &m1->seq_ctrl_style[i]) == false) + return false; + } + + return true; +} + +ran_func_def_ctrl_dapp_sm_t cp_ran_func_def_ctrl_dapp_sm(ran_func_def_ctrl_dapp_sm_t const* src) +{ + assert(src != NULL); + + ran_func_def_ctrl_dapp_sm_t dst = {0}; + + assert(src->sz_seq_ctrl_style > 0 && src->sz_seq_ctrl_style < 64); + dst.sz_seq_ctrl_style = src->sz_seq_ctrl_style; + + dst.seq_ctrl_style = calloc(dst.sz_seq_ctrl_style, sizeof(seq_ctrl_style_dapp_sm_t)); + assert(dst.seq_ctrl_style != NULL && "Memory exhausted"); + + for (size_t i = 0; i < dst.sz_seq_ctrl_style; ++i) { + dst.seq_ctrl_style[i] = cp_seq_ctrl_style_dapp_sm(&src->seq_ctrl_style[i]); + } + + return dst; +} diff --git a/src/sm/dapp_sm/ie/ir/ran_func_def_ctrl.h b/src/sm/dapp_sm/ie/ir/ran_func_def_ctrl.h new file mode 100644 index 000000000..662048ca0 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/ran_func_def_ctrl.h @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef RAN_FUNC_DEF_CTRL_DAPP_SM_H +#define RAN_FUNC_DEF_CTRL_DAPP_SM_H + +#include "seq_ctrl_style.h" + +#include + +typedef struct { + size_t sz_seq_ctrl_style; + seq_ctrl_style_dapp_sm_t* seq_ctrl_style; +} ran_func_def_ctrl_dapp_sm_t; + +void free_ran_func_def_ctrl_dapp_sm(ran_func_def_ctrl_dapp_sm_t* src); + +bool eq_ran_func_def_ctrl_dapp_sm(ran_func_def_ctrl_dapp_sm_t const* m0, ran_func_def_ctrl_dapp_sm_t const* m1); + +ran_func_def_ctrl_dapp_sm_t cp_ran_func_def_ctrl_dapp_sm(ran_func_def_ctrl_dapp_sm_t const* src); + +#endif diff --git a/src/sm/dapp_sm/ie/ir/ran_func_def_ev_trig.c b/src/sm/dapp_sm/ie/ir/ran_func_def_ev_trig.c new file mode 100644 index 000000000..d086c42bd --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/ran_func_def_ev_trig.c @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "ran_func_def_ev_trig.h" + +#include + +void free_ran_func_def_ev_trig_dapp_sm(ran_func_def_ev_trig_dapp_sm_t* src) +{ + assert(src != NULL); +} + +bool eq_ran_func_def_ev_trig_dapp_sm(ran_func_def_ev_trig_dapp_sm_t const* m0, ran_func_def_ev_trig_dapp_sm_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + return true; +} + +ran_func_def_ev_trig_dapp_sm_t cp_ran_func_def_ev_trig_dapp_sm(ran_func_def_ev_trig_dapp_sm_t const* src) +{ + assert(src != NULL); + ran_func_def_ev_trig_dapp_sm_t dst = {}; + return dst; +} \ No newline at end of file diff --git a/src/sm/dapp_sm/ie/ir/ran_func_def_ev_trig.h b/src/sm/dapp_sm/ie/ir/ran_func_def_ev_trig.h new file mode 100644 index 000000000..ac4efcb82 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/ran_func_def_ev_trig.h @@ -0,0 +1,20 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef RAN_FUNC_DEF_EV_TRIG_DAPP_SM_H +#define RAN_FUNC_DEF_EV_TRIG_DAPP_SM_H + +#include +#include + +typedef struct { +} ran_func_def_ev_trig_dapp_sm_t; + +void free_ran_func_def_ev_trig_dapp_sm(ran_func_def_ev_trig_dapp_sm_t* src); + +bool eq_ran_func_def_ev_trig_dapp_sm(ran_func_def_ev_trig_dapp_sm_t const* m0, ran_func_def_ev_trig_dapp_sm_t const* m1); + +ran_func_def_ev_trig_dapp_sm_t cp_ran_func_def_ev_trig_dapp_sm(ran_func_def_ev_trig_dapp_sm_t const* src); + +#endif diff --git a/src/sm/dapp_sm/ie/ir/ran_func_def_report.c b/src/sm/dapp_sm/ie/ir/ran_func_def_report.c new file mode 100644 index 000000000..04ddf38c5 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/ran_func_def_report.c @@ -0,0 +1,53 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "ran_func_def_report.h" + +#include + +void free_ran_func_def_report_dapp_sm(ran_func_def_report_dapp_sm_t* src) +{ + assert(src != NULL); + assert(src->sz_seq_report_sty > 0 && src->sz_seq_report_sty < 64); + for (size_t i = 0; i < src->sz_seq_report_sty; ++i) { + free_seq_report_sty_dapp_sm(&src->seq_report_sty[i]); + } + free(src->seq_report_sty); +} + +bool eq_ran_func_def_report_dapp_sm(ran_func_def_report_dapp_sm_t const* m0, ran_func_def_report_dapp_sm_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->sz_seq_report_sty != m1->sz_seq_report_sty) + return false; + + for (size_t i = 0; i < m0->sz_seq_report_sty; ++i) { + if (eq_seq_report_sty_dapp_sm(&m0->seq_report_sty[i], &m1->seq_report_sty[i]) == false) + return false; + } + + return true; +} + +ran_func_def_report_dapp_sm_t cp_ran_func_def_report_dapp_sm(ran_func_def_report_dapp_sm_t const* src) +{ + assert(src != NULL); + ran_func_def_report_dapp_sm_t dst = {0}; + assert(src->sz_seq_report_sty > 0 && src->sz_seq_report_sty < 64); + + dst.sz_seq_report_sty = src->sz_seq_report_sty; + dst.seq_report_sty = calloc(dst.sz_seq_report_sty, sizeof(seq_report_sty_dapp_sm_t)); + assert(dst.seq_report_sty != NULL && "Memory exhausted"); + + for (size_t i = 0; i < src->sz_seq_report_sty; ++i) { + dst.seq_report_sty[i] = cp_seq_report_sty_dapp_sm(&src->seq_report_sty[i]); + } + + return dst; +} diff --git a/src/sm/dapp_sm/ie/ir/ran_func_def_report.h b/src/sm/dapp_sm/ie/ir/ran_func_def_report.h new file mode 100644 index 000000000..1fbaada74 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/ran_func_def_report.h @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef RAN_FUNC_DEF_REPORT_DAPP_SM_H +#define RAN_FUNC_DEF_REPORT_DAPP_SM_H + +#include "seq_report_sty.h" + +#include +#include + +typedef struct { + size_t sz_seq_report_sty; + seq_report_sty_dapp_sm_t* seq_report_sty; +} ran_func_def_report_dapp_sm_t; + +void free_ran_func_def_report_dapp_sm(ran_func_def_report_dapp_sm_t* src); + +bool eq_ran_func_def_report_dapp_sm(ran_func_def_report_dapp_sm_t const* m0, ran_func_def_report_dapp_sm_t const* m1); + +ran_func_def_report_dapp_sm_t cp_ran_func_def_report_dapp_sm(ran_func_def_report_dapp_sm_t const* src); + +#endif diff --git a/src/sm/dapp_sm/ie/ir/seq_ctrl_style.c b/src/sm/dapp_sm/ie/ir/seq_ctrl_style.c new file mode 100644 index 000000000..c0f477cae --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/seq_ctrl_style.c @@ -0,0 +1,96 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "seq_ctrl_style.h" + +#include +#include + +void free_seq_ctrl_style_dapp_sm(seq_ctrl_style_dapp_sm_t* src) +{ + assert(src != NULL); + + if (src->name.buf != NULL) { + free(src->name.buf); + src->name.buf = NULL; + src->name.len = 0; + } + + if (src->dapp_e3_subs != NULL) { + free_dapp_e3_subscription_list(src->dapp_e3_subs); + free(src->dapp_e3_subs); + } +} + +bool eq_seq_ctrl_style_dapp_sm(seq_ctrl_style_dapp_sm_t const* m0, seq_ctrl_style_dapp_sm_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->style_type != m1->style_type) + return false; + + if (m0->name.len != m1->name.len) + return false; + + if (m0->name.len > 0) { + assert(m0->name.buf != NULL); + assert(m1->name.buf != NULL); + if (memcmp(m0->name.buf, m1->name.buf, m0->name.len) != 0) + return false; + } + + if (m0->hdr != m1->hdr) + return false; + + if (m0->msg != m1->msg) + return false; + + if (m0->out_frmt != m1->out_frmt) + return false; + + if (m0->dapp_e3_subs == NULL && m1->dapp_e3_subs == NULL) + return true; + + if (m0->dapp_e3_subs == NULL || m1->dapp_e3_subs == NULL) + return false; + + return eq_dapp_e3_subscription_list(m0->dapp_e3_subs, m1->dapp_e3_subs); +} + +seq_ctrl_style_dapp_sm_t cp_seq_ctrl_style_dapp_sm(seq_ctrl_style_dapp_sm_t const* src) +{ + assert(src != NULL); + + seq_ctrl_style_dapp_sm_t dst = {0}; + + dst.style_type = src->style_type; + + dst.name.len = src->name.len; + if (src->name.len > 0) { + assert(src->name.buf != NULL); + dst.name.buf = malloc(src->name.len); + assert(dst.name.buf != NULL && "Memory exhausted while copying name"); + memcpy(dst.name.buf, src->name.buf, src->name.len); + } else { + dst.name.buf = NULL; + } + + dst.hdr = src->hdr; + + dst.msg = src->msg; + + dst.out_frmt = src->out_frmt; + + if (src->dapp_e3_subs != NULL) { + dst.dapp_e3_subs = calloc(1, sizeof(dapp_e3_subscription_list_t)); + assert(dst.dapp_e3_subs != NULL && "Memory exhausted"); + *dst.dapp_e3_subs = cp_dapp_e3_subscription_list(src->dapp_e3_subs); + } + + return dst; +} diff --git a/src/sm/dapp_sm/ie/ir/seq_ctrl_style.h b/src/sm/dapp_sm/ie/ir/seq_ctrl_style.h new file mode 100644 index 000000000..a7aa11aea --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/seq_ctrl_style.h @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef SEQUENCE_CONTROL_STYLE_E2SM_DAPP_H +#define SEQUENCE_CONTROL_STYLE_E2SM_DAPP_H + +#include +#include +#include "../../../../util/byte_array.h" +#include "dapp_e3_subscription_list.h" + +typedef struct { + uint32_t style_type; + byte_array_t name; + uint32_t hdr; + uint32_t msg; + uint32_t out_frmt; + dapp_e3_subscription_list_t* dapp_e3_subs; +} seq_ctrl_style_dapp_sm_t; + +void free_seq_ctrl_style_dapp_sm(seq_ctrl_style_dapp_sm_t* src); + +bool eq_seq_ctrl_style_dapp_sm(seq_ctrl_style_dapp_sm_t const* m0, seq_ctrl_style_dapp_sm_t const* m1); + +seq_ctrl_style_dapp_sm_t cp_seq_ctrl_style_dapp_sm(seq_ctrl_style_dapp_sm_t const* src); + +#endif diff --git a/src/sm/dapp_sm/ie/ir/seq_report_sty.c b/src/sm/dapp_sm/ie/ir/seq_report_sty.c new file mode 100644 index 000000000..f86792b74 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/seq_report_sty.c @@ -0,0 +1,73 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "seq_report_sty.h" + +#include + +void free_seq_report_sty_dapp_sm(seq_report_sty_dapp_sm_t* src) +{ + assert(src != NULL); + assert(src->name.len > 0 && src->name.len < 151); + free_byte_array(src->name); + + if (src->dapp_e3_subs != NULL) { + free_dapp_e3_subscription_list(src->dapp_e3_subs); + free(src->dapp_e3_subs); + } +} + +seq_report_sty_dapp_sm_t cp_seq_report_sty_dapp_sm(seq_report_sty_dapp_sm_t const* src) +{ + assert(src != NULL); + seq_report_sty_dapp_sm_t dst = {0}; + + dst.report_type = src->report_type; + + assert(src->name.len > 0 && src->name.len < 151); + dst.name = copy_byte_array(src->name); + + dst.ind_hdr_type = src->ind_hdr_type; + + dst.ind_msg_type = src->ind_msg_type; + + if (src->dapp_e3_subs != NULL) { + dst.dapp_e3_subs = calloc(1, sizeof(dapp_e3_subscription_list_t)); + assert(dst.dapp_e3_subs != NULL && "Memory exhausted"); + *dst.dapp_e3_subs = cp_dapp_e3_subscription_list(src->dapp_e3_subs); + } + + return dst; +} + +bool eq_seq_report_sty_dapp_sm(seq_report_sty_dapp_sm_t const* m0, seq_report_sty_dapp_sm_t const* m1) +{ + if (m0 == m1) + return true; + + if (m0 == NULL || m1 == NULL) + return false; + + if (m0->report_type != m1->report_type) + return false; + + assert(m0->name.len > 0 && m0->name.len < 151); + assert(m1->name.len > 0 && m1->name.len < 151); + if (eq_byte_array(&m0->name, &m1->name) == false) + return false; + + if (m0->ind_hdr_type != m1->ind_hdr_type) + return false; + + if (m0->ind_msg_type != m1->ind_msg_type) + return false; + + if (m0->dapp_e3_subs == NULL && m1->dapp_e3_subs == NULL) + return true; + + if (m0->dapp_e3_subs == NULL || m1->dapp_e3_subs == NULL) + return false; + + return eq_dapp_e3_subscription_list(m0->dapp_e3_subs, m1->dapp_e3_subs); +} diff --git a/src/sm/dapp_sm/ie/ir/seq_report_sty.h b/src/sm/dapp_sm/ie/ir/seq_report_sty.h new file mode 100644 index 000000000..868f56645 --- /dev/null +++ b/src/sm/dapp_sm/ie/ir/seq_report_sty.h @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef SEQ_REPORT_STY_E2SM_DAPP_H +#define SEQ_REPORT_STY_E2SM_DAPP_H + +#include +#include +#include +#include "../../../../util/byte_array.h" +#include "dapp_e3_subscription_list.h" + +typedef struct { + uint32_t report_type; + byte_array_t name; + uint32_t ind_hdr_type; + uint32_t ind_msg_type; + dapp_e3_subscription_list_t* dapp_e3_subs; +} seq_report_sty_dapp_sm_t; + +void free_seq_report_sty_dapp_sm(seq_report_sty_dapp_sm_t* src); + +seq_report_sty_dapp_sm_t cp_seq_report_sty_dapp_sm(seq_report_sty_dapp_sm_t const* src); + +bool eq_seq_report_sty_dapp_sm(seq_report_sty_dapp_sm_t const* m0, seq_report_sty_dapp_sm_t const* m1); + +#endif diff --git a/src/util/time_now_us.c b/src/util/time_now_us.c index c74075a31..6470eef9d 100644 --- a/src/util/time_now_us.c +++ b/src/util/time_now_us.c @@ -29,4 +29,12 @@ int64_t time_now_us(void) return micros; } +int64_t time_now_ns(void) +{ + struct timespec tms; + if (clock_gettime(CLOCK_REALTIME, &tms)) { + return -1; + } + return (int64_t)tms.tv_sec * 1000000000 + tms.tv_nsec; +} diff --git a/src/util/time_now_us.h b/src/util/time_now_us.h index 3a63d5613..37f311e0a 100644 --- a/src/util/time_now_us.h +++ b/src/util/time_now_us.h @@ -5,5 +5,15 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + int64_t time_now_us(void); +int64_t time_now_ns(void); + +#ifdef __cplusplus +} +#endif + diff --git a/src/xApp/CMakeLists.txt b/src/xApp/CMakeLists.txt index 609bf29f0..638ae245d 100644 --- a/src/xApp/CMakeLists.txt +++ b/src/xApp/CMakeLists.txt @@ -83,6 +83,10 @@ set(XAPP_SRC ../sm/tc_sm/ie/tc_data_ie.c ../sm/gtp_sm/ie/gtp_data_ie.c ../sm/ccc_sm/ie/ccc_data_ie.c + ../sm/dapp_sm/ie/dapp_data_ie.c + + $ + $ ) @@ -105,6 +109,17 @@ if(E2AP_ENCODING STREQUAL "ASN") $ ) + # The shared xApp library pulls in the RC service model's decoders, which + # reference the NR RRC ASN.1 definitions. Without these, e42_xapp_shared + # links but cannot be loaded: dlopen fails on an undefined + # asn_DEF_NR_UL_DCCH_Message, which is what the SWIG binding hits. + target_link_libraries(e42_xapp_shared + PUBLIC + asn1_nr_rrc + sm_common_dec_asn_obj_rc + 3gpp_derived_ie_dec_asn_obj_rc + ) + target_compile_options(e42_xapp_shared PRIVATE "-DASN_DISABLE_OER_SUPPORT" -fPIC) if(E2AP_VERSION STREQUAL "E2AP_V1") diff --git a/src/xApp/db/sqlite3/sqlite3_wrapper.c b/src/xApp/db/sqlite3/sqlite3_wrapper.c index b3cef71ef..d1c2ee874 100644 --- a/src/xApp/db/sqlite3/sqlite3_wrapper.c +++ b/src/xApp/db/sqlite3/sqlite3_wrapper.c @@ -1653,7 +1653,7 @@ void write_db_sqlite3(sqlite3* db, global_e2_node_id_t const* id, sm_ag_if_rd_t assert(rd->type == MAC_STATS_V0 || rd->type == RLC_STATS_V0 || rd->type == PDCP_STATS_V0 || rd->type == SLICE_STATS_V0 || rd->type == KPM_STATS_V3_0 || rd->type == GTP_STATS_V0 - || rd->type == RAN_CTRL_STATS_V1_03 || rd->type == CCC_STATS_V6); + || rd->type == RAN_CTRL_STATS_V1_03 || rd->type == CCC_STATS_V6 || rd->type == DAPP_STATS_V0); if(rd->type == MAC_STATS_V0){ write_mac_stats(db, id, &rd->mac); @@ -1671,6 +1671,10 @@ void write_db_sqlite3(sqlite3* db, global_e2_node_id_t const* id, sm_ag_if_rd_t write_rc_stats(db, id, &rd->rc.ind); } else if (rd->type == CCC_STATS_V6) { write_ccc_stats(db, id, &rd->ccc); + } else if(rd->type == DAPP_STATS_V0){ + // The E2SM-DAPP indication relays an opaque dApp payload; there is no + // column layout for it. + } else { assert(0!=0 && "Unknown statistics type received "); } diff --git a/src/xApp/e42_xapp.c b/src/xApp/e42_xapp.c index 21edb0809..8d5eb6f35 100644 --- a/src/xApp/e42_xapp.c +++ b/src/xApp/e42_xapp.c @@ -32,6 +32,8 @@ #include "../sm/kpm_sm/kpm_sm_id_wrapper.h" #include "../sm/rc_sm/rc_sm_id.h" #include "../sm/ccc_sm/ccc_sm_id.h" +#include "../sm/dapp_sm/dapp_sm_id.h" + #include "../../test/rnd/fill_rnd_data_rc.h" #include "../../test/rnd/fill_rnd_data_kpm.h" @@ -141,6 +143,13 @@ void read_rc_e2_setup_xapp(void* data) // rc->ran_func_def = fill_rc_ran_func_def(); } +// Not needed when using E42 +static +void read_dapp_e2_setup_xapp(void* data) +{ + assert(data != NULL); +} + static sm_io_ag_ran_t init_io_ag_ran(void) { @@ -148,6 +157,7 @@ sm_io_ag_ran_t init_io_ag_ran(void) dst.read_setup_tbl[KPM_V3_0_AGENT_IF_E2_SETUP_ANS_V0] = read_kpm_e2setup_xapp; dst.read_setup_tbl[RAN_CTRL_V1_3_AGENT_IF_E2_SETUP_ANS_V0] = read_rc_e2_setup_xapp; + dst.read_setup_tbl[DAPP_AGENT_IF_E2_SETUP_ANS_V0] = read_dapp_e2_setup_xapp; return dst; } @@ -388,6 +398,7 @@ bool valid_ran_func_id(uint16_t ran_func_id)\ || ran_func_id == SM_KPM_ID || ran_func_id == SM_RC_ID || ran_func_id == SM_CCC_ID + || ran_func_id == SM_DAPP_ID ) return true; diff --git a/src/xApp/e42_xapp_api.c b/src/xApp/e42_xapp_api.c index f28b64518..be5476941 100644 --- a/src/xApp/e42_xapp_api.c +++ b/src/xApp/e42_xapp_api.c @@ -14,6 +14,8 @@ #include "../sm/rc_sm/rc_sm_id.h" #include "../sm/mac_sm/mac_sm_id.h" #include "../sm/ccc_sm/ccc_sm_id.h" +#include "../sm/dapp_sm/dapp_sm_id.h" + #include #include #include @@ -146,7 +148,7 @@ bool valid_sm_id(global_e2_node_id_t* id, uint32_t sm_id) // Only for testing purposes assert( sm_id == 2 || sm_id == 3 || sm_id == 4 || sm_id == 142 || sm_id == 143 || sm_id == 144 - || sm_id == 145 || sm_id == 146 || sm_id == 147 || sm_id == 148); + || sm_id == 145 || sm_id == 146 || sm_id == 147 || sm_id == 148 || sm_id == SM_DAPP_ID); return true; } @@ -178,7 +180,7 @@ sm_ans_xapp_t control_sm_xapp_api(global_e2_node_id_t* id, uint32_t ran_func_id, { assert(xapp != NULL); assert(id != NULL); - assert(ran_func_id == SM_MAC_ID || ran_func_id == SM_SLICE_ID || ran_func_id == SM_TC_ID || ran_func_id == SM_RC_ID || ran_func_id == SM_CCC_ID); + assert(ran_func_id == SM_MAC_ID || ran_func_id == SM_SLICE_ID || ran_func_id == SM_TC_ID || ran_func_id == SM_RC_ID || ran_func_id == SM_CCC_ID || ran_func_id == SM_DAPP_ID); assert(wr != NULL); return control_sm_sync_xapp(xapp, id, ran_func_id, wr); diff --git a/src/xApp/msg_handler_xapp.c b/src/xApp/msg_handler_xapp.c index feb0e4e45..a45ad0823 100644 --- a/src/xApp/msg_handler_xapp.c +++ b/src/xApp/msg_handler_xapp.c @@ -237,7 +237,7 @@ sm_ind_data_t ind_sm_payload(ric_indication_t const* src) assert(msg_disp.rd.ind.type == MAC_STATS_V0 || msg_disp.rd.ind.type == RLC_STATS_V0 || msg_disp.rd.ind.type == PDCP_STATS_V0 || msg_disp.rd.ind.type == SLICE_STATS_V0 || msg_disp.rd.ind.type == KPM_STATS_V3_0 || msg_disp.rd.ind.type == GTP_STATS_V0 - || msg_disp.rd.ind.type == RAN_CTRL_STATS_V1_03 || msg_disp.rd.ind.type == CCC_STATS_V6); + || msg_disp.rd.ind.type == RAN_CTRL_STATS_V1_03 || msg_disp.rd.ind.type == CCC_STATS_V6 || msg_disp.rd.ind.type == DAPP_STATS_V0); act_proc_ans_t ans = find_act_proc(&xapp->act_proc, src->ric_id.ric_req_id); @@ -285,8 +285,19 @@ sm_ind_data_t ind_sm_payload(ric_indication_t const* src) // Unblock UI thread signal_sync_ui(&xapp->sync); - // If the answer of control_ack is needed - // use the field ack->control_outcome + // The control outcome is optional in E2AP, and not every service model + // decodes one. Hand it to the SM that owns the RAN function when it does. + if (ack->control_outcome != NULL && ack->control_outcome->buf != NULL) { + sm_ric_t* sm_out = sm_plugin_ric(&xapp->plugin_ric, ack->ric_id.ran_func_id); + if (sm_out != NULL && sm_out->proc.on_control_out != NULL) { + sm_ctrl_out_data_t out_data = {.ctrl_out = ack->control_outcome->buf, + .len_out = ack->control_outcome->len}; + sm_ag_if_ans_ctrl_t out = sm_out->proc.on_control_out(sm_out, &out_data); + + if (sm_out->alloc.free_ctrl_out_data != NULL) + sm_out->alloc.free_ctrl_out_data(&out); + } + } e2ap_msg_t ans = {.type = NONE_E2_MSG_TYPE}; return ans; diff --git a/src/xApp/sm_ran_function_def.c b/src/xApp/sm_ran_function_def.c index e2af5c472..3c1eab7e8 100644 --- a/src/xApp/sm_ran_function_def.c +++ b/src/xApp/sm_ran_function_def.c @@ -27,6 +27,8 @@ void free_sm_ran_function_def(sm_ran_function_def_t* src) free_tc_func_def(&src->tc); } else if(src->type == CCC_RAN_FUNC_DEF_E){ free_ccc_func_def(&src->ccc); + } else if(src->type == DAPP_RAN_FUNC_DEF_E){ + free_e2sm_dapp_func_def(&src->dapp); } else{ assert(0 != 0 && "Unknown type"); } @@ -58,6 +60,8 @@ sm_ran_function_def_t cp_sm_ran_function_def(sm_ran_function_def_t const* src) dst.tc = cp_tc_func_def(&src->tc); } else if(src->type == CCC_RAN_FUNC_DEF_E){ dst.ccc = cp_ccc_func_def(&src->ccc); + } else if(src->type == DAPP_RAN_FUNC_DEF_E){ + dst.dapp = cp_e2sm_dapp_func_def(&src->dapp); } else{ assert(0 != 0 && "Unknown type"); } @@ -93,6 +97,8 @@ bool eq_sm_ran_function_def(sm_ran_function_def_t const* m0,sm_ran_function_def_ return eq_tc_func_def(&m0->tc, &m1->tc); } else if(m0->type == CCC_RAN_FUNC_DEF_E){ return eq_ccc_func_def(&m0->ccc, &m1->ccc); + } else if(m0->type == DAPP_RAN_FUNC_DEF_E){ + return eq_e2sm_dapp_func_def(&m0->dapp, &m1->dapp); } else{ assert(0 != 0 && "Unknown type"); } diff --git a/src/xApp/sm_ran_function_def.h b/src/xApp/sm_ran_function_def.h index e371b3348..3b123440e 100644 --- a/src/xApp/sm_ran_function_def.h +++ b/src/xApp/sm_ran_function_def.h @@ -16,6 +16,7 @@ #include "../sm/slice_sm/ie/slice_data_ie.h" #include "../sm/tc_sm/ie/tc_data_ie.h" #include "../sm/ccc_sm/ie/ccc_data_ie.h" +#include "../sm/dapp_sm/ie/dapp_data_ie.h" typedef enum { KPM_RAN_FUNC_DEF_E, @@ -27,6 +28,7 @@ typedef enum { SLICE_RAN_FUNC_DEF_E, TC_RAN_FUNC_DEF_E, CCC_RAN_FUNC_DEF_E, + DAPP_RAN_FUNC_DEF_E, } ran_func_def_e; typedef struct{ @@ -41,6 +43,7 @@ typedef struct{ slice_func_def_t slice; tc_func_def_t tc; ccc_func_def_t ccc; + e2sm_dapp_func_def_t dapp; }; } sm_ran_function_def_t; diff --git a/src/xApp/swig/CMakeLists.txt b/src/xApp/swig/CMakeLists.txt index e38883b88..0b1e88469 100644 --- a/src/xApp/swig/CMakeLists.txt +++ b/src/xApp/swig/CMakeLists.txt @@ -1,5 +1,3 @@ -# SPDX-License-Identifier: LicenseRef-CSSL-1.0 - # This is a CMake example for Python CMAKE_MINIMUM_REQUIRED(VERSION 3.8) CMAKE_POLICY(VERSION 3.8) @@ -72,6 +70,9 @@ SWIG_ADD_LIBRARY(xapp_sdk LANGUAGE ${XAPP_LANG} SOURCES ../../sm/gtp_sm/ie/gtp_data_ie.c ../../util/byte_array.c ../../util/alg_ds/alg/eq_float.c + # control_dapp_spectrum_sm stamps the E2SM-DAPP header and the + # spectrum payload, both of which the codecs require. + ../../util/time_now_us.c ) @@ -93,6 +94,9 @@ if(XAPP_TARGET_LANGUAGE STREQUAL "PYTHON_LANG") add_custom_command(TARGET xapp_sdk POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/examples/xApp/python3/xapp_slice_moni_ctrl.py" "${CMAKE_BINARY_DIR}/examples/xApp/python3/xapp_slice_moni_ctrl.py" ) + add_custom_command(TARGET xapp_sdk POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${CMAKE_SOURCE_DIR}/examples/xApp/python3/xapp_spectrum.py" "${CMAKE_BINARY_DIR}/examples/xApp/python3/xapp_spectrum.py" ) + add_custom_command(TARGET xapp_sdk POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/examples/xApp/python3/watch_slice_stats" "${CMAKE_BINARY_DIR}/examples/xApp/python3/watch_slice_stats" ) diff --git a/src/xApp/swig/swig_wrapper.cpp b/src/xApp/swig/swig_wrapper.cpp index dbdc8b81b..bc4a5202d 100644 --- a/src/xApp/swig/swig_wrapper.cpp +++ b/src/xApp/swig/swig_wrapper.cpp @@ -1,7 +1,3 @@ -/* - * SPDX-License-Identifier: LicenseRef-CSSL-1.0 - */ - //#include "FlexRIC.h" #include "swig_wrapper.h" @@ -522,5 +518,317 @@ void rm_report_gtp_sm(int handler) #ifdef XAPP_LANG_PYTHON PyGILState_Release(gstate); #endif +} + +////////////////////////////////////// +// DAPP SM (Spectrum) +///////////////////////////////////// + +#include "../../sm/dapp_sm/dapp_sm_id.h" +#include "../../sm/dapp_sm/ie/dapp_data_ie.h" +#include "../../sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_report.h" +#include "../../sm/dapp_sm/e3/service_models/spectrum_sm/ir/spectrum_control.h" +#include "../../util/time_now_us.h" +#include "../e2_node_connected_xapp.h" +#include "../sm_ran_function_def.h" + +// ---- print_dapp_ran_func_info: mirrors print_dapp_sm_info from xapp_spectrum.c ---- + +static void _print_dapp_e3_subs(const dapp_e3_subscription_list_t* subs, const char* indent) +{ + if (subs == NULL || subs->sz_dapp_e3_subscriptions == 0 || subs->dapp_e3_subscriptions == NULL) { + printf("%sdApp E3 subscriptions: none\n", indent); + return; + } + printf("%sdApp E3 subscriptions (%zu):\n", indent, subs->sz_dapp_e3_subscriptions); + for (size_t i = 0; i < subs->sz_dapp_e3_subscriptions; ++i) { + const dapp_e3_subscription_item_t* sub = &subs->dapp_e3_subscriptions[i]; + printf("%s - dApp %u: subscribed to %zu E3 RAN function(s):", indent, sub->dapp_id, sub->sz_subscribed_e3_ran_functions); + for (size_t j = 0; j < sub->sz_subscribed_e3_ran_functions; ++j) + printf(" %u", sub->subscribed_e3_ran_functions[j]); + printf("\n"); + } +} + +void print_dapp_ran_func_info(global_e2_node_id_t* id) +{ + (void)id; // currently prints all nodes; future: filter by id + e2_node_arr_xapp_t arr = e2_nodes_xapp_api(); + + for (int i = 0; i < arr.len; ++i) { + e2_node_connected_xapp_t* n = &arr.n[i]; + + for (size_t j = 0; j < n->len_rf; ++j) { + sm_ran_function_t* rf = &n->rf[j]; + if (rf->id != SM_DAPP_ID) + continue; + if (rf->defn.type != DAPP_RAN_FUNC_DEF_E) + continue; + + const e2sm_dapp_func_def_t* d = &rf->defn.dapp; + + printf("[DAPP xApp] RAN function @node=%d idx=%zu\n", i, j); + printf(" SM ID: %d\n", rf->id); + + if (d->name.name.buf && d->name.name.len > 0) + printf(" Name: %.*s\n", (int)d->name.name.len, (const char*)d->name.name.buf); + + if (d->name.description.buf && d->name.description.len > 0) + printf(" Description: %.*s\n", (int)d->name.description.len, (const char*)d->name.description.buf); + + if (d->name.oid.buf && d->name.oid.len > 0) + printf(" OID: %.*s\n", (int)d->name.oid.len, (const char*)d->name.oid.buf); + + printf(" Event trigger: %s\n", d->ev_trig ? "present" : "none"); + + if (d->report && d->report->sz_seq_report_sty > 0 && d->report->seq_report_sty) { + printf(" Report styles (%zu):\n", d->report->sz_seq_report_sty); + for (size_t k = 0; k < d->report->sz_seq_report_sty; ++k) { + const seq_report_sty_dapp_sm_t* s = &d->report->seq_report_sty[k]; + printf(" - report_type=%u, name=%.*s, ind_hdr_type=%u, ind_msg_type=%u\n", + s->report_type, + (int)s->name.len, + (const char*)s->name.buf, + s->ind_hdr_type, + s->ind_msg_type); + _print_dapp_e3_subs(s->dapp_e3_subs, " "); + } + } else { + printf(" Report styles: none\n"); + } + + if (d->ctrl && d->ctrl->sz_seq_ctrl_style > 0 && d->ctrl->seq_ctrl_style) { + printf(" Control styles (%zu):\n", d->ctrl->sz_seq_ctrl_style); + for (size_t k = 0; k < d->ctrl->sz_seq_ctrl_style; ++k) { + const seq_ctrl_style_dapp_sm_t* s = &d->ctrl->seq_ctrl_style[k]; + printf(" - style_type=%u, name=%.*s, hdr_type=%u, msg_type=%u, out_frmt_type=%u\n", + s->style_type, + (int)s->name.len, + (const char*)s->name.buf, + s->hdr, + s->msg, + s->out_frmt); + _print_dapp_e3_subs(s->dapp_e3_subs, " "); + } + } else { + printf(" Control styles: none\n"); + } + } + } + + free_e2_node_arr_xapp(&arr); +} + +// ---- Style 1: E3 data report (Format 1 indication) ---- + +static dapp_e3_data_cb* hndlr_dapp_e3_data_cb; + +static void sm_cb_dapp_frmt1(sm_ag_if_rd_t const* rd) +{ + assert(rd != NULL); + assert(rd->type == INDICATION_MSG_AGENT_IF_ANS_V0); + assert(rd->ind.type == DAPP_STATS_V0); + assert(hndlr_dapp_e3_data_cb != NULL); + + const e2sm_dapp_ind_hdr_t* hdr = &rd->ind.dapp.ind.hdr; + const dapp_e3_ind_payload_t* e3 = &rd->ind.dapp.ind.e3; + + if (hdr->format != FORMAT_1_E2SM_DAPP_IND_HDR) + return; + + swig_dapp_e3_data_ind_t ind; + + const e2sm_dapp_ind_hdr_frmt_1_t* h1 = &hdr->frmt_1; + ind.ran_function_id = h1->ran_function_id; + ind.dapp_id = h1->dapp_id; + ind.node_type = h1->node_type; + ind.plmn_0 = h1->node_plmn_id[0]; + ind.plmn_1 = h1->node_plmn_id[1]; + ind.plmn_2 = h1->node_plmn_id[2]; + ind.node_nb_id = h1->node_nb_id; + ind.node_cu_du_id_present = h1->node_cu_du_id_present; + ind.node_cu_du_id = h1->node_cu_du_id; + ind.timestamp_ns = h1->timestamp_ns; + ind.sequence_id = h1->sequence_id; + + if (e3->type == DAPP_E3_SM_SPECTRUM) { + const spectrum_sm_report_t* rep = &e3->u.spectrum; + for (long i = 0; i < rep->prb_count; ++i) + ind.prbs.push_back((int)rep->prbs[i]); + } + +#ifdef XAPP_LANG_PYTHON + PyGILState_STATE gstate = PyGILState_Ensure(); +#endif + + hndlr_dapp_e3_data_cb->handle(&ind); + +#ifdef XAPP_LANG_PYTHON + PyGILState_Release(gstate); +#endif +} + +int report_dapp_e3_data_sm(global_e2_node_id_t* id, dapp_e3_data_cb* handler) +{ + assert(id != NULL); + assert(handler != NULL); + + hndlr_dapp_e3_data_cb = handler; + + dapp_sub_data_t sub = {}; + sub.et.format = FORMAT_1_E2SM_DAPP_EV_TRIGGER_FORMAT; + sub.action_def = (e2sm_dapp_action_def_t*)calloc(1, sizeof(e2sm_dapp_action_def_t)); + assert(sub.action_def != NULL); + sub.action_def->format = FORMAT_1_E2SM_DAPP_ACTION_DEF; + sub.action_def->ric_style_type = 1; // DAPP_STYLE_E3_DATA + + sm_ans_xapp_t ans = report_sm_xapp_api(id, SM_DAPP_ID, &sub, sm_cb_dapp_frmt1); + assert(ans.success == true); + + free_dapp_sub_data(&sub); + + return ans.u.handle; +} + +void rm_report_dapp_e3_data_sm(int handle) +{ +#ifdef XAPP_LANG_PYTHON + PyGILState_STATE gstate = PyGILState_Ensure(); +#endif + + rm_report_sm_xapp_api(handle); + +#ifdef XAPP_LANG_PYTHON + PyGILState_Release(gstate); +#endif +} + +// ---- Style 2: subscription map (Format 2 indication) ---- + +static dapp_sub_map_cb* hndlr_dapp_sub_map_cb; + +static void sm_cb_dapp_frmt2(sm_ag_if_rd_t const* rd) +{ + assert(rd != NULL); + assert(rd->type == INDICATION_MSG_AGENT_IF_ANS_V0); + assert(rd->ind.type == DAPP_STATS_V0); + assert(hndlr_dapp_sub_map_cb != NULL); + + const e2sm_dapp_ind_hdr_t* hdr = &rd->ind.dapp.ind.hdr; + const e2sm_dapp_ind_msg_t* msg = &rd->ind.dapp.ind.msg; + + if (hdr->format != FORMAT_2_E2SM_DAPP_IND_HDR) + return; + + swig_dapp_sub_map_ind_t ind; + + const e2sm_dapp_ind_hdr_frmt_2_t* h2 = &hdr->frmt_2; + ind.node_type = h2->node_type; + ind.plmn_0 = h2->node_plmn_id[0]; + ind.plmn_1 = h2->node_plmn_id[1]; + ind.plmn_2 = h2->node_plmn_id[2]; + ind.node_nb_id = h2->node_nb_id; + ind.timestamp_ns = h2->timestamp_ns; + ind.sequence_id = h2->sequence_id; + ind.node_cu_du_id_present = h2->node_cu_du_id_present; + ind.node_cu_du_id = h2->node_cu_du_id; + + const e2sm_dapp_ind_msg_frmt_2_t* m2 = &msg->frmt_2; + const dapp_e3_subscription_list_t* subs = &m2->dapp_e3_subs; + + for (size_t i = 0; i < subs->sz_dapp_e3_subscriptions; ++i) { + const dapp_e3_subscription_item_t* item = &subs->dapp_e3_subscriptions[i]; + swig_dapp_sub_item_t si; + si.dapp_id = item->dapp_id; + for (size_t j = 0; j < item->sz_subscribed_e3_ran_functions; ++j) + si.e3_ran_functions.push_back((int)item->subscribed_e3_ran_functions[j]); + ind.dapp_subs.push_back(si); + } + +#ifdef XAPP_LANG_PYTHON + PyGILState_STATE gstate = PyGILState_Ensure(); +#endif + + hndlr_dapp_sub_map_cb->handle(&ind); + +#ifdef XAPP_LANG_PYTHON + PyGILState_Release(gstate); +#endif +} + +int report_dapp_sub_map_sm(global_e2_node_id_t* id, dapp_sub_map_cb* handler) +{ + assert(id != NULL); + assert(handler != NULL); + + hndlr_dapp_sub_map_cb = handler; + + dapp_sub_data_t sub = {}; + sub.et.format = FORMAT_1_E2SM_DAPP_EV_TRIGGER_FORMAT; + sub.action_def = (e2sm_dapp_action_def_t*)calloc(1, sizeof(e2sm_dapp_action_def_t)); + assert(sub.action_def != NULL); + sub.action_def->format = FORMAT_1_E2SM_DAPP_ACTION_DEF; + sub.action_def->ric_style_type = 2; // DAPP_STYLE_SUBSCRIPTION_MAP + + sm_ans_xapp_t ans = report_sm_xapp_api(id, SM_DAPP_ID, &sub, sm_cb_dapp_frmt2); + assert(ans.success == true); + + free_dapp_sub_data(&sub); + + return ans.u.handle; +} + +void rm_report_dapp_sub_map_sm(int handle) +{ +#ifdef XAPP_LANG_PYTHON + PyGILState_STATE gstate = PyGILState_Ensure(); +#endif + + rm_report_sm_xapp_api(handle); + +#ifdef XAPP_LANG_PYTHON + PyGILState_Release(gstate); +#endif +} + +// ---- Control ---- + +/* sequence_id is a wire-visible correlation id. Starts at 1 -- 0 is the + * E2SM-DAPP "no id assigned" sentinel. Mirrors + * examples/xApp/c/spectrum/xapp_spectrum.c's next_sequence_id(); this is the + * Python-binding path's own counter, not shared with that example. */ +static uint32_t next_sequence_id() { + static uint32_t counter; + return ++counter; +} + +void control_dapp_spectrum_sm(global_e2_node_id_t* id, uint32_t ran_func_id, uint32_t dapp_id, const std::vector& blocked_prbs) +{ + assert(id != NULL); + + dapp_ctrl_req_data_t ctrl = {}; + ctrl.hdr.format = FORMAT_1_E2SM_DAPP_CTRL_HDR; + ctrl.hdr.frmt_1.ran_function_id = ran_func_id; + ctrl.hdr.frmt_1.dapp_id = dapp_id; + ctrl.hdr.frmt_1.timestamp_ns = time_now_ns(); + ctrl.hdr.frmt_1.sequence_id = next_sequence_id(); + + ctrl.msg.format = FORMAT_1_E2SM_DAPP_CTRL_MSG; + ctrl.msg.frmt_1.data = NULL; + ctrl.msg.frmt_1.data_size = 0; + + ctrl.e3.type = DAPP_E3_SM_SPECTRUM; + ctrl.e3.u.spectrum.timestamp_ns = time_now_ns(); + ctrl.e3.u.spectrum.prb_count = (long)blocked_prbs.size(); + if (!blocked_prbs.empty()) { + ctrl.e3.u.spectrum.blockedPRBs = (uint16_t*)calloc(blocked_prbs.size(), sizeof(uint16_t)); + assert(ctrl.e3.u.spectrum.blockedPRBs != NULL); + for (size_t i = 0; i < blocked_prbs.size(); ++i) + ctrl.e3.u.spectrum.blockedPRBs[i] = blocked_prbs[i]; + } + + sm_ans_xapp_t ans = control_sm_xapp_api(id, SM_DAPP_ID, &ctrl); + assert(ans.success == true); + free_dapp_ctrl_req_data(&ctrl); } diff --git a/src/xApp/swig/swig_wrapper.h b/src/xApp/swig/swig_wrapper.h index 223f71327..8af58f4a8 100644 --- a/src/xApp/swig/swig_wrapper.h +++ b/src/xApp/swig/swig_wrapper.h @@ -1,7 +1,3 @@ -/* - * SPDX-License-Identifier: LicenseRef-CSSL-1.0 - */ - #ifndef SWIG_WRAPPER_H #define SWIG_WRAPPER_H @@ -167,5 +163,61 @@ int report_gtp_sm(global_e2_node_id_t* id, Interval inter, gtp_cb* handler); void rm_report_gtp_sm(int); -#endif +////////////////////////////////////// +// DAPP SM +///////////////////////////////////// + +struct swig_dapp_e3_data_ind_t { + uint32_t ran_function_id; + uint32_t dapp_id; + uint8_t node_type; + uint8_t plmn_0, plmn_1, plmn_2; + uint32_t node_nb_id; + bool node_cu_du_id_present; + uint64_t node_cu_du_id; + int64_t timestamp_ns; + int64_t sequence_id; + std::vector prbs; +}; + +struct swig_dapp_sub_item_t { + uint32_t dapp_id; + std::vector e3_ran_functions; +}; + +struct swig_dapp_sub_map_ind_t { + uint8_t node_type; + uint8_t plmn_0, plmn_1, plmn_2; + uint32_t node_nb_id; + bool node_cu_du_id_present; + uint64_t node_cu_du_id; + int64_t timestamp_ns; + int64_t sequence_id; + std::vector dapp_subs; +}; +struct dapp_e3_data_cb { + virtual void handle(swig_dapp_e3_data_ind_t* a) = 0; + virtual ~dapp_e3_data_cb() + { + } +}; + +struct dapp_sub_map_cb { + virtual void handle(swig_dapp_sub_map_ind_t* a) = 0; + virtual ~dapp_sub_map_cb() + { + } +}; + +void print_dapp_ran_func_info(global_e2_node_id_t* id); + +int report_dapp_e3_data_sm(global_e2_node_id_t* id, dapp_e3_data_cb* handler); +void rm_report_dapp_e3_data_sm(int handle); + +int report_dapp_sub_map_sm(global_e2_node_id_t* id, dapp_sub_map_cb* handler); +void rm_report_dapp_sub_map_sm(int handle); + +void control_dapp_spectrum_sm(global_e2_node_id_t* id, uint32_t ran_func_id, uint32_t dapp_id, const std::vector& blocked_prbs); + +#endif diff --git a/src/xApp/swig/swig_wrapper.i b/src/xApp/swig/swig_wrapper.i index 7062e5ab3..202070fe6 100644 --- a/src/xApp/swig/swig_wrapper.i +++ b/src/xApp/swig/swig_wrapper.i @@ -42,10 +42,26 @@ $1 = (uint32_t) PyInt_AsLong($input); } %typemap(in) uint64_t { - $1 = (uint64_t) PyInt_AsLong($input); + $1 = (uint64_t) PyLong_AsUnsignedLongLong($input); + if (PyErr_Occurred()) SWIG_fail; +} + +/* const uintXX_t & mapping: Python -> C */ +%typemap(in) const uint8_t & (uint8_t temp) { + temp = (uint8_t) PyInt_AsLong($input); $1 = &temp; +} +%typemap(in) const uint16_t & (uint16_t temp) { + temp = (uint16_t) PyInt_AsLong($input); $1 = &temp; +} +%typemap(in) const uint32_t & (uint32_t temp) { + temp = (uint32_t) PyInt_AsLong($input); $1 = &temp; +} +%typemap(in) const uint64_t & (uint64_t temp) { + temp = (uint64_t) PyLong_AsUnsignedLongLong($input); + if (PyErr_Occurred()) SWIG_fail; + $1 = &temp; } -/* intXX_t mapping: Python -> C */ %typemap(in) int8_t { $1 = (int8_t) PyInt_AsLong($input); } @@ -56,36 +72,54 @@ $1 = (int32_t) PyInt_AsLong($input); } %typemap(in) int64_t { - $1 = (int64_t) PyInt_AsLong($input); + $1 = (int64_t) PyLong_AsLongLong($input); + if (PyErr_Occurred()) SWIG_fail; } -/* uintXX_t mapping: C -> Python */ -%typemap(out) uint8_t { - $result = PyInt_FromLong((long) $1); +%typemap(in) const int8_t & (int8_t temp) { + temp = (int8_t) PyInt_AsLong($input); $1 = &temp; } -%typemap(out) uint16_t { - $result = PyInt_FromLong((long) $1); +%typemap(in) const int16_t & (int16_t temp) { + temp = (int16_t) PyInt_AsLong($input); $1 = &temp; } -%typemap(out) uint32_t { - $result = PyInt_FromLong((long) $1); +%typemap(in) const int32_t & (int32_t temp) { + temp = (int32_t) PyInt_AsLong($input); $1 = &temp; } -%typemap(out) uint64_t { - $result = PyInt_FromLong((long) $1); +%typemap(in) const int64_t & (int64_t temp) { + temp = (int64_t) PyLong_AsLongLong($input); + if (PyErr_Occurred()) SWIG_fail; + $1 = &temp; } +/* uintXX_t mapping: C -> Python */ +%typemap(out) uint8_t { $result = PyInt_FromLong((long) $1); } +%typemap(out) uint16_t { $result = PyInt_FromLong((long) $1); } +%typemap(out) uint32_t { $result = PyInt_FromLong((long) $1); } +%typemap(out) uint64_t { $result = PyLong_FromUnsignedLongLong((unsigned long long) $1); } + +%typemap(out) uint8_t & { $result = PyInt_FromLong((long) *$1); } +%typemap(out) uint16_t & { $result = PyInt_FromLong((long) *$1); } +%typemap(out) uint32_t & { $result = PyInt_FromLong((long) *$1); } +%typemap(out) uint64_t & { $result = PyLong_FromUnsignedLongLong((unsigned long long) *$1); } +%typemap(out) const uint8_t & { $result = PyInt_FromLong((long) *$1); } +%typemap(out) const uint16_t & { $result = PyInt_FromLong((long) *$1); } +%typemap(out) const uint32_t & { $result = PyInt_FromLong((long) *$1); } +%typemap(out) const uint64_t & { $result = PyLong_FromUnsignedLongLong((unsigned long long) *$1); } + /* intXX_t mapping: C -> Python */ -%typemap(out) int8_t { - $result = PyInt_FromLong((long) $1); -} -%typemap(out) int16_t { - $result = PyInt_FromLong((long) $1); -} -%typemap(out) int32_t { - $result = PyInt_FromLong((long) $1); -} -%typemap(out) int64_t { - $result = PyInt_FromLong((long) $1); -} +%typemap(out) int8_t { $result = PyInt_FromLong((long) $1); } +%typemap(out) int16_t { $result = PyInt_FromLong((long) $1); } +%typemap(out) int32_t { $result = PyInt_FromLong((long) $1); } +%typemap(out) int64_t { $result = PyLong_FromLongLong((long long) $1); } + +%typemap(out) int8_t & { $result = PyInt_FromLong((long) *$1); } +%typemap(out) int16_t & { $result = PyInt_FromLong((long) *$1); } +%typemap(out) int32_t & { $result = PyInt_FromLong((long) *$1); } +%typemap(out) int64_t & { $result = PyLong_FromLongLong((long long) *$1); } +%typemap(out) const int8_t & { $result = PyInt_FromLong((long) *$1); } +%typemap(out) const int16_t & { $result = PyInt_FromLong((long) *$1); } +%typemap(out) const int32_t & { $result = PyInt_FromLong((long) *$1); } +%typemap(out) const int64_t & { $result = PyLong_FromLongLong((long long) *$1); } #endif @@ -94,6 +128,8 @@ %feature("director") pdcp_cb; %feature("director") slice_cb; %feature("director") gtp_cb; +%feature("director") dapp_e3_data_cb; +%feature("director") dapp_sub_map_cb; namespace std { %template(IntVector) vector; @@ -106,6 +142,8 @@ namespace std { %template(SLICE_slicesStatsVector) vector; %template(SLICE_UEsStatsVector) vector; %template(GTP_NGUTStatsVector) vector; + %template(DAPP_PRBVector) vector; + %template(DAPP_SubItemVector) vector; } diff --git a/test/encode_decode/e2ap/v2_03/test_e2ap_enc_dec_asn.c b/test/encode_decode/e2ap/v2_03/test_e2ap_enc_dec_asn.c index a47890799..39e51931b 100644 --- a/test/encode_decode/e2ap/v2_03/test_e2ap_enc_dec_asn.c +++ b/test/encode_decode/e2ap/v2_03/test_e2ap_enc_dec_asn.c @@ -666,39 +666,71 @@ void test_reset_response() void test_service_update() { - byte_array_t ba; - memset(&ba, 0, sizeof(byte_array_t)); + // Exercise all three lists at once: added and modified are distinct CHOICE + // members of the same ASN.1 type, and deleted is a RANfunctionsID-List, so a + // round trip that only fills one of them would not catch a member mix-up. const char* def = "This is a dummy definition"; - ba.buf = malloc(strlen(def)); - memcpy(ba.buf, def, strlen(def)); - ba.len = strlen(def); const size_t len_added = 1; - ran_function_t* added = calloc(len_added, sizeof(ran_function_t )); - added->id = 42; - added->rev = 0; - added->defn = ba; - - ran_function_t* modified = NULL; - const size_t len_modified = 0; - e2ap_ran_function_id_rev_t* deleted = NULL; - size_t len_deleted = 0; + ran_function_t* added = calloc(len_added, sizeof(ran_function_t)); + assert(added != NULL); + added[0].id = 42; + added[0].rev = 0; + added[0].defn = copy_str_to_ba(def); + added[0].oid = copy_str_to_ba("1.3.6.1.4.1.53148.1.1.2.2"); + + const size_t len_modified = 1; + ran_function_t* modified = calloc(len_modified, sizeof(ran_function_t)); + assert(modified != NULL); + modified[0].id = 143; + modified[0].rev = 7; + modified[0].defn = copy_str_to_ba(def); + modified[0].oid = copy_str_to_ba("1.3.6.1.4.1.53148.1.1.2.3"); + + const size_t len_deleted = 2; + e2ap_ran_function_id_rev_t* deleted = calloc(len_deleted, sizeof(e2ap_ran_function_id_rev_t)); + assert(deleted != NULL); + deleted[0].id = 144; + deleted[0].rev = 1; + deleted[1].id = 145; + deleted[1].rev = 2; ric_service_update_t su_begin = { + .trans_id = 5, .len_added = len_added, - .added = added, + .added = added, .modified = modified, - .len_modified = len_modified, + .len_modified = len_modified, .deleted = deleted, .len_deleted = len_deleted, }; E2AP_PDU_t* pdu = e2ap_enc_service_update_asn_pdu(&su_begin); e2ap_msg_t msg = e2ap_dec_service_update(pdu); - free_pdu(pdu); - assert(msg.type == RIC_SERVICE_UPDATE); + free_pdu(pdu); + assert(msg.type == RIC_SERVICE_UPDATE); + ric_service_update_t* su_end = &msg.u_msgs.ric_serv_updt; + + assert(su_end->trans_id == su_begin.trans_id); + assert(eq_ric_service_update(&su_begin, su_end) == true); + e2ap_free_service_update(&su_begin); + e2ap_free_service_update(su_end); +} + +// Only the mandatory TransactionID: every RAN-function list in a RIC Service +// Update is optional, and an update with none of them must still round trip. +void test_service_update_empty() +{ + ric_service_update_t su_begin = {.trans_id = 11}; + + E2AP_PDU_t* pdu = e2ap_enc_service_update_asn_pdu(&su_begin); + e2ap_msg_t msg = e2ap_dec_service_update(pdu); + free_pdu(pdu); + assert(msg.type == RIC_SERVICE_UPDATE); ric_service_update_t* su_end = &msg.u_msgs.ric_serv_updt; + assert(su_end->trans_id == su_begin.trans_id); + assert(su_end->len_added == 0 && su_end->len_modified == 0 && su_end->len_deleted == 0); assert(eq_ric_service_update(&su_begin, su_end) == true); e2ap_free_service_update(&su_begin); e2ap_free_service_update(su_end); @@ -715,6 +747,7 @@ void test_service_update_ack() size_t len_rejected = 0; ric_service_update_ack_t su_begin = { + .trans_id = 5, .accepted = accepted, .len_accepted = len_accepted, .rejected = rejected, @@ -727,6 +760,7 @@ void test_service_update_ack() assert(msg.type == RIC_SERVICE_UPDATE_ACKNOWLEDGE); ric_service_update_ack_t* su_end = &msg.u_msgs.ric_serv_updt_ack; + assert(su_end->trans_id == su_begin.trans_id); assert(eq_ric_service_update_ack(&su_begin, su_end) == true); e2ap_free_service_update_ack(&su_begin); e2ap_free_service_update_ack(su_end); @@ -1138,8 +1172,9 @@ int main(int argc, char* argv[]) //test_reset_request(); //test_reset_response(); - //test_service_update(); - //test_service_update_ack(); + test_service_update(); + test_service_update_empty(); + test_service_update_ack(); //test_service_update_failure(); //test_service_query(); diff --git a/test/encode_decode/sm/CMakeLists.txt b/test/encode_decode/sm/CMakeLists.txt index a76d64891..7b517f215 100644 --- a/test/encode_decode/sm/CMakeLists.txt +++ b/test/encode_decode/sm/CMakeLists.txt @@ -2,6 +2,7 @@ add_subdirectory(kpm) add_subdirectory(rc) +add_subdirectory(dapp) enable_testing() diff --git a/test/encode_decode/sm/dapp/CMakeLists.txt b/test/encode_decode/sm/dapp/CMakeLists.txt new file mode 100644 index 000000000..1858e4f5d --- /dev/null +++ b/test/encode_decode/sm/dapp/CMakeLists.txt @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: LicenseRef-CSSL-1.0 + +project(test_enc_dec_dapp_sm) + +add_executable(test_enc_dec_dapp_sm + ../../../rnd/fill_rnd_data_dapp.c + ../../../../src/util/time_now_us.c + ../../../../src/util/alg_ds/alg/defer.c + main.c) + +target_link_libraries(test_enc_dec_dapp_sm PUBLIC + dapp_sm_static + e2sm_dapp_e3_spectrum_asn1_obj + dapp_sm_static + -lm + ) + +target_compile_options(test_enc_dec_dapp_sm PRIVATE -Wno-missing-field-initializers -Wno-unused-parameter) + +target_compile_options(test_enc_dec_dapp_sm PRIVATE "-DASN_DISABLE_OER_SUPPORT" "-DASN_DISABLE_JER_SUPPORT") + +##### +### CTest +#### +enable_testing() +add_test(Unit_test_enc_dec_DAPP test_enc_dec_dapp_sm) diff --git a/test/encode_decode/sm/dapp/main.c b/test/encode_decode/sm/dapp/main.c new file mode 100644 index 000000000..44a1bbd48 --- /dev/null +++ b/test/encode_decode/sm/dapp/main.c @@ -0,0 +1,469 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "../../../../src/util/byte_array.h" +#include "../../../../src/util/alg_ds/alg/defer.h" +#include "../../../../src/sm/dapp_sm/enc/dapp_enc_asn.h" +#include "../../../../src/sm/dapp_sm/dec/dapp_dec_asn.h" +#include "../../../../src/sm/dapp_sm/e3/dapp_enc_e3.h" +#include "../../../../src/sm/dapp_sm/e3/dapp_dec_e3.h" +#include "../../../../src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/encoder.h" +#include "../../../../src/sm/dapp_sm/e3/service_models/spectrum_sm/asn/decoder.h" +#include "../../../rnd/fill_rnd_data_dapp.h" +#include "../../../../src/util/time_now_us.h" + +#include +#include +#include +#include +#include + +/* =========================================================================== + * E2SM-DAPP ASN.1 codec round-trips + * =========================================================================== */ + +static void test_dapp_event_trigger(void) +{ + e2sm_dapp_event_trigger_t msg = fill_rnd_dapp_ev_trigger(); + defer({ free_e2sm_dapp_event_trigger(&msg); }); + + byte_array_t ba = dapp_enc_event_trigger_asn(&msg); + defer({ free_byte_array(ba); }); + + e2sm_dapp_event_trigger_t out = dapp_dec_event_trigger_asn(ba.len, ba.buf); + defer({ free_e2sm_dapp_event_trigger(&out); }); + + assert(eq_e2sm_dapp_event_trigger(&msg, &out) == true); +} + +static void test_dapp_action_def(void) +{ + e2sm_dapp_action_def_t msg = fill_rnd_dapp_action_def(); + defer({ free_e2sm_dapp_action_def(&msg); }); + + byte_array_t ba = dapp_enc_action_def_asn(&msg); + defer({ free_byte_array(ba); }); + + e2sm_dapp_action_def_t out = dapp_dec_action_def_asn(ba.len, ba.buf); + defer({ free_e2sm_dapp_action_def(&out); }); + + assert(eq_e2sm_dapp_action_def(&msg, &out) == true); +} + +static void test_dapp_ind_hdr_format(e2sm_dapp_ind_hdr_t hdr) +{ + defer({ free_e2sm_dapp_ind_hdr(&hdr); }); + + byte_array_t ba = dapp_enc_ind_hdr_asn(&hdr); + defer({ free_byte_array(ba); }); + + e2sm_dapp_ind_hdr_t out = dapp_dec_ind_hdr_asn(ba.len, ba.buf); + defer({ free_e2sm_dapp_ind_hdr(&out); }); + + assert(eq_e2sm_dapp_ind_hdr(&hdr, &out) == true); +} + +static void test_dapp_ind_hdr(void) +{ + e2sm_dapp_ind_hdr_t f1 = {.format = FORMAT_1_E2SM_DAPP_IND_HDR, .frmt_1 = fill_rnd_dapp_ind_hdr_frmt_1()}; + test_dapp_ind_hdr_format(f1); + + e2sm_dapp_ind_hdr_t f2 = {.format = FORMAT_2_E2SM_DAPP_IND_HDR, .frmt_2 = fill_rnd_dapp_ind_hdr_frmt_2()}; + test_dapp_ind_hdr_format(f2); +} + +static void test_dapp_ind_msg_format(e2sm_dapp_ind_msg_t msg) +{ + defer({ free_e2sm_dapp_ind_msg(&msg); }); + + byte_array_t ba = dapp_enc_ind_msg_asn(&msg); + defer({ free_byte_array(ba); }); + + e2sm_dapp_ind_msg_t out = dapp_dec_ind_msg_asn(ba.len, ba.buf); + defer({ free_e2sm_dapp_ind_msg(&out); }); + + assert(eq_e2sm_dapp_ind_msg(&msg, &out) == true); +} + +static void test_dapp_ind_msg(void) +{ + e2sm_dapp_ind_msg_t f1 = {.format = FORMAT_1_E2SM_DAPP_IND_MSG, .frmt_1 = fill_rnd_dapp_ind_msg_frmt_1()}; + test_dapp_ind_msg_format(f1); + + e2sm_dapp_ind_msg_t f2 = {.format = FORMAT_2_E2SM_DAPP_IND_MSG, .frmt_2 = fill_rnd_dapp_ind_msg_frmt_2()}; + test_dapp_ind_msg_format(f2); +} + +static void test_dapp_ctrl_hdr(void) +{ + e2sm_dapp_ctrl_hdr_t msg = fill_rnd_dapp_ctrl_hdr(); + defer({ free_e2sm_dapp_ctrl_hdr(&msg); }); + + byte_array_t ba = dapp_enc_ctrl_hdr_asn(&msg); + defer({ free_byte_array(ba); }); + + e2sm_dapp_ctrl_hdr_t out = dapp_dec_ctrl_hdr_asn(ba.len, ba.buf); + defer({ free_e2sm_dapp_ctrl_hdr(&out); }); + + assert(eq_e2sm_dapp_ctrl_hdr(&msg, &out) == true); +} + +static void test_dapp_ctrl_msg(void) +{ + e2sm_dapp_ctrl_msg_t msg = fill_rnd_dapp_ctrl_msg(); + defer({ free_e2sm_dapp_ctrl_msg(&msg); }); + + byte_array_t ba = dapp_enc_ctrl_msg_asn(&msg); + defer({ free_byte_array(ba); }); + + e2sm_dapp_ctrl_msg_t out = dapp_dec_ctrl_msg_asn(ba.len, ba.buf); + defer({ free_e2sm_dapp_ctrl_msg(&out); }); + + assert(eq_e2sm_dapp_ctrl_msg(&msg, &out) == true); +} + +static void test_dapp_ctrl_out(void) +{ + e2sm_dapp_ctrl_out_t msg = fill_rnd_dapp_ctrl_out(); + defer({ free_e2sm_dapp_ctrl_out(&msg); }); + + byte_array_t ba = dapp_enc_ctrl_out_asn(&msg); + defer({ free_byte_array(ba); }); + + e2sm_dapp_ctrl_out_t out = dapp_dec_ctrl_out_asn(ba.len, ba.buf); + defer({ free_e2sm_dapp_ctrl_out(&out); }); + + assert(eq_e2sm_dapp_ctrl_out(&msg, &out) == true); +} + +static void test_dapp_ran_func_def(void) +{ + e2sm_dapp_func_def_t msg = fill_rnd_dapp_func_def(); + defer({ free_e2sm_dapp_func_def(&msg); }); + + byte_array_t ba = dapp_enc_func_def_asn(&msg); + defer({ free_byte_array(ba); }); + + e2sm_dapp_func_def_t out = dapp_dec_func_def_asn(ba.len, ba.buf); + defer({ free_e2sm_dapp_func_def(&out); }); + + assert(eq_e2sm_dapp_func_def(&msg, &out) == true); +} + +/* =========================================================================== + * Spectrum SM IR helpers (cp / eq / free) + * =========================================================================== */ + +static void test_spectrum_ir_helpers_report(void) +{ + /* Random non-empty case. */ + spectrum_sm_report_t a = fill_rnd_spectrum_report(); + if (a.prb_count == 0) { + a.prb_count = 4; + a.prbs = calloc(4, sizeof(uint16_t)); + assert(a.prbs != NULL && "Memory exhausted"); + for (int i = 0; i < 4; ++i) + a.prbs[i] = (uint16_t)(i * 7); + } + defer({ free_spectrum_sm_report(&a); }); + + spectrum_sm_report_t b = cp_spectrum_sm_report(&a); + defer({ free_spectrum_sm_report(&b); }); + + assert(eq_spectrum_sm_report(&a, &b) == true); + + /* Mutate the copy and verify inequality. */ + if (b.prb_count > 0) + b.prbs[0] = (uint16_t)((a.prbs[0] + 1u) & 0xFFFFu); + assert(eq_spectrum_sm_report(&a, &b) == false); + + /* Empty case round-trips and free-on-empty is a no-op. */ + spectrum_sm_report_t empty = {.prb_count = 0, .prbs = NULL}; + spectrum_sm_report_t empty_cp = cp_spectrum_sm_report(&empty); + assert(eq_spectrum_sm_report(&empty, &empty_cp) == true); + free_spectrum_sm_report(&empty_cp); + free_spectrum_sm_report(&empty); +} + +static void test_spectrum_ir_helpers_control(void) +{ + spectrum_sm_control_t a = fill_rnd_spectrum_control(); + if (a.prb_count == 0) { + a.prb_count = 3; + a.blockedPRBs = calloc(3, sizeof(uint16_t)); + assert(a.blockedPRBs != NULL && "Memory exhausted"); + for (int i = 0; i < 3; ++i) + a.blockedPRBs[i] = (uint16_t)(i + 1); + } + defer({ free_spectrum_sm_control(&a); }); + + spectrum_sm_control_t b = cp_spectrum_sm_control(&a); + defer({ free_spectrum_sm_control(&b); }); + + assert(eq_spectrum_sm_control(&a, &b) == true); + + if (b.prb_count > 0) + b.blockedPRBs[0] = (uint16_t)((a.blockedPRBs[0] + 1u) & 0xFFFFu); + assert(eq_spectrum_sm_control(&a, &b) == false); + + spectrum_sm_control_t empty = {.prb_count = 0, .blockedPRBs = NULL}; + spectrum_sm_control_t empty_cp = cp_spectrum_sm_control(&empty); + assert(eq_spectrum_sm_control(&empty, &empty_cp) == true); + free_spectrum_sm_control(&empty_cp); + free_spectrum_sm_control(&empty); +} + +/* =========================================================================== + * Spectrum SM ASN.1 codec — IR ↔ wire round-trips + * (production code only ships one direction per IE; the other is implemented + * via the asn1c-direct helpers in fill_rnd_data_dapp.c.) + * =========================================================================== */ + +/* spectrum_sm_enc_control output decodes back into IR equivalent to the input. */ +static void test_spectrum_enc_control_roundtrip(void) +{ + spectrum_sm_control_t in = fill_rnd_spectrum_control(); + if (in.prb_count == 0) { + in.prb_count = 1; + in.blockedPRBs = calloc(1, sizeof(uint16_t)); + assert(in.blockedPRBs != NULL && "Memory exhausted"); + in.blockedPRBs[0] = 42; + } + defer({ free_spectrum_sm_control(&in); }); + + uint8_t* buf = NULL; + size_t len = 0; + bool const ok = spectrum_sm_enc_control(&in, &buf, &len); + assert(ok == true); + assert(buf != NULL); + defer({ free(buf); }); + + spectrum_sm_control_t out = {0}; + bool const dec_ok = spectrum_control_from_aper_bytes(buf, len, &out); + assert(dec_ok == true); + defer({ free_spectrum_sm_control(&out); }); + + assert(eq_spectrum_sm_control(&in, &out) == true); +} + +/* spectrum_sm_dec_report decodes the IR our asn1c-direct helper produced. */ +static void test_spectrum_dec_report_roundtrip(void) +{ + spectrum_sm_report_t in = fill_rnd_spectrum_report(); + if (in.prb_count == 0) { + in.prb_count = 5; + in.prbs = calloc(5, sizeof(uint16_t)); + assert(in.prbs != NULL && "Memory exhausted"); + for (int i = 0; i < 5; ++i) + in.prbs[i] = (uint16_t)((i * 11) % 273); + } + defer({ free_spectrum_sm_report(&in); }); + + byte_array_t ba = spectrum_report_to_aper_bytes(&in); + defer({ free_byte_array(ba); }); + + spectrum_sm_report_t out = {0}; + bool const ok = spectrum_sm_dec_report(ba.buf, ba.len, &out); + assert(ok == true); + defer({ free_spectrum_sm_report(&out); }); + + assert(eq_spectrum_sm_report(&in, &out) == true); +} + +/* =========================================================================== + * Boundary / failure paths + * =========================================================================== */ + +static void test_spectrum_enc_control_oob(void) +{ + uint8_t* buf = NULL; + size_t len = 0; + + /* Negative prb_count is rejected. */ + uint16_t dummy_prb = 0; + spectrum_sm_control_t neg = {.prb_count = -1, .blockedPRBs = &dummy_prb, .timestamp_ns = time_now_ns()}; + assert(spectrum_sm_enc_control(&neg, &buf, &len) == false); + assert(buf == NULL && len == 0); + + /* prb_count > 273 is rejected. */ + spectrum_sm_control_t hi = {.prb_count = 274, .blockedPRBs = &dummy_prb, .timestamp_ns = time_now_ns()}; + assert(spectrum_sm_enc_control(&hi, &buf, &len) == false); + assert(buf == NULL && len == 0); + + /* PRB index > 272 is rejected. */ + uint16_t bad_prb[2] = {0, 273}; + spectrum_sm_control_t bad = {.prb_count = 2, .blockedPRBs = bad_prb, .timestamp_ns = time_now_ns()}; + assert(spectrum_sm_enc_control(&bad, &buf, &len) == false); + assert(buf == NULL && len == 0); + + /* NULL ctrl is rejected. */ + assert(spectrum_sm_enc_control(NULL, &buf, &len) == false); + assert(buf == NULL && len == 0); + + /* An unstamped control is valid: the schema marks timestamp OPTIONAL, so 0 + means "no producer reference", not "malformed". It encodes with the field + absent. */ + spectrum_sm_control_t unstamped = {.prb_count = 0, .blockedPRBs = NULL}; + assert(spectrum_sm_enc_control(&unstamped, &buf, &len) == true); + assert(buf != NULL && len > 0); + free(buf); + buf = NULL; + len = 0; + + /* prb_count == 0 (with NULL prbs) is valid and produces output. */ + spectrum_sm_control_t zero = {.prb_count = 0, .blockedPRBs = NULL, .timestamp_ns = time_now_ns()}; + assert(spectrum_sm_enc_control(&zero, &buf, &len) == true); + assert(buf != NULL); + free(buf); +} + +static void test_spectrum_dec_report_invalid(void) +{ + spectrum_sm_report_t out = {0}; + + /* NULL buffer is rejected. */ + assert(spectrum_sm_dec_report(NULL, 0, &out) == false); + + /* Zero length is rejected. */ + uint8_t one = 0; + assert(spectrum_sm_dec_report(&one, 0, &out) == false); + + /* Garbage bytes — the asn1c decoder may reject, or may accept with an + * unexpected layout; both are acceptable as long as we don't crash and the + * output is left in a consistent (free()-able) state. */ + uint8_t garbage[16] = {0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xBA, 0xBE, + 0x00, 0xFF, 0x55, 0xAA, 0x12, 0x34, 0x56, 0x78}; + spectrum_sm_report_t r = {0}; + bool const dec_ok = spectrum_sm_dec_report(garbage, sizeof(garbage), &r); + if (dec_ok) + free_spectrum_sm_report(&r); +} + +static void test_dapp_enc_e3_control_dispatch(void) +{ + uint8_t* buf = NULL; + size_t len = 0; + + /* Unsupported RAN function ID returns false. */ + dapp_e3_ctrl_payload_t spec = {.type = DAPP_E3_SM_SPECTRUM}; + spec.u.spectrum.prb_count = 0; + spec.u.spectrum.blockedPRBs = NULL; + assert(dapp_enc_e3_control(/*ran_function_id=*/999u, &spec, &buf, &len) == false); + assert(buf == NULL && len == 0); + + /* RAN function ID 1 with the wrong inner SM type returns false. */ + dapp_e3_ctrl_payload_t mismatched = {.type = DAPP_E3_SM_NONE}; + assert(dapp_enc_e3_control(/*ran_function_id=*/1u, &mismatched, &buf, &len) == false); + assert(buf == NULL && len == 0); + + /* NULL payload returns false. */ + assert(dapp_enc_e3_control(/*ran_function_id=*/1u, NULL, &buf, &len) == false); + assert(buf == NULL && len == 0); + + /* Happy path: ran_function_id=1 + DAPP_E3_SM_SPECTRUM produces bytes. */ + spectrum_sm_control_t* c = &spec.u.spectrum; + c->timestamp_ns = time_now_ns(); + c->prb_count = 4; + c->blockedPRBs = calloc(4, sizeof(uint16_t)); + assert(c->blockedPRBs != NULL && "Memory exhausted"); + for (int i = 0; i < 4; ++i) + c->blockedPRBs[i] = (uint16_t)i; + assert(dapp_enc_e3_control(/*ran_function_id=*/1u, &spec, &buf, &len) == true); + assert(buf != NULL && len > 0); + free(buf); + free_spectrum_sm_control(c); +} + +static void test_dapp_dec_e3_indication_dispatch(void) +{ + /* NULL/zero-length input returns false and out is reset to NONE. */ + dapp_e3_ind_payload_t out = {.type = DAPP_E3_SM_SPECTRUM}; + assert(dapp_dec_e3_indication(/*ran_function_id=*/1u, NULL, 0, &out) == false); + assert(out.type == DAPP_E3_SM_NONE); + + uint8_t one = 0xFF; + out.type = DAPP_E3_SM_SPECTRUM; + assert(dapp_dec_e3_indication(/*ran_function_id=*/1u, &one, 0, &out) == false); + assert(out.type == DAPP_E3_SM_NONE); + + /* Unsupported RAN function ID returns false (and leaves type NONE). */ + uint8_t buf[1] = {0}; + assert(dapp_dec_e3_indication(/*ran_function_id=*/999u, buf, 1, &out) == false); + assert(out.type == DAPP_E3_SM_NONE); + + /* Happy path: encode a Spectrum report via the asn1c-direct helper and + * verify the dispatcher routes to the spectrum decoder and matches. */ + spectrum_sm_report_t in = {.prb_count = 3}; + in.prbs = calloc(3, sizeof(uint16_t)); + assert(in.prbs != NULL && "Memory exhausted"); + in.prbs[0] = 1; + in.prbs[1] = 17; + in.prbs[2] = 271; + byte_array_t ba = spectrum_report_to_aper_bytes(&in); + + out = (dapp_e3_ind_payload_t){0}; + bool const ok = dapp_dec_e3_indication(/*ran_function_id=*/1u, ba.buf, ba.len, &out); + assert(ok == true); + assert(out.type == DAPP_E3_SM_SPECTRUM); + assert(eq_spectrum_sm_report(&in, &out.u.spectrum) == true); + + free_dapp_e3_ind_payload(&out); + free_byte_array(ba); + free_spectrum_sm_report(&in); +} + +int main(void) +{ + srand((unsigned)time(NULL)); + + printf("\nDAPP SM enc/dec test launched\n"); + + test_dapp_event_trigger(); + printf("DAPP Event Trigger test succeeded\n"); + + test_dapp_action_def(); + printf("DAPP Action Definition test succeeded\n"); + + test_dapp_ind_hdr(); + printf("DAPP Indication Header test succeeded (format 1 + format 2)\n"); + + test_dapp_ind_msg(); + printf("DAPP Indication Message test succeeded (format 1 + format 2)\n"); + + test_dapp_ctrl_hdr(); + printf("DAPP Control Header test succeeded\n"); + + test_dapp_ctrl_msg(); + printf("DAPP Control Message test succeeded\n"); + + test_dapp_ctrl_out(); + printf("DAPP Control Outcome test succeeded\n"); + + test_dapp_ran_func_def(); + printf("DAPP RAN Function Definition test succeeded (with ev_trig + dapp_e3_subs)\n"); + + test_spectrum_ir_helpers_report(); + test_spectrum_ir_helpers_control(); + printf("Spectrum SM IR cp/eq/free test succeeded\n"); + + test_spectrum_enc_control_roundtrip(); + printf("Spectrum SM control encode roundtrip test succeeded\n"); + + test_spectrum_dec_report_roundtrip(); + printf("Spectrum SM report decode roundtrip test succeeded\n"); + + test_spectrum_enc_control_oob(); + printf("Spectrum SM control out-of-bound rejection test succeeded\n"); + + test_spectrum_dec_report_invalid(); + printf("Spectrum SM report invalid input test succeeded\n"); + + test_dapp_enc_e3_control_dispatch(); + printf("DAPP E3 control dispatch test succeeded\n"); + + test_dapp_dec_e3_indication_dispatch(); + printf("DAPP E3 indication dispatch test succeeded\n"); + + return EXIT_SUCCESS; +} diff --git a/test/rnd/fill_rnd_data_dapp.c b/test/rnd/fill_rnd_data_dapp.c new file mode 100644 index 000000000..058aad373 --- /dev/null +++ b/test/rnd/fill_rnd_data_dapp.c @@ -0,0 +1,487 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "fill_rnd_data_dapp.h" + +#include "../../src/sm/dapp_sm/dapp_sm_id.h" +#include "../../src/util/time_now_us.h" + +#include +#include +#include +#include + +#include "Spectrum-DAppReportData.h" +#include "Spectrum-PRBBlacklistReport.h" +#include "Spectrum-XAppControlData.h" +#include "Spectrum-PRBBlockedControl.h" +#include "asn_application.h" +#include "per_encoder.h" +#include "per_decoder.h" + +#define DAPP_SPECTRUM_RAN_FUNCTION_ID 1u +#define DAPP_PRB_MAX_INDEX 272u +#define DAPP_PRB_MAX_COUNT 273 + +static byte_array_t fill_rnd_byte_array(size_t len) +{ + assert(len > 0); + byte_array_t ba = {.len = len, .buf = malloc(len)}; + assert(ba.buf != NULL && "Memory exhausted"); + for (size_t i = 0; i < len; ++i) + ba.buf[i] = (uint8_t)(rand() & 0xFF); + return ba; +} + +/* Event Trigger ------------------------------------------------------------ */ + +e2sm_dapp_event_trigger_t fill_rnd_dapp_ev_trigger(void) +{ + e2sm_dapp_event_trigger_t dst = {.format = FORMAT_1_E2SM_DAPP_EV_TRIGGER_FORMAT}; + return dst; +} + +/* Action Definition -------------------------------------------------------- */ + +e2sm_dapp_action_def_t fill_rnd_dapp_action_def(void) +{ + e2sm_dapp_action_def_t dst = { + .format = FORMAT_1_E2SM_DAPP_ACTION_DEF, + .ric_style_type = (rand() & 1) ? DAPP_RIC_STYLE_E3_DATA_REPORT : DAPP_RIC_STYLE_E3_SUBSCRIPTION_MAP, + }; + return dst; +} + +/* Indication Header -------------------------------------------------------- */ + +e2sm_dapp_ind_hdr_frmt_1_t fill_rnd_dapp_ind_hdr_frmt_1(void) +{ + e2sm_dapp_ind_hdr_frmt_1_t dst = {0}; + dst.ran_function_id = (uint32_t)rand(); + dst.dapp_id = (uint32_t)rand(); + dst.node_type = (uint8_t)(rand() & 0x7F); + dst.node_nb_id = (uint32_t)rand(); + for (size_t i = 0; i < 3; ++i) + dst.node_plmn_id[i] = (uint8_t)(rand() & 0xFF); + dst.node_cu_du_id_present = (rand() & 1) != 0; + dst.node_cu_du_id = dst.node_cu_du_id_present ? (uint64_t)rand() : 0; + dst.timestamp_ns = time_now_ns(); + dst.sequence_id = + (int64_t)rand() + 1; /* never 0: that's the "absent" sentinel */ + return dst; +} + +e2sm_dapp_ind_hdr_frmt_2_t fill_rnd_dapp_ind_hdr_frmt_2(void) +{ + e2sm_dapp_ind_hdr_frmt_2_t dst = {0}; + dst.node_type = (uint8_t)(rand() & 0x7F); + dst.node_nb_id = (uint32_t)rand(); + for (size_t i = 0; i < 3; ++i) + dst.node_plmn_id[i] = (uint8_t)(rand() & 0xFF); + dst.node_cu_du_id_present = (rand() & 1) != 0; + dst.node_cu_du_id = dst.node_cu_du_id_present ? (uint64_t)rand() : 0; + dst.timestamp_ns = time_now_ns(); + dst.sequence_id = + (int64_t)rand() + 1; /* never 0: that's the "absent" sentinel */ + return dst; +} + +e2sm_dapp_ind_hdr_t fill_rnd_dapp_ind_hdr(void) +{ + e2sm_dapp_ind_hdr_t dst = {0}; + if (rand() & 1) { + dst.format = FORMAT_1_E2SM_DAPP_IND_HDR; + dst.frmt_1 = fill_rnd_dapp_ind_hdr_frmt_1(); + } else { + dst.format = FORMAT_2_E2SM_DAPP_IND_HDR; + dst.frmt_2 = fill_rnd_dapp_ind_hdr_frmt_2(); + } + return dst; +} + +/* Indication Message ------------------------------------------------------- */ + +e2sm_dapp_ind_msg_frmt_1_t fill_rnd_dapp_ind_msg_frmt_1(void) +{ + e2sm_dapp_ind_msg_frmt_1_t dst = {0}; + size_t const n = (size_t)((rand() % 256) + 1); + byte_array_t ba = fill_rnd_byte_array(n); + dst.data_size = ba.len; + dst.data = ba.buf; + return dst; +} + +static dapp_e3_subscription_item_t fill_rnd_dapp_e3_subscription_item(void) +{ + dapp_e3_subscription_item_t dst = {0}; + dst.dapp_id = (uint32_t)rand(); + size_t const n = (size_t)((rand() % 4) + 1); + dst.sz_subscribed_e3_ran_functions = n; + dst.subscribed_e3_ran_functions = calloc(n, sizeof(uint32_t)); + assert(dst.subscribed_e3_ran_functions != NULL && "Memory exhausted"); + for (size_t i = 0; i < n; ++i) + dst.subscribed_e3_ran_functions[i] = (uint32_t)rand(); + return dst; +} + +static dapp_e3_subscription_list_t fill_rnd_dapp_e3_subscription_list(void) +{ + dapp_e3_subscription_list_t dst = {0}; + size_t const n = (size_t)((rand() % 3) + 1); + dst.sz_dapp_e3_subscriptions = n; + dst.dapp_e3_subscriptions = calloc(n, sizeof(dapp_e3_subscription_item_t)); + assert(dst.dapp_e3_subscriptions != NULL && "Memory exhausted"); + for (size_t i = 0; i < n; ++i) + dst.dapp_e3_subscriptions[i] = fill_rnd_dapp_e3_subscription_item(); + return dst; +} + +e2sm_dapp_ind_msg_frmt_2_t fill_rnd_dapp_ind_msg_frmt_2(void) +{ + e2sm_dapp_ind_msg_frmt_2_t dst = {0}; + dst.dapp_e3_subs = fill_rnd_dapp_e3_subscription_list(); + return dst; +} + +e2sm_dapp_ind_msg_t fill_rnd_dapp_ind_msg(void) +{ + e2sm_dapp_ind_msg_t dst = {0}; + if (rand() & 1) { + dst.format = FORMAT_1_E2SM_DAPP_IND_MSG; + dst.frmt_1 = fill_rnd_dapp_ind_msg_frmt_1(); + } else { + dst.format = FORMAT_2_E2SM_DAPP_IND_MSG; + dst.frmt_2 = fill_rnd_dapp_ind_msg_frmt_2(); + } + return dst; +} + +/* Control Header / Message / Outcome --------------------------------------- */ + +e2sm_dapp_ctrl_hdr_t fill_rnd_dapp_ctrl_hdr(void) +{ + e2sm_dapp_ctrl_hdr_t dst = {.format = FORMAT_1_E2SM_DAPP_CTRL_HDR}; + dst.frmt_1.ran_function_id = (uint32_t)rand(); + dst.frmt_1.dapp_id = (uint32_t)rand(); + dst.frmt_1.timestamp_ns = time_now_ns(); + dst.frmt_1.sequence_id = + (int64_t)rand() + 1; /* never 0: that's the "absent" sentinel */ + return dst; +} + +e2sm_dapp_ctrl_msg_t fill_rnd_dapp_ctrl_msg(void) +{ + e2sm_dapp_ctrl_msg_t dst = {.format = FORMAT_1_E2SM_DAPP_CTRL_MSG}; + size_t const n = (size_t)((rand() % 256) + 1); + byte_array_t ba = fill_rnd_byte_array(n); + dst.frmt_1.data_size = (uint32_t)ba.len; + dst.frmt_1.data = ba.buf; + return dst; +} + +e2sm_dapp_ctrl_out_t fill_rnd_dapp_ctrl_out(void) +{ + e2sm_dapp_ctrl_out_t dst = {.format = FORMAT_1_E2SM_DAPP_CTRL_OUT}; + dst.frmt_1.timestamp_ns = time_now_ns(); + dst.frmt_1.sequence_id = + (int64_t)rand() + 1; /* never 0: that's the "absent" sentinel */ + return dst; +} + +e2sm_dapp_ctrl_out_t fill_dapp_ctrl_out(void) { return fill_rnd_dapp_ctrl_out(); } + +/* RAN Function Definition -------------------------------------------------- */ + +static seq_report_sty_dapp_sm_t fill_rnd_seq_report_sty(void) +{ + seq_report_sty_dapp_sm_t dst = {0}; + dst.report_type = (uint32_t)((rand() % 2) + 1); + char const* nm = (dst.report_type == 1) ? "E3 Data Report" : "E3 Subscription Map"; + dst.name = cp_str_to_ba(nm); + dst.ind_hdr_type = dst.report_type; + dst.ind_msg_type = dst.report_type; + /* Exercise the encoder/decoder branch that copies the inner subscription + * list into ReportStyle items. */ + dst.dapp_e3_subs = calloc(1, sizeof(dapp_e3_subscription_list_t)); + assert(dst.dapp_e3_subs != NULL && "Memory exhausted"); + *dst.dapp_e3_subs = fill_rnd_dapp_e3_subscription_list(); + return dst; +} + +static seq_ctrl_style_dapp_sm_t fill_rnd_seq_ctrl_style(void) +{ + seq_ctrl_style_dapp_sm_t dst = {0}; + dst.style_type = 1; + dst.name = cp_str_to_ba("E3 Control Style"); + dst.hdr = 1; + dst.msg = 1; + dst.out_frmt = 1; + dst.dapp_e3_subs = calloc(1, sizeof(dapp_e3_subscription_list_t)); + assert(dst.dapp_e3_subs != NULL && "Memory exhausted"); + *dst.dapp_e3_subs = fill_rnd_dapp_e3_subscription_list(); + return dst; +} + +static e2sm_dapp_func_def_t fill_dapp_func_def_with_name(byte_array_t name, byte_array_t oid, byte_array_t desc) +{ + e2sm_dapp_func_def_t dst = {0}; + dst.name.name = name; + dst.name.oid = oid; + dst.name.description = desc; + dst.name.instance = NULL; + + dst.ev_trig = calloc(1, sizeof(ran_func_def_ev_trig_dapp_sm_t)); + assert(dst.ev_trig != NULL && "Memory exhausted"); + + dst.report = calloc(1, sizeof(ran_func_def_report_dapp_sm_t)); + assert(dst.report != NULL && "Memory exhausted"); + dst.report->sz_seq_report_sty = 2; + dst.report->seq_report_sty = calloc(2, sizeof(seq_report_sty_dapp_sm_t)); + assert(dst.report->seq_report_sty != NULL && "Memory exhausted"); + dst.report->seq_report_sty[0] = fill_rnd_seq_report_sty(); + dst.report->seq_report_sty[1] = fill_rnd_seq_report_sty(); + + dst.ctrl = calloc(1, sizeof(ran_func_def_ctrl_dapp_sm_t)); + assert(dst.ctrl != NULL && "Memory exhausted"); + dst.ctrl->sz_seq_ctrl_style = 1; + dst.ctrl->seq_ctrl_style = calloc(1, sizeof(seq_ctrl_style_dapp_sm_t)); + assert(dst.ctrl->seq_ctrl_style != NULL && "Memory exhausted"); + dst.ctrl->seq_ctrl_style[0] = fill_rnd_seq_ctrl_style(); + + return dst; +} + +e2sm_dapp_func_def_t fill_rnd_dapp_func_def(void) +{ + return fill_dapp_func_def_with_name(cp_str_to_ba("E2SM-DAPP-Test"), + cp_str_to_ba("1.3.6.1.4.1.53148.1.1.255.3"), + cp_str_to_ba("Test DAPP RAN function")); +} + +e2sm_dapp_func_def_t fill_dapp_ran_func_def(void) +{ + return fill_dapp_func_def_with_name(cp_str_to_ba(SM_DAPP_SHORT_NAME), + cp_str_to_ba(SM_DAPP_OID), + cp_str_to_ba(SM_DAPP_DESCRIPTION)); +} + +/* Spectrum SM helpers ------------------------------------------------------ */ + +spectrum_sm_report_t fill_rnd_spectrum_report(void) +{ + spectrum_sm_report_t dst = {0}; + dst.timestamp_ns = time_now_ns(); + long const n = (long)(rand() % (DAPP_PRB_MAX_COUNT + 1)); + dst.prb_count = n; + if (n == 0) { + dst.prbs = NULL; + return dst; + } + dst.prbs = calloc((size_t)n, sizeof(uint16_t)); + assert(dst.prbs != NULL && "Memory exhausted"); + for (long i = 0; i < n; ++i) + dst.prbs[i] = (uint16_t)(rand() % (DAPP_PRB_MAX_INDEX + 1)); + return dst; +} + +spectrum_sm_control_t fill_rnd_spectrum_control(void) +{ + spectrum_sm_control_t dst = {0}; + dst.timestamp_ns = time_now_ns(); + long const n = (long)(rand() % (DAPP_PRB_MAX_COUNT + 1)); + dst.prb_count = n; + if (n == 0) { + dst.blockedPRBs = NULL; + return dst; + } + dst.blockedPRBs = calloc((size_t)n, sizeof(uint16_t)); + assert(dst.blockedPRBs != NULL && "Memory exhausted"); + for (long i = 0; i < n; ++i) + dst.blockedPRBs[i] = (uint16_t)(rand() % (DAPP_PRB_MAX_INDEX + 1)); + return dst; +} + +byte_array_t spectrum_report_to_aper_bytes(spectrum_sm_report_t const* r) +{ + assert(r != NULL); + assert(r->prb_count >= 0 && r->prb_count <= DAPP_PRB_MAX_COUNT); + + Spectrum_DAppReportData_t asn; + memset(&asn, 0, sizeof(asn)); + /* OPTIONAL now: absent when the producer did not stamp. */ + if (r->timestamp_ns != 0) { + asn.timestamp = calloc(1, sizeof(*asn.timestamp)); + assert(asn.timestamp != NULL && "Memory exhausted"); + *asn.timestamp = (long)r->timestamp_ns; + } + asn.reportPayload.present = Spectrum_DAppReportPayload_PR_prbBlacklistReport; + + Spectrum_PRBBlacklistReport_t* rep = (Spectrum_PRBBlacklistReport_t*)calloc(1, sizeof(*rep)); + assert(rep != NULL && "Memory exhausted"); + asn.reportPayload.choice.prbBlacklistReport = rep; + + for (long i = 0; i < r->prb_count; ++i) { + long* elem = (long*)calloc(1, sizeof(*elem)); + assert(elem != NULL && "Memory exhausted"); + *elem = (long)r->prbs[i]; + int const rc = ASN_SEQUENCE_ADD(&rep->blacklistedPRBs.list, elem); + assert(rc == 0 && "ASN_SEQUENCE_ADD failed"); + } + + uint8_t tmp[2048]; + asn_enc_rval_t const er = aper_encode_to_buffer(&asn_DEF_Spectrum_DAppReportData, NULL, &asn, tmp, sizeof(tmp)); + assert(er.encoded > 0 && "aper_encode_to_buffer failed"); + + size_t const n = (size_t)((er.encoded + 7) / 8); + byte_array_t ba = {.len = n, .buf = malloc(n)}; + assert(ba.buf != NULL && "Memory exhausted"); + memcpy(ba.buf, tmp, n); + + ASN_STRUCT_RESET(asn_DEF_Spectrum_DAppReportData, &asn); + return ba; +} + +bool spectrum_control_from_aper_bytes(uint8_t const* buf, size_t len, spectrum_sm_control_t* out) +{ + assert(out != NULL); + out->prb_count = 0; + out->blockedPRBs = NULL; + + if (buf == NULL || len == 0) + return false; + + Spectrum_XAppControlData_t asn; + memset(&asn, 0, sizeof(asn)); + Spectrum_XAppControlData_t* asn_ref = &asn; + + asn_dec_rval_t const ret = aper_decode(NULL, &asn_DEF_Spectrum_XAppControlData, (void**)&asn_ref, buf, len, 0, 0); + if (ret.code != RC_OK) { + ASN_STRUCT_RESET(asn_DEF_Spectrum_XAppControlData, &asn); + return false; + } + + out->timestamp_ns = asn.timestamp != NULL ? (int64_t)*asn.timestamp : 0; + + if (asn.controlPayload.present != Spectrum_XAppControlPayload_PR_prbBlockedControl + || asn.controlPayload.choice.prbBlockedControl == NULL) { + ASN_STRUCT_RESET(asn_DEF_Spectrum_XAppControlData, &asn); + return false; + } + + Spectrum_PRBBlockedControl_t const* blocked = asn.controlPayload.choice.prbBlockedControl; + int const n = blocked->blockedPRBs.list.count; + if (n < 0 || n > DAPP_PRB_MAX_COUNT) { + ASN_STRUCT_RESET(asn_DEF_Spectrum_XAppControlData, &asn); + return false; + } + + out->prb_count = (long)n; + if (n > 0) { + out->blockedPRBs = calloc((size_t)n, sizeof(uint16_t)); + assert(out->blockedPRBs != NULL && "Memory exhausted"); + for (int i = 0; i < n; ++i) { + long const v = *blocked->blockedPRBs.list.array[i]; + if (v < 0 || v > (long)DAPP_PRB_MAX_INDEX) { + ASN_STRUCT_RESET(asn_DEF_Spectrum_XAppControlData, &asn); + free(out->blockedPRBs); + out->blockedPRBs = NULL; + out->prb_count = 0; + return false; + } + out->blockedPRBs[i] = (uint16_t)v; + } + } + + ASN_STRUCT_RESET(asn_DEF_Spectrum_XAppControlData, &asn); + return true; +} + +/* Top-level containers ----------------------------------------------------- */ + +dapp_sub_data_t fill_rnd_dapp_subscription(void) +{ + dapp_sub_data_t dst = {0}; + dst.et = fill_rnd_dapp_ev_trigger(); + dst.action_def = calloc(1, sizeof(e2sm_dapp_action_def_t)); + assert(dst.action_def != NULL && "Memory exhausted"); + *dst.action_def = fill_rnd_dapp_action_def(); + return dst; +} + +static dapp_ind_data_t fill_rnd_dapp_ind_data_fmt2(void) +{ + dapp_ind_data_t dst = {0}; + dst.hdr.format = FORMAT_2_E2SM_DAPP_IND_HDR; + dst.hdr.frmt_2 = fill_rnd_dapp_ind_hdr_frmt_2(); + + dst.msg.format = FORMAT_2_E2SM_DAPP_IND_MSG; + dst.msg.frmt_2 = fill_rnd_dapp_ind_msg_frmt_2(); + + dst.e3.type = DAPP_E3_SM_NONE; + return dst; +} + +static dapp_ind_data_t fill_rnd_dapp_ind_data_fmt1_spectrum(void) +{ + spectrum_sm_report_t report = fill_rnd_spectrum_report(); + byte_array_t ba = spectrum_report_to_aper_bytes(&report); + + while (ba.len == 0) { + free_byte_array(ba); + free_spectrum_sm_report(&report); + report = fill_rnd_spectrum_report(); + if (report.prb_count == 0) { + report.prb_count = 1; + report.prbs = calloc(1, sizeof(uint16_t)); + assert(report.prbs != NULL && "Memory exhausted"); + report.prbs[0] = (uint16_t)(rand() % (DAPP_PRB_MAX_INDEX + 1)); + } + ba = spectrum_report_to_aper_bytes(&report); + } + + dapp_ind_data_t dst = {0}; + dst.hdr.format = FORMAT_1_E2SM_DAPP_IND_HDR; + dst.hdr.frmt_1 = fill_rnd_dapp_ind_hdr_frmt_1(); + dst.hdr.frmt_1.ran_function_id = DAPP_SPECTRUM_RAN_FUNCTION_ID; + + dst.msg.format = FORMAT_1_E2SM_DAPP_IND_MSG; + dst.msg.frmt_1.data_size = ba.len; + dst.msg.frmt_1.data = ba.buf; + + dst.e3.type = DAPP_E3_SM_SPECTRUM; + dst.e3.u.spectrum = report; + return dst; +} + +dapp_ind_data_t fill_rnd_dapp_ind_data(void) +{ + return (rand() & 1) ? fill_rnd_dapp_ind_data_fmt1_spectrum() : fill_rnd_dapp_ind_data_fmt2(); +} + +dapp_ctrl_req_data_t fill_dapp_ctrl(void) +{ + dapp_ctrl_req_data_t dst = {0}; + + dst.hdr.format = FORMAT_1_E2SM_DAPP_CTRL_HDR; + dst.hdr.frmt_1.ran_function_id = DAPP_SPECTRUM_RAN_FUNCTION_ID; + dst.hdr.frmt_1.dapp_id = (uint32_t)rand(); + dst.hdr.frmt_1.timestamp_ns = time_now_ns(); + dst.hdr.frmt_1.sequence_id = + (int64_t)rand() + 1; /* never 0: that's the "absent" sentinel */ + + dst.msg.format = FORMAT_1_E2SM_DAPP_CTRL_MSG; + dst.msg.frmt_1.data = NULL; + dst.msg.frmt_1.data_size = 0; + + dst.e3.type = DAPP_E3_SM_SPECTRUM; + dst.e3.u.spectrum.timestamp_ns = time_now_ns(); + long const prb_count = (long)((rand() % 16) + 1); + dst.e3.u.spectrum.prb_count = prb_count; + dst.e3.u.spectrum.blockedPRBs = calloc((size_t)prb_count, sizeof(uint16_t)); + assert(dst.e3.u.spectrum.blockedPRBs != NULL && "Memory exhausted"); + for (long i = 0; i < prb_count; ++i) + dst.e3.u.spectrum.blockedPRBs[i] = (uint16_t)(rand() % (DAPP_PRB_MAX_INDEX + 1)); + + return dst; +} diff --git a/test/rnd/fill_rnd_data_dapp.h b/test/rnd/fill_rnd_data_dapp.h new file mode 100644 index 000000000..9c488f086 --- /dev/null +++ b/test/rnd/fill_rnd_data_dapp.h @@ -0,0 +1,81 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#ifndef FILL_RND_DATA_DAPP_H +#define FILL_RND_DATA_DAPP_H + +#include "../../src/sm/dapp_sm/ie/dapp_data_ie.h" +#include "../../src/util/byte_array.h" + +/* Top-level dApp SM IEs ---------------------------------------------------- */ + +e2sm_dapp_event_trigger_t fill_rnd_dapp_ev_trigger(void); + +e2sm_dapp_action_def_t fill_rnd_dapp_action_def(void); + +e2sm_dapp_ind_hdr_frmt_1_t fill_rnd_dapp_ind_hdr_frmt_1(void); +e2sm_dapp_ind_hdr_frmt_2_t fill_rnd_dapp_ind_hdr_frmt_2(void); +e2sm_dapp_ind_hdr_t fill_rnd_dapp_ind_hdr(void); + +e2sm_dapp_ind_msg_frmt_1_t fill_rnd_dapp_ind_msg_frmt_1(void); +e2sm_dapp_ind_msg_frmt_2_t fill_rnd_dapp_ind_msg_frmt_2(void); +e2sm_dapp_ind_msg_t fill_rnd_dapp_ind_msg(void); + +e2sm_dapp_ctrl_hdr_t fill_rnd_dapp_ctrl_hdr(void); +e2sm_dapp_ctrl_msg_t fill_rnd_dapp_ctrl_msg(void); +e2sm_dapp_ctrl_out_t fill_rnd_dapp_ctrl_out(void); + +e2sm_dapp_func_def_t fill_rnd_dapp_func_def(void); + +/* Top-level containers used by the agent ⇄ RIC roundtrip test -------------- */ + +/* + * Indication container, randomly chooses Format 1 or Format 2. + * - Format 2: hdr+msg are subscription maps, e3 stays DAPP_E3_SM_NONE. + * - Format 1: hdr.frmt_1.ran_function_id = 1 (Spectrum), msg.frmt_1.data + * contains valid Spectrum-PRBBlacklistReport bytes, and e3 mirrors the + * same prbs so the RIC's inner E3 decoder yields a result equal to e3. + */ +dapp_ind_data_t fill_rnd_dapp_ind_data(void); + +dapp_sub_data_t fill_rnd_dapp_subscription(void); + +/* + * Control request shaped to traverse the RIC's E3 spectrum encoding path: + * - hdr.frmt_1.ran_function_id = 1 (Spectrum) + * - msg.frmt_1.{data,data_size} are NULL/0 so the RIC injects encoded E3 bytes + * - e3.type = DAPP_E3_SM_SPECTRUM with random PRBs + */ +dapp_ctrl_req_data_t fill_dapp_ctrl(void); + +e2sm_dapp_ctrl_out_t fill_dapp_ctrl_out(void); + +/* + * RAN function definition matching what the dApp SM agent installs at E2 setup. + * Name/OID/description come from dapp_sm_id.h so the equality check after + * encode/decode survives the agent overwriting the name in on_e2_setup. + */ +e2sm_dapp_func_def_t fill_dapp_ran_func_def(void); + +/* Spectrum SM helpers ------------------------------------------------------ */ + +spectrum_sm_report_t fill_rnd_spectrum_report(void); +spectrum_sm_control_t fill_rnd_spectrum_control(void); + +/* + * Encode an IR Spectrum report into APER bytes via the asn1c runtime + * directly. The production codebase only ships spectrum_sm_dec_report (the + * gNB-side encoder lives outside this repo), so tests need this bridge to + * round-trip the report direction. + */ +byte_array_t spectrum_report_to_aper_bytes(spectrum_sm_report_t const* r); + +/* + * Decode APER-encoded Spectrum control bytes into IR via the asn1c runtime. + * Mirror of spectrum_report_to_aper_bytes for the control direction: + * production only ships spectrum_sm_enc_control. + */ +bool spectrum_control_from_aper_bytes(uint8_t const* buf, size_t len, spectrum_sm_control_t* out); + +#endif diff --git a/test/sm/CMakeLists.txt b/test/sm/CMakeLists.txt index 2fe78b6e4..b47afc1a3 100644 --- a/test/sm/CMakeLists.txt +++ b/test/sm/CMakeLists.txt @@ -9,4 +9,5 @@ add_subdirectory(gtp_sm) add_subdirectory(rc_sm) add_subdirectory(kpm_sm) add_subdirectory(ccc_sm) +add_subdirectory(dapp_sm) enable_testing() diff --git a/test/sm/dapp_sm/CMakeLists.txt b/test/sm/dapp_sm/CMakeLists.txt new file mode 100644 index 000000000..cba33494b --- /dev/null +++ b/test/sm/dapp_sm/CMakeLists.txt @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: LicenseRef-CSSL-1.0 + +set(SM_ENCODING_DAPP "ASN" CACHE STRING "The DAPP SM encoding to use") +set_property(CACHE SM_ENCODING_DAPP PROPERTY STRINGS "ASN") +message(STATUS "Selected DAPP SM_ENCODING: ${SM_ENCODING_DAPP}") + +if(SM_ENCODING_DAPP STREQUAL "ASN") + add_executable(test_dapp_sm + main.c + ../../rnd/fill_rnd_data_dapp.c + ../../../src/util/time_now_us.c + ../../../src/util/alg_ds/alg/defer.c + ) +endif() + +target_compile_definitions(test_dapp_sm PUBLIC ${SM_ENCODING_DAPP}) +target_link_libraries(test_dapp_sm PUBLIC dapp_sm_static e2sm_dapp_e3_spectrum_asn1_obj dapp_sm_static -pthread -lm) + + +enable_testing() +add_test(Unit_test_DAPP test_dapp_sm) diff --git a/test/sm/dapp_sm/main.c b/test/sm/dapp_sm/main.c new file mode 100644 index 000000000..c6eddd4f0 --- /dev/null +++ b/test/sm/dapp_sm/main.c @@ -0,0 +1,220 @@ +/* + * SPDX-License-Identifier: LicenseRef-CSSL-1.0 + */ + +#include "../../rnd/fill_rnd_data_dapp.h" +#include "../../../src/util/alg_ds/alg/defer.h" +#include "../../../src/sm/dapp_sm/dapp_sm_agent.h" +#include "../../../src/sm/dapp_sm/dapp_sm_ric.h" +#include "../../../src/sm/dapp_sm/ie/dapp_data_ie.h" + +#include +#include +#include +#include + +/* ---- Captures from the agent-side I/O callbacks --------------------------- */ + +static dapp_ind_data_t cp_ind; +static dapp_e2_setup_t cp_e2_setup; +static dapp_sub_data_t cp_dapp_sub; +static dapp_ctrl_req_data_t cp_dapp_ctrl; +static e2sm_dapp_ctrl_out_t cp_dapp_ctrl_out; + +/* ---- Agent-side I/O implementations -------------------------------------- */ + +static bool read_ind_dapp(void* read) +{ + assert(read != NULL); + + dapp_rd_ind_data_t* dapp = (dapp_rd_ind_data_t*)read; + dapp->ind = fill_rnd_dapp_ind_data(); + cp_ind = cp_dapp_ind_data(&dapp->ind); + assert(eq_dapp_ind_data(&dapp->ind, &cp_ind) == true); + return true; +} + +static void read_setup_dapp(void* read) +{ + assert(read != NULL); + + dapp_e2_setup_t* dapp = (dapp_e2_setup_t*)read; + dapp->ran_func_def = fill_dapp_ran_func_def(); + cp_e2_setup.ran_func_def = cp_e2sm_dapp_func_def(&dapp->ran_func_def); + assert(eq_e2sm_dapp_func_def(&cp_e2_setup.ran_func_def, &dapp->ran_func_def) == true); +} + +static void free_aperiodic_subscription(uint32_t ric_req_id) { (void)ric_req_id; } + +static sm_ag_if_ans_t write_subs_dapp(void const* data) +{ + assert(data != NULL); + + wr_dapp_sub_data_t const* wr_dapp = (wr_dapp_sub_data_t const*)data; + cp_dapp_sub = cp_dapp_sub_data(&wr_dapp->dapp); + + sm_ag_if_ans_t ans = {.type = SUBS_OUTCOME_SM_AG_IF_ANS_V0}; + ans.subs_out.type = APERIODIC_SUBSCRIPTION_FLRC; + ans.subs_out.aper.free_aper_subs = free_aperiodic_subscription; + return ans; +} + +static sm_ag_if_ans_t write_ctrl_dapp(void const* data) +{ + assert(data != NULL); + + dapp_ctrl_req_data_t const* ctrl = (dapp_ctrl_req_data_t const*)data; + cp_dapp_ctrl = cp_dapp_ctrl_req_data(ctrl); + + sm_ag_if_ans_t ans = {.type = CTRL_OUTCOME_SM_AG_IF_ANS_V0}; + ans.ctrl_out.type = DAPP_AGENT_IF_CTRL_ANS_V0; + ans.ctrl_out.dapp = fill_dapp_ctrl_out(); + cp_dapp_ctrl_out = cp_e2sm_dapp_ctrl_out(&ans.ctrl_out.dapp); + + return ans; +} + +/* ---- Procedure round-trip checks ----------------------------------------- */ + +static void check_subscription(sm_agent_t* ag, sm_ric_t* ric) +{ + assert(ag != NULL); + assert(ric != NULL); + + dapp_sub_data_t dapp = fill_rnd_dapp_subscription(); + defer({ free_dapp_sub_data(&dapp); }); + + sm_subs_data_t data = ric->proc.on_subscription(ric, &dapp); + defer({ ric->alloc.free_subs_data_msg(&data); }); + + sm_ag_if_ans_subs_t const subs = ag->proc.on_subscription(ag, &data); + assert(subs.type == APERIODIC_SUBSCRIPTION_FLRC); + assert(subs.aper.free_aper_subs != NULL); + + defer({ free_dapp_sub_data(&cp_dapp_sub); }); + + assert(eq_dapp_sub_data(&dapp, &cp_dapp_sub) == true); +} + +static void check_indication(sm_agent_t* ag, sm_ric_t* ric) +{ + assert(ag != NULL); + assert(ric != NULL); + + dapp_ind_data_t* d = calloc(1, sizeof(dapp_ind_data_t)); + assert(d != NULL && "Memory exhausted"); + *d = fill_rnd_dapp_ind_data(); + cp_ind = cp_dapp_ind_data(d); + + exp_ind_data_t exp = ag->proc.on_indication(ag, d); + assert(exp.has_value == true); + defer({ free_exp_ind_data(&exp); }); + defer({ free_dapp_ind_data(&cp_ind); }); + + sm_ag_if_rd_ind_t msg = ric->proc.on_indication(ric, &exp.data); + assert(msg.type == DAPP_STATS_V0); + defer({ ric->alloc.free_ind_data(&msg); }); + + dapp_ind_data_t const* data = &msg.dapp.ind; + assert(eq_dapp_ind_data(&cp_ind, data) == true); +} + +static void check_ctrl(sm_agent_t* ag, sm_ric_t* ric) +{ + assert(ag != NULL); + assert(ric != NULL); + + dapp_ctrl_req_data_t dapp_ctrl = fill_dapp_ctrl(); + defer({ free_dapp_ctrl_req_data(&dapp_ctrl); }); + + sm_ctrl_req_data_t ctrl_req = ric->proc.on_control_req(ric, &dapp_ctrl); + defer({ ric->alloc.free_ctrl_req_data(&ctrl_req); }); + + sm_ctrl_out_data_t out_data = ag->proc.on_control(ag, &ctrl_req); + defer({ free_sm_ctrl_out_data(&out_data); }); + defer({ free_dapp_ctrl_req_data(&cp_dapp_ctrl); }); + + assert(eq_e2sm_dapp_ctrl_hdr(&dapp_ctrl.hdr, &cp_dapp_ctrl.hdr) == true); + assert(cp_dapp_ctrl.msg.format == FORMAT_1_E2SM_DAPP_CTRL_MSG); + assert(cp_dapp_ctrl.msg.frmt_1.data != NULL); + assert(cp_dapp_ctrl.msg.frmt_1.data_size > 0); + + sm_ag_if_ans_ctrl_t ans = ric->proc.on_control_out(ric, &out_data); + assert(ans.type == DAPP_AGENT_IF_CTRL_ANS_V0); + defer({ ric->alloc.free_ctrl_out_data(&ans); }); + defer({ free_e2sm_dapp_ctrl_out(&cp_dapp_ctrl_out); }); + + assert(eq_e2sm_dapp_ctrl_out(&ans.dapp, &cp_dapp_ctrl_out) == true); +} + +static void check_e2_setup(sm_agent_t* ag, sm_ric_t* ric) +{ + assert(ag != NULL); + assert(ric != NULL); + + sm_e2_setup_data_t data = ag->proc.on_e2_setup(ag); + defer({ free_sm_e2_setup(&data); }); + + sm_ag_if_rd_e2setup_t out = ric->proc.on_e2_setup(ric, &data); + assert(out.type == DAPP_AGENT_IF_E2_SETUP_ANS_V0); + defer({ ric->alloc.free_e2_setup(&out); }); + + assert(eq_e2sm_dapp_func_def(&out.dapp.ran_func_def, &cp_e2_setup.ran_func_def) == true); + free_e2sm_dapp_func_def(&cp_e2_setup.ran_func_def); +} + +static void check_ric_service_update(sm_agent_t* ag, sm_ric_t* ric) +{ + assert(ag != NULL); + assert(ric != NULL); + + sm_ric_service_update_data_t agent_data = ag->proc.on_ric_service_update(ag); + assert(agent_data.ran_fun_def == NULL); + assert(agent_data.len_rfd == 0); + + sm_ag_if_rd_rsu_t ric_data = ric->proc.on_ric_service_update(ric, &agent_data); + ric->alloc.free_ric_service_update(&ric_data); +} + +static void check_ric_alloc_table_complete(sm_ric_t* ric) +{ + assert(ric != NULL); + assert(ric->alloc.free_subs_data_msg != NULL); + assert(ric->alloc.free_ind_data != NULL); + assert(ric->alloc.free_ctrl_req_data != NULL); + assert(ric->alloc.free_ctrl_out_data != NULL); + assert(ric->alloc.free_e2_setup != NULL); + assert(ric->alloc.free_ric_service_update != NULL); +} + +int main(void) +{ + srand((unsigned)time(NULL)); + + sm_io_ag_ran_t io_ag = {0}; + io_ag.read_ind_tbl[DAPP_STATS_V0] = read_ind_dapp; + io_ag.read_setup_tbl[DAPP_AGENT_IF_E2_SETUP_ANS_V0] = read_setup_dapp; + io_ag.write_ctrl_tbl[DAPP_CTRL_V0] = write_ctrl_dapp; + io_ag.write_subs_tbl[DAPP_SUBS_V0] = write_subs_dapp; + + sm_agent_t* sm_ag = make_dapp_sm_agent(io_ag); + sm_ric_t* sm_ric = make_dapp_sm_ric(); + + printf("Running DAPP SM agent ⇄ RIC roundtrip test. Patience.\n"); + for (int i = 0; i < 1024; ++i) { + check_subscription(sm_ag, sm_ric); + check_indication(sm_ag, sm_ric); + check_ctrl(sm_ag, sm_ric); + check_e2_setup(sm_ag, sm_ric); + check_ric_service_update(sm_ag, sm_ric); + } + + check_ric_alloc_table_complete(sm_ric); + + sm_ag->free_sm(sm_ag); + sm_ric->free_sm(sm_ric); + + printf("DAPP SM agent ⇄ RIC roundtrip test passed\n"); + return EXIT_SUCCESS; +} +