xref: /titanic_44/usr/src/uts/common/smbsrv/smb.h (revision 4a6ec905b96eb96a398c346f59e034a90ce8ad37)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SMBSRV_SMB_H
27 #define	_SMBSRV_SMB_H
28 
29 /*
30  * SMB definitions and interfaces, mostly defined in the CIFS spec.
31  */
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 /*
36  * SMB definitions and interfaces, mostly defined in the CIFS spec.
37  */
38 
39 #ifdef _KERNEL
40 #include <sys/types.h>
41 #endif
42 #include <smbsrv/smb_i18n.h>
43 #include <smbsrv/msgbuf.h>
44 
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 
51 /*
52  * Typedefs from CIFS section 3.2
53  */
54 typedef unsigned char UCHAR;
55 typedef unsigned short USHORT;
56 typedef uint32_t ULONG;
57 typedef int32_t LONG;
58 
59 
60 /*
61  * The msgbuf format and length of an SMB header.
62  */
63 #define	SMB_HEADER_DOS_FMT	"Mbbbwbww10.wwww"
64 #define	SMB_HEADER_NT_FMT	"Mblbww#c2.wwww"
65 #define	SMB_HEADER_LEN		32
66 #define	SMB_SIG_SIZE		8	/* SMB signature size */
67 
68 /*
69  * CIFS definition for the SMB header (CIFS Section 3.2). Note that the
70  * pid_high field is not documented in the 1997 CIFS specificaction. This
71  * is a decoded or memory-based definition, which may be padded to align
72  * its elements on word boundaries. See smb_hdrbuf_t for the network
73  * ready structure.
74  */
75 typedef struct smb_hdr {
76 	UCHAR protocol[4];
77 	UCHAR command;
78 
79 	union {
80 		struct {
81 			UCHAR error_class;
82 			UCHAR reserved;
83 			USHORT error;
84 		} dos_error;
85 		ULONG ntstatus;
86 	}status;
87 
88 	UCHAR flags;
89 	USHORT flags2;
90 	USHORT pid_high;
91 
92 	union {
93 		USHORT pad[5];
94 		struct {
95 			USHORT reserved;
96 			UCHAR security_sig[SMB_SIG_SIZE];
97 		} extra;
98 	} extra;
99 
100 	USHORT tid;
101 	USHORT pid;
102 	USHORT uid;
103 	USHORT mid;
104 } smb_hdr_t;
105 
106 
107 /*
108  * Encoded or packed SMB header in network ready format.
109  */
110 typedef struct smb_hdrbuf {
111 	unsigned char hdr[SMB_HEADER_LEN];
112 } smb_hdrbuf_t;
113 
114 typedef struct smb_nethdr {
115 	uint8_t sh_protocol[4];
116 	uint8_t sh_command;
117 
118 	union {
119 		struct {
120 			uint8_t sh_error_class;
121 			uint8_t sh_reserved;
122 			uint8_t sh_error[2];
123 		} dos_error;
124 		uint8_t sh_ntstatus[4];
125 	} status;
126 
127 	uint8_t sh_flags;
128 	uint8_t sh_flags2[2];
129 	uint8_t sh_pid_high[2];
130 
131 	union {
132 		uint8_t sh_pad[10];
133 		struct {
134 			uint8_t sh_reserved[2];
135 			uint8_t sh_security_sig[SMB_SIG_SIZE];
136 		} extra;
137 	} extra;
138 
139 	uint8_t sh_tid[2];
140 	uint8_t sh_pid[2];
141 	uint8_t sh_uid[2];
142 	uint8_t sh_mid[2];
143 } smb_nethdr_t;
144 
145 /*
146  * Protocol magic value as a 32-bit.  This will be 0xff 0x53 0x4d 0x42 on
147  * the wire.
148  */
149 
150 #define	SMB_PROTOCOL_MAGIC	0x424d53ff
151 
152 /*
153  * Time and date encoding (CIFS Section 3.6). The date is encoded such
154  * that the year has a range of 0-119, which represents 1980-2099. The
155  * month range is 1-12, and the day range is 1-31.
156  */
157 typedef struct smb_date {
158 	USHORT day   : 5;
159 	USHORT month : 4;
160 	USHORT year  : 7;
161 } smb_date_t;
162 
163 
164 /*
165  * The hours range is 0-23, the minutes range is 0-59 and the two_sec
166  * range is 0-29.
167  */
168 typedef struct smb_time {
169 	USHORT two_sec : 5;
170 	USHORT minutes : 6;
171 	USHORT hours    : 5;
172 } smb_time_t;
173 
174 
175 /*
176  * This is a 64-bit signed absolute time representing 100ns increments.
177  * A positive value represents the absolute time since 1601AD. A
178  * negative value represents a context specific relative time.
179  */
180 typedef struct smb_time2 {
181 	ULONG low_time;
182 	LONG high_time;
183 } smb_time2_t;
184 
185 
186 /*
187  * The number of seconds since Jan 1, 1970, 00:00:00.0.
188  */
189 typedef uint32_t smb_utime_t;
190 
191 
192 #define	SMB_LM_NEGOTIATE_WORDCNT		13
193 #define	SMB_NT_NEGOTIATE_WORDCNT		17
194 
195 
196 typedef struct smb_nt_negotiate_rsp {
197 	UCHAR word_count;
198 	USHORT dialect_index;
199 	UCHAR security_mode;
200 	USHORT max_mpx;
201 	USHORT max_vc;
202 	ULONG max_buffer_size;
203 	ULONG max_raw_size;
204 	ULONG session_key;
205 	ULONG capabilities;
206 	ULONG time_low;
207 	ULONG time_high;
208 	USHORT server_tz;
209 	UCHAR security_len;
210 	USHORT byte_count;
211 	UCHAR *guid;
212 	UCHAR *challenge;
213 	UCHAR *oem_domain;
214 } smb_nt_negotiate_rsp_t;
215 
216 /*
217  * SMB_COM_TRANSACTION
218  */
219 typedef struct smb_transact_rsp {
220 	UCHAR  WordCount;		/* Count of data bytes */
221 					/* value = 10 + SetupCount */
222 	USHORT TotalParamCount;		/* Total parameter bytes being sent */
223 	USHORT TotalDataCount;		/* Total data bytes being sent */
224 	USHORT Reserved;
225 	USHORT ParamCount;		/* Parameter bytes sent this buffer */
226 	USHORT ParamOffset;		/* Offset (from hdr start) to params */
227 	USHORT ParamDisplacement;	/* Displacement of these param bytes */
228 	USHORT DataCount;		/* Data bytes sent this buffer */
229 	USHORT DataOffset;		/* Offset (from hdr start) to data */
230 	USHORT DataDisplacement;	/* Displacement of these data bytes */
231 	UCHAR  SetupCount;		/* Count of setup words */
232 	USHORT BCC;
233 #if 0
234 	UCHAR Reserved2;		/* Reserved (pad above to word) */
235 	UCHAR Buffer[1];		/* Buffer containing: */
236 	USHORT Setup[];			/*  Setup words (# = SetupWordCount) */
237 	USHORT ByteCount;		/*  Count of data bytes */
238 	UCHAR Pad[];			/*  Pad to SHORT or LONG */
239 	UCHAR Params[];			/*  Param. bytes (# = ParamCount) */
240 	UCHAR Pad1[];			/*  Pad to SHORT or LONG */
241 	UCHAR Data[];			/*  Data bytes (# = DataCount) */
242 #endif
243 } smb_transact_rsp_t;
244 
245 /*
246  * SMBreadX
247  */
248 typedef struct smb_read_andx_rsp {
249 	UCHAR WordCount;
250 	UCHAR AndXCmd;
251 	UCHAR AndXReserved;
252 	USHORT AndXOffset;
253 	USHORT Remaining;
254 	USHORT DataCompactionMode;
255 	USHORT Reserved;
256 	USHORT DataLength;
257 	USHORT DataOffset;
258 	ULONG  DataLengthHigh;
259 	USHORT Reserved2[3];
260 	USHORT ByteCount;
261 #if 0
262 	UCHAR Pad[];
263 	UCHAR Data[];
264 #endif
265 } smb_read_andx_rsp_t;
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 
271 
272 #endif /* _SMBSRV_SMB_H */
273