xref: /titanic_51/usr/src/uts/common/smbsrv/netbios.h (revision a90cf9f29973990687fa61de9f1f6ea22e924e40)
1da6c28aaSamw /*
2da6c28aaSamw  * CDDL HEADER START
3da6c28aaSamw  *
4da6c28aaSamw  * The contents of this file are subject to the terms of the
5da6c28aaSamw  * Common Development and Distribution License (the "License").
6da6c28aaSamw  * You may not use this file except in compliance with the License.
7da6c28aaSamw  *
8da6c28aaSamw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aaSamw  * or http://www.opensolaris.org/os/licensing.
10da6c28aaSamw  * See the License for the specific language governing permissions
11da6c28aaSamw  * and limitations under the License.
12da6c28aaSamw  *
13da6c28aaSamw  * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aaSamw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aaSamw  * If applicable, add the following below this CDDL HEADER, with the
16da6c28aaSamw  * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aaSamw  * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aaSamw  *
19da6c28aaSamw  * CDDL HEADER END
20da6c28aaSamw  */
21da6c28aaSamw /*
228b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23da6c28aaSamw  * Use is subject to license terms.
24da6c28aaSamw  */
25da6c28aaSamw 
26da6c28aaSamw #ifndef _SMBSRV_NETBIOS_H
27da6c28aaSamw #define	_SMBSRV_NETBIOS_H
28da6c28aaSamw 
29da6c28aaSamw /*
30da6c28aaSamw  * NetBIOS over TCP/IP interface definitions. NetBIOS over TCP/IP is
31da6c28aaSamw  * documented in the following RFC documents:
32da6c28aaSamw  *
33da6c28aaSamw  * RFC 1001: Protocol Standard for a NetBIOS Service on a TCP/UDP
34da6c28aaSamw  *           Transport: Concepts and Methods
35da6c28aaSamw  *
36da6c28aaSamw  * RFC 1002: Protocol Standard for a NetBIOS Service on a TCP/UDP
37da6c28aaSamw  *           Transport: Detailed Specifications
38da6c28aaSamw  *
39da6c28aaSamw  * These documents reference RCF883.
40da6c28aaSamw  * RFC 883:  Domain Names - Implementation and Specification
41da6c28aaSamw  */
42da6c28aaSamw 
43da6c28aaSamw #ifdef __cplusplus
44da6c28aaSamw extern "C" {
45da6c28aaSamw #endif
46da6c28aaSamw 
47da6c28aaSamw 
48da6c28aaSamw /*
49da6c28aaSamw  * NetBIOS names in NetBIOS packets are valid domain names as defined in
50da6c28aaSamw  * RFC 883. Each label is limited to 63 bytes with an overall length of
51da6c28aaSamw  * 255 bytes as described in RFC 1002 section 4.1. This is known as
52da6c28aaSamw  * second-level encoding. In first-level encoding the label lengths are
53da6c28aaSamw  * represented as dots (.).
54da6c28aaSamw  *
55da6c28aaSamw  * RFC 1001 section 14.1 describes first-level encoding of the NetBIOS
56da6c28aaSamw  * name (hostname) and scope. The ASCII name is padded to 15 bytes using
57da6c28aaSamw  * spaces and a one byte type or suffix is written to the 16th byte.
58da6c28aaSamw  * This is then encoded as a 32 byte string.
59da6c28aaSamw  *
60da6c28aaSamw  * NetBIOS Name:  NetBIOS
61*a0aa776eSAlan Wright  * NetBIOS Scope: DOMAIN.COM
62*a0aa776eSAlan Wright  * First Level:   EOGFHEECEJEPFDCACACACACACACACACA.DOMAIN.COM
63*a0aa776eSAlan Wright  * Second Level:  <32>EOGFHEECEJEPFDCACACACACACACACACA<6>DOMAIN<3>COM<0>
64da6c28aaSamw  */
65da6c28aaSamw #define	NETBIOS_NAME_SZ			16
66da6c28aaSamw #define	NETBIOS_ENCODED_NAME_SZ		32
67da6c28aaSamw #define	NETBIOS_LABEL_MAX		63
68da6c28aaSamw #define	NETBIOS_DOMAIN_NAME_MAX		255
69da6c28aaSamw #define	NETBIOS_DOMAIN_NAME_BUFLEN	(NETBIOS_DOMAIN_NAME_MAX + 1)
70da6c28aaSamw #define	NETBIOS_SESSION_REQUEST_DATA_LENGTH \
71da6c28aaSamw 	((NETBIOS_ENCODED_NAME_SZ + 2) * 2)
72da6c28aaSamw 
73da6c28aaSamw #define	NETBIOS_HDR_SZ			4	/* bytes */
74*a0aa776eSAlan Wright 
75*a0aa776eSAlan Wright /*
76*a0aa776eSAlan Wright  * NetBIOS name type/suffix: 16th byte of the NetBIOS name.
77*a0aa776eSAlan Wright  * The NetBIOS suffix is used by to identify computer services.
78*a0aa776eSAlan Wright  */
79*a0aa776eSAlan Wright #define	NBT_WKSTA			0x00	/* Workstation Service */
80*a0aa776eSAlan Wright #define	NBT_CLIENT			0x03	/* Messenger Service */
81*a0aa776eSAlan Wright #define	NBT_RASSRVR			0x06	/* RAS Server Service */
82*a0aa776eSAlan Wright #define	NBT_DMB				0x1B	/* Domain Master Browser */
83*a0aa776eSAlan Wright #define	NBT_IP				0x1C	/* Domain Controller */
84*a0aa776eSAlan Wright #define	NBT_MB				0x1D	/* Master Browser */
85*a0aa776eSAlan Wright #define	NBT_BS				0x1E	/* Browser Elections */
86*a0aa776eSAlan Wright #define	NBT_NETDDE			0x1F	/* NetDDE Service */
87*a0aa776eSAlan Wright #define	NBT_SERVER			0x20	/* Server Service */
88*a0aa776eSAlan Wright #define	NBT_RASCLNT			0x21	/* RAS Client Service */
89*a0aa776eSAlan Wright 
90da6c28aaSamw /*
91da6c28aaSamw  * Session Packet Types (RFC 1002 4.3.1).
92da6c28aaSamw  */
93da6c28aaSamw #define	SESSION_MESSAGE			0x00
94da6c28aaSamw #define	SESSION_REQUEST			0x81
95da6c28aaSamw #define	POSITIVE_SESSION_RESPONSE	0x82
96da6c28aaSamw #define	NEGATIVE_SESSION_RESPONSE	0x83
97da6c28aaSamw #define	RETARGET_SESSION_RESPONSE	0x84
98da6c28aaSamw #define	SESSION_KEEP_ALIVE		0x85
99da6c28aaSamw 
100da6c28aaSamw /*
101da6c28aaSamw  * NEGATIVE SESSION RESPONSE packet error code values (RFC 1002 4.3.4).
102da6c28aaSamw  */
103da6c28aaSamw #define	SESSION_NOT_LISTENING_ON_CALLED_NAME	0x80
104da6c28aaSamw #define	SESSION_NOT_LISTENING_FOR_CALLING_NAME	0x81
105da6c28aaSamw #define	SESSION_CALLED_NAME_NOT_PRESENT		0x82
106da6c28aaSamw #define	SESSION_INSUFFICIENT_RESOURCES		0x83
107da6c28aaSamw #define	SESSION_UNSPECIFIED_ERROR		0x8F
108da6c28aaSamw 
109da6c28aaSamw /*
110da6c28aaSamw  * Time conversions
111da6c28aaSamw  */
112da6c28aaSamw #define	MILLISECONDS	1
113da6c28aaSamw #define	SECONDS		(1000 * MILLISECONDS)
114da6c28aaSamw #define	MINUTES		(60 * SECONDS)
115da6c28aaSamw #define	HOURS		(60 * MINUTES)
116da6c28aaSamw #define	TO_SECONDS(x)		((x) / 1000)
117da6c28aaSamw #define	TO_MILLISECONDS(x)	((x) * 1000)
118da6c28aaSamw 
119da6c28aaSamw /*
120da6c28aaSamw  * DATAGRAM service definitions
121da6c28aaSamw  */
122da6c28aaSamw #define	DATAGRAM_DESTINATION_NAME_NOT_PRESENT		0x82
123da6c28aaSamw #define	DATAGRAM_INVALID_SOURCE_NAME_FORMAT		0x83
124da6c28aaSamw #define	DATAGRAM_INVALID_DESTINATION_NAME_FORMAT	0x84
125da6c28aaSamw 
126da6c28aaSamw #define	MAX_DATAGRAM_LENGTH		576
127da6c28aaSamw #define	DATAGRAM_HEADER_LENGTH		14
1288b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States #define	DATAGRAM_ERR_HEADER_LENGTH	11
129da6c28aaSamw #define	MAX_NAME_LENGTH			256
130da6c28aaSamw #define	BCAST_REQ_RETRY_COUNT		2
131da6c28aaSamw #define	UCAST_REQ_RETRY_COUNT		2
132da6c28aaSamw #define	BCAST_REQ_RETRY_TIMEOUT		(500 * MILLISECONDS)
133da6c28aaSamw #define	UCAST_REQ_RETRY_TIMEOUT		(500 * MILLISECONDS)
134da6c28aaSamw #define	CONFLICT_TIMER			(1 * SECONDS)
135da6c28aaSamw #define	INFINITE_TTL			0
136da6c28aaSamw #define	DEFAULT_TTL			(600 * SECONDS)
137da6c28aaSamw #define	SSN_RETRY_COUNT			4
138da6c28aaSamw #define	SSN_CLOSE_TIMEOUT		(30 * SECONDS)
139da6c28aaSamw #define	FRAGMENT_TIMEOUT	(2 * SECONDS)
140da6c28aaSamw 
141da6c28aaSamw /* smb_netbios_util.c */
142da6c28aaSamw extern int netbios_first_level_name_decode(char *in, char *name, char *scope);
143da6c28aaSamw extern int netbios_first_level_name_encode(unsigned char *name,
144da6c28aaSamw     unsigned char *scope, unsigned char *out, int max_out);
145da6c28aaSamw extern int netbios_name_isvalid(char *in, char *out);
146da6c28aaSamw 
147da6c28aaSamw #ifdef __cplusplus
148da6c28aaSamw }
149da6c28aaSamw #endif
150da6c28aaSamw 
151da6c28aaSamw #endif /* _SMBSRV_NETBIOS_H */
152