Merge git://oss.sgi.com:8090/xfs/xfs-2.6
[linux-2.6] / net / irda / irlap_frame.c
1 /*********************************************************************
2  *
3  * Filename:      irlap_frame.c
4  * Version:       1.0
5  * Description:   Build and transmit IrLAP frames
6  * Status:        Stable
7  * Author:        Dag Brattli <dagb@cs.uit.no>
8  * Created at:    Tue Aug 19 10:27:26 1997
9  * Modified at:   Wed Jan  5 08:59:04 2000
10  * Modified by:   Dag Brattli <dagb@cs.uit.no>
11  *
12  *     Copyright (c) 1998-2000 Dag Brattli <dagb@cs.uit.no>,
13  *     All Rights Reserved.
14  *     Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
15  *
16  *     This program is free software; you can redistribute it and/or
17  *     modify it under the terms of the GNU General Public License as
18  *     published by the Free Software Foundation; either version 2 of
19  *     the License, or (at your option) any later version.
20  *
21  *     Neither Dag Brattli nor University of Tromsø admit liability nor
22  *     provide warranty for any of this software. This material is
23  *     provided "AS-IS" and at no charge.
24  *
25  ********************************************************************/
26
27 #include <linux/skbuff.h>
28 #include <linux/if.h>
29 #include <linux/if_ether.h>
30 #include <linux/netdevice.h>
31 #include <linux/irda.h>
32
33 #include <net/pkt_sched.h>
34 #include <net/sock.h>
35
36 #include <asm/byteorder.h>
37
38 #include <net/irda/irda.h>
39 #include <net/irda/irda_device.h>
40 #include <net/irda/irlap.h>
41 #include <net/irda/wrapper.h>
42 #include <net/irda/timer.h>
43 #include <net/irda/irlap_frame.h>
44 #include <net/irda/qos.h>
45
46 static void irlap_send_i_frame(struct irlap_cb *self, struct sk_buff *skb,
47                                int command);
48
49 /*
50  * Function irlap_insert_info (self, skb)
51  *
52  *    Insert minimum turnaround time and speed information into the skb. We
53  *    need to do this since it's per packet relevant information. Safe to
54  *    have this function inlined since it's only called from one place
55  */
56 static inline void irlap_insert_info(struct irlap_cb *self,
57                                      struct sk_buff *skb)
58 {
59         struct irda_skb_cb *cb = (struct irda_skb_cb *) skb->cb;
60
61         /*
62          * Insert MTT (min. turn time) and speed into skb, so that the
63          * device driver knows which settings to use
64          */
65         cb->magic = LAP_MAGIC;
66         cb->mtt = self->mtt_required;
67         cb->next_speed = self->speed;
68
69         /* Reset */
70         self->mtt_required = 0;
71
72         /*
73          * Delay equals negotiated BOFs count, plus the number of BOFs to
74          * force the negotiated minimum turnaround time
75          */
76         cb->xbofs = self->bofs_count;
77         cb->next_xbofs = self->next_bofs;
78         cb->xbofs_delay = self->xbofs_delay;
79
80         /* Reset XBOF's delay (used only for getting min turn time) */
81         self->xbofs_delay = 0;
82         /* Put the correct xbofs value for the next packet */
83         self->bofs_count = self->next_bofs;
84 }
85
86 /*
87  * Function irlap_queue_xmit (self, skb)
88  *
89  *    A little wrapper for dev_queue_xmit, so we can insert some common
90  *    code into it.
91  */
92 void irlap_queue_xmit(struct irlap_cb *self, struct sk_buff *skb)
93 {
94         /* Some common init stuff */
95         skb->dev = self->netdev;
96         skb->h.raw = skb->nh.raw = skb->mac.raw = skb->data;
97         skb->protocol = htons(ETH_P_IRDA);
98         skb->priority = TC_PRIO_BESTEFFORT;
99
100         irlap_insert_info(self, skb);
101
102         dev_queue_xmit(skb);
103 }
104
105 /*
106  * Function irlap_send_snrm_cmd (void)
107  *
108  *    Transmits a connect SNRM command frame
109  */
110 void irlap_send_snrm_frame(struct irlap_cb *self, struct qos_info *qos)
111 {
112         struct sk_buff *tx_skb;
113         struct snrm_frame *frame;
114         int ret;
115
116         IRDA_ASSERT(self != NULL, return;);
117         IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
118
119         /* Allocate frame */
120         tx_skb = alloc_skb(sizeof(struct snrm_frame) +
121                            IRLAP_NEGOCIATION_PARAMS_LEN,
122                            GFP_ATOMIC);
123         if (!tx_skb)
124                 return;
125
126         frame = (struct snrm_frame *) skb_put(tx_skb, 2);
127
128         /* Insert connection address field */
129         if (qos)
130                 frame->caddr = CMD_FRAME | CBROADCAST;
131         else
132                 frame->caddr = CMD_FRAME | self->caddr;
133
134         /* Insert control field */
135         frame->control = SNRM_CMD | PF_BIT;
136
137         /*
138          *  If we are establishing a connection then insert QoS paramerters
139          */
140         if (qos) {
141                 skb_put(tx_skb, 9); /* 25 left */
142                 frame->saddr = cpu_to_le32(self->saddr);
143                 frame->daddr = cpu_to_le32(self->daddr);
144
145                 frame->ncaddr = self->caddr;
146
147                 ret = irlap_insert_qos_negotiation_params(self, tx_skb);
148                 if (ret < 0) {
149                         dev_kfree_skb(tx_skb);
150                         return;
151                 }
152         }
153         irlap_queue_xmit(self, tx_skb);
154 }
155
156 /*
157  * Function irlap_recv_snrm_cmd (skb, info)
158  *
159  *    Received SNRM (Set Normal Response Mode) command frame
160  *
161  */
162 static void irlap_recv_snrm_cmd(struct irlap_cb *self, struct sk_buff *skb,
163                                 struct irlap_info *info)
164 {
165         struct snrm_frame *frame;
166
167         if (pskb_may_pull(skb,sizeof(struct snrm_frame))) {
168                 frame = (struct snrm_frame *) skb->data;
169
170                 /* Copy the new connection address ignoring the C/R bit */
171                 info->caddr = frame->ncaddr & 0xFE;
172
173                 /* Check if the new connection address is valid */
174                 if ((info->caddr == 0x00) || (info->caddr == 0xfe)) {
175                         IRDA_DEBUG(3, "%s(), invalid connection address!\n",
176                                    __FUNCTION__);
177                         return;
178                 }
179
180                 /* Copy peer device address */
181                 info->daddr = le32_to_cpu(frame->saddr);
182                 info->saddr = le32_to_cpu(frame->daddr);
183
184                 /* Only accept if addressed directly to us */
185                 if (info->saddr != self->saddr) {
186                         IRDA_DEBUG(2, "%s(), not addressed to us!\n",
187                                    __FUNCTION__);
188                         return;
189                 }
190                 irlap_do_event(self, RECV_SNRM_CMD, skb, info);
191         } else {
192                 /* Signal that this SNRM frame does not contain and I-field */
193                 irlap_do_event(self, RECV_SNRM_CMD, skb, NULL);
194         }
195 }
196
197 /*
198  * Function irlap_send_ua_response_frame (qos)
199  *
200  *    Send UA (Unnumbered Acknowledgement) frame
201  *
202  */
203 void irlap_send_ua_response_frame(struct irlap_cb *self, struct qos_info *qos)
204 {
205         struct sk_buff *tx_skb;
206         struct ua_frame *frame;
207         int ret;
208
209         IRDA_DEBUG(2, "%s() <%ld>\n", __FUNCTION__, jiffies);
210
211         IRDA_ASSERT(self != NULL, return;);
212         IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
213
214         /* Allocate frame */
215         tx_skb = alloc_skb(sizeof(struct ua_frame) +
216                            IRLAP_NEGOCIATION_PARAMS_LEN,
217                            GFP_ATOMIC);
218         if (!tx_skb)
219                 return;
220
221         frame = (struct ua_frame *) skb_put(tx_skb, 10);
222
223         /* Build UA response */
224         frame->caddr = self->caddr;
225         frame->control = UA_RSP | PF_BIT;
226
227         frame->saddr = cpu_to_le32(self->saddr);
228         frame->daddr = cpu_to_le32(self->daddr);
229
230         /* Should we send QoS negotiation parameters? */
231         if (qos) {
232                 ret = irlap_insert_qos_negotiation_params(self, tx_skb);
233                 if (ret < 0) {
234                         dev_kfree_skb(tx_skb);
235                         return;
236                 }
237         }
238
239         irlap_queue_xmit(self, tx_skb);
240 }
241
242
243 /*
244  * Function irlap_send_dm_frame (void)
245  *
246  *    Send disconnected mode (DM) frame
247  *
248  */
249 void irlap_send_dm_frame( struct irlap_cb *self)
250 {
251         struct sk_buff *tx_skb = NULL;
252         struct dm_frame *frame;
253
254         IRDA_ASSERT(self != NULL, return;);
255         IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
256
257         tx_skb = alloc_skb(sizeof(struct dm_frame), GFP_ATOMIC);
258         if (!tx_skb)
259                 return;
260
261         frame = (struct dm_frame *)skb_put(tx_skb, 2);
262
263         if (self->state == LAP_NDM)
264                 frame->caddr = CBROADCAST;
265         else
266                 frame->caddr = self->caddr;
267
268         frame->control = DM_RSP | PF_BIT;
269
270         irlap_queue_xmit(self, tx_skb);
271 }
272
273 /*
274  * Function irlap_send_disc_frame (void)
275  *
276  *    Send disconnect (DISC) frame
277  *
278  */
279 void irlap_send_disc_frame(struct irlap_cb *self)
280 {
281         struct sk_buff *tx_skb = NULL;
282         struct disc_frame *frame;
283
284         IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
285
286         IRDA_ASSERT(self != NULL, return;);
287         IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
288
289         tx_skb = alloc_skb(sizeof(struct disc_frame), GFP_ATOMIC);
290         if (!tx_skb)
291                 return;
292
293         frame = (struct disc_frame *)skb_put(tx_skb, 2);
294
295         frame->caddr = self->caddr | CMD_FRAME;
296         frame->control = DISC_CMD | PF_BIT;
297
298         irlap_queue_xmit(self, tx_skb);
299 }
300
301 /*
302  * Function irlap_send_discovery_xid_frame (S, s, command)
303  *
304  *    Build and transmit a XID (eXchange station IDentifier) discovery
305  *    frame.
306  */
307 void irlap_send_discovery_xid_frame(struct irlap_cb *self, int S, __u8 s,
308                                     __u8 command, discovery_t *discovery)
309 {
310         struct sk_buff *tx_skb = NULL;
311         struct xid_frame *frame;
312         __u32 bcast = BROADCAST;
313         __u8 *info;
314
315         IRDA_DEBUG(4, "%s(), s=%d, S=%d, command=%d\n", __FUNCTION__,
316                    s, S, command);
317
318         IRDA_ASSERT(self != NULL, return;);
319         IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
320         IRDA_ASSERT(discovery != NULL, return;);
321
322         tx_skb = alloc_skb(sizeof(struct xid_frame) + IRLAP_DISCOVERY_INFO_LEN,
323                            GFP_ATOMIC);
324         if (!tx_skb)
325                 return;
326
327         skb_put(tx_skb, 14);
328         frame = (struct xid_frame *) tx_skb->data;
329
330         if (command) {
331                 frame->caddr = CBROADCAST | CMD_FRAME;
332                 frame->control =  XID_CMD | PF_BIT;
333         } else {
334                 frame->caddr = CBROADCAST;
335                 frame->control =  XID_RSP | PF_BIT;
336         }
337         frame->ident = XID_FORMAT;
338
339         frame->saddr = cpu_to_le32(self->saddr);
340
341         if (command)
342                 frame->daddr = cpu_to_le32(bcast);
343         else
344                 frame->daddr = cpu_to_le32(discovery->data.daddr);
345
346         switch (S) {
347         case 1:
348                 frame->flags = 0x00;
349                 break;
350         case 6:
351                 frame->flags = 0x01;
352                 break;
353         case 8:
354                 frame->flags = 0x02;
355                 break;
356         case 16:
357                 frame->flags = 0x03;
358                 break;
359         default:
360                 frame->flags = 0x02;
361                 break;
362         }
363
364         frame->slotnr = s;
365         frame->version = 0x00;
366
367         /*
368          *  Provide info for final slot only in commands, and for all
369          *  responses. Send the second byte of the hint only if the
370          *  EXTENSION bit is set in the first byte.
371          */
372         if (!command || (frame->slotnr == 0xff)) {
373                 int len;
374
375                 if (discovery->data.hints[0] & HINT_EXTENSION) {
376                         info = skb_put(tx_skb, 2);
377                         info[0] = discovery->data.hints[0];
378                         info[1] = discovery->data.hints[1];
379                 } else {
380                         info = skb_put(tx_skb, 1);
381                         info[0] = discovery->data.hints[0];
382                 }
383                 info = skb_put(tx_skb, 1);
384                 info[0] = discovery->data.charset;
385
386                 len = IRDA_MIN(discovery->name_len, skb_tailroom(tx_skb));
387                 info = skb_put(tx_skb, len);
388                 memcpy(info, discovery->data.info, len);
389         }
390         irlap_queue_xmit(self, tx_skb);
391 }
392
393 /*
394  * Function irlap_recv_discovery_xid_rsp (skb, info)
395  *
396  *    Received a XID discovery response
397  *
398  */
399 static void irlap_recv_discovery_xid_rsp(struct irlap_cb *self,
400                                          struct sk_buff *skb,
401                                          struct irlap_info *info)
402 {
403         struct xid_frame *xid;
404         discovery_t *discovery = NULL;
405         __u8 *discovery_info;
406         char *text;
407
408         IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
409
410         IRDA_ASSERT(self != NULL, return;);
411         IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
412
413         if (!pskb_may_pull(skb, sizeof(struct xid_frame))) {
414                 IRDA_ERROR("%s: frame to short!\n", __FUNCTION__);
415                 return;
416         }
417                 
418         xid = (struct xid_frame *) skb->data;
419
420         info->daddr = le32_to_cpu(xid->saddr);
421         info->saddr = le32_to_cpu(xid->daddr);
422
423         /* Make sure frame is addressed to us */
424         if ((info->saddr != self->saddr) && (info->saddr != BROADCAST)) {
425                 IRDA_DEBUG(0, "%s(), frame is not addressed to us!\n",
426                            __FUNCTION__);
427                 return;
428         }
429
430         if ((discovery = kzalloc(sizeof(discovery_t), GFP_ATOMIC)) == NULL) {
431                 IRDA_WARNING("%s: kmalloc failed!\n", __FUNCTION__);
432                 return;
433         }
434
435         discovery->data.daddr = info->daddr;
436         discovery->data.saddr = self->saddr;
437         discovery->timestamp = jiffies;
438
439         IRDA_DEBUG(4, "%s(), daddr=%08x\n", __FUNCTION__,
440                    discovery->data.daddr);
441
442         discovery_info = skb_pull(skb, sizeof(struct xid_frame));
443
444         /* Get info returned from peer */
445         discovery->data.hints[0] = discovery_info[0];
446         if (discovery_info[0] & HINT_EXTENSION) {
447                 IRDA_DEBUG(4, "EXTENSION\n");
448                 discovery->data.hints[1] = discovery_info[1];
449                 discovery->data.charset = discovery_info[2];
450                 text = (char *) &discovery_info[3];
451         } else {
452                 discovery->data.hints[1] = 0;
453                 discovery->data.charset = discovery_info[1];
454                 text = (char *) &discovery_info[2];
455         }
456         /*
457          *  Terminate info string, should be safe since this is where the
458          *  FCS bytes resides.
459          */
460         skb->data[skb->len] = '\0';
461         strncpy(discovery->data.info, text, NICKNAME_MAX_LEN);
462         discovery->name_len = strlen(discovery->data.info);
463
464         info->discovery = discovery;
465
466         irlap_do_event(self, RECV_DISCOVERY_XID_RSP, skb, info);
467 }
468
469 /*
470  * Function irlap_recv_discovery_xid_cmd (skb, info)
471  *
472  *    Received a XID discovery command
473  *
474  */
475 static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
476                                          struct sk_buff *skb,
477                                          struct irlap_info *info)
478 {
479         struct xid_frame *xid;
480         discovery_t *discovery = NULL;
481         __u8 *discovery_info;
482         char *text;
483
484         if (!pskb_may_pull(skb, sizeof(struct xid_frame))) {
485                 IRDA_ERROR("%s: frame to short!\n", __FUNCTION__);
486                 return;
487         }
488         
489         xid = (struct xid_frame *) skb->data;
490
491         info->daddr = le32_to_cpu(xid->saddr);
492         info->saddr = le32_to_cpu(xid->daddr);
493
494         /* Make sure frame is addressed to us */
495         if ((info->saddr != self->saddr) && (info->saddr != BROADCAST)) {
496                 IRDA_DEBUG(0, "%s(), frame is not addressed to us!\n",
497                            __FUNCTION__);
498                 return;
499         }
500
501         switch (xid->flags & 0x03) {
502         case 0x00:
503                 info->S = 1;
504                 break;
505         case 0x01:
506                 info->S = 6;
507                 break;
508         case 0x02:
509                 info->S = 8;
510                 break;
511         case 0x03:
512                 info->S = 16;
513                 break;
514         default:
515                 /* Error!! */
516                 return;
517         }
518         info->s = xid->slotnr;
519
520         discovery_info = skb_pull(skb, sizeof(struct xid_frame));
521
522         /*
523          *  Check if last frame
524          */
525         if (info->s == 0xff) {
526                 /* Check if things are sane at this point... */
527                 if((discovery_info == NULL) || 
528                    !pskb_may_pull(skb, 3)) {
529                         IRDA_ERROR("%s: discovery frame to short!\n",
530                                    __FUNCTION__);
531                         return;
532                 }
533
534                 /*
535                  *  We now have some discovery info to deliver!
536                  */
537                 discovery = kmalloc(sizeof(discovery_t), GFP_ATOMIC);
538                 if (!discovery) {
539                         IRDA_WARNING("%s: unable to malloc!\n", __FUNCTION__);
540                         return;
541                 }
542
543                 discovery->data.daddr = info->daddr;
544                 discovery->data.saddr = self->saddr;
545                 discovery->timestamp = jiffies;
546
547                 discovery->data.hints[0] = discovery_info[0];
548                 if (discovery_info[0] & HINT_EXTENSION) {
549                         discovery->data.hints[1] = discovery_info[1];
550                         discovery->data.charset = discovery_info[2];
551                         text = (char *) &discovery_info[3];
552                 } else {
553                         discovery->data.hints[1] = 0;
554                         discovery->data.charset = discovery_info[1];
555                         text = (char *) &discovery_info[2];
556                 }
557                 /*
558                  *  Terminate string, should be safe since this is where the
559                  *  FCS bytes resides.
560                  */
561                 skb->data[skb->len] = '\0';
562                 strncpy(discovery->data.info, text, NICKNAME_MAX_LEN);
563                 discovery->name_len = strlen(discovery->data.info);
564
565                 info->discovery = discovery;
566         } else
567                 info->discovery = NULL;
568
569         irlap_do_event(self, RECV_DISCOVERY_XID_CMD, skb, info);
570 }
571
572 /*
573  * Function irlap_send_rr_frame (self, command)
574  *
575  *    Build and transmit RR (Receive Ready) frame. Notice that it is currently
576  *    only possible to send RR frames with the poll bit set.
577  */
578 void irlap_send_rr_frame(struct irlap_cb *self, int command)
579 {
580         struct sk_buff *tx_skb;
581         struct rr_frame *frame;
582
583         tx_skb = alloc_skb(sizeof(struct rr_frame), GFP_ATOMIC);
584         if (!tx_skb)
585                 return;
586
587         frame = (struct rr_frame *)skb_put(tx_skb, 2);
588
589         frame->caddr = self->caddr;
590         frame->caddr |= (command) ? CMD_FRAME : 0;
591
592         frame->control = RR | PF_BIT | (self->vr << 5);
593
594         irlap_queue_xmit(self, tx_skb);
595 }
596
597 /*
598  * Function irlap_send_rd_frame (self)
599  *
600  *    Request disconnect. Used by a secondary station to request the
601  *    disconnection of the link.
602  */
603 void irlap_send_rd_frame(struct irlap_cb *self)
604 {
605         struct sk_buff *tx_skb;
606         struct rd_frame *frame;
607
608         tx_skb = alloc_skb(sizeof(struct rd_frame), GFP_ATOMIC);
609         if (!tx_skb)
610                 return;
611
612         frame = (struct rd_frame *)skb_put(tx_skb, 2);
613
614         frame->caddr = self->caddr;
615         frame->caddr = RD_RSP | PF_BIT;
616
617         irlap_queue_xmit(self, tx_skb);
618 }
619
620 /*
621  * Function irlap_recv_rr_frame (skb, info)
622  *
623  *    Received RR (Receive Ready) frame from peer station, no harm in
624  *    making it inline since its called only from one single place
625  *    (irlap_driver_rcv).
626  */
627 static inline void irlap_recv_rr_frame(struct irlap_cb *self,
628                                        struct sk_buff *skb,
629                                        struct irlap_info *info, int command)
630 {
631         info->nr = skb->data[1] >> 5;
632
633         /* Check if this is a command or a response frame */
634         if (command)
635                 irlap_do_event(self, RECV_RR_CMD, skb, info);
636         else
637                 irlap_do_event(self, RECV_RR_RSP, skb, info);
638 }
639
640 /*
641  * Function irlap_recv_rnr_frame (self, skb, info)
642  *
643  *    Received RNR (Receive Not Ready) frame from peer station
644  *
645  */
646 static void irlap_recv_rnr_frame(struct irlap_cb *self, struct sk_buff *skb,
647                                  struct irlap_info *info, int command)
648 {
649         info->nr = skb->data[1] >> 5;
650
651         IRDA_DEBUG(4, "%s(), nr=%d, %ld\n", __FUNCTION__, info->nr, jiffies);
652
653         if (command)
654                 irlap_do_event(self, RECV_RNR_CMD, skb, info);
655         else
656                 irlap_do_event(self, RECV_RNR_RSP, skb, info);
657 }
658
659 static void irlap_recv_rej_frame(struct irlap_cb *self, struct sk_buff *skb,
660                                  struct irlap_info *info, int command)
661 {
662         IRDA_DEBUG(0, "%s()\n", __FUNCTION__);
663
664         info->nr = skb->data[1] >> 5;
665
666         /* Check if this is a command or a response frame */
667         if (command)
668                 irlap_do_event(self, RECV_REJ_CMD, skb, info);
669         else
670                 irlap_do_event(self, RECV_REJ_RSP, skb, info);
671 }
672
673 static void irlap_recv_srej_frame(struct irlap_cb *self, struct sk_buff *skb,
674                                   struct irlap_info *info, int command)
675 {
676         IRDA_DEBUG(0, "%s()\n", __FUNCTION__);
677
678         info->nr = skb->data[1] >> 5;
679
680         /* Check if this is a command or a response frame */
681         if (command)
682                 irlap_do_event(self, RECV_SREJ_CMD, skb, info);
683         else
684                 irlap_do_event(self, RECV_SREJ_RSP, skb, info);
685 }
686
687 static void irlap_recv_disc_frame(struct irlap_cb *self, struct sk_buff *skb,
688                                   struct irlap_info *info, int command)
689 {
690         IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
691
692         /* Check if this is a command or a response frame */
693         if (command)
694                 irlap_do_event(self, RECV_DISC_CMD, skb, info);
695         else
696                 irlap_do_event(self, RECV_RD_RSP, skb, info);
697 }
698
699 /*
700  * Function irlap_recv_ua_frame (skb, frame)
701  *
702  *    Received UA (Unnumbered Acknowledgement) frame
703  *
704  */
705 static inline void irlap_recv_ua_frame(struct irlap_cb *self,
706                                        struct sk_buff *skb,
707                                        struct irlap_info *info)
708 {
709         irlap_do_event(self, RECV_UA_RSP, skb, info);
710 }
711
712 /*
713  * Function irlap_send_data_primary(self, skb)
714  *
715  *    Send I-frames as the primary station but without the poll bit set
716  *
717  */
718 void irlap_send_data_primary(struct irlap_cb *self, struct sk_buff *skb)
719 {
720         struct sk_buff *tx_skb;
721
722         if (skb->data[1] == I_FRAME) {
723
724                 /*
725                  *  Insert frame sequence number (Vs) in control field before
726                  *  inserting into transmit window queue.
727                  */
728                 skb->data[1] = I_FRAME | (self->vs << 1);
729
730                 /*
731                  *  Insert frame in store, in case of retransmissions
732                  *  Increase skb reference count, see irlap_do_event()
733                  */
734                 skb_get(skb);
735                 skb_queue_tail(&self->wx_list, skb);
736
737                 /* Copy buffer */
738                 tx_skb = skb_clone(skb, GFP_ATOMIC);
739                 if (tx_skb == NULL) {
740                         return;
741                 }
742
743                 self->vs = (self->vs + 1) % 8;
744                 self->ack_required = FALSE;
745                 self->window -= 1;
746
747                 irlap_send_i_frame( self, tx_skb, CMD_FRAME);
748         } else {
749                 IRDA_DEBUG(4, "%s(), sending unreliable frame\n", __FUNCTION__);
750                 irlap_send_ui_frame(self, skb_get(skb), self->caddr, CMD_FRAME);
751                 self->window -= 1;
752         }
753 }
754 /*
755  * Function irlap_send_data_primary_poll (self, skb)
756  *
757  *    Send I(nformation) frame as primary with poll bit set
758  */
759 void irlap_send_data_primary_poll(struct irlap_cb *self, struct sk_buff *skb)
760 {
761         struct sk_buff *tx_skb;
762         int transmission_time;
763
764         /* Stop P timer */
765         del_timer(&self->poll_timer);
766
767         /* Is this reliable or unreliable data? */
768         if (skb->data[1] == I_FRAME) {
769
770                 /*
771                  *  Insert frame sequence number (Vs) in control field before
772                  *  inserting into transmit window queue.
773                  */
774                 skb->data[1] = I_FRAME | (self->vs << 1);
775
776                 /*
777                  *  Insert frame in store, in case of retransmissions
778                  *  Increase skb reference count, see irlap_do_event()
779                  */
780                 skb_get(skb);
781                 skb_queue_tail(&self->wx_list, skb);
782
783                 /* Copy buffer */
784                 tx_skb = skb_clone(skb, GFP_ATOMIC);
785                 if (tx_skb == NULL) {
786                         return;
787                 }
788
789                 /*
790                  *  Set poll bit if necessary. We do this to the copied
791                  *  skb, since retransmitted need to set or clear the poll
792                  *  bit depending on when they are sent.
793                  */
794                 tx_skb->data[1] |= PF_BIT;
795
796                 self->vs = (self->vs + 1) % 8;
797                 self->ack_required = FALSE;
798
799                 irlap_send_i_frame(self, tx_skb, CMD_FRAME);
800         } else {
801                 IRDA_DEBUG(4, "%s(), sending unreliable frame\n", __FUNCTION__);
802
803                 if (self->ack_required) {
804                         irlap_send_ui_frame(self, skb_get(skb), self->caddr, CMD_FRAME);
805                         irlap_send_rr_frame(self, CMD_FRAME);
806                         self->ack_required = FALSE;
807                 } else {
808                         skb->data[1] |= PF_BIT;
809                         irlap_send_ui_frame(self, skb_get(skb), self->caddr, CMD_FRAME);
810                 }
811         }
812
813         /* How much time we took for transmission of all frames.
814          * We don't know, so let assume we used the full window. Jean II */
815         transmission_time = self->final_timeout;
816
817         /* Reset parameter so that we can fill next window */
818         self->window = self->window_size;
819
820 #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
821         /* Remove what we have not used. Just do a prorata of the
822          * bytes left in window to window capacity.
823          * See max_line_capacities[][] in qos.c for details. Jean II */
824         transmission_time -= (self->final_timeout * self->bytes_left
825                               / self->line_capacity);
826         IRDA_DEBUG(4, "%s() adjusting transmission_time : ft=%d, bl=%d, lc=%d -> tt=%d\n", __FUNCTION__, self->final_timeout, self->bytes_left, self->line_capacity, transmission_time);
827
828         /* We are allowed to transmit a maximum number of bytes again. */
829         self->bytes_left = self->line_capacity;
830 #endif /* CONFIG_IRDA_DYNAMIC_WINDOW */
831
832         /*
833          * The network layer has a intermediate buffer between IrLAP
834          * and the IrDA driver which can contain 8 frames. So, even
835          * though IrLAP is currently sending the *last* frame of the
836          * tx-window, the driver most likely has only just started
837          * sending the *first* frame of the same tx-window.
838          * I.e. we are always at the very begining of or Tx window.
839          * Now, we are supposed to set the final timer from the end
840          * of our tx-window to let the other peer reply. So, we need
841          * to add extra time to compensate for the fact that we
842          * are really at the start of tx-window, otherwise the final timer
843          * might expire before he can answer...
844          * Jean II
845          */
846         irlap_start_final_timer(self, self->final_timeout + transmission_time);
847
848         /*
849          * The clever amongst you might ask why we do this adjustement
850          * only here, and not in all the other cases in irlap_event.c.
851          * In all those other case, we only send a very short management
852          * frame (few bytes), so the adjustement would be lost in the
853          * noise...
854          * The exception of course is irlap_resend_rejected_frame().
855          * Jean II */
856 }
857
858 /*
859  * Function irlap_send_data_secondary_final (self, skb)
860  *
861  *    Send I(nformation) frame as secondary with final bit set
862  *
863  */
864 void irlap_send_data_secondary_final(struct irlap_cb *self,
865                                      struct sk_buff *skb)
866 {
867         struct sk_buff *tx_skb = NULL;
868
869         IRDA_ASSERT(self != NULL, return;);
870         IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
871         IRDA_ASSERT(skb != NULL, return;);
872
873         /* Is this reliable or unreliable data? */
874         if (skb->data[1] == I_FRAME) {
875
876                 /*
877                  *  Insert frame sequence number (Vs) in control field before
878                  *  inserting into transmit window queue.
879                  */
880                 skb->data[1] = I_FRAME | (self->vs << 1);
881
882                 /*
883                  *  Insert frame in store, in case of retransmissions
884                  *  Increase skb reference count, see irlap_do_event()
885                  */
886                 skb_get(skb);
887                 skb_queue_tail(&self->wx_list, skb);
888
889                 tx_skb = skb_clone(skb, GFP_ATOMIC);
890                 if (tx_skb == NULL) {
891                         return;
892                 }
893
894                 tx_skb->data[1] |= PF_BIT;
895
896                 self->vs = (self->vs + 1) % 8;
897                 self->ack_required = FALSE;
898
899                 irlap_send_i_frame(self, tx_skb, RSP_FRAME);
900         } else {
901                 if (self->ack_required) {
902                         irlap_send_ui_frame(self, skb_get(skb), self->caddr, RSP_FRAME);
903                         irlap_send_rr_frame(self, RSP_FRAME);
904                         self->ack_required = FALSE;
905                 } else {
906                         skb->data[1] |= PF_BIT;
907                         irlap_send_ui_frame(self, skb_get(skb), self->caddr, RSP_FRAME);
908                 }
909         }
910
911         self->window = self->window_size;
912 #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
913         /* We are allowed to transmit a maximum number of bytes again. */
914         self->bytes_left = self->line_capacity;
915 #endif /* CONFIG_IRDA_DYNAMIC_WINDOW */
916
917         irlap_start_wd_timer(self, self->wd_timeout);
918 }
919
920 /*
921  * Function irlap_send_data_secondary (self, skb)
922  *
923  *    Send I(nformation) frame as secondary without final bit set
924  *
925  */
926 void irlap_send_data_secondary(struct irlap_cb *self, struct sk_buff *skb)
927 {
928         struct sk_buff *tx_skb = NULL;
929
930         /* Is this reliable or unreliable data? */
931         if (skb->data[1] == I_FRAME) {
932
933                 /*
934                  *  Insert frame sequence number (Vs) in control field before
935                  *  inserting into transmit window queue.
936                  */
937                 skb->data[1] = I_FRAME | (self->vs << 1);
938
939                 /*
940                  *  Insert frame in store, in case of retransmissions
941                  *  Increase skb reference count, see irlap_do_event()
942                  */
943                 skb_get(skb);
944                 skb_queue_tail(&self->wx_list, skb);
945
946                 tx_skb = skb_clone(skb, GFP_ATOMIC);
947                 if (tx_skb == NULL) {
948                         return;
949                 }
950
951                 self->vs = (self->vs + 1) % 8;
952                 self->ack_required = FALSE;
953                 self->window -= 1;
954
955                 irlap_send_i_frame(self, tx_skb, RSP_FRAME);
956         } else {
957                 irlap_send_ui_frame(self, skb_get(skb), self->caddr, RSP_FRAME);
958                 self->window -= 1;
959         }
960 }
961
962 /*
963  * Function irlap_resend_rejected_frames (nr)
964  *
965  *    Resend frames which has not been acknowledged. Should be safe to
966  *    traverse the list without locking it since this function will only be
967  *    called from interrupt context (BH)
968  */
969 void irlap_resend_rejected_frames(struct irlap_cb *self, int command)
970 {
971         struct sk_buff *tx_skb;
972         struct sk_buff *skb;
973         int count;
974
975         IRDA_ASSERT(self != NULL, return;);
976         IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
977
978         /* Initialize variables */
979         count = skb_queue_len(&self->wx_list);
980
981         /*  Resend unacknowledged frame(s) */
982         skb = skb_peek(&self->wx_list);
983         while (skb != NULL) {
984                 irlap_wait_min_turn_around(self, &self->qos_tx);
985
986                 /* We copy the skb to be retransmitted since we will have to
987                  * modify it. Cloning will confuse packet sniffers
988                  */
989                 /* tx_skb = skb_clone( skb, GFP_ATOMIC); */
990                 tx_skb = skb_copy(skb, GFP_ATOMIC);
991                 if (!tx_skb) {
992                         IRDA_DEBUG(0, "%s(), unable to copy\n", __FUNCTION__);
993                         return;
994                 }
995
996                 /* Clear old Nr field + poll bit */
997                 tx_skb->data[1] &= 0x0f;
998
999                 /*
1000                  *  Set poll bit on the last frame retransmitted
1001                  */
1002                 if (count-- == 1)
1003                         tx_skb->data[1] |= PF_BIT; /* Set p/f bit */
1004                 else
1005                         tx_skb->data[1] &= ~PF_BIT; /* Clear p/f bit */
1006
1007                 irlap_send_i_frame(self, tx_skb, command);
1008
1009                 /*
1010                  *  If our skb is the last buffer in the list, then
1011                  *  we are finished, if not, move to the next sk-buffer
1012                  */
1013                 if (skb == skb_peek_tail(&self->wx_list))
1014                         skb = NULL;
1015                 else
1016                         skb = skb->next;
1017         }
1018 #if 0 /* Not yet */
1019         /*
1020          *  We can now fill the window with additional data frames
1021          */
1022         while (!skb_queue_empty(&self->txq)) {
1023
1024                 IRDA_DEBUG(0, "%s(), sending additional frames!\n", __FUNCTION__);
1025                 if (self->window > 0) {
1026                         skb = skb_dequeue( &self->txq);
1027                         IRDA_ASSERT(skb != NULL, return;);
1028
1029                         /*
1030                          *  If send window > 1 then send frame with pf
1031                          *  bit cleared
1032                          */
1033                         if ((self->window > 1) &&
1034                             !skb_queue_empty(&self->txq)) {
1035                                 irlap_send_data_primary(self, skb);
1036                         } else {
1037                                 irlap_send_data_primary_poll(self, skb);
1038                         }
1039                         kfree_skb(skb);
1040                 }
1041         }
1042 #endif
1043 }
1044
1045 void irlap_resend_rejected_frame(struct irlap_cb *self, int command)
1046 {
1047         struct sk_buff *tx_skb;
1048         struct sk_buff *skb;
1049
1050         IRDA_ASSERT(self != NULL, return;);
1051         IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
1052
1053         /*  Resend unacknowledged frame(s) */
1054         skb = skb_peek(&self->wx_list);
1055         if (skb != NULL) {
1056                 irlap_wait_min_turn_around(self, &self->qos_tx);
1057
1058                 /* We copy the skb to be retransmitted since we will have to
1059                  * modify it. Cloning will confuse packet sniffers
1060                  */
1061                 /* tx_skb = skb_clone( skb, GFP_ATOMIC); */
1062                 tx_skb = skb_copy(skb, GFP_ATOMIC);
1063                 if (!tx_skb) {
1064                         IRDA_DEBUG(0, "%s(), unable to copy\n", __FUNCTION__);
1065                         return;
1066                 }
1067
1068                 /* Clear old Nr field + poll bit */
1069                 tx_skb->data[1] &= 0x0f;
1070
1071                 /*  Set poll/final bit */
1072                 tx_skb->data[1] |= PF_BIT; /* Set p/f bit */
1073
1074                 irlap_send_i_frame(self, tx_skb, command);
1075         }
1076 }
1077
1078 /*
1079  * Function irlap_send_ui_frame (self, skb, command)
1080  *
1081  *    Contruct and transmit an Unnumbered Information (UI) frame
1082  *
1083  */
1084 void irlap_send_ui_frame(struct irlap_cb *self, struct sk_buff *skb,
1085                          __u8 caddr, int command)
1086 {
1087         IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
1088
1089         IRDA_ASSERT(self != NULL, return;);
1090         IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
1091         IRDA_ASSERT(skb != NULL, return;);
1092
1093         /* Insert connection address */
1094         skb->data[0] = caddr | ((command) ? CMD_FRAME : 0);
1095
1096         irlap_queue_xmit(self, skb);
1097 }
1098
1099 /*
1100  * Function irlap_send_i_frame (skb)
1101  *
1102  *    Contruct and transmit Information (I) frame
1103  */
1104 static void irlap_send_i_frame(struct irlap_cb *self, struct sk_buff *skb,
1105                                int command)
1106 {
1107         /* Insert connection address */
1108         skb->data[0] = self->caddr;
1109         skb->data[0] |= (command) ? CMD_FRAME : 0;
1110
1111         /* Insert next to receive (Vr) */
1112         skb->data[1] |= (self->vr << 5);  /* insert nr */
1113
1114         irlap_queue_xmit(self, skb);
1115 }
1116
1117 /*
1118  * Function irlap_recv_i_frame (skb, frame)
1119  *
1120  *    Receive and parse an I (Information) frame, no harm in making it inline
1121  *    since it's called only from one single place (irlap_driver_rcv).
1122  */
1123 static inline void irlap_recv_i_frame(struct irlap_cb *self,
1124                                       struct sk_buff *skb,
1125                                       struct irlap_info *info, int command)
1126 {
1127         info->nr = skb->data[1] >> 5;          /* Next to receive */
1128         info->pf = skb->data[1] & PF_BIT;      /* Final bit */
1129         info->ns = (skb->data[1] >> 1) & 0x07; /* Next to send */
1130
1131         /* Check if this is a command or a response frame */
1132         if (command)
1133                 irlap_do_event(self, RECV_I_CMD, skb, info);
1134         else
1135                 irlap_do_event(self, RECV_I_RSP, skb, info);
1136 }
1137
1138 /*
1139  * Function irlap_recv_ui_frame (self, skb, info)
1140  *
1141  *    Receive and parse an Unnumbered Information (UI) frame
1142  *
1143  */
1144 static void irlap_recv_ui_frame(struct irlap_cb *self, struct sk_buff *skb,
1145                                 struct irlap_info *info)
1146 {
1147         IRDA_DEBUG( 4, "%s()\n", __FUNCTION__);
1148
1149         info->pf = skb->data[1] & PF_BIT;      /* Final bit */
1150
1151         irlap_do_event(self, RECV_UI_FRAME, skb, info);
1152 }
1153
1154 /*
1155  * Function irlap_recv_frmr_frame (skb, frame)
1156  *
1157  *    Received Frame Reject response.
1158  *
1159  */
1160 static void irlap_recv_frmr_frame(struct irlap_cb *self, struct sk_buff *skb,
1161                                   struct irlap_info *info)
1162 {
1163         __u8 *frame;
1164         int w, x, y, z;
1165
1166         IRDA_DEBUG(0, "%s()\n", __FUNCTION__);
1167
1168         IRDA_ASSERT(self != NULL, return;);
1169         IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
1170         IRDA_ASSERT(skb != NULL, return;);
1171         IRDA_ASSERT(info != NULL, return;);
1172
1173         if (!pskb_may_pull(skb, 4)) {
1174                 IRDA_ERROR("%s: frame to short!\n", __FUNCTION__);
1175                 return;
1176         }
1177
1178         frame = skb->data;
1179
1180         info->nr = frame[2] >> 5;          /* Next to receive */
1181         info->pf = frame[2] & PF_BIT;      /* Final bit */
1182         info->ns = (frame[2] >> 1) & 0x07; /* Next to send */
1183
1184         w = frame[3] & 0x01;
1185         x = frame[3] & 0x02;
1186         y = frame[3] & 0x04;
1187         z = frame[3] & 0x08;
1188
1189         if (w) {
1190                 IRDA_DEBUG(0, "Rejected control field is undefined or not "
1191                       "implemented.\n");
1192         }
1193         if (x) {
1194                 IRDA_DEBUG(0, "Rejected control field was invalid because it "
1195                       "contained a non permitted I field.\n");
1196         }
1197         if (y) {
1198                 IRDA_DEBUG(0, "Received I field exceeded the maximum negotiated "
1199                       "for the existing connection or exceeded the maximum "
1200                       "this station supports if no connection exists.\n");
1201         }
1202         if (z) {
1203                 IRDA_DEBUG(0, "Rejected control field control field contained an "
1204                       "invalid Nr count.\n");
1205         }
1206         irlap_do_event(self, RECV_FRMR_RSP, skb, info);
1207 }
1208
1209 /*
1210  * Function irlap_send_test_frame (self, daddr)
1211  *
1212  *    Send a test frame response
1213  *
1214  */
1215 void irlap_send_test_frame(struct irlap_cb *self, __u8 caddr, __u32 daddr,
1216                            struct sk_buff *cmd)
1217 {
1218         struct sk_buff *tx_skb;
1219         struct test_frame *frame;
1220         __u8 *info;
1221
1222         tx_skb = alloc_skb(cmd->len + sizeof(struct test_frame), GFP_ATOMIC);
1223         if (!tx_skb)
1224                 return;
1225
1226         /* Broadcast frames must include saddr and daddr fields */
1227         if (caddr == CBROADCAST) {
1228                 frame = (struct test_frame *)
1229                         skb_put(tx_skb, sizeof(struct test_frame));
1230
1231                 /* Insert the swapped addresses */
1232                 frame->saddr = cpu_to_le32(self->saddr);
1233                 frame->daddr = cpu_to_le32(daddr);
1234         } else
1235                 frame = (struct test_frame *) skb_put(tx_skb, LAP_ADDR_HEADER + LAP_CTRL_HEADER);
1236
1237         frame->caddr = caddr;
1238         frame->control = TEST_RSP | PF_BIT;
1239
1240         /* Copy info */
1241         info = skb_put(tx_skb, cmd->len);
1242         memcpy(info, cmd->data, cmd->len);
1243
1244         /* Return to sender */
1245         irlap_wait_min_turn_around(self, &self->qos_tx);
1246         irlap_queue_xmit(self, tx_skb);
1247 }
1248
1249 /*
1250  * Function irlap_recv_test_frame (self, skb)
1251  *
1252  *    Receive a test frame
1253  *
1254  */
1255 static void irlap_recv_test_frame(struct irlap_cb *self, struct sk_buff *skb,
1256                                   struct irlap_info *info, int command)
1257 {
1258         struct test_frame *frame;
1259
1260         IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
1261
1262         if (!pskb_may_pull(skb, sizeof(*frame))) {
1263                 IRDA_ERROR("%s: frame to short!\n", __FUNCTION__);
1264                 return;
1265         }
1266         frame = (struct test_frame *) skb->data;
1267
1268         /* Broadcast frames must carry saddr and daddr fields */
1269         if (info->caddr == CBROADCAST) {
1270                 if (skb->len < sizeof(struct test_frame)) {
1271                         IRDA_DEBUG(0, "%s() test frame to short!\n",
1272                                    __FUNCTION__);
1273                         return;
1274                 }
1275
1276                 /* Read and swap addresses */
1277                 info->daddr = le32_to_cpu(frame->saddr);
1278                 info->saddr = le32_to_cpu(frame->daddr);
1279
1280                 /* Make sure frame is addressed to us */
1281                 if ((info->saddr != self->saddr) &&
1282                     (info->saddr != BROADCAST)) {
1283                         return;
1284                 }
1285         }
1286
1287         if (command)
1288                 irlap_do_event(self, RECV_TEST_CMD, skb, info);
1289         else
1290                 irlap_do_event(self, RECV_TEST_RSP, skb, info);
1291 }
1292
1293 /*
1294  * Function irlap_driver_rcv (skb, netdev, ptype)
1295  *
1296  *    Called when a frame is received. Dispatches the right receive function
1297  *    for processing of the frame.
1298  *
1299  * Note on skb management :
1300  * After calling the higher layers of the IrDA stack, we always
1301  * kfree() the skb, which drop the reference count (and potentially
1302  * destroy it).
1303  * If a higher layer of the stack want to keep the skb around (to put
1304  * in a queue or pass it to the higher layer), it will need to use
1305  * skb_get() to keep a reference on it. This is usually done at the
1306  * LMP level in irlmp.c.
1307  * Jean II
1308  */
1309 int irlap_driver_rcv(struct sk_buff *skb, struct net_device *dev,
1310                      struct packet_type *ptype, struct net_device *orig_dev)
1311 {
1312         struct irlap_info info;
1313         struct irlap_cb *self;
1314         int command;
1315         __u8 control;
1316
1317         /* FIXME: should we get our own field? */
1318         self = (struct irlap_cb *) dev->atalk_ptr;
1319
1320         /* If the net device is down, then IrLAP is gone! */
1321         if (!self || self->magic != LAP_MAGIC) {
1322                 dev_kfree_skb(skb);
1323                 return -1;
1324         }
1325
1326         /* We are no longer an "old" protocol, so we need to handle
1327          * share and non linear skbs. This should never happen, so
1328          * we don't need to be clever about it. Jean II */
1329         if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
1330                 IRDA_ERROR("%s: can't clone shared skb!\n", __FUNCTION__);
1331                 dev_kfree_skb(skb);
1332                 return -1;
1333         }
1334
1335         /* Check if frame is large enough for parsing */
1336         if (!pskb_may_pull(skb, 2)) {
1337                 IRDA_ERROR("%s: frame to short!\n", __FUNCTION__);
1338                 dev_kfree_skb(skb);
1339                 return -1;
1340         }
1341
1342         command    = skb->data[0] & CMD_FRAME;
1343         info.caddr = skb->data[0] & CBROADCAST;
1344
1345         info.pf      = skb->data[1] &  PF_BIT;
1346         info.control = skb->data[1] & ~PF_BIT; /* Mask away poll/final bit */
1347
1348         control = info.control;
1349
1350         /*  First we check if this frame has a valid connection address */
1351         if ((info.caddr != self->caddr) && (info.caddr != CBROADCAST)) {
1352                 IRDA_DEBUG(0, "%s(), wrong connection address!\n",
1353                            __FUNCTION__);
1354                 goto out;
1355         }
1356         /*
1357          *  Optimize for the common case and check if the frame is an
1358          *  I(nformation) frame. Only I-frames have bit 0 set to 0
1359          */
1360         if (~control & 0x01) {
1361                 irlap_recv_i_frame(self, skb, &info, command);
1362                 goto out;
1363         }
1364         /*
1365          *  We now check is the frame is an S(upervisory) frame. Only
1366          *  S-frames have bit 0 set to 1 and bit 1 set to 0
1367          */
1368         if (~control & 0x02) {
1369                 /*
1370                  *  Received S(upervisory) frame, check which frame type it is
1371                  *  only the first nibble is of interest
1372                  */
1373                 switch (control & 0x0f) {
1374                 case RR:
1375                         irlap_recv_rr_frame(self, skb, &info, command);
1376                         break;
1377                 case RNR:
1378                         irlap_recv_rnr_frame(self, skb, &info, command);
1379                         break;
1380                 case REJ:
1381                         irlap_recv_rej_frame(self, skb, &info, command);
1382                         break;
1383                 case SREJ:
1384                         irlap_recv_srej_frame(self, skb, &info, command);
1385                         break;
1386                 default:
1387                         IRDA_WARNING("%s: Unknown S-frame %02x received!\n",
1388                                 __FUNCTION__, info.control);
1389                         break;
1390                 }
1391                 goto out;
1392         }
1393         /*
1394          *  This must be a C(ontrol) frame
1395          */
1396         switch (control) {
1397         case XID_RSP:
1398                 irlap_recv_discovery_xid_rsp(self, skb, &info);
1399                 break;
1400         case XID_CMD:
1401                 irlap_recv_discovery_xid_cmd(self, skb, &info);
1402                 break;
1403         case SNRM_CMD:
1404                 irlap_recv_snrm_cmd(self, skb, &info);
1405                 break;
1406         case DM_RSP:
1407                 irlap_do_event(self, RECV_DM_RSP, skb, &info);
1408                 break;
1409         case DISC_CMD: /* And RD_RSP since they have the same value */
1410                 irlap_recv_disc_frame(self, skb, &info, command);
1411                 break;
1412         case TEST_CMD:
1413                 irlap_recv_test_frame(self, skb, &info, command);
1414                 break;
1415         case UA_RSP:
1416                 irlap_recv_ua_frame(self, skb, &info);
1417                 break;
1418         case FRMR_RSP:
1419                 irlap_recv_frmr_frame(self, skb, &info);
1420                 break;
1421         case UI_FRAME:
1422                 irlap_recv_ui_frame(self, skb, &info);
1423                 break;
1424         default:
1425                 IRDA_WARNING("%s: Unknown frame %02x received!\n",
1426                                 __FUNCTION__, info.control);
1427                 break;
1428         }
1429 out:
1430         /* Always drop our reference on the skb */
1431         dev_kfree_skb(skb);
1432         return 0;
1433 }