xref: /titanic_41/usr/src/uts/common/ktli/t_kgtstate.c (revision 82629e3015252bf18319ba3815c773df23e21436)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
41 
42 /*
43  * Kernel TLI-like function to get the state of an
44  * endpoint.
45  *
46  * Returns:
47  * 	0 on success and "state" is set to the current state,
48  * 	or a positive error code.
49  */
50 
51 #include <sys/param.h>
52 #include <sys/types.h>
53 #include <sys/proc.h>
54 #include <sys/file.h>
55 #include <sys/user.h>
56 #include <sys/vnode.h>
57 #include <sys/errno.h>
58 #include <sys/stream.h>
59 #include <sys/ioctl.h>
60 #include <sys/stropts.h>
61 #include <sys/strsubr.h>
62 #include <sys/tihdr.h>
63 #include <sys/timod.h>
64 #include <sys/tiuser.h>
65 #include <sys/t_kuser.h>
66 
67 
68 int
69 t_kgetstate(TIUSER *tiptr, int *state)
70 {
71 	struct T_info_ack	inforeq;
72 	struct strioctl		strioc;
73 	int 			retval;
74 	vnode_t 		*vp;
75 	file_t			*fp;
76 	int			error;
77 
78 	error = 0;
79 	retval = 0;
80 	fp = tiptr->fp;
81 	vp = fp->f_vnode;
82 
83 	if (state == NULL)
84 		return (EINVAL);
85 
86 	inforeq.PRIM_type = T_INFO_REQ;
87 	strioc.ic_cmd = TI_GETINFO;
88 	strioc.ic_timout = 0;
89 	strioc.ic_dp = (char *)&inforeq;
90 	strioc.ic_len = (int)sizeof (struct T_info_req);
91 
92 	error = strdoioctl(vp->v_stream, &strioc, FNATIVE, K_TO_K, CRED(),
93 	    &retval);
94 	if (error)
95 		return (error);
96 
97 	if (retval) {
98 		if ((retval & 0xff) == TSYSERR)
99 			error = (retval >> 8) & 0xff;
100 		else
101 			error = t_tlitosyserr(retval & 0xff);
102 		return (error);
103 	}
104 
105 	if (strioc.ic_len != sizeof (struct T_info_ack))
106 		return (EPROTO);
107 
108 	switch (inforeq.CURRENT_state) {
109 	case TS_UNBND:
110 		*state = T_UNBND;
111 		break;
112 
113 	case TS_IDLE:
114 		*state = T_IDLE;
115 		break;
116 
117 	case TS_WRES_CIND:
118 		*state = T_INCON;
119 		break;
120 
121 	case TS_WCON_CREQ:
122 		*state = T_OUTCON;
123 		break;
124 
125 	case TS_DATA_XFER:
126 		*state = T_DATAXFER;
127 		break;
128 
129 	case TS_WIND_ORDREL:
130 		*state = T_OUTREL;
131 		break;
132 
133 	case TS_WREQ_ORDREL:
134 		*state = T_INREL;
135 		break;
136 
137 	default:
138 		error = EPROTO;
139 		break;
140 	}
141 	return (error);
142 }
143