Commit | Line | Data |
---|---|---|
68c0bdff HG |
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 | * | |
d36b6910 | 26 | * Copyright © 2003 Agere Systems Inc. |
68c0bdff HG |
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 | * | |
d36b6910 | 47 | * THIS SOFTWARE IS PROVIDED \93AS IS\94 AND ANY EXPRESS OR IMPLIED WARRANTIES, |
68c0bdff HG |
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 | ||
68c0bdff HG |
62 | /******************************************************************************* |
63 | * include files | |
64 | ******************************************************************************/ | |
8174fc04 | 65 | #include <linux/string.h> |
68c0bdff HG |
66 | #include <wl_version.h> |
67 | ||
68 | #include <debug.h> | |
69 | #include <hcf.h> | |
70 | ||
71 | #include <wl_enc.h> | |
72 | ||
68c0bdff HG |
73 | /******************************************************************************* |
74 | * wl_wep_code() | |
75 | ******************************************************************************* | |
76 | * | |
77 | * DESCRIPTION: | |
78 | * | |
79 | * This function encodes a set of wep keys for privacy | |
80 | * | |
81 | * PARAMETERS: | |
82 | * | |
83 | * szCrypt - | |
84 | * szDest - | |
85 | * Data - | |
86 | * nLen - | |
87 | * | |
88 | * RETURNS: | |
89 | * | |
90 | * OK | |
91 | * | |
92 | ******************************************************************************/ | |
2d33309e | 93 | int wl_wep_code(char *szCrypt, char *szDest, void *Data, int nLen) |
68c0bdff | 94 | { |
9413127a JM |
95 | int i; |
96 | int t; | |
97 | int k ; | |
98 | char bits; | |
99 | char *szData = (char *) Data; | |
100 | /*------------------------------------------------------------------------*/ | |
68c0bdff HG |
101 | |
102 | ||
2d33309e | 103 | for (i = bits = 0; i < MACADDRESS_STR_LEN; i++) { |
9413127a JM |
104 | bits ^= szCrypt[i]; |
105 | bits += szCrypt[i]; | |
106 | } | |
68c0bdff | 107 | |
2d33309e JM |
108 | for (i = t = *szDest = 0; i < nLen; i++, t++) { |
109 | k = szData[i] ^ (bits + i); | |
68c0bdff HG |
110 | |
111 | ||
2d33309e | 112 | switch (i % 3) { |
68c0bdff | 113 | |
f83a7c34 | 114 | case 0: |
68c0bdff | 115 | |
9413127a JM |
116 | szDest[t] = ((k & 0xFC) >> 2) + CH_START ; |
117 | szDest[t+1] = ((k & 0x03) << 4) + CH_START ; | |
118 | szDest[t+2] = '\0'; | |
68c0bdff | 119 | |
9413127a | 120 | break; |
68c0bdff HG |
121 | |
122 | ||
f83a7c34 | 123 | case 1: |
68c0bdff | 124 | |
2d33309e JM |
125 | szDest[t] += ((k & 0xF0) >> 4); |
126 | szDest[t+1] = ((k & 0x0F) << 2) + CH_START ; | |
9413127a | 127 | szDest[t+2] = '\0'; |
68c0bdff | 128 | |
9413127a | 129 | break; |
68c0bdff HG |
130 | |
131 | ||
f83a7c34 | 132 | case 2: |
68c0bdff | 133 | |
2d33309e JM |
134 | szDest[t] += ((k & 0xC0) >> 6); |
135 | szDest[t+1] = (k & 0x3F) + CH_START ; | |
9413127a JM |
136 | szDest[t+2] = '\0'; |
137 | t++; | |
68c0bdff | 138 | |
9413127a JM |
139 | break; |
140 | } | |
141 | } | |
68c0bdff | 142 | |
13821d96 | 143 | return strlen(szDest); |
68c0bdff HG |
144 | |
145 | } | |
146 | /*============================================================================*/ | |
147 | ||
148 | ||
149 | ||
150 | ||
151 | /******************************************************************************* | |
152 | * wl_wep_decode() | |
153 | ******************************************************************************* | |
154 | * | |
155 | * DESCRIPTION: | |
156 | * | |
157 | * This function decodes a set of WEP keys for use by the card. | |
158 | * | |
159 | * PARAMETERS: | |
160 | * | |
161 | * szCrypt - | |
162 | * szDest - | |
163 | * Data - | |
164 | * | |
165 | * RETURNS: | |
166 | * | |
167 | * OK | |
168 | * | |
169 | ******************************************************************************/ | |
2d33309e | 170 | int wl_wep_decode(char *szCrypt, void *Dest, char *szData) |
68c0bdff | 171 | { |
9413127a JM |
172 | int i; |
173 | int t; | |
174 | int nLen; | |
175 | char bits; | |
176 | char *szDest = Dest; | |
177 | /*------------------------------------------------------------------------*/ | |
68c0bdff HG |
178 | |
179 | ||
2d33309e | 180 | for (i = bits = 0; i < 12; i++) { |
9413127a JM |
181 | bits ^= szCrypt[i] ; |
182 | bits += szCrypt[i] ; | |
183 | } | |
68c0bdff | 184 | |
2d33309e | 185 | nLen = (strlen(szData) * 3) / 4 ; |
68c0bdff | 186 | |
2d33309e JM |
187 | for (i = t = 0; i < nLen; i++, t++) { |
188 | switch (i % 3) { | |
f83a7c34 | 189 | case 0: |
68c0bdff | 190 | |
2d33309e JM |
191 | szDest[i] = (((szData[t] - CH_START) & 0x3f) << 2) + |
192 | (((szData[t+1] - CH_START) & 0x30) >> 4); | |
9413127a | 193 | break; |
68c0bdff HG |
194 | |
195 | ||
f83a7c34 | 196 | case 1: |
2d33309e JM |
197 | szDest[i] = (((szData[t] - CH_START) & 0x0f) << 4) + |
198 | (((szData[t+1] - CH_START) & 0x3c) >> 2); | |
9413127a | 199 | break; |
68c0bdff HG |
200 | |
201 | ||
f83a7c34 | 202 | case 2: |
2d33309e JM |
203 | szDest[i] = (((szData[t] - CH_START) & 0x03) << 6) + |
204 | ((szData[t+1] - CH_START) & 0x3f); | |
9413127a JM |
205 | t++; |
206 | break; | |
207 | } | |
68c0bdff | 208 | |
2d33309e | 209 | szDest[i] ^= (bits + i); |
68c0bdff | 210 | |
9413127a | 211 | } |
68c0bdff | 212 | |
13821d96 | 213 | return i; |
68c0bdff HG |
214 | |
215 | } | |
216 | /*============================================================================*/ | |
217 |