2 /*******************************************************************************
4 * Wireless device driver for Linux (wlags49).
6 * Copyright (c) 1998-2003 Agere Systems Inc.
10 * Initially developed by TriplePoint, Inc.
11 * http://www.triplepoint.com
13 *------------------------------------------------------------------------------
15 * This file defines functions related to WEP key coding/decoding.
17 *------------------------------------------------------------------------------
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.
26 * Copyright © 2003 Agere Systems Inc.
27 * All rights reserved.
29 * Redistribution and use in source or binary forms, with or without
30 * modifications, are permitted provided that the following conditions are met:
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
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.
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.
47 * THIS SOFTWARE IS PROVIDED
\93AS IS
\94 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
60 ******************************************************************************/
62 /*******************************************************************************
64 ******************************************************************************/
65 #include <wl_version.h>
75 /*******************************************************************************
77 ******************************************************************************/
80 extern dbg_info_t *DbgInfo;
87 /*******************************************************************************
89 *******************************************************************************
93 * This function encodes a set of wep keys for privacy
106 ******************************************************************************/
107 int wl_wep_code( char *szCrypt, char *szDest, void *Data, int nLen )
113 char *szData = (char *) Data;
114 /*------------------------------------------------------------------------*/
117 for( i = bits = 0 ; i < MACADDRESS_STR_LEN; i++ ) {
122 for( i = t = *szDest = 0; i < nLen; i++, t++ ) {
123 k = szData[i] ^ ( bits + i );
130 szDest[t] = ((k & 0xFC) >> 2) + CH_START ;
131 szDest[t+1] = ((k & 0x03) << 4) + CH_START ;
139 szDest[t] += (( k & 0xF0 ) >> 4 );
140 szDest[t+1] = (( k & 0x0F ) << 2 ) + CH_START ;
148 szDest[t] += (( k & 0xC0 ) >> 6 );
149 szDest[t+1] = ( k & 0x3F ) + CH_START ;
157 return( strlen( szDest )) ;
160 /*============================================================================*/
165 /*******************************************************************************
167 *******************************************************************************
171 * This function decodes a set of WEP keys for use by the card.
183 ******************************************************************************/
184 int wl_wep_decode( char *szCrypt, void *Dest, char *szData )
191 /*------------------------------------------------------------------------*/
194 for( i = bits = 0 ; i < 12; i++ ) {
199 nLen = ( strlen( szData ) * 3) / 4 ;
201 for( i = t = 0; i < nLen; i++, t++ ) {
205 szDest[i] = ((( szData[t]-CH_START ) & 0x3f ) << 2 ) +
206 ((( szData[t+1]-CH_START ) & 0x30 ) >> 4 );
211 szDest[i] = ((( szData[t]-CH_START ) & 0x0f ) << 4 ) +
212 ((( szData[t+1]-CH_START ) & 0x3c ) >> 2 );
217 szDest[i] = ((( szData[t]-CH_START ) & 0x03 ) << 6 ) +
218 (( szData[t+1]-CH_START ) & 0x3f );
223 szDest[i] ^= ( bits + i ) ;
230 /*============================================================================*/