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