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