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