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