From d9956d91ba1504deae248b3e1978de5e584f275f Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 17 Dec 2017 21:48:47 +0100 Subject: Remove dead code left over from NITB split There still is a lot of dead code that we inherited from the NITB days, let's remove more of it. libtrau will be re-introduced as part of osmo-mgw later. Change-Id: I8e0af56a158f25a4f1384d667c03eb20e72df5b8 --- src/Makefile.am | 1 - src/ipaccess/Makefile.am | 3 - src/ipaccess/ipaccess-config.c | 2 +- src/libbsc/abis_rsl.c | 24 +- src/libbsc/bsc_api.c | 12 - src/libbsc/bsc_init.c | 4 +- src/libbsc/chan_alloc.c | 14 - src/libbsc/e1_config.c | 9 - src/libbsc/gsm_04_08_utils.c | 1 - src/libbsc/handover_logic.c | 7 - src/libbsc/net_init.c | 5 +- src/libcommon-cs/common_cs.c | 20 +- src/libcommon-cs/common_cs_vty.c | 1 - src/libcommon/Makefile.am | 1 - src/libcommon/common_vty.c | 1 - src/libcommon/gsm_subscriber_base.c | 37 -- src/libcommon/talloc_ctx.c | 4 - src/libtrau/Makefile.am | 31 -- src/libtrau/rtp_proxy.c | 764 ------------------------------------ src/libtrau/trau_mux.c | 547 -------------------------- src/libtrau/trau_upqueue.c | 27 -- src/osmo-bsc/Makefile.am | 2 - src/osmo-bsc/osmo_bsc_filter.c | 1 - src/osmo-bsc/osmo_bsc_main.c | 2 +- src/osmo-bsc_nat/Makefile.am | 1 - src/osmo-bsc_nat/bsc_filter.c | 2 + src/utils/Makefile.am | 1 - src/utils/bs11_config.c | 2 +- 28 files changed, 15 insertions(+), 1511 deletions(-) delete mode 100644 src/libcommon/gsm_subscriber_base.c delete mode 100644 src/libtrau/Makefile.am delete mode 100644 src/libtrau/rtp_proxy.c delete mode 100644 src/libtrau/trau_mux.c delete mode 100644 src/libtrau/trau_upqueue.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 454bf26e1..637272de1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,7 +24,6 @@ SUBDIRS = \ libcommon \ libcommon-cs \ libbsc \ - libtrau \ libfilter \ $(NULL) diff --git a/src/ipaccess/Makefile.am b/src/ipaccess/Makefile.am index 4dfe24738..b3b2b8cd8 100644 --- a/src/ipaccess/Makefile.am +++ b/src/ipaccess/Makefile.am @@ -30,7 +30,6 @@ bin_PROGRAMS = \ abisip_find_LDADD = \ $(top_builddir)/src/libbsc/libbsc.a \ - $(top_builddir)/src/libtrau/libtrau.a \ $(top_builddir)/src/libcommon/libcommon.a \ $(OSMO_LIBS) \ $(NULL) @@ -49,7 +48,6 @@ ipaccess_config_SOURCES = \ ipaccess_config_LDADD = \ $(top_builddir)/src/libbsc/libbsc.a \ $(top_builddir)/src/libcommon-cs/libcommon-cs.a \ - $(top_builddir)/src/libtrau/libtrau.a \ $(top_builddir)/src/libcommon/libcommon.a \ $(OSMO_LIBS) \ $(NULL) @@ -60,7 +58,6 @@ ipaccess_proxy_SOURCES = \ ipaccess_proxy_LDADD = \ $(top_builddir)/src/libbsc/libbsc.a \ - $(top_builddir)/src/libtrau/libtrau.a \ $(top_builddir)/src/libcommon/libcommon.a \ $(OSMO_LIBS) \ $(NULL) diff --git a/src/ipaccess/ipaccess-config.c b/src/ipaccess/ipaccess-config.c index c68e3eadd..957a5bb2c 100644 --- a/src/ipaccess/ipaccess-config.c +++ b/src/ipaccess/ipaccess-config.c @@ -978,7 +978,7 @@ int main(int argc, char **argv) } libosmo_abis_init(tall_ctx_config); - bsc_gsmnet = bsc_network_init(tall_bsc_ctx, 1, 1, NULL); + bsc_gsmnet = bsc_network_init(tall_bsc_ctx, 1, 1); if (!bsc_gsmnet) exit(1); diff --git a/src/libbsc/abis_rsl.c b/src/libbsc/abis_rsl.c index ef7a6fbd5..980b3e662 100644 --- a/src/libbsc/abis_rsl.c +++ b/src/libbsc/abis_rsl.c @@ -40,8 +40,6 @@ #include #include #include -#include -#include #include #include #include @@ -51,6 +49,11 @@ #define RSL_ALLOC_SIZE 1024 #define RSL_ALLOC_HEADROOM 128 +#define RTP_PT_GSM_FULL 3 +#define RTP_PT_GSM_HALF 96 +#define RTP_PT_GSM_EFR 97 +#define RTP_PT_AMR 98 + enum sacch_deact { SACCH_NONE, SACCH_DEACTIVATE, @@ -160,9 +163,6 @@ static struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr, LOGP(DRSL, LOGL_ERROR, "%s %smismatching chan_nr=0x%02x\n", gsm_ts_and_pchan_name(lchan->ts), log_name, chan_nr); - if (lchan->conn) - log_set_context(LOG_CTX_VLR_SUBSCR, lchan->conn->vsub); - return lchan; } @@ -2422,20 +2422,6 @@ int rsl_ipacc_mdcx(struct gsm_lchan *lchan, uint32_t ip, uint16_t port, return abis_rsl_sendmsg(msg); } -/* tell BTS to connect RTP stream to our local RTP socket */ -int rsl_ipacc_mdcx_to_rtpsock(struct gsm_lchan *lchan) -{ - struct rtp_socket *rs = lchan->abis_ip.rtp_socket; - int rc; - - rc = rsl_ipacc_mdcx(lchan, ntohl(rs->rtp.sin_local.sin_addr.s_addr), - ntohs(rs->rtp.sin_local.sin_port), - /* FIXME: use RTP payload of bound socket, not BTS*/ - lchan->abis_ip.rtp_payload2); - - return rc; -} - int rsl_ipacc_pdch_activate(struct gsm_bts_trx_ts *ts, int act) { struct msgb *msg = rsl_msgb_alloc(); diff --git a/src/libbsc/bsc_api.c b/src/libbsc/bsc_api.c index 845b1b703..6ff1688f7 100644 --- a/src/libbsc/bsc_api.c +++ b/src/libbsc/bsc_api.c @@ -24,13 +24,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include @@ -263,7 +261,6 @@ struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_lchan *lcha conn->network = net; conn->lchan = lchan; conn->bts = lchan->ts->trx->bts; - conn->via_ran = RAN_GERAN_A; conn->lac = conn->bts->location_area_code; lchan->conn = conn; llist_add_tail(&conn->entry, &net->subscr_conns); @@ -278,11 +275,6 @@ void bsc_subscr_con_free(struct gsm_subscriber_connection *conn) if (conn->network->bsc_api->conn_cleanup) conn->network->bsc_api->conn_cleanup(conn); - if (conn->vsub) { - LOGP(DNM, LOGL_ERROR, "conn->vsub should have been cleared.\n"); - conn->vsub = NULL; - } - if (conn->ho_lchan) { LOGP(DNM, LOGL_ERROR, "The ho_lchan should have been cleared.\n"); conn->ho_lchan->conn = NULL; @@ -453,10 +445,6 @@ static void handle_ass_compl(struct gsm_subscriber_connection *conn, return; } - /* switch TRAU muxer for E1 based BTS from one channel to another */ - if (is_e1_bts(conn->bts)) - switch_trau_mux(conn->lchan, conn->secondary_lchan); - /* swap channels */ osmo_timer_del(&conn->T10); diff --git a/src/libbsc/bsc_init.c b/src/libbsc/bsc_init.c index 2fb384262..34dfd3610 100644 --- a/src/libbsc/bsc_init.c +++ b/src/libbsc/bsc_init.c @@ -529,10 +529,10 @@ static int bootstrap_bts(struct gsm_bts *bts) return 0; } -int bsc_network_alloc(mncc_recv_cb_t mncc_recv) +int bsc_network_alloc(void) { /* initialize our data structures */ - bsc_gsmnet = bsc_network_init(tall_bsc_ctx, 1, 1, mncc_recv); + bsc_gsmnet = bsc_network_init(tall_bsc_ctx, 1, 1); if (!bsc_gsmnet) return -ENOMEM; diff --git a/src/libbsc/chan_alloc.c b/src/libbsc/chan_alloc.c index 4b2531eac..ad24a1e78 100644 --- a/src/libbsc/chan_alloc.c +++ b/src/libbsc/chan_alloc.c @@ -25,12 +25,10 @@ #include #include -#include #include #include #include #include -#include #include #include @@ -392,13 +390,6 @@ void lchan_free(struct gsm_lchan *lchan) osmo_signal_dispatch(SS_LCHAN, S_LCHAN_UNEXPECTED_RELEASE, &sig); } - if (lchan->abis_ip.rtp_socket) { - LOGP(DRLL, LOGL_ERROR, "%s RTP Proxy Socket remained open.\n", - gsm_lchan_name(lchan)); - rtp_socket_free(lchan->abis_ip.rtp_socket); - lchan->abis_ip.rtp_socket = NULL; - } - /* stop the timer */ osmo_timer_del(&lchan->T3101); @@ -449,11 +440,6 @@ void lchan_reset(struct gsm_lchan *lchan) lchan->type = GSM_LCHAN_NONE; rsl_lchan_set_state(lchan, LCHAN_S_NONE); - - if (lchan->abis_ip.rtp_socket) { - rtp_socket_free(lchan->abis_ip.rtp_socket); - lchan->abis_ip.rtp_socket = NULL; - } } /* Drive the release process of the lchan */ diff --git a/src/libbsc/e1_config.c b/src/libbsc/e1_config.c index 365631562..90e29d3cf 100644 --- a/src/libbsc/e1_config.c +++ b/src/libbsc/e1_config.c @@ -25,8 +25,6 @@ #include #include -#include -#include #include #include #include @@ -45,7 +43,6 @@ int e1_reconfig_ts(struct gsm_bts_trx_ts *ts) { struct gsm_e1_subslot *e1_link = &ts->e1_link; struct e1inp_line *line; - struct e1inp_ts *e1_ts; DEBUGP(DLMI, "e1_reconfig_ts(%u,%u,%u)\n", ts->trx->bts->nr, ts->trx->nr, ts->nr); @@ -63,12 +60,6 @@ int e1_reconfig_ts(struct gsm_bts_trx_ts *ts) return -ENOMEM; } - if (ts_is_tch(ts)) { - e1_ts = &line->ts[e1_link->e1_ts-1]; - e1inp_ts_config_trau(e1_ts, line, subch_cb); - subch_demux_activate(&e1_ts->trau.demux, e1_link->e1_ts_ss); - } - return 0; } diff --git a/src/libbsc/gsm_04_08_utils.c b/src/libbsc/gsm_04_08_utils.c index 7fc696f53..414fd6d47 100644 --- a/src/libbsc/gsm_04_08_utils.c +++ b/src/libbsc/gsm_04_08_utils.c @@ -32,7 +32,6 @@ #include #include -#include #include #include #include diff --git a/src/libbsc/handover_logic.c b/src/libbsc/handover_logic.c index 7b9dece9d..a30cd0912 100644 --- a/src/libbsc/handover_logic.c +++ b/src/libbsc/handover_logic.c @@ -32,13 +32,10 @@ #include #include #include -#include #include #include #include #include -#include -#include #include #include @@ -271,10 +268,6 @@ static int ho_gsm48_ho_compl(struct gsm_lchan *new_lchan) osmo_timer_del(&ho->T3103); - /* switch TRAU muxer for E1 based BTS from one channel to another */ - if (is_e1_bts(new_lchan->conn->bts)) - switch_trau_mux(ho->old_lchan, new_lchan); - /* Replace the ho lchan with the primary one */ if (ho->old_lchan != new_lchan->conn->lchan) LOGP(DHO, LOGL_ERROR, "Primary lchan changed during handover.\n"); diff --git a/src/libbsc/net_init.c b/src/libbsc/net_init.c index a71662c9a..59a8d5caa 100644 --- a/src/libbsc/net_init.c +++ b/src/libbsc/net_init.c @@ -24,12 +24,11 @@ struct gsm_network *bsc_network_init(void *ctx, uint16_t country_code, - uint16_t network_code, - mncc_recv_cb_t mncc_recv) + uint16_t network_code) { struct gsm_network *net; - net = gsm_network_init(ctx, country_code, network_code, mncc_recv); + net = gsm_network_init(ctx, country_code, network_code); net->bsc_data = talloc_zero(net, struct osmo_bsc_data); if (!net->bsc_data) { diff --git a/src/libcommon-cs/common_cs.c b/src/libcommon-cs/common_cs.c index 2ac261257..b410b1764 100644 --- a/src/libcommon-cs/common_cs.c +++ b/src/libcommon-cs/common_cs.c @@ -27,7 +27,6 @@ #include #include -#include #include #include @@ -39,8 +38,7 @@ */ struct gsm_network *gsm_network_init(void *ctx, uint16_t country_code, - uint16_t network_code, - mncc_recv_cb_t mncc_recv) + uint16_t network_code) { struct gsm_network *net; @@ -55,7 +53,6 @@ struct gsm_network *gsm_network_init(void *ctx, net->t3212 = 5; INIT_LLIST_HEAD(&net->trans_list); - INIT_LLIST_HEAD(&net->upqueue); INIT_LLIST_HEAD(&net->subscr_conns); net->bsc_subscribers = talloc_zero(net, struct llist_head); @@ -63,8 +60,6 @@ struct gsm_network *gsm_network_init(void *ctx, net->active_calls = osmo_counter_alloc("msc.active_calls"); - net->mncc_recv = mncc_recv; - net->dyn_ts_allow_tch_f = true; INIT_LLIST_HEAD(&net->a.bscs); @@ -128,16 +123,3 @@ int gsm48_paging_extract_mi(struct gsm48_pag_resp *resp, int length, return gsm48_extract_mi(classmark2_lv, length - classmark_offset, mi_string, mi_type); } - -uint8_t sms_next_rp_msg_ref(uint8_t *next_rp_ref) -{ - const uint8_t rp_msg_ref = *next_rp_ref; - /* - * This should wrap as the valid range is 0 to 255. We only - * transfer one SMS at a time so we don't need to check if - * the id has been already assigned. - */ - *next_rp_ref += 1; - - return rp_msg_ref; -} diff --git a/src/libcommon-cs/common_cs_vty.c b/src/libcommon-cs/common_cs_vty.c index 74b1a9395..beb936bfd 100644 --- a/src/libcommon-cs/common_cs_vty.c +++ b/src/libcommon-cs/common_cs_vty.c @@ -28,7 +28,6 @@ #include #include -#include struct cmd_node net_node = { GSMNET_NODE, diff --git a/src/libcommon/Makefile.am b/src/libcommon/Makefile.am index 6cfebc2da..ec997b76a 100644 --- a/src/libcommon/Makefile.am +++ b/src/libcommon/Makefile.am @@ -25,5 +25,4 @@ libcommon_a_SOURCES = \ gsm_data_shared.c \ socket.c \ talloc_ctx.c \ - gsm_subscriber_base.c \ $(NULL) diff --git a/src/libcommon/common_vty.c b/src/libcommon/common_vty.c index d4d5fb5ab..82327d190 100644 --- a/src/libcommon/common_vty.c +++ b/src/libcommon/common_vty.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include diff --git a/src/libcommon/gsm_subscriber_base.c b/src/libcommon/gsm_subscriber_base.c deleted file mode 100644 index a746c2468..000000000 --- a/src/libcommon/gsm_subscriber_base.c +++ /dev/null @@ -1,37 +0,0 @@ -/* The concept of a subscriber as seen by the BSC */ - -/* (C) 2008 by Harald Welte - * (C) 2009-2010 by Holger Hans Peter Freyther - * (C) 2010 by On-Waves - * - * All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -LLIST_HEAD(active_subscribers); -void *tall_subscr_ctx; - diff --git a/src/libcommon/talloc_ctx.c b/src/libcommon/talloc_ctx.c index c8e9cd31d..9f64d75b3 100644 --- a/src/libcommon/talloc_ctx.c +++ b/src/libcommon/talloc_ctx.c @@ -32,8 +32,6 @@ extern void *tall_paging_ctx; extern void *tall_sigh_ctx; extern void *tall_tqe_ctx; extern void *tall_trans_ctx; -extern void *tall_map_ctx; -extern void *tall_upq_ctx; extern void *tall_ctr_ctx; void talloc_ctx_init(void *ctx_root) @@ -49,7 +47,5 @@ void talloc_ctx_init(void *ctx_root) tall_sigh_ctx = talloc_named_const(ctx_root, 0, "signal_handler"); tall_tqe_ctx = talloc_named_const(ctx_root, 0, "subch_txq_entry"); tall_trans_ctx = talloc_named_const(ctx_root, 0, "transaction"); - tall_map_ctx = talloc_named_const(ctx_root, 0, "trau_map_entry"); - tall_upq_ctx = talloc_named_const(ctx_root, 0, "trau_upq_entry"); tall_ctr_ctx = talloc_named_const(ctx_root, 0, "counter"); } diff --git a/src/libtrau/Makefile.am b/src/libtrau/Makefile.am deleted file mode 100644 index 46becd6aa..000000000 --- a/src/libtrau/Makefile.am +++ /dev/null @@ -1,31 +0,0 @@ -AM_CPPFLAGS = \ - $(all_includes) \ - -I$(top_srcdir)/include \ - -I$(top_builddir) \ - $(NULL) - -AM_CFLAGS = \ - -Wall \ - $(LIBOSMOCORE_CFLAGS) \ - $(LIBOSMOVTY_CFLAGS) \ - $(LIBOSMOABIS_CFLAGS) \ - $(LIBOSMONETIF_CFLAGS) \ - $(COVERAGE_CFLAGS) \ - $(NULL) - -AM_LDFLAGS = \ - $(LIBOSMOCORE_LIBS) \ - $(LIBOSMOGSM_LIBS) \ - $(LIBOSMOABIS_LIBS) \ - $(COVERAGE_LDFLAGS) \ - $(NULL) - -noinst_LIBRARIES = \ - libtrau.a \ - $(NULL) - -libtrau_a_SOURCES = \ - rtp_proxy.c \ - trau_mux.c \ - trau_upqueue.c \ - $(NULL) diff --git a/src/libtrau/rtp_proxy.c b/src/libtrau/rtp_proxy.c deleted file mode 100644 index 5b1ca7913..000000000 --- a/src/libtrau/rtp_proxy.c +++ /dev/null @@ -1,764 +0,0 @@ -/* RTP proxy handling for ip.access nanoBTS */ - -/* (C) 2009-2013 by Harald Welte - * All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -#include -#include -#include -#include -#include -#include /* gettimeofday() */ -#include /* get..() */ -#include /* clock() */ -#include /* uname() */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -/* attempt to determine byte order */ -#include -#include - -static LLIST_HEAD(rtp_sockets); - -/* should we mangle the CNAME inside SDES of RTCP packets? We disable - * this by default, as it seems to be not needed */ -static int mangle_rtcp_cname = 0; - -enum rtp_bfd_priv { - RTP_PRIV_NONE, - RTP_PRIV_RTP, - RTP_PRIV_RTCP -}; - -#define RTP_ALLOC_SIZE 1500 - -#define RTCP_TYPE_SDES 202 - -#define RTCP_IE_CNAME 1 - - -#define RTP_VERSION 2 - -/* 33 for FR, all other codecs have smaller size */ -#define MAX_RTP_PAYLOAD_LEN 33 - -/* decode an rtp frame and create a new buffer with payload */ -static int rtp_decode(struct msgb *msg, uint32_t callref, struct msgb **data) -{ - struct msgb *new_msg; - struct gsm_data_frame *frame; - struct rtp_hdr *rtph = (struct rtp_hdr *)msg->data; - struct rtp_x_hdr *rtpxh; - uint8_t *payload, *payload_out; - int payload_len; - int msg_type; - int x_len; - - if (msg->len < 12) { - DEBUGPC(DLMUX, "received RTP frame too short (len = %d)\n", - msg->len); - return -EINVAL; - } - if (rtph->version != RTP_VERSION) { - DEBUGPC(DLMUX, "received RTP version %d not supported.\n", - rtph->version); - return -EINVAL; - } - payload = msg->data + sizeof(struct rtp_hdr) + (rtph->csrc_count << 2); - payload_len = msg->len - sizeof(struct rtp_hdr) - (rtph->csrc_count << 2); - if (payload_len < 0) { - DEBUGPC(DLMUX, "received RTP frame too short (len = %d, " - "csrc count = %d)\n", msg->len, rtph->csrc_count); - return -EINVAL; - } - if (rtph->extension) { - if (payload_len < sizeof(struct rtp_x_hdr)) { - DEBUGPC(DLMUX, "received RTP frame too short for " - "extension header\n"); - return -EINVAL; - } - rtpxh = (struct rtp_x_hdr *)payload; - x_len = ntohs(rtpxh->length) * 4 + sizeof(struct rtp_x_hdr); - payload += x_len; - payload_len -= x_len; - if (payload_len < 0) { - DEBUGPC(DLMUX, "received RTP frame too short, " - "extension header exceeds frame length\n"); - return -EINVAL; - } - } - if (rtph->padding) { - if (payload_len < 1) { - DEBUGPC(DLMUX, "received RTP frame too short for " - "padding length\n"); - return -EINVAL; - } - payload_len -= payload[payload_len - 1]; - if (payload_len < 0) { - DEBUGPC(DLMUX, "received RTP frame with padding " - "greater than payload\n"); - return -EINVAL; - } - } - - switch (rtph->payload_type) { - case RTP_PT_GSM_FULL: - msg_type = GSM_TCHF_FRAME; - if (payload_len != RTP_LEN_GSM_FULL) { - DEBUGPC(DLMUX, "received RTP full rate frame with " - "payload length != %d (len = %d)\n", - RTP_LEN_GSM_FULL, payload_len); - return -EINVAL; - } - break; - case RTP_PT_GSM_EFR: - msg_type = GSM_TCHF_FRAME_EFR; - if (payload_len != RTP_LEN_GSM_EFR) { - DEBUGPC(DLMUX, "received RTP extended full rate frame " - "with payload length != %d (len = %d)\n", - RTP_LEN_GSM_EFR, payload_len); - return -EINVAL; - } - break; - case RTP_PT_GSM_HALF: - msg_type = GSM_TCHH_FRAME; - if (payload_len != RTP_LEN_GSM_HALF) { - DEBUGPC(DLMUX, "received RTP half rate frame with " - "payload length != %d (len = %d)\n", - RTP_LEN_GSM_HALF, payload_len); - return -EINVAL; - } - break; - case RTP_PT_AMR: - msg_type = GSM_TCH_FRAME_AMR; - break; - default: - DEBUGPC(DLMUX, "received RTP frame with unknown payload " - "type %d\n", rtph->payload_type); - return -EINVAL; - } - - if (payload_len > MAX_RTP_PAYLOAD_LEN || - (rtph->payload_type == RTP_PT_AMR && - payload_len > MAX_RTP_PAYLOAD_LEN - 1)) { - DEBUGPC(DLMUX, "RTP payload too large (%d octets)\n", - payload_len); - return -EINVAL; - } - - /* always allocate for the maximum possible size to avoid - * fragmentation */ - new_msg = msgb_alloc(sizeof(struct gsm_data_frame) + - MAX_RTP_PAYLOAD_LEN+1, "GSM-DATA (TCH)"); - - if (!new_msg) - return -ENOMEM; - frame = (struct gsm_data_frame *) msgb_put(new_msg, sizeof(struct gsm_data_frame)); - frame->msg_type = msg_type; - frame->callref = callref; - if (rtph->payload_type == RTP_PT_AMR) { - /* for FR/HR/EFR the length is implicit. In AMR, we - * need to make it explicit by using the first byte of - * the data[] buffer as length byte */ - uint8_t *data0 = msgb_put(new_msg, 1); - *data0 = payload_len; - } - payload_out = msgb_put(new_msg, payload_len); - memcpy(payload_out, payload, payload_len); - - *data = new_msg; - return 0; -} - -/*! \brief encode and send a rtp frame - * \param[in] rs RTP socket through which we shall send - * \param[in] frame GSM RTP frame to be sent - */ -int rtp_send_frame(struct rtp_socket *rs, struct gsm_data_frame *frame) -{ - struct rtp_sub_socket *rss = &rs->rtp; - struct msgb *msg; - struct rtp_hdr *rtph; - uint8_t *payload; - int payload_type; - int payload_len; - int duration; /* in samples */ - int is_bfi = 0; - - if (rs->tx_action != RTP_SEND_DOWNSTREAM) { - /* initialize sequences */ - rs->tx_action = RTP_SEND_DOWNSTREAM; - rs->transmit.ssrc = rand(); - rs->transmit.sequence = random(); - rs->transmit.timestamp = random(); - } - - switch (frame->msg_type) { - case GSM_TCHF_FRAME: - payload_type = RTP_PT_GSM_FULL; - payload_len = RTP_LEN_GSM_FULL; - duration = RTP_GSM_DURATION; - break; - case GSM_TCHF_FRAME_EFR: - payload_type = RTP_PT_GSM_EFR; - payload_len = RTP_LEN_GSM_EFR; - duration = RTP_GSM_DURATION; - break; - case GSM_TCHH_FRAME: - payload_type = RTP_PT_GSM_HALF; - payload_len = RTP_LEN_GSM_HALF; - duration = RTP_GSM_DURATION; - break; - case GSM_TCH_FRAME_AMR: - payload_type = RTP_PT_AMR; - payload_len = frame->data[0]; - duration = RTP_GSM_DURATION; - break; - case GSM_BAD_FRAME: - payload_type = 0; - payload_len = 0; - duration = RTP_GSM_DURATION; - is_bfi = 1; - break; - default: - DEBUGPC(DLMUX, "unsupported message type %d\n", - frame->msg_type); - return -EINVAL; - } - - if (payload_len > MAX_RTP_PAYLOAD_LEN) { - DEBUGPC(DLMUX, "RTP payload too large (%d octets)\n", - payload_len); - return -EINVAL; - } - - if (is_bfi) { - /* In case of a bad frame, just count and drop packet. */ - rs->transmit.timestamp += duration; - rs->transmit.sequence++; - return 0; - } - - msg = msgb_alloc(sizeof(struct rtp_hdr) + payload_len, "RTP-GSM"); - if (!msg) - return -ENOMEM; - rtph = (struct rtp_hdr *) msgb_put(msg, sizeof(struct rtp_hdr)); - rtph->version = RTP_VERSION; - rtph->padding = 0; - rtph->extension = 0; - rtph->csrc_count = 0; - rtph->marker = 0; - rtph->payload_type = payload_type; - rtph->sequence = htons(rs->transmit.sequence++); - rtph->timestamp = htonl(rs->transmit.timestamp); - rs->transmit.timestamp += duration; - rtph->ssrc = htonl(rs->transmit.ssrc); - - payload = msgb_put(msg, payload_len); - if (frame->msg_type == GSM_TCH_FRAME_AMR) - memcpy(payload, frame->data + 1, payload_len); - else - memcpy(payload, frame->data, payload_len); - msgb_enqueue(&rss->tx_queue, msg); - rss->bfd.when |= BSC_FD_WRITE; - - return 0; -} - -/* iterate over all chunks in one RTCP message, look for CNAME IEs and - * replace all of those with 'new_cname' */ -static int rtcp_sdes_cname_mangle(struct msgb *msg, struct rtcp_hdr *rh, - uint16_t *rtcp_len, const char *new_cname) -{ - uint8_t *rtcp_end; - uint8_t *cur = (uint8_t *) rh; - uint8_t tag, len = 0; - - rtcp_end = cur + *rtcp_len; - /* move cur to end of RTP header */ - cur += sizeof(*rh); - - /* iterate over Chunks */ - while (cur+4 < rtcp_end) { - /* skip four bytes SSRC/CSRC */ - cur += 4; - - /* iterate over IE's inside the chunk */ - while (cur+1 < rtcp_end) { - tag = *cur++; - if (tag == 0) { - /* end of chunk, skip additional zero */ - while ((*cur++ == 0) && (cur < rtcp_end)) { } - break; - } - len = *cur++; - - if (tag == RTCP_IE_CNAME) { - /* we've found the CNAME, lets mangle it */ - if (len < strlen(new_cname)) { - /* we need to make more space */ - int increase = strlen(new_cname) - len; - - msgb_push(msg, increase); - memmove(cur+len+increase, cur+len, - rtcp_end - (cur+len)); - /* FIXME: we have to respect RTCP - * padding/alignment rules! */ - len += increase; - *(cur-1) += increase; - rtcp_end += increase; - *rtcp_len += increase; - } - /* copy new CNAME into message */ - memcpy(cur, new_cname, strlen(new_cname)); - /* FIXME: zero the padding in case new CNAME - * is smaller than old one !!! */ - } - cur += len; - } - } - - return 0; -} - -static int rtcp_mangle(struct msgb *msg, struct rtp_socket *rs) -{ - struct rtp_sub_socket *rss = &rs->rtcp; - struct rtcp_hdr *rtph; - uint16_t old_len; - int rc; - - if (!mangle_rtcp_cname) - return 0; - - printf("RTCP\n"); - /* iterate over list of RTCP messages */ - rtph = (struct rtcp_hdr *)msg->data; - while ((void *)rtph + sizeof(*rtph) <= (void *)msg->data + msg->len) { - old_len = (ntohs(rtph->length) + 1) * 4; - if ((void *)rtph + old_len > (void *)msg->data + msg->len) { - DEBUGPC(DLMUX, "received RTCP packet too short for " - "length element\n"); - return -EINVAL; - } - if (rtph->type == RTCP_TYPE_SDES) { - char new_cname[255]; - osmo_strlcpy(new_cname, - inet_ntoa(rss->sin_local.sin_addr), - sizeof(new_cname)); - rc = rtcp_sdes_cname_mangle(msg, rtph, &old_len, - new_cname); - if (rc < 0) - return rc; - } - rtph = (void *)rtph + old_len; - } - - return 0; -} - -/* read from incoming RTP/RTCP socket */ -static int rtp_socket_read(struct rtp_socket *rs, struct rtp_sub_socket *rss) -{ - int rc; - struct msgb *msg = msgb_alloc(RTP_ALLOC_SIZE, "RTP/RTCP"); - struct msgb *new_msg; - struct rtp_sub_socket *other_rss; - - if (!msg) - return -ENOMEM; - - rc = read(rss->bfd.fd, msg->data, RTP_ALLOC_SIZE); - if (rc == 0) { - rss->bfd.when &= ~BSC_FD_READ; - goto out_free; - } else if (rc < 0) { - /* Ignore "connection refused". this happens, If we open the - * socket faster than the remote side. */ - if (errno == ECONNREFUSED) - goto out_free; - DEBUGPC(DLMUX, "Read of RTP socket (%p) failed (errno %d, " - "%s)\n", rs, errno, strerror(errno)); - rss->bfd.when &= ~BSC_FD_READ; - goto out_free; - } - - msgb_put(msg, rc); - - switch (rs->rx_action) { - case RTP_PROXY: - if (!rs->proxy.other_sock) { - rc = -EIO; - goto out_free; - } - if (rss->bfd.priv_nr == RTP_PRIV_RTP) - other_rss = &rs->proxy.other_sock->rtp; - else if (rss->bfd.priv_nr == RTP_PRIV_RTCP) { - other_rss = &rs->proxy.other_sock->rtcp; - /* modify RTCP SDES CNAME */ - rc = rtcp_mangle(msg, rs); - if (rc < 0) - goto out_free; - } else { - rc = -EINVAL; - goto out_free; - } - msgb_enqueue(&other_rss->tx_queue, msg); - other_rss->bfd.when |= BSC_FD_WRITE; - break; - - case RTP_RECV_UPSTREAM: - if (!rs->receive.callref || !rs->receive.net) { - rc = -EIO; - goto out_free; - } - if (rss->bfd.priv_nr == RTP_PRIV_RTCP) { - if (!mangle_rtcp_cname) { - msgb_free(msg); - break; - } - /* modify RTCP SDES CNAME */ - rc = rtcp_mangle(msg, rs); - if (rc < 0) - goto out_free; - msgb_enqueue(&rss->tx_queue, msg); - rss->bfd.when |= BSC_FD_WRITE; - break; - } - if (rss->bfd.priv_nr != RTP_PRIV_RTP) { - rc = -EINVAL; - goto out_free; - } - rc = rtp_decode(msg, rs->receive.callref, &new_msg); - if (rc < 0) - goto out_free; - msgb_free(msg); - trau_tx_to_mncc(rs->receive.net, new_msg); - break; - - case RTP_NONE: /* if socket exists, but disabled by app */ - msgb_free(msg); - break; - } - - return 0; - -out_free: - msgb_free(msg); - return rc; -} - -/* \brief write from tx_queue to RTP/RTCP socket */ -static int rtp_socket_write(struct rtp_socket *rs, struct rtp_sub_socket *rss) -{ - struct msgb *msg; - int written; - - msg = msgb_dequeue(&rss->tx_queue); - if (!msg) { - rss->bfd.when &= ~BSC_FD_WRITE; - return 0; - } - - written = write(rss->bfd.fd, msg->data, msg->len); - if (written < msg->len) { - LOGP(DLMIB, LOGL_ERROR, "short write"); - msgb_free(msg); - return -EIO; - } - - msgb_free(msg); - - return 0; -} - - -/*! \brief callback for the select.c:bfd_* layer */ -static int rtp_bfd_cb(struct osmo_fd *bfd, unsigned int flags) -{ - struct rtp_socket *rs = bfd->data; - struct rtp_sub_socket *rss; - - switch (bfd->priv_nr) { - case RTP_PRIV_RTP: - rss = &rs->rtp; - break; - case RTP_PRIV_RTCP: - rss = &rs->rtcp; - break; - default: - return -EINVAL; - } - - if (flags & BSC_FD_READ) - rtp_socket_read(rs, rss); - - if (flags & BSC_FD_WRITE) - rtp_socket_write(rs, rss); - - return 0; -} - -/*! \brief initialize one rtp sub-socket */ -static void init_rss(struct rtp_sub_socket *rss, - struct rtp_socket *rs, int fd, int priv_nr) -{ - /* initialize bfd */ - rss->bfd.fd = fd; - rss->bfd.data = rs; - rss->bfd.priv_nr = priv_nr; - rss->bfd.cb = rtp_bfd_cb; -} - -/*! \brief create a new RTP/RTCP socket and bind it */ -struct rtp_socket *rtp_socket_create(void) -{ - int rc; - struct rtp_socket *rs; - - DEBUGP(DLMUX, "rtp_socket_create(): "); - - rs = talloc_zero(tall_bsc_ctx, struct rtp_socket); - if (!rs) - return NULL; - - INIT_LLIST_HEAD(&rs->rtp.tx_queue); - INIT_LLIST_HEAD(&rs->rtcp.tx_queue); - - rc = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (rc < 0) - goto out_free; - - init_rss(&rs->rtp, rs, rc, RTP_PRIV_RTP); - rc = osmo_fd_register(&rs->rtp.bfd); - if (rc < 0) - goto out_rtp_socket; - - rc = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (rc < 0) - goto out_rtp_bfd; - - init_rss(&rs->rtcp, rs, rc, RTP_PRIV_RTCP); - rc = osmo_fd_register(&rs->rtcp.bfd); - if (rc < 0) - goto out_rtcp_socket; - - DEBUGPC(DLMUX, "success\n"); - - rc = rtp_socket_bind(rs, INADDR_ANY); - if (rc < 0) - goto out_rtcp_bfd; - - return rs; - -out_rtcp_bfd: - osmo_fd_unregister(&rs->rtcp.bfd); -out_rtcp_socket: - close(rs->rtcp.bfd.fd); -out_rtp_bfd: - osmo_fd_unregister(&rs->rtp.bfd); -out_rtp_socket: - close(rs->rtp.bfd.fd); -out_free: - talloc_free(rs); - DEBUGPC(DLMUX, "failed\n"); - return NULL; -} - -static int rtp_sub_socket_bind(struct rtp_sub_socket *rss, uint32_t ip, - uint16_t port) -{ - int rc; - socklen_t alen = sizeof(rss->sin_local); - - rss->sin_local.sin_family = AF_INET; - rss->sin_local.sin_addr.s_addr = htonl(ip); - rss->sin_local.sin_port = htons(port); - rss->bfd.when |= BSC_FD_READ; - - rc = bind(rss->bfd.fd, (struct sockaddr *)&rss->sin_local, - sizeof(rss->sin_local)); - if (rc < 0) - return rc; - - /* retrieve the address we actually bound to, in case we - * passed INADDR_ANY as IP address */ - return getsockname(rss->bfd.fd, (struct sockaddr *)&rss->sin_local, - &alen); -} - -#define RTP_PORT_BASE 30000 -static unsigned int next_udp_port = RTP_PORT_BASE; - -/*! \brief bind a RTP socket to a specific local address - * \param[in] rs RTP socket to be bound - * \param[in] ip local IP address to which socket is to be bound - */ -int rtp_socket_bind(struct rtp_socket *rs, uint32_t ip) -{ - int rc = -EIO; - struct in_addr ia; - - ia.s_addr = htonl(ip); - DEBUGP(DLMUX, "rtp_socket_bind(rs=%p, IP=%s): ", rs, - inet_ntoa(ia)); - - /* try to bind to a consecutive pair of ports */ - for (next_udp_port = next_udp_port % 0xffff; - next_udp_port < 0xffff; next_udp_port += 2) { - rc = rtp_sub_socket_bind(&rs->rtp, ip, next_udp_port); - if (rc != 0) - continue; - - rc = rtp_sub_socket_bind(&rs->rtcp, ip, next_udp_port+1); - if (rc == 0) - break; - } - if (rc < 0) { - DEBUGPC(DLMUX, "failed\n"); - return rc; - } - - ia.s_addr = rs->rtp.sin_local.sin_addr.s_addr; - DEBUGPC(DLMUX, "BOUND_IP=%s, BOUND_PORT=%u\n", - inet_ntoa(ia), ntohs(rs->rtp.sin_local.sin_port)); - return ntohs(rs->rtp.sin_local.sin_port); -} - -static int rtp_sub_socket_connect(struct rtp_sub_socket *rss, - uint32_t ip, uint16_t port) -{ - int rc; - socklen_t alen = sizeof(rss->sin_local); - - rss->sin_remote.sin_family = AF_INET; - rss->sin_remote.sin_addr.s_addr = htonl(ip); - rss->sin_remote.sin_port = htons(port); - - rc = connect(rss->bfd.fd, (struct sockaddr *) &rss->sin_remote, - sizeof(rss->sin_remote)); - if (rc < 0) - return rc; - - return getsockname(rss->bfd.fd, (struct sockaddr *)&rss->sin_local, - &alen); -} - -/*! \brief 'connect' a RTP socket to a remote peer - * \param[in] rs RTP socket to be connected - * \param[in] ip remote IP address to which to connect - * \param[in] port remote UDP port number to which to connect - */ -int rtp_socket_connect(struct rtp_socket *rs, uint32_t ip, uint16_t port) -{ - int rc; - struct in_addr ia; - - ia.s_addr = htonl(ip); - DEBUGP(DLMUX, "rtp_socket_connect(rs=%p, ip=%s, port=%u)\n", - rs, inet_ntoa(ia), port); - - rc = rtp_sub_socket_connect(&rs->rtp, ip, port); - if (rc < 0) - return rc; - - return rtp_sub_socket_connect(&rs->rtcp, ip, port+1); -} - -/*! \brief bind two RTP/RTCP sockets together in the proxy - * \param[in] this First RTP socket - * \param[in] other Second RTP socket - */ -int rtp_socket_proxy(struct rtp_socket *this, struct rtp_socket *other) -{ - DEBUGP(DLMUX, "rtp_socket_proxy(this=%p, other=%p)\n", - this, other); - - this->rx_action = RTP_PROXY; - this->proxy.other_sock = other; - - other->rx_action = RTP_PROXY; - other->proxy.other_sock = this; - - return 0; -} - -/*! \brief bind RTP/RTCP socket to application, disabling proxy - * \param[in] this RTP socket - * \param[in] net gsm_network argument to trau_tx_to_mncc() - * \param[in] callref callref argument to trau_tx_to_mncc() - */ -int rtp_socket_upstream(struct rtp_socket *this, struct gsm_network *net, - uint32_t callref) -{ - DEBUGP(DLMUX, "rtp_socket_proxy(this=%p, callref=%u)\n", - this, callref); - - if (callref) { - this->rx_action = RTP_RECV_UPSTREAM; - this->receive.net = net; - this->receive.callref = callref; - } else - this->rx_action = RTP_NONE; - - return 0; -} - -static void free_tx_queue(struct rtp_sub_socket *rss) -{ - struct msgb *msg; - - while ((msg = msgb_dequeue(&rss->tx_queue))) - msgb_free(msg); -} - -/*! \brief Free/release a previously allocated RTP socket - * \param[in[] rs RTP/RTCP socket to be released - */ -int rtp_socket_free(struct rtp_socket *rs) -{ - DEBUGP(DLMUX, "rtp_socket_free(rs=%p)\n", rs); - - /* make sure we don't leave references dangling to us */ - if (rs->rx_action == RTP_PROXY && - rs->proxy.other_sock) - rs->proxy.other_sock->proxy.other_sock = NULL; - - osmo_fd_unregister(&rs->rtp.bfd); - close(rs->rtp.bfd.fd); - free_tx_queue(&rs->rtp); - - osmo_fd_unregister(&rs->rtcp.bfd); - close(rs->rtcp.bfd.fd); - free_tx_queue(&rs->rtcp); - - talloc_free(rs); - - return 0; -} diff --git a/src/libtrau/trau_mux.c b/src/libtrau/trau_mux.c deleted file mode 100644 index e570b93f5..000000000 --- a/src/libtrau/trau_mux.c +++ /dev/null @@ -1,547 +0,0 @@ -/* Simple TRAU frame reflector to route voice calls */ - -/* (C) 2009 by Harald Welte - * All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* this corresponds to the bit-lengths of the individual codec - * parameters as indicated in Table 1.1 of TS 06.10 */ -static const uint8_t gsm_fr_map[] = { - 6, 6, 5, 5, 4, 4, 3, 3, - 7, 2, 2, 6, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, - 3, 7, 2, 2, 6, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 7, 2, 2, 6, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 7, 2, 2, 6, 3, - 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3 -}; - - -/* - * EFR TRAU parity - * - * g(x) = x^3 + x^1 + 1 - */ -static const struct osmo_crc8gen_code gsm0860_efr_crc3 = { - .bits = 3, - .poly = 0x3, - .init = 0x0, - .remainder = 0x7, -}; - -/* EFR parity bits */ -static inline void efr_parity_bits_1(ubit_t *check_bits, const ubit_t *d_bits) -{ - memcpy(check_bits + 0 , d_bits + 0, 22); - memcpy(check_bits + 22 , d_bits + 24, 3); - check_bits[25] = d_bits[28]; -} - -static inline void efr_parity_bits_2(ubit_t *check_bits, const ubit_t *d_bits) -{ - memcpy(check_bits + 0 , d_bits + 42, 10); - memcpy(check_bits + 10 , d_bits + 90, 2); -} - -static inline void efr_parity_bits_3(ubit_t *check_bits, const ubit_t *d_bits) -{ - memcpy(check_bits + 0 , d_bits + 98, 5); - check_bits[5] = d_bits[104]; - memcpy(check_bits + 6 , d_bits + 143, 2); -} - -static inline void efr_parity_bits_4(ubit_t *check_bits, const ubit_t *d_bits) -{ - memcpy(check_bits + 0 , d_bits + 151, 10); - memcpy(check_bits + 10 , d_bits + 199, 2); -} - -static inline void efr_parity_bits_5(ubit_t *check_bits, const ubit_t *d_bits) -{ - memcpy(check_bits + 0 , d_bits + 207, 5); - check_bits[5] = d_bits[213]; - memcpy(check_bits + 6 , d_bits + 252, 2); -} - -struct map_entry { - struct llist_head list; - struct gsm_e1_subslot src, dst; -}; - -struct upqueue_entry { - struct llist_head list; - struct gsm_network *net; - struct gsm_e1_subslot src; - uint32_t callref; -}; - -static LLIST_HEAD(ss_map); -static LLIST_HEAD(ss_upqueue); - -void *tall_map_ctx, *tall_upq_ctx; - -/* map one particular subslot to another subslot */ -int trau_mux_map(const struct gsm_e1_subslot *src, - const struct gsm_e1_subslot *dst) -{ - struct map_entry *me; - - me = talloc(tall_map_ctx, struct map_entry); - if (!me) { - LOGP(DLMIB, LOGL_FATAL, "Out of memory\n"); - return -ENOMEM; - } - - DEBUGP(DCC, "Setting up TRAU mux map between (e1=%u,ts=%u,ss=%u) " - "and (e1=%u,ts=%u,ss=%u)\n", - src->e1_nr, src->e1_ts, src->e1_ts_ss, - dst->e1_nr, dst->e1_ts, dst->e1_ts_ss); - - /* make sure to get rid of any stale old mappings */ - trau_mux_unmap(src, 0); - trau_mux_unmap(dst, 0); - - memcpy(&me->src, src, sizeof(me->src)); - memcpy(&me->dst, dst, sizeof(me->dst)); - llist_add(&me->list, &ss_map); - - return 0; -} - -int trau_mux_map_lchan(const struct gsm_lchan *src, - const struct gsm_lchan *dst) -{ - struct gsm_e1_subslot *src_ss, *dst_ss; - - src_ss = &src->ts->e1_link; - dst_ss = &dst->ts->e1_link; - - return trau_mux_map(src_ss, dst_ss); -} - - -/* unmap one particular subslot from another subslot */ -int trau_mux_unmap(const struct gsm_e1_subslot *ss, uint32_t callref) -{ - struct map_entry *me, *me2; - struct upqueue_entry *ue, *ue2; - - if (ss) - llist_for_each_entry_safe(me, me2, &ss_map, list) { - if (!memcmp(&me->src, ss, sizeof(*ss)) || - !memcmp(&me->dst, ss, sizeof(*ss))) { - llist_del(&me->list); - return 0; - } - } - llist_for_each_entry_safe(ue, ue2, &ss_upqueue, list) { - if (ue->callref == callref) { - llist_del(&ue->list); - return 0; - } - if (ss && !memcmp(&ue->src, ss, sizeof(*ss))) { - llist_del(&ue->list); - return 0; - } - } - return -ENOENT; -} - -/* look-up an enty in the TRAU mux map */ -static struct gsm_e1_subslot * -lookup_trau_mux_map(const struct gsm_e1_subslot *src) -{ - struct map_entry *me; - - llist_for_each_entry(me, &ss_map, list) { - if (!memcmp(&me->src, src, sizeof(*src))) - return &me->dst; - if (!memcmp(&me->dst, src, sizeof(*src))) - return &me->src; - } - return NULL; -} - -/* look-up an enty in the TRAU upqueue */ -struct upqueue_entry * -lookup_trau_upqueue(const struct gsm_e1_subslot *src) -{ - struct upqueue_entry *ue; - - llist_for_each_entry(ue, &ss_upqueue, list) { - if (!memcmp(&ue->src, src, sizeof(*src))) - return ue; - } - return NULL; -} - -static const uint8_t c_bits_check_fr[] = { 0, 0, 0, 1, 0 }; -static const uint8_t c_bits_check_efr[] = { 1, 1, 0, 1, 0 }; - -struct msgb *trau_decode_fr(uint32_t callref, - const struct decoded_trau_frame *tf) -{ - struct msgb *msg; - struct gsm_data_frame *frame; - unsigned char *data; - int i, j, k, l, o; - - msg = msgb_alloc(sizeof(struct gsm_data_frame) + 33, - "GSM-DATA"); - if (!msg) - return NULL; - - frame = (struct gsm_data_frame *)msg->data; - memset(frame, 0, sizeof(struct gsm_data_frame)); - data = frame->data; - data[0] = 0xd << 4; - /* reassemble d-bits */ - i = 0; /* counts bits */ - j = 4; /* counts output bits */ - k = gsm_fr_map[0]-1; /* current number bit in element */ - l = 0; /* counts element bits */ - o = 0; /* offset input bits */ - while (i < 260) { - data[j/8] |= (tf->d_bits[k+o] << (7-(j%8))); - /* to avoid out-of-bounds access in gsm_fr_map[++l] */ - if (i == 259) - break; - if (--k < 0) { - o += gsm_fr_map[l]; - k = gsm_fr_map[++l]-1; - } - i++; - j++; - } - if (tf->c_bits[11]) /* BFI */ - frame->msg_type = GSM_BAD_FRAME; - else - frame->msg_type = GSM_TCHF_FRAME; - frame->callref = callref; - msgb_put(msg, sizeof(struct gsm_data_frame) + 33); - - return msg; -} - -struct msgb *trau_decode_efr(uint32_t callref, - const struct decoded_trau_frame *tf) -{ - struct msgb *msg; - struct gsm_data_frame *frame; - unsigned char *data; - int i, j, rc; - ubit_t check_bits[26]; - - msg = msgb_alloc(sizeof(struct gsm_data_frame) + 31, - "GSM-DATA"); - if (!msg) - return NULL; - - frame = (struct gsm_data_frame *)msg->data; - memset(frame, 0, sizeof(struct gsm_data_frame)); - frame->msg_type = GSM_TCHF_FRAME_EFR; - frame->callref = callref; - msgb_put(msg, sizeof(struct gsm_data_frame) + 31); - - if (tf->c_bits[11]) /* BFI */ - goto bad_frame; - - data = frame->data; - data[0] = 0xc << 4; - /* reassemble d-bits */ - for (i = 1, j = 4; i < 39; i++, j++) - data[j/8] |= (tf->d_bits[i] << (7-(j%8))); - efr_parity_bits_1(check_bits, tf->d_bits); - rc = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 26, - tf->d_bits + 39); - if (rc) - goto bad_frame; - for (i = 42, j = 42; i < 95; i++, j++) - data[j/8] |= (tf->d_bits[i] << (7-(j%8))); - efr_parity_bits_2(check_bits, tf->d_bits); - rc = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 12, - tf->d_bits + 95); - if (rc) - goto bad_frame; - for (i = 98, j = 95; i < 148; i++, j++) - data[j/8] |= (tf->d_bits[i] << (7-(j%8))); - efr_parity_bits_3(check_bits, tf->d_bits); - rc = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 8, - tf->d_bits + 148); - if (rc) - goto bad_frame; - for (i = 151, j = 145; i < 204; i++, j++) - data[j/8] |= (tf->d_bits[i] << (7-(j%8))); - efr_parity_bits_4(check_bits, tf->d_bits); - rc = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 12, - tf->d_bits + 204); - if (rc) - goto bad_frame; - for (i = 207, j = 198; i < 257; i++, j++) - data[j/8] |= (tf->d_bits[i] << (7-(j%8))); - efr_parity_bits_5(check_bits, tf->d_bits); - rc = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 8, - tf->d_bits + 257); - if (rc) - goto bad_frame; - - return msg; - -bad_frame: - frame->msg_type = GSM_BAD_FRAME; - - return msg; -} - -/* we get called by subchan_demux */ -int trau_mux_input(struct gsm_e1_subslot *src_e1_ss, - const uint8_t *trau_bits, int num_bits) -{ - struct decoded_trau_frame tf; - uint8_t trau_bits_out[TRAU_FRAME_BITS]; - struct gsm_e1_subslot *dst_e1_ss = lookup_trau_mux_map(src_e1_ss); - struct subch_mux *mx; - struct upqueue_entry *ue; - int rc; - - /* decode TRAU, change it to downlink, re-encode */ - rc = decode_trau_frame(&tf, trau_bits); - if (rc) - return rc; - - if (!dst_e1_ss) { - struct msgb *msg = NULL; - /* frame shall be sent to upqueue */ - if (!(ue = lookup_trau_upqueue(src_e1_ss))) - return -EINVAL; - if (!ue->callref) - return -EINVAL; - if (!memcmp(tf.c_bits, c_bits_check_fr, 5)) - msg = trau_decode_fr(ue->callref, &tf); - else if (!memcmp(tf.c_bits, c_bits_check_efr, 5)) - msg = trau_decode_efr(ue->callref, &tf); - else { - DEBUGPC(DLMUX, "illegal trau (C1-C5) %s\n", - osmo_hexdump(tf.c_bits, 5)); - DEBUGPC(DLMUX, "test trau (C1-C5) %s\n", - osmo_hexdump(c_bits_check_efr, 5)); - return -EINVAL; - } - if (!msg) - return -ENOMEM; - trau_tx_to_mncc(ue->net, msg); - - return 0; - } - - mx = e1inp_get_mux(dst_e1_ss->e1_nr, dst_e1_ss->e1_ts); - if (!mx) - return -EINVAL; - - trau_frame_up2down(&tf); - encode_trau_frame(trau_bits_out, &tf); - - /* and send it to the muxer */ - return subchan_mux_enqueue(mx, dst_e1_ss->e1_ts_ss, trau_bits_out, - TRAU_FRAME_BITS); -} - -/* callback when a TRAU frame was received */ -int subch_cb(struct subch_demux *dmx, int ch, uint8_t *data, int len, - void *_priv) -{ - struct e1inp_ts *e1i_ts = _priv; - struct gsm_e1_subslot src_ss; - - src_ss.e1_nr = e1i_ts->line->num; - src_ss.e1_ts = e1i_ts->num; - src_ss.e1_ts_ss = ch; - - return trau_mux_input(&src_ss, data, len); -} - -/* add receiver instance for lchan and callref */ -int trau_recv_lchan(struct gsm_lchan *lchan, uint32_t callref) -{ - struct gsm_e1_subslot *src_ss; - struct upqueue_entry *ue; - - ue = talloc(tall_upq_ctx, struct upqueue_entry); - if (!ue) - return -ENOMEM; - - src_ss = &lchan->ts->e1_link; - - DEBUGP(DCC, "Setting up TRAU receiver (e1=%u,ts=%u,ss=%u) " - "and (callref 0x%x)\n", - src_ss->e1_nr, src_ss->e1_ts, src_ss->e1_ts_ss, - callref); - - /* make sure to get rid of any stale old mappings */ - trau_mux_unmap(src_ss, callref); - - memcpy(&ue->src, src_ss, sizeof(ue->src)); - ue->net = lchan->ts->trx->bts->network; - ue->callref = callref; - llist_add(&ue->list, &ss_upqueue); - - return 0; -} - -void trau_encode_fr(struct decoded_trau_frame *tf, - const unsigned char *data) -{ - int i, j, k, l, o; - - /* set c-bits and t-bits */ - tf->c_bits[0] = 1; - tf->c_bits[1] = 1; - tf->c_bits[2] = 1; - tf->c_bits[3] = 0; - tf->c_bits[4] = 0; - memset(&tf->c_bits[5], 0, 6); - memset(&tf->c_bits[11], 1, 10); - memset(&tf->t_bits[0], 1, 4); - /* reassemble d-bits */ - i = 0; /* counts bits */ - j = 4; /* counts input bits */ - k = gsm_fr_map[0]-1; /* current number bit in element */ - l = 0; /* counts element bits */ - o = 0; /* offset output bits */ - while (i < 260) { - tf->d_bits[k+o] = (data[j/8] >> (7-(j%8))) & 1; - /* to avoid out-of-bounds access in gsm_fr_map[++l] */ - if (i == 259) - break; - if (--k < 0) { - o += gsm_fr_map[l]; - k = gsm_fr_map[++l]-1; - } - i++; - j++; - } -} - -void trau_encode_efr(struct decoded_trau_frame *tf, - const unsigned char *data) -{ - int i, j; - ubit_t check_bits[26]; - - /* set c-bits and t-bits */ - tf->c_bits[0] = 1; - tf->c_bits[1] = 1; - tf->c_bits[2] = 0; - tf->c_bits[3] = 1; - tf->c_bits[4] = 0; - memset(&tf->c_bits[5], 0, 6); - memset(&tf->c_bits[11], 1, 10); - memset(&tf->t_bits[0], 1, 4); - /* reassemble d-bits */ - tf->d_bits[0] = 1; - for (i = 1, j = 4; i < 39; i++, j++) - tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1; - efr_parity_bits_1(check_bits, tf->d_bits); - osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 26, - tf->d_bits + 39); - for (i = 42, j = 42; i < 95; i++, j++) - tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1; - efr_parity_bits_2(check_bits, tf->d_bits); - osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 12, - tf->d_bits + 95); - for (i = 98, j = 95; i < 148; i++, j++) - tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1; - efr_parity_bits_3(check_bits, tf->d_bits); - osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 8, - tf->d_bits + 148); - for (i = 151, j = 145; i < 204; i++, j++) - tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1; - efr_parity_bits_4(check_bits, tf->d_bits); - osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 12, - tf->d_bits + 204); - for (i = 207, j = 198; i < 257; i++, j++) - tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1; - efr_parity_bits_5(check_bits, tf->d_bits); - osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 8, - tf->d_bits + 257); -} - -int trau_send_frame(struct gsm_lchan *lchan, struct gsm_data_frame *frame) -{ - uint8_t trau_bits_out[TRAU_FRAME_BITS]; - struct gsm_e1_subslot *dst_e1_ss = &lchan->ts->e1_link; - struct subch_mux *mx; - struct decoded_trau_frame tf; - - mx = e1inp_get_mux(dst_e1_ss->e1_nr, dst_e1_ss->e1_ts); - if (!mx) - return -EINVAL; - - switch (frame->msg_type) { - case GSM_TCHF_FRAME: - trau_encode_fr(&tf, frame->data); - break; - case GSM_TCHF_FRAME_EFR: - trau_encode_efr(&tf, frame->data); - break; - default: - DEBUGPC(DLMUX, "unsupported message type %d\n", - frame->msg_type); - return -EINVAL; - } - - encode_trau_frame(trau_bits_out, &tf); - - /* and send it to the muxer */ - return subchan_mux_enqueue(mx, dst_e1_ss->e1_ts_ss, trau_bits_out, - TRAU_FRAME_BITS); -} - -/* switch trau muxer to new lchan */ -int switch_trau_mux(struct gsm_lchan *old_lchan, struct gsm_lchan *new_lchan) -{ - struct gsm_network *net = old_lchan->ts->trx->bts->network; - struct gsm_trans *trans; - - /* look up transaction with TCH frame receive enabled */ - llist_for_each_entry(trans, &net->trans_list, entry) { - if (trans->conn && trans->conn->lchan == old_lchan && trans->tch_recv) { - /* switch */ - trau_recv_lchan(new_lchan, trans->callref); - } - } - - return 0; -} diff --git a/src/libtrau/trau_upqueue.c b/src/libtrau/trau_upqueue.c deleted file mode 100644 index c1c0003ba..000000000 --- a/src/libtrau/trau_upqueue.c +++ /dev/null @@ -1,27 +0,0 @@ -/* trau_upqueue.c - Pass msgb's up the chain */ - -/* (C) 2010 by Harald Welte - * All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -#include -#include - -void trau_tx_to_mncc(struct gsm_network *net, struct msgb *msg) -{ - net->mncc_recv(net, msg); -} diff --git a/src/osmo-bsc/Makefile.am b/src/osmo-bsc/Makefile.am index 7db698c1d..4acbe5623 100644 --- a/src/osmo-bsc/Makefile.am +++ b/src/osmo-bsc/Makefile.am @@ -40,12 +40,10 @@ osmo_bsc_SOURCES = \ osmo_bsc_ctrl.c \ $(NULL) -# once again since TRAU uses CC symbol :( osmo_bsc_LDADD = \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libbsc/libbsc.a \ $(top_builddir)/src/libcommon-cs/libcommon-cs.a \ - $(top_builddir)/src/libtrau/libtrau.a \ $(top_builddir)/src/libcommon/libcommon.a \ $(LIBOSMOSCCP_LIBS) \ $(LIBOSMOCORE_LIBS) \ diff --git a/src/osmo-bsc/osmo_bsc_filter.c b/src/osmo-bsc/osmo_bsc_filter.c index 2b71b8508..17dddf8ea 100644 --- a/src/osmo-bsc/osmo_bsc_filter.c +++ b/src/osmo-bsc/osmo_bsc_filter.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/src/osmo-bsc/osmo_bsc_main.c b/src/osmo-bsc/osmo_bsc_main.c index 5d25701bb..829f2075c 100644 --- a/src/osmo-bsc/osmo_bsc_main.c +++ b/src/osmo-bsc/osmo_bsc_main.c @@ -201,7 +201,7 @@ int main(int argc, char **argv) osmo_stats_init(tall_bsc_ctx); /* Allocate global gsm_network struct */ - rc = bsc_network_alloc(NULL); + rc = bsc_network_alloc(); if (rc) { fprintf(stderr, "Allocation failed. exiting.\n"); exit(1); diff --git a/src/osmo-bsc_nat/Makefile.am b/src/osmo-bsc_nat/Makefile.am index dd20ddb76..1bee68edf 100644 --- a/src/osmo-bsc_nat/Makefile.am +++ b/src/osmo-bsc_nat/Makefile.am @@ -42,7 +42,6 @@ osmo_bsc_nat_LDADD = \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libbsc/libbsc.a \ $(top_builddir)/src/libcommon-cs/libcommon-cs.a \ - $(top_builddir)/src/libtrau/libtrau.a \ $(top_builddir)/src/libcommon/libcommon.a \ $(LIBOSMOSCCP_LIBS) \ $(LIBOSMOCORE_LIBS) \ diff --git a/src/osmo-bsc_nat/bsc_filter.c b/src/osmo-bsc_nat/bsc_filter.c index 8d4a680b9..77ef5833f 100644 --- a/src/osmo-bsc_nat/bsc_filter.c +++ b/src/osmo-bsc_nat/bsc_filter.c @@ -20,6 +20,8 @@ * */ +#include + #include #include #include diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am index d3f6d624f..78d4965e6 100644 --- a/src/utils/Makefile.am +++ b/src/utils/Makefile.am @@ -49,7 +49,6 @@ bs11_config_SOURCES = \ bs11_config_LDADD = \ $(top_builddir)/src/libbsc/libbsc.a \ $(top_builddir)/src/libcommon-cs/libcommon-cs.a \ - $(top_builddir)/src/libtrau/libtrau.a \ $(top_builddir)/src/libcommon/libcommon.a \ $(LIBOSMOCORE_LIBS) \ $(LIBOSMOGSM_LIBS) \ diff --git a/src/utils/bs11_config.c b/src/utils/bs11_config.c index 6487df284..c72a23a53 100644 --- a/src/utils/bs11_config.c +++ b/src/utils/bs11_config.c @@ -897,7 +897,7 @@ int main(int argc, char **argv) handle_options(argc, argv); bts_model_bs11_init(); - gsmnet = bsc_network_init(tall_bs11cfg_ctx, 1, 1, NULL); + gsmnet = bsc_network_init(tall_bs11cfg_ctx, 1, 1); if (!gsmnet) { fprintf(stderr, "Unable to allocate gsm network\n"); exit(1); -- cgit v1.2.3