23 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/errno.h>
26 #include <linux/types.h>
27 #include <linux/socket.h>
29 #include <linux/slab.h>
30 #include <linux/kernel.h>
31 #include <linux/string.h>
32 #include <linux/net.h>
34 #include <linux/netdevice.h>
35 #include <linux/if_arp.h>
38 #include <asm/uaccess.h>
42 #include <linux/stat.h>
43 #include <linux/netfilter.h>
44 #include <linux/module.h>
50 static const u8 bcast_addr[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
54 #define MAXLAPBDEV 100
73 list_for_each_entry_rcu(lapbeth, &lapbeth_devices,
node) {
74 if (lapbeth->
ethdev == dev)
101 if (!pskb_may_pull(skb, 2))
105 lapbeth = lapbeth_get_x25_dev(dev);
108 if (!netif_running(lapbeth->
axdev))
111 len = skb->
data[0] + skb->
data[1] * 256;
112 dev->
stats.rx_packets++;
113 dev->
stats.rx_bytes += len;
145 skb->
protocol = x25_type_trans(skb, dev);
161 if (!netif_running(dev))
164 switch (skb->
data[0]) {
169 pr_err(
"lapb_connect_request error: %d\n", err);
173 pr_err(
"lapb_disconnect_request err: %d\n", err);
182 pr_err(
"lapb_data_request error - %d\n", err);
194 struct lapbethdev *lapbeth = netdev_priv(ndev);
206 ndev->
stats.tx_packets++;
219 struct sk_buff *skb = dev_alloc_skb(1);
222 pr_err(
"out of memory\n");
229 skb->
protocol = x25_type_trans(skb, dev);
233 static void lapbeth_disconnected(
struct net_device *dev,
int reason)
236 struct sk_buff *skb = dev_alloc_skb(1);
239 pr_err(
"out of memory\n");
246 skb->
protocol = x25_type_trans(skb, dev);
253 static int lapbeth_set_mac_address(
struct net_device *dev,
void *
addr)
262 .connect_confirmation = lapbeth_connected,
263 .connect_indication = lapbeth_connected,
264 .disconnect_confirmation = lapbeth_disconnected,
265 .disconnect_indication = lapbeth_disconnected,
266 .data_indication = lapbeth_data_indication,
267 .data_transmit = lapbeth_data_transmit,
273 static int lapbeth_open(
struct net_device *dev)
278 pr_err(
"lapb_register error: %d\n", err);
282 netif_start_queue(dev);
286 static int lapbeth_close(
struct net_device *dev)
290 netif_stop_queue(dev);
293 pr_err(
"lapb_unregister error: %d\n", err);
301 .ndo_open = lapbeth_open,
302 .ndo_stop = lapbeth_close,
303 .ndo_start_xmit = lapbeth_xmit,
304 .ndo_set_mac_address = lapbeth_set_mac_address,
307 static void lapbeth_setup(
struct net_device *dev)
320 static int lapbeth_new_device(
struct net_device *dev)
333 lapbeth = netdev_priv(ndev);
343 list_add_rcu(&lapbeth->
node, &lapbeth_devices);
357 static void lapbeth_free_device(
struct lapbethdev *lapbeth)
360 list_del_rcu(&lapbeth->
node);
361 unregister_netdevice(lapbeth->
axdev);
370 unsigned long event,
void *ptr)
378 if (!dev_is_ethdev(dev))
384 if (lapbeth_get_x25_dev(dev) ==
NULL)
385 lapbeth_new_device(dev);
389 lapbeth = lapbeth_get_x25_dev(dev);
395 lapbeth = lapbeth_get_x25_dev(dev);
397 lapbeth_free_device(lapbeth);
412 .notifier_call = lapbeth_device_event,
416 KERN_INFO "LAPB Ethernet driver version 0.02\n";
418 static int __init lapbeth_init_driver(
void)
430 static void __exit lapbeth_cleanup_driver(
void)
443 unregister_netdevice(lapbeth->
axdev);