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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
37 */
38
39 #ifndef _NETSMB_SMB_RQ_H_
40 #define _NETSMB_SMB_RQ_H_
41
42 #include <netsmb/mchain.h>
43 #include <sys/queue.h>
44
45 #define SMBR_ALLOCED 0x0001 /* structure was malloced */
46 #define SMBR_SENT 0x0002 /* request successfully transmitted */
47 #define SMBR_REXMIT 0x0004 /* request should be retransmitted */
48 #define SMBR_INTR 0x0008 /* request interrupted */
49 #define SMBR_RESTART 0x0010 /* req should be repeated if possible */
50 #define SMBR_NORESTART 0x0020 /* request is not restartable */
51 #define SMBR_MULTIPACKET 0x0040 /* multiple pkts can be sent/received */
52 #define SMBR_INTERNAL 0x0080 /* request enqueued by the IOD! */
53 #define SMBR_NOINTR_SEND 0x0100 /* no interrupt in send wait */
54 #define SMBR_NOINTR_RECV 0x0200 /* no interrupt in recv wait */
55 #define SMBR_SENDWAIT 0x0400 /* waiting for send to complete */
56 #define SMBR_NORECONNECT 0x0800 /* do not reconnect for this */
57 /* SMBR_VCREF 0x4000 * took vc reference (obsolete) */
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 enum smbrq_state {
71 SMBRQ_NOTSENT, /* rq have data to send */
72 SMBRQ_SENT, /* send procedure completed */
73 SMBRQ_REPLYRECEIVED,
74 SMBRQ_NOTIFIED /* owner notified about completion */
75 };
76
77 struct smb_vc;
78
79 struct smb_rq {
80 TAILQ_ENTRY(smb_rq) sr_link;
81 kmutex_t sr_lock;
82 kcondvar_t sr_cond;
83 enum smbrq_state sr_state;
84 struct smb_vc *sr_vc;
85 struct smb_share *sr_share;
86 struct _kthread *sr_owner;
87 uint32_t sr_seqno; /* Seq. no. of request */
88 uint32_t sr_rseqno; /* Seq. no. of reply */
89 struct mbchain sr_rq;
90 uchar_t sr_cmd;
91 uint8_t sr_rqflags;
92 uint16_t sr_rqflags2;
93 uint16_t sr_rqtid;
94 uint16_t sr_pid;
95 uint16_t sr_rquid;
96 uint16_t sr_mid;
97 uchar_t *sr_wcount;
98 uchar_t *sr_bcount;
99 struct mdchain sr_rp;
100 int sr_rpgen;
101 int sr_rplast;
102 int sr_flags; /* SMBR_* */
103 int sr_rpsize;
104 struct smb_cred *sr_cred;
105 int sr_timo;
106 int sr_rexmit; /* how many more retries. dflt 0 */
107 int sr_sendcnt;
108 struct timespec sr_timesent;
109 int sr_lerror;
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[SMBIOC_T2RQ_MAXSETUP];
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;
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 #define smb_rq_getrequest(RQ, MBPP) \
178 *(MBPP) = &(RQ)->sr_rq
179 #define smb_rq_getreply(RQ, MDPP) \
180 *(MDPP) = &(RQ)->sr_rp
181
182 void smb_rq_done(struct smb_rq *rqp);
183 int smb_rq_alloc(struct smb_connobj *layer, uchar_t cmd,
184 struct smb_cred *scred, struct smb_rq **rqpp);
185 int smb_rq_init(struct smb_rq *rqp, struct smb_connobj *layer,
186 uchar_t cmd, struct smb_cred *scred);
187
188 void smb_rq_fillhdr(struct smb_rq *rqp);
189 void smb_rq_wstart(struct smb_rq *rqp);
190 void smb_rq_wend(struct smb_rq *rqp);
191 void smb_rq_bstart(struct smb_rq *rqp);
192 void smb_rq_bend(struct smb_rq *rqp);
193 int smb_rq_intr(struct smb_rq *rqp);
194 int smb_rq_simple(struct smb_rq *rqp);
195 int smb_rq_simple_timed(struct smb_rq *rqp, int timeout);
196
197 int smb_t2_alloc(struct smb_connobj *layer, ushort_t setup,
198 struct smb_cred *scred, struct smb_t2rq **rqpp);
199 int smb_t2_init(struct smb_t2rq *rqp, struct smb_connobj *layer,
200 ushort_t *setup, int setupcnt, struct smb_cred *scred);
201 void smb_t2_done(struct smb_t2rq *t2p);
202 int smb_t2_request(struct smb_t2rq *t2p);
203
204 int smb_nt_alloc(struct smb_connobj *layer, ushort_t fn,
205 struct smb_cred *scred, struct smb_ntrq **rqpp);
206 int smb_nt_init(struct smb_ntrq *rqp, struct smb_connobj *layer,
207 ushort_t fn, struct smb_cred *scred);
208 void smb_nt_done(struct smb_ntrq *ntp);
209 int smb_nt_request(struct smb_ntrq *ntp);
210
211 #endif /* _NETSMB_SMB_RQ_H_ */
|
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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
37 * Portions Copyright (C) 2001 - 2012 Apple Inc. All rights reserved.
38 * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
39 */
40
41 #ifndef _NETSMB_SMB_RQ_H_
42 #define _NETSMB_SMB_RQ_H_
43
44 #include <netsmb/mchain.h>
45 #include <sys/queue.h>
46
47 #define SMBR_ALLOCED 0x0001 /* structure was malloced */
48 #define SMBR_SENT 0x0002 /* request successfully transmitted */
49 #define SMBR_REXMIT 0x0004 /* request should be retransmitted */
50 #define SMBR_INTR 0x0008 /* request interrupted */
51 #define SMBR_RESTART 0x0010 /* req should be repeated if possible */
52 #define SMBR_NORESTART 0x0020 /* request is not restartable */
53 #define SMBR_MULTIPACKET 0x0040 /* multiple pkts can be sent/received */
54 #define SMBR_INTERNAL 0x0080 /* request enqueued by the IOD! */
55 #define SMBR_NOINTR_SEND 0x0100 /* no interrupt in send wait */
56 #define SMBR_NOINTR_RECV 0x0200 /* no interrupt in recv wait */
57 #define SMBR_SENDWAIT 0x0400 /* waiting for send to complete */
58 #define SMBR_NORECONNECT 0x0800 /* do not reconnect for this */
59 /* SMBR_VCREF 0x4000 * took vc reference (obsolete) */
60 #define SMBR_MOREDATA 0x8000 /* our buffer was too small */
61 #define SMBR_COMPOUND_RQ 0x10000 /* SMB 2/3 compound request */
62 #define SMBR_ASYNC 0x20000 /* got async response */
63 #define SMBR_RECONNECTED 0x40000 /* reconnected during request */
64
65
66 #define SMBT2_ALLSENT 0x0001 /* all data and params are sent */
67 #define SMBT2_ALLRECV 0x0002 /* all data and params are received */
68 #define SMBT2_ALLOCED 0x0004
69 #define SMBT2_RESTART 0x0008
70 #define SMBT2_NORESTART 0x0010
71 #define SMBT2_MOREDATA 0x8000 /* our buffer was too small */
72
73 #define SMBRQ_LOCK(rqp) mutex_enter(&(rqp)->sr_lock)
74 #define SMBRQ_UNLOCK(rqp) mutex_exit(&(rqp)->sr_lock)
75
76 enum smbrq_state {
77 SMBRQ_NOTSENT, /* rq have data to send */
78 SMBRQ_SENT, /* send procedure completed */
79 SMBRQ_REPLYRECEIVED,
80 SMBRQ_NOTIFIED /* owner notified about completion */
81 };
82
83 struct smb_vc;
84
85 struct smb_rq {
86 TAILQ_ENTRY(smb_rq) sr_link;
87 kmutex_t sr_lock;
88 kcondvar_t sr_cond;
89 enum smbrq_state sr_state;
90 struct smb_vc *sr_vc;
91 struct smb_share *sr_share;
92 struct _kthread *sr_owner;
93 uint32_t sr_seqno; /* Seq. no. of request */
94 uint32_t sr_rseqno; /* Seq. no. of reply */
95 struct mbchain sr_rq;
96 uchar_t sr_cmd;
97 uint8_t sr_rqflags;
98 uint16_t sr_rqflags2;
99 uint16_t sr_rqtid;
100 uint32_t sr_pid;
101 uint16_t sr_rquid;
102 uint16_t sr_mid;
103 uchar_t *sr_wcount;
104 uchar_t *sr_bcount;
105
106 /* SMB 2/3 request fields */
107 struct smb_rq *sr2_compound_next;
108 uint16_t sr2_command;
109 uint16_t sr2_totalcreditcharge;
110 uint16_t sr2_creditcharge;
111 uint16_t sr2_creditsrequested;
112 uint32_t sr2_rqflags;
113 uint32_t sr2_nextcmd;
114 uint64_t sr2_messageid; /* local copy of message id */
115 uint64_t sr2_rqsessionid;
116 uint32_t sr2_rqtreeid;
117
118 struct mdchain sr_rp;
119 int sr_rpgen;
120 int sr_rplast;
121 int sr_flags; /* SMBR_* */
122 int sr_rpsize;
123 struct smb_cred *sr_cred;
124 int sr_timo;
125 int sr_rexmit; /* how many more retries. dflt 0 */
126 int sr_sendcnt;
127 struct timespec sr_timesent;
128 int sr_lerror;
129 uint8_t sr_errclass;
130 uint16_t sr_serror;
131 uint32_t sr_error;
132 uint8_t sr_rpflags;
133 uint16_t sr_rpflags2;
134 uint16_t sr_rptid;
135 uint16_t sr_rppid;
136 uint16_t sr_rpuid;
137 uint16_t sr_rpmid;
138
139 /* SMB2 response fields */
140 uint16_t sr2_rspcreditsgranted;
141 uint32_t sr2_rspflags;
142 uint32_t sr2_rspnextcmd;
143 uint32_t sr2_rsppid;
144 uint32_t sr2_rsptreeid;
145 uint64_t sr2_rspasyncid;
146 uint64_t sr2_rspsessionid;
147 };
148 typedef struct smb_rq smb_rq_t;
149
150 struct smb_t2rq {
151 kmutex_t t2_lock;
152 kcondvar_t t2_cond;
153 uint16_t t2_setupcount;
154 uint16_t *t2_setupdata;
155 uint16_t t2_setup[4];
156 uint8_t t2_maxscount; /* max setup words to return */
157 uint16_t t2_maxpcount; /* max param bytes to return */
158 uint16_t t2_maxdcount; /* max data bytes to return */
159 uint16_t t2_fid; /* for T2 request */
160 char *t_name; /* for T, must be NULL for T2 */
161 int t_name_len; /* t_name string length */
162 int t_name_maxlen; /* t_name allocated size */
163 int t2_flags; /* SMBT2_ */
164 struct mbchain t2_tparam; /* parameters to transmit */
165 struct mbchain t2_tdata; /* data to transmit */
166 struct mdchain t2_rparam; /* received paramters */
167 struct mdchain t2_rdata; /* received data */
168 struct smb_cred *t2_cred;
169 struct smb_connobj *t2_source;
170 struct smb_rq *t2_rq;
171 struct smb_vc *t2_vc;
172 struct smb_share *t2_share; /* for smb up/down */
173 /* unmapped windows error detail */
174 uint8_t t2_sr_errclass;
175 uint16_t t2_sr_serror;
195 struct smb_connobj *nt_source;
196 struct smb_rq *nt_rq;
197 struct smb_vc *nt_vc;
198 struct smb_share *nt_share; /* for smb up/down */
199 /* unmapped windows error details */
200 uint32_t nt_sr_error;
201 uint16_t nt_sr_rpflags2;
202 };
203 typedef struct smb_ntrq smb_ntrq_t;
204
205 #define smb_rq_getrequest(RQ, MBPP) \
206 *(MBPP) = &(RQ)->sr_rq
207 #define smb_rq_getreply(RQ, MDPP) \
208 *(MDPP) = &(RQ)->sr_rp
209
210 void smb_rq_done(struct smb_rq *rqp);
211 int smb_rq_alloc(struct smb_connobj *layer, uchar_t cmd,
212 struct smb_cred *scred, struct smb_rq **rqpp);
213 int smb_rq_init(struct smb_rq *rqp, struct smb_connobj *layer,
214 uchar_t cmd, struct smb_cred *scred);
215 int smb_rq_getenv(struct smb_connobj *layer,
216 struct smb_vc **vcpp, struct smb_share **sspp);
217
218 void smb_rq_fillhdr(struct smb_rq *rqp);
219 void smb_rq_wstart(struct smb_rq *rqp);
220 void smb_rq_wend(struct smb_rq *rqp);
221 void smb_rq_bstart(struct smb_rq *rqp);
222 void smb_rq_bend(struct smb_rq *rqp);
223 int smb_rq_simple(struct smb_rq *rqp);
224 int smb_rq_simple_timed(struct smb_rq *rqp, int timeout);
225 int smb_rq_internal(struct smb_rq *rqp, int timeout);
226
227 int smb2_parse_smb1nego_resp(struct smb_rq *rqp);
228
229 int smb_t2_alloc(struct smb_connobj *layer, ushort_t setup,
230 struct smb_cred *scred, struct smb_t2rq **rqpp);
231 int smb_t2_init(struct smb_t2rq *rqp, struct smb_connobj *layer,
232 ushort_t *setup, int setupcnt, struct smb_cred *scred);
233 void smb_t2_done(struct smb_t2rq *t2p);
234 int smb_t2_request(struct smb_t2rq *t2p);
235
236 int smb_t2_xnp(struct smb_share *ssp, uint16_t fid,
237 struct mbchain *send_mb, struct mdchain *recv_md,
238 uint32_t *data_out_sz, uint32_t *more, struct smb_cred *scrp);
239
240 int smb_nt_alloc(struct smb_connobj *layer, ushort_t fn,
241 struct smb_cred *scred, struct smb_ntrq **rqpp);
242 int smb_nt_init(struct smb_ntrq *rqp, struct smb_connobj *layer,
243 ushort_t fn, struct smb_cred *scred);
244 void smb_nt_done(struct smb_ntrq *ntp);
245 int smb_nt_request(struct smb_ntrq *ntp);
246
247 #endif /* _NETSMB_SMB_RQ_H_ */
|