<p>dexter has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-mgw/+/19075">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">mgcp_client: add function to generate e1-endpoint names<br><br>mgcp_client.h offers functions to generate endpoint names for wildcarded<br>request. This is used in osmo-bsc, lets now also add a function that can<br>generate e1-endpoint names.<br><br>Related: OS#2547<br>Change-Id: Iec35b5bae8a7b07ddb3559f7114a24dcd10e8f14<br>---<br>M include/osmocom/mgcp_client/mgcp_client.h<br>M src/libosmo-mgcp-client/mgcp_client.c<br>2 files changed, 62 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/75/19075/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 32bd87b..8a43ccc 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>@@ -137,6 +137,8 @@</span><br><span> </span><br><span> const char *mgcp_client_endpoint_domain(const struct mgcp_client *mgcp);</span><br><span> const char *mgcp_client_rtpbridge_wildcard(const struct mgcp_client *mgcp);</span><br><span style="color: hsl(120, 100%, 40%);">+const char *mgcp_client_e1_epname(const struct mgcp_client *mgcp, uint8_t trunk_id, uint8_t ts, uint8_t rate,</span><br><span style="color: hsl(120, 100%, 40%);">+ uint8_t offset);</span><br><span> </span><br><span> /* Invoked when an MGCP response is received or sending failed. When the</span><br><span> * response is passed as NULL, this indicates failure during transmission. */</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 819461d..17983fa 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>@@ -900,6 +900,66 @@</span><br><span> return _mgcp_client_name_append_domain(mgcp, "rtpbridge/*");</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Compose endpoint name for an E1 endpoint.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] mgcp MGCP client descriptor.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] trunk_id id number of the E1 trunk (1-64).</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] ts timeslot on the E1 trunk (1-31).</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] rate bitrate used on the E1 trunk (e.g 16 for 16kbit).</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] offset bit offset of the E1 subslot (e.g. 4 for the third 16k subslot).</span><br><span style="color: hsl(120, 100%, 40%);">+ * \returns string containing the endpoint name (e.g. ds/e1-0/s-1/su16-4). */</span><br><span style="color: hsl(120, 100%, 40%);">+const char *mgcp_client_e1_epname(const struct mgcp_client *mgcp, uint8_t trunk_id, uint8_t ts, uint8_t rate,</span><br><span style="color: hsl(120, 100%, 40%);">+ uint8_t offset)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ /* See also comment in libosmo-mgcp, mgcp_client.c, gen_e1_epname() */</span><br><span style="color: hsl(120, 100%, 40%);">+ static const uint8_t valid_rates[] = { 64, 32, 32, 16, 16, 16, 16, 8, 8, 8, 8, 8, 8, 8, 8 };</span><br><span style="color: hsl(120, 100%, 40%);">+ static const uint8_t valid_offsets[] = { 0, 0, 4, 0, 2, 4, 6, 0, 1, 2, 3, 4, 5, 6, 7 };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ static char endpoint[MGCP_ENDPOINT_MAXLEN];</span><br><span style="color: hsl(120, 100%, 40%);">+ uint8_t i;</span><br><span style="color: hsl(120, 100%, 40%);">+ int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+ bool rate_offs_valid = false;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Check if the supplied rate/offset pair resembles a valid combination */</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < sizeof(valid_rates); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (valid_rates[i] == rate && valid_offsets[i] == offset)</span><br><span style="color: hsl(120, 100%, 40%);">+ rate_offs_valid = true;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!rate_offs_valid) {</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(DLMGCP, LOGL_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">+ "Cannot compose MGCP e1-endpoint name, rate(%u)/offset(%u) combination is invalid!\n", rate,</span><br><span style="color: hsl(120, 100%, 40%);">+ offset);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</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%);">+ /* osmo-mgw only allows a maximum of 64 trunks. The trunk id 0 is</span><br><span style="color: hsl(120, 100%, 40%);">+ * reserved due to historical reasons. */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (trunk_id == 0 || trunk_id > 64) {</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(DLMGCP, LOGL_ERROR, "Cannot compose MGCP e1-endpoint name, trunk number (%u) is invalid!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ trunk_id);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ /* An E1 line has a maximum of 32 timeslots, while the first (ts=0) is</span><br><span style="color: hsl(120, 100%, 40%);">+ * reserverd for signalling, so we can not use it here. */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ts == 0 || ts > 31) {</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(DLMGCP, LOGL_ERROR, "Cannot compose MGCP e1-endpoint name, E1-timeslot number (%u) is invalid!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ ts);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</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%);">+ rc = snprintf(endpoint, sizeof(endpoint), "ds/e1-%u/s-%u/su%u-%u", trunk_id, ts, rate, offset);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc > sizeof(endpoint) - 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(DLMGCP, LOGL_ERROR, "MGCP endpoint exceeds maximum length of %zu: 'ds/e1-%u/s-%u/su%u-%u'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ sizeof(endpoint) - 1, trunk_id, ts, rate, offset);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc < 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(DLMGCP, LOGL_ERROR, "Cannot compose MGCP endpoint name\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</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%);">+ return _mgcp_client_name_append_domain(mgcp, endpoint);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct mgcp_response_pending * mgcp_client_pending_add(</span><br><span> struct mgcp_client *mgcp,</span><br><span> mgcp_trans_id_t trans_id,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-mgw/+/19075">change 19075</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/c/osmo-mgw/+/19075"/><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-Change-Id: Iec35b5bae8a7b07ddb3559f7114a24dcd10e8f14 </div>
<div style="display:none"> Gerrit-Change-Number: 19075 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>