40 #include <linux/module.h>
44 #include <linux/bitops.h>
45 #include <linux/string.h>
46 #include <linux/tty.h>
47 #include <linux/errno.h>
48 #include <linux/netdevice.h>
50 #include <linux/rtnetlink.h>
51 #include <linux/if_arp.h>
52 #include <linux/if_ether.h>
53 #include <linux/sched.h>
56 #include <linux/kernel.h>
60 KERN_INFO "slcan: serial line CAN interface driver\n";
67 #define SLCAN_MAGIC 0x53CA
69 static int maxdev = 10;
76 #define SLC_MTU (sizeof("T1111222281122334455667788EA5F\r")+1)
140 static void slc_bump(
struct slcan *
sl)
148 if ((cmd !=
't') && (cmd !=
'T') && (cmd !=
'r') && (cmd !=
'R'))
156 if (!((sl->
rbuff[dlc_pos] >=
'0') && (sl->
rbuff[dlc_pos] <
'9')))
161 sl->
rbuff[dlc_pos] = 0;
171 if ((cmd | 0x20) ==
'r')
174 *(
u64 *) (&cf.data) = 0;
176 for (i = 0, dlc_pos++; i < cf.
can_dlc; i++) {
180 cf.data[
i] = (tmp << 4);
187 skb = dev_alloc_skb(
sizeof(
struct can_frame));
199 sl->
dev->stats.rx_packets++;
204 static void slcan_unesc(
struct slcan *sl,
unsigned char s)
207 if ((s ==
'\r') || (s ==
'\a')) {
219 sl->
dev->stats.rx_over_errors++;
250 for (i = 0; i < cf->
can_dlc; i++)
274 static void slcan_write_wakeup(
struct tty_struct *tty)
283 if (sl->
xleft <= 0) {
286 sl->
dev->stats.tx_packets++;
288 netif_wake_queue(sl->
dev);
300 struct slcan *sl = netdev_priv(dev);
305 spin_lock(&sl->
lock);
306 if (!netif_running(dev)) {
307 spin_unlock(&sl->
lock);
312 spin_unlock(&sl->
lock);
316 netif_stop_queue(sl->
dev);
318 spin_unlock(&sl->
lock);
333 struct slcan *sl = netdev_priv(dev);
335 spin_lock_bh(&sl->
lock);
340 netif_stop_queue(dev);
343 spin_unlock_bh(&sl->
lock);
351 struct slcan *sl = netdev_priv(dev);
357 netif_start_queue(dev);
362 static void slc_free_netdev(
struct net_device *dev)
366 slcan_devs[
i] =
NULL;
370 .ndo_open = slc_open,
371 .ndo_stop = slc_close,
372 .ndo_start_xmit = slc_xmit,
405 static void slcan_receive_buf(
struct tty_struct *tty,
406 const unsigned char *
cp,
char *
fp,
int count)
417 sl->
dev->stats.rx_errors++;
421 slcan_unesc(sl, *cp++);
430 static void slc_sync(
void)
436 for (i = 0; i < maxdev; i++) {
441 sl = netdev_priv(dev);
457 for (i = 0; i < maxdev; i++) {
474 sl = netdev_priv(dev);
570 static void slcan_close(
struct tty_struct *tty)
586 static int slcan_hangup(
struct tty_struct *tty)
594 unsigned int cmd,
unsigned long arg)
623 .close = slcan_close,
624 .hangup = slcan_hangup,
625 .ioctl = slcan_ioctl,
626 .receive_buf = slcan_receive_buf,
627 .write_wakeup = slcan_write_wakeup,
630 static int __init slcan_init(
void)
653 static void __exit slcan_exit(
void)
661 if (slcan_devs ==
NULL)
671 for (i = 0; i < maxdev; i++) {
675 sl = netdev_priv(dev);
676 spin_lock_bh(&sl->
lock);
681 spin_unlock_bh(&sl->
lock);
688 for (i = 0; i < maxdev; i++) {
692 slcan_devs[
i] =
NULL;
694 sl = netdev_priv(dev);