5 * This module is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
10 * This module implements the AX.25 protocol for kernel-based
11 * devices like TTYs. It interfaces between a raw TTY, and the
12 * kernel's AX.25 protocol layers, just like slip.c.
13 * AX.25 needs to be separated from slip.c while slip.c is no
14 * longer a static kernel device since it is a module.
15 * This method clears the way to implement other kiss protocols
16 * like mkiss smack g8bpq ..... so far only mkiss is implemented.
18 * Hans Alblas <hans@esrac.ele.tue.nl>
21 * Jonathan (G4KLX) Fixed to match Linux networking changes - 2.1.15.
22 * Matthias (DG2FEF) Added support for FlexNet CRC (on special request)
23 * Fixed bug in ax25_close(): dev_lock_wait() was
24 * called twice, causing a deadlock.
25 * Jeroen (PE1RXQ) Removed old MKISS_MAGIC stuff and calls to
27 * Remove cli() and fix rtnl lock usage.
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <asm/system.h>
33 #include <linux/bitops.h>
34 #include <asm/uaccess.h>
35 #include <linux/string.h>
37 #include <linux/interrupt.h>
39 #include <linux/inet.h>
40 #include <linux/tty.h>
41 #include <linux/errno.h>
42 #include <linux/netdevice.h>
43 #include <linux/major.h>
44 #include <linux/init.h>
45 #include <linux/rtnetlink.h>
46 #include <linux/etherdevice.h>
47 #include <linux/skbuff.h>
48 #include <linux/if_arp.h>
49 #include <linux/jiffies.h>
57 #include <linux/tcp.h>
60 static char banner[] __initdata = KERN_INFO "mkiss: AX.25 Multikiss, Hans Albas PE1AYX\n";
62 typedef struct ax25_ctrl {
63 struct ax_disp ctrl; /* */
64 struct net_device dev; /* the device */
67 static ax25_ctrl_t **ax25_ctrls;
69 int ax25_maxdev = AX25_MAXDEV; /* Can be overridden with insmod! */
71 static struct tty_ldisc ax_ldisc;
73 static int ax25_init(struct net_device *);
74 static int kiss_esc(unsigned char *, unsigned char *, int);
75 static int kiss_esc_crc(unsigned char *, unsigned char *, unsigned short, int);
76 static void kiss_unesc(struct ax_disp *, unsigned char);
78 /*---------------------------------------------------------------------------*/
80 static const unsigned short Crc_flex_table[] = {
81 0x0f87, 0x1e0e, 0x2c95, 0x3d1c, 0x49a3, 0x582a, 0x6ab1, 0x7b38,
82 0x83cf, 0x9246, 0xa0dd, 0xb154, 0xc5eb, 0xd462, 0xe6f9, 0xf770,
83 0x1f06, 0x0e8f, 0x3c14, 0x2d9d, 0x5922, 0x48ab, 0x7a30, 0x6bb9,
84 0x934e, 0x82c7, 0xb05c, 0xa1d5, 0xd56a, 0xc4e3, 0xf678, 0xe7f1,
85 0x2e85, 0x3f0c, 0x0d97, 0x1c1e, 0x68a1, 0x7928, 0x4bb3, 0x5a3a,
86 0xa2cd, 0xb344, 0x81df, 0x9056, 0xe4e9, 0xf560, 0xc7fb, 0xd672,
87 0x3e04, 0x2f8d, 0x1d16, 0x0c9f, 0x7820, 0x69a9, 0x5b32, 0x4abb,
88 0xb24c, 0xa3c5, 0x915e, 0x80d7, 0xf468, 0xe5e1, 0xd77a, 0xc6f3,
89 0x4d83, 0x5c0a, 0x6e91, 0x7f18, 0x0ba7, 0x1a2e, 0x28b5, 0x393c,
90 0xc1cb, 0xd042, 0xe2d9, 0xf350, 0x87ef, 0x9666, 0xa4fd, 0xb574,
91 0x5d02, 0x4c8b, 0x7e10, 0x6f99, 0x1b26, 0x0aaf, 0x3834, 0x29bd,
92 0xd14a, 0xc0c3, 0xf258, 0xe3d1, 0x976e, 0x86e7, 0xb47c, 0xa5f5,
93 0x6c81, 0x7d08, 0x4f93, 0x5e1a, 0x2aa5, 0x3b2c, 0x09b7, 0x183e,
94 0xe0c9, 0xf140, 0xc3db, 0xd252, 0xa6ed, 0xb764, 0x85ff, 0x9476,
95 0x7c00, 0x6d89, 0x5f12, 0x4e9b, 0x3a24, 0x2bad, 0x1936, 0x08bf,
96 0xf048, 0xe1c1, 0xd35a, 0xc2d3, 0xb66c, 0xa7e5, 0x957e, 0x84f7,
97 0x8b8f, 0x9a06, 0xa89d, 0xb914, 0xcdab, 0xdc22, 0xeeb9, 0xff30,
98 0x07c7, 0x164e, 0x24d5, 0x355c, 0x41e3, 0x506a, 0x62f1, 0x7378,
99 0x9b0e, 0x8a87, 0xb81c, 0xa995, 0xdd2a, 0xcca3, 0xfe38, 0xefb1,
100 0x1746, 0x06cf, 0x3454, 0x25dd, 0x5162, 0x40eb, 0x7270, 0x63f9,
101 0xaa8d, 0xbb04, 0x899f, 0x9816, 0xeca9, 0xfd20, 0xcfbb, 0xde32,
102 0x26c5, 0x374c, 0x05d7, 0x145e, 0x60e1, 0x7168, 0x43f3, 0x527a,
103 0xba0c, 0xab85, 0x991e, 0x8897, 0xfc28, 0xeda1, 0xdf3a, 0xceb3,
104 0x3644, 0x27cd, 0x1556, 0x04df, 0x7060, 0x61e9, 0x5372, 0x42fb,
105 0xc98b, 0xd802, 0xea99, 0xfb10, 0x8faf, 0x9e26, 0xacbd, 0xbd34,
106 0x45c3, 0x544a, 0x66d1, 0x7758, 0x03e7, 0x126e, 0x20f5, 0x317c,
107 0xd90a, 0xc883, 0xfa18, 0xeb91, 0x9f2e, 0x8ea7, 0xbc3c, 0xadb5,
108 0x5542, 0x44cb, 0x7650, 0x67d9, 0x1366, 0x02ef, 0x3074, 0x21fd,
109 0xe889, 0xf900, 0xcb9b, 0xda12, 0xaead, 0xbf24, 0x8dbf, 0x9c36,
110 0x64c1, 0x7548, 0x47d3, 0x565a, 0x22e5, 0x336c, 0x01f7, 0x107e,
111 0xf808, 0xe981, 0xdb1a, 0xca93, 0xbe2c, 0xafa5, 0x9d3e, 0x8cb7,
112 0x7440, 0x65c9, 0x5752, 0x46db, 0x3264, 0x23ed, 0x1176, 0x00ff
115 /*---------------------------------------------------------------------------*/
117 static unsigned short calc_crc_flex(unsigned char *cp, int size)
119 unsigned short crc = 0xffff;
122 crc = (crc << 8) ^ Crc_flex_table[((crc >> 8) ^ *cp++) & 0xff];
127 /*---------------------------------------------------------------------------*/
129 static int check_crc_flex(unsigned char *cp, int size)
131 unsigned short crc = 0xffff;
137 crc = (crc << 8) ^ Crc_flex_table[((crc >> 8) ^ *cp++) & 0xff];
139 if ((crc & 0xffff) != 0x7070)
145 /*---------------------------------------------------------------------------*/
147 /* Find a free channel, and link in this `tty' line. */
148 static inline struct ax_disp *ax_alloc(void)
150 ax25_ctrl_t *axp=NULL;
153 for (i = 0; i < ax25_maxdev; i++) {
156 /* Not allocated ? */
161 if (!test_and_set_bit(AXF_INUSE, &axp->ctrl.flags))
165 /* Sorry, too many, all slots in use */
166 if (i >= ax25_maxdev)
169 /* If no channels are available, allocate one */
170 if (axp == NULL && (ax25_ctrls[i] = kmalloc(sizeof(ax25_ctrl_t), GFP_KERNEL)) != NULL) {
173 memset(axp, 0, sizeof(ax25_ctrl_t));
175 /* Initialize channel control data */
176 set_bit(AXF_INUSE, &axp->ctrl.flags);
177 sprintf(axp->dev.name, "ax%d", i++);
178 axp->ctrl.tty = NULL;
179 axp->dev.base_addr = i;
180 axp->dev.priv = (void *)&axp->ctrl;
181 axp->dev.next = NULL;
182 axp->dev.init = ax25_init;
186 * register device so that it can be ifconfig'ed
187 * ax25_init() will be called as a side-effect
188 * SIDE-EFFECT WARNING: ax25_init() CLEARS axp->ctrl !
190 if (register_netdev(&axp->dev) == 0) {
191 /* (Re-)Set the INUSE bit. Very Important! */
192 set_bit(AXF_INUSE, &axp->ctrl.flags);
193 axp->ctrl.dev = &axp->dev;
194 axp->dev.priv = (void *) &axp->ctrl;
198 clear_bit(AXF_INUSE,&axp->ctrl.flags);
199 printk(KERN_ERR "mkiss: ax_alloc() - register_netdev() failure.\n");
206 /* Free an AX25 channel. */
207 static inline void ax_free(struct ax_disp *ax)
209 /* Free all AX25 frame buffers. */
216 if (!test_and_clear_bit(AXF_INUSE, &ax->flags))
217 printk(KERN_ERR "mkiss: %s: ax_free for already free unit.\n", ax->dev->name);
220 static void ax_changedmtu(struct ax_disp *ax)
222 struct net_device *dev = ax->dev;
223 unsigned char *xbuff, *rbuff, *oxbuff, *orbuff;
229 * allow for arrival of larger UDP packets, even if we say not to
230 * also fixes a bug in which SunOS sends 512-byte packets even with
236 xbuff = kmalloc(len + 4, GFP_ATOMIC);
237 rbuff = kmalloc(len + 4, GFP_ATOMIC);
239 if (xbuff == NULL || rbuff == NULL) {
240 printk(KERN_ERR "mkiss: %s: unable to grow ax25 buffers, MTU change cancelled.\n",
250 spin_lock_bh(&ax->buflock);
258 if (ax->xleft <= len) {
259 memcpy(ax->xbuff, ax->xhead, ax->xleft);
266 ax->xhead = ax->xbuff;
269 if (ax->rcount <= len) {
270 memcpy(ax->rbuff, orbuff, ax->rcount);
273 ax->rx_over_errors++;
274 set_bit(AXF_ERROR, &ax->flags);
278 ax->mtu = dev->mtu + 73;
281 spin_unlock_bh(&ax->buflock);
290 /* Set the "sending" flag. This must be atomic. */
291 static inline void ax_lock(struct ax_disp *ax)
293 netif_stop_queue(ax->dev);
297 /* Clear the "sending" flag. This must be atomic. */
298 static inline void ax_unlock(struct ax_disp *ax)
300 netif_start_queue(ax->dev);
303 /* Send one completely decapsulated AX.25 packet to the AX.25 layer. */
304 static void ax_bump(struct ax_disp *ax)
309 spin_lock_bh(&ax->buflock);
310 if (ax->rbuff[0] > 0x0f) {
311 if (ax->rbuff[0] & 0x20) {
312 ax->crcmode = CRC_MODE_FLEX;
313 if (check_crc_flex(ax->rbuff, ax->rcount) < 0) {
318 /* dl9sau bugfix: the trailling two bytes flexnet crc
319 * will not be passed to the kernel. thus we have
320 * to correct the kissparm signature, because it
321 * indicates a crc but there's none
326 spin_unlock_bh(&ax->buflock);
330 if ((skb = dev_alloc_skb(count)) == NULL) {
331 printk(KERN_ERR "mkiss: %s: memory squeeze, dropping packet.\n", ax->dev->name);
336 spin_lock_bh(&ax->buflock);
337 memcpy(skb_put(skb,count), ax->rbuff, count);
338 spin_unlock_bh(&ax->buflock);
339 skb->protocol = ax25_type_trans(skb, ax->dev);
341 ax->dev->last_rx = jiffies;
346 /* Encapsulate one AX.25 packet and stuff into a TTY queue. */
347 static void ax_encaps(struct ax_disp *ax, unsigned char *icp, int len)
352 if (ax->mtu != ax->dev->mtu + 73) /* Someone has been ifconfigging */
355 if (len > ax->mtu) { /* Sigh, shouldn't occur BUT ... */
357 printk(KERN_ERR "mkiss: %s: truncating oversized transmit packet!\n", ax->dev->name);
365 spin_lock_bh(&ax->buflock);
366 switch (ax->crcmode) {
371 crc = calc_crc_flex(p, len);
372 count = kiss_esc_crc(p, (unsigned char *)ax->xbuff, crc, len+2);
376 count = kiss_esc(p, (unsigned char *)ax->xbuff, len);
380 ax->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
381 actual = ax->tty->driver->write(ax->tty, ax->xbuff, count);
383 ax->tx_bytes+=actual;
384 ax->dev->trans_start = jiffies;
385 ax->xleft = count - actual;
386 ax->xhead = ax->xbuff + actual;
388 spin_unlock_bh(&ax->buflock);
392 * Called by the driver when there's room for more data. If we have
393 * more packets to send, we send them here.
395 static void ax25_write_wakeup(struct tty_struct *tty)
398 struct ax_disp *ax = (struct ax_disp *) tty->disc_data;
400 /* First make sure we're connected. */
401 if (ax == NULL || ax->magic != AX25_MAGIC || !netif_running(ax->dev))
403 if (ax->xleft <= 0) {
404 /* Now serial buffer is almost free & we can start
405 * transmission of another packet
407 tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
409 netif_wake_queue(ax->dev);
413 actual = tty->driver->write(tty, ax->xhead, ax->xleft);
418 /* Encapsulate an AX.25 packet and kick it into a TTY queue. */
419 static int ax_xmit(struct sk_buff *skb, struct net_device *dev)
421 struct ax_disp *ax = netdev_priv(dev);
423 if (!netif_running(dev)) {
424 printk(KERN_ERR "mkiss: %s: xmit call when iface is down\n", dev->name);
428 if (netif_queue_stopped(dev)) {
430 * May be we must check transmitter timeout here ?
431 * 14 Oct 1994 Dmitry Gorodchanin.
433 if (time_before(jiffies, dev->trans_start + 20 * HZ)) {
434 /* 20 sec timeout not reached */
438 printk(KERN_ERR "mkiss: %s: transmit timed out, %s?\n", dev->name,
439 (ax->tty->driver->chars_in_buffer(ax->tty) || ax->xleft) ?
440 "bad line quality" : "driver error");
443 ax->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
447 /* We were not busy, so we are now... :-) */
450 ax_encaps(ax, skb->data, skb->len);
457 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
459 /* Return the frame type ID */
460 static int ax_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
461 void *daddr, void *saddr, unsigned len)
464 if (type != htons(ETH_P_AX25))
465 return ax25_encapsulate(skb, dev, type, daddr, saddr, len);
471 static int ax_rebuild_header(struct sk_buff *skb)
474 return ax25_rebuild_header(skb);
480 #endif /* CONFIG_{AX25,AX25_MODULE} */
482 /* Open the low-level part of the AX25 channel. Easy! */
483 static int ax_open(struct net_device *dev)
485 struct ax_disp *ax = netdev_priv(dev);
492 * Allocate the frame buffers:
494 * rbuff Receive buffer.
495 * xbuff Transmit buffer.
500 * allow for arrival of larger UDP packets, even if we say not to
501 * also fixes a bug in which SunOS sends 512-byte packets even with
507 if ((ax->rbuff = kmalloc(len + 4, GFP_KERNEL)) == NULL)
510 if ((ax->xbuff = kmalloc(len + 4, GFP_KERNEL)) == NULL)
513 ax->mtu = dev->mtu + 73;
518 ax->flags &= (1 << AXF_INUSE); /* Clear ESCAPE & ERROR flags */
520 spin_lock_init(&ax->buflock);
522 netif_start_queue(dev);
533 /* Close the low-level part of the AX25 channel. Easy! */
534 static int ax_close(struct net_device *dev)
536 struct ax_disp *ax = netdev_priv(dev);
541 ax->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
543 netif_stop_queue(dev);
548 static int ax25_receive_room(struct tty_struct *tty)
550 return 65536; /* We can handle an infinite amount of data. :-) */
554 * Handle the 'receiver data ready' interrupt.
555 * This function is called by the 'tty_io' module in the kernel when
556 * a block of data has been received, which can now be decapsulated
557 * and sent on to the AX.25 layer for further processing.
559 static void ax25_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, int count)
561 struct ax_disp *ax = (struct ax_disp *) tty->disc_data;
563 if (ax == NULL || ax->magic != AX25_MAGIC || !netif_running(ax->dev))
567 * Argh! mtu change time! - costs us the packet part received
570 if (ax->mtu != ax->dev->mtu + 73)
573 /* Read the characters out of the buffer */
575 if (fp != NULL && *fp++) {
576 if (!test_and_set_bit(AXF_ERROR, &ax->flags))
582 kiss_unesc(ax, *cp++);
586 static int ax25_open(struct tty_struct *tty)
588 struct ax_disp *ax = (struct ax_disp *) tty->disc_data;
591 /* First make sure we're not already connected. */
592 if (ax && ax->magic == AX25_MAGIC)
595 /* OK. Find a free AX25 channel to use. */
596 if ((ax = ax_alloc()) == NULL)
602 if (tty->driver->flush_buffer)
603 tty->driver->flush_buffer(tty);
605 /* Restore default settings */
606 ax->dev->type = ARPHRD_AX25;
608 /* Perform the low-level AX25 initialization. */
609 if ((err = ax_open(ax->dev)))
612 /* Done. We have linked the TTY line to a channel. */
613 return ax->dev->base_addr;
616 static void ax25_close(struct tty_struct *tty)
618 struct ax_disp *ax = (struct ax_disp *) tty->disc_data;
620 /* First make sure we're connected. */
621 if (ax == NULL || ax->magic != AX25_MAGIC)
624 unregister_netdev(ax->dev);
626 tty->disc_data = NULL;
633 static struct net_device_stats *ax_get_stats(struct net_device *dev)
635 static struct net_device_stats stats;
636 struct ax_disp *ax = netdev_priv(dev);
638 memset(&stats, 0, sizeof(struct net_device_stats));
640 stats.rx_packets = ax->rx_packets;
641 stats.tx_packets = ax->tx_packets;
642 stats.rx_bytes = ax->rx_bytes;
643 stats.tx_bytes = ax->tx_bytes;
644 stats.rx_dropped = ax->rx_dropped;
645 stats.tx_dropped = ax->tx_dropped;
646 stats.tx_errors = ax->tx_errors;
647 stats.rx_errors = ax->rx_errors;
648 stats.rx_over_errors = ax->rx_over_errors;
654 /************************************************************************
655 * STANDARD ENCAPSULATION *
656 ************************************************************************/
658 static int kiss_esc(unsigned char *s, unsigned char *d, int len)
660 unsigned char *ptr = d;
664 * Send an initial END character to flush out any
665 * data that may have accumulated in the receiver
694 * OK its ugly, but tell me a better solution without copying the
695 * packet to a temporary buffer :-)
697 static int kiss_esc_crc(unsigned char *s, unsigned char *d, unsigned short crc, int len)
699 unsigned char *ptr = d;
731 static void kiss_unesc(struct ax_disp *ax, unsigned char s)
735 /* drop keeptest bit = VSV */
736 if (test_bit(AXF_KEEPTEST, &ax->flags))
737 clear_bit(AXF_KEEPTEST, &ax->flags);
739 if (!test_and_clear_bit(AXF_ERROR, &ax->flags) && (ax->rcount > 2))
742 clear_bit(AXF_ESCAPE, &ax->flags);
747 set_bit(AXF_ESCAPE, &ax->flags);
750 if (test_and_clear_bit(AXF_ESCAPE, &ax->flags))
754 if (test_and_clear_bit(AXF_ESCAPE, &ax->flags))
759 spin_lock_bh(&ax->buflock);
760 if (!test_bit(AXF_ERROR, &ax->flags)) {
761 if (ax->rcount < ax->buffsize) {
762 ax->rbuff[ax->rcount++] = s;
763 spin_unlock_bh(&ax->buflock);
767 ax->rx_over_errors++;
768 set_bit(AXF_ERROR, &ax->flags);
770 spin_unlock_bh(&ax->buflock);
774 static int ax_set_mac_address(struct net_device *dev, void __user *addr)
776 if (copy_from_user(dev->dev_addr, addr, AX25_ADDR_LEN))
781 static int ax_set_dev_mac_address(struct net_device *dev, void *addr)
783 struct sockaddr *sa = addr;
785 memcpy(dev->dev_addr, sa->sa_data, AX25_ADDR_LEN);
791 /* Perform I/O control on an active ax25 channel. */
792 static int ax25_disp_ioctl(struct tty_struct *tty, void *file, int cmd, void __user *arg)
794 struct ax_disp *ax = (struct ax_disp *) tty->disc_data;
797 /* First make sure we're connected. */
798 if (ax == NULL || ax->magic != AX25_MAGIC)
803 if (copy_to_user(arg, ax->dev->name, strlen(ax->dev->name) + 1))
808 return put_user(4, (int __user *)arg);
811 if (get_user(tmp, (int __user *)arg))
814 ax->dev->addr_len = AX25_ADDR_LEN; /* sizeof an AX.25 addr */
815 ax->dev->hard_header_len = AX25_KISS_HEADER_LEN + AX25_MAX_HEADER_LEN + 3;
816 ax->dev->type = ARPHRD_AX25;
820 return ax_set_mac_address(ax->dev, arg);
827 static int ax_open_dev(struct net_device *dev)
829 struct ax_disp *ax = netdev_priv(dev);
838 /* Initialize the driver. Called by network startup. */
839 static int ax25_init(struct net_device *dev)
841 struct ax_disp *ax = netdev_priv(dev);
843 static char ax25_bcast[AX25_ADDR_LEN] =
844 {'Q'<<1,'S'<<1,'T'<<1,' '<<1,' '<<1,' '<<1,'0'<<1};
845 static char ax25_test[AX25_ADDR_LEN] =
846 {'L'<<1,'I'<<1,'N'<<1,'U'<<1,'X'<<1,' '<<1,'1'<<1};
848 if (ax == NULL) /* Allocation failed ?? */
851 /* Set up the "AX25 Control Block". (And clear statistics) */
852 memset(ax, 0, sizeof (struct ax_disp));
853 ax->magic = AX25_MAGIC;
856 /* Finish setting up the DEVICE info. */
858 dev->hard_start_xmit = ax_xmit;
859 dev->open = ax_open_dev;
860 dev->stop = ax_close;
861 dev->get_stats = ax_get_stats;
862 dev->set_mac_address = ax_set_dev_mac_address;
863 dev->hard_header_len = 0;
865 dev->type = ARPHRD_AX25;
866 dev->tx_queue_len = 10;
867 dev->hard_header = ax_header;
868 dev->rebuild_header = ax_rebuild_header;
870 memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN);
871 memcpy(dev->dev_addr, ax25_test, AX25_ADDR_LEN);
873 /* New-style flags. */
874 dev->flags = IFF_BROADCAST | IFF_MULTICAST;
880 /* ******************************************************************** */
881 /* * Init MKISS driver * */
882 /* ******************************************************************** */
884 static int __init mkiss_init_driver(void)
891 ax25_maxdev = 4; /* Sanity */
893 if ((ax25_ctrls = kmalloc(sizeof(void *) * ax25_maxdev, GFP_KERNEL)) == NULL) {
894 printk(KERN_ERR "mkiss: Can't allocate ax25_ctrls[] array!\n");
898 /* Clear the pointer array, we allocate devices when we need them */
899 memset(ax25_ctrls, 0, sizeof(void*) * ax25_maxdev); /* Pointers */
901 /* Fill in our line protocol discipline, and register it */
902 ax_ldisc.magic = TTY_LDISC_MAGIC;
903 ax_ldisc.name = "mkiss";
904 ax_ldisc.open = ax25_open;
905 ax_ldisc.close = ax25_close;
906 ax_ldisc.ioctl = (int (*)(struct tty_struct *, struct file *,
907 unsigned int, unsigned long))ax25_disp_ioctl;
908 ax_ldisc.receive_buf = ax25_receive_buf;
909 ax_ldisc.receive_room = ax25_receive_room;
910 ax_ldisc.write_wakeup = ax25_write_wakeup;
912 if ((status = tty_register_ldisc(N_AX25, &ax_ldisc)) != 0) {
913 printk(KERN_ERR "mkiss: can't register line discipline (err = %d)\n", status);
919 static void __exit mkiss_exit_driver(void)
923 for (i = 0; i < ax25_maxdev; i++) {
926 * VSV = if dev->start==0, then device
927 * unregistered while close proc.
929 if (netif_running(&ax25_ctrls[i]->dev))
930 unregister_netdev(&ax25_ctrls[i]->dev);
931 kfree(ax25_ctrls[i]);
938 if ((i = tty_unregister_ldisc(N_AX25)))
939 printk(KERN_ERR "mkiss: can't unregister line discipline (err = %d)\n", i);
942 MODULE_AUTHOR("Hans Albas PE1AYX <hans@esrac.ele.tue.nl>");
943 MODULE_DESCRIPTION("KISS driver for AX.25 over TTYs");
944 MODULE_PARM(ax25_maxdev, "i");
945 MODULE_PARM_DESC(ax25_maxdev, "number of MKISS devices");
946 MODULE_LICENSE("GPL");
947 MODULE_ALIAS_LDISC(N_AX25);
948 module_init(mkiss_init_driver);
949 module_exit(mkiss_exit_driver);