Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/ptem.c
+++ new/usr/src/uts/common/io/ptem.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
21 21 */
22 22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 23 /* All Rights Reserved */
24 24
25 25
26 26 /*
27 27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 28 * Use is subject to license terms.
29 29 */
30 30
31 -#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R4 1.13 */
32 -
33 31 /*
34 32 * Description:
35 33 *
36 34 * The PTEM streams module is used as a pseudo driver emulator. Its purpose
37 35 * is to emulate the ioctl() functions of a terminal device driver.
38 36 */
39 37
40 38 #include <sys/types.h>
41 39 #include <sys/param.h>
42 40 #include <sys/stream.h>
43 41 #include <sys/stropts.h>
44 42 #include <sys/strsun.h>
45 43 #include <sys/termio.h>
46 44 #include <sys/pcb.h>
47 45 #include <sys/signal.h>
48 46 #include <sys/cred.h>
49 47 #include <sys/strtty.h>
50 48 #include <sys/errno.h>
51 49 #include <sys/cmn_err.h>
52 50 #include <sys/jioctl.h>
53 51 #include <sys/ptem.h>
54 52 #include <sys/ptms.h>
55 53 #include <sys/debug.h>
56 54 #include <sys/kmem.h>
57 55 #include <sys/ddi.h>
58 56 #include <sys/sunddi.h>
59 57 #include <sys/conf.h>
60 58 #include <sys/modctl.h>
61 59
62 60 extern struct streamtab pteminfo;
63 61
64 62 static struct fmodsw fsw = {
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
65 63 "ptem",
66 64 &pteminfo,
67 65 D_MTQPAIR | D_MP
68 66 };
69 67
70 68 static struct modlstrmod modlstrmod = {
71 69 &mod_strmodops, "pty hardware emulator", &fsw
72 70 };
73 71
74 72 static struct modlinkage modlinkage = {
75 - MODREV_1, &modlstrmod, NULL
73 + MODREV_1, { &modlstrmod, NULL }
76 74 };
77 75
78 76 int
79 77 _init()
80 78 {
81 79 return (mod_install(&modlinkage));
82 80 }
83 81
84 82 int
85 83 _fini()
86 84 {
87 85 return (mod_remove(&modlinkage));
88 86 }
89 87
90 88 int
91 89 _info(struct modinfo *modinfop)
92 90 {
93 91 return (mod_info(&modlinkage, modinfop));
94 92 }
95 93
96 94 /*
97 95 * stream data structure definitions
98 96 */
99 97 static int ptemopen(queue_t *, dev_t *, int, int, cred_t *);
100 98 static int ptemclose(queue_t *, int, cred_t *);
101 99 static void ptemrput(queue_t *, mblk_t *);
102 100 static void ptemwput(queue_t *, mblk_t *);
103 101 static void ptemwsrv(queue_t *);
104 102
105 103 static struct module_info ptem_info = {
106 104 0xabcd,
107 105 "ptem",
108 106 0,
109 107 512,
110 108 512,
111 109 128
112 110 };
113 111
114 112 static struct qinit ptemrinit = {
115 113 (int (*)()) ptemrput,
116 114 NULL,
117 115 ptemopen,
118 116 ptemclose,
119 117 NULL,
120 118 &ptem_info,
121 119 NULL
122 120 };
123 121
124 122 static struct qinit ptemwinit = {
125 123 (int (*)()) ptemwput,
126 124 (int (*)()) ptemwsrv,
127 125 ptemopen,
128 126 ptemclose,
129 127 nulldev,
130 128 &ptem_info,
131 129 NULL
132 130 };
133 131
134 132 struct streamtab pteminfo = {
135 133 &ptemrinit,
136 134 &ptemwinit,
137 135 NULL,
138 136 NULL
139 137 };
140 138
141 139 static void ptioc(queue_t *, mblk_t *, int);
142 140 static int ptemwmsg(queue_t *, mblk_t *);
143 141
144 142 /*
145 143 * ptemopen - open routine gets called when the module gets pushed onto the
146 144 * stream.
147 145 */
148 146 /* ARGSUSED */
149 147 static int
150 148 ptemopen(
151 149 queue_t *q, /* pointer to the read side queue */
152 150 dev_t *devp, /* pointer to stream tail's dev */
153 151 int oflag, /* the user open(2) supplied flags */
154 152 int sflag, /* open state flag */
155 153 cred_t *credp) /* credentials */
156 154 {
157 155 struct ptem *ntp; /* ptem entry for this PTEM module */
158 156 mblk_t *mop; /* an setopts mblk */
159 157 struct stroptions *sop;
160 158 struct termios *termiosp;
161 159 int len;
162 160
163 161 if (sflag != MODOPEN)
164 162 return (EINVAL);
165 163
166 164 if (q->q_ptr != NULL) {
167 165 /* It's already attached. */
168 166 return (0);
169 167 }
170 168
171 169 /*
172 170 * Allocate state structure.
173 171 */
174 172 ntp = kmem_alloc(sizeof (*ntp), KM_SLEEP);
175 173
176 174 /*
177 175 * Allocate a message block, used to pass the zero length message for
178 176 * "stty 0".
179 177 *
180 178 * NOTE: it's better to find out if such a message block can be
181 179 * allocated before it's needed than to not be able to
182 180 * deliver (for possible lack of buffers) when a hang-up
183 181 * occurs.
184 182 */
185 183 if ((ntp->dack_ptr = allocb(4, BPRI_MED)) == NULL) {
186 184 kmem_free(ntp, sizeof (*ntp));
187 185 return (EAGAIN);
188 186 }
189 187
190 188 /*
191 189 * Initialize an M_SETOPTS message to set up hi/lo water marks on
192 190 * stream head read queue and add controlling tty if not set.
193 191 */
194 192 mop = allocb(sizeof (struct stroptions), BPRI_MED);
195 193 if (mop == NULL) {
196 194 freemsg(ntp->dack_ptr);
197 195 kmem_free(ntp, sizeof (*ntp));
198 196 return (EAGAIN);
199 197 }
200 198 mop->b_datap->db_type = M_SETOPTS;
201 199 mop->b_wptr += sizeof (struct stroptions);
202 200 sop = (struct stroptions *)mop->b_rptr;
203 201 sop->so_flags = SO_HIWAT | SO_LOWAT | SO_ISTTY;
204 202 sop->so_hiwat = 512;
205 203 sop->so_lowat = 256;
206 204
207 205 /*
208 206 * Cross-link.
209 207 */
210 208 ntp->q_ptr = q;
211 209 q->q_ptr = ntp;
212 210 WR(q)->q_ptr = ntp;
213 211
214 212 /*
215 213 * Get termios defaults. These are stored as
216 214 * a property in the "options" node.
217 215 */
218 216 if (ddi_getlongprop(DDI_DEV_T_ANY, ddi_root_node(), 0, "ttymodes",
219 217 (caddr_t)&termiosp, &len) == DDI_PROP_SUCCESS &&
220 218 len == sizeof (struct termios)) {
221 219
222 220 ntp->cflags = termiosp->c_cflag;
223 221 kmem_free(termiosp, len);
224 222 } else {
225 223 /*
226 224 * Gack! Whine about it.
227 225 */
228 226 cmn_err(CE_WARN, "ptem: Couldn't get ttymodes property!");
229 227 }
230 228 ntp->wsz.ws_row = 0;
231 229 ntp->wsz.ws_col = 0;
232 230 ntp->wsz.ws_xpixel = 0;
233 231 ntp->wsz.ws_ypixel = 0;
234 232
235 233 ntp->state = 0;
236 234
237 235 /*
238 236 * Commit to the open and send the M_SETOPTS off to the stream head.
239 237 */
240 238 qprocson(q);
241 239 putnext(q, mop);
242 240
243 241 return (0);
244 242 }
245 243
246 244
247 245 /*
248 246 * ptemclose - This routine gets called when the module gets popped off of the
249 247 * stream.
250 248 */
251 249 /* ARGSUSED */
252 250 static int
253 251 ptemclose(queue_t *q, int flag, cred_t *credp)
254 252 {
255 253 struct ptem *ntp; /* ptem entry for this PTEM module */
256 254
257 255 qprocsoff(q);
258 256 ntp = (struct ptem *)q->q_ptr;
259 257 freemsg(ntp->dack_ptr);
260 258 kmem_free(ntp, sizeof (*ntp));
261 259 q->q_ptr = WR(q)->q_ptr = NULL;
262 260 return (0);
263 261 }
264 262
265 263
266 264 /*
267 265 * ptemrput - Module read queue put procedure.
268 266 *
269 267 * This is called from the module or driver downstream.
270 268 */
271 269 static void
272 270 ptemrput(queue_t *q, mblk_t *mp)
273 271 {
274 272 struct iocblk *iocp; /* M_IOCTL data */
275 273 struct copyresp *resp; /* transparent ioctl response struct */
276 274 int error;
277 275
278 276 switch (mp->b_datap->db_type) {
279 277 case M_DELAY:
280 278 case M_READ:
281 279 freemsg(mp);
282 280 break;
283 281
284 282 case M_IOCTL:
285 283 iocp = (struct iocblk *)mp->b_rptr;
286 284
287 285 switch (iocp->ioc_cmd) {
288 286 case TCSBRK:
289 287 /*
290 288 * Send a break message upstream.
291 289 *
292 290 * XXX: Shouldn't the argument come into play in
293 291 * determining whether or not so send an M_BREAK?
294 292 * It certainly does in the write-side direction.
295 293 */
296 294 error = miocpullup(mp, sizeof (int));
297 295 if (error != 0) {
298 296 miocnak(q, mp, 0, error);
299 297 break;
300 298 }
301 299 if (!(*(int *)mp->b_cont->b_rptr)) {
302 300 if (!putnextctl(q, M_BREAK)) {
303 301 /*
304 302 * Send an NAK reply back
305 303 */
306 304 miocnak(q, mp, 0, EAGAIN);
307 305 break;
308 306 }
309 307 }
310 308 /*
311 309 * ACK it.
312 310 */
313 311 mioc2ack(mp, NULL, 0, 0);
314 312 qreply(q, mp);
315 313 break;
316 314
317 315 case JWINSIZE:
318 316 case TIOCGWINSZ:
319 317 case TIOCSWINSZ:
320 318 ptioc(q, mp, RDSIDE);
321 319 break;
322 320
323 321 case TIOCSIGNAL:
324 322 /*
325 323 * The following subtle logic is due to the fact that
326 324 * `mp' may be in any one of three distinct formats:
327 325 *
328 326 * 1. A transparent M_IOCTL with an intptr_t-sized
329 327 * payload containing the signal number.
330 328 *
331 329 * 2. An I_STR M_IOCTL with an int-sized payload
332 330 * containing the signal number.
333 331 *
334 332 * 3. An M_IOCDATA with an int-sized payload
335 333 * containing the signal number.
336 334 */
337 335 if (iocp->ioc_count == TRANSPARENT) {
338 336 intptr_t sig = *(intptr_t *)mp->b_cont->b_rptr;
339 337
340 338 if (sig < 1 || sig >= NSIG) {
341 339 /*
342 340 * it's transparent with pointer
343 341 * to the arg
344 342 */
345 343 mcopyin(mp, NULL, sizeof (int), NULL);
346 344 qreply(q, mp);
347 345 break;
348 346 }
349 347 }
350 348 ptioc(q, mp, RDSIDE);
351 349 break;
352 350
353 351 case TIOCREMOTE:
354 352 if (iocp->ioc_count != TRANSPARENT)
355 353 ptioc(q, mp, RDSIDE);
356 354 else {
357 355 mcopyin(mp, NULL, sizeof (int), NULL);
358 356 qreply(q, mp);
359 357 }
360 358 break;
361 359
362 360 default:
363 361 putnext(q, mp);
364 362 break;
365 363 }
366 364 break;
367 365
368 366 case M_IOCDATA:
369 367 resp = (struct copyresp *)mp->b_rptr;
370 368 if (resp->cp_rval) {
371 369 /*
372 370 * Just free message on failure.
373 371 */
374 372 freemsg(mp);
375 373 break;
376 374 }
377 375
378 376 /*
379 377 * Only need to copy data for the SET case.
380 378 */
381 379 switch (resp->cp_cmd) {
382 380
383 381 case TIOCSWINSZ:
384 382 case TIOCSIGNAL:
385 383 case TIOCREMOTE:
386 384 ptioc(q, mp, RDSIDE);
387 385 break;
388 386
389 387 case JWINSIZE:
390 388 case TIOCGWINSZ:
391 389 mp->b_datap->db_type = M_IOCACK;
392 390 mioc2ack(mp, NULL, 0, 0);
393 391 qreply(q, mp);
394 392 break;
395 393
396 394 default:
397 395 freemsg(mp);
398 396 break;
399 397 }
400 398 break;
401 399
402 400 case M_IOCACK:
403 401 case M_IOCNAK:
404 402 /*
405 403 * We only pass write-side ioctls through to the master that
406 404 * we've already ACKed or NAKed to the stream head. Thus, we
407 405 * discard ones arriving from below, since they're redundant
408 406 * from the point of view of modules above us.
409 407 */
410 408 freemsg(mp);
411 409 break;
412 410
413 411 case M_HANGUP:
414 412 /*
415 413 * clear blocked state.
416 414 */
417 415 {
418 416 struct ptem *ntp = (struct ptem *)q->q_ptr;
419 417 if (ntp->state & OFLOW_CTL) {
420 418 ntp->state &= ~OFLOW_CTL;
421 419 qenable(WR(q));
422 420 }
423 421 }
424 422 default:
425 423 putnext(q, mp);
426 424 break;
427 425 }
428 426 }
429 427
430 428
431 429 /*
432 430 * ptemwput - Module write queue put procedure.
433 431 *
434 432 * This is called from the module or stream head upstream.
435 433 *
436 434 * XXX: This routine is quite lazy about handling allocation failures,
437 435 * basically just giving up and reporting failure. It really ought to
438 436 * set up bufcalls and only fail when it's absolutely necessary.
439 437 */
440 438 static void
441 439 ptemwput(queue_t *q, mblk_t *mp)
442 440 {
443 441 struct ptem *ntp = (struct ptem *)q->q_ptr;
444 442 struct iocblk *iocp; /* outgoing ioctl structure */
445 443 struct copyresp *resp;
446 444 unsigned char type = mp->b_datap->db_type;
447 445
448 446 if (type >= QPCTL) {
449 447 switch (type) {
450 448
451 449 case M_IOCDATA:
452 450 resp = (struct copyresp *)mp->b_rptr;
453 451 if (resp->cp_rval) {
454 452 /*
455 453 * Just free message on failure.
456 454 */
457 455 freemsg(mp);
458 456 break;
459 457 }
460 458
461 459 /*
462 460 * Only need to copy data for the SET case.
463 461 */
464 462 switch (resp->cp_cmd) {
465 463
466 464 case TIOCSWINSZ:
467 465 ptioc(q, mp, WRSIDE);
468 466 break;
469 467
470 468 case JWINSIZE:
471 469 case TIOCGWINSZ:
472 470 mioc2ack(mp, NULL, 0, 0);
473 471 qreply(q, mp);
474 472 break;
475 473
476 474 default:
477 475 freemsg(mp);
478 476 }
479 477 break;
480 478
481 479 case M_FLUSH:
482 480 if (*mp->b_rptr & FLUSHW) {
483 481 if ((ntp->state & IS_PTSTTY) &&
484 482 (*mp->b_rptr & FLUSHBAND))
485 483 flushband(q, *(mp->b_rptr + 1), FLUSHDATA);
486 484 else
487 485 flushq(q, FLUSHDATA);
488 486 }
489 487 putnext(q, mp);
490 488 break;
491 489
492 490 case M_READ:
493 491 freemsg(mp);
494 492 break;
495 493
496 494 case M_STOP:
497 495 /*
498 496 * Set the output flow control state.
499 497 */
500 498 ntp->state |= OFLOW_CTL;
501 499 putnext(q, mp);
502 500 break;
503 501
504 502 case M_START:
505 503 /*
506 504 * Relieve the output flow control state.
507 505 */
508 506 ntp->state &= ~OFLOW_CTL;
509 507 putnext(q, mp);
510 508 qenable(q);
511 509 break;
512 510 default:
513 511 putnext(q, mp);
514 512 break;
515 513 }
516 514 return;
517 515 }
518 516 /*
519 517 * If our queue is nonempty or flow control persists
520 518 * downstream or module in stopped state, queue this message.
521 519 */
522 520 if (q->q_first != NULL || !bcanputnext(q, mp->b_band)) {
523 521 /*
524 522 * Exception: ioctls, except for those defined to
525 523 * take effect after output has drained, should be
526 524 * processed immediately.
527 525 */
528 526 switch (type) {
529 527
530 528 case M_IOCTL:
531 529 iocp = (struct iocblk *)mp->b_rptr;
532 530 switch (iocp->ioc_cmd) {
533 531 /*
534 532 * Queue these.
535 533 */
536 534 case TCSETSW:
537 535 case TCSETSF:
538 536 case TCSETAW:
539 537 case TCSETAF:
540 538 case TCSBRK:
541 539 break;
542 540
543 541 /*
544 542 * Handle all others immediately.
545 543 */
546 544 default:
547 545 (void) ptemwmsg(q, mp);
548 546 return;
549 547 }
550 548 break;
551 549
552 550 case M_DELAY: /* tty delays not supported */
553 551 freemsg(mp);
554 552 return;
555 553
556 554 case M_DATA:
557 555 if ((mp->b_wptr - mp->b_rptr) < 0) {
558 556 /*
559 557 * Free all bad length messages.
560 558 */
561 559 freemsg(mp);
562 560 return;
563 561 } else if ((mp->b_wptr - mp->b_rptr) == 0) {
564 562 if (!(ntp->state & IS_PTSTTY)) {
565 563 freemsg(mp);
566 564 return;
567 565 }
568 566 }
569 567 }
570 568 (void) putq(q, mp);
571 569 return;
572 570 }
573 571 /*
574 572 * fast path into ptemwmsg to dispose of mp.
575 573 */
576 574 if (!ptemwmsg(q, mp))
577 575 (void) putq(q, mp);
578 576 }
579 577
580 578 /*
581 579 * ptem write queue service procedure.
582 580 */
583 581 static void
584 582 ptemwsrv(queue_t *q)
585 583 {
586 584 mblk_t *mp;
587 585
588 586 while ((mp = getq(q)) != NULL) {
589 587 if (!bcanputnext(q, mp->b_band) || !ptemwmsg(q, mp)) {
590 588 (void) putbq(q, mp);
591 589 break;
592 590 }
593 591 }
594 592 }
595 593
596 594
597 595 /*
598 596 * This routine is called from both ptemwput and ptemwsrv to do the
599 597 * actual work of dealing with mp. ptmewput will have already
600 598 * dealt with high priority messages.
601 599 *
602 600 * Return 1 if the message was processed completely and 0 if not.
603 601 */
604 602 static int
605 603 ptemwmsg(queue_t *q, mblk_t *mp)
606 604 {
607 605 struct ptem *ntp = (struct ptem *)q->q_ptr;
608 606 struct iocblk *iocp; /* outgoing ioctl structure */
609 607 struct termio *termiop;
610 608 struct termios *termiosp;
611 609 mblk_t *dack_ptr; /* disconnect message ACK block */
612 610 mblk_t *pckt_msgp; /* message sent to the PCKT module */
613 611 mblk_t *dp; /* ioctl reply data */
614 612 tcflag_t cflags;
615 613 int error;
616 614
617 615 switch (mp->b_datap->db_type) {
618 616
619 617 case M_IOCTL:
620 618 /*
621 619 * Note: for each "set" type operation a copy
622 620 * of the M_IOCTL message is made and passed
623 621 * downstream. Eventually the PCKT module, if
624 622 * it has been pushed, should pick up this message.
625 623 * If the PCKT module has not been pushed the master
626 624 * side stream head will free it.
627 625 */
628 626 iocp = (struct iocblk *)mp->b_rptr;
629 627 switch (iocp->ioc_cmd) {
630 628
631 629 case TCSETAF:
632 630 case TCSETSF:
633 631 /*
634 632 * Flush the read queue.
635 633 */
636 634 if (putnextctl1(q, M_FLUSH, FLUSHR) == 0) {
637 635 miocnak(q, mp, 0, EAGAIN);
638 636 break;
639 637 }
640 638 /* FALLTHROUGH */
641 639
642 640 case TCSETA:
643 641 case TCSETAW:
644 642 case TCSETS:
645 643 case TCSETSW:
646 644
647 645 switch (iocp->ioc_cmd) {
648 646 case TCSETAF:
649 647 case TCSETA:
650 648 case TCSETAW:
651 649 error = miocpullup(mp, sizeof (struct termio));
652 650 if (error != 0) {
653 651 miocnak(q, mp, 0, error);
654 652 goto out;
655 653 }
656 654 cflags = ((struct termio *)
657 655 mp->b_cont->b_rptr)->c_cflag;
658 656 ntp->cflags =
659 657 (ntp->cflags & 0xffff0000 | cflags);
660 658 break;
661 659
662 660 case TCSETSF:
663 661 case TCSETS:
664 662 case TCSETSW:
665 663 error = miocpullup(mp, sizeof (struct termios));
666 664 if (error != 0) {
667 665 miocnak(q, mp, 0, error);
668 666 goto out;
669 667 }
670 668 cflags = ((struct termios *)
671 669 mp->b_cont->b_rptr)->c_cflag;
672 670 ntp->cflags = cflags;
673 671 break;
674 672 }
675 673
676 674 if ((cflags & CBAUD) == B0) {
677 675 /*
678 676 * Hang-up: Send a zero length message.
679 677 */
680 678 dack_ptr = ntp->dack_ptr;
681 679
682 680 if (dack_ptr) {
683 681 ntp->dack_ptr = NULL;
684 682 /*
685 683 * Send a zero length message
686 684 * downstream.
687 685 */
688 686 putnext(q, dack_ptr);
689 687 }
690 688 } else {
691 689 /*
692 690 * Make a copy of this message and pass it on
693 691 * to the PCKT module.
694 692 */
695 693 if ((pckt_msgp = copymsg(mp)) == NULL) {
696 694 miocnak(q, mp, 0, EAGAIN);
697 695 break;
698 696 }
699 697 putnext(q, pckt_msgp);
700 698 }
701 699 /*
702 700 * Send ACK upstream.
703 701 */
704 702 mioc2ack(mp, NULL, 0, 0);
705 703 qreply(q, mp);
706 704 out:
707 705 break;
708 706
709 707 case TCGETA:
710 708 dp = allocb(sizeof (struct termio), BPRI_MED);
711 709 if (dp == NULL) {
712 710 miocnak(q, mp, 0, EAGAIN);
713 711 break;
714 712 }
715 713 termiop = (struct termio *)dp->b_rptr;
716 714 termiop->c_cflag = (ushort_t)ntp->cflags;
717 715 mioc2ack(mp, dp, sizeof (struct termio), 0);
718 716 qreply(q, mp);
719 717 break;
720 718
721 719 case TCGETS:
722 720 dp = allocb(sizeof (struct termios), BPRI_MED);
723 721 if (dp == NULL) {
724 722 miocnak(q, mp, 0, EAGAIN);
725 723 break;
726 724 }
727 725 termiosp = (struct termios *)dp->b_rptr;
728 726 termiosp->c_cflag = ntp->cflags;
729 727 mioc2ack(mp, dp, sizeof (struct termios), 0);
730 728 qreply(q, mp);
731 729 break;
732 730
733 731 case TCSBRK:
734 732 error = miocpullup(mp, sizeof (int));
735 733 if (error != 0) {
736 734 miocnak(q, mp, 0, error);
737 735 break;
738 736 }
739 737
740 738 /*
741 739 * Need a copy of this message to pass it on to
742 740 * the PCKT module.
743 741 */
744 742 if ((pckt_msgp = copymsg(mp)) == NULL) {
745 743 miocnak(q, mp, 0, EAGAIN);
746 744 break;
747 745 }
748 746 /*
749 747 * Send a copy of the M_IOCTL to the PCKT module.
750 748 */
751 749 putnext(q, pckt_msgp);
752 750
753 751 /*
754 752 * TCSBRK meaningful if data part of message is 0
755 753 * cf. termio(7).
756 754 */
757 755 if (!(*(int *)mp->b_cont->b_rptr))
758 756 (void) putnextctl(q, M_BREAK);
759 757 /*
760 758 * ACK the ioctl.
761 759 */
762 760 mioc2ack(mp, NULL, 0, 0);
763 761 qreply(q, mp);
764 762 break;
765 763
766 764 case JWINSIZE:
767 765 case TIOCGWINSZ:
768 766 case TIOCSWINSZ:
769 767 ptioc(q, mp, WRSIDE);
770 768 break;
771 769
772 770 case TIOCSTI:
773 771 /*
774 772 * Simulate typing of a character at the terminal. In
775 773 * all cases, we acknowledge the ioctl and pass a copy
776 774 * of it along for the PCKT module to encapsulate. If
777 775 * not in remote mode, we also process the ioctl
778 776 * itself, looping the character given as its argument
779 777 * back around to the read side.
780 778 */
781 779
782 780 /*
783 781 * Need a copy of this message to pass on to the PCKT
784 782 * module.
785 783 */
786 784 if ((pckt_msgp = copymsg(mp)) == NULL) {
787 785 miocnak(q, mp, 0, EAGAIN);
788 786 break;
789 787 }
790 788 if ((ntp->state & REMOTEMODE) == 0) {
791 789 mblk_t *bp;
792 790
793 791 error = miocpullup(mp, sizeof (char));
794 792 if (error != 0) {
795 793 freemsg(pckt_msgp);
796 794 miocnak(q, mp, 0, error);
797 795 break;
798 796 }
799 797
800 798 /*
801 799 * The permission checking has already been
802 800 * done at the stream head, since it has to be
803 801 * done in the context of the process doing
804 802 * the call.
805 803 */
806 804 if ((bp = allocb(1, BPRI_MED)) == NULL) {
807 805 freemsg(pckt_msgp);
808 806 miocnak(q, mp, 0, EAGAIN);
809 807 break;
810 808 }
811 809 /*
812 810 * XXX: Is EAGAIN really the right response to
813 811 * flow control blockage?
814 812 */
815 813 if (!bcanputnext(RD(q), mp->b_band)) {
816 814 freemsg(bp);
817 815 freemsg(pckt_msgp);
818 816 miocnak(q, mp, 0, EAGAIN);
819 817 break;
820 818 }
821 819 *bp->b_wptr++ = *mp->b_cont->b_rptr;
822 820 qreply(q, bp);
823 821 }
824 822
825 823 putnext(q, pckt_msgp);
826 824 mioc2ack(mp, NULL, 0, 0);
827 825 qreply(q, mp);
828 826 break;
829 827
830 828 case PTSSTTY:
831 829 if (ntp->state & IS_PTSTTY) {
832 830 miocnak(q, mp, 0, EEXIST);
833 831 } else {
834 832 ntp->state |= IS_PTSTTY;
835 833 mioc2ack(mp, NULL, 0, 0);
836 834 qreply(q, mp);
837 835 }
838 836 break;
839 837
840 838 default:
841 839 /*
842 840 * End of the line. The slave driver doesn't see any
843 841 * ioctls that we don't explicitly pass along to it.
844 842 */
845 843 miocnak(q, mp, 0, EINVAL);
846 844 break;
847 845 }
848 846 break;
849 847
850 848 case M_DELAY: /* tty delays not supported */
851 849 freemsg(mp);
852 850 break;
853 851
854 852 case M_DATA:
855 853 if ((mp->b_wptr - mp->b_rptr) < 0) {
856 854 /*
857 855 * Free all bad length messages.
858 856 */
859 857 freemsg(mp);
860 858 break;
861 859 } else if ((mp->b_wptr - mp->b_rptr) == 0) {
862 860 if (!(ntp->state & IS_PTSTTY)) {
863 861 freemsg(mp);
864 862 break;
865 863 }
866 864 }
867 865 if (ntp->state & OFLOW_CTL)
868 866 return (0);
869 867
870 868 default:
871 869 putnext(q, mp);
872 870 break;
873 871
874 872 }
875 873
876 874 return (1);
877 875 }
878 876
879 877 /*
880 878 * Message must be of type M_IOCTL or M_IOCDATA for this routine to be called.
881 879 */
882 880 static void
883 881 ptioc(queue_t *q, mblk_t *mp, int qside)
884 882 {
885 883 struct ptem *tp;
886 884 struct iocblk *iocp;
887 885 struct winsize *wb;
888 886 struct jwinsize *jwb;
889 887 mblk_t *tmp;
890 888 mblk_t *pckt_msgp; /* message sent to the PCKT module */
891 889 int error;
892 890
893 891 iocp = (struct iocblk *)mp->b_rptr;
894 892 tp = (struct ptem *)q->q_ptr;
895 893
896 894 switch (iocp->ioc_cmd) {
897 895
898 896 case JWINSIZE:
899 897 /*
900 898 * For compatibility: If all zeros, NAK the message for dumb
901 899 * terminals.
902 900 */
903 901 if ((tp->wsz.ws_row == 0) && (tp->wsz.ws_col == 0) &&
904 902 (tp->wsz.ws_xpixel == 0) && (tp->wsz.ws_ypixel == 0)) {
905 903 miocnak(q, mp, 0, EINVAL);
906 904 return;
907 905 }
908 906
909 907 tmp = allocb(sizeof (struct jwinsize), BPRI_MED);
910 908 if (tmp == NULL) {
911 909 miocnak(q, mp, 0, EAGAIN);
912 910 return;
913 911 }
914 912
915 913 if (iocp->ioc_count == TRANSPARENT)
916 914 mcopyout(mp, NULL, sizeof (struct jwinsize), NULL, tmp);
917 915 else
918 916 mioc2ack(mp, tmp, sizeof (struct jwinsize), 0);
919 917
920 918 jwb = (struct jwinsize *)mp->b_cont->b_rptr;
921 919 jwb->bytesx = tp->wsz.ws_col;
922 920 jwb->bytesy = tp->wsz.ws_row;
923 921 jwb->bitsx = tp->wsz.ws_xpixel;
924 922 jwb->bitsy = tp->wsz.ws_ypixel;
925 923
926 924 qreply(q, mp);
927 925 return;
928 926
929 927 case TIOCGWINSZ:
930 928 /*
931 929 * If all zeros NAK the message for dumb terminals.
932 930 */
933 931 if ((tp->wsz.ws_row == 0) && (tp->wsz.ws_col == 0) &&
934 932 (tp->wsz.ws_xpixel == 0) && (tp->wsz.ws_ypixel == 0)) {
935 933 miocnak(q, mp, 0, EINVAL);
936 934 return;
937 935 }
938 936
939 937 tmp = allocb(sizeof (struct winsize), BPRI_MED);
940 938 if (tmp == NULL) {
941 939 miocnak(q, mp, 0, EAGAIN);
942 940 return;
943 941 }
944 942
945 943 mioc2ack(mp, tmp, sizeof (struct winsize), 0);
946 944
947 945 wb = (struct winsize *)mp->b_cont->b_rptr;
948 946 wb->ws_row = tp->wsz.ws_row;
949 947 wb->ws_col = tp->wsz.ws_col;
950 948 wb->ws_xpixel = tp->wsz.ws_xpixel;
951 949 wb->ws_ypixel = tp->wsz.ws_ypixel;
952 950
953 951 qreply(q, mp);
954 952 return;
955 953
956 954 case TIOCSWINSZ:
957 955 error = miocpullup(mp, sizeof (struct winsize));
958 956 if (error != 0) {
959 957 miocnak(q, mp, 0, error);
960 958 return;
961 959 }
962 960
963 961 wb = (struct winsize *)mp->b_cont->b_rptr;
964 962 /*
965 963 * Send a SIGWINCH signal if the row/col information has
966 964 * changed.
967 965 */
968 966 if ((tp->wsz.ws_row != wb->ws_row) ||
969 967 (tp->wsz.ws_col != wb->ws_col) ||
970 968 (tp->wsz.ws_xpixel != wb->ws_xpixel) ||
971 969 (tp->wsz.ws_ypixel != wb->ws_xpixel)) {
972 970 /*
973 971 * SIGWINCH is always sent upstream.
974 972 */
975 973 if (qside == WRSIDE)
976 974 (void) putnextctl1(RD(q), M_SIG, SIGWINCH);
977 975 else if (qside == RDSIDE)
978 976 (void) putnextctl1(q, M_SIG, SIGWINCH);
979 977 /*
980 978 * Message may have come in as an M_IOCDATA; pass it
981 979 * to the master side as an M_IOCTL.
982 980 */
983 981 mp->b_datap->db_type = M_IOCTL;
984 982 if (qside == WRSIDE) {
985 983 /*
986 984 * Need a copy of this message to pass on to
987 985 * the PCKT module, only if the M_IOCTL
988 986 * orginated from the slave side.
989 987 */
990 988 if ((pckt_msgp = copymsg(mp)) == NULL) {
991 989 miocnak(q, mp, 0, EAGAIN);
992 990 return;
993 991 }
994 992 putnext(q, pckt_msgp);
995 993 }
996 994 tp->wsz.ws_row = wb->ws_row;
997 995 tp->wsz.ws_col = wb->ws_col;
998 996 tp->wsz.ws_xpixel = wb->ws_xpixel;
999 997 tp->wsz.ws_ypixel = wb->ws_ypixel;
1000 998 }
1001 999
1002 1000 mioc2ack(mp, NULL, 0, 0);
1003 1001 qreply(q, mp);
1004 1002 return;
1005 1003
1006 1004 case TIOCSIGNAL: {
1007 1005 /*
1008 1006 * This ioctl can emanate from the master side in remote
1009 1007 * mode only.
1010 1008 */
1011 1009 int sig;
1012 1010
1013 1011 if (DB_TYPE(mp) == M_IOCTL && iocp->ioc_count != TRANSPARENT) {
1014 1012 error = miocpullup(mp, sizeof (int));
1015 1013 if (error != 0) {
1016 1014 miocnak(q, mp, 0, error);
1017 1015 return;
1018 1016 }
1019 1017 }
1020 1018
1021 1019 if (DB_TYPE(mp) == M_IOCDATA || iocp->ioc_count != TRANSPARENT)
1022 1020 sig = *(int *)mp->b_cont->b_rptr;
1023 1021 else
1024 1022 sig = (int)*(intptr_t *)mp->b_cont->b_rptr;
1025 1023
1026 1024 if (sig < 1 || sig >= NSIG) {
1027 1025 miocnak(q, mp, 0, EINVAL);
1028 1026 return;
1029 1027 }
1030 1028
1031 1029 /*
1032 1030 * Send an M_PCSIG message up the slave's read side and
1033 1031 * respond back to the master with an ACK or NAK as
1034 1032 * appropriate.
1035 1033 */
1036 1034 if (putnextctl1(q, M_PCSIG, sig) == 0) {
1037 1035 miocnak(q, mp, 0, EAGAIN);
1038 1036 return;
1039 1037 }
1040 1038
1041 1039 mioc2ack(mp, NULL, 0, 0);
1042 1040 qreply(q, mp);
1043 1041 return;
1044 1042 }
1045 1043
1046 1044 case TIOCREMOTE: {
1047 1045 int onoff;
1048 1046 mblk_t *mctlp;
1049 1047
1050 1048 if (DB_TYPE(mp) == M_IOCTL) {
1051 1049 error = miocpullup(mp, sizeof (int));
1052 1050 if (error != 0) {
1053 1051 miocnak(q, mp, 0, error);
1054 1052 return;
1055 1053 }
1056 1054 }
1057 1055
1058 1056 onoff = *(int *)mp->b_cont->b_rptr;
1059 1057
1060 1058 /*
1061 1059 * Send M_CTL up using the iocblk format.
1062 1060 */
1063 1061 mctlp = mkiocb(onoff ? MC_NO_CANON : MC_DO_CANON);
1064 1062 if (mctlp == NULL) {
1065 1063 miocnak(q, mp, 0, EAGAIN);
1066 1064 return;
1067 1065 }
1068 1066 mctlp->b_datap->db_type = M_CTL;
1069 1067 putnext(q, mctlp);
1070 1068
1071 1069 /*
1072 1070 * ACK the ioctl.
1073 1071 */
1074 1072 mioc2ack(mp, NULL, 0, 0);
1075 1073 qreply(q, mp);
1076 1074
1077 1075 /*
1078 1076 * Record state change.
1079 1077 */
1080 1078 if (onoff)
1081 1079 tp->state |= REMOTEMODE;
1082 1080 else
1083 1081 tp->state &= ~REMOTEMODE;
1084 1082 return;
1085 1083 }
1086 1084
1087 1085 default:
1088 1086 putnext(q, mp);
1089 1087 return;
1090 1088 }
1091 1089 }
↓ open down ↓ |
1006 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX