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