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