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