1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/sched.h>
17#include <linux/smp_lock.h>
18#include "irnet_ppp.h"
19
20
21
22static struct ppp_channel_ops irnet_ppp_ops = {
23 .start_xmit = ppp_irnet_send,
24 .ioctl = ppp_irnet_ioctl
25};
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44static inline ssize_t
45irnet_ctrl_write(irnet_socket * ap,
46 const char __user *buf,
47 size_t count)
48{
49 char command[IRNET_MAX_COMMAND];
50 char * start;
51 char * next;
52 int length;
53
54 DENTER(CTRL_TRACE, "(ap=0x%p, count=%Zd)\n", ap, count);
55
56
57 DABORT(count >= IRNET_MAX_COMMAND, -ENOMEM,
58 CTRL_ERROR, "Too much data !!!\n");
59
60
61 if(copy_from_user(command, buf, count))
62 {
63 DERROR(CTRL_ERROR, "Invalid user space pointer.\n");
64 return -EFAULT;
65 }
66
67
68 command[count] = '\0';
69 DEBUG(CTRL_INFO, "Command line received is ``%s'' (%Zd).\n",
70 command, count);
71
72
73 next = command;
74 while(next != NULL)
75 {
76
77 start = next;
78
79
80 while(isspace(*start))
81 start++;
82
83
84 next = strchr(start, ',');
85 if(next)
86 {
87 *next = '\0';
88 length = next - start;
89 next++;
90 }
91 else
92 length = strlen(start);
93
94 DEBUG(CTRL_INFO, "Found command ``%s'' (%d).\n", start, length);
95
96
97
98
99
100 if(!strncmp(start, "name", 4))
101 {
102
103 if((length > 5) && (strcmp(start + 5, "any")))
104 {
105
106 while(isspace(start[length - 1]))
107 length--;
108
109
110 memcpy(ap->rname, start + 5, length - 5);
111 ap->rname[length - 5] = '\0';
112 }
113 else
114 ap->rname[0] = '\0';
115 DEBUG(CTRL_INFO, "Got rname = ``%s''\n", ap->rname);
116
117
118 continue;
119 }
120
121
122
123 if((!strncmp(start, "addr", 4)) ||
124 (!strncmp(start, "daddr", 5)) ||
125 (!strncmp(start, "saddr", 5)))
126 {
127 __u32 addr = DEV_ADDR_ANY;
128
129
130 if((length > 5) && (strcmp(start + 5, "any")))
131 {
132 char * begp = start + 5;
133 char * endp;
134
135
136 while(isspace(*begp))
137 begp++;
138
139
140 addr = simple_strtoul(begp, &endp, 16);
141
142 DABORT(endp <= (start + 5), -EINVAL,
143 CTRL_ERROR, "Invalid address.\n");
144 }
145
146 if(start[0] == 's')
147 {
148
149 ap->rsaddr = addr;
150 DEBUG(CTRL_INFO, "Got rsaddr = %08x\n", ap->rsaddr);
151 }
152 else
153 {
154
155 ap->rdaddr = addr;
156 DEBUG(CTRL_INFO, "Got rdaddr = %08x\n", ap->rdaddr);
157 }
158
159
160 continue;
161 }
162
163
164
165
166 DABORT(1, -EINVAL, CTRL_ERROR, "Not a recognised IrNET command.\n");
167 }
168
169
170 return(count);
171}
172
173#ifdef INITIAL_DISCOVERY
174
175
176
177
178
179
180
181
182
183static void
184irnet_get_discovery_log(irnet_socket * ap)
185{
186 __u16 mask = irlmp_service_to_hint(S_LAN);
187
188
189 ap->discoveries = irlmp_get_discoveries(&ap->disco_number, mask,
190 DISCOVERY_DEFAULT_SLOTS);
191
192
193 if(ap->discoveries == NULL)
194 ap->disco_number = -1;
195
196 DEBUG(CTRL_INFO, "Got the log (0x%p), size is %d\n",
197 ap->discoveries, ap->disco_number);
198}
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215static inline int
216irnet_read_discovery_log(irnet_socket * ap,
217 char * event)
218{
219 int done_event = 0;
220
221 DENTER(CTRL_TRACE, "(ap=0x%p, event=0x%p)\n",
222 ap, event);
223
224
225 if(ap->disco_number == -1)
226 {
227 DEBUG(CTRL_INFO, "Already done\n");
228 return 0;
229 }
230
231
232 if(ap->discoveries == NULL)
233 irnet_get_discovery_log(ap);
234
235
236 if(ap->disco_index < ap->disco_number)
237 {
238
239 sprintf(event, "Found %08x (%s) behind %08x {hints %02X-%02X}\n",
240 ap->discoveries[ap->disco_index].daddr,
241 ap->discoveries[ap->disco_index].info,
242 ap->discoveries[ap->disco_index].saddr,
243 ap->discoveries[ap->disco_index].hints[0],
244 ap->discoveries[ap->disco_index].hints[1]);
245 DEBUG(CTRL_INFO, "Writing discovery %d : %s\n",
246 ap->disco_index, ap->discoveries[ap->disco_index].info);
247
248
249 done_event = 1;
250
251 ap->disco_index++;
252 }
253
254
255 if(ap->disco_index >= ap->disco_number)
256 {
257
258 DEBUG(CTRL_INFO, "Cleaning up log (0x%p)\n",
259 ap->discoveries);
260 if(ap->discoveries != NULL)
261 {
262
263 kfree(ap->discoveries);
264 ap->discoveries = NULL;
265 }
266 ap->disco_number = -1;
267 }
268
269 return done_event;
270}
271#endif
272
273
274
275
276
277static inline ssize_t
278irnet_ctrl_read(irnet_socket * ap,
279 struct file * file,
280 char __user * buf,
281 size_t count)
282{
283 DECLARE_WAITQUEUE(wait, current);
284 char event[64];
285 ssize_t ret = 0;
286
287 DENTER(CTRL_TRACE, "(ap=0x%p, count=%Zd)\n", ap, count);
288
289
290 DABORT(count < sizeof(event), -EOVERFLOW, CTRL_ERROR, "Buffer to small.\n");
291
292#ifdef INITIAL_DISCOVERY
293
294 if(irnet_read_discovery_log(ap, event))
295 {
296
297 if(copy_to_user(buf, event, strlen(event)))
298 {
299 DERROR(CTRL_ERROR, "Invalid user space pointer.\n");
300 return -EFAULT;
301 }
302
303 DEXIT(CTRL_TRACE, "\n");
304 return(strlen(event));
305 }
306#endif
307
308
309 add_wait_queue(&irnet_events.rwait, &wait);
310 current->state = TASK_INTERRUPTIBLE;
311 for(;;)
312 {
313
314 ret = 0;
315 if(ap->event_index != irnet_events.index)
316 break;
317 ret = -EAGAIN;
318 if(file->f_flags & O_NONBLOCK)
319 break;
320 ret = -ERESTARTSYS;
321 if(signal_pending(current))
322 break;
323
324 schedule();
325 }
326 current->state = TASK_RUNNING;
327 remove_wait_queue(&irnet_events.rwait, &wait);
328
329
330 if(ret != 0)
331 {
332
333 DEXIT(CTRL_TRACE, " - ret %Zd\n", ret);
334 return ret;
335 }
336
337
338 switch(irnet_events.log[ap->event_index].event)
339 {
340 case IRNET_DISCOVER:
341 sprintf(event, "Discovered %08x (%s) behind %08x {hints %02X-%02X}\n",
342 irnet_events.log[ap->event_index].daddr,
343 irnet_events.log[ap->event_index].name,
344 irnet_events.log[ap->event_index].saddr,
345 irnet_events.log[ap->event_index].hints.byte[0],
346 irnet_events.log[ap->event_index].hints.byte[1]);
347 break;
348 case IRNET_EXPIRE:
349 sprintf(event, "Expired %08x (%s) behind %08x {hints %02X-%02X}\n",
350 irnet_events.log[ap->event_index].daddr,
351 irnet_events.log[ap->event_index].name,
352 irnet_events.log[ap->event_index].saddr,
353 irnet_events.log[ap->event_index].hints.byte[0],
354 irnet_events.log[ap->event_index].hints.byte[1]);
355 break;
356 case IRNET_CONNECT_TO:
357 sprintf(event, "Connected to %08x (%s) on ppp%d\n",
358 irnet_events.log[ap->event_index].daddr,
359 irnet_events.log[ap->event_index].name,
360 irnet_events.log[ap->event_index].unit);
361 break;
362 case IRNET_CONNECT_FROM:
363 sprintf(event, "Connection from %08x (%s) on ppp%d\n",
364 irnet_events.log[ap->event_index].daddr,
365 irnet_events.log[ap->event_index].name,
366 irnet_events.log[ap->event_index].unit);
367 break;
368 case IRNET_REQUEST_FROM:
369 sprintf(event, "Request from %08x (%s) behind %08x\n",
370 irnet_events.log[ap->event_index].daddr,
371 irnet_events.log[ap->event_index].name,
372 irnet_events.log[ap->event_index].saddr);
373 break;
374 case IRNET_NOANSWER_FROM:
375 sprintf(event, "No-answer from %08x (%s) on ppp%d\n",
376 irnet_events.log[ap->event_index].daddr,
377 irnet_events.log[ap->event_index].name,
378 irnet_events.log[ap->event_index].unit);
379 break;
380 case IRNET_BLOCKED_LINK:
381 sprintf(event, "Blocked link with %08x (%s) on ppp%d\n",
382 irnet_events.log[ap->event_index].daddr,
383 irnet_events.log[ap->event_index].name,
384 irnet_events.log[ap->event_index].unit);
385 break;
386 case IRNET_DISCONNECT_FROM:
387 sprintf(event, "Disconnection from %08x (%s) on ppp%d\n",
388 irnet_events.log[ap->event_index].daddr,
389 irnet_events.log[ap->event_index].name,
390 irnet_events.log[ap->event_index].unit);
391 break;
392 case IRNET_DISCONNECT_TO:
393 sprintf(event, "Disconnected to %08x (%s)\n",
394 irnet_events.log[ap->event_index].daddr,
395 irnet_events.log[ap->event_index].name);
396 break;
397 default:
398 sprintf(event, "Bug\n");
399 }
400
401 ap->event_index = (ap->event_index + 1) % IRNET_MAX_EVENTS;
402
403 DEBUG(CTRL_INFO, "Event is :%s", event);
404
405
406 if(copy_to_user(buf, event, strlen(event)))
407 {
408 DERROR(CTRL_ERROR, "Invalid user space pointer.\n");
409 return -EFAULT;
410 }
411
412 DEXIT(CTRL_TRACE, "\n");
413 return(strlen(event));
414}
415
416
417
418
419
420
421static inline unsigned int
422irnet_ctrl_poll(irnet_socket * ap,
423 struct file * file,
424 poll_table * wait)
425{
426 unsigned int mask;
427
428 DENTER(CTRL_TRACE, "(ap=0x%p)\n", ap);
429
430 poll_wait(file, &irnet_events.rwait, wait);
431 mask = POLLOUT | POLLWRNORM;
432
433 if(ap->event_index != irnet_events.index)
434 mask |= POLLIN | POLLRDNORM;
435#ifdef INITIAL_DISCOVERY
436 if(ap->disco_number != -1)
437 {
438
439 if(ap->discoveries == NULL)
440 irnet_get_discovery_log(ap);
441
442 if(ap->disco_number != -1)
443 mask |= POLLIN | POLLRDNORM;
444 }
445#endif
446
447 DEXIT(CTRL_TRACE, " - mask=0x%X\n", mask);
448 return mask;
449}
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465static int
466dev_irnet_open(struct inode * inode,
467 struct file * file)
468{
469 struct irnet_socket * ap;
470 int err;
471
472 DENTER(FS_TRACE, "(file=0x%p)\n", file);
473
474#ifdef SECURE_DEVIRNET
475
476 if(!capable(CAP_NET_ADMIN))
477 return -EPERM;
478#endif
479
480
481 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
482 DABORT(ap == NULL, -ENOMEM, FS_ERROR, "Can't allocate struct irnet...\n");
483
484 lock_kernel();
485
486 ap->file = file;
487
488
489 ap->ppp_open = 0;
490 ap->chan.private = ap;
491 ap->chan.ops = &irnet_ppp_ops;
492 ap->chan.mtu = (2048 - TTP_MAX_HEADER - 2 - PPP_HDRLEN);
493 ap->chan.hdrlen = 2 + TTP_MAX_HEADER;
494
495 ap->mru = (2048 - TTP_MAX_HEADER - 2 - PPP_HDRLEN);
496 ap->xaccm[0] = ~0U;
497 ap->xaccm[3] = 0x60000000U;
498 ap->raccm = ~0U;
499
500
501 err = irda_irnet_create(ap);
502 if(err)
503 {
504 DERROR(FS_ERROR, "Can't setup IrDA link...\n");
505 kfree(ap);
506 unlock_kernel();
507 return err;
508 }
509
510
511 ap->event_index = irnet_events.index;
512
513
514 file->private_data = ap;
515
516 DEXIT(FS_TRACE, " - ap=0x%p\n", ap);
517 unlock_kernel();
518 return 0;
519}
520
521
522
523
524
525
526
527static int
528dev_irnet_close(struct inode * inode,
529 struct file * file)
530{
531 irnet_socket * ap = (struct irnet_socket *) file->private_data;
532
533 DENTER(FS_TRACE, "(file=0x%p, ap=0x%p)\n",
534 file, ap);
535 DABORT(ap == NULL, 0, FS_ERROR, "ap is NULL !!!\n");
536
537
538 file->private_data = NULL;
539
540
541 irda_irnet_destroy(ap);
542
543
544 if(ap->ppp_open)
545 {
546 DERROR(FS_ERROR, "Channel still registered - deregistering !\n");
547 ap->ppp_open = 0;
548 ppp_unregister_channel(&ap->chan);
549 }
550
551 kfree(ap);
552
553 DEXIT(FS_TRACE, "\n");
554 return 0;
555}
556
557
558
559
560
561
562static ssize_t
563dev_irnet_write(struct file * file,
564 const char __user *buf,
565 size_t count,
566 loff_t * ppos)
567{
568 irnet_socket * ap = (struct irnet_socket *) file->private_data;
569
570 DPASS(FS_TRACE, "(file=0x%p, ap=0x%p, count=%Zd)\n",
571 file, ap, count);
572 DABORT(ap == NULL, -ENXIO, FS_ERROR, "ap is NULL !!!\n");
573
574
575 if(ap->ppp_open)
576 return -EAGAIN;
577 else
578 return irnet_ctrl_write(ap, buf, count);
579}
580
581
582
583
584
585
586static ssize_t
587dev_irnet_read(struct file * file,
588 char __user * buf,
589 size_t count,
590 loff_t * ppos)
591{
592 irnet_socket * ap = (struct irnet_socket *) file->private_data;
593
594 DPASS(FS_TRACE, "(file=0x%p, ap=0x%p, count=%Zd)\n",
595 file, ap, count);
596 DABORT(ap == NULL, -ENXIO, FS_ERROR, "ap is NULL !!!\n");
597
598
599 if(ap->ppp_open)
600 return -EAGAIN;
601 else
602 return irnet_ctrl_read(ap, file, buf, count);
603}
604
605
606
607
608
609static unsigned int
610dev_irnet_poll(struct file * file,
611 poll_table * wait)
612{
613 irnet_socket * ap = (struct irnet_socket *) file->private_data;
614 unsigned int mask;
615
616 DENTER(FS_TRACE, "(file=0x%p, ap=0x%p)\n",
617 file, ap);
618
619 mask = POLLOUT | POLLWRNORM;
620 DABORT(ap == NULL, mask, FS_ERROR, "ap is NULL !!!\n");
621
622
623 if(!ap->ppp_open)
624 mask |= irnet_ctrl_poll(ap, file, wait);
625
626 DEXIT(FS_TRACE, " - mask=0x%X\n", mask);
627 return(mask);
628}
629
630
631
632
633
634
635
636static long
637dev_irnet_ioctl(
638 struct file * file,
639 unsigned int cmd,
640 unsigned long arg)
641{
642 irnet_socket * ap = (struct irnet_socket *) file->private_data;
643 int err;
644 int val;
645 void __user *argp = (void __user *)arg;
646
647 DENTER(FS_TRACE, "(file=0x%p, ap=0x%p, cmd=0x%X)\n",
648 file, ap, cmd);
649
650
651 DASSERT(ap != NULL, -ENXIO, PPP_ERROR, "ap is NULL...\n");
652#ifdef SECURE_DEVIRNET
653 if(!capable(CAP_NET_ADMIN))
654 return -EPERM;
655#endif
656
657 err = -EFAULT;
658 switch(cmd)
659 {
660
661 case TIOCSETD:
662 if(get_user(val, (int __user *)argp))
663 break;
664 if((val == N_SYNC_PPP) || (val == N_PPP))
665 {
666 DEBUG(FS_INFO, "Entering PPP discipline.\n");
667
668 lock_kernel();
669 err = ppp_register_channel(&ap->chan);
670 if(err == 0)
671 {
672
673 ap->ppp_open = 1;
674
675 DEBUG(FS_INFO, "Trying to establish a connection.\n");
676
677 irda_irnet_connect(ap);
678 }
679 else
680 DERROR(FS_ERROR, "Can't setup PPP channel...\n");
681 unlock_kernel();
682 }
683 else
684 {
685
686 DEBUG(FS_INFO, "Exiting PPP discipline.\n");
687
688 lock_kernel();
689 if(ap->ppp_open)
690 {
691 ap->ppp_open = 0;
692 ppp_unregister_channel(&ap->chan);
693 }
694 else
695 DERROR(FS_ERROR, "Channel not registered !\n");
696 err = 0;
697 unlock_kernel();
698 }
699 break;
700
701
702 case PPPIOCGCHAN:
703 if(ap->ppp_open && !put_user(ppp_channel_index(&ap->chan),
704 (int __user *)argp))
705 err = 0;
706 break;
707 case PPPIOCGUNIT:
708 lock_kernel();
709 if(ap->ppp_open && !put_user(ppp_unit_number(&ap->chan),
710 (int __user *)argp))
711 err = 0;
712 break;
713
714
715
716
717 case PPPIOCGFLAGS:
718 case PPPIOCSFLAGS:
719 case PPPIOCGASYNCMAP:
720 case PPPIOCSASYNCMAP:
721 case PPPIOCGRASYNCMAP:
722 case PPPIOCSRASYNCMAP:
723 case PPPIOCGXASYNCMAP:
724 case PPPIOCSXASYNCMAP:
725 case PPPIOCGMRU:
726 case PPPIOCSMRU:
727 DEBUG(FS_INFO, "Standard PPP ioctl.\n");
728 if(!capable(CAP_NET_ADMIN))
729 err = -EPERM;
730 else {
731 lock_kernel();
732 err = ppp_irnet_ioctl(&ap->chan, cmd, arg);
733 unlock_kernel();
734 }
735 break;
736
737
738
739 case TCGETS:
740 DEBUG(FS_INFO, "Get termios.\n");
741 lock_kernel();
742#ifndef TCGETS2
743 if(!kernel_termios_to_user_termios((struct termios __user *)argp, &ap->termios))
744 err = 0;
745#else
746 if(kernel_termios_to_user_termios_1((struct termios __user *)argp, &ap->termios))
747 err = 0;
748#endif
749 unlock_kernel();
750 break;
751
752 case TCSETSF:
753 DEBUG(FS_INFO, "Set termios.\n");
754 lock_kernel();
755#ifndef TCGETS2
756 if(!user_termios_to_kernel_termios(&ap->termios, (struct termios __user *)argp))
757 err = 0;
758#else
759 if(!user_termios_to_kernel_termios_1(&ap->termios, (struct termios __user *)argp))
760 err = 0;
761#endif
762 unlock_kernel();
763 break;
764
765
766 case TIOCMBIS:
767 case TIOCMBIC:
768
769 case TIOCEXCL:
770 case TIOCNXCL:
771 DEBUG(FS_INFO, "TTY compatibility.\n");
772 err = 0;
773 break;
774
775 case TCGETA:
776 DEBUG(FS_INFO, "TCGETA\n");
777 break;
778
779 case TCFLSH:
780 DEBUG(FS_INFO, "TCFLSH\n");
781
782
783
784#ifdef FLUSH_TO_PPP
785 lock_kernel();
786 ppp_output_wakeup(&ap->chan);
787 unlock_kernel();
788#endif
789 err = 0;
790 break;
791
792 case FIONREAD:
793 DEBUG(FS_INFO, "FIONREAD\n");
794 val = 0;
795 if(put_user(val, (int __user *)argp))
796 break;
797 err = 0;
798 break;
799
800 default:
801 DERROR(FS_ERROR, "Unsupported ioctl (0x%X)\n", cmd);
802 err = -ENOTTY;
803 }
804
805 DEXIT(FS_TRACE, " - err = 0x%X\n", err);
806 return err;
807}
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822static inline struct sk_buff *
823irnet_prepare_skb(irnet_socket * ap,
824 struct sk_buff * skb)
825{
826 unsigned char * data;
827 int proto;
828 int islcp;
829 int needaddr;
830
831 DENTER(PPP_TRACE, "(ap=0x%p, skb=0x%p)\n",
832 ap, skb);
833
834
835 data = skb->data;
836 proto = (data[0] << 8) + data[1];
837
838
839
840
841 islcp = (proto == PPP_LCP) && (1 <= data[2]) && (data[2] <= 7);
842
843
844 if((data[0] == 0) && (ap->flags & SC_COMP_PROT) && (!islcp))
845 skb_pull(skb,1);
846
847
848 needaddr = 2*((ap->flags & SC_COMP_AC) == 0 || islcp);
849
850
851 if((skb_headroom(skb) < (ap->max_header_size + needaddr)) ||
852 (skb_shared(skb)))
853 {
854 struct sk_buff * new_skb;
855
856 DEBUG(PPP_INFO, "Reallocating skb\n");
857
858
859 new_skb = skb_realloc_headroom(skb, ap->max_header_size + needaddr);
860
861
862 dev_kfree_skb(skb);
863
864
865 DABORT(new_skb == NULL, NULL, PPP_ERROR, "Could not realloc skb\n");
866
867
868 skb = new_skb;
869 }
870
871
872 if(needaddr)
873 {
874 skb_push(skb, 2);
875 skb->data[0] = PPP_ALLSTATIONS;
876 skb->data[1] = PPP_UI;
877 }
878
879 DEXIT(PPP_TRACE, "\n");
880
881 return skb;
882}
883
884
885
886
887
888
889
890
891
892static int
893ppp_irnet_send(struct ppp_channel * chan,
894 struct sk_buff * skb)
895{
896 irnet_socket * self = (struct irnet_socket *) chan->private;
897 int ret;
898
899 DENTER(PPP_TRACE, "(channel=0x%p, ap/self=0x%p)\n",
900 chan, self);
901
902
903 DASSERT(self != NULL, 0, PPP_ERROR, "Self is NULL !!!\n");
904
905
906 if(!(test_bit(0, &self->ttp_open)))
907 {
908#ifdef CONNECT_IN_SEND
909
910
911
912
913 irda_irnet_connect(self);
914#endif
915
916 DEBUG(PPP_INFO, "IrTTP not ready ! (%ld-%ld)\n",
917 self->ttp_open, self->ttp_connect);
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938#ifdef BLOCK_WHEN_CONNECT
939
940 if(test_bit(0, &self->ttp_connect))
941 {
942
943 return 0;
944 }
945#endif
946
947
948 dev_kfree_skb(skb);
949 return 1;
950 }
951
952
953 if(self->tx_flow != FLOW_START)
954 DRETURN(0, PPP_INFO, "IrTTP queue full (%d skbs)...\n",
955 skb_queue_len(&self->tsap->tx_queue));
956
957
958 skb = irnet_prepare_skb(self, skb);
959 DABORT(skb == NULL, 1, PPP_ERROR, "Prepare skb for Tx failed.\n");
960
961
962 ret = irttp_data_request(self->tsap, skb);
963 if(ret < 0)
964 {
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980 DERROR(PPP_ERROR, "IrTTP doesn't like this packet !!! (0x%X)\n", ret);
981
982 }
983
984 DEXIT(PPP_TRACE, "\n");
985 return 1;
986}
987
988
989
990
991
992
993static int
994ppp_irnet_ioctl(struct ppp_channel * chan,
995 unsigned int cmd,
996 unsigned long arg)
997{
998 irnet_socket * ap = (struct irnet_socket *) chan->private;
999 int err;
1000 int val;
1001 u32 accm[8];
1002 void __user *argp = (void __user *)arg;
1003
1004 DENTER(PPP_TRACE, "(channel=0x%p, ap=0x%p, cmd=0x%X)\n",
1005 chan, ap, cmd);
1006
1007
1008 DASSERT(ap != NULL, -ENXIO, PPP_ERROR, "ap is NULL...\n");
1009
1010 err = -EFAULT;
1011 switch(cmd)
1012 {
1013
1014 case PPPIOCGFLAGS:
1015 val = ap->flags | ap->rbits;
1016 if(put_user(val, (int __user *) argp))
1017 break;
1018 err = 0;
1019 break;
1020 case PPPIOCSFLAGS:
1021 if(get_user(val, (int __user *) argp))
1022 break;
1023 ap->flags = val & ~SC_RCV_BITS;
1024 ap->rbits = val & SC_RCV_BITS;
1025 err = 0;
1026 break;
1027
1028
1029 case PPPIOCGASYNCMAP:
1030 if(put_user(ap->xaccm[0], (u32 __user *) argp))
1031 break;
1032 err = 0;
1033 break;
1034 case PPPIOCSASYNCMAP:
1035 if(get_user(ap->xaccm[0], (u32 __user *) argp))
1036 break;
1037 err = 0;
1038 break;
1039 case PPPIOCGRASYNCMAP:
1040 if(put_user(ap->raccm, (u32 __user *) argp))
1041 break;
1042 err = 0;
1043 break;
1044 case PPPIOCSRASYNCMAP:
1045 if(get_user(ap->raccm, (u32 __user *) argp))
1046 break;
1047 err = 0;
1048 break;
1049 case PPPIOCGXASYNCMAP:
1050 if(copy_to_user(argp, ap->xaccm, sizeof(ap->xaccm)))
1051 break;
1052 err = 0;
1053 break;
1054 case PPPIOCSXASYNCMAP:
1055 if(copy_from_user(accm, argp, sizeof(accm)))
1056 break;
1057 accm[2] &= ~0x40000000U;
1058 accm[3] |= 0x60000000U;
1059 memcpy(ap->xaccm, accm, sizeof(ap->xaccm));
1060 err = 0;
1061 break;
1062
1063
1064 case PPPIOCGMRU:
1065 if(put_user(ap->mru, (int __user *) argp))
1066 break;
1067 err = 0;
1068 break;
1069 case PPPIOCSMRU:
1070 if(get_user(val, (int __user *) argp))
1071 break;
1072 if(val < PPP_MRU)
1073 val = PPP_MRU;
1074 ap->mru = val;
1075 err = 0;
1076 break;
1077
1078 default:
1079 DEBUG(PPP_INFO, "Unsupported ioctl (0x%X)\n", cmd);
1080 err = -ENOIOCTLCMD;
1081 }
1082
1083 DEXIT(PPP_TRACE, " - err = 0x%X\n", err);
1084 return err;
1085}
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097static inline int __init
1098ppp_irnet_init(void)
1099{
1100 int err = 0;
1101
1102 DENTER(MODULE_TRACE, "()\n");
1103
1104
1105 err = misc_register(&irnet_misc_device);
1106
1107 DEXIT(MODULE_TRACE, "\n");
1108 return err;
1109}
1110
1111
1112
1113
1114
1115static inline void __exit
1116ppp_irnet_cleanup(void)
1117{
1118 DENTER(MODULE_TRACE, "()\n");
1119
1120
1121 misc_deregister(&irnet_misc_device);
1122
1123 DEXIT(MODULE_TRACE, "\n");
1124}
1125
1126
1127
1128
1129
1130static int __init
1131irnet_init(void)
1132{
1133 int err;
1134
1135
1136 err = irda_irnet_init();
1137 if(!err)
1138 err = ppp_irnet_init();
1139 return err;
1140}
1141
1142
1143
1144
1145
1146static void __exit
1147irnet_cleanup(void)
1148{
1149 irda_irnet_cleanup();
1150 ppp_irnet_cleanup();
1151}
1152
1153
1154
1155
1156
1157module_init(irnet_init);
1158module_exit(irnet_cleanup);
1159MODULE_AUTHOR("Jean Tourrilhes <jt@hpl.hp.com>");
1160MODULE_DESCRIPTION("IrNET : Synchronous PPP over IrDA");
1161MODULE_LICENSE("GPL");
1162MODULE_ALIAS_CHARDEV(10, 187);
1163