xref: /titanic_41/usr/src/uts/common/netsmb/netbios.h (revision cc1a9a89a73172cc2db053635fab3b1b91691657)
1 /*
2  * Copyright (c) 2000-2001 Boris Popov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *    This product includes software developed by Boris Popov.
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * $Id: netbios.h,v 1.5 2004/03/19 01:49:45 lindak Exp $
33  */
34 
35 #ifndef _NETSMB_NETBIOS_H_
36 #define	_NETSMB_NETBIOS_H_
37 
38 #pragma ident	"%Z%%M%	%I%	%E% SMI"
39 
40 #ifndef _NETINET_IN_H_
41 #include <netinet/in.h>
42 #endif
43 
44 /*
45  * This is a fake address family number, used to
46  * recognize our fake sockaddr_nb objects.
47  * This is never handed to bind or connect.
48  */
49 #ifndef AF_NETBIOS
50 #define	AF_NETBIOS (AF_MAX+2)
51 #endif
52 
53 #define	PF_NETBIOS	AF_NETBIOS
54 
55 /*
56  * NetBIOS port numbers by the names used in the Darwin code.
57  * XXX: Change the code to use IPPORT_xxx from in.h directly.
58  * XXX: Add IPPORT_SMB_OVER_TCP or some such (port 445)
59  */
60 #define	NBNS_UDP_PORT		IPPORT_NETBIOS_NS	/* 137 */
61 #define	SMB_TCP_PORT		IPPORT_NETBIOS_SSN	/* 139 */
62 
63 #define	NBPROTO_TCPSSN	1		/* NETBIOS session over TCP */
64 
65 #define	NB_NAMELEN	16
66 #define	NB_ENCNAMELEN	NB_NAMELEN * 2
67 #define	NB_MAXLABLEN	63
68 
69 #define	NB_MINSALEN	(sizeof (struct sockaddr_nb))
70 
71 /*
72  * name types
73  */
74 #define	NBT_WKSTA	0x00
75 #define	NBT_CLIENT	0x03
76 #define	NBT_RASSRVR	0x06
77 #define	NBT_DMB		0x1B
78 #define	NBT_IP		0x1C
79 #define	NBT_MB		0x1D
80 #define	NBT_BS		0x1E
81 #define	NBT_NETDDE	0x1F
82 #define	NBT_SERVER	0x20
83 #define	NBT_RASCLNT	0x21
84 #define	NBT_NMAGENT	0xBE
85 #define	NBT_NMUTIL	0xBF
86 
87 /*
88  * Session packet types
89  */
90 #define	NB_SSN_MESSAGE		0x0
91 #define	NB_SSN_REQUEST		0x81
92 #define	NB_SSN_POSRESP		0x82
93 #define	NB_SSN_NEGRESP		0x83
94 #define	NB_SSN_RTGRESP		0x84
95 #define	NB_SSN_KEEPALIVE	0x85
96 
97 /*
98  * resolver: Opcodes
99  */
100 #define	NBNS_OPCODE_QUERY	0x00
101 #define	NBNS_OPCODE_REGISTER	0x05
102 #define	NBNS_OPCODE_RELEASE	0x06
103 #define	NBNS_OPCODE_WACK	0x07
104 #define	NBNS_OPCODE_REFRESH	0x08
105 #define	NBNS_OPCODE_RESPONSE	0x10	/* or'ed with other opcodes */
106 
107 /*
108  * resolver: NM_FLAGS
109  */
110 #define	NBNS_NMFLAG_BCAST	0x01
111 #define	NBNS_NMFLAG_RA		0x08	/* recursion available */
112 #define	NBNS_NMFLAG_RD		0x10	/* recursion desired */
113 #define	NBNS_NMFLAG_TC		0x20	/* truncation occured */
114 #define	NBNS_NMFLAG_AA		0x40	/* authoritative answer */
115 
116 /*
117  * resolver: Question types
118  */
119 #define	NBNS_QUESTION_TYPE_NB		0x0020
120 #define	NBNS_QUESTION_TYPE_NBSTAT	0x0021
121 
122 /*
123  * resolver: Question class
124  */
125 #define	NBNS_QUESTION_CLASS_IN	0x0001
126 
127 /*
128  * resolver: Limits
129  */
130 #define	NBNS_MAXREDIRECTS	3	/* max number of accepted redirects */
131 #define	NBDG_MAXSIZE		576	/* maximum nbns datagram size */
132 
133 /*
134  * NETBIOS addressing
135  */
136 
137 struct nb_name {
138 	uint_t		nn_type;
139 	char		nn_name[NB_NAMELEN];
140 	char		*nn_scope;
141 };
142 typedef struct nb_name nb_name_t;
143 
144 /*
145  * Our private NetBIOS socket address format.
146  * Note that it's LARGER than sockaddr.
147  *
148  * XXX: Also note that the library code is sloppy about
149  * casting this to sockaddr_in so let's keep snb_ipaddr
150  * at the same offset, at least until that's fixed.
151  */
152 struct sockaddr_nb {
153 	sa_family_t	snb_family;	/* address family */
154 	uint16_t    snb_flags;	/* NBNS_GROUPFLG, etc. */
155 	uint32_t	snb_ipaddr; /* always IPv4 */
156 	char		snb_name[NB_NAMELEN]; /* NOT encoded */
157 };
158 typedef struct sockaddr_nb sockaddr_nb_t;
159 
160 #endif /* !_NETSMB_NETBIOS_H_ */
161