e7cc89f8e7a8f6dec97b02f27c1ab0eb3365eaed
[firefly-linux-kernel-4.4.55.git] / drivers / staging / wlan-ng / p80211conv.c
1 /* src/p80211/p80211conv.c
2 *
3 * Ether/802.11 conversions and packet buffer routines
4 *
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc.  All Rights Reserved.
6 * --------------------------------------------------------------------
7 *
8 * linux-wlan
9 *
10 *   The contents of this file are subject to the Mozilla Public
11 *   License Version 1.1 (the "License"); you may not use this file
12 *   except in compliance with the License. You may obtain a copy of
13 *   the License at http://www.mozilla.org/MPL/
14 *
15 *   Software distributed under the License is distributed on an "AS
16 *   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 *   implied. See the License for the specific language governing
18 *   rights and limitations under the License.
19 *
20 *   Alternatively, the contents of this file may be used under the
21 *   terms of the GNU Public License version 2 (the "GPL"), in which
22 *   case the provisions of the GPL are applicable instead of the
23 *   above.  If you wish to allow the use of your version of this file
24 *   only under the terms of the GPL and not to allow others to use
25 *   your version of this file under the MPL, indicate your decision
26 *   by deleting the provisions above and replace them with the notice
27 *   and other provisions required by the GPL.  If you do not delete
28 *   the provisions above, a recipient may use your version of this
29 *   file under either the MPL or the GPL.
30 *
31 * --------------------------------------------------------------------
32 *
33 * Inquiries regarding the linux-wlan Open Source project can be
34 * made directly to:
35 *
36 * AbsoluteValue Systems Inc.
37 * info@linux-wlan.com
38 * http://www.linux-wlan.com
39 *
40 * --------------------------------------------------------------------
41 *
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
44 *
45 * --------------------------------------------------------------------
46 *
47 * This file defines the functions that perform Ethernet to/from
48 * 802.11 frame conversions.
49 *
50 * --------------------------------------------------------------------
51 */
52 /*================================================================*/
53 /* System Includes */
54
55 #include <linux/version.h>
56
57 #include <linux/module.h>
58 #include <linux/kernel.h>
59 #include <linux/sched.h>
60 #include <linux/types.h>
61 #include <linux/skbuff.h>
62 #include <linux/slab.h>
63 #include <linux/wireless.h>
64 #include <linux/netdevice.h>
65 #include <linux/etherdevice.h>
66 #include <linux/if_ether.h>
67
68 #include <asm/byteorder.h>
69
70 #include "wlan_compat.h"
71
72 /*================================================================*/
73 /* Project Includes */
74
75 #include "p80211types.h"
76 #include "p80211hdr.h"
77 #include "p80211conv.h"
78 #include "p80211mgmt.h"
79 #include "p80211msg.h"
80 #include "p80211netdev.h"
81 #include "p80211ioctl.h"
82 #include "p80211req.h"
83
84
85 /*================================================================*/
86 /* Local Constants */
87
88 /*================================================================*/
89 /* Local Macros */
90
91
92 /*================================================================*/
93 /* Local Types */
94
95
96 /*================================================================*/
97 /* Local Static Definitions */
98
99 static u8       oui_rfc1042[] = {0x00, 0x00, 0x00};
100 static u8       oui_8021h[] = {0x00, 0x00, 0xf8};
101
102 /*================================================================*/
103 /* Local Function Declarations */
104
105
106 /*================================================================*/
107 /* Function Definitions */
108
109 /*----------------------------------------------------------------
110 * p80211pb_ether_to_80211
111 *
112 * Uses the contents of the ether frame and the etherconv setting
113 * to build the elements of the 802.11 frame.
114 *
115 * We don't actually set
116 * up the frame header here.  That's the MAC's job.  We're only handling
117 * conversion of DIXII or 802.3+LLC frames to something that works
118 * with 802.11.
119 *
120 * Note -- 802.11 header is NOT part of the skb.  Likewise, the 802.11
121 *         FCS is also not present and will need to be added elsewhere.
122 *
123 * Arguments:
124 *       ethconv         Conversion type to perform
125 *       skb             skbuff containing the ether frame
126 *       p80211_hdr      802.11 header
127 *
128 * Returns:
129 *       0 on success, non-zero otherwise
130 *
131 * Call context:
132 *       May be called in interrupt or non-interrupt context
133 ----------------------------------------------------------------*/
134 int skb_ether_to_p80211( wlandevice_t *wlandev, u32 ethconv, struct sk_buff *skb, p80211_hdr_t *p80211_hdr, p80211_metawep_t *p80211_wep)
135 {
136
137         u16          fc;
138         u16          proto;
139         wlan_ethhdr_t   e_hdr;
140         wlan_llc_t      *e_llc;
141         wlan_snap_t     *e_snap;
142         int foo;
143
144         DBFENTER;
145         memcpy(&e_hdr, skb->data, sizeof(e_hdr));
146
147         if (skb->len <= 0) {
148                 WLAN_LOG_DEBUG(1, "zero-length skb!\n");
149                 return 1;
150         }
151
152         if ( ethconv == WLAN_ETHCONV_ENCAP ) { /* simplest case */
153                 WLAN_LOG_DEBUG(3, "ENCAP len: %d\n", skb->len);
154                 /* here, we don't care what kind of ether frm. Just stick it */
155                 /*  in the 80211 payload */
156                 /* which is to say, leave the skb alone. */
157         } else {
158                 /* step 1: classify ether frame, DIX or 802.3? */
159                 proto = ntohs(e_hdr.type);
160                 if ( proto <= 1500 ) {
161                         WLAN_LOG_DEBUG(3, "802.3 len: %d\n", skb->len);
162                         /* codes <= 1500 reserved for 802.3 lengths */
163                         /* it's 802.3, pass ether payload unchanged,  */
164
165                         /* trim off ethernet header */
166                         skb_pull(skb, WLAN_ETHHDR_LEN);
167
168                         /*   leave off any PAD octets.  */
169                         skb_trim(skb, proto);
170                 } else {
171                         WLAN_LOG_DEBUG(3, "DIXII len: %d\n", skb->len);
172                         /* it's DIXII, time for some conversion */
173
174                         /* trim off ethernet header */
175                         skb_pull(skb, WLAN_ETHHDR_LEN);
176
177                         /* tack on SNAP */
178                         e_snap = (wlan_snap_t *) skb_push(skb, sizeof(wlan_snap_t));
179                         e_snap->type = htons(proto);
180                         if ( ethconv == WLAN_ETHCONV_8021h && p80211_stt_findproto(proto) ) {
181                                 memcpy( e_snap->oui, oui_8021h, WLAN_IEEE_OUI_LEN);
182                         } else {
183                                 memcpy( e_snap->oui, oui_rfc1042, WLAN_IEEE_OUI_LEN);
184                         }
185
186                         /* tack on llc */
187                         e_llc = (wlan_llc_t *) skb_push(skb, sizeof(wlan_llc_t));
188                         e_llc->dsap = 0xAA;     /* SNAP, see IEEE 802 */
189                         e_llc->ssap = 0xAA;
190                         e_llc->ctl = 0x03;
191
192                 }
193         }
194
195         /* Set up the 802.11 header */
196         /* It's a data frame */
197         fc = host2ieee16( WLAN_SET_FC_FTYPE(WLAN_FTYPE_DATA) |
198                           WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DATAONLY));
199
200         switch ( wlandev->macmode ) {
201         case WLAN_MACMODE_IBSS_STA:
202                 memcpy(p80211_hdr->a3.a1, &e_hdr.daddr, WLAN_ADDR_LEN);
203                 memcpy(p80211_hdr->a3.a2, wlandev->netdev->dev_addr, WLAN_ADDR_LEN);
204                 memcpy(p80211_hdr->a3.a3, wlandev->bssid, WLAN_ADDR_LEN);
205                 break;
206         case WLAN_MACMODE_ESS_STA:
207                 fc |= host2ieee16(WLAN_SET_FC_TODS(1));
208                 memcpy(p80211_hdr->a3.a1, wlandev->bssid, WLAN_ADDR_LEN);
209                 memcpy(p80211_hdr->a3.a2, wlandev->netdev->dev_addr, WLAN_ADDR_LEN);
210                 memcpy(p80211_hdr->a3.a3, &e_hdr.daddr, WLAN_ADDR_LEN);
211                 break;
212         case WLAN_MACMODE_ESS_AP:
213                 fc |= host2ieee16(WLAN_SET_FC_FROMDS(1));
214                 memcpy(p80211_hdr->a3.a1, &e_hdr.daddr, WLAN_ADDR_LEN);
215                 memcpy(p80211_hdr->a3.a2, wlandev->bssid, WLAN_ADDR_LEN);
216                 memcpy(p80211_hdr->a3.a3, &e_hdr.saddr, WLAN_ADDR_LEN);
217                 break;
218         default:
219                 WLAN_LOG_ERROR("Error: Converting eth to wlan in unknown mode.\n");
220                 return 1;
221                 break;
222         }
223
224         p80211_wep->data = NULL;
225
226         if ((wlandev->hostwep & HOSTWEP_PRIVACYINVOKED) && (wlandev->hostwep & HOSTWEP_ENCRYPT)) {
227                 // XXXX need to pick keynum other than default?
228
229 #if 1
230                 p80211_wep->data = kmalloc(skb->len, GFP_ATOMIC);
231 #else
232                 p80211_wep->data = skb->data;
233 #endif
234
235                 if ((foo = wep_encrypt(wlandev, skb->data, p80211_wep->data,
236                                        skb->len,
237                                 (wlandev->hostwep & HOSTWEP_DEFAULTKEY_MASK),
238                                 p80211_wep->iv, p80211_wep->icv))) {
239                         WLAN_LOG_WARNING("Host en-WEP failed, dropping frame (%d).\n", foo);
240                         return 2;
241                 }
242                 fc |= host2ieee16(WLAN_SET_FC_ISWEP(1));
243         }
244
245
246         //      skb->nh.raw = skb->data;
247
248         p80211_hdr->a3.fc = fc;
249         p80211_hdr->a3.dur = 0;
250         p80211_hdr->a3.seq = 0;
251
252         DBFEXIT;
253         return 0;
254 }
255
256 /* jkriegl: from orinoco, modified */
257 static void orinoco_spy_gather(wlandevice_t *wlandev, char *mac,
258                                p80211_rxmeta_t *rxmeta)
259 {
260         int i;
261
262         /* Gather wireless spy statistics: for each packet, compare the
263          * source address with out list, and if match, get the stats... */
264
265         for (i = 0; i < wlandev->spy_number; i++) {
266
267                 if (!memcmp(wlandev->spy_address[i], mac, ETH_ALEN)) {
268                         memcpy(wlandev->spy_address[i], mac, ETH_ALEN);
269                         wlandev->spy_stat[i].level = rxmeta->signal;
270                         wlandev->spy_stat[i].noise = rxmeta->noise;
271                         wlandev->spy_stat[i].qual = (rxmeta->signal > rxmeta->noise) ? \
272                                                      (rxmeta->signal - rxmeta->noise) : 0;
273                         wlandev->spy_stat[i].updated = 0x7;
274                 }
275         }
276 }
277
278 /*----------------------------------------------------------------
279 * p80211pb_80211_to_ether
280 *
281 * Uses the contents of a received 802.11 frame and the etherconv
282 * setting to build an ether frame.
283 *
284 * This function extracts the src and dest address from the 802.11
285 * frame to use in the construction of the eth frame.
286 *
287 * Arguments:
288 *       ethconv         Conversion type to perform
289 *       skb             Packet buffer containing the 802.11 frame
290 *
291 * Returns:
292 *       0 on success, non-zero otherwise
293 *
294 * Call context:
295 *       May be called in interrupt or non-interrupt context
296 ----------------------------------------------------------------*/
297 int skb_p80211_to_ether( wlandevice_t *wlandev, u32 ethconv, struct sk_buff *skb)
298 {
299         netdevice_t     *netdev = wlandev->netdev;
300         u16          fc;
301         unsigned int            payload_length;
302         unsigned int            payload_offset;
303         u8              daddr[WLAN_ETHADDR_LEN];
304         u8              saddr[WLAN_ETHADDR_LEN];
305         p80211_hdr_t    *w_hdr;
306         wlan_ethhdr_t   *e_hdr;
307         wlan_llc_t      *e_llc;
308         wlan_snap_t     *e_snap;
309
310         int foo;
311
312         DBFENTER;
313
314         payload_length = skb->len - WLAN_HDR_A3_LEN - WLAN_CRC_LEN;
315         payload_offset = WLAN_HDR_A3_LEN;
316
317         w_hdr = (p80211_hdr_t *) skb->data;
318
319         /* setup some vars for convenience */
320         fc = ieee2host16(w_hdr->a3.fc);
321         if ( (WLAN_GET_FC_TODS(fc) == 0) && (WLAN_GET_FC_FROMDS(fc) == 0) ) {
322                 memcpy(daddr, w_hdr->a3.a1, WLAN_ETHADDR_LEN);
323                 memcpy(saddr, w_hdr->a3.a2, WLAN_ETHADDR_LEN);
324         } else if( (WLAN_GET_FC_TODS(fc) == 0) && (WLAN_GET_FC_FROMDS(fc) == 1) ) {
325                 memcpy(daddr, w_hdr->a3.a1, WLAN_ETHADDR_LEN);
326                 memcpy(saddr, w_hdr->a3.a3, WLAN_ETHADDR_LEN);
327         } else if( (WLAN_GET_FC_TODS(fc) == 1) && (WLAN_GET_FC_FROMDS(fc) == 0) ) {
328                 memcpy(daddr, w_hdr->a3.a3, WLAN_ETHADDR_LEN);
329                 memcpy(saddr, w_hdr->a3.a2, WLAN_ETHADDR_LEN);
330         } else {
331                 payload_offset = WLAN_HDR_A4_LEN;
332                 payload_length -= ( WLAN_HDR_A4_LEN - WLAN_HDR_A3_LEN );
333                 if (payload_length < 0 ) {
334                         WLAN_LOG_ERROR("A4 frame too short!\n");
335                         return 1;
336                 }
337                 memcpy(daddr, w_hdr->a4.a3, WLAN_ETHADDR_LEN);
338                 memcpy(saddr, w_hdr->a4.a4, WLAN_ETHADDR_LEN);
339         }
340
341         /* perform de-wep if necessary.. */
342         if ((wlandev->hostwep & HOSTWEP_PRIVACYINVOKED) && WLAN_GET_FC_ISWEP(fc) && (wlandev->hostwep & HOSTWEP_DECRYPT)) {
343                 if (payload_length <= 8) {
344                         WLAN_LOG_ERROR("WEP frame too short (%u).\n",
345                                         skb->len);
346                         return 1;
347                 }
348                 if ((foo = wep_decrypt(wlandev, skb->data + payload_offset + 4,
349                                        payload_length - 8, -1,
350                                        skb->data + payload_offset,
351                                        skb->data + payload_offset + payload_length - 4))) {
352                         /* de-wep failed, drop skb. */
353                         WLAN_LOG_DEBUG(1, "Host de-WEP failed, dropping frame (%d).\n", foo);
354                         wlandev->rx.decrypt_err++;
355                         return 2;
356                 }
357
358                 /* subtract the IV+ICV length off the payload */
359                 payload_length -= 8;
360                 /* chop off the IV */
361                 skb_pull(skb, 4);
362                 /* chop off the ICV. */
363                 skb_trim(skb, skb->len - 4);
364
365                 wlandev->rx.decrypt++;
366         }
367
368         e_hdr = (wlan_ethhdr_t *) (skb->data + payload_offset);
369
370         e_llc = (wlan_llc_t *) (skb->data + payload_offset);
371         e_snap = (wlan_snap_t *) (skb->data + payload_offset + sizeof(wlan_llc_t));
372
373         /* Test for the various encodings */
374         if ( (payload_length >= sizeof(wlan_ethhdr_t)) &&
375              ( e_llc->dsap != 0xaa || e_llc->ssap != 0xaa ) &&
376              ((memcmp(daddr, e_hdr->daddr, WLAN_ETHADDR_LEN) == 0) ||
377              (memcmp(saddr, e_hdr->saddr, WLAN_ETHADDR_LEN) == 0))) {
378                 WLAN_LOG_DEBUG(3, "802.3 ENCAP len: %d\n", payload_length);
379                 /* 802.3 Encapsulated */
380
381                 /* Chop off the 802.11 header.  it's already sane. */
382                 skb_pull(skb, payload_offset);
383                 /* chop off the 802.11 CRC */
384                 skb_trim(skb, skb->len - WLAN_CRC_LEN);
385
386         } else if ((payload_length >= sizeof(wlan_llc_t) + sizeof(wlan_snap_t)) &&
387                    (e_llc->dsap == 0xaa) &&
388                    (e_llc->ssap == 0xaa) &&
389                    (e_llc->ctl == 0x03) &&
390                    (((memcmp( e_snap->oui, oui_rfc1042, WLAN_IEEE_OUI_LEN)==0) &&
391                     (ethconv == WLAN_ETHCONV_8021h) &&
392                     (p80211_stt_findproto(ieee2host16(e_snap->type)))) ||
393                     (memcmp( e_snap->oui, oui_rfc1042, WLAN_IEEE_OUI_LEN)!=0)))
394         {
395                 WLAN_LOG_DEBUG(3, "SNAP+RFC1042 len: %d\n", payload_length);
396                 /* it's a SNAP + RFC1042 frame && protocol is in STT */
397                 /* build 802.3 + RFC1042 */
398
399                 /* chop 802.11 header from skb. */
400                 skb_pull(skb, payload_offset);
401
402                 /* create 802.3 header at beginning of skb. */
403                 e_hdr = (wlan_ethhdr_t *) skb_push(skb, WLAN_ETHHDR_LEN);
404                 memcpy(e_hdr->daddr, daddr, WLAN_ETHADDR_LEN);
405                 memcpy(e_hdr->saddr, saddr, WLAN_ETHADDR_LEN);
406                 e_hdr->type = htons(payload_length);
407
408                 /* chop off the 802.11 CRC */
409                 skb_trim(skb, skb->len - WLAN_CRC_LEN);
410
411         }  else if ((payload_length >= sizeof(wlan_llc_t) + sizeof(wlan_snap_t)) &&
412                     (e_llc->dsap == 0xaa) &&
413                     (e_llc->ssap == 0xaa) &&
414                     (e_llc->ctl == 0x03) ) {
415                 WLAN_LOG_DEBUG(3, "802.1h/RFC1042 len: %d\n", payload_length);
416                 /* it's an 802.1h frame || (an RFC1042 && protocol is not in STT) */
417                 /* build a DIXII + RFC894 */
418
419                 /* chop 802.11 header from skb. */
420                 skb_pull(skb, payload_offset);
421
422                 /* chop llc header from skb. */
423                 skb_pull(skb, sizeof(wlan_llc_t));
424
425                 /* chop snap header from skb. */
426                 skb_pull(skb, sizeof(wlan_snap_t));
427
428                 /* create 802.3 header at beginning of skb. */
429                 e_hdr = (wlan_ethhdr_t *) skb_push(skb, WLAN_ETHHDR_LEN);
430                 e_hdr->type = e_snap->type;
431                 memcpy(e_hdr->daddr, daddr, WLAN_ETHADDR_LEN);
432                 memcpy(e_hdr->saddr, saddr, WLAN_ETHADDR_LEN);
433
434                 /* chop off the 802.11 CRC */
435                 skb_trim(skb, skb->len - WLAN_CRC_LEN);
436         } else {
437                 WLAN_LOG_DEBUG(3, "NON-ENCAP len: %d\n", payload_length);
438                 /* any NON-ENCAP */
439                 /* it's a generic 80211+LLC or IPX 'Raw 802.3' */
440                 /*  build an 802.3 frame */
441                 /* allocate space and setup hostbuf */
442
443                 /* Chop off the 802.11 header. */
444                 skb_pull(skb, payload_offset);
445
446                 /* create 802.3 header at beginning of skb. */
447                 e_hdr = (wlan_ethhdr_t *) skb_push(skb, WLAN_ETHHDR_LEN);
448                 memcpy(e_hdr->daddr, daddr, WLAN_ETHADDR_LEN);
449                 memcpy(e_hdr->saddr, saddr, WLAN_ETHADDR_LEN);
450                 e_hdr->type = htons(payload_length);
451
452                 /* chop off the 802.11 CRC */
453                 skb_trim(skb, skb->len - WLAN_CRC_LEN);
454
455         }
456
457         skb->protocol = eth_type_trans(skb, netdev);
458         skb_reset_mac_header(skb);
459
460         /* jkriegl: process signal and noise as set in hfa384x_int_rx() */
461         /* jkriegl: only process signal/noise if requested by iwspy */
462         if (wlandev->spy_number)
463                 orinoco_spy_gather(wlandev, eth_hdr(skb)->h_source, P80211SKB_RXMETA(skb));
464
465         /* Free the metadata */
466         p80211skb_rxmeta_detach(skb);
467
468         DBFEXIT;
469         return 0;
470 }
471
472 /*----------------------------------------------------------------
473 * p80211_stt_findproto
474 *
475 * Searches the 802.1h Selective Translation Table for a given
476 * protocol.
477 *
478 * Arguments:
479 *       proto   protocl number (in host order) to search for.
480 *
481 * Returns:
482 *       1 - if the table is empty or a match is found.
483 *       0 - if the table is non-empty and a match is not found.
484 *
485 * Call context:
486 *       May be called in interrupt or non-interrupt context
487 ----------------------------------------------------------------*/
488 int p80211_stt_findproto(u16 proto)
489 {
490         /* Always return found for now.  This is the behavior used by the */
491         /*  Zoom Win95 driver when 802.1h mode is selected */
492         /* TODO: If necessary, add an actual search we'll probably
493                  need this to match the CMAC's way of doing things.
494                  Need to do some testing to confirm.
495         */
496
497         if (proto == 0x80f3)  /* APPLETALK */
498                 return 1;
499
500         return 0;
501 }
502
503 /*----------------------------------------------------------------
504 * p80211skb_rxmeta_detach
505 *
506 * Disconnects the frmmeta and rxmeta from an skb.
507 *
508 * Arguments:
509 *       wlandev         The wlandev this skb belongs to.
510 *       skb             The skb we're attaching to.
511 *
512 * Returns:
513 *       0 on success, non-zero otherwise
514 *
515 * Call context:
516 *       May be called in interrupt or non-interrupt context
517 ----------------------------------------------------------------*/
518 void
519 p80211skb_rxmeta_detach(struct sk_buff *skb)
520 {
521         p80211_rxmeta_t         *rxmeta;
522         p80211_frmmeta_t        *frmmeta;
523
524         DBFENTER;
525         /* Sanity checks */
526         if ( skb==NULL ) {                      /* bad skb */
527                 WLAN_LOG_DEBUG(1, "Called w/ null skb.\n");
528                 goto exit;
529         }
530         frmmeta = P80211SKB_FRMMETA(skb);
531         if ( frmmeta == NULL ) {                /* no magic */
532                 WLAN_LOG_DEBUG(1, "Called w/ bad frmmeta magic.\n");
533                 goto exit;
534         }
535         rxmeta = frmmeta->rx;
536         if ( rxmeta == NULL ) {                 /* bad meta ptr */
537                 WLAN_LOG_DEBUG(1, "Called w/ bad rxmeta ptr.\n");
538                 goto exit;
539         }
540
541         /* Free rxmeta */
542         kfree(rxmeta);
543
544         /* Clear skb->cb */
545         memset(skb->cb, 0, sizeof(skb->cb));
546 exit:
547         DBFEXIT;
548         return;
549 }
550
551 /*----------------------------------------------------------------
552 * p80211skb_rxmeta_attach
553 *
554 * Allocates a p80211rxmeta structure, initializes it, and attaches
555 * it to an skb.
556 *
557 * Arguments:
558 *       wlandev         The wlandev this skb belongs to.
559 *       skb             The skb we're attaching to.
560 *
561 * Returns:
562 *       0 on success, non-zero otherwise
563 *
564 * Call context:
565 *       May be called in interrupt or non-interrupt context
566 ----------------------------------------------------------------*/
567 int
568 p80211skb_rxmeta_attach(struct wlandevice *wlandev, struct sk_buff *skb)
569 {
570         int                     result = 0;
571         p80211_rxmeta_t         *rxmeta;
572         p80211_frmmeta_t        *frmmeta;
573
574         DBFENTER;
575
576         /* If these already have metadata, we error out! */
577         if (P80211SKB_RXMETA(skb) != NULL) {
578                 WLAN_LOG_ERROR("%s: RXmeta already attached!\n",
579                                 wlandev->name);
580                 result = 0;
581                 goto exit;
582         }
583
584         /* Allocate the rxmeta */
585         rxmeta = kmalloc(sizeof(p80211_rxmeta_t), GFP_ATOMIC);
586
587         if ( rxmeta == NULL ) {
588                 WLAN_LOG_ERROR("%s: Failed to allocate rxmeta.\n",
589                                 wlandev->name);
590                 result = 1;
591                 goto exit;
592         }
593
594         /* Initialize the rxmeta */
595         memset(rxmeta, 0, sizeof(p80211_rxmeta_t));
596         rxmeta->wlandev = wlandev;
597         rxmeta->hosttime = jiffies;
598
599         /* Overlay a frmmeta_t onto skb->cb */
600         memset(skb->cb, 0, sizeof(p80211_frmmeta_t));
601         frmmeta = (p80211_frmmeta_t*)(skb->cb);
602         frmmeta->magic = P80211_FRMMETA_MAGIC;
603         frmmeta->rx = rxmeta;
604 exit:
605         DBFEXIT;
606         return result;
607 }
608
609 /*----------------------------------------------------------------
610 * p80211skb_free
611 *
612 * Frees an entire p80211skb by checking and freeing the meta struct
613 * and then freeing the skb.
614 *
615 * Arguments:
616 *       wlandev         The wlandev this skb belongs to.
617 *       skb             The skb we're attaching to.
618 *
619 * Returns:
620 *       0 on success, non-zero otherwise
621 *
622 * Call context:
623 *       May be called in interrupt or non-interrupt context
624 ----------------------------------------------------------------*/
625 void
626 p80211skb_free(struct wlandevice *wlandev, struct sk_buff *skb)
627 {
628         p80211_frmmeta_t        *meta;
629         DBFENTER;
630         meta = P80211SKB_FRMMETA(skb);
631         if ( meta && meta->rx) {
632                 p80211skb_rxmeta_detach(skb);
633         } else {
634                 WLAN_LOG_ERROR("Freeing an skb (%p) w/ no frmmeta.\n", skb);
635         }
636
637         dev_kfree_skb(skb);
638         DBFEXIT;
639         return;
640 }