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
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.
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]
23 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
24 /* All Rights Reserved */
27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */
34 * t_rcvudata.c and t_rcvvudata.c are very similar and contain common code.
35 * Any changes to either of them should be reviewed to see whether they
36 * are applicable to the other file.
43 #include <sys/stream.h>
44 #define _SUN_TPI_VERSION 2
45 #include <sys/tihdr.h>
46 #include <sys/timod.h>
55 struct t_unitdata
*unitdata
,
62 union T_primitives
*pptr
;
63 struct _ti_user
*tiptr
;
68 if ((tiptr
= _t_checkfd(fd
, 0, api_semantics
)) == NULL
)
70 sig_mutex_lock(&tiptr
->ti_lock
);
72 if (tiptr
->ti_servtype
!= T_CLTS
) {
73 t_errno
= TNOTSUPPORT
;
74 sig_mutex_unlock(&tiptr
->ti_lock
);
78 if (_T_IS_XTI(api_semantics
)) {
80 * User level state verification only done for XTI
81 * because doing for TLI may break existing applications
83 if (tiptr
->ti_state
!= T_IDLE
) {
85 sig_mutex_unlock(&tiptr
->ti_lock
);
92 * check if there is something in look buffer
94 if (tiptr
->ti_lookcnt
> 0) {
95 sig_mutex_unlock(&tiptr
->ti_lock
);
101 * Acquire ctlbuf for use in sending/receiving control part
104 if (_t_acquire_ctlbuf(tiptr
, &ctlbuf
, &didalloc
) < 0) {
106 sig_mutex_unlock(&tiptr
->ti_lock
);
114 * This is a call that may block indefinitely so we drop the
115 * lock and allow signals in MT case here and reacquire it.
116 * Error case should roll back state changes done above
117 * (happens to be no state change here)
119 sig_mutex_unlock(&tiptr
->ti_lock
);
120 if ((retval
= getmsg(fd
, &ctlbuf
, (struct strbuf
*)&unitdata
->udata
,
127 sig_mutex_lock(&tiptr
->ti_lock
);
131 sig_mutex_lock(&tiptr
->ti_lock
);
133 if (((struct strbuf
*)&unitdata
->udata
)->len
== -1)
134 unitdata
->udata
.len
= 0;
137 * is there control piece with data?
139 if (ctlbuf
.len
> 0) {
140 if (ctlbuf
.len
< (int)sizeof (t_scalar_t
)) {
141 unitdata
->udata
.len
= 0;
147 /* LINTED pointer cast */
148 pptr
= (union T_primitives
*)ctlbuf
.buf
;
150 switch (pptr
->type
) {
154 (int)sizeof (struct T_unitdata_ind
)) ||
155 (pptr
->unitdata_ind
.OPT_length
&&
156 (ctlbuf
.len
< (int)(pptr
->unitdata_ind
.OPT_length
157 + pptr
->unitdata_ind
.OPT_offset
)))) {
159 unitdata
->udata
.len
= 0;
164 if (_T_IS_TLI(api_semantics
) ||
165 unitdata
->addr
.maxlen
> 0) {
166 if (TLEN_GT_NLEN(pptr
->unitdata_ind
.SRC_length
,
167 unitdata
->addr
.maxlen
)) {
169 unitdata
->udata
.len
= 0;
172 (void) memcpy(unitdata
->addr
.buf
,
173 ctlbuf
.buf
+ pptr
->unitdata_ind
.SRC_offset
,
174 (size_t)pptr
->unitdata_ind
.SRC_length
);
176 pptr
->unitdata_ind
.SRC_length
;
178 if (_T_IS_TLI(api_semantics
) ||
179 unitdata
->opt
.maxlen
> 0) {
180 if (TLEN_GT_NLEN(pptr
->unitdata_ind
.OPT_length
,
181 unitdata
->opt
.maxlen
)) {
183 unitdata
->udata
.len
= 0;
186 (void) memcpy(unitdata
->opt
.buf
, ctlbuf
.buf
+
187 pptr
->unitdata_ind
.OPT_offset
,
188 (size_t)pptr
->unitdata_ind
.OPT_length
);
190 pptr
->unitdata_ind
.OPT_length
;
192 if (retval
& MOREDATA
)
195 * No state changes happens on T_RCVUDATA
196 * event (NOOP). We do it only to log errors.
198 _T_TX_NEXTSTATE(T_RCVUDATA
, tiptr
,
199 "t_rcvudata: invalid state event T_RCVUDATA");
204 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
206 sig_mutex_unlock(&tiptr
->ti_lock
);
210 if (_t_register_lookevent(tiptr
, 0, 0, ctlbuf
.buf
,
216 unitdata
->udata
.len
= 0;
228 } else { /* else part of "if (ctlbuf.len > 0)" */
229 unitdata
->addr
.len
= 0;
230 unitdata
->opt
.len
= 0;
232 * only data in message no control piece
234 if (retval
& MOREDATA
)
237 * No state transition occurs on
238 * event T_RCVUDATA. We do it only to
241 _T_TX_NEXTSTATE(T_RCVUDATA
, tiptr
,
242 "t_rcvudata: invalid state event T_RCVUDATA");
246 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
247 sig_mutex_unlock(&tiptr
->ti_lock
);
256 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
257 sig_mutex_unlock(&tiptr
->ti_lock
);