This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1d/+/19046 )
Change subject: factor-out core E1 mux/demux functions to intf_line.c
......................................................................
factor-out core E1 mux/demux functions to intf_line.c
This way we can de-couple the E1 mux/demux from the specific USB
interface code that the current hardware uses.
Change-Id: I9ab11617e70697b84c85f7793f118fb8c915997b
---
M src/e1d.h
M src/intf_line.c
M src/usb.c
3 files changed, 99 insertions(+), 70 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-e1d refs/changes/46/19046/1
diff --git a/src/e1d.h b/src/e1d.h
index 0cc1993..39df28e 100644
--- a/src/e1d.h
+++ b/src/e1d.h
@@ -109,6 +109,12 @@
int
_e1_tx_hdlcfs(struct e1_ts *ts, uint8_t *buf, int len);
+int
+_e1_mux_out(struct e1_line *line, uint8_t *buf, int fts);
+
+int
+_e1_demux_in(struct e1_line *line, const uint8_t *buf, int size);
+
void e1d_vty_init(struct e1_daemon *e1d);
void
diff --git a/src/intf_line.c b/src/intf_line.c
index 0dfa3fc..33edf05 100644
--- a/src/intf_line.c
+++ b/src/intf_line.c
@@ -201,3 +201,92 @@
return len;
}
+
+/*! generate (multiplex) output data for the specified e1_line
+ * \param[in] line E1 line for which to genrate output data
+ * \param[in] buf caller-allocated output buffer for multiplexed data
+ * \param[in] fts number of E1 frames (32 bytes each) to generate
+ * \return number of bytes written to buf */
+int
+_e1_mux_out(struct e1_line *line, uint8_t *buf, int fts)
+{
+ int tsz;
+
+ /* Prepare */
+ tsz = 32 * fts;
+ memset(buf, 0xff, tsz);
+
+ /* Scan timeslots */
+ for (int tsn=1; tsn<32; tsn++)
+ {
+ struct e1_ts *ts = &line->ts[tsn];
+ uint8_t buf_ts[fts];
+ int l;
+
+ if (ts->mode == E1_TS_MODE_OFF)
+ continue;
+
+ switch (ts->mode) {
+ case E1_TS_MODE_RAW:
+ l = read(ts->fd, buf_ts, fts);
+ break;
+ case E1_TS_MODE_HDLCFCS:
+ l = _e1_tx_hdlcfs(ts, buf_ts, fts);
+ break;
+ default:
+ continue;
+ }
+
+ if (l <= 0)
+ continue;
+
+ for (int i=0; i<l; i++)
+ buf[tsn+(i*32)] = buf_ts[i];
+ }
+
+ return tsz;
+}
+
+/*! de-multiplex E1 line data to the individual timeslots.
+ * \param[in] line E1 line on which we operate.
+ * \param[in] buf buffer containing multiplexed frame-aligned E1 data.
+ * \param[in] size size of 'buf' in octets; assumed to be multiple of E1 frame size (32).
+ * \returns 0 on success; negative on error */
+int
+_e1_demux_in(struct e1_line *line, const uint8_t *buf, int size)
+{
+ int ftr;
+
+ if (size <= 0) {
+ LOGP(DXFR, LOGL_ERROR, "IN ERROR: %d\n", size);
+ return -1;
+ }
+
+ ftr = size / 32;
+ OSMO_ASSERT(size % 32 == 0);
+
+ for (int tsn=1; tsn<32; tsn++)
+ {
+ struct e1_ts *ts = &line->ts[tsn];
+ uint8_t buf_ts[ftr];
+
+ if (ts->mode == E1_TS_MODE_OFF)
+ continue;
+
+ for (int i=0; i<ftr; i++)
+ buf_ts[i] = buf[tsn+(i*32)];
+
+ switch (ts->mode) {
+ case E1_TS_MODE_RAW:
+ write(ts->fd, buf_ts, ftr);
+ break;
+ case E1_TS_MODE_HDLCFCS:
+ _e1_rx_hdlcfs(ts, buf_ts, ftr);
+ break;
+ default:
+ continue;
+ }
+ }
+
+ return 0;
+}
diff --git a/src/usb.c b/src/usb.c
index 8938a78..59bcac8 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -107,40 +107,7 @@
static int
e1_usb_xfer_in(struct e1_usb_flow *flow, uint8_t *buf, int size)
{
- struct e1_line *line = flow->line;
- int ftr;
-
- if (size <= 0) {
- LOGP(DXFR, LOGL_ERROR, "IN ERROR: %d\n", size);
- return -1;
- }
-
- ftr = (size - 4) / 32;
-
- for (int tsn=1; tsn<32; tsn++)
- {
- struct e1_ts *ts = &line->ts[tsn];
- uint8_t buf_ts[32];
-
- if (ts->mode == E1_TS_MODE_OFF)
- continue;
-
- for (int i=0; i<ftr; i++)
- buf_ts[i] = buf[4+tsn+(i*32)];
-
- switch (ts->mode) {
- case E1_TS_MODE_RAW:
- write(ts->fd, buf_ts, ftr);
- break;
- case E1_TS_MODE_HDLCFCS:
- _e1_rx_hdlcfs(ts, buf_ts, ftr);
- break;
- default:
- continue;
- }
- }
-
- return 0;
+ return _e1_demux_in(flow->line, buf, size - 4);
}
static int
@@ -148,7 +115,7 @@
{
struct e1_line *line = flow->line;
struct e1_usb_line_data *ld = (struct e1_usb_line_data *) line->drv_data;
- int fts, tsz;
+ int fts;
if (size <= 0) {
LOGP(DXFR, LOGL_ERROR, "OUT ERROR: %d\n", size);
@@ -166,42 +133,9 @@
if (ld->r_acc & 0x80000000)
ld->r_acc = 0;
- /* Prepare */
- tsz = 4 + 32 * fts;
- memset(buf, 0xff, tsz);
+ memset(buf, 0xff, 4);
- /* Header */
- /* FIXME */
-
- /* Scan timeslots */
- for (int tsn=1; tsn<32; tsn++)
- {
- struct e1_ts *ts = &line->ts[tsn];
- uint8_t buf_ts[32];
- int l;
-
- if (ts->mode == E1_TS_MODE_OFF)
- continue;
-
- switch (ts->mode) {
- case E1_TS_MODE_RAW:
- l = read(ts->fd, buf_ts, fts);
- break;
- case E1_TS_MODE_HDLCFCS:
- l = _e1_tx_hdlcfs(ts, buf_ts, fts);
- break;
- default:
- continue;
- }
-
- if (l <= 0)
- continue;
-
- for (int i=0; i<l; i++)
- buf[4+tsn+(i*32)] = buf_ts[i];
- }
-
- return tsz;
+ return _e1_mux_out(line, buf+4, fts);
}
static int
--
To view, visit https://gerrit.osmocom.org/c/osmo-e1d/+/19046
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-e1d
Gerrit-Branch: master
Gerrit-Change-Id: I9ab11617e70697b84c85f7793f118fb8c915997b
Gerrit-Change-Number: 19046
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200629/149e7917/attachment.htm>