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