Change in libosmo-abis[master]: dahdi: Use ioctl(DAHDI_SPECIFY) instead of legacy /dev/dahdi/%u

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
Thu Nov 14 22:06:23 UTC 2019


laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-abis/+/15996 )

Change subject: dahdi: Use ioctl(DAHDI_SPECIFY) instead of legacy /dev/dahdi/%u
......................................................................

dahdi: Use ioctl(DAHDI_SPECIFY) instead of legacy /dev/dahdi/%u

It appears that opening "/dev/dahdi/channel" and using
ioctl(DAHDI_SPECIFY) is possible at least since dahdi 2.4 (from 2010),
and opening "/dev/dahdi/%u" has been deprecated ever since.  One
advantage of the new interface is that you can use channel numbers
larger than 250, which is quite easily possible if you have more than
eight E1 lines on a system.  It also makes libosmo-abis work on systems
where there are no udev rules for creating the legacy device nodes.

Change-Id: Id6c8f27d7ae948b50e9cf5a38f039d782ff78e1d
---
M src/input/dahdi.c
1 file changed, 35 insertions(+), 26 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/dahdi.c b/src/input/dahdi.c
index 47276a7..6594eea 100644
--- a/src/input/dahdi.c
+++ b/src/input/dahdi.c
@@ -1,6 +1,6 @@
 /* OpenBSC Abis input driver for DAHDI */
 
-/* (C) 2008-2011 by Harald Welte <laforge at gnumonks.org>
+/* (C) 2008-2019 by Harald Welte <laforge at gnumonks.org>
  * (C) 2009 by Holger Hans Peter Freyther <zecke at selfish.org>
  * (C) 2010 by Digium and Matthew Fredrickson <creslin at digium.com>
  *
@@ -603,6 +603,33 @@
 	return 0;
 }
 
+static int dahdi_open_slot(int dahdi_chan_nr)
+{
+	int rc, fd;
+#ifndef DAHDI_SPECIFY
+	char openstr[128];
+	snprintf(openstr, sizeof(openstr), "/dev/dahdi/%d", dev_nr);
+#else
+	const char *openstr = "/dev/dahdi/channel";
+#endif
+	rc = open(openstr, O_RDWR | O_NONBLOCK);
+	if (rc < 0) {
+		LOGP(DLINP, LOGL_ERROR, "DAHDI: could not open %s %s\n", openstr, strerror(errno));
+		return -EIO;
+	}
+	fd = rc;
+#ifdef DAHDI_SPECIFY
+	rc = ioctl(fd, DAHDI_SPECIFY, &dahdi_chan_nr);
+	if (rc < 0) {
+		close(fd);
+		LOGP(DLINP, LOGL_ERROR, "DAHDI: could not DAHDI_SPECIFY %d: %s\n",
+		     dahdi_chan_nr, strerror(errno));
+		return -EIO;
+	}
+#endif
+	return fd;
+}
+
 static int dahdi_e1_setup(struct e1inp_line *line)
 {
 	struct span_cfg *scfg;
@@ -623,7 +650,6 @@
 	/* TS0 is CRC4, don't need any fd for it */
 	for (ts = 1; ts <= scfg->chan_num; ts++) {
 		unsigned int idx = ts-1;
-		char openstr[128];
 		struct e1inp_ts *e1i_ts = &line->ts[idx];
 		struct osmo_fd *bfd = &e1i_ts->driver.dahdi.fd;
 		int dev_nr;
@@ -640,7 +666,6 @@
 		bfd->data = line;
 		bfd->priv_nr = ts;
 		bfd->cb = dahdi_fd_cb;
-		snprintf(openstr, sizeof(openstr), "/dev/dahdi/%d", dev_nr);
 
 		switch (e1i_ts->type) {
 		case E1INP_TS_TYPE_NONE:
@@ -657,13 +682,9 @@
 			break;
 		case E1INP_TS_TYPE_SIGN:
 			if (!bfd->fd)
-				bfd->fd = open(openstr, O_RDWR | O_NONBLOCK);
-			if (bfd->fd == -1) {
-				LOGP(DLINP, LOGL_ERROR,
-					"%s could not open %s %s\n",
-					__func__, openstr, strerror(errno));
+				bfd->fd = dahdi_open_slot(dev_nr);
+			if (bfd->fd < 0)
 				return -EIO;
-			}
 			bfd->when = BSC_FD_READ | BSC_FD_EXCEPT;
 			ret = dahdi_set_bufinfo(bfd->fd, 1);
 			if (ret < 0)
@@ -676,13 +697,9 @@
 			break;
 		case E1INP_TS_TYPE_HDLC:
 			if (!bfd->fd)
-				bfd->fd = open(openstr, O_RDWR | O_NONBLOCK);
-			if (bfd->fd == -1) {
-				LOGP(DLINP, LOGL_ERROR,
-					"%s could not open %s %s\n",
-					__func__, openstr, strerror(errno));
+				bfd->fd = dahdi_open_slot(dev_nr);
+			if (bfd->fd < 0)
 				return -EIO;
-			}
 			bfd->when = BSC_FD_READ | BSC_FD_EXCEPT;
 			ret = dahdi_set_bufinfo(bfd->fd, 1);
 			if (ret < 0)
@@ -696,13 +713,9 @@
 				e1i_ts->lapd = NULL;
 			}
 			if (!bfd->fd)
-				bfd->fd = open(openstr, O_RDWR | O_NONBLOCK);
-			if (bfd->fd == -1) {
-				LOGP(DLINP, LOGL_ERROR,
-					"%s could not open %s %s\n",
-					__func__, openstr, strerror(errno));
+				bfd->fd = dahdi_open_slot(dev_nr);
+			if (bfd->fd < 0)
 				return -EIO;
-			}
 			ret = dahdi_set_bufinfo(bfd->fd, 0);
 			if (ret < 0)
 				return -EIO;
@@ -713,12 +726,8 @@
 			break;
 		}
 
-		if (bfd->fd < 0) {
-			LOGP(DLINP, LOGL_ERROR,
-				"%s could not open %s %s\n",
-				__func__, openstr, strerror(errno));
+		if (bfd->fd < 0)
 			return bfd->fd;
-		}
 
 		ret = osmo_fd_register(bfd);
 		if (ret < 0) {

-- 
To view, visit https://gerrit.osmocom.org/c/libosmo-abis/+/15996
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-abis
Gerrit-Branch: master
Gerrit-Change-Id: Id6c8f27d7ae948b50e9cf5a38f039d782ff78e1d
Gerrit-Change-Number: 15996
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191114/27896948/attachment.htm>


More information about the gerrit-log mailing list