root/net/netrom/nr_dev.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. nr_rx_ip
  2. nr_header
  3. nr_rebuild_header
  4. nr_set_mac_address
  5. nr_open
  6. nr_close
  7. nr_xmit
  8. nr_get_stats
  9. nr_init

   1 /*
   2  *      NET/ROM release 003
   3  *
   4  *      This is ALPHA test software. This code may break your machine, randomly fail to work with new 
   5  *      releases, misbehave and/or generally screw up. It might even work. 
   6  *
   7  *      This code REQUIRES 1.3.0 or higher/ NET3.029
   8  *
   9  *      This module:
  10  *              This module is free software; you can redistribute it and/or
  11  *              modify it under the terms of the GNU General Public License
  12  *              as published by the Free Software Foundation; either version
  13  *              2 of the License, or (at your option) any later version.
  14  *
  15  *      History
  16  *      NET/ROM 001     Jonathan(G4KLX) Cloned from loopback.c
  17  *      NET/ROM 002     Steve Whitehouse(GW7RRM) fixed the set_mac_address
  18  */
  19 
  20 #include <linux/config.h>
  21 #ifdef CONFIG_NETROM
  22 #include <linux/kernel.h>
  23 #include <linux/sched.h>
  24 #include <linux/interrupt.h>
  25 #include <linux/fs.h>
  26 #include <linux/types.h>
  27 #include <linux/string.h>
  28 #include <linux/socket.h>
  29 #include <linux/errno.h>
  30 #include <linux/fcntl.h>
  31 #include <linux/in.h>
  32 #include <linux/if_ether.h>     /* For the statistics structure. */
  33 
  34 #include <asm/system.h>
  35 #include <asm/segment.h>
  36 #include <asm/io.h>
  37 
  38 #include <linux/inet.h>
  39 #include <linux/netdevice.h>
  40 #include <linux/etherdevice.h>
  41 #include <linux/if_arp.h>
  42 #include <linux/skbuff.h>
  43 
  44 #include <net/ip.h>
  45 #include <net/arp.h>
  46 
  47 #include <net/ax25.h>
  48 #include <net/netrom.h>
  49 
  50 /*
  51  *      Only allow IP over NET/ROM frames through if the netrom device is up.
  52  */
  53 
  54 int nr_rx_ip(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56         struct enet_statistics *stats = (struct enet_statistics *)dev->priv;
  57 
  58         if (!dev->start) {
  59                 stats->rx_errors++;
  60                 return 0;
  61         }
  62 
  63         stats->rx_packets++;
  64         skb->protocol = htons(ETH_P_IP);
  65 
  66         /* Spoof incoming device */
  67         skb->dev = dev;
  68 
  69         skb->h.raw = skb->data;
  70         ip_rcv(skb, skb->dev, NULL);
  71 
  72         return 1;
  73 }
  74 
  75 static int nr_header(struct sk_buff *skb, struct device *dev, unsigned short type,
     /* [previous][next][first][last][top][bottom][index][help] */
  76         void *daddr, void *saddr, unsigned len)
  77 {
  78         unsigned char *buff = skb_push(skb, NR_NETWORK_LEN + NR_TRANSPORT_LEN);
  79 
  80         memcpy(buff, (saddr != NULL) ? saddr : dev->dev_addr, dev->addr_len);
  81         buff[6] &= ~LAPB_C;
  82         buff[6] &= ~LAPB_E;
  83         buff[6] |= SSSID_SPARE;
  84         buff    += AX25_ADDR_LEN;
  85 
  86         if (daddr != NULL)
  87                 memcpy(buff, daddr, dev->addr_len);
  88         buff[6] &= ~LAPB_C;
  89         buff[6] |= LAPB_E;
  90         buff[6] |= SSSID_SPARE;
  91         buff    += AX25_ADDR_LEN;
  92 
  93         *buff++ = nr_default.ttl;
  94 
  95         *buff++ = NR_PROTO_IP;
  96         *buff++ = NR_PROTO_IP;
  97         *buff++ = 0;
  98         *buff++ = 0;
  99         *buff++ = NR_PROTOEXT;
 100 
 101         if (daddr != NULL)
 102                 return 37;
 103         
 104         return -37;     
 105 }
 106 
 107 static int nr_rebuild_header(void *buff, struct device *dev,
     /* [previous][next][first][last][top][bottom][index][help] */
 108         unsigned long raddr, struct sk_buff *skb)
 109 {
 110         struct enet_statistics *stats = (struct enet_statistics *)dev->priv;
 111         unsigned char *bp = (unsigned char *)buff;
 112 
 113         skb_device_unlock(skb);
 114 
 115         if (!arp_query(bp + 7, raddr, dev)) {
 116                 skb->free = 1;
 117                 kfree_skb(skb, FREE_WRITE);
 118                 return 1;
 119         }
 120 
 121         bp[6] &= ~LAPB_C;
 122         bp[6] &= ~LAPB_E;
 123         bp[6] |= SSSID_SPARE;
 124         bp    += AX25_ADDR_LEN;
 125         
 126         bp[6] &= ~LAPB_C;
 127         bp[6] |= LAPB_E;
 128         bp[6] |= SSSID_SPARE;
 129 
 130         if (!nr_route_frame(skb, NULL)) {
 131                 skb->free = 1;
 132                 kfree_skb(skb, FREE_WRITE);
 133                 stats->tx_errors++;
 134         }
 135 
 136         stats->tx_packets++;
 137 
 138         return 1;
 139 }
 140 
 141 static int nr_set_mac_address(struct device *dev, void *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 142 {
 143         struct sockaddr *sa=addr;
 144         memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
 145 
 146         return 0;
 147 }
 148 
 149 static int nr_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 150 {
 151         dev->tbusy = 0;
 152         dev->start = 1;
 153 
 154         return 0;
 155 }
 156 
 157 static int nr_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 158 {
 159         dev->tbusy = 1;
 160         dev->start = 0;
 161 
 162         return 0;
 163 }
 164 
 165 static int nr_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 166 {
 167         struct enet_statistics *stats = (struct enet_statistics *)dev->priv;
 168 
 169         if (skb == NULL || dev == NULL)
 170                 return 0;
 171 
 172         if (!dev->start) {
 173                 printk("netrom: xmit call when iface is down\n");
 174                 return 1;
 175         }
 176 
 177         cli();
 178 
 179         if (dev->tbusy != 0) {
 180                 sti();
 181                 stats->tx_errors++;
 182                 return 1;
 183         }
 184 
 185         dev->tbusy = 1;
 186 
 187         sti();
 188 
 189         dev_kfree_skb(skb, FREE_WRITE);
 190 
 191         stats->tx_errors++;
 192 
 193         dev->tbusy = 0;
 194 
 195         mark_bh(NET_BH);
 196 
 197         return 0;
 198 }
 199 
 200 static struct enet_statistics *nr_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 201 {
 202         return (struct enet_statistics *)dev->priv;
 203 }
 204 
 205 int nr_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 206 {
 207         int i;
 208 
 209         dev->mtu                = 236;          /* MTU                  */
 210         dev->tbusy              = 0;
 211         dev->hard_start_xmit    = nr_xmit;
 212         dev->open               = nr_open;
 213         dev->stop               = nr_close;
 214 
 215         dev->hard_header        = nr_header;
 216         dev->hard_header_len    = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + NR_NETWORK_LEN + NR_TRANSPORT_LEN;
 217         dev->addr_len           = AX25_ADDR_LEN;
 218         dev->type               = ARPHRD_NETROM;
 219         dev->rebuild_header     = nr_rebuild_header;
 220         dev->set_mac_address    = nr_set_mac_address;
 221 
 222         /* New-style flags. */
 223         dev->flags              = 0;
 224         dev->family             = AF_INET;
 225 
 226         dev->pa_addr            = 0;
 227         dev->pa_brdaddr         = 0;
 228         dev->pa_mask            = 0;
 229         dev->pa_alen            = sizeof(unsigned long);
 230 
 231         dev->priv = kmalloc(sizeof(struct enet_statistics), GFP_KERNEL);
 232         if (dev->priv == NULL)
 233                 return -ENOMEM;
 234 
 235         memset(dev->priv, 0, sizeof(struct enet_statistics));
 236 
 237         dev->get_stats = nr_get_stats;
 238 
 239         /* Fill in the generic fields of the device structure. */
 240         for (i = 0; i < DEV_NUMBUFFS; i++)
 241                 skb_queue_head_init(&dev->buffs[i]);
 242 
 243         return 0;
 244 };
 245 
 246 #endif

/* [previous][next][first][last][top][bottom][index][help] */