modify open() functionality for TTY device

Issues related to hardware problems
Post Reply
jeremyardley
Posts: 14
Joined: 2011/09/19 03:30:11

modify open() functionality for TTY device

Post by jeremyardley » 2014/12/16 23:20:55

I have a USB serial device that uses the pl2303 driver.

I have a problem that is not unique to this device. Calling

Code: Select all

int open(const char *pathname, int flags)
for the device ttyUSB0 results in RTS and DTR being automatically asserted on the device. I can turn them off immediately afterwards but I still get a flash of DTR & RTS which is undesirbale for my application.

I've checked the driver source and it simply sets the lines as requested by some upstream code. There is also no sign of RTS and CTS being set in the open method. So somewhere inbetween the call to open and the call to the driver the line flags are being set.

I'd like some advice on which bit of code does this and then advice on how to patch it and install on the system - hopefully without completely recompiling the kernel.

User avatar
Super Jamie
Posts: 310
Joined: 2014/01/10 23:44:51

Re: modify open() functionality for TTY device

Post by Super Jamie » 2014/12/17 12:36:49

I looked at kernel 3.18-rc5 because it's what I had at hand.

You would have seen pl2303_open() calls pl2303_set_termios() which can set these flags:

Code: Select all

        if (C_BAUD(tty) == B0)
                priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
        else if (old_termios && (old_termios->c_cflag & CBAUD) == B0)
                priv->line_control |= (CONTROL_DTR | CONTROL_RTS);
There's also a function pl2303_dtr_rts() which can do the same. This function pointed to in the driver's usb_serial_driver struct as .dtr_rts.

void (*dtr_rts) is defined in both generic tty and generic USB serial code. You'd probably need to understand how glibc sets up ttys and serial connections to know if/where that is called.

Your next stop would be the glibc documentation. I think you might be looking for c_cflag being set in struct termios.

Hope that helps.

Post Reply