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