From 15f733a7f6af0f686365a8445f039b660fd43d3c Mon Sep 17 00:00:00 2001 From: hartkopp Date: Fri, 16 Apr 2010 19:39:09 +0000 Subject: [PATCH] Added possibility to force the slcan driver to use a specific device number when set via SWTC char (e.g. with stty). See thread https://lists.berlios.de/pipermail/socketcan-users/2010-April/001378.html Provided by Stephen Hellriegel So far this change only applies for Kernels < 2.6.32 ... git-svn-id: svn://svn.berlios.de//socketcan/trunk@1170 030b6a49-0b11-0410-94ab-b0dab22257f2 --- kernel/2.6/drivers/net/can/slcan.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/kernel/2.6/drivers/net/can/slcan.c b/kernel/2.6/drivers/net/can/slcan.c index dd29d7d..3cbb9b8 100644 --- a/kernel/2.6/drivers/net/can/slcan.c +++ b/kernel/2.6/drivers/net/can/slcan.c @@ -623,7 +623,7 @@ static void slc_sync(void) /* Find a free SLCAN channel, and link in this `tty' line. */ -static struct slcan *slc_alloc(dev_t line) +static struct slcan *slc_alloc(dev_t line, char forcednum) { int i; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) @@ -680,10 +680,18 @@ static struct slcan *slc_alloc(dev_t line) } } + /* Check if the user specified an exact interface to use */ + if (forcednum) { + sel = forcednum - '0'; + score = 0; + i = sel; + dev = slcan_devs[i]; + } + if (sel >= 0) { i = sel; dev = slcan_devs[i]; - if (score > 1) { + if ((score > 1) && (dev)) { sl = netdev_priv(dev); sl->flags &= (1 << SLF_INUSE); return sl; @@ -766,7 +774,21 @@ static int slcan_open(struct tty_struct *tty) /* OK. Find a free SLCAN channel to use. */ err = -ENFILE; - sl = slc_alloc(tty_devnum(tty)); + + /* Look to see if the user has requested a specific channel + * to be used (encoded as '0' plus the interface number requested in + * the otherwise unused swtch termios variable ) + * stty swtch 'channel' device + * where 'channel' is '0' to maxdevs (0) + * where device is the name of the serial device (/dev/ttyUSB0) + */ + if ((SWTC_CHAR(tty)>='0') && (SWTC_CHAR(tty)<'0'+maxdev)){ + sl = slc_alloc(tty_devnum(tty),SWTC_CHAR(tty)); + } else { + /* OK. Find a free SLCAN channel to use. */ + sl = slc_alloc(tty_devnum(tty),0); + } + if (sl == NULL) goto err_exit; -- 2.39.2