xref: /freebsd/sys/netsmb/smb_dev.h (revision 681a5bbef259fc57ece764cdc43d57327ab65c47)
1681a5bbeSBoris Popov /*
2681a5bbeSBoris Popov  * Copyright (c) 2000-2001 Boris Popov
3681a5bbeSBoris Popov  * All rights reserved.
4681a5bbeSBoris Popov  *
5681a5bbeSBoris Popov  * Redistribution and use in source and binary forms, with or without
6681a5bbeSBoris Popov  * modification, are permitted provided that the following conditions
7681a5bbeSBoris Popov  * are met:
8681a5bbeSBoris Popov  * 1. Redistributions of source code must retain the above copyright
9681a5bbeSBoris Popov  *    notice, this list of conditions and the following disclaimer.
10681a5bbeSBoris Popov  * 2. Redistributions in binary form must reproduce the above copyright
11681a5bbeSBoris Popov  *    notice, this list of conditions and the following disclaimer in the
12681a5bbeSBoris Popov  *    documentation and/or other materials provided with the distribution.
13681a5bbeSBoris Popov  * 3. All advertising materials mentioning features or use of this software
14681a5bbeSBoris Popov  *    must display the following acknowledgement:
15681a5bbeSBoris Popov  *    This product includes software developed by Boris Popov.
16681a5bbeSBoris Popov  * 4. Neither the name of the author nor the names of any co-contributors
17681a5bbeSBoris Popov  *    may be used to endorse or promote products derived from this software
18681a5bbeSBoris Popov  *    without specific prior written permission.
19681a5bbeSBoris Popov  *
20681a5bbeSBoris Popov  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21681a5bbeSBoris Popov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22681a5bbeSBoris Popov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23681a5bbeSBoris Popov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24681a5bbeSBoris Popov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25681a5bbeSBoris Popov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26681a5bbeSBoris Popov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27681a5bbeSBoris Popov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28681a5bbeSBoris Popov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29681a5bbeSBoris Popov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30681a5bbeSBoris Popov  * SUCH DAMAGE.
31681a5bbeSBoris Popov  *
32681a5bbeSBoris Popov  * $FreeBSD$
33681a5bbeSBoris Popov  */
34681a5bbeSBoris Popov #ifndef _NETSMB_DEV_H_
35681a5bbeSBoris Popov #define _NETSMB_DEV_H_
36681a5bbeSBoris Popov 
37681a5bbeSBoris Popov #define	NSMB_NAME		"nsmb"
38681a5bbeSBoris Popov #define	NSMB_MAJOR		144
39681a5bbeSBoris Popov 
40681a5bbeSBoris Popov #define NSMB_VERMAJ	1
41681a5bbeSBoris Popov #define NSMB_VERMIN	3006
42681a5bbeSBoris Popov #define NSMB_VERSION	(NSMB_VERMAJ * 100000 + NSMB_VERMIN)
43681a5bbeSBoris Popov 
44681a5bbeSBoris Popov #define NSMBFL_OPEN		0x0001
45681a5bbeSBoris Popov 
46681a5bbeSBoris Popov #define	SMBVOPT_CREATE		0x0001	/* create object if necessary */
47681a5bbeSBoris Popov #define	SMBVOPT_PRIVATE		0x0002	/* connection should be private */
48681a5bbeSBoris Popov #define	SMBVOPT_SINGLESHARE	0x0004	/* keep only ane share at this VC */
49681a5bbeSBoris Popov #define	SMBVOPT_PERMANENT	0x0010	/* object will keep last reference */
50681a5bbeSBoris Popov 
51681a5bbeSBoris Popov #define	SMBSOPT_CREATE		0x0001	/* create object if necessary */
52681a5bbeSBoris Popov #define	SMBSOPT_PERMANENT	0x0010	/* object will keep last reference */
53681a5bbeSBoris Popov 
54681a5bbeSBoris Popov /*
55681a5bbeSBoris Popov  * SMBIOC_LOOKUP flags
56681a5bbeSBoris Popov  */
57681a5bbeSBoris Popov #define SMBLK_CREATE		0x0001
58681a5bbeSBoris Popov 
59681a5bbeSBoris Popov struct smbioc_ossn {
60681a5bbeSBoris Popov 	int		ioc_opt;
61681a5bbeSBoris Popov 	int		ioc_svlen;	/* size of ioc_server address */
62681a5bbeSBoris Popov 	struct sockaddr*ioc_server;
63681a5bbeSBoris Popov 	int		ioc_lolen;	/* size of ioc_local address */
64681a5bbeSBoris Popov 	struct sockaddr*ioc_local;
65681a5bbeSBoris Popov 	char		ioc_srvname[SMB_MAXSRVNAMELEN + 1];
66681a5bbeSBoris Popov 	int		ioc_timeout;
67681a5bbeSBoris Popov 	int		ioc_retrycount;	/* number of retries before giveup */
68681a5bbeSBoris Popov 	char		ioc_localcs[16];/* local charset */
69681a5bbeSBoris Popov 	char		ioc_servercs[16];/* server charset */
70681a5bbeSBoris Popov 	char		ioc_user[SMB_MAXUSERNAMELEN + 1];
71681a5bbeSBoris Popov 	char		ioc_workgroup[SMB_MAXUSERNAMELEN + 1];
72681a5bbeSBoris Popov 	char		ioc_password[SMB_MAXPASSWORDLEN + 1];
73681a5bbeSBoris Popov 	uid_t		ioc_owner;	/* proposed owner */
74681a5bbeSBoris Popov 	gid_t		ioc_group;	/* proposed group */
75681a5bbeSBoris Popov 	mode_t		ioc_mode;	/* desired access mode */
76681a5bbeSBoris Popov 	mode_t		ioc_rights;	/* SMBM_* */
77681a5bbeSBoris Popov };
78681a5bbeSBoris Popov 
79681a5bbeSBoris Popov struct smbioc_oshare {
80681a5bbeSBoris Popov 	int		ioc_opt;
81681a5bbeSBoris Popov 	int		ioc_stype;	/* share type */
82681a5bbeSBoris Popov 	char		ioc_share[SMB_MAXSHARENAMELEN + 1];
83681a5bbeSBoris Popov 	char		ioc_password[SMB_MAXPASSWORDLEN + 1];
84681a5bbeSBoris Popov 	uid_t		ioc_owner;	/* proposed owner of share */
85681a5bbeSBoris Popov 	gid_t		ioc_group;	/* proposed group of share */
86681a5bbeSBoris Popov 	mode_t		ioc_mode;	/* desired access mode to share */
87681a5bbeSBoris Popov 	mode_t		ioc_rights;	/* SMBM_* */
88681a5bbeSBoris Popov };
89681a5bbeSBoris Popov 
90681a5bbeSBoris Popov struct smbioc_rq {
91681a5bbeSBoris Popov 	u_char		ioc_cmd;
92681a5bbeSBoris Popov 	u_char		ioc_twc;
93681a5bbeSBoris Popov 	void *		ioc_twords;
94681a5bbeSBoris Popov 	u_short		ioc_tbc;
95681a5bbeSBoris Popov 	void *		ioc_tbytes;
96681a5bbeSBoris Popov 	int		ioc_rpbufsz;
97681a5bbeSBoris Popov 	char *		ioc_rpbuf;
98681a5bbeSBoris Popov 	u_char		ioc_rwc;
99681a5bbeSBoris Popov 	u_short		ioc_rbc;
100681a5bbeSBoris Popov 	u_int8_t	ioc_errclass;
101681a5bbeSBoris Popov 	u_int16_t	ioc_serror;
102681a5bbeSBoris Popov 	u_int32_t	ioc_error;
103681a5bbeSBoris Popov };
104681a5bbeSBoris Popov 
105681a5bbeSBoris Popov struct smbioc_t2rq {
106681a5bbeSBoris Popov 	u_int16_t	ioc_setup[3];
107681a5bbeSBoris Popov 	int		ioc_setupcnt;
108681a5bbeSBoris Popov 	char *		ioc_name;
109681a5bbeSBoris Popov 	u_short		ioc_tparamcnt;
110681a5bbeSBoris Popov 	void *		ioc_tparam;
111681a5bbeSBoris Popov 	u_short		ioc_tdatacnt;
112681a5bbeSBoris Popov 	void *		ioc_tdata;
113681a5bbeSBoris Popov 	u_short		ioc_rparamcnt;
114681a5bbeSBoris Popov 	void *		ioc_rparam;
115681a5bbeSBoris Popov 	u_short		ioc_rdatacnt;
116681a5bbeSBoris Popov 	void *		ioc_rdata;
117681a5bbeSBoris Popov };
118681a5bbeSBoris Popov 
119681a5bbeSBoris Popov struct smbioc_flags {
120681a5bbeSBoris Popov 	int		ioc_level;	/* 0 - session, 1 - share */
121681a5bbeSBoris Popov 	int		ioc_mask;
122681a5bbeSBoris Popov 	int		ioc_flags;
123681a5bbeSBoris Popov };
124681a5bbeSBoris Popov 
125681a5bbeSBoris Popov struct smbioc_lookup {
126681a5bbeSBoris Popov 	int		ioc_level;
127681a5bbeSBoris Popov 	int		ioc_flags;
128681a5bbeSBoris Popov 	struct smbioc_ossn	ioc_ssn;
129681a5bbeSBoris Popov 	struct smbioc_oshare	ioc_sh;
130681a5bbeSBoris Popov };
131681a5bbeSBoris Popov 
132681a5bbeSBoris Popov struct smbioc_rw {
133681a5bbeSBoris Popov 	smbfh	ioc_fh;
134681a5bbeSBoris Popov 	char *	ioc_base;
135681a5bbeSBoris Popov 	off_t	ioc_offset;
136681a5bbeSBoris Popov 	int	ioc_cnt;
137681a5bbeSBoris Popov };
138681a5bbeSBoris Popov 
139681a5bbeSBoris Popov /*
140681a5bbeSBoris Popov  * Device IOCTLs
141681a5bbeSBoris Popov  */
142681a5bbeSBoris Popov #define	SMBIOC_OPENSESSION	_IOW('n',  100, struct smbioc_ossn)
143681a5bbeSBoris Popov #define	SMBIOC_OPENSHARE	_IOW('n',  101, struct smbioc_oshare)
144681a5bbeSBoris Popov #define	SMBIOC_REQUEST		_IOWR('n', 102, struct smbioc_rq)
145681a5bbeSBoris Popov #define	SMBIOC_T2RQ		_IOWR('n', 103, struct smbioc_t2rq)
146681a5bbeSBoris Popov #define	SMBIOC_SETFLAGS		_IOW('n',  104, struct smbioc_flags)
147681a5bbeSBoris Popov #define	SMBIOC_LOOKUP		_IOW('n',  106, struct smbioc_lookup)
148681a5bbeSBoris Popov #define	SMBIOC_READ		_IOWR('n', 107, struct smbioc_rw)
149681a5bbeSBoris Popov #define	SMBIOC_WRITE		_IOWR('n', 108, struct smbioc_rw)
150681a5bbeSBoris Popov 
151681a5bbeSBoris Popov #ifdef _KERNEL
152681a5bbeSBoris Popov 
153681a5bbeSBoris Popov #ifndef LK_SHARED
154681a5bbeSBoris Popov #include <sys/lock.h>
155681a5bbeSBoris Popov #endif
156681a5bbeSBoris Popov 
157681a5bbeSBoris Popov #define IF_QEMPTY(ifq)	((ifq)->ifq_len == 0)
158681a5bbeSBoris Popov 
159681a5bbeSBoris Popov #define SMBST_CONNECTED	1
160681a5bbeSBoris Popov 
161681a5bbeSBoris Popov STAILQ_HEAD(smbrqh, smb_rq);
162681a5bbeSBoris Popov 
163681a5bbeSBoris Popov struct smb_dev {
164681a5bbeSBoris Popov 	int		sd_opened;
165681a5bbeSBoris Popov 	int		sd_level;
166681a5bbeSBoris Popov 	struct smb_vc * sd_vc;		/* reference to VC */
167681a5bbeSBoris Popov 	struct smb_share *sd_share;	/* reference to share if any */
168681a5bbeSBoris Popov 	int		sd_poll;
169681a5bbeSBoris Popov 	int		sd_seq;
170681a5bbeSBoris Popov /*	struct ifqueue	sd_rdqueue;
171681a5bbeSBoris Popov 	struct ifqueue	sd_wrqueue;
172681a5bbeSBoris Popov 	struct selinfo	sd_pollinfo;
173681a5bbeSBoris Popov 	struct smbrqh	sd_rqlist;
174681a5bbeSBoris Popov 	struct smbrqh	sd_rplist;
175681a5bbeSBoris Popov 	struct ucred 	*sd_owner;*/
176681a5bbeSBoris Popov 	int		sd_flags;
177681a5bbeSBoris Popov };
178681a5bbeSBoris Popov 
179681a5bbeSBoris Popov struct smb_cred;
180681a5bbeSBoris Popov /*
181681a5bbeSBoris Popov  * Compound user interface
182681a5bbeSBoris Popov  */
183681a5bbeSBoris Popov int  smb_usr_lookup(struct smbioc_lookup *dp, struct smb_cred *scred,
184681a5bbeSBoris Popov 	struct smb_vc **vcpp, struct smb_share **sspp);
185681a5bbeSBoris Popov int  smb_usr_opensession(struct smbioc_ossn *data,
186681a5bbeSBoris Popov 	struct smb_cred *scred,	struct smb_vc **vcpp);
187681a5bbeSBoris Popov int  smb_usr_openshare(struct smb_vc *vcp, struct smbioc_oshare *data,
188681a5bbeSBoris Popov 	struct smb_cred *scred, struct smb_share **sspp);
189681a5bbeSBoris Popov int  smb_usr_simplerequest(struct smb_share *ssp, struct smbioc_rq *data,
190681a5bbeSBoris Popov 	struct smb_cred *scred);
191681a5bbeSBoris Popov int  smb_usr_t2request(struct smb_share *ssp, struct smbioc_t2rq *data,
192681a5bbeSBoris Popov 	struct smb_cred *scred);
193681a5bbeSBoris Popov int  smb_dev2share(int fd, int mode, struct smb_cred *scred,
194681a5bbeSBoris Popov 	struct smb_share **sspp);
195681a5bbeSBoris Popov 
196681a5bbeSBoris Popov 
197681a5bbeSBoris Popov #endif /* _KERNEL */
198681a5bbeSBoris Popov 
199681a5bbeSBoris Popov #endif /* _NETSMB_DEV_H_ */
200