iso88025.h revision 264299
1179237Sjb/*-
2179237Sjb * Copyright (c) 1998, Larry Lile
3179237Sjb * All rights reserved.
4179237Sjb *
5179237Sjb * For latest sources and information on this driver, please
6179237Sjb * go to http://anarchy.stdio.com.
7179237Sjb *
8179237Sjb * Questions, comments or suggestions should be directed to
9179237Sjb * Larry Lile <lile@stdio.com>.
10179237Sjb *
11179237Sjb * Redistribution and use in source and binary forms, with or without
12179237Sjb * modification, are permitted provided that the following conditions
13179237Sjb * are met:
14179237Sjb * 1. Redistributions of source code must retain the above copyright
15179237Sjb *    notice unmodified, this list of conditions, and the following
16179237Sjb *    disclaimer.
17179237Sjb * 2. Redistributions in binary form must reproduce the above copyright
18179237Sjb *    notice, this list of conditions and the following disclaimer in the
19179237Sjb *    documentation and/or other materials provided with the distribution.
20179237Sjb *
21179237Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22179237Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23179237Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24179237Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25179237Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26179237Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27179237Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28179237Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29179237Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30179237Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31179237Sjb * SUCH DAMAGE.
32179237Sjb *
33179237Sjb * $FreeBSD: stable/10/sys/net/iso88025.h 264299 2014-04-09 11:15:50Z glebius $
34179237Sjb *
35179237Sjb * Information gathered from tokenring@freebsd, /sys/net/ethernet.h and
36179237Sjb * the Mach token ring driver.
37179237Sjb */
38179237Sjb
39211610Srpaulo/*
40179237Sjb * Fundamental constants relating to iso 802.5
41179237Sjb */
42179237Sjb
43179237Sjb#ifndef _NET_ISO88025_H_
44179237Sjb#define	_NET_ISO88025_H_
45179237Sjb
46179237Sjb/*
47179237Sjb * General ISO 802.5 definitions
48179237Sjb */
49179237Sjb#define	ISO88025_ADDR_LEN	6
50179237Sjb#define	ISO88025_CF_LEN		2
51179237Sjb#define	ISO88025_HDR_LEN	(ISO88025_CF_LEN + (ISO88025_ADDR_LEN * 2))
52179237Sjb#define	RCF_LEN			2
53179237Sjb#define	RIF_MAX_RD		14
54179237Sjb#define	RIF_MAX_LEN		16
55179237Sjb
56179237Sjb#define	TR_AC			0x10
57179237Sjb#define	TR_LLC_FRAME		0x40
58179237Sjb
59179237Sjb#define	TR_4MBPS		4000000
60179237Sjb#define	TR_16MBPS		16000000
61179237Sjb#define	TR_100MBPS		100000000
62179237Sjb
63211610Srpaulo/*
64211610Srpaulo * Source routing
65211610Srpaulo */
66179237Sjb#define	TR_RII			0x80
67179237Sjb#define	TR_RCF_BCST_MASK	0xe000
68179237Sjb#define	TR_RCF_LEN_MASK		0x1f00
69179237Sjb#define	TR_RCF_DIR		0x0080
70179237Sjb#define	TR_RCF_LF_MASK		0x0070
71179237Sjb
72179237Sjb#define	TR_RCF_RIFLEN(x)	((ntohs(x) & TR_RCF_LEN_MASK) >> 8)
73179237Sjb
74211610Srpaulo/*
75179237Sjb * Minimum and maximum packet payload lengths.
76179237Sjb */
77179237Sjb#define	ISO88025_MIN_LEN	0
78179237Sjb#define	ISO88025_MAX_LEN_4	4464
79179237Sjb#define	ISO88025_MAX_LEN_16	17960
80179237Sjb#define	ISO88025_MAX_LEN	ISO88025_MAX_LEN_16
81179237Sjb
82211610Srpaulo/*
83211610Srpaulo * A macro to validate a length with
84211610Srpaulo */
85179237Sjb#define	ISO88025_IS_VALID_LEN(foo)	\
86179237Sjb	((foo) >= ISO88025_MIN_LEN && (foo) <= ISO88025_MAX_LEN)
87269342Smarkj
88179237Sjb/* Access Control field */
89179237Sjb#define	AC_PRI_MASK		0xe0	/* Priority bits 		*/
90179237Sjb#define	AC_TOKEN		0x10	/* Token bit: 0=Token, 1=Frame	*/
91179237Sjb#define	AC_MONITOR		0x08	/* Monitor			*/
92179237Sjb#define	AC_RESV_MASK		0x07	/* Reservation bits		*/
93179237Sjb
94179237Sjb/* Frame Control field */
95179237Sjb#define	FC_FT_MASK		0xc0	/* Frame Type			*/
96179237Sjb#define	FC_FT_MAC		0x00	/* MAC frame			*/
97179237Sjb#define	FC_FT_LLC		0x40	/* LLC frame			*/
98179237Sjb#define	FC_ATTN_MASK		0x0f	/* Attention bits		*/
99179237Sjb#define	FC_ATTN_EB		0x01	/* Express buffer		*/
100179237Sjb#define	FC_ATTN_BE		0x02	/* Beacon			*/
101211610Srpaulo#define	FC_ATTN_CT		0x03	/* Claim token			*/
102211610Srpaulo#define	FC_ATTN_RP		0x04	/* Ring purge			*/
103211610Srpaulo#define	FC_ATTN_AMP		0x05	/* Active monitor present	*/
104211610Srpaulo#define	FC_ATTN_SMP		0x06	/* Standby monitor present	*/
105211610Srpaulo
106211610Srpaulo/* Token Ring destination address */
107211610Srpaulo#define	DA_IG			0x80	/* Individual/group address.	*/
108211610Srpaulo					/* 0=Individual, 1=Group	*/
109211610Srpaulo#define	DA_UL			0x40	/* Universal/local address.	*/
110211610Srpaulo					/* 0=Universal, 1=Local		*/
111211610Srpaulo/* Token Ring source address */
112269342Smarkj#define	SA_RII			0x80	/* Routing information indicator */
113211610Srpaulo#define	SA_IG			0x40	/* Individual/group address	*/
114211610Srpaulo					/* 0=Group, 1=Individual	*/
115211610Srpaulo
116211610Srpaulo/*
117269342Smarkj * ISO 802.5 physical header
118211610Srpaulo */
119211610Srpaulostruct iso88025_header {
120211610Srpaulo	u_int8_t	ac;				    /* access control field */
121211610Srpaulo	u_int8_t	fc;				    /* frame control field */
122211610Srpaulo	u_int8_t	iso88025_dhost[ISO88025_ADDR_LEN];  /* destination address */
123211610Srpaulo	u_int8_t	iso88025_shost[ISO88025_ADDR_LEN];  /* source address */
124211610Srpaulo	u_int16_t	rcf;				    /* route control field */
125211610Srpaulo	u_int16_t	rd[RIF_MAX_RD];			    /* routing designators */
126179237Sjb} __packed;
127179237Sjb
128211610Srpaulostruct iso88025_rif {
129179237Sjb	u_int16_t	rcf;				    /* route control field */
130179237Sjb	u_int16_t	rd[RIF_MAX_RD];			    /* routing designators */
131179237Sjb} __packed;
132179237Sjb
133179237Sjbstruct iso88025_sockaddr_data {
134211610Srpaulo	u_char ether_dhost[ISO88025_ADDR_LEN];
135179237Sjb	u_char ether_shost[ISO88025_ADDR_LEN];
136179237Sjb	u_char ac;
137179237Sjb	u_char fc;
138179237Sjb};
139268578Srpaulo
140179237Sjbstruct iso88025_sockaddr_dl_data {
141179237Sjb	u_short	 trld_rcf;
142179237Sjb	u_short	*trld_route[RIF_MAX_LEN];
143179237Sjb};
144179237Sjb
145179237Sjb#define	ISO88025_MAX(a, b)	(((a)>(b))?(a):(b))
146179237Sjb#define	SDL_ISO88025(s)		((struct iso88025_sockaddr_dl_data *)	\
147179237Sjb				 ((s)->sdl_data + \
148179237Sjb				  ISO88025_MAX((s)->sdl_nlen + (s)->sdl_alen + \
149179237Sjb					       (s)->sdl_slen, 12)))
150179237Sjb
151179237Sjb/*
152179237Sjb * Structure of a 48-bit iso 802.5 address.
153179237Sjb *  ( We could also add the 16 bit addresses as a union)
154179237Sjb */
155179237Sjbstruct	iso88025_addr {
156179237Sjb	u_char octet[ISO88025_ADDR_LEN];
157179237Sjb};
158179237Sjb
159179237Sjb#define	ISO88025_MAX_MTU		18000
160179237Sjb#define	ISO88025_DEFAULT_MTU		1500
161179237Sjb
162179237Sjb#define	ISO88025_BPF_UNSUPPORTED	0
163179237Sjb#define	ISO88025_BPF_SUPPORTED		1
164179237Sjb
165179237Sjb#ifdef _KERNEL
166179237Sjbvoid	iso88025_ifattach	(struct ifnet *, const u_int8_t *, int);
167179237Sjbvoid	iso88025_ifdetach	(struct ifnet *, int);
168179237Sjbint	iso88025_ioctl		(struct ifnet *, u_long, caddr_t );
169int	iso88025_output		(struct ifnet *, struct mbuf *,
170				 const struct sockaddr *, struct route *);
171void	iso88025_input		(struct ifnet *, struct mbuf *);
172#endif	/* _KERNEL */
173
174#endif	/* !_NET_ISO88025_H_ */
175