OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [net/] [802/] [fddi.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
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
13
 *                      Ross Biro, <bir7@leland.Stanford.Edu>
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>
18
 *
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
#include <asm/segment.h>
25
#include <asm/system.h>
26
#include <linux/types.h>
27
#include <linux/kernel.h>
28
#include <linux/sched.h>
29
#include <linux/string.h>
30
#include <linux/mm.h>
31
#include <linux/socket.h>
32
#include <linux/in.h>
33
#include <linux/inet.h>
34
#include <linux/netdevice.h>
35
#include <linux/fddidevice.h>
36
#include <linux/skbuff.h>
37
#include <linux/errno.h>
38
#include <net/arp.h>
39
#include <net/sock.h>
40
 
41
/*
42
 * Create the FDDI MAC header for an arbitrary protocol layer
43
 *
44
 * saddr=NULL   means use device source address
45
 * daddr=NULL   means leave destination address (eg unresolved arp)
46
 */
47
 
48
int fddi_header(
49
        struct sk_buff  *skb,
50
        struct device   *dev,
51
        unsigned short  type,
52
        void                    *daddr,
53
        void                    *saddr,
54
        unsigned                len
55
        )
56
 
57
        {
58
        struct fddihdr *fddi = (struct fddihdr *)skb_push(skb, FDDI_K_SNAP_HLEN);
59
 
60
        /* Fill in frame header - assume 802.2 SNAP frames for now */
61
 
62
        fddi->fc                                         = FDDI_FC_K_ASYNC_LLC_DEF;
63
        fddi->hdr.llc_snap.dsap          = FDDI_EXTENDED_SAP;
64
        fddi->hdr.llc_snap.ssap          = FDDI_EXTENDED_SAP;
65
        fddi->hdr.llc_snap.ctrl          = FDDI_UI_CMD;
66
        fddi->hdr.llc_snap.oui[0]         = 0x00;
67
        fddi->hdr.llc_snap.oui[1]        = 0x00;
68
        fddi->hdr.llc_snap.oui[2]        = 0x00;
69
        fddi->hdr.llc_snap.ethertype = htons(type);
70
 
71
        /* Set the source and destination hardware addresses */
72
 
73
        if (saddr != NULL)
74
                memcpy(fddi->saddr, saddr, dev->addr_len);
75
        else
76
                memcpy(fddi->saddr, dev->dev_addr, dev->addr_len);
77
 
78
        if (daddr != NULL)
79
                {
80
                memcpy(fddi->daddr, daddr, dev->addr_len);
81
                return(FDDI_K_SNAP_HLEN);
82
                }
83
        return(-FDDI_K_SNAP_HLEN);
84
        }
85
 
86
 
87
/*
88
 * Rebuild the FDDI MAC header. This is called after an ARP
89
 * (or in future other address resolution) has completed on
90
 * this sk_buff.  We now let ARP fill in the other fields.
91
 */
92
 
93
int fddi_rebuild_header(
94
        void                    *buff,
95
        struct device   *dev,
96
        unsigned long   dest,
97
        struct sk_buff  *skb
98
        )
99
 
100
        {
101
        struct fddihdr *fddi = (struct fddihdr *)buff;
102
 
103
        /* Only ARP/IP is currently supported */
104
 
105
        if (fddi->hdr.llc_snap.ethertype != htons(ETH_P_IP))
106
                {
107
                printk("fddi_rebuild_header: Don't know how to resolve type %04X addresses?\n", (unsigned int)htons(fddi->hdr.llc_snap.ethertype));
108
                return(0);
109
                }
110
 
111
        /* Try to get ARP to resolve the header and fill destination address */
112
 
113
        if (arp_find(fddi->daddr, dest, dev, dev->pa_addr, skb))
114
                return(1);
115
        else
116
                return(0);
117
        }
118
 
119
 
120
/*
121
 * Determine the packet's protocol ID and fill in skb fields.
122
 * This routine is called before an incoming packet is passed
123
 * up.  It's used to fill in specific skb fields and to set
124
 * the proper pointer to the start of packet data (skb->data).
125
 */
126
 
127
unsigned short fddi_type_trans(
128
        struct sk_buff  *skb,
129
        struct device   *dev
130
        )
131
 
132
        {
133
        struct fddihdr *fddi = (struct fddihdr *)skb->data;
134
 
135
        /*
136
         * Set mac.raw field to point to FC byte, set data field to point
137
         * to start of packet data.  Assume 802.2 SNAP frames for now.
138
         */
139
 
140
        skb->mac.raw = skb->data;                       /* point to frame control (FC) */
141
        skb_pull(skb, FDDI_K_SNAP_HLEN);        /* adjust for 21 byte header */
142
 
143
        /* Set packet type based on destination address and flag settings */
144
 
145
        if (*fddi->daddr & 0x01)
146
                {
147
                if (memcmp(fddi->daddr, dev->broadcast, FDDI_K_ALEN) == 0)
148
                        skb->pkt_type = PACKET_BROADCAST;
149
                else
150
                        skb->pkt_type = PACKET_MULTICAST;
151
                }
152
 
153
        else if (dev->flags & IFF_PROMISC)
154
                {
155
                if (memcmp(fddi->daddr, dev->dev_addr, FDDI_K_ALEN))
156
                        skb->pkt_type = PACKET_OTHERHOST;
157
                }
158
 
159
        /* Assume 802.2 SNAP frames, for now */
160
 
161
        return(fddi->hdr.llc_snap.ethertype);
162
        }

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.