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 /************************* CONTROL CHANNEL *************************/
21 * When a pppd instance is not active on /dev/irnet, it acts as a control
23 * Writing allow to set up the IrDA destination of the IrNET channel,
24 * and any application may be read events happening in IrNET...
27 /*------------------------------------------------------------------*/
29 * Write is used to send a command to configure a IrNET channel
30 * before it is open by pppd. The syntax is : "command argument"
31 * Currently there is only two defined commands :
32 * o name : set the requested IrDA nickname of the IrNET peer.
33 * o addr : set the requested IrDA address of the IrNET peer.
34 * Note : the code is crude, but effective...
37 irnet_ctrl_write(irnet_socket * ap,
41 char command[IRNET_MAX_COMMAND];
42 char * start; /* Current command being processed */
43 char * next; /* Next command to process */
44 int length; /* Length of current command */
46 DENTER(CTRL_TRACE, "(ap=0x%p, count=%Zd)\n", ap, count);
48 /* Check for overflow... */
49 DABORT(count >= IRNET_MAX_COMMAND, -ENOMEM,
50 CTRL_ERROR, "Too much data !!!\n");
52 /* Get the data in the driver */
53 if(copy_from_user(command, buf, count))
55 DERROR(CTRL_ERROR, "Invalid user space pointer.\n");
59 /* Safe terminate the string */
60 command[count] = '\0';
61 DEBUG(CTRL_INFO, "Command line received is ``%s'' (%Zd).\n",
64 /* Check every commands in the command line */
68 /* Look at the next command */
71 /* Scrap whitespaces before the command */
72 while(isspace(*start))
75 /* ',' is our command separator */
76 next = strchr(start, ',');
79 *next = '\0'; /* Terminate command */
80 length = next - start; /* Length */
81 next++; /* Skip the '\0' */
84 length = strlen(start);
86 DEBUG(CTRL_INFO, "Found command ``%s'' (%d).\n", start, length);
88 /* Check if we recognised one of the known command
89 * We can't use "switch" with strings, so hack with "continue" */
91 /* First command : name -> Requested IrDA nickname */
92 if(!strncmp(start, "name", 4))
94 /* Copy the name only if is included and not "any" */
95 if((length > 5) && (strcmp(start + 5, "any")))
97 /* Strip out trailing whitespaces */
98 while(isspace(start[length - 1]))
101 /* Copy the name for later reuse */
102 memcpy(ap->rname, start + 5, length - 5);
103 ap->rname[length - 5] = '\0';
107 DEBUG(CTRL_INFO, "Got rname = ``%s''\n", ap->rname);
109 /* Restart the loop */
113 /* Second command : addr, daddr -> Requested IrDA destination address
114 * Also process : saddr -> Requested IrDA source address */
115 if((!strncmp(start, "addr", 4)) ||
116 (!strncmp(start, "daddr", 5)) ||
117 (!strncmp(start, "saddr", 5)))
119 __u32 addr = DEV_ADDR_ANY;
121 /* Copy the address only if is included and not "any" */
122 if((length > 5) && (strcmp(start + 5, "any")))
124 char * begp = start + 5;
127 /* Scrap whitespaces before the command */
128 while(isspace(*begp))
131 /* Convert argument to a number (last arg is the base) */
132 addr = simple_strtoul(begp, &endp, 16);
133 /* Has it worked ? (endp should be start + length) */
134 DABORT(endp <= (start + 5), -EINVAL,
135 CTRL_ERROR, "Invalid address.\n");
137 /* Which type of address ? */
142 DEBUG(CTRL_INFO, "Got rsaddr = %08x\n", ap->rsaddr);
148 DEBUG(CTRL_INFO, "Got rdaddr = %08x\n", ap->rdaddr);
151 /* Restart the loop */
155 /* Other possible command : connect N (number of retries) */
157 /* No command matched -> Failed... */
158 DABORT(1, -EINVAL, CTRL_ERROR, "Not a recognised IrNET command.\n");
161 /* Success : we have parsed all commands successfully */
165 #ifdef INITIAL_DISCOVERY
166 /*------------------------------------------------------------------*/
168 * Function irnet_read_discovery_log (self)
170 * Read the content on the discovery log
172 * This function dump the current content of the discovery log
173 * at the startup of the event channel.
174 * Return 1 if written on the control channel...
176 * State of the ap->disco_XXX variables :
177 * at socket creation : disco_index = 0 ; disco_number = 0
178 * while reading : disco_index = X ; disco_number = Y
179 * After reading : disco_index = Y ; disco_number = -1
182 irnet_read_discovery_log(irnet_socket * ap,
187 DENTER(CTRL_TRACE, "(ap=0x%p, event=0x%p)\n",
190 /* Test if we have some work to do or we have already finished */
191 if(ap->disco_number == -1)
193 DEBUG(CTRL_INFO, "Already done\n");
197 /* Test if it's the first time and therefore we need to get the log */
198 if(ap->disco_index == 0)
200 __u16 mask = irlmp_service_to_hint(S_LAN);
202 /* Ask IrLMP for the current discovery log */
203 ap->discoveries = irlmp_get_discoveries(&ap->disco_number, mask,
204 DISCOVERY_DEFAULT_SLOTS);
205 /* Check if the we got some results */
206 if(ap->discoveries == NULL)
207 ap->disco_number = -1;
208 DEBUG(CTRL_INFO, "Got the log (0x%p), size is %d\n",
209 ap->discoveries, ap->disco_number);
212 /* Check if we have more item to dump */
213 if(ap->disco_index < ap->disco_number)
216 sprintf(event, "Found %08x (%s) behind %08x {hints %02X-%02X}\n",
217 ap->discoveries[ap->disco_index].daddr,
218 ap->discoveries[ap->disco_index].info,
219 ap->discoveries[ap->disco_index].saddr,
220 ap->discoveries[ap->disco_index].hints[0],
221 ap->discoveries[ap->disco_index].hints[1]);
222 DEBUG(CTRL_INFO, "Writing discovery %d : %s\n",
223 ap->disco_index, ap->discoveries[ap->disco_index].info);
225 /* We have an event */
231 /* Check if we have done the last item */
232 if(ap->disco_index >= ap->disco_number)
234 /* No more items : remove the log and signal termination */
235 DEBUG(CTRL_INFO, "Cleaning up log (0x%p)\n",
237 if(ap->discoveries != NULL)
239 /* Cleanup our copy of the discovery log */
240 kfree(ap->discoveries);
241 ap->discoveries = NULL;
243 ap->disco_number = -1;
248 #endif /* INITIAL_DISCOVERY */
250 /*------------------------------------------------------------------*/
252 * Read is used to get IrNET events
254 static inline ssize_t
255 irnet_ctrl_read(irnet_socket * ap,
260 DECLARE_WAITQUEUE(wait, current);
261 char event[64]; /* Max event is 61 char */
264 DENTER(CTRL_TRACE, "(ap=0x%p, count=%Zd)\n", ap, count);
266 /* Check if we can write an event out in one go */
267 DABORT(count < sizeof(event), -EOVERFLOW, CTRL_ERROR, "Buffer to small.\n");
269 #ifdef INITIAL_DISCOVERY
270 /* Check if we have read the log */
271 if(irnet_read_discovery_log(ap, event))
273 /* We have an event !!! Copy it to the user */
274 if(copy_to_user(buf, event, strlen(event)))
276 DERROR(CTRL_ERROR, "Invalid user space pointer.\n");
280 DEXIT(CTRL_TRACE, "\n");
281 return(strlen(event));
283 #endif /* INITIAL_DISCOVERY */
285 /* Put ourselves on the wait queue to be woken up */
286 add_wait_queue(&irnet_events.rwait, &wait);
287 current->state = TASK_INTERRUPTIBLE;
290 /* If there is unread events */
292 if(ap->event_index != irnet_events.index)
295 if(file->f_flags & O_NONBLOCK)
298 if(signal_pending(current))
300 /* Yield and wait to be woken up */
303 current->state = TASK_RUNNING;
304 remove_wait_queue(&irnet_events.rwait, &wait);
306 /* Did we got it ? */
309 /* No, return the error code */
310 DEXIT(CTRL_TRACE, " - ret %Zd\n", ret);
314 /* Which event is it ? */
315 switch(irnet_events.log[ap->event_index].event)
318 sprintf(event, "Discovered %08x (%s) behind %08x {hints %02X-%02X}\n",
319 irnet_events.log[ap->event_index].daddr,
320 irnet_events.log[ap->event_index].name,
321 irnet_events.log[ap->event_index].saddr,
322 irnet_events.log[ap->event_index].hints.byte[0],
323 irnet_events.log[ap->event_index].hints.byte[1]);
326 sprintf(event, "Expired %08x (%s) behind %08x {hints %02X-%02X}\n",
327 irnet_events.log[ap->event_index].daddr,
328 irnet_events.log[ap->event_index].name,
329 irnet_events.log[ap->event_index].saddr,
330 irnet_events.log[ap->event_index].hints.byte[0],
331 irnet_events.log[ap->event_index].hints.byte[1]);
333 case IRNET_CONNECT_TO:
334 sprintf(event, "Connected to %08x (%s) on ppp%d\n",
335 irnet_events.log[ap->event_index].daddr,
336 irnet_events.log[ap->event_index].name,
337 irnet_events.log[ap->event_index].unit);
339 case IRNET_CONNECT_FROM:
340 sprintf(event, "Connection from %08x (%s) on ppp%d\n",
341 irnet_events.log[ap->event_index].daddr,
342 irnet_events.log[ap->event_index].name,
343 irnet_events.log[ap->event_index].unit);
345 case IRNET_REQUEST_FROM:
346 sprintf(event, "Request from %08x (%s) behind %08x\n",
347 irnet_events.log[ap->event_index].daddr,
348 irnet_events.log[ap->event_index].name,
349 irnet_events.log[ap->event_index].saddr);
351 case IRNET_NOANSWER_FROM:
352 sprintf(event, "No-answer from %08x (%s) on ppp%d\n",
353 irnet_events.log[ap->event_index].daddr,
354 irnet_events.log[ap->event_index].name,
355 irnet_events.log[ap->event_index].unit);
357 case IRNET_BLOCKED_LINK:
358 sprintf(event, "Blocked link with %08x (%s) on ppp%d\n",
359 irnet_events.log[ap->event_index].daddr,
360 irnet_events.log[ap->event_index].name,
361 irnet_events.log[ap->event_index].unit);
363 case IRNET_DISCONNECT_FROM:
364 sprintf(event, "Disconnection from %08x (%s) on ppp%d\n",
365 irnet_events.log[ap->event_index].daddr,
366 irnet_events.log[ap->event_index].name,
367 irnet_events.log[ap->event_index].unit);
369 case IRNET_DISCONNECT_TO:
370 sprintf(event, "Disconnected to %08x (%s)\n",
371 irnet_events.log[ap->event_index].daddr,
372 irnet_events.log[ap->event_index].name);
375 sprintf(event, "Bug\n");
377 /* Increment our event index */
378 ap->event_index = (ap->event_index + 1) % IRNET_MAX_EVENTS;
380 DEBUG(CTRL_INFO, "Event is :%s", event);
382 /* Copy it to the user */
383 if(copy_to_user(buf, event, strlen(event)))
385 DERROR(CTRL_ERROR, "Invalid user space pointer.\n");
389 DEXIT(CTRL_TRACE, "\n");
390 return(strlen(event));
393 /*------------------------------------------------------------------*/
395 * Poll : called when someone do a select on /dev/irnet.
396 * Just check if there are new events...
398 static inline unsigned int
399 irnet_ctrl_poll(irnet_socket * ap,
405 DENTER(CTRL_TRACE, "(ap=0x%p)\n", ap);
407 poll_wait(file, &irnet_events.rwait, wait);
408 mask = POLLOUT | POLLWRNORM;
409 /* If there is unread events */
410 if(ap->event_index != irnet_events.index)
411 mask |= POLLIN | POLLRDNORM;
412 #ifdef INITIAL_DISCOVERY
413 if(ap->disco_number != -1)
414 mask |= POLLIN | POLLRDNORM;
415 #endif /* INITIAL_DISCOVERY */
417 DEXIT(CTRL_TRACE, " - mask=0x%X\n", mask);
422 /*********************** FILESYSTEM CALLBACKS ***********************/
424 * Implement the usual open, read, write functions that will be called
425 * by the file system when some action is performed on /dev/irnet.
426 * Most of those actions will in fact be performed by "pppd" or
427 * the control channel, we just act as a redirector...
430 /*------------------------------------------------------------------*/
432 * Open : when somebody open /dev/irnet
433 * We basically create a new instance of irnet and initialise it.
436 dev_irnet_open(struct inode * inode,
439 struct irnet_socket * ap;
442 DENTER(FS_TRACE, "(file=0x%p)\n", file);
444 #ifdef SECURE_DEVIRNET
445 /* This could (should?) be enforced by the permissions on /dev/irnet. */
446 if(!capable(CAP_NET_ADMIN))
448 #endif /* SECURE_DEVIRNET */
450 /* Allocate a private structure for this IrNET instance */
451 ap = kmalloc(sizeof(*ap), GFP_KERNEL);
452 DABORT(ap == NULL, -ENOMEM, FS_ERROR, "Can't allocate struct irnet...\n");
454 /* initialize the irnet structure */
455 memset(ap, 0, sizeof(*ap));
458 /* PPP channel setup */
460 ap->chan.private = ap;
461 ap->chan.ops = &irnet_ppp_ops;
462 ap->chan.mtu = (2048 - TTP_MAX_HEADER - 2 - PPP_HDRLEN);
463 ap->chan.hdrlen = 2 + TTP_MAX_HEADER; /* for A/C + Max IrDA hdr */
465 ap->mru = (2048 - TTP_MAX_HEADER - 2 - PPP_HDRLEN);
467 ap->xaccm[3] = 0x60000000U;
470 /* Setup the IrDA part... */
471 err = irda_irnet_create(ap);
474 DERROR(FS_ERROR, "Can't setup IrDA link...\n");
479 /* For the control channel */
480 ap->event_index = irnet_events.index; /* Cancel all past events */
482 /* Put our stuff where we will be able to find it later */
483 file->private_data = ap;
485 DEXIT(FS_TRACE, " - ap=0x%p\n", ap);
490 /*------------------------------------------------------------------*/
492 * Close : when somebody close /dev/irnet
493 * Destroy the instance of /dev/irnet
496 dev_irnet_close(struct inode * inode,
499 irnet_socket * ap = (struct irnet_socket *) file->private_data;
501 DENTER(FS_TRACE, "(file=0x%p, ap=0x%p)\n",
503 DABORT(ap == NULL, 0, FS_ERROR, "ap is NULL !!!\n");
505 /* Detach ourselves */
506 file->private_data = NULL;
508 /* Close IrDA stuff */
509 irda_irnet_destroy(ap);
511 /* Disconnect from the generic PPP layer if not already done */
514 DERROR(FS_ERROR, "Channel still registered - deregistering !\n");
516 ppp_unregister_channel(&ap->chan);
521 DEXIT(FS_TRACE, "\n");
525 /*------------------------------------------------------------------*/
527 * Write does nothing.
528 * (we receive packet from ppp_generic through ppp_irnet_send())
531 dev_irnet_write(struct file * file,
536 irnet_socket * ap = (struct irnet_socket *) file->private_data;
538 DPASS(FS_TRACE, "(file=0x%p, ap=0x%p, count=%Zd)\n",
540 DABORT(ap == NULL, -ENXIO, FS_ERROR, "ap is NULL !!!\n");
542 /* If we are connected to ppp_generic, let it handle the job */
546 return irnet_ctrl_write(ap, buf, count);
549 /*------------------------------------------------------------------*/
551 * Read doesn't do much either.
552 * (pppd poll us, but ultimately reads through /dev/ppp)
555 dev_irnet_read(struct file * file,
560 irnet_socket * ap = (struct irnet_socket *) file->private_data;
562 DPASS(FS_TRACE, "(file=0x%p, ap=0x%p, count=%Zd)\n",
564 DABORT(ap == NULL, -ENXIO, FS_ERROR, "ap is NULL !!!\n");
566 /* If we are connected to ppp_generic, let it handle the job */
570 return irnet_ctrl_read(ap, file, buf, count);
573 /*------------------------------------------------------------------*/
575 * Poll : called when someone do a select on /dev/irnet
578 dev_irnet_poll(struct file * file,
581 irnet_socket * ap = (struct irnet_socket *) file->private_data;
584 DENTER(FS_TRACE, "(file=0x%p, ap=0x%p)\n",
587 mask = POLLOUT | POLLWRNORM;
588 DABORT(ap == NULL, mask, FS_ERROR, "ap is NULL !!!\n");
590 /* If we are connected to ppp_generic, let it handle the job */
592 mask |= irnet_ctrl_poll(ap, file, wait);
594 DEXIT(FS_TRACE, " - mask=0x%X\n", mask);
598 /*------------------------------------------------------------------*/
600 * IOCtl : Called when someone does some ioctls on /dev/irnet
601 * This is the way pppd configure us and control us while the PPP
602 * instance is active.
605 dev_irnet_ioctl(struct inode * inode,
610 irnet_socket * ap = (struct irnet_socket *) file->private_data;
614 DENTER(FS_TRACE, "(file=0x%p, ap=0x%p, cmd=0x%X)\n",
617 /* Basic checks... */
618 DASSERT(ap != NULL, -ENXIO, PPP_ERROR, "ap is NULL...\n");
619 #ifdef SECURE_DEVIRNET
620 if(!capable(CAP_NET_ADMIN))
622 #endif /* SECURE_DEVIRNET */
627 /* Set discipline (should be N_SYNC_PPP or N_TTY) */
629 if(get_user(val, (int *) arg))
631 if((val == N_SYNC_PPP) || (val == N_PPP))
633 DEBUG(FS_INFO, "Entering PPP discipline.\n");
634 /* PPP channel setup (ap->chan in configued in dev_irnet_open())*/
635 err = ppp_register_channel(&ap->chan);
638 /* Our ppp side is active */
641 DEBUG(FS_INFO, "Trying to establish a connection.\n");
642 /* Setup the IrDA link now - may fail... */
643 irda_irnet_connect(ap);
646 DERROR(FS_ERROR, "Can't setup PPP channel...\n");
650 /* In theory, should be N_TTY */
651 DEBUG(FS_INFO, "Exiting PPP discipline.\n");
652 /* Disconnect from the generic PPP layer */
656 ppp_unregister_channel(&ap->chan);
659 DERROR(FS_ERROR, "Channel not registered !\n");
664 /* Query PPP channel and unit number */
668 if(put_user(ppp_channel_index(&ap->chan), (int *) arg))
670 DEBUG(FS_INFO, "Query channel.\n");
676 if(put_user(ppp_unit_number(&ap->chan), (int *) arg))
678 DEBUG(FS_INFO, "Query unit number.\n");
682 /* All these ioctls can be passed both directly and from ppp_generic,
683 * so we just deal with them in one place...
687 case PPPIOCGASYNCMAP:
688 case PPPIOCSASYNCMAP:
689 case PPPIOCGRASYNCMAP:
690 case PPPIOCSRASYNCMAP:
691 case PPPIOCGXASYNCMAP:
692 case PPPIOCSXASYNCMAP:
695 DEBUG(FS_INFO, "Standard PPP ioctl.\n");
696 if(!capable(CAP_NET_ADMIN))
699 err = ppp_irnet_ioctl(&ap->chan, cmd, arg);
702 /* TTY IOCTLs : Pretend that we are a tty, to keep pppd happy */
705 DEBUG(FS_INFO, "Get termios.\n");
706 if(kernel_termios_to_user_termios((struct termios *)arg, &ap->termios))
712 DEBUG(FS_INFO, "Set termios.\n");
713 if(user_termios_to_kernel_termios(&ap->termios, (struct termios *) arg))
721 /* Set exclusive/non-exclusive mode */
724 DEBUG(FS_INFO, "TTY compatibility.\n");
729 DEBUG(FS_INFO, "TCGETA\n");
733 DEBUG(FS_INFO, "TCFLSH\n");
734 /* Note : this will flush buffers in PPP, so it *must* be done
735 * We should also worry that we don't accept junk here and that
736 * we get rid of our own buffers */
738 ppp_output_wakeup(&ap->chan);
739 #endif /* FLUSH_TO_PPP */
744 DEBUG(FS_INFO, "FIONREAD\n");
746 if(put_user(val, (int *) arg))
752 DERROR(FS_ERROR, "Unsupported ioctl (0x%X)\n", cmd);
756 DEXIT(FS_TRACE, " - err = 0x%X\n", err);
760 /************************** PPP CALLBACKS **************************/
762 * This are the functions that the generic PPP driver in the kernel
763 * will call to communicate to us.
766 /*------------------------------------------------------------------*/
768 * Prepare the ppp frame for transmission over the IrDA socket.
769 * We make sure that the header space is enough, and we change ppp header
770 * according to flags passed by pppd.
771 * This is not a callback, but just a helper function used in ppp_irnet_send()
773 static inline struct sk_buff *
774 irnet_prepare_skb(irnet_socket * ap,
775 struct sk_buff * skb)
777 unsigned char * data;
778 int proto; /* PPP protocol */
779 int islcp; /* Protocol == LCP */
780 int needaddr; /* Need PPP address */
782 DENTER(PPP_TRACE, "(ap=0x%p, skb=0x%p)\n",
785 /* Extract PPP protocol from the frame */
787 proto = (data[0] << 8) + data[1];
789 /* LCP packets with codes between 1 (configure-request)
790 * and 7 (code-reject) must be sent as though no options
791 * have been negotiated. */
792 islcp = (proto == PPP_LCP) && (1 <= data[2]) && (data[2] <= 7);
794 /* compress protocol field if option enabled */
795 if((data[0] == 0) && (ap->flags & SC_COMP_PROT) && (!islcp))
798 /* Check if we need address/control fields */
799 needaddr = 2*((ap->flags & SC_COMP_AC) == 0 || islcp);
801 /* Is the skb headroom large enough to contain all IrDA-headers? */
802 if((skb_headroom(skb) < (ap->max_header_size + needaddr)) ||
805 struct sk_buff * new_skb;
807 DEBUG(PPP_INFO, "Reallocating skb\n");
809 /* Create a new skb */
810 new_skb = skb_realloc_headroom(skb, ap->max_header_size + needaddr);
812 /* We have to free the original skb anyway */
815 /* Did the realloc succeed ? */
816 DABORT(new_skb == NULL, NULL, PPP_ERROR, "Could not realloc skb\n");
818 /* Use the new skb instead */
822 /* prepend address/control fields if necessary */
826 skb->data[0] = PPP_ALLSTATIONS;
827 skb->data[1] = PPP_UI;
830 DEXIT(PPP_TRACE, "\n");
835 /*------------------------------------------------------------------*/
837 * Send a packet to the peer over the IrTTP connection.
838 * Returns 1 iff the packet was accepted.
839 * Returns 0 iff packet was not consumed.
840 * If the packet was not accepted, we will call ppp_output_wakeup
841 * at some later time to reactivate flow control in ppp_generic.
844 ppp_irnet_send(struct ppp_channel * chan,
845 struct sk_buff * skb)
847 irnet_socket * self = (struct irnet_socket *) chan->private;
850 DENTER(PPP_TRACE, "(channel=0x%p, ap/self=0x%p)\n",
853 /* Check if things are somewhat valid... */
854 DASSERT(self != NULL, 0, PPP_ERROR, "Self is NULL !!!\n");
856 /* Check if we are connected */
857 if(!(test_bit(0, &self->ttp_open)))
859 #ifdef CONNECT_IN_SEND
860 /* Let's try to connect one more time... */
861 /* Note : we won't be connected after this call, but we should be
862 * ready for next packet... */
863 /* If we are already connecting, this will fail */
864 irda_irnet_connect(self);
865 #endif /* CONNECT_IN_SEND */
867 DEBUG(PPP_INFO, "IrTTP not ready ! (%ld-%ld)\n",
868 self->ttp_open, self->ttp_connect);
870 /* Note : we can either drop the packet or block the packet.
872 * Blocking the packet allow us a better connection time,
873 * because by calling ppp_output_wakeup() we can have
874 * ppp_generic resending the LCP request immediately to us,
875 * rather than waiting for one of pppd periodic transmission of
878 * On the other hand, if we block all packet, all those periodic
879 * transmissions of pppd accumulate in ppp_generic, creating a
880 * backlog of LCP request. When we eventually connect later on,
881 * we have to transmit all this backlog before we can connect
882 * proper (if we don't timeout before).
884 * The current strategy is as follow :
885 * While we are attempting to connect, we block packets to get
886 * a better connection time.
887 * If we fail to connect, we drain the queue and start dropping packets
889 #ifdef BLOCK_WHEN_CONNECT
890 /* If we are attempting to connect */
891 if(test_bit(0, &self->ttp_connect))
893 /* Blocking packet, ppp_generic will retry later */
896 #endif /* BLOCK_WHEN_CONNECT */
898 /* Dropping packet, pppd will retry later */
903 /* Check if the queue can accept any packet, otherwise block */
904 if(self->tx_flow != FLOW_START)
905 DRETURN(0, PPP_INFO, "IrTTP queue full (%d skbs)...\n",
906 skb_queue_len(&self->tsap->tx_queue));
908 /* Prepare ppp frame for transmission */
909 skb = irnet_prepare_skb(self, skb);
910 DABORT(skb == NULL, 1, PPP_ERROR, "Prepare skb for Tx failed.\n");
912 /* Send the packet to IrTTP */
913 ret = irttp_data_request(self->tsap, skb);
917 * > IrTTPs tx queue is full, so we just have to
918 * > drop the frame! You might think that we should
919 * > just return -1 and don't deallocate the frame,
920 * > but that is dangerous since it's possible that
921 * > we have replaced the original skb with a new
922 * > one with larger headroom, and that would really
923 * > confuse do_dev_queue_xmit() in dev.c! I have
925 * Correction : we verify the flow control above (self->tx_flow),
926 * so we come here only if IrTTP doesn't like the packet (empty,
927 * too large, IrTTP not connected). In those rare cases, it's ok
928 * to drop it, we don't want to see it here again...
931 DERROR(PPP_ERROR, "IrTTP doesn't like this packet !!! (0x%X)\n", ret);
932 /* irttp_data_request already free the packet */
935 DEXIT(PPP_TRACE, "\n");
936 return 1; /* Packet has been consumed */
939 /*------------------------------------------------------------------*/
941 * Take care of the ioctls that ppp_generic doesn't want to deal with...
942 * Note : we are also called from dev_irnet_ioctl().
945 ppp_irnet_ioctl(struct ppp_channel * chan,
949 irnet_socket * ap = (struct irnet_socket *) chan->private;
954 DENTER(PPP_TRACE, "(channel=0x%p, ap=0x%p, cmd=0x%X)\n",
957 /* Basic checks... */
958 DASSERT(ap != NULL, -ENXIO, PPP_ERROR, "ap is NULL...\n");
965 val = ap->flags | ap->rbits;
966 if(put_user(val, (int *) arg))
971 if(get_user(val, (int *) arg))
973 ap->flags = val & ~SC_RCV_BITS;
974 ap->rbits = val & SC_RCV_BITS;
978 /* Async map stuff - all dummy to please pppd */
979 case PPPIOCGASYNCMAP:
980 if(put_user(ap->xaccm[0], (u32 *) arg))
984 case PPPIOCSASYNCMAP:
985 if(get_user(ap->xaccm[0], (u32 *) arg))
989 case PPPIOCGRASYNCMAP:
990 if(put_user(ap->raccm, (u32 *) arg))
994 case PPPIOCSRASYNCMAP:
995 if(get_user(ap->raccm, (u32 *) arg))
999 case PPPIOCGXASYNCMAP:
1000 if(copy_to_user((void *) arg, ap->xaccm, sizeof(ap->xaccm)))
1004 case PPPIOCSXASYNCMAP:
1005 if(copy_from_user(accm, (void *) arg, sizeof(accm)))
1007 accm[2] &= ~0x40000000U; /* can't escape 0x5e */
1008 accm[3] |= 0x60000000U; /* must escape 0x7d, 0x7e */
1009 memcpy(ap->xaccm, accm, sizeof(ap->xaccm));
1013 /* Max PPP frame size */
1015 if(put_user(ap->mru, (int *) arg))
1020 if(get_user(val, (int *) arg))
1029 DEBUG(PPP_INFO, "Unsupported ioctl (0x%X)\n", cmd);
1033 DEXIT(PPP_TRACE, " - err = 0x%X\n", err);
1037 /************************** INITIALISATION **************************/
1039 * Module initialisation and all that jazz...
1042 /*------------------------------------------------------------------*/
1044 * Hook our device callbacks in the filesystem, to connect our code
1047 static inline int __init
1048 ppp_irnet_init(void)
1052 DENTER(MODULE_TRACE, "()\n");
1054 /* Allocate ourselves as a minor in the misc range */
1055 err = misc_register(&irnet_misc_device);
1057 DEXIT(MODULE_TRACE, "\n");
1061 /*------------------------------------------------------------------*/
1063 * Cleanup at exit...
1065 static inline void __exit
1066 ppp_irnet_cleanup(void)
1068 DENTER(MODULE_TRACE, "()\n");
1070 /* De-allocate /dev/irnet minor in misc range */
1071 misc_deregister(&irnet_misc_device);
1073 DEXIT(MODULE_TRACE, "\n");
1076 /*------------------------------------------------------------------*/
1078 * Module main entry point
1085 /* Initialise both parts... */
1086 err = irda_irnet_init();
1088 err = ppp_irnet_init();
1092 /*------------------------------------------------------------------*/
1099 irda_irnet_cleanup();
1100 return ppp_irnet_cleanup();
1103 /*------------------------------------------------------------------*/
1107 module_init(irnet_init);
1108 module_exit(irnet_cleanup);
1109 MODULE_AUTHOR("Jean Tourrilhes <jt@hpl.hp.com>");
1110 MODULE_DESCRIPTION("IrNET : Synchronous PPP over IrDA");
1111 MODULE_LICENSE("GPL");