diff options
author | Harald Welte <laforge@osmocom.org> | 2020-07-20 18:32:17 +0200 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2020-07-20 22:37:10 +0200 |
commit | 77683c810dfd0dddca7845c61b40041cd8d599eb (patch) | |
tree | fe109ad4d687f3cd0b2658592d53885e1d8dd451 | |
parent | 5d5e47ff3b05f32a3d30d201c6bc7dc57fc9307f (diff) |
cosmetic: create HDLC specific sub-structure within e1_ts
This groups all HDLC-specific members together, in preparation
of adding more fields for other modes.
Change-Id: Ide0577c25836252862153b4f24da550bee013687
-rw-r--r-- | src/ctl.c | 4 | ||||
-rw-r--r-- | src/e1d.h | 16 | ||||
-rw-r--r-- | src/intf_line.c | 40 |
3 files changed, 31 insertions, 29 deletions
@@ -150,8 +150,8 @@ _e1d_ts_start(struct e1_ts *ts, enum e1_ts_mode mode) ts->mode = mode; if (mode == E1_TS_MODE_HDLCFCS) { - osmo_isdnhdlc_out_init(&ts->hdlc_tx, OSMO_HDLC_F_BITREVERSE); - osmo_isdnhdlc_rcv_init(&ts->hdlc_rx, OSMO_HDLC_F_BITREVERSE); + osmo_isdnhdlc_out_init(&ts->hdlc.tx, OSMO_HDLC_F_BITREVERSE); + osmo_isdnhdlc_rcv_init(&ts->hdlc.rx, OSMO_HDLC_F_BITREVERSE); } int flags = fcntl(ts->fd, F_GETFL); @@ -43,13 +43,15 @@ struct e1_ts { enum e1_ts_mode mode; /* HDLC handling */ - struct osmo_isdnhdlc_vars hdlc_tx; - struct osmo_isdnhdlc_vars hdlc_rx; - - uint8_t rx_buf[264]; - uint8_t tx_buf[264]; - int tx_ofs; - int tx_len; + struct { + struct osmo_isdnhdlc_vars tx; + struct osmo_isdnhdlc_vars rx; + + uint8_t rx_buf[264]; + uint8_t tx_buf[264]; + int tx_ofs; + int tx_len; + } hdlc; /* Remote end */ int fd; diff --git a/src/intf_line.c b/src/intf_line.c index af0d45d..6213151 100644 --- a/src/intf_line.c +++ b/src/intf_line.c @@ -157,16 +157,16 @@ _e1_rx_hdlcfs(struct e1_ts *ts, const uint8_t *buf, int len) oi = 0; while (oi < len) { - rv = osmo_isdnhdlc_decode(&ts->hdlc_rx, + rv = osmo_isdnhdlc_decode(&ts->hdlc.rx, &buf[oi], len-oi, &cl, - ts->rx_buf, sizeof(ts->rx_buf) + ts->hdlc.rx_buf, sizeof(ts->hdlc.rx_buf) ); if (rv > 0) { int bytes_to_write = rv; LOGPTS(ts, DXFR, LOGL_DEBUG, "RX Message: %d [ %s]\n", - rv, osmo_hexdump(ts->rx_buf, rv)); - rv = write(ts->fd, ts->rx_buf, bytes_to_write); + rv, osmo_hexdump(ts->hdlc.rx_buf, rv)); + rv = write(ts->fd, ts->hdlc.rx_buf, bytes_to_write); if (rv < 0) return rv; } else if (rv < 0 && ts->id == 4) { @@ -189,44 +189,44 @@ _e1_tx_hdlcfs(struct e1_ts *ts, uint8_t *buf, int len) while (oo < len) { /* Pending message ? */ - if (!ts->tx_len) { - rv = recv(ts->fd, ts->tx_buf, sizeof(ts->tx_buf), MSG_TRUNC); + if (!ts->hdlc.tx_len) { + rv = recv(ts->fd, ts->hdlc.tx_buf, sizeof(ts->hdlc.tx_buf), MSG_TRUNC); if (rv > 0) { - if (rv > sizeof(ts->tx_buf)) { + if (rv > sizeof(ts->hdlc.tx_buf)) { LOGPTS(ts, DXFR, LOGL_ERROR, "Truncated message: Client tried to " "send %d bytes but our buffer is limited to %lu\n", - rv, sizeof(ts->tx_buf)); - rv = sizeof(ts->tx_buf); + rv, sizeof(ts->hdlc.tx_buf)); + rv = sizeof(ts->hdlc.tx_buf); } LOGPTS(ts, DXFR, LOGL_DEBUG, "TX Message: %d [ %s]\n", - rv, osmo_hexdump(ts->tx_buf, rv)); - ts->tx_len = rv; - ts->tx_ofs = 0; + rv, osmo_hexdump(ts->hdlc.tx_buf, rv)); + ts->hdlc.tx_len = rv; + ts->hdlc.tx_ofs = 0; } else if (rv < 0 && errno != EAGAIN) return rv; } /* */ - rv = osmo_isdnhdlc_encode(&ts->hdlc_tx, - &ts->tx_buf[ts->tx_ofs], ts->tx_len - ts->tx_ofs, &cl, + rv = osmo_isdnhdlc_encode(&ts->hdlc.tx, + &ts->hdlc.tx_buf[ts->hdlc.tx_ofs], ts->hdlc.tx_len - ts->hdlc.tx_ofs, &cl, &buf[oo], len - oo ); if (rv < 0) LOGPTS(ts, DXFR, LOGL_ERROR, "ERR TX: %d\n", rv); - if (ts->tx_ofs < ts->tx_len) { + if (ts->hdlc.tx_ofs < ts->hdlc.tx_len) { LOGPTS(ts, DXFR, LOGL_DEBUG, "TX chunk %d/%d %d [ %s]\n", - ts->tx_ofs, ts->tx_len, cl, osmo_hexdump(&buf[ts->tx_ofs], rv)); + ts->hdlc.tx_ofs, ts->hdlc.tx_len, cl, osmo_hexdump(&buf[ts->hdlc.tx_ofs], rv)); } if (rv > 0) oo += rv; - ts->tx_ofs += cl; - if (ts->tx_ofs >= ts->tx_len) { - ts->tx_len = 0; - ts->tx_ofs = 0; + ts->hdlc.tx_ofs += cl; + if (ts->hdlc.tx_ofs >= ts->hdlc.tx_len) { + ts->hdlc.tx_len = 0; + ts->hdlc.tx_ofs = 0; } } |