haiku/headers/posix
PulkoMandy a38c3c0384 serial/tty: fix handling of custom baudrates
Fixes the code I introduced in hrev50114 for custom serial port
baudrates. The idea there was based on FreeBSD implementation, but I
missed a key detail: speed_t in BeOS (and Haiku) is only an 8 bit value.
Note that BeOS does not have c_ispeed and c_ospeed fields, instead they
are named c_ixxxxx and c_oxxxxx with a comment in termios.h saying that
they are not used. So the renaming and moving of these fields isn't a problem.

This means the previous code worked only for speed between 20 and 255
baud, quite the opposite of what I wanted to do, which is to enable
access to fast baudrates.

This new implementation exploits the fact that tcflag_t is 32 bit, but
we never actually use more than 16 bits. Therefore, the high bits of
each value were unused, and can be reclaimed to store the speed,
by changing tcflag_t to 16 bits. The speed is then inserted as two 16
bit values that can be combined as a 32 bit one. The flag bits are not
moved (on little endian systems), and the extra values are guaranteed to
be set to 0 by any previous code that was compiled with 32 bit tcflag_t.

Support for different speeds for input and output is now also possible
(POSIX specifies separate functions for setting the input and output
speeds, which is useful for some old terminals and modems, where it was
useful to have a high baudrate for data to display on the screen, but
things typed on the keyboard aren't quite as fast). If desired, we could
now properly implement this in our serial drivers, but it isn't done
here yet.

Additional changes:
- speed_t is now a 32bit type, allowing to pass large values to
  cfset(i,o)speed
- fix some places where a baudrate enum value was incorrectly put in the
  c_ispeed and c_ospeed fields, this is not how they were meant to be
  used (it meant the default was to use a speed of 0, that means "hangup"
  the line, which I think no serial driver really implemented).
- do not put baudrate enumeration values in c_iflag and c_oflag, they
  are meant to be used in c_cflag only, and conflict with other bits.
  Separate speeds for input and output can be done by setting the
  c_cflag value to CBAUD (indicating custom baudrates) and then setting
  the values in c_ispeed and c_ospeed.

Fixes #18483

Change-Id: If63a24b5ced5edf6d051d921197db194def0c614
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7068
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
2024-12-14 12:29:05 +00:00
..
arch
arpa
compat/sys
net net: Rename IFT_TUN to IFT_TUNNEL as on BSD 2023-12-10 19:50:48 +00:00
netinet network/ping: update to freebsd-current 2024-02-26 14:06:29 +00:00
netinet6
sys kernel/libnetwork: add accept4() from POSIX.1/2024 2024-11-04 17:55:40 +00:00
alloca.h
assert.h headers: Don't define static_assert for C23 and C++ 2024-11-21 19:26:51 +00:00
complex.h
ctype.h
devctl.h libroot: add posix_devctl() from POSIX.1-2024 2024-11-10 20:08:54 +00:00
dirent.h
div_t.h
dlfcn.h posix: dladdr was introduced in POSIX-2024, but with Dl_info_t 2024-09-11 14:02:22 +00:00
endian.h
errno.h
fcntl.h Change AT_FDCWD from -1 to -100. 2024-02-26 14:04:27 +00:00
features.h features.h: fix build when BSD headers are not in include path 2024-01-03 17:11:56 +00:00
fenv.h
fnmatch.h
ftw.h ftw.h: Remove unneeded #include <features.h>. 2024-10-14 13:53:48 -04:00
getopt.h
glob.h
grp.h
inttypes.h
iovec.h
langinfo.h
libgen.h
libio.h
limits.h regex.h: use _DEFAULT_SOURCE 2023-12-30 18:09:57 +00:00
locale_t.h locale_t.h: Add missing newline at end of file. 2023-04-25 12:38:37 -04:00
locale.h
malloc_debug.h
malloc.h headers: Change most remaining include guards to _DEFAULT_SOURCE. 2024-09-19 16:43:31 +00:00
math.h
memory.h
monetary.h
netdb.h
nl_types.h
null.h
poll.h
pthread.h pthread: Use 1 for PTHREAD_BARRIER_SERIAL_THREAD. 2023-06-07 15:12:11 +00:00
pwd.h
regex.h features.h: fix build when BSD headers are not in include path 2024-01-03 17:11:56 +00:00
resolv.h
sched.h
search.h headers: Change most remaining include guards to _DEFAULT_SOURCE. 2024-09-19 16:43:31 +00:00
semaphore.h
setjmp.h
shadow.h
signal.h signal.h: Look for _DEFAULT_SOURCE not __USE_GNU for sighandler_t. 2023-08-30 17:31:31 -04:00
size_t.h
spawn.h
stdint.h
stdio_ext.h
stdio_post.h
stdio_pre.h
stdio.h headers: Change most remaining include guards to _DEFAULT_SOURCE. 2024-09-19 16:43:31 +00:00
stdlib.h stdlib.h: Remove *rand48_r methods. 2024-12-10 13:15:06 -05:00
string.h libroot: move memmem for POSIX.1/2024 2024-11-04 17:55:40 +00:00
strings.h
syslog.h
tar.h
termios.h serial/tty: fix handling of custom baudrates 2024-12-14 12:29:05 +00:00
threads.h
time.h
uchar.h
unistd.h ioctl: Document in Haiku book and in comments 2024-11-18 17:12:04 +00:00
utime.h
utmpx.h
wchar_t.h
wchar.h headers: Change most remaining include guards to _DEFAULT_SOURCE. 2024-09-19 16:43:31 +00:00
wctype.h