1139823Simp/*-
244165Sjulian * Copyright (c) 1998, Larry Lile
344165Sjulian * All rights reserved.
444165Sjulian *
544165Sjulian * For latest sources and information on this driver, please
644165Sjulian * go to http://anarchy.stdio.com.
744165Sjulian *
844165Sjulian * Questions, comments or suggestions should be directed to
944165Sjulian * Larry Lile <lile@stdio.com>.
1044165Sjulian *
1144165Sjulian * Redistribution and use in source and binary forms, with or without
1244165Sjulian * modification, are permitted provided that the following conditions
1344165Sjulian * are met:
1444165Sjulian * 1. Redistributions of source code must retain the above copyright
1544165Sjulian *    notice unmodified, this list of conditions, and the following
1644165Sjulian *    disclaimer.
1744165Sjulian * 2. Redistributions in binary form must reproduce the above copyright
1844165Sjulian *    notice, this list of conditions and the following disclaimer in the
1944165Sjulian *    documentation and/or other materials provided with the distribution.
2044165Sjulian *
2144165Sjulian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2244165Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2344165Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2444165Sjulian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2544165Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2644165Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2744165Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2844165Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2944165Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3044165Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3144165Sjulian * SUCH DAMAGE.
3244165Sjulian *
3350477Speter * $FreeBSD$
3444165Sjulian *
3544165Sjulian * Information gathered from tokenring@freebsd, /sys/net/ethernet.h and
3644165Sjulian * the Mach token ring driver.
3744165Sjulian */
3844165Sjulian
3944165Sjulian/*
4044165Sjulian * Fundamental constants relating to iso 802.5
4144165Sjulian */
4244165Sjulian
4344165Sjulian#ifndef _NET_ISO88025_H_
44112305Smdodd#define	_NET_ISO88025_H_
4544165Sjulian
4644165Sjulian/*
4758313Slile * General ISO 802.5 definitions
4844165Sjulian */
4944165Sjulian#define	ISO88025_ADDR_LEN	6
50112305Smdodd#define	ISO88025_CF_LEN		2
51112305Smdodd#define	ISO88025_HDR_LEN	(ISO88025_CF_LEN + (ISO88025_ADDR_LEN * 2))
52112305Smdodd#define	RCF_LEN			2
53112305Smdodd#define	RIF_MAX_RD		14
54112305Smdodd#define	RIF_MAX_LEN		16
5544165Sjulian
56112305Smdodd#define	TR_AC			0x10
57112305Smdodd#define	TR_LLC_FRAME		0x40
5844165Sjulian
59112305Smdodd#define	TR_4MBPS		4000000
60112305Smdodd#define	TR_16MBPS		16000000
61112305Smdodd#define	TR_100MBPS		100000000
6244165Sjulian
6344165Sjulian/*
6458313Slile * Source routing
6544165Sjulian */
6658313Slile#define	TR_RII			0x80
67112305Smdodd#define	TR_RCF_BCST_MASK	0xe000
68112305Smdodd#define	TR_RCF_LEN_MASK		0x1f00
69112305Smdodd#define	TR_RCF_DIR		0x0080
70112305Smdodd#define	TR_RCF_LF_MASK		0x0070
7144165Sjulian
72112305Smdodd#define	TR_RCF_RIFLEN(x)	((ntohs(x) & TR_RCF_LEN_MASK) >> 8)
7358313Slile
7444165Sjulian/*
7558313Slile * Minimum and maximum packet payload lengths.
7644165Sjulian */
7758313Slile#define	ISO88025_MIN_LEN	0
7874407Smdodd#define	ISO88025_MAX_LEN_4	4464
7974407Smdodd#define	ISO88025_MAX_LEN_16	17960
8074407Smdodd#define	ISO88025_MAX_LEN	ISO88025_MAX_LEN_16
8144165Sjulian
8244165Sjulian/*
8344165Sjulian * A macro to validate a length with
8444165Sjulian */
8544165Sjulian#define	ISO88025_IS_VALID_LEN(foo)	\
8644165Sjulian	((foo) >= ISO88025_MIN_LEN && (foo) <= ISO88025_MAX_LEN)
8744165Sjulian
88145002Smdodd/* Access Control field */
89145002Smdodd#define	AC_PRI_MASK		0xe0	/* Priority bits 		*/
90145002Smdodd#define	AC_TOKEN		0x10	/* Token bit: 0=Token, 1=Frame	*/
91145002Smdodd#define	AC_MONITOR		0x08	/* Monitor			*/
92145002Smdodd#define	AC_RESV_MASK		0x07	/* Reservation bits		*/
93145002Smdodd
94145002Smdodd/* Frame Control field */
95145002Smdodd#define	FC_FT_MASK		0xc0	/* Frame Type			*/
96145002Smdodd#define	FC_FT_MAC		0x00	/* MAC frame			*/
97145002Smdodd#define	FC_FT_LLC		0x40	/* LLC frame			*/
98145002Smdodd#define	FC_ATTN_MASK		0x0f	/* Attention bits		*/
99145002Smdodd#define	FC_ATTN_EB		0x01	/* Express buffer		*/
100145002Smdodd#define	FC_ATTN_BE		0x02	/* Beacon			*/
101145002Smdodd#define	FC_ATTN_CT		0x03	/* Claim token			*/
102145002Smdodd#define	FC_ATTN_RP		0x04	/* Ring purge			*/
103145002Smdodd#define	FC_ATTN_AMP		0x05	/* Active monitor present	*/
104145002Smdodd#define	FC_ATTN_SMP		0x06	/* Standby monitor present	*/
105145002Smdodd
106145002Smdodd/* Token Ring destination address */
107145002Smdodd#define	DA_IG			0x80	/* Individual/group address.	*/
108145002Smdodd					/* 0=Individual, 1=Group	*/
109145002Smdodd#define	DA_UL			0x40	/* Universal/local address.	*/
110145002Smdodd					/* 0=Universal, 1=Local		*/
111145002Smdodd/* Token Ring source address */
112145002Smdodd#define	SA_RII			0x80	/* Routing information indicator */
113145002Smdodd#define	SA_IG			0x40	/* Individual/group address	*/
114145002Smdodd					/* 0=Group, 1=Individual	*/
115145002Smdodd
11644165Sjulian/*
11758313Slile * ISO 802.5 physical header
11844165Sjulian */
11944165Sjulianstruct iso88025_header {
12074407Smdodd	u_int8_t	ac;				    /* access control field */
12174407Smdodd	u_int8_t	fc;				    /* frame control field */
12274407Smdodd	u_int8_t	iso88025_dhost[ISO88025_ADDR_LEN];  /* destination address */
12374407Smdodd	u_int8_t	iso88025_shost[ISO88025_ADDR_LEN];  /* source address */
12474407Smdodd	u_int16_t	rcf;				    /* route control field */
12574407Smdodd	u_int16_t	rd[RIF_MAX_RD];			    /* routing designators */
126103844Salfred} __packed;
12744165Sjulian
12874407Smdoddstruct iso88025_rif {
12974407Smdodd	u_int16_t	rcf;				    /* route control field */
13074407Smdodd	u_int16_t	rd[RIF_MAX_RD];			    /* routing designators */
131103844Salfred} __packed;
13274407Smdodd
13344627Sjulianstruct iso88025_sockaddr_data {
13444627Sjulian	u_char ether_dhost[ISO88025_ADDR_LEN];
13544627Sjulian	u_char ether_shost[ISO88025_ADDR_LEN];
13644627Sjulian	u_char ac;
13744627Sjulian	u_char fc;
13844627Sjulian};
13944627Sjulian
14096184Skbyancstruct iso88025_sockaddr_dl_data {
14196184Skbyanc	u_short	 trld_rcf;
14296184Skbyanc	u_short	*trld_route[RIF_MAX_LEN];
14396184Skbyanc};
14496184Skbyanc
145112305Smdodd#define	ISO88025_MAX(a, b)	(((a)>(b))?(a):(b))
146112305Smdodd#define	SDL_ISO88025(s)		((struct iso88025_sockaddr_dl_data *)	\
14796203Skbyanc				 ((s)->sdl_data + \
14896400Skbyanc				  ISO88025_MAX((s)->sdl_nlen + (s)->sdl_alen + \
14996203Skbyanc					       (s)->sdl_slen, 12)))
15096184Skbyanc
15144165Sjulian/*
15244165Sjulian * Structure of a 48-bit iso 802.5 address.
15344165Sjulian *  ( We could also add the 16 bit addresses as a union)
15444165Sjulian */
15544165Sjulianstruct	iso88025_addr {
15644165Sjulian	u_char octet[ISO88025_ADDR_LEN];
15744165Sjulian};
15844165Sjulian
159112305Smdodd#define	ISO88025_MAX_MTU		18000
160112305Smdodd#define	ISO88025_DEFAULT_MTU		1500
16144165Sjulian
162112297Smdodd#define	ISO88025_BPF_UNSUPPORTED	0
163112297Smdodd#define	ISO88025_BPF_SUPPORTED		1
164112297Smdodd
165264299Sglebius#ifdef _KERNEL
166152296Sruvoid	iso88025_ifattach	(struct ifnet *, const u_int8_t *, int);
16774407Smdoddvoid	iso88025_ifdetach	(struct ifnet *, int);
168194581Srdivackyint	iso88025_ioctl		(struct ifnet *, u_long, caddr_t );
169249925Sglebiusint	iso88025_output		(struct ifnet *, struct mbuf *,
170249925Sglebius				 const struct sockaddr *, struct route *);
171112299Smdoddvoid	iso88025_input		(struct ifnet *, struct mbuf *);
172264299Sglebius#endif	/* _KERNEL */
17344165Sjulian
174264299Sglebius#endif	/* !_NET_ISO88025_H_ */
175