laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-abis/+/31502 )
(
2 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: e1d: Add support for HDLC type channels ......................................................................
e1d: Add support for HDLC type channels
Change-Id: I2f4b9f7ed6430804ca511c7f5283a16bc13bc2fc --- M src/input/e1d.c 1 file changed, 71 insertions(+), 0 deletions(-)
Approvals: laforge: Looks good to me, approved pespin: Looks good to me, but someone else must approve Jenkins Builder: Verified
diff --git a/src/input/e1d.c b/src/input/e1d.c index db4988f..6392b4f 100644 --- a/src/input/e1d.c +++ b/src/input/e1d.c @@ -250,6 +250,62 @@ return ret; }
+/* write to a hdlc channel TS */ +static int handle_ts_hdlc_write(struct osmo_fd *bfd) +{ + struct e1inp_line *line = bfd->data; + unsigned int ts_nr = bfd->priv_nr; + struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; + struct msgb *msg; + int ret; + + /* get the next msg for this timeslot */ + msg = e1inp_tx_ts(e1i_ts, NULL); + if (!msg) { + osmo_fd_write_disable(bfd); + return 0; + } + + LOGPITS(e1i_ts, DLMIB, LOGL_DEBUG, "HDLC CHAN TX: %s\n", osmo_hexdump(msg->data, msg->len)); + + ret = write(bfd->fd, msg->data, msg->len); + if (ret < msg->len) + LOGPITS(e1i_ts, DLINP, LOGL_NOTICE, "send returns %d instead of %d\n", ret, msg->len); + msgb_free(msg); + + return ret; +} + +#define TSX_ALLOC_SIZE 4096 + +/* read from a hdlc channel TS */ +static int handle_ts_hdlc_read(struct osmo_fd *bfd) +{ + struct e1inp_line *line = bfd->data; + unsigned int ts_nr = bfd->priv_nr; + struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; + struct msgb *msg = msgb_alloc(TSX_ALLOC_SIZE, "E1D HDLC TS"); + int ret; + + if (!msg) + return -ENOMEM; + + ret = read(bfd->fd, msg->data, TSX_ALLOC_SIZE); + if (ret < 0) { + LOGPITS(e1i_ts, DLINP, LOGL_NOTICE, "read error %d %s\n", ret, strerror(errno)); + msgb_free(msg); + return ret; + } + + msgb_put(msg, ret); + + msg->l2h = msg->data; + LOGPITS(e1i_ts, DLMIB, LOGL_DEBUG, "HDLC CHAN RX: %s\n", msgb_hexdump_l2(msg)); + ret = e1inp_rx_ts(e1i_ts, msg, 0, 0); + + return ret; +} + static void e1d_write_msg(struct msgb *msg, void *cbdata) { @@ -294,6 +350,12 @@ if (what & OSMO_FD_WRITE) ret = handle_ts_raw_write(bfd); break; + case E1INP_TS_TYPE_HDLC: + if (what & OSMO_FD_READ) + ret = handle_ts_hdlc_read(bfd); + if (what & OSMO_FD_WRITE) + ret = handle_ts_hdlc_write(bfd); + break; default: LOGPITS(e1i_ts, DLINP, LOGL_NOTICE, "unknown/unsupported E1 TS type %u\n", e1i_ts->type); break;