From 1f0c5b47426b4236ae0c91c71bc0d14a157f222f Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 28 Feb 2011 14:37:03 +0100 Subject: mgcp: Allocate the endpoints for the E1 trunks as well. --- openbsc/src/mgcp/mgcp_protocol.c | 9 ++--- openbsc/src/mgcp/mgcp_vty.c | 83 +++++++++++++++++++++++++--------------- 2 files changed, 56 insertions(+), 36 deletions(-) (limited to 'openbsc/src') diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c index 46214a559..b95cc81a8 100644 --- a/openbsc/src/mgcp/mgcp_protocol.c +++ b/openbsc/src/mgcp/mgcp_protocol.c @@ -942,15 +942,12 @@ static void mgcp_rtp_end_init(struct mgcp_rtp_end *end) end->rtcp.fd = -1; } -int mgcp_endpoints_allocate(struct mgcp_config *cfg) +int mgcp_endpoints_allocate(struct mgcp_trunk_config *tcfg) { - struct mgcp_trunk_config *tcfg; int i; - tcfg = &cfg->trunk; - /* Initialize all endpoints */ - tcfg->endpoints = _talloc_zero_array(cfg, + tcfg->endpoints = _talloc_zero_array(tcfg->cfg, sizeof(struct mgcp_endpoint), tcfg->number_endpoints, "endpoints"); if (!tcfg->endpoints) @@ -958,7 +955,7 @@ int mgcp_endpoints_allocate(struct mgcp_config *cfg) for (i = 0; i < tcfg->number_endpoints; ++i) { tcfg->endpoints[i].ci = CI_UNUSED; - tcfg->endpoints[i].cfg = cfg; + tcfg->endpoints[i].cfg = tcfg->cfg; tcfg->endpoints[i].tcfg = tcfg; mgcp_rtp_end_init(&tcfg->endpoints[i].net_end); mgcp_rtp_end_init(&tcfg->endpoints[i].bts_end); diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c index 81cc68b26..f9554980c 100644 --- a/openbsc/src/mgcp/mgcp_vty.c +++ b/openbsc/src/mgcp/mgcp_vty.c @@ -636,40 +636,26 @@ int mgcp_vty_init(void) return 0; } -int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg) +static int allocate_trunk(struct mgcp_trunk_config *trunk) { - int i, rc; - - g_cfg = cfg; - rc = vty_read_config_file(config_file, NULL); - if (rc < 0) { - fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); - return rc; - } - - - if (!g_cfg->bts_ip) - fprintf(stderr, "No BTS ip address specified. This will allow everyone to connect.\n"); - - if (!g_cfg->source_addr) { - fprintf(stderr, "You need to specify a bind address.\n"); - return -1; - } + int i; + struct mgcp_config *cfg = trunk->cfg; - if (mgcp_endpoints_allocate(g_cfg) != 0) { - fprintf(stderr, "Failed to allocate endpoints: %d. Quitting.\n", - g_cfg->trunk.number_endpoints); + if (mgcp_endpoints_allocate(trunk) != 0) { + LOGP(DMGCP, LOGL_ERROR, + "Failed to allocate %d endpoints on trunk %d.\n", + trunk->number_endpoints, trunk->trunk_nr); return -1; } /* early bind */ - for (i = 1; i < g_cfg->trunk.number_endpoints; ++i) { - struct mgcp_endpoint *endp = &g_cfg->trunk.endpoints[i]; + for (i = 1; i < trunk->number_endpoints; ++i) { + struct mgcp_endpoint *endp = &trunk->endpoints[i]; int rtp_port; - if (g_cfg->bts_ports.mode == PORT_ALLOC_STATIC) { + if (cfg->bts_ports.mode == PORT_ALLOC_STATIC) { rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), - g_cfg->bts_ports.base_port); + cfg->bts_ports.base_port); if (mgcp_bind_bts_rtp_port(endp, rtp_port) != 0) { LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); return -1; @@ -677,9 +663,9 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg) endp->bts_end.local_alloc = PORT_ALLOC_STATIC; } - if (g_cfg->net_ports.mode == PORT_ALLOC_STATIC) { + if (cfg->net_ports.mode == PORT_ALLOC_STATIC) { rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), - g_cfg->net_ports.base_port); + cfg->net_ports.base_port); if (mgcp_bind_net_rtp_port(endp, rtp_port) != 0) { LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); return -1; @@ -687,10 +673,10 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg) endp->net_end.local_alloc = PORT_ALLOC_STATIC; } - if (g_cfg->transcoder_ip && g_cfg->transcoder_ports.mode == PORT_ALLOC_STATIC) { + if (cfg->transcoder_ip && cfg->transcoder_ports.mode == PORT_ALLOC_STATIC) { /* network side */ rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), - g_cfg->transcoder_ports.base_port); + cfg->transcoder_ports.base_port); if (mgcp_bind_trans_net_rtp_port(endp, rtp_port) != 0) { LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); return -1; @@ -699,7 +685,7 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg) /* bts side */ rtp_port = rtp_calculate_port(endp_back_channel(ENDPOINT_NUMBER(endp)), - g_cfg->transcoder_ports.base_port); + cfg->transcoder_ports.base_port); if (mgcp_bind_trans_bts_rtp_port(endp, rtp_port) != 0) { LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); return -1; @@ -711,3 +697,40 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg) return 0; } +int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg) +{ + int rc; + struct mgcp_trunk_config *trunk; + + g_cfg = cfg; + rc = vty_read_config_file(config_file, NULL); + if (rc < 0) { + fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); + return rc; + } + + + if (!g_cfg->bts_ip) + fprintf(stderr, "No BTS ip address specified. This will allow everyone to connect.\n"); + + if (!g_cfg->source_addr) { + fprintf(stderr, "You need to specify a bind address.\n"); + return -1; + } + + if (allocate_trunk(&g_cfg->trunk) != 0) { + LOGP(DMGCP, LOGL_ERROR, "Failed to initialize the virtual trunk.\n"); + return -1; + } + + llist_for_each_entry(trunk, &g_cfg->trunks, entry) { + if (allocate_trunk(trunk) != 0) { + LOGP(DMGCP, LOGL_ERROR, + "Failed to initialize E1 trunk %d.\n", trunk->trunk_nr); + return -1; + } + } + + return 0; +} + -- cgit v1.2.3