Pau Espin Pedrol has uploaded this change for review. ( 
https://gerrit.osmocom.org/14026


Change subject: mgcp-cli: Parse X-Osmux on CRCX response
......................................................................

mgcp-cli: Parse X-Osmux on CRCX response

Change-Id: I6174d092b7425b8d3d6d02a55bf294be3e710e6a
---
M include/osmocom/mgcp_client/mgcp_client.h
M src/libosmo-mgcp-client/mgcp_client.c
M src/libosmo-mgcp-client/mgcp_client_fsm.c
3 files changed, 56 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/26/14026/1

diff --git a/include/osmocom/mgcp_client/mgcp_client.h 
b/include/osmocom/mgcp_client/mgcp_client.h
index be84356..32bd87b 100644
--- a/include/osmocom/mgcp_client/mgcp_client.h
+++ b/include/osmocom/mgcp_client/mgcp_client.h
@@ -67,6 +67,8 @@
        char comment[MGCP_COMMENT_MAXLEN];
        char conn_id[MGCP_CONN_ID_MAXLEN];
        char endpoint[MGCP_ENDPOINT_MAXLEN];
+       bool x_osmo_osmux_use;
+       uint8_t x_osmo_osmux_cid;
 };

 struct mgcp_response {
diff --git a/src/libosmo-mgcp-client/mgcp_client.c 
b/src/libosmo-mgcp-client/mgcp_client.c
index bbef9ef..d65a799 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -393,6 +393,40 @@
        return -EINVAL;
 }

+/*! Extract OSMUX CID from an MGCP parameter line (string).
+ *  \param[in] line single parameter line from the MGCP message
+ *  \returns OSMUX CID, -1 wildcard, -2 on error
+ * FIXME: This is a copy of function in mgcp_msg.c. Have some common.c file 
between both libs?
+ */
+static int mgcp_parse_osmux_cid(const char *line)
+{
+       int osmux_cid;
+
+
+       if (strstr(line + 2, "Osmux: *")) {
+               LOGP(DLMGCP, LOGL_DEBUG, "Parsed wilcard Osmux CID\n");
+               return -1;
+       }
+
+       if (sscanf(line + 2, "Osmux: %u", &osmux_cid) != 1) {
+               LOGP(DLMGCP, LOGL_ERROR, "Failed parsing Osmux in MGCP msg 
line: %s\n",
+                    line);
+               return -2;
+       }
+
+#ifndef OSMUX_CID_MAX
+#define OSMUX_CID_MAX 255 /* FIXME: use OSMUX_CID_MAX from libosmo-netif? */
+#endif
+       if (osmux_cid > OSMUX_CID_MAX) { /* OSMUX_CID_MAX from libosmo-netif */
+               LOGP(DLMGCP, LOGL_ERROR, "Osmux ID too large: %u > %u\n",
+                    osmux_cid, OSMUX_CID_MAX);
+               return -2;
+       }
+       LOGP(DLMGCP, LOGL_DEBUG, "bsc-nat offered Osmux CID %u\n", osmux_cid);
+
+       return osmux_cid;
+}
+
 /* A new section is marked by a double line break, check a few more
  * patterns as there may be variants */
 static char *mgcp_find_section_end(char *string)
@@ -567,6 +601,21 @@
                        if (rc)
                                goto exit;
                        break;
+               case 'X':
+                       if (strncmp("Osmux: ", line + 2, strlen("Osmux: ")) == 
0) {
+                               rc = mgcp_parse_osmux_cid(line);
+                               if (rc < 0) {
+                                       /* -1: we don't want wildcards in 
response. -2: error */
+                                       rc = -EINVAL;
+                                       goto exit;
+                               }
+                               r->head.x_osmo_osmux_use = true;
+                               r->head.x_osmo_osmux_cid = (uint8_t) rc;
+                               rc = 0;
+                               break;
+                       }
+                       /* Ignore unknown X-headers */
+                       break;
                default:
                        /* skip unhandled parameters */
                        break;
diff --git a/src/libosmo-mgcp-client/mgcp_client_fsm.c 
b/src/libosmo-mgcp-client/mgcp_client_fsm.c
index 0d16720..efbb365 100644
--- a/src/libosmo-mgcp-client/mgcp_client_fsm.c
+++ b/src/libosmo-mgcp-client/mgcp_client_fsm.c
@@ -275,6 +275,11 @@
                return;
        }
        LOGPFSML(fi, LOGL_DEBUG, "MGW/CRCX: MGW responded with address 
%s:%u\n", r->audio_ip, r->audio_port);
+       if(r->head.x_osmo_osmux_use) {
+               LOGPFSML(fi, LOGL_DEBUG, "MGW/CRCX: MGW responded using Osmux 
%u\n", r->head.x_osmo_osmux_cid);
+               mgcp_ctx->conn_peer_remote.x_osmo_osmux_use = true;
+               mgcp_ctx->conn_peer_remote.x_osmo_osmux_cid = 
r->head.x_osmo_osmux_cid;
+       }

        osmo_strlcpy(mgcp_ctx->conn_peer_remote.addr, r->audio_ip, 
sizeof(mgcp_ctx->conn_peer_remote.addr));
        mgcp_ctx->conn_peer_remote.port = r->audio_port;

--
To view, visit https://gerrit.osmocom.org/14026
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6174d092b7425b8d3d6d02a55bf294be3e710e6a
Gerrit-Change-Number: 14026
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol <[email protected]>

Reply via email to