| 1 | /* $NetBSD: smb_rq.h,v 1.13 2009/09/12 12:52:21 pooka Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2000-2001, Boris Popov |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. All advertising materials mentioning features or use of this software |
| 16 | * must display the following acknowledgement: |
| 17 | * This product includes software developed by Boris Popov. |
| 18 | * 4. Neither the name of the author nor the names of any co-contributors |
| 19 | * may be used to endorse or promote products derived from this software |
| 20 | * without specific prior written permission. |
| 21 | * |
| 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | * SUCH DAMAGE. |
| 33 | * |
| 34 | * FreeBSD: src/sys/netsmb/smb_rq.h,v 1.1 2001/04/10 07:59:06 bp Exp |
| 35 | */ |
| 36 | #ifndef _NETSMB_SMB_RQ_H_ |
| 37 | #define _NETSMB_SMB_RQ_H_ |
| 38 | |
| 39 | #ifndef _KERNEL |
| 40 | #error not supposed to be exposed to userland. |
| 41 | #endif /* !_KERNEL */ |
| 42 | |
| 43 | #ifndef MB_MSYSTEM |
| 44 | #include <netsmb/mchain.h> |
| 45 | #endif |
| 46 | |
| 47 | #define SMBR_ALLOCED 0x0001 /* structure was malloced */ |
| 48 | #define SMBR_SENT 0x0002 /* request successfully transmitted */ |
| 49 | #define SMBR_REXMIT 0x0004 /* request should be retransmitted */ |
| 50 | #define SMBR_INTR 0x0008 /* request interrupted */ |
| 51 | #define SMBR_RESTART 0x0010 /* request should be repeated if possible */ |
| 52 | #define SMBR_NORESTART 0x0020 /* request is not restartable */ |
| 53 | #define SMBR_MULTIPACKET 0x0040 /* multiple packets can be sent and received */ |
| 54 | #define SMBR_INTERNAL 0x0080 /* request is internal to smbrqd */ |
| 55 | #define SMBR_XLOCK 0x0100 /* request locked and can't be moved */ |
| 56 | #define SMBR_XLOCKWANT 0x0200 /* waiter on XLOCK */ |
| 57 | #define SMBR_NOWAIT 0x0400 /* don't wait for reply */ |
| 58 | |
| 59 | #define SMBT2_ALLSENT 0x0001 /* all data and params are sent */ |
| 60 | #define SMBT2_ALLRECV 0x0002 /* all data and params are received */ |
| 61 | #define SMBT2_ALLOCED 0x0004 |
| 62 | #define SMBT2_RESTART 0x0008 |
| 63 | #define SMBT2_NORESTART 0x0010 |
| 64 | |
| 65 | #define SMBRQ_SLOCK(rqp) smb_sl_lock(&(rqp)->sr_slock) |
| 66 | #define SMBRQ_SUNLOCK(rqp) smb_sl_unlock(&(rqp)->sr_slock) |
| 67 | #define SMBRQ_SLOCKPTR(rqp) (&(rqp)->sr_slock) |
| 68 | |
| 69 | /* save 16bit 'what' to memory pointed out by 'where' in little-endian format */ |
| 70 | #define SMBRQ_PUTLE16(where, what) \ |
| 71 | (where)[0] = (what) & 0xff; \ |
| 72 | (where)[1] = (what) >> 8 |
| 73 | |
| 74 | enum smbrq_state { |
| 75 | SMBRQ_NOTSENT, /* rq have data to send */ |
| 76 | SMBRQ_SENT, /* send procedure completed */ |
| 77 | SMBRQ_REPLYRECEIVED, |
| 78 | SMBRQ_NOTIFIED /* owner notified about completion */ |
| 79 | }; |
| 80 | |
| 81 | struct smb_vc; |
| 82 | struct smb_t2rq; |
| 83 | |
| 84 | struct smb_rq { |
| 85 | enum smbrq_state sr_state; |
| 86 | struct smb_vc * sr_vc; /* session */ |
| 87 | struct smb_share * sr_share; |
| 88 | struct mbchain sr_rq; |
| 89 | u_int8_t * sr_wcount; |
| 90 | u_int8_t * sr_bcount; |
| 91 | struct mdchain sr_rp; |
| 92 | u_int sr_rpgen; |
| 93 | u_int sr_rplast; |
| 94 | struct smb_cred * sr_cred; |
| 95 | u_short sr_mid; |
| 96 | u_short sr_flags; /* SMBR_* */ |
| 97 | struct callout sr_timo_ch; /* for timeout expiration */ |
| 98 | int sr_timo; /* timeout in ticks, -1 notimo*/ |
| 99 | int sr_sendcnt; |
| 100 | int sr_lerror; |
| 101 | u_int8_t * sr_rqtid; |
| 102 | u_int8_t * sr_rquid; |
| 103 | u_int16_t sr_rptid; |
| 104 | u_int16_t sr_rppid; |
| 105 | u_int16_t sr_rpuid; |
| 106 | u_int16_t sr_rpmid; |
| 107 | struct smb_slock sr_slock; /* short term locks */ |
| 108 | SIMPLEQ_ENTRY(smb_rq) sr_link; |
| 109 | |
| 110 | void (*sr_recvcallback)(void *); |
| 111 | void *sr_recvarg; |
| 112 | }; |
| 113 | |
| 114 | struct smb_t2rq { |
| 115 | u_int16_t t2_setupcount; |
| 116 | u_int16_t * t2_setupdata; |
| 117 | u_int16_t t2_setup[2]; /* most of rqs has setupcount of 1 */ |
| 118 | u_int8_t t2_maxscount; /* max setup words to return */ |
| 119 | u_int16_t t2_maxpcount; /* max param bytes to return */ |
| 120 | u_int16_t t2_maxdcount; /* max data bytes to return */ |
| 121 | u_int16_t t2_fid; /* for T2 request */ |
| 122 | char * t_name; /* for T request, should be zero for T2 */ |
| 123 | int t2_flags; /* SMBT2_ */ |
| 124 | struct mbchain t2_tparam; /* parameters to transmit */ |
| 125 | struct mbchain t2_tdata; /* data to transmit */ |
| 126 | struct mdchain t2_rparam; /* received parameters */ |
| 127 | struct mdchain t2_rdata; /* received data */ |
| 128 | struct smb_cred*t2_cred; |
| 129 | struct smb_connobj *t2_source; |
| 130 | struct smb_rq * t2_rq; |
| 131 | struct smb_vc * t2_vc; |
| 132 | }; |
| 133 | |
| 134 | void smb_rqpool_init(void); |
| 135 | void smb_rqpool_fini(void); |
| 136 | |
| 137 | int smb_rq_alloc(struct smb_connobj *layer, u_char cmd, |
| 138 | struct smb_cred *scred, struct smb_rq **rqpp); |
| 139 | void smb_rq_done(struct smb_rq *rqp); |
| 140 | int smb_rq_getrequest(struct smb_rq *rqp, struct mbchain **mbpp); |
| 141 | int smb_rq_getreply(struct smb_rq *rqp, struct mdchain **mbpp); |
| 142 | void smb_rq_wstart(struct smb_rq *rqp); |
| 143 | void smb_rq_wend(struct smb_rq *rqp); |
| 144 | void smb_rq_bstart(struct smb_rq *rqp); |
| 145 | void smb_rq_bend(struct smb_rq *rqp); |
| 146 | int smb_rq_intr(struct smb_rq *rqp); |
| 147 | int smb_rq_simple(struct smb_rq *rqp); |
| 148 | int smb_rq_enqueue(struct smb_rq *rqp); |
| 149 | int smb_rq_reply(struct smb_rq *rqp); |
| 150 | void smb_rq_setcallback(struct smb_rq *, void (*)(void *), void *); |
| 151 | |
| 152 | int smb_t2_alloc(struct smb_connobj *layer, u_short setup, struct smb_cred *scred, |
| 153 | struct smb_t2rq **rqpp); |
| 154 | void smb_t2_done(struct smb_t2rq *t2p); |
| 155 | int smb_t2_request(struct smb_t2rq *t2p); |
| 156 | |
| 157 | #endif /* !_NETSMB_SMB_RQ_H_ */ |
| 158 | |