Change in osmo-e1d[master]: e1_line.c: Split multiplex + demultiplex into separate mux_demux.c
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1d/+/21801 ) Change subject: e1_line.c: Split multiplex + demultiplex into separate mux_demux.c .. e1_line.c: Split multiplex + demultiplex into separate mux_demux.c The remaining intf_line.c really only manages the data structures. This is useful for building other programs than osmo-e1d, such as an upcoming E1 test utility called osmo-e1gen which will also use the USB interface and icE1usb hardware, but not any of the mux/demux/ctl code. Change-Id: I1ceaea85a15e2fae1d2e041173be9d758c6d0b78 --- M src/Makefile.am M src/intf_line.c A src/mux_demux.c 3 files changed, 378 insertions(+), 334 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1d refs/changes/01/21801/1 diff --git a/src/Makefile.am b/src/Makefile.am index d9d8236..09cf0e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,6 +35,7 @@ ctl.c \ intf_line.c \ log.c \ + mux_demux.c \ osmo-e1d.c \ usb.c \ vpair.c \ diff --git a/src/intf_line.c b/src/intf_line.c index 2ed9e66..3aebf9c 100644 --- a/src/intf_line.c +++ b/src/intf_line.c @@ -166,338 +166,4 @@ } -// --- -// data transfer -// --- -static int -_e1_rx_hdlcfs(struct e1_ts *ts, const uint8_t *buf, int len) -{ - int rv, cl, oi; - - oi = 0; - - while (oi < len) { - rv = osmo_isdnhdlc_decode(&ts->hdlc.rx, - &buf[oi], len-oi, &cl, - 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->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) { - LOGPTS(ts, DXFR, LOGL_ERROR, "ERR RX: %d %d %d [ %s]\n", - rv,oi,cl, osmo_hexdump(buf, len)); - } - - oi += cl; - } - - return len; -} - -static int -_e1_tx_hdlcfs(struct e1_ts *ts, uint8_t *buf, int len) -{ - int rv, oo, cl; - - oo = 0; - - while (oo < len) { - /* Pending message ? */ - 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->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->hdlc.tx_buf)); - rv = sizeof(ts->hdlc.tx_buf); - } - LOGPTS(ts, DXFR, LOGL_DEBUG, "TX Message: %d [ %s]\n", - 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->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->hdlc.tx_ofs < ts->hdlc.tx_len) { - LOGPTS(ts, DXFR, LOGL_DEBUG, "TX chunk %d/%d %d [ %s]\n", - ts->hdlc.tx_ofs, ts->hdlc.tx_len, cl, osmo_hexdump(&buf[ts->hdlc.tx_ofs], rv)); - } - - if (rv > 0) - oo += rv; - - ts->hdlc.tx_ofs += cl; - if (ts->hdlc.tx_ofs >= ts->hdlc.tx_len) { - ts->hdlc.tx_len = 0; - ts->hdlc.tx_ofs = 0; - } - } - - return len; -} - -/* read from a timeslot-FD (direction application -> hardware) */ -static int -_e1_ts_read(struct e1_ts *ts, uint8_t *buf, size_t len) -{ - int l; - - switch (ts->mode) { - case E1_TS_MODE_RAW: - l = read(ts->fd, buf, len); - /* FIXME: handle underflow */ - break; - case E1_TS_MODE_HDLCFCS: - l = _e1_tx_hdlcfs(ts, buf, len); -
Change in osmo-e1d[master]: e1_line.c: Split multiplex + demultiplex into separate mux_demux.c
tnt has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-e1d/+/21801 ) Change subject: e1_line.c: Split multiplex + demultiplex into separate mux_demux.c .. Patch Set 4: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/osmo-e1d/+/21801 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-e1d Gerrit-Branch: master Gerrit-Change-Id: I1ceaea85a15e2fae1d2e041173be9d758c6d0b78 Gerrit-Change-Number: 21801 Gerrit-PatchSet: 4 Gerrit-Owner: laforge Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: tnt Gerrit-Comment-Date: Sat, 19 Dec 2020 21:16:26 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in osmo-e1d[master]: e1_line.c: Split multiplex + demultiplex into separate mux_demux.c
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-e1d/+/21801 ) Change subject: e1_line.c: Split multiplex + demultiplex into separate mux_demux.c .. Patch Set 4: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/osmo-e1d/+/21801 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-e1d Gerrit-Branch: master Gerrit-Change-Id: I1ceaea85a15e2fae1d2e041173be9d758c6d0b78 Gerrit-Change-Number: 21801 Gerrit-PatchSet: 4 Gerrit-Owner: laforge Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: tnt Gerrit-Comment-Date: Sun, 20 Dec 2020 10:42:56 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in osmo-e1d[master]: e1_line.c: Split multiplex + demultiplex into separate mux_demux.c
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-e1d/+/21801 ) Change subject: e1_line.c: Split multiplex + demultiplex into separate mux_demux.c .. e1_line.c: Split multiplex + demultiplex into separate mux_demux.c The remaining intf_line.c really only manages the data structures. This is useful for building other programs than osmo-e1d, such as an upcoming E1 test utility called osmo-e1gen which will also use the USB interface and icE1usb hardware, but not any of the mux/demux/ctl code. Change-Id: I1ceaea85a15e2fae1d2e041173be9d758c6d0b78 --- M src/Makefile.am M src/intf_line.c A src/mux_demux.c 3 files changed, 378 insertions(+), 334 deletions(-) Approvals: Jenkins Builder: Verified tnt: Looks good to me, but someone else must approve laforge: Looks good to me, approved diff --git a/src/Makefile.am b/src/Makefile.am index d9d8236..09cf0e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,6 +35,7 @@ ctl.c \ intf_line.c \ log.c \ + mux_demux.c \ osmo-e1d.c \ usb.c \ vpair.c \ diff --git a/src/intf_line.c b/src/intf_line.c index 2ed9e66..3aebf9c 100644 --- a/src/intf_line.c +++ b/src/intf_line.c @@ -166,338 +166,4 @@ } -// --- -// data transfer -// --- -static int -_e1_rx_hdlcfs(struct e1_ts *ts, const uint8_t *buf, int len) -{ - int rv, cl, oi; - - oi = 0; - - while (oi < len) { - rv = osmo_isdnhdlc_decode(&ts->hdlc.rx, - &buf[oi], len-oi, &cl, - 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->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) { - LOGPTS(ts, DXFR, LOGL_ERROR, "ERR RX: %d %d %d [ %s]\n", - rv,oi,cl, osmo_hexdump(buf, len)); - } - - oi += cl; - } - - return len; -} - -static int -_e1_tx_hdlcfs(struct e1_ts *ts, uint8_t *buf, int len) -{ - int rv, oo, cl; - - oo = 0; - - while (oo < len) { - /* Pending message ? */ - 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->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->hdlc.tx_buf)); - rv = sizeof(ts->hdlc.tx_buf); - } - LOGPTS(ts, DXFR, LOGL_DEBUG, "TX Message: %d [ %s]\n", - 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->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->hdlc.tx_ofs < ts->hdlc.tx_len) { - LOGPTS(ts, DXFR, LOGL_DEBUG, "TX chunk %d/%d %d [ %s]\n", - ts->hdlc.tx_ofs, ts->hdlc.tx_len, cl, osmo_hexdump(&buf[ts->hdlc.tx_ofs], rv)); - } - - if (rv > 0) - oo += rv; - - ts->hdlc.tx_ofs += cl; - if (ts->hdlc.tx_ofs >= ts->hdlc.tx_len) { - ts->hdlc.tx_len = 0; - ts->hdlc.tx_ofs = 0; - } - } - - return len; -} - -/* read from a timeslot-FD (direction application -> hardware) */ -static int -_e1_ts_read(struct e1_ts *ts, uint8_t *buf, size_t len) -{ - int l; - - switch (ts->mode) { - case E1_TS_MODE_RAW: - l = read(ts->fd, buf, len); - /* FIXME: handle underflow */ - break; - case E1_TS_MODE_HDLCFCS: -