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