Change in osmo-e1d[master]: remove code not specific to USB from usb.c to intf_line.c

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.org
Sun Jun 28 16:29:46 UTC 2020


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1d/+/19033 )


Change subject: remove code not specific to USB from usb.c to intf_line.c
......................................................................

remove code not specific to USB from usb.c to intf_line.c

Change-Id: I7d4d4ab39cb3e7e6a7eb8e738a367122eb3fbee2
---
M src/Makefile.am
M src/e1d.h
A src/intf_line.c
M src/usb.c
4 files changed, 176 insertions(+), 125 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-e1d refs/changes/33/19033/1

diff --git a/src/Makefile.am b/src/Makefile.am
index 2890554..bc05998 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -30,6 +30,7 @@
 
 osmo_e1d_SOURCES = \
 	ctl.c \
+	intf_line.c \
 	log.c \
 	osmo-e1d.c \
 	usb.c \
diff --git a/src/e1d.h b/src/e1d.h
index 330168b..fe3f733 100644
--- a/src/e1d.h
+++ b/src/e1d.h
@@ -80,3 +80,15 @@
 	void *ctx;
 	struct llist_head interfaces;
 };
+
+struct e1_intf *
+_e1_intf_new(struct e1_daemon *e1d, void *drv_data);
+
+struct e1_line *
+_e1_line_new(struct e1_intf *intf, void *drv_data);
+
+int
+_e1_rx_hdlcfs(struct e1_ts *ts, uint8_t *buf, int len);
+
+int
+_e1_tx_hdlcfs(struct e1_ts *ts, uint8_t *buf, int len);
diff --git a/src/intf_line.c b/src/intf_line.c
new file mode 100644
index 0000000..87cc22a
--- /dev/null
+++ b/src/intf_line.c
@@ -0,0 +1,163 @@
+/*
+ * intf_line.c
+ *
+ * (C) 2019 by Sylvain Munaut <tnt at 246tNt.com>
+ *
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <errno.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <string.h>
+#include <talloc.h>
+
+#include <osmocom/core/isdnhdlc.h>
+#include <osmocom/core/utils.h>
+
+#include "e1d.h"
+#include "log.h"
+
+
+// ---------------------------------------------------------------------------
+// e1d structures
+// ---------------------------------------------------------------------------
+
+struct e1_intf *
+_e1_intf_new(struct e1_daemon *e1d, void *drv_data)
+{
+	struct e1_intf *intf;
+
+	intf = talloc_zero(e1d->ctx, struct e1_intf);
+	OSMO_ASSERT(intf);
+
+	intf->e1d = e1d;
+	intf->drv_data = drv_data;
+
+	INIT_LLIST_HEAD(&intf->list);
+	INIT_LLIST_HEAD(&intf->lines);
+
+	if (!llist_empty(&e1d->interfaces)) {
+		struct e1_intf *f = llist_first_entry(&e1d->interfaces, struct e1_intf, list);
+		intf->id = f->id + 1;
+	}
+
+	llist_add(&intf->list, &e1d->interfaces);
+
+	return intf;
+}
+
+struct e1_line *
+_e1_line_new(struct e1_intf *intf, void *drv_data)
+{
+	struct e1_line *line;
+
+	line = talloc_zero(intf->e1d->ctx, struct e1_line);
+	OSMO_ASSERT(line);
+
+	line->intf = intf;
+	line->drv_data = drv_data;
+
+	for (int i=0; i<32; i++)
+		line->ts[i].id = i;
+
+	INIT_LLIST_HEAD(&line->list);
+
+	if (!llist_empty(&intf->lines)) {
+		struct e1_line *l = llist_first_entry(&intf->lines, struct e1_line, list);
+		line->id = l->id + 1;
+	}
+
+	llist_add(&line->list, &intf->lines);
+
+	return line;
+}
+
+// ---------------------------------------------------------------------------
+// data transfer
+// ---------------------------------------------------------------------------
+
+int
+_e1_rx_hdlcfs(struct e1_ts *ts, 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->rx_buf, sizeof(ts->rx_buf)
+		);
+
+		if (rv > 0) {
+			printf("RX Message: %d %d [ %s]\n", ts->id, rv, osmo_hexdump(ts->rx_buf, rv));
+			write(ts->fd, ts->rx_buf, rv);
+		} else  if (rv < 0 && ts->id == 4) {
+			printf("ERR RX: %d %d %d [ %s]\n",rv,oi,cl, osmo_hexdump(buf, len));
+		}
+
+		oi += cl;
+	}
+
+	return 0;
+}
+
+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->tx_len) {
+			rv = read(ts->fd, ts->tx_buf, sizeof(ts->tx_buf));
+			if (rv > 0) {
+				printf("TX Message: %d %d [ %s]\n", ts->id, rv, osmo_hexdump(ts->tx_buf, rv));
+				ts->tx_len = rv; 
+				ts->tx_ofs = 0;
+			}
+		}
+
+		/* */
+		rv = osmo_isdnhdlc_encode(&ts->hdlc_tx,
+			&ts->tx_buf[ts->tx_ofs], ts->tx_len - ts->tx_ofs, &cl,
+			&buf[oo], len - oo
+		);
+
+		if (rv < 0)
+			printf("ERR TX: %d\n", rv);
+
+		if (ts->tx_ofs < ts->tx_len)
+			printf("TX chunk %d/%d %d [ %s]\n", ts->tx_ofs, ts->tx_len, cl, osmo_hexdump(&buf[ts->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;
+		}
+	}
+
+	return len;
+}
diff --git a/src/usb.c b/src/usb.c
index 19855f8..c7b8f13 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -105,75 +105,6 @@
 // ---------------------------------------------------------------------------
 
 static int
