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