aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-08-28 16:08:39 +0800
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-08-29 16:35:24 +0800
commitf4b343920668280b39ddb95209f6ab0ceccab630 (patch)
tree20244d3e611e6ff966c9cb4ab2879943c39c2bc4 /openbsc
parent591003328dac804592c8a5dc749d93d5e0be4347 (diff)
nat: Make the code work in terms of endpoints instead of timeslot/multiplex
We are going to have more than one trunk, so all code hardcoding the multiplex to zero must go. Avoid this kind of problem by saving the MGCP endpoint number and comparing that.
Diffstat (limited to 'openbsc')
-rw-r--r--openbsc/include/openbsc/bsc_nat_sccp.h9
-rw-r--r--openbsc/src/nat/bsc_mgcp_utils.c30
-rw-r--r--openbsc/src/nat/bsc_nat_vty.c2
-rw-r--r--openbsc/tests/bsc-nat/bsc_nat_test.c17
4 files changed, 26 insertions, 32 deletions
diff --git a/openbsc/include/openbsc/bsc_nat_sccp.h b/openbsc/include/openbsc/bsc_nat_sccp.h
index 73e9c690..fcfd23be 100644
--- a/openbsc/include/openbsc/bsc_nat_sccp.h
+++ b/openbsc/include/openbsc/bsc_nat_sccp.h
@@ -79,10 +79,13 @@ struct sccp_connections {
int con_type;
int con_local;
- /* GSM audio handling. That is 32 * multiplex + ts */
+ /*
+ * audio handling. Remember if we have ever send a CRCX,
+ * remember the endpoint used by the MSC and BSC.
+ */
int crcx;
- int msc_timeslot;
- int bsc_timeslot;
+ int msc_endp;
+ int bsc_endp;
/* timeout handling */
struct timespec creation_time;
diff --git a/openbsc/src/nat/bsc_mgcp_utils.c b/openbsc/src/nat/bsc_mgcp_utils.c
index e3258f02..4983c352 100644
--- a/openbsc/src/nat/bsc_mgcp_utils.c
+++ b/openbsc/src/nat/bsc_mgcp_utils.c
@@ -45,7 +45,7 @@ int bsc_mgcp_assign(struct sccp_connections *con, struct msgb *msg)
uint16_t cic;
uint8_t timeslot;
uint8_t multiplex;
- int combined;
+ int endp;
if (!msg->l3h) {
LOGP(DNAT, LOGL_ERROR, "Assignment message should have l3h pointer.\n");
@@ -68,22 +68,22 @@ int bsc_mgcp_assign(struct sccp_connections *con, struct msgb *msg)
multiplex = (cic & ~0x1f) >> 5;
- combined = (32 * multiplex) + timeslot;
+ endp = mgcp_timeslot_to_endpoint(multiplex, timeslot);
/* find stale connections using that endpoint */
llist_for_each_entry(mcon, &con->bsc->nat->sccp_connections, list_entry) {
- if (mcon->msc_timeslot == combined) {
+ if (mcon->msc_endp == endp) {
LOGP(DNAT, LOGL_ERROR,
- "Timeslot %d was assigned to 0x%x and now 0x%x\n",
- combined,
+ "Endpoint %d was assigned to 0x%x and now 0x%x\n",
+ endp,
sccp_src_ref_to_int(&mcon->patched_ref),
sccp_src_ref_to_int(&con->patched_ref));
bsc_mgcp_dlcx(mcon);
}
}
- con->msc_timeslot = combined;
- con->bsc_timeslot = con->msc_timeslot;
+ con->msc_endp = endp;
+ con->bsc_endp = endp;
return 0;
}
@@ -147,19 +147,17 @@ static void bsc_mgcp_send_dlcx(struct bsc_connection *bsc, int endpoint)
void bsc_mgcp_init(struct sccp_connections *con)
{
- con->msc_timeslot = -1;
- con->bsc_timeslot = -1;
+ con->msc_endp = -1;
+ con->bsc_endp = -1;
con->crcx = 0;
}
void bsc_mgcp_dlcx(struct sccp_connections *con)
{
/* send a DLCX down the stream */
- if (con->bsc_timeslot != -1 && con->crcx) {
- int bsc_endp = mgcp_timeslot_to_endpoint(0, con->bsc_timeslot);
- int msc_endp = mgcp_timeslot_to_endpoint(0, con->msc_timeslot);
- bsc_mgcp_send_dlcx(con->bsc, bsc_endp);
- bsc_mgcp_free_endpoint(con->bsc->nat, msc_endp);
+ if (con->bsc_endp != -1 && con->crcx) {
+ bsc_mgcp_send_dlcx(con->bsc, con->bsc_endp);
+ bsc_mgcp_free_endpoint(con->bsc->nat, con->msc_endp);
}
bsc_mgcp_init(con);
@@ -172,9 +170,9 @@ struct sccp_connections *bsc_mgcp_find_con(struct bsc_nat *nat, int endpoint)
struct sccp_connections *sccp;
llist_for_each_entry(sccp, &nat->sccp_connections, list_entry) {
- if (sccp->msc_timeslot == -1)
+ if (sccp->msc_endp == -1)
continue;
- if (mgcp_timeslot_to_endpoint(0, sccp->msc_timeslot) != endpoint)
+ if (sccp->msc_endp != endpoint)
continue;
con = sccp;
diff --git a/openbsc/src/nat/bsc_nat_vty.c b/openbsc/src/nat/bsc_nat_vty.c
index d8af1c23..b72eb4e2 100644
--- a/openbsc/src/nat/bsc_nat_vty.c
+++ b/openbsc/src/nat/bsc_nat_vty.c
@@ -121,7 +121,7 @@ DEFUN(show_sccp, show_sccp_cmd, "show sccp connections",
sccp_src_ref_to_int(&con->patched_ref),
con->has_remote_ref,
sccp_src_ref_to_int(&con->remote_ref),
- con->msc_timeslot, con->bsc_timeslot,
+ con->msc_endp, con->bsc_endp,
bsc_con_type_to_string(con->con_type),
VTY_NEWLINE);
}
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index c5234aa2..b7a89c5b 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -449,19 +449,19 @@ static void test_mgcp_ass_tracking(void)
abort();
}
- if (con.msc_timeslot != 21) {
+ if (con.msc_endp != 21) {
fprintf(stderr, "Timeslot should be 21.\n");
abort();
}
- if (con.bsc_timeslot != 21) {
+ if (con.bsc_endp != 21) {
fprintf(stderr, "Assigned timeslot should have been 21.\n");
abort();
}
talloc_free(parsed);
bsc_mgcp_dlcx(&con);
- if (con.bsc_timeslot != -1 || con.msc_timeslot != -1) {
+ if (con.bsc_endp != -1 || con.msc_endp != -1) {
fprintf(stderr, "Clearing should remove the mapping.\n");
abort();
}
@@ -483,8 +483,8 @@ static void test_mgcp_find(void)
llist_add(&con->list_entry, &nat->bsc_connections);
sccp_con = talloc_zero(con, struct sccp_connections);
- sccp_con->msc_timeslot = 12;
- sccp_con->bsc_timeslot = 12;
+ sccp_con->msc_endp = 12;
+ sccp_con->bsc_endp = 12;
sccp_con->bsc = con;
llist_add(&sccp_con->list_entry, &nat->sccp_connections);
@@ -498,13 +498,6 @@ static void test_mgcp_find(void)
abort();
}
- sccp_con->msc_timeslot = 0;
- sccp_con->bsc_timeslot = 0;
- if (bsc_mgcp_find_con(nat, 1) != sccp_con) {
- fprintf(stderr, "Didn't find the connection\n");
- abort();
- }
-
/* free everything */
talloc_free(nat);
}