1c398230bSWarner Losh /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3fe267a55SPedro 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 #ifndef _NETSMB_DEV_H_ 29681a5bbeSBoris Popov #define _NETSMB_DEV_H_ 30681a5bbeSBoris Popov 3134ae6c75SBoris Popov #ifndef _KERNEL 3234ae6c75SBoris Popov #include <sys/types.h> 3334ae6c75SBoris Popov #endif 3434ae6c75SBoris Popov #include <sys/ioccom.h> 3534ae6c75SBoris Popov 36cdcb16abSBoris Popov #include <netsmb/smb.h> 37cdcb16abSBoris Popov 38681a5bbeSBoris Popov #define NSMB_NAME "nsmb" 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 */ 4834ae6c75SBoris Popov #define SMBVOPT_SINGLESHARE 0x0004 /* keep only one 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; 61a67b22d6SChristian S.J. Peron uint32_t ioc_svlen; /* size of ioc_server address */ 62681a5bbeSBoris Popov struct sockaddr*ioc_server; 63a67b22d6SChristian S.J. Peron uint32_t 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 #define SMBST_CONNECTED 1 154681a5bbeSBoris Popov 155681a5bbeSBoris Popov STAILQ_HEAD(smbrqh, smb_rq); 156681a5bbeSBoris Popov 157681a5bbeSBoris Popov struct smb_dev { 15892a4d9bcSDavide Italiano struct cdev * dev; 159681a5bbeSBoris Popov int sd_opened; 160681a5bbeSBoris Popov int sd_level; 161681a5bbeSBoris Popov struct smb_vc * sd_vc; /* reference to VC */ 162681a5bbeSBoris Popov struct smb_share *sd_share; /* reference to share if any */ 163681a5bbeSBoris Popov int sd_poll; 164681a5bbeSBoris Popov int sd_seq; 165681a5bbeSBoris Popov int sd_flags; 16692a4d9bcSDavide Italiano int refcount; 16792a4d9bcSDavide Italiano int usecount; 168681a5bbeSBoris Popov }; 169681a5bbeSBoris Popov 17092a4d9bcSDavide Italiano extern struct sx smb_lock; 17192a4d9bcSDavide Italiano #define SMB_LOCK() sx_xlock(&smb_lock) 17292a4d9bcSDavide Italiano #define SMB_UNLOCK() sx_unlock(&smb_lock) 17392a4d9bcSDavide Italiano #define SMB_LOCKASSERT() sx_assert(&smb_lock, SA_XLOCKED) 17492a4d9bcSDavide Italiano 175681a5bbeSBoris Popov struct smb_cred; 17692a4d9bcSDavide Italiano 17792a4d9bcSDavide Italiano void sdp_dtor(void *arg); 17892a4d9bcSDavide Italiano void sdp_trydestroy(struct smb_dev *dev); 17992a4d9bcSDavide Italiano 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, 19492a4d9bcSDavide Italiano struct smb_share **sspp, struct smb_dev **ssdp); 195681a5bbeSBoris Popov 196681a5bbeSBoris Popov #endif /* _KERNEL */ 197681a5bbeSBoris Popov 198681a5bbeSBoris Popov #endif /* _NETSMB_DEV_H_ */ 199