117680Spst/*
217680Spst * Copyright (c) 1988, 1989, 1990, 1993, 1994, 1995, 1996
317680Spst *	The Regents of the University of California.  All rights reserved.
417680Spst *
517680Spst * Redistribution and use in source and binary forms, with or without
617680Spst * modification, are permitted provided that: (1) source code distributions
717680Spst * retain the above copyright notice and this paragraph in its entirety, (2)
817680Spst * distributions including binary code include the above copyright notice and
917680Spst * this paragraph in its entirety in the documentation or other materials
1017680Spst * provided with the distribution, and (3) all advertising materials mentioning
1117680Spst * features or use of this software display the following acknowledgement:
1217680Spst * ``This product includes software developed by the University of California,
1317680Spst * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1417680Spst * the University nor the names of its contributors may be used to endorse
1517680Spst * or promote products derived from this software without specific prior
1617680Spst * written permission.
1717680Spst * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1817680Spst * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1917680Spst * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2017680Spst *
2117680Spst * AppleTalk protocol formats (courtesy Bill Croft of Stanford/SUMEX).
2217680Spst */
2317680Spst
2417680Spststruct LAP {
25276788Sdelphij	uint8_t		dst;
26276788Sdelphij	uint8_t		src;
27276788Sdelphij	uint8_t		type;
2817680Spst};
2917680Spst#define lapShortDDP	1	/* short DDP type */
3017680Spst#define lapDDP		2	/* DDP type */
3117680Spst#define lapKLAP		'K'	/* Kinetics KLAP type */
3217680Spst
3317680Spst/* Datagram Delivery Protocol */
3417680Spst
3517680Spststruct atDDP {
36276788Sdelphij	uint16_t	length;
37276788Sdelphij	uint16_t	checksum;
38276788Sdelphij	uint16_t	dstNet;
39276788Sdelphij	uint16_t	srcNet;
40276788Sdelphij	uint8_t		dstNode;
41276788Sdelphij	uint8_t		srcNode;
42276788Sdelphij	uint8_t		dstSkt;
43276788Sdelphij	uint8_t		srcSkt;
44276788Sdelphij	uint8_t		type;
4517680Spst};
4617680Spst
4717680Spststruct atShortDDP {
48276788Sdelphij	uint16_t	length;
49276788Sdelphij	uint8_t		dstSkt;
50276788Sdelphij	uint8_t		srcSkt;
51276788Sdelphij	uint8_t		type;
5217680Spst};
5317680Spst
5417680Spst#define	ddpMaxWKS	0x7F
5517680Spst#define	ddpMaxData	586
5617680Spst#define	ddpLengthMask	0x3FF
5717680Spst#define	ddpHopShift	10
5817680Spst#define	ddpSize		13	/* size of DDP header (avoid struct padding) */
5917680Spst#define	ddpSSize	5
6017680Spst#define	ddpWKS		128	/* boundary of DDP well known sockets */
6117680Spst#define	ddpRTMP		1	/* RTMP type */
6217680Spst#define	ddpRTMPrequest	5	/* RTMP request type */
6317680Spst#define	ddpNBP		2	/* NBP type */
6417680Spst#define	ddpATP		3	/* ATP type */
6517680Spst#define	ddpECHO		4	/* ECHO type */
6617680Spst#define	ddpIP		22	/* IP type */
6717680Spst#define	ddpARP		23	/* ARP type */
68146773Ssam#define ddpEIGRP        88      /* EIGRP over Appletalk */
6917680Spst#define	ddpKLAP		0x4b	/* Kinetics KLAP type */
7017680Spst
7117680Spst
7217680Spst/* AppleTalk Transaction Protocol */
7317680Spst
7417680Spststruct atATP {
75276788Sdelphij	uint8_t		control;
76276788Sdelphij	uint8_t		bitmap;
77276788Sdelphij	uint16_t	transID;
78276788Sdelphij	int32_t		userData;
7917680Spst};
8017680Spst
8117680Spst#define	atpReqCode	0x40
8217680Spst#define	atpRspCode	0x80
8317680Spst#define	atpRelCode	0xC0
8417680Spst#define	atpXO		0x20
8517680Spst#define	atpEOM		0x10
8617680Spst#define	atpSTS		0x08
8717680Spst#define	atpFlagMask	0x3F
8817680Spst#define	atpControlMask	0xF8
8917680Spst#define	atpMaxNum	8
9017680Spst#define	atpMaxData	578
9117680Spst
9217680Spst
9317680Spst/* AppleTalk Echo Protocol */
9417680Spst
9517680Spststruct atEcho {
96276788Sdelphij	uint8_t		echoFunction;
97276788Sdelphij	uint8_t		*echoData;
9817680Spst};
9917680Spst
10017680Spst#define echoSkt		4		/* the echoer socket */
10117680Spst#define echoSize	1		/* size of echo header */
10217680Spst#define echoRequest	1		/* echo request */
10317680Spst#define echoReply	2		/* echo request */
10417680Spst
10517680Spst
10617680Spst/* Name Binding Protocol */
10717680Spst
10817680Spststruct atNBP {
109276788Sdelphij	uint8_t		control;
110276788Sdelphij	uint8_t		id;
11117680Spst};
11217680Spst
11317680Spststruct atNBPtuple {
114276788Sdelphij	uint16_t	net;
115276788Sdelphij	uint8_t		node;
116276788Sdelphij	uint8_t		skt;
117276788Sdelphij	uint8_t		enumerator;
11817680Spst};
11917680Spst
12017680Spst#define	nbpBrRq		0x10
12117680Spst#define	nbpLkUp		0x20
12217680Spst#define	nbpLkUpReply	0x30
12317680Spst
12417680Spst#define	nbpNIS		2
12517680Spst#define	nbpTupleMax	15
12617680Spst
12717680Spst#define	nbpHeaderSize	2
12817680Spst#define nbpTupleSize	5
12917680Spst
13017680Spst#define nbpSkt		2		/* NIS */
13117680Spst
13217680Spst
13317680Spst/* Routing Table Maint. Protocol */
13417680Spst
13517680Spst#define	rtmpSkt		1	/* number of RTMP socket */
13617680Spst#define	rtmpSize	4	/* minimum size */
13717680Spst#define	rtmpTupleSize	3
13817680Spst
13917680Spst
14017680Spst/* Zone Information Protocol */
14117680Spst
14217680Spststruct zipHeader {
143276788Sdelphij	uint8_t		command;
144276788Sdelphij	uint8_t		netcount;
14517680Spst};
14617680Spst
14717680Spst#define	zipHeaderSize	2
14817680Spst#define	zipQuery	1
14917680Spst#define	zipReply	2
15017680Spst#define	zipTakedown	3
15117680Spst#define	zipBringup	4
15217680Spst#define	ddpZIP		6
15317680Spst#define	zipSkt		6
15417680Spst#define	GetMyZone	7
15517680Spst#define	GetZoneList	8
15617680Spst
15717680Spst/*
15817680Spst * UDP port range used for ddp-in-udp encapsulation is 16512-16639
15917680Spst * for client sockets (128-255) and 200-327 for server sockets
16017680Spst * (0-127).  We also try to recognize the pre-April 88 server
16117680Spst * socket range of 768-895.
16217680Spst */
16317680Spst#define atalk_port(p) \
16417680Spst	(((unsigned)((p) - 16512) < 128) || \
16517680Spst	 ((unsigned)((p) - 200) < 128) || \
16617680Spst	 ((unsigned)((p) - 768) < 128))
167