1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39
40 /*
41 * Kernel TLI-like function to get the state of an
42 * endpoint.
43 *
44 * Returns:
45 * 0 on success and "state" is set to the current state,
46 * or a positive error code.
47 */
48
49 #include <sys/param.h>
50 #include <sys/types.h>
51 #include <sys/proc.h>
52 #include <sys/file.h>
53 #include <sys/user.h>
54 #include <sys/vnode.h>
55 #include <sys/errno.h>
56 #include <sys/stream.h>
57 #include <sys/ioctl.h>
58 #include <sys/stropts.h>
59 #include <sys/strsubr.h>
60 #include <sys/tihdr.h>
61 #include <sys/timod.h>
62 #include <sys/tiuser.h>
63 #include <sys/t_kuser.h>
64
65
66 int
t_kgetstate(TIUSER * tiptr,int * state)67 t_kgetstate(TIUSER *tiptr, int *state)
68 {
69 struct T_info_ack inforeq;
70 struct strioctl strioc;
71 int retval;
72 vnode_t *vp;
73 file_t *fp;
74 int error;
75
76 error = 0;
77 retval = 0;
78 fp = tiptr->fp;
79 vp = fp->f_vnode;
80
81 if (state == NULL)
82 return (EINVAL);
83
84 inforeq.PRIM_type = T_INFO_REQ;
85 strioc.ic_cmd = TI_GETINFO;
86 strioc.ic_timout = 0;
87 strioc.ic_dp = (char *)&inforeq;
88 strioc.ic_len = (int)sizeof (struct T_info_req);
89
90 error = strdoioctl(vp->v_stream, &strioc, FNATIVE, K_TO_K, CRED(),
91 &retval);
92 if (error)
93 return (error);
94
95 if (retval) {
96 if ((retval & 0xff) == TSYSERR)
97 error = (retval >> 8) & 0xff;
98 else
99 error = t_tlitosyserr(retval & 0xff);
100 return (error);
101 }
102
103 if (strioc.ic_len != sizeof (struct T_info_ack))
104 return (EPROTO);
105
106 switch (inforeq.CURRENT_state) {
107 case TS_UNBND:
108 *state = T_UNBND;
109 break;
110
111 case TS_IDLE:
112 *state = T_IDLE;
113 break;
114
115 case TS_WRES_CIND:
116 *state = T_INCON;
117 break;
118
119 case TS_WCON_CREQ:
120 *state = T_OUTCON;
121 break;
122
123 case TS_DATA_XFER:
124 *state = T_DATAXFER;
125 break;
126
127 case TS_WIND_ORDREL:
128 *state = T_OUTREL;
129 break;
130
131 case TS_WREQ_ORDREL:
132 *state = T_INREL;
133 break;
134
135 default:
136 error = EPROTO;
137 break;
138 }
139 return (error);
140 }
141