4 * This code REQUIRES 2.1.15 or higher/ NET3.038
7 * This module is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 * NET/ROM 001 Jonathan(G4KLX) Cloned from loopback.c
14 * NET/ROM 002 Steve Whitehouse(GW7RRM) fixed the set_mac_address
15 * NET/ROM 003 Jonathan(G4KLX) Put nr_rebuild_header into line with
17 * NET/ROM 004 Jonathan(G4KLX) Callsign registration with AX.25.
18 * NET/ROM 006 Hans(PE1AYX) Fixed interface to IP layer.
21 #include <linux/config.h>
22 #if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
23 #define __NO_VERSION__
24 #include <linux/module.h>
25 #include <linux/proc_fs.h>
26 #include <linux/kernel.h>
27 #include <linux/sched.h>
28 #include <linux/interrupt.h>
30 #include <linux/types.h>
31 #include <linux/sysctl.h>
32 #include <linux/string.h>
33 #include <linux/socket.h>
34 #include <linux/errno.h>
35 #include <linux/fcntl.h>
37 #include <linux/if_ether.h> /* For the statistics structure. */
39 #include <asm/system.h>
40 #include <asm/uaccess.h>
43 #include <linux/inet.h>
44 #include <linux/netdevice.h>
45 #include <linux/etherdevice.h>
46 #include <linux/if_arp.h>
47 #include <linux/skbuff.h>
53 #include <net/netrom.h>
58 * Only allow IP over NET/ROM frames through if the netrom device is up.
61 int nr_rx_ip(struct sk_buff
*skb
, struct net_device
*dev
)
63 struct net_device_stats
*stats
= (struct net_device_stats
*)dev
->priv
;
65 if (!netif_running(dev
)) {
71 stats
->rx_bytes
+= skb
->len
;
73 skb
->protocol
= htons(ETH_P_IP
);
75 /* Spoof incoming device */
77 skb
->h
.raw
= skb
->data
;
78 skb
->nh
.raw
= skb
->data
;
79 skb
->pkt_type
= PACKET_HOST
;
81 ip_rcv(skb
, skb
->dev
, NULL
);
87 static int nr_rebuild_header(struct sk_buff
*skb
)
89 struct net_device
*dev
= skb
->dev
;
90 struct net_device_stats
*stats
= (struct net_device_stats
*)dev
->priv
;
92 unsigned char *bp
= skb
->data
;
94 if (arp_find(bp
+ 7, skb
)) {
100 bp
[6] |= AX25_SSSID_SPARE
;
105 bp
[6] |= AX25_SSSID_SPARE
;
107 if ((skbn
= skb_clone(skb
, GFP_ATOMIC
)) == NULL
) {
113 skb_set_owner_w(skbn
, skb
->sk
);
117 if (!nr_route_frame(skbn
, NULL
)) {
123 stats
->tx_bytes
+= skbn
->len
;
130 static int nr_rebuild_header(struct sk_buff
*skb
)
137 static int nr_header(struct sk_buff
*skb
, struct net_device
*dev
, unsigned short type
,
138 void *daddr
, void *saddr
, unsigned len
)
140 unsigned char *buff
= skb_push(skb
, NR_NETWORK_LEN
+ NR_TRANSPORT_LEN
);
142 memcpy(buff
, (saddr
!= NULL
) ? saddr
: dev
->dev_addr
, dev
->addr_len
);
143 buff
[6] &= ~AX25_CBIT
;
144 buff
[6] &= ~AX25_EBIT
;
145 buff
[6] |= AX25_SSSID_SPARE
;
146 buff
+= AX25_ADDR_LEN
;
149 memcpy(buff
, daddr
, dev
->addr_len
);
150 buff
[6] &= ~AX25_CBIT
;
151 buff
[6] |= AX25_EBIT
;
152 buff
[6] |= AX25_SSSID_SPARE
;
153 buff
+= AX25_ADDR_LEN
;
155 *buff
++ = sysctl_netrom_network_ttl_initialiser
;
157 *buff
++ = NR_PROTO_IP
;
158 *buff
++ = NR_PROTO_IP
;
161 *buff
++ = NR_PROTOEXT
;
169 static int nr_set_mac_address(struct net_device
*dev
, void *addr
)
171 struct sockaddr
*sa
= addr
;
173 ax25_listen_release((ax25_address
*)dev
->dev_addr
, NULL
);
175 memcpy(dev
->dev_addr
, sa
->sa_data
, dev
->addr_len
);
177 ax25_listen_register((ax25_address
*)dev
->dev_addr
, NULL
);
182 static int nr_open(struct net_device
*dev
)
185 netif_start_queue(dev
);
186 ax25_listen_register((ax25_address
*)dev
->dev_addr
, NULL
);
190 static int nr_close(struct net_device
*dev
)
192 netif_stop_queue(dev
);
193 ax25_listen_release((ax25_address
*)dev
->dev_addr
, NULL
);
198 static int nr_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
200 struct net_device_stats
*stats
= (struct net_device_stats
*)dev
->priv
;
206 static struct net_device_stats
*nr_get_stats(struct net_device
*dev
)
208 return (struct net_device_stats
*)dev
->priv
;
211 int nr_init(struct net_device
*dev
)
213 dev
->mtu
= NR_MAX_PACKET_SIZE
;
214 dev
->hard_start_xmit
= nr_xmit
;
216 dev
->stop
= nr_close
;
218 dev
->hard_header
= nr_header
;
219 dev
->hard_header_len
= AX25_BPQ_HEADER_LEN
+ AX25_MAX_HEADER_LEN
+ NR_NETWORK_LEN
+ NR_TRANSPORT_LEN
;
220 dev
->addr_len
= AX25_ADDR_LEN
;
221 dev
->type
= ARPHRD_NETROM
;
222 dev
->rebuild_header
= nr_rebuild_header
;
223 dev
->set_mac_address
= nr_set_mac_address
;
225 /* New-style flags. */
228 if ((dev
->priv
= kmalloc(sizeof(struct net_device_stats
), GFP_KERNEL
)) == NULL
)
231 memset(dev
->priv
, 0, sizeof(struct net_device_stats
));
233 dev
->get_stats
= nr_get_stats
;
235 dev_init_buffers(dev
);