LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 02-06-2012, 05:13 PM   #1
tilman1
Member
 
Registered: Mar 2007
Location: Stuttgart, Germany
Distribution: gentoo
Posts: 61

Rep: Reputation: 15
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.

Thank you and best regards

Tilman



Debug message from /var/log/messages
Code:
[ 7357.548188] usbrsa ttyUSB1: usbrsa_read_callback - length = 4, data = 41 42 43 44 
[ 7357.548200] drivers/usb/serial/usbrsa.c: usbrsa_write_room(): 640
[ 7357.548203] drivers/usb/serial/usbrsa.c: usbrsa_write - port 1
[ 7357.548238] usbrsa ttyUSB1: usbrsa_write - length = 1, data = 42 
[ 7357.548247] drivers/usb/serial/usbrsa.c: usbrsa_write_room(): 512
[ 7357.548261] usbrsa ttyUSB1: usbrsa_write - length = 1, data = 43 
[ 7357.548270] drivers/usb/serial/usbrsa.c: usbrsa_write_room(): 448
[ 7357.548281] drivers/usb/serial/usbrsa.c: usbrsa_write - port 1{  [ 7357.548283] usbrsa ttyUSB1: usbrsa_write - length = 1, data = 44

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 ?
Code:
        data = urb->transfer_buffer;
	tty = tty_port_tty_get(&port->port);
	if (tty != NULL && urb->actual_length > 0) {
		tty_insert_flip_string(tty, data, urb->actual_length);
		tty_flip_buffer_push(tty);
	}
	tty_kref_put(tty);
 
Old 02-07-2012, 04:46 AM   #2
vedasolutions
LQ Newbie
 
Registered: Feb 2012
Posts: 5

Rep: Reputation: Disabled
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.
 
Old 02-07-2012, 04:25 PM   #3
tilman1
Member
 
Registered: Mar 2007
Location: Stuttgart, Germany
Distribution: gentoo
Posts: 61

Original Poster
Rep: Reputation: 15
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--;
		}
	}
	
}
 
Old 02-08-2012, 08:22 AM   #4
tilman1
Member
 
Registered: Mar 2007
Location: Stuttgart, Germany
Distribution: gentoo
Posts: 61

Original Poster
Rep: Reputation: 15
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 ?

Thanks
Tilman
 
  


Reply

Tags
usb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data written to unformatted disk peterlowrie Linux - General 1 01-14-2011 07:32 PM
/dev/..... Where is the data in this directory being written to? Completely Clueless Linux - General 10 08-22-2010 06:52 AM
Catch all data being written to Hard Drives vzxen Linux - Newbie 20 07-27-2010 09:43 AM
Received Data (RX) Errors and very slow connection SilvioGesell Linux - Networking 1 06-22-2010 06:39 AM
Tracking amount of sent/received data MartenH Linux - Newbie 3 04-01-2009 02:05 PM


All times are GMT -5. The time now is 12:28 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration