2 * slip.c This module implements the SLIP protocol for kernel-based
3 * devices like TTY. It interfaces between a raw TTY, and the
4 * kernel's INET protocol layers (via DDI).
6 * Version: @(#)slip.c 0.7.6 05/25/93
8 * Authors: Laurence Culhane, <loz@holmes.demon.co.uk>
9 * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
12 * Alan Cox : Sanity checks and avoid tx overruns.
13 * Has a new sl->mtu field.
14 * Alan Cox : Found cause of overrun. ifconfig sl0 mtu upwards.
15 * Driver now spots this and grows/shrinks its buffers(hack!).
16 * Memory leak if you run out of memory setting up a slip driver fixed.
17 * Matt Dillon : Printable slip (borrowed from NET2E)
18 * Pauline Middelink : Slip driver fixes.
19 * Alan Cox : Honours the old SL_COMPRESSED flag
20 * Alan Cox : KISS AX.25 and AXUI IP support
21 * Michael Riepe : Automatic CSLIP recognition added
24 #include <asm/segment.h>
25 #include <asm/system.h>
27 #include <linux/config.h>
28 #include <linux/types.h>
29 #include <linux/kernel.h>
30 #include <linux/sched.h>
31 #include <linux/string.h>
33 #include <linux/socket.h>
34 #include <linux/sockios.h>
35 #include <linux/interrupt.h>
36 #include <linux/tty.h>
37 #include <linux/errno.h>
38 #include <linux/stat.h>
56 #define SLIP_VERSION "0.7.5"
58 /* Define some IP layer stuff. Not all systems have it. */
60 # define IP_VERSION 4 /* version# of our IP software */
61 # define IPF_F_OFFSET 0x1fff /* Offset field */
62 # define IPF_DF 0x4000 /* Don't fragment flag */
63 # define IPF_MF 0x2000 /* More Fragments flag */
64 # define IP_OF_COPIED 0x80 /* Copied-on-fragmentation flag */
65 # define IP_OF_CLASS 0x60 /* Option class */
66 # define IP_OF_NUMBER 0x1f /* Option number */
70 static struct slip sl_ctrl
[SL_NRUNIT
];
71 static struct tty_ldisc sl_ldisc
;
72 static int already
= 0;
75 /* Dump the contents of an IP datagram. */
77 ip_dump(unsigned char *ptr
, int len
)
84 if (inet_debug
!= DBG_SLIP
) return;
86 ip
= (struct iphdr
*) ptr
;
87 th
= (struct tcphdr
*) (ptr
+ ip
->ihl
* 4);
88 printk("\r%s -> %s seq %lx ack %lx len %d\n",
89 in_ntoa(ip
->saddr
), in_ntoa(ip
->daddr
),
90 ntohl(th
->seq
), ntohl(th
->ack_seq
), ntohs(ip
->tot_len
));
94 printk("%p %d\n", ptr
, len
);
95 ip
= (struct iphdr
*) ptr
;
96 dlen
= ntohs(ip
->tot_len
);
97 doff
= ((ntohs(ip
->frag_off
) & IPF_F_OFFSET
) << 3);
100 printk("SLIP: %s->", in_ntoa(ip
->saddr
));
101 printk("%s\n", in_ntoa(ip
->daddr
));
102 printk(" len %u ihl %u ver %u ttl %u prot %u",
103 dlen
, ip
->ihl
, ip
->version
, ip
->ttl
, ip
->protocol
);
105 if (ip
->tos
!= 0) printk(" tos %u", ip
->tos
);
106 if (doff
!= 0 || (ntohs(ip
->frag_off
) & IPF_MF
))
107 printk(" id %u offs %u", ntohs(ip
->id
), doff
);
109 if (ntohs(ip
->frag_off
) & IPF_DF
) printk(" DF");
110 if (ntohs(ip
->frag_off
) & IPF_MF
) printk(" MF");
116 void clh_dump(unsigned char *cp
, int len
)
122 printk(" %x", *cp
++);
129 /* Initialize a SLIP control block for use. */
131 sl_initialize(struct slip
*sl
, struct device
*dev
)
138 sl
->mode
= SL_MODE_ADAPTIVE
; /* automatic CSLIP recognition */
141 sl
->mode
= SL_MODE_CSLIP
| SL_MODE_ADAPTIVE
; /* Default */
143 sl
->mode
= SL_MODE_SLIP
; /* Default for non compressors */
147 sl
->line
= dev
->base_addr
;
152 /* Clear all pointers. */
159 dev
->rmem_end
= (unsigned long) NULL
;
160 dev
->rmem_start
= (unsigned long) NULL
;
161 dev
->mem_end
= (unsigned long) NULL
;
162 dev
->mem_start
= (unsigned long) NULL
;
166 /* Find a SLIP channel from its `tty' link. */
168 sl_find(struct tty_struct
*tty
)
173 if (tty
== NULL
) return(NULL
);
174 for (i
= 0; i
< SL_NRUNIT
; i
++) {
176 if (sl
->tty
== tty
) return(sl
);
182 /* Find a free SLIP channel, and link in this `tty' line. */
183 static inline struct slip
*
192 for (i
= 0; i
< SL_NRUNIT
; i
++) {
194 if (sl
->inuse
== 0) {
197 restore_flags(flags
);
201 restore_flags(flags
);
206 /* Free a SLIP channel. */
208 sl_free(struct slip
*sl
)
217 restore_flags(flags
);
221 /* MTU has been changed by the IP layer. Unfortunately we are not told about this, but
222 we spot it ourselves and fix things up. We could be in an upcall from the tty
223 driver, or in an ip packet queue. */
225 static void sl_changedmtu(struct slip
*sl
)
227 struct device
*dev
=sl
->dev
;
228 unsigned char *tb
,*rb
,*cb
,*tf
,*rf
,*cf
;
235 DPRINTF((DBG_SLIP
,"SLIP: mtu changed!\n"));
237 tb
= (unsigned char *) kmalloc(l
+ 4, GFP_KERNEL
);
238 rb
= (unsigned char *) kmalloc(l
+ 4, GFP_KERNEL
);
239 cb
= (unsigned char *) kmalloc(l
+ 4, GFP_KERNEL
);
241 if(tb
==NULL
|| rb
==NULL
|| cb
==NULL
)
243 printk("Unable to grow slip buffers. MTU change cancelled.\n");
257 tf
=(unsigned char *)sl
->dev
->mem_start
;
258 sl
->dev
->mem_start
=(unsigned long)tb
;
259 sl
->dev
->mem_end
=(unsigned long) (sl
->dev
->mem_start
+ l
);
260 rf
=(unsigned char *)sl
->dev
->rmem_start
;
261 sl
->dev
->rmem_start
=(unsigned long)rb
;
262 sl
->dev
->rmem_end
=(unsigned long) (sl
->dev
->rmem_start
+ l
);
264 sl
->xbuff
= (unsigned char *) sl
->dev
->mem_start
;
265 sl
->rbuff
= (unsigned char *) sl
->dev
->rmem_start
;
266 sl
->rend
= (unsigned char *) sl
->dev
->rmem_end
;
267 sl
->rhead
= sl
->rbuff
;
287 /* Stuff one byte into a SLIP receiver buffer. */
289 sl_enqueue(struct slip
*sl
, unsigned char c
)
295 if (sl
->rhead
< sl
->rend
) {
299 } else sl
->roverrun
++;
300 restore_flags(flags
);
303 /* Release 'i' bytes from a SLIP receiver buffer. */
305 sl_dequeue(struct slip
*sl
, int i
)
311 if (sl
->rhead
> sl
->rbuff
) {
315 restore_flags(flags
);
319 /* Set the "sending" flag. This must be atomic, hence the ASM. */
321 sl_lock(struct slip
*sl
)
329 restore_flags(flags
);
333 /* Clear the "sending" flag. This must be atomic, hence the ASM. */
335 sl_unlock(struct slip
*sl
)
343 restore_flags(flags
);
347 /* Send one completely decapsulated IP datagram to the IP layer. */
349 sl_bump(struct slip
*sl
)
357 if (sl
->mode
& (SL_MODE_ADAPTIVE
| SL_MODE_CSLIP
)) {
358 if ((c
= sl
->rbuff
[0]) & SL_TYPE_COMPRESSED_TCP
) {
360 /* ignore compressed packets when CSLIP is off */
361 if (!(sl
->mode
& SL_MODE_CSLIP
)) {
362 printk("SLIP: compressed packet ignored\n");
366 /* make sure we've reserved enough space for uncompress to use */
369 if ((sl
->rhead
+ 80) < sl
->rend
) {
377 restore_flags(flags
);
378 if (! done
) /* not enough space available */
381 count
= slhc_uncompress(sl
->slcomp
, sl
->rbuff
, count
);
386 } else if (c
>= SL_TYPE_UNCOMPRESSED_TCP
) {
387 if (!(sl
->mode
& SL_MODE_CSLIP
)) {
388 /* turn on header compression */
389 sl
->mode
|= SL_MODE_CSLIP
;
390 printk("SLIP: header compression turned on\n");
392 sl
->rbuff
[0] &= 0x4f;
393 if (slhc_remember(sl
->slcomp
, sl
->rbuff
, count
) <= 0) {
400 DPRINTF((DBG_SLIP
, "<< \"%s\" recv:\r\n", sl
->dev
->name
));
401 ip_dump(sl
->rbuff
, sl
->rcount
);
403 /* Bump the datagram to the upper layers... */
405 DPRINTF((DBG_SLIP
, "SLIP: packet is %d at 0x%X\n",
406 sl
->rcount
, sl
->rbuff
));
407 /* clh_dump(sl->rbuff, count); */
408 done
= dev_rint(sl
->rbuff
, count
, 0, sl
->dev
);
409 if (done
== 0 || done
== 1) break;
416 /* TTY finished sending a datagram, so clean up. */
418 sl_next(struct slip
*sl
)
420 DPRINTF((DBG_SLIP
, "SLIP: sl_next(0x%X) called!\n", sl
));
426 /* Encapsulate one IP datagram and stuff into a TTY queue. */
428 sl_encaps(struct slip
*sl
, unsigned char *icp
, int len
)
430 unsigned char *bp
, *p
;
433 DPRINTF((DBG_SLIP
, "SLIP: sl_encaps(0x%X, %d) called\n", icp
, len
));
434 DPRINTF((DBG_SLIP
, ">> \"%s\" sent:\r\n", sl
->dev
->name
));
438 if(sl
->mtu
!= sl
->dev
->mtu
) /* Someone has been ifconfigging */
441 if(len
>sl
->mtu
) /* Sigh, shouldn't occur BUT ... */
444 printk("slip: truncating oversized transmit packet!\n");
448 if(sl
->mode
& SL_MODE_CSLIP
)
449 len
= slhc_compress(sl
->slcomp
, p
, len
, sl
->cbuff
, &p
, 1);
453 * Send an initial END character to flush out any
454 * data that may have accumulated in the receiver
462 * For each byte in the packet, send the appropriate
463 * character sequence, according to the SLIP protocol.
486 if(sl
->mode
& SL_MODE_SLIP6
)
487 count
=slip_esc6(p
, (unsigned char *)sl
->xbuff
,len
);
489 count
=slip_esc(p
, (unsigned char *)sl
->xbuff
,len
);
494 /* Tell TTY to send it on its way. */
495 DPRINTF((DBG_SLIP
, "SLIP: kicking TTY for %d bytes at 0x%X\n", count
, bp
));
496 if (tty_write_data(sl
->tty
, (char *) bp
, count
,
497 (void (*)(void *))sl_next
, (void *) sl
) == 0) {
498 DPRINTF((DBG_SLIP
, "SLIP: TTY already done with %d bytes!\n", count
));
503 /*static void sl_hex_dump(unsigned char *x,int l)
506 printk("sl_xmit: (%d bytes)\n",l);
509 printk("%2X ",(int)*x++);
519 /* Encapsulate an IP datagram and kick it into a TTY queue. */
521 sl_xmit(struct sk_buff
*skb
, struct device
*dev
)
523 struct tty_struct
*tty
;
526 /* Find the correct SLIP channel to use. */
527 sl
= &sl_ctrl
[dev
->base_addr
];
529 DPRINTF((DBG_SLIP
, "SLIP: sl_xmit(\"%s\") skb=0x%X busy=%d\n",
530 dev
->name
, skb
, sl
->sending
));
533 * If we are busy already- too bad. We ought to be able
534 * to queue things at this point, to allow for a little
535 * frame buffer. Oh well...
538 DPRINTF((DBG_SLIP
, "SLIP: sl_xmit: BUSY\r\n"));
543 /* We were not, so we are now... :-) */
546 if(sl
->mode
& SL_MODE_AX25
)
548 if(!skb
->arp
&& dev
->rebuild_header(skb
->data
,dev
))
558 /* sl_hex_dump(skb->data,skb->len);*/
559 sl_encaps(sl
, skb
->data
, skb
->len
);
560 if (skb
->free
) kfree_skb(skb
, FREE_WRITE
);
566 /* Return the frame type ID. This is normally IP but maybe be AX.25. */
567 static unsigned short
568 sl_type_trans (struct sk_buff
*skb
, struct device
*dev
)
571 struct slip
*sl
=&sl_ctrl
[dev
->base_addr
];
572 if(sl
->mode
&SL_MODE_AX25
)
573 return(NET16(ETH_P_AX25
));
575 return(NET16(ETH_P_IP
));
579 /* Fill in the MAC-level header. Not used by SLIP. */
581 sl_header(unsigned char *buff
, struct device
*dev
, unsigned short type
,
582 unsigned long daddr
, unsigned long saddr
, unsigned len
)
585 struct slip
*sl
=&sl_ctrl
[dev
->base_addr
];
586 if((sl
->mode
&SL_MODE_AX25
) && type
!=NET16(ETH_P_AX25
))
587 return ax25_encapsulate_ip(buff
,dev
,type
,daddr
,saddr
,len
);
594 /* Add an ARP-entry for this device's broadcast address. Not used. */
596 sl_add_arp(unsigned long addr
, struct sk_buff
*skb
, struct device
*dev
)
599 struct slip
*sl
=&sl_ctrl
[dev
->base_addr
];
601 if(sl
->mode
&SL_MODE_AX25
)
602 arp_add(addr
,((char *) skb
->data
)+8,dev
);
607 /* Rebuild the MAC-level header. Not used by SLIP. */
609 sl_rebuild_header(void *buff
, struct device
*dev
)
612 struct slip
*sl
=&sl_ctrl
[dev
->base_addr
];
614 if(sl
->mode
&SL_MODE_AX25
)
615 return ax25_rebuild_header(buff
,dev
);
621 /* Open the low-level part of the SLIP channel. Easy! */
623 sl_open(struct device
*dev
)
629 sl
= &sl_ctrl
[dev
->base_addr
];
630 if (sl
->tty
== NULL
) {
631 DPRINTF((DBG_SLIP
, "SLIP: channel %d not connected!\n", sl
->line
));
637 * Allocate the SLIP frame buffers:
639 * mem_end Top of frame buffers
640 * mem_start Start of frame buffers
641 * rmem_end Top of RECV frame buffer
642 * rmem_start Start of RECV frame buffer
645 p
= (unsigned char *) kmalloc(l
+ 4, GFP_KERNEL
);
647 DPRINTF((DBG_SLIP
, "SLIP: no memory for SLIP XMIT buffer!\n"));
652 sl
->dev
->mem_start
= (unsigned long) p
;
653 sl
->dev
->mem_end
= (unsigned long) (sl
->dev
->mem_start
+ l
);
655 p
= (unsigned char *) kmalloc(l
+ 4, GFP_KERNEL
);
657 DPRINTF((DBG_SLIP
, "SLIP: no memory for SLIP RECV buffer!\n"));
660 sl
->dev
->rmem_start
= (unsigned long) p
;
661 sl
->dev
->rmem_end
= (unsigned long) (sl
->dev
->rmem_start
+ l
);
663 sl
->xbuff
= (unsigned char *) sl
->dev
->mem_start
;
664 sl
->rbuff
= (unsigned char *) sl
->dev
->rmem_start
;
665 sl
->rend
= (unsigned char *) sl
->dev
->rmem_end
;
666 sl
->rhead
= sl
->rbuff
;
672 p
= (unsigned char *) kmalloc(l
+ 4, GFP_KERNEL
);
674 kfree((unsigned char *)sl
->dev
->mem_start
);
675 DPRINTF((DBG_SLIP
, "SLIP: no memory for SLIP COMPRESS buffer!\n"));
680 sl
->slcomp
= slhc_init(16, 16);
681 if (sl
->slcomp
== NULL
) {
682 kfree((unsigned char *)sl
->dev
->mem_start
);
683 kfree((unsigned char *)sl
->dev
->rmem_start
);
685 DPRINTF((DBG_SLIP
, "SLIP: no memory for SLCOMP!\n"));
690 /* Needed because address '0' is special */
692 dev
->pa_addr
=ntohl(0xC0000001);
693 DPRINTF((DBG_SLIP
, "SLIP: channel %d opened.\n", sl
->line
));
698 /* Close the low-level part of the SLIP channel. Easy! */
700 sl_close(struct device
*dev
)
704 sl
= &sl_ctrl
[dev
->base_addr
];
705 if (sl
->tty
== NULL
) {
706 DPRINTF((DBG_SLIP
, "SLIP: channel %d not connected!\n", sl
->line
));
711 /* Free all SLIP frame buffers. */
715 slhc_free(sl
->slcomp
);
717 sl_initialize(sl
, dev
);
719 DPRINTF((DBG_SLIP
, "SLIP: channel %d closed.\n", sl
->line
));
725 * Handle the 'receiver data ready' interrupt.
726 * This function is called by the 'tty_io' module in the kernel when
727 * a block of SLIP data has been received, which can now be decapsulated
728 * and sent on to some IP layer for further processing.
731 slip_recv(struct tty_struct
*tty
)
733 unsigned char buff
[128];
738 DPRINTF((DBG_SLIP
, "SLIP: slip_recv(%d) called\n", tty
->line
));
739 if ((sl
= sl_find(tty
)) == NULL
) return; /* not connected */
741 if(sl
->mtu
!=sl
->dev
->mtu
) /* Argh! mtu change time! - costs us the packet part received at the change */
744 /* Suck the bytes out of the TTY queues. */
746 count
= tty_read_raw_data(tty
, buff
, 128);
761 else if (c
== ESC_END
)
764 printk ("SLIP: received wrong character\n");
770 if (sl
->rcount
> 2) sl_bump(sl
);
771 sl_dequeue(sl
, sl
->rcount
);
773 } else sl_enqueue(sl
, c
);
777 if(sl
->mode
& SL_MODE_SLIP6
)
778 slip_unesc6(sl
,buff
,count
,error
);
780 slip_unesc(sl
,buff
,count
,error
);
788 * Open the high-level part of the SLIP channel.
789 * This function is called by the TTY module when the
790 * SLIP line discipline is called for. Because we are
791 * sure the tty line exists, we only have to link it to
792 * a free SLIP channel...
795 slip_open(struct tty_struct
*tty
)
799 /* First make sure we're not already connected. */
800 if ((sl
= sl_find(tty
)) != NULL
) {
801 DPRINTF((DBG_SLIP
, "SLIP: TTY %d already connected to %s !\n",
802 tty
->line
, sl
->dev
->name
));
806 /* OK. Find a free SLIP channel to use. */
807 if ((sl
= sl_alloc()) == NULL
) {
808 DPRINTF((DBG_SLIP
, "SLIP: TTY %d not connected: all channels in use!\n",
814 tty_write_flush(tty
);
816 /* Perform the low-level SLIP initialization. */
817 (void) sl_open(sl
->dev
);
818 DPRINTF((DBG_SLIP
, "SLIP: TTY %d connected to %s.\n",
819 tty
->line
, sl
->dev
->name
));
821 /* Done. We have linked the TTY line to a channel. */
826 static struct enet_statistics
*
827 sl_get_stats(struct device
*dev
)
829 static struct enet_statistics stats
;
831 struct slcompress
*comp
;
833 /* Find the correct SLIP channel to use. */
834 sl
= &sl_ctrl
[dev
->base_addr
];
838 memset(&stats
, 0, sizeof(struct enet_statistics
));
840 stats
.rx_packets
= sl
->rpacket
;
841 stats
.rx_over_errors
= sl
->roverrun
;
842 stats
.tx_packets
= sl
->spacket
;
843 stats
.tx_dropped
= sl
->sbusy
;
844 stats
.rx_errors
= sl
->errors
;
848 stats
.rx_fifo_errors
= comp
->sls_i_compressed
;
849 stats
.rx_dropped
= comp
->sls_i_tossed
;
850 stats
.tx_fifo_errors
= comp
->sls_o_compressed
;
851 stats
.collisions
= comp
->sls_o_misses
;
858 * Close down a SLIP channel.
859 * This means flushing out any pending queues, and then restoring the
860 * TTY line discipline to what it was before it got hooked to SLIP
861 * (which usually is TTY again).
864 slip_close(struct tty_struct
*tty
)
868 /* First make sure we're connected. */
869 if ((sl
= sl_find(tty
)) == NULL
) {
870 DPRINTF((DBG_SLIP
, "SLIP: TTY %d not connected !\n", tty
->line
));
874 (void) dev_close(sl
->dev
);
875 DPRINTF((DBG_SLIP
, "SLIP: TTY %d disconnected from %s.\n",
876 tty
->line
, sl
->dev
->name
));
880 /************************************************************************
881 * STANDARD SLIP ENCAPSULATION *
882 ************************************************************************
887 slip_esc(unsigned char *s
, unsigned char *d
, int len
)
892 * Send an initial END character to flush out any
893 * data that may have accumulated in the receiver
900 * For each byte in the packet, send the appropriate
901 * character sequence, according to the SLIP protocol.
908 d
[count
++] = ESC_END
;
912 d
[count
++] = ESC_ESC
;
924 slip_unesc(struct slip
*sl
, unsigned char *s
, int count
, int error
)
928 for (i
= 0; i
< count
; ++i
, ++s
) {
931 sl
->flags
|= SLF_ESCAPE
;
934 if (sl
->flags
& SLF_ESCAPE
)
938 sl
->flags
&= ~SLF_ESCAPE
;
941 if (sl
->flags
& SLF_ESCAPE
)
945 sl
->flags
&= ~SLF_ESCAPE
;
950 sl_dequeue(sl
, sl
->rcount
);
952 sl
->flags
&= ~(SLF_ESCAPE
| SLF_ERROR
);
956 sl
->flags
&= ~SLF_ESCAPE
;
960 sl
->flags
|= SLF_ERROR
;
963 /************************************************************************
964 * 6 BIT SLIP ENCAPSULATION *
965 ************************************************************************
970 slip_esc6(unsigned char *s
, unsigned char *d
, int len
)
974 unsigned short v
= 0;
978 * Send an initial END character to flush out any
979 * data that may have accumulated in the receiver
986 * Encode the packet into printable ascii characters
989 for (i
= 0; i
< len
; ++i
) {
996 c
= 0x30 + ((v
>> bits
) & 0x3F);
1003 c
= 0x30 + ((v
<< (6 - bits
)) & 0x3F);
1011 slip_unesc6(struct slip
*sl
, unsigned char *s
, int count
, int error
)
1016 for (i
= 0; i
< count
; ++i
, ++s
) {
1018 if (sl
->rcount
> 8) { /* XXX must be 2 for compressed slip */
1020 printk("rbuff %02x %02x %02x %02x\n",
1029 sl_dequeue(sl
, sl
->rcount
);
1031 sl
->flags
&= ~(SLF_ESCAPE
| SLF_ERROR
); /* SLF_ESCAPE not used */
1033 } else if (*s
>= 0x30 && *s
< 0x70) {
1034 sl
->xdata
= (sl
->xdata
<< 6) | ((*s
- 0x30) & 0x3F);
1036 if (sl
->xbits
>= 8) {
1038 c
= (unsigned char)(sl
->xdata
>> sl
->xbits
);
1045 sl
->flags
|= SLF_ERROR
;
1051 int sl_set_mac_address(struct device
*dev
, void *addr
)
1053 int err
=verify_area(VERIFY_READ
,addr
,7);
1056 memcpy_fromfs(dev
->dev_addr
,addr
,7); /* addr is an AX.25 shifted ASCII mac address */
1062 /* Perform I/O control on an active SLIP channel. */
1064 slip_ioctl(struct tty_struct
*tty
, void *file
, int cmd
, void *arg
)
1069 /* First make sure we're connected. */
1070 if ((sl
= sl_find(tty
)) == NULL
) {
1071 DPRINTF((DBG_SLIP
, "SLIP: ioctl: TTY %d not connected !\n", tty
->line
));
1075 DPRINTF((DBG_SLIP
, "SLIP: ioctl(%d, 0x%X, 0x%X)\n", tty
->line
, cmd
, arg
));
1078 err
=verify_area(VERIFY_WRITE
, arg
, 16);
1081 memcpy_tofs(arg
, sl
->dev
->name
, strlen(sl
->dev
->name
) + 1);
1084 err
=verify_area(VERIFY_WRITE
,arg
,sizeof(long));
1085 put_fs_long(sl
->mode
,(long *)arg
);
1088 err
=verify_area(VERIFY_READ
,arg
,sizeof(long));
1089 sl
->mode
=get_fs_long((long *)arg
);
1091 if(sl
->mode
& SL_MODE_AX25
)
1093 sl
->dev
->addr_len
=7; /* sizeof an AX.25 addr */
1094 sl
->dev
->hard_header_len
=17; /* We don't do digipeaters */
1095 sl
->dev
->type
=3; /* AF_AX25 not an AF_INET device */
1099 sl
->dev
->addr_len
=0; /* No mac addr in slip mode */
1100 sl
->dev
->hard_header_len
=0;
1107 return sl_set_mac_address(sl
->dev
,arg
);
1116 /* Initialize the SLIP driver. Called by DDI. */
1118 slip_init(struct device
*dev
)
1123 static char ax25_bcast
[7]={'Q'<<1,'S'<<1,'T'<<1,' '<<1,' '<<1,' '<<1,'0'<<1};
1124 static char ax25_test
[7]={'L'<<1,'I'<<1,'N'<<1,'U'<<1,'X'<<1,' '<<1,'1'<<1};
1127 sl
= &sl_ctrl
[dev
->base_addr
];
1129 if (already
++ == 0) {
1130 printk("SLIP: version %s (%d channels)\n",
1131 SLIP_VERSION
, SL_NRUNIT
);
1132 printk("CSLIP: code copyright 1989 Regents of the University of California\n");
1134 printk("AX25: KISS encapsulation enabled\n");
1136 /* Fill in our LDISC request block. */
1138 sl_ldisc
.open
= slip_open
;
1139 sl_ldisc
.close
= slip_close
;
1140 sl_ldisc
.read
= NULL
;
1141 sl_ldisc
.write
= NULL
;
1142 sl_ldisc
.ioctl
= (int (*)(struct tty_struct
*, struct file
*,
1143 unsigned int, unsigned long)) slip_ioctl
;
1144 sl_ldisc
.select
= NULL
;
1145 sl_ldisc
.handler
= slip_recv
;
1146 if ((i
= tty_register_ldisc(N_SLIP
, &sl_ldisc
)) != 0)
1147 printk("ERROR: %d\n", i
);
1150 /* Set up the "SLIP Control Block". */
1151 sl_initialize(sl
, dev
);
1153 /* Clear all statistics. */
1154 sl
->rcount
= 0; /* SLIP receiver count */
1155 sl
->rpacket
= 0; /* #frames received */
1156 sl
->roverrun
= 0; /* "overrun" counter */
1157 sl
->spacket
= 0; /* #frames sent out */
1158 sl
->sbusy
= 0; /* "xmit busy" counter */
1159 sl
->errors
= 0; /* not used at present */
1161 /* Finish setting up the DEVICE info. */
1163 dev
->hard_start_xmit
= sl_xmit
;
1164 dev
->open
= sl_open
;
1165 dev
->stop
= sl_close
;
1166 dev
->hard_header
= sl_header
;
1167 dev
->add_arp
= sl_add_arp
;
1168 dev
->type_trans
= sl_type_trans
;
1169 dev
->get_stats
= sl_get_stats
;
1170 #ifdef HAVE_SET_MAC_ADDR
1172 dev
->set_mac_address
= sl_set_mac_address
;
1175 dev
->hard_header_len
= 0;
1179 memcpy(dev
->broadcast
,ax25_bcast
,7); /* Only activated in AX.25 mode */
1180 memcpy(dev
->dev_addr
,ax25_test
,7); /* "" "" "" "" */
1182 dev
->queue_xmit
= dev_queue_xmit
;
1183 dev
->rebuild_header
= sl_rebuild_header
;
1184 for (i
= 0; i
< DEV_NUMBUFFS
; i
++)
1185 dev
->buffs
[i
] = NULL
;
1187 /* New-style flags. */
1189 dev
->family
= AF_INET
;
1191 dev
->pa_brdaddr
= 0;
1193 dev
->pa_alen
= sizeof(unsigned long);