aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/mgcp/mgcp_vty.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsc/src/mgcp/mgcp_vty.c')
-rw-r--r--openbsc/src/mgcp/mgcp_vty.c83
1 files changed, 53 insertions, 30 deletions
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;
+}
+