xref: /titanic_50/usr/src/uts/common/smbsrv/netbios.h (revision 6343349bf9d42501532d1ee2e75718d86ee366fe)
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_NETBIOS_H
27 #define	_SMBSRV_NETBIOS_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * NetBIOS over TCP/IP interface definitions. NetBIOS over TCP/IP is
33  * documented in the following RFC documents:
34  *
35  * RFC 1001: Protocol Standard for a NetBIOS Service on a TCP/UDP
36  *           Transport: Concepts and Methods
37  *
38  * RFC 1002: Protocol Standard for a NetBIOS Service on a TCP/UDP
39  *           Transport: Detailed Specifications
40  *
41  * These documents reference RCF883.
42  * RFC 883:  Domain Names - Implementation and Specification
43  */
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 
50 /*
51  * NetBIOS names in NetBIOS packets are valid domain names as defined in
52  * RFC 883. Each label is limited to 63 bytes with an overall length of
53  * 255 bytes as described in RFC 1002 section 4.1. This is known as
54  * second-level encoding. In first-level encoding the label lengths are
55  * represented as dots (.).
56  *
57  * RFC 1001 section 14.1 describes first-level encoding of the NetBIOS
58  * name (hostname) and scope. The ASCII name is padded to 15 bytes using
59  * spaces and a one byte type or suffix is written to the 16th byte.
60  * This is then encoded as a 32 byte string.
61  *
62  * NetBIOS Name:  NetBIOS
63  * NetBIOS Scope: PROCOM.COM
64  * First Level:   EOGFHEECEJEPFDCACACACACACACACACA.PROCOM.COM
65  * Second Level:  <32>EOGFHEECEJEPFDCACACACACACACACACA<6>PROCOM<3>COM<0>
66  */
67 #define	NETBIOS_NAME_SZ			16
68 #define	NETBIOS_ENCODED_NAME_SZ		32
69 #define	NETBIOS_LABEL_MAX		63
70 #define	NETBIOS_DOMAIN_NAME_MAX		255
71 #define	NETBIOS_DOMAIN_NAME_BUFLEN	(NETBIOS_DOMAIN_NAME_MAX + 1)
72 #define	NETBIOS_SESSION_REQUEST_DATA_LENGTH \
73 	((NETBIOS_ENCODED_NAME_SZ + 2) * 2)
74 
75 #define	NETBIOS_HDR_SZ			4	/* bytes */
76 /*
77  * Session Packet Types (RFC 1002 4.3.1).
78  */
79 #define	SESSION_MESSAGE			0x00
80 #define	SESSION_REQUEST			0x81
81 #define	POSITIVE_SESSION_RESPONSE	0x82
82 #define	NEGATIVE_SESSION_RESPONSE	0x83
83 #define	RETARGET_SESSION_RESPONSE	0x84
84 #define	SESSION_KEEP_ALIVE		0x85
85 
86 /*
87  * NEGATIVE SESSION RESPONSE packet error code values (RFC 1002 4.3.4).
88  */
89 #define	SESSION_NOT_LISTENING_ON_CALLED_NAME	0x80
90 #define	SESSION_NOT_LISTENING_FOR_CALLING_NAME	0x81
91 #define	SESSION_CALLED_NAME_NOT_PRESENT		0x82
92 #define	SESSION_INSUFFICIENT_RESOURCES		0x83
93 #define	SESSION_UNSPECIFIED_ERROR		0x8F
94 
95 /*
96  * Time conversions
97  */
98 #define	MILLISECONDS	1
99 #define	SECONDS		(1000 * MILLISECONDS)
100 #define	MINUTES		(60 * SECONDS)
101 #define	HOURS		(60 * MINUTES)
102 #define	TO_SECONDS(x)		((x) / 1000)
103 #define	TO_MILLISECONDS(x)	((x) * 1000)
104 
105 /*
106  * DATAGRAM service definitions
107  */
108 #define	DATAGRAM_DESTINATION_NAME_NOT_PRESENT		0x82
109 #define	DATAGRAM_INVALID_SOURCE_NAME_FORMAT		0x83
110 #define	DATAGRAM_INVALID_DESTINATION_NAME_FORMAT	0x84
111 
112 #define	NAME_SERVICE_TCP_PORT	137
113 #define	NAME_SERVICE_UDP_PORT	137
114 #define	DGM_SRVC_UDP_PORT	138
115 #define	SSN_SRVC_TCP_PORT	139
116 #define	MAX_DATAGRAM_LENGTH	576
117 #define	DATAGRAM_HEADER_LENGTH	14
118 #define	MAX_NAME_LENGTH		256
119 #define	BCAST_REQ_RETRY_COUNT	2
120 #define	UCAST_REQ_RETRY_COUNT	2
121 #define	BCAST_REQ_RETRY_TIMEOUT	(500 * MILLISECONDS)
122 #define	UCAST_REQ_RETRY_TIMEOUT	(500 * MILLISECONDS)
123 #define	CONFLICT_TIMER		(1 * SECONDS)
124 #define	INFINITE_TTL		0
125 #define	DEFAULT_TTL		(600 * SECONDS)
126 #define	SSN_RETRY_COUNT		4
127 #define	SSN_CLOSE_TIMEOUT	(30 * SECONDS)
128 /*
129  * K.L. The keep alive time out use to be default to
130  * 900 seconds. It is not long enough for some applications
131  * i.e. MS Access. Therefore, the timeout is increased to
132  * 5400 seconds.
133  */
134 #define	SSN_KEEP_ALIVE_TIMEOUT	(90 * 60) /* seconds */
135 #define	FRAGMENT_TIMEOUT	(2 * SECONDS)
136 
137 /* smb_netbios_util.c */
138 extern int netbios_first_level_name_decode(char *in, char *name, char *scope);
139 extern int netbios_first_level_name_encode(unsigned char *name,
140     unsigned char *scope, unsigned char *out, int max_out);
141 extern int netbios_name_isvalid(char *in, char *out);
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif /* _SMBSRV_NETBIOS_H */
148