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