self written usb driver: received data is retransmitted
Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
self written usb driver: received data is retransmitted
Hi,
I am writting a driver for a serial converter.
In principle, receiving and sending data already works.
Data that is received is however echoed and thereby retransmitted on the tx feed. I suspect the tty layer, but know to little about it to really pinpoint it to that.
Looking at other postings, this question might be too detailed and too close to the kernel for the forum. If so, I would appreciate information on where to sent this question to.
Here a code fragment from the completion handler that processes the received data from the usb-to-serial-convertor. The received data is stored in a transfer buffer to which data points.
Am I doing this correctly ?
Your read call back code is okay. Based on some conditions received characters are echoed in the tty layer.
Check the function n_tty_receive_char() in drivers/tty/n_tty.c. This function echoes the charactors on the tx
using the process_echoes() function. You can put the printk's in the n_tty_recieve_char() and check which condition
is met to make the characters echoed on tx. You can even use stty command on your device file and check the condtions.
stty -F /dev/ttyUSB1 -echo prevents the characters being echoed.
The tty flags are however only persisted if the device is opened:
stty -F /dev/ttyUSB1 -echo is only persisted if I keep the device opened by cat /dev/ttyUSB1.
I guess that set_termios function is lacking something. But what ?
Code:
static void usbrsa_set_termios(struct tty_struct *tty,
struct usb_serial_port *port, struct ktermios *old_termios)
{
struct usbrsa_port_private* priv = usb_get_serial_port_data(port);
unsigned int cflag;
speed_t baud_rate;
unsigned long flags;
int retval;
int retries = 3;
dbg("%s - port %d", __func__, port->number);
if (!tty)
{
dbg("%s(): no tty structures", __func__);
return;
}
if (I_IXOFF(tty) || I_IXON(tty))
{
priv->xon = START_CHAR(tty);
priv->xoff = STOP_CHAR(tty);
dbg("%s - XON = %2x, XOFF = %2x",
__func__, priv->xon, priv->xoff );
}
cflag = tty->termios->c_cflag;
/* get the baud rate wanted */
baud_rate = tty_get_baud_rate(tty);
dbg("%s - baudrate = %u",__func__, baud_rate );
// compute values for baud rate counter and LCR. Then sent to USB-RSA
while(retries > 0)
{
spin_lock_irqsave(&priv->lock, flags);
if (!(test_bit(LOCK_BAUDRATE_LCR,&priv->urb_lock)))
{
prepare_baudrate_lcr_urb(cflag,
baud_rate,
priv->baudrate_lcr_urb->transfer_buffer);
set_bit(LOCK_BAUDRATE_LCR,&priv->urb_lock);
spin_unlock_irqrestore(&priv->lock, flags);
retval = usb_submit_urb(priv->baudrate_lcr_urb,GFP_KERNEL);
if (retval != 0)
{
dev_err(&port->dev, "%s(): usb_submit_urb() failed"
" with error %d\n", __func__, retval);
spin_lock_irqsave(&priv->lock, flags);
clear_bit(LOCK_BAUDRATE_LCR,&priv->urb_lock);
spin_unlock_irqrestore(&priv->lock, flags);
retries--;
}
}
else
{
spin_unlock_irqrestore(&priv->lock, flags);
retries--;
}
}
}
Found it. Actually, there is nothing lacking but too much:
I had set usb_serial_driver.init_termios to an init function assuming that it is only called if the driver initializes, i.e. when the function assigned to the attach-hook (usb_serial_driver.attach) is called by the usb system. I wonder what the init_termios hook is normally used for ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.