]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/staging/wlags49_h2/wl_enc.c
33181da413cb59f5c301bbc0b9a164311b659d96
[net-next-2.6.git] / drivers / staging / wlags49_h2 / wl_enc.c
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  *
26  * Copyright � 2003 Agere Systems Inc.
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  *
47  * THIS SOFTWARE IS PROVIDED �AS IS� AND ANY EXPRESS OR IMPLIED WARRANTIES,
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
62
63
64
65 /*******************************************************************************
66  * VERSION CONTROL INFORMATION
67  *******************************************************************************
68  *
69  * $Author: nico $
70  * $Date: 2004/07/19 08:16:15 $
71  * $Revision: 1.2 $
72  * $Source: /usr/local/cvs/wl_lkm/wireless/wl_enc.c,v $
73  *
74  ******************************************************************************/
75
76
77
78
79 /*******************************************************************************
80  *  include files
81  ******************************************************************************/
82 #include <wl_version.h>
83
84 #include <debug.h>
85 #include <hcf.h>
86
87 #include <wl_enc.h>
88
89
90
91
92 /*******************************************************************************
93  *  global definitions
94  ******************************************************************************/
95 #if DBG
96
97 extern dbg_info_t *DbgInfo;
98
99 #endif  /* DBG */
100
101
102
103
104 /*******************************************************************************
105  *      wl_wep_code()
106  *******************************************************************************
107  *
108  *  DESCRIPTION:
109  *
110  *      This function encodes a set of wep keys for privacy
111  *
112  *  PARAMETERS:
113  *
114  *      szCrypt -
115  *      szDest  -
116  *      Data    -
117  *      nLen    -
118  *
119  *  RETURNS:
120  *
121  *      OK
122  *
123  ******************************************************************************/
124 int wl_wep_code( char *szCrypt, char *szDest, void *Data, int nLen )
125 {
126     int     i;
127     int     t;
128     int     k ;
129     char    bits;
130     char    *szData = (char *) Data;
131     /*------------------------------------------------------------------------*/
132
133
134     for( i = bits = 0 ; i < MACADDRESS_STR_LEN; i++ ) {
135             bits ^= szCrypt[i];
136             bits += szCrypt[i];
137     }
138
139     for( i = t = *szDest = 0; i < nLen; i++, t++ ) {
140             k = szData[i] ^ ( bits + i );
141
142
143         switch( i % 3 ) {
144
145         case 0 :
146
147             szDest[t]   = ((k & 0xFC) >> 2) + CH_START ;
148                         szDest[t+1] = ((k & 0x03) << 4) + CH_START ;
149                 szDest[t+2] = '\0';
150
151             break;
152
153
154         case 1 :
155
156             szDest[t]  += (( k & 0xF0 ) >> 4 );
157                         szDest[t+1] = (( k & 0x0F ) << 2 ) + CH_START ;
158                 szDest[t+2] = '\0';
159
160             break;
161
162
163         case 2 :
164
165             szDest[t]  += (( k & 0xC0 ) >> 6 );
166                         szDest[t+1] = ( k & 0x3F ) + CH_START ;
167                 szDest[t+2] = '\0';
168                 t++;
169
170             break;
171         }
172     }
173
174     return( strlen( szDest )) ;
175
176 }
177 /*============================================================================*/
178
179
180
181
182 /*******************************************************************************
183  *      wl_wep_decode()
184  *******************************************************************************
185  *
186  *  DESCRIPTION:
187  *
188  *      This function decodes a set of WEP keys for use by the card.
189  *
190  *  PARAMETERS:
191  *
192  *      szCrypt -
193  *      szDest  -
194  *      Data    -
195  *
196  *  RETURNS:
197  *
198  *      OK
199  *
200  ******************************************************************************/
201 int wl_wep_decode( char *szCrypt, void *Dest, char *szData )
202 {
203     int     i;
204     int     t;
205     int     nLen;
206     char    bits;
207     char    *szDest = Dest;
208   /*------------------------------------------------------------------------*/
209
210
211   for( i = bits = 0 ; i < 12; i++ ) {
212       bits ^= szCrypt[i] ;
213       bits += szCrypt[i] ;
214   }
215
216   nLen = ( strlen( szData ) * 3) / 4 ;
217
218   for( i = t = 0; i < nLen; i++, t++ ) {
219       switch( i % 3 ) {
220       case 0 :
221
222           szDest[i] = ((( szData[t]-CH_START ) & 0x3f ) << 2 ) +
223                       ((( szData[t+1]-CH_START ) & 0x30 ) >> 4 );
224               break;
225
226
227       case 1 :
228           szDest[i] = ((( szData[t]-CH_START ) & 0x0f ) << 4 ) +
229                       ((( szData[t+1]-CH_START ) & 0x3c ) >> 2 );
230               break;
231
232
233       case 2 :
234           szDest[i] = ((( szData[t]-CH_START ) & 0x03 ) << 6 ) +
235                        (( szData[t+1]-CH_START ) & 0x3f );
236               t++;
237               break;
238       }
239
240         szDest[i] ^= ( bits + i ) ;
241
242   }
243
244   return( i ) ;
245
246 }
247 /*============================================================================*/
248