-_e1_rx_hdlcfs(struct e1_ts *ts, 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->rx_buf, sizeof(ts->rx_buf)
-		);
-
-		if (rv > 0) {
-			printf("RX Message: %d %d [ %s]\n", ts->id, rv, osmo_hexdump(ts->rx_buf, rv));
-			write(ts->fd, ts->rx_buf, rv);
-		} else  if (rv < 0 && ts->id == 4) {
-			printf("ERR RX: %d %d %d [ %s]\n",rv,oi,cl, osmo_hexdump(buf, len));
-		}
-
-		oi += cl;
-	}
-
-	return 0;
-}
-
-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->tx_len) {
-			rv = read(ts->fd, ts->tx_buf, sizeof(ts->tx_buf));
-			if (rv > 0) {
-				printf("TX Message: %d %d [ %s]\n", ts->id, rv, osmo_hexdump(ts->tx_buf, rv));
-				ts->tx_len = rv; 
-				ts->tx_ofs = 0;
-			}
-		}
-
-		/* */
-		rv = osmo_isdnhdlc_encode(&ts->hdlc_tx,
-			&ts->tx_buf[ts->tx_ofs], ts->tx_len - ts->tx_ofs, &cl,
-			&buf[oo], len - oo
-		);
-
-		if (rv < 0)
-			printf("ERR TX: %d\n", rv);
-
-		if (ts->tx_ofs < ts->tx_len)
-			printf("TX chunk %d/%d %d [ %s]\n", ts->tx_ofs, ts->tx_len, cl, osmo_hexdump(&buf[ts->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;
-		}
-	}
-
-	return len;
-}
-
-static int
 e1_usb_xfer_in(struct e1_usb_flow *flow, uint8_t *buf, int size)
 {
 	struct e1_line *line = flow->line;
@@ -410,62 +341,6 @@
 
 
 // ---------------------------------------------------------------------------
-// e1d structures
-// ---------------------------------------------------------------------------
-
-struct e1_intf *
-_e1_intf_new(struct e1_daemon *e1d, void *drv_data)
-{
-	struct e1_intf *intf;
-
-	intf = talloc_zero(e1d->ctx, struct e1_intf);
-	OSMO_ASSERT(intf);
-
-	intf->e1d = e1d;
-	intf->drv_data = drv_data;
-
-	INIT_LLIST_HEAD(&intf->list);
-	INIT_LLIST_HEAD(&intf->lines);
-
-	if (!llist_empty(&e1d->interfaces)) {
-		struct e1_intf *f = llist_first_entry(&e1d->interfaces, struct e1_intf, list);
-		intf->id = f->id + 1;
-	}
-
-	llist_add(&intf->list, &e1d->interfaces);
-
-	return intf;
-}
-
-struct e1_line *
-_e1_line_new(struct e1_intf *intf, void *drv_data)
-{
-	struct e1_line *line;
-
-	line = talloc_zero(intf->e1d->ctx, struct e1_line);
-	OSMO_ASSERT(line);
-
-	line->intf = intf;
-	line->drv_data = drv_data;
-
-	for (int i=0; i<32; i++)
-		line->ts[i].id = i;
-
-	INIT_LLIST_HEAD(&line->list);
-
-	if (!llist_empty(&intf->lines)) {
-		struct e1_line *l = llist_first_entry(&intf->lines, struct e1_line, list);
-		line->id = l->id + 1;
-	}
-
-	llist_add(&line->list, &intf->lines);
-
-	return line;
-}
-
-
-
-// ---------------------------------------------------------------------------
 // Init / Probing
 // ---------------------------------------------------------------------------
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-e1d/+/19033
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-e1d
Gerrit-Branch: master
Gerrit-Change-Id: I7d4d4ab39cb3e7e6a7eb8e738a367122eb3fbee2
Gerrit-Change-Number: 19033
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/20200628/9a25a29d/attachment.htm>


More information about the gerrit-log mailing list