Re: [PATCH v3] ioctl_tty.2: Add example how to get or set baudrate on the serial port

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Pali,

On 8/1/21 3:51 PM, Pali Rohár wrote:
Signed-off-by: Pali Rohár <pali@xxxxxxxxxx>

---
Changes in v3:
* Check support for custom baudrate only based on BOTHER macro
* Use TCGETS/TCSETS/termios when TCGETS2/TCSETS2/termios2 is not available

Changes in v2:
* Use \e for backslash
* Use exit(EXIT_*) instead of return num
* Sort includes
* Add comment about possible fallback
---

Hello Alejandro!

I found out that this stuff is more complicated as I originally thought.
And seems that additional documentation on this topic is needed...

For setting custom baudrate it is needed to set BOTHER flag in c_cflag
field and baudrate value itself in c_ospeed and c_ispeed fields.

So when BOTHER flag is not provided by <asm/termbits.h> then setting custom
baudrate is not possible, fields c_ospeed and c_ispeed do not exist (and
only some predefined Bnnn baudrate values are supported). This applies when
compiling application with older version of header files (prior support for
custom baudrate was introduced into header files).

First caveat: BOTHER constant is different for different architectures.
So it is not possible to provide fallback #ifndef..#define BOTHER.

And now the biggest issue: Some architectures have these c_ospeed and
c_ispeed fields in struct termios and some in struct termios2.

TCGETS/TCSETS ioctls use struct termios and TCGETS/TCSETS2 use
struct termios2.

Some architectures (e.g. amd64) provide both struct termios and struct
termios2, but c_ospeed and c_ispeed are only in struct termios2.

Some other architectures (e.g. alpha) provide both struct termios and struct
termios2 and both have c_ospeed and c_ispeed fields.

And some other architectures (e.g. powerpc) provide only struct termios
(no struct termios2) and it has c_ospeed and c_ispeed fields.

So basically to support all architectures it is needed to use
struct termios2 when TCGETS2/TCSETS2 is supported. Otherwise it is needed
to use struct termios with TCGETS/TCSETS (case for e.g. powerpc).

When you send v4, please include the above text (or something similar) to the commit message.

Thanks,

Alex


I updated v3 patch to handle this logic.
---


--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux