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