diff --git a/main.c b/src/main.c similarity index 83% rename from main.c rename to src/main.c index 401eb58..478599b 100644 --- a/main.c +++ b/src/main.c @@ -1,5 +1,6 @@ /* * (C) 2022 by Harald Welte + * (C) 2021 by Andreas Eversberg * All Rights Reserved * * This program is free software; you can redistribute it and/or modify @@ -50,15 +51,15 @@ #include -#include "logging.h" #include "v5x_internal.h" #include "v5x_protocol.h" -#include "v51_le_ctrl.h" -#include "v52_le_user_port_fsm.h" +#include "v5x_le_ctrl_fsm.h" +#include "v5x_le_port_fsm.h" #include "v5x_le_pstn_fsm.h" -#include "v5x_l2_mgmt.h" -#include "v51_le_provisioning.h" -#include "lapv5.h" +#include "v5x_le_management.h" +#include "v5x_le_provisioning.h" +#include "v5x_vty.h" +#include "logging.h" #define _GNU_SOURCE #include @@ -103,7 +104,6 @@ static const struct e1inp_line_ops v5le_e1_line_ops = { .sign_link = v5le_rx_sign, }; -#include "v5x_protocol.h" /* data L1 -> L2 */ static void hdlc_rx_cb(struct e1inp_ts *ts, struct msgb *msg) { @@ -183,6 +183,56 @@ int ph_data_req_raw(struct msgb *msg, int ts_nr) return e1inp_ts_send_raw(ts, msg); } +#warning hacking +void ph_socket_rx_cb(ph_socket_t *s, int channel, uint8_t prim, uint8_t *data, int length) +{ + struct v5x_user_port *v5up = s->priv; + + switch (prim) { + case PH_PRIM_CTRL_REQ: + /* deactivate channels, if active */ + if ((channel == 0 || channel == 3) && length && *data == PH_CTRL_BLOCK) { + v5up->ts_activated[0] = 0; + v5up->ts_activated[1] = 0; + } + v5x_mph_rcv_le(v5up, prim, data, length); + break; + case PH_PRIM_ACT_REQ: + if (channel == 1 || channel == 2) { + v5up->ts_activated[channel - 1] = 1; + ph_socket_tx_msg(s, channel, PH_PRIM_ACT_IND, NULL, 0); + break; + } + v5x_mph_rcv_le(v5up, prim, data, length); + break; + case PH_PRIM_DACT_REQ: + if (channel == 1 || channel == 2) { + v5up->ts_activated[channel - 1] = 0; + ph_socket_tx_msg(s, channel, PH_PRIM_DACT_IND, NULL, 0); + break; + } + v5x_mph_rcv_le(v5up, prim, data, length); + break; + case PH_PRIM_DATA_REQ: + if (v5up->type == V5X_USER_TYPE_PSTN && channel == 0) { + struct msgb *msg = msgb_alloc_headroom(length + 32, 32, "V5 PSTN MSG"); + memcpy(msgb_put(msg, length), data, length); + v5x_nat_rcv_fe(v5up, msg); + } else if (v5up->type == V5X_USER_TYPE_ISDN && channel == 3) { + struct msgb *msg = msgb_alloc_headroom(length + 32, 32, "V5 EF MSG"); + memcpy(msgb_put(msg, length), data, length); + lapv5ef_tx(v5up, msg); + } else if ((channel == 1 || channel == 2) && v5up->ts_nr[channel - 1]) { + struct msgb *msg = msgb_alloc_headroom(length + 32, 32, "B MSG"); + memcpy(msgb_put(msg, length), data, length); + ph_data_req_raw(msg, v5up->ts_nr[channel - 1]); + } + /* always confirm */ + ph_socket_tx_msg(s, channel, PH_PRIM_DATA_CNF, NULL, 0); + break; + } +} + static int e1_init(void) { int line_nr = 1, ts; @@ -210,12 +260,12 @@ static struct v5le_config *g_cfg; static int daemonize = 0; const char *v5le_copyright = - "Copyright (C) 2022 by Harald Welte\r\n" + "Copyright (C) 2022 by Harald Welte & Andreas Eversberg\r\n" "License AGPLv3+: GNU AGPL version 3 or later \r\n" "This is free software: you are free to change and redistribute it.\r\n" "There is NO WARRANTY, to the extent permitted by law.\r\n"; -static char *config_file = "osmo-v5le.cfg"; +static char *config_file = "osmo-v5-le.cfg"; static void print_help() { @@ -309,39 +359,6 @@ static void handle_options(int argc, char **argv) } } -int v5le_vty_is_config_node(struct vty *vty, int node) -{ - switch (node) { - case CONFIG_NODE: - return 0; - default: - return 1; - } -} - -int v5le_vty_go_parent(struct vty *vty) -{ - switch (vty->node) { - default: - if (v5le_vty_is_config_node(vty, vty->node)) - vty->node = CONFIG_NODE; - else - vty->node = ENABLE_NODE; - - vty->index = NULL; - } - - return vty->node; -} - - -static struct vty_app_info vty_info = { - .name = "OsmoV5LE", - .version = PACKAGE_VERSION, - .go_parent_cb = v5le_vty_go_parent, - .is_config_node = v5le_vty_is_config_node, -}; - int main(int argc, char **argv) { unsigned int flags; @@ -377,11 +394,11 @@ int main(int argc, char **argv) osmo_stats_init(tall_v5le_ctx); /* global inits of protocols */ - v51_ctrl_init(); - v51_port_ctrl_init(); - v51_pstn_init(); - v51_provisioning_init(); - v51_mgmt_init(); + v5x_le_ctrl_init(); + v5x_le_port_init(); + v5x_le_pstn_init(); + v5x_le_provisioning_init(); + v5x_le_mgmt_init(); /* create v5x instance */ v5i = v5x_instance_alloc(tall_v5le_ctx); @@ -391,20 +408,15 @@ int main(int argc, char **argv) // FIXME: move this to VTY code /* create v5x interface */ struct v5x_interface *v5if; -// struct v5x_user_port *v5up; - uint32_t interface_id = 1; - uint8_t interface_variant = 1; - v5if = v5x_interface_alloc(v5i, V5X_DIALECT_V51, interface_id, interface_variant, ph_data_req); + v5if = v5x_interface_alloc(v5i, V5X_DIALECT_V51, ph_data_req); if (!v5if) return -ENOMEM; -// v5up = v5x_user_port_create(v5if, 1001, V5X_USER_TYPE_ISDN, 1, 2); -// v5up = v5x_user_port_create(v5if, 1002, V5X_USER_TYPE_PSTN, 3, 0); -// if (!v5up) -// return -ENOMEM; rc = vty_read_config_file(config_file, NULL); - if (rc < 0) + if (rc < 0) { + fprintf(stderr, "Failed to read config file '%s'.\n", config_file); return rc; + } g_gti = gsmtap_source_init("224.0.0.1", GSMTAP_UDP_PORT, 0); OSMO_ASSERT(g_gti);