1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
|
/* $OpenBSD: hpux_tty.c,v 1.12 2004/09/19 21:58:41 mickey Exp $ */
/* $NetBSD: hpux_tty.c,v 1.14 1997/04/01 19:59:05 scottr Exp $ */
/*
* Copyright (c) 1988 University of Utah.
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Science Department.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Utah $Hdr: hpux_tty.c 1.14 93/08/05$
*
* @(#)hpux_tty.c 8.3 (Berkeley) 1/12/94
*/
/*
* stty/gtty/termio emulation stuff
*/
#ifndef COMPAT_43
#define COMPAT_43
#endif
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/filedesc.h>
#include <sys/ioctl.h>
#include <sys/proc.h>
#include <sys/tty.h>
#include <sys/file.h>
#include <sys/conf.h>
#include <sys/buf.h>
#include <sys/kernel.h>
#include <compat/hpux/hpux.h>
#include <compat/hpux/hpux_termio.h>
#include <compat/hpux/hpux_syscallargs.h>
/*
* Map BSD/POSIX style termios info to and from SYS5 style termio stuff.
*/
int
hpux_termio(fd, com, data, p)
int fd, com;
caddr_t data;
struct proc *p;
{
struct file *fp;
struct termios tios;
struct hpux_termios htios;
int line, error;
int newi = 0;
int (*ioctlrout)(struct file *fp, u_long com,
caddr_t data, struct proc *p);
if ((fp = fd_getfile(p->p_fd, fd)) == NULL)
return (EBADF);
FREF(fp);
ioctlrout = fp->f_ops->fo_ioctl;
switch (com) {
case HPUXTCGETATTR:
newi = 1;
/* fall into ... */
case HPUXTCGETA:
/*
* Get BSD terminal state
*/
if ((error = (*ioctlrout)(fp, TIOCGETA, (caddr_t)&tios, p)))
break;
bzero((char *)&htios, sizeof htios);
/*
* Set iflag.
* Same through ICRNL, no BSD equivs for IUCLC, IENQAK
*/
htios.c_iflag = tios.c_iflag & 0x1ff;
if (tios.c_iflag & IXON)
htios.c_iflag |= TIO_IXON;
if (tios.c_iflag & IXOFF)
htios.c_iflag |= TIO_IXOFF;
if (tios.c_iflag & IXANY)
htios.c_iflag |= TIO_IXANY;
/*
* Set oflag.
* No BSD equivs for OLCUC/OCRNL/ONOCR/ONLRET/OFILL/OFDEL
* or any of the delays.
*/
if (tios.c_oflag & OPOST)
htios.c_oflag |= TIO_OPOST;
if (tios.c_oflag & ONLCR)
htios.c_oflag |= TIO_ONLCR;
if (tios.c_oflag & OXTABS)
htios.c_oflag |= TIO_TAB3;
/*
* Set cflag.
* Baud from ospeed, rest from cflag.
*/
htios.c_cflag = bsdtohpuxbaud(tios.c_ospeed);
switch (tios.c_cflag & CSIZE) {
case CS5:
htios.c_cflag |= TIO_CS5; break;
case CS6:
htios.c_cflag |= TIO_CS6; break;
case CS7:
htios.c_cflag |= TIO_CS7; break;
case CS8:
htios.c_cflag |= TIO_CS8; break;
}
if (tios.c_cflag & CSTOPB)
htios.c_cflag |= TIO_CSTOPB;
if (tios.c_cflag & CREAD)
htios.c_cflag |= TIO_CREAD;
if (tios.c_cflag & PARENB)
htios.c_cflag |= TIO_PARENB;
if (tios.c_cflag & PARODD)
htios.c_cflag |= TIO_PARODD;
if (tios.c_cflag & HUPCL)
htios.c_cflag |= TIO_HUPCL;
if (tios.c_cflag & CLOCAL)
htios.c_cflag |= TIO_CLOCAL;
/*
* Set lflag.
* No BSD equiv for XCASE.
*/
if (tios.c_lflag & ECHOE)
htios.c_lflag |= TIO_ECHOE;
if (tios.c_lflag & ECHOK)
htios.c_lflag |= TIO_ECHOK;
if (tios.c_lflag & ECHO)
htios.c_lflag |= TIO_ECHO;
if (tios.c_lflag & ECHONL)
htios.c_lflag |= TIO_ECHONL;
if (tios.c_lflag & ISIG)
htios.c_lflag |= TIO_ISIG;
if (tios.c_lflag & ICANON)
htios.c_lflag |= TIO_ICANON;
if (tios.c_lflag & NOFLSH)
htios.c_lflag |= TIO_NOFLSH;
/*
* Line discipline
*/
if (!newi) {
line = 0;
(void) (*ioctlrout)(fp, TIOCGETD, (caddr_t)&line, p);
htios.c_reserved = line;
}
/*
* Set editing chars.
* No BSD equiv for VSWTCH.
*/
htios.c_cc[HPUXVINTR] = tios.c_cc[VINTR];
htios.c_cc[HPUXVQUIT] = tios.c_cc[VQUIT];
htios.c_cc[HPUXVERASE] = tios.c_cc[VERASE];
htios.c_cc[HPUXVKILL] = tios.c_cc[VKILL];
htios.c_cc[HPUXVEOF] = tios.c_cc[VEOF];
htios.c_cc[HPUXVEOL] = tios.c_cc[VEOL];
htios.c_cc[HPUXVEOL2] = tios.c_cc[VEOL2];
htios.c_cc[HPUXVSWTCH] = 0;
#if 1
/*
* XXX since VMIN and VTIME are not implemented,
* we need to return something reasonable.
* Otherwise a GETA/SETA combo would always put
* the tty in non-blocking mode (since VMIN == VTIME == 0).
*/
if (fp->f_flag & FNONBLOCK) {
htios.c_cc[HPUXVMINS] = 0;
htios.c_cc[HPUXVTIMES] = 0;
} else {
htios.c_cc[HPUXVMINS] = 6;
htios.c_cc[HPUXVTIMES] = 1;
}
#else
htios.c_cc[HPUXVMINS] = tios.c_cc[VMIN];
htios.c_cc[HPUXVTIMES] = tios.c_cc[VTIME];
#endif
htios.c_cc[HPUXVSUSP] = tios.c_cc[VSUSP];
htios.c_cc[HPUXVSTART] = tios.c_cc[VSTART];
htios.c_cc[HPUXVSTOP] = tios.c_cc[VSTOP];
if (newi)
bcopy((char *)&htios, data, sizeof htios);
else
termiostotermio(&htios, (struct hpux_termio *)data);
break;
case HPUXTCSETATTR:
case HPUXTCSETATTRD:
case HPUXTCSETATTRF:
newi = 1;
/* fall into ... */
case HPUXTCSETA:
case HPUXTCSETAW:
case HPUXTCSETAF:
/*
* Get old characteristics and determine if we are a tty.
*/
if ((error = (*ioctlrout)(fp, TIOCGETA, (caddr_t)&tios, p)))
break;
if (newi)
bcopy(data, (char *)&htios, sizeof htios);
else
termiototermios((struct hpux_termio *)data,
&htios, &tios);
/*
* Set iflag.
* Same through ICRNL, no HP-UX equiv for IMAXBEL
*/
tios.c_iflag &= ~(IXON|IXOFF|IXANY|0x1ff);
tios.c_iflag |= htios.c_iflag & 0x1ff;
if (htios.c_iflag & TIO_IXON)
tios.c_iflag |= IXON;
if (htios.c_iflag & TIO_IXOFF)
tios.c_iflag |= IXOFF;
if (htios.c_iflag & TIO_IXANY)
tios.c_iflag |= IXANY;
/*
* Set oflag.
* No HP-UX equiv for ONOEOT
*/
tios.c_oflag &= ~(OPOST|ONLCR|OXTABS);
if (htios.c_oflag & TIO_OPOST)
tios.c_oflag |= OPOST;
if (htios.c_oflag & TIO_ONLCR)
tios.c_oflag |= ONLCR;
if (htios.c_oflag & TIO_TAB3)
tios.c_oflag |= OXTABS;
/*
* Set cflag.
* No HP-UX equiv for CCTS_OFLOW/CCTS_IFLOW/MDMBUF
*/
tios.c_cflag &=
~(CSIZE|CSTOPB|CREAD|PARENB|PARODD|HUPCL|CLOCAL);
switch (htios.c_cflag & TIO_CSIZE) {
case TIO_CS5:
tios.c_cflag |= CS5; break;
case TIO_CS6:
tios.c_cflag |= CS6; break;
case TIO_CS7:
tios.c_cflag |= CS7; break;
case TIO_CS8:
tios.c_cflag |= CS8; break;
}
if (htios.c_cflag & TIO_CSTOPB)
tios.c_cflag |= CSTOPB;
if (htios.c_cflag & TIO_CREAD)
tios.c_cflag |= CREAD;
if (htios.c_cflag & TIO_PARENB)
tios.c_cflag |= PARENB;
if (htios.c_cflag & TIO_PARODD)
tios.c_cflag |= PARODD;
if (htios.c_cflag & TIO_HUPCL)
tios.c_cflag |= HUPCL;
if (htios.c_cflag & TIO_CLOCAL)
tios.c_cflag |= CLOCAL;
/*
* Set lflag.
* No HP-UX equiv for ECHOKE/ECHOPRT/ECHOCTL
* IEXTEN treated as part of ICANON
*/
tios.c_lflag &= ~(ECHOE|ECHOK|ECHO|ISIG|ICANON|IEXTEN|NOFLSH);
if (htios.c_lflag & TIO_ECHOE)
tios.c_lflag |= ECHOE;
if (htios.c_lflag & TIO_ECHOK)
tios.c_lflag |= ECHOK;
if (htios.c_lflag & TIO_ECHO)
tios.c_lflag |= ECHO;
if (htios.c_lflag & TIO_ECHONL)
tios.c_lflag |= ECHONL;
if (htios.c_lflag & TIO_ISIG)
tios.c_lflag |= ISIG;
if (htios.c_lflag & TIO_ICANON)
tios.c_lflag |= (ICANON|IEXTEN);
if (htios.c_lflag & TIO_NOFLSH)
tios.c_lflag |= NOFLSH;
/*
* Set editing chars.
* No HP-UX equivs of VWERASE/VREPRINT/VDSUSP/VLNEXT
* /VDISCARD/VSTATUS/VERASE2
*/
tios.c_cc[VINTR] = htios.c_cc[HPUXVINTR];
tios.c_cc[VQUIT] = htios.c_cc[HPUXVQUIT];
tios.c_cc[VERASE] = htios.c_cc[HPUXVERASE];
tios.c_cc[VKILL] = htios.c_cc[HPUXVKILL];
tios.c_cc[VEOF] = htios.c_cc[HPUXVEOF];
tios.c_cc[VEOL] = htios.c_cc[HPUXVEOL];
tios.c_cc[VEOL2] = htios.c_cc[HPUXVEOL2];
tios.c_cc[VMIN] = htios.c_cc[HPUXVMINS];
tios.c_cc[VTIME] = htios.c_cc[HPUXVTIMES];
tios.c_cc[VSUSP] = htios.c_cc[HPUXVSUSP];
tios.c_cc[VSTART] = htios.c_cc[HPUXVSTART];
tios.c_cc[VSTOP] = htios.c_cc[HPUXVSTOP];
/*
* Set the new stuff
*/
if (com == HPUXTCSETA || com == HPUXTCSETATTR)
com = TIOCSETA;
else if (com == HPUXTCSETAW || com == HPUXTCSETATTRD)
com = TIOCSETAW;
else
com = TIOCSETAF;
error = (*ioctlrout)(fp, com, (caddr_t)&tios, p);
if (error == 0) {
/*
* Set line discipline
*/
if (!newi) {
line = htios.c_reserved;
(void) (*ioctlrout)(fp, TIOCSETD,
(caddr_t)&line, p);
}
/*
* Set non-blocking IO if VMIN == VTIME == 0, clear
* if not. Should handle the other cases as well.
* Note it isn't correct to just turn NBIO off like
* we do as it could be on as the result of a fcntl
* operation.
*
* XXX - wouldn't need to do this at all if VMIN/VTIME
* were implemented.
*/
{
struct hpux_sys_fcntl_args {
int fdes, cmd, arg;
} args;
int flags, nbio;
nbio = (htios.c_cc[HPUXVMINS] == 0 &&
htios.c_cc[HPUXVTIMES] == 0);
if ((nbio && (fp->f_flag & FNONBLOCK) == 0) ||
(!nbio && (fp->f_flag & FNONBLOCK))) {
args.fdes = fd;
args.cmd = F_GETFL;
args.arg = 0;
(void) hpux_sys_fcntl(p, &args, &flags);
if (nbio)
flags |= HPUXNDELAY;
else
flags &= ~HPUXNDELAY;
args.cmd = F_SETFL;
args.arg = flags;
(void) hpux_sys_fcntl(p, &args, &flags);
}
}
}
break;
default:
error = EINVAL;
break;
}
FRELE(fp);
return(error);
}
void
termiototermios(tio, tios, bsdtios)
struct hpux_termio *tio;
struct hpux_termios *tios;
struct termios *bsdtios;
{
int i;
bzero((char *)tios, sizeof *tios);
tios->c_iflag = tio->c_iflag;
tios->c_oflag = tio->c_oflag;
tios->c_cflag = tio->c_cflag;
tios->c_lflag = tio->c_lflag;
tios->c_reserved = tio->c_line;
for (i = 0; i <= HPUXVSWTCH; i++)
tios->c_cc[i] = tio->c_cc[i];
if (tios->c_lflag & TIO_ICANON) {
tios->c_cc[HPUXVEOF] = tio->c_cc[HPUXVEOF];
tios->c_cc[HPUXVEOL] = tio->c_cc[HPUXVEOL];
tios->c_cc[HPUXVMINS] = 0;
tios->c_cc[HPUXVTIMES] = 0;
} else {
tios->c_cc[HPUXVEOF] = 0;
tios->c_cc[HPUXVEOL] = 0;
tios->c_cc[HPUXVMINS] = tio->c_cc[HPUXVMIN];
tios->c_cc[HPUXVTIMES] = tio->c_cc[HPUXVTIME];
}
tios->c_cc[HPUXVSUSP] = bsdtios->c_cc[VSUSP];
tios->c_cc[HPUXVSTART] = bsdtios->c_cc[VSTART];
tios->c_cc[HPUXVSTOP] = bsdtios->c_cc[VSTOP];
}
void
termiostotermio(tios, tio)
struct hpux_termios *tios;
struct hpux_termio *tio;
{
int i;
tio->c_iflag = tios->c_iflag;
tio->c_oflag = tios->c_oflag;
tio->c_cflag = tios->c_cflag;
tio->c_lflag = tios->c_lflag;
tio->c_line = tios->c_reserved;
for (i = 0; i <= HPUXVSWTCH; i++)
tio->c_cc[i] = tios->c_cc[i];
if (tios->c_lflag & TIO_ICANON) {
tio->c_cc[HPUXVEOF] = tios->c_cc[HPUXVEOF];
tio->c_cc[HPUXVEOL] = tios->c_cc[HPUXVEOL];
} else {
tio->c_cc[HPUXVMIN] = tios->c_cc[HPUXVMINS];
tio->c_cc[HPUXVTIME] = tios->c_cc[HPUXVTIMES];
}
}
int
bsdtohpuxbaud(bsdspeed)
long bsdspeed;
{
switch (bsdspeed) {
case B0: return(TIO_B0);
case B50: return(TIO_B50);
case B75: return(TIO_B75);
case B110: return(TIO_B110);
case B134: return(TIO_B134);
case B150: return(TIO_B150);
case B200: return(TIO_B200);
case B300: return(TIO_B300);
case B600: return(TIO_B600);
case B1200: return(TIO_B1200);
case B1800: return(TIO_B1800);
case B2400: return(TIO_B2400);
case B4800: return(TIO_B4800);
case B9600: return(TIO_B9600);
case B19200: return(TIO_B19200);
case B38400: return(TIO_B38400);
default: return(TIO_B0);
}
}
int
hpuxtobsdbaud(hpux_speed)
int hpux_speed;
{
static const int hpuxtobsdbaudtab[32] = {
B0, B50, B75, B110, B134, B150, B200, B300,
B600, B0, B1200, B1800, B2400, B0, B4800, B0,
B9600, B19200, B38400, B0, B0, B0, B0, B0,
B0, B0, B0, B0, B0, B0, EXTA, EXTB
};
return(hpuxtobsdbaudtab[hpux_speed & TIO_CBAUD]);
}
int
hpux_sys_stty_6x(p, v, retval)
struct proc *p;
void *v;
register_t *retval;
{
struct hpux_sys_stty_6x_args /* {
syscallarg(int) fd;
syscallarg(caddr_t) arg;
} */ *uap = v;
return (getsettty(p, SCARG(uap, fd), HPUXTIOCGETP, SCARG(uap, arg)));
}
int
hpux_sys_gtty_6x(p, v, retval)
struct proc *p;
void *v;
register_t *retval;
{
struct hpux_sys_gtty_6x_args /* {
syscallarg(int) fd;
syscallarg(caddr_t) arg;
} */ *uap = v;
return (getsettty(p, SCARG(uap, fd), HPUXTIOCSETP, SCARG(uap, arg)));
}
/*
* Simplified version of ioctl() for use by
* gtty/stty and TIOCGETP/TIOCSETP.
*/
int
getsettty(p, fdes, com, cmarg)
struct proc *p;
int fdes, com;
caddr_t cmarg;
{
struct filedesc *fdp = p->p_fd;
struct file *fp;
struct hpux_sgttyb hsb;
struct sgttyb sb;
int error;
if ((fp = fd_getfile(fdp, fdes)) == NULL)
return (EBADF);
if ((fp->f_flag & (FREAD|FWRITE)) == 0)
return (EBADF);
FREF(fp);
if (com == HPUXTIOCSETP) {
if ((error = copyin(cmarg, (caddr_t)&hsb, sizeof hsb)))
goto bad;
sb.sg_ispeed = hsb.sg_ispeed;
sb.sg_ospeed = hsb.sg_ospeed;
sb.sg_erase = hsb.sg_erase;
sb.sg_kill = hsb.sg_kill;
sb.sg_flags = hsb.sg_flags & ~(V7_HUPCL|V7_XTABS|V7_NOAL);
if (hsb.sg_flags & V7_XTABS)
sb.sg_flags |= XTABS;
if (hsb.sg_flags & V7_HUPCL)
(void)(*fp->f_ops->fo_ioctl)
(fp, TIOCHPCL, (caddr_t)0, p);
com = TIOCSETP;
} else {
bzero((caddr_t)&hsb, sizeof hsb);
com = TIOCGETP;
}
error = (*fp->f_ops->fo_ioctl)(fp, com, (caddr_t)&sb, p);
if (error == 0 && com == TIOCGETP) {
hsb.sg_ispeed = sb.sg_ispeed;
hsb.sg_ospeed = sb.sg_ospeed;
hsb.sg_erase = sb.sg_erase;
hsb.sg_kill = sb.sg_kill;
hsb.sg_flags = sb.sg_flags & ~(V7_HUPCL|V7_XTABS|V7_NOAL);
if (sb.sg_flags & XTABS)
hsb.sg_flags |= V7_XTABS;
error = copyout((caddr_t)&hsb, cmarg, sizeof hsb);
}
bad:
FRELE(fp);
return (error);
}
|