smb_rq.h revision 75374
175374Sbp/*
275374Sbp * 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 * 3. All advertising materials mentioning features or use of this software
1475374Sbp *    must display the following acknowledgement:
1575374Sbp *    This product includes software developed by Boris Popov.
1675374Sbp * 4. Neither the name of the author nor the names of any co-contributors
1775374Sbp *    may be used to endorse or promote products derived from this software
1875374Sbp *    without specific prior written permission.
1975374Sbp *
2075374Sbp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2175374Sbp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2275374Sbp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2375374Sbp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2475374Sbp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2575374Sbp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2675374Sbp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2775374Sbp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2875374Sbp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2975374Sbp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3075374Sbp * SUCH DAMAGE.
3175374Sbp *
3275374Sbp * $FreeBSD: head/sys/netsmb/smb_rq.h 75374 2001-04-10 07:59:06Z bp $
3375374Sbp */
3475374Sbp#ifndef _NETSMB_SMB_RQ_H_
3575374Sbp#define	_NETSMB_SMB_RQ_H_
3675374Sbp
3775374Sbp#ifndef MB_MSYSTEM
3875374Sbp#include <sys/mchain.h>
3975374Sbp#endif
4075374Sbp
4175374Sbp#define	SMBR_ALLOCED		0x0001	/* structure was malloced */
4275374Sbp#define	SMBR_SENT		0x0002	/* request successfully transmitted */
4375374Sbp#define	SMBR_REXMIT		0x0004	/* request should be retransmitted */
4475374Sbp#define	SMBR_INTR		0x0008	/* request interrupted */
4575374Sbp#define	SMBR_RESTART		0x0010	/* request should be repeated if possible */
4675374Sbp#define	SMBR_NORESTART		0x0020	/* request is not restartable */
4775374Sbp#define	SMBR_MULTIPACKET	0x0040	/* multiple packets can be sent and received */
4875374Sbp#define	SMBR_INTERNAL		0x0080	/* request is internal to smbrqd */
4975374Sbp#define	SMBR_XLOCK		0x0100	/* request locked and can't be moved */
5075374Sbp#define	SMBR_XLOCKWANT		0x0200	/* waiter on XLOCK */
5175374Sbp
5275374Sbp#define SMBT2_ALLSENT		0x0001	/* all data and params are sent */
5375374Sbp#define SMBT2_ALLRECV		0x0002	/* all data and params are received */
5475374Sbp#define	SMBT2_ALLOCED		0x0004
5575374Sbp#define	SMBT2_RESTART		0x0008
5675374Sbp#define	SMBT2_NORESTART		0x0010
5775374Sbp
5875374Sbp#define SMBRQ_SLOCK(rqp)	smb_sl_lock(&(rqp)->sr_slock)
5975374Sbp#define SMBRQ_SUNLOCK(rqp)	smb_sl_unlock(&(rqp)->sr_slock)
6075374Sbp#define SMBRQ_SLOCKPTR(rqp)	(&(rqp)->sr_slock)
6175374Sbp
6275374Sbp
6375374Sbpenum smbrq_state {
6475374Sbp	SMBRQ_NOTSENT,		/* rq have data to send */
6575374Sbp	SMBRQ_SENT,		/* send procedure completed */
6675374Sbp	SMBRQ_REPLYRECEIVED,
6775374Sbp	SMBRQ_NOTIFIED		/* owner notified about completion */
6875374Sbp};
6975374Sbp
7075374Sbpstruct smb_vc;
7175374Sbpstruct smb_t2rq;
7275374Sbp
7375374Sbpstruct smb_rq {
7475374Sbp	enum smbrq_state	sr_state;
7575374Sbp	struct smb_vc * 	sr_vc;
7675374Sbp	struct smb_share*	sr_share;
7775374Sbp	u_short			sr_mid;
7875374Sbp	struct mbchain		sr_rq;
7975374Sbp	u_int8_t		sr_rqflags;
8075374Sbp	u_int16_t		sr_rqflags2;
8175374Sbp	u_char *		sr_wcount;
8275374Sbp	u_short *		sr_bcount;
8375374Sbp	struct mdchain		sr_rp;
8475374Sbp	int			sr_rpgen;
8575374Sbp	int			sr_rplast;
8675374Sbp	int			sr_flags;	/* SMBR_* */
8775374Sbp	int			sr_rpsize;
8875374Sbp	struct smb_cred *	sr_cred;
8975374Sbp	int			sr_timo;
9075374Sbp	int			sr_rexmit;
9175374Sbp	int			sr_sendcnt;
9275374Sbp	struct timespec 	sr_timesent;
9375374Sbp	int			sr_lerror;
9475374Sbp	u_int16_t *		sr_rqtid;
9575374Sbp	u_int16_t *		sr_rquid;
9675374Sbp	u_int8_t		sr_errclass;
9775374Sbp	u_int16_t		sr_serror;
9875374Sbp	u_int32_t		sr_error;
9975374Sbp	u_int8_t		sr_rpflags;
10075374Sbp	u_int16_t		sr_rpflags2;
10175374Sbp	u_int16_t		sr_rptid;
10275374Sbp	u_int16_t		sr_rppid;
10375374Sbp	u_int16_t		sr_rpuid;
10475374Sbp	u_int16_t		sr_rpmid;
10575374Sbp	struct smb_slock	sr_slock;	/* short term locks */
10675374Sbp/*	struct smb_t2rq*sr_t2;*/
10775374Sbp	TAILQ_ENTRY(smb_rq)	sr_link;
10875374Sbp};
10975374Sbp
11075374Sbpstruct smb_t2rq {
11175374Sbp	u_int16_t	t2_setupcount;
11275374Sbp	u_int16_t *	t2_setupdata;
11375374Sbp	u_int16_t	t2_setup[2];	/* most of rqs has setupcount of 1 */
11475374Sbp	u_int8_t	t2_maxscount;	/* max setup words to return */
11575374Sbp	u_int16_t	t2_maxpcount;	/* max param bytes to return */
11675374Sbp	u_int16_t	t2_maxdcount;	/* max data bytes to return */
11775374Sbp	u_int16_t	t2_fid;		/* for T2 request */
11875374Sbp	char *		t_name;		/* for T request, should be zero for T2 */
11975374Sbp	int		t2_flags;	/* SMBT2_ */
12075374Sbp	struct mbchain	t2_tparam;	/* parameters to transmit */
12175374Sbp	struct mbchain	t2_tdata;	/* data to transmit */
12275374Sbp	struct mdchain	t2_rparam;	/* received paramters */
12375374Sbp	struct mdchain	t2_rdata;	/* received data */
12475374Sbp	struct smb_cred*t2_cred;
12575374Sbp	struct smb_connobj *t2_source;
12675374Sbp	struct smb_rq *	t2_rq;
12775374Sbp	struct smb_vc * t2_vc;
12875374Sbp};
12975374Sbp
13075374Sbpint  smb_rq_alloc(struct smb_connobj *layer, u_char cmd,
13175374Sbp	struct smb_cred *scred, struct smb_rq **rqpp);
13275374Sbpint  smb_rq_init(struct smb_rq *rqp, struct smb_connobj *layer, u_char cmd,
13375374Sbp	struct smb_cred *scred);
13475374Sbpvoid smb_rq_done(struct smb_rq *rqp);
13575374Sbpint  smb_rq_getrequest(struct smb_rq *rqp, struct mbchain **mbpp);
13675374Sbpint  smb_rq_getreply(struct smb_rq *rqp, struct mdchain **mbpp);
13775374Sbpvoid smb_rq_wstart(struct smb_rq *rqp);
13875374Sbpvoid smb_rq_wend(struct smb_rq *rqp);
13975374Sbpvoid smb_rq_bstart(struct smb_rq *rqp);
14075374Sbpvoid smb_rq_bend(struct smb_rq *rqp);
14175374Sbpint  smb_rq_intr(struct smb_rq *rqp);
14275374Sbpint  smb_rq_simple(struct smb_rq *rqp);
14375374Sbp
14475374Sbpint  smb_t2_alloc(struct smb_connobj *layer, u_short setup, struct smb_cred *scred,
14575374Sbp	struct smb_t2rq **rqpp);
14675374Sbpint  smb_t2_init(struct smb_t2rq *rqp, struct smb_connobj *layer, u_short setup,
14775374Sbp	struct smb_cred *scred);
14875374Sbpvoid smb_t2_done(struct smb_t2rq *t2p);
14975374Sbpint  smb_t2_request(struct smb_t2rq *t2p);
15075374Sbp
15175374Sbp#endif /* !_NETSMB_SMB_RQ_H_ */
152