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