1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 *
30 * ORIGINS: 82
31 *
32 * (C) COPYRIGHT Apple Computer, Inc. 1992-1996
33 * All Rights Reserved
34 *
35 */
36
37/* Miscellaneous definitions for AppleTalk used by all protocol
38 * modules.
39 */
40
41#ifndef _NETAT_APPLETALK_H_
42#define _NETAT_APPLETALK_H_
43#include <sys/appleapiopts.h>
44
45#include <sys/types.h>
46#include <sys/uio.h>
47
48#ifdef __APPLE_API_OBSOLETE
49
50/*
51   Non-aligned types are used in packet headers.
52*/
53
54/* New fundemental types: non-aligned variations of u_short and u_long */
55typedef u_char ua_short[2];		/* Unaligned short */
56typedef u_char ua_long[4];		/* Unaligned long */
57
58/* Two at_net typedefs; the first is aligned the other isn't */
59typedef u_short at_net_al;		/* Aligned AppleTalk network number */
60typedef ua_short at_net_unal;		/* Unaligned AppleTalk network number */
61
62/* Miscellaneous types */
63typedef u_char	at_node;		/* AppleTalk node number */
64typedef u_char  at_socket;		/* AppleTalk socket number */
65
66typedef at_net_unal at_net;	/* Default: Unaligned AppleTalk network number */
67struct atalk_addr {
68	u_char	atalk_unused;
69	at_net	atalk_net;
70	at_node	atalk_node;
71};
72
73/* Macros to manipulate unaligned fields */
74#define	UAS_ASSIGN(x,s)	*(unsigned short *) &(x[0]) = (unsigned short) (s)
75#define	UAS_UAS(x,y)	*(unsigned short *) &(x[0]) = *(unsigned short *) &(y[0])
76#define	UAS_VALUE(x)	(*(unsigned short *) &(x[0]))
77#define	UAL_ASSIGN(x,l)	*(unsigned long *) &(x[0]) = (unsigned long) (l)
78#define	UAL_UAL(x,y)	*(unsigned long *) &(x[0]) = *(unsigned long *) &(y[0])
79#define	UAL_VALUE(x)	(*(unsigned long *) &(x[0]))
80
81/* Macros to assign unaligned fields with byte swapping */
82#define	UAS_ASSIGN_HTON(x,s)	*(unsigned short *) &(x[0]) = htons((unsigned short) (s))
83#define	UAS_ASSIGN_NTOH(x,s)	*(unsigned short *) &(x[0]) = ntohs((unsigned short) (s))
84#define	UAS_VALUE_HTON(x)		htons((*(unsigned short *) &(x[0])))
85#define	UAS_VALUE_NTOH(x)		ntohs((*(unsigned short *) &(x[0])))
86#define	UAL_ASSIGN_HTON(x,l)	*(unsigned long *) &(x[0]) = htonl((unsigned long) (l))
87#define	UAL_ASSIGN_NTOH(x,l)	*(unsigned long *) &(x[0]) = ntohl((unsigned long) (l))
88#define	UAL_VALUE_HTON(x)		htonl((*(unsigned long *) &(x[0])))
89#define	UAL_VALUE_NTOH(x)		ntohl((*(unsigned long *) &(x[0])))
90
91/* Macros to manipulate at_net variables */
92#define	NET_ASSIGN(x,s)		*(unsigned short *)&(x[0]) = htons((unsigned short)(s))
93#define	NET_ASSIGN_NOSWAP(x,s)		*(unsigned short *)&(x[0]) = (unsigned short)(s)
94#define	NET_NET(x, y)		*(unsigned short *)&(x[0]) = *(unsigned short *)&(y[0])
95#define	NET_VALUE(x)		ntohs((*(unsigned short *) &(x[0])))
96#define	NET_VALUE_NOSWAP(x)		(*(unsigned short *) &(x[0]))
97#define ATALK_ASSIGN(a, net, node, unused ) \
98  a.atalk_unused = unused; a.atalk_node = node; NET_ASSIGN(a.atalk_net, net)
99
100#define NET_EQUAL(a, b)	(NET_VALUE(a) == NET_VALUE(b))
101#define NET_NOTEQ(a, b)	(NET_VALUE(a) != NET_VALUE(b))
102#define NET_EQUAL0(a)	(NET_VALUE(a) == 0)
103#define NET_NOTEQ0(a)	(NET_VALUE(a) != 0)
104
105
106/*
107   AppleTalk Internet Address
108*/
109
110typedef struct at_inet {
111	u_short	net;			/* Network Address */
112	u_char	node;			/* Node number */
113	u_char	socket;			/* Socket number */
114} at_inet_t;
115
116/*
117   DDP Address for OT
118*/
119
120typedef struct ddp_addr {
121	at_inet_t	inet;
122	u_short		ddptype;
123} ddp_addr_t;
124
125/*
126  AppleTalk address
127*/
128
129struct at_addr {
130	u_short     s_net;		/* 16-bit network address */
131	u_char      s_node;		/* 8-bit node # (1-0xfd) */
132};
133
134/*
135  Appletalk sockaddr definition
136*/
137struct sockaddr_at {
138	u_char  	sat_len;        /* total length */
139	u_char  	sat_family;     /* address family (AF_APPLETALK) */
140	u_char  	sat_port;	/* 8-bit "socket number" */
141	struct at_addr 	sat_addr;	/* 16-bit "net" and 8-bit "node */
142	char		sat_zero[8];	/* used for netrange in netatalk */
143};
144
145#define ATADDR_ANYNET	(u_short)0x0000
146#define ATADDR_ANYNODE	(u_char)0x00
147#define ATADDR_ANYPORT	(u_char)0x00
148
149#define ATADDR_BCASTNODE (u_char)0xff	/* There is no BCAST for NET */
150
151/* make sure the net, node and socket numbers are in legal range :
152 *
153 * Net#		0		Local Net
154 *		1 - 0xfffe	Legal net nos
155 *		0xffff		Reserved by Apple for future use.
156 * Node#	0		Illegal
157 *		1 - 0x7f	Legal (user node id's)
158 *		0x80 - 0xfe	Legal (server node id's; 0xfe illegal in
159 *				Phase II nodes)
160 *		0xff		Broadcast
161 * Socket#	0		Illegal
162 *		1 - 0xfe	Legal
163 *		0xff		Illegal
164 */
165#define valid_at_addr(addr) \
166	((!(addr) || (addr)->net == 0xffff || (addr)->node == 0 || \
167	  (addr)->socket == 0 || (addr)->socket == 0xff)? 0: 1)
168
169/*** * ETHERTYPE_ definitions are in netinet/if_ether.h *** */
170#define ETHERTYPE_AT    0x809B          /* AppleTalk protocol */
171#define ETHERTYPE_AARP  0x80F3          /* AppleTalk ARP */
172
173/*
174   DDP protocol types
175*/
176
177#define DDP_RTMP          0x01
178#define DDP_NBP           0x02
179#define DDP_ATP           0x03
180#define DDP_ECHO          0x04
181#define DDP_RTMP_REQ      0x05
182#define DDP_ZIP           0x06
183#define DDP_ADSP          0x07
184
185/*
186   Protocols for the socket API
187*/
188
189#define ATPROTO_NONE  	0		/* no corresponding DDP type exists */
190
191#define ATPROTO_ATP	DDP_ATP		/* must match DDP type */
192#define ATPROTO_ADSP    DDP_ADSP	/* must match DDP type */
193
194#define ATPROTO_DDP	249		/* *** to be eliminated eventually *** */
195#define ATPROTO_LAP   	250 		/* *** to be eliminated eventually *** */
196
197#define ATPROTO_AURP  	251		/* no corresponding DDP type exists */
198#define ATPROTO_ASP	252		/* no corresponding DDP type exists */
199#define ATPROTO_AFP	253		/* no corresponding DDP type exists */
200
201#define ATPROTO_RAW	255		/* no corresponding DDP type exists */
202
203/*
204  Options for use with [gs]etsockopt at the DDP level.
205  First word of comment is data type; bool is stored in int.
206*/
207#define DDP_CHKSUM_ON	1	/* int; default = FALSE;
208				   DDP checksums should be used */
209#define DDP_HDRINCL	2	/* int; default = FALSE;
210				   header is included with data */
211#define DDP_GETSOCKNAME	3	/* used to get ddp_addr_t */
212#define DDP_SLFSND_ON	4	/* int; default = FALSE;
213				   packets sent to the cable-multicast address
214				   on this socket will be looped back */
215#define DDP_STRIPHDR	5	/* int; default = FALSE;
216				   drop DDP header on receive (raw) */
217
218/*
219   AppleTalk protocol retry and timeout
220*/
221
222typedef struct at_retry {
223    short	interval;		/* Retry interval in seconds */
224    short	retries;		/* Maximum number of retries */
225    u_char      backoff;                /* Retry backoff, must be 1 through 4 */
226} at_retry_t;
227
228/*
229   Basic NBP Definitions needed for AppleTalk framework
230*/
231
232#define MAX_ZONES 50
233
234#define NBP_NVE_STR_SIZE	32	/* Maximum NBP tuple string size */
235typedef struct at_nvestr {
236	u_char		len;
237	u_char		str[NBP_NVE_STR_SIZE];
238} at_nvestr_t;
239
240/* Entity Name */
241typedef struct at_entity {
242	at_nvestr_t	object;
243	at_nvestr_t	type;
244	at_nvestr_t	zone;
245} at_entity_t;
246
247#define NBP_TUPLE_SIZE	((3*NBP_NVE_STR_SIZE)+3)
248			/* 3 for field lengths + 3*32 for three names */
249typedef struct at_nbptuple {
250	at_inet_t	enu_addr;
251	u_char		enu_enum;
252	at_entity_t 	enu_entity;
253} at_nbptuple_t;
254
255/*
256   Basic ATP Definitions needed for LibcAT
257*/
258
259#define ATP_TRESP_MAX       8	/* Maximum number of Tresp pkts */
260
261/* Response buffer structure for atp_sendreq() and atp_sendrsp() */
262typedef	struct	at_resp {
263	u_char	bitmap;				/* Bitmap of responses */
264	u_char	filler[3];			/* Force 68K to RISC alignment */
265	struct	iovec resp[ATP_TRESP_MAX];	/* Buffer for response data */
266	long	userdata[ATP_TRESP_MAX];	/* Buffer for response user data */
267} at_resp_t;
268
269/*
270   Needed for ASP and ADSP
271*/
272
273typedef struct {
274	int  maxlen; /* max buffer length */
275	int  len;    /* length of data */
276	char *buf;   /* pointer to buffer */
277} strbuf_t;
278
279#define	IFID_HOME	1 		/* home port in ifID_table */
280
281#define	ATALK_VALUE(a)		((*(u_long *) &(a))&0x00ffffff)
282
283#define VERSION_LENGTH		80	/* length of version string */
284
285/* struture containing general information regarding the state of
286 * the Appletalk networking
287 */
288typedef struct at_state {
289	unsigned int	flags;		/* various init flags */
290} at_state_t;
291
292/*  at_state_t 'flags' defines */
293#define AT_ST_STARTED		0x0001	/* set if protocol is fully enabled */
294#define AT_ST_STARTING		0x0002	/* set if interfaces are configured */
295#define AT_ST_MULTIHOME		0x0080	/* set if multihome mode */
296#define AT_ST_ROUTER		0x0100	/* set if we are a router */
297#define AT_ST_IF_CHANGED	0x0200	/* set when state of any I/F
298					   changes (for SNMP) */
299#define AT_ST_RT_CHANGED	0x0400  /* route table changed (for SNMP)*/
300#define AT_ST_ZT_CHANGED 	0x0800  /* zone table changed (for SNMP) */
301#define AT_ST_NBP_CHANGED	0x1000  /* if nbp table changed (for SNMP)*/
302
303#ifdef KERNEL_PRIVATE
304extern at_state_t at_state;		/* global state of AT network */
305
306#define ROUTING_MODE	(at_state.flags & AT_ST_ROUTER)
307#define MULTIHOME_MODE	(at_state.flags & AT_ST_MULTIHOME)
308#define MULTIPORT_MODE (ROUTING_MODE || MULTIHOME_MODE)
309#endif /* KERNEL_PRIVATE */
310
311/* defines originally from h/at_elap.h */
312#define AT_ADDR			0
313#define ET_ADDR			1
314#define AT_ADDR_NO_LOOP		2	/* disables packets from looping back */
315
316#endif /* __APPLE_API_OBSOLETE */
317#endif /* _NETAT_APPLETALK_H_ */
318