xref: /illumos-gate/usr/src/uts/common/fs/smbclnt/netsmb/smb_rq.h (revision 2a8d6eba033e4713ab12b61178f0513f1f075482)
1 /*
2  * Copyright (c) 2000-2001, Boris Popov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *    This product includes software developed by Boris Popov.
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * $Id: smb_rq.h,v 1.9 2005/01/22 22:20:58 lindak Exp $
33  */
34 
35 /*
36  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
37  * Use is subject to license terms.
38  */
39 
40 #ifndef _NETSMB_SMB_RQ_H_
41 #define	_NETSMB_SMB_RQ_H_
42 
43 #include <netsmb/mchain.h>
44 #include <sys/queue.h>
45 
46 #define	SMBR_ALLOCED		0x0001	/* structure was malloced */
47 #define	SMBR_SENT		0x0002	/* request successfully transmitted */
48 #define	SMBR_REXMIT		0x0004	/* request should be retransmitted */
49 #define	SMBR_INTR		0x0008	/* request interrupted */
50 #define	SMBR_RESTART		0x0010	/* req should be repeated if possible */
51 #define	SMBR_NORESTART		0x0020	/* request is not restartable */
52 #define	SMBR_MULTIPACKET	0x0040	/* multiple pkts can be sent/received */
53 #define	SMBR_INTERNAL		0x0080	/* request is internal to netsmb */
54 #define	SMBR_NOINTR_SEND	0x0100	/* no interrupt in send wait */
55 #define	SMBR_NOINTR_RECV	0x0200	/* no interrupt in recv wait */
56 #define	SMBR_SENDWAIT		0x0400	/* waiting for send to complete */
57 #define	SMBR_VCREF		0x4000	/* took vc reference */
58 #define	SMBR_MOREDATA		0x8000	/* our buffer was too small */
59 
60 #define	SMBT2_ALLSENT		0x0001	/* all data and params are sent */
61 #define	SMBT2_ALLRECV		0x0002	/* all data and params are received */
62 #define	SMBT2_ALLOCED		0x0004
63 #define	SMBT2_RESTART		0x0008
64 #define	SMBT2_NORESTART		0x0010
65 #define	SMBT2_MOREDATA		0x8000	/* our buffer was too small */
66 
67 #define	SMBRQ_LOCK(rqp) 	mutex_enter(&(rqp)->sr_lock)
68 #define	SMBRQ_UNLOCK(rqp)	mutex_exit(&(rqp)->sr_lock)
69 
70 
71 enum smbrq_state {
72 	SMBRQ_NOTSENT,		/* rq have data to send */
73 	SMBRQ_SENT,		/* send procedure completed */
74 	SMBRQ_REPLYRECEIVED,
75 	SMBRQ_NOTIFIED		/* owner notified about completion */
76 };
77 
78 struct smb_vc;
79 
80 struct smb_rq {
81 	TAILQ_ENTRY(smb_rq)	sr_link;
82 	kmutex_t		sr_lock;
83 	kcondvar_t		sr_cond;
84 	enum smbrq_state	sr_state;
85 	struct smb_vc		*sr_vc;
86 	struct smb_share	*sr_share;
87 	struct _kthread 	*sr_owner;
88 	ushort_t		sr_mid;
89 	uint32_t		sr_seqno;	/* Seq. no. of request */
90 	uint32_t		sr_rseqno;	/* Seq. no. of reply */
91 	struct mbchain		sr_rq;
92 	uchar_t			sr_cmd;
93 	uint8_t			sr_rqflags;
94 	uint16_t		sr_rqflags2;
95 	uchar_t			*sr_wcount;
96 	uchar_t			*sr_bcount;
97 	struct mdchain		sr_rp;
98 	int			sr_rpgen;
99 	int			sr_rplast;
100 	int			sr_flags;	/* SMBR_* */
101 	int			sr_rpsize;
102 	struct smb_cred		*sr_cred;
103 	int			sr_timo;
104 	int			sr_rexmit; /* how many more retries.  dflt 0 */
105 	int			sr_sendcnt;
106 	struct timespec 	sr_timesent;
107 	int			sr_lerror;
108 	uint16_t		*sr_rqtid;
109 	uint16_t		*sr_rquid;
110 	uint8_t			sr_errclass;
111 	uint16_t		sr_serror;
112 	uint32_t		sr_error;
113 	uint8_t			sr_rpflags;
114 	uint16_t		sr_rpflags2;
115 	uint16_t		sr_rptid;
116 	uint16_t		sr_rppid;
117 	uint16_t		sr_rpuid;
118 	uint16_t		sr_rpmid;
119 };
120 typedef struct smb_rq smb_rq_t;
121 
122 struct smb_t2rq {
123 	kmutex_t	t2_lock;
124 	kcondvar_t	t2_cond;
125 	uint16_t	t2_setupcount;
126 	uint16_t	*t2_setupdata;
127 	uint16_t	t2_setup[SMB_MAXSETUPWORDS];
128 	uint8_t		t2_maxscount;	/* max setup words to return */
129 	uint16_t	t2_maxpcount;	/* max param bytes to return */
130 	uint16_t	t2_maxdcount;	/* max data bytes to return */
131 	uint16_t	t2_fid;		/* for T2 request */
132 	char		*t_name;	/* for T, must be NULL for T2 */
133 	int		t_name_len;	/* t_name string length */
134 	int		t_name_maxlen;	/* t_name allocated size */
135 	int		t2_flags;	/* SMBT2_ */
136 	struct mbchain	t2_tparam;	/* parameters to transmit */
137 	struct mbchain	t2_tdata;	/* data to transmit */
138 	struct mdchain	t2_rparam;	/* received paramters */
139 	struct mdchain	t2_rdata;	/* received data */
140 	struct smb_cred	*t2_cred;
141 	struct smb_connobj	*t2_source;
142 	struct smb_rq	*t2_rq;
143 	struct smb_vc	*t2_vc;
144 	struct smb_share *t2_share;	/* for smb up/down */
145 	/* unmapped windows error detail */
146 	uint8_t		t2_sr_errclass;
147 	uint16_t	t2_sr_serror;
148 	uint32_t	t2_sr_error;
149 	uint16_t	t2_sr_rpflags2;
150 };
151 typedef struct smb_t2rq smb_t2rq_t;
152 
153 struct smb_ntrq {
154 	kmutex_t	nt_lock;
155 	kcondvar_t	nt_cond;
156 	uint16_t	nt_function;
157 	uint8_t		nt_maxscount;	/* max setup words to return */
158 	uint32_t	nt_maxpcount;	/* max param bytes to return */
159 	uint32_t	nt_maxdcount;	/* max data bytes to return */
160 	int		nt_flags;	/* SMBT2_ */
161 	struct mbchain	nt_tsetup;	/* setup to transmit */
162 	struct mbchain	nt_tparam;	/* parameters to transmit */
163 	struct mbchain	nt_tdata;	/* data to transmit */
164 	struct mdchain	nt_rparam;	/* received paramters */
165 	struct mdchain	nt_rdata;	/* received data */
166 	struct smb_cred	*nt_cred;
167 	struct smb_connobj *nt_source;
168 	struct smb_rq	*nt_rq;
169 	struct smb_vc	*nt_vc;
170 	struct smb_share *nt_share;	/* for smb up/down */
171 	/* unmapped windows error details */
172 	uint32_t	nt_sr_error;
173 	uint16_t	nt_sr_rpflags2;
174 };
175 typedef struct smb_ntrq smb_ntrq_t;
176 
177 int   smb_rq_alloc(struct smb_connobj *layer, uchar_t cmd,
178 	struct smb_cred *scred, struct smb_rq **rqpp);
179 int  smb_rq_init(struct smb_rq *rqp, struct smb_connobj *layer,
180 	uchar_t cmd, struct smb_cred *scred);
181 void smb_rq_done(struct smb_rq *rqp);
182 int  smb_rq_getrequest(struct smb_rq *rqp, struct mbchain **mbpp);
183 int  smb_rq_getreply(struct smb_rq *rqp, struct mdchain **mbpp);
184 void smb_rq_wstart(struct smb_rq *rqp);
185 void smb_rq_wend(struct smb_rq *rqp);
186 void smb_rq_bstart(struct smb_rq *rqp);
187 void smb_rq_bend(struct smb_rq *rqp);
188 int  smb_rq_intr(struct smb_rq *rqp);
189 int  smb_rq_simple(struct smb_rq *rqp);
190 int  smb_rq_simple_timed(struct smb_rq *rqp, int timeout);
191 
192 int  smb_t2_alloc(struct smb_connobj *layer, ushort_t setup,
193 	struct smb_cred *scred, struct smb_t2rq **rqpp);
194 int  smb_t2_init(struct smb_t2rq *rqp, struct smb_connobj *layer,
195 	ushort_t *setup, int setupcnt, struct smb_cred *scred);
196 void smb_t2_done(struct smb_t2rq *t2p);
197 int  smb_t2_request(struct smb_t2rq *t2p);
198 uint32_t smb_t2_err(struct smb_t2rq *t2p);
199 
200 int  smb_nt_alloc(struct smb_connobj *layer, ushort_t fn,
201 	struct smb_cred *scred, struct smb_ntrq **rqpp);
202 int  smb_nt_init(struct smb_ntrq *rqp, struct smb_connobj *layer,
203 	ushort_t fn, struct smb_cred *scred);
204 void smb_nt_done(struct smb_ntrq *ntp);
205 int  smb_nt_request(struct smb_ntrq *ntp);
206 
207 #endif /* _NETSMB_SMB_RQ_H_ */
208