10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
22*132Srobinson
230Sstevel@tonic-gate /*
24*132Srobinson * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
250Sstevel@tonic-gate * Use is subject to license terms.
260Sstevel@tonic-gate */
270Sstevel@tonic-gate
280Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
290Sstevel@tonic-gate
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate * t_sndrel.c and t_sndreldata.c are very similar and contain common code.
320Sstevel@tonic-gate * Any changes to either of them should be reviewed to see whether they
330Sstevel@tonic-gate * are applicable to the other file.
340Sstevel@tonic-gate */
350Sstevel@tonic-gate #include "mt.h"
360Sstevel@tonic-gate #include <errno.h>
370Sstevel@tonic-gate #include <stropts.h>
380Sstevel@tonic-gate #include <sys/stream.h>
390Sstevel@tonic-gate #define _SUN_TPI_VERSION 2
400Sstevel@tonic-gate #include <sys/tihdr.h>
410Sstevel@tonic-gate #include <sys/timod.h>
420Sstevel@tonic-gate #include <xti.h>
430Sstevel@tonic-gate #include <assert.h>
440Sstevel@tonic-gate #include "tx.h"
450Sstevel@tonic-gate
460Sstevel@tonic-gate int
_tx_sndreldata(int fd,struct t_discon * discon,int api_semantics)470Sstevel@tonic-gate _tx_sndreldata(int fd, struct t_discon *discon, int api_semantics)
480Sstevel@tonic-gate {
490Sstevel@tonic-gate struct T_ordrel_req orreq;
500Sstevel@tonic-gate struct strbuf ctlbuf;
510Sstevel@tonic-gate struct _ti_user *tiptr;
520Sstevel@tonic-gate
530Sstevel@tonic-gate assert(api_semantics == TX_XTI_XNS5_API);
54*132Srobinson if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == NULL)
550Sstevel@tonic-gate return (-1);
560Sstevel@tonic-gate sig_mutex_lock(&tiptr->ti_lock);
570Sstevel@tonic-gate
580Sstevel@tonic-gate if (tiptr->ti_servtype != T_COTS_ORD) {
590Sstevel@tonic-gate t_errno = TNOTSUPPORT;
600Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock);
610Sstevel@tonic-gate return (-1);
620Sstevel@tonic-gate }
630Sstevel@tonic-gate
64*132Srobinson if (!(tiptr->ti_state == T_DATAXFER ||
650Sstevel@tonic-gate tiptr->ti_state == T_INREL)) {
660Sstevel@tonic-gate t_errno = TOUTSTATE;
670Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock);
680Sstevel@tonic-gate return (-1);
690Sstevel@tonic-gate }
700Sstevel@tonic-gate
710Sstevel@tonic-gate if (_t_look_locked(fd, tiptr, 0,
720Sstevel@tonic-gate api_semantics) == T_DISCONNECT) {
730Sstevel@tonic-gate t_errno = TLOOK;
740Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock);
750Sstevel@tonic-gate return (-1);
760Sstevel@tonic-gate }
770Sstevel@tonic-gate
780Sstevel@tonic-gate /*
790Sstevel@tonic-gate * Someday there could be transport providers that support T_ORDRELDATA
800Sstevel@tonic-gate * Until that happens, this function returns TBADDATA if user data
810Sstevel@tonic-gate * was specified. If no user data is specified, this function
820Sstevel@tonic-gate * behaves as t_sndrel()
830Sstevel@tonic-gate * Note: Currently only mOSI ("minimal OSI") provider is specified
840Sstevel@tonic-gate * to use T_ORDRELDATA so probability of needing it is minimal.
850Sstevel@tonic-gate */
860Sstevel@tonic-gate
870Sstevel@tonic-gate if (discon && discon->udata.len) {
880Sstevel@tonic-gate t_errno = TBADDATA;
890Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock);
900Sstevel@tonic-gate return (-1);
910Sstevel@tonic-gate }
920Sstevel@tonic-gate
930Sstevel@tonic-gate orreq.PRIM_type = T_ORDREL_REQ;
940Sstevel@tonic-gate ctlbuf.maxlen = (int)sizeof (struct T_ordrel_req);
950Sstevel@tonic-gate ctlbuf.len = (int)sizeof (struct T_ordrel_req);
960Sstevel@tonic-gate ctlbuf.buf = (caddr_t)&orreq;
970Sstevel@tonic-gate
980Sstevel@tonic-gate /*
990Sstevel@tonic-gate * Calls to send data (write or putmsg) can potentially
1000Sstevel@tonic-gate * block, for MT case, we drop the lock and enable signals here
1010Sstevel@tonic-gate * and acquire it back
1020Sstevel@tonic-gate */
1030Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock);
1040Sstevel@tonic-gate if (putmsg(fd, &ctlbuf, NULL, 0) < 0) {
1050Sstevel@tonic-gate if (errno == EAGAIN)
1060Sstevel@tonic-gate t_errno = TFLOW;
1070Sstevel@tonic-gate else
1080Sstevel@tonic-gate t_errno = TSYSERR;
1090Sstevel@tonic-gate return (-1);
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate sig_mutex_lock(&tiptr->ti_lock);
1120Sstevel@tonic-gate _T_TX_NEXTSTATE(T_SNDREL, tiptr,
1130Sstevel@tonic-gate "t_sndreldata: invalid state on event T_SNDREL");
1140Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock);
1150Sstevel@tonic-gate return (0);
1160Sstevel@tonic-gate }
117