diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-02-27 11:04:27 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-02-27 11:05:18 +0100 |
commit | 9ec030d32da5426e184179c4867b01b910885dec (patch) | |
tree | 8590afb1a90b87274fd0224606f6a6ac1d3353e9 /openbsc/src/nat/bsc_mgcp_utils.c | |
parent | a9e9331285bccb97e3e9b8aeb5659b1fe119597b (diff) |
nat: Change number of multiplexes to the max-endpoints
Diffstat (limited to 'openbsc/src/nat/bsc_mgcp_utils.c')
-rw-r--r-- | openbsc/src/nat/bsc_mgcp_utils.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/openbsc/src/nat/bsc_mgcp_utils.c b/openbsc/src/nat/bsc_mgcp_utils.c index 4df5621ed..363734932 100644 --- a/openbsc/src/nat/bsc_mgcp_utils.c +++ b/openbsc/src/nat/bsc_mgcp_utils.c @@ -38,8 +38,20 @@ #include <errno.h> #include <unistd.h> +int bsc_mgcp_nr_multiplexes(int max_endpoints) +{ + int div = max_endpoints / 32; + + if ((max_endpoints % 32) != 0) + div += 1; + + return div; +} + static int bsc_init_endps_if_needed(struct bsc_connection *con) { + int multiplexes; + /* we have done that */ if (con->_endpoint_status) return 0; @@ -48,9 +60,10 @@ static int bsc_init_endps_if_needed(struct bsc_connection *con) if (!con->cfg) return -1; - con->number_multiplexes = con->cfg->number_multiplexes; - con->_endpoint_status = talloc_zero_array(con, char, - (32 * con->cfg->number_multiplexes) + 1); + multiplexes = bsc_mgcp_nr_multiplexes(con->cfg->max_endpoints); + con->number_multiplexes = multiplexes; + con->max_endpoints = con->cfg->max_endpoints; + con->_endpoint_status = talloc_zero_array(con, char, 32 * multiplexes + 1); return con->_endpoint_status == NULL; } @@ -58,7 +71,7 @@ static int bsc_assign_endpoint(struct bsc_connection *bsc, struct sccp_connectio { int multiplex; int timeslot; - const int number_endpoints = 32 * bsc->number_multiplexes; + const int number_endpoints = bsc->max_endpoints; int i; mgcp_endpoint_to_timeslot(bsc->last_endpoint, &multiplex, ×lot); @@ -82,6 +95,14 @@ static int bsc_assign_endpoint(struct bsc_connection *bsc, struct sccp_connectio endpoint = mgcp_timeslot_to_endpoint(multiplex, timeslot); + /* Now check if we are allowed to assign this one */ + if (endpoint >= bsc->max_endpoints) { + multiplex = 0; + timeslot = 1; + endpoint = mgcp_timeslot_to_endpoint(multiplex, timeslot); + } + + if (bsc->_endpoint_status[endpoint] == 0) { bsc->_endpoint_status[endpoint] = 1; con->bsc_endp = endpoint; |