This source file includes following definitions.
- sl_initialize
- sl_alloc
- sl_free
- sl_changedmtu
- sl_lock
- sl_unlock
- sl_bump
- sl_encaps
- slip_write_wakeup
- sl_xmit
- sl_type_trans
- sl_header
- sl_rebuild_header
- sl_open
- sl_close
- slip_receive_room
- slip_receive_buf
- slip_open
- slip_close
- sl_get_stats
- slip_esc
- slip_unesc
- slip_esc6
- slip_unesc6
- sl_set_mac_address
- sl_set_dev_mac_address
- slip_ioctl
- slip_init
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 #define SL_CHECK_TRANSMIT
44 #include <linux/config.h>
45
46 #ifdef SL_COMPRESSED
47
48
49
50 #define CONFIG_SLIP_COMPRESSED
51 #endif
52 #define CONFIG_SLIP_MODE_SLIP6
53
54 #include <asm/system.h>
55 #include <asm/segment.h>
56 #include <asm/bitops.h>
57 #include <linux/string.h>
58 #include <linux/mm.h>
59 #include <linux/interrupt.h>
60 #include <linux/in.h>
61 #include <linux/tty.h>
62 #include <linux/errno.h>
63 #include <linux/netdevice.h>
64 #ifdef CONFIG_AX25
65 #include "ax25.h"
66 #endif
67 #include <linux/etherdevice.h>
68 #include <linux/skbuff.h>
69 #include <linux/if_arp.h>
70 #include "slip.h"
71 #ifdef CONFIG_INET
72 #include "ip.h"
73 #include "tcp.h"
74 #include "slhc.h"
75 #endif
76 #ifdef MODULE
77 #include <linux/module.h>
78 #include <linux/version.h>
79 #endif
80
81
82 #ifdef MODULE
83 #define SLIP_VERSION "0.8.1-NET3.014-NEWTTY-MODULAR"
84 #else
85 #define SLIP_VERSION "0.8.1-NET3.014-NEWTTY"
86 #endif
87
88
89 static struct slip sl_ctrl[SL_NRUNIT];
90 static struct tty_ldisc sl_ldisc;
91 static int already = 0;
92
93 static int slip_esc(unsigned char *p, unsigned char *d, int len);
94 static void slip_unesc(struct slip *sl, unsigned char c);
95 #ifdef CONFIG_SLIP_MODE_SLIP6
96 static int slip_esc6(unsigned char *p, unsigned char *d, int len);
97 static void slip_unesc6(struct slip *sl, unsigned char c);
98 #endif
99
100
101 static void
102 sl_initialize(struct slip *sl, struct device *dev)
103 {
104 memset(sl, 0, sizeof (struct slip));
105 sl->magic = SLIP_MAGIC;
106 sl->dev = dev;
107 sl->mode = SL_MODE_DEFAULT;
108 dev->type = ARPHRD_SLIP + sl->mode;
109 if (dev->type == 260) {
110 dev->type = ARPHRD_AX25;
111 }
112 }
113
114
115 static inline struct slip *
116 sl_alloc(void)
117 {
118 struct slip *sl;
119 int i;
120
121 for (i = 0; i < SL_NRUNIT; i++) {
122 sl = &sl_ctrl[i];
123 if (!set_bit(SLF_INUSE, &sl->flags)) {
124 return sl;
125 }
126 }
127 return NULL;
128 }
129
130
131
132 static inline void
133 sl_free(struct slip *sl)
134 {
135 if (!clear_bit(SLF_INUSE, &sl->flags)) {
136 printk("%s: sl_free for already free unit.\n", sl->dev->name);
137 }
138 }
139
140
141
142
143
144 static void sl_changedmtu(struct slip *sl)
145 {
146 struct device *dev = sl->dev;
147 unsigned char *xbuff, *rbuff, *oxbuff, *orbuff;
148 #ifdef CONFIG_INET
149 unsigned char *cbuff, *ocbuff;
150 #endif
151 int len;
152 unsigned long flags;
153
154 len = dev->mtu * 2;
155
156
157
158
159
160 if (len < 576 * 2) {
161 len = 576 * 2;
162 }
163
164 xbuff = (unsigned char *) kmalloc (len + 4, GFP_ATOMIC);
165 rbuff = (unsigned char *) kmalloc (len + 4, GFP_ATOMIC);
166 #ifdef CONFIG_INET
167 cbuff = (unsigned char *) kmalloc (len + 4, GFP_ATOMIC);
168 #endif
169
170 #ifdef CONFIG_INET
171 if (xbuff == NULL || rbuff == NULL || cbuff == NULL) {
172 #else
173 if (xbuff == NULL || rbuff == NULL) {
174 #endif
175 printk("%s: unable to grow slip buffers, MTU change cancelled.\n",
176 sl->dev->name);
177 dev->mtu = sl->mtu;
178 if (xbuff != NULL) {
179 kfree(xbuff);
180 }
181 if (rbuff != NULL) {
182 kfree(rbuff);
183 }
184 #ifdef CONFIG_INET
185 if (cbuff != NULL) {
186 kfree(cbuff);
187 }
188 #endif
189 return;
190 }
191
192 save_flags(flags); cli();
193
194 oxbuff = sl->xbuff;
195 sl->xbuff = xbuff;
196 orbuff = sl->rbuff;
197 sl->rbuff = rbuff;
198 #ifdef CONFIG_INET
199 ocbuff = sl->cbuff;
200 sl->cbuff = cbuff;
201 #endif
202 if (sl->xleft) {
203 if (sl->xleft <= len) {
204 memcpy(sl->xbuff, sl->xhead, sl->xleft);
205 } else {
206 sl->xleft = 0;
207 sl->tx_dropped++;
208 }
209 }
210 sl->xhead = sl->xbuff;
211
212 if (sl->rcount) {
213 if (sl->rcount <= len) {
214 memcpy(sl->rbuff, orbuff, sl->rcount);
215 } else {
216 sl->rcount = 0;
217 sl->rx_over_errors++;
218 set_bit(SLF_ERROR, &sl->flags);
219 }
220 }
221 #ifdef CONFIG_AX25
222 sl->mtu = dev->mtu + 73;
223 #else
224 sl->mtu = dev->mtu;
225 #endif
226 sl->buffsize = len;
227
228 restore_flags(flags);
229
230 if (oxbuff != NULL) {
231 kfree(oxbuff);
232 }
233 if (orbuff != NULL) {
234 kfree(orbuff);
235 }
236 #ifdef CONFIG_INET
237 if (ocbuff != NULL) {
238 kfree(ocbuff);
239 }
240 #endif
241 }
242
243
244
245 static inline void
246 sl_lock(struct slip *sl)
247 {
248 if (set_bit(0, (void *) &sl->dev->tbusy)) {
249 printk("%s: trying to lock already locked device!\n", sl->dev->name);
250 }
251 }
252
253
254
255 static inline void
256 sl_unlock(struct slip *sl)
257 {
258 if (!clear_bit(0, (void *)&sl->dev->tbusy)) {
259 printk("%s: trying to unlock already unlocked device!\n", sl->dev->name);
260 }
261 }
262
263
264 static void
265 sl_bump(struct slip *sl)
266 {
267 struct sk_buff *skb;
268 int count;
269
270 count = sl->rcount;
271 #ifdef CONFIG_INET
272 if (sl->mode & (SL_MODE_ADAPTIVE | SL_MODE_CSLIP)) {
273 unsigned char c;
274 if ((c = sl->rbuff[0]) & SL_TYPE_COMPRESSED_TCP) {
275
276 if (!(sl->mode & SL_MODE_CSLIP)) {
277 printk("%s: compressed packet ignored\n", sl->dev->name);
278 return;
279 }
280
281 if (count + 80 > sl->buffsize) {
282 sl->rx_over_errors++;
283 return;
284 }
285 count = slhc_uncompress(sl->slcomp, sl->rbuff, count);
286 if (count <= 0) {
287 return;
288 }
289 } else if (c >= SL_TYPE_UNCOMPRESSED_TCP) {
290 if (!(sl->mode & SL_MODE_CSLIP)) {
291
292 sl->mode |= SL_MODE_CSLIP;
293 printk("%s: header compression turned on\n", sl->dev->name);
294 }
295 sl->rbuff[0] &= 0x4f;
296 if (slhc_remember(sl->slcomp, sl->rbuff, count) <= 0) {
297 return;
298 }
299 }
300 }
301 #endif
302
303 skb = alloc_skb(count, GFP_ATOMIC);
304 if (skb == NULL) {
305 printk("%s: memory squeeze, dropping packet.\n", sl->dev->name);
306 sl->rx_dropped++;
307 return;
308 }
309 skb->len = count;
310 skb->dev = sl->dev;
311 memcpy(skb->data, sl->rbuff, count);
312 netif_rx(skb);
313 sl->rx_packets++;
314 }
315
316
317 static void
318 sl_encaps(struct slip *sl, unsigned char *icp, int len)
319 {
320 unsigned char *p;
321 int actual, count;
322
323
324 #ifdef CONFIG_AX25
325 if (sl->mtu != sl->dev->mtu + 73) {
326 #else
327 if (sl->mtu != sl->dev->mtu) {
328 #endif
329 sl_changedmtu(sl);
330 }
331
332 if (len > sl->mtu) {
333 len = sl->mtu;
334 printk ("%s: truncating oversized transmit packet!\n", sl->dev->name);
335 sl->tx_dropped++;
336 sl_unlock(sl);
337 return;
338 }
339
340 p = icp;
341 #ifdef CONFIG_INET
342 if (sl->mode & SL_MODE_CSLIP) {
343 len = slhc_compress(sl->slcomp, p, len, sl->cbuff, &p, 1);
344 }
345 #endif
346 #ifdef CONFIG_SLIP_MODE_SLIP6
347 if(sl->mode & SL_MODE_SLIP6)
348 count = slip_esc6(p, (unsigned char *) sl->xbuff, len);
349 else
350 #endif
351 count = slip_esc(p, (unsigned char *) sl->xbuff, len);
352
353
354
355
356
357
358
359
360
361 sl->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
362 actual = sl->tty->driver.write(sl->tty, 0, sl->xbuff, count);
363 #ifdef SL_CHECK_TRANSMIT
364 sl->dev->trans_start = jiffies;
365 #endif
366 sl->xleft = count - actual;
367 sl->xhead = sl->xbuff + actual;
368 }
369
370
371
372
373
374 static void slip_write_wakeup(struct tty_struct *tty)
375 {
376 int actual;
377 struct slip *sl = (struct slip *) tty->disc_data;
378
379
380 if (!sl || sl->magic != SLIP_MAGIC || !sl->dev->start) {
381 return;
382 }
383
384 if (sl->xleft <= 0) {
385
386
387 sl->tx_packets++;
388 tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
389 sl_unlock(sl);
390 mark_bh(NET_BH);
391 return;
392 }
393
394 actual = tty->driver.write(tty, 0, sl->xhead, sl->xleft);
395 sl->xleft -= actual;
396 sl->xhead += actual;
397 }
398
399
400 static int
401 sl_xmit(struct sk_buff *skb, struct device *dev)
402 {
403 struct slip *sl = &sl_ctrl[dev->base_addr];
404
405 if (!dev->start) {
406 printk("%s: xmit call when iface is down\n", dev->name);
407 return 1;
408 }
409
410
411
412
413
414
415
416
417
418
419 if (dev->tbusy) {
420
421
422
423 #ifdef SL_CHECK_TRANSMIT
424 if (jiffies - dev->trans_start < 20 * HZ) {
425
426 return 1;
427 }
428 printk("%s: transmit timed out, %s?\n", dev->name,
429 (sl->tty->driver.chars_in_buffer(sl->tty) || sl->xleft) ?
430 "bad line quality" : "driver error");
431 sl->xleft = 0;
432 sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
433 sl_unlock(sl);
434 #else
435 return 1;
436 #endif
437 }
438
439
440 if (skb != NULL) {
441 sl_lock(sl);
442 sl_encaps(sl, skb->data, skb->len);
443 dev_kfree_skb(skb, FREE_WRITE);
444 }
445 return 0;
446 }
447
448
449
450 static unsigned short
451 sl_type_trans (struct sk_buff *skb, struct device *dev)
452 {
453 #ifdef CONFIG_AX25
454 struct slip *sl = &sl_ctrl[dev->base_addr];
455
456 if (sl->mode & SL_MODE_AX25) {
457 return htons(ETH_P_AX25);
458 }
459 #endif
460 return htons(ETH_P_IP);
461 }
462
463
464
465 static int
466 sl_header(unsigned char *buff, struct device *dev, unsigned short type,
467 void *daddr, void *saddr, unsigned len, struct sk_buff *skb)
468 {
469 #ifdef CONFIG_AX25
470 #ifdef CONFIG_INET
471 struct slip *sl = &sl_ctrl[dev->base_addr];
472
473 if ((sl->mode & SL_MODE_AX25) && type != htons(ETH_P_AX25)) {
474 return ax25_encapsulate(buff, dev, type, daddr, saddr, len, skb);
475 }
476 #endif
477 #endif
478 return 0;
479 }
480
481
482
483 static int
484 sl_rebuild_header(void *buff, struct device *dev, unsigned long raddr,
485 struct sk_buff *skb)
486 {
487 #ifdef CONFIG_AX25
488 #ifdef CONFIG_INET
489 struct slip *sl = &sl_ctrl[dev->base_addr];
490
491 if (sl->mode & SL_MODE_AX25) {
492 return ax25_rebuild_header(buff, dev, raddr, skb);
493 }
494 #endif
495 #endif
496 return 0;
497 }
498
499
500
501 static int
502 sl_open(struct device *dev)
503 {
504 struct slip *sl = &sl_ctrl[dev->base_addr];
505 unsigned long len;
506
507 if (sl->tty == NULL) {
508 return -ENXIO;
509 }
510
511
512
513
514
515
516
517
518 len = dev->mtu * 2;
519
520
521
522
523
524 if (len < 576 * 2) {
525 len = 576 * 2;
526 }
527 sl->rbuff = (unsigned char *) kmalloc(len + 4, GFP_KERNEL);
528 if (sl->rbuff == NULL) {
529 goto norbuff;
530 }
531 sl->xbuff = (unsigned char *) kmalloc(len + 4, GFP_KERNEL);
532 if (sl->xbuff == NULL) {
533 goto noxbuff;
534 }
535 #ifdef CONFIG_INET
536 sl->cbuff = (unsigned char *) kmalloc(len + 4, GFP_KERNEL);
537 if (sl->cbuff == NULL) {
538 goto nocbuff;
539 }
540 sl->slcomp = slhc_init(16, 16);
541 if (sl->slcomp == NULL) {
542 goto noslcomp;
543 }
544 #endif
545
546 #ifdef CONFIG_AX25
547 sl->mtu = dev->mtu + 73;
548 #else
549 sl->mtu = dev->mtu;
550 #endif
551 sl->buffsize = len;
552 sl->rcount = 0;
553 sl->xleft = 0;
554 #ifdef CONFIG_SLIP_MODE_SLIP6
555 sl->xdata = 0;
556 sl->xbits = 0;
557 #endif
558 sl->flags &= (1 << SLF_INUSE);
559 sl->mode = SL_MODE_DEFAULT;
560
561
562 if (dev->pa_addr == 0) {
563 dev->pa_addr=ntohl(0xC0A80001);
564 }
565 dev->tbusy = 0;
566 dev->flags |= IFF_UP;
567 dev->start = 1;
568
569 return 0;
570
571
572 #ifdef CONFIG_INET
573 noslcomp:
574 kfree(sl->cbuff);
575 nocbuff:
576 #endif
577 kfree(sl->xbuff);
578 noxbuff:
579 kfree(sl->rbuff);
580 norbuff:
581 return -ENOMEM;
582 }
583
584
585
586 static int
587 sl_close(struct device *dev)
588 {
589 struct slip *sl = &sl_ctrl[dev->base_addr];
590
591 if (sl->tty == NULL) {
592 return -EBUSY;
593 }
594 sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
595 dev->tbusy = 1;
596 dev->flags &= ~IFF_UP;
597
598
599 kfree(sl->rbuff);
600 sl->rbuff = NULL;
601 kfree(sl->xbuff);
602 sl->xbuff = NULL;
603 #ifdef CONFIG_INET
604 kfree(sl->cbuff);
605 sl->cbuff = NULL;
606 slhc_free(sl->slcomp);
607 sl->slcomp = NULL;
608 #endif
609 dev->start = 0;
610 return 0;
611 }
612
613 static int
614 slip_receive_room(struct tty_struct *tty)
615 {
616 return 65536;
617 }
618
619
620
621
622
623
624
625 static void
626 slip_receive_buf(struct tty_struct *tty, unsigned char *cp, char *fp, int count)
627 {
628 struct slip *sl = (struct slip *) tty->disc_data;
629
630 if (!sl || sl->magic != SLIP_MAGIC || !sl->dev->start)
631 return;
632
633
634
635
636
637 #ifdef CONFIG_AX25
638 if (sl->mtu != sl->dev->mtu + 73) {
639 #else
640 if (sl->mtu != sl->dev->mtu) {
641 #endif
642 sl_changedmtu(sl);
643 }
644
645
646 while (count--) {
647 if (fp && *fp++) {
648 if (!set_bit(SLF_ERROR, &sl->flags)) {
649 sl->rx_errors++;
650 }
651 cp++;
652 continue;
653 }
654 #ifdef CONFIG_SLIP_MODE_SLIP6
655 if (sl->mode & SL_MODE_SLIP6)
656 slip_unesc6(sl, *cp++);
657 else
658 #endif
659 slip_unesc(sl, *cp++);
660 }
661 }
662
663
664
665
666
667
668
669
670 static int
671 slip_open(struct tty_struct *tty)
672 {
673 struct slip *sl = (struct slip *) tty->disc_data;
674
675
676 if (sl && sl->magic == SLIP_MAGIC) {
677 return -EEXIST;
678 }
679
680
681 if ((sl = sl_alloc()) == NULL) {
682 return -ENFILE;
683 }
684
685 sl->tty = tty;
686 tty->disc_data = sl;
687 if (tty->driver.flush_buffer) {
688 tty->driver.flush_buffer(tty);
689 }
690 if (tty->ldisc.flush_buffer) {
691 tty->ldisc.flush_buffer(tty);
692 }
693
694
695 (void) sl_open(sl->dev);
696
697 #ifdef MODULE
698 MOD_INC_USE_COUNT;
699 #endif
700
701
702 return sl->dev->base_addr;
703 }
704
705
706
707
708
709
710
711
712 static void
713 slip_close(struct tty_struct *tty)
714 {
715 struct slip *sl = (struct slip *) tty->disc_data;
716
717
718 if (!sl || sl->magic != SLIP_MAGIC) {
719 return;
720 }
721
722 (void) dev_close(sl->dev);
723
724 tty->disc_data = 0;
725 sl->tty = NULL;
726 sl_free(sl);
727 #ifdef MODULE
728 MOD_DEC_USE_COUNT;
729 #endif
730 }
731
732
733 static struct enet_statistics *
734 sl_get_stats(struct device *dev)
735 {
736 static struct enet_statistics stats;
737 struct slip *sl = &sl_ctrl[dev->base_addr];
738 #ifdef CONFIG_INET
739 struct slcompress *comp;
740 #endif
741
742 if (! sl) {
743 return NULL;
744 }
745
746 memset(&stats, 0, sizeof(struct enet_statistics));
747
748 stats.rx_packets = sl->rx_packets;
749 stats.tx_packets = sl->tx_packets;
750 stats.rx_dropped = sl->rx_dropped;
751 stats.tx_dropped = sl->tx_dropped;
752 stats.tx_errors = sl->tx_errors;
753 stats.rx_errors = sl->rx_errors;
754 stats.rx_over_errors = sl->rx_over_errors;
755
756 #ifdef CONFIG_INET
757 comp = sl->slcomp;
758 if (comp) {
759 stats.rx_fifo_errors = comp->sls_i_compressed;
760 stats.rx_dropped += comp->sls_i_tossed;
761 stats.tx_fifo_errors = comp->sls_o_compressed;
762 stats.collisions = comp->sls_o_misses;
763 }
764 #endif
765 return (&stats);
766 }
767
768
769
770
771
772
773 int
774 slip_esc(unsigned char *s, unsigned char *d, int len)
775 {
776 unsigned char *ptr = d;
777 unsigned char c;
778
779
780
781
782
783
784
785 *ptr++ = END;
786
787
788
789
790
791
792 while (len-- > 0) {
793 switch(c = *s++) {
794 case END:
795 *ptr++ = ESC;
796 *ptr++ = ESC_END;
797 break;
798 case ESC:
799 *ptr++ = ESC;
800 *ptr++ = ESC_ESC;
801 break;
802 default:
803 *ptr++ = c;
804 break;
805 }
806 }
807 *ptr++ = END;
808 return (ptr - d);
809 }
810
811 static void
812 slip_unesc(struct slip *sl, unsigned char s)
813 {
814
815 switch(s) {
816 case END:
817 if (!clear_bit(SLF_ERROR, &sl->flags) && (sl->rcount > 2)) {
818 sl_bump(sl);
819 }
820 clear_bit(SLF_ESCAPE, &sl->flags);
821 sl->rcount = 0;
822 return;
823
824 case ESC:
825 set_bit(SLF_ESCAPE, &sl->flags);
826 return;
827 case ESC_ESC:
828 if (clear_bit(SLF_ESCAPE, &sl->flags)) {
829 s = ESC;
830 }
831 break;
832 case ESC_END:
833 if (clear_bit(SLF_ESCAPE, &sl->flags)) {
834 s = END;
835 }
836 break;
837 }
838 if (!test_bit(SLF_ERROR, &sl->flags)) {
839 if (sl->rcount < sl->buffsize) {
840 sl->rbuff[sl->rcount++] = s;
841 return;
842 }
843 sl->rx_over_errors++;
844 set_bit(SLF_ERROR, &sl->flags);
845 }
846 }
847
848
849 #ifdef CONFIG_SLIP_MODE_SLIP6
850
851
852
853
854 int
855 slip_esc6(unsigned char *s, unsigned char *d, int len)
856 {
857 unsigned char *ptr = d;
858 unsigned char c;
859 int i;
860 unsigned short v = 0;
861 short bits = 0;
862
863
864
865
866
867
868
869 *ptr++ = 0x70;
870
871
872
873
874
875 for (i = 0; i < len; ++i) {
876 v = (v << 8) | s[i];
877 bits += 8;
878 while (bits >= 6) {
879 bits -= 6;
880 c = 0x30 + ((v >> bits) & 0x3F);
881 *ptr++ = c;
882 }
883 }
884 if (bits) {
885 c = 0x30 + ((v << (6 - bits)) & 0x3F);
886 *ptr++ = c;
887 }
888 *ptr++ = 0x70;
889 return ptr - d;
890 }
891
892 void
893 slip_unesc6(struct slip *sl, unsigned char s)
894 {
895 unsigned char c;
896
897 if (s == 0x70) {
898 if (!clear_bit(SLF_ERROR, &sl->flags) && (sl->rcount > 2)) {
899 sl_bump(sl);
900 }
901 sl->rcount = 0;
902 sl->xbits = 0;
903 sl->xdata = 0;
904 } else if (s >= 0x30 && s < 0x70) {
905 sl->xdata = (sl->xdata << 6) | ((s - 0x30) & 0x3F);
906 sl->xbits += 6;
907 if (sl->xbits >= 8) {
908 sl->xbits -= 8;
909 c = (unsigned char)(sl->xdata >> sl->xbits);
910 if (!test_bit(SLF_ERROR, &sl->flags)) {
911 if (sl->rcount < sl->buffsize) {
912 sl->rbuff[sl->rcount++] = c;
913 return;
914 }
915 sl->rx_over_errors++;
916 set_bit(SLF_ERROR, &sl->flags);
917 }
918 }
919 }
920 }
921 #endif
922
923
924
925 #ifdef CONFIG_AX25
926
927 int
928 sl_set_mac_address(struct device *dev, void *addr)
929 {
930 int err;
931
932 err = verify_area(VERIFY_READ, addr, 7);
933 if (err) {
934 return err;
935 }
936
937 memcpy_fromfs(dev->dev_addr, addr, 7);
938
939 return 0;
940 }
941
942 static int
943 sl_set_dev_mac_address(struct device *dev, void *addr)
944 {
945 memcpy(dev->dev_addr, addr, 7);
946 return 0;
947 }
948
949 #endif
950
951
952
953 static int
954 slip_ioctl(struct tty_struct *tty, void *file, int cmd, void *arg)
955 {
956 struct slip *sl = (struct slip *) tty->disc_data;
957 int err;
958 unsigned int tmp;
959
960
961 if (!sl || sl->magic != SLIP_MAGIC) {
962 return -EINVAL;
963 }
964
965 switch(cmd) {
966 case SIOCGIFNAME:
967 err = verify_area(VERIFY_WRITE, arg, 16);
968 if (err) {
969 return -err;
970 }
971 memcpy_tofs(arg, sl->dev->name, strlen(sl->dev->name) + 1);
972 return 0;
973
974 case SIOCGIFENCAP:
975 err = verify_area(VERIFY_WRITE, arg, sizeof(long));
976 if (err) {
977 return -err;
978 }
979 put_fs_long(sl->mode, (long *)arg);
980 return 0;
981
982 case SIOCSIFENCAP:
983 err = verify_area(VERIFY_READ, arg, sizeof(long));
984 if (err) {
985 return -err;
986 }
987 tmp = get_fs_long((long *)arg);
988 #ifndef CONFIG_INET
989 if (tmp & SL_MODE_CSLIP) {
990 return -EINVAL;
991 }
992 #endif
993 #ifndef CONFIG_SLIP_MODE_SLIP6
994 if (tmp & SL_MODE_SLIP6) {
995 return -EINVAL;
996 }
997 #endif
998 #ifndef CONFIG_AX25
999 if (tmp & SL_MODE_AX25) {
1000 return -EINVAL;
1001 }
1002 #else
1003 if (tmp & SL_MODE_AX25) {
1004 sl->dev->addr_len=7;
1005 sl->dev->hard_header_len=17;
1006 } else {
1007 sl->dev->addr_len=0;
1008 sl->dev->hard_header_len=0;
1009 }
1010 #endif
1011 sl->mode = tmp;
1012 sl->dev->type = ARPHRD_SLIP+sl->mode;
1013 if (sl->dev->type == 260) {
1014 sl->dev->type = ARPHRD_AX25;
1015 }
1016 return 0;
1017
1018 case SIOCSIFHWADDR:
1019 #ifdef CONFIG_AX25
1020 return sl_set_mac_address(sl->dev, arg);
1021 #else
1022 return -EINVAL;
1023 #endif
1024
1025
1026 case TCGETS:
1027 case TCGETA:
1028 return n_tty_ioctl(tty, (struct file *) file, cmd, (unsigned long) arg);
1029
1030 default:
1031 return -ENOIOCTLCMD;
1032 }
1033 }
1034
1035
1036
1037 int
1038 slip_init(struct device *dev)
1039 {
1040 struct slip *sl = &sl_ctrl[dev->base_addr];
1041 int i;
1042 #ifdef CONFIG_AX25
1043 static char ax25_bcast[7] =
1044 {'Q'<<1,'S'<<1,'T'<<1,' '<<1,' '<<1,' '<<1,'0'<<1};
1045 static char ax25_test[7] =
1046 {'L'<<1,'I'<<1,'N'<<1,'U'<<1,'X'<<1,' '<<1,'1'<<1};
1047 #endif
1048
1049 if (already++ == 0) {
1050 printk("SLIP: version %s (%d channels) %s\n",
1051 SLIP_VERSION, SL_NRUNIT,
1052 #ifdef CONFIG_SLIP_MODE_SLIP6
1053 "(6 bit encapsulation enabled)"
1054 #else
1055 ""
1056 #endif
1057 );
1058 #if defined(CONFIG_INET) && !defined(MODULE)
1059 printk("CSLIP: code copyright 1989 Regents of the University of California\n");
1060 #endif
1061 #ifdef CONFIG_AX25
1062 printk("AX25: KISS encapsulation enabled\n");
1063 #endif
1064
1065 memset(&sl_ldisc, 0, sizeof(sl_ldisc));
1066 sl_ldisc.magic = TTY_LDISC_MAGIC;
1067 sl_ldisc.flags = 0;
1068 sl_ldisc.open = slip_open;
1069 sl_ldisc.close = slip_close;
1070 sl_ldisc.read = NULL;
1071 sl_ldisc.write = NULL;
1072 sl_ldisc.ioctl = (int (*)(struct tty_struct *, struct file *,
1073 unsigned int, unsigned long)) slip_ioctl;
1074 sl_ldisc.select = NULL;
1075 sl_ldisc.receive_buf = slip_receive_buf;
1076 sl_ldisc.receive_room = slip_receive_room;
1077 sl_ldisc.write_wakeup = slip_write_wakeup;
1078 if ((i = tty_register_ldisc(N_SLIP, &sl_ldisc)) != 0) {
1079 printk("SLIP: can't register line discipline (err = %d)\n", i);
1080 }
1081 }
1082
1083
1084 sl_initialize(sl, dev);
1085
1086
1087 dev->mtu = SL_MTU;
1088 dev->hard_start_xmit = sl_xmit;
1089 dev->open = sl_open;
1090 dev->stop = sl_close;
1091 dev->hard_header = sl_header;
1092 dev->type_trans = sl_type_trans;
1093 dev->get_stats = sl_get_stats;
1094 #ifdef HAVE_SET_MAC_ADDR
1095 #ifdef CONFIG_AX25
1096 dev->set_mac_address = sl_set_dev_mac_address;
1097 #endif
1098 #endif
1099 dev->hard_header_len = 0;
1100 dev->addr_len = 0;
1101 dev->type = 0;
1102 #ifdef CONFIG_AX25
1103 memcpy(dev->broadcast, ax25_bcast, 7);
1104 memcpy(dev->dev_addr, ax25_test, 7);
1105 #endif
1106 dev->rebuild_header = sl_rebuild_header;
1107
1108 for (i = 0; i < DEV_NUMBUFFS; i++) {
1109 skb_queue_head_init(&dev->buffs[i]);
1110 }
1111
1112
1113 dev->flags = 0;
1114 dev->family = AF_INET;
1115 dev->pa_addr = 0;
1116 dev->pa_brdaddr = 0;
1117 dev->pa_mask = 0;
1118 dev->pa_alen = sizeof(unsigned long);
1119
1120 return 0;
1121 }
1122 #ifdef MODULE
1123 char kernel_version[] = UTS_RELEASE;
1124
1125 static struct device dev_slip[SL_NRUNIT] = {
1126 {
1127 "sl0",
1128 0, 0, 0, 0,
1129 0, 0,
1130 0, 0, 0, NULL, slip_init,
1131 },
1132 { "sl1" , 0, 0, 0, 0, 1, 0, 0, 0, 0, NULL, slip_init },
1133 { "sl2" , 0, 0, 0, 0, 2, 0, 0, 0, 0, NULL, slip_init },
1134 { "sl3" , 0, 0, 0, 0, 3, 0, 0, 0, 0, NULL, slip_init },
1135 #ifdef SL_SLIP_LOTS
1136 { "sl4" , 0, 0, 0, 0, 4, 0, 0, 0, 0, NULL, slip_init },
1137 { "sl5" , 0, 0, 0, 0, 5, 0, 0, 0, 0, NULL, slip_init },
1138 { "sl6" , 0, 0, 0, 0, 6, 0, 0, 0, 0, NULL, slip_init },
1139 { "sl7" , 0, 0, 0, 0, 7, 0, 0, 0, 0, NULL, slip_init },
1140 { "sl8" , 0, 0, 0, 0, 8, 0, 0, 0, 0, NULL, slip_init },
1141 { "sl9" , 0, 0, 0, 0, 9, 0, 0, 0, 0, NULL, slip_init },
1142 { "sl10", 0, 0, 0, 0, 10, 0, 0, 0, 0, NULL, slip_init },
1143 { "sl11", 0, 0, 0, 0, 11, 0, 0, 0, 0, NULL, slip_init },
1144 { "sl12", 0, 0, 0, 0, 12, 0, 0, 0, 0, NULL, slip_init },
1145 { "sl13", 0, 0, 0, 0, 13, 0, 0, 0, 0, NULL, slip_init },
1146 { "sl14", 0, 0, 0, 0, 14, 0, 0, 0, 0, NULL, slip_init },
1147 { "sl15", 0, 0, 0, 0, 15, 0, 0, 0, 0, NULL, slip_init },
1148 #endif
1149 };
1150
1151 int
1152 init_module(void)
1153 {
1154 int err;
1155 int i;
1156
1157 for (i = 0; i < SL_NRUNIT; i++) {
1158 if ((err = register_netdev(&dev_slip[i]))) {
1159 if (err == -EEXIST) {
1160 printk("SLIP: devices already present. Module not loaded.\n");
1161 }
1162 return err;
1163 }
1164 }
1165 return 0;
1166 }
1167
1168 void
1169 cleanup_module(void)
1170 {
1171 int i;
1172
1173 if (MOD_IN_USE) {
1174 printk("SLIP: device busy, remove delayed\n");
1175 return;
1176 }
1177 for (i = 0; i < SL_NRUNIT; i++) {
1178 unregister_netdev(&dev_slip[i]);
1179 }
1180 if ((i = tty_register_ldisc(N_SLIP, NULL))) {
1181 printk("SLIP: can't unregister line discipline (err = %d)\n", i);
1182 }
1183 already = 0;
1184 }
1185 #endif