xref: /onnv-gate/usr/src/uts/common/smbsrv/netbios.h (revision 10717:fe0545fc3cdd)
15331Samw /*
25331Samw  * CDDL HEADER START
35331Samw  *
45331Samw  * The contents of this file are subject to the terms of the
55331Samw  * Common Development and Distribution License (the "License").
65331Samw  * You may not use this file except in compliance with the License.
75331Samw  *
85331Samw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95331Samw  * or http://www.opensolaris.org/os/licensing.
105331Samw  * See the License for the specific language governing permissions
115331Samw  * and limitations under the License.
125331Samw  *
135331Samw  * When distributing Covered Code, include this CDDL HEADER in each
145331Samw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155331Samw  * If applicable, add the following below this CDDL HEADER, with the
165331Samw  * fields enclosed by brackets "[]" replaced with your own identifying
175331Samw  * information: Portions Copyright [yyyy] [name of copyright owner]
185331Samw  *
195331Samw  * CDDL HEADER END
205331Samw  */
215331Samw /*
229231SAfshin.Ardakani@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
235331Samw  * Use is subject to license terms.
245331Samw  */
255331Samw 
265331Samw #ifndef _SMBSRV_NETBIOS_H
275331Samw #define	_SMBSRV_NETBIOS_H
285331Samw 
295331Samw /*
305331Samw  * NetBIOS over TCP/IP interface definitions. NetBIOS over TCP/IP is
315331Samw  * documented in the following RFC documents:
325331Samw  *
335331Samw  * RFC 1001: Protocol Standard for a NetBIOS Service on a TCP/UDP
345331Samw  *           Transport: Concepts and Methods
355331Samw  *
365331Samw  * RFC 1002: Protocol Standard for a NetBIOS Service on a TCP/UDP
375331Samw  *           Transport: Detailed Specifications
385331Samw  *
395331Samw  * These documents reference RCF883.
405331Samw  * RFC 883:  Domain Names - Implementation and Specification
415331Samw  */
425331Samw 
435331Samw #ifdef __cplusplus
445331Samw extern "C" {
455331Samw #endif
465331Samw 
475331Samw 
485331Samw /*
495331Samw  * NetBIOS names in NetBIOS packets are valid domain names as defined in
505331Samw  * RFC 883. Each label is limited to 63 bytes with an overall length of
515331Samw  * 255 bytes as described in RFC 1002 section 4.1. This is known as
525331Samw  * second-level encoding. In first-level encoding the label lengths are
535331Samw  * represented as dots (.).
545331Samw  *
555331Samw  * RFC 1001 section 14.1 describes first-level encoding of the NetBIOS
565331Samw  * name (hostname) and scope. The ASCII name is padded to 15 bytes using
575331Samw  * spaces and a one byte type or suffix is written to the 16th byte.
585331Samw  * This is then encoded as a 32 byte string.
595331Samw  *
605331Samw  * NetBIOS Name:  NetBIOS
61*10717Samw@Sun.COM  * NetBIOS Scope: DOMAIN.COM
62*10717Samw@Sun.COM  * First Level:   EOGFHEECEJEPFDCACACACACACACACACA.DOMAIN.COM
63*10717Samw@Sun.COM  * Second Level:  <32>EOGFHEECEJEPFDCACACACACACACACACA<6>DOMAIN<3>COM<0>
645331Samw  */
655331Samw #define	NETBIOS_NAME_SZ			16
665331Samw #define	NETBIOS_ENCODED_NAME_SZ		32
675331Samw #define	NETBIOS_LABEL_MAX		63
685331Samw #define	NETBIOS_DOMAIN_NAME_MAX		255
695331Samw #define	NETBIOS_DOMAIN_NAME_BUFLEN	(NETBIOS_DOMAIN_NAME_MAX + 1)
705331Samw #define	NETBIOS_SESSION_REQUEST_DATA_LENGTH \
715331Samw 	((NETBIOS_ENCODED_NAME_SZ + 2) * 2)
725331Samw 
735331Samw #define	NETBIOS_HDR_SZ			4	/* bytes */
74*10717Samw@Sun.COM 
75*10717Samw@Sun.COM /*
76*10717Samw@Sun.COM  * NetBIOS name type/suffix: 16th byte of the NetBIOS name.
77*10717Samw@Sun.COM  * The NetBIOS suffix is used by to identify computer services.
78*10717Samw@Sun.COM  */
79*10717Samw@Sun.COM #define	NBT_WKSTA			0x00	/* Workstation Service */
80*10717Samw@Sun.COM #define	NBT_CLIENT			0x03	/* Messenger Service */
81*10717Samw@Sun.COM #define	NBT_RASSRVR			0x06	/* RAS Server Service */
82*10717Samw@Sun.COM #define	NBT_DMB				0x1B	/* Domain Master Browser */
83*10717Samw@Sun.COM #define	NBT_IP				0x1C	/* Domain Controller */
84*10717Samw@Sun.COM #define	NBT_MB				0x1D	/* Master Browser */
85*10717Samw@Sun.COM #define	NBT_BS				0x1E	/* Browser Elections */
86*10717Samw@Sun.COM #define	NBT_NETDDE			0x1F	/* NetDDE Service */
87*10717Samw@Sun.COM #define	NBT_SERVER			0x20	/* Server Service */
88*10717Samw@Sun.COM #define	NBT_RASCLNT			0x21	/* RAS Client Service */
89*10717Samw@Sun.COM 
905331Samw /*
915331Samw  * Session Packet Types (RFC 1002 4.3.1).
925331Samw  */
935331Samw #define	SESSION_MESSAGE			0x00
945331Samw #define	SESSION_REQUEST			0x81
955331Samw #define	POSITIVE_SESSION_RESPONSE	0x82
965331Samw #define	NEGATIVE_SESSION_RESPONSE	0x83
975331Samw #define	RETARGET_SESSION_RESPONSE	0x84
985331Samw #define	SESSION_KEEP_ALIVE		0x85
995331Samw 
1005331Samw /*
1015331Samw  * NEGATIVE SESSION RESPONSE packet error code values (RFC 1002 4.3.4).
1025331Samw  */
1035331Samw #define	SESSION_NOT_LISTENING_ON_CALLED_NAME	0x80
1045331Samw #define	SESSION_NOT_LISTENING_FOR_CALLING_NAME	0x81
1055331Samw #define	SESSION_CALLED_NAME_NOT_PRESENT		0x82
1065331Samw #define	SESSION_INSUFFICIENT_RESOURCES		0x83
1075331Samw #define	SESSION_UNSPECIFIED_ERROR		0x8F
1085331Samw 
1095331Samw /*
1105331Samw  * Time conversions
1115331Samw  */
1125331Samw #define	MILLISECONDS	1
1135331Samw #define	SECONDS		(1000 * MILLISECONDS)
1145331Samw #define	MINUTES		(60 * SECONDS)
1155331Samw #define	HOURS		(60 * MINUTES)
1165331Samw #define	TO_SECONDS(x)		((x) / 1000)
1175331Samw #define	TO_MILLISECONDS(x)	((x) * 1000)
1185331Samw 
1195331Samw /*
1205331Samw  * DATAGRAM service definitions
1215331Samw  */
1225331Samw #define	DATAGRAM_DESTINATION_NAME_NOT_PRESENT		0x82
1235331Samw #define	DATAGRAM_INVALID_SOURCE_NAME_FORMAT		0x83
1245331Samw #define	DATAGRAM_INVALID_DESTINATION_NAME_FORMAT	0x84
1255331Samw 
1269231SAfshin.Ardakani@Sun.COM #define	MAX_DATAGRAM_LENGTH		576
1279231SAfshin.Ardakani@Sun.COM #define	DATAGRAM_HEADER_LENGTH		14
1289231SAfshin.Ardakani@Sun.COM #define	DATAGRAM_ERR_HEADER_LENGTH	11
1299231SAfshin.Ardakani@Sun.COM #define	MAX_NAME_LENGTH			256
1309231SAfshin.Ardakani@Sun.COM #define	BCAST_REQ_RETRY_COUNT		2
1319231SAfshin.Ardakani@Sun.COM #define	UCAST_REQ_RETRY_COUNT		2
1329231SAfshin.Ardakani@Sun.COM #define	BCAST_REQ_RETRY_TIMEOUT		(500 * MILLISECONDS)
1339231SAfshin.Ardakani@Sun.COM #define	UCAST_REQ_RETRY_TIMEOUT		(500 * MILLISECONDS)
1349231SAfshin.Ardakani@Sun.COM #define	CONFLICT_TIMER			(1 * SECONDS)
1359231SAfshin.Ardakani@Sun.COM #define	INFINITE_TTL			0
1369231SAfshin.Ardakani@Sun.COM #define	DEFAULT_TTL			(600 * SECONDS)
1379231SAfshin.Ardakani@Sun.COM #define	SSN_RETRY_COUNT			4
1389231SAfshin.Ardakani@Sun.COM #define	SSN_CLOSE_TIMEOUT		(30 * SECONDS)
1395331Samw /*
1405331Samw  * K.L. The keep alive time out use to be default to
1415331Samw  * 900 seconds. It is not long enough for some applications
1425331Samw  * i.e. MS Access. Therefore, the timeout is increased to
1435331Samw  * 5400 seconds.
1445331Samw  */
1455331Samw #define	SSN_KEEP_ALIVE_TIMEOUT	(90 * 60) /* seconds */
1465331Samw #define	FRAGMENT_TIMEOUT	(2 * SECONDS)
1475331Samw 
1485331Samw /* smb_netbios_util.c */
1495331Samw extern int netbios_first_level_name_decode(char *in, char *name, char *scope);
1505331Samw extern int netbios_first_level_name_encode(unsigned char *name,
1515331Samw     unsigned char *scope, unsigned char *out, int max_out);
1525331Samw extern int netbios_name_isvalid(char *in, char *out);
1535331Samw 
1545331Samw #ifdef __cplusplus
1555331Samw }
1565331Samw #endif
1575331Samw 
1585331Samw #endif /* _SMBSRV_NETBIOS_H */
159