xref: /illumos-gate/usr/src/uts/common/netsmb/netbios.h (revision 7801e5e8b5bc4af34929c54a02cfb78398da08dd)
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  /*
36   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
37   * Use is subject to license terms.
38   */
39  
40  #ifndef _NETSMB_NETBIOS_H_
41  #define	_NETSMB_NETBIOS_H_
42  
43  #ifndef _NETINET_IN_H_
44  #include <netinet/in.h>
45  #endif
46  
47  /*
48   * This is a fake address family number, used to
49   * recognize our fake sockaddr_nb objects.
50   * This is never handed to bind or connect.
51   */
52  #ifndef AF_NETBIOS
53  #define	AF_NETBIOS (AF_MAX+2)
54  #endif
55  
56  #define	PF_NETBIOS	AF_NETBIOS
57  
58  /*
59   * NetBIOS port numbers by the names used in the Darwin code.
60   * XXX: Change the code to use IPPORT_xxx from in.h directly.
61   * XXX: Add IPPORT_SMB_OVER_TCP or some such (port 445)
62   */
63  #define	NBNS_UDP_PORT		IPPORT_NETBIOS_NS	/* 137 */
64  #define	SMB_TCP_PORT		IPPORT_NETBIOS_SSN	/* 139 */
65  
66  #define	NBPROTO_TCPSSN	1		/* NETBIOS session over TCP */
67  
68  #define	NB_NAMELEN	16
69  #define	NB_ENCNAMELEN	NB_NAMELEN * 2
70  #define	NB_MAXLABLEN	63
71  
72  #define	NB_MAXPKTLEN	0x1FFFF
73  
74  #define	NB_MINSALEN	(sizeof (struct sockaddr_nb))
75  
76  /*
77   * name types
78   */
79  #define	NBT_WKSTA	0x00
80  #define	NBT_CLIENT	0x03
81  #define	NBT_RASSRVR	0x06
82  #define	NBT_DMB		0x1B
83  #define	NBT_IP		0x1C
84  #define	NBT_MB		0x1D
85  #define	NBT_BS		0x1E
86  #define	NBT_NETDDE	0x1F
87  #define	NBT_SERVER	0x20
88  #define	NBT_RASCLNT	0x21
89  #define	NBT_NMAGENT	0xBE
90  #define	NBT_NMUTIL	0xBF
91  
92  /*
93   * Session packet types
94   */
95  #define	NB_SSN_MESSAGE		0x0
96  #define	NB_SSN_REQUEST		0x81
97  #define	NB_SSN_POSRESP		0x82
98  #define	NB_SSN_NEGRESP		0x83
99  #define	NB_SSN_RTGRESP		0x84
100  #define	NB_SSN_KEEPALIVE	0x85
101  
102  /*
103   * resolver: Opcodes
104   */
105  #define	NBNS_OPCODE_QUERY	0x00
106  #define	NBNS_OPCODE_REGISTER	0x05
107  #define	NBNS_OPCODE_RELEASE	0x06
108  #define	NBNS_OPCODE_WACK	0x07
109  #define	NBNS_OPCODE_REFRESH	0x08
110  #define	NBNS_OPCODE_RESPONSE	0x10	/* or'ed with other opcodes */
111  
112  /*
113   * resolver: NM_FLAGS
114   */
115  #define	NBNS_NMFLAG_BCAST	0x01
116  #define	NBNS_NMFLAG_RA		0x08	/* recursion available */
117  #define	NBNS_NMFLAG_RD		0x10	/* recursion desired */
118  #define	NBNS_NMFLAG_TC		0x20	/* truncation occured */
119  #define	NBNS_NMFLAG_AA		0x40	/* authoritative answer */
120  
121  /*
122   * resolver: Question types
123   */
124  #define	NBNS_QUESTION_TYPE_NB		0x0020
125  #define	NBNS_QUESTION_TYPE_NBSTAT	0x0021
126  
127  /*
128   * resolver: Question class
129   */
130  #define	NBNS_QUESTION_CLASS_IN	0x0001
131  
132  /*
133   * resolver: Limits
134   */
135  #define	NBNS_MAXREDIRECTS	3	/* max number of accepted redirects */
136  #define	NBDG_MAXSIZE		576	/* maximum nbns datagram size */
137  
138  /*
139   * NETBIOS addressing
140   */
141  
142  struct nb_name {
143  	uint_t		nn_type;
144  	char		nn_name[NB_NAMELEN];
145  	char		*nn_scope;
146  };
147  typedef struct nb_name nb_name_t;
148  
149  /*
150   * Our private NetBIOS socket address format.
151   * Note that it's LARGER than sockaddr.
152   *
153   * XXX: Also note that the library code is sloppy about
154   * casting this to sockaddr_in so let's keep snb_ipaddr
155   * at the same offset, at least until that's fixed.
156   */
157  struct sockaddr_nb {
158  	sa_family_t	snb_family;	/* address family */
159  	uint16_t    snb_flags;	/* NBNS_GROUPFLG, etc. */
160  	uint32_t	snb_ipaddr; /* always IPv4 */
161  	char		snb_name[NB_NAMELEN]; /* NOT encoded */
162  };
163  typedef struct sockaddr_nb sockaddr_nb_t;
164  
165  #endif /* !_NETSMB_NETBIOS_H_ */
166