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#ifndef _NETSMB_DEV_H_ 2975374Sbp#define _NETSMB_DEV_H_ 3075374Sbp 3175475Sbp#ifndef _KERNEL 3275475Sbp#include <sys/types.h> 3375475Sbp#endif 3475475Sbp#include <sys/ioccom.h> 3575475Sbp 3675430Sbp#include <netsmb/smb.h> 3775430Sbp 3875374Sbp#define NSMB_NAME "nsmb" 3975374Sbp 4075374Sbp#define NSMB_VERMAJ 1 4175374Sbp#define NSMB_VERMIN 3006 4275374Sbp#define NSMB_VERSION (NSMB_VERMAJ * 100000 + NSMB_VERMIN) 4375374Sbp 4475374Sbp#define NSMBFL_OPEN 0x0001 4575374Sbp 4675374Sbp#define SMBVOPT_CREATE 0x0001 /* create object if necessary */ 4775374Sbp#define SMBVOPT_PRIVATE 0x0002 /* connection should be private */ 4875475Sbp#define SMBVOPT_SINGLESHARE 0x0004 /* keep only one share at this VC */ 4975374Sbp#define SMBVOPT_PERMANENT 0x0010 /* object will keep last reference */ 5075374Sbp 5175374Sbp#define SMBSOPT_CREATE 0x0001 /* create object if necessary */ 5275374Sbp#define SMBSOPT_PERMANENT 0x0010 /* object will keep last reference */ 5375374Sbp 5475374Sbp/* 5575374Sbp * SMBIOC_LOOKUP flags 5675374Sbp */ 5775374Sbp#define SMBLK_CREATE 0x0001 5875374Sbp 5975374Sbpstruct smbioc_ossn { 6075374Sbp int ioc_opt; 61217174Scsjp uint32_t ioc_svlen; /* size of ioc_server address */ 6275374Sbp struct sockaddr*ioc_server; 63217174Scsjp uint32_t ioc_lolen; /* size of ioc_local address */ 6475374Sbp struct sockaddr*ioc_local; 6575374Sbp char ioc_srvname[SMB_MAXSRVNAMELEN + 1]; 6675374Sbp int ioc_timeout; 6775374Sbp int ioc_retrycount; /* number of retries before giveup */ 6875374Sbp char ioc_localcs[16];/* local charset */ 6975374Sbp char ioc_servercs[16];/* server charset */ 7075374Sbp char ioc_user[SMB_MAXUSERNAMELEN + 1]; 7175374Sbp char ioc_workgroup[SMB_MAXUSERNAMELEN + 1]; 7275374Sbp char ioc_password[SMB_MAXPASSWORDLEN + 1]; 7375374Sbp uid_t ioc_owner; /* proposed owner */ 7475374Sbp gid_t ioc_group; /* proposed group */ 7575374Sbp mode_t ioc_mode; /* desired access mode */ 7675374Sbp mode_t ioc_rights; /* SMBM_* */ 7775374Sbp}; 7875374Sbp 7975374Sbpstruct smbioc_oshare { 8075374Sbp int ioc_opt; 8175374Sbp int ioc_stype; /* share type */ 8275374Sbp char ioc_share[SMB_MAXSHARENAMELEN + 1]; 8375374Sbp char ioc_password[SMB_MAXPASSWORDLEN + 1]; 8475374Sbp uid_t ioc_owner; /* proposed owner of share */ 8575374Sbp gid_t ioc_group; /* proposed group of share */ 8675374Sbp mode_t ioc_mode; /* desired access mode to share */ 8775374Sbp mode_t ioc_rights; /* SMBM_* */ 8875374Sbp}; 8975374Sbp 9075374Sbpstruct smbioc_rq { 9175374Sbp u_char ioc_cmd; 9275374Sbp u_char ioc_twc; 9375374Sbp void * ioc_twords; 9475374Sbp u_short ioc_tbc; 9575374Sbp void * ioc_tbytes; 9675374Sbp int ioc_rpbufsz; 9775374Sbp char * ioc_rpbuf; 9875374Sbp u_char ioc_rwc; 9975374Sbp u_short ioc_rbc; 10075374Sbp u_int8_t ioc_errclass; 10175374Sbp u_int16_t ioc_serror; 10275374Sbp u_int32_t ioc_error; 10375374Sbp}; 10475374Sbp 10575374Sbpstruct smbioc_t2rq { 10675374Sbp u_int16_t ioc_setup[3]; 10775374Sbp int ioc_setupcnt; 10875374Sbp char * ioc_name; 10975374Sbp u_short ioc_tparamcnt; 11075374Sbp void * ioc_tparam; 11175374Sbp u_short ioc_tdatacnt; 11275374Sbp void * ioc_tdata; 11375374Sbp u_short ioc_rparamcnt; 11475374Sbp void * ioc_rparam; 11575374Sbp u_short ioc_rdatacnt; 11675374Sbp void * ioc_rdata; 11775374Sbp}; 11875374Sbp 11975374Sbpstruct smbioc_flags { 12075374Sbp int ioc_level; /* 0 - session, 1 - share */ 12175374Sbp int ioc_mask; 12275374Sbp int ioc_flags; 12375374Sbp}; 12475374Sbp 12575374Sbpstruct smbioc_lookup { 12675374Sbp int ioc_level; 12775374Sbp int ioc_flags; 12875374Sbp struct smbioc_ossn ioc_ssn; 12975374Sbp struct smbioc_oshare ioc_sh; 13075374Sbp}; 13175374Sbp 13275374Sbpstruct smbioc_rw { 13375374Sbp smbfh ioc_fh; 13475374Sbp char * ioc_base; 13575374Sbp off_t ioc_offset; 13675374Sbp int ioc_cnt; 13775374Sbp}; 13875374Sbp 13975374Sbp/* 14075374Sbp * Device IOCTLs 14175374Sbp */ 14275374Sbp#define SMBIOC_OPENSESSION _IOW('n', 100, struct smbioc_ossn) 14375374Sbp#define SMBIOC_OPENSHARE _IOW('n', 101, struct smbioc_oshare) 14475374Sbp#define SMBIOC_REQUEST _IOWR('n', 102, struct smbioc_rq) 14575374Sbp#define SMBIOC_T2RQ _IOWR('n', 103, struct smbioc_t2rq) 14675374Sbp#define SMBIOC_SETFLAGS _IOW('n', 104, struct smbioc_flags) 14775374Sbp#define SMBIOC_LOOKUP _IOW('n', 106, struct smbioc_lookup) 14875374Sbp#define SMBIOC_READ _IOWR('n', 107, struct smbioc_rw) 14975374Sbp#define SMBIOC_WRITE _IOWR('n', 108, struct smbioc_rw) 15075374Sbp 15175374Sbp#ifdef _KERNEL 15275374Sbp 15375374Sbp#define SMBST_CONNECTED 1 15475374Sbp 15575374SbpSTAILQ_HEAD(smbrqh, smb_rq); 15675374Sbp 15775374Sbpstruct smb_dev { 158250236Sdavide struct cdev * dev; 15975374Sbp int sd_opened; 16075374Sbp int sd_level; 16175374Sbp struct smb_vc * sd_vc; /* reference to VC */ 16275374Sbp struct smb_share *sd_share; /* reference to share if any */ 16375374Sbp int sd_poll; 16475374Sbp int sd_seq; 16575374Sbp int sd_flags; 166250236Sdavide int refcount; 167250236Sdavide int usecount; 16875374Sbp}; 16975374Sbp 170250236Sdavideextern struct sx smb_lock; 171250236Sdavide#define SMB_LOCK() sx_xlock(&smb_lock) 172250236Sdavide#define SMB_UNLOCK() sx_unlock(&smb_lock) 173250236Sdavide#define SMB_LOCKASSERT() sx_assert(&smb_lock, SA_XLOCKED) 174250236Sdavide 17575374Sbpstruct smb_cred; 176250236Sdavide 177250236Sdavidevoid sdp_dtor(void *arg); 178250236Sdavidevoid sdp_trydestroy(struct smb_dev *dev); 179250236Sdavide 18075374Sbp/* 18175374Sbp * Compound user interface 18275374Sbp */ 18375374Sbpint smb_usr_lookup(struct smbioc_lookup *dp, struct smb_cred *scred, 18475374Sbp struct smb_vc **vcpp, struct smb_share **sspp); 18575374Sbpint smb_usr_opensession(struct smbioc_ossn *data, 18675374Sbp struct smb_cred *scred, struct smb_vc **vcpp); 18775374Sbpint smb_usr_openshare(struct smb_vc *vcp, struct smbioc_oshare *data, 18875374Sbp struct smb_cred *scred, struct smb_share **sspp); 18975374Sbpint smb_usr_simplerequest(struct smb_share *ssp, struct smbioc_rq *data, 19075374Sbp struct smb_cred *scred); 19175374Sbpint smb_usr_t2request(struct smb_share *ssp, struct smbioc_t2rq *data, 19275374Sbp struct smb_cred *scred); 19375374Sbpint smb_dev2share(int fd, int mode, struct smb_cred *scred, 194250236Sdavide struct smb_share **sspp, struct smb_dev **ssdp); 19575374Sbp 19675374Sbp 19775374Sbp#endif /* _KERNEL */ 19875374Sbp 19975374Sbp#endif /* _NETSMB_DEV_H_ */ 200