<p>laforge has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-e1d/+/19344">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">cosmetic: create HDLC specific sub-structure within e1_ts<br><br>This groups all HDLC-specific members together, in preparation<br>of adding more fields for other modes.<br><br>Change-Id: Ide0577c25836252862153b4f24da550bee013687<br>---<br>M src/ctl.c<br>M src/e1d.h<br>M src/intf_line.c<br>3 files changed, 30 insertions(+), 28 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-e1d refs/changes/44/19344/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/ctl.c b/src/ctl.c</span><br><span>index 4e74485..697af01 100644</span><br><span>--- a/src/ctl.c</span><br><span>+++ b/src/ctl.c</span><br><span>@@ -150,8 +150,8 @@</span><br><span> ts->mode = mode;</span><br><span> </span><br><span> if (mode == E1_TS_MODE_HDLCFCS) {</span><br><span style="color: hsl(0, 100%, 40%);">- osmo_isdnhdlc_out_init(&ts->hdlc_tx, OSMO_HDLC_F_BITREVERSE);</span><br><span style="color: hsl(0, 100%, 40%);">- osmo_isdnhdlc_rcv_init(&ts->hdlc_rx, OSMO_HDLC_F_BITREVERSE);</span><br><span style="color: hsl(120, 100%, 40%);">+ osmo_isdnhdlc_out_init(&ts->hdlc.tx, OSMO_HDLC_F_BITREVERSE);</span><br><span style="color: hsl(120, 100%, 40%);">+ osmo_isdnhdlc_rcv_init(&ts->hdlc.rx, OSMO_HDLC_F_BITREVERSE);</span><br><span> }</span><br><span> </span><br><span> int flags = fcntl(ts->fd, F_GETFL);</span><br><span>diff --git a/src/e1d.h b/src/e1d.h</span><br><span>index fca7d3e..98c3ddc 100644</span><br><span>--- a/src/e1d.h</span><br><span>+++ b/src/e1d.h</span><br><span>@@ -43,13 +43,15 @@</span><br><span> enum e1_ts_mode mode;</span><br><span> </span><br><span> /* HDLC handling */</span><br><span style="color: hsl(0, 100%, 40%);">- struct osmo_isdnhdlc_vars hdlc_tx;</span><br><span style="color: hsl(0, 100%, 40%);">- struct osmo_isdnhdlc_vars hdlc_rx;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct osmo_isdnhdlc_vars tx;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct osmo_isdnhdlc_vars rx;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- uint8_t rx_buf[264];</span><br><span style="color: hsl(0, 100%, 40%);">- uint8_t tx_buf[264];</span><br><span style="color: hsl(0, 100%, 40%);">- int tx_ofs;</span><br><span style="color: hsl(0, 100%, 40%);">- int tx_len;</span><br><span style="color: hsl(120, 100%, 40%);">+ uint8_t rx_buf[264];</span><br><span style="color: hsl(120, 100%, 40%);">+ uint8_t tx_buf[264];</span><br><span style="color: hsl(120, 100%, 40%);">+ int tx_ofs;</span><br><span style="color: hsl(120, 100%, 40%);">+ int tx_len;</span><br><span style="color: hsl(120, 100%, 40%);">+ } hdlc;</span><br><span> </span><br><span> /* Remote end */</span><br><span> int fd;</span><br><span>diff --git a/src/intf_line.c b/src/intf_line.c</span><br><span>index af0d45d..6213151 100644</span><br><span>--- a/src/intf_line.c</span><br><span>+++ b/src/intf_line.c</span><br><span>@@ -157,16 +157,16 @@</span><br><span> oi = 0;</span><br><span> </span><br><span> while (oi < len) {</span><br><span style="color: hsl(0, 100%, 40%);">- rv = osmo_isdnhdlc_decode(&ts->hdlc_rx,</span><br><span style="color: hsl(120, 100%, 40%);">+ rv = osmo_isdnhdlc_decode(&ts->hdlc.rx,</span><br><span> &buf[oi], len-oi, &cl,</span><br><span style="color: hsl(0, 100%, 40%);">- ts->rx_buf, sizeof(ts->rx_buf)</span><br><span style="color: hsl(120, 100%, 40%);">+ ts->hdlc.rx_buf, sizeof(ts->hdlc.rx_buf)</span><br><span> );</span><br><span> </span><br><span> if (rv > 0) {</span><br><span> int bytes_to_write = rv;</span><br><span> LOGPTS(ts, DXFR, LOGL_DEBUG, "RX Message: %d [ %s]\n",</span><br><span style="color: hsl(0, 100%, 40%);">- rv, osmo_hexdump(ts->rx_buf, rv));</span><br><span style="color: hsl(0, 100%, 40%);">- rv = write(ts->fd, ts->rx_buf, bytes_to_write);</span><br><span style="color: hsl(120, 100%, 40%);">+ rv, osmo_hexdump(ts->hdlc.rx_buf, rv));</span><br><span style="color: hsl(120, 100%, 40%);">+ rv = write(ts->fd, ts->hdlc.rx_buf, bytes_to_write);</span><br><span> if (rv < 0)</span><br><span> return rv;</span><br><span> } else if (rv < 0 && ts->id == 4) {</span><br><span>@@ -189,44 +189,44 @@</span><br><span> </span><br><span> while (oo < len) {</span><br><span> /* Pending message ? */</span><br><span style="color: hsl(0, 100%, 40%);">- if (!ts->tx_len) {</span><br><span style="color: hsl(0, 100%, 40%);">- rv = recv(ts->fd, ts->tx_buf, sizeof(ts->tx_buf), MSG_TRUNC);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ts->hdlc.tx_len) {</span><br><span style="color: hsl(120, 100%, 40%);">+ rv = recv(ts->fd, ts->hdlc.tx_buf, sizeof(ts->hdlc.tx_buf), MSG_TRUNC);</span><br><span> if (rv > 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (rv > sizeof(ts->tx_buf)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rv > sizeof(ts->hdlc.tx_buf)) {</span><br><span> LOGPTS(ts, DXFR, LOGL_ERROR, "Truncated message: Client tried to "</span><br><span> "send %d bytes but our buffer is limited to %lu\n",</span><br><span style="color: hsl(0, 100%, 40%);">- rv, sizeof(ts->tx_buf));</span><br><span style="color: hsl(0, 100%, 40%);">- rv = sizeof(ts->tx_buf);</span><br><span style="color: hsl(120, 100%, 40%);">+ rv, sizeof(ts->hdlc.tx_buf));</span><br><span style="color: hsl(120, 100%, 40%);">+ rv = sizeof(ts->hdlc.tx_buf);</span><br><span> }</span><br><span> LOGPTS(ts, DXFR, LOGL_DEBUG, "TX Message: %d [ %s]\n",</span><br><span style="color: hsl(0, 100%, 40%);">- rv, osmo_hexdump(ts->tx_buf, rv));</span><br><span style="color: hsl(0, 100%, 40%);">- ts->tx_len = rv; </span><br><span style="color: hsl(0, 100%, 40%);">- ts->tx_ofs = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ rv, osmo_hexdump(ts->hdlc.tx_buf, rv));</span><br><span style="color: hsl(120, 100%, 40%);">+ ts->hdlc.tx_len = rv; </span><br><span style="color: hsl(120, 100%, 40%);">+ ts->hdlc.tx_ofs = 0;</span><br><span> } else if (rv < 0 && errno != EAGAIN)</span><br><span> return rv;</span><br><span> }</span><br><span> </span><br><span> /* */</span><br><span style="color: hsl(0, 100%, 40%);">- rv = osmo_isdnhdlc_encode(&ts->hdlc_tx,</span><br><span style="color: hsl(0, 100%, 40%);">- &ts->tx_buf[ts->tx_ofs], ts->tx_len - ts->tx_ofs, &cl,</span><br><span style="color: hsl(120, 100%, 40%);">+ rv = osmo_isdnhdlc_encode(&ts->hdlc.tx,</span><br><span style="color: hsl(120, 100%, 40%);">+ &ts->hdlc.tx_buf[ts->hdlc.tx_ofs], ts->hdlc.tx_len - ts->hdlc.tx_ofs, &cl,</span><br><span> &buf[oo], len - oo</span><br><span> );</span><br><span> </span><br><span> if (rv < 0)</span><br><span> LOGPTS(ts, DXFR, LOGL_ERROR, "ERR TX: %d\n", rv);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (ts->tx_ofs < ts->tx_len) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ts->hdlc.tx_ofs < ts->hdlc.tx_len) {</span><br><span> LOGPTS(ts, DXFR, LOGL_DEBUG, "TX chunk %d/%d %d [ %s]\n",</span><br><span style="color: hsl(0, 100%, 40%);">- ts->tx_ofs, ts->tx_len, cl, osmo_hexdump(&buf[ts->tx_ofs], rv));</span><br><span style="color: hsl(120, 100%, 40%);">+ ts->hdlc.tx_ofs, ts->hdlc.tx_len, cl, osmo_hexdump(&buf[ts->hdlc.tx_ofs], rv));</span><br><span> }</span><br><span> </span><br><span> if (rv > 0)</span><br><span> oo += rv;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ts->tx_ofs += cl;</span><br><span style="color: hsl(0, 100%, 40%);">- if (ts->tx_ofs >= ts->tx_len) {</span><br><span style="color: hsl(0, 100%, 40%);">- ts->tx_len = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- ts->tx_ofs = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ ts->hdlc.tx_ofs += cl;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ts->hdlc.tx_ofs >= ts->hdlc.tx_len) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ts->hdlc.tx_len = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ ts->hdlc.tx_ofs = 0;</span><br><span> }</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-e1d/+/19344">change 19344</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-e1d/+/19344"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: osmo-e1d </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ide0577c25836252862153b4f24da550bee013687 </div>
<div style="display:none"> Gerrit-Change-Number: 19344 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>