1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2000-2001 Boris Popov 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 #ifndef _NETSMB_SMB_RQ_H_ 29 #define _NETSMB_SMB_RQ_H_ 30 31 #ifndef MB_MSYSTEM 32 #include <sys/mchain.h> 33 #endif 34 35 #define SMBR_ALLOCED 0x0001 /* structure was malloced */ 36 #define SMBR_SENT 0x0002 /* request successfully transmitted */ 37 #define SMBR_REXMIT 0x0004 /* request should be retransmitted */ 38 #define SMBR_INTR 0x0008 /* request interrupted */ 39 #define SMBR_RESTART 0x0010 /* request should be repeated if possible */ 40 #define SMBR_NORESTART 0x0020 /* request is not restartable */ 41 #define SMBR_MULTIPACKET 0x0040 /* multiple packets can be sent and received */ 42 #define SMBR_INTERNAL 0x0080 /* request is internal to smbrqd */ 43 #define SMBR_XLOCK 0x0100 /* request locked and can't be moved */ 44 #define SMBR_XLOCKWANT 0x0200 /* waiter on XLOCK */ 45 46 #define SMBT2_ALLSENT 0x0001 /* all data and params are sent */ 47 #define SMBT2_ALLRECV 0x0002 /* all data and params are received */ 48 #define SMBT2_ALLOCED 0x0004 49 #define SMBT2_RESTART 0x0008 50 #define SMBT2_NORESTART 0x0010 51 #define SMBT2_SECONDARY 0x0020 /* secondary request */ 52 53 #define SMBRQ_SLOCK(rqp) smb_sl_lock(&(rqp)->sr_slock) 54 #define SMBRQ_SUNLOCK(rqp) smb_sl_unlock(&(rqp)->sr_slock) 55 #define SMBRQ_SLOCKPTR(rqp) (&(rqp)->sr_slock) 56 57 enum smbrq_state { 58 SMBRQ_NOTSENT, /* rq have data to send */ 59 SMBRQ_SENT, /* send procedure completed */ 60 SMBRQ_REPLYRECEIVED, 61 SMBRQ_NOTIFIED /* owner notified about completion */ 62 }; 63 64 struct smb_vc; 65 struct smb_t2rq; 66 67 struct smb_rq { 68 enum smbrq_state sr_state; 69 struct smb_vc * sr_vc; 70 struct smb_share* sr_share; 71 u_short sr_mid; 72 u_int32_t sr_seqno; 73 u_int32_t sr_rseqno; 74 struct mbchain sr_rq; 75 u_int8_t sr_rqflags; 76 u_int16_t sr_rqflags2; 77 u_char * sr_wcount; 78 void * sr_bcount; /* Points to 2-byte buffer. */ 79 struct mdchain sr_rp; 80 int sr_rpgen; 81 int sr_rplast; 82 int sr_flags; /* SMBR_* */ 83 int sr_rpsize; 84 struct smb_cred * sr_cred; 85 int sr_timo; 86 int sr_rexmit; 87 int sr_sendcnt; 88 struct timespec sr_timesent; 89 int sr_lerror; 90 u_int8_t * sr_rqsig; 91 void * sr_rqtid; /* Points to 2-byte buffer. */ 92 void * sr_rquid; /* Points to 2-byte buffer. */ 93 u_int8_t sr_errclass; 94 u_int16_t sr_serror; 95 u_int32_t sr_error; 96 u_int8_t sr_rpflags; 97 u_int16_t sr_rpflags2; 98 u_int16_t sr_rptid; 99 u_int16_t sr_rppid; 100 u_int16_t sr_rpuid; 101 u_int16_t sr_rpmid; 102 struct smb_slock sr_slock; /* short term locks */ 103 struct smb_t2rq * sr_t2; 104 TAILQ_ENTRY(smb_rq) sr_link; 105 }; 106 107 struct smb_t2rq { 108 u_int16_t t2_setupcount; 109 u_int16_t * t2_setupdata; 110 u_int16_t t2_setup[2]; /* most of rqs has setupcount of 1 */ 111 u_int8_t t2_maxscount; /* max setup words to return */ 112 u_int16_t t2_maxpcount; /* max param bytes to return */ 113 u_int16_t t2_maxdcount; /* max data bytes to return */ 114 u_int16_t t2_fid; /* for T2 request */ 115 char * t_name; /* for T request, should be zero for T2 */ 116 int t2_flags; /* SMBT2_ */ 117 struct mbchain t2_tparam; /* parameters to transmit */ 118 struct mbchain t2_tdata; /* data to transmit */ 119 struct mdchain t2_rparam; /* received parameters */ 120 struct mdchain t2_rdata; /* received data */ 121 struct smb_cred*t2_cred; 122 struct smb_connobj *t2_source; 123 struct smb_rq * t2_rq; 124 struct smb_vc * t2_vc; 125 }; 126 127 int smb_rq_alloc(struct smb_connobj *layer, u_char cmd, 128 struct smb_cred *scred, struct smb_rq **rqpp); 129 int smb_rq_init(struct smb_rq *rqp, struct smb_connobj *layer, u_char cmd, 130 struct smb_cred *scred); 131 void smb_rq_done(struct smb_rq *rqp); 132 int smb_rq_getrequest(struct smb_rq *rqp, struct mbchain **mbpp); 133 int smb_rq_getreply(struct smb_rq *rqp, struct mdchain **mbpp); 134 void smb_rq_wstart(struct smb_rq *rqp); 135 void smb_rq_wend(struct smb_rq *rqp); 136 void smb_rq_bstart(struct smb_rq *rqp); 137 void smb_rq_bend(struct smb_rq *rqp); 138 int smb_rq_intr(struct smb_rq *rqp); 139 int smb_rq_simple(struct smb_rq *rqp); 140 141 int smb_t2_alloc(struct smb_connobj *layer, u_short setup, struct smb_cred *scred, 142 struct smb_t2rq **rqpp); 143 int smb_t2_init(struct smb_t2rq *rqp, struct smb_connobj *layer, u_short setup, 144 struct smb_cred *scred); 145 void smb_t2_done(struct smb_t2rq *t2p); 146 int smb_t2_request(struct smb_t2rq *t2p); 147 148 #endif /* !_NETSMB_SMB_RQ_H_ */ 149