This source file includes following definitions.
- nr_rx_ip
- nr_header
- nr_rebuild_header
- nr_set_mac_address
- nr_open
- nr_close
- nr_xmit
- nr_get_stats
- nr_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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>
33 #include <linux/if_arp.h>
34
35 #include <asm/system.h>
36 #include <asm/segment.h>
37 #include <asm/io.h>
38
39 #include <linux/inet.h>
40 #include <linux/netdevice.h>
41 #include <linux/etherdevice.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
52
53
54 int nr_rx_ip(struct sk_buff *skb, struct device *dev)
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
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,
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,
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)
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)
150 {
151 dev->tbusy = 0;
152 dev->start = 1;
153
154 return 0;
155 }
156
157 static int nr_close(struct device *dev)
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)
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)
201 {
202 return (struct enet_statistics *)dev->priv;
203 }
204
205 int nr_init(struct device *dev)
206 {
207 int i;
208
209 dev->mtu = 236;
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
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
240 for (i = 0; i < DEV_NUMBUFFS; i++)
241 skb_queue_head_init(&dev->buffs[i]);
242
243 return 0;
244 };
245
246 #endif