1139823Simp/*-
2206361Sjoel * Copyright (c) 2000-2001 Boris Popov
375374Sbp * All rights reserved.
475374Sbp *
575374Sbp * Redistribution and use in source and binary forms, with or without
675374Sbp * modification, are permitted provided that the following conditions
775374Sbp * are met:
875374Sbp * 1. Redistributions of source code must retain the above copyright
975374Sbp *    notice, this list of conditions and the following disclaimer.
1075374Sbp * 2. Redistributions in binary form must reproduce the above copyright
1175374Sbp *    notice, this list of conditions and the following disclaimer in the
1275374Sbp *    documentation and/or other materials provided with the distribution.
1375374Sbp *
1475374Sbp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1575374Sbp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1675374Sbp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1775374Sbp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1875374Sbp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1975374Sbp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2075374Sbp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2175374Sbp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2275374Sbp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2375374Sbp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2475374Sbp * SUCH DAMAGE.
2575374Sbp *
2675374Sbp * $FreeBSD$
2775374Sbp */
2875374Sbp#ifndef _NETSMB_SMB_RQ_H_
2975374Sbp#define	_NETSMB_SMB_RQ_H_
3075374Sbp
3175374Sbp#ifndef MB_MSYSTEM
3275374Sbp#include <sys/mchain.h>
3375374Sbp#endif
3475374Sbp
3575374Sbp#define	SMBR_ALLOCED		0x0001	/* structure was malloced */
3675374Sbp#define	SMBR_SENT		0x0002	/* request successfully transmitted */
3775374Sbp#define	SMBR_REXMIT		0x0004	/* request should be retransmitted */
3875374Sbp#define	SMBR_INTR		0x0008	/* request interrupted */
3975374Sbp#define	SMBR_RESTART		0x0010	/* request should be repeated if possible */
4075374Sbp#define	SMBR_NORESTART		0x0020	/* request is not restartable */
4175374Sbp#define	SMBR_MULTIPACKET	0x0040	/* multiple packets can be sent and received */
4275374Sbp#define	SMBR_INTERNAL		0x0080	/* request is internal to smbrqd */
4375374Sbp#define	SMBR_XLOCK		0x0100	/* request locked and can't be moved */
4475374Sbp#define	SMBR_XLOCKWANT		0x0200	/* waiter on XLOCK */
4575374Sbp
4675374Sbp#define SMBT2_ALLSENT		0x0001	/* all data and params are sent */
4775374Sbp#define SMBT2_ALLRECV		0x0002	/* all data and params are received */
4875374Sbp#define	SMBT2_ALLOCED		0x0004
4975374Sbp#define	SMBT2_RESTART		0x0008
5075374Sbp#define	SMBT2_NORESTART		0x0010
51124087Stjr#define	SMBT2_SECONDARY		0x0020	/* secondary request */
5275374Sbp
5375374Sbp#define SMBRQ_SLOCK(rqp)	smb_sl_lock(&(rqp)->sr_slock)
5475374Sbp#define SMBRQ_SUNLOCK(rqp)	smb_sl_unlock(&(rqp)->sr_slock)
5575374Sbp#define SMBRQ_SLOCKPTR(rqp)	(&(rqp)->sr_slock)
5675374Sbp
5775374Sbp
5875374Sbpenum smbrq_state {
5975374Sbp	SMBRQ_NOTSENT,		/* rq have data to send */
6075374Sbp	SMBRQ_SENT,		/* send procedure completed */
6175374Sbp	SMBRQ_REPLYRECEIVED,
6275374Sbp	SMBRQ_NOTIFIED		/* owner notified about completion */
6375374Sbp};
6475374Sbp
6575374Sbpstruct smb_vc;
6675374Sbpstruct smb_t2rq;
6775374Sbp
6875374Sbpstruct smb_rq {
6975374Sbp	enum smbrq_state	sr_state;
7075374Sbp	struct smb_vc * 	sr_vc;
7175374Sbp	struct smb_share*	sr_share;
7275374Sbp	u_short			sr_mid;
73124087Stjr	u_int32_t		sr_seqno;
74124087Stjr	u_int32_t		sr_rseqno;
7575374Sbp	struct mbchain		sr_rq;
7675374Sbp	u_int8_t		sr_rqflags;
7775374Sbp	u_int16_t		sr_rqflags2;
7875374Sbp	u_char *		sr_wcount;
79161523Smarcel	void *			sr_bcount;	/* Points to 2-byte buffer. */
8075374Sbp	struct mdchain		sr_rp;
8175374Sbp	int			sr_rpgen;
8275374Sbp	int			sr_rplast;
8375374Sbp	int			sr_flags;	/* SMBR_* */
8475374Sbp	int			sr_rpsize;
8575374Sbp	struct smb_cred *	sr_cred;
8675374Sbp	int			sr_timo;
8775374Sbp	int			sr_rexmit;
8875374Sbp	int			sr_sendcnt;
8975374Sbp	struct timespec 	sr_timesent;
9075374Sbp	int			sr_lerror;
91124087Stjr	u_int8_t *		sr_rqsig;
92161523Smarcel	void *			sr_rqtid;	/* Points to 2-byte buffer. */
93161523Smarcel	void *			sr_rquid;	/* Points to 2-byte buffer. */
9475374Sbp	u_int8_t		sr_errclass;
9575374Sbp	u_int16_t		sr_serror;
9675374Sbp	u_int32_t		sr_error;
9775374Sbp	u_int8_t		sr_rpflags;
9875374Sbp	u_int16_t		sr_rpflags2;
9975374Sbp	u_int16_t		sr_rptid;
10075374Sbp	u_int16_t		sr_rppid;
10175374Sbp	u_int16_t		sr_rpuid;
10275374Sbp	u_int16_t		sr_rpmid;
10375374Sbp	struct smb_slock	sr_slock;	/* short term locks */
104124087Stjr	struct smb_t2rq *	sr_t2;
10575374Sbp	TAILQ_ENTRY(smb_rq)	sr_link;
10675374Sbp};
10775374Sbp
10875374Sbpstruct smb_t2rq {
10975374Sbp	u_int16_t	t2_setupcount;
11075374Sbp	u_int16_t *	t2_setupdata;
11175374Sbp	u_int16_t	t2_setup[2];	/* most of rqs has setupcount of 1 */
11275374Sbp	u_int8_t	t2_maxscount;	/* max setup words to return */
11375374Sbp	u_int16_t	t2_maxpcount;	/* max param bytes to return */
11475374Sbp	u_int16_t	t2_maxdcount;	/* max data bytes to return */
11575374Sbp	u_int16_t	t2_fid;		/* for T2 request */
11675374Sbp	char *		t_name;		/* for T request, should be zero for T2 */
11775374Sbp	int		t2_flags;	/* SMBT2_ */
11875374Sbp	struct mbchain	t2_tparam;	/* parameters to transmit */
11975374Sbp	struct mbchain	t2_tdata;	/* data to transmit */
12088741Sbp	struct mdchain	t2_rparam;	/* received parameters */
12175374Sbp	struct mdchain	t2_rdata;	/* received data */
12275374Sbp	struct smb_cred*t2_cred;
12375374Sbp	struct smb_connobj *t2_source;
12475374Sbp	struct smb_rq *	t2_rq;
12575374Sbp	struct smb_vc * t2_vc;
12675374Sbp};
12775374Sbp
12875374Sbpint  smb_rq_alloc(struct smb_connobj *layer, u_char cmd,
12975374Sbp	struct smb_cred *scred, struct smb_rq **rqpp);
13075374Sbpint  smb_rq_init(struct smb_rq *rqp, struct smb_connobj *layer, u_char cmd,
13175374Sbp	struct smb_cred *scred);
13275374Sbpvoid smb_rq_done(struct smb_rq *rqp);
13375374Sbpint  smb_rq_getrequest(struct smb_rq *rqp, struct mbchain **mbpp);
13475374Sbpint  smb_rq_getreply(struct smb_rq *rqp, struct mdchain **mbpp);
13575374Sbpvoid smb_rq_wstart(struct smb_rq *rqp);
13675374Sbpvoid smb_rq_wend(struct smb_rq *rqp);
13775374Sbpvoid smb_rq_bstart(struct smb_rq *rqp);
13875374Sbpvoid smb_rq_bend(struct smb_rq *rqp);
13975374Sbpint  smb_rq_intr(struct smb_rq *rqp);
14075374Sbpint  smb_rq_simple(struct smb_rq *rqp);
14175374Sbp
14275374Sbpint  smb_t2_alloc(struct smb_connobj *layer, u_short setup, struct smb_cred *scred,
14375374Sbp	struct smb_t2rq **rqpp);
14475374Sbpint  smb_t2_init(struct smb_t2rq *rqp, struct smb_connobj *layer, u_short setup,
14575374Sbp	struct smb_cred *scred);
14675374Sbpvoid smb_t2_done(struct smb_t2rq *t2p);
14775374Sbpint  smb_t2_request(struct smb_t2rq *t2p);
14875374Sbp
14975374Sbp#endif /* !_NETSMB_SMB_RQ_H_ */
150