1c398230bSWarner Losh /*- 2*fe267a55SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*fe267a55SPedro F. Giffuni * 4681a5bbeSBoris Popov * Copyright (c) 2000-2001 Boris Popov 5681a5bbeSBoris Popov * All rights reserved. 6681a5bbeSBoris Popov * 7681a5bbeSBoris Popov * Redistribution and use in source and binary forms, with or without 8681a5bbeSBoris Popov * modification, are permitted provided that the following conditions 9681a5bbeSBoris Popov * are met: 10681a5bbeSBoris Popov * 1. Redistributions of source code must retain the above copyright 11681a5bbeSBoris Popov * notice, this list of conditions and the following disclaimer. 12681a5bbeSBoris Popov * 2. Redistributions in binary form must reproduce the above copyright 13681a5bbeSBoris Popov * notice, this list of conditions and the following disclaimer in the 14681a5bbeSBoris Popov * documentation and/or other materials provided with the distribution. 15681a5bbeSBoris Popov * 16681a5bbeSBoris Popov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17681a5bbeSBoris Popov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18681a5bbeSBoris Popov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19681a5bbeSBoris Popov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20681a5bbeSBoris Popov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21681a5bbeSBoris Popov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22681a5bbeSBoris Popov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23681a5bbeSBoris Popov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24681a5bbeSBoris Popov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25681a5bbeSBoris Popov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26681a5bbeSBoris Popov * SUCH DAMAGE. 27681a5bbeSBoris Popov * 28681a5bbeSBoris Popov * $FreeBSD$ 29681a5bbeSBoris Popov */ 30681a5bbeSBoris Popov #ifndef _NETSMB_DEV_H_ 31681a5bbeSBoris Popov #define _NETSMB_DEV_H_ 32681a5bbeSBoris Popov 3334ae6c75SBoris Popov #ifndef _KERNEL 3434ae6c75SBoris Popov #include <sys/types.h> 3534ae6c75SBoris Popov #endif 3634ae6c75SBoris Popov #include <sys/ioccom.h> 3734ae6c75SBoris Popov 38cdcb16abSBoris Popov #include <netsmb/smb.h> 39cdcb16abSBoris Popov 40681a5bbeSBoris Popov #define NSMB_NAME "nsmb" 41681a5bbeSBoris Popov 42681a5bbeSBoris Popov #define NSMB_VERMAJ 1 43681a5bbeSBoris Popov #define NSMB_VERMIN 3006 44681a5bbeSBoris Popov #define NSMB_VERSION (NSMB_VERMAJ * 100000 + NSMB_VERMIN) 45681a5bbeSBoris Popov 46681a5bbeSBoris Popov #define NSMBFL_OPEN 0x0001 47681a5bbeSBoris Popov 48681a5bbeSBoris Popov #define SMBVOPT_CREATE 0x0001 /* create object if necessary */ 49681a5bbeSBoris Popov #define SMBVOPT_PRIVATE 0x0002 /* connection should be private */ 5034ae6c75SBoris Popov #define SMBVOPT_SINGLESHARE 0x0004 /* keep only one share at this VC */ 51681a5bbeSBoris Popov #define SMBVOPT_PERMANENT 0x0010 /* object will keep last reference */ 52681a5bbeSBoris Popov 53681a5bbeSBoris Popov #define SMBSOPT_CREATE 0x0001 /* create object if necessary */ 54681a5bbeSBoris Popov #define SMBSOPT_PERMANENT 0x0010 /* object will keep last reference */ 55681a5bbeSBoris Popov 56681a5bbeSBoris Popov /* 57681a5bbeSBoris Popov * SMBIOC_LOOKUP flags 58681a5bbeSBoris Popov */ 59681a5bbeSBoris Popov #define SMBLK_CREATE 0x0001 60681a5bbeSBoris Popov 61681a5bbeSBoris Popov struct smbioc_ossn { 62681a5bbeSBoris Popov int ioc_opt; 63a67b22d6SChristian S.J. Peron uint32_t ioc_svlen; /* size of ioc_server address */ 64681a5bbeSBoris Popov struct sockaddr*ioc_server; 65a67b22d6SChristian S.J. Peron uint32_t ioc_lolen; /* size of ioc_local address */ 66681a5bbeSBoris Popov struct sockaddr*ioc_local; 67681a5bbeSBoris Popov char ioc_srvname[SMB_MAXSRVNAMELEN + 1]; 68681a5bbeSBoris Popov int ioc_timeout; 69681a5bbeSBoris Popov int ioc_retrycount; /* number of retries before giveup */ 70681a5bbeSBoris Popov char ioc_localcs[16];/* local charset */ 71681a5bbeSBoris Popov char ioc_servercs[16];/* server charset */ 72681a5bbeSBoris Popov char ioc_user[SMB_MAXUSERNAMELEN + 1]; 73681a5bbeSBoris Popov char ioc_workgroup[SMB_MAXUSERNAMELEN + 1]; 74681a5bbeSBoris Popov char ioc_password[SMB_MAXPASSWORDLEN + 1]; 75681a5bbeSBoris Popov uid_t ioc_owner; /* proposed owner */ 76681a5bbeSBoris Popov gid_t ioc_group; /* proposed group */ 77681a5bbeSBoris Popov mode_t ioc_mode; /* desired access mode */ 78681a5bbeSBoris Popov mode_t ioc_rights; /* SMBM_* */ 79681a5bbeSBoris Popov }; 80681a5bbeSBoris Popov 81681a5bbeSBoris Popov struct smbioc_oshare { 82681a5bbeSBoris Popov int ioc_opt; 83681a5bbeSBoris Popov int ioc_stype; /* share type */ 84681a5bbeSBoris Popov char ioc_share[SMB_MAXSHARENAMELEN + 1]; 85681a5bbeSBoris Popov char ioc_password[SMB_MAXPASSWORDLEN + 1]; 86681a5bbeSBoris Popov uid_t ioc_owner; /* proposed owner of share */ 87681a5bbeSBoris Popov gid_t ioc_group; /* proposed group of share */ 88681a5bbeSBoris Popov mode_t ioc_mode; /* desired access mode to share */ 89681a5bbeSBoris Popov mode_t ioc_rights; /* SMBM_* */ 90681a5bbeSBoris Popov }; 91681a5bbeSBoris Popov 92681a5bbeSBoris Popov struct smbioc_rq { 93681a5bbeSBoris Popov u_char ioc_cmd; 94681a5bbeSBoris Popov u_char ioc_twc; 95681a5bbeSBoris Popov void * ioc_twords; 96681a5bbeSBoris Popov u_short ioc_tbc; 97681a5bbeSBoris Popov void * ioc_tbytes; 98681a5bbeSBoris Popov int ioc_rpbufsz; 99681a5bbeSBoris Popov char * ioc_rpbuf; 100681a5bbeSBoris Popov u_char ioc_rwc; 101681a5bbeSBoris Popov u_short ioc_rbc; 102681a5bbeSBoris Popov u_int8_t ioc_errclass; 103681a5bbeSBoris Popov u_int16_t ioc_serror; 104681a5bbeSBoris Popov u_int32_t ioc_error; 105681a5bbeSBoris Popov }; 106681a5bbeSBoris Popov 107681a5bbeSBoris Popov struct smbioc_t2rq { 108681a5bbeSBoris Popov u_int16_t ioc_setup[3]; 109681a5bbeSBoris Popov int ioc_setupcnt; 110681a5bbeSBoris Popov char * ioc_name; 111681a5bbeSBoris Popov u_short ioc_tparamcnt; 112681a5bbeSBoris Popov void * ioc_tparam; 113681a5bbeSBoris Popov u_short ioc_tdatacnt; 114681a5bbeSBoris Popov void * ioc_tdata; 115681a5bbeSBoris Popov u_short ioc_rparamcnt; 116681a5bbeSBoris Popov void * ioc_rparam; 117681a5bbeSBoris Popov u_short ioc_rdatacnt; 118681a5bbeSBoris Popov void * ioc_rdata; 119681a5bbeSBoris Popov }; 120681a5bbeSBoris Popov 121681a5bbeSBoris Popov struct smbioc_flags { 122681a5bbeSBoris Popov int ioc_level; /* 0 - session, 1 - share */ 123681a5bbeSBoris Popov int ioc_mask; 124681a5bbeSBoris Popov int ioc_flags; 125681a5bbeSBoris Popov }; 126681a5bbeSBoris Popov 127681a5bbeSBoris Popov struct smbioc_lookup { 128681a5bbeSBoris Popov int ioc_level; 129681a5bbeSBoris Popov int ioc_flags; 130681a5bbeSBoris Popov struct smbioc_ossn ioc_ssn; 131681a5bbeSBoris Popov struct smbioc_oshare ioc_sh; 132681a5bbeSBoris Popov }; 133681a5bbeSBoris Popov 134681a5bbeSBoris Popov struct smbioc_rw { 135681a5bbeSBoris Popov smbfh ioc_fh; 136681a5bbeSBoris Popov char * ioc_base; 137681a5bbeSBoris Popov off_t ioc_offset; 138681a5bbeSBoris Popov int ioc_cnt; 139681a5bbeSBoris Popov }; 140681a5bbeSBoris Popov 141681a5bbeSBoris Popov /* 142681a5bbeSBoris Popov * Device IOCTLs 143681a5bbeSBoris Popov */ 144681a5bbeSBoris Popov #define SMBIOC_OPENSESSION _IOW('n', 100, struct smbioc_ossn) 145681a5bbeSBoris Popov #define SMBIOC_OPENSHARE _IOW('n', 101, struct smbioc_oshare) 146681a5bbeSBoris Popov #define SMBIOC_REQUEST _IOWR('n', 102, struct smbioc_rq) 147681a5bbeSBoris Popov #define SMBIOC_T2RQ _IOWR('n', 103, struct smbioc_t2rq) 148681a5bbeSBoris Popov #define SMBIOC_SETFLAGS _IOW('n', 104, struct smbioc_flags) 149681a5bbeSBoris Popov #define SMBIOC_LOOKUP _IOW('n', 106, struct smbioc_lookup) 150681a5bbeSBoris Popov #define SMBIOC_READ _IOWR('n', 107, struct smbioc_rw) 151681a5bbeSBoris Popov #define SMBIOC_WRITE _IOWR('n', 108, struct smbioc_rw) 152681a5bbeSBoris Popov 153681a5bbeSBoris Popov #ifdef _KERNEL 154681a5bbeSBoris Popov 155681a5bbeSBoris Popov #define SMBST_CONNECTED 1 156681a5bbeSBoris Popov 157681a5bbeSBoris Popov STAILQ_HEAD(smbrqh, smb_rq); 158681a5bbeSBoris Popov 159681a5bbeSBoris Popov struct smb_dev { 16092a4d9bcSDavide Italiano struct cdev * dev; 161681a5bbeSBoris Popov int sd_opened; 162681a5bbeSBoris Popov int sd_level; 163681a5bbeSBoris Popov struct smb_vc * sd_vc; /* reference to VC */ 164681a5bbeSBoris Popov struct smb_share *sd_share; /* reference to share if any */ 165681a5bbeSBoris Popov int sd_poll; 166681a5bbeSBoris Popov int sd_seq; 167681a5bbeSBoris Popov int sd_flags; 16892a4d9bcSDavide Italiano int refcount; 16992a4d9bcSDavide Italiano int usecount; 170681a5bbeSBoris Popov }; 171681a5bbeSBoris Popov 17292a4d9bcSDavide Italiano extern struct sx smb_lock; 17392a4d9bcSDavide Italiano #define SMB_LOCK() sx_xlock(&smb_lock) 17492a4d9bcSDavide Italiano #define SMB_UNLOCK() sx_unlock(&smb_lock) 17592a4d9bcSDavide Italiano #define SMB_LOCKASSERT() sx_assert(&smb_lock, SA_XLOCKED) 17692a4d9bcSDavide Italiano 177681a5bbeSBoris Popov struct smb_cred; 17892a4d9bcSDavide Italiano 17992a4d9bcSDavide Italiano void sdp_dtor(void *arg); 18092a4d9bcSDavide Italiano void sdp_trydestroy(struct smb_dev *dev); 18192a4d9bcSDavide Italiano 182681a5bbeSBoris Popov /* 183681a5bbeSBoris Popov * Compound user interface 184681a5bbeSBoris Popov */ 185681a5bbeSBoris Popov int smb_usr_lookup(struct smbioc_lookup *dp, struct smb_cred *scred, 186681a5bbeSBoris Popov struct smb_vc **vcpp, struct smb_share **sspp); 187681a5bbeSBoris Popov int smb_usr_opensession(struct smbioc_ossn *data, 188681a5bbeSBoris Popov struct smb_cred *scred, struct smb_vc **vcpp); 189681a5bbeSBoris Popov int smb_usr_openshare(struct smb_vc *vcp, struct smbioc_oshare *data, 190681a5bbeSBoris Popov struct smb_cred *scred, struct smb_share **sspp); 191681a5bbeSBoris Popov int smb_usr_simplerequest(struct smb_share *ssp, struct smbioc_rq *data, 192681a5bbeSBoris Popov struct smb_cred *scred); 193681a5bbeSBoris Popov int smb_usr_t2request(struct smb_share *ssp, struct smbioc_t2rq *data, 194681a5bbeSBoris Popov struct smb_cred *scred); 195681a5bbeSBoris Popov int smb_dev2share(int fd, int mode, struct smb_cred *scred, 19692a4d9bcSDavide Italiano struct smb_share **sspp, struct smb_dev **ssdp); 197681a5bbeSBoris Popov 198681a5bbeSBoris Popov 199681a5bbeSBoris Popov #endif /* _KERNEL */ 200681a5bbeSBoris Popov 201681a5bbeSBoris Popov #endif /* _NETSMB_DEV_H_ */ 202