]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/Include/sys/termios.h
671a5c06c067ebda7b903bae0840748be4d1608d
[mirror_edk2.git] / StdLib / Include / sys / termios.h
1 /** @file
2 Macros and declarations for terminal oriented ioctls and
3 I/O discipline.
4
5 Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials are licensed and made available under
7 the terms and conditions of the BSD License that accompanies this distribution.
8 The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 * Copyright (c) 1988, 1989, 1993, 1994
15 * The Regents of the University of California. All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 *
41 * @(#)termios.h 8.3 (Berkeley) 3/28/94
42 NetBSD: termios.h,v 1.29 2005/12/11 12:25:21 christos Exp
43 **/
44 #ifndef _SYS_TERMIOS_H_
45 #define _SYS_TERMIOS_H_
46
47 #include <sys/ansi.h>
48 #include <sys/featuretest.h>
49
50 /* Special Control Characters
51 *
52 * Index into c_cc[] character array.
53 */
54 typedef enum {
55 /* Name Enabled by */
56 VTABLEN, /* OXTABS - Length between TAB stops. */
57 VEOF, /* ICANON */
58 VEOL, /* ICANON */
59 VERASE, /* ICANON */
60 VKILL, /* ICANON */
61 VINTR, /* ISIG */
62 VQUIT, /* ISIG */
63 VMIN, /* !ICANON */
64 VTIME, /* !ICANON */
65
66 /* Extensions from BSD and POSIX -- Not yet implemented for UEFI */
67 VWERASE, /* IEXTEN, ICANON -- Erase the WORD to the left of the cursor */
68 VREPRINT, /* IEXTEN, ICANON -- Re-draw the current line (input buffer) */
69 VLNEXT, /* IEXTEN, ICANON -- Input the next character literally */
70 VDISCARD, /* IEXTEN -- Toggle. Discards output display until toggled. */
71
72 /* NCCS must always be the last member of this enum. */
73 NCCS /* Number of control characters in c_cc[] */
74 } CCC_INDEX;
75
76 #define _POSIX_VDISABLE ((unsigned char)'\377')
77
78 #define CCEQ(val, c) (c == val ? val != _POSIX_VDISABLE : 0)
79
80 /*
81 * Input flags - software input processing
82 c_iflag
83 */
84 #define INLCR 0x0001 /* map NL into CR */
85 #define IGNCR 0x0002 /* ignore CR */
86 #define ICRNL 0x0004 /* map CR to NL (ala CRMOD) */
87 #define IGNSPEC 0x0008 /* Ignore function, control, and other non-printing special keys. */
88 #ifdef HAVE_DA_SERIAL
89 #define ISTRIP 0x0010 /* strip 8th bit off chars */
90 #define IGNBRK 0x0020 /* ignore BREAK condition */
91 #define BRKINT 0x0040 /* map BREAK to SIGINTR */
92 #define IRESRV1 0x0080
93 #define IGNPAR 0x0100 /* ignore (discard) parity errors */
94 #define PARMRK 0x0200 /* mark parity and framing errors */
95 #define INPCK 0x0400 /* enable checking of parity errors */
96 #define IXON 0x0800 /* enable output flow control */
97 #define IXOFF 0x1000 /* enable input flow control */
98 #define IXANY 0x2000 /* any char will restart after stop */
99 #endif /* HAVE_DA_SERIAL */
100
101 /*
102 * Output flags - software output processing
103 c_oflag
104 */
105 #define OPOST 0x0001 /* enable following output processing */
106 #define ONLCR 0x0002 /* map NL to CR-NL (ala CRMOD) */
107 #define OXTABS 0x0004 /* expand tabs to spaces */
108 #define ONOEOT 0x0008 /* discard EOT's (^D) on output */
109 #define OCRNL 0x0010 /* map CR to NL */
110 #define ONOCR 0x0020 /* discard CR's when on column 0 */
111 #define ONLRET 0x0040 /* move to column 0 on CR */
112 #define OCTRL 0x0080 /* Map control characters to the sequence ^C */
113
114 /*
115 * Control flags - hardware control of terminal
116 c_cflag
117 */
118 #ifdef HAVE_DA_SERIAL
119 #define CIGNORE 0x0001 /* ignore control flags */
120 #define CSIZE 0x0300 /* character size mask */
121 #define CS5 0x0000 /* 5 bits (pseudo) */
122 #define CS6 0x0100 /* 6 bits */
123 #define CS7 0x0200 /* 7 bits */
124 #define CS8 0x0300 /* 8 bits */
125 #define CSTOPB 0x0400 /* send 2 stop bits, else 1 */
126 #define CREAD 0x0800 /* enable receiver */
127 #define PARENB 0x1000 /* parity enable */
128 #define PARODD 0x2000 /* odd parity, else even */
129 #define HUPCL 0x4000 /* hang up on last close */
130 #define CLOCAL 0x8000 /* ignore modem status lines */
131 #endif
132
133
134 /*
135 * "Local" flags - dumping ground for other state
136 *
137 * Warning: some flags in this structure begin with
138 * the letter "I" and look like they belong in the
139 * input flag.
140 */
141 #define ECHO 0x0001 /* enable echoing */
142 #define ECHOE 0x0002 /* visually erase chars */
143 #define ECHOK 0x0004 /* echo NL after line kill */
144 #define ECHONL 0x0008 /* echo NL even if ECHO is off */
145 #define ISIG 0x0010 /* enable signals INTR, QUIT, [D]SUSP */
146 #define ICANON 0x0020 /* canonicalize input lines */
147 #define IEXTEN 0x0040 /* enable Extensions */
148 #define SKIP_1 0x0100 /* Currently unused */
149 #define TOSTOP 0x0200 /* stop background jobs on output */
150 #define PENDIN 0x0400 /* re-echo input buffer at next read */
151 #define NOFLSH 0x0800 /* don't flush output on signal */
152 #define FLUSHO 0x1000 /* output being flushed (state) */
153
154 typedef INT8 cc_t;
155 typedef UINT16 tcflag_t;
156 typedef UINT32 speed_t;
157
158 struct termios {
159 INT32 c_ispeed; /* input speed - Use a signed type instead of speed_t */
160 INT32 c_ospeed; /* output speed - to ease integer promotion when used. */
161 tcflag_t c_iflag; /* input flags */
162 tcflag_t c_oflag; /* output flags */
163 tcflag_t c_cflag; /* control flags */
164 tcflag_t c_lflag; /* local flags */
165 cc_t c_cc[NCCS]; /* control chars */
166 };
167
168 /*
169 * Commands passed to tcsetattr() for setting the termios structure.
170 */
171 #define TCSANOW 0 /* make change immediate */
172 #define TCSADRAIN 1 /* drain output, then change */
173 #define TCSAFLUSH 2 /* drain output, flush input */
174 #define TCSASOFT 0x10 /* flag - don't alter h.w. state */
175
176 /*
177 * Standard speeds
178 */
179 #define B0 0
180 #define B50 50
181 #define B75 75
182 #define B110 110
183 #define B134 134
184 #define B150 150
185 #define B200 200
186 #define B300 300
187 #define B600 600
188 #define B1200 1200
189 #define B1800 1800
190 #define B2400 2400
191 #define B4800 4800
192 #define B9600 9600
193 #define B19200 19200
194 #define B38400 38400
195
196 // Extended speed definitions
197 #define B7200 7200
198 #define B14400 14400
199 #define B28800 28800
200 #define B57600 57600
201 #define B76800 76800
202 #define B115200 115200
203 #define B230400 230400
204 #define B460800 460800
205 #define B921600 921600
206
207 #define TCIFLUSH 1
208 #define TCOFLUSH 2
209 #define TCIOFLUSH 3
210 #define TCOOFF 1
211 #define TCOON 2
212 #define TCIOFF 3
213 #define TCION 4
214
215 #include <sys/EfiCdefs.h>
216
217 __BEGIN_DECLS
218
219 /** Get input baud rate.
220
221 Extracts the input baud rate from the termios structure pointed to by the
222 pTermios argument.
223
224 @param[in] pTermios A pointer to the termios structure from which to extract
225 the input baud rate.
226
227 @return The value of the input speed is returned exactly as it is contained
228 in the termios structure, without interpretation.
229 **/
230 speed_t cfgetispeed (const struct termios *);
231
232 /** Get output baud rate.
233
234 Extracts the output baud rate from the termios structure pointed to by the
235 pTermios argument.
236
237 @param[in] pTermios A pointer to the termios structure from which to extract
238 the output baud rate.
239
240 @return The value of the output speed is returned exactly as it is contained
241 in the termios structure, without interpretation.
242 **/
243 speed_t cfgetospeed (const struct termios *);
244
245 /** Set input baud rate.
246
247 Replaces the input baud rate, in the termios structure pointed to by the
248 pTermios argument, with the value of NewSpeed.
249
250 @param[out] pTermios A pointer to the termios structure into which to set
251 the input baud rate.
252 @param[in] NewSpeed The new input baud rate.
253
254 @retval 0 The operation completed successfully.
255 @retval -1 An error occured and errno is set to indicate the error.
256 * EINVAL - The value of NewSpeed is outside the range of
257 possible speed values as specified in <sys/termios.h>.
258 **/
259 int cfsetispeed (struct termios *, speed_t);
260
261 /** Set output baud rate.
262
263 Replaces the output baud rate, in the termios structure pointed to by the
264 pTermios argument, with the value of NewSpeed.
265
266 @param[out] pTermios A pointer to the termios structure into which to set
267 the output baud rate.
268 @param[in] NewSpeed The new output baud rate.
269
270 @retval 0 The operation completed successfully.
271 @retval -1 An error occured and errno is set to indicate the error.
272 * EINVAL - The value of NewSpeed is outside the range of
273 possible speed values as specified in <sys/termios.h>.
274 **/
275 int cfsetospeed (struct termios *, speed_t);
276
277 /** Get the parameters associated with an interactive IO device.
278
279 Get the parameters associated with the device referred to by
280 fd and store them into the termios structure referenced by pTermios.
281
282 @param[in] fd The file descriptor for an open interactive IO device.
283 @param[out] pTermios A pointer to a termios structure into which to store
284 attributes of the interactive IO device.
285
286 @retval 0 The operation completed successfully.
287 @retval -1 An error occured and errno is set to indicate the error.
288 * EBADF - The fd argument is not a valid file descriptor.
289 * ENOTTY - The file associated with fd is not an interactive IO device.
290 **/
291 int tcgetattr (int, struct termios *);
292
293 /** Set the parameters associated with an interactive IO device.
294
295 Set the parameters associated with the device referred to by
296 fd to the values in the termios structure referenced by pTermios.
297
298 Behavior is modified by the value of the OptAct parameter:
299 * TCSANOW: The change shall occur immediately.
300 * TCSADRAIN: The change shall occur after all output written to fd is
301 transmitted. This action should be used when changing parameters which
302 affect output.
303 * TCSAFLUSH: The change shall occur after all output written to fd is
304 transmitted, and all input so far received but not read shall be
305 discarded before the change is made.
306
307 @param[in] fd The file descriptor for an open interactive IO device.
308 @param[in] OptAct Currently has no effect.
309 @param[in] pTermios A pointer to a termios structure into which to retrieve
310 attributes to set in the interactive IO device.
311
312 @retval 0 The operation completed successfully.
313 @retval -1 An error occured and errno is set to indicate the error.
314 * EBADF - The fd argument is not a valid file descriptor.
315 * ENOTTY - The file associated with fd is not an interactive IO device.
316 **/
317 int tcsetattr (int, int, const struct termios *);
318
319 /** Transmit pending output.
320
321
322 @param[in] fd The file descriptor for an open interactive IO device.
323
324 @retval 0 The operation completed successfully.
325 @retval -1 An error occured and errno is set to indicate the error.
326 * EBADF - The fd argument is not a valid file descriptor.
327 * ENOTTY - The file associated with fd is not an interactive IO device.
328 * EINTR - A signal interrupted tcdrain().
329 * ENOTSUP - This function is not supported.
330 **/
331 int tcdrain (int);
332
333 /** Suspend or restart the transmission or reception of data.
334
335 This function will suspend or resume transmission or reception of data on
336 the file referred to by fd, depending on the value of Action.
337
338 @param[in] fd The file descriptor of an open interactive IO device (terminal).
339 @param[in] Action The action to be performed:
340 * TCOOFF - Suspend output.
341 * TCOON - Resume suspended output.
342 * TCIOFF - If fd refers to an IIO device, transmit a
343 STOP character, which is intended to cause the
344 terminal device to stop transmitting data.
345 * TCION - If fd refers to an IIO device, transmit a
346 START character, which is intended to cause the
347 terminal device to start transmitting data.
348
349 @retval 0 The operation completed successfully.
350 @retval -1 An error occured and errno is set to indicate the error.
351 * EBADF - The fd argument is not a valid file descriptor.
352 * ENOTTY - The file associated with fd is not an interactive IO device.
353 * EINVAL - The Action argument is not a supported value.
354 * ENOTSUP - This function is not supported.
355 **/
356 int tcflow (int, int);
357
358 /** Discard non-transmitted output data, non-read input data, or both.
359
360
361 @param[in] fd The file descriptor for an open interactive IO device.
362 @param[in] QueueSelector The IO queue to be affected:
363 * TCIFLUSH - If fd refers to a device open for input, flush
364 pending input. Otherwise error EINVAL.
365 * TCOFLUSH - If fd refers to a device open for output,
366 flush pending output. Otherwise error EINVAL.
367 * TCIOFLUSH - If fd refers to a device open for both
368 input and output, flush pending input and output.
369 Otherwise error EINVAL.
370
371 @retval 0 The operation completed successfully.
372 @retval -1 An error occured and errno is set to indicate the error.
373 * EBADF - The fd argument is not a valid file descriptor.
374 * ENOTTY - The file associated with fd is not an interactive IO device.
375 * EINVAL - The QueueSelector argument is not a supported value.
376 * ENOTSUP - This function is not supported.
377 **/
378 int tcflush (int, int);
379
380 //int tcsendbreak (int, int);
381 //pid_t tcgetsid (int);
382
383 //void cfmakeraw (struct termios *);
384 //int cfsetspeed (struct termios *, speed_t);
385 __END_DECLS
386
387 /* Input values for UEFI Keyboard Scan Codes.
388
389 The UEFI Keyboard Scan Codes are mapped into the upper range of the Unicode
390 Private Use Area so that the characters can be inserted into the input stream
391 and treated the same as any other character.
392
393 These values are only used for input. If these codes are output to the
394 console, or another interactive I/O device, the behavior will depend upon
395 the current locale and UEFI character set loaded.
396 */
397 typedef enum {
398 TtySpecKeyMin = 0xF7F0,
399 /* This area is reserved for use by internal I/O software.
400 At least 4 values must exist between TtySpecKeyMin and TtyFunKeyMin.
401 */
402 TtyFunKeyMin = 0xF7FA,
403 TtyKeyEject = 0xF7FA,
404 TtyRecovery, TtyToggleDisplay, TtyHibernate,
405 TtySuspend, TtyBrightnessDown, TtyBrightnessUp,
406 TtyVolumeDown = 0xF87F,
407 TtyVolumeUp, TtyMute,
408 TtyF24 = 0xF88D,
409 TtyF23, TtyF22, TtyF21, TtyF20,
410 TtyF19, TtyF18, TtyF17, TtyF16,
411 TtyF15, TtyF14, TtyF13,
412 TtyEscape = 0xF8E9,
413 TtyF12, TtyF11, TtyF10, TtyF9,
414 TtyF8, TtyF7, TtyF6, TtyF5,
415 TtyF4, TtyF3, TtyF2, TtyF1,
416 TtyPageDown, TtyPageUp, TtyDelete, TtyInsert,
417 TtyEnd, TtyHome, TtyLeftArrow, TtyRightArrow,
418 TtyDownArrow,
419 TtyUpArrow = 0xF8FF,
420 TtyFunKeyMax = 0xF900
421 } TtyFunKey;
422
423 // Non-UEFI character definitions
424 #define CHAR_EOT 0x0004 /* End of Text (EOT) character -- Unix End-of-File character */
425 #define CHAR_SUB 0x001a /* MSDOS End-of-File character */
426 #define CHAR_ESC 0x001b /* Escape (ESC) character */
427
428 #endif /* !_SYS_TERMIOS_H_ */