From 98657d5dee59fbe84e6a53aa481edb6a82185ab3 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 11 Jan 2010 16:42:07 +0100 Subject: [PATCH 1/6] misc: Fix compilation of the test cases. --- openbsc/tests/channel/Makefile.am | 5 ++++- openbsc/tests/channel/channel_test.c | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/openbsc/tests/channel/Makefile.am b/openbsc/tests/channel/Makefile.am index 564cbafe2..6b9f6e3cb 100644 --- a/openbsc/tests/channel/Makefile.am +++ b/openbsc/tests/channel/Makefile.am @@ -13,6 +13,9 @@ channel_test_SOURCES = channel_test.c \ $(top_srcdir)/src/talloc.c \ $(top_srcdir)/src/gsm_data.c \ $(top_srcdir)/src/signal.c \ - $(top_srcdir)/src/statistics.c + $(top_srcdir)/src/statistics.c \ + $(top_srcdir)/src/bts_ipaccess_nanobts.c \ + $(top_srcdir)/src/bts_siemens_bs11.c \ + $(top_srcdir)/src/tlv_parser.c channel_test_LDADD = -ldl -ldbi diff --git a/openbsc/tests/channel/channel_test.c b/openbsc/tests/channel/channel_test.c index 1b01878b5..36d057273 100644 --- a/openbsc/tests/channel/channel_test.c +++ b/openbsc/tests/channel/channel_test.c @@ -77,3 +77,5 @@ void nm_state_event() {} void input_event() {} void sms_alloc() {} +struct tlv_definition nm_att_tlvdef; + From 14083bef0f77dc2af080e0239e97e905f3a37b69 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 5 Jan 2010 12:21:36 +0100 Subject: [PATCH 2/6] [bsc_mgcp] Add a new forward only mode to the bsc_mgcp With forward IP in the config and early bind on we will simply forward RTP data on the endpoints from BTS to the forward IP address. This is implemented by disabling MGCP functionality when a forward IP address was specified, setting the forward IP in the endp->remote and assigning a ci != CI_UNUSED. Early bind will make sure the sockets are created, the BSC FD's are registered and then the normal dispatch code will do the forwarding. --- openbsc/src/bsc_mgcp.c | 86 ++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 25 deletions(-) diff --git a/openbsc/src/bsc_mgcp.c b/openbsc/src/bsc_mgcp.c index fff6d6039..17c54d1bb 100644 --- a/openbsc/src/bsc_mgcp.c +++ b/openbsc/src/bsc_mgcp.c @@ -64,6 +64,7 @@ static int audio_payload = 97; static int audio_loop = 0; static int early_bind = 0; +static char *forward_ip = NULL; static char *config_file = "mgcp.cfg"; /* used by msgb and mgcp */ @@ -1055,6 +1056,17 @@ DEFUN(cfg_mgcp_number_endp, return CMD_SUCCESS; } +DEFUN(cfg_mgcp_forward, + cfg_mgcp_forward_cmd, + "forward audio IP", + "Forward packets from and to the IP. This disables most of the MGCP feature.") +{ + if (forward_ip) + talloc_free(forward_ip); + forward_ip = talloc_strdup(tall_bsc_ctx, argv[0]); + return CMD_SUCCESS; +} + int bsc_vty_init(struct gsm_network *dummy) { cmd_init(1); @@ -1076,6 +1088,7 @@ int bsc_vty_init(struct gsm_network *dummy) install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_name_cmd); install_element(MGCP_NODE, &cfg_mgcp_loop_cmd); install_element(MGCP_NODE, &cfg_mgcp_number_endp_cmd); + install_element(MGCP_NODE, &cfg_mgcp_forward_cmd); return 0; } @@ -1123,37 +1136,60 @@ int main(int argc, char** argv) endpoints[i].ci = CI_UNUSED; } - /* initialize the socket */ - bfd.when = BSC_FD_READ; - bfd.cb = read_call_agent; - bfd.fd = socket(AF_INET, SOCK_DGRAM, 0); - if (bfd.fd < 0) { - perror("Gateway failed to listen"); - return -1; - } + /* + * This application supports two modes. + * 1.) a true MGCP gateway with support for AUEP, CRCX, MDCX, DLCX + * 2.) plain forwarding of RTP packets on the endpoints. + * both modes are mutual exclusive + */ + if (forward_ip) { - setsockopt(bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); + if (!early_bind) { + DEBUGP(DMGCP, "Forwarding requires early bind.\n"); + return -1; + } - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(source_port); - inet_aton(source_addr, &addr.sin_addr); + /* + * Store the forward IP and assign a ci. For early bind + * the sockets will be created after this. + */ + for (i = 1; i < number_endpoints; ++i) { + struct mgcp_endpoint *endp = &endpoints[i]; + inet_aton(forward_ip, &endp->remote); + endp->ci = CI_UNUSED + 23; + } + } else { + bfd.when = BSC_FD_READ; + bfd.cb = read_call_agent; + bfd.fd = socket(AF_INET, SOCK_DGRAM, 0); + if (bfd.fd < 0) { + perror("Gateway failed to listen"); + return -1; + } - if (bind(bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { - perror("Gateway failed to bind"); - return -1; - } + setsockopt(bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); - bfd.data = msgb_alloc(4096, "mgcp-msg"); - if (!bfd.data) { - fprintf(stderr, "Gateway memory error.\n"); - return -1; - } + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_port = htons(source_port); + inet_aton(source_addr, &addr.sin_addr); + + if (bind(bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + perror("Gateway failed to bind"); + return -1; + } + + bfd.data = msgb_alloc(4096, "mgcp-msg"); + if (!bfd.data) { + fprintf(stderr, "Gateway memory error.\n"); + return -1; + } - if (bsc_register_fd(&bfd) != 0) { - DEBUGP(DMGCP, "Failed to register the fd\n"); - return -1; + if (bsc_register_fd(&bfd) != 0) { + DEBUGP(DMGCP, "Failed to register the fd\n"); + return -1; + } } /* initialisation */ From f986cfc5085e9149d4cabeaf2b89c22996279edf Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 5 Jan 2010 12:25:25 +0100 Subject: [PATCH 3/6] [bsc_mgcp] Print a message which mode is configured --- openbsc/src/bsc_mgcp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openbsc/src/bsc_mgcp.c b/openbsc/src/bsc_mgcp.c index 17c54d1bb..3d130db3a 100644 --- a/openbsc/src/bsc_mgcp.c +++ b/openbsc/src/bsc_mgcp.c @@ -1158,6 +1158,8 @@ int main(int argc, char** argv) inet_aton(forward_ip, &endp->remote); endp->ci = CI_UNUSED + 23; } + + DEBUGP(DMGCP, "Configured for Audio Forwarding.\n"); } else { bfd.when = BSC_FD_READ; bfd.cb = read_call_agent; @@ -1190,6 +1192,8 @@ int main(int argc, char** argv) DEBUGP(DMGCP, "Failed to register the fd\n"); return -1; } + + DEBUGP(DMGCP, "Configured for MGCP.\n"); } /* initialisation */ From 2c492ed276012054a4a4dacebf675c651a0146fa Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 5 Jan 2010 12:29:36 +0100 Subject: [PATCH 4/6] [bsc_mgcp] Fix writing of the config file... * Add the new forward audio option --- openbsc/src/bsc_mgcp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openbsc/src/bsc_mgcp.c b/openbsc/src/bsc_mgcp.c index 3d130db3a..72ff421b9 100644 --- a/openbsc/src/bsc_mgcp.c +++ b/openbsc/src/bsc_mgcp.c @@ -910,6 +910,8 @@ static int config_write_mgcp(struct vty *vty) vty_out(vty, " sdp audio payload name %s%s", audio_name, VTY_NEWLINE); vty_out(vty, " loop %u%s", !!audio_loop, VTY_NEWLINE); vty_out(vty, " endpoints %u%s", number_endpoints, VTY_NEWLINE); + if (forward_ip) + vty_out(vty, " forward audio %s%s", forward_ip, VTY_NEWLINE); return CMD_SUCCESS; } From 620961983c595e387ce9494f30aff25effa8424f Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 5 Jan 2010 12:35:16 +0100 Subject: [PATCH 5/6] [bsc_mgcp] Set the right remote rtp and rtcp port * It is the same as local endpoint port --- openbsc/src/bsc_mgcp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openbsc/src/bsc_mgcp.c b/openbsc/src/bsc_mgcp.c index 72ff421b9..ecc13ca68 100644 --- a/openbsc/src/bsc_mgcp.c +++ b/openbsc/src/bsc_mgcp.c @@ -1159,6 +1159,8 @@ int main(int argc, char** argv) struct mgcp_endpoint *endp = &endpoints[i]; inet_aton(forward_ip, &endp->remote); endp->ci = CI_UNUSED + 23; + endp->rtp = htons(rtp_calculate_port(ENDPOINT_NUMBER(endp), rtp_base_port)); + endp->rtcp = htons(rtp_calculate_port(ENDPOINT_NUMBER(endp), rtp_base_port) + 1); } DEBUGP(DMGCP, "Configured for Audio Forwarding.\n"); From 6af56d1501244f4ce3cfd2e3bf07da19a59108da Mon Sep 17 00:00:00 2001 From: laforge Date: Tue, 12 Jan 2010 10:44:26 +0100 Subject: [PATCH 6/6] Fix allocation of BTS from VTY In 39315c47989326275823d1589425ee62d15bc823 we introduced per-bts OML attribute parser definitions and disallowed a BTS of type unknown. However, the VTY code first allocates a BTS with unknown type. --- openbsc/src/gsm_data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbsc/src/gsm_data.c b/openbsc/src/gsm_data.c index 694ae06c6..1f2e1a1fc 100644 --- a/openbsc/src/gsm_data.c +++ b/openbsc/src/gsm_data.c @@ -191,7 +191,7 @@ struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type, if (!bts) return NULL; - if (!model) { + if (!model && type != GSM_BTS_TYPE_UNKNOWN) { talloc_free(bts); return NULL; }