1139823Simp/*-
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 *
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
2975374Sbp/*
3075374Sbp * Two levels of connection hierarchy
3175374Sbp */
3275374Sbp#define	SMBL_SM		0
3375374Sbp#define SMBL_VC		1
3475374Sbp#define SMBL_SHARE	2
3575374Sbp#define SMBL_NUM	3
3675374Sbp#define SMBL_NONE	(-1)
3775374Sbp
3875374Sbp#define	SMB_CS_NONE	0x0000
3975374Sbp#define	SMB_CS_UPPER	0x0001		/* convert passed string to upper case */
4075374Sbp#define	SMB_CS_LOWER	0x0002		/* convert passed string to lower case */
4175374Sbp
4275374Sbp/*
4375374Sbp * Common object flags
4475374Sbp */
4575374Sbp#define SMBO_GONE		0x1000000
4675374Sbp
4775374Sbp/*
4875374Sbp * access modes
4975374Sbp */
5075374Sbp#define	SMBM_READ		0400	/* read conn attrs.(like list shares) */
5175374Sbp#define	SMBM_WRITE		0200	/* modify conn attrs */
5275374Sbp#define	SMBM_EXEC		0100	/* can send SMB requests */
5375374Sbp#define	SMBM_READGRP		0040
5475374Sbp#define	SMBM_WRITEGRP		0020
5575374Sbp#define	SMBM_EXECGRP		0010
5675374Sbp#define	SMBM_READOTH		0004
5775374Sbp#define	SMBM_WRITEOTH		0002
5875374Sbp#define	SMBM_EXECOTH		0001
5975374Sbp#define	SMBM_MASK		0777
6075374Sbp#define	SMBM_EXACT		010000	/* check for specified mode exactly */
6175374Sbp#define	SMBM_ALL		(SMBM_READ | SMBM_WRITE | SMBM_EXEC)
6275374Sbp#define	SMBM_DEFAULT		(SMBM_READ | SMBM_WRITE | SMBM_EXEC)
6375374Sbp#define	SMBM_ANY_OWNER		((uid_t)-1)
6475374Sbp#define	SMBM_ANY_GROUP		((gid_t)-1)
6575374Sbp
6675374Sbp/*
6775374Sbp * VC flags
6875374Sbp */
6975374Sbp#define SMBV_PERMANENT		0x0002
7075374Sbp#define SMBV_LONGNAMES		0x0004	/* connection is configured to use long names */
7175374Sbp#define	SMBV_ENCRYPT		0x0008	/* server asked for encrypted password */
7275374Sbp#define	SMBV_WIN95		0x0010	/* used to apply bugfixes for this OS */
7375374Sbp#define	SMBV_PRIVATE		0x0020	/* connection can be used only by creator */
7475374Sbp#define	SMBV_RECONNECTING	0x0040	/* conn is in the process of reconnection */
7588741Sbp#define SMBV_SINGLESHARE	0x0080	/* only one share connecting should be allowed */
7688741Sbp#define SMBV_CREATE		0x0100	/* lookup for create operation */
7775374Sbp/*#define SMBV_FAILED		0x0200*/	/* last reconnect attempt has failed */
7891022Sbp#define SMBV_UNICODE		0x0400	/* connection is configured to use Unicode */
7975374Sbp
8075374Sbp
8175374Sbp/*
8275374Sbp * smb_share flags
8375374Sbp */
8475374Sbp#define SMBS_PERMANENT		0x0001
8575374Sbp#define SMBS_RECONNECTING	0x0002
8675374Sbp#define SMBS_CONNECTED		0x0004
8775374Sbp
8875374Sbp/*
8975374Sbp * share types
9075374Sbp */
9175374Sbp#define	SMB_ST_DISK		0x0	/* A: */
9275374Sbp#define	SMB_ST_PRINTER		0x1	/* LPT: */
9375374Sbp#define	SMB_ST_PIPE		0x2	/* IPC */
9475374Sbp#define	SMB_ST_COMM		0x3	/* COMM */
9575374Sbp#define	SMB_ST_ANY		0x4
9675374Sbp#define	SMB_ST_MAX		0x4
9775374Sbp#define SMB_ST_NONE		0xff	/* not a part of protocol */
9875374Sbp
9975374Sbp/*
10075374Sbp * Negotiated protocol parameters
10175374Sbp */
10275374Sbpstruct smb_sopt {
10375374Sbp	int		sv_proto;
10475374Sbp	int16_t		sv_tz;		/* offset in min relative to UTC */
10575374Sbp	u_int32_t	sv_maxtx;	/* maximum transmit buf size */
10675374Sbp	u_char		sv_sm;		/* security mode */
10775374Sbp	u_int16_t	sv_maxmux;	/* max number of outstanding rq's */
10875374Sbp	u_int16_t 	sv_maxvcs;	/* max number of VCs */
10975374Sbp	u_int16_t	sv_rawmode;
11075374Sbp	u_int32_t	sv_maxraw;	/* maximum raw-buffer size */
11175374Sbp	u_int32_t	sv_skey;	/* session key */
11288741Sbp	u_int32_t	sv_caps;	/* capabilities SMB_CAP_ */
11375374Sbp};
11475374Sbp
11575374Sbp/*
11675374Sbp * network IO daemon states
11775374Sbp */
11875374Sbpenum smbiod_state {
11975374Sbp	SMBIOD_ST_NOTCONN,	/* no connect request was made */
12075374Sbp	SMBIOD_ST_RECONNECT,	/* a [re]connect attempt is in progress */
12175374Sbp	SMBIOD_ST_TRANACTIVE,	/* transport level is up */
12275374Sbp	SMBIOD_ST_VCACTIVE,	/* session established */
12375374Sbp	SMBIOD_ST_DEAD		/* connection broken, transport is down */
12475374Sbp};
12575374Sbp
12675374Sbp
12775374Sbp/*
12875374Sbp * Info structures
12975374Sbp */
13075374Sbp#define	SMB_INFO_NONE		0
13175374Sbp#define	SMB_INFO_VC		2
13275374Sbp#define	SMB_INFO_SHARE		3
13375374Sbp
13475374Sbpstruct smb_vc_info {
13575374Sbp	int		itype;
13675374Sbp	int		usecount;
13775374Sbp	uid_t		uid;		/* user id of connection */
13875374Sbp	gid_t		gid;		/* group of connection */
13975374Sbp	mode_t		mode;		/* access mode */
14075374Sbp	int		flags;
14175374Sbp	enum smbiod_state iodstate;
14275374Sbp	struct smb_sopt	sopt;
143118078Stjr	char		srvname[SMB_MAXSRVNAMELEN + 1];
14475374Sbp	char		vcname[128];
14575374Sbp};
14675374Sbp
14775374Sbpstruct smb_share_info {
14875374Sbp	int		itype;
14975374Sbp	int		usecount;
15075374Sbp	u_short		tid;		/* TID */
15175374Sbp	int		type;		/* share type */
15275374Sbp	uid_t		uid;		/* user id of connection */
15375374Sbp	gid_t		gid;		/* group of connection */
15475374Sbp	mode_t		mode;		/* access mode */
15575374Sbp	int		flags;
15675374Sbp	char		sname[128];
15775374Sbp};
15875374Sbp
15975374Sbp#ifdef _KERNEL
16075374Sbp
161176708Sattilio#include <sys/lock.h>
162102479Sbde#include <sys/lockmgr.h>
16375374Sbp#include <netsmb/smb_subr.h>
16475374Sbp
16575374Sbp#define CONNADDREQ(a1,a2)	((a1)->sa_len == (a2)->sa_len && \
16675374Sbp				 bcmp(a1, a2, (a1)->sa_len) == 0)
16775374Sbp
16875374Sbpstruct smb_vc;
16975374Sbpstruct smb_share;
17075374Sbpstruct smb_cred;
17175374Sbpstruct smb_rq;
17275374Sbpstruct mbdata;
17375374Sbpstruct smbioc_oshare;
17475374Sbpstruct smbioc_ossn;
17575374Sbpstruct uio;
17675374Sbp
17775374SbpTAILQ_HEAD(smb_rqhead, smb_rq);
17875374Sbp
17975374Sbp#define SMB_DEFRQTIMO	5
18075374Sbp
18175374Sbp#define SMB_DIALECT(vcp)	((vcp)->vc_sopt.sv_proto)
18275374Sbp
18375374Sbpstruct smb_tran_desc;
18475374Sbp
18575374Sbp/*
18675374Sbp * Connection object
18775374Sbp */
18875374Sbpstruct smb_connobj;
18975374Sbp
19075374Sbptypedef void smb_co_gone_t (struct smb_connobj *cp, struct smb_cred *scred);
19175374Sbptypedef void smb_co_free_t (struct smb_connobj *cp);
19275374Sbp
19375374Sbp#define	SMB_CO_LOCK(cp)		smb_sl_lock(&(cp)->co_interlock)
19475374Sbp#define	SMB_CO_UNLOCK(cp)	smb_sl_unlock(&(cp)->co_interlock)
19575374Sbp
19675374Sbpstruct smb_connobj {
19775374Sbp	int			co_level;	/* SMBL_ */
19875374Sbp	int			co_flags;
19975374Sbp	struct lock		co_lock;
20075374Sbp	struct smb_slock	co_interlock;
20175374Sbp	int			co_usecount;
20275374Sbp	struct smb_connobj *	co_parent;
20375374Sbp	SLIST_HEAD(,smb_connobj)co_children;
20475374Sbp	SLIST_ENTRY(smb_connobj)co_next;
20575374Sbp	smb_co_gone_t *		co_gone;
20675374Sbp	smb_co_free_t *		co_free;
20775374Sbp};
20875374Sbp
20975374Sbp#define	SMBCO_FOREACH(var, cp)	SLIST_FOREACH((var), &(cp)->co_children, co_next)
21075374Sbp
21175374Sbp/*
21275374Sbp * Virtual Circuit (session) to a server.
21375374Sbp * This is the most (over)complicated part of SMB protocol.
21475374Sbp * For the user security level (usl), each session with different remote
21575374Sbp * user name has its own VC.
21675374Sbp * It is unclear however, should share security level (ssl) allow additional
21775374Sbp * VCs, because user name is not used and can be the same. On other hand,
21875374Sbp * multiple VCs allows us to create separate sessions to server on a per
21975374Sbp * user basis.
22075374Sbp */
22175374Sbp
22275374Sbp/*
22375374Sbp * This lock protects vc_flags
22475374Sbp */
22575374Sbp#define	SMBC_ST_LOCK(vcp)	smb_sl_lock(&(vcp)->vc_stlock)
22675374Sbp#define	SMBC_ST_UNLOCK(vcp)	smb_sl_unlock(&(vcp)->vc_stlock)
22775374Sbp
22875374Sbp
22975374Sbpstruct smb_vc {
23075374Sbp	struct smb_connobj obj;
23175374Sbp	char *		vc_srvname;
23275374Sbp	struct sockaddr*vc_paddr;	/* server addr */
23375374Sbp	struct sockaddr*vc_laddr;	/* local addr, if any */
23475374Sbp	char *		vc_username;
23575374Sbp	char *		vc_pass;	/* password for usl case */
23675374Sbp	char *		vc_domain;	/* workgroup/primary domain */
23775374Sbp
23875374Sbp	u_int		vc_timo;	/* default request timeout */
23975374Sbp	int		vc_maxvcs;	/* maximum number of VC per connection */
24075374Sbp
24175374Sbp	void *		vc_tolower;	/* local charset */
24275374Sbp	void *		vc_toupper;	/* local charset */
24375374Sbp	void *		vc_toserver;	/* local charset to server one */
24475374Sbp	void *		vc_tolocal;	/* server charset to local one */
245230196Skevlo	void *		vc_cp_toserver;	/* local charset to server one (using CodePage) */
246230196Skevlo	void *		vc_cp_tolocal;	/* server charset to local one (using CodePage) */
247230196Skevlo	void *		vc_ucs_toserver; /* local charset to server one (using UCS-2) */
248230196Skevlo	void *		vc_ucs_tolocal;	/* server charset to local one (using UCS-2) */
24975374Sbp	int		vc_number;	/* number of this VC from the client side */
25075374Sbp	int		vc_genid;
25175374Sbp	uid_t		vc_uid;		/* user id of connection */
25275374Sbp	gid_t		vc_grp;		/* group of connection */
25375374Sbp	mode_t		vc_mode;	/* access mode */
25475374Sbp	u_short		vc_smbuid;	/* unique vc id assigned by server */
25575374Sbp
25675374Sbp	u_char		vc_hflags;	/* or'ed with flags in the smb header */
25775374Sbp	u_short		vc_hflags2;	/* or'ed with flags in the smb header */
25875374Sbp	void *		vc_tdata;	/* transport control block */
25975374Sbp	struct smb_tran_desc *vc_tdesc;
26075374Sbp	int		vc_chlen;	/* actual challenge length */
26175374Sbp	u_char 		vc_ch[SMB_MAXCHALLENGELEN];
26275374Sbp	u_short		vc_mid;		/* multiplex id */
26375374Sbp	struct smb_sopt	vc_sopt;	/* server options */
26475374Sbp	int		vc_txmax;	/* max tx/rx packet size */
265103395Sbp	int		vc_rxmax;	/* max readx data size */
266103395Sbp	int		vc_wxmax;	/* max writex data size */
26775374Sbp	struct smbiod *	vc_iod;
26875374Sbp	struct smb_slock vc_stlock;
269124087Stjr	u_int32_t	vc_seqno;	/* my next sequence number */
270124087Stjr	u_int8_t	*vc_mackey;	/* MAC key */
271124087Stjr	int		vc_mackeylen;	/* length of MAC key */
27275374Sbp};
27375374Sbp
27475374Sbp#define vc_maxmux	vc_sopt.sv_maxmux
27575374Sbp#define	vc_flags	obj.co_flags
27675374Sbp
277103396Sbp#define SMB_UNICODE_STRINGS(vcp)	((vcp)->vc_hflags2 & SMB_FLAGS2_UNICODE)
27875374Sbp
279230196Skevlo#define	SMB_UNICODE_NAME	"UCS-2LE"
280230196Skevlo
28175374Sbp/*
28275374Sbp * smb_share structure describes connection to the given SMB share (tree).
28375374Sbp * Connection to share is always built on top of the VC.
28475374Sbp */
28575374Sbp
28675374Sbp/*
28775374Sbp * This lock protects ss_flags
28875374Sbp */
28975374Sbp#define	SMBS_ST_LOCK(ssp)	smb_sl_lock(&(ssp)->ss_stlock)
29075374Sbp#define	SMBS_ST_LOCKPTR(ssp)	(&(ssp)->ss_stlock)
29175374Sbp#define	SMBS_ST_UNLOCK(ssp)	smb_sl_unlock(&(ssp)->ss_stlock)
29275374Sbp
29375374Sbpstruct smb_share {
29475374Sbp	struct smb_connobj obj;
29575374Sbp	char *		ss_name;
29675374Sbp	u_short		ss_tid;		/* TID */
29775374Sbp	int		ss_type;	/* share type */
29875374Sbp	uid_t		ss_uid;		/* user id of connection */
29975374Sbp	gid_t		ss_grp;		/* group of connection */
30075374Sbp	mode_t		ss_mode;	/* access mode */
30175374Sbp	int		ss_vcgenid;
30275374Sbp	char *		ss_pass;	/* password to a share, can be null */
30375374Sbp	struct smb_slock ss_stlock;
30475374Sbp};
30575374Sbp
30675374Sbp#define	ss_flags	obj.co_flags
30775374Sbp
30875374Sbp#define CPTOVC(cp)	((struct smb_vc*)(cp))
30975374Sbp#define VCTOCP(vcp)	(&(vcp)->obj)
31075374Sbp#define CPTOSS(cp)	((struct smb_share*)(cp))
31175374Sbp#define	SSTOVC(ssp)	CPTOVC(((ssp)->obj.co_parent))
31275374Sbp#define SSTOCP(ssp)	(&(ssp)->obj)
31375374Sbp
31475374Sbpstruct smb_vcspec {
31575374Sbp	char *		srvname;
31675374Sbp	struct sockaddr*sap;
31775374Sbp	struct sockaddr*lap;
31875374Sbp	int		flags;
31975374Sbp	char *		username;
32075374Sbp	char *		pass;
32175374Sbp	char *		domain;
32275374Sbp	mode_t		mode;
32375374Sbp	mode_t		rights;
32475374Sbp	uid_t		owner;
32575374Sbp	gid_t		group;
32675374Sbp	char *		localcs;
32775374Sbp	char *		servercs;
32875374Sbp	struct smb_sharespec *shspec;
32975374Sbp	struct smb_share *ssp;		/* returned */
33075374Sbp	/*
33175374Sbp	 * The rest is an internal data
33275374Sbp	 */
33375374Sbp	struct smb_cred *scred;
33475374Sbp};
33575374Sbp
33675374Sbpstruct smb_sharespec {
33775374Sbp	char *		name;
33875374Sbp	char *		pass;
33975374Sbp	mode_t		mode;
34075374Sbp	mode_t		rights;
34175374Sbp	uid_t		owner;
34275374Sbp	gid_t		group;
34375374Sbp	int		stype;
34475374Sbp	/*
34575374Sbp	 * The rest is an internal data
34675374Sbp	 */
34775374Sbp	struct smb_cred *scred;
34875374Sbp};
34975374Sbp
35075374Sbp/*
35175374Sbp * Session level functions
35275374Sbp */
35375374Sbpint  smb_sm_init(void);
35475374Sbpint  smb_sm_done(void);
35575374Sbpint  smb_sm_lookup(struct smb_vcspec *vcspec,
35675374Sbp	struct smb_sharespec *shspec, struct smb_cred *scred,
35775374Sbp	struct smb_vc **vcpp);
35875374Sbp
35975374Sbp/*
36075374Sbp * Connection object
36175374Sbp */
36287192Sbpvoid smb_co_ref(struct smb_connobj *cp);
36375374Sbpvoid smb_co_rele(struct smb_connobj *cp, struct smb_cred *scred);
36475374Sbpint  smb_co_get(struct smb_connobj *cp, int flags, struct smb_cred *scred);
36575374Sbpvoid smb_co_put(struct smb_connobj *cp, struct smb_cred *scred);
366184571Srwatsonint  smb_co_lock(struct smb_connobj *cp, int flags);
367184571Srwatsonvoid smb_co_unlock(struct smb_connobj *cp, int flags);
36875374Sbp
36975374Sbp/*
37075374Sbp * session level functions
37175374Sbp */
37275374Sbpint  smb_vc_create(struct smb_vcspec *vcspec,
37375374Sbp	struct smb_cred *scred, struct smb_vc **vcpp);
37475374Sbpint  smb_vc_connect(struct smb_vc *vcp, struct smb_cred *scred);
37575374Sbpint  smb_vc_access(struct smb_vc *vcp, struct smb_cred *scred, mode_t mode);
37675374Sbpint  smb_vc_get(struct smb_vc *vcp, int flags, struct smb_cred *scred);
37775374Sbpvoid smb_vc_put(struct smb_vc *vcp, struct smb_cred *scred);
37887192Sbpvoid smb_vc_ref(struct smb_vc *vcp);
37975374Sbpvoid smb_vc_rele(struct smb_vc *vcp, struct smb_cred *scred);
380184571Srwatsonint  smb_vc_lock(struct smb_vc *vcp, int flags);
381184571Srwatsonvoid smb_vc_unlock(struct smb_vc *vcp, int flags);
38275374Sbpint  smb_vc_lookupshare(struct smb_vc *vcp, struct smb_sharespec *shspec,
38375374Sbp	struct smb_cred *scred, struct smb_share **sspp);
38475374Sbpconst char * smb_vc_getpass(struct smb_vc *vcp);
38575374Sbpu_short smb_vc_nextmid(struct smb_vc *vcp);
38675374Sbp
38775374Sbp/*
38875374Sbp * share level functions
38975374Sbp */
39075374Sbpint  smb_share_create(struct smb_vc *vcp, struct smb_sharespec *shspec,
39175374Sbp	struct smb_cred *scred, struct smb_share **sspp);
39275374Sbpint  smb_share_access(struct smb_share *ssp, struct smb_cred *scred, mode_t mode);
39387192Sbpvoid smb_share_ref(struct smb_share *ssp);
39475374Sbpvoid smb_share_rele(struct smb_share *ssp, struct smb_cred *scred);
39575374Sbpint  smb_share_get(struct smb_share *ssp, int flags, struct smb_cred *scred);
39675374Sbpvoid smb_share_put(struct smb_share *ssp, struct smb_cred *scred);
397184571Srwatsonint  smb_share_lock(struct smb_share *ssp, int flags);
398184571Srwatsonvoid smb_share_unlock(struct smb_share *ssp, int flags);
39975374Sbpvoid smb_share_invalidate(struct smb_share *ssp);
40075374Sbpint  smb_share_valid(struct smb_share *ssp);
40175374Sbpconst char * smb_share_getpass(struct smb_share *ssp);
40275374Sbp
40375374Sbp/*
40475374Sbp * SMB protocol level functions
40575374Sbp */
40675374Sbpint  smb_smb_negotiate(struct smb_vc *vcp, struct smb_cred *scred);
40775374Sbpint  smb_smb_ssnsetup(struct smb_vc *vcp, struct smb_cred *scred);
40875374Sbpint  smb_smb_ssnclose(struct smb_vc *vcp, struct smb_cred *scred);
40975374Sbpint  smb_smb_treeconnect(struct smb_share *ssp, struct smb_cred *scred);
41075374Sbpint  smb_smb_treedisconnect(struct smb_share *ssp, struct smb_cred *scred);
41175374Sbpint  smb_read(struct smb_share *ssp, u_int16_t fid, struct uio *uio,
41275374Sbp	struct smb_cred *scred);
41375374Sbpint  smb_write(struct smb_share *ssp, u_int16_t fid, struct uio *uio,
41475374Sbp	struct smb_cred *scred);
41575374Sbpint  smb_smb_echo(struct smb_vc *vcp, struct smb_cred *scred);
41675374Sbp
41775374Sbp/*
41875374Sbp * smbiod thread
41975374Sbp */
42075374Sbp
42175374Sbp#define	SMBIOD_EV_NEWRQ		0x0001
42275374Sbp#define	SMBIOD_EV_SHUTDOWN	0x0002
42375374Sbp#define	SMBIOD_EV_CONNECT	0x0003
42475374Sbp#define	SMBIOD_EV_DISCONNECT	0x0004
42575374Sbp#define	SMBIOD_EV_TREECONNECT	0x0005
42675374Sbp#define	SMBIOD_EV_MASK		0x00ff
42775374Sbp#define	SMBIOD_EV_SYNC		0x0100
42875374Sbp#define	SMBIOD_EV_PROCESSING	0x0200
42975374Sbp
43075374Sbpstruct smbiod_event {
43175374Sbp	int	ev_type;
43275374Sbp	int	ev_error;
43375374Sbp	void *	ev_ident;
43475374Sbp	STAILQ_ENTRY(smbiod_event)	ev_link;
43575374Sbp};
43675374Sbp
43775374Sbp#define	SMBIOD_SHUTDOWN		0x0001
43875374Sbp
43975374Sbpstruct smbiod {
44075374Sbp	int			iod_id;
44175374Sbp	int			iod_flags;
44275374Sbp	enum smbiod_state	iod_state;
44375374Sbp	int			iod_muxcnt;	/* number of active outstanding requests */
44475374Sbp	int			iod_sleeptimo;
44575374Sbp	struct smb_vc *		iod_vc;
44675374Sbp	struct smb_slock	iod_rqlock;	/* iod_rqlist, iod_muxwant */
44775374Sbp	struct smb_rqhead	iod_rqlist;	/* list of outstanding requests */
44875374Sbp	int			iod_muxwant;
44975374Sbp	struct proc *		iod_p;
45087192Sbp	struct thread *		iod_td;
45175374Sbp	struct smb_cred		iod_scred;
45275374Sbp	struct smb_slock	iod_evlock;	/* iod_evlist */
45375374Sbp	STAILQ_HEAD(,smbiod_event) iod_evlist;
45475374Sbp	struct timespec 	iod_lastrqsent;
45575374Sbp	struct timespec 	iod_pingtimo;
45675374Sbp};
45775374Sbp
45875374Sbpint  smb_iod_init(void);
45975374Sbpint  smb_iod_done(void);
46075374Sbpint  smb_iod_create(struct smb_vc *vcp);
46175374Sbpint  smb_iod_destroy(struct smbiod *iod);
46275374Sbpint  smb_iod_request(struct smbiod *iod, int event, void *ident);
46375374Sbpint  smb_iod_addrq(struct smb_rq *rqp);
46475374Sbpint  smb_iod_waitrq(struct smb_rq *rqp);
46575374Sbpint  smb_iod_removerq(struct smb_rq *rqp);
46675374Sbp
46775374Sbp#endif /* _KERNEL */
468