Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus
[linux-2.6-block.git] / net / 802 / fddi.c
CommitLineData
1da177e4
LT
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * FDDI-type device handling.
7 *
8 * Version: @(#)fddi.c 1.0.0 08/12/96
9 *
10 * Authors: Lawrence V. Stefani, <stefani@lkg.dec.com>
11 *
12 * fddi.c is based on previous eth.c and tr.c work by
02c30a84 13 * Ross Biro
1da177e4
LT
14 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
15 * Mark Evans, <evansmp@uhura.aston.ac.uk>
16 * Florian La Roche, <rzsfl@rz.uni-sb.de>
17 * Alan Cox, <gw4pts@gw4pts.ampr.org>
9afa0949 18 *
1da177e4
LT
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version
22 * 2 of the License, or (at your option) any later version.
23 *
24 * Changes
25 * Alan Cox : New arp/rebuild header
26 * Maciej W. Rozycki : IPv6 support
27 */
9afa0949 28
1da177e4 29#include <linux/module.h>
1da177e4
LT
30#include <linux/types.h>
31#include <linux/kernel.h>
1da177e4
LT
32#include <linux/string.h>
33#include <linux/mm.h>
34#include <linux/socket.h>
35#include <linux/in.h>
36#include <linux/inet.h>
37#include <linux/netdevice.h>
38#include <linux/fddidevice.h>
39#include <linux/if_ether.h>
40#include <linux/skbuff.h>
41#include <linux/errno.h>
42#include <net/arp.h>
43#include <net/sock.h>
44
45/*
46 * Create the FDDI MAC header for an arbitrary protocol layer
47 *
48 * saddr=NULL means use device source address
49 * daddr=NULL means leave destination address (eg unresolved arp)
50 */
51
52static int fddi_header(struct sk_buff *skb, struct net_device *dev,
53 unsigned short type,
95c96174 54 const void *daddr, const void *saddr, unsigned int len)
1da177e4
LT
55{
56 int hl = FDDI_K_SNAP_HLEN;
57 struct fddihdr *fddi;
9afa0949 58
1da177e4
LT
59 if(type != ETH_P_IP && type != ETH_P_IPV6 && type != ETH_P_ARP)
60 hl=FDDI_K_8022_HLEN-3;
61 fddi = (struct fddihdr *)skb_push(skb, hl);
62 fddi->fc = FDDI_FC_K_ASYNC_LLC_DEF;
63 if(type == ETH_P_IP || type == ETH_P_IPV6 || type == ETH_P_ARP)
64 {
65 fddi->hdr.llc_snap.dsap = FDDI_EXTENDED_SAP;
66 fddi->hdr.llc_snap.ssap = FDDI_EXTENDED_SAP;
67 fddi->hdr.llc_snap.ctrl = FDDI_UI_CMD;
68 fddi->hdr.llc_snap.oui[0] = 0x00;
69 fddi->hdr.llc_snap.oui[1] = 0x00;
70 fddi->hdr.llc_snap.oui[2] = 0x00;
71 fddi->hdr.llc_snap.ethertype = htons(type);
72 }
73
74 /* Set the source and destination hardware addresses */
9afa0949 75
1da177e4
LT
76 if (saddr != NULL)
77 memcpy(fddi->saddr, saddr, dev->addr_len);
78 else
79 memcpy(fddi->saddr, dev->dev_addr, dev->addr_len);
80
81 if (daddr != NULL)
82 {
83 memcpy(fddi->daddr, daddr, dev->addr_len);
a02cec21 84 return hl;
1da177e4
LT
85 }
86
a02cec21 87 return -hl;
1da177e4
LT
88}
89
1da177e4
LT
90/*
91 * Determine the packet's protocol ID and fill in skb fields.
92 * This routine is called before an incoming packet is passed
93 * up. It's used to fill in specific skb fields and to set
94 * the proper pointer to the start of packet data (skb->data).
95 */
9afa0949 96
ab611487 97__be16 fddi_type_trans(struct sk_buff *skb, struct net_device *dev)
1da177e4
LT
98{
99 struct fddihdr *fddi = (struct fddihdr *)skb->data;
ab611487 100 __be16 type;
9afa0949 101
1da177e4
LT
102 /*
103 * Set mac.raw field to point to FC byte, set data field to point
104 * to start of packet data. Assume 802.2 SNAP frames for now.
105 */
106
0a4f23fb 107 skb->dev = dev;
459a98ed 108 skb_reset_mac_header(skb); /* point to frame control (FC) */
9afa0949 109
1da177e4
LT
110 if(fddi->hdr.llc_8022_1.dsap==0xe0)
111 {
112 skb_pull(skb, FDDI_K_8022_HLEN-3);
2953fd24 113 type = htons(ETH_P_802_2);
1da177e4
LT
114 }
115 else
116 {
117 skb_pull(skb, FDDI_K_SNAP_HLEN); /* adjust for 21 byte header */
118 type=fddi->hdr.llc_snap.ethertype;
119 }
9afa0949 120
1da177e4 121 /* Set packet type based on destination address and flag settings */
9afa0949 122
1da177e4
LT
123 if (*fddi->daddr & 0x01)
124 {
125 if (memcmp(fddi->daddr, dev->broadcast, FDDI_K_ALEN) == 0)
126 skb->pkt_type = PACKET_BROADCAST;
127 else
128 skb->pkt_type = PACKET_MULTICAST;
129 }
9afa0949 130
1da177e4
LT
131 else if (dev->flags & IFF_PROMISC)
132 {
133 if (memcmp(fddi->daddr, dev->dev_addr, FDDI_K_ALEN))
134 skb->pkt_type = PACKET_OTHERHOST;
135 }
136
137 /* Assume 802.2 SNAP frames, for now */
138
a02cec21 139 return type;
1da177e4
LT
140}
141
142EXPORT_SYMBOL(fddi_type_trans);
143
145186a3 144int fddi_change_mtu(struct net_device *dev, int new_mtu)
1da177e4
LT
145{
146 if ((new_mtu < FDDI_K_SNAP_HLEN) || (new_mtu > FDDI_K_SNAP_DLEN))
a02cec21 147 return -EINVAL;
1da177e4 148 dev->mtu = new_mtu;
a02cec21 149 return 0;
1da177e4 150}
145186a3 151EXPORT_SYMBOL(fddi_change_mtu);
1da177e4 152
3b04ddde
SH
153static const struct header_ops fddi_header_ops = {
154 .create = fddi_header,
3b04ddde
SH
155};
156
145186a3 157
1da177e4
LT
158static void fddi_setup(struct net_device *dev)
159{
3b04ddde 160 dev->header_ops = &fddi_header_ops;
1da177e4
LT
161 dev->type = ARPHRD_FDDI;
162 dev->hard_header_len = FDDI_K_SNAP_HLEN+3; /* Assume 802.2 SNAP hdr len + 3 pad bytes */
163 dev->mtu = FDDI_K_SNAP_DLEN; /* Assume max payload of 802.2 SNAP frame */
164 dev->addr_len = FDDI_K_ALEN;
165 dev->tx_queue_len = 100; /* Long queues on FDDI */
166 dev->flags = IFF_BROADCAST | IFF_MULTICAST;
9afa0949 167
1da177e4
LT
168 memset(dev->broadcast, 0xFF, FDDI_K_ALEN);
169}
170
171/**
172 * alloc_fddidev - Register FDDI device
173 * @sizeof_priv: Size of additional driver-private structure to be allocated
174 * for this FDDI device
175 *
176 * Fill in the fields of the device structure with FDDI-generic values.
177 *
178 * Constructs a new net device, complete with a private data area of
179 * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for
180 * this private data area.
181 */
182struct net_device *alloc_fddidev(int sizeof_priv)
183{
c835a677
TG
184 return alloc_netdev(sizeof_priv, "fddi%d", NET_NAME_UNKNOWN,
185 fddi_setup);
1da177e4
LT
186}
187EXPORT_SYMBOL(alloc_fddidev);
d9677a45
AB
188
189MODULE_LICENSE("GPL");