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 seperated 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 Hansa@cuci.nl
21 * Jonathan (G4KLX) Fixed to match Linux networking changes - 2.1.15.
24 #include <linux/config.h>
25 #include <linux/module.h>
26 #include <asm/system.h>
27 #include <asm/segment.h>
28 #include <asm/bitops.h>
29 #include <asm/uaccess.h>
30 #include <linux/string.h>
32 #include <linux/interrupt.h>
34 #include <linux/tty.h>
35 #include <linux/errno.h>
36 #include <linux/netdevice.h>
37 #include <linux/major.h>
38 #include <linux/init.h>
40 #include <linux/timer.h>
42 #include <linux/etherdevice.h>
43 #include <linux/skbuff.h>
44 #include <linux/if_arp.h>
52 #include <linux/tcp.h>
56 #define AX25_VERSION "AX25-MODULAR-NET3.019-NEWTTY"
57 #define min(a,b) (a < b ? a : b)
59 #define AX25_VERSION "AX25-NET3.019-NEWTTY"
63 #define MKISS_SERIAL_TYPE_NORMAL 1
65 struct mkiss_channel
{
66 int magic
; /* magic word */
67 int init
; /* channel exists? */
68 struct tty_struct
*tty
; /* link to tty control structure */
71 typedef struct ax25_ctrl
{
72 char if_name
[8]; /* "ax0\0" .. "ax99999\0" */
73 struct ax_disp ctrl
; /* */
74 struct device dev
; /* the device */
77 static ax25_ctrl_t
**ax25_ctrls
= NULL
;
78 int ax25_maxdev
= AX25_MAXDEV
; /* Can be overridden with insmod! */
79 MODULE_PARM(ax25_maxdev
, "i");
81 static struct tty_ldisc ax_ldisc
;
82 static struct tty_driver mkiss_driver
;
83 static int mkiss_refcount
;
84 static struct tty_struct
*mkiss_table
[NR_MKISS
];
85 static struct termios
*mkiss_termios
[NR_MKISS
];
86 static struct termios
*mkiss_termios_locked
[NR_MKISS
];
87 struct mkiss_channel MKISS_Info
[NR_MKISS
];
89 static int ax25_init(struct device
*);
90 static int mkiss_init(void);
91 static int mkiss_write(struct tty_struct
*, int, const unsigned char *, int);
92 static int kiss_esc(unsigned char *, unsigned char *, int);
93 static void kiss_unesc(struct ax_disp
*, unsigned char);
95 /* Find a free channel, and link in this `tty' line. */
96 static inline struct ax_disp
*ax_alloc(void)
101 if (ax25_ctrls
== NULL
) /* Master array missing ! */
104 for (i
= 0; i
< ax25_maxdev
; i
++) {
107 /* Not allocated ? */
112 if (!set_bit(AXF_INUSE
, &axp
->ctrl
.flags
))
116 /* Sorry, too many, all slots in use */
117 if (i
>= ax25_maxdev
)
120 /* If no channels are available, allocate one */
121 if (axp
== NULL
&& (ax25_ctrls
[i
] = (ax25_ctrl_t
*)kmalloc(sizeof(ax25_ctrl_t
), GFP_KERNEL
)) != NULL
) {
123 memset(axp
, 0, sizeof(ax25_ctrl_t
));
125 /* Initialize channel control data */
126 set_bit(AXF_INUSE
, &axp
->ctrl
.flags
);
127 sprintf(axp
->if_name
, "ax%d", i
++);
128 axp
->ctrl
.tty
= NULL
;
129 axp
->dev
.name
= axp
->if_name
;
130 axp
->dev
.base_addr
= i
;
131 axp
->dev
.priv
= (void *)&axp
->ctrl
;
132 axp
->dev
.next
= NULL
;
133 axp
->dev
.init
= ax25_init
;
138 * register device so that it can be ifconfig'ed
139 * ax25_init() will be called as a side-effect
140 * SIDE-EFFECT WARNING: ax25_init() CLEARS axp->ctrl !
142 if (register_netdev(&axp
->dev
) == 0) {
143 /* (Re-)Set the INUSE bit. Very Important! */
144 set_bit(AXF_INUSE
, &axp
->ctrl
.flags
);
145 axp
->ctrl
.dev
= &axp
->dev
;
146 axp
->dev
.priv
= (void *)&axp
->ctrl
;
150 clear_bit(AXF_INUSE
,&axp
->ctrl
.flags
);
151 printk(KERN_ERR
"ax_alloc() - register_netdev() failure.\n");
158 /* Free an AX25 channel. */
159 static inline void ax_free(struct ax_disp
*ax
)
161 /* Free all AX25 frame buffers. */
168 if (!clear_bit(AXF_INUSE
, &ax
->flags
))
169 printk(KERN_ERR
"%s: ax_free for already free unit.\n", ax
->dev
->name
);
172 static void ax_changedmtu(struct ax_disp
*ax
)
174 struct device
*dev
= ax
->dev
;
175 unsigned char *xbuff
, *rbuff
, *oxbuff
, *orbuff
;
182 * allow for arrival of larger UDP packets, even if we say not to
183 * also fixes a bug in which SunOS sends 512-byte packets even with
189 xbuff
= (unsigned char *)kmalloc(len
+ 4, GFP_ATOMIC
);
190 rbuff
= (unsigned char *)kmalloc(len
+ 4, GFP_ATOMIC
);
192 if (xbuff
== NULL
|| rbuff
== NULL
) {
193 printk(KERN_ERR
"%s: unable to grow ax25 buffers, MTU change cancelled.\n",
212 if (ax
->xleft
<= len
) {
213 memcpy(ax
->xbuff
, ax
->xhead
, ax
->xleft
);
220 ax
->xhead
= ax
->xbuff
;
223 if (ax
->rcount
<= len
) {
224 memcpy(ax
->rbuff
, orbuff
, ax
->rcount
);
227 ax
->rx_over_errors
++;
228 set_bit(AXF_ERROR
, &ax
->flags
);
232 ax
->mtu
= dev
->mtu
+ 73;
235 restore_flags(flags
);
244 /* Set the "sending" flag. This must be atomic, hence the ASM. */
245 static inline void ax_lock(struct ax_disp
*ax
)
247 if (set_bit(0, (void *)&ax
->dev
->tbusy
))
248 printk(KERN_ERR
"%s: trying to lock already locked device!\n", ax
->dev
->name
);
252 /* Clear the "sending" flag. This must be atomic, hence the ASM. */
253 static inline void ax_unlock(struct ax_disp
*ax
)
255 if (!clear_bit(0, (void *)&ax
->dev
->tbusy
))
256 printk(KERN_ERR
"%s: trying to unlock already unlocked device!\n", ax
->dev
->name
);
259 /* Send one completely decapsulated AX.25 packet to the AX.25 layer. */
260 static void ax_bump(struct ax_disp
*ax
)
262 struct ax_disp
*tmp_ax
;
264 struct mkiss_channel
*mkiss
;
269 if (ax
->rbuff
[0] > 0x0f) {
270 if (ax
->mkiss
!= NULL
) {
271 mkiss
= ax
->mkiss
->tty
->driver_data
;
272 if (mkiss
->magic
== MKISS_DRIVER_MAGIC
)
279 if ((skb
= dev_alloc_skb(count
)) == NULL
) {
280 printk(KERN_ERR
"%s: memory squeeze, dropping packet.\n", ax
->dev
->name
);
285 skb
->dev
= tmp_ax
->dev
;
286 memcpy(skb_put(skb
,count
), ax
->rbuff
, count
);
287 skb
->mac
.raw
= skb
->data
;
288 skb
->protocol
= htons(ETH_P_AX25
);
290 tmp_ax
->rx_packets
++;
293 /* Encapsulate one AX.25 packet and stuff into a TTY queue. */
294 static void ax_encaps(struct ax_disp
*ax
, unsigned char *icp
, int len
)
298 struct mkiss_channel
*mkiss
= ax
->tty
->driver_data
;
300 if (ax
->mtu
!= ax
->dev
->mtu
+ 73) /* Someone has been ifconfigging */
303 if (len
> ax
->mtu
) { /* Sigh, shouldn't occur BUT ... */
305 printk(KERN_ERR
"%s: truncating oversized transmit packet!\n", ax
->dev
->name
);
313 if (mkiss
->magic
!= MKISS_DRIVER_MAGIC
) {
314 count
= kiss_esc(p
, (unsigned char *)ax
->xbuff
, len
);
315 ax
->tty
->flags
|= (1 << TTY_DO_WRITE_WAKEUP
);
316 actual
= ax
->tty
->driver
.write(ax
->tty
, 0, ax
->xbuff
, count
);
318 ax
->dev
->trans_start
= jiffies
;
319 ax
->xleft
= count
- actual
;
320 ax
->xhead
= ax
->xbuff
+ actual
;
322 count
= kiss_esc(p
, (unsigned char *) ax
->mkiss
->xbuff
, len
);
323 ax
->mkiss
->tty
->flags
|= (1 << TTY_DO_WRITE_WAKEUP
);
324 actual
= ax
->mkiss
->tty
->driver
.write(ax
->mkiss
->tty
, 0, ax
->mkiss
->xbuff
, count
);
326 ax
->mkiss
->dev
->trans_start
= jiffies
;
327 ax
->mkiss
->xleft
= count
- actual
;
328 ax
->mkiss
->xhead
= ax
->mkiss
->xbuff
+ actual
;
333 * Called by the driver when there's room for more data. If we have
334 * more packets to send, we send them here.
336 static void ax25_write_wakeup(struct tty_struct
*tty
)
339 struct ax_disp
*ax
= (struct ax_disp
*)tty
->disc_data
;
340 struct mkiss_channel
*mkiss
;
342 /* First make sure we're connected. */
343 if (ax
== NULL
|| ax
->magic
!= AX25_MAGIC
|| !ax
->dev
->start
)
345 if (ax
->xleft
<= 0) {
346 /* Now serial buffer is almost free & we can start
347 * transmission of another packet
349 tty
->flags
&= ~(1 << TTY_DO_WRITE_WAKEUP
);
351 if (ax
->mkiss
!= NULL
) {
352 mkiss
= ax
->mkiss
->tty
->driver_data
;
353 if (mkiss
->magic
== MKISS_DRIVER_MAGIC
)
354 ax_unlock(ax
->mkiss
);
362 actual
= tty
->driver
.write(tty
, 0, ax
->xhead
, ax
->xleft
);
367 /* Encapsulate an AX.25 packet and kick it into a TTY queue. */
368 static int ax_xmit(struct sk_buff
*skb
, struct device
*dev
)
370 struct ax_disp
*ax
= (struct ax_disp
*)dev
->priv
;
371 struct mkiss_channel
*mkiss
= ax
->tty
->driver_data
;
372 struct ax_disp
*tmp_ax
;
376 if (mkiss
->magic
== MKISS_DRIVER_MAGIC
) {
377 if (skb
->data
[0] < 0x10)
378 skb
->data
[0] = skb
->data
[0] + 0x10;
383 printk(KERN_ERR
"%s: xmit call when iface is down\n", dev
->name
);
388 if (tmp_ax
->dev
->tbusy
)
393 printk(KERN_ERR
"mkiss: dev busy while serial dev is free\n");
399 * May be we must check transmitter timeout here ?
400 * 14 Oct 1994 Dmitry Gorodchanin.
402 if (jiffies
- dev
->trans_start
< 20 * HZ
) {
403 /* 20 sec timeout not reached */
407 printk(KERN_ERR
"%s: transmit timed out, %s?\n", dev
->name
,
408 (ax
->tty
->driver
.chars_in_buffer(ax
->tty
) || ax
->xleft
) ?
409 "bad line quality" : "driver error");
412 ax
->tty
->flags
&= ~(1 << TTY_DO_WRITE_WAKEUP
);
416 /* We were not busy, so we are now... :-) */
421 ax_encaps(ax
, skb
->data
, skb
->len
);
422 dev_kfree_skb(skb
, FREE_WRITE
);
428 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
430 /* Return the frame type ID */
431 static int ax_header(struct sk_buff
*skb
, struct device
*dev
, unsigned short type
,
432 void *daddr
, void *saddr
, unsigned len
)
435 if (type
!= htons(ETH_P_AX25
))
436 return ax25_encapsulate(skb
, dev
, type
, daddr
, saddr
, len
);
442 static int ax_rebuild_header(struct sk_buff
*skb
)
445 return ax25_rebuild_header(skb
);
451 #endif /* CONFIG_{AX25,AX25_MODULE} */
453 /* Open the low-level part of the AX25 channel. Easy! */
454 static int ax_open(struct device
*dev
)
456 struct ax_disp
*ax
= (struct ax_disp
*)dev
->priv
;
463 * Allocate the frame buffers:
465 * rbuff Receive buffer.
466 * xbuff Transmit buffer.
467 * cbuff Temporary compression buffer.
472 * allow for arrival of larger UDP packets, even if we say not to
473 * also fixes a bug in which SunOS sends 512-byte packets even with
479 if ((ax
->rbuff
= (unsigned char *) kmalloc(len
+ 4, GFP_KERNEL
)) == NULL
)
482 if ((ax
->xbuff
= (unsigned char *) kmalloc(len
+ 4, GFP_KERNEL
)) == NULL
)
485 ax
->mtu
= dev
->mtu
+ 73;
490 ax
->flags
&= (1 << AXF_INUSE
); /* Clear ESCAPE & ERROR flags */
491 /* Needed because address '0' is special */
492 if (dev
->pa_addr
== 0)
493 dev
->pa_addr
= ntohl(0xC0A80001);
510 /* Close the low-level part of the AX25 channel. Easy! */
511 static int ax_close(struct device
*dev
)
513 struct ax_disp
*ax
= (struct ax_disp
*)dev
->priv
;
518 ax
->tty
->flags
&= ~(1 << TTY_DO_WRITE_WAKEUP
);
526 static int ax25_receive_room(struct tty_struct
*tty
)
528 return 65536; /* We can handle an infinite amount of data. :-) */
532 * Handle the 'receiver data ready' interrupt.
533 * This function is called by the 'tty_io' module in the kernel when
534 * a block of data has been received, which can now be decapsulated
535 * and sent on to the AX.25 layer for further processing.
537 static void ax25_receive_buf(struct tty_struct
*tty
, const unsigned char *cp
, char *fp
, int count
)
539 struct ax_disp
*ax
= (struct ax_disp
*)tty
->disc_data
;
541 if (ax
== NULL
|| ax
->magic
!= AX25_MAGIC
|| !ax
->dev
->start
)
545 * Argh! mtu change time! - costs us the packet part received
548 if (ax
->mtu
!= ax
->dev
->mtu
+ 73)
551 /* Read the characters out of the buffer */
553 if (fp
!= NULL
&& *fp
++) {
554 if (!set_bit(AXF_ERROR
, &ax
->flags
))
560 kiss_unesc(ax
, *cp
++);
564 static int ax25_open(struct tty_struct
*tty
)
566 struct ax_disp
*ax
= (struct ax_disp
*)tty
->disc_data
;
567 struct ax_disp
*tmp_ax
;
568 struct mkiss_channel
*mkiss
;
571 /* First make sure we're not already connected. */
572 if (ax
&& ax
->magic
== AX25_MAGIC
)
575 /* OK. Find a free AX25 channel to use. */
576 if ((ax
= ax_alloc()) == NULL
)
585 if (tty
->driver
.flush_buffer
)
586 tty
->driver
.flush_buffer(tty
);
587 if (tty
->ldisc
.flush_buffer
)
588 tty
->ldisc
.flush_buffer(tty
);
590 /* Restore default settings */
591 ax
->dev
->type
= ARPHRD_AX25
;
593 /* Perform the low-level AX25 initialization. */
594 if ((err
= ax_open(ax
->dev
)))
597 mkiss
= ax
->tty
->driver_data
;
599 if (mkiss
->magic
== MKISS_DRIVER_MAGIC
) {
600 for (cnt
= 1; cnt
< ax25_maxdev
; cnt
++) {
601 if (ax25_ctrls
[cnt
]) {
602 if (ax25_ctrls
[cnt
]->dev
.start
) {
603 if (ax
== &ax25_ctrls
[cnt
]->ctrl
) {
605 tmp_ax
= &ax25_ctrls
[cnt
]->ctrl
;
613 if (tmp_ax
!= NULL
) {
620 /* Done. We have linked the TTY line to a channel. */
621 return ax
->dev
->base_addr
;
624 static void ax25_close(struct tty_struct
*tty
)
626 struct ax_disp
*ax
= (struct ax_disp
*)tty
->disc_data
;
629 /* First make sure we're connected. */
630 if (ax
== NULL
|| ax
->magic
!= AX25_MAGIC
)
639 /* VSV = very important to remove timers */
641 unregister_netdev(ax
->dev
);
647 static struct net_device_stats
*ax_get_stats(struct device
*dev
)
649 static struct net_device_stats stats
;
650 struct ax_disp
*ax
= (struct ax_disp
*)dev
->priv
;
652 memset(&stats
, 0, sizeof(struct net_device_stats
));
654 stats
.rx_packets
= ax
->rx_packets
;
655 stats
.tx_packets
= ax
->tx_packets
;
656 stats
.rx_dropped
= ax
->rx_dropped
;
657 stats
.tx_dropped
= ax
->tx_dropped
;
658 stats
.tx_errors
= ax
->tx_errors
;
659 stats
.rx_errors
= ax
->rx_errors
;
660 stats
.rx_over_errors
= ax
->rx_over_errors
;
666 /************************************************************************
667 * STANDARD ENCAPSULATION *
668 ************************************************************************/
670 int kiss_esc(unsigned char *s
, unsigned char *d
, int len
)
672 unsigned char *ptr
= d
;
676 * Send an initial END character to flush out any
677 * data that may have accumulated in the receiver
704 static void kiss_unesc(struct ax_disp
*ax
, unsigned char s
)
708 /* drop keeptest bit = VSV */
709 if (test_bit(AXF_KEEPTEST
, &ax
->flags
))
710 clear_bit(AXF_KEEPTEST
, &ax
->flags
);
712 if (!clear_bit(AXF_ERROR
, &ax
->flags
) && (ax
->rcount
> 2))
715 clear_bit(AXF_ESCAPE
, &ax
->flags
);
720 set_bit(AXF_ESCAPE
, &ax
->flags
);
723 if (clear_bit(AXF_ESCAPE
, &ax
->flags
))
727 if (clear_bit(AXF_ESCAPE
, &ax
->flags
))
732 if (!test_bit(AXF_ERROR
, &ax
->flags
)) {
733 if (ax
->rcount
< ax
->buffsize
) {
734 ax
->rbuff
[ax
->rcount
++] = s
;
738 ax
->rx_over_errors
++;
739 set_bit(AXF_ERROR
, &ax
->flags
);
744 int ax_set_mac_address(struct device
*dev
, void *addr
)
748 if ((err
= verify_area(VERIFY_READ
, addr
, AX25_ADDR_LEN
)) != 0)
751 /* addr is an AX.25 shifted ASCII mac address */
752 copy_from_user(dev
->dev_addr
, addr
, AX25_ADDR_LEN
);
757 static int ax_set_dev_mac_address(struct device
*dev
, void *addr
)
759 struct sockaddr
*sa
= addr
;
761 memcpy(dev
->dev_addr
, sa
->sa_data
, AX25_ADDR_LEN
);
767 /* Perform I/O control on an active ax25 channel. */
768 static int ax25_disp_ioctl(struct tty_struct
*tty
, void *file
, int cmd
, void *arg
)
770 struct ax_disp
*ax
= (struct ax_disp
*)tty
->disc_data
;
774 /* First make sure we're connected. */
775 if (ax
== NULL
|| ax
->magic
!= AX25_MAGIC
)
780 if ((err
= verify_area(VERIFY_WRITE
, arg
, strlen(ax
->dev
->name
) + 1)) != 0)
782 copy_to_user(arg
, ax
->dev
->name
, strlen(ax
->dev
->name
) + 1);
786 if ((err
= verify_area(VERIFY_WRITE
, arg
, sizeof(int))) != 0)
788 put_user(4, (int *)arg
);
792 if ((err
= verify_area(VERIFY_READ
, arg
, sizeof(int))) != 0)
794 get_user(tmp
, (int *)arg
);
796 ax
->dev
->addr_len
= AX25_ADDR_LEN
; /* sizeof an AX.25 addr */
797 ax
->dev
->hard_header_len
= AX25_KISS_HEADER_LEN
+ AX25_MAX_HEADER_LEN
+ 3;
798 ax
->dev
->type
= ARPHRD_AX25
;
802 return ax_set_mac_address(ax
->dev
, arg
);
809 static int ax_open_dev(struct device
*dev
)
811 struct ax_disp
*ax
= (struct ax_disp
*)dev
->priv
;
819 /* Initialize AX25 control device -- register AX25 line discipline */
820 __initfunc(int mkiss_init_ctrl_dev(void))
824 if (ax25_maxdev
< 4) ax25_maxdev
= 4; /* Sanity */
826 if ((ax25_ctrls
= (ax25_ctrl_t
**)kmalloc(sizeof(void*) * ax25_maxdev
, GFP_KERNEL
)) == NULL
) {
827 printk(KERN_ERR
"mkiss: Can't allocate ax25_ctrls[] array ! No mkiss available\n");
831 /* Clear the pointer array, we allocate devices when we need them */
832 memset(ax25_ctrls
, 0, sizeof(void*) * ax25_maxdev
); /* Pointers */
834 /* Fill in our line protocol discipline, and register it */
835 memset(&ax_ldisc
, 0, sizeof(ax_ldisc
));
836 ax_ldisc
.magic
= TTY_LDISC_MAGIC
;
837 ax_ldisc
.name
= "mkiss";
839 ax_ldisc
.open
= ax25_open
;
840 ax_ldisc
.close
= ax25_close
;
841 ax_ldisc
.read
= NULL
;
842 ax_ldisc
.write
= NULL
;
843 ax_ldisc
.ioctl
= (int (*)(struct tty_struct
*, struct file
*, unsigned int, unsigned long))ax25_disp_ioctl
;
844 ax_ldisc
.poll
= NULL
;
846 ax_ldisc
.receive_buf
= ax25_receive_buf
;
847 ax_ldisc
.receive_room
= ax25_receive_room
;
848 ax_ldisc
.write_wakeup
= ax25_write_wakeup
;
850 if ((status
= tty_register_ldisc(N_AX25
, &ax_ldisc
)) != 0)
851 printk(KERN_ERR
"mkiss: can't register line discipline (err = %d)\n", status
);
859 * Return "not found", so that dev_init() will unlink
860 * the placeholder device entry for us.
867 /* Initialize the driver. Called by network startup. */
869 static int ax25_init(struct device
*dev
)
871 struct ax_disp
*ax
= (struct ax_disp
*)dev
->priv
;
873 static char ax25_bcast
[AX25_ADDR_LEN
] =
874 {'Q'<<1,'S'<<1,'T'<<1,' '<<1,' '<<1,' '<<1,'0'<<1};
875 static char ax25_test
[AX25_ADDR_LEN
] =
876 {'L'<<1,'I'<<1,'N'<<1,'U'<<1,'X'<<1,' '<<1,'1'<<1};
878 if (ax
== NULL
) /* Allocation failed ?? */
881 /* Set up the "AX25 Control Block". (And clear statistics) */
882 memset(ax
, 0, sizeof (struct ax_disp
));
883 ax
->magic
= AX25_MAGIC
;
886 /* Finish setting up the DEVICE info. */
888 dev
->hard_start_xmit
= ax_xmit
;
889 dev
->open
= ax_open_dev
;
890 dev
->stop
= ax_close
;
891 dev
->get_stats
= ax_get_stats
;
892 #ifdef HAVE_SET_MAC_ADDR
893 dev
->set_mac_address
= ax_set_dev_mac_address
;
895 dev
->hard_header_len
= 0;
897 dev
->type
= ARPHRD_AX25
;
898 dev
->tx_queue_len
= 10;
900 memcpy(dev
->broadcast
, ax25_bcast
, AX25_ADDR_LEN
);
901 memcpy(dev
->dev_addr
, ax25_test
, AX25_ADDR_LEN
);
903 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
904 dev
->hard_header
= ax_header
;
905 dev
->rebuild_header
= ax_rebuild_header
;
908 dev_init_buffers(dev
);
910 /* New-style flags. */
912 dev
->family
= AF_INET
;
921 static int mkiss_open(struct tty_struct
*tty
, struct file
*filp
)
923 struct mkiss_channel
*mkiss
;
926 chan
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
928 if (chan
< 0 || chan
>= NR_MKISS
)
931 mkiss
= &MKISS_Info
[chan
];
933 mkiss
->magic
= MKISS_DRIVER_MAGIC
;
937 tty
->driver_data
= mkiss
;
939 tty
->termios
->c_iflag
= IGNBRK
| IGNPAR
;
940 tty
->termios
->c_cflag
= B9600
| CS8
| CLOCAL
;
941 tty
->termios
->c_cflag
&= ~CBAUD
;
946 static void mkiss_close(struct tty_struct
*tty
, struct file
* filp
)
948 struct mkiss_channel
*mkiss
= tty
->driver_data
;
950 if (mkiss
== NULL
|| mkiss
->magic
!= MKISS_DRIVER_MAGIC
)
958 static int mkiss_write(struct tty_struct
*tty
, int from_user
, const unsigned char *buf
, int count
)
963 static int mkiss_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
965 /* Ignore serial ioctl's */
973 case TCSETSF
: /* should flush first, but... */
974 case TCSETSW
: /* should wait until flush, but... */
982 static void mkiss_dummy(struct tty_struct
*tty
)
984 struct mkiss_channel
*mkiss
= tty
->driver_data
;
993 static void mkiss_dummy2(struct tty_struct
*tty
, unsigned char ch
)
995 struct mkiss_channel
*mkiss
= tty
->driver_data
;
1005 static int mkiss_write_room(struct tty_struct
* tty
)
1007 struct mkiss_channel
*mkiss
= tty
->driver_data
;
1015 return 65536; /* We can handle an infinite amount of data. :-) */
1019 static int mkiss_chars_in_buffer(struct tty_struct
*tty
)
1021 struct mkiss_channel
*mkiss
= tty
->driver_data
;
1033 static void mkiss_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1035 /* we don't do termios */
1038 /* ******************************************************************** */
1039 /* * Init MKISS driver * */
1040 /* ******************************************************************** */
1042 __initfunc(static int mkiss_init(void))
1044 memset(&mkiss_driver
, 0, sizeof(struct tty_driver
));
1046 mkiss_driver
.magic
= MKISS_DRIVER_MAGIC
;
1047 mkiss_driver
.name
= "mkiss";
1048 mkiss_driver
.major
= MKISS_MAJOR
;
1049 mkiss_driver
.minor_start
= 0;
1050 mkiss_driver
.num
= NR_MKISS
;
1051 mkiss_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
1052 mkiss_driver
.subtype
= MKISS_SERIAL_TYPE_NORMAL
; /* not needed */
1054 mkiss_driver
.init_termios
= tty_std_termios
;
1055 mkiss_driver
.init_termios
.c_iflag
= IGNBRK
| IGNPAR
;
1056 mkiss_driver
.init_termios
.c_cflag
= B9600
| CS8
| CLOCAL
;
1058 mkiss_driver
.flags
= TTY_DRIVER_REAL_RAW
;
1059 mkiss_driver
.refcount
= &mkiss_refcount
;
1060 mkiss_driver
.table
= mkiss_table
;
1061 mkiss_driver
.termios
= (struct termios
**)mkiss_termios
;
1062 mkiss_driver
.termios_locked
= (struct termios
**)mkiss_termios_locked
;
1064 mkiss_driver
.ioctl
= mkiss_ioctl
;
1065 mkiss_driver
.open
= mkiss_open
;
1066 mkiss_driver
.close
= mkiss_close
;
1067 mkiss_driver
.write
= mkiss_write
;
1068 mkiss_driver
.write_room
= mkiss_write_room
;
1069 mkiss_driver
.chars_in_buffer
= mkiss_chars_in_buffer
;
1070 mkiss_driver
.set_termios
= mkiss_set_termios
;
1072 /* some unused functions */
1073 mkiss_driver
.flush_buffer
= mkiss_dummy
;
1074 mkiss_driver
.throttle
= mkiss_dummy
;
1075 mkiss_driver
.unthrottle
= mkiss_dummy
;
1076 mkiss_driver
.stop
= mkiss_dummy
;
1077 mkiss_driver
.start
= mkiss_dummy
;
1078 mkiss_driver
.hangup
= mkiss_dummy
;
1079 mkiss_driver
.flush_chars
= mkiss_dummy
;
1080 mkiss_driver
.put_char
= mkiss_dummy2
;
1082 if (tty_register_driver(&mkiss_driver
)) {
1083 printk(KERN_ERR
"Couldn't register Mkiss device\n");
1087 printk(KERN_INFO
"AX.25 Multikiss device enabled\n");
1095 int init_module(void)
1097 return mkiss_init_ctrl_dev();
1100 void cleanup_module(void)
1104 if (ax25_ctrls
!= NULL
) {
1105 for (i
= 0; i
< ax25_maxdev
; i
++) {
1106 if (ax25_ctrls
[i
]) {
1108 * VSV = if dev->start==0, then device
1109 * unregistred while close proc.
1111 if (ax25_ctrls
[i
]->dev
.start
)
1112 unregister_netdev(&(ax25_ctrls
[i
]->dev
));
1114 kfree(ax25_ctrls
[i
]);
1115 ax25_ctrls
[i
] = NULL
;
1123 if ((i
= tty_register_ldisc(N_AX25
, NULL
)))
1124 printk(KERN_ERR
"mkiss: can't unregister line discipline (err = %d)\n", i
);
1126 if (tty_unregister_driver(&mkiss_driver
)) /* remove devive */
1127 printk(KERN_ERR
"mkiss: can't unregister MKISS device\n");