xref: /dragonfly/sys/netproto/smb/smb_rq.h (revision e0bd597d)
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  * $FreeBSD: src/sys/netsmb/smb_rq.h,v 1.1.2.2 2002/04/23 03:45:01 bp Exp $
33  * $DragonFly: src/sys/netproto/smb/smb_rq.h,v 1.4 2005/12/06 04:03:56 dillon Exp $
34  */
35 #ifndef _NETSMB_SMB_RQ_H_
36 #define	_NETSMB_SMB_RQ_H_
37 
38 #ifndef MB_MSYSTEM
39 #include <sys/mchain.h>
40 #endif
41 
42 #define	SMBR_ALLOCED		0x0001	/* structure was malloced */
43 #define	SMBR_SENT		0x0002	/* request successfully transmitted */
44 #define	SMBR_REXMIT		0x0004	/* request should be retransmitted */
45 #define	SMBR_INTR		0x0008	/* request interrupted */
46 #define	SMBR_RESTART		0x0010	/* request should be repeated if possible */
47 #define	SMBR_NORESTART		0x0020	/* request is not restartable */
48 #define	SMBR_MULTIPACKET	0x0040	/* multiple packets can be sent and received */
49 #define	SMBR_INTERNAL		0x0080	/* request is internal to smbrqd */
50 #define	SMBR_XLOCK		0x0100	/* request locked and can't be moved */
51 #define	SMBR_XLOCKWANT		0x0200	/* waiter on XLOCK */
52 
53 #define SMBT2_ALLSENT		0x0001	/* all data and params are sent */
54 #define SMBT2_ALLRECV		0x0002	/* all data and params are received */
55 #define	SMBT2_ALLOCED		0x0004
56 #define	SMBT2_RESTART		0x0008
57 #define	SMBT2_NORESTART		0x0010
58 #define	SMBT2_SECONDARY		0x0020	/* secondary request */
59 
60 #define SMBRQ_SLOCK(rqp)	smb_sl_lock(&(rqp)->sr_slock)
61 #define SMBRQ_SUNLOCK(rqp)	smb_sl_unlock(&(rqp)->sr_slock)
62 #define SMBRQ_INTERLOCK(rqp)	(&(rqp)->sr_slock)
63 #define SMBRQ_SLOCKPTR(rqp)	(&(rqp)->sr_slock)
64 
65 
66 enum smbrq_state {
67 	SMBRQ_NOTSENT,		/* rq have data to send */
68 	SMBRQ_SENT,		/* send procedure completed */
69 	SMBRQ_REPLYRECEIVED,
70 	SMBRQ_NOTIFIED		/* owner notified about completion */
71 };
72 
73 struct smb_vc;
74 struct smb_t2rq;
75 
76 struct smb_rq {
77 	enum smbrq_state	sr_state;
78 	struct smb_vc * 	sr_vc;
79 	struct smb_share*	sr_share;
80 	u_short			sr_mid;
81 	u_int32_t		sr_seqno;
82 	u_int32_t		sr_rseqno;
83 	struct mbchain		sr_rq;
84 	u_int8_t		sr_rqflags;
85 	u_int16_t		sr_rqflags2;
86 	u_char *		sr_wcount;
87 	u_short *		sr_bcount;
88 	struct mdchain		sr_rp;
89 	int			sr_rpgen;
90 	int			sr_rplast;
91 	int			sr_flags;	/* SMBR_* */
92 	int			sr_rpsize;
93 	struct smb_cred *	sr_cred;
94 	int			sr_timo;
95 	int			sr_rexmit;
96 	int			sr_sendcnt;
97 	struct timespec 	sr_timesent;
98 	int			sr_lerror;
99 	u_int8_t *		sr_rqsig;
100 	u_int16_t *		sr_rqtid;
101 	u_int16_t *		sr_rquid;
102 	u_int8_t		sr_errclass;
103 	u_int16_t		sr_serror;
104 	u_int32_t		sr_error;
105 	u_int8_t		sr_rpflags;
106 	u_int16_t		sr_rpflags2;
107 	u_int16_t		sr_rptid;
108 	u_int16_t		sr_rppid;
109 	u_int16_t		sr_rpuid;
110 	u_int16_t		sr_rpmid;
111 	struct smb_slock	sr_slock;	/* short term locks */
112 	struct smb_t2rq *	sr_t2;
113 	TAILQ_ENTRY(smb_rq)	sr_link;
114 };
115 
116 struct smb_t2rq {
117 	u_int16_t	t2_setupcount;
118 	u_int16_t *	t2_setupdata;
119 	u_int16_t	t2_setup[2];	/* most of rqs has setupcount of 1 */
120 	u_int8_t	t2_maxscount;	/* max setup words to return */
121 	u_int16_t	t2_maxpcount;	/* max param bytes to return */
122 	u_int16_t	t2_maxdcount;	/* max data bytes to return */
123 	u_int16_t	t2_fid;		/* for T2 request */
124 	char *		t_name;		/* for T request, should be zero for T2 */
125 	int		t2_flags;	/* SMBT2_ */
126 	struct mbchain	t2_tparam;	/* parameters to transmit */
127 	struct mbchain	t2_tdata;	/* data to transmit */
128 	struct mdchain	t2_rparam;	/* received parameters */
129 	struct mdchain	t2_rdata;	/* received data */
130 	struct smb_cred*t2_cred;
131 	struct smb_connobj *t2_source;
132 	struct smb_rq *	t2_rq;
133 	struct smb_vc * t2_vc;
134 };
135 
136 int  smb_rq_alloc(struct smb_connobj *layer, u_char cmd,
137 	struct smb_cred *scred, struct smb_rq **rqpp);
138 int  smb_rq_init(struct smb_rq *rqp, struct smb_connobj *layer, u_char cmd,
139 	struct smb_cred *scred);
140 void smb_rq_done(struct smb_rq *rqp);
141 int  smb_rq_getrequest(struct smb_rq *rqp, struct mbchain **mbpp);
142 int  smb_rq_getreply(struct smb_rq *rqp, struct mdchain **mbpp);
143 void smb_rq_wstart(struct smb_rq *rqp);
144 void smb_rq_wend(struct smb_rq *rqp);
145 void smb_rq_bstart(struct smb_rq *rqp);
146 void smb_rq_bend(struct smb_rq *rqp);
147 int  smb_rq_intr(struct smb_rq *rqp);
148 int  smb_rq_simple(struct smb_rq *rqp);
149 
150 int  smb_t2_alloc(struct smb_connobj *layer, u_short setup, struct smb_cred *scred,
151 	struct smb_t2rq **rqpp);
152 int  smb_t2_init(struct smb_t2rq *rqp, struct smb_connobj *layer, u_short setup,
153 	struct smb_cred *scred);
154 void smb_t2_done(struct smb_t2rq *t2p);
155 int  smb_t2_request(struct smb_t2rq *t2p);
156 
157 #endif /* !_NETSMB_SMB_RQ_H_ */
158