2 * IrNET protocol module : Synchronous PPP over an IrDA socket.
4 * Jean II - HPL `00 - <jt@hpl.hp.com>
6 * This file implement the PPP interface and /dev/irnet character device.
7 * The PPP interface hook to the ppp_generic module, handle all our
8 * relationship to the PPP code in the kernel (and by extension to pppd),
9 * and exchange PPP frames with this module (send/receive).
10 * The /dev/irnet device is used primarily for 2 functions :
11 * 1) as a stub for pppd (the ppp daemon), so that we can appropriately
12 * generate PPP sessions (we pretend we are a tty).
13 * 2) as a control channel (write commands, read events)
16 #include "irnet_ppp.h" /* Private header */
17 /* Please put other headers in irnet.h - Thanks */
19 /* Generic PPP callbacks (to call us) */
20 static struct ppp_channel_ops irnet_ppp_ops
= {
21 .start_xmit
= ppp_irnet_send
,
22 .ioctl
= ppp_irnet_ioctl
25 /************************* CONTROL CHANNEL *************************/
27 * When a pppd instance is not active on /dev/irnet, it acts as a control
29 * Writing allow to set up the IrDA destination of the IrNET channel,
30 * and any application may be read events happening in IrNET...
33 /*------------------------------------------------------------------*/
35 * Write is used to send a command to configure a IrNET channel
36 * before it is open by pppd. The syntax is : "command argument"
37 * Currently there is only two defined commands :
38 * o name : set the requested IrDA nickname of the IrNET peer.
39 * o addr : set the requested IrDA address of the IrNET peer.
40 * Note : the code is crude, but effective...
43 irnet_ctrl_write(irnet_socket
* ap
,
44 const char __user
*buf
,
47 char command
[IRNET_MAX_COMMAND
];
48 char * start
; /* Current command being processed */
49 char * next
; /* Next command to process */
50 int length
; /* Length of current command */
52 DENTER(CTRL_TRACE
, "(ap=0x%p, count=%Zd)\n", ap
, count
);
54 /* Check for overflow... */
55 DABORT(count
>= IRNET_MAX_COMMAND
, -ENOMEM
,
56 CTRL_ERROR
, "Too much data !!!\n");
58 /* Get the data in the driver */
59 if(copy_from_user(command
, buf
, count
))
61 DERROR(CTRL_ERROR
, "Invalid user space pointer.\n");
65 /* Safe terminate the string */
66 command
[count
] = '\0';
67 DEBUG(CTRL_INFO
, "Command line received is ``%s'' (%Zd).\n",
70 /* Check every commands in the command line */
74 /* Look at the next command */
77 /* Scrap whitespaces before the command */
78 while(isspace(*start
))
81 /* ',' is our command separator */
82 next
= strchr(start
, ',');
85 *next
= '\0'; /* Terminate command */
86 length
= next
- start
; /* Length */
87 next
++; /* Skip the '\0' */
90 length
= strlen(start
);
92 DEBUG(CTRL_INFO
, "Found command ``%s'' (%d).\n", start
, length
);
94 /* Check if we recognised one of the known command
95 * We can't use "switch" with strings, so hack with "continue" */
97 /* First command : name -> Requested IrDA nickname */
98 if(!strncmp(start
, "name", 4))
100 /* Copy the name only if is included and not "any" */
101 if((length
> 5) && (strcmp(start
+ 5, "any")))
103 /* Strip out trailing whitespaces */
104 while(isspace(start
[length
- 1]))
107 /* Copy the name for later reuse */
108 memcpy(ap
->rname
, start
+ 5, length
- 5);
109 ap
->rname
[length
- 5] = '\0';
113 DEBUG(CTRL_INFO
, "Got rname = ``%s''\n", ap
->rname
);
115 /* Restart the loop */
119 /* Second command : addr, daddr -> Requested IrDA destination address
120 * Also process : saddr -> Requested IrDA source address */
121 if((!strncmp(start
, "addr", 4)) ||
122 (!strncmp(start
, "daddr", 5)) ||
123 (!strncmp(start
, "saddr", 5)))
125 __u32 addr
= DEV_ADDR_ANY
;
127 /* Copy the address only if is included and not "any" */
128 if((length
> 5) && (strcmp(start
+ 5, "any")))
130 char * begp
= start
+ 5;
133 /* Scrap whitespaces before the command */
134 while(isspace(*begp
))
137 /* Convert argument to a number (last arg is the base) */
138 addr
= simple_strtoul(begp
, &endp
, 16);
139 /* Has it worked ? (endp should be start + length) */
140 DABORT(endp
<= (start
+ 5), -EINVAL
,
141 CTRL_ERROR
, "Invalid address.\n");
143 /* Which type of address ? */
148 DEBUG(CTRL_INFO
, "Got rsaddr = %08x\n", ap
->rsaddr
);
154 DEBUG(CTRL_INFO
, "Got rdaddr = %08x\n", ap
->rdaddr
);
157 /* Restart the loop */
161 /* Other possible command : connect N (number of retries) */
163 /* No command matched -> Failed... */
164 DABORT(1, -EINVAL
, CTRL_ERROR
, "Not a recognised IrNET command.\n");
167 /* Success : we have parsed all commands successfully */
171 #ifdef INITIAL_DISCOVERY
172 /*------------------------------------------------------------------*/
174 * Function irnet_get_discovery_log (self)
176 * Query the content on the discovery log if not done
178 * This function query the current content of the discovery log
179 * at the startup of the event channel and save it in the internal struct.
182 irnet_get_discovery_log(irnet_socket
* ap
)
184 __u16 mask
= irlmp_service_to_hint(S_LAN
);
186 /* Ask IrLMP for the current discovery log */
187 ap
->discoveries
= irlmp_get_discoveries(&ap
->disco_number
, mask
,
188 DISCOVERY_DEFAULT_SLOTS
);
190 /* Check if the we got some results */
191 if(ap
->discoveries
== NULL
)
192 ap
->disco_number
= -1;
194 DEBUG(CTRL_INFO
, "Got the log (0x%p), size is %d\n",
195 ap
->discoveries
, ap
->disco_number
);
198 /*------------------------------------------------------------------*/
200 * Function irnet_read_discovery_log (self, event)
202 * Read the content on the discovery log
204 * This function dump the current content of the discovery log
205 * at the startup of the event channel.
206 * Return 1 if wrote an event on the control channel...
208 * State of the ap->disco_XXX variables :
209 * Socket creation : discoveries = NULL ; disco_index = 0 ; disco_number = 0
210 * While reading : discoveries = ptr ; disco_index = X ; disco_number = Y
211 * After reading : discoveries = NULL ; disco_index = Y ; disco_number = -1
214 irnet_read_discovery_log(irnet_socket
* ap
,
219 DENTER(CTRL_TRACE
, "(ap=0x%p, event=0x%p)\n",
222 /* Test if we have some work to do or we have already finished */
223 if(ap
->disco_number
== -1)
225 DEBUG(CTRL_INFO
, "Already done\n");
229 /* Test if it's the first time and therefore we need to get the log */
230 if(ap
->discoveries
== NULL
)
231 irnet_get_discovery_log(ap
);
233 /* Check if we have more item to dump */
234 if(ap
->disco_index
< ap
->disco_number
)
237 sprintf(event
, "Found %08x (%s) behind %08x {hints %02X-%02X}\n",
238 ap
->discoveries
[ap
->disco_index
].daddr
,
239 ap
->discoveries
[ap
->disco_index
].info
,
240 ap
->discoveries
[ap
->disco_index
].saddr
,
241 ap
->discoveries
[ap
->disco_index
].hints
[0],
242 ap
->discoveries
[ap
->disco_index
].hints
[1]);
243 DEBUG(CTRL_INFO
, "Writing discovery %d : %s\n",
244 ap
->disco_index
, ap
->discoveries
[ap
->disco_index
].info
);
246 /* We have an event */
252 /* Check if we have done the last item */
253 if(ap
->disco_index
>= ap
->disco_number
)
255 /* No more items : remove the log and signal termination */
256 DEBUG(CTRL_INFO
, "Cleaning up log (0x%p)\n",
258 if(ap
->discoveries
!= NULL
)
260 /* Cleanup our copy of the discovery log */
261 kfree(ap
->discoveries
);
262 ap
->discoveries
= NULL
;
264 ap
->disco_number
= -1;
269 #endif /* INITIAL_DISCOVERY */
271 /*------------------------------------------------------------------*/
273 * Read is used to get IrNET events
275 static inline ssize_t
276 irnet_ctrl_read(irnet_socket
* ap
,
281 DECLARE_WAITQUEUE(wait
, current
);
282 char event
[64]; /* Max event is 61 char */
285 DENTER(CTRL_TRACE
, "(ap=0x%p, count=%Zd)\n", ap
, count
);
287 /* Check if we can write an event out in one go */
288 DABORT(count
< sizeof(event
), -EOVERFLOW
, CTRL_ERROR
, "Buffer to small.\n");
290 #ifdef INITIAL_DISCOVERY
291 /* Check if we have read the log */
292 if(irnet_read_discovery_log(ap
, event
))
294 /* We have an event !!! Copy it to the user */
295 if(copy_to_user(buf
, event
, strlen(event
)))
297 DERROR(CTRL_ERROR
, "Invalid user space pointer.\n");
301 DEXIT(CTRL_TRACE
, "\n");
302 return(strlen(event
));
304 #endif /* INITIAL_DISCOVERY */
306 /* Put ourselves on the wait queue to be woken up */
307 add_wait_queue(&irnet_events
.rwait
, &wait
);
308 current
->state
= TASK_INTERRUPTIBLE
;
311 /* If there is unread events */
313 if(ap
->event_index
!= irnet_events
.index
)
316 if(file
->f_flags
& O_NONBLOCK
)
319 if(signal_pending(current
))
321 /* Yield and wait to be woken up */
324 current
->state
= TASK_RUNNING
;
325 remove_wait_queue(&irnet_events
.rwait
, &wait
);
327 /* Did we got it ? */
330 /* No, return the error code */
331 DEXIT(CTRL_TRACE
, " - ret %Zd\n", ret
);
335 /* Which event is it ? */
336 switch(irnet_events
.log
[ap
->event_index
].event
)
339 sprintf(event
, "Discovered %08x (%s) behind %08x {hints %02X-%02X}\n",
340 irnet_events
.log
[ap
->event_index
].daddr
,
341 irnet_events
.log
[ap
->event_index
].name
,
342 irnet_events
.log
[ap
->event_index
].saddr
,
343 irnet_events
.log
[ap
->event_index
].hints
.byte
[0],
344 irnet_events
.log
[ap
->event_index
].hints
.byte
[1]);
347 sprintf(event
, "Expired %08x (%s) behind %08x {hints %02X-%02X}\n",
348 irnet_events
.log
[ap
->event_index
].daddr
,
349 irnet_events
.log
[ap
->event_index
].name
,
350 irnet_events
.log
[ap
->event_index
].saddr
,
351 irnet_events
.log
[ap
->event_index
].hints
.byte
[0],
352 irnet_events
.log
[ap
->event_index
].hints
.byte
[1]);
354 case IRNET_CONNECT_TO
:
355 sprintf(event
, "Connected to %08x (%s) on ppp%d\n",
356 irnet_events
.log
[ap
->event_index
].daddr
,
357 irnet_events
.log
[ap
->event_index
].name
,
358 irnet_events
.log
[ap
->event_index
].unit
);
360 case IRNET_CONNECT_FROM
:
361 sprintf(event
, "Connection from %08x (%s) on ppp%d\n",
362 irnet_events
.log
[ap
->event_index
].daddr
,
363 irnet_events
.log
[ap
->event_index
].name
,
364 irnet_events
.log
[ap
->event_index
].unit
);
366 case IRNET_REQUEST_FROM
:
367 sprintf(event
, "Request from %08x (%s) behind %08x\n",
368 irnet_events
.log
[ap
->event_index
].daddr
,
369 irnet_events
.log
[ap
->event_index
].name
,
370 irnet_events
.log
[ap
->event_index
].saddr
);
372 case IRNET_NOANSWER_FROM
:
373 sprintf(event
, "No-answer from %08x (%s) on ppp%d\n",
374 irnet_events
.log
[ap
->event_index
].daddr
,
375 irnet_events
.log
[ap
->event_index
].name
,
376 irnet_events
.log
[ap
->event_index
].unit
);
378 case IRNET_BLOCKED_LINK
:
379 sprintf(event
, "Blocked link with %08x (%s) on ppp%d\n",
380 irnet_events
.log
[ap
->event_index
].daddr
,
381 irnet_events
.log
[ap
->event_index
].name
,
382 irnet_events
.log
[ap
->event_index
].unit
);
384 case IRNET_DISCONNECT_FROM
:
385 sprintf(event
, "Disconnection from %08x (%s) on ppp%d\n",
386 irnet_events
.log
[ap
->event_index
].daddr
,
387 irnet_events
.log
[ap
->event_index
].name
,
388 irnet_events
.log
[ap
->event_index
].unit
);
390 case IRNET_DISCONNECT_TO
:
391 sprintf(event
, "Disconnected to %08x (%s)\n",
392 irnet_events
.log
[ap
->event_index
].daddr
,
393 irnet_events
.log
[ap
->event_index
].name
);
396 sprintf(event
, "Bug\n");
398 /* Increment our event index */
399 ap
->event_index
= (ap
->event_index
+ 1) % IRNET_MAX_EVENTS
;
401 DEBUG(CTRL_INFO
, "Event is :%s", event
);
403 /* Copy it to the user */
404 if(copy_to_user(buf
, event
, strlen(event
)))
406 DERROR(CTRL_ERROR
, "Invalid user space pointer.\n");
410 DEXIT(CTRL_TRACE
, "\n");
411 return(strlen(event
));
414 /*------------------------------------------------------------------*/
416 * Poll : called when someone do a select on /dev/irnet.
417 * Just check if there are new events...
419 static inline unsigned int
420 irnet_ctrl_poll(irnet_socket
* ap
,
426 DENTER(CTRL_TRACE
, "(ap=0x%p)\n", ap
);
428 poll_wait(file
, &irnet_events
.rwait
, wait
);
429 mask
= POLLOUT
| POLLWRNORM
;
430 /* If there is unread events */
431 if(ap
->event_index
!= irnet_events
.index
)
432 mask
|= POLLIN
| POLLRDNORM
;
433 #ifdef INITIAL_DISCOVERY
434 if(ap
->disco_number
!= -1)
436 /* Test if it's the first time and therefore we need to get the log */
437 if(ap
->discoveries
== NULL
)
438 irnet_get_discovery_log(ap
);
440 if(ap
->disco_number
!= -1)
441 mask
|= POLLIN
| POLLRDNORM
;
443 #endif /* INITIAL_DISCOVERY */
445 DEXIT(CTRL_TRACE
, " - mask=0x%X\n", mask
);
450 /*********************** FILESYSTEM CALLBACKS ***********************/
452 * Implement the usual open, read, write functions that will be called
453 * by the file system when some action is performed on /dev/irnet.
454 * Most of those actions will in fact be performed by "pppd" or
455 * the control channel, we just act as a redirector...
458 /*------------------------------------------------------------------*/
460 * Open : when somebody open /dev/irnet
461 * We basically create a new instance of irnet and initialise it.
464 dev_irnet_open(struct inode
* inode
,
467 struct irnet_socket
* ap
;
470 DENTER(FS_TRACE
, "(file=0x%p)\n", file
);
472 #ifdef SECURE_DEVIRNET
473 /* This could (should?) be enforced by the permissions on /dev/irnet. */
474 if(!capable(CAP_NET_ADMIN
))
476 #endif /* SECURE_DEVIRNET */
478 /* Allocate a private structure for this IrNET instance */
479 ap
= kzalloc(sizeof(*ap
), GFP_KERNEL
);
480 DABORT(ap
== NULL
, -ENOMEM
, FS_ERROR
, "Can't allocate struct irnet...\n");
482 /* initialize the irnet structure */
485 /* PPP channel setup */
487 ap
->chan
.private = ap
;
488 ap
->chan
.ops
= &irnet_ppp_ops
;
489 ap
->chan
.mtu
= (2048 - TTP_MAX_HEADER
- 2 - PPP_HDRLEN
);
490 ap
->chan
.hdrlen
= 2 + TTP_MAX_HEADER
; /* for A/C + Max IrDA hdr */
492 ap
->mru
= (2048 - TTP_MAX_HEADER
- 2 - PPP_HDRLEN
);
494 ap
->xaccm
[3] = 0x60000000U
;
497 /* Setup the IrDA part... */
498 err
= irda_irnet_create(ap
);
501 DERROR(FS_ERROR
, "Can't setup IrDA link...\n");
506 /* For the control channel */
507 ap
->event_index
= irnet_events
.index
; /* Cancel all past events */
509 /* Put our stuff where we will be able to find it later */
510 file
->private_data
= ap
;
512 DEXIT(FS_TRACE
, " - ap=0x%p\n", ap
);
517 /*------------------------------------------------------------------*/
519 * Close : when somebody close /dev/irnet
520 * Destroy the instance of /dev/irnet
523 dev_irnet_close(struct inode
* inode
,
526 irnet_socket
* ap
= (struct irnet_socket
*) file
->private_data
;
528 DENTER(FS_TRACE
, "(file=0x%p, ap=0x%p)\n",
530 DABORT(ap
== NULL
, 0, FS_ERROR
, "ap is NULL !!!\n");
532 /* Detach ourselves */
533 file
->private_data
= NULL
;
535 /* Close IrDA stuff */
536 irda_irnet_destroy(ap
);
538 /* Disconnect from the generic PPP layer if not already done */
541 DERROR(FS_ERROR
, "Channel still registered - deregistering !\n");
543 ppp_unregister_channel(&ap
->chan
);
548 DEXIT(FS_TRACE
, "\n");
552 /*------------------------------------------------------------------*/
554 * Write does nothing.
555 * (we receive packet from ppp_generic through ppp_irnet_send())
558 dev_irnet_write(struct file
* file
,
559 const char __user
*buf
,
563 irnet_socket
* ap
= (struct irnet_socket
*) file
->private_data
;
565 DPASS(FS_TRACE
, "(file=0x%p, ap=0x%p, count=%Zd)\n",
567 DABORT(ap
== NULL
, -ENXIO
, FS_ERROR
, "ap is NULL !!!\n");
569 /* If we are connected to ppp_generic, let it handle the job */
573 return irnet_ctrl_write(ap
, buf
, count
);
576 /*------------------------------------------------------------------*/
578 * Read doesn't do much either.
579 * (pppd poll us, but ultimately reads through /dev/ppp)
582 dev_irnet_read(struct file
* file
,
587 irnet_socket
* ap
= (struct irnet_socket
*) file
->private_data
;
589 DPASS(FS_TRACE
, "(file=0x%p, ap=0x%p, count=%Zd)\n",
591 DABORT(ap
== NULL
, -ENXIO
, FS_ERROR
, "ap is NULL !!!\n");
593 /* If we are connected to ppp_generic, let it handle the job */
597 return irnet_ctrl_read(ap
, file
, buf
, count
);
600 /*------------------------------------------------------------------*/
602 * Poll : called when someone do a select on /dev/irnet
605 dev_irnet_poll(struct file
* file
,
608 irnet_socket
* ap
= (struct irnet_socket
*) file
->private_data
;
611 DENTER(FS_TRACE
, "(file=0x%p, ap=0x%p)\n",
614 mask
= POLLOUT
| POLLWRNORM
;
615 DABORT(ap
== NULL
, mask
, FS_ERROR
, "ap is NULL !!!\n");
617 /* If we are connected to ppp_generic, let it handle the job */
619 mask
|= irnet_ctrl_poll(ap
, file
, wait
);
621 DEXIT(FS_TRACE
, " - mask=0x%X\n", mask
);
625 /*------------------------------------------------------------------*/
627 * IOCtl : Called when someone does some ioctls on /dev/irnet
628 * This is the way pppd configure us and control us while the PPP
629 * instance is active.
632 dev_irnet_ioctl(struct inode
* inode
,
637 irnet_socket
* ap
= (struct irnet_socket
*) file
->private_data
;
640 void __user
*argp
= (void __user
*)arg
;
642 DENTER(FS_TRACE
, "(file=0x%p, ap=0x%p, cmd=0x%X)\n",
645 /* Basic checks... */
646 DASSERT(ap
!= NULL
, -ENXIO
, PPP_ERROR
, "ap is NULL...\n");
647 #ifdef SECURE_DEVIRNET
648 if(!capable(CAP_NET_ADMIN
))
650 #endif /* SECURE_DEVIRNET */
655 /* Set discipline (should be N_SYNC_PPP or N_TTY) */
657 if(get_user(val
, (int __user
*)argp
))
659 if((val
== N_SYNC_PPP
) || (val
== N_PPP
))
661 DEBUG(FS_INFO
, "Entering PPP discipline.\n");
662 /* PPP channel setup (ap->chan in configued in dev_irnet_open())*/
663 err
= ppp_register_channel(&ap
->chan
);
666 /* Our ppp side is active */
669 DEBUG(FS_INFO
, "Trying to establish a connection.\n");
670 /* Setup the IrDA link now - may fail... */
671 irda_irnet_connect(ap
);
674 DERROR(FS_ERROR
, "Can't setup PPP channel...\n");
678 /* In theory, should be N_TTY */
679 DEBUG(FS_INFO
, "Exiting PPP discipline.\n");
680 /* Disconnect from the generic PPP layer */
684 ppp_unregister_channel(&ap
->chan
);
687 DERROR(FS_ERROR
, "Channel not registered !\n");
692 /* Query PPP channel and unit number */
696 if(put_user(ppp_channel_index(&ap
->chan
), (int __user
*)argp
))
698 DEBUG(FS_INFO
, "Query channel.\n");
704 if(put_user(ppp_unit_number(&ap
->chan
), (int __user
*)argp
))
706 DEBUG(FS_INFO
, "Query unit number.\n");
710 /* All these ioctls can be passed both directly and from ppp_generic,
711 * so we just deal with them in one place...
715 case PPPIOCGASYNCMAP
:
716 case PPPIOCSASYNCMAP
:
717 case PPPIOCGRASYNCMAP
:
718 case PPPIOCSRASYNCMAP
:
719 case PPPIOCGXASYNCMAP
:
720 case PPPIOCSXASYNCMAP
:
723 DEBUG(FS_INFO
, "Standard PPP ioctl.\n");
724 if(!capable(CAP_NET_ADMIN
))
727 err
= ppp_irnet_ioctl(&ap
->chan
, cmd
, arg
);
730 /* TTY IOCTLs : Pretend that we are a tty, to keep pppd happy */
733 DEBUG(FS_INFO
, "Get termios.\n");
734 if(kernel_termios_to_user_termios((struct termios __user
*)argp
, &ap
->termios
))
740 DEBUG(FS_INFO
, "Set termios.\n");
741 if(user_termios_to_kernel_termios(&ap
->termios
, (struct termios __user
*)argp
))
749 /* Set exclusive/non-exclusive mode */
752 DEBUG(FS_INFO
, "TTY compatibility.\n");
757 DEBUG(FS_INFO
, "TCGETA\n");
761 DEBUG(FS_INFO
, "TCFLSH\n");
762 /* Note : this will flush buffers in PPP, so it *must* be done
763 * We should also worry that we don't accept junk here and that
764 * we get rid of our own buffers */
766 ppp_output_wakeup(&ap
->chan
);
767 #endif /* FLUSH_TO_PPP */
772 DEBUG(FS_INFO
, "FIONREAD\n");
774 if(put_user(val
, (int __user
*)argp
))
780 DERROR(FS_ERROR
, "Unsupported ioctl (0x%X)\n", cmd
);
784 DEXIT(FS_TRACE
, " - err = 0x%X\n", err
);
788 /************************** PPP CALLBACKS **************************/
790 * This are the functions that the generic PPP driver in the kernel
791 * will call to communicate to us.
794 /*------------------------------------------------------------------*/
796 * Prepare the ppp frame for transmission over the IrDA socket.
797 * We make sure that the header space is enough, and we change ppp header
798 * according to flags passed by pppd.
799 * This is not a callback, but just a helper function used in ppp_irnet_send()
801 static inline struct sk_buff
*
802 irnet_prepare_skb(irnet_socket
* ap
,
803 struct sk_buff
* skb
)
805 unsigned char * data
;
806 int proto
; /* PPP protocol */
807 int islcp
; /* Protocol == LCP */
808 int needaddr
; /* Need PPP address */
810 DENTER(PPP_TRACE
, "(ap=0x%p, skb=0x%p)\n",
813 /* Extract PPP protocol from the frame */
815 proto
= (data
[0] << 8) + data
[1];
817 /* LCP packets with codes between 1 (configure-request)
818 * and 7 (code-reject) must be sent as though no options
819 * have been negotiated. */
820 islcp
= (proto
== PPP_LCP
) && (1 <= data
[2]) && (data
[2] <= 7);
822 /* compress protocol field if option enabled */
823 if((data
[0] == 0) && (ap
->flags
& SC_COMP_PROT
) && (!islcp
))
826 /* Check if we need address/control fields */
827 needaddr
= 2*((ap
->flags
& SC_COMP_AC
) == 0 || islcp
);
829 /* Is the skb headroom large enough to contain all IrDA-headers? */
830 if((skb_headroom(skb
) < (ap
->max_header_size
+ needaddr
)) ||
833 struct sk_buff
* new_skb
;
835 DEBUG(PPP_INFO
, "Reallocating skb\n");
837 /* Create a new skb */
838 new_skb
= skb_realloc_headroom(skb
, ap
->max_header_size
+ needaddr
);
840 /* We have to free the original skb anyway */
843 /* Did the realloc succeed ? */
844 DABORT(new_skb
== NULL
, NULL
, PPP_ERROR
, "Could not realloc skb\n");
846 /* Use the new skb instead */
850 /* prepend address/control fields if necessary */
854 skb
->data
[0] = PPP_ALLSTATIONS
;
855 skb
->data
[1] = PPP_UI
;
858 DEXIT(PPP_TRACE
, "\n");
863 /*------------------------------------------------------------------*/
865 * Send a packet to the peer over the IrTTP connection.
866 * Returns 1 iff the packet was accepted.
867 * Returns 0 iff packet was not consumed.
868 * If the packet was not accepted, we will call ppp_output_wakeup
869 * at some later time to reactivate flow control in ppp_generic.
872 ppp_irnet_send(struct ppp_channel
* chan
,
873 struct sk_buff
* skb
)
875 irnet_socket
* self
= (struct irnet_socket
*) chan
->private;
878 DENTER(PPP_TRACE
, "(channel=0x%p, ap/self=0x%p)\n",
881 /* Check if things are somewhat valid... */
882 DASSERT(self
!= NULL
, 0, PPP_ERROR
, "Self is NULL !!!\n");
884 /* Check if we are connected */
885 if(!(test_bit(0, &self
->ttp_open
)))
887 #ifdef CONNECT_IN_SEND
888 /* Let's try to connect one more time... */
889 /* Note : we won't be connected after this call, but we should be
890 * ready for next packet... */
891 /* If we are already connecting, this will fail */
892 irda_irnet_connect(self
);
893 #endif /* CONNECT_IN_SEND */
895 DEBUG(PPP_INFO
, "IrTTP not ready ! (%ld-%ld)\n",
896 self
->ttp_open
, self
->ttp_connect
);
898 /* Note : we can either drop the packet or block the packet.
900 * Blocking the packet allow us a better connection time,
901 * because by calling ppp_output_wakeup() we can have
902 * ppp_generic resending the LCP request immediately to us,
903 * rather than waiting for one of pppd periodic transmission of
906 * On the other hand, if we block all packet, all those periodic
907 * transmissions of pppd accumulate in ppp_generic, creating a
908 * backlog of LCP request. When we eventually connect later on,
909 * we have to transmit all this backlog before we can connect
910 * proper (if we don't timeout before).
912 * The current strategy is as follow :
913 * While we are attempting to connect, we block packets to get
914 * a better connection time.
915 * If we fail to connect, we drain the queue and start dropping packets
917 #ifdef BLOCK_WHEN_CONNECT
918 /* If we are attempting to connect */
919 if(test_bit(0, &self
->ttp_connect
))
921 /* Blocking packet, ppp_generic will retry later */
924 #endif /* BLOCK_WHEN_CONNECT */
926 /* Dropping packet, pppd will retry later */
931 /* Check if the queue can accept any packet, otherwise block */
932 if(self
->tx_flow
!= FLOW_START
)
933 DRETURN(0, PPP_INFO
, "IrTTP queue full (%d skbs)...\n",
934 skb_queue_len(&self
->tsap
->tx_queue
));
936 /* Prepare ppp frame for transmission */
937 skb
= irnet_prepare_skb(self
, skb
);
938 DABORT(skb
== NULL
, 1, PPP_ERROR
, "Prepare skb for Tx failed.\n");
940 /* Send the packet to IrTTP */
941 ret
= irttp_data_request(self
->tsap
, skb
);
945 * > IrTTPs tx queue is full, so we just have to
946 * > drop the frame! You might think that we should
947 * > just return -1 and don't deallocate the frame,
948 * > but that is dangerous since it's possible that
949 * > we have replaced the original skb with a new
950 * > one with larger headroom, and that would really
951 * > confuse do_dev_queue_xmit() in dev.c! I have
953 * Correction : we verify the flow control above (self->tx_flow),
954 * so we come here only if IrTTP doesn't like the packet (empty,
955 * too large, IrTTP not connected). In those rare cases, it's ok
956 * to drop it, we don't want to see it here again...
959 DERROR(PPP_ERROR
, "IrTTP doesn't like this packet !!! (0x%X)\n", ret
);
960 /* irttp_data_request already free the packet */
963 DEXIT(PPP_TRACE
, "\n");
964 return 1; /* Packet has been consumed */
967 /*------------------------------------------------------------------*/
969 * Take care of the ioctls that ppp_generic doesn't want to deal with...
970 * Note : we are also called from dev_irnet_ioctl().
973 ppp_irnet_ioctl(struct ppp_channel
* chan
,
977 irnet_socket
* ap
= (struct irnet_socket
*) chan
->private;
981 void __user
*argp
= (void __user
*)arg
;
983 DENTER(PPP_TRACE
, "(channel=0x%p, ap=0x%p, cmd=0x%X)\n",
986 /* Basic checks... */
987 DASSERT(ap
!= NULL
, -ENXIO
, PPP_ERROR
, "ap is NULL...\n");
994 val
= ap
->flags
| ap
->rbits
;
995 if(put_user(val
, (int __user
*) argp
))
1000 if(get_user(val
, (int __user
*) argp
))
1002 ap
->flags
= val
& ~SC_RCV_BITS
;
1003 ap
->rbits
= val
& SC_RCV_BITS
;
1007 /* Async map stuff - all dummy to please pppd */
1008 case PPPIOCGASYNCMAP
:
1009 if(put_user(ap
->xaccm
[0], (u32 __user
*) argp
))
1013 case PPPIOCSASYNCMAP
:
1014 if(get_user(ap
->xaccm
[0], (u32 __user
*) argp
))
1018 case PPPIOCGRASYNCMAP
:
1019 if(put_user(ap
->raccm
, (u32 __user
*) argp
))
1023 case PPPIOCSRASYNCMAP
:
1024 if(get_user(ap
->raccm
, (u32 __user
*) argp
))
1028 case PPPIOCGXASYNCMAP
:
1029 if(copy_to_user(argp
, ap
->xaccm
, sizeof(ap
->xaccm
)))
1033 case PPPIOCSXASYNCMAP
:
1034 if(copy_from_user(accm
, argp
, sizeof(accm
)))
1036 accm
[2] &= ~0x40000000U
; /* can't escape 0x5e */
1037 accm
[3] |= 0x60000000U
; /* must escape 0x7d, 0x7e */
1038 memcpy(ap
->xaccm
, accm
, sizeof(ap
->xaccm
));
1042 /* Max PPP frame size */
1044 if(put_user(ap
->mru
, (int __user
*) argp
))
1049 if(get_user(val
, (int __user
*) argp
))
1058 DEBUG(PPP_INFO
, "Unsupported ioctl (0x%X)\n", cmd
);
1062 DEXIT(PPP_TRACE
, " - err = 0x%X\n", err
);
1066 /************************** INITIALISATION **************************/
1068 * Module initialisation and all that jazz...
1071 /*------------------------------------------------------------------*/
1073 * Hook our device callbacks in the filesystem, to connect our code
1076 static inline int __init
1077 ppp_irnet_init(void)
1081 DENTER(MODULE_TRACE
, "()\n");
1083 /* Allocate ourselves as a minor in the misc range */
1084 err
= misc_register(&irnet_misc_device
);
1086 DEXIT(MODULE_TRACE
, "\n");
1090 /*------------------------------------------------------------------*/
1092 * Cleanup at exit...
1094 static inline void __exit
1095 ppp_irnet_cleanup(void)
1097 DENTER(MODULE_TRACE
, "()\n");
1099 /* De-allocate /dev/irnet minor in misc range */
1100 misc_deregister(&irnet_misc_device
);
1102 DEXIT(MODULE_TRACE
, "\n");
1105 /*------------------------------------------------------------------*/
1107 * Module main entry point
1114 /* Initialise both parts... */
1115 err
= irda_irnet_init();
1117 err
= ppp_irnet_init();
1121 /*------------------------------------------------------------------*/
1128 irda_irnet_cleanup();
1129 ppp_irnet_cleanup();
1132 /*------------------------------------------------------------------*/
1136 module_init(irnet_init
);
1137 module_exit(irnet_cleanup
);
1138 MODULE_AUTHOR("Jean Tourrilhes <jt@hpl.hp.com>");
1139 MODULE_DESCRIPTION("IrNET : Synchronous PPP over IrDA");
1140 MODULE_LICENSE("GPL");
1141 MODULE_ALIAS_CHARDEV(10, 187);