xref: /illumos-gate/usr/src/uts/common/fs/smbclnt/netsmb/smb_rq.h (revision 48e11a6ea0245c522078ddb86a73f16c8c28b949)
14bff34e3Sthurlow /*
24bff34e3Sthurlow  * Copyright (c) 2000-2001, Boris Popov
34bff34e3Sthurlow  * All rights reserved.
44bff34e3Sthurlow  *
54bff34e3Sthurlow  * Redistribution and use in source and binary forms, with or without
64bff34e3Sthurlow  * modification, are permitted provided that the following conditions
74bff34e3Sthurlow  * are met:
84bff34e3Sthurlow  * 1. Redistributions of source code must retain the above copyright
94bff34e3Sthurlow  *    notice, this list of conditions and the following disclaimer.
104bff34e3Sthurlow  * 2. Redistributions in binary form must reproduce the above copyright
114bff34e3Sthurlow  *    notice, this list of conditions and the following disclaimer in the
124bff34e3Sthurlow  *    documentation and/or other materials provided with the distribution.
134bff34e3Sthurlow  * 3. All advertising materials mentioning features or use of this software
144bff34e3Sthurlow  *    must display the following acknowledgement:
154bff34e3Sthurlow  *    This product includes software developed by Boris Popov.
164bff34e3Sthurlow  * 4. Neither the name of the author nor the names of any co-contributors
174bff34e3Sthurlow  *    may be used to endorse or promote products derived from this software
184bff34e3Sthurlow  *    without specific prior written permission.
194bff34e3Sthurlow  *
204bff34e3Sthurlow  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
214bff34e3Sthurlow  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
224bff34e3Sthurlow  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
234bff34e3Sthurlow  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
244bff34e3Sthurlow  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
254bff34e3Sthurlow  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
264bff34e3Sthurlow  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
274bff34e3Sthurlow  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
284bff34e3Sthurlow  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
294bff34e3Sthurlow  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
304bff34e3Sthurlow  * SUCH DAMAGE.
314bff34e3Sthurlow  *
324bff34e3Sthurlow  * $Id: smb_rq.h,v 1.9 2005/01/22 22:20:58 lindak Exp $
334bff34e3Sthurlow  */
349c9af259SGordon Ross 
359c9af259SGordon Ross /*
36148c5f43SAlan Wright  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
37adee6784SGordon Ross  * Portions Copyright (C) 2001 - 2012 Apple Inc. All rights reserved.
3840c0e231SGordon Ross  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
39*48e11a6eSGordon Ross  * Copyright 2024 RackTop Systems, Inc.
409c9af259SGordon Ross  */
419c9af259SGordon Ross 
424bff34e3Sthurlow #ifndef _NETSMB_SMB_RQ_H_
434bff34e3Sthurlow #define	_NETSMB_SMB_RQ_H_
444bff34e3Sthurlow 
454bff34e3Sthurlow #include <netsmb/mchain.h>
464bff34e3Sthurlow #include <sys/queue.h>
474bff34e3Sthurlow 
484bff34e3Sthurlow #define	SMBR_ALLOCED		0x0001	/* structure was malloced */
494bff34e3Sthurlow #define	SMBR_SENT		0x0002	/* request successfully transmitted */
504bff34e3Sthurlow #define	SMBR_REXMIT		0x0004	/* request should be retransmitted */
514bff34e3Sthurlow #define	SMBR_INTR		0x0008	/* request interrupted */
524bff34e3Sthurlow #define	SMBR_RESTART		0x0010	/* req should be repeated if possible */
534bff34e3Sthurlow #define	SMBR_NORESTART		0x0020	/* request is not restartable */
544bff34e3Sthurlow #define	SMBR_MULTIPACKET	0x0040	/* multiple pkts can be sent/received */
55613a2f6bSGordon Ross #define	SMBR_INTERNAL		0x0080	/* request enqueued by the IOD! */
564bff34e3Sthurlow #define	SMBR_NOINTR_SEND	0x0100	/* no interrupt in send wait */
574bff34e3Sthurlow #define	SMBR_NOINTR_RECV	0x0200	/* no interrupt in recv wait */
584bff34e3Sthurlow #define	SMBR_SENDWAIT		0x0400	/* waiting for send to complete */
59613a2f6bSGordon Ross #define	SMBR_NORECONNECT	0x0800	/* do not reconnect for this */
60613a2f6bSGordon Ross /*	SMBR_VCREF		0x4000	 * took vc reference (obsolete) */
614bff34e3Sthurlow #define	SMBR_MOREDATA		0x8000	/* our buffer was too small */
62adee6784SGordon Ross #define	SMBR_COMPOUND_RQ	0x10000	/* SMB 2/3 compound request */
63adee6784SGordon Ross #define	SMBR_ASYNC		0x20000	/* got async response */
64adee6784SGordon Ross #define	SMBR_RECONNECTED	0x40000	/* reconnected during request */
65*48e11a6eSGordon Ross #define	SMBR_ENCRYPTED		0x80000	/* reply was encrypted */
66adee6784SGordon Ross 
674bff34e3Sthurlow 
684bff34e3Sthurlow #define	SMBT2_ALLSENT		0x0001	/* all data and params are sent */
694bff34e3Sthurlow #define	SMBT2_ALLRECV		0x0002	/* all data and params are received */
704bff34e3Sthurlow #define	SMBT2_ALLOCED		0x0004
714bff34e3Sthurlow #define	SMBT2_RESTART		0x0008
724bff34e3Sthurlow #define	SMBT2_NORESTART		0x0010
734bff34e3Sthurlow #define	SMBT2_MOREDATA		0x8000	/* our buffer was too small */
744bff34e3Sthurlow 
754bff34e3Sthurlow #define	SMBRQ_LOCK(rqp)		mutex_enter(&(rqp)->sr_lock)
764bff34e3Sthurlow #define	SMBRQ_UNLOCK(rqp)	mutex_exit(&(rqp)->sr_lock)
774bff34e3Sthurlow 
784bff34e3Sthurlow enum smbrq_state {
794bff34e3Sthurlow 	SMBRQ_NOTSENT,		/* rq have data to send */
804bff34e3Sthurlow 	SMBRQ_SENT,		/* send procedure completed */
814bff34e3Sthurlow 	SMBRQ_REPLYRECEIVED,
824bff34e3Sthurlow 	SMBRQ_NOTIFIED		/* owner notified about completion */
834bff34e3Sthurlow };
844bff34e3Sthurlow 
854bff34e3Sthurlow struct smb_vc;
864bff34e3Sthurlow 
874bff34e3Sthurlow struct smb_rq {
884bff34e3Sthurlow 	TAILQ_ENTRY(smb_rq)	sr_link;
894bff34e3Sthurlow 	kmutex_t		sr_lock;
904bff34e3Sthurlow 	kcondvar_t		sr_cond;
914bff34e3Sthurlow 	enum smbrq_state	sr_state;
924bff34e3Sthurlow 	struct smb_vc		*sr_vc;
934bff34e3Sthurlow 	struct smb_share	*sr_share;
944bff34e3Sthurlow 	struct _kthread		*sr_owner;
959c9af259SGordon Ross 	uint32_t		sr_seqno;	/* Seq. no. of request */
969c9af259SGordon Ross 	uint32_t		sr_rseqno;	/* Seq. no. of reply */
974bff34e3Sthurlow 	struct mbchain		sr_rq;
984bff34e3Sthurlow 	uchar_t			sr_cmd;
994bff34e3Sthurlow 	uint8_t			sr_rqflags;
1004bff34e3Sthurlow 	uint16_t		sr_rqflags2;
101613a2f6bSGordon Ross 	uint16_t		sr_rqtid;
102adee6784SGordon Ross 	uint32_t		sr_pid;
103613a2f6bSGordon Ross 	uint16_t		sr_rquid;
104613a2f6bSGordon Ross 	uint16_t		sr_mid;
1054bff34e3Sthurlow 	uchar_t			*sr_wcount;
1064bff34e3Sthurlow 	uchar_t			*sr_bcount;
107adee6784SGordon Ross 
108adee6784SGordon Ross 	/* SMB 2/3 request fields */
109adee6784SGordon Ross 	struct smb_rq		*sr2_compound_next;
110adee6784SGordon Ross 	uint16_t		sr2_command;
111adee6784SGordon Ross 	uint16_t		sr2_totalcreditcharge;
112adee6784SGordon Ross 	uint16_t		sr2_creditcharge;
113adee6784SGordon Ross 	uint16_t		sr2_creditsrequested;
114adee6784SGordon Ross 	uint32_t		sr2_rqflags;
115adee6784SGordon Ross 	uint32_t		sr2_nextcmd;
116adee6784SGordon Ross 	uint64_t		sr2_messageid;   /* local copy of message id */
117adee6784SGordon Ross 	uint64_t		sr2_rqsessionid;
118adee6784SGordon Ross 	uint32_t		sr2_rqtreeid;
119adee6784SGordon Ross 
1204bff34e3Sthurlow 	struct mdchain		sr_rp;
1214bff34e3Sthurlow 	int			sr_rpgen;
1224bff34e3Sthurlow 	int			sr_rplast;
1234bff34e3Sthurlow 	int			sr_flags;	/* SMBR_* */
1244bff34e3Sthurlow 	int			sr_rpsize;
1254bff34e3Sthurlow 	struct smb_cred		*sr_cred;
1264bff34e3Sthurlow 	int			sr_timo;
1274bff34e3Sthurlow 	int			sr_rexmit; /* how many more retries.  dflt 0 */
1284bff34e3Sthurlow 	int			sr_sendcnt;
1294bff34e3Sthurlow 	struct timespec		sr_timesent;
1304bff34e3Sthurlow 	int			sr_lerror;
1314bff34e3Sthurlow 	uint8_t			sr_errclass;
1324bff34e3Sthurlow 	uint16_t		sr_serror;
1334bff34e3Sthurlow 	uint32_t		sr_error;
1344bff34e3Sthurlow 	uint8_t			sr_rpflags;
1354bff34e3Sthurlow 	uint16_t		sr_rpflags2;
1364bff34e3Sthurlow 	uint16_t		sr_rptid;
1374bff34e3Sthurlow 	uint16_t		sr_rppid;
1384bff34e3Sthurlow 	uint16_t		sr_rpuid;
1394bff34e3Sthurlow 	uint16_t		sr_rpmid;
140adee6784SGordon Ross 
141adee6784SGordon Ross 	/* SMB2 response fields */
142adee6784SGordon Ross 	uint16_t		sr2_rspcreditsgranted;
143adee6784SGordon Ross 	uint32_t		sr2_rspflags;
144adee6784SGordon Ross 	uint32_t		sr2_rspnextcmd;
145adee6784SGordon Ross 	uint32_t		sr2_rsppid;
146adee6784SGordon Ross 	uint32_t		sr2_rsptreeid;
147adee6784SGordon Ross 	uint64_t		sr2_rspasyncid;
148adee6784SGordon Ross 	uint64_t		sr2_rspsessionid;
1494bff34e3Sthurlow };
1504bff34e3Sthurlow typedef struct smb_rq smb_rq_t;
1514bff34e3Sthurlow 
1524bff34e3Sthurlow struct smb_t2rq {
1534bff34e3Sthurlow 	kmutex_t	t2_lock;
1544bff34e3Sthurlow 	kcondvar_t	t2_cond;
1554bff34e3Sthurlow 	uint16_t	t2_setupcount;
1564bff34e3Sthurlow 	uint16_t	*t2_setupdata;
15740c0e231SGordon Ross 	uint16_t	t2_setup[4];
1584bff34e3Sthurlow 	uint8_t		t2_maxscount;	/* max setup words to return */
1594bff34e3Sthurlow 	uint16_t	t2_maxpcount;	/* max param bytes to return */
1604bff34e3Sthurlow 	uint16_t	t2_maxdcount;	/* max data bytes to return */
1614bff34e3Sthurlow 	uint16_t	t2_fid;		/* for T2 request */
1629c9af259SGordon Ross 	char		*t_name;	/* for T, must be NULL for T2 */
1639c9af259SGordon Ross 	int		t_name_len;	/* t_name string length */
1649c9af259SGordon Ross 	int		t_name_maxlen;	/* t_name allocated size */
1654bff34e3Sthurlow 	int		t2_flags;	/* SMBT2_ */
1664bff34e3Sthurlow 	struct mbchain	t2_tparam;	/* parameters to transmit */
1674bff34e3Sthurlow 	struct mbchain	t2_tdata;	/* data to transmit */
1684bff34e3Sthurlow 	struct mdchain	t2_rparam;	/* received paramters */
1694bff34e3Sthurlow 	struct mdchain	t2_rdata;	/* received data */
1704bff34e3Sthurlow 	struct smb_cred	*t2_cred;
1714bff34e3Sthurlow 	struct smb_connobj	*t2_source;
1724bff34e3Sthurlow 	struct smb_rq	*t2_rq;
1734bff34e3Sthurlow 	struct smb_vc	*t2_vc;
1744bff34e3Sthurlow 	struct smb_share *t2_share;	/* for smb up/down */
1754bff34e3Sthurlow 	/* unmapped windows error detail */
1764bff34e3Sthurlow 	uint8_t		t2_sr_errclass;
1774bff34e3Sthurlow 	uint16_t	t2_sr_serror;
1784bff34e3Sthurlow 	uint32_t	t2_sr_error;
1794bff34e3Sthurlow 	uint16_t	t2_sr_rpflags2;
1804bff34e3Sthurlow };
1814bff34e3Sthurlow typedef struct smb_t2rq smb_t2rq_t;
1824bff34e3Sthurlow 
1834bff34e3Sthurlow struct smb_ntrq {
1844bff34e3Sthurlow 	kmutex_t	nt_lock;
1854bff34e3Sthurlow 	kcondvar_t	nt_cond;
1864bff34e3Sthurlow 	uint16_t	nt_function;
1874bff34e3Sthurlow 	uint8_t		nt_maxscount;	/* max setup words to return */
1884bff34e3Sthurlow 	uint32_t	nt_maxpcount;	/* max param bytes to return */
1894bff34e3Sthurlow 	uint32_t	nt_maxdcount;	/* max data bytes to return */
1904bff34e3Sthurlow 	int		nt_flags;	/* SMBT2_ */
1914bff34e3Sthurlow 	struct mbchain	nt_tsetup;	/* setup to transmit */
1924bff34e3Sthurlow 	struct mbchain	nt_tparam;	/* parameters to transmit */
1934bff34e3Sthurlow 	struct mbchain	nt_tdata;	/* data to transmit */
1944bff34e3Sthurlow 	struct mdchain	nt_rparam;	/* received paramters */
1954bff34e3Sthurlow 	struct mdchain	nt_rdata;	/* received data */
1964bff34e3Sthurlow 	struct smb_cred	*nt_cred;
1974bff34e3Sthurlow 	struct smb_connobj *nt_source;
1984bff34e3Sthurlow 	struct smb_rq	*nt_rq;
1994bff34e3Sthurlow 	struct smb_vc	*nt_vc;
2004bff34e3Sthurlow 	struct smb_share *nt_share;	/* for smb up/down */
2014bff34e3Sthurlow 	/* unmapped windows error details */
2024bff34e3Sthurlow 	uint32_t	nt_sr_error;
2034bff34e3Sthurlow 	uint16_t	nt_sr_rpflags2;
2044bff34e3Sthurlow };
2054bff34e3Sthurlow typedef struct smb_ntrq smb_ntrq_t;
2064bff34e3Sthurlow 
207613a2f6bSGordon Ross #define	smb_rq_getrequest(RQ, MBPP) \
208613a2f6bSGordon Ross 	*(MBPP) = &(RQ)->sr_rq
209613a2f6bSGordon Ross #define	smb_rq_getreply(RQ, MDPP) \
210613a2f6bSGordon Ross 	*(MDPP) = &(RQ)->sr_rp
211613a2f6bSGordon Ross 
212613a2f6bSGordon Ross void smb_rq_done(struct smb_rq *rqp);
2134bff34e3Sthurlow int   smb_rq_alloc(struct smb_connobj *layer, uchar_t cmd,
2144bff34e3Sthurlow 	struct smb_cred *scred, struct smb_rq **rqpp);
2154bff34e3Sthurlow int  smb_rq_init(struct smb_rq *rqp, struct smb_connobj *layer,
2164bff34e3Sthurlow 	uchar_t cmd, struct smb_cred *scred);
217adee6784SGordon Ross int  smb_rq_getenv(struct smb_connobj *layer,
218adee6784SGordon Ross 	struct smb_vc **vcpp, struct smb_share **sspp);
219613a2f6bSGordon Ross 
220613a2f6bSGordon Ross void smb_rq_fillhdr(struct smb_rq *rqp);
2214bff34e3Sthurlow void smb_rq_wstart(struct smb_rq *rqp);
2224bff34e3Sthurlow void smb_rq_wend(struct smb_rq *rqp);
2234bff34e3Sthurlow void smb_rq_bstart(struct smb_rq *rqp);
2244bff34e3Sthurlow void smb_rq_bend(struct smb_rq *rqp);
2254bff34e3Sthurlow int  smb_rq_simple(struct smb_rq *rqp);
2264bff34e3Sthurlow int  smb_rq_simple_timed(struct smb_rq *rqp, int timeout);
22740c0e231SGordon Ross int  smb_rq_internal(struct smb_rq *rqp, int timeout);
2284bff34e3Sthurlow 
229adee6784SGordon Ross int smb2_parse_smb1nego_resp(struct smb_rq *rqp);
230adee6784SGordon Ross 
2314bff34e3Sthurlow int  smb_t2_alloc(struct smb_connobj *layer, ushort_t setup,
2324bff34e3Sthurlow 	struct smb_cred *scred, struct smb_t2rq **rqpp);
2334bff34e3Sthurlow int  smb_t2_init(struct smb_t2rq *rqp, struct smb_connobj *layer,
2344bff34e3Sthurlow 	ushort_t *setup, int setupcnt, struct smb_cred *scred);
2354bff34e3Sthurlow void smb_t2_done(struct smb_t2rq *t2p);
2364bff34e3Sthurlow int  smb_t2_request(struct smb_t2rq *t2p);
2374bff34e3Sthurlow 
238adee6784SGordon Ross int smb_t2_xnp(struct smb_share *ssp, uint16_t fid,
239adee6784SGordon Ross     struct mbchain *send_mb, struct mdchain *recv_md,
240adee6784SGordon Ross     uint32_t *data_out_sz, uint32_t *more, struct smb_cred *scrp);
241adee6784SGordon Ross 
2424bff34e3Sthurlow int  smb_nt_alloc(struct smb_connobj *layer, ushort_t fn,
2434bff34e3Sthurlow 	struct smb_cred *scred, struct smb_ntrq **rqpp);
2444bff34e3Sthurlow int  smb_nt_init(struct smb_ntrq *rqp, struct smb_connobj *layer,
2454bff34e3Sthurlow 	ushort_t fn, struct smb_cred *scred);
2464bff34e3Sthurlow void smb_nt_done(struct smb_ntrq *ntp);
2474bff34e3Sthurlow int  smb_nt_request(struct smb_ntrq *ntp);
2484bff34e3Sthurlow 
2494bff34e3Sthurlow #endif /* _NETSMB_SMB_RQ_H_ */
250