1 /* 2 * Copyright 2004-2012 Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _TERMIOS_H_ 6 #define _TERMIOS_H_ 7 8 9 #include <sys/types.h> 10 11 12 typedef __haiku_uint32 tcflag_t; 13 typedef unsigned char speed_t; 14 typedef unsigned char cc_t; 15 16 #define NCCS 11 /* number of control characters */ 17 18 struct termios { 19 tcflag_t c_iflag; /* input modes */ 20 tcflag_t c_oflag; /* output modes */ 21 tcflag_t c_cflag; /* control modes */ 22 tcflag_t c_lflag; /* local modes */ 23 char c_line; /* line discipline */ 24 speed_t c_ispeed; /* custom input baudrate */ 25 speed_t c_ospeed; /* custom output baudrate */ 26 cc_t c_cc[NCCS]; /* control characters */ 27 }; 28 29 /* control characters */ 30 #define VINTR 0 31 #define VQUIT 1 32 #define VERASE 2 33 #define VKILL 3 34 #define VEOF 4 35 #define VEOL 5 36 #define VMIN 4 37 #define VTIME 5 38 #define VEOL2 6 39 #define VSWTCH 7 40 #define VSTART 8 41 #define VSTOP 9 42 #define VSUSP 10 43 44 /* c_iflag - input control modes */ 45 #define IGNBRK 0x01 /* ignore break condition */ 46 #define BRKINT 0x02 /* break sends interrupt */ 47 #define IGNPAR 0x04 /* ignore characters with parity errors */ 48 #define PARMRK 0x08 /* mark parity errors */ 49 #define INPCK 0x10 /* enable input parity checking */ 50 #define ISTRIP 0x20 /* strip high bit from characters */ 51 #define INLCR 0x40 /* maps newline to CR on input */ 52 #define IGNCR 0x80 /* ignore carriage returns */ 53 #define ICRNL 0x100 /* map CR to newline on input */ 54 #define IUCLC 0x200 /* map all upper case to lower */ 55 #define IXON 0x400 /* enable input SW flow control */ 56 #define IXANY 0x800 /* any character will restart input */ 57 #define IXOFF 0x1000 /* enable output SW flow control */ 58 59 /* c_oflag - output control modes */ 60 #define OPOST 0x01 /* enable postprocessing of output */ 61 #define OLCUC 0x02 /* map lowercase to uppercase */ 62 #define ONLCR 0x04 /* map NL to CR-NL on output */ 63 #define OCRNL 0x08 /* map CR to NL on output */ 64 #define ONOCR 0x10 /* no CR output when at column 0 */ 65 #define ONLRET 0x20 /* newline performs CR function */ 66 #define OFILL 0x40 /* use fill characters for delays */ 67 #define OFDEL 0x80 /* Fills are DEL, otherwise NUL */ 68 #define NLDLY 0x100 /* Newline delays: */ 69 #define NL0 0x000 70 #define NL1 0x100 71 #define CRDLY 0x600 /* Carriage return delays: */ 72 #define CR0 0x000 73 #define CR1 0x200 74 #define CR2 0x400 75 #define CR3 0x600 76 #define TABDLY 0x1800 /* Tab delays: */ 77 #define TAB0 0x0000 78 #define TAB1 0x0800 79 #define TAB2 0x1000 80 #define TAB3 0x1800 81 #define BSDLY 0x2000 /* Backspace delays: */ 82 #define BS0 0x0000 83 #define BS1 0x2000 84 #define VTDLY 0x4000 /* Vertical tab delays: */ 85 #define VT0 0x0000 86 #define VT1 0x4000 87 #define FFDLY 0x8000 /* Form feed delays: */ 88 #define FF0 0x0000 89 #define FF1 0x8000 90 91 /* c_cflag - control modes */ 92 #define CBAUD 0x1F /* line speed definitions */ 93 94 #define B0 0x00 /* hang up */ 95 #define B50 0x01 /* 50 baud */ 96 #define B75 0x02 97 #define B110 0x03 98 #define B134 0x04 99 #define B150 0x05 100 #define B200 0x06 101 #define B300 0x07 102 #define B600 0x08 103 #define B1200 0x09 104 #define B1800 0x0A 105 #define B2400 0x0B 106 #define B4800 0x0C 107 #define B9600 0x0D 108 #define B19200 0x0E 109 #define B38400 0x0F 110 #define B57600 0x10 111 #define B115200 0x11 112 #define B230400 0x12 113 #define B31250 0x13 /* for MIDI */ 114 115 #define CSIZE 0x20 /* character size */ 116 #define CS5 0x00 /* only 7 and 8 bits supported */ 117 #define CS6 0x00 /* Note, it was not very wise to set all of these */ 118 #define CS7 0x00 /* to zero, but there is not much we can do about it*/ 119 #define CS8 0x20 120 #define CSTOPB 0x40 /* send 2 stop bits, not 1 */ 121 #define CREAD 0x80 /* enable receiver */ 122 #define PARENB 0x100 /* parity enable */ 123 #define PARODD 0x200 /* odd parity, else even */ 124 #define HUPCL 0x400 /* hangs up on last close */ 125 #define CLOCAL 0x800 /* indicates local line */ 126 #define XLOBLK 0x1000 /* block layer output ?*/ 127 #define CTSFLOW 0x2000 /* enable CTS flow */ 128 #define RTSFLOW 0x4000 /* enable RTS flow */ 129 #define CRTSCTS (RTSFLOW | CTSFLOW) 130 131 /* c_lflag - local modes */ 132 #define ISIG 0x01 /* enable signals */ 133 #define ICANON 0x02 /* Canonical input */ 134 #define XCASE 0x04 /* Canonical u/l case */ 135 #define ECHO 0x08 /* Enable echo */ 136 #define ECHOE 0x10 /* Echo erase as bs-sp-bs */ 137 #define ECHOK 0x20 /* Echo nl after kill */ 138 #define ECHONL 0x40 /* Echo nl */ 139 #define NOFLSH 0x80 /* Disable flush after int or quit */ 140 #define TOSTOP 0x100 /* stop bg processes that write to tty */ 141 #define IEXTEN 0x200 /* implementation defined extensions */ 142 #define ECHOCTL 0x400 143 #define ECHOPRT 0x800 144 #define ECHOKE 0x1000 145 #define FLUSHO 0x2000 146 #define PENDIN 0x4000 147 148 /* options to tcsetattr() */ 149 #define TCSANOW 0x01 /* make change immediate */ 150 #define TCSADRAIN 0x02 /* drain output, then change */ 151 #define TCSAFLUSH 0x04 /* drain output, flush input */ 152 153 /* actions for tcflow() */ 154 #define TCOOFF 0x01 /* suspend output */ 155 #define TCOON 0x02 /* restart output */ 156 #define TCIOFF 0x04 /* transmit STOP character, intended to stop input data */ 157 #define TCION 0x08 /* transmit START character, intended to resume input data */ 158 159 /* values for tcflush() */ 160 #define TCIFLUSH 0x01 /* flush pending input */ 161 #define TCOFLUSH 0x02 /* flush untransmitted output */ 162 #define TCIOFLUSH 0x03 /* flush both */ 163 164 165 /* ioctl() identifiers to control the TTY */ 166 #define TCGETA 0x8000 167 #define TCSETA (TCGETA + 1) 168 #define TCSETAF (TCGETA + 2) 169 #define TCSETAW (TCGETA + 3) 170 /* TCWAITEVENT (TCGETA + 4) */ 171 #define TCSBRK (TCGETA + 5) 172 #define TCFLSH (TCGETA + 6) 173 #define TCXONC (TCGETA + 7) 174 /* TCQUERYCONNECTED (TCGETA + 8) */ 175 #define TCGETBITS (TCGETA + 9) /* same as TIOCMGET */ 176 #define TCSETDTR (TCGETA + 10) 177 #define TCSETRTS (TCGETA + 11) 178 #define TIOCGWINSZ (TCGETA + 12) /* pass in a struct winsize */ 179 #define TIOCSWINSZ (TCGETA + 13) /* pass in a struct winsize */ 180 /* TCVTIME (TCGETA + 14) */ 181 #define TIOCGPGRP (TCGETA + 15) /* Gets the process group ID of the TTY device */ 182 #define TIOCSPGRP (TCGETA + 16) /* Sets the process group ID ('pgid' in BeOS) */ 183 #define TIOCSCTTY (TCGETA + 17) /* Become controlling TTY */ 184 #define TIOCMGET (TCGETA + 18) /* get line state */ 185 #define TIOCMSET (TCGETA + 19) /* does TCSETDTR/TCSETRTS */ 186 #define TIOCSBRK (TCGETA + 20) /* set txd pin */ 187 #define TIOCCBRK (TCGETA + 21) /* both are a frontend to TCSBRK */ 188 #define TIOCMBIS (TCGETA + 22) /* set bits in line state */ 189 #define TIOCMBIC (TCGETA + 23) /* clear bits in line state */ 190 #define TIOCGSID (TCGETA + 24) /* get session leader process group ID */ 191 #define TIOCOUTQ (TCGETA + 25) /* get output queue size */ 192 #define TIOCEXCL (TCGETA + 26) /* set exclusive use of tty */ 193 #define TIOCNXCL (TCGETA + 27) /* clear exclusive use of tty */ 194 195 /* for TIOCGWINSZ */ 196 struct winsize { 197 unsigned short ws_row; 198 unsigned short ws_col; 199 unsigned short ws_xpixel; 200 unsigned short ws_ypixel; 201 }; 202 203 /* Bits for the TCGETBITS control */ 204 #define TCGB_CTS 0x01 205 #define TCGB_DSR 0x02 206 #define TCGB_RI 0x04 207 #define TCGB_DCD 0x08 208 209 /* Bits for the TIOCMGET / TIOCMSET control */ 210 #define TIOCM_CTS TCGB_CTS /* clear to send */ 211 #define TIOCM_CD TCGB_DCD /* carrier detect */ 212 #define TIOCM_CAR TCGB_DCD 213 #define TIOCM_RI TCGB_RI /* ring indicator */ 214 #define TIOCM_RNG TCGB_RI 215 #define TIOCM_DSR TCGB_DSR /* dataset ready */ 216 #define TIOCM_DTR 0x10 /* data terminal ready */ 217 #define TIOCM_RTS 0x20 /* request to send */ 218 219 220 #ifdef __cplusplus 221 extern "C" { 222 #endif 223 224 extern speed_t cfgetispeed(const struct termios *termios); 225 extern speed_t cfgetospeed(const struct termios *termios); 226 extern int cfsetispeed(struct termios *termios, speed_t speed); 227 extern int cfsetospeed(struct termios *termios, speed_t speed); 228 extern void cfmakeraw(struct termios *termios); 229 extern int tcgetattr(int fd, struct termios *termios); 230 extern int tcsetattr(int fd, int option, const struct termios *termios); 231 extern int tcsendbreak(int fd, int duration); 232 extern int tcdrain(int fd); 233 extern int tcflow(int fd, int action); 234 extern int tcflush(int fd, int queueSelector); 235 extern pid_t tcgetsid(int fd); 236 extern int tcsetsid(int fd, pid_t pid); 237 238 #ifdef __cplusplus 239 } 240 #endif 241 242 #endif /* _TERMIOS_H_ */ 243