Initially implement the new osmo-mgw and libosmo-mgcp
Leave the old osmo-bsc_mgcp and libosmo-legacy-mgcp as it is; on a copy thereof
(added by a previous commit), apply changes to initially implement the new
osmo-mgw.
Adjust build system and debian packaging to accomodate the new libosmo-mgcp and
osmo-mgw.
The main differences:
*) use a list to manage rtp connections.
Aggregate all rtp related information inside a single struct.
Use a linked list to manage the both connections (net and bts).
The idea behind using a list is that we might support conference
calls at some later point.
Store the linked list in struct mgcp_endpoint, have a private linked
list for each endpoint. The list contains connection items which are
implemented in struct mgcp_conn. A connection is allocated and freed
using the functions in mgcp_conn.c. A connection is allocated on the
reception of a CRCX command and freed with the reception of a DLCX
command.
*) remove external transcoder feature
Fortunatelly the external transcoder feature is not needed
anymore. This patch removes the related code.
*) vty: get rid of CONN_BTS and CONN_NET
Since the new connection model does not make a difference
between BTS and NET connections the VTY should not use
the fixed CONN_BTS and CONN_NET constants.
- Handle the conns list inside the endpoint directly
- introduce function to dump basic rtp connection info
- introduce human readable names for connections
Parts of the code adjusted to use generalized connections instead of explicit
BTS/NET ones:
- teach mgcp_send_dummy() to send dummy packets to any RTP connection
- network: generalize mgcp_bind_net/bts_rtp_port()
- network: generalize mgcp_send()
- tap: generalize call tapping feature
- stat: generalize statistics
- Replace rtp_data_net() and rtp_data_bts() with generalized rtp_data_rx()
*) mgcp_protocol.c fixes:
- check ci string before it is converted:
In case of missing ci, a nullpointer is delivered to strtoul().
Add a function that takes ci, checks it and converts it to an
uint32_t. Use the return code to react on missing ci.
- output error message on missing CI.
- when parsing the mode, print log message when mode is missing.
- use mode_orig when mode is missing.
- fix ptime formatstring to use %u rather than %d.
- cosmetic: log when connection is deleted on DLCX.
- change loglevels of CRCX, MDCX, DLCX events from DEBUG to NOTICE.
*) mgcp_test
- apply rename of strline_r() to mgcp_strline().
- MGCP command macros:
- Add 'I: 1' parameters.
- Use proper port numbers:
from m=audio 0 RTP/AVP 126
to m=audio 16002 RTP/AVP 128
- Change ptime to 'a=ptime:40' because this is what the MGW currently
returns. CRCX generally feed a ptime:40 and this is expected to be
returned.
- struct mgcp_test: Use only one ptype, there are no explicit BTS and NET
endpoints anymore.
Hence remove one column from tests[].
- test_messages():
- Enable: remove '#if 0'
- Remove concept of BTS and NET endpoints: test only one conn, as they are
now interchangeable anyway.
- remove endpoint init, now done internally.
- add false asserts in error cases.
- test_retransmission():
- remove endpoint init, now done internally.
- add false asserts in error cases.
- test_packet_error_detection():
- Remove concept of BTS and NET endpoints: test only one conn, as they are
now interchangeable anyway. Use arbitrary conn ids (e.g. 4711).
- remove endpoint init, now done internally.
- add false assert in error case.
- Assert that a conn really vanishes on DLCX, previously the conn would
remain and just be unused, now it is actually discarded.
- test_no_cycle()
- Remove concept of BTS and NET endpoints: test only one conn, as they are
now interchangeable anyway. Use arbitrary conn ids (e.g. 4711).
- test_no_name()
- Enable: remove '#if 0'.
- remove endpoint init, now done internally.
- add false assert in error case.
- mgcp_test.ok: adjust expected results to status quo:
- We now see two dummy packets instead of one, now sent to both sides because
we don't know of BTS or NET side. (maybe drop dummy packets later...)
- packet duration, conn mode: now sane defaults show instead of unset.
- various whitespace and formatting changes from lindent.
Change-Id: Ie008599136c7ed8a0dfbb0cf803188975a499fc5
2017-08-22 14:35:41 +00:00
|
|
|
/* A Media Gateway Control Protocol Media Gateway: RFC 3435 */
|
|
|
|
/* Message parser/generator utilities */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (C) 2009-2012 by Holger Hans Peter Freyther <zecke@selfish.org>
|
|
|
|
* (C) 2009-2012 by On-Waves
|
|
|
|
* (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include <osmocom/mgcp/mgcp_internal.h>
|
2017-09-08 02:25:16 +00:00
|
|
|
#include <osmocom/mgcp/mgcp_common.h>
|
Initially implement the new osmo-mgw and libosmo-mgcp
Leave the old osmo-bsc_mgcp and libosmo-legacy-mgcp as it is; on a copy thereof
(added by a previous commit), apply changes to initially implement the new
osmo-mgw.
Adjust build system and debian packaging to accomodate the new libosmo-mgcp and
osmo-mgw.
The main differences:
*) use a list to manage rtp connections.
Aggregate all rtp related information inside a single struct.
Use a linked list to manage the both connections (net and bts).
The idea behind using a list is that we might support conference
calls at some later point.
Store the linked list in struct mgcp_endpoint, have a private linked
list for each endpoint. The list contains connection items which are
implemented in struct mgcp_conn. A connection is allocated and freed
using the functions in mgcp_conn.c. A connection is allocated on the
reception of a CRCX command and freed with the reception of a DLCX
command.
*) remove external transcoder feature
Fortunatelly the external transcoder feature is not needed
anymore. This patch removes the related code.
*) vty: get rid of CONN_BTS and CONN_NET
Since the new connection model does not make a difference
between BTS and NET connections the VTY should not use
the fixed CONN_BTS and CONN_NET constants.
- Handle the conns list inside the endpoint directly
- introduce function to dump basic rtp connection info
- introduce human readable names for connections
Parts of the code adjusted to use generalized connections instead of explicit
BTS/NET ones:
- teach mgcp_send_dummy() to send dummy packets to any RTP connection
- network: generalize mgcp_bind_net/bts_rtp_port()
- network: generalize mgcp_send()
- tap: generalize call tapping feature
- stat: generalize statistics
- Replace rtp_data_net() and rtp_data_bts() with generalized rtp_data_rx()
*) mgcp_protocol.c fixes:
- check ci string before it is converted:
In case of missing ci, a nullpointer is delivered to strtoul().
Add a function that takes ci, checks it and converts it to an
uint32_t. Use the return code to react on missing ci.
- output error message on missing CI.
- when parsing the mode, print log message when mode is missing.
- use mode_orig when mode is missing.
- fix ptime formatstring to use %u rather than %d.
- cosmetic: log when connection is deleted on DLCX.
- change loglevels of CRCX, MDCX, DLCX events from DEBUG to NOTICE.
*) mgcp_test
- apply rename of strline_r() to mgcp_strline().
- MGCP command macros:
- Add 'I: 1' parameters.
- Use proper port numbers:
from m=audio 0 RTP/AVP 126
to m=audio 16002 RTP/AVP 128
- Change ptime to 'a=ptime:40' because this is what the MGW currently
returns. CRCX generally feed a ptime:40 and this is expected to be
returned.
- struct mgcp_test: Use only one ptype, there are no explicit BTS and NET
endpoints anymore.
Hence remove one column from tests[].
- test_messages():
- Enable: remove '#if 0'
- Remove concept of BTS and NET endpoints: test only one conn, as they are
now interchangeable anyway.
- remove endpoint init, now done internally.
- add false asserts in error cases.
- test_retransmission():
- remove endpoint init, now done internally.
- add false asserts in error cases.
- test_packet_error_detection():
- Remove concept of BTS and NET endpoints: test only one conn, as they are
now interchangeable anyway. Use arbitrary conn ids (e.g. 4711).
- remove endpoint init, now done internally.
- add false assert in error case.
- Assert that a conn really vanishes on DLCX, previously the conn would
remain and just be unused, now it is actually discarded.
- test_no_cycle()
- Remove concept of BTS and NET endpoints: test only one conn, as they are
now interchangeable anyway. Use arbitrary conn ids (e.g. 4711).
- test_no_name()
- Enable: remove '#if 0'.
- remove endpoint init, now done internally.
- add false assert in error case.
- mgcp_test.ok: adjust expected results to status quo:
- We now see two dummy packets instead of one, now sent to both sides because
we don't know of BTS or NET side. (maybe drop dummy packets later...)
- packet duration, conn mode: now sane defaults show instead of unset.
- various whitespace and formatting changes from lindent.
Change-Id: Ie008599136c7ed8a0dfbb0cf803188975a499fc5
2017-08-22 14:35:41 +00:00
|
|
|
#include <osmocom/mgcp/mgcp_msg.h>
|
|
|
|
#include <osmocom/mgcp/mgcp_conn.h>
|
|
|
|
|
|
|
|
/*! Display an mgcp message on the log output.
|
|
|
|
* \param[in] message mgcp message string
|
|
|
|
* \param[in] len message mgcp message string length
|
|
|
|
* \param[in] preamble string to display in logtext in front of each line */
|
|
|
|
void mgcp_disp_msg(unsigned char *message, unsigned int len, char *preamble)
|
|
|
|
{
|
|
|
|
unsigned char line[80];
|
|
|
|
unsigned char *ptr;
|
|
|
|
unsigned int consumed = 0;
|
|
|
|
unsigned int consumed_line = 0;
|
|
|
|
unsigned int line_count = 0;
|
|
|
|
|
|
|
|
if (!log_check_level(DLMGCP, LOGL_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
memset(line, 0, sizeof(line));
|
|
|
|
ptr = line;
|
|
|
|
consumed_line = 0;
|
|
|
|
do {
|
|
|
|
if (*message != '\n' && *message != '\r') {
|
|
|
|
*ptr = *message;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
message++;
|
|
|
|
consumed++;
|
|
|
|
consumed_line++;
|
|
|
|
} while (*message != '\n' && consumed < len
|
|
|
|
&& consumed_line < sizeof(line));
|
|
|
|
|
|
|
|
if (strlen((const char *)line)) {
|
|
|
|
LOGP(DLMGCP, LOGL_DEBUG, "%s: line #%02u: %s\n",
|
|
|
|
preamble, line_count, line);
|
|
|
|
line_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (consumed >= len)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Parse connection mode.
|
|
|
|
* \param[in] mode as string (recvonly, sendrecv, sendonly or loopback)
|
|
|
|
* \param[in] endp pointer to endpoint (only used for log output)
|
|
|
|
* \param[out] associated connection to be modified accordingly
|
|
|
|
* \returns 0 on success, -1 on error */
|
|
|
|
int mgcp_parse_conn_mode(const char *mode, struct mgcp_endpoint *endp,
|
|
|
|
struct mgcp_conn *conn)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!mode) {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR,
|
|
|
|
"endpoint:%x missing connection mode\n",
|
|
|
|
ENDPOINT_NUMBER(endp));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!conn)
|
|
|
|
return -1;
|
|
|
|
if (!endp)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (strcmp(mode, "recvonly") == 0)
|
|
|
|
conn->mode = MGCP_CONN_RECV_ONLY;
|
|
|
|
else if (strcmp(mode, "sendrecv") == 0)
|
|
|
|
conn->mode = MGCP_CONN_RECV_SEND;
|
|
|
|
else if (strcmp(mode, "sendonly") == 0)
|
|
|
|
conn->mode = MGCP_CONN_SEND_ONLY;
|
|
|
|
else if (strcmp(mode, "loopback") == 0)
|
|
|
|
conn->mode = MGCP_CONN_LOOPBACK;
|
|
|
|
else {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR,
|
|
|
|
"endpoint:%x unknown connection mode: '%s'\n",
|
|
|
|
ENDPOINT_NUMBER(endp), mode);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Special handling für RTP connections */
|
|
|
|
if (conn->type == MGCP_CONN_TYPE_RTP) {
|
|
|
|
conn->u.rtp.end.output_enabled =
|
|
|
|
conn->mode & MGCP_CONN_SEND_ONLY ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGP(DLMGCP, LOGL_DEBUG,
|
|
|
|
"endpoint:%x conn:%s\n",
|
|
|
|
ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn));
|
|
|
|
|
|
|
|
LOGP(DLMGCP, LOGL_DEBUG,
|
|
|
|
"endpoint:%x connection mode '%s' %d\n",
|
|
|
|
ENDPOINT_NUMBER(endp), mode, conn->mode);
|
|
|
|
|
|
|
|
/* Special handling für RTP connections */
|
|
|
|
if (conn->type == MGCP_CONN_TYPE_RTP) {
|
|
|
|
LOGP(DLMGCP, LOGL_DEBUG, "endpoint:%x output_enabled %d\n",
|
|
|
|
ENDPOINT_NUMBER(endp), conn->u.rtp.end.output_enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The VTY might change the connection mode at any time, so we have
|
|
|
|
* to hold a copy of the original connection mode */
|
|
|
|
conn->mode_orig = conn->mode;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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. (helper function for find_endpoint()) */
|
|
|
|
static struct mgcp_endpoint *find_e1_endpoint(struct mgcp_config *cfg,
|
|
|
|
const char *mgcp)
|
|
|
|
{
|
|
|
|
char *rest = NULL;
|
|
|
|
struct mgcp_trunk_config *tcfg;
|
|
|
|
int trunk, endp;
|
|
|
|
|
|
|
|
trunk = strtoul(mgcp + 6, &rest, 10);
|
|
|
|
if (rest == NULL || rest[0] != '/' || trunk < 1) {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR, "Wrong trunk name '%s'\n", mgcp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
endp = strtoul(rest + 1, &rest, 10);
|
|
|
|
if (rest == NULL || rest[0] != '@') {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR, "Wrong endpoint name '%s'\n", mgcp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* signalling is on timeslot 1 */
|
|
|
|
if (endp == 1)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tcfg = mgcp_trunk_num(cfg, trunk);
|
|
|
|
if (!tcfg) {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR, "The trunk %d is not declared.\n",
|
|
|
|
trunk);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tcfg->endpoints) {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR,
|
|
|
|
"Endpoints of trunk %d not allocated.\n", trunk);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endp < 1 || endp >= tcfg->number_endpoints) {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR, "Failed to find endpoint '%s'\n",
|
|
|
|
mgcp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &tcfg->endpoints[endp];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search the endpoint pool for the endpoint that had been selected via the
|
|
|
|
* MGCP message (helper function for mgcp_analyze_header()) */
|
|
|
|
static struct mgcp_endpoint *find_endpoint(struct mgcp_config *cfg,
|
|
|
|
const char *mgcp)
|
|
|
|
{
|
|
|
|
char *endptr = NULL;
|
|
|
|
unsigned int gw = INT_MAX;
|
|
|
|
|
|
|
|
if (strncmp(mgcp, "ds/e1", 5) == 0)
|
|
|
|
return find_e1_endpoint(cfg, mgcp);
|
|
|
|
|
MGCP endpoints: parse as decimal, not hex
Parse the endpoint index from the MGCP messages as base-10, not 16.
If osmo-mgw parses the endpoint IDs as base-16 numbers while OsmoMSC and
OsmoBSC pass in decimal endpoint numbers, the consequence is, for example:
- I configure 32 endpoints in osmo-mgw,
- I tell OsmoBSC to use endpoint range 1-32,
- At some point OsmoBSC may pass in, say, "30@mgw",
- "30" is parsed base-16 and ends up being endpoint index 48, instead of 32,
- OsmoMGW sees that 48 > number_endpoints and barfs.
Related: OS#2633
Change-Id: Ic18608ff23303c1564548a86d5f6bfa539fe555e
2017-11-11 01:00:03 +00:00
|
|
|
gw = strtoul(mgcp, &endptr, 10);
|
Initially implement the new osmo-mgw and libosmo-mgcp
Leave the old osmo-bsc_mgcp and libosmo-legacy-mgcp as it is; on a copy thereof
(added by a previous commit), apply changes to initially implement the new
osmo-mgw.
Adjust build system and debian packaging to accomodate the new libosmo-mgcp and
osmo-mgw.
The main differences:
*) use a list to manage rtp connections.
Aggregate all rtp related information inside a single struct.
Use a linked list to manage the both connections (net and bts).
The idea behind using a list is that we might support conference
calls at some later point.
Store the linked list in struct mgcp_endpoint, have a private linked
list for each endpoint. The list contains connection items which are
implemented in struct mgcp_conn. A connection is allocated and freed
using the functions in mgcp_conn.c. A connection is allocated on the
reception of a CRCX command and freed with the reception of a DLCX
command.
*) remove external transcoder feature
Fortunatelly the external transcoder feature is not needed
anymore. This patch removes the related code.
*) vty: get rid of CONN_BTS and CONN_NET
Since the new connection model does not make a difference
between BTS and NET connections the VTY should not use
the fixed CONN_BTS and CONN_NET constants.
- Handle the conns list inside the endpoint directly
- introduce function to dump basic rtp connection info
- introduce human readable names for connections
Parts of the code adjusted to use generalized connections instead of explicit
BTS/NET ones:
- teach mgcp_send_dummy() to send dummy packets to any RTP connection
- network: generalize mgcp_bind_net/bts_rtp_port()
- network: generalize mgcp_send()
- tap: generalize call tapping feature
- stat: generalize statistics
- Replace rtp_data_net() and rtp_data_bts() with generalized rtp_data_rx()
*) mgcp_protocol.c fixes:
- check ci string before it is converted:
In case of missing ci, a nullpointer is delivered to strtoul().
Add a function that takes ci, checks it and converts it to an
uint32_t. Use the return code to react on missing ci.
- output error message on missing CI.
- when parsing the mode, print log message when mode is missing.
- use mode_orig when mode is missing.
- fix ptime formatstring to use %u rather than %d.
- cosmetic: log when connection is deleted on DLCX.
- change loglevels of CRCX, MDCX, DLCX events from DEBUG to NOTICE.
*) mgcp_test
- apply rename of strline_r() to mgcp_strline().
- MGCP command macros:
- Add 'I: 1' parameters.
- Use proper port numbers:
from m=audio 0 RTP/AVP 126
to m=audio 16002 RTP/AVP 128
- Change ptime to 'a=ptime:40' because this is what the MGW currently
returns. CRCX generally feed a ptime:40 and this is expected to be
returned.
- struct mgcp_test: Use only one ptype, there are no explicit BTS and NET
endpoints anymore.
Hence remove one column from tests[].
- test_messages():
- Enable: remove '#if 0'
- Remove concept of BTS and NET endpoints: test only one conn, as they are
now interchangeable anyway.
- remove endpoint init, now done internally.
- add false asserts in error cases.
- test_retransmission():
- remove endpoint init, now done internally.
- add false asserts in error cases.
- test_packet_error_detection():
- Remove concept of BTS and NET endpoints: test only one conn, as they are
now interchangeable anyway. Use arbitrary conn ids (e.g. 4711).
- remove endpoint init, now done internally.
- add false assert in error case.
- Assert that a conn really vanishes on DLCX, previously the conn would
remain and just be unused, now it is actually discarded.
- test_no_cycle()
- Remove concept of BTS and NET endpoints: test only one conn, as they are
now interchangeable anyway. Use arbitrary conn ids (e.g. 4711).
- test_no_name()
- Enable: remove '#if 0'.
- remove endpoint init, now done internally.
- add false assert in error case.
- mgcp_test.ok: adjust expected results to status quo:
- We now see two dummy packets instead of one, now sent to both sides because
we don't know of BTS or NET side. (maybe drop dummy packets later...)
- packet duration, conn mode: now sane defaults show instead of unset.
- various whitespace and formatting changes from lindent.
Change-Id: Ie008599136c7ed8a0dfbb0cf803188975a499fc5
2017-08-22 14:35:41 +00:00
|
|
|
if (gw > 0 && gw < cfg->trunk.number_endpoints && endptr[0] == '@')
|
|
|
|
return &cfg->trunk.endpoints[gw];
|
|
|
|
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR, "Not able to find the endpoint: '%s'\n", mgcp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Analyze and parse the the hader of an MGCP messeage string.
|
|
|
|
* \param[out] pdata caller provided memory to store the parsing results
|
|
|
|
* \param[in] data mgcp message string
|
|
|
|
* \returns when the status line was complete and transaction_id and
|
|
|
|
* endp out parameters are set, -1 on error */
|
|
|
|
int mgcp_parse_header(struct mgcp_parse_data *pdata, char *data)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
char *elem, *save = NULL;
|
|
|
|
|
|
|
|
/*! This function will parse the header part of the received
|
|
|
|
* MGCP message. The parsing results are stored in pdata.
|
|
|
|
* The function will also automatically search the pool with
|
|
|
|
* available endpoints in order to find an endpoint that matches
|
|
|
|
* the endpoint string in in the header */
|
|
|
|
|
|
|
|
OSMO_ASSERT(data);
|
|
|
|
pdata->trans = "000000";
|
|
|
|
|
|
|
|
for (elem = strtok_r(data, " ", &save); elem;
|
|
|
|
elem = strtok_r(NULL, " ", &save)) {
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
pdata->trans = elem;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pdata->endp = find_endpoint(pdata->cfg, elem);
|
|
|
|
if (!pdata->endp) {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR,
|
|
|
|
"Unable to find Endpoint `%s'\n", elem);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (strcmp("MGCP", elem)) {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR,
|
|
|
|
"MGCP header parsing error\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (strcmp("1.0", elem)) {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR, "MGCP version `%s' "
|
|
|
|
"not supported\n", elem);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != 4) {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR, "MGCP status line too short.\n");
|
|
|
|
pdata->trans = "000000";
|
|
|
|
pdata->endp = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Extract OSMUX CID from an MGCP parameter line (string).
|
|
|
|
* \param[in] line single parameter line from the MGCP message
|
|
|
|
* \returns OSMUX CID, -1 on error */
|
|
|
|
int mgcp_parse_osmux_cid(const char *line)
|
|
|
|
{
|
|
|
|
int osmux_cid;
|
|
|
|
|
|
|
|
if (sscanf(line + 2, "Osmux: %u", &osmux_cid) != 1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (osmux_cid > OSMUX_CID_MAX) {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR, "Osmux ID too large: %u > %u\n",
|
|
|
|
osmux_cid, OSMUX_CID_MAX);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
LOGP(DLMGCP, LOGL_DEBUG, "bsc-nat offered Osmux CID %u\n", osmux_cid);
|
|
|
|
|
|
|
|
return osmux_cid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Check MGCP parameter line (string) for plausibility.
|
|
|
|
* \param[in] endp pointer to endpoint (only used for log output)
|
|
|
|
* \param[in] line single parameter line from the MGCP message
|
|
|
|
* \returns 1 when line seems plausible, 0 on error */
|
|
|
|
int mgcp_check_param(const struct mgcp_endpoint *endp, const char *line)
|
|
|
|
{
|
|
|
|
const size_t line_len = strlen(line);
|
|
|
|
if (line[0] != '\0' && line_len < 2) {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR,
|
|
|
|
"Wrong MGCP option format: '%s' on 0x%x\n",
|
|
|
|
line, ENDPOINT_NUMBER(endp));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: A couple more checks wouldn't hurt... */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Check if the specified callid seems plausible.
|
|
|
|
* \param[in] endp pointer to endpoint
|
|
|
|
* \param{in] callid to verify
|
|
|
|
* \returns 1 when callid seems plausible, 0 on error */
|
|
|
|
int mgcp_verify_call_id(struct mgcp_endpoint *endp, const char *callid)
|
|
|
|
{
|
|
|
|
/*! This function compares the supplied callid with the called that is
|
|
|
|
* stored in the endpoint structure. */
|
|
|
|
|
|
|
|
if (!endp)
|
|
|
|
return -1;
|
|
|
|
if (!callid)
|
|
|
|
return -1;
|
|
|
|
if (!endp->callid)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (strcmp(endp->callid, callid) != 0) {
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR,
|
|
|
|
"endpoint:%x CallIDs does not match '%s' != '%s'\n",
|
|
|
|
ENDPOINT_NUMBER(endp), endp->callid, callid);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Check if the specified connection id seems plausible.
|
|
|
|
* \param[in] endp pointer to endpoint
|
|
|
|
* \param{in] connection id to verify
|
|
|
|
* \returns 1 when connection id seems plausible, 0 on error */
|
|
|
|
int mgcp_verify_ci(struct mgcp_endpoint *endp, const char *ci)
|
|
|
|
{
|
|
|
|
uint32_t id;
|
|
|
|
|
|
|
|
if (!endp)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
id = strtoul(ci, NULL, 10);
|
|
|
|
|
|
|
|
if (mgcp_conn_get(endp, id))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
LOGP(DLMGCP, LOGL_ERROR,
|
|
|
|
"endpoint:%x No connection found under ConnectionIdentifier %u\n",
|
|
|
|
ENDPOINT_NUMBER(endp), id);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Extract individual lines from MCGP message.
|
|
|
|
* \param[in] str MGCP message string, consisting of multiple lines
|
|
|
|
* \param{in] saveptr pointer to next line in str
|
|
|
|
* \returns line, NULL when done */
|
|
|
|
char *mgcp_strline(char *str, char **saveptr)
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
/*! The function must be called with *str set to the input string
|
|
|
|
* for the first line. After that saveptr will be initalized.
|
|
|
|
* all consecutive lines are extracted by calling the function
|
|
|
|
* with str set to NULL. When done, the function will return NULL
|
|
|
|
* to indicate that all lines have been parsed. */
|
|
|
|
|
|
|
|
if (str)
|
|
|
|
*saveptr = str;
|
|
|
|
|
|
|
|
result = *saveptr;
|
|
|
|
|
|
|
|
if (*saveptr != NULL) {
|
|
|
|
*saveptr = strpbrk(*saveptr, "\r\n");
|
|
|
|
|
|
|
|
if (*saveptr != NULL) {
|
|
|
|
char *eos = *saveptr;
|
|
|
|
|
|
|
|
if ((*saveptr)[0] == '\r' && (*saveptr)[1] == '\n')
|
|
|
|
(*saveptr)++;
|
|
|
|
(*saveptr)++;
|
|
|
|
if ((*saveptr)[0] == '\0')
|
|
|
|
*saveptr = NULL;
|
|
|
|
|
|
|
|
*eos = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Parse CI from a given string.
|
|
|
|
* \param[out] caller provided memory to store the result
|
|
|
|
* \param{in] string containing the connection id
|
|
|
|
* \returns 0 on success, -1 on error */
|
|
|
|
int mgcp_parse_ci(uint32_t *conn_id, const char *ci)
|
|
|
|
{
|
|
|
|
|
|
|
|
OSMO_ASSERT(conn_id);
|
|
|
|
|
|
|
|
if (!ci)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*conn_id = strtoul(ci, NULL, 10);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|