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  */
  18 
  19 #include <linux/config.h>
  20 #ifdef CONFIG_NETROM
  21 #include <linux/kernel.h>
  22 #include <linux/sched.h>
  23 #include <linux/interrupt.h>
  24 #include <linux/fs.h>
  25 #include <linux/types.h>
  26 #include <linux/string.h>
  27 #include <linux/socket.h>
  28 #include <linux/errno.h>
  29 #include <linux/fcntl.h>
  30 #include <linux/in.h>
  31 #include <linux/if_ether.h>     /* For the statistics structure. */
  32 #include <linux/if_arp.h>
  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/skbuff.h>
  42 
  43 #include <net/ip.h>
  44 #include <net/arp.h>
  45 
  46 #include <net/ax25.h>
  47 #include <net/netrom.h>
  48 
  49 /*
  50  *      Only allow IP over NET/ROM frames through if the netrom device is up.
  51  */
  52 
  53 int nr_rx_ip(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  54 {
  55         struct enet_statistics *stats = (struct enet_statistics *)dev->priv;
  56 
  57         if (!dev->start) 
  58         {
  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, ARPHRD_NETROM)) {
 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         memcpy(dev->dev_addr, addr, dev->addr_len);
 144 
 145         return 0;
 146 }
 147 
 148 static int nr_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 149 {
 150         dev->tbusy = 0;
 151         dev->start = 1;
 152 
 153         return 0;
 154 }
 155 
 156 static int nr_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 157 {
 158         dev->tbusy = 1;
 159         dev->start = 0;
 160 
 161         return 0;
 162 }
 163 
 164 static int nr_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 165 {
 166         struct enet_statistics *stats = (struct enet_statistics *)dev->priv;
 167 
 168         if (skb == NULL || dev == NULL)
 169                 return 0;
 170 
 171         if (!dev->start) {
 172                 printk("netrom: xmit call when iface is down\n");
 173                 return 1;
 174         }
 175 
 176         cli();
 177 
 178         if (dev->tbusy != 0) {
 179                 sti();
 180                 stats->tx_errors++;
 181                 return 1;
 182         }
 183 
 184         dev->tbusy = 1;
 185 
 186         sti();
 187 
 188         dev_kfree_skb(skb, FREE_WRITE);
 189 
 190         stats->tx_errors++;
 191 
 192         dev->tbusy = 0;
 193 
 194         mark_bh(NET_BH);
 195 
 196         return 0;
 197 }
 198 
 199 static struct enet_statistics *nr_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 200 {
 201         return (struct enet_statistics *)dev->priv;
 202 }
 203 
 204 int nr_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 205 {
 206         int i;
 207 
 208         dev->mtu                = 236;          /* MTU                  */
 209         dev->tbusy              = 0;
 210         dev->hard_start_xmit    = nr_xmit;
 211         dev->open               = nr_open;
 212         dev->stop               = nr_close;
 213 
 214         dev->hard_header        = nr_header;
 215         dev->hard_header_len    = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + NR_NETWORK_LEN + NR_TRANSPORT_LEN;
 216         dev->addr_len           = AX25_ADDR_LEN;
 217         dev->type               = ARPHRD_NETROM;
 218         dev->rebuild_header     = nr_rebuild_header;
 219         dev->set_mac_address    = nr_set_mac_address;
 220 
 221         /* New-style flags. */
 222         dev->flags              = 0;
 223         dev->family             = AF_INET;
 224 
 225         dev->pa_addr            = 0;
 226         dev->pa_brdaddr         = 0;
 227         dev->pa_mask            = 0;
 228         dev->pa_alen            = sizeof(unsigned long);
 229 
 230         dev->priv = kmalloc(sizeof(struct enet_statistics), GFP_KERNEL);
 231         if (dev->priv == NULL)
 232                 return -ENOMEM;
 233 
 234         memset(dev->priv, 0, sizeof(struct enet_statistics));
 235 
 236         dev->get_stats = nr_get_stats;
 237 
 238         /* Fill in the generic fields of the device structure. */
 239         for (i = 0; i < DEV_NUMBUFFS; i++)
 240                 skb_queue_head_init(&dev->buffs[i]);
 241 
 242         return 0;
 243 };
 244 
 245 #endif

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