From 9f239a2a0f8b53eb10a7226271eb599ddbfcffb6 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 6 Jan 2011 19:32:52 +0100 Subject: mgcp: Parse a Digital Trunk endpoint name. --- openbsc/src/mgcp/mgcp_protocol.c | 48 +++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'openbsc/src/mgcp/mgcp_protocol.c') diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c index dba4870f0..f9d723ad7 100644 --- a/openbsc/src/mgcp/mgcp_protocol.c +++ b/openbsc/src/mgcp/mgcp_protocol.c @@ -260,18 +260,56 @@ static int find_msg_pointers(struct msgb *msg, struct mgcp_msg_ptr *ptrs, int pt return found; } +/** + * We have a null terminated string with the endpoint name here. We only + * support two kinds. Simple ones as seen on the BSC level and the ones + * seen on the trunk side. + */ +static struct mgcp_endpoint *find_e1_endpoint(struct mgcp_config *cfg, + const char *mgcp) +{ + char *rest = NULL; + int trunk, endp, mgcp_endp; + + trunk = strtoul(mgcp + 6, &rest, 10); + if (rest == NULL || rest[0] != '/') { + LOGP(DMGCP, LOGL_ERROR, "Wrong trunk name '%s'\n", mgcp); + return NULL; + } + + endp = strtoul(rest + 1, &rest, 10); + if (rest == NULL || rest[0] != '@') { + LOGP(DMGCP, LOGL_ERROR, "Wrong trunk name '%s'\n", mgcp); + return NULL; + } + + /* signalling is on timeslot 1 */ + if (endp == 1) + return NULL; + + mgcp_endp = mgcp_timeslot_to_endpoint(trunk, endp); + if (mgcp_endp < 1 || mgcp_endp >= cfg->number_endpoints) { + LOGP(DMGCP, LOGL_ERROR, "Failed to find endpoint '%s'\n", mgcp); + } + + return &cfg->endpoints[mgcp_endp]; +} + static struct mgcp_endpoint *find_endpoint(struct mgcp_config *cfg, const char *mgcp) { char *endptr = NULL; unsigned int gw = INT_MAX; - gw = strtoul(mgcp, &endptr, 16); - if (gw == 0 || gw >= cfg->number_endpoints || strcmp(endptr, "@mgw") != 0) { - LOGP(DMGCP, LOGL_ERROR, "Not able to find endpoint: '%s'\n", mgcp); - return NULL; + if (strncmp(mgcp, "ds/e1", 5) == 0) { + return find_e1_endpoint(cfg, mgcp); + } else { + gw = strtoul(mgcp, &endptr, 16); + if (gw > 0 && gw < cfg->number_endpoints && strcmp(endptr, "@mgw") == 0) + return &cfg->endpoints[gw]; } - return &cfg->endpoints[gw]; + LOGP(DMGCP, LOGL_ERROR, "Not able to find endpoint: '%s'\n", mgcp); + return NULL; } int mgcp_analyze_header(struct mgcp_config *cfg, struct msgb *msg, -- cgit v1.2.3