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