Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 1 | |
| 2 | /******************************************************************************* |
| 3 | * Agere Systems Inc. |
| 4 | * Wireless device driver for Linux (wlags49). |
| 5 | * |
| 6 | * Copyright (c) 1998-2003 Agere Systems Inc. |
| 7 | * All rights reserved. |
| 8 | * http://www.agere.com |
| 9 | * |
| 10 | * Initially developed by TriplePoint, Inc. |
| 11 | * http://www.triplepoint.com |
| 12 | * |
| 13 | *------------------------------------------------------------------------------ |
| 14 | * |
| 15 | * This file defines functions related to WEP key coding/decoding. |
| 16 | * |
| 17 | *------------------------------------------------------------------------------ |
| 18 | * |
| 19 | * SOFTWARE LICENSE |
| 20 | * |
| 21 | * This software is provided subject to the following terms and conditions, |
| 22 | * which you should read carefully before using the software. Using this |
| 23 | * software indicates your acceptance of these terms and conditions. If you do |
| 24 | * not agree with these terms and conditions, do not use the software. |
| 25 | * |
Al Viro | d36b691 | 2011-12-29 17:09:01 -0500 | [diff] [blame] | 26 | * Copyright © 2003 Agere Systems Inc. |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 27 | * All rights reserved. |
| 28 | * |
| 29 | * Redistribution and use in source or binary forms, with or without |
| 30 | * modifications, are permitted provided that the following conditions are met: |
| 31 | * |
| 32 | * . Redistributions of source code must retain the above copyright notice, this |
| 33 | * list of conditions and the following Disclaimer as comments in the code as |
| 34 | * well as in the documentation and/or other materials provided with the |
| 35 | * distribution. |
| 36 | * |
| 37 | * . Redistributions in binary form must reproduce the above copyright notice, |
| 38 | * this list of conditions and the following Disclaimer in the documentation |
| 39 | * and/or other materials provided with the distribution. |
| 40 | * |
| 41 | * . Neither the name of Agere Systems Inc. nor the names of the contributors |
| 42 | * may be used to endorse or promote products derived from this software |
| 43 | * without specific prior written permission. |
| 44 | * |
| 45 | * Disclaimer |
| 46 | * |
Al Viro | d36b691 | 2011-12-29 17:09:01 -0500 | [diff] [blame] | 47 | * THIS SOFTWARE IS PROVIDED AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 48 | * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF |
| 49 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY |
| 50 | * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN |
| 51 | * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY |
| 52 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 53 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 54 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 55 | * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT |
| 56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 57 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 58 | * DAMAGE. |
| 59 | * |
| 60 | ******************************************************************************/ |
| 61 | |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 62 | /******************************************************************************* |
| 63 | * include files |
| 64 | ******************************************************************************/ |
Jeff Mahoney | 8174fc0 | 2010-06-09 16:01:10 -0400 | [diff] [blame] | 65 | #include <linux/string.h> |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 66 | #include <wl_version.h> |
| 67 | |
| 68 | #include <debug.h> |
| 69 | #include <hcf.h> |
| 70 | |
| 71 | #include <wl_enc.h> |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | /******************************************************************************* |
| 77 | * global definitions |
| 78 | ******************************************************************************/ |
| 79 | #if DBG |
| 80 | |
| 81 | extern dbg_info_t *DbgInfo; |
| 82 | |
| 83 | #endif /* DBG */ |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | /******************************************************************************* |
| 89 | * wl_wep_code() |
| 90 | ******************************************************************************* |
| 91 | * |
| 92 | * DESCRIPTION: |
| 93 | * |
| 94 | * This function encodes a set of wep keys for privacy |
| 95 | * |
| 96 | * PARAMETERS: |
| 97 | * |
| 98 | * szCrypt - |
| 99 | * szDest - |
| 100 | * Data - |
| 101 | * nLen - |
| 102 | * |
| 103 | * RETURNS: |
| 104 | * |
| 105 | * OK |
| 106 | * |
| 107 | ******************************************************************************/ |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 108 | int wl_wep_code(char *szCrypt, char *szDest, void *Data, int nLen) |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 109 | { |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 110 | int i; |
| 111 | int t; |
| 112 | int k ; |
| 113 | char bits; |
| 114 | char *szData = (char *) Data; |
| 115 | /*------------------------------------------------------------------------*/ |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 116 | |
| 117 | |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 118 | for (i = bits = 0; i < MACADDRESS_STR_LEN; i++) { |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 119 | bits ^= szCrypt[i]; |
| 120 | bits += szCrypt[i]; |
| 121 | } |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 122 | |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 123 | for (i = t = *szDest = 0; i < nLen; i++, t++) { |
| 124 | k = szData[i] ^ (bits + i); |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 125 | |
| 126 | |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 127 | switch (i % 3) { |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 128 | |
Johan Meiring | f83a7c3 | 2012-11-30 18:58:34 +0200 | [diff] [blame] | 129 | case 0: |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 130 | |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 131 | szDest[t] = ((k & 0xFC) >> 2) + CH_START ; |
| 132 | szDest[t+1] = ((k & 0x03) << 4) + CH_START ; |
| 133 | szDest[t+2] = '\0'; |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 134 | |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 135 | break; |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 136 | |
| 137 | |
Johan Meiring | f83a7c3 | 2012-11-30 18:58:34 +0200 | [diff] [blame] | 138 | case 1: |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 139 | |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 140 | szDest[t] += ((k & 0xF0) >> 4); |
| 141 | szDest[t+1] = ((k & 0x0F) << 2) + CH_START ; |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 142 | szDest[t+2] = '\0'; |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 143 | |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 144 | break; |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 145 | |
| 146 | |
Johan Meiring | f83a7c3 | 2012-11-30 18:58:34 +0200 | [diff] [blame] | 147 | case 2: |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 148 | |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 149 | szDest[t] += ((k & 0xC0) >> 6); |
| 150 | szDest[t+1] = (k & 0x3F) + CH_START ; |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 151 | szDest[t+2] = '\0'; |
| 152 | t++; |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 153 | |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 154 | break; |
| 155 | } |
| 156 | } |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 157 | |
Johan Meiring | 13821d9 | 2012-11-30 18:58:35 +0200 | [diff] [blame] | 158 | return strlen(szDest); |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 159 | |
| 160 | } |
| 161 | /*============================================================================*/ |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | /******************************************************************************* |
| 167 | * wl_wep_decode() |
| 168 | ******************************************************************************* |
| 169 | * |
| 170 | * DESCRIPTION: |
| 171 | * |
| 172 | * This function decodes a set of WEP keys for use by the card. |
| 173 | * |
| 174 | * PARAMETERS: |
| 175 | * |
| 176 | * szCrypt - |
| 177 | * szDest - |
| 178 | * Data - |
| 179 | * |
| 180 | * RETURNS: |
| 181 | * |
| 182 | * OK |
| 183 | * |
| 184 | ******************************************************************************/ |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 185 | int wl_wep_decode(char *szCrypt, void *Dest, char *szData) |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 186 | { |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 187 | int i; |
| 188 | int t; |
| 189 | int nLen; |
| 190 | char bits; |
| 191 | char *szDest = Dest; |
| 192 | /*------------------------------------------------------------------------*/ |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 193 | |
| 194 | |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 195 | for (i = bits = 0; i < 12; i++) { |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 196 | bits ^= szCrypt[i] ; |
| 197 | bits += szCrypt[i] ; |
| 198 | } |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 199 | |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 200 | nLen = (strlen(szData) * 3) / 4 ; |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 201 | |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 202 | for (i = t = 0; i < nLen; i++, t++) { |
| 203 | switch (i % 3) { |
Johan Meiring | f83a7c3 | 2012-11-30 18:58:34 +0200 | [diff] [blame] | 204 | case 0: |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 205 | |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 206 | szDest[i] = (((szData[t] - CH_START) & 0x3f) << 2) + |
| 207 | (((szData[t+1] - CH_START) & 0x30) >> 4); |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 208 | break; |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 209 | |
| 210 | |
Johan Meiring | f83a7c3 | 2012-11-30 18:58:34 +0200 | [diff] [blame] | 211 | case 1: |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 212 | szDest[i] = (((szData[t] - CH_START) & 0x0f) << 4) + |
| 213 | (((szData[t+1] - CH_START) & 0x3c) >> 2); |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 214 | break; |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 215 | |
| 216 | |
Johan Meiring | f83a7c3 | 2012-11-30 18:58:34 +0200 | [diff] [blame] | 217 | case 2: |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 218 | szDest[i] = (((szData[t] - CH_START) & 0x03) << 6) + |
| 219 | ((szData[t+1] - CH_START) & 0x3f); |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 220 | t++; |
| 221 | break; |
| 222 | } |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 223 | |
Johan Meiring | 2d33309 | 2012-11-30 18:58:33 +0200 | [diff] [blame] | 224 | szDest[i] ^= (bits + i); |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 225 | |
Johan Meiring | 9413127 | 2012-11-30 18:58:32 +0200 | [diff] [blame] | 226 | } |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 227 | |
Johan Meiring | 13821d9 | 2012-11-30 18:58:35 +0200 | [diff] [blame] | 228 | return i; |
Henk de Groot | 68c0bdf | 2009-09-27 11:12:52 +0200 | [diff] [blame] | 229 | |
| 230 | } |
| 231 | /*============================================================================*/ |
| 232 | |