1 /*
2  * termbits2.c
3  *
4  * Stuff that we should include from kernel sources, if we could; but
5  * we can't. Included from "termios2.h"
6  *
7  * by Nick Patavalis (npat@efault.net)
8  *
9  * ATTENTION: Linux-specific kludge!
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of the
14  * License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24  * USA
25  */
26 
27 #ifndef TERMBITS2_H
28 #define TERMBITS2_H
29 
30 #ifndef __linux__
31 #error "Linux specific code!"
32 #endif
33 
34 /* We need tcflag_t, cc_t, speed_t, CBAUDEX, etc */
35 #include <termios.h>
36 
37 /* These definitions must correspond to the kernel structures as
38    defined in:
39 
40      <linux-kernel>/arch/<arch>/include/uapi/asm/termbits.h
41      or <linux-kernel>/include/uapi/asm-generic/termbits.h
42 
43    which are the same as:
44 
45      /usr/include/<arch>/asm/termbits.h
46      or /usr/include/asm-generic/termbits.h
47 
48   Unfortunatelly, we cannot just include <asm/termbits.h> or
49   <asm/termios.h> or <linux/termios.h> (all would do the trick)
50   because then "struct termios" would be re-defined to the kernel
51   version, which is not the same as the libc version. In effect, you
52   cannot both include <termios.h> and <linux/termios.h> because both
53   define a "struct termios" which may or maynot be the same. We want
54   our "struct termios" here to be the libc version (as defined in
55   <termios.h>), because that's what our callers use. As a result we
56   cannot get the definion of "struct termios2" from the above header
57   files, since this would also bring-in the clashing definition of the
58   kernel version of "struct termios". If you have an idea for a better
59   way out of this mess, I would REALLY like to hear it.
60 
61   I hope that soon GLIBC will pick-up termios2 and all these will be
62   useless. Until then ...
63 
64   ATTENTION: For most architectures "struct termios2" and the
65   associated constants we care about (NCCS, BOTHER, IBSHIFT) are the
66   same. For some there are small differences, and some architectures
67   do not support termios2 at all. I don't claim to have done a
68   thorough job figuring out the specifics for every architecture, so
69   your milleage may vary. In any case, if you want support for
70   something that's missing, just copy the relevant definitions from
71   the kernel header file in here, recompile, test, and send me a
72   patch. */
73 
74 #if defined (__alpha__)
75 
76 #error "Architecure has no termios2 support"
77 
78 
79 #elif defined (__powerpc__) || defined (__powerpc64__)
80 
81 #define K_NCCS 19
82 /* The "old" termios is the same with termios2 for powerpc's */
83 struct termios2 {
84         tcflag_t c_iflag;               /* input mode flags */
85         tcflag_t c_oflag;               /* output mode flags */
86         tcflag_t c_cflag;               /* control mode flags */
87         tcflag_t c_lflag;               /* local mode flags */
88         cc_t c_cc[K_NCCS];              /* control characters */
89         cc_t c_line;                    /* line discipline */
90         speed_t c_ispeed;               /* input speed */
91         speed_t c_ospeed;               /* output speed */
92 };
93 
94 #define BOTHER 00037
95 #define IBSHIFT 16
96 
97 /* powerpc ioctl numbers have the argument-size encoded. Make sure we
98    use the correct structure (i.e. kernel termios, not LIBC termios)
99    when calculating them. */
100 #define IOCTL_SETS  _IOW('t', 20, struct termios2)
101 #define IOCTL_SETSW _IOW('t', 21, struct termios2)
102 #define IOCTL_SETSF _IOW('t', 22, struct termios2)
103 #define IOCTL_GETS  _IOR('t', 19, struct termios2)
104 
105 
106 #elif defined (__mips__)
107 
108 #define K_NCCS 23
109 struct termios2 {
110         tcflag_t c_iflag;               /* input mode flags */
111         tcflag_t c_oflag;               /* output mode flags */
112         tcflag_t c_cflag;               /* control mode flags */
113         tcflag_t c_lflag;               /* local mode flags */
114         cc_t c_line;                    /* line discipline */
115         cc_t c_cc[K_NCCS];              /* control characters */
116         speed_t c_ispeed;               /* input speed */
117         speed_t c_ospeed;               /* output speed */
118 };
119 
120 #define BOTHER  CBAUDEX
121 #define IBSHIFT 16
122 
123 #define IOCTL_SETS TCSETS2
124 #define IOCTL_SETSW TCSETSW2
125 #define IOCTL_SETSF TCSETSF2
126 #define IOCTL_GETS TCGETS2
127 
128 
129 #else /* All others */
130 
131 #define K_NCCS 19
132 struct termios2 {
133         tcflag_t c_iflag;               /* input mode flags */
134         tcflag_t c_oflag;               /* output mode flags */
135         tcflag_t c_cflag;               /* control mode flags */
136         tcflag_t c_lflag;               /* local mode flags */
137         cc_t c_line;                    /* line discipline */
138         cc_t c_cc[K_NCCS];              /* control characters */
139         speed_t c_ispeed;               /* input speed */
140         speed_t c_ospeed;               /* output speed */
141 };
142 
143 #define BOTHER CBAUDEX
144 #define IBSHIFT 16
145 
146 #define IOCTL_SETS TCSETS2
147 #define IOCTL_SETSW TCSETSW2
148 #define IOCTL_SETSF TCSETSF2
149 #define IOCTL_GETS TCGETS2
150 
151 #endif /* of architectures */
152 
153 /***************************************************************************/
154 
155 #endif /* of TERMBITS2_H */
156 
157 /***************************************************************************/
158 
159 /*
160  * Local Variables:
161  * mode:c
162  * tab-width: 4
163  * c-basic-offset: 4
164  * indent-tabs-mode: nil
165  * End:
166  */
167