<p>Pau Espin Pedrol has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/14026">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">mgcp-cli: Parse X-Osmux on CRCX response<br><br>Change-Id: I6174d092b7425b8d3d6d02a55bf294be3e710e6a<br>---<br>M include/osmocom/mgcp_client/mgcp_client.h<br>M src/libosmo-mgcp-client/mgcp_client.c<br>M src/libosmo-mgcp-client/mgcp_client_fsm.c<br>3 files changed, 56 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/26/14026/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/mgcp_client/mgcp_client.h b/include/osmocom/mgcp_client/mgcp_client.h</span><br><span>index be84356..32bd87b 100644</span><br><span>--- a/include/osmocom/mgcp_client/mgcp_client.h</span><br><span>+++ b/include/osmocom/mgcp_client/mgcp_client.h</span><br><span>@@ -67,6 +67,8 @@</span><br><span> char comment[MGCP_COMMENT_MAXLEN];</span><br><span> char conn_id[MGCP_CONN_ID_MAXLEN];</span><br><span> char endpoint[MGCP_ENDPOINT_MAXLEN];</span><br><span style="color: hsl(120, 100%, 40%);">+ bool x_osmo_osmux_use;</span><br><span style="color: hsl(120, 100%, 40%);">+ uint8_t x_osmo_osmux_cid;</span><br><span> };</span><br><span> </span><br><span> struct mgcp_response {</span><br><span>diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c</span><br><span>index bbef9ef..d65a799 100644</span><br><span>--- a/src/libosmo-mgcp-client/mgcp_client.c</span><br><span>+++ b/src/libosmo-mgcp-client/mgcp_client.c</span><br><span>@@ -393,6 +393,40 @@</span><br><span> return -EINVAL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Extract OSMUX CID from an MGCP parameter line (string).</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] line single parameter line from the MGCP message</span><br><span style="color: hsl(120, 100%, 40%);">+ * \returns OSMUX CID, -1 wildcard, -2 on error</span><br><span style="color: hsl(120, 100%, 40%);">+ * FIXME: This is a copy of function in mgcp_msg.c. Have some common.c file between both libs?</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int mgcp_parse_osmux_cid(const char *line)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int osmux_cid;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strstr(line + 2, "Osmux: *")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(DLMGCP, LOGL_DEBUG, "Parsed wilcard Osmux CID\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (sscanf(line + 2, "Osmux: %u", &osmux_cid) != 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(DLMGCP, LOGL_ERROR, "Failed parsing Osmux in MGCP msg line: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ line);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -2;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifndef OSMUX_CID_MAX</span><br><span style="color: hsl(120, 100%, 40%);">+#define OSMUX_CID_MAX 255 /* FIXME: use OSMUX_CID_MAX from libosmo-netif? */</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+ if (osmux_cid > OSMUX_CID_MAX) { /* OSMUX_CID_MAX from libosmo-netif */</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(DLMGCP, LOGL_ERROR, "Osmux ID too large: %u > %u\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ osmux_cid, OSMUX_CID_MAX);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -2;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(DLMGCP, LOGL_DEBUG, "bsc-nat offered Osmux CID %u\n", osmux_cid);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return osmux_cid;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* A new section is marked by a double line break, check a few more</span><br><span> * patterns as there may be variants */</span><br><span> static char *mgcp_find_section_end(char *string)</span><br><span>@@ -567,6 +601,21 @@</span><br><span> if (rc)</span><br><span> goto exit;</span><br><span> break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case 'X':</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strncmp("Osmux: ", line + 2, strlen("Osmux: ")) == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = mgcp_parse_osmux_cid(line);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* -1: we don't want wildcards in response. -2: error */</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+ goto exit;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ r->head.x_osmo_osmux_use = true;</span><br><span style="color: hsl(120, 100%, 40%);">+ r->head.x_osmo_osmux_cid = (uint8_t) rc;</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Ignore unknown X-headers */</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span> default:</span><br><span> /* skip unhandled parameters */</span><br><span> break;</span><br><span>diff --git a/src/libosmo-mgcp-client/mgcp_client_fsm.c b/src/libosmo-mgcp-client/mgcp_client_fsm.c</span><br><span>index 0d16720..efbb365 100644</span><br><span>--- a/src/libosmo-mgcp-client/mgcp_client_fsm.c</span><br><span>+++ b/src/libosmo-mgcp-client/mgcp_client_fsm.c</span><br><span>@@ -275,6 +275,11 @@</span><br><span> return;</span><br><span> }</span><br><span> LOGPFSML(fi, LOGL_DEBUG, "MGW/CRCX: MGW responded with address %s:%u\n", r->audio_ip, r->audio_port);</span><br><span style="color: hsl(120, 100%, 40%);">+ if(r->head.x_osmo_osmux_use) {</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGPFSML(fi, LOGL_DEBUG, "MGW/CRCX: MGW responded using Osmux %u\n", r->head.x_osmo_osmux_cid);</span><br><span style="color: hsl(120, 100%, 40%);">+ mgcp_ctx->conn_peer_remote.x_osmo_osmux_use = true;</span><br><span style="color: hsl(120, 100%, 40%);">+ mgcp_ctx->conn_peer_remote.x_osmo_osmux_cid = r->head.x_osmo_osmux_cid;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> osmo_strlcpy(mgcp_ctx->conn_peer_remote.addr, r->audio_ip, sizeof(mgcp_ctx->conn_peer_remote.addr));</span><br><span> mgcp_ctx->conn_peer_remote.port = r->audio_port;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/14026">change 14026</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/14026"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: osmo-mgw </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I6174d092b7425b8d3d6d02a55bf294be3e710e6a </div>
<div style="display:none"> Gerrit-Change-Number: 14026 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Pau Espin Pedrol <pespin@sysmocom.de> </div